[Php] <? Php if (! Defined ('basepath') exit ('no direct script access allowed '); /*** CodeIgniter ** An open source application development framework for PHP 5.1.6 or newer ** @ package CodeIgniter * @ author ExpressionEngine Dev Team * @ copyright Copyright (c) 2008-2011, ellisLab, Inc. * @ license http://codeigniter.com/user_guide/license.html * @ link http://codeigniter.com * @ since Version 1.0 * @ filesource *// /----------------------------------------------------------------------/*** CodeIgniter Hooks Class *** Provides a mechanism to extend the base system without hacking. * User Manual address: http://codeigniter.org.cn/user_guide/general/hooks.html * @ package CodeIgniter * @ subpackage Libraries * @ category Libraries * @ author ExpressionEngine Dev Team * @ link http://codeigniter.com/user_guide/libraries /Encryption.html */class CI_Hooks {/*** Determines wether hooks are enabled * Determines whether the hook is enabled ** @ var bool */var $ enabled = FALSE; /*** List of all hooks set in config/hooks. php ** @ var array */var $ hooks = array ();/*** Determines wether hook is in progress, used to prevent prevents infinte infinite loops ** @ var bool */var $ in_progress = FALSE;/*** Constructor **/function _ construct () {$ this-> _ ini Tialize (); log_message ('debug', "Hooks Class Initialized");} // specify/*** Initialize the Hooks Preferences parameter, preference * initialization hook * @ access private * @ return void */function _ initialize () {$ CFG = & load_class ('config', 'core '); // If hooks are not enabled in the config file // there is nothing else to do // If hooks is not allowed in the configuration file, exit the function directly. If ($ CFG-> item ('Enable _ hooks') = FALSE) {return;} // Grab the "hooks" definition file. // capture the hook definition file // If there are no hooks, we're done. // If hooks is not defined. php does not define the $ hook array. We directly return if (defined ('Environment ') AND is_file (APPPATH. 'config /'. ENVIRONMENT. '/hooks. php ') {include (APPPATH. 'config /'. ENVIRONMENT. '/hooks. php ');} elseif (is_file (APPPATH. 'config/hooks. php ') {include (APPPATH. 'config/hooks. php ') ;} If (! Isset ($ hook) OR! Is_array ($ hook) {return;} // set hooks. reference the $ hook array in php to $ this-> hooks // enable $ this-> enabled $ this-> hooks = & $ hook; $ this-> enabled = TRUE ;} // ----------------------------------------------------------------------/*** Call Hook * is actually calling the _ call_hook function to Call the Hook program. * In this method, _ run_hook is called to execute the corresponding hook. * Calla participant hook ** @ access private * @ param string the hook name * @ return mixed */function _ call_hook ($ which = '') {// determine whether $ this-> enabled is enabled and whether the hook to be called exists in $ htis-> hooks. If (! $ This-> enabled OR! Isset ($ this-> hooks [$ which]) {return FALSE;} // checks whether the hook to be called is a two-dimensional array. If yes, it traverses and runs. // If it is not a two-dimensional array, execute it directly. // here, multiple hooks can be executed at a hook point, which is implemented by defining a two-dimensional array. If (isset ($ this-> hooks [$ which] [0]) AND is_array ($ this-> hooks [$ which] [0]) {foreach ($ this-> hooks [$ which] as $ val) {$ this-> _ run_hook ($ val );}} else {$ this-> _ run_hook ($ this-> hooks [$ which]);} return TRUE ;} // hooks/*** Run Hook * Runs a special hook of the particle ** @ access private * @ param array the hook details * @ return bool * /Function _ run_hook ($ data) {/** $ data is stored in APPPATH/config/hook. php-defined hook array * $ hook ['pre _ controller'] = array (* 'class' => 'myclass', * 'function' => 'myfunction ', * 'filename' => 'myclass. php ', * 'filepath' => 'hooks', * 'params' => array ('beer', 'wine', 'snacks ')*); ** because each hook must be composed of arrays *, we can determine whether $ data is an array. if not, the system returns **/if (! Is_array ($ data) {return FALSE ;} // outputs // Safety-Prevents run-away loops // --------------------------------------- // If the script being called happens to have the same // hook call within it a loop can happen // If call a hook, execute some scripts, and it is possible that these scripts will trigger other hooks. // if the other hooks contain the current/hook, it will enter an endless loop, this in_progress is to prevent this situation. If ($ this-> in_progress = TRUE) {return;} // ----------------------------------- // extract the data in the data and load the APPPATH. $ data ['filepath']. $ data ['filename']; // Set file path // --------------------------------------- if (! Isset ($ data ['filepath']) OR! Isset ($ data ['filename']) {return FALSE;} $ filepath = APPPATH. $ data ['filepath']. '/'. $ data ['filename']; if (! File_exists ($ filepath) {return FALSE;} // ----------------------------------- // Set class/function name/functions $ class = FALSE; $ function = FALSE; $ params = ''; // retrieve the class function params if (isset ($ data ['class']) AND $ data ['class'] in $ hooks! = '') {$ Class = $ data ['class'];} if (isset ($ data ['function']) {$ function = $ data ['function'];} if (isset ($ data ['params']) {$ params = $ data ['params'];} if ($ class === false and $ function === FALSE) {return FALSE ;} // ----------------------------------- // Set the in_progress flag // Set the current hook status to running before running the program. // ----------------------------------- $ This-> in_progress = TRUE; // ----------------------------------- // Call the requested class and/or function // contains the hook file and instantiate the class, call the function // ----------------------------------- if ($ class! = FALSE) {if (! Class_exists ($ class) {require ($ filepath);} $ HOOK = new $ class; $ HOOK-> $ function ($ params);} else {if (! Function_exists ($ function) {require ($ filepath) ;}$ function ($ params) ;}www.2cto.com // after the corresponding program is executed, change the current hook status to not running // so that it can be triggered again. $ This-> in_progress = FALSE; return TRUE ;}// END CI_Hooks class/* End of file Hooks. php * // * Location :. /system/core/Hooks. php */