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
32
* Determines wether hooks are enabled
38
* List of all hooks set in config/hooks.php
44
* Determines wether hook is in progress, used to prevent infinte loops
48
var $in_progress = FALSE;
54
function __construct()
57
log_message('debug', "Hooks Class Initialized");
60
// --------------------------------------------------------------------
63
* Initialize the Hooks Preferences
68
function _initialize()
70
$CFG =& load_class('Config', 'core');
72
// If hooks are not enabled in the config file
73
// there is nothing else to do
75
if ($CFG->item('enable_hooks') == FALSE)
80
// Grab the "hooks" definition file.
81
// If there are no hooks, we're done.
83
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
85
include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
87
elseif (is_file(APPPATH.'config/hooks.php'))
89
include(APPPATH.'config/hooks.php');
93
if ( ! isset($hook) OR ! is_array($hook))
98
$this->hooks =& $hook;
99
$this->enabled = TRUE;
102
// --------------------------------------------------------------------
107
* Calls a particular hook
110
* @param string the hook name
113
function _call_hook($which = '')
115
if ( ! $this->enabled OR ! isset($this->hooks[$which]))
120
if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
122
foreach ($this->hooks[$which] as $val)
124
$this->_run_hook($val);
129
$this->_run_hook($this->hooks[$which]);
135
// --------------------------------------------------------------------
140
* Runs a particular hook
143
* @param array the hook details
146
function _run_hook($data)
148
if ( ! is_array($data))
153
// -----------------------------------
154
// Safety - Prevents run-away loops
155
// -----------------------------------
157
// If the script being called happens to have the same
158
// hook call within it a loop can happen
160
if ($this->in_progress == TRUE)
165
// -----------------------------------
167
// -----------------------------------
169
if ( ! isset($data['filepath']) OR ! isset($data['filename']))
174
$filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
176
if ( ! file_exists($filepath))
181
// -----------------------------------
182
// Set class/function name
183
// -----------------------------------
189
if (isset($data['class']) AND $data['class'] != '')
191
$class = $data['class'];
194
if (isset($data['function']))
196
$function = $data['function'];
199
if (isset($data['params']))
201
$params = $data['params'];
204
if ($class === FALSE AND $function === FALSE)
209
// -----------------------------------
210
// Set the in_progress flag
211
// -----------------------------------
213
$this->in_progress = TRUE;
215
// -----------------------------------
216
// Call the requested class and/or function
217
// -----------------------------------
219
if ($class !== FALSE)
221
if ( ! class_exists($class))
227
$HOOK->$function($params);
231
if ( ! function_exists($function))
239
$this->in_progress = FALSE;
245
// END CI_Hooks class
247
/* End of file Hooks.php */
248
/* Location: ./system/core/Hooks.php */
b'\\ No newline at end of file'