From f58529ec276d3d966eba30865540a484d8ddf59d Mon Sep 17 00:00:00 2001 From: nguyenanhung Date: Fri, 10 Sep 2021 14:22:09 +0700 Subject: [PATCH] Deploy --- thirdParty/MX/Base.php | 114 +++--- thirdParty/MX/CI.php | 110 +++--- thirdParty/MX/Config.php | 123 +++--- thirdParty/MX/Controller.php | 111 +++--- thirdParty/MX/Lang.php | 128 +++---- thirdParty/MX/Loader.php | 716 +++++++++++++++++------------------ thirdParty/MX/Modules.php | 386 +++++++++---------- thirdParty/MX/Router.php | 376 +++++++++--------- 8 files changed, 1029 insertions(+), 1035 deletions(-) diff --git a/thirdParty/MX/Base.php b/thirdParty/MX/Base.php index 649f3e1..5db9a00 100644 --- a/thirdParty/MX/Base.php +++ b/thirdParty/MX/Base.php @@ -1,64 +1,62 @@ is_loaded, true)) { - return $this->item($file); - } - $_module or $_module = CI::$APP->router->fetch_module(); - list($path, $file) = Modules::find($file, $_module, 'config/'); - if ($path === false) { - parent::load($file, $use_sections, $fail_gracefully); + if (in_array($file, $this->is_loaded, true)) { + return $this->item($file); + } + $_module or $_module = CI::$APP->router->fetch_module(); + list($path, $file) = Modules::find($file, $_module, 'config/'); + if ($path === false) { + parent::load($file, $use_sections, $fail_gracefully); - return $this->item($file); - } - if ($config = Modules::load_file($file, $path, 'config')) { - /* reference to the config array */ - $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; - } + return $this->item($file); + } + if ($config = Modules::load_file($file, $path, 'config')) { + /* reference to the config array */ + $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 = array_merge($current_config, $config); + $current_config[$file] = $config; } - $this->is_loaded[] = $file; - unset($config); - - return $this->item($file); + } else { + $current_config = array_merge($current_config, $config); } + $this->is_loaded[] = $file; + unset($config); + + return $this->item($file); } } } diff --git a/thirdParty/MX/Controller.php b/thirdParty/MX/Controller.php index 861aec8..b1e9b52 100644 --- a/thirdParty/MX/Controller.php +++ b/thirdParty/MX/Controller.php @@ -1,62 +1,61 @@ config->item('controller_suffix'), '', get_class($this)); - log_message('debug', $class . " MX_Controller Initialized"); - Modules::$registry[strtolower($class)] = $this; - /* copy a loader instance and initialize */ - $this->load = clone load_class('Loader'); - $this->load->initialize($this); - /* autoload module items */ - $this->load->_autoloader($this->autoload); - } +/** + * Modular Extensions - HMVC + * + * Adapted from the CodeIgniter Core Classes + * + * @link http://codeigniter.com + * + * Description: + * This library replaces the CodeIgniter Controller class + * and adds features allowing use of modules and the HMVC design pattern. + * + * Install this file as application/third_party/MX/Controller.php + * + * @copyright Copyright (c) 2015 Wiredesignz + * @version 5.5 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + **/ +class MX_Controller +{ + public $autoload = array(); - public function __get($class) - { - return CI::$APP->$class; - } + public function __construct() + { + $class = str_replace(CI::$APP->config->item('controller_suffix'), '', get_class($this)); + log_message('debug', $class . " MX_Controller Initialized"); + Modules::$registry[strtolower($class)] = $this; + /* copy a loader instance and initialize */ + $this->load = clone load_class('Loader'); + $this->load->initialize($this); + /* autoload module items */ + $this->load->_autoloader($this->autoload); + } + + public function __get($class) + { + return CI::$APP->$class; } } diff --git a/thirdParty/MX/Lang.php b/thirdParty/MX/Lang.php index 0b5f774..c5794d7 100644 --- a/thirdParty/MX/Lang.php +++ b/thirdParty/MX/Lang.php @@ -1,74 +1,74 @@ load($_lang); - } +(defined('BASEPATH')) OR exit('No direct script access allowed'); - return $this->language; +/** + * Modular Extensions - HMVC + * + * Adapted from the CodeIgniter Core Classes + * + * @link http://codeigniter.com + * + * Description: + * This library extends the CodeIgniter CI_Language class + * and adds features allowing use of modules and the HMVC design pattern. + * + * Install this file as application/third_party/MX/Lang.php + * + * @copyright Copyright (c) 2011 Wiredesignz + * @version 5.5 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + **/ +class MX_Lang extends CI_Lang +{ + public function load($langfile, $lang = '', $return = false, $add_suffix = true, $alt_path = '', $_module = '') + { + if (is_array($langfile)) { + foreach ($langfile as $_lang) { + $this->load($_lang); } - $deft_lang = CI::$APP->config->item('language'); - $idiom = ($lang == '') ? $deft_lang : $lang; - if (in_array($langfile . '_lang' . EXT, $this->is_loaded, true)) { - return $this->language; + + return $this->language; + } + $deft_lang = CI::$APP->config->item('language'); + $idiom = ($lang == '') ? $deft_lang : $lang; + if (in_array($langfile . '_lang' . EXT, $this->is_loaded, true)) { + return $this->language; + } + $_module or $_module = CI::$APP->router->fetch_module(); + list($path, $_langfile) = Modules::find($langfile . '_lang', $_module, 'language/' . $idiom . '/'); + if ($path === false) { + if ($lang = parent::load($langfile, $lang, $return, $add_suffix, $alt_path)) { + return $lang; } - $_module or $_module = CI::$APP->router->fetch_module(); - list($path, $_langfile) = Modules::find($langfile . '_lang', $_module, 'language/' . $idiom . '/'); - if ($path === false) { - if ($lang = parent::load($langfile, $lang, $return, $add_suffix, $alt_path)) { + } else { + if ($lang = Modules::load_file($_langfile, $path, 'lang')) { + if ($return) { return $lang; } - } else { - if ($lang = Modules::load_file($_langfile, $path, 'lang')) { - if ($return) { - return $lang; - } - $this->language = array_merge($this->language, $lang); - $this->is_loaded[] = $langfile . '_lang' . EXT; - unset($lang); - } + $this->language = array_merge($this->language, $lang); + $this->is_loaded[] = $langfile . '_lang' . EXT; + unset($lang); } - - return $this->language; } + + return $this->language; } } + diff --git a/thirdParty/MX/Loader.php b/thirdParty/MX/Loader.php index c768c16..937e05f 100644 --- a/thirdParty/MX/Loader.php +++ b/thirdParty/MX/Loader.php @@ -1,424 +1,424 @@ _module = CI::$APP->router->fetch_module(); - if ($controller instanceof MX_Controller) { - /* reference to the module controller */ - $this->controller = $controller; - /* references to ci loader variables */ - foreach (get_class_vars('CI_Loader') as $var => $val) { - if ($var != '_ci_ob_level') { - $this->$var =& CI::$APP->load->$var; - } + /* set the module name */ + $this->_module = CI::$APP->router->fetch_module(); + if ($controller instanceof MX_Controller) { + /* reference to the module controller */ + $this->controller = $controller; + /* references to ci loader variables */ + foreach (get_class_vars('CI_Loader') as $var => $val) { + if ($var != '_ci_ob_level') { + $this->$var =& CI::$APP->load->$var; } - } else { - parent::initialize(); - /* autoload module items */ - $this->_autoloader(array()); } - /* add this module path to the loader variables */ - $this->_add_module_paths($this->_module); + } else { + parent::initialize(); + /* autoload module items */ + $this->_autoloader(array()); } + /* add this module path to the loader variables */ + $this->_add_module_paths($this->_module); + } - /** Add a module path loader variables **/ - public function _add_module_paths($module = '') - { - if (empty($module)) - return; - foreach (Modules::$locations as $location => $offset) { - /* only add a module path if it exists */ - if (is_dir($module_path = $location . $module . '/') && !in_array($module_path, $this->_ci_model_paths)) { - array_unshift($this->_ci_model_paths, $module_path); - } + /** Add a module path loader variables **/ + public function _add_module_paths($module = '') + { + if (empty($module)) + return; + foreach (Modules::$locations as $location => $offset) { + /* only add a module path if it exists */ + if (is_dir($module_path = $location . $module . '/') && !in_array($module_path, $this->_ci_model_paths)) { + array_unshift($this->_ci_model_paths, $module_path); } } + } - /** Load a module config file **/ - public function config($file, $use_sections = false, $fail_gracefully = false) - { - return CI::$APP->config->load($file, $use_sections, $fail_gracefully, $this->_module); - } - - /** Load the database drivers **/ - public function database($params = '', $return = false, $query_builder = null) - { - if ($return === false && $query_builder === null && isset(CI::$APP->db) && is_object(CI::$APP->db) && !empty(CI::$APP->db->conn_id)) { - return false; - } - require_once BASEPATH . 'database/DB' . EXT; - if ($return === true) - return DB($params, $query_builder); - CI::$APP->db = DB($params, $query_builder); + /** Load a module config file **/ + public function config($file, $use_sections = false, $fail_gracefully = false) + { + return CI::$APP->config->load($file, $use_sections, $fail_gracefully, $this->_module); + } - return $this; + /** Load the database drivers **/ + public function database($params = '', $return = false, $query_builder = null) + { + if ($return === false && $query_builder === null && isset(CI::$APP->db) && is_object(CI::$APP->db) && !empty(CI::$APP->db->conn_id)) { + return false; } + require_once BASEPATH . 'database/DB' . EXT; + if ($return === true) + return DB($params, $query_builder); + CI::$APP->db = DB($params, $query_builder); - /** Load a module helper **/ - public function helper($helper = array()) - { - if (is_array($helper)) - return $this->helpers($helper); - if (isset($this->_ci_helpers[$helper])) - return; - list($path, $_helper) = Modules::find($helper . '_helper', $this->_module, 'helpers/'); - if ($path === false) - return parent::helper($helper); - Modules::load_file($_helper, $path); - $this->_ci_helpers[$_helper] = true; + return $this; + } - return $this; - } + /** Load a module helper **/ + public function helper($helper = array()) + { + if (is_array($helper)) + return $this->helpers($helper); + if (isset($this->_ci_helpers[$helper])) + return; + list($path, $_helper) = Modules::find($helper . '_helper', $this->_module, 'helpers/'); + if ($path === false) + return parent::helper($helper); + Modules::load_file($_helper, $path); + $this->_ci_helpers[$_helper] = true; + + return $this; + } - /** Load an array of helpers **/ - public function helpers($helpers = array()) - { - foreach ($helpers as $_helper) - $this->helper($_helper); + /** Load an array of helpers **/ + public function helpers($helpers = array()) + { + foreach ($helpers as $_helper) + $this->helper($_helper); - return $this; - } + return $this; + } - /** Load a module language file **/ - public function language($langfile, $idiom = '', $return = false, $add_suffix = true, $alt_path = '') - { - CI::$APP->lang->load($langfile, $idiom, $return, $add_suffix, $alt_path, $this->_module); + /** Load a module language file **/ + public function language($langfile, $idiom = '', $return = false, $add_suffix = true, $alt_path = '') + { + CI::$APP->lang->load($langfile, $idiom, $return, $add_suffix, $alt_path, $this->_module); - return $this; - } + return $this; + } - public function languages($languages) - { - foreach ($languages as $_language) - $this->language($_language); + public function languages($languages) + { + foreach ($languages as $_language) + $this->language($_language); + + return $this; + } + /** Load a module library **/ + public function library($library, $params = null, $object_name = null) + { + if (is_array($library)) + return $this->libraries($library); + $class = strtolower(basename($library)); + if (isset($this->_ci_classes[$class]) && $_alias = $this->_ci_classes[$class]) return $this; + ($_alias = strtolower($object_name)) or $_alias = $class; + list($path, $_library) = Modules::find($library, $this->_module, 'libraries/'); + /* load library config file as params */ + if ($params == null) { + list($path2, $file) = Modules::find($_alias, $this->_module, 'config/'); + ($path2) && $params = Modules::load_file($file, $path2, 'config'); + } + if ($path === false) { + $this->_ci_load_library($library, $params, $object_name); + } else { + Modules::load_file($_library, $path); + $library = ucfirst($_library); + CI::$APP->$_alias = new $library($params); + $this->_ci_classes[$class] = $_alias; } - /** Load a module library **/ - public function library($library, $params = null, $object_name = null) - { - if (is_array($library)) - return $this->libraries($library); - $class = strtolower(basename($library)); - if (isset($this->_ci_classes[$class]) && $_alias = $this->_ci_classes[$class]) - return $this; - ($_alias = strtolower($object_name)) or $_alias = $class; - list($path, $_library) = Modules::find($library, $this->_module, 'libraries/'); - /* load library config file as params */ - if ($params == null) { - list($path2, $file) = Modules::find($_alias, $this->_module, 'config/'); - ($path2) && $params = Modules::load_file($file, $path2, 'config'); - } - if ($path === false) { - $this->_ci_load_library($library, $params, $object_name); - } else { - Modules::load_file($_library, $path); - $library = ucfirst($_library); - CI::$APP->$_alias = new $library($params); - $this->_ci_classes[$class] = $_alias; - } + return $this; + } - return $this; + /** Load an array of libraries **/ + public function libraries($libraries) + { + foreach ($libraries as $library => $alias) { + (is_int($library)) ? $this->library($alias) : $this->library($library, null, $alias); } - /** Load an array of libraries **/ - public function libraries($libraries) - { - foreach ($libraries as $library => $alias) { - (is_int($library)) ? $this->library($alias) : $this->library($library, null, $alias); - } + return $this; + } + /** Load a module model **/ + public function model($model, $object_name = null, $connect = false) + { + if (is_array($model)) + return $this->models($model); + ($_alias = $object_name) or $_alias = basename($model); + if (in_array($_alias, $this->_ci_models, true)) return $this; + /* check module */ + list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/'); + if ($path == false) { + /* check application & packages */ + parent::model($model, $object_name, $connect); + } else { + class_exists('CI_Model', false) or load_class('Model', 'core'); + if ($connect !== false && !class_exists('CI_DB', false)) { + if ($connect === true) + $connect = ''; + $this->database($connect, false, true); + } + Modules::load_file($_model, $path); + $model = ucfirst($_model); + CI::$APP->$_alias = new $model(); + $this->_ci_models[] = $_alias; } - /** Load a module model **/ - public function model($model, $object_name = null, $connect = false) - { - if (is_array($model)) - return $this->models($model); - ($_alias = $object_name) or $_alias = basename($model); - if (in_array($_alias, $this->_ci_models, true)) - return $this; - /* check module */ - list($path, $_model) = Modules::find(strtolower($model), $this->_module, 'models/'); - if ($path == false) { - /* check application & packages */ - parent::model($model, $object_name, $connect); - } else { - class_exists('CI_Model', false) or load_class('Model', 'core'); - if ($connect !== false && !class_exists('CI_DB', false)) { - if ($connect === true) - $connect = ''; - $this->database($connect, false, true); - } - Modules::load_file($_model, $path); - $model = ucfirst($_model); - CI::$APP->$_alias = new $model(); - $this->_ci_models[] = $_alias; - } + return $this; + } - return $this; + /** Load an array of models **/ + public function models($models) + { + foreach ($models as $model => $alias) { + (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); } - /** Load an array of models **/ - public function models($models) - { - foreach ($models as $model => $alias) { - (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); - } + return $this; + } - return $this; - } + /** Load a module controller **/ + public function module($module, $params = null) + { + if (is_array($module)) + return $this->modules($module); + $_alias = strtolower(basename($module)); + CI::$APP->$_alias = Modules::load(array( + $module => $params + )); + + return $this; + } - /** Load a module controller **/ - public function module($module, $params = null) - { - if (is_array($module)) - return $this->modules($module); - $_alias = strtolower(basename($module)); - CI::$APP->$_alias = Modules::load(array( - $module => $params - )); + /** Load an array of controllers **/ + public function modules($modules) + { + foreach ($modules as $_module) + $this->module($_module); + return $this; + } + + /** Load a module plugin **/ + public function plugin($plugin) + { + if (is_array($plugin)) + return $this->plugins($plugin); + if (isset($this->_ci_plugins[$plugin])) return $this; + list($path, $_plugin) = Modules::find($plugin . '_pi', $this->_module, 'plugins/'); + if ($path === false && !is_file($_plugin = APPPATH . 'plugins/' . $_plugin . EXT)) { + show_error("Unable to locate the plugin file: {$_plugin}"); } + Modules::load_file($_plugin, $path); + $this->_ci_plugins[$plugin] = true; - /** Load an array of controllers **/ - public function modules($modules) - { - foreach ($modules as $_module) - $this->module($_module); + return $this; + } - return $this; - } + /** Load an array of plugins **/ + public function plugins($plugins) + { + foreach ($plugins as $_plugin) + $this->plugin($_plugin); - /** Load a module plugin **/ - public function plugin($plugin) - { - if (is_array($plugin)) - return $this->plugins($plugin); - if (isset($this->_ci_plugins[$plugin])) - return $this; - list($path, $_plugin) = Modules::find($plugin . '_pi', $this->_module, 'plugins/'); - if ($path === false && !is_file($_plugin = APPPATH . 'plugins/' . $_plugin . EXT)) { - show_error("Unable to locate the plugin file: {$_plugin}"); - } - Modules::load_file($_plugin, $path); - $this->_ci_plugins[$plugin] = true; + return $this; + } - return $this; + /** Load a module view **/ + public function view($view, $vars = array(), $return = false) + { + list($path, $_view) = Modules::find($view, $this->_module, 'views/'); + if ($path != false) { + $this->_ci_view_paths = array( + $path => true + ) + $this->_ci_view_paths; + $view = $_view; } + // return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); + if (method_exists($this, '_ci_object_to_array')) { + return $this->_ci_load(array( + '_ci_view' => $view, + '_ci_vars' => $this->_ci_prepare_view_vars($vars), + '_ci_return' => $return + )); + } else { + return $this->_ci_load(array( + '_ci_view' => $view, + '_ci_vars' => $this->_ci_prepare_view_vars($vars), + '_ci_return' => $return + )); + } + } - /** Load an array of plugins **/ - public function plugins($plugins) - { - foreach ($plugins as $_plugin) - $this->plugin($_plugin); + protected function &_ci_get_component($component) + { + return CI::$APP->$component; + } - return $this; - } + public function __get($class) + { + return (isset($this->controller)) ? $this->controller->$class : CI::$APP->$class; + } - /** Load a module view **/ - public function view($view, $vars = array(), $return = false) - { - list($path, $_view) = Modules::find($view, $this->_module, 'views/'); - if ($path != false) { - $this->_ci_view_paths = array( - $path => true - ) + $this->_ci_view_paths; - $view = $_view; - } - // return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); - if (method_exists($this, '_ci_object_to_array')) { - return $this->_ci_load(array( - '_ci_view' => $view, - '_ci_vars' => $this->_ci_prepare_view_vars($vars), - '_ci_return' => $return - )); - } else { - return $this->_ci_load(array( - '_ci_view' => $view, - '_ci_vars' => $this->_ci_prepare_view_vars($vars), - '_ci_return' => $return - )); + public function _ci_load($_ci_data) + { + extract($_ci_data); + if (isset($_ci_view)) { + $_ci_path = ''; + /* add file extension if not provided */ + $_ci_file = (pathinfo($_ci_view, PATHINFO_EXTENSION)) ? $_ci_view : $_ci_view . EXT; + foreach ($this->_ci_view_paths as $path => $cascade) { + if (file_exists($view = $path . $_ci_file)) { + $_ci_path = $view; + break; + } + if (!$cascade) + break; } + } elseif (isset($_ci_path)) { + $_ci_file = basename($_ci_path); + if (!file_exists($_ci_path)) + $_ci_path = ''; } - - protected function &_ci_get_component($component) - { - return CI::$APP->$component; + if (empty($_ci_path)) + show_error('Unable to load the requested file: ' . $_ci_file); + if (isset($_ci_vars)) + $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, (array) $_ci_vars); + extract($this->_ci_cached_vars); + ob_start(); + if ((bool) @ini_get('short_open_tag') === false && CI::$APP->config->item('rewrite_short_tags') == true) { + echo eval('?>' . preg_replace("/;*\s*\?>/", "; ?>", str_replace('controller)) ? $this->controller->$class : CI::$APP->$class; + log_message('debug', 'File loaded: ' . $_ci_path); + if ($_ci_return == true) + return ob_get_clean(); + if (ob_get_level() > $this->_ci_ob_level + 1) { + ob_end_flush(); + } else { + CI::$APP->output->append_output(ob_get_clean()); } + } - public function _ci_load($_ci_data) - { - extract($_ci_data); - if (isset($_ci_view)) { - $_ci_path = ''; - /* add file extension if not provided */ - $_ci_file = (pathinfo($_ci_view, PATHINFO_EXTENSION)) ? $_ci_view : $_ci_view . EXT; - foreach ($this->_ci_view_paths as $path => $cascade) { - if (file_exists($view = $path . $_ci_file)) { - $_ci_path = $view; - break; - } - if (!$cascade) - break; - } - } elseif (isset($_ci_path)) { - $_ci_file = basename($_ci_path); - if (!file_exists($_ci_path)) - $_ci_path = ''; - } - if (empty($_ci_path)) - show_error('Unable to load the requested file: ' . $_ci_file); - if (isset($_ci_vars)) - $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, (array) $_ci_vars); - extract($this->_ci_cached_vars); - ob_start(); - if ((bool) @ini_get('short_open_tag') === false && CI::$APP->config->item('rewrite_short_tags') == true) { - echo eval('?>' . preg_replace("/;*\s*\?>/", "; ?>", str_replace('_module) { + list($path, $file) = Modules::find('constants', $this->_module, 'config/'); + /* module constants file */ + if ($path != false) { + include_once $path . $file . EXT; } - log_message('debug', 'File loaded: ' . $_ci_path); - if ($_ci_return == true) - return ob_get_clean(); - if (ob_get_level() > $this->_ci_ob_level + 1) { - ob_end_flush(); - } else { - CI::$APP->output->append_output(ob_get_clean()); + 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); } } - - /** Autoload module items **/ - public function _autoloader($autoload) - { - $path = false; - if ($this->_module) { - list($path, $file) = Modules::find('constants', $this->_module, 'config/'); - /* module constants file */ - if ($path != false) { - include_once $path . $file . EXT; - } - 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 package paths */ + if (isset($autoload['packages'])) { + foreach ($autoload['packages'] as $package_path) { + $this->add_package_path($package_path); } - /* nothing to do */ - if (count($autoload) == 0) - return; - /* autoload package paths */ - if (isset($autoload['packages'])) { - foreach ($autoload['packages'] as $package_path) { - $this->add_package_path($package_path); - } + } + /* autoload config */ + if (isset($autoload['config'])) { + foreach ($autoload['config'] as $config) { + $this->config($config); } - /* autoload config */ - if (isset($autoload['config'])) { - foreach ($autoload['config'] as $config) { - $this->config($config); + } + /* autoload helpers, plugins, languages */ + foreach (array( + 'helper', + 'plugin', + 'language' + ) as $type) { + if (isset($autoload[$type])) { + foreach ($autoload[$type] as $item) { + $this->$type($item); } } - /* autoload helpers, plugins, languages */ - foreach (array( - 'helper', - 'plugin', - 'language' - ) as $type) { - if (isset($autoload[$type])) { - foreach ($autoload[$type] as $item) { - $this->$type($item); - } - } + } + // Autoload drivers + if (isset($autoload['drivers'])) { + foreach ($autoload['drivers'] as $item => $alias) { + (is_int($item)) ? $this->driver($alias) : $this->driver($item, $alias); } - // Autoload drivers - if (isset($autoload['drivers'])) { - foreach ($autoload['drivers'] as $item => $alias) { - (is_int($item)) ? $this->driver($alias) : $this->driver($item, $alias); + } + /* autoload database & libraries */ + if (isset($autoload['libraries'])) { + if (in_array('database', $autoload['libraries'])) { + /* autoload database */ + if (!$db = CI::$APP->config->item('database')) { + $this->database(); + $autoload['libraries'] = array_diff($autoload['libraries'], array( + 'database' + )); } } - /* autoload database & libraries */ - if (isset($autoload['libraries'])) { - if (in_array('database', $autoload['libraries'])) { - /* autoload database */ - if (!$db = CI::$APP->config->item('database')) { - $this->database(); - $autoload['libraries'] = array_diff($autoload['libraries'], array( - 'database' - )); - } - } - /* autoload libraries */ - foreach ($autoload['libraries'] as $library => $alias) { - (is_int($library)) ? $this->library($alias) : $this->library($library, null, $alias); - } + /* autoload libraries */ + foreach ($autoload['libraries'] as $library => $alias) { + (is_int($library)) ? $this->library($alias) : $this->library($library, null, $alias); } - /* autoload models */ - if (isset($autoload['model'])) { - foreach ($autoload['model'] as $model => $alias) { - (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); - } + } + /* autoload models */ + if (isset($autoload['model'])) { + foreach ($autoload['model'] as $model => $alias) { + (is_int($model)) ? $this->model($alias) : $this->model($model, $alias); } - /* autoload module controllers */ - if (isset($autoload['modules'])) { - foreach ($autoload['modules'] as $controller) { - ($controller != $this->_module) && $this->module($controller); - } + } + /* autoload module controllers */ + if (isset($autoload['modules'])) { + foreach ($autoload['modules'] as $controller) { + ($controller != $this->_module) && $this->module($controller); } } } - - /** load the CI class for Modular Separation **/ - (class_exists('CI', false)) or require dirname(__FILE__) . '/CI.php'; } + +/** load the CI class for Modular Separation **/ +(class_exists('CI', false)) or require dirname(__FILE__) . '/CI.php'; + diff --git a/thirdParty/MX/Modules.php b/thirdParty/MX/Modules.php index 86d9539..8b366c4 100644 --- a/thirdParty/MX/Modules.php +++ b/thirdParty/MX/Modules.php @@ -1,228 +1,228 @@ item('modules_locations')) or Modules::$locations = array( - APPPATH . 'modules/' => '../modules/' - ); - /* PHP5 spl_autoload */ - spl_autoload_register('Modules::autoload'); +(defined('BASEPATH')) OR exit('No direct script access allowed'); + +(defined('EXT')) or define('EXT', '.php'); +global $CFG; +/* get module locations from config settings or use the default module location and offset */ +is_array(Modules::$locations = $CFG->item('modules_locations')) or Modules::$locations = array( + APPPATH . 'modules/' => '../modules/' +); +/* PHP5 spl_autoload */ +spl_autoload_register('Modules::autoload'); + +/** + * Modular Extensions - HMVC + * + * Adapted from the CodeIgniter Core Classes + * + * @link http://codeigniter.com + * + * Description: + * This library provides functions to load and instantiate controllers + * and module controllers allowing use of modules and the HMVC design pattern. + * + * Install this file as application/third_party/MX/Modules.php + * + * @copyright Copyright (c) 2015 Wiredesignz + * @version 5.5 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + **/ +class Modules +{ + public static $routes, $registry, $locations; /** - * Modular Extensions - HMVC - * - * Adapted from the CodeIgniter Core Classes - * - * @link http://codeigniter.com - * - * Description: - * This library provides functions to load and instantiate controllers - * and module controllers allowing use of modules and the HMVC design pattern. - * - * Install this file as application/third_party/MX/Modules.php - * - * @copyright Copyright (c) 2015 Wiredesignz - * @version 5.5 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. + * Run a module controller method + * Output from module is buffered and returned. **/ - class Modules + public static function run($module) { - public static $routes, $registry, $locations; - - /** - * Run a module controller method - * Output from module is buffered and returned. - **/ - public static function run($module) - { - $method = 'index'; - if (($pos = strrpos($module, '/')) != false) { - $method = substr($module, $pos + 1); - $module = substr($module, 0, $pos); - } - if ($class = self::load($module)) { - if (method_exists($class, $method)) { - ob_start(); - $args = func_get_args(); - $output = call_user_func_array(array( - $class, - $method - ), array_slice($args, 1)); - $buffer = ob_get_clean(); - - return ($output !== null) ? $output : $buffer; - } - } - log_message('error', "Module controller failed to run: {$module}/{$method}"); + $method = 'index'; + if (($pos = strrpos($module, '/')) != false) { + $method = substr($module, $pos + 1); + $module = substr($module, 0, $pos); } - - /** Load a module controller **/ - public static function load($module) - { - (is_array($module)) ? list($module, $params) = each($module) : $params = null; - /* get the requested controller class name */ - $alias = strtolower(basename($module)); - /* create or return an existing controller from the registry */ - if (!isset(self::$registry[$alias])) { - /* find the controller */ - list($class) = CI::$APP->router->locate(explode('/', $module)); - /* controller cannot be located */ - if (empty($class)) { - return; - } - /* set the module directory */ - $path = APPPATH . 'controllers/' . CI::$APP->router->directory; - /* load the controller class */ - $class = $class . CI::$APP->config->item('controller_suffix'); - self::load_file(ucfirst($class), $path); - /* create and register the new controller */ - $controller = ucfirst($class); - self::$registry[$alias] = new $controller($params); + if ($class = self::load($module)) { + if (method_exists($class, $method)) { + ob_start(); + $args = func_get_args(); + $output = call_user_func_array(array( + $class, + $method + ), array_slice($args, 1)); + $buffer = ob_get_clean(); + + return ($output !== null) ? $output : $buffer; } - - return self::$registry[$alias]; } + log_message('error', "Module controller failed to run: {$module}/{$method}"); + } - /** Library base class autoload **/ - public static function autoload($class) - { - /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ - if (strstr($class, 'CI_') or strstr($class, config_item('subclass_prefix'))) { + /** Load a module controller **/ + public static function load($module) + { + (is_array($module)) ? list($module, $params) = each($module) : $params = null; + /* get the requested controller class name */ + $alias = strtolower(basename($module)); + /* create or return an existing controller from the registry */ + if (!isset(self::$registry[$alias])) { + /* find the controller */ + list($class) = CI::$APP->router->locate(explode('/', $module)); + /* controller cannot be located */ + if (empty($class)) { return; } - /* autoload Modular Extensions MX core classes */ - if (strstr($class, 'MX_')) { - if (is_file($location = dirname(__FILE__) . '/' . substr($class, 3) . EXT)) { - include_once $location; + /* set the module directory */ + $path = APPPATH . 'controllers/' . CI::$APP->router->directory; + /* load the controller class */ + $class = $class . CI::$APP->config->item('controller_suffix'); + self::load_file(ucfirst($class), $path); + /* create and register the new controller */ + $controller = ucfirst($class); + self::$registry[$alias] = new $controller($params); + } - return; - } - show_error('Failed to load MX core class: ' . $class); - } - /* autoload core classes */ - if (is_file($location = APPPATH . 'core/' . ucfirst($class) . EXT)) { - include_once $location; + return self::$registry[$alias]; + } - return; - } - /* autoload library classes */ - if (is_file($location = APPPATH . 'libraries/' . ucfirst($class) . EXT)) { + /** Library base class autoload **/ + public static function autoload($class) + { + /* don't autoload CI_ prefixed classes or those using the config subclass_prefix */ + if (strstr($class, 'CI_') or strstr($class, config_item('subclass_prefix'))) { + return; + } + /* autoload Modular Extensions MX core classes */ + if (strstr($class, 'MX_')) { + if (is_file($location = dirname(__FILE__) . '/' . substr($class, 3) . EXT)) { include_once $location; return; } + show_error('Failed to load MX core class: ' . $class); } + /* autoload core classes */ + if (is_file($location = APPPATH . 'core/' . ucfirst($class) . EXT)) { + include_once $location; - /** Load a module file **/ - public static function load_file($file, $path, $type = 'other', $result = true) - { - $file = str_replace(EXT, '', $file); - $location = $path . $file . EXT; - if ($type === 'other') { - if (class_exists($file, false)) { - log_message('debug', "File already loaded: {$location}"); - - return $result; - } - include_once $location; - } else { - /* load config or language array */ - include $location; - if (!isset($$type) or !is_array($$type)) - show_error("{$location} does not contain a valid {$type} array"); - $result = $$type; - } - log_message('debug', "File loaded: {$location}"); + return; + } + /* autoload library classes */ + if (is_file($location = APPPATH . 'libraries/' . ucfirst($class) . EXT)) { + include_once $location; - return $result; + return; } + } + + /** Load a module file **/ + public static function load_file($file, $path, $type = 'other', $result = true) + { + $file = str_replace(EXT, '', $file); + $location = $path . $file . EXT; + if ($type === 'other') { + if (class_exists($file, false)) { + log_message('debug', "File already loaded: {$location}"); - /** - * Find a file - * Scans for files located within modules directories. - * Also scans application directories for models, plugins and views. - * Generates fatal error if file not found. - **/ - public static function find($file, $module, $base) - { - $segments = explode('/', $file); - $file = array_pop($segments); - $file_ext = (pathinfo($file, PATHINFO_EXTENSION)) ? $file : $file . EXT; - $path = ltrim(implode('/', $segments) . '/', '/'); - $module ? $modules[$module] = $path : $modules = array(); - if (!empty($segments)) { - $modules[array_shift($segments)] = ltrim(implode('/', $segments) . '/', '/'); + return $result; } - foreach (Modules::$locations as $location => $offset) { - foreach ($modules as $module => $subpath) { - $fullpath = $location . $module . '/' . $base . $subpath; - if ($base == 'libraries/' or $base == 'models/') { - if (is_file($fullpath . ucfirst($file_ext))) - return array( - $fullpath, - ucfirst($file) - ); - } else /* load non-class files */ if (is_file($fullpath . $file_ext)) + include_once $location; + } else { + /* load config or language array */ + include $location; + if (!isset($$type) or !is_array($$type)) + show_error("{$location} does not contain a valid {$type} array"); + $result = $$type; + } + log_message('debug', "File loaded: {$location}"); + + return $result; + } + + /** + * Find a file + * Scans for files located within modules directories. + * Also scans application directories for models, plugins and views. + * Generates fatal error if file not found. + **/ + public static function find($file, $module, $base) + { + $segments = explode('/', $file); + $file = array_pop($segments); + $file_ext = (pathinfo($file, PATHINFO_EXTENSION)) ? $file : $file . EXT; + $path = ltrim(implode('/', $segments) . '/', '/'); + $module ? $modules[$module] = $path : $modules = array(); + if (!empty($segments)) { + $modules[array_shift($segments)] = ltrim(implode('/', $segments) . '/', '/'); + } + foreach (Modules::$locations as $location => $offset) { + foreach ($modules as $module => $subpath) { + $fullpath = $location . $module . '/' . $base . $subpath; + if ($base == 'libraries/' or $base == 'models/') { + if (is_file($fullpath . ucfirst($file_ext))) return array( $fullpath, - $file + ucfirst($file) ); - } + } else /* load non-class files */ if (is_file($fullpath . $file_ext)) + return array( + $fullpath, + $file + ); } - - return array( - false, - $file - ); } - /** Parse module routes **/ - public static function parse_routes($module, $uri) - { - /* load the route file */ - if (!isset(self::$routes[$module])) { - if (list($path) = self::find('routes', $module, 'config/')) { - $path && self::$routes[$module] = self::load_file('routes', $path, 'route'); - } + return array( + false, + $file + ); + } + + /** Parse module routes **/ + public static function parse_routes($module, $uri) + { + /* load the route file */ + if (!isset(self::$routes[$module])) { + if (list($path) = self::find('routes', $module, 'config/')) { + $path && self::$routes[$module] = self::load_file('routes', $path, 'route'); } - if (!isset(self::$routes[$module])) - return; - /* parse module routes */ - foreach (self::$routes[$module] as $key => $val) { - $key = str_replace(array( - ':any', - ':num' - ), array( - '.+', - '[0-9]+' - ), $key); - if (preg_match('#^' . $key . '$#', $uri)) { - if (strpos($val, '$') !== false and strpos($key, '(') !== false) { - $val = preg_replace('#^' . $key . '$#', $val, $uri); - } - - return explode('/', $module . '/' . $val); + } + if (!isset(self::$routes[$module])) + return; + /* parse module routes */ + foreach (self::$routes[$module] as $key => $val) { + $key = str_replace(array( + ':any', + ':num' + ), array( + '.+', + '[0-9]+' + ), $key); + if (preg_match('#^' . $key . '$#', $uri)) { + if (strpos($val, '$') !== false and strpos($key, '(') !== false) { + $val = preg_replace('#^' . $key . '$#', $val, $uri); } + + return explode('/', $module . '/' . $val); } } } } + diff --git a/thirdParty/MX/Router.php b/thirdParty/MX/Router.php index 2259351..5d1df54 100644 --- a/thirdParty/MX/Router.php +++ b/thirdParty/MX/Router.php @@ -1,219 +1,219 @@ module; - } - - protected function _set_request($segments = array()) - { - if ($this->translate_uri_dashes === true) { - foreach (range(0, 2) as $v) { - isset($segments[$v]) && $segments[$v] = str_replace('-', '_', $segments[$v]); - } - } - $segments = $this->locate($segments); - if ($this->located == -1) { - $this->_set_404override_controller(); + return $this->module; + } - return; + protected function _set_request($segments = array()) + { + if ($this->translate_uri_dashes === true) { + foreach (range(0, 2) as $v) { + isset($segments[$v]) && $segments[$v] = str_replace('-', '_', $segments[$v]); } - if (empty($segments)) { - $this->_set_default_controller(); + } + $segments = $this->locate($segments); + if ($this->located == -1) { + $this->_set_404override_controller(); - return; - } - $this->set_class($segments[0]); - if (isset($segments[1])) { - $this->set_method($segments[1]); - } else { - $segments[1] = 'index'; - } - array_unshift($segments, null); - unset($segments[0]); - $this->uri->rsegments = $segments; + return; } + if (empty($segments)) { + $this->_set_default_controller(); - protected function _set_404override_controller() - { - $this->_set_module_path($this->routes['404_override']); + return; } + $this->set_class($segments[0]); + if (isset($segments[1])) { + $this->set_method($segments[1]); + } else { + $segments[1] = 'index'; + } + array_unshift($segments, null); + unset($segments[0]); + $this->uri->rsegments = $segments; + } - protected function _set_default_controller() - { - if (empty($this->directory)) { - /* set the default controller module path */ - $this->_set_module_path($this->default_controller); - } - parent::_set_default_controller(); - if (empty($this->class)) { - $this->_set_404override_controller(); - } + protected function _set_404override_controller() + { + $this->_set_module_path($this->routes['404_override']); + } + + protected function _set_default_controller() + { + if (empty($this->directory)) { + /* set the default controller module path */ + $this->_set_module_path($this->default_controller); + } + parent::_set_default_controller(); + if (empty($this->class)) { + $this->_set_404override_controller(); } + } - /** Locate the controller **/ - public function locate($segments) - { - $this->located = 0; - $ext = $this->config->item('controller_suffix') . EXT; - /* use module route if available */ - if (isset($segments[0]) && $routes = Modules::parse_routes($segments[0], implode('/', $segments))) { - $segments = $routes; - } - /* get the segments array elements */ - list($module, $directory, $controller) = array_pad($segments, 3, null); - /* check modules */ - foreach (Modules::$locations as $location => $offset) { - /* module exists? */ - if (is_dir($source = $location . $module . '/controllers/')) { - $this->module = $module; - $this->directory = $offset . $module . '/controllers/'; - /* module sub-controller exists? */ - if ($directory) { - /* module sub-directory exists? */ - if (is_dir($source . $directory . '/')) { - $source .= $directory . '/'; - $this->directory .= $directory . '/'; - /* module sub-directory controller exists? */ - if ($controller) { - if (is_file($source . ucfirst($controller) . $ext)) { - $this->located = 3; - - return array_slice($segments, 2); - } else - $this->located = -1; - } - } elseif (is_file($source . ucfirst($directory) . $ext)) { - $this->located = 2; - - return array_slice($segments, 1); - } else - $this->located = -1; - } - /* module controller exists? */ - if (is_file($source . ucfirst($module) . $ext)) { - $this->located = 1; - - return $segments; - } - } - } - if (!empty($this->directory)) - return; - /* application sub-directory controller exists? */ - if ($directory) { - if (is_file(APPPATH . 'controllers/' . $module . '/' . ucfirst($directory) . $ext)) { - $this->directory = $module . '/'; - - return array_slice($segments, 1); + /** Locate the controller **/ + public function locate($segments) + { + $this->located = 0; + $ext = $this->config->item('controller_suffix') . EXT; + /* use module route if available */ + if (isset($segments[0]) && $routes = Modules::parse_routes($segments[0], implode('/', $segments))) { + $segments = $routes; + } + /* get the segments array elements */ + list($module, $directory, $controller) = array_pad($segments, 3, null); + /* check modules */ + foreach (Modules::$locations as $location => $offset) { + /* module exists? */ + if (is_dir($source = $location . $module . '/controllers/')) { + $this->module = $module; + $this->directory = $offset . $module . '/controllers/'; + /* module sub-controller exists? */ + if ($directory) { + /* module sub-directory exists? */ + if (is_dir($source . $directory . '/')) { + $source .= $directory . '/'; + $this->directory .= $directory . '/'; + /* module sub-directory controller exists? */ + if ($controller) { + if (is_file($source . ucfirst($controller) . $ext)) { + $this->located = 3; + + return array_slice($segments, 2); + } else + $this->located = -1; + } + } elseif (is_file($source . ucfirst($directory) . $ext)) { + $this->located = 2; + + return array_slice($segments, 1); + } else + $this->located = -1; } - /* application sub-sub-directory controller exists? */ - if ($controller) { - if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . '/' . ucfirst($controller) . $ext)) { - $this->directory = $module . '/' . $directory . '/'; + /* module controller exists? */ + if (is_file($source . ucfirst($module) . $ext)) { + $this->located = 1; - return array_slice($segments, 2); - } + return $segments; } } - /* application controllers sub-directory exists? */ - if (is_dir(APPPATH . 'controllers/' . $module . '/')) { + } + if (!empty($this->directory)) + return; + /* application sub-directory controller exists? */ + if ($directory) { + if (is_file(APPPATH . 'controllers/' . $module . '/' . ucfirst($directory) . $ext)) { $this->directory = $module . '/'; return array_slice($segments, 1); } - /* application controller exists? */ - if (is_file(APPPATH . 'controllers/' . ucfirst($module) . $ext)) { - return $segments; + /* application sub-sub-directory controller exists? */ + if ($controller) { + if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . '/' . ucfirst($controller) . $ext)) { + $this->directory = $module . '/' . $directory . '/'; + + return array_slice($segments, 2); + } } - $this->located = -1; } + /* application controllers sub-directory exists? */ + if (is_dir(APPPATH . 'controllers/' . $module . '/')) { + $this->directory = $module . '/'; - /* set module path */ - protected function _set_module_path(&$_route) - { - if (!empty($_route)) { - // Are module/directory/controller/method segments being specified? - $sgs = sscanf($_route, '%[^/]/%[^/]/%[^/]/%s', $module, $directory, $class, $method); - // set the module/controller directory location if found - if ($this->locate(array( - $module, - $directory, - $class - ))) { - //reset to class/method - switch ($sgs) { - case 1: - $_route = $module . '/index'; - break; - case 2: - $_route = ($this->located < 2) ? $module . '/' . $directory : $directory . '/index'; - break; - case 3: - $_route = ($this->located == 2) ? $directory . '/' . $class : $class . '/index'; - break; - case 4: - $_route = ($this->located == 3) ? $class . '/' . $method : $method . '/index'; - break; - } + return array_slice($segments, 1); + } + /* application controller exists? */ + if (is_file(APPPATH . 'controllers/' . ucfirst($module) . $ext)) { + return $segments; + } + $this->located = -1; + } + + /* set module path */ + protected function _set_module_path(&$_route) + { + if (!empty($_route)) { + // Are module/directory/controller/method segments being specified? + $sgs = sscanf($_route, '%[^/]/%[^/]/%[^/]/%s', $module, $directory, $class, $method); + // set the module/controller directory location if found + if ($this->locate(array( + $module, + $directory, + $class + ))) { + //reset to class/method + switch ($sgs) { + case 1: + $_route = $module . '/index'; + break; + case 2: + $_route = ($this->located < 2) ? $module . '/' . $directory : $directory . '/index'; + break; + case 3: + $_route = ($this->located == 2) ? $directory . '/' . $class : $class . '/index'; + break; + case 4: + $_route = ($this->located == 3) ? $class . '/' . $method : $method . '/index'; + break; } } } + } - public function set_class($class) - { + public function set_class($class) + { // $suffix = $this->config->item('controller_suffix'); // if (strpos($class, $suffix) === FALSE) - $suffix = strval($this->config->item('controller_suffix')); - $pos = !empty($suffix) ? strpos($class, $suffix) : false; - if ($pos === false) { - $class .= $suffix; - } - parent::set_class($class); + $suffix = strval($this->config->item('controller_suffix')); + $pos = !empty($suffix) ? strpos($class, $suffix) : false; + if ($pos === false) { + $class .= $suffix; } + parent::set_class($class); } } +