Elgg  Version 5.1
SystemEventHandlers.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Application;
4 
10 
17 
23  public static function init() {
24 
25  // searchable
26  elgg_entity_enable_capability('object', 'comment', 'searchable');
27  elgg_entity_enable_capability('user', 'user', 'searchable');
28 
29  // likable
30  elgg_entity_enable_capability('object', 'comment', 'likable');
31 
32  elgg_entity_enable_capability('object', 'comment', 'commentable');
33 
35  if ((bool) elgg_get_config('enable_delayed_email')) {
36  elgg_register_notification_method('delayed_email');
37  }
38 
39  elgg_register_notification_event('object', 'comment', ['create'], CreateCommentEventHandler::class);
40  elgg_register_notification_event('object', 'comment', ['mentions'], MentionsEventHandler::class);
41  elgg_register_notification_event('user', 'user', ['make_admin'], MakeAdminUserEventHandler::class);
42  elgg_register_notification_event('user', 'user', ['remove_admin'], RemoveAdminUserEventHandler::class);
43  elgg_register_notification_event('user', 'user', ['unban'], UnbanUserEventHandler::class);
44 
45  // if mb functions are available, set internal encoding to UTF8
46  if (is_callable('mb_internal_encoding')) {
47  mb_internal_encoding('UTF-8');
48  }
49 
50  elgg_register_ajax_view('admin/users/listing/details');
51  elgg_register_ajax_view('core/ajax/edit_comment');
52  elgg_register_ajax_view('forms/admin/user/change_email');
53  elgg_register_ajax_view('forms/comment/save');
54  elgg_register_ajax_view('navigation/menu/user_hover/contents');
55  elgg_register_ajax_view('notifications/subscriptions/details');
56  elgg_register_ajax_view('object/plugin/details');
57  elgg_register_ajax_view('object/widget/edit');
58  elgg_register_ajax_view('page/elements/comments');
59  elgg_register_ajax_view('river/elements/responses');
60 
61  elgg_extend_view('admin.css', 'lightbox/elgg-colorbox-theme/colorbox.css');
62  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/online');
63  elgg_extend_view('core/settings/statistics', 'core/settings/statistics/numentities');
64  elgg_extend_view('forms/usersettings/save', 'core/settings/account/username', 100);
65  elgg_extend_view('forms/usersettings/save', 'core/settings/account/name', 100);
66  elgg_extend_view('forms/usersettings/save', 'core/settings/account/password', 100);
67  elgg_extend_view('forms/usersettings/save', 'core/settings/account/email', 100);
68  elgg_extend_view('forms/usersettings/save', 'core/settings/account/language', 100);
69  elgg_extend_view('forms/usersettings/save', 'core/settings/account/default_access', 100);
70 
71  elgg_register_simplecache_view('admin.css');
72  elgg_register_simplecache_view('resources/manifest.json');
73 
74  elgg_register_external_file('css', 'elgg.admin', elgg_get_simplecache_url('admin.css'));
75  elgg_register_external_file('css', 'admin/users/unvalidated', elgg_get_simplecache_url('admin/users/unvalidated.css'));
76  elgg_register_external_file('css', 'maintenance', elgg_get_simplecache_url('maintenance.css'));
77 
78  elgg_register_event_handler('registeruser:validate:password', 'all', [_elgg_services()->passwordGenerator, 'registerUserPasswordValidation']);
79  elgg_register_event_handler('view_vars', 'input/password', [_elgg_services()->passwordGenerator, 'addInputRequirements']);
80 
81  $widgets = ['online_users', 'new_users', 'content_stats', 'banned_users', 'admin_welcome', 'cron_status', 'elgg_blog'];
82  foreach ($widgets as $widget) {
84  'id' => $widget,
85  'name' => elgg_echo("admin:widget:{$widget}"),
86  'description' => elgg_echo("admin:widget:{$widget}:help"),
87  'context' => ['admin'],
88  ]);
89  }
90  }
91 
97  public static function initEarly() {
98  elgg_register_pam_handler(\Elgg\PAM\User\Password::class);
99 
100  // @todo registering an alias helps in the transition from Elgg 4 to Elgg 5. This can be removed in Elgg 6
101  if (!class_exists('Elgg\Hook')) {
102  class_alias(\Elgg\Event::class, 'Elgg\Hook');
103  }
104  }
105 
111  public static function initLate() {
112  self::initWalledGarden();
113  }
114 
120  public static function ready() {
121  _elgg_services()->systemCache->init();
122  }
123 
129  protected static function initWalledGarden() {
130  if (!_elgg_services()->config->walled_garden) {
131  return;
132  }
133 
134  elgg_register_external_file('css', 'elgg.walled_garden', elgg_get_simplecache_url('walled_garden.css'));
135 
136  if (_elgg_services()->config->default_access == ACCESS_PUBLIC) {
137  elgg_set_config('default_access', ACCESS_LOGGED_IN);
138  }
139 
140  if (!elgg_is_logged_in()) {
141  // override the front page
142  elgg_register_route('index', [
143  'path' => '/',
144  'resource' => 'walled_garden',
145  ]);
146  }
147  }
148 }
elgg_register_event_handler(string $event, string $type, callable|string $callback, int $priority=500)
Helper functions for event handling.
Definition: events.php:48
static initEarly()
Initializes the system (contains actions that require to be executed early [priority: 0]) ...
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:43
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_register_route(string $name, array $params=[])
Elgg page handler functions.
Definition: pagehandler.php:27
if(empty($page_owner)||$owner->guid!==$page_owner->guid) $widgets
Definition: widgets.php:40
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_register_ajax_view(string $view)
Register a view to be available for ajax calls.
Definition: views.php:107
elgg_register_external_file(string $type, string $name, string $url, string $location= '')
Core registration function for external files.
elgg_entity_enable_capability(string $type, string $subtype, string $capability)
Enables the capability for a specified type/subtype.
Definition: entities.php:712
static ready()
Actions performed when the system is ready.
elgg_set_config(string $name, $value)
Set an Elgg configuration value.
const ACCESS_LOGGED_IN
Definition: constants.php:11
elgg_register_widget_type(array $options)
Register a widget type.
Definition: widgets.php:64
static initLate()
Initializes the system (contains actions that require to be executed after regular priority [priority...
elgg_register_notification_event(string $object_type, string $object_subtype, array $actions=[], string $handler=NotificationEventHandler::class)
Register a notification event.
static init()
Initializes the system.
if($guid===false) $widget
Definition: add.php:31
static initWalledGarden()
Initializes the walled garden logic.
elgg_register_notification_method(string $name)
Register a delivery method for notifications.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
elgg_register_simplecache_view(string $view_name)
Registers a view to simple cache.
Definition: cache.php:111
const ACCESS_PUBLIC
Definition: constants.php:12
elgg_get_simplecache_url(string $view, string $subview= '')
Get the URL for the cached view.
Definition: cache.php:139
elgg_extend_view(string $view, string $view_extension, int $priority=501)
Extends a view with another view.
Definition: views.php:204
elgg_register_pam_handler($handler, string $importance= 'sufficient', string $policy= 'user')
Elgg Simple PAM library Contains functions for managing authentication.
Definition: pam.php:31
Contains the system event handlers.