1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
19 * CodeIgniter Hooks Class
\r
21 * Provides a mechanism to extend the base system without hacking. Most of
\r
22 * this class is borrowed from Paul's Extension class in ExpressionEngine.
\r
24 * @package CodeIgniter
\r
25 * @subpackage Libraries
\r
26 * @category Libraries
\r
27 * @author ExpressionEngine Dev Team
\r
28 * @link http://codeigniter.com/user_guide/libraries/encryption.html
\r
32 var $enabled = FALSE;
\r
33 var $hooks = array();
\r
34 var $in_progress = FALSE;
\r
42 $this->_initialize();
\r
43 log_message('debug', "Hooks Class Initialized");
\r
46 // --------------------------------------------------------------------
\r
49 * Initialize the Hooks Preferences
\r
54 function _initialize()
\r
56 $CFG =& load_class('Config');
\r
58 // If hooks are not enabled in the config file
\r
59 // there is nothing else to do
\r
61 if ($CFG->item('enable_hooks') == FALSE)
\r
66 // Grab the "hooks" definition file.
\r
67 // If there are no hooks, we're done.
\r
69 @include(APPPATH.'config/hooks'.EXT);
\r
71 if ( ! isset($hook) OR ! is_array($hook))
\r
76 $this->hooks =& $hook;
\r
77 $this->enabled = TRUE;
\r
80 // --------------------------------------------------------------------
\r
85 * Calls a particular hook
\r
88 * @param string the hook name
\r
91 function _call_hook($which = '')
\r
93 if ( ! $this->enabled OR ! isset($this->hooks[$which]))
\r
98 if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
\r
100 foreach ($this->hooks[$which] as $val)
\r
102 $this->_run_hook($val);
\r
107 $this->_run_hook($this->hooks[$which]);
\r
113 // --------------------------------------------------------------------
\r
118 * Runs a particular hook
\r
121 * @param array the hook details
\r
124 function _run_hook($data)
\r
126 if ( ! is_array($data))
\r
131 // -----------------------------------
\r
132 // Safety - Prevents run-away loops
\r
133 // -----------------------------------
\r
135 // If the script being called happens to have the same
\r
136 // hook call within it a loop can happen
\r
138 if ($this->in_progress == TRUE)
\r
143 // -----------------------------------
\r
145 // -----------------------------------
\r
147 if ( ! isset($data['filepath']) OR ! isset($data['filename']))
\r
152 $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
\r
154 if ( ! file_exists($filepath))
\r
159 // -----------------------------------
\r
160 // Set class/function name
\r
161 // -----------------------------------
\r
167 if (isset($data['class']) AND $data['class'] != '')
\r
169 $class = $data['class'];
\r
172 if (isset($data['function']))
\r
174 $function = $data['function'];
\r
177 if (isset($data['params']))
\r
179 $params = $data['params'];
\r
182 if ($class === FALSE AND $function === FALSE)
\r
187 // -----------------------------------
\r
188 // Set the in_progress flag
\r
189 // -----------------------------------
\r
191 $this->in_progress = TRUE;
\r
193 // -----------------------------------
\r
194 // Call the requested class and/or function
\r
195 // -----------------------------------
\r
197 if ($class !== FALSE)
\r
199 if ( ! class_exists($class))
\r
201 require($filepath);
\r
204 $HOOK = new $class;
\r
205 $HOOK->$function($params);
\r
209 if ( ! function_exists($function))
\r
211 require($filepath);
\r
214 $function($params);
\r
217 $this->in_progress = FALSE;
\r
223 // END CI_Hooks class
\r
225 /* End of file Hooks.php */
\r
226 /* Location: ./system/libraries/Hooks.php */