11 use Elgg\Traits\Loggable as ElggLoggable;
67 parent::initializeAttributes();
69 $this->attributes[
'subtype'] =
'plugin';
84 throw new ElggInvalidArgumentException(
'Plugin ID must be set');
115 $this->attributes[
'owner_guid'] =
$site->guid;
116 $this->attributes[
'container_guid'] =
$site->guid;
123 }
elseif ($this->getPriority() ===
null) {
131 return parent::save();
140 return (string) $this->title;
155 return ucwords(str_replace([
'-',
'_'],
' ', $this->getID()));
176 if (isset($this->path)) {
191 return $this->getPath() .
'languages/';
206 if ($this->static_config ===
null) {
207 $this->static_config = [];
210 $this->static_config = $this->includeFile(self::STATIC_CONFIG_FILENAME);
212 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
262 $old_priority = $this->getPriority();
263 $old_priority = $old_priority ?: 1;
280 return min($max_priority, max(1, (
int)
$priority));
295 $values = $this->getAllSettings();
309 if (!$this->isActive()) {
313 $defaults = (array) $this->getStaticConfig(
'settings', []);
337 'plugin_id' => $this->getID(),
344 elgg_log(
'Plugin settings cannot store arrays.', \Psr\Log\LogLevel::ERROR);
378 $this->unsetSetting(
$name);
392 $result = $this->unsetAllSettings();
395 $delete = Delete::fromTable(MetadataTable::TABLE_NAME);
404 elgg_log($e, \Psr\Log\LogLevel::ERROR);
424 $this->assertValid();
440 if (!$this->getID()) {
441 throw PluginException::factory([
442 'message' =>
elgg_echo(
'ElggPlugin:MissingID', [$this->guid]),
447 $this->getComposer()->assertPluginId();
449 if (file_exists($this->getPath() .
'start.php')) {
450 throw PluginException::factory([
451 'message' =>
elgg_echo(
'ElggPlugin:StartFound', [$this->getID()]),
463 if (isset($this->activated)) {
464 return $this->activated;
468 return $this->activated;
478 if ($this->isActive()) {
483 $this->assertCanActivate();
499 $this->assertValid();
500 $this->assertDependencies();
512 if ($this->isActive()) {
516 $this->assertCanActivate();
519 $this->assertStaticConfigValid();
521 if (!$this->setStatus(
true)) {
530 'plugin_id' => $this->getID(),
531 'plugin_entity' => $this,
545 $this->loadLanguages();
549 $this->getBootstrap()->activate();
553 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
559 if ($return ===
false) {
565 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been activated");
577 $plugin_config = $this->getStaticConfig(
'plugin', []);
578 return (array)
elgg_extract(
'dependencies', $plugin_config, []);
589 if (!$this->isActive()) {
594 $this->assertcanDeactivate();
614 foreach ($active_plugins as
$plugin) {
615 $dependencies =
$plugin->getDependencies();
616 if (!array_key_exists($this->getID(), $dependencies)) {
620 if (
elgg_extract(
'must_be_active', $dependencies[$this->getID()],
true)) {
625 if (empty($dependents)) {
630 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-',
$plugin->getID());
633 'text' =>
$plugin->getDisplayName(),
634 'href' =>
"#{$css_id}",
639 throw PluginException::factory([
640 'message' =>
elgg_echo(
'ElggPlugin:Dependencies:ActiveDependent', [$this->getDisplayName(),
$list]),
653 if (!$this->isActive()) {
657 $this->assertCanDeactivate();
661 'plugin_id' => $this->getID(),
662 'plugin_entity' => $this,
666 if ($return ===
false) {
670 $this->getBootstrap()->deactivate();
672 $this->deactivateEntities();
676 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been deactivated");
678 return $this->setStatus(
false);
690 $bootstrap = $this->getStaticConfig(
'bootstrap');
692 if (!is_subclass_of($bootstrap, \
Elgg\PluginBootstrapInterface::class)) {
693 throw PluginException::factory([
694 'message' =>
elgg_echo(
'LogicException:InterfaceNotImplemented', [
696 \
Elgg\PluginBootstrapInterface::class
702 return new $bootstrap($this,
elgg());
705 return new \Elgg\DefaultPluginBootstrap($this,
elgg());
715 $this->registerClasses();
717 $autoload_file =
'vendor/autoload.php';
718 if (!$this->canReadFile($autoload_file)) {
722 $autoloader = Includer::requireFileOnce(
"{$this->getPath()}{$autoload_file}");
724 if (!$autoloader instanceof \Composer\Autoload\ClassLoader) {
728 $autoloader->unregister();
731 $autoloader->register(
false);
742 public function register():
void {
745 $this->registerPublicServices();
746 $this->activateEntities();
747 $this->registerLanguages();
748 $this->registerViews();
750 $this->getBootstrap()->load();
760 $this->getBootstrap()->boot();
770 $this->registerRoutes();
771 $this->registerActions();
772 $this->registerEntities();
773 $this->registerWidgets();
774 $this->registerEvents();
775 $this->registerViewExtensions();
776 $this->registerGroupTools();
777 $this->registerViewOptions();
778 $this->registerNotifications();
780 $this->getBootstrap()->init();
792 $filepath =
"{$this->getPath()}{$filename}";
796 'ElggPlugin:Exception:CannotIncludeFile',
797 [
$filename, $this->getID(), $this->guid, $this->getPath()]
800 throw PluginException::factory([
807 $ret = Includer::requireFile($filepath);
808 }
catch (Exception $e) {
810 'ElggPlugin:Exception:IncludeFileThrew',
811 [
$filename, $this->getID(), $this->guid, $this->getPath()]
814 throw PluginException::factory([
832 return is_file(
"{$this->getPath()}{$filename}");
842 if (!$this->canReadFile(self::STATIC_CONFIG_FILENAME)) {
847 $value = $this->includeFile(self::STATIC_CONFIG_FILENAME);
848 if (ob_get_clean() !==
'') {
849 throw PluginException::factory([
850 'message' =>
elgg_echo(
'ElggPlugin:activate:ConfigSentOutput'),
858 throw PluginException::factory([
859 'message' =>
elgg_echo(
'ElggPlugin:activate:BadConfigFormat'),
871 $services_path = $this->getPath() . self::PUBLIC_SERVICES_FILENAME;
872 if (!is_file($services_path)) {
876 $services = Includer::includeFile($services_path);
877 foreach ($services as
$name => $definition) {
896 $spec = $this->getStaticConfig(
'views');
898 $views->mergeViewsSpec($spec);
902 if (!
$views->registerViewsFromPath($this->getPath())) {
903 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterViews', [$this->getID(), $this->guid, $this->getPath()]);
905 throw PluginException::factory([
918 $spec = (array) $this->getStaticConfig(
'entities', []);
926 foreach ($capabilities as $capability =>
$value) {
939 $root_path = $this->getPath();
941 $spec = (array) $this->getStaticConfig(
'actions', []);
943 foreach ($spec as
$action => $action_spec) {
944 if (!is_array($action_spec)) {
953 $handler =
"{$root_path}actions/{$action}.php";
958 unset($action_spec[
'access']);
959 unset($action_spec[
'controller']);
960 unset($action_spec[
'filename']);
974 $spec = (array) $this->getStaticConfig(
'routes', []);
975 foreach ($spec as
$name => $route_spec) {
976 if (!is_array($route_spec)) {
980 $routes->register(
$name, $route_spec);
992 $spec = (array) $this->getStaticConfig(
'widgets', []);
993 foreach ($spec as $widget_id => $widget_definition) {
994 if (!is_array($widget_definition)) {
998 if (!isset($widget_definition[
'id'])) {
999 $widget_definition[
'id'] = $widget_id;
1004 $widgets->registerType($definition);
1016 _elgg_services()->translator->registerLanguagePath($this->getLanguagesPath());
1029 $languages_path = $this->getLanguagesPath();
1030 if (!is_dir($languages_path)) {
1034 _elgg_services()->translator->registerTranslations($languages_path);
1043 _elgg_services()->autoloadManager->addClasses(
"{$this->getPath()}classes");
1052 $spec = (array) $this->getStaticConfig(
'entities', []);
1067 $spec = (array) $this->getStaticConfig(
'entities', []);
1084 $spec = (array) $this->getStaticConfig(
'events', []);
1086 foreach ($spec as
$name => $types) {
1087 foreach ($types as
$type => $callbacks) {
1088 foreach ($callbacks as $callback => $event_spec) {
1089 if (!is_array($event_spec)) {
1093 $unregister = (bool)
elgg_extract(
'unregister', $event_spec,
false);
1096 $events->unregisterHandler(
$name,
$type, $callback);
1115 $spec = (array) $this->getStaticConfig(
'view_extensions', []);
1118 foreach (
$extensions as $extention => $extention_spec) {
1119 if (!is_array($extention_spec)) {
1123 $unextend = (bool)
elgg_extract(
'unextend', $extention_spec,
false);
1126 $views->unextendView($src_view, $extention);
1144 $spec = (array) $this->getStaticConfig(
'group_tools', []);
1146 foreach ($spec as $tool_name => $tool_options) {
1147 if (!is_array($tool_options)) {
1151 $unregister = (bool)
elgg_extract(
'unregister', $tool_options,
false);
1154 $tools->unregister($tool_name);
1156 $tools->register($tool_name, $tool_options);
1167 $spec = (array) $this->getStaticConfig(
'view_options', []);
1169 foreach ($spec as $view_name =>
$options) {
1183 _elgg_services()->simpleCache->registerCacheableView($view_name);
1194 $spec = (array) $this->getStaticConfig(
'notifications', []);
1199 if ($callback ===
false) {
1201 }
elseif ($callback ===
true) {
1220 if (array_key_exists(
$name, $this->attributes)) {
1221 return $this->attributes[
$name];
1225 if (in_array(
$name, [
'title',
'description'])) {
1226 return parent::__get(
$name);
1229 return $this->getSetting(
$name);
1241 if (array_key_exists(
$name, $this->attributes)) {
1243 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
1253 if (in_array(
$name, [
'title',
'description'])) {
1277 $result = $this->addRelationship(
$site->guid,
'active_plugin');
1279 $result = $this->removeRelationship(
$site->guid,
'active_plugin');
1286 $this->invalidateCache();
1305 parent::invalidateCache();
1316 if (isset($this->composer)) {
1317 return $this->composer;
1320 $this->composer = new \Elgg\Plugin\Composer($this);
1321 return $this->composer;
1333 $this->assertDependencies();
1350 $this->getComposer()->assertConflicts();
1351 $this->getComposer()->assertActivePluginConflicts();
1352 $this->getComposer()->assertRequiredPhpVersion();
1353 $this->getComposer()->assertRequiredPhpExtensions();
1354 $this->assertPluginDependencies();
1367 $must_be_active =
elgg_extract(
'must_be_active', $plugin_dep,
true);
1372 if ($must_be_active && (!$dependent_plugin instanceof \
ElggPlugin || !$dependent_plugin->
isActive())) {
1373 throw PluginException::factory([
1379 if ($dependent_plugin instanceof \
ElggPlugin &&
$position && $dependent_plugin->isActive()) {
1380 if (
$position ==
'after' && ($this->getPriority() < $dependent_plugin->getPriority())) {
1381 throw PluginException::factory([
1385 }
elseif (
$position ==
'before' && ($this->getPriority() > $dependent_plugin->getPriority())) {
1386 throw PluginException::factory([
1408 $plugin_config = $this->getStaticConfig(
'plugin', []);
1415 if (in_array($this->getID(), Plugins::BUNDLED_PLUGINS)) {
1430 return $this->getComposer()->getCategories();
1441 return $this->getComposer()->getLicense();
1463 return (string) $this->getComposer()->getConfiguration()->support()->source();
1474 return (string) $this->getComposer()->getConfiguration()->support()->issues();
1485 return (string) $this->getComposer()->getConfiguration()->homepage();
1496 return (array) $this->getComposer()->getConfiguration()->authors();
1507 return $this->getComposer()->getConflicts();
$guid
Reset an ElggUpgrade.
if(! $user||! $user->canDelete()) $name
$plugin_id
Remove all user and plugin settings from the give plugin ID.
$params
Saves global plugin settings.
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
foreach( $paths as $path)
elgg_invalidate_caches()
Invalidate all the registered caches.
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
getComposer()
Returns the composer parser.
getWebsite()
Return the website.
assertCanActivate()
Asserts if a plugin can activate.
loadLanguages()
Loads the plugin's translations.
setPriority($priority)
Sets the priority of the plugin Returns the new priority or false on error.
getCategories()
Returns an array with categories.
canReadFile(string $filename)
Checks whether a plugin file with the given name exists.
getDescription()
Return the description.
assertCanDeactivate()
Asserts if a plugin can be deactivated.
unsetSetting(string $name)
Removes a plugin setting name and value.
const PRIORITY_SETTING_NAME
autoload()
Register plugin classes and require composer autoloader.
getPath()
Returns the plugin's full path with trailing slash.
registerViewExtensions()
Registers the plugin's view extensions provided in the plugin config file.
setStatus(bool $active)
Sets the plugin to active or inactive.
__set($name, $value)
Set a value as attribute or setting.
__get($name)
Get an attribute or setting value.
setSetting(string $name, $value)
Set a plugin setting for the plugin.
const ADDITIONAL_TEXT_FILES
getLicense()
Returns the license.
normalizePriority($priority)
Normalize and validate new priority.
registerEvents()
Registers the plugin's events provided in the plugin config file.
unsetAllSettings()
Removes all settings for this plugin.
assertStaticConfigValid()
If a static config file is present, is it a serializable array?
registerLanguages()
Registers the plugin's languages.
getVersion()
Returns the plugin version.
registerActions()
Registers the plugin's actions provided in the plugin config file.
getBootstrap()
Bootstrap object.
assertDependencies()
Assert plugin dependencies.
getDependencies()
Returns an array of dependencies as configured in the static config.
invalidateCache()
{Invalidate cache for entity.void}
registerViews()
Registers the plugin's views.
canDeactivate()
Checks if this plugin can be deactivated on the current Elgg installation.
initializeAttributes()
{{Initialize the attributes array.This is vital to distinguish between metadata and base parameters....
assertValid()
Asserts if a plugin is valid.
isActive()
Is this plugin active?
registerClasses()
Registers the plugin's classes.
static fromId(string $plugin_id, ?string $path=null)
Load a plugin object from its ID Create a new plugin entity if it doesn't exist.
getRepositoryURL()
Returns the repository url.
isCacheable()
{Is entity cacheable in the runtime cache.bool}
activateEntities()
Activates the plugin's entities.
registerGroupTools()
Registers the plugin's group tools provided in the plugin config file.
getID()
Returns the ID (dir name) of this plugin.
isValid()
Returns if the plugin is complete, meaning has all required files and Elgg can read them and they mak...
unsetAllEntityAndPluginSettings()
Remove all entity and plugin settings for this plugin.
const PUBLIC_SERVICES_FILENAME
registerViewOptions()
Registers the plugin's view options provided in the plugin config file.
registerNotifications()
Registers the plugin's notification events.
getBugTrackerURL()
Returns the bug tracker page.
getDisplayName()
Returns the name from elgg-plugin.php if available, otherwise a nicely formatted ID.
registerEntities()
Registers the plugin's entities.
getPriority()
Gets the plugin's load priority.
getConflicts()
Returns an array of projectnames with their conflicting version.
registerPublicServices()
Registers the plugin public services.
activate()
Activates the plugin for the current site.
getAuthors()
Returns an array of authors.
canActivate()
Checks if this plugin can be activated on the current Elgg installation.
getAllSettings()
Returns an array of all settings saved for this plugin when the plugin is active.
getStaticConfig(string $key, $default=null)
Get a value from the plugins' static config file.
setPath(string $path)
Set path.
registerRoutes()
Registers the plugin's routes provided in the plugin config file.
meetsDependencies()
Checks if dependencies are met.
assertPluginDependencies()
Assert required plugins or plugin position.
save()
{Save this data to the appropriate database table.bool}
getLanguagesPath()
Returns the plugin's languages directory full path with trailing slash.
deactivateEntities()
Deactivates the plugin's entities.
registerWidgets()
Registers the plugin's widgets provided in the plugin config file.
const STATIC_CONFIG_FILENAME
getSetting(string $name, $default=null)
Returns a plugin setting when the plugin is active.
includeFile(string $filename)
Includes one of the plugins files.
deactivate()
Deactivates the plugin.
Query builder for updating data in the database.
Persistent, installation-wide key-value storage.
A generic parent class for database exceptions.
Exception thrown if an argument is not of the expected type.
Allow executing scripts without $this context or local vars.
Find Elgg and project paths.
elgg_get_plugins_path()
Get the plugin path for this installation, ending with slash.
elgg_get_release()
Get the current Elgg release.
const ELGG_IGNORE_ACCESS
elgg_call() flags
const ELGG_DISABLE_SYSTEM_LOG
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
_elgg_services()
Get the global service provider.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_delete_admin_notice(string $id)
Remove an admin notice by ID.
elgg_get_plugins(string $status='active')
Returns an ordered list of plugins.
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
elgg_is_active_plugin(string $plugin_id)
Returns if a plugin is active for a current site.
elgg_get_site_entity()
Get the current site entity.
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
elgg_view(string $view, array $vars=[], string $viewtype='')
Return a parsed view.
setMetadata(string $name, mixed $value, string $value_type='', bool $multiple=false)
Set metadata on this entity.
getMetadata(string $name)
Return the value of a piece of metadata.
getAllMetadata()
Get all entity metadata.
deleteMetadata(?string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
if(! $menu instanceof \Elgg\Menu\PreparedMenu) $actions
if(empty($page_owner)|| $owner->guid !==$page_owner->guid) $widgets