_ci_events_paths = array(APPPATH); } /** Load a events module * */ public function event($event = '', $params = NULL, $object_name = NULL) { if (is_array($event)) { foreach ($event as $class) { $this->library($class, $params); } return; } if ($event == '' OR isset($this->_base_classes[$event])) { return FALSE; } if ( ! is_null($params) && ! is_array($params)) { $params = NULL; } $this->_ci_events_class($event, $params, $object_name); } /** Load an array of events * */ public function events($event = '', $params = NULL, $object_name = NULL) { if (is_array($event)) { foreach ($event as $class) { $this->library($class, $params); } } return; } /** * Load Events * * This function loads the requested class. * * @param string the item that is being loaded * @param mixed any additional parameters * @param string an optional object name * @return void */ protected function _ci_events_class($class, $params = NULL, $object_name = NULL) { // Get the class name, and while we're at it trim any slashes. // The directory path can be included as part of the class name, // but we don't want a leading slash $class = str_replace('.php', '', trim($class, '/')); // Was the path included with the class name? // We look for a slash to determine this if (($last_slash = strrpos($class, '/')) !== FALSE) { // Extract the path $subdir = substr($class, 0, ++$last_slash); // Get the filename from the path $class = substr($class, $last_slash); } else { $subdir = ''; } $class = ucfirst($class); // Is this a stock library? There are a few special conditions if so ... if (file_exists(BASEPATH.'events/'.$subdir.$class.'.php')) { return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); } // Let's search for the requested library file and load it. foreach ($this->_ci_library_paths as $path) { // BASEPATH has already been checked for if ($path === BASEPATH) { continue; } $filepath = $path.'events/'.$subdir.$class.'.php'; // Safety: Was the class already loaded by a previous call? if (class_exists($class, FALSE)) { // Before we deem this to be a duplicate request, let's see // if a custom object name is being supplied. If so, we'll // return a new instance of the object if ($object_name !== NULL) { $CI =& get_instance(); if ( ! isset($CI->$object_name)) { return $this->_ci_init_library($class, '', $params, $object_name); } } log_message('debug', $class.' class already loaded. Second attempt ignored.'); return; } // Does the file exist? No? Bummer... elseif ( ! file_exists($filepath)) { continue; } include_once($filepath); return $this->_ci_init_library($class, '', $params, $object_name); } // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? if ($subdir === '') { return $this->_ci_events_class($class.'/'.$class, $params, $object_name); } return; } }