23 private $static_config;
26 private $errorMsg =
'';
34 parent::initializeAttributes();
36 $this->attributes[
'subtype'] =
"plugin";
56 throw new \PluginException(
"ElggPlugin cannot be null instantiated. You must pass a full path.");
59 if (is_object($path)) {
61 parent::__construct($path);
63 }
else if (is_numeric($path)) {
67 parent::__construct($path);
75 if (strpos($path, $mod_dir) !== 0) {
77 $path = $mod_dir . $path;
83 $path_parts = explode(
'/', rtrim($path,
'/'));
90 if ($existing_plugin) {
91 $this->
load($existing_plugin->guid);
107 $this->attributes[
'site_guid'] =
$site->guid;
108 $this->attributes[
'owner_guid'] =
$site->guid;
109 $this->attributes[
'container_guid'] =
$site->guid;
143 return $manifest->getName();
146 return $this->
getID();
172 if ($this->static_config === null) {
173 $this->static_config = [];
180 if (array_key_exists(
$key, $this->static_config)) {
181 return $this->static_config[
$key];
194 return $this->attributes[
'title'] =
$id;
203 $filenames = $this->
getPackage()->getTextFilenames();
245 $old_priority = (!$old_priority) ? 1 : $old_priority;
278 $where =
"CAST(value as unsigned) BETWEEN $old_priority AND $priority";
281 $where =
"CAST(value as unsigned) BETWEEN $priority AND $old_priority";
285 $q =
"UPDATE {$db_prefix}private_settings 286 SET value = CAST(value as unsigned) $op 1 287 WHERE entity_guid != $this->guid 317 $values =
_elgg_services()->pluginSettingsCache->getAll($this->guid);
319 if ($values !== null) {
324 return $val !== null ? $val :
$default;
335 $values =
_elgg_services()->pluginSettingsCache->getAll($this->guid);
336 if ($values !== null) {
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%'";
355 $private_settings = $this->
getDatabase()->getData($q);
359 if ($private_settings) {
360 foreach ($private_settings as $setting) {
361 $return[$setting->name] = $setting->value;
385 'plugin_id' => $this->
getID(),
392 elgg_log(
'Plugin settings cannot store arrays.',
'ERROR');
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%'";
462 return $val !== null ? $val :
$default;
489 $ps_prefix_len = strlen($ps_prefix);
492 $q =
"SELECT * FROM {$db_prefix}private_settings 493 WHERE entity_guid = {$user->guid} 494 AND name LIKE '$ps_prefix%'";
496 $private_settings = $this->
getDatabase()->getData($q);
500 if ($private_settings) {
501 foreach ($private_settings as $setting) {
502 $name = substr($setting->name, $ps_prefix_len);
539 'plugin_id' => $this->
getID(),
545 elgg_log(
'Plugin user settings cannot store arrays.',
'ERROR');
597 $q =
"DELETE FROM {$db_prefix}private_settings 598 WHERE entity_guid = $user_guid 599 AND name LIKE '$ps_prefix%'";
616 $q =
"DELETE FROM {$db_prefix}private_settings 617 WHERE name LIKE '$ps_prefix%'";
634 if (!$this->
getID()) {
635 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:MissingID', array($this->guid));
640 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:NoPluginPackagePackage', array($this->
getID(), $this->guid));
645 $this->errorMsg = $this->
getPackage()->getError();
693 $this->errorMsg = $this->
getPackage()->getError();
721 if (!$this->isStaticConfigValid()) {
725 if (!$this->setStatus(
true, $site_guid)) {
734 'plugin_id' => $this->
getID(),
735 'plugin_entity' => $this,
747 $this->
start($flags);
777 foreach ($active_plugins as
$plugin) {
778 $manifest = $plugin->getManifest();
782 $requires = $manifest->getRequires();
785 if ($required[
'type'] ==
'plugin' && $required[
'name'] == $this->
getID()) {
787 $dependents[$manifest->getPluginID()] =
$plugin;
792 if (!empty($dependents)) {
797 'href' =>
"#$css_id",
802 $this->errorMsg =
elgg_echo(
'ElggPlugin:Dependencies:ActiveDependent', [$name,
$list]);
826 'plugin_id' => $this->
getID(),
827 'plugin_entity' => $this,
842 return $this->setStatus(
false, $site_guid);
891 if (null === $wrapper) {
893 $warning =
'Do not rely on local $CONFIG being available in start.php';
894 $wrapper = new \Elgg\DeprecationWrapper($CONFIG, $warning,
"1.10");
911 $CONFIG = self::getConfigWrapper();
914 $filepath =
"$this->path/$filename";
917 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:CannotIncludeFile',
919 throw new \PluginException($msg);
923 $ret = require_once $filepath;
925 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:IncludeFileThrew',
927 throw new \PluginException($msg, 0, $e);
940 $path =
"{$this->path}/$filename";
941 return is_file($path) && is_readable($path);
950 private function isStaticConfigValid() {
957 if (ob_get_clean() !==
'') {
958 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:activate:ConfigSentOutput');
965 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:activate:BadConfigFormat');
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);
992 $views->mergeViewsSpec($spec);
996 if (!$views->registerPluginViews($this->path, $failed_dir)) {
997 $key =
'ElggPlugin:Exception:CannotRegisterViews';
1000 throw new \PluginException($msg);
1021 $classes_path =
"$this->path/classes";
1023 if (is_dir($classes_path)) {
1038 if (array_key_exists(
$name, $this->attributes)) {
1039 return $this->attributes[
$name];
1047 if ($meta ===
false) {
1077 if (array_key_exists(
$name, $this->attributes)) {
1079 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
1114 private function setStatus(
$active, $site_guid = null) {
1147 return $this->errorMsg;
1157 return $this->manifest;
1163 throw new \Exception(
'Package cannot be loaded');
1165 $this->manifest = $package->getManifest();
1167 _elgg_services()->logger->warn(
"Failed to load manifest for plugin $this->guid. " . $e->getMessage());
1168 $this->errorMsg = $e->getmessage();
1171 return $this->manifest;
1181 return $this->package;
1185 $this->
package = new \ElggPluginPackage($this->path, false);
1187 _elgg_services()->logger->warn(
"Failed to load package for $this->guid. " . $e->getMessage());
1188 $this->errorMsg = $e->getmessage();
1191 return $this->package;
getSetting($name, $default=null)
Returns a plugin setting.
registerViews()
Registers the plugin's views.
getID()
Returns the ID (dir name) of this plugin.
getDatabase()
Provides a pointer to the database object.
start($flags)
Start the plugin.
if(!array_key_exists($filename, $text_files)) $file
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
registerClasses()
Registers the plugin's classes.
if($guid==elgg_get_logged_in_user_guid()) $name
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
activate($site_guid=null)
Actives the plugin for the current site.
getAllSettings()
Returns an array of all settings saved for this plugin.
canDeactivate($site_guid=null)
Checks if this plugin can be deactivated on the current Elgg installation.
getPrivateSetting($name)
Returns a private setting value.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
load($guid)
Loads the full when given a guid.
unsetAllUsersSettings()
Removes this plugin's user settings for all users.
$guid
Removes an admin notice.
canActivate($site_guid=null)
Checks if this plugin can be activated on the current Elgg installation.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
const ELGG_PLUGIN_REGISTER_LANGUAGES
Tells ::start() to automatically register the plugin's languages.
$CONFIG path
The full path where Elgg is installed.
unsetUserSetting($name, $user_guid=0)
Removes a user setting name and value.
getUserSetting($name, $user_guid=0, $default=null)
Returns a user's setting for this plugin.
includeFile($filename)
Includes one of the plugins files.
setID($id)
Sets the location of this plugin.
_elgg_namespace_plugin_private_setting($type, $name, $id=null)
Namespaces a string to be used as a private setting name for a plugin.
if(!$plugin instanceof ElggPlugin) $active
canReadFile($filename)
Checks whether a plugin file with the given name exists.
_elgg_cache_plugin_by_id(\ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
unsetAllUserSettings($user_guid)
Removes all User Settings for this plugin for a particular user.
getPackage()
Returns this plugin's object.
setUserSetting($name, $value, $user_guid=0)
Sets a user setting for a plugin.
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
registerLanguages()
Registers the plugin's languages.
getAvailableTextFiles()
Returns an array of available markdown files for this plugin.
initializeAttributes()
Set subtype to 'plugin'.
const ELGG_PLUGIN_INCLUDE_START
Tells ::start() to include the start.php file.
unsetAllSettings()
Removes all settings for this plugin.
const ELGG_PLUGIN_REGISTER_VIEWS
Tells ::start() to automatically register the plugin's views.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
getStaticConfig($key, $default=null)
Get a value from the plugins's static config file.
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.
elgg river item elgg form comment save
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
isActive($site_guid=null)
Is this plugin active?
isValid()
Returns if the plugin is complete, meaning has all required files and Elgg can read them and they mak...
setPriority($priority, $site_guid=null)
Sets the priority of the plugin.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
__construct($path)
Creates a new plugin from path.
getError()
Returns the last error message registered.
static getConfigWrapper()
Get the config object in a deprecation wrapper.
setSetting($name, $value)
Set a plugin setting for the plugin.
elgg_log($message, $level= 'NOTICE')
Display or log a message.
getManifest()
Returns this plugin's object.
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
__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.
deactivate($site_guid=null)
Deactivates the plugin.
getFriendlyName()
Returns the manifest's name if available, otherwise the ID.
unsetSetting($name)
Removes a plugin setting name and value.
getPriority()
Gets the plugin's load priority.
__set($name, $value)
Set a value as private setting or attribute.
save()
Save the plugin object.
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's classes.
_elgg_invalidate_plugins_provides_cache()
Deletes all cached data on plugins being provided.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
$user_guid
Avatar remove action.
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
if(!$collection_name) $id
getPath()
Returns the plugin's full path with trailing slash.
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
if(!$num_display) $db_prefix
const STATIC_CONFIG_FILENAME
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
get_entity($guid)
Loads and returns an entity object from a guid.