Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 226 lines (185 sloc) 4.337 kb
b0a69fc Let the games begin.
Kristopher Murata authored
1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2 /**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
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
12 * @since Version 1.0
13 * @filesource
14 */
15
16 // ------------------------------------------------------------------------
17
18 /**
19 * CodeIgniter Hooks Class
20 *
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.
23 *
24 * @package CodeIgniter
25 * @subpackage Libraries
26 * @category Libraries
27 * @author ExpressionEngine Dev Team
28 * @link http://codeigniter.com/user_guide/libraries/encryption.html
29 */
30 class CI_Hooks {
31
32 var $enabled = FALSE;
33 var $hooks = array();
34 var $in_progress = FALSE;
35
36 /**
37 * Constructor
38 *
39 */
40 function CI_Hooks()
41 {
42 $this->_initialize();
43 log_message('debug', "Hooks Class Initialized");
44 }
45
46 // --------------------------------------------------------------------
47
48 /**
49 * Initialize the Hooks Preferences
50 *
51 * @access private
52 * @return void
53 */
54 function _initialize()
55 {
56 $CFG =& load_class('Config');
57
58 // If hooks are not enabled in the config file
59 // there is nothing else to do
60
61 if ($CFG->item('enable_hooks') == FALSE)
62 {
63 return;
64 }
65
66 // Grab the "hooks" definition file.
67 // If there are no hooks, we're done.
68
69 @include(APPPATH.'config/hooks'.EXT);
70
71 if ( ! isset($hook) OR ! is_array($hook))
72 {
73 return;
74 }
75
76 $this->hooks =& $hook;
77 $this->enabled = TRUE;
78 }
79
80 // --------------------------------------------------------------------
81
82 /**
83 * Call Hook
84 *
85 * Calls a particular hook
86 *
87 * @access private
88 * @param string the hook name
89 * @return mixed
90 */
91 function _call_hook($which = '')
92 {
93 if ( ! $this->enabled OR ! isset($this->hooks[$which]))
94 {
95 return FALSE;
96 }
97
98 if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
99 {
100 foreach ($this->hooks[$which] as $val)
101 {
102 $this->_run_hook($val);
103 }
104 }
105 else
106 {
107 $this->_run_hook($this->hooks[$which]);
108 }
109
110 return TRUE;
111 }
112
113 // --------------------------------------------------------------------
114
115 /**
116 * Run Hook
117 *
118 * Runs a particular hook
119 *
120 * @access private
121 * @param array the hook details
122 * @return bool
123 */
124 function _run_hook($data)
125 {
126 if ( ! is_array($data))
127 {
128 return FALSE;
129 }
130
131 // -----------------------------------
132 // Safety - Prevents run-away loops
133 // -----------------------------------
134
135 // If the script being called happens to have the same
136 // hook call within it a loop can happen
137
138 if ($this->in_progress == TRUE)
139 {
140 return;
141 }
142
143 // -----------------------------------
144 // Set file path
145 // -----------------------------------
146
147 if ( ! isset($data['filepath']) OR ! isset($data['filename']))
148 {
149 return FALSE;
150 }
151
152 $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
153
154 if ( ! file_exists($filepath))
155 {
156 return FALSE;
157 }
158
159 // -----------------------------------
160 // Set class/function name
161 // -----------------------------------
162
163 $class = FALSE;
164 $function = FALSE;
165 $params = '';
166
167 if (isset($data['class']) AND $data['class'] != '')
168 {
169 $class = $data['class'];
170 }
171
172 if (isset($data['function']))
173 {
174 $function = $data['function'];
175 }
176
177 if (isset($data['params']))
178 {
179 $params = $data['params'];
180 }
181
182 if ($class === FALSE AND $function === FALSE)
183 {
184 return FALSE;
185 }
186
187 // -----------------------------------
188 // Set the in_progress flag
189 // -----------------------------------
190
191 $this->in_progress = TRUE;
192
193 // -----------------------------------
194 // Call the requested class and/or function
195 // -----------------------------------
196
197 if ($class !== FALSE)
198 {
199 if ( ! class_exists($class))
200 {
201 require($filepath);
202 }
203
204 $HOOK = new $class;
205 $HOOK->$function($params);
206 }
207 else
208 {
209 if ( ! function_exists($function))
210 {
211 require($filepath);
212 }
213
214 $function($params);
215 }
216
217 $this->in_progress = FALSE;
218 return TRUE;
219 }
220
221 }
222
223 // END CI_Hooks class
224
225 /* End of file Hooks.php */
226 /* Location: ./system/libraries/Hooks.php */
Something went wrong with that request. Please try again.