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