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');
370 if (str_starts_with(
$name,
'elgg:internal:')) {
391 $delete = Delete::fromTable(
'metadata');
436 if (!$this->
getID()) {
437 throw PluginException::factory([
438 'message' =>
elgg_echo(
'ElggPlugin:MissingID', [$this->guid]),
445 if (file_exists($this->
getPath() .
'start.php')) {
446 throw PluginException::factory([
447 'message' =>
elgg_echo(
'ElggPlugin:StartFound', [$this->
getID()]),
459 if (isset($this->activated)) {
526 'plugin_id' => $this->
getID(),
527 'plugin_entity' => $this,
549 elgg_log($ex, \Psr\Log\LogLevel::ERROR);
555 if ($return ===
false) {
561 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been activated");
574 return (array)
elgg_extract(
'dependencies', $plugin_config, []);
590 $this->assertcanDeactivate();
610 foreach ($active_plugins as
$plugin) {
611 $dependencies = $plugin->getDependencies();
612 if (!array_key_exists($this->
getID(), $dependencies)) {
617 $dependents[$plugin->getID()] =
$plugin;
621 if (empty($dependents)) {
626 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-', $plugin->
getID());
630 'href' =>
"#{$css_id}",
635 throw PluginException::factory([
657 'plugin_id' => $this->
getID(),
658 'plugin_entity' => $this,
662 if ($return ===
false) {
672 _elgg_services()->logger->notice(
"Plugin {$this->getID()} has been deactivated");
688 if (!is_subclass_of($bootstrap, \
Elgg\PluginBootstrapInterface::class)) {
689 throw PluginException::factory([
690 'message' =>
elgg_echo(
'LogicException:InterfaceNotImplemented', [
692 \
Elgg\PluginBootstrapInterface::class
698 return new $bootstrap($this,
elgg());
701 return new \Elgg\DefaultPluginBootstrap($this,
elgg());
713 $autoload_file =
'vendor/autoload.php';
718 $autoloader = Includer::requireFileOnce(
"{$this->getPath()}{$autoload_file}");
720 if (!$autoloader instanceof \Composer\Autoload\ClassLoader) {
724 $autoloader->unregister();
727 $autoloader->register(
false);
738 public function register():
void {
789 $filepath =
"{$this->getPath()}{$filename}";
793 'ElggPlugin:Exception:CannotIncludeFile',
794 [$filename, $this->
getID(), $this->guid, $this->
getPath()]
797 throw PluginException::factory([
804 $ret = Includer::requireFile($filepath);
807 'ElggPlugin:Exception:IncludeFileThrew',
808 [$filename, $this->
getID(), $this->guid, $this->
getPath()]
811 throw PluginException::factory([
829 return is_file(
"{$this->getPath()}{$filename}");
839 if (!$this->
canReadFile(self::STATIC_CONFIG_FILENAME)) {
845 if (ob_get_clean() !==
'') {
846 throw PluginException::factory([
847 'message' =>
elgg_echo(
'ElggPlugin:activate:ConfigSentOutput'),
855 throw PluginException::factory([
856 'message' =>
elgg_echo(
'ElggPlugin:activate:BadConfigFormat'),
868 $services_path = $this->
getPath() . self::PUBLIC_SERVICES_FILENAME;
869 if (!is_file($services_path)) {
873 $services = Includer::includeFile($services_path);
874 foreach ($services as
$name => $definition) {
895 $views->mergeViewsSpec($spec);
899 if (!
$views->registerPluginViews($this->getPath())) {
900 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterViews', [$this->
getID(), $this->guid, $this->
getPath()]);
902 throw PluginException::factory([
918 if (!isset($entity[
'type']) || !isset($entity[
'subtype'])) {
922 $capabilities =
elgg_extract(
'capabilities', $entity, []);
923 foreach ($capabilities as $capability =>
$value) {
924 _elgg_services()->entity_capabilities->setCapability($entity[
'type'], $entity[
'subtype'], $capability,
$value);
940 foreach ($spec as
$action => $action_spec) {
941 if (!is_array($action_spec)) {
950 $handler =
"{$root_path}actions/{$action}.php";
955 unset($action_spec[
'access']);
956 unset($action_spec[
'controller']);
957 unset($action_spec[
'filename']);
972 foreach ($spec as
$name => $route_spec) {
973 if (!is_array($route_spec)) {
977 $routes->register(
$name, $route_spec);
990 foreach ($spec as $widget_id => $widget_definition) {
991 if (!is_array($widget_definition)) {
995 if (!isset($widget_definition[
'id'])) {
996 $widget_definition[
'id'] = $widget_id;
1001 $widgets->registerType($definition);
1027 if (!is_dir($languages_path)) {
1031 _elgg_services()->translator->registerTranslations($languages_path);
1040 _elgg_services()->autoloadManager->addClasses(
"{$this->getPath()}classes");
1052 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1053 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype'], $entity[
'class']);
1067 if (isset($entity[
'type'], $entity[
'subtype'], $entity[
'class'])) {
1068 _elgg_services()->entityTable->setEntityClass($entity[
'type'], $entity[
'subtype']);
1085 if (!empty($spec)) {
1086 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');
1089 foreach ($spec as
$name => $types) {
1090 foreach ($types as
$type => $callbacks) {
1091 foreach ($callbacks as $callback => $hook_spec) {
1092 if (!is_array($hook_spec)) {
1096 $unregister = (bool)
elgg_extract(
'unregister', $hook_spec,
false);
1099 $events->unregisterHandler(
$name,
$type, $callback);
1120 foreach ($spec as
$name => $types) {
1121 foreach ($types as
$type => $callbacks) {
1122 foreach ($callbacks as $callback => $event_spec) {
1123 if (!is_array($event_spec)) {
1127 $unregister = (bool)
elgg_extract(
'unregister', $event_spec,
false);
1130 $events->unregisterHandler(
$name,
$type, $callback);
1152 foreach (
$extensions as $extention => $extention_spec) {
1153 if (!is_array($extention_spec)) {
1157 $unextend = (bool)
elgg_extract(
'unextend', $extention_spec,
false);
1160 $views->unextendView($src_view, $extention);
1180 foreach ($spec as $tool_name => $tool_options) {
1181 if (!is_array($tool_options)) {
1185 $unregister = (bool)
elgg_extract(
'unregister', $tool_options,
false);
1188 $tools->unregister($tool_name);
1190 $tools->register($tool_name, $tool_options);
1203 foreach ($spec as $view_name =>
$options) {
1233 if ($callback ===
false) {
1235 }
elseif ($callback ===
true) {
1254 if (array_key_exists(
$name, $this->attributes)) {
1255 return $this->attributes[
$name];
1259 if (in_array(
$name, [
'title',
'description'])) {
1260 return parent::__get(
$name);
1282 if (array_key_exists(
$name, $this->attributes)) {
1284 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
1294 if (in_array(
$name, [
'title',
'description'])) {
1345 parent::cache($persist);
1356 parent::invalidateCache();
1367 if (isset($this->composer)) {
1371 $this->composer = new \Elgg\Plugin\Composer($this);
1402 $this->
getComposer()->assertActivePluginConflicts();
1404 $this->
getComposer()->assertRequiredPhpExtensions();
1418 $must_be_active =
elgg_extract(
'must_be_active', $plugin_dep,
true);
1423 if ($must_be_active && (!$dependent_plugin instanceof \
ElggPlugin || !$dependent_plugin->isActive())) {
1424 throw PluginException::factory([
1430 if ($dependent_plugin instanceof \
ElggPlugin &&
$position && $dependent_plugin->isActive()) {
1432 throw PluginException::factory([
1437 throw PluginException::factory([
1466 if (in_array($this->
getID(), Plugins::BUNDLED_PLUGINS)) {
1503 return (
string) $this->
getComposer()->getConfiguration()->description();
1514 return (
string) $this->
getComposer()->getConfiguration()->support()->source();
1525 return (
string) $this->
getComposer()->getConfiguration()->support()->issues();
1536 return (
string) $this->
getComposer()->getConfiguration()->homepage();
1547 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.
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.
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.
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.
if(empty($page_owner)||$owner->guid!=$page_owner->guid) $widgets
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.