public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
 {
     // first we need to check if this is called before CI_controller
     // if yes, well just use default
     if (!class_exists('CI_controller')) {
         return parent::load($file, $use_sections, $fail_gracefully);
     }
     if (in_array($file, $this->is_loaded, TRUE)) {
         return $this->item($file);
     }
     $_module = Modules::$current;
     if ($path = modules::find($file, $_module, 'config')) {
         // this file expected contain $config var
         include $path;
         if (!isset($config) or !is_array($config)) {
             show_error("{$path} does not contain a valid config array");
         }
         log_message('debug', "File loaded: {$path}");
         $current_config =& $this->config;
         if ($use_sections === TRUE) {
             if (isset($current_config[$file])) {
                 $current_config[$file] = array_merge($current_config[$file], $config);
             } else {
                 $current_config[$file] = $config;
             }
         } else {
             $current_config = array_merge($current_config, $config);
         }
         $this->is_loaded[] = $file;
         unset($config);
         return $this->item($file);
     }
     return parent::load($file, $use_sections, $fail_gracefully);
 }
 public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
 {
     // first we need to check if this is called before CI_controller
     // if yes, well just use default
     if (!class_exists('CI_controller')) {
         return parent::load($file, $use_sections, $fail_gracefully);
     }
     if (is_array($langfile)) {
         foreach ($langfile as $_lang) {
             $this->load($_lang);
         }
         return $this->language;
     }
     $deft_lang = get_instance()->config->item('language');
     $idiom or $idiom = $deft_lang;
     if (in_array($langfile . '_lang.php', $this->is_loaded, TRUE)) {
         return $this->language;
     }
     $_module = get_instance()->router->fetch_module();
     if ($path = modules::find($langfile . '_lang', $_module, 'language/' . $idiom)) {
         include $path;
         if (!isset($lang) or !is_array($lang)) {
             show_error("{$path} does not contain a valid lang array");
         }
         if ($return) {
             return $lang;
         }
         $this->language = array_merge($this->language, $lang);
         $this->is_loaded[] = $langfile . '_lang.php';
         unset($lang);
         return $this->language;
     }
     return parent::load($langfile, $idiom, $return, $add_suffix, $alt_path);
 }
 private function _loadModules()
 {
     $modules = (array) $this->modules;
     if (count($modules) > 0 && defined('INIT_MODULES') && INIT_MODULES) {
         // start module init
         $_paths = array();
         require_once 'system.modules.php';
         // application users modules - lets load up the system module file.
         __log("Loading " . count($modules) . " modules.");
         // report how many modules we are loading.
         foreach ((array) $modules as $_module) {
             if (is_dir(BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . '_' . $_module)) {
                 // any module contained in a directory with _ in front is considered a must load over any  modules in use directory
                 $module_directory = BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . '_' . $_module;
             } else {
                 if (is_dir(APPLICATION_PATH . DS . DIRECTORY_MODULES . DS . $_module)) {
                     // rule off thumb always use modules in users application path before we use modules in system directory
                     $module_directory = APPLICATION_PATH . DS . DIRECTORY_MODULES . DS . $_module;
                 } else {
                     if (is_dir(BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . $_module)) {
                         $module_directory = BASE_SYSTEM . DS . DIRECTORY_MODULES . DS . $_module;
                     } else {
                         throw new Exception('Tried loading a system module that does not exists');
                     }
                 }
             }
             if (file_exists($module_directory . DS . $_module . '.module.php')) {
                 include $module_directory . DS . $_module . '.module.php';
                 $_paths[$_module] = $module_directory . DS . $_module . '.module.php';
             } else {
                 throw new Exception("required system file was not install module.init.php was not found in {$module_directory}.");
             }
         }
         $modules = modules::find();
         // find all loaded module classes
         // interate through each module and execute
         foreach ((array) $modules as $module) {
             $module_object =& new $module();
             $name = $module_object->__name();
             if (key_exists($name, $this->_modules)) {
                 throw new Exception($module . ": fatal Conflict with the module name: " . $name . " taken by the class: " . get_class($this->modules[$name]));
             }
             __log("Loading module: {$name}");
             $module_object->attach($this);
             $this->_modules[$name] = $module_object;
             if (method_exists($module_object, '__init')) {
                 __log("Initializing module. ");
                 $module_object->__init();
             }
             // odd a module should have an init
         }
         // end of module init
     }
 }
Exemple #4
0
 /** Autload items **/
 public function autoload()
 {
     $ci = modules::$registry[$this->_class];
     /* process application autoload */
     if (!isset(self::$autoload) and self::$autoload = TRUE) {
         self::$loader->_ci_autoloader();
     }
     /* controller autoload array */
     $autoload = $ci->autoload() or $autoload = array();
     list($path, $file) = modules::find('autoload', $this->_module, 'config/');
     /* module autoload file */
     if ($path != FALSE) {
         $autoload = array_merge(modules::load_file($file, $path, 'autoload'), $autoload);
     }
     /* nothing to do? */
     if (count($autoload) == 0) {
         return;
     }
     /* autoload database & libraries */
     if (isset($autoload['libraries'])) {
         if (in_array('database', $autoload['libraries'])) {
             /* autoload database */
             if (!($db = $ci->config->item('database'))) {
                 $db['params'] = 'default';
                 $db['active_record'] = TRUE;
             }
             $ci->db = $this->database($db['params'], TRUE, $db['active_record']);
             $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
         }
         /* autoload libraries */
         foreach ($autoload['libraries'] as $library) {
             $this->library($library);
         }
     }
     /* autoload config */
     if (isset($autoload['config'])) {
         foreach ($autoload['config'] as $key => $val) {
             $this->config($val, TRUE);
         }
     }
     /* autoload helpers, plugins, scripts, languages */
     foreach (array('helper', 'plugin', 'script', 'language') as $type) {
         if (isset($autoload[$type])) {
             foreach ($autoload[$type] as $item) {
                 $this->{$type}($item);
             }
         }
     }
     /* autoload base classes */
     if (isset($autoload['class'])) {
         foreach ($autoload['class'] as $class) {
             modules::autoload($class);
         }
     }
     /* autoload models */
     if (isset($autoload['model'])) {
         foreach ($autoload['model'] as $model => $alias) {
             is_numeric($model) ? $this->model($alias) : $this->model($model, $alias);
         }
     }
     /* autoload module controllers */
     if (isset($autoload['modules']) and !in_array($this->_class, $autoload['modules'])) {
         foreach ($autoload['modules'] as $module) {
             $this->module($module);
         }
     }
 }