123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- /**
- * CodeIgniter
- *
- * An open source application development framework for PHP 5.1.6 or newer
- *
- * @package CodeIgniter
- * @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
- * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
- * @since Version 1.0
- * @filesource
- */
- // ------------------------------------------------------------------------
- /**
- * CodeIgniter Hooks Class
- *
- * Provides a mechanism to extend the base system without hacking.
- *
- * @package CodeIgniter
- * @subpackage Libraries
- * @category Libraries
- * @author EllisLab Dev Team
- * @link http://codeigniter.com/user_guide/libraries/encryption.html
- */
- class CI_Hooks {
- /**
- * Determines wether hooks are enabled
- *
- * @var bool
- */
- var $enabled = FALSE;
- /**
- * List of all hooks set in config/hooks.php
- *
- * @var array
- */
- var $hooks = array();
- /**
- * Determines wether hook is in progress, used to prevent infinte loops
- *
- * @var bool
- */
- var $in_progress = FALSE;
- /**
- * Constructor
- *
- */
- function __construct()
- {
- $this->_initialize();
- log_message('debug', "Hooks Class Initialized");
- }
- // --------------------------------------------------------------------
- /**
- * Initialize the Hooks Preferences
- *
- * @access private
- * @return void
- */
- function _initialize()
- {
- $CFG =& load_class('Config', 'core');
- // If hooks are not enabled in the config file
- // there is nothing else to do
- if ($CFG->item('enable_hooks') == FALSE)
- {
- return;
- }
- // Grab the "hooks" definition file.
- // If there are no hooks, we're done.
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
- {
- include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
- }
- elseif (is_file(APPPATH.'config/hooks.php'))
- {
- include(APPPATH.'config/hooks.php');
- }
- if ( ! isset($hook) OR ! is_array($hook))
- {
- return;
- }
- $this->hooks =& $hook;
- $this->enabled = TRUE;
- }
- // --------------------------------------------------------------------
- /**
- * Call Hook
- *
- * Calls a particular hook
- *
- * @access private
- * @param string the hook name
- * @return mixed
- */
- function _call_hook($which = '')
- {
- if ( ! $this->enabled OR ! isset($this->hooks[$which]))
- {
- return FALSE;
- }
- if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
- {
- foreach ($this->hooks[$which] as $val)
- {
- $this->_run_hook($val);
- }
- }
- else
- {
- $this->_run_hook($this->hooks[$which]);
- }
- return TRUE;
- }
- // --------------------------------------------------------------------
- /**
- * Run Hook
- *
- * Runs a particular hook
- *
- * @access private
- * @param array the hook details
- * @return bool
- */
- function _run_hook($data)
- {
- if ( ! is_array($data))
- {
- return FALSE;
- }
- // -----------------------------------
- // Safety - Prevents run-away loops
- // -----------------------------------
- // If the script being called happens to have the same
- // hook call within it a loop can happen
- if ($this->in_progress == TRUE)
- {
- return;
- }
- // -----------------------------------
- // Set file path
- // -----------------------------------
- if ( ! isset($data['filepath']) OR ! isset($data['filename']))
- {
- return FALSE;
- }
- $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
- if ( ! file_exists($filepath))
- {
- return FALSE;
- }
- // -----------------------------------
- // Set class/function name
- // -----------------------------------
- $class = FALSE;
- $function = FALSE;
- $params = '';
- if (isset($data['class']) AND $data['class'] != '')
- {
- $class = $data['class'];
- }
- if (isset($data['function']))
- {
- $function = $data['function'];
- }
- if (isset($data['params']))
- {
- $params = $data['params'];
- }
- if ($class === FALSE AND $function === FALSE)
- {
- return FALSE;
- }
- // -----------------------------------
- // Set the in_progress flag
- // -----------------------------------
- $this->in_progress = TRUE;
- // -----------------------------------
- // Call the requested class and/or function
- // -----------------------------------
- if ($class !== FALSE)
- {
- if ( ! class_exists($class))
- {
- require($filepath);
- }
- $HOOK = new $class;
- $HOOK->$function($params);
- }
- else
- {
- if ( ! function_exists($function))
- {
- require($filepath);
- }
- $function($params);
- }
- $this->in_progress = FALSE;
- return TRUE;
- }
- }
- // END CI_Hooks class
- /* End of file Hooks.php */
- /* Location: ./system/core/Hooks.php */
|