Hooks.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class CI_Hooks {
00031
00032 var $enabled = FALSE;
00033 var $hooks = array();
00034 var $in_progress = FALSE;
00035
00036
00037
00038
00039
00040 function CI_Hooks()
00041 {
00042 $this->_initialize();
00043 log_message('debug', "Hooks Class Initialized");
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 function _initialize()
00055 {
00056 $CFG =& load_class('Config');
00057
00058
00059
00060
00061 if ($CFG->item('enable_hooks') == FALSE)
00062 {
00063 return;
00064 }
00065
00066
00067
00068
00069 @include(APPPATH.'config/hooks'.EXT);
00070
00071 if ( ! isset($hook) OR ! is_array($hook))
00072 {
00073 return;
00074 }
00075
00076 $this->hooks =& $hook;
00077 $this->enabled = TRUE;
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 function _call_hook($which = '')
00092 {
00093 if ( ! $this->enabled OR ! isset($this->hooks[$which]))
00094 {
00095 return FALSE;
00096 }
00097
00098 if (isset($this->hooks[$which][0]) AND is_array($this->hooks[$which][0]))
00099 {
00100 foreach ($this->hooks[$which] as $val)
00101 {
00102 $this->_run_hook($val);
00103 }
00104 }
00105 else
00106 {
00107 $this->_run_hook($this->hooks[$which]);
00108 }
00109
00110 return TRUE;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 function _run_hook($data)
00125 {
00126 if ( ! is_array($data))
00127 {
00128 return FALSE;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 if ($this->in_progress == TRUE)
00139 {
00140 return;
00141 }
00142
00143
00144
00145
00146
00147 if ( ! isset($data['filepath']) OR ! isset($data['filename']))
00148 {
00149 return FALSE;
00150 }
00151
00152 $filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
00153
00154 if ( ! file_exists($filepath))
00155 {
00156 return FALSE;
00157 }
00158
00159
00160
00161
00162
00163 $class = FALSE;
00164 $function = FALSE;
00165 $params = '';
00166
00167 if (isset($data['class']) AND $data['class'] != '')
00168 {
00169 $class = $data['class'];
00170 }
00171
00172 if (isset($data['function']))
00173 {
00174 $function = $data['function'];
00175 }
00176
00177 if (isset($data['params']))
00178 {
00179 $params = $data['params'];
00180 }
00181
00182 if ($class === FALSE AND $function === FALSE)
00183 {
00184 return FALSE;
00185 }
00186
00187
00188
00189
00190
00191 $this->in_progress = TRUE;
00192
00193
00194
00195
00196
00197 if ($class !== FALSE)
00198 {
00199 if ( ! class_exists($class))
00200 {
00201 require($filepath);
00202 }
00203
00204 $HOOK = new $class;
00205 $HOOK->$function($params);
00206 }
00207 else
00208 {
00209 if ( ! function_exists($function))
00210 {
00211 require($filepath);
00212 }
00213
00214 $function($params);
00215 }
00216
00217 $this->in_progress = FALSE;
00218 return TRUE;
00219 }
00220
00221 }
00222
00223
00224
00225
00226