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%'";
428 $ps_prefix_len = strlen($ps_prefix);
431 $q =
"SELECT * FROM {$db_prefix}private_settings 432 WHERE entity_guid = {$user->guid} 433 AND name LIKE '$ps_prefix%'";
435 $private_settings = $this->
getDatabase()->getData($q);
439 if ($private_settings) {
440 foreach ($private_settings as $setting) {
441 $name = substr($setting->name, $ps_prefix_len);
478 'plugin_id' => $this->
getID(),
531 $q =
"DELETE FROM {$db_prefix}private_settings 532 WHERE entity_guid = $user_guid 533 AND name LIKE '$ps_prefix%'";
550 $q =
"DELETE FROM {$db_prefix}private_settings 551 WHERE name LIKE '$ps_prefix%'";
568 if (!$this->
getID()) {
569 $this->errorMsg =
elgg_echo(
'ElggPlugin:MissingID', array($this->guid));
574 $this->errorMsg =
elgg_echo(
'ElggPlugin:NoPluginPackagePackage', array($this->
getID(), $this->guid));
579 $this->errorMsg = $this->
getPackage()->getError();
623 $this->errorMsg = $this->
getPackage()->getError();
651 if ($this->setStatus(
true, $site_guid)) {
656 'plugin_id' => $this->
getID(),
657 'plugin_entity' => $this,
669 $this->
start($flags);
698 'plugin_id' => $this->
getID(),
699 'plugin_entity' => $this,
714 return $this->setStatus(
false, $site_guid);
771 $filepath =
"$this->path/$filename";
774 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotIncludeFile',
779 return include $filepath;
799 $view_dir =
"$this->path/views/";
802 if (!is_dir($view_dir)) {
807 $handle = opendir($view_dir);
809 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterViews',
810 array($this->
getID(), $this->guid, $view_dir));
814 while (
false !== ($view_type = readdir($handle))) {
815 $view_type_dir = $view_dir . $view_type;
817 if (
'.' !== substr($view_type, 0, 1) && is_dir($view_type_dir)) {
821 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterViews',
822 array($this->
getID(), $view_type_dir));
838 $languages_path =
"$this->path/languages";
841 if (!is_dir($languages_path)) {
847 $msg =
elgg_echo(
'ElggPlugin:Exception:CannotRegisterLanguages',
848 array($this->
getID(), $this->guid, $languages_path));
862 $classes_path =
"$this->path/classes";
864 if (is_dir($classes_path)) {
879 if (strstr(
$name,
'plugin:setting:')) {
880 $msg =
'Direct access of user settings is deprecated. Use ElggPlugin->getUserSetting()';
882 $name = str_replace(
'plugin:setting:',
'',
$name);
887 if (array_key_exists(
$name, $this->attributes)) {
888 return $this->attributes[
$name];
896 if ($meta ===
false) {
926 if (array_key_exists(
$name, $this->attributes)) {
928 if ((array_key_exists(
'guid', $this->attributes)) && (
$name ==
'guid')) {
963 private function setStatus(
$active, $site_guid = null) {
995 return $this->errorMsg;
1005 return $this->manifest;
1009 $this->manifest = $this->
getPackage()->getManifest();
1010 }
catch (Exception
$e) {
1011 elgg_log(
"Failed to load manifest for plugin $this->guid. " . $e->getMessage(),
'WARNING');
1012 $this->errorMsg = $e->getmessage();
1015 return $this->manifest;
1025 return $this->package;
1029 $this->
package = new ElggPluginPackage($this->path, false);
1030 }
catch (Exception
$e) {
1031 elgg_log(
"Failed to load package for $this->guid. " . $e->getMessage(),
'WARNING');
1032 $this->errorMsg = $e->getmessage();
1035 return $this->package;
getSetting($name, $default=null)
Returns a plugin setting.
registerViews()
Registers the plugin's views.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
getID()
Returns the ID (dir name) of this plugin.
getDatabase()
Provides a pointer to the database object.
start($flags)
Start the plugin.
getUserSetting($name, $user_guid=0)
Returns a user's setting for this 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.
get_config($name, $site_guid=0)
Gets a configuration value.
load($guid)
Loads the full ElggObject 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 ElggPlugin::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.
autoregister_views($view_base, $folder, $base_location_path, $viewtype)
Auto-registers views from a location.
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.
unsetAllUserSettings($user_guid)
Removes all User Settings for this plugin for a particular user.
getPackage()
Returns this plugin's ElggPluginPackage object.
setUserSetting($name, $value, $user_guid=0)
Sets a user setting for a plugin.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
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 ElggPlugin::start() to include the start.php file.
unsetAllSettings()
Removes all settings for this plugin.
const ELGG_PLUGIN_REGISTER_VIEWS
Tells ElggPlugin::start() to automatically register the plugin's views.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
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)
Sends a notice about deprecated use of a function, view, etc.
elgg global
Pointer to the global context.
elgg river item elgg form comment save
_elgg_cache_plugin_by_id(ElggPlugin $plugin)
Cache a reference to this plugin by its ID.
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.
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 ElggPluginManifest 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.
register_translations($path, $load_all=false)
When given a full path, finds translation files and loads them.
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 ElggPlugin::start() to automatically register the plugin's classes.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
elgg_get_plugins_path()
Get the plugin path for this installation.
_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.
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
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 ElggPlugin object with the path $path.
get_entity($guid)
Loads and returns an entity object from a guid.
elgg_register_viewtype($viewtype)
Register a viewtype.