Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Plugins_lib {
- /**
- * Instance of this class (CI basically initiates all models/libs as
- * singletons, so essentially, this is a reference to a singleton
- * @var object
- */
- public static $instance;
- /**
- * Static CI reference property
- * @var object
- */
- private static $CI;
- /**
- * Plugins Model
- * @var object
- */
- private static $PM;
- /**
- * Plugin Path - Specified in config plugin_path
- * @var string
- */
- private static $plugin_path;
- /**
- * Plugin messages (Errors, debugging, warnings)
- * @var array
- */
- private static $messages;
- /**
- * Plugins List
- * @var array
- */
- public static $plugins;
- /**
- * Array of active plugins - This is a reference of $plugins['enabled']
- * @var array
- */
- public static $enabled_plugins;
- /**
- * Actions/Filters to run
- * @var array
- */
- public static $actions = array();
- /**
- * Current tag being executed
- * @var string
- */
- public static $current_action;
- /**
- * Previously executed tags
- * @var array
- */
- public static $run_actions = array();
- // ------------------------------------------------------------------------
- /**
- * Plugin Constructor
- *
- * Constructor performs...
- * - Set $CI Reference
- * - Load Plugins Model
- * - Set the plugin directory
- * - Get plugins from DB and include enabled plugins
- * - Load the plugins by initializing the plugin Classes
- *
- * @access public
- */
- public function __construct()
- {
- // Codeigniter instance
- static::$CI =& get_instance();
- // Set a static handler for the instance (So it can be called outside of CI classes, IE: below)
- // No real need to setup a singleton with CI....
- static::$instance = $this;
- // Load the plugins model, if loaded by autoloader, it
- static::$CI->load->model('Plugins_model');
- // Set a shorter handle for the plugins model
- static::$PM = static::$CI->Plugins_model;
- static::$messages = array(
- 'error' => [],
- 'debug' => [],
- 'warn' => []
- );
- // Set plugin path
- $this->set_plugin_dir();
- // Get all activated plugins
- $this->get_plugins();
- // Include plugins
- $this->include_enabled_plugins();
- // Load them
- $this->load_enabled_plugins();
- }
- // ------------------------------------------------------------------------
- /**
- * Set Plugin Directory
- *
- * Set the plugins directory that contains all the plugin folders, at the local
- * private property: static::$plugin_path
- *
- * @param str $dir Directory, an ending slash is appended if not found, and any
- * accidental double slashes are replaced with single slashes
- * @access private
- */
- private function set_plugin_dir()
- {
- if($path = static::$CI->config->item('plugin_path'))
- {
- $this->debug("Plugin path set to {$path} via config setting");
- }
- elseif(defined('PLUGIN_DIR'))
- {
- $this->debug("Plugin path set to ".PLUGIN_DIR."via constant PLUGIN_DIR");
- $path = PLUGIN_DIR;
- }
- else
- {
- $path = FCPATH . 'plugins/';
- $this->debug("Plugin path defaulted to {$path}");
- $this->warn("No plugin path specified in CI settings or PLUGIN_DIR constant, defaulting to {$path}");
- }
- // Make sure it ends in /
- if( ! preg_match('%/$%', $path))
- {
- $path = "{$path}/";
- }
- static::$plugin_path = str_replace('//','/',$path);
- }
- // ------------------------------------------------------------------------
- /**
- * View Controller
- *
- * View the controller from the plugin.
- *
- * @param string $plugin Systen name of plugin
- * @param mixed $plugin_data Any data to hand down to the plugin (Anything
- * processed from the controller, etc)
- * @access public
- * @return string Whatever content is returned from the plugins controller (which
- * is usually HTML from the settings form)
- */
- public function view_controller($plugin, $plugin_data = NULL)
- {
- if( ! isset(static::$plugins[$plugin]))
- {
- Logger_lib::error("The plugin {$plugin} was not found");
- return FALSE;
- }
- elseif( ! method_exists(static::$plugins[$plugin]['handler'], 'controller'))
- {
- App_lib::add_notification('error','Plugin Error',"The plugin {$plugin} does not have a controller", TRUE);
- return FALSE;
- }
- return call_user_func(array(static::$plugins[$plugin]['handler'], 'controller'), $plugin_data);
- }
- // ------------------------------------------------------------------------
- /**
- * Plugin Error Collector
- *
- * Push an error message into the messages array
- *
- * @param str $message Message to push
- * @access private
- */
- private function error($message)
- {
- log_message('error', 'PLUGIN-ERROR: ' . $message);
- array_push(static::$messages['error'], $message);
- }
- // ------------------------------------------------------------------------
- /**
- * Plugin Debug Collector
- *
- * Push a debug message into the messages array
- *
- * @param str $message Message to push
- * @access private
- */
- private function debug($message)
- {
- log_message('debug', 'PLUGIN-DEBUG: ' . $message);
- array_push(static::$messages['debug'], $message);
- }
- // ------------------------------------------------------------------------
- /**
- * Plugin Warn Collector
- *
- * Push a warn message into the messages array
- *
- * @param str $message Message to push
- * @access private
- */
- private function warn($message)
- {
- log_message('error', 'PLUGIN-WARN: ' . $message);
- array_push(static::$messages['warn'], $message);
- }
- // ------------------------------------------------------------------------
- /**
- * Enable Plugin
- *
- * Enable a plugin by setting the plugins.status to 1 in the plugins table
- *
- * @oaram string $plugin Plugin Name
- * @param mixed $data Any data that should be handed down to the plugins deactivate method (optional)
- * @access public
- * @return bool
- */
- public function enable_plugin($plugin, $data = NULL)
- {
- // Run the plugins activation method to run anything required by the plugin
- call_user_func(array(static::$plugins[$plugin]['handler'], 'activate'), $data);
- // Enable it in the database
- return static::$PM->set_status($plugin, 1);
- }
- // ------------------------------------------------------------------------
- /**
- * Disable Plugin
- *
- * Disable a plugin by setting the plugins.status to 0 in the plugins table
- *
- * @oaram string $plugin Plugin Name
- * @param mixed $data Any data that should be handed down to the plugins activate method (optional)
- * @access public
- * @return bool
- */
- public function disable_plugin($plugin, $data = NULL)
- {
- // Run the plugins deactivation method to run anything required by the plugin
- call_user_func(array(static::$plugins[$plugin]['handler'], 'deactivate'), $data);
- // Disable it in the database
- return static::$PM->set_status($plugin, 0);
- }
- // ------------------------------------------------------------------------
- /**
- * Install Plugin
- *
- * Install a plugin by adding it to the database and executing any installation code thats in
- * the plugins install method
- *
- * @param string $plugin Plugins system name (Folder name)
- * @access public
- * @param boolean
- */
- public function install_plugin($plugin, $data = NULL)
- {
- // System name for folder and file
- $system_name = strtolower($plugin);
- // Class name is just system name with ucfirst
- $class_name = ucfirst($system_name);
- $plugin_path = static::$plugin_path . "{$system_name}/{$system_name}.php";
- // If the plugins class hasnt been loaded...
- if( ! class_exists($class_name))
- {
- // Make sure a valid plugin file by the same name as the folder exists
- if (file_exists($plugin_path))
- {
- if( ! include_once $plugin_path)
- {
- $this->error("Failed to install {$plugin}, there was an error loading the plugin file {$plugin_path}, is it readable?");
- }
- else
- {
- $this->debug("Successfully loaded the plugin file {$plugin_path}");
- }
- }
- else
- {
- $this->error("Failed to install {$plugin}, unable to find the file {$plugin_path}");
- }
- }
- // Execute the plugin installation
- return call_user_func("{$class_name}::install", $data);
- }
- // ------------------------------------------------------------------------
- /**
- * Plugin Details
- *
- * Retrieve the details of a plugin from the database
- *
- * @param string $plugin Plugin system name
- * @access public
- * @return object|bool
- */
- public function plugin_details($plugin)
- {
- return static::$PM->get_plugin($plugin);
- }
- // ------------------------------------------------------------------------
- /**
- * Get Enabled Plugins
- *
- * Retrieve the enabled plugins from the database and load them into the enabled_plugins
- * array. This does not initiate the plugins, thats done in a different method
- *
- * @access private
- */
- private function get_plugins()
- {
- // Fetch all plugins
- if( ! $plugins = static::$PM->get_plugins())
- {
- return FALSE;
- }
- // Load the plugins
- foreach($plugins as $p)
- {
- if( ! isset( static::$plugins[ $p->system_name ] ) )
- {
- $this->debug( "Adding plugin {$p->system_name}" );
- static::$plugins[$p->system_name] = array(
- 'data' => $p->data
- );
- // If its enabled, add it to $enabled_plugins referencing the plugin in $plugins
- if($p->status == '1')
- {
- $this->debug( "Enabling plugin {$p->system_name}" );
- static::$enabled_plugins[ $p->system_name ] = &static::$plugins[$p->system_name];
- }
- }
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Print Plugins
- *
- * Retrieve all plugin information from the database
- *
- * @access public
- * @return array
- */
- public function retrieve_plugins()
- {
- return static::$PM->get_plugins();
- }
- // ------------------------------------------------------------------------
- /**
- * Include Enabled Plugins
- *
- * Iterate through the enabled_plugins property array and include the actual plugin files
- *
- * @access private
- */
- private function include_enabled_plugins()
- {
- if(empty(static::$enabled_plugins))
- {
- $this->error("Unable to include enabled plugin files, enabled plugins not retrieved");
- return FALSE;
- }
- foreach(static::$enabled_plugins as $name => $p)
- {
- $plugin_path = static::$plugin_path . "{$name}/{$name}.php";
- // Make sure a valid plugin file by the same name as the folder exists
- if (file_exists($plugin_path))
- {
- if( ! include_once $plugin_path)
- {
- $this->error("There was an error loading the plugin file {$plugin_path}");
- }
- else
- {
- $this->debug("Successfully loaded the plugin file {$plugin_path}");
- }
- }
- else
- {
- $this->error("Failed to include the plugin {$name}, unable to find the file {$plugin_path}");
- }
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Load Enabled Plugins
- *
- * Load the enabled plugins into objects, store the objects into the loaded plugins array
- *
- * @access private
- */
- private function load_enabled_plugins()
- {
- foreach(static::$enabled_plugins as $name => $p)
- {
- new $name;
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Add Action
- *
- * Assign a function to be executed by a certain tag. An action will just fire off a function
- * when the tag is called, a filter will parse data and return the modified data
- *
- * @param string $tag Tag to add filter to
- * @param string|array $function Either a string (function), or an array (Object, method)
- * @param int $priority Priority
- * @param string $type Either action or filter
- * @access public
- * @return bool
- */
- public function add_action($tag, $function, $priority = 10, $type = 'action')
- {
- if(is_array($function))
- {
- if(count($function) < 2)
- {
- // If its an array of one element, then just add the first element
- $function = $function[0];
- }
- elseif( ! is_object($function[0]))
- {
- $this->error("Failing to add method '" . implode('::', $function) . "'' as {$type} to tag {$tag}, an array was given, first element was not an object");
- return FALSE;
- }
- elseif( ! method_exists($function[0], $function[1]))
- {
- $this->error("Failing to add method '" . get_class($function[0]) . "::{$function[1]}' as {$type} to tag {$tag}, the method does not exist");
- return FALSE;
- }
- }
- // Execute is_array again, since the above could have converted it to an array
- if( ! is_array($function))
- {
- if( ! function_exists($function))
- {
- $this->error("Failing to add function {$function} as {$type} to tag {$tag}, the function does not exist");
- return FALSE;
- }
- }
- if( ! in_array($type, ['action','filter']))
- {
- $this->error("Unknown type '{$type}', must be 'filter' or 'action'");
- return FALSE;
- }
- static::$actions[$tag][$priority][] = array(
- 'function' => $function,
- 'type' => $type
- );
- return TRUE;
- }
- // ------------------------------------------------------------------------
- /**
- * Add Filter
- *
- * Just a wrapper for add_function except adds it as type 'filter'. Filters will
- * take in data and perform an action on it, then return it, actions will just
- * fire off a function
- *
- * @param string $tag Tag to add filter to
- * @param string|array $function Either a string (function), or an array (Object, method)
- * @param int $priority Priority
- * @access public
- * @return bool
- */
- public function add_filter($tag, $function, $priority = 10)
- {
- return $this->add_action($tag, $function, $priority, 'filter');
- }
- // ------------------------------------------------------------------------
- /**
- * Get Actions
- *
- * Get actions....
- *
- * @access public
- * @return array
- */
- public function get_actions()
- {
- foreach(static::$actions as $k => $a)
- ksort(static::$actions[$k]);
- return static::$actions;
- }
- // ------------------------------------------------------------------------
- /**
- * Do Action
- *
- * Execute a specific action, pass optional arguments to it
- * @param string $tag Tag to execute
- * @param null $args Arguments to hand to functions assigned to tag
- * @access public
- * @return mixed Returns whatever the type of $args is
- * @todo This seems broken, when asset.(edit|create).post array is filtered, it returns a single value
- */
- public function do_action($tag, $args = NULL)
- {
- static::$current_action = $tag;
- array_push(static::$run_actions, $tag);
- if( ! isset(static::$actions[$tag]))
- {
- $this->debug("No actions found for tag {$tag}");
- return $args;
- }
- ksort(static::$actions[$tag]);
- //die('<pre>' . print_r(static::$actions, TRUE));
- foreach(static::$actions[$tag] as $actions)
- {
- foreach($actions as $a)
- {
- // Make sure the function or method exists
- if(is_array($a['function']))
- {
- // Methods are setup as an array, [0] is the object/class, [1] is the method
- if( ! method_exists($a['function'][0], $a['function'][1]))
- {
- $this->error("Unable to execute method '" . get_class($a['function'][0]) . "::{$a['function'][1]}' for action {$tag}, the method doesn't exist");
- return $args;
- }
- }
- else
- {
- // Strings are just functions
- if( ! function_exists($a['function']))
- {
- $this->error("Unable to execute function '{$a['function']}' for action {$tag}, the function doesn't exist");
- return $args;
- }
- }
- // Actions
- if($a['type'] == 'action')
- {
- // No arguments/null
- if(is_null($args))
- {
- call_user_func( $a['function'] );
- }
- // Single argument
- else
- {
- call_user_func( $a['function'], $args );
- }
- }
- // Filters
- else
- {
- // No arguments/null
- if(is_null($args))
- {
- $args = call_user_func( $a['function'] );
- }
- else
- {
- $args = call_user_func( $a['function'], $args );
- }
- }
- }
- }
- static::$current_action = NULL;
- // Be polite, return it as you found it
- settype($args, gettype($args));
- return $args;
- }
- // ------------------------------------------------------------------------
- /**
- * Remove Action
- *
- * Remove a function from an action
- *
- * @param string $tag Tag to check in
- * @param mixed $function Function to be removed
- * @param int $priority Priority to check for function
- * @todo This was copied from the old POS plugins library, where the functions were strings, now they are arrays of objects/functions, so this needs to check for that Maybe it should check if $function is array, if so, iterate through $actions, if($a[0] instanceof $function[0] and $a[1] == $function[1], remove
- * @access public
- * @return bool
- */
- public function remove_action($tag, $function, $priority = 10)
- {
- if (isset(static::$actions[$tag][$priority][$function]))
- {
- // Remove the action hook from our hooks array
- unset(static::$actions[$tag][$priority][$function]);
- }
- return TRUE;
- }
- // ------------------------------------------------------------------------
- /**
- * Current Action
- *
- * Set the currently running action
- *
- * @access public
- * @return string
- */
- public function current_action()
- {
- return static::$current_action;
- }
- // ------------------------------------------------------------------------
- /**
- * Has Run
- *
- * See if a particular action has ran yet
- *
- * @param string $action Action to check for
- * @access public
- * @return boolean
- */
- public function has_run($action)
- {
- if (isset(static::$run_actions[$action]))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Update Plugin Headers
- *
- * Parse a given plugins PHP file for the header information in the comments, and update the database info
- * accordingly
- *
- * @param string $plugin Plugin System Name to check
- * @access public
- * @todo Try to retrieve only the top X lines of the file, not the whole file
- * @return TRUE Always true
- */
- public function update_plugin_headers($plugin)
- {
- if (isset(static::$plugins[$plugin]))
- {
- $arr = array();
- $plugin_data = file_get_contents(static::$plugin_path.$plugin."/".$plugin.".php"); // Load the plugin we want
- preg_match ('|Plugin Name:(.*)$|mi', $plugin_data, $name);
- preg_match ('|Plugin URI:(.*)$|mi', $plugin_data, $uri);
- preg_match ('|Version:(.*)|i', $plugin_data, $version);
- preg_match ('|Description:(.*)$|mi', $plugin_data, $description);
- preg_match ('|Author:(.*)$|mi', $plugin_data, $author_name);
- preg_match ('|Author URI:(.*)$|mi', $plugin_data, $author_uri);
- if (isset($name[1]))
- {
- $arr['name'] = trim($name[1]);
- }
- if (isset($uri[1]))
- {
- $arr['uri'] = trim($uri[1]);
- }
- if (isset($version[1]))
- {
- $arr['version'] = trim($version[1]);
- }
- if (isset($description[1]))
- {
- $arr['description'] = trim($description[1]);
- }
- if (isset($author_name[1]))
- {
- $arr['author'] = trim($author_name[1]);
- }
- if (isset($author_uri[1]))
- {
- $arr['author_uri'] = trim($author_uri[1]);
- }
- if(empty($arr))
- {
- $this->warn("Skipping header update for {$plugin}, no headers matched");
- }
- elseif(self::$PM->update_plugin_info($plugin, $arr))
- {
- $this->debug("Updated plugin headers for {$plugin}: " . serialize($arr));
- }
- else
- {
- $this->error("Failed to update plugin headers for {$plugin}: " . serialize($arr));
- }
- }
- return TRUE;
- }
- // ------------------------------------------------------------------------
- /**
- * Update All Plugin Headers
- *
- * Execute self::update_plugin_headers for each plugin found in static::$plugins
- *
- * @access public
- * @return boolean
- */
- public function update_all_plugin_headers()
- {
- if(empty(static::$plugins))
- {
- $this->warn("No plugins to update headers for");
- return TRUE;
- }
- foreach(static::$plugins as $name => $plugin)
- {
- $this->debug("Updating plugin headers for {$name}");
- if( ! $this->update_plugin_headers($name))
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- // ------------------------------------------------------------------------
- /**
- * Doing Action
- *
- * If the param is NULL, then this will return what action is being executed,
- * if an action is supplied, then it will return boolean based on if that action
- * is being executed or not
- *
- * @param null $action Action to check for
- */
- public function doing_action($action = NULL)
- {
- if(is_null($action))
- {
- return static::$current_action;
- }
- else
- {
- return $action === static::$current_action;
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Did Action
- *
- * Returns if a tag has been fired or not
- *
- * @param $tag
- */
- public function did_action($tag)
- {
- return in_array($tag, static::$run_actions);
- }
- // ------------------------------------------------------------------------
- /**
- * Get Class Usages
- *
- * Parse through the plugins .php code to check for any classes that it
- * attempts to use, returns an array of class names
- *
- * @param string $plugin System name of plugin (NOT display name)
- * @access public
- * @return array
- * @todo This needs to be finished and more solid/stable
- */
- public function get_class_usages($plugin)
- {
- // Get the base path of the plugin
- $plugin_path = "/" . static::$plugin_path . "/{$plugin}/";
- // Should get re-defined once class_profiles.php loads
- $classes = NULL;
- // An array of class names and their data
- require_once APPPATH . 'libraries/class_profiles.php';
- //die('CLASSES:<pre>' . print_r($classes, TRUE));
- $files = array();
- if( ! $dir = @new RecursiveDirectoryIterator( realpath($plugin_path) ))
- {
- Logger_lib::error("Failed to read from plugin path: {$plugin_path}", TRUE, TRUE);
- return FALSE;
- }
- $objects = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
- foreach($objects as $name => $object)
- {
- if(preg_match('/\.php$/', $name))
- {
- array_push($files, $name);
- }
- }
- $matches = array();
- foreach($files as $f)
- {
- $line_num = 0;
- if( ! $fh = @fopen($f, 'r'))
- {
- Logger_lib::error("Failed to open plugin file for parsing: {$f}", TRUE, TRUE);
- return FALSE;
- }
- $file_lines = array();
- while ( ! feof($fh))
- {
- $line_num++;
- $line = fgets($fh, 4096);
- $file_lines[] = trim($line);
- foreach($classes as $c => $d) // Classes is defined in class_profiles.php
- {
- if (preg_match('/' . $d['regex'] . '/', $line)) {
- $matches[$c][] = array(
- 'file' => $f,
- 'class' => $d['class'],
- 'line_num' => $line_num,
- 'line' => trim($line)
- );
- }
- }
- }
- fclose($fh);
- }
- return $matches;
- }
- // ------------------------------------------------------------------------
- /**
- * Get Orphaned Plugins
- *
- * Look in the plugin directory for any folders that do not have an associated entry
- * in the plugins table
- *
- * @access public
- * @return array|bool If no orphaned plugins are found, return false
- */
- public function get_orphaned_plugins()
- {
- $files = scandir(static::$plugin_path);
- $plugins = static::$PM->get_plugins();
- $orphaned = array();
- foreach($files as $f)
- {
- // Skip directories
- if(in_array($f, ['.','..'])) continue;
- if( ! isset($plugins[$f]))
- {
- array_push($orphaned, $f);
- }
- }
- return (count($orphaned) > 0 ? $orphaned : FALSE);
- }
- // ------------------------------------------------------------------------
- /**
- * Get Messages
- *
- * Get all messages, or a specific type of message
- *
- * @param string $type Type of error to retrieve (error, debug, warn)
- * @access public
- * @return array|bool
- */
- public function get_messages($type = NULL)
- {
- if( ! $type)
- {
- return static::$messages;
- }
- elseif( ! isset(static::$messages[ strtolower($type) ]))
- {
- $this->error("Failed to retrieve error type '{$type}', no such type found. Use 'error', 'warn' or 'debug'");
- return FALSE;
- }
- return static::$messages[strtolower($type)];
- }
- // ------------------------------------------------------------------------
- /**
- * Print Messages
- *
- * Print all messages, or messages of a certain type
- *
- * @param string $type Type of error to display (error, debug, warn)
- * @access public
- * @return array|bool
- */
- public function print_messages($type = NULL)
- {
- if($type)
- {
- if(@empty(static::$messages[ strtolower($type) ]) || ! isset(static::$messages[ strtolower($type) ]))
- {
- echo "{$type} IS EMPTY\n";
- return TRUE;
- }
- echo "<h3>Plugin Messages - <strong>" . ucfirst($type) . "</strong></h3>\n";
- echo "<ol>\n";
- foreach(static::$messages[ strtolower($type) ] as $m)
- {
- echo "<li>$m</li>\n";
- }
- echo "</ol>\n</hr>\n";
- return TRUE;
- }
- foreach(static::$messages as $type => $messages)
- {
- if(@empty($messages))
- {
- echo "{$type} IS EMPTY\n";
- continue;
- }
- echo "<h3>Plugin Messages - <strong>" . ucfirst($type) . "</strong></h3>\n";
- echo "<ol>\n";
- foreach($messages as $m)
- {
- echo "<li>$m</li>\n";
- }
- echo "</ol>\n</hr>\n";
- }
- return TRUE;
- }
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::update_all_plugin_headers()
- *
- * Executes update_plugin_headers() for all plugins in database
- *
- * @return bool
- */
- function update_all_plugin_headers()
- {
- return Plugins_lib::$instance->update_all_plugin_headers();
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::update_plugin_headers()
- *
- * Updates the plugin headers for a specified plugin based on the plugins .php file comments
- *
- * @param string $plugin Plugin system name
- * @return bool
- */
- function update_plugin_headers($plugin)
- {
- return Plugins_lib::$instance->update_plugin_headers($plugin);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::install_plugin()
- *
- * Executes whatevers in the plugins install method
- *
- * @param string $plugin Plugin system name
- * @return bool
- */
- function install_plugin($plugin, $data = NULL)
- {
- return Plugins_lib::$instance->install_plugin($plugin, $data);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::enable_plugin()
- *
- * Enable a specified plugin by setting the database status value to 1
- *
- * @param string $plugin Plugin system name
- * @param mixed $data Any data that should be handed down to the plugins activation method (optional)
- * @return bool
- */
- function enable_plugin($plugin, $data = NULL)
- {
- return Plugins_lib::$instance->enable_plugin($plugin, $data);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::disable_plugin()
- *
- * Disable a specified plugin by setting the database status value to 0
- *
- * @param string $plugin Plugin system name
- * @param mixed $data Any data that should be handed down to the plugins deactivate method (optional)
- * @return bool
- */
- function disable_plugin($plugin, $data = NULL)
- {
- return Plugins_lib::$instance->disable_plugin($plugin, $data);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::plugin_details()
- *
- * Return the details of a plugin from the plugins database table
- *
- * @param string $plugin Plugin system name
- * @return array
- */
- function plugin_details($plugin)
- {
- return Plugins_lib::$instance->plugin_details($plugin);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::get_messages()
- *
- * Gets all the plugin messages thus far (errors, debug messages, warnings)
- *
- * @param string $type Specific type to retrieve, if NULL, all are returned
- * @return array
- */
- function get_messages($type = NULL)
- {
- return Plugins_lib::$instance->get_messages($type);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::print_messages()
- *
- * Displays all the plugin messages thus far (errors, debug messages, warnings)
- *
- * @param string $type Specific type to retrieve, if NULL, all are printed
- * @return array
- */
- function print_messages($type = NULL)
- {
- return Plugins_lib::$instance->print_messages($type);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::get_orphaned_plugins()
- *
- * See if there are any plugins in the plugins directory that arent in the database
- *
- * @return array
- */
- function get_orphaned_plugins()
- {
- return Plugins_lib::$instance->get_orphaned_plugins();
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::add_action()
- *
- * Add an action - a function that will fire off when a tag/action is executed (NOT
- * the same as add_filter - which will return a value
- *
- * @param string $tag Tag/Action thats being executed
- * @param string|array $function Either a single function (string), or a class and method (array)
- * @param int $priority Priority of this action
- * @return boolean
- */
- function add_action($tag, $function, $priority = 10)
- {
- return Plugins_lib::$instance->add_action($tag, $function, $priority);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::add_filter()
- *
- * Add a filter - a function that can be used to effect/parse/filter out some content (NOT
- * the same as add_action - which will just fire off a function
- *
- * @param string $tag Tag/Action thats being executed
- * @param string|array $function Either a single function (string), or a class and method (array)
- * @param int $priority Priority of this action
- * @return boolean
- */
- function add_filter($tag, $function, $priority = 10)
- {
- return Plugins_lib::$instance->add_filter($tag, $function, $priority);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::get_actions()
- *
- * Retrieve all actions/filters that are assigned to actions/tags
- *
- * @return array
- */
- function get_actions()
- {
- return Plugins_lib::$instance->get_actions();
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::retrieve_plugins()
- *
- * Retrieve all plugins
- *
- * @return array
- */
- function retrieve_plugins()
- {
- return Plugins_lib::$instance->retrieve_plugins();
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::do_action()
- *
- * Execute all plugin functions tied to a specific tag
- *
- * @param string $tag Tag to execute
- * @param mixed $args Arguments to hand to plugin (Can be anything)
- * @return mixed
- */
- function do_action($tag, $args = NULL)
- {
- return Plugins_lib::$instance->do_action($tag, $args);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::remove_action()
- *
- * Remove a specific plugin function assigned to execute on a specific tag at a specific priority
- *
- * @param string $tag Tag to clear actions from
- * @param string|array $function Function or object/method to remove from tag
- * @param int $priority Priority to clear
- * @return boolean
- */
- function remove_action($tag, $function, $priority = 10)
- {
- return Plugins_lib::$instance->remove_action($tag, $function, $priority);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::current_action()
- *
- * Get the current plugin action being executed
- *
- * @return string
- */
- function current_action()
- {
- return Plugins_lib::$instance->current_action();
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::has_run()
- *
- * See if an action has run or not
- *
- * @param string $action Tag/action to check
- * @return boolean
- */
- function has_run($action = NULL)
- {
- return Plugins_lib::$instance->has_run($action);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::doing_action()
- *
- * If no action is specified, then the current action being executed will be returned, if
- * an action is specified, then TRUE/FALSE will be returned based on if the action is
- * being executed or not
- *
- * @oaran string $action Action to check
- * @return boolean|string
- */
- function doing_action($action = NULL)
- {
- return Plugins_lib::$instance->doing_action($action);
- }
- // ------------------------------------------------------------------------
- /**
- * Shortcut to Plugins_lib::did_action()
- *
- * Check if an action/tag has been executed or not
- *
- * @param string $tag Tag/action to check
- * @return boolean
- */
- function did_action($tag)
- {
- return Plugins_lib::$instance->did_action($tag);
- }
Advertisement
Add Comment
Please, Sign In to add comment