67 parent::initializeAttributes();
69 $this->attributes[
'subtype'] =
'plugin';
83 if (empty($plugin_id)) {
115 $this->attributes[
'owner_guid'] =
$site->guid;
116 $this->attributes[
'container_guid'] =
$site->guid;
131 return parent::save();
167 $this->path = Paths::sanitize($path,
true);
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);
263 $old_priority = $old_priority ?: 1;
337 'plugin_id' => $this->
getID(),
344 elgg_log(
'Plugin settings cannot store arrays.', \Psr\Log\LogLevel::ERROR);
395 $delete = Delete::fromTable(MetadataTable::TABLE_NAME);
404 elgg_log($e, \Psr\Log\LogLevel::ERROR);
440 if (!$this->
getID()) {
441 throw PluginException::factory([
442 'message' =>
elgg_echo(
'ElggPlugin:MissingID', [$this->guid]),
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)) {
530 'plugin_id' => $this->
getID(),
531 'plugin_entity' => $this,
553 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
559 if ($return ===
false) {
565 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been activated");
578 return (array)
elgg_extract(
'dependencies', $plugin_config, []);
594 $this->assertcanDeactivate();
614 foreach ($active_plugins as
$plugin) {
615 $dependencies = $plugin->getDependencies();
616 if (!array_key_exists($this->
getID(), $dependencies)) {
621 $dependents[$plugin->getID()] =
$plugin;
625 if (empty($dependents)) {
630 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-', $plugin->
getID());
634 'href' =>
"#{$css_id}",
639 throw PluginException::factory([
661 'plugin_id' => $this->
getID(),
662 'plugin_entity' => $this,
666 if ($return ===
false) {
676 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been deactivated");
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());
717 $autoload_file =
'vendor/autoload.php';
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 {
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)) {
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) {
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([
921 if (!isset($entity[
'type']) || !isset($entity[
'subtype'])) {
925 $capabilities =
elgg_extract(
'capabilities', $entity, []);
926 foreach ($capabilities as $capability =>
$value) {
927 _elgg_services()->entity_capabilities->setCapability($entity[
'type'], $entity[
'subtype'], $capability,
$value);
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']);
975 foreach ($spec as
$name => $route_spec) {
976 if (!is_array($route_spec)) {
980 $routes->register(
$name, $route_spec);
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);
1030 if (!is_dir($languages_path)) {
1034 _elgg_services()->translator->registerTranslations($languages_path);
1043 _elgg_services()->autoloadManager->addClasses(
"{$this->getPath()}classes");
1055 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1056 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype'], $entity[
'class']);
1070 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1071 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype']);
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);
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);
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);
1169 foreach ($spec as $view_name =>
$options) {
1183 _elgg_services()->simpleCache->registerCacheableView($view_name);
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);
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');
1305 parent::invalidateCache();
1316 if (isset($this->composer)) {
1320 $this->composer = new \Elgg\Plugin\Composer($this);
1351 $this->
getComposer()->assertActivePluginConflicts();
1353 $this->
getComposer()->assertRequiredPhpExtensions();
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()) {
1381 throw PluginException::factory([
1386 throw PluginException::factory([
1415 if (in_array($this->
getID(), Plugins::BUNDLED_PLUGINS)) {
1452 return (
string) $this->
getComposer()->getConfiguration()->description();
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();
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
registerViews()
Registers the plugin's views.
const ELGG_DISABLE_SYSTEM_LOG
registerEntities()
Registers the plugin's entities.
getID()
Returns the ID (dir name) of this plugin.
elgg_get_release()
Get the current Elgg release.
elgg_get_plugins(string $status= 'active')
Returns an ordered list of plugins.
registerActions()
Registers the plugin's actions provided in the plugin config file.
$params
Saves global plugin settings.
getLanguagesPath()
Returns the plugin's languages directory full path with trailing slash.
registerClasses()
Registers the plugin's classes.
assertCanDeactivate()
Asserts if a plugin can be deactivated.
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
const STATIC_CONFIG_FILENAME
setSetting(string $name, $value)
Set a plugin setting for the plugin.
if(!$user||!$user->canDelete()) $name
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
if(empty($page_owner)||$owner->guid!==$page_owner->guid) $widgets
getAllSettings()
Returns an array of all settings saved for this plugin when the plugin is active. ...
getConflicts()
Returns an array of projectnames with their conflicting version.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
assertValid()
Asserts if a plugin is valid.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
registerPublicServices()
Registers the plugin public services.
meetsDependencies()
Checks if dependencies are met.
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
unsetSetting(string $name)
Removes a plugin setting name and value.
getDescription()
Return the description.
registerRoutes()
Registers the plugin's routes provided in the plugin config file.
setPriority($priority)
Sets the priority of the plugin Returns the new priority or false on error.
activateEntities()
Activates the plugin's entities.
getAllMetadata()
Get all entity metadata.
assertCanActivate()
Asserts if a plugin can activate.
const PUBLIC_SERVICES_FILENAME
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
$plugin_id
Remove all user and plugin settings from the give plugin ID.
elgg_delete_admin_notice(string $id)
Remove an admin notice by ID.
deactivateEntities()
Deactivates the plugin's entities.
canDeactivate()
Checks if this plugin can be deactivated on the current Elgg installation.
elgg_invalidate_caches()
Invalidate all the registered caches.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
getDependencies()
Returns an array of dependencies as configured in the static config.
const ADDITIONAL_TEXT_FILES
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
getDisplayName()
Returns the name from elgg-plugin.php if available, otherwise a nicely formatted ID.
assertStaticConfigValid()
If a static config file is present, is it a serializable array?
setPath(string $path)
Set path.
const ELGG_IGNORE_ACCESS
elgg_call() flags
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
assertDependencies()
Assert plugin dependencies.
isActive()
Is this plugin active?
getRepositoryURL()
Returns the repository url.
registerLanguages()
Registers the plugin's languages.
getCategories()
Returns an array with categories.
elgg_is_active_plugin(string $plugin_id)
Returns if a plugin is active for a current site.
setStatus(bool $active)
Sets the plugin to active or inactive.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
A generic parent class for database exceptions.
normalizePriority($priority)
Normalize and validate new priority.
unsetAllSettings()
Removes all settings for this plugin.
getBugTrackerURL()
Returns the bug tracker page.
if(!$menu instanceof\Elgg\Menu\PreparedMenu) $actions
setMetadata(string $name, mixed $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
getWebsite()
Return the website.
getBootstrap()
Bootstrap object.
isValid()
Returns if the plugin is complete, meaning has all required files and Elgg can read them and they mak...
elgg_get_site_entity()
Get the current site entity.
const PRIORITY_SETTING_NAME
getVersion()
Returns the plugin version.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
registerViewExtensions()
Registers the plugin's view extensions provided in the plugin config file.
activate()
Activates the plugin for the current site.
registerWidgets()
Registers the plugin's widgets provided in the plugin config file.
deactivate()
Deactivates the plugin.
__get($name)
Get an attribute or setting value.
getComposer()
Returns the composer parser.
canReadFile(string $filename)
Checks whether a plugin file with the given name exists.
registerNotifications()
Registers the plugin's notification events.
registerEvents()
Registers the plugin's events provided in the plugin config file.
getPriority()
Gets the plugin's load priority.
__set($name, $value)
Set a value as attribute or setting.
_elgg_services()
Get the global service provider.
loadLanguages()
Loads the plugin's translations.
getMetadata(string $name)
Return the value of a piece of metadata.
elgg_get_plugins_path()
Get the plugin path for this installation, ending with slash.
static fromId(string $plugin_id, string $path=null)
Load a plugin object from its ID Create a new plugin entity if doesn't exist.
getSetting(string $name, $default=null)
Returns a plugin setting when the plugin is active.
registerGroupTools()
Registers the plugin's group tools provided in the plugin config file.
canActivate()
Checks if this plugin can be activated on the current Elgg installation.
includeFile(string $filename)
Includes one of the plugins files.
getPath()
Returns the plugin's full path with trailing slash.
getLicense()
Returns the license.
assertPluginDependencies()
Assert required plugins or plugin position.
autoload()
Register plugin classes and require composer autoloader.
unsetAllEntityAndPluginSettings()
Remove all entity and plugin settings for this plugin.
registerViewOptions()
Registers the plugin's view options provided in the plugin config file.
getStaticConfig(string $key, $default=null)
Get a value from the plugins' static config file.
$guid
Reset an ElggUpgrade.
getAuthors()
Returns an array of authors.