1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, 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.
23 * @package CodeIgniter
24 * @subpackage Libraries
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/libraries/encryption.html
33 var $in_progress = FALSE;
39 function __construct()
42 log_message('debug', "Hooks Class Initialized");
45 // --------------------------------------------------------------------
48 * Initialize the Hooks Preferences
53 function _initialize()
55 $CFG =& load_class('Config', 'core');
57 // If hooks are not enabled in the config file
58 // there is nothing else to do
60 if ($CFG->item('enable_hooks') == FALSE)
65 // Grab the "hooks" definition file.
66 // If there are no hooks, we're done.
68 if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT))
70 include(APPPATH.'config/'.ENVIRONMENT.'/hooks'.EXT);
72 elseif (is_file(APPPATH.'config/hooks'.EXT))
74 include(APPPATH.'config/hooks'.EXT);
78 if ( ! isset($hook) OR ! is_array($hook))
83 $this->hooks =& $hook;
84 $this->enabled = TRUE;
87 // --------------------------------------------------------------------
92 * Calls a particular hook
95 * @param string the hook name
98 function _call_hook($which = '')
100 if ( ! $this->enabled OR ! isset($this->hooks[$which]))
105 if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
107 foreach ($this->hooks[$which] as $val)
109 $this->_run_hook($val);
114 $this->_run_hook($this->hooks[$which]);
120 // --------------------------------------------------------------------
125 * Runs a particular hook
128 * @param array the hook details
131 function _run_hook($data)
133 if ( ! is_array($data))
138 // -----------------------------------
139 // Safety - Prevents run-away loops
140 // -----------------------------------
142 // If the script being called happens to have the same
143 // hook call within it a loop can happen
145 if ($this->in_progress == TRUE)
150 // -----------------------------------
152 // -----------------------------------
154 if ( ! isset($data['filepath']) OR ! isset($data['filename']))
159 $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
161 if ( ! file_exists($filepath))
166 // -----------------------------------
167 // Set class/function name
168 // -----------------------------------
174 if (isset($data['class']) AND $data['class'] != '')
176 $class = $data['class'];
179 if (isset($data['function']))
181 $function = $data['function'];
184 if (isset($data['params']))
186 $params = $data['params'];
189 if ($class === FALSE AND $function === FALSE)
194 // -----------------------------------
195 // Set the in_progress flag
196 // -----------------------------------
198 $this->in_progress = TRUE;
200 // -----------------------------------
201 // Call the requested class and/or function
202 // -----------------------------------
204 if ($class !== FALSE)
206 if ( ! class_exists($class))
212 $HOOK->$function($params);
216 if ( ! function_exists($function))
224 $this->in_progress = FALSE;
230 // END CI_Hooks class
232 /* End of file Hooks.php */
233 /* Location: ./system/core/Hooks.php */