66 parent::initializeAttributes();
68 $this->attributes[
'subtype'] =
'plugin';
82 if (empty($plugin_id)) {
114 $this->attributes[
'owner_guid'] =
$site->guid;
115 $this->attributes[
'container_guid'] =
$site->guid;
130 return parent::save();
166 $this->path = Paths::sanitize($path,
true);
175 if (isset($this->path)) {
190 return $this->
getPath() .
'languages/';
205 if ($this->static_config === null) {
206 $this->static_config = [];
209 $this->static_config = $this->
includeFile(self::STATIC_CONFIG_FILENAME);
211 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
262 $old_priority = $old_priority ?: 1;
336 'plugin_id' => $this->
getID(),
343 elgg_log(
'Plugin settings cannot store arrays.',
'ERROR');
374 if (str_starts_with(
$name,
'elgg:internal:')) {
395 $delete = Delete::fromTable(
'metadata');
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 {
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->registerPluginViews($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']);
1089 if (!empty($spec)) {
1090 elgg_deprecated_notice(
"The plugin {$this->getID()} still has hooks definitions in the elgg-plugin.php. This should be moved to the events configuration.",
'5.0');
1093 foreach ($spec as
$name => $types) {
1094 foreach ($types as
$type => $callbacks) {
1095 foreach ($callbacks as $callback => $hook_spec) {
1096 if (!is_array($hook_spec)) {
1100 $unregister = (bool)
elgg_extract(
'unregister', $hook_spec,
false);
1103 $events->unregisterHandler(
$name,
$type, $callback);
1124 foreach ($spec as
$name => $types) {
1125 foreach ($types as
$type => $callbacks) {
1126 foreach ($callbacks as $callback => $event_spec) {
1127 if (!is_array($event_spec)) {
1131 $unregister = (bool)
elgg_extract(
'unregister', $event_spec,
false);
1134 $events->unregisterHandler(
$name,
$type, $callback);
1156 foreach (
$extensions as $extention => $extention_spec) {
1157 if (!is_array($extention_spec)) {
1161 $unextend = (bool)
elgg_extract(
'unextend', $extention_spec,
false);
1164 $views->unextendView($src_view, $extention);
1184 foreach ($spec as $tool_name => $tool_options) {
1185 if (!is_array($tool_options)) {
1189 $unregister = (bool)
elgg_extract(
'unregister', $tool_options,
false);
1192 $tools->unregister($tool_name);
1194 $tools->register($tool_name, $tool_options);
1207 foreach ($spec as $view_name =>
$options) {
1237 if ($callback ===
false) {
1239 }
elseif ($callback ===
true) {
1258 if (array_key_exists(
$name, $this->attributes)) {
1259 return $this->attributes[
$name];
1263 if (in_array(
$name, [
'title',
'description'])) {
1264 return parent::__get(
$name);
1286 if (array_key_exists(
$name, $this->attributes)) {
1288 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
1298 if (in_array(
$name, [
'title',
'description'])) {
1349 parent::cache($persist);
1360 parent::invalidateCache();
1371 if (isset($this->composer)) {
1375 $this->composer = new \Elgg\Plugin\Composer($this);
1406 $this->
getComposer()->assertActivePluginConflicts();
1408 $this->
getComposer()->assertRequiredPhpExtensions();
1422 $must_be_active =
elgg_extract(
'must_be_active', $plugin_dep,
true);
1427 if ($must_be_active && (!$dependent_plugin instanceof \
ElggPlugin || !$dependent_plugin->
isActive())) {
1428 throw PluginException::factory([
1434 if ($dependent_plugin instanceof \
ElggPlugin &&
$position && $dependent_plugin->isActive()) {
1436 throw PluginException::factory([
1441 throw PluginException::factory([
1470 if (in_array($this->
getID(), Plugins::BUNDLED_PLUGINS)) {
1507 return (
string) $this->
getComposer()->getConfiguration()->description();
1518 return (
string) $this->
getComposer()->getConfiguration()->support()->source();
1529 return (
string) $this->
getComposer()->getConfiguration()->support()->issues();
1540 return (
string) $this->
getComposer()->getConfiguration()->homepage();
1551 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.
cache(bool $persist=true)
{}
$params
Saves global plugin settings.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
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
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
registerHooks()
Registers the plugin's hooks provided in the plugin config file.
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.