Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
plugins.php
Go to the documentation of this file.
1 <?php
8 
9 
13 define('ELGG_PLUGIN_INCLUDE_START', 1);
14 
18 define('ELGG_PLUGIN_REGISTER_VIEWS', 2);
19 
23 define('ELGG_PLUGIN_REGISTER_LANGUAGES', 4);
24 
28 define('ELGG_PLUGIN_REGISTER_CLASSES', 8);
29 
36 //define('ELGG_PLUGIN_SETTING_PREFIX', 'plugin:setting:');
37 
41 define('ELGG_PLUGIN_USER_SETTING_PREFIX', 'plugin:user_setting:');
42 
48 define('ELGG_PLUGIN_INTERNAL_PREFIX', 'elgg:internal:');
49 
61  return _elgg_services()->plugins->generateEntities();
62 }
63 
72  return _elgg_services()->plugins->cache($plugin);
73 }
74 
83  return _elgg_services()->plugins->get($plugin_id);
84 }
85 
98  return _elgg_services()->plugins->exists($id);
99 }
100 
109  return _elgg_services()->plugins->getMaxPriority();
110 }
111 
120 function elgg_is_active_plugin($plugin_id, $site_guid = null) {
121  return _elgg_services()->plugins->isActive($plugin_id, $site_guid);
122 }
123 
132 function elgg_get_plugins($status = 'active', $site_guid = null) {
133  return _elgg_services()->plugins->find($status, $site_guid);
134 }
135 
152  return _elgg_services()->plugins->namespacePrivateSetting($type, $name, $id);
153 }
154 
163  return _elgg_services()->plugins->invalidateProvidesCache();
164 }
165 
182 function _elgg_check_plugins_provides($type, $name, $version = null, $comparison = 'ge') {
183  return _elgg_services()->plugins->checkProvides($type, $name, $version, $comparison);
184 }
185 
202  return _elgg_services()->plugins->getDependencyStrings($dep);
203 }
204 
216 function elgg_get_all_plugin_user_settings($user_guid = 0, $plugin_id = null, $return_obj = false) {
217  return _elgg_services()->plugins->getAllUserSettings($user_guid, $plugin_id, $return_obj);
218 }
219 
233  return _elgg_services()->plugins->setUserSetting($name, $value, $user_guid, $plugin_id);
234 }
235 
248  return _elgg_services()->plugins->unsetUserSetting($name, $user_guid, $plugin_id);
249 }
250 
264  return _elgg_services()->plugins->getUserSetting($name, $user_guid, $plugin_id, $default);
265 }
266 
279  return _elgg_services()->plugins->setSetting($name, $value, $plugin_id);
280 }
281 
294  return _elgg_services()->plugins->getSetting($name, $plugin_id, $default);
295 }
296 
308  return _elgg_services()->plugins->unsetSetting($name, $plugin_id);
309 }
310 
321  return _elgg_services()->plugins->unsetAllSettings($plugin_id);
322 }
323 
353  return _elgg_services()->plugins->getEntitiesFromUserSettings($options);
354 }
355 
368  global $CONFIG;
369  $value[] = $CONFIG->path . 'engine/tests/ElggCorePluginsAPITest.php';
370  return $value;
371 }
372 
384  $plugin_id = $params['plugin_entity']->getManifest()->getPluginID();
385  $plugin_name = $params['plugin_entity']->getManifest()->getName();
386 
387  $active_plugins = elgg_get_plugins();
388 
389  $dependents = array();
390  foreach ($active_plugins as $plugin) {
391  $manifest = $plugin->getManifest();
392  $requires = $manifest->getRequires();
393 
394  foreach ($requires as $required) {
395  if ($required['type'] == 'plugin' && $required['name'] == $plugin_id) {
396  // there are active dependents
397  $dependents[$manifest->getPluginID()] = $plugin;
398  }
399  }
400  }
401 
402  if ($dependents) {
403  $list = '<ul>';
404  // construct error message and prevent disabling
405  foreach ($dependents as $dependent) {
406  $list .= '<li>' . $dependent->getManifest()->getName() . '</li>';
407  }
408  $list .= '</ul>';
409 
410  register_error(elgg_echo('ElggPlugin:Dependencies:ActiveDependent', array($plugin_name, $list)));
411 
412  return false;
413  }
414 }
415 
422 function _elgg_plugins_init() {
423 
424  if (elgg_is_admin_logged_in()) {
425  elgg_register_ajax_view('object/plugin/full');
426  elgg_register_ajax_view('object/plugin/details');
427  }
428 
429  elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_plugins_test');
430 
431  // note - plugins are booted by the time this handler is registered
432  // deactivation due to error may have already occurred
433  elgg_register_event_handler('deactivate', 'plugin', '_plugins_deactivate_dependency_check');
434 
438  $svc = _elgg_services()->plugins;
439  elgg_register_event_handler('deactivate', 'plugin', array($svc, 'invalidateIsActiveCache'));
440  elgg_register_event_handler('activate', 'plugin', array($svc, 'invalidateIsActiveCache'));
441 
442  elgg_register_action("plugins/settings/save", '', 'admin');
443  elgg_register_action("plugins/usersettings/save");
444 
445  elgg_register_action('admin/plugins/activate', '', 'admin');
446  elgg_register_action('admin/plugins/deactivate', '', 'admin');
447  elgg_register_action('admin/plugins/activate_all', '', 'admin');
448  elgg_register_action('admin/plugins/deactivate_all', '', 'admin');
449 
450  elgg_register_action('admin/plugins/set_priority', '', 'admin');
451 }
452 
453 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
454  $events->registerHandler('init', 'system', '_elgg_plugins_init');
455 };
A simple directory abstraction.
Definition: Directory.php:13
elgg_get_entities_from_plugin_user_settings(array $options=array())
Returns entities based upon plugin user settings.
Definition: plugins.php:352
$plugin
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:60
elgg_set_plugin_setting($name, $value, $plugin_id=null)
Set a setting for a plugin.
Definition: plugins.php:278
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
_elgg_check_plugins_provides($type, $name, $version=null, $comparison= 'ge')
Checks if a plugin is currently providing $type and $name, and optionally checking a version...
Definition: plugins.php:182
elgg_get_all_plugin_user_settings($user_guid=0, $plugin_id=null, $return_obj=false)
Returns an array of all plugin user settings for a user.
Definition: plugins.php:216
$value
Definition: longtext.php:26
$default
Definition: checkbox.php:35
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:715
register_error($error)
Display an error on next page load.
Definition: elgglib.php:452
$params
Definition: login.php:72
_elgg_namespace_plugin_private_setting($type, $name, $id=null)
Namespaces a string to be used as a private setting name for a plugin.
Definition: plugins.php:151
_elgg_cache_plugin_by_id(\ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
Definition: plugins.php:71
elgg_unset_all_plugin_settings($plugin_id=null)
Unsets all plugin settings for a plugin.
Definition: plugins.php:320
$options
Definition: plugins.php:88
_plugins_deactivate_dependency_check($event, $type, $params)
Checks on deactivate plugin event if disabling it won't create unmet dependencies and blocks disable ...
Definition: plugins.php:383
_elgg_get_plugin_dependency_strings($dep)
Returns an array of parsed strings for a dependency in the format: array( 'type' => requires...
Definition: plugins.php:201
$plugin_id
Definition: save.php:16
global $CONFIG
elgg_set_plugin_user_setting($name, $value, $user_guid=0, $plugin_id=null)
Set a user specific setting for a plugin.
Definition: plugins.php:232
_elgg_get_max_plugin_priority()
Returns the highest priority of the plugins.
Definition: plugins.php:108
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:220
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
elgg_get_plugin_user_setting($name, $user_guid=0, $plugin_id=null, $default=null)
Get a user specific setting for a plugin.
Definition: plugins.php:263
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Definition: elgglib.php:538
elgg_plugin_exists($id)
Returns if a plugin exists in the system.
Definition: plugins.php:97
_elgg_plugins_init()
Initialize the plugin system.
Definition: plugins.php:422
elgg_unset_plugin_user_setting($name, $user_guid=0, $plugin_id=null)
Unsets a user-specific plugin setting.
Definition: plugins.php:247
_elgg_plugins_test($hook, $type, $value, $params)
Runs unit tests for plugin API.
Definition: plugins.php:367
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: plugins.php:132
elgg_unset_plugin_setting($name, $plugin_id=null)
Unsets a plugin setting.
Definition: plugins.php:307
elgg_get_plugin_setting($name, $plugin_id=null, $default=null)
Get setting for a plugin.
Definition: plugins.php:293
$required
Definition: label.php:12
elgg_is_active_plugin($plugin_id, $site_guid=null)
Returns if a plugin is active for a current site.
Definition: plugins.php:120
_elgg_invalidate_plugins_provides_cache()
Deletes all cached data on plugins being provided.
Definition: plugins.php:162
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
Definition: actions.php:85
$user_guid
Avatar remove action.
Definition: remove.php:6
if(!$collection_name) $id
Definition: add.php:17
$version
Definition: version.php:14
_elgg_generate_plugin_entities()
Discovers plugins in the plugins_path setting and creates entities for them if they don't exist...
Definition: plugins.php:60
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:82
if(!($plugin instanceof ElggPlugin)) $plugin_name
Definition: save.php:24
if(!$display_name) $type
Definition: delete.php:27