Elgg  Version 1.11
plugins.php
Go to the documentation of this file.
1 <?php
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 
50 
61 function _elgg_get_plugin_dirs_in_dir($dir = null) {
62  return _elgg_services()->plugins->getDirsInDir($dir);
63 }
64 
76  return _elgg_services()->plugins->generateEntities();
77 }
78 
87  return _elgg_services()->plugins->cache($plugin);
88 }
89 
98  return _elgg_services()->plugins->get($plugin_id);
99 }
100 
113  return _elgg_services()->plugins->exists($id);
114 }
115 
124  return _elgg_services()->plugins->getMaxPriority();
125 }
126 
135 function elgg_is_active_plugin($plugin_id, $site_guid = null) {
136  return _elgg_services()->plugins->isActive($plugin_id, $site_guid);
137 }
138 
150 function _elgg_load_plugins() {
151  return _elgg_services()->plugins->load();
152 }
153 
162 function elgg_get_plugins($status = 'active', $site_guid = null) {
163  return _elgg_services()->plugins->find($status, $site_guid);
164 }
165 
179 function _elgg_set_plugin_priorities(array $order) {
180  return _elgg_services()->plugins->setPriorities($order);
181 }
182 
192  return _elgg_services()->plugins->reindexPriorities();
193 }
194 
211  return _elgg_services()->plugins->namespacePrivateSetting($type, $name, $id);
212 }
213 
233 function _elgg_get_plugins_provides($type = null, $name = null) {
234  return _elgg_services()->plugins->getProvides($type, $name);
235 }
236 
245  return _elgg_services()->plugins->invalidateProvidesCache();
246 }
247 
264 function _elgg_check_plugins_provides($type, $name, $version = null, $comparison = 'ge') {
265  return _elgg_services()->plugins->checkProvides($type, $name, $version, $comparison);
266 }
267 
284  return _elgg_services()->plugins->getDependencyStrings($dep);
285 }
286 
298 function elgg_get_all_plugin_user_settings($user_guid = 0, $plugin_id = null, $return_obj = false) {
299  return _elgg_services()->plugins->getAllUserSettings($user_guid, $plugin_id, $return_obj);
300 }
301 
315  return _elgg_services()->plugins->setUserSetting($name, $value, $user_guid, $plugin_id);
316 }
317 
330  return _elgg_services()->plugins->unsetUserSetting($name, $user_guid, $plugin_id);
331 }
332 
346  return _elgg_services()->plugins->getUserSetting($name, $user_guid, $plugin_id, $default);
347 }
348 
361  return _elgg_services()->plugins->setSetting($name, $value, $plugin_id);
362 }
363 
376  return _elgg_services()->plugins->getSetting($name, $plugin_id, $default);
377 }
378 
390  return _elgg_services()->plugins->unsetSetting($name, $plugin_id);
391 }
392 
403  return _elgg_services()->plugins->unsetAllSettings($plugin_id);
404 }
405 
435  return _elgg_services()->plugins->getEntitiesFromUserSettings($options);
436 }
437 
450  global $CONFIG;
451  $value[] = $CONFIG->path . 'engine/tests/ElggCorePluginsAPITest.php';
452  return $value;
453 }
454 
466  $plugin_id = $params['plugin_entity']->getManifest()->getPluginID();
467  $plugin_name = $params['plugin_entity']->getManifest()->getName();
468 
469  $active_plugins = elgg_get_plugins();
470 
471  $dependents = array();
472  foreach ($active_plugins as $plugin) {
473  $manifest = $plugin->getManifest();
474  $requires = $manifest->getRequires();
475 
476  foreach ($requires as $required) {
477  if ($required['type'] == 'plugin' && $required['name'] == $plugin_id) {
478  // there are active dependents
479  $dependents[$manifest->getPluginID()] = $plugin;
480  }
481  }
482  }
483 
484  if ($dependents) {
485  $list = '<ul>';
486  // construct error message and prevent disabling
487  foreach ($dependents as $dependent) {
488  $list .= '<li>' . $dependent->getManifest()->getName() . '</li>';
489  }
490  $list .= '</ul>';
491 
492  register_error(elgg_echo('ElggPlugin:Dependencies:ActiveDependent', array($plugin_name, $list)));
493 
494  return false;
495  }
496 }
497 
504 function _elgg_plugins_init() {
505 
506  if (elgg_is_admin_logged_in()) {
507  elgg_register_ajax_view('object/plugin/full');
508  }
509 
510  elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_plugins_test');
511 
512  // note - plugins are booted by the time this handler is registered
513  // deactivation due to error may have already occurred
514  elgg_register_event_handler('deactivate', 'plugin', '_plugins_deactivate_dependency_check');
515 
519  $svc = _elgg_services()->plugins;
520  elgg_register_event_handler('deactivate', 'plugin', array($svc, 'invalidateIsActiveCache'));
521  elgg_register_event_handler('activate', 'plugin', array($svc, 'invalidateIsActiveCache'));
522 
523  elgg_register_action("plugins/settings/save", '', 'admin');
524  elgg_register_action("plugins/usersettings/save");
525 
526  elgg_register_action('admin/plugins/activate', '', 'admin');
527  elgg_register_action('admin/plugins/deactivate', '', 'admin');
528  elgg_register_action('admin/plugins/activate_all', '', 'admin');
529  elgg_register_action('admin/plugins/deactivate_all', '', 'admin');
530 
531  elgg_register_action('admin/plugins/set_priority', '', 'admin');
532 
533  elgg_register_library('elgg:markdown', elgg_get_root_path() . 'vendors/markdown/markdown.php');
534 }
535 
536 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
537  $events->registerHandler('init', 'system', '_elgg_plugins_init');
538 };
_elgg_get_plugins_provides($type=null, $name=null)
Returns an array of all provides from all active plugins.
Definition: plugins.php:233
elgg_get_entities_from_plugin_user_settings(array $options=array())
Returns entities based upon plugin user settings.
Definition: plugins.php:434
$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:360
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.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:264
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:298
$value
Definition: longtext.php:26
$default
Definition: checkbox.php:34
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
_elgg_load_plugins()
Loads all active plugins in the order specified in the tool admin panel.
Definition: plugins.php:150
$params
Definition: login.php:72
$options
Definition: index.php:14
_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:210
_elgg_cache_plugin_by_id(\ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
Definition: plugins.php:86
elgg_unset_all_plugin_settings($plugin_id=null)
Unsets all plugin settings for a plugin.
Definition: plugins.php:402
_plugins_deactivate_dependency_check($event, $type, $params)
Checks on deactivate plugin event if disabling it won&#39;t create unmet dependencies and blocks disable ...
Definition: plugins.php:465
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
_elgg_get_plugin_dependency_strings($dep)
Returns an array of parsed strings for a dependency in the format: array( &#39;type&#39; => requires...
Definition: plugins.php:283
_elgg_services()
Definition: autoloader.php:14
$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:314
elgg_get_root_path()
Get the root directory path for this installation.
_elgg_get_max_plugin_priority()
Returns the highest priority of the plugins.
Definition: plugins.php:123
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
elgg_register_library($name, $location)
Register a PHP file as a library.
Definition: elgglib.php:21
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:345
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Definition: elgglib.php:519
elgg_plugin_exists($id)
Returns if a plugin exists in the system.
Definition: plugins.php:112
_elgg_plugins_init()
Initialize the plugin system.
Definition: plugins.php:504
elgg_unset_plugin_user_setting($name, $user_guid=0, $plugin_id=null)
Unsets a user-specific plugin setting.
Definition: plugins.php:329
_elgg_plugins_test($hook, $type, $value, $params)
Runs unit tests for plugin API.
Definition: plugins.php:449
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: plugins.php:162
elgg_unset_plugin_setting($name, $plugin_id=null)
Unsets a plugin setting.
Definition: plugins.php:389
_elgg_set_plugin_priorities(array $order)
Reorder plugins to an order specified by the array.
Definition: plugins.php:179
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_get_plugin_setting($name, $plugin_id=null, $default=null)
Get setting for a plugin.
Definition: plugins.php:375
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:208
_elgg_reindex_plugin_priorities()
Reindexes all plugin priorities starting at 1.
Definition: plugins.php:191
elgg_is_active_plugin($plugin_id, $site_guid=null)
Returns if a plugin is active for a current site.
Definition: plugins.php:135
_elgg_invalidate_plugins_provides_cache()
Deletes all cached data on plugins being provided.
Definition: plugins.php:244
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
Definition: actions.php:85
_elgg_get_plugin_dirs_in_dir($dir=null)
Returns a list of plugin directory names from a base directory.
Definition: plugins.php:61
$user_guid
Avatar remove action.
Definition: remove.php:6
if(!$collection_name) $id
Definition: add.php:17
$version
Definition: version.php:14
define(function(require){var $=require('jquery');var active=false;var SHOW_DELAY=20;$('body').append('< div class="elgg-spinner">< div class="elgg-ajax-loader"></div ></div >');return{start:function(){active=true;setTimeout(function(){if(active){$('body').addClass('elgg-spinner-active');}}, SHOW_DELAY);}, stop:function(){active=false;$('body').removeClass('elgg-spinner-active');}};})
_elgg_generate_plugin_entities()
Discovers plugins in the plugins_path setting and creates entities for them if they don&#39;t exist...
Definition: plugins.php:75
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:97
if(!($plugin instanceof ElggPlugin)) $plugin_name
Definition: save.php:24