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();
787 $dependents[$manifest->getPluginID()] =
$plugin;
792 if (!empty($dependents)) {
794 $css_id = preg_replace(
'/[^a-z0-9-]/i',
'-',
$plugin->getManifest()->getID());
796 'text' =>
$plugin->getManifest()->getName(),
797 'href' =>
"#$css_id",
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");
914 $filepath =
"$this->path/$filename";
917 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:CannotIncludeFile',
919 throw new \PluginException($msg);
923 $ret = require_once $filepath;
924 }
catch (Exception
$e) {
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();
1166 }
catch (Exception
$e) {
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);
1186 }
catch (Exception
$e) {
1187 _elgg_services()->logger->warn(
"Failed to load package for $this->guid. " .
$e->getMessage());
1188 $this->errorMsg =
$e->getmessage();
1191 return $this->package;
if(! $collection_name) $id
if($guid==elgg_get_logged_in_user_guid()) $name
$user_guid
Avatar remove action.
getDatabase()
Provides a pointer to the database object.
setPrivateSetting($name, $value)
Adds a private setting to this entity.
getPrivateSetting($name)
Returns a private setting value.
load($guid)
Loads the full \ElggObject when given a guid.
const STATIC_CONFIG_FILENAME
includeFile($filename)
Includes one of the plugins files.
getUserSetting($name, $user_guid=0, $default=null)
Returns a user's setting for this plugin.
start($flags)
Start the plugin.
getPath()
Returns the plugin's full path with trailing slash.
__set($name, $value)
Set a value as private setting or attribute.
__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.
getSetting($name, $default=null)
Returns a plugin setting.
canDeactivate($site_guid=null)
Checks if this plugin can be deactivated on the current Elgg installation.
unsetAllSettings()
Removes all settings for this plugin.
setSetting($name, $value)
Set a plugin setting for the plugin.
setID($id)
Sets the location of this plugin.
registerLanguages()
Registers the plugin's languages.
registerViews()
Registers the plugin's views.
canReadFile($filename)
Checks whether a plugin file with the given name exists.
getPackage()
Returns this plugin's \ElggPluginPackage object.
initializeAttributes()
Set subtype to 'plugin'.
getManifest()
Returns this plugin's \ElggPluginManifest object.
__construct($path)
Creates a new plugin from path.
registerClasses()
Registers the plugin's classes.
activate($site_guid=null)
Actives the plugin for the current site.
getID()
Returns the ID (dir name) of this plugin.
unsetSetting($name)
Removes a plugin setting name and value.
getError()
Returns the last error message registered.
isValid()
Returns if the plugin is complete, meaning has all required files and Elgg can read them and they mak...
getAvailableTextFiles()
Returns an array of available markdown files for this plugin.
static getConfigWrapper()
Get the config object in a deprecation wrapper.
getStaticConfig($key, $default=null)
Get a value from the plugins's static config file.
isActive($site_guid=null)
Is this plugin active?
setUserSetting($name, $value, $user_guid=0)
Sets a user setting for a plugin.
deactivate($site_guid=null)
Deactivates the plugin.
getPriority()
Gets the plugin's load priority.
unsetAllUserSettings($user_guid)
Removes all User Settings for this plugin for a particular user.
getAllSettings()
Returns an array of all settings saved for this plugin.
canActivate($site_guid=null)
Checks if this plugin can be activated on the current Elgg installation.
save()
Save the plugin object.
setPriority($priority, $site_guid=null)
Sets the priority of the plugin.
unsetAllUsersSettings()
Removes this plugin's user settings for all users.
unsetUserSetting($name, $user_guid=0)
Removes a user setting name and value.
getFriendlyName()
Returns the manifest's name if available, otherwise the ID.
Allow executing scripts without $this context or local vars.
elgg river item elgg form comment save
$CONFIG path
The full path where Elgg is installed.
$guid
Removes an admin notice.
foreach($resources as $id=> $href) if(!empty($resources_html)) $files
if(! $plugin instanceof ElggPlugin) $active
elgg_log($message, $level='NOTICE')
Display or log a message.
sanitise_filepath($path, $append_slash=true)
Sanitise file paths ensuring that they begin and end with slashes etc.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_get_plugin_from_id($plugin_id)
Returns an \ElggPlugin object with the path $path.
const ELGG_PLUGIN_REGISTER_LANGUAGES
Tells \ElggPlugin::start() to automatically register the plugin's languages.
_elgg_cache_plugin_by_id(\ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
const ELGG_PLUGIN_REGISTER_VIEWS
Tells \ElggPlugin::start() to automatically register the plugin's views.
const ELGG_PLUGIN_REGISTER_CLASSES
Tells \ElggPlugin::start() to automatically register the plugin's classes.
elgg_get_plugins($status='active', $site_guid=null)
Returns an ordered list of plugins.
const ELGG_PLUGIN_INCLUDE_START
Tells \ElggPlugin::start() to include the start.php file.
_elgg_namespace_plugin_private_setting($type, $name, $id=null)
Namespaces a string to be used as a private setting name for a plugin.
_elgg_invalidate_plugins_provides_cache()
Deletes all cached data on plugins being provided.
_elgg_get_max_plugin_priority()
Returns the highest priority of the plugins.
get_entity($guid)
Loads and returns an entity object from a guid.
$args
Some servers don't allow PHP to check the rewrite, so try via AJAX.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype='')
Return a parsed view.
if(!array_key_exists($filename, $text_files)) $file
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
get_private_setting($entity_guid, $name)
Gets a private setting for an entity.
set_private_setting($entity_guid, $name, $value)
Sets a private setting for an entity.
add_entity_relationship($guid_one, $relationship, $guid_two)
Create a relationship between two entities.
remove_entity_relationship($guid_one, $relationship, $guid_two)
Delete a relationship between two entities.
check_entity_relationship($guid_one, $relationship, $guid_two)
Check if a relationship exists between two entities.
if(! $num_display) $db_prefix