16 private $errorMsg =
'';
24 parent::initializeAttributes();
26 $this->attributes[
'subtype'] =
"plugin";
46 throw new \PluginException(
"ElggPlugin cannot be null instantiated. You must pass a full path.");
49 if (is_object($path)) {
51 parent::__construct($path);
53 }
else if (is_numeric($path)) {
57 parent::__construct($path);
65 if (strpos($path, $mod_dir) !== 0) {
67 $path = $mod_dir . $path;
73 $path_parts = explode(
'/', rtrim($path,
'/'));
80 if ($existing_plugin) {
81 $this->
load($existing_plugin->guid);
97 $this->attributes[
'site_guid'] =
$site->guid;
98 $this->attributes[
'owner_guid'] =
$site->guid;
99 $this->attributes[
'container_guid'] =
$site->guid;
133 return $manifest->getName();
136 return $this->
getID();
155 return $this->attributes[
'title'] =
$id;
164 $filenames = $this->
getPackage()->getTextFilenames();
206 $old_priority = (!$old_priority) ? 1 : $old_priority;
239 $where =
"CAST(value as unsigned) BETWEEN $old_priority AND $priority";
242 $where =
"CAST(value as unsigned) BETWEEN $priority AND $old_priority";
246 $q =
"UPDATE {$db_prefix}private_settings 247 SET value = CAST(value as unsigned) $op 1 248 WHERE entity_guid != $this->guid 279 return $val !== null ? $val :
$default;
300 $q =
"SELECT * FROM {$db_prefix}private_settings 301 WHERE entity_guid = $this->guid 302 AND name NOT LIKE '$us_prefix%' 303 AND name NOT LIKE '$is_prefix%'";
305 $private_settings = $this->
getDatabase()->getData($q);
309 if ($private_settings) {
310 foreach ($private_settings as $setting) {
311 $return[$setting->name] = $setting->value;
335 'plugin_id' => $this->
getID(),
368 $q =
"DELETE FROM {$db_prefix}private_settings 369 WHERE entity_guid = $this->guid 370 AND name NOT LIKE '$us_prefix%' 371 AND name NOT LIKE '$is_prefix%'";
404 return $val !== null ? $val :
$default;
431 $ps_prefix_len = strlen($ps_prefix);
434 $q =
"SELECT * FROM {$db_prefix}private_settings 435 WHERE entity_guid = {$user->guid} 436 AND name LIKE '$ps_prefix%'";
438 $private_settings = $this->
getDatabase()->getData($q);
442 if ($private_settings) {
443 foreach ($private_settings as $setting) {
444 $name = substr($setting->name, $ps_prefix_len);
481 'plugin_id' => $this->
getID(),
534 $q =
"DELETE FROM {$db_prefix}private_settings 535 WHERE entity_guid = $user_guid 536 AND name LIKE '$ps_prefix%'";
553 $q =
"DELETE FROM {$db_prefix}private_settings 554 WHERE name LIKE '$ps_prefix%'";
571 if (!$this->
getID()) {
572 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:MissingID', array($this->guid));
577 $this->errorMsg =
_elgg_services()->translator->translate(
'ElggPlugin:NoPluginPackagePackage', array($this->
getID(), $this->guid));
582 $this->errorMsg = $this->
getPackage()->getError();
626 $this->errorMsg = $this->
getPackage()->getError();
654 if ($this->setStatus(
true, $site_guid)) {
659 'plugin_id' => $this->
getID(),
660 'plugin_entity' => $this,
672 $this->
start($flags);
701 'plugin_id' => $this->
getID(),
702 'plugin_entity' => $this,
717 return $this->setStatus(
false, $site_guid);
766 if (null === $wrapper) {
768 $warning =
'Do not rely on local $CONFIG being available in start.php';
769 $wrapper = new \Elgg\DeprecationWrapper($CONFIG, $warning,
"1.10");
786 $CONFIG = self::getConfigWrapper();
789 $filepath =
"$this->path/$filename";
792 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:CannotIncludeFile',
794 throw new \PluginException($msg);
797 return include $filepath;
818 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:CannotRegisterViews',
819 array($this->
getID(), $this->guid, $failed_dir));
820 throw new \PluginException($msg);
831 $languages_path =
"$this->path/languages";
834 if (!is_dir($languages_path)) {
839 if (!
_elgg_services()->translator->registerTranslations($languages_path)) {
840 $msg =
_elgg_services()->translator->translate(
'ElggPlugin:Exception:CannotRegisterLanguages',
841 array($this->
getID(), $this->guid, $languages_path));
842 throw new \PluginException($msg);
855 $classes_path =
"$this->path/classes";
857 if (is_dir($classes_path)) {
872 if (strstr(
$name,
'plugin:setting:')) {
873 $msg =
'Direct access of user settings is deprecated. Use ElggPlugin->getUserSetting()';
875 $name = str_replace(
'plugin:setting:',
'',
$name);
880 if (array_key_exists(
$name, $this->attributes)) {
881 return $this->attributes[
$name];
889 if ($meta ===
false) {
919 if (array_key_exists(
$name, $this->attributes)) {
921 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
956 private function setStatus(
$active, $site_guid = null) {
988 return $this->errorMsg;
998 return $this->manifest;
1002 $this->manifest = $this->
getPackage()->getManifest();
1004 _elgg_services()->logger->warn(
"Failed to load manifest for plugin $this->guid. " . $e->getMessage());
1005 $this->errorMsg = $e->getmessage();
1008 return $this->manifest;
1018 return $this->package;
1022 $this->
package = new \ElggPluginPackage($this->path, false);
1024 _elgg_services()->logger->warn(
"Failed to load package for $this->guid. " . $e->getMessage());
1025 $this->errorMsg = $e->getmessage();
1028 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.
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
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.
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.
canActivate($site_guid=null)
Checks if this plugin can be activated on the current Elgg installation.
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.
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.
$CONFIG views
Holds information about views.
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)
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_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.
elgg river item elgg form comment save
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.
__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.
getManifest()
Returns this plugin's object.
__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.
if(!$collection_name) $id
getPath()
Returns the plugin's full path with trailing slash.
if(!$num_display) $db_prefix
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.