Elgg  Version 2.3
ElggPlugin.php
Go to the documentation of this file.
1 <?php
2 
4 
14 class ElggPlugin extends \ElggObject {
15  private $package;
16  private $manifest;
17 
23  private $static_config;
24 
25  private $path;
26  private $errorMsg = '';
27 
33  protected function initializeAttributes() {
34  parent::initializeAttributes();
35 
36  $this->attributes['subtype'] = "plugin";
37 
38  // plugins must be public.
39  $this->access_id = ACCESS_PUBLIC;
40  }
41 
54  public function __construct($path) {
55  if (!$path) {
56  throw new \PluginException("ElggPlugin cannot be null instantiated. You must pass a full path.");
57  }
58 
59  if (is_object($path)) {
60  // database object
61  parent::__construct($path);
62  $this->path = _elgg_services()->config->getPluginsPath() . $this->getID();
63  } else if (is_numeric($path)) {
64  // guid
65  // @todo plugins with directory names of '12345'
66  elgg_deprecated_notice("Use elgg_get_plugin_from_id() to load a plugin.", 1.9);
67  parent::__construct($path);
68  $this->path = _elgg_services()->config->getPluginsPath() . $this->getID();
69  } else {
70  $this->initializeAttributes();
71 
72  $mod_dir = _elgg_services()->config->getPluginsPath();
73 
74  // not a full path, so assume a directory name and use the default path
75  if (strpos($path, $mod_dir) !== 0) {
76  elgg_deprecated_notice("You should pass a full path to ElggPlugin.", 1.9);
77  $path = $mod_dir . $path;
78  }
79 
80  // path checking is done in the package
81  $path = sanitise_filepath($path);
82  $this->path = $path;
83  $path_parts = explode('/', rtrim($path, '/'));
84  $plugin_id = array_pop($path_parts);
85  $this->title = $plugin_id;
86 
87  // check if we're loading an existing plugin
88  $existing_plugin = elgg_get_plugin_from_id($plugin_id);
89 
90  if ($existing_plugin) {
91  $this->load($existing_plugin->guid);
92  }
93  }
94 
96  }
97 
104  public function save() {
105  // own by the current site so users can be deleted without affecting plugins
106  $site = _elgg_services()->configTable->get('site');
107  $this->attributes['site_guid'] = $site->guid;
108  $this->attributes['owner_guid'] = $site->guid;
109  $this->attributes['container_guid'] = $site->guid;
110 
111  if (parent::save()) {
112  // make sure we have a priority
113  $priority = $this->getPriority();
114  if ($priority === false || $priority === null) {
115  return $this->setPriority('last');
116  }
117  } else {
118  return false;
119  }
120  }
121 
122 
123  // Plugin ID and path
124 
130  public function getID() {
131  return $this->title;
132  }
133 
140  public function getFriendlyName() {
141  $manifest = $this->getManifest();
142  if ($manifest) {
143  return $manifest->getName();
144  }
145 
146  return $this->getID();
147  }
148 
154  public function getPath() {
155  return sanitise_filepath($this->path);
156  }
157 
171  public function getStaticConfig($key, $default = null) {
172  if ($this->static_config === null) {
173  $this->static_config = [];
174 
176  $this->static_config = $this->includeFile(ElggPluginPackage::STATIC_CONFIG_FILENAME);
177  }
178  }
179 
180  if (array_key_exists($key, $this->static_config)) {
181  return $this->static_config[$key];
182  } else {
183  return $default;
184  }
185  }
186 
193  public function setID($id) {
194  return $this->attributes['title'] = $id;
195  }
196 
202  public function getAvailableTextFiles() {
203  $filenames = $this->getPackage()->getTextFilenames();
204 
205  $files = array();
206  foreach ($filenames as $filename) {
207  if ($this->canReadFile($filename)) {
208  $files[$filename] = "$this->path/$filename";
209  }
210  }
211 
212  return $files;
213  }
214 
215  // Load Priority
216 
222  public function getPriority() {
223  $name = _elgg_namespace_plugin_private_setting('internal', 'priority');
224  return $this->$name;
225  }
226 
236  public function setPriority($priority, $site_guid = null) {
237  if (!$this->guid) {
238  return false;
239  }
240 
241  $db_prefix = _elgg_services()->configTable->get('dbprefix');
242  $name = _elgg_namespace_plugin_private_setting('internal', 'priority');
243  // if no priority assume a priority of 1
244  $old_priority = (int) $this->getPriority();
245  $old_priority = (!$old_priority) ? 1 : $old_priority;
247 
248  // can't use switch here because it's not strict and
249  // php evaluates +1 == 1
250  if ($priority === '+1') {
251  $priority = $old_priority + 1;
252  } elseif ($priority === '-1') {
253  $priority = $old_priority - 1;
254  } elseif ($priority === 'first') {
255  $priority = 1;
256  } elseif ($priority === 'last') {
258  }
259 
260  // should be a number by now
261  if ($priority > 0) {
262  if (!is_numeric($priority)) {
263  return false;
264  }
265 
266  // there's nothing above the max.
267  if ($priority > $max_priority) {
269  }
270 
271  // there's nothing below 1.
272  if ($priority < 1) {
273  $priority = 1;
274  }
275 
276  if ($priority > $old_priority) {
277  $op = '-';
278  $where = "CAST(value as unsigned) BETWEEN $old_priority AND $priority";
279  } else {
280  $op = '+';
281  $where = "CAST(value as unsigned) BETWEEN $priority AND $old_priority";
282  }
283 
284  // displace the ones affected by this change
285  $q = "UPDATE {$db_prefix}private_settings
286  SET value = CAST(value as unsigned) $op 1
287  WHERE entity_guid != $this->guid
288  AND name = '$name'
289  AND $where";
290 
291  if (!$this->getDatabase()->updateData($q)) {
292  return false;
293  }
294 
295  // set this priority
296  if ($this->setPrivateSetting($name, $priority)) {
297  return true;
298  } else {
299  return false;
300  }
301  }
302 
303  return false;
304  }
305 
306 
307  // Plugin settings
308 
316  public function getSetting($name, $default = null) {
317  $values = _elgg_services()->pluginSettingsCache->getAll($this->guid);
318 
319  if ($values !== null) {
320  return isset($values[$name]) ? $values[$name] : $default;
321  }
322 
323  $val = $this->$name;
324  return $val !== null ? $val : $default;
325  }
326 
334  public function getAllSettings() {
335  $values = _elgg_services()->pluginSettingsCache->getAll($this->guid);
336  if ($values !== null) {
337  return $values;
338  }
339 
340  if (!$this->guid) {
341  return false;
342  }
343 
344  $db_prefix = _elgg_services()->config->get('dbprefix');
345  // need to remove all namespaced private settings.
346  $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID());
347  $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID());
348 
349  // Get private settings for user
350  $q = "SELECT * FROM {$db_prefix}private_settings
351  WHERE entity_guid = $this->guid
352  AND name NOT LIKE '$us_prefix%'
353  AND name NOT LIKE '$is_prefix%'";
354 
355  $private_settings = $this->getDatabase()->getData($q);
356 
357  $return = array();
358 
359  if ($private_settings) {
360  foreach ($private_settings as $setting) {
361  $return[$setting->name] = $setting->value;
362  }
363  }
364 
365  return $return;
366  }
367 
378  public function setSetting($name, $value) {
379  if (!$this->guid) {
380  return false;
381  }
382 
383  // Hook to validate setting
384  $value = elgg_trigger_plugin_hook('setting', 'plugin', array(
385  'plugin_id' => $this->getID(),
386  'plugin' => $this,
387  'name' => $name,
388  'value' => $value,
389  ), $value);
390 
391  if (is_array($value)) {
392  elgg_log('Plugin settings cannot store arrays.', 'ERROR');
393  return false;
394  }
395 
396  return $this->setPrivateSetting($name, $value);
397  }
398 
406  public function unsetSetting($name) {
407  return remove_private_setting($this->guid, $name);
408  }
409 
418  public function unsetAllSettings() {
419  _elgg_services()->pluginSettingsCache->clear($this->guid);
420  _elgg_services()->boot->invalidateCache();
421 
422  $db_prefix = _elgg_services()->configTable->get('dbprefix');
423  $us_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID());
424  $is_prefix = _elgg_namespace_plugin_private_setting('internal', '', $this->getID());
425 
426  $q = "DELETE FROM {$db_prefix}private_settings
427  WHERE entity_guid = $this->guid
428  AND name NOT LIKE '$us_prefix%'
429  AND name NOT LIKE '$is_prefix%'";
430 
431  return $this->getDatabase()->deleteData($q);
432  }
433 
434 
435  // User settings
436 
446  public function getUserSetting($name, $user_guid = 0, $default = null) {
447  $user_guid = (int)$user_guid;
448 
449  if ($user_guid) {
451  } else {
452  $user = _elgg_services()->session->getLoggedInUser();
453  }
454 
455  if (!($user instanceof \ElggUser)) {
456  return false;
457  }
458 
459  $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
460 
461  $val = get_private_setting($user->guid, $name);
462  return $val !== null ? $val : $default;
463  }
464 
473  public function getAllUserSettings($user_guid = 0) {
474  $user_guid = (int)$user_guid;
475 
476  if ($user_guid) {
478  } else {
479  $user = _elgg_services()->session->getLoggedInUser();
480  }
481 
482  if (!($user instanceof \ElggUser)) {
483  return false;
484  }
485 
486  $db_prefix = _elgg_services()->config->get('dbprefix');
487  // send an empty name so we just get the first part of the namespace
488  $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID());
489  $ps_prefix_len = strlen($ps_prefix);
490 
491  // Get private settings for user
492  $q = "SELECT * FROM {$db_prefix}private_settings
493  WHERE entity_guid = {$user->guid}
494  AND name LIKE '$ps_prefix%'";
495 
496  $private_settings = $this->getDatabase()->getData($q);
497 
498  $return = array();
499 
500  if ($private_settings) {
501  foreach ($private_settings as $setting) {
502  $name = substr($setting->name, $ps_prefix_len);
503  $value = $setting->value;
504 
505  $return[$name] = $value;
506  }
507  }
508 
509  return $return;
510  }
511 
521  public function setUserSetting($name, $value, $user_guid = 0) {
522  $user_guid = (int)$user_guid;
523 
524  if ($user_guid) {
526  } else {
527  $user = _elgg_services()->session->getLoggedInUser();
528  }
529 
530  if (!($user instanceof \ElggUser)) {
531  return false;
532  }
533 
534  // Hook to validate setting
535  // note: this doesn't pass the namespaced name
536  $value = _elgg_services()->hooks->trigger('usersetting', 'plugin', array(
537  'user' => $user,
538  'plugin' => $this,
539  'plugin_id' => $this->getID(),
540  'name' => $name,
541  'value' => $value
542  ), $value);
543 
544  if (is_array($value)) {
545  elgg_log('Plugin user settings cannot store arrays.', 'ERROR');
546  return false;
547  }
548 
549  // set the namespaced name.
550  $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
551 
552  return set_private_setting($user->guid, $name, $value);
553  }
554 
562  public function unsetUserSetting($name, $user_guid = 0) {
563  $user_guid = (int)$user_guid;
564 
565  if ($user_guid) {
567  } else {
568  $user = _elgg_services()->session->getLoggedInUser();
569  }
570 
571  if (!($user instanceof \ElggUser)) {
572  return false;
573  }
574 
575  // set the namespaced name.
576  $name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
577 
578  return remove_private_setting($user->guid, $name);
579  }
580 
593  public function unsetAllUserSettings($user_guid) {
594  $db_prefix = _elgg_services()->configTable->get('dbprefix');
595  $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID());
596 
597  $q = "DELETE FROM {$db_prefix}private_settings
598  WHERE entity_guid = $user_guid
599  AND name LIKE '$ps_prefix%'";
600 
601  return $this->getDatabase()->deleteData($q);
602  }
603 
612  public function unsetAllUsersSettings() {
613  $db_prefix = _elgg_services()->configTable->get('dbprefix');
614  $ps_prefix = _elgg_namespace_plugin_private_setting('user_setting', '', $this->getID());
615 
616  $q = "DELETE FROM {$db_prefix}private_settings
617  WHERE name LIKE '$ps_prefix%'";
618 
619  return $this->getDatabase()->deleteData($q);
620  }
621 
622 
623  // validation
624 
633  public function isValid() {
634  if (!$this->getID()) {
635  $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:MissingID', array($this->guid));
636  return false;
637  }
638 
639  if (!$this->getPackage() instanceof \ElggPluginPackage) {
640  $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:NoPluginPackagePackage', array($this->getID(), $this->guid));
641  return false;
642  }
643 
644  if (!$this->getPackage()->isValid()) {
645  $this->errorMsg = $this->getPackage()->getError();
646  return false;
647  }
648 
649  return true;
650  }
651 
658  public function isActive($site_guid = null) {
659  if (!$this->guid) {
660  return false;
661  }
662 
663  if ($site_guid) {
664  $site = get_entity($site_guid);
665  } else {
666  $site = _elgg_services()->configTable->get('site');
667  }
668 
669  if (!($site instanceof \ElggSite)) {
670  return false;
671  }
672 
673  return check_entity_relationship($this->guid, 'active_plugin', $site->guid);
674  }
675 
685  public function canActivate($site_guid = null) {
686  if ($this->isActive($site_guid)) {
687  return false;
688  }
689 
690  if ($this->getPackage()) {
691  $result = $this->getPackage()->isValid() && $this->getPackage()->checkDependencies();
692  if (!$result) {
693  $this->errorMsg = $this->getPackage()->getError();
694  }
695 
696  return $result;
697  }
698 
699  return false;
700  }
701 
702 
703  // activating and deactivating
704 
711  public function activate($site_guid = null) {
712  if ($this->isActive($site_guid)) {
713  return false;
714  }
715 
716  if (!$this->canActivate()) {
717  return false;
718  }
719 
720  // Check this before setting status because the file could potentially throw
721  if (!$this->isStaticConfigValid()) {
722  return false;
723  }
724 
725  if (!$this->setStatus(true, $site_guid)) {
726  return false;
727  }
728 
729  // perform tasks and emit events
730  // emit an event. returning false will make this not be activated.
731  // we need to do this after it's been fully activated
732  // or the deactivate will be confused.
733  $params = array(
734  'plugin_id' => $this->getID(),
735  'plugin_entity' => $this,
736  );
737 
738  $return = _elgg_services()->events->trigger('activate', 'plugin', $params);
739 
740  // if there are any on_enable functions, start the plugin now and run them
741  // Note: this will not run re-run the init hooks!
742  if ($return) {
743  if ($this->canReadFile('activate.php')) {
746 
747  $this->start($flags);
748 
749  $return = $this->includeFile('activate.php');
750  }
751  }
752 
753  if ($return === false) {
754  $this->deactivate($site_guid);
755  }
756 
757  return $return;
758  }
759 
768  public function canDeactivate($site_guid = null) {
769  if (!$this->isActive($site_guid)) {
770  return false;
771  }
772 
773  $dependents = [];
774 
775  $active_plugins = elgg_get_plugins();
776 
777  foreach ($active_plugins as $plugin) {
778  $manifest = $plugin->getManifest();
779  if (!$manifest) {
780  return true;
781  }
782  $requires = $manifest->getRequires();
783 
784  foreach ($requires as $required) {
785  if ($required['type'] == 'plugin' && $required['name'] == $this->getID()) {
786  // there are active dependents
787  $dependents[$manifest->getPluginID()] = $plugin;
788  }
789  }
790  }
791 
792  if (!empty($dependents)) {
793  $list = array_map(function(\ElggPlugin $plugin) {
794  $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getManifest()->getID());
795  return elgg_view('output/url', [
796  'text' => $plugin->getManifest()->getName(),
797  'href' => "#$css_id",
798  ]);
799  }, $dependents);
800  $name = $this->getManifest()->getName();
801  $list = implode(', ', $list);
802  $this->errorMsg = elgg_echo('ElggPlugin:Dependencies:ActiveDependent', [$name, $list]);
803  return false;
804  }
805 
806  return true;
807  }
808 
815  public function deactivate($site_guid = null) {
816  if (!$this->isActive($site_guid)) {
817  return false;
818  }
819 
820  if (!$this->canDeactivate($site_guid)) {
821  return false;
822  }
823 
824  // emit an event. returning false will cause this to not be deactivated.
825  $params = array(
826  'plugin_id' => $this->getID(),
827  'plugin_entity' => $this,
828  );
829 
830  $return = _elgg_services()->events->trigger('deactivate', 'plugin', $params);
831 
832  // run any deactivate code
833  if ($return) {
834  if ($this->canReadFile('deactivate.php')) {
835  $return = $this->includeFile('deactivate.php');
836  }
837  }
838 
839  if ($return === false) {
840  return false;
841  } else {
842  return $this->setStatus(false, $site_guid);
843  }
844  }
845 
853  public function start($flags) {
854  //if (!$this->canActivate()) {
855  // return false;
856  //}
857 
858  // include classes
859  if ($flags & ELGG_PLUGIN_REGISTER_CLASSES) {
860  $this->registerClasses();
861  }
862 
863  // include start file
864  if ($flags & ELGG_PLUGIN_INCLUDE_START) {
865  $this->includeFile('start.php');
866  }
867 
868  // include views
869  if ($flags & ELGG_PLUGIN_REGISTER_VIEWS) {
870  $this->registerViews();
871  }
872 
873  // include languages
874  if ($flags & ELGG_PLUGIN_REGISTER_LANGUAGES) {
875  $this->registerLanguages();
876  }
877 
878  return true;
879  }
880 
881 
882  // start helpers
883 
889  protected static function getConfigWrapper() {
890  static $wrapper;
891  if (null === $wrapper) {
892  global $CONFIG;
893  $warning = 'Do not rely on local $CONFIG being available in start.php';
894  $wrapper = new \Elgg\DeprecationWrapper($CONFIG, $warning, "1.10");
895  }
896  return $wrapper;
897  }
898 
907  protected function includeFile($filename) {
908  // This needs to be here to be backwards compatible for 1.0-1.7.
909  // They expect the global config object to be available in start.php.
910  if ($filename == 'start.php') {
911  $CONFIG = self::getConfigWrapper();
912  }
913 
914  $filepath = "$this->path/$filename";
915 
916  if (!$this->canReadFile($filename)) {
917  $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:CannotIncludeFile',
918  array($filename, $this->getID(), $this->guid, $this->path));
919  throw new \PluginException($msg);
920  }
921 
922  try {
923  $ret = require_once $filepath;
924  } catch (Exception $e) {
925  $msg = _elgg_services()->translator->translate('ElggPlugin:Exception:IncludeFileThrew',
926  array($filename, $this->getID(), $this->guid, $this->path));
927  throw new \PluginException($msg, 0, $e);
928  }
929 
930  return $ret;
931  }
932 
939  protected function canReadFile($filename) {
940  $path = "{$this->path}/$filename";
941  return is_file($path) && is_readable($path);
942  }
943 
950  private function isStaticConfigValid() {
952  return true;
953  }
954 
955  ob_start();
957  if (ob_get_clean() !== '') {
958  $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:ConfigSentOutput');
959  return false;
960  }
961 
962  // make sure can serialize
963  $value = @unserialize(serialize($value));
964  if (!is_array($value)) {
965  $this->errorMsg = _elgg_services()->translator->translate('ElggPlugin:activate:BadConfigFormat');
966  return false;
967  }
968 
969  return true;
970  }
971 
978  protected function registerViews() {
979  $views = _elgg_services()->views;
980 
981  // Declared views first
982  $file = "{$this->path}/views.php";
983  if (is_file($file)) {
984  $spec = Includer::includeFile($file);
985  if (is_array($spec)) {
986  $views->mergeViewsSpec($spec);
987  }
988  }
989 
990  $spec = $this->getStaticConfig('views');
991  if ($spec) {
992  $views->mergeViewsSpec($spec);
993  }
994 
995  // Allow /views directory files to override
996  if (!$views->registerPluginViews($this->path, $failed_dir)) {
997  $key = 'ElggPlugin:Exception:CannotRegisterViews';
998  $args = [$this->getID(), $this->guid, $failed_dir];
999  $msg = _elgg_services()->translator->translate($key, $args);
1000  throw new \PluginException($msg);
1001  }
1002  }
1003 
1010  protected function registerLanguages() {
1011  return _elgg_services()->translator->registerPluginTranslations($this->path);
1012  }
1013 
1020  protected function registerClasses() {
1021  $classes_path = "$this->path/classes";
1022 
1023  if (is_dir($classes_path)) {
1024  _elgg_services()->autoloadManager->addClasses($classes_path);
1025  }
1026 
1027  return true;
1028  }
1029 
1036  public function __get($name) {
1037  // See if its in our base attribute
1038  if (array_key_exists($name, $this->attributes)) {
1039  return $this->attributes[$name];
1040  }
1041 
1042  // @todo clean below - getPrivateSetting() should return null now
1043  // No, so see if its in the private data store.
1044  // get_private_setting() returns false if it doesn't exist
1045  $meta = $this->getPrivateSetting($name);
1046 
1047  if ($meta === false) {
1048  // Can't find it, so return null
1049  return null;
1050  }
1051 
1052  return $meta;
1053  }
1054 
1062  public function get($name) {
1063  elgg_deprecated_notice("Use -> instead of get()", 1.9);
1064  return $this->__get($name);
1065  }
1066 
1076  public function __set($name, $value) {
1077  if (array_key_exists($name, $this->attributes)) {
1078  // Check that we're not trying to change the guid!
1079  if ((array_key_exists('guid', $this->attributes)) && ($name == 'guid')) {
1080  return;
1081  }
1082 
1083  $this->attributes[$name] = $value;
1084  } else {
1085  // to make sure we trigger the correct hooks
1086  $this->setSetting($name, $value);
1087  }
1088  }
1089 
1099  public function set($name, $value) {
1100  elgg_deprecated_notice("Use -> instead of set()", 1.9);
1101  $this->__set($name, $value);
1102 
1103  return true;
1104  }
1105 
1114  private function setStatus($active, $site_guid = null) {
1115  if (!$this->guid) {
1116  return false;
1117  }
1118 
1119  if ($site_guid) {
1120  $site = get_entity($site_guid);
1121 
1122  if (!($site instanceof \ElggSite)) {
1123  return false;
1124  }
1125  } else {
1126  $site = _elgg_services()->configTable->get('site');
1127  }
1128 
1129  if ($active) {
1130  $result = add_entity_relationship($this->guid, 'active_plugin', $site->guid);
1131  } else {
1132  $result = remove_entity_relationship($this->guid, 'active_plugin', $site->guid);
1133  }
1134 
1136  _elgg_services()->boot->invalidateCache();
1137 
1138  return $result;
1139  }
1140 
1146  public function getError() {
1147  return $this->errorMsg;
1148  }
1149 
1155  public function getManifest() {
1156  if ($this->manifest instanceof \ElggPluginManifest) {
1157  return $this->manifest;
1158  }
1159 
1160  try {
1161  $package = $this->getPackage();
1162  if (!$package) {
1163  throw new \Exception('Package cannot be loaded');
1164  }
1165  $this->manifest = $package->getManifest();
1166  } catch (Exception $e) {
1167  _elgg_services()->logger->warn("Failed to load manifest for plugin $this->guid. " . $e->getMessage());
1168  $this->errorMsg = $e->getmessage();
1169  }
1170 
1171  return $this->manifest;
1172  }
1173 
1179  public function getPackage() {
1180  if ($this->package instanceof \ElggPluginPackage) {
1181  return $this->package;
1182  }
1183 
1184  try {
1185  $this->package = new \ElggPluginPackage($this->path, false);
1186  } catch (Exception $e) {
1187  _elgg_services()->logger->warn("Failed to load package for $this->guid. " . $e->getMessage());
1188  $this->errorMsg = $e->getmessage();
1189  }
1190 
1191  return $this->package;
1192  }
1193 }
getSetting($name, $default=null)
Returns a plugin setting.
Definition: ElggPlugin.php:316
registerViews()
Registers the plugin&#39;s views.
Definition: ElggPlugin.php:978
getID()
Returns the ID (dir name) of this plugin.
Definition: ElggPlugin.php:130
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:48
start($flags)
Start the plugin.
Definition: ElggPlugin.php:853
$plugin
if(!array_key_exists($filename, $text_files)) $file
$max_priority
Definition: full.php:28
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
registerClasses()
Registers the plugin&#39;s classes.
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
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
$e
Definition: metadata.php:12
setPrivateSetting($name, $value)
Adds a private setting to this entity.
Definition: ElggEntity.php:675
activate($site_guid=null)
Actives the plugin for the current site.
Definition: ElggPlugin.php:711
getAllSettings()
Returns an array of all settings saved for this plugin.
Definition: ElggPlugin.php:334
canDeactivate($site_guid=null)
Checks if this plugin can be deactivated on the current Elgg installation.
Definition: ElggPlugin.php:768
getPrivateSetting($name)
Returns a private setting value.
Definition: ElggEntity.php:691
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
Definition: elgglib.php:411
load($guid)
Loads the full when given a guid.
Definition: ElggObject.php:98
$value
Definition: longtext.php:42
unsetAllUsersSettings()
Removes this plugin&#39;s user settings for all users.
Definition: ElggPlugin.php:612
$return
Definition: opendd.php:15
$default
Definition: checkbox.php:34
$guid
Removes an admin notice.
canActivate($site_guid=null)
Checks if this plugin can be activated on the current Elgg installation.
Definition: ElggPlugin.php:685
$args
Some servers don&#39;t allow PHP to check the rewrite, so try via AJAX.
const ELGG_PLUGIN_REGISTER_LANGUAGES
Tells ::start() to automatically register the plugin&#39;s languages.
Definition: plugins.php:23
$CONFIG path
The full path where Elgg is installed.
Definition: config.php:16
$title
Definition: save.php:22
unsetUserSetting($name, $user_guid=0)
Removes a user setting name and value.
Definition: ElggPlugin.php:562
getUserSetting($name, $user_guid=0, $default=null)
Returns a user&#39;s setting for this plugin.
Definition: ElggPlugin.php:446
includeFile($filename)
Includes one of the plugins files.
Definition: ElggPlugin.php:907
$params
Definition: login.php:72
setID($id)
Sets the location of this plugin.
Definition: ElggPlugin.php:193
_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
if(!$plugin instanceof ElggPlugin) $active
Definition: details.php:14
canReadFile($filename)
Checks whether a plugin file with the given name exists.
Definition: ElggPlugin.php:939
ui datepicker title
Definition: admin.css.php:662
_elgg_cache_plugin_by_id(\ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
Definition: plugins.php:71
unsetAllUserSettings($user_guid)
Removes all User Settings for this plugin for a particular user.
Definition: ElggPlugin.php:593
getPackage()
Returns this plugin&#39;s object.
setUserSetting($name, $value, $user_guid=0)
Sets a user setting for a plugin.
Definition: ElggPlugin.php:521
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
$key
Definition: summary.php:34
registerLanguages()
Registers the plugin&#39;s languages.
getAvailableTextFiles()
Returns an array of available markdown files for this plugin.
Definition: ElggPlugin.php:202
$plugin_id
Definition: save.php:16
global $CONFIG
initializeAttributes()
Set subtype to &#39;plugin&#39;.
Definition: ElggPlugin.php:33
$user
Definition: ban.php:13
const ELGG_PLUGIN_INCLUDE_START
Tells ::start() to include the start.php file.
Definition: plugins.php:13
unsetAllSettings()
Removes all settings for this plugin.
Definition: ElggPlugin.php:418
const ELGG_PLUGIN_REGISTER_VIEWS
Tells ::start() to automatically register the plugin&#39;s views.
Definition: plugins.php:18
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:826
getStaticConfig($key, $default=null)
Get a value from the plugins&#39;s static config file.
Definition: ElggPlugin.php:171
check_entity_relationship($guid_one, $relationship, $guid_two)
Check if a relationship exists between two entities.
_elgg_get_max_plugin_priority()
Returns the highest priority of the plugins.
Definition: plugins.php:108
elgg river item elgg form comment save
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
elgg global
Pointer to the global context.
Definition: elgglib.js:12
isActive($site_guid=null)
Is this plugin active?
Definition: ElggPlugin.php:658
isValid()
Returns if the plugin is complete, meaning has all required files and Elgg can read them and they mak...
Definition: ElggPlugin.php:633
$css_id
Definition: full.php:30
setPriority($priority, $site_guid=null)
Sets the priority of the plugin.
Definition: ElggPlugin.php:236
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
__construct($path)
Creates a new plugin from path.
Definition: ElggPlugin.php:54
getError()
Returns the last error message registered.
static getConfigWrapper()
Get the config object in a deprecation wrapper.
Definition: ElggPlugin.php:889
setSetting($name, $value)
Set a plugin setting for the plugin.
Definition: ElggPlugin.php:378
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:1028
getManifest()
Returns this plugin&#39;s object.
$comment access_id
Definition: save.php:60
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: plugins.php:132
const ACCESS_PUBLIC
Definition: elgglib.php:2084
__get($name)
Get an attribute or private setting value.
getAllUserSettings($user_guid=0)
Returns an array of all user settings saved for this plugin for the user.
Definition: ElggPlugin.php:473
deactivate($site_guid=null)
Deactivates the plugin.
Definition: ElggPlugin.php:815
getFriendlyName()
Returns the manifest&#39;s name if available, otherwise the ID.
Definition: ElggPlugin.php:140
$required
Definition: label.php:12
unsetSetting($name)
Removes a plugin setting name and value.
Definition: ElggPlugin.php:406
getPriority()
Gets the plugin&#39;s load priority.
Definition: ElggPlugin.php:222
__set($name, $value)
Set a value as private setting or attribute.
$filename
save()
Save the plugin object.
Definition: ElggPlugin.php:104
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
const ELGG_PLUGIN_REGISTER_CLASSES
Tells ::start() to automatically register the plugin&#39;s classes.
Definition: plugins.php:28
_elgg_invalidate_plugins_provides_cache()
Deletes all cached data on plugins being provided.
Definition: plugins.php:162
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
$user_guid
Avatar remove action.
Definition: remove.php:6
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
Definition: details.php:141
if(!$collection_name) $id
Definition: add.php:17
getPath()
Returns the plugin&#39;s full path with trailing slash.
Definition: ElggPlugin.php:154
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5
if(!$num_display) $db_prefix
Definition: content.php:13
$priority
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:82
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204