18 use Elgg\Traits\Loggable;
45 'friends_collections',
63 'uservalidationbyemail',
100 $this->context =
$request->getContextStack();
109 return $this->config->plugins_path;
120 public function setBootPlugins(?array $plugins =
null,
bool $order_plugins =
true): void {
121 $this->cache->clear();
122 if (!is_array($plugins)) {
123 unset($this->boot_plugins);
128 $this->boot_plugins = [];
130 if ($order_plugins) {
131 $plugins = $this->orderPluginsByPriority($plugins);
134 foreach ($plugins as
$plugin) {
166 $dir = $this->getPath();
173 $handle = opendir($dir);
174 if ($handle ===
false) {
179 while (($plugin_dir = readdir($handle)) !==
false) {
181 if (!str_starts_with($plugin_dir,
'.') && is_dir($dir . $plugin_dir)) {
182 $plugin_dirs[] = $plugin_dir;
203 $mod_dir = $this->getPath();
205 $known_plugins = $this->find(
'all');
212 $latest_priority = 0;
213 foreach ($known_plugins as $i =>
$plugin) {
218 unset($known_plugins[$i]);
222 $id_map[
$plugin->getID()] = $i;
229 $current_priority =
$plugin->getPriority();
230 if (($current_priority - $latest_priority) > 1) {
234 $latest_priority = $current_priority;
237 $physical_plugins = $this->getDirsInDir($mod_dir);
238 if (empty($physical_plugins)) {
261 unset($known_plugins[
$index]);
272 foreach ($known_plugins as
$plugin) {
294 $this->reindexPriorities();
320 'subtype' =>
'plugin',
321 'metadata_name_value_pairs' => [
329 if (empty($plugins)) {
347 $qb->select(
'MAX(CAST(md.value AS unsigned)) as max')
348 ->join(
$qb->getTableAlias(), MetadataTable::TABLE_NAME,
'md',
"{$qb->getTableAlias()}.guid = md.entity_guid")
358 return max(1, (
int)
$data->max);
369 if (isset($this->boot_plugins) && is_array($this->boot_plugins)) {
370 return array_key_exists(
$plugin_id, $this->boot_plugins);
378 return $plugin->hasRelationship(1,
'active_plugin');
391 $plugins_path = $this->getPath();
394 if (file_exists(
"{$plugins_path}/disabled")) {
395 if ($this->session_manager->isAdminLoggedIn() && $this->context->contains(
'admin')) {
396 $this->system_messages->addSuccessMessage($this->translator->translate(
'plugins:disabled'));
402 $this->events->registerHandler(
'plugins_load',
'system', [$this,
'register']);
403 $this->events->registerHandler(
'plugins_boot:before',
'system', [$this,
'boot']);
404 $this->events->registerHandler(
'init',
'system', [$this,
'init']);
405 $this->events->registerHandler(
'ready',
'system', [$this,
'ready']);
406 $this->events->registerHandler(
'upgrade',
'system', [$this,
'upgrade']);
407 $this->events->registerHandler(
'shutdown',
'system', [$this,
'shutdown']);
418 public function register():
void {
419 $plugins = $this->find(
'active');
420 if (empty($plugins)) {
426 foreach ($plugins as
$plugin) {
429 }
catch (\Exception $ex) {
443 $plugins = $this->find(
'active');
444 if (empty($plugins)) {
450 foreach ($plugins as
$plugin) {
453 }
catch (\Exception $ex) {
467 $plugins = $this->find(
'active');
468 if (empty($plugins)) {
474 foreach ($plugins as
$plugin) {
477 }
catch (\Exception $ex) {
491 $plugins = $this->find(
'active');
492 if (empty($plugins)) {
498 foreach ($plugins as
$plugin) {
500 $plugin->getBootstrap()->ready();
501 }
catch (\Exception $ex) {
515 $plugins = $this->find(
'active');
516 if (empty($plugins)) {
522 foreach ($plugins as
$plugin) {
524 $plugin->getBootstrap()->upgrade();
525 }
catch (\Exception $ex) {
539 $plugins = $this->find(
'active');
540 if (empty($plugins)) {
546 foreach ($plugins as
$plugin) {
548 $plugin->getBootstrap()->shutdown();
549 }
catch (\Exception $ex) {
566 $this->getLogger()->log(LogLevel::ERROR, $previous, [
572 if (!$this->config->auto_disable_plugins) {
580 $msg = $this->translator->translate(
581 'PluginException:CannotStart',
586 }
catch (PluginException $ex) {
587 $this->getLogger()->log(LogLevel::ERROR, $ex, [
602 public function find(
string $status =
'active'): array {
603 if (!$this->db || !$this->config->installed) {
607 if ($status ===
'active' && isset($this->boot_plugins)) {
609 return array_values($this->boot_plugins);
612 $volatile_data_name =
null;
618 'subtype' =>
'plugin',
625 $options[
'relationship'] =
'active_plugin';
626 $options[
'relationship_guid'] = $site_guid;
627 $options[
'inverse_relationship'] =
true;
630 $volatile_data_name =
'select:value';
631 $options[
'select'] = [MetadataTable::DEFAULT_JOIN_ALIAS .
'.value'];
639 $subquery =
$qb->subquery(
'entity_relationships',
'active_er');
640 $subquery->select(
'active_er.guid_one')
644 return $qb->compare(
"{$main_alias}.guid",
'NOT IN', $subquery->getSQL());
657 $result = $this->orderPluginsByPriority($plugins, $volatile_data_name);
659 if ($status ===
'active' && !isset($this->boot_plugins)) {
661 $this->setBootPlugins(
$result,
false);
664 foreach ($plugins as
$plugin) {
682 $sorted_plugins = [];
684 foreach ($plugins as
$plugin) {
686 if (!empty($volatile_data_name)) {
700 return array_values(array_replace($priorities, $sorted_plugins));
718 $plugins = $this->find(
'all');
719 if (empty($plugins)) {
725 $order = array_values($order);
728 $missing_plugins = [];
731 foreach ($plugins as
$plugin) {
734 if (
$plugin->getPriority() !==
null) {
757 if (empty($missing_plugins)) {
761 foreach ($missing_plugins as
$plugin) {
777 return $this->setPriorities([]);
789 $old_priority =
$plugin->getPriority() ?: 1;
801 $qb = Update::table(MetadataTable::TABLE_NAME);
806 $qb->set(
'value',
'CAST(value AS UNSIGNED) - 1');
809 $qb->set(
'value',
'CAST(value AS UNSIGNED) + 1');
813 if (!$this->db->updateData(
$qb)) {
if(! $user||! $user->canDelete()) $name
$id
Generic annotation delete action.
$plugin_id
Remove all user and plugin settings from the give plugin ID.
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'=>[],]
if(! $entity instanceof \ElggUser) $data
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
const PRIORITY_SETTING_NAME
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.
Manages a global stack of strings for sharing information about the current execution context.
Entity table database service.
Persistent, installation-wide key-value storage.
disable(\ElggPlugin $plugin, \Exception $previous)
Disable a plugin upon exception.
find(string $status='active')
Returns an ordered list of plugins.
reindexPriorities()
Reindexes all plugin priorities starting at 1.
shutdown()
Run plugin shutdown handlers.
ready()
Run plugin ready handlers.
setPriorities(array $order)
Reorder plugins to an order specified by the array.
getMaxPriority()
Returns the highest priority of the plugins.
build()
Registers lifecycle events for all active plugins sorted by their priority.
getDirsInDir(?string $dir=null)
Returns a list of plugin directory names from a base directory.
setPriority(\ElggPlugin $plugin, int $priority)
Set plugin priority and adjust the priorities of other plugins.
init()
Initialize plugins.
__construct(protected PluginsCache $cache, protected Database $db, protected SessionManagerService $session_manager, protected EventsService $events, protected Translator $translator, protected ViewsService $views, protected Config $config, protected SystemMessagesService $system_messages, protected Invoker $invoker, Request $request)
Constructor.
generateEntities()
Discovers plugins in the plugins_path setting and creates \ElggPlugin entities for them if they don't...
orderPluginsByPriority(array $plugins=[], ?string $volatile_data_name=null)
Sorts plugins by priority.
isActive(string $plugin_id)
Returns if a plugin is active for a current site.
setBootPlugins(?array $plugins=null, bool $order_plugins=true)
Set the list of active plugins according to the boot data cache.
getPath()
Get the plugin path for this installation, ending with slash.
upgrade()
Run plugin upgrade handlers.
Database abstraction query builder.
Query builder for fetching data from the database.
Find Elgg and project paths.
const ELGG_IGNORE_ACCESS
elgg_call() flags
const ELGG_SHOW_DISABLED_ENTITIES
const ELGG_VALUE_INTEGER
Value types.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
$config
Advanced site settings, debugging section.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
elgg_add_admin_notice(string $id, string $message)
Write a persistent message to the admin view.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
endTimer(array $keys)
Ends the timer (when enabled)
trait Profilable
Make an object accept a timer.
beginTimer(array $keys)
Start the timer (when enabled)
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.