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.',
'ERROR');
375 if (str_starts_with(
$name,
'elgg:internal:')) {
396 $delete = Delete::fromTable(MetadataTable::TABLE_NAME);
441 if (!$this->
getID()) {
442 throw PluginException::factory([
443 'message' =>
elgg_echo(
'ElggPlugin:MissingID', [$this->guid]),
450 if (file_exists($this->
getPath() .
'start.php')) {
451 throw PluginException::factory([
452 'message' =>
elgg_echo(
'ElggPlugin:StartFound', [$this->
getID()]),
464 if (isset($this->activated)) {
531 'plugin_id' => $this->
getID(),
532 'plugin_entity' => $this,
554 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
560 if ($return ===
false) {
566 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been activated");
579 return (array)
elgg_extract(
'dependencies', $plugin_config, []);
595 $this->assertcanDeactivate();
615 foreach ($active_plugins as
$plugin) {
616 $dependencies = $plugin->getDependencies();
617 if (!array_key_exists($this->
getID(), $dependencies)) {
622 $dependents[$plugin->getID()] =
$plugin;
626 if (empty($dependents)) {
631 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-', $plugin->
getID());
635 'href' =>
"#{$css_id}",
640 throw PluginException::factory([
662 'plugin_id' => $this->
getID(),
663 'plugin_entity' => $this,
667 if ($return ===
false) {
677 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been deactivated");
693 if (!is_subclass_of($bootstrap, \
Elgg\PluginBootstrapInterface::class)) {
694 throw PluginException::factory([
695 'message' =>
elgg_echo(
'LogicException:InterfaceNotImplemented', [
697 \
Elgg\PluginBootstrapInterface::class
703 return new $bootstrap($this,
elgg());
706 return new \Elgg\DefaultPluginBootstrap($this,
elgg());
718 $autoload_file =
'vendor/autoload.php';
723 $autoloader = Includer::requireFileOnce(
"{$this->getPath()}{$autoload_file}");
725 if (!$autoloader instanceof \Composer\Autoload\ClassLoader) {
729 $autoloader->unregister();
732 $autoloader->register(
false);
743 public function register():
void {
793 $filepath =
"{$this->getPath()}{$filename}";
797 'ElggPlugin:Exception:CannotIncludeFile',
798 [$filename, $this->
getID(), $this->guid, $this->
getPath()]
801 throw PluginException::factory([
808 $ret = Includer::requireFile($filepath);
809 }
catch (Exception $e) {
811 'ElggPlugin:Exception:IncludeFileThrew',
812 [$filename, $this->
getID(), $this->guid, $this->
getPath()]
815 throw PluginException::factory([
833 return is_file(
"{$this->getPath()}{$filename}");
843 if (!$this->
canReadFile(self::STATIC_CONFIG_FILENAME)) {
849 if (ob_get_clean() !==
'') {
850 throw PluginException::factory([
851 'message' =>
elgg_echo(
'ElggPlugin:activate:ConfigSentOutput'),
859 throw PluginException::factory([
860 'message' =>
elgg_echo(
'ElggPlugin:activate:BadConfigFormat'),
872 $services_path = $this->
getPath() . self::PUBLIC_SERVICES_FILENAME;
873 if (!is_file($services_path)) {
877 $services = Includer::includeFile($services_path);
878 foreach ($services as
$name => $definition) {
899 $views->mergeViewsSpec($spec);
903 if (!
$views->registerViewsFromPath($this->getPath())) {
904 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterViews', [$this->
getID(), $this->guid, $this->
getPath()]);
906 throw PluginException::factory([
922 if (!isset($entity[
'type']) || !isset($entity[
'subtype'])) {
926 $capabilities =
elgg_extract(
'capabilities', $entity, []);
927 foreach ($capabilities as $capability =>
$value) {
928 _elgg_services()->entity_capabilities->setCapability($entity[
'type'], $entity[
'subtype'], $capability,
$value);
944 foreach ($spec as
$action => $action_spec) {
945 if (!is_array($action_spec)) {
954 $handler =
"{$root_path}actions/{$action}.php";
959 unset($action_spec[
'access']);
960 unset($action_spec[
'controller']);
961 unset($action_spec[
'filename']);
976 foreach ($spec as
$name => $route_spec) {
977 if (!is_array($route_spec)) {
981 $routes->register(
$name, $route_spec);
994 foreach ($spec as $widget_id => $widget_definition) {
995 if (!is_array($widget_definition)) {
999 if (!isset($widget_definition[
'id'])) {
1000 $widget_definition[
'id'] = $widget_id;
1005 $widgets->registerType($definition);
1031 if (!is_dir($languages_path)) {
1035 _elgg_services()->translator->registerTranslations($languages_path);
1044 _elgg_services()->autoloadManager->addClasses(
"{$this->getPath()}classes");
1056 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1057 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype'], $entity[
'class']);
1071 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1072 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype']);
1087 foreach ($spec as
$name => $types) {
1088 foreach ($types as
$type => $callbacks) {
1089 foreach ($callbacks as $callback => $event_spec) {
1090 if (!is_array($event_spec)) {
1094 $unregister = (bool)
elgg_extract(
'unregister', $event_spec,
false);
1097 $events->unregisterHandler(
$name,
$type, $callback);
1119 foreach (
$extensions as $extention => $extention_spec) {
1120 if (!is_array($extention_spec)) {
1124 $unextend = (bool)
elgg_extract(
'unextend', $extention_spec,
false);
1127 $views->unextendView($src_view, $extention);
1147 foreach ($spec as $tool_name => $tool_options) {
1148 if (!is_array($tool_options)) {
1152 $unregister = (bool)
elgg_extract(
'unregister', $tool_options,
false);
1155 $tools->unregister($tool_name);
1157 $tools->register($tool_name, $tool_options);
1170 foreach ($spec as $view_name =>
$options) {
1184 _elgg_services()->simpleCache->registerCacheableView($view_name);
1200 if ($callback ===
false) {
1202 }
elseif ($callback ===
true) {
1221 if (array_key_exists(
$name, $this->attributes)) {
1222 return $this->attributes[
$name];
1226 if (in_array(
$name, [
'title',
'description'])) {
1227 return parent::__get(
$name);
1249 if (array_key_exists(
$name, $this->attributes)) {
1251 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
1261 if (in_array(
$name, [
'title',
'description'])) {
1313 parent::invalidateCache();
1324 if (isset($this->composer)) {
1328 $this->composer = new \Elgg\Plugin\Composer($this);
1359 $this->
getComposer()->assertActivePluginConflicts();
1361 $this->
getComposer()->assertRequiredPhpExtensions();
1375 $must_be_active =
elgg_extract(
'must_be_active', $plugin_dep,
true);
1380 if ($must_be_active && (!$dependent_plugin instanceof \
ElggPlugin || !$dependent_plugin->
isActive())) {
1381 throw PluginException::factory([
1387 if ($dependent_plugin instanceof \
ElggPlugin &&
$position && $dependent_plugin->isActive()) {
1389 throw PluginException::factory([
1394 throw PluginException::factory([
1423 if (in_array($this->
getID(), Plugins::BUNDLED_PLUGINS)) {
1460 return (
string) $this->
getComposer()->getConfiguration()->description();
1471 return (
string) $this->
getComposer()->getConfiguration()->support()->source();
1482 return (
string) $this->
getComposer()->getConfiguration()->support()->issues();
1493 return (
string) $this->
getComposer()->getConfiguration()->homepage();
1504 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.
setMetadata(string $name, $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
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.
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.
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.
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.
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
getBugTrackerURL()
Returns the bug tracker page.
if(!$menu instanceof\Elgg\Menu\PreparedMenu) $actions
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.
getAllMetadata()
Get all entity metadata.
_elgg_services()
Get the global service provider.
loadLanguages()
Loads the plugin's translations.
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.
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.
getMetadata(string $name)
Return the value of a piece of metadata.
registerViewOptions()
Registers the plugin's view options provided in the plugin config file.
getStaticConfig(string $key, $default=null)
Get a value from the plugins's static config file.
$guid
Reset an ElggUpgrade.
getAuthors()
Returns an array of authors.