parse_routes() public static method

Parse module routes *
public static parse_routes ( $module, $uri )
コード例 #1
0
ファイル: Router.php プロジェクト: budhinusa/kurcaci
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     //print_r(Modules::$locations);die;
     /* check modules */
     foreach (Modules::$locations as $location => $offset) {
         if (!is_dir($location . $module)) {
             list($client, $module, $directory, $controller) = array_pad($segments, 4, NULL);
         }
         /* module exists? */
         if (is_dir($source = $location . $module . '/controllers/')) {
             $this->module = $module;
             $this->directory = $offset . $module . '/controllers/';
             /* module sub-controller exists? */
             if ($directory and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #2
0
ファイル: BF_Router.php プロジェクト: brkrishna/freelance
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . '.php';
     /* 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 && is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory && is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller && is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     foreach (array(APPPATH, BFPATH) as $searchPath) {
         /* application controller exists? */
         if (is_file($searchPath . 'controllers/' . $module . $ext)) {
             return $segments;
         }
         /* application sub-directory controller exists? */
         if ($directory && is_file($searchPath . 'controllers/' . $module . '/' . $directory . $ext)) {
             $this->directory = $module . '/';
             return array_slice($segments, 1);
         }
         /* application sub-directory default controller exists? */
         if (is_file($searchPath . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
             $this->directory = $module . '/';
             return array($this->default_controller);
         }
     }
 }
コード例 #3
0
ファイル: Router.php プロジェクト: Garybaldy/rotio
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $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 = $offset . '/' . $module . '/controllers/')) {
             $this->module = $module;
             $this->directory = '../../' . $offset . '/' . $module . '/controllers/';
             // custom disini ... pakai dua kali segment '../' karena di 'core/CodeIgniter.php' langsung di fix dari 'applicaton/controller'
             /* module sub-controller exists? */
             if ($directory and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #4
0
ファイル: Router.php プロジェクト: hqye/stblog
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     /* use module route if available */
     if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     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 and is_file($source . $directory . EXT)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($module_subdir = $source . $directory . '/')) {
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($module_subdir . $directory . EXT)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($module_subdir . $controller . EXT)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . EXT)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . EXT)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . EXT)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
 }
コード例 #5
0
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     if (isset($segments[0]) && $segments[0] == 'admin') {
         $lang = 'en';
     } else {
         if (isset($segments[0]) && $segments[0] == 'tv') {
             $lang = 'en';
         } else {
             if (count($segments) >= 2) {
                 $lang = $segments[0];
                 array_shift($segments);
             } else {
                 $res = explode('/', $this->routes['default_controller']);
                 $lang = $res[0];
                 $segments = array($res[1]);
             }
         }
     }
     // echo $lang;
     // print_r($segments);die;
     /* 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 and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #6
0
ファイル: Router.php プロジェクト: johnotaalo/zerotech
 /** 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;
                         }
                     }
                 } else {
                     if (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);
         }
         /* 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);
             }
         }
     }
     /* application controllers sub-directory exists? */
     if (is_dir(APPPATH . 'controllers/' . $module . '/')) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . ucfirst($module) . $ext)) {
         return $segments;
     }
     $this->located = -1;
 }
コード例 #7
0
ファイル: Router.php プロジェクト: wildanSawaludin/ci-cms
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     /* but only if we are not in back-end admin */
     if (isset($segments[0]) and (isset($segments[1]) and $segments[1] != 'admin') and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     foreach (Modules::$locations as $location => $offset) {
         if (is_dir($source = $location . $module . '/controllers/')) {
             $this->module = $module;
             $this->directory = $offset . $module . '/controllers/';
             /* module sub-controller exists? */
             if ($directory and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($module_subdir = $source . $directory . '/')) {
                 $this->directory .= $directory . '/';
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($module_subdir . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
                 /* module sub-directory controller exists? */
                 if (is_file($module_subdir . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
         // End
     }
     // End foreach()
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
 }
コード例 #8
0
ファイル: Router.php プロジェクト: SevenMonks/100cities-dev
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $this->location = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     $routed = implode("/", $segments);
     /* use module route if available and use exact module location if exists */
     if (isset($segments[0]) && $this->module_map($segments[0]) and list($routes) = Modules::parse_routes($segments[0], $routed, $this->module_map($segments[0]))) {
         $segments = $routes;
     } elseif (isset($segments[0])) {
         //log_message('debug', "Scanning for first match in all modules' routing files with the URI segment: " . $routed);
         //Get all of the module names and locations
         $directories = $this->module_map();
         foreach ($directories as $module => $locations) {
             if (list($routes) = Modules::parse_routes($module, $routed, array($module => $locations))) {
                 $segments = $routes;
                 //Since a route is found, no need to keep looking, break out of loop
                 break;
             }
         }
     }
     // Let's see where the request originated ie, from a module or router, (is there a better way?)
     // If it comes from a router that assumes it is being loaded via a public website address, if it comes from
     // a module then that means it was called from somewhere internally. Tests indicate this is almost a free
     // task, benchmarks show 0.0000 seconds to complete, so not even traceable.
     $trace = debug_backtrace();
     $module_source = isset($trace[1]['class']) && $trace[1]['class'] == 'Modules' && isset($trace[1]['function']) && $trace[1]['function'] == 'load';
     // Should all modules be unaccessable unless a route explicitly matches?
     if ($this->remove_default_routes && !$module_source && empty($routes) && !$this->_validate_route($routed)) {
         return;
     }
     // Let's make sure all segments are lower case. It is possible in routing files that uppercase letters are
     // used. This ensures everything gets translated to lowercase. The main reason for doing this is that on
     // Windows machines since files will match any case, it may work there, but on Linux machines it must match
     // the exact case. This could cause differences between development machines and production machines which
     // would allow a route to work fine on Windows, but not on Linux, and may be hard to trace the cause. By
     // adding this you should always ensure all controllers are in lowercase.
     $segments = array_map('strtolower', $segments);
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     /* check modules */
     $directories = $this->module_map($module);
     foreach ($directories as $module => $locations) {
         foreach ($locations as $location) {
             $offset = Modules::$locations[$location];
             /* module exists? */
             if (is_dir($source = $location . $module . '/controllers/')) {
                 $this->module = $module;
                 $this->directory = $offset . $module . '/controllers/';
                 $this->location = $location;
                 /* module sub-controller exists? */
                 if ($directory and is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory exists? */
                 if ($directory and is_dir($source . $directory . '/')) {
                     $source = $source . $directory . '/';
                     $this->directory .= $directory . '/';
                     /* module sub-directory controller exists? */
                     if (is_file($source . $directory . $ext)) {
                         return array_slice($segments, 1);
                     }
                     /* module sub-directory sub-controller exists? */
                     if ($controller and is_file($source . $controller . $ext)) {
                         return array_slice($segments, 2);
                     }
                 }
                 /* module controller exists? */
                 if (is_file($source . $module . $ext)) {
                     return $segments;
                 }
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #9
0
 public function locate($segments, $router_initialization = true)
 {
     //
     // Resolving the language.
     if ($router_initialization) {
         if (!empty($segments) && $this->config->valid_language_uri_segment($segments[0])) {
             $language = $this->config->language_by_uri_segment($segments[0]);
             array_shift($segments);
             $this->config->set_current_language($language);
             if (empty($segments)) {
                 $segments = array($this->default_controller, 'index');
             }
         }
     }
     // Processing slugs, if there are any.
     if ($router_initialization) {
         $segments = $this->remap($segments, $router_initialization);
     }
     $this->module = '';
     $this->directory = '';
     // 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($segment0, $segment1, $segment2) = array_pad($segments, 3, NULL);
     $segment0 = str_replace('-', '_', $segment0);
     $segment1 = str_replace('-', '_', $segment1);
     $segment2 = str_replace('-', '_', $segment2);
     // Check modules.
     foreach (Modules::$locations as $location => $offset) {
         // Module exists?
         if (is_dir($source = $location . $segment0 . '/controllers/')) {
             $is_module_default_controller = false;
             $is_module_controller = false;
             $is_module_directory = false;
             $is_module_directory_default_controller = false;
             $is_module_directory_controller = false;
             $subdirectory = '';
             $this->module = $segment0;
             $this->directory = $offset . $segment0 . '/controllers/';
             // module/controller
             if ($segment1 && ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1))) {
                 $is_module_controller = true;
             }
             // module/directory
             if ($segment1 && is_dir($source . $segment1 . '/')) {
                 $is_module_directory = true;
                 $source = $source . $segment1 . '/';
                 $subdirectory = $this->directory . $segment1 . '/';
                 // module/directory (deault_controller = directory)
                 if ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1)) {
                     $is_module_directory_default_controller = true;
                 }
                 // module/directory/controller
                 if ($segment2 && ($this->is_controller($source . ucfirst($segment2)) || $this->is_controller($source . $segment2))) {
                     $is_module_directory_controller = true;
                 }
             }
             // module (deault_controller = module)
             if ($this->is_controller($source . ucfirst($segment0)) || $this->is_controller($source . $segment0)) {
                 $is_module_default_controller = true;
             }
             /*
             // This is the original logic.
             if ($is_module_controller) {
                 return array_slice($segments, 1);
             } elseif ($is_module_directory) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_default_controller) {
                     return array_slice($segments, 1);
                 } elseif ($is_module_directory_controller) {
                     return array_slice($segments, 2);
                 }
             } elseif ($is_module_default_controller) {
                 return $segments;
             }
             */
             // This is the modified logic, Ivan Tcholakov, 16-JUN-2012.
             $result = false;
             if ($is_module_controller && $is_module_directory && ($is_module_directory_default_controller || $is_module_directory_controller)) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_default_controller) {
                     $result = array_slice($segments, 1);
                     if ($router_initialization) {
                         $this->rdir = $segment0 . '/';
                     }
                 } elseif ($is_module_directory_controller) {
                     $result = array_slice($segments, 2);
                     if ($router_initialization) {
                         $this->rdir = $segment0 . '/' . $segment1 . '/';
                     }
                 }
             } elseif ($is_module_controller) {
                 $result = array_slice($segments, 1);
                 if ($router_initialization) {
                     $this->rdir = $segment0 . '/';
                 }
             } elseif ($is_module_directory) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_controller) {
                     $result = array_slice($segments, 2);
                     if ($router_initialization) {
                         $this->rdir = $segment0 . '/' . $segment1 . '/';
                     }
                 } elseif ($is_module_directory_default_controller) {
                     $result = array_slice($segments, 1);
                     if ($router_initialization) {
                         $this->rdir = $segment0 . '/';
                     }
                 }
             } elseif ($is_module_default_controller) {
                 $result = $segments;
             }
             if ($result !== false) {
                 return $result;
             }
             //
         }
     }
     // Application controller exists?
     if ($this->is_controller(APPPATH . 'controllers/' . ucfirst($segment0)) || $this->is_controller(APPPATH . 'controllers/' . $segment0) || $this->is_controller(COMMONPATH . 'controllers/' . ucfirst($segment0)) || $this->is_controller(COMMONPATH . 'controllers/' . $segment0)) {
         return $segments;
     }
     // Application sub-directory controller exists?
     if ($segment1 && ($this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . ucfirst($segment1)) || $this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . $segment1) || $this->is_controller(COMMONPATH . 'controllers/' . $segment0 . '/' . ucfirst($segment1)) || $this->is_controller(COMMONPATH . 'controllers/' . $segment0 . '/' . $segment1))) {
         $this->directory = $segment0 . '/';
         if ($router_initialization) {
             $this->rdir = $segment0 . '/';
         }
         return array_slice($segments, 1);
     }
     // Application sub-directory default controller exists?
     if ($this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . ucfirst($this->default_controller)) || $this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . $this->default_controller) || $this->is_controller(COMMONPATH . 'controllers/' . $segment0 . '/' . ucfirst($this->default_controller)) || $this->is_controller(COMMONPATH . 'controllers/' . $segment0 . '/' . $this->default_controller)) {
         $this->directory = $segment0 . '/';
         return array($this->default_controller);
     }
 }
コード例 #10
0
ファイル: MY_Router.php プロジェクト: kevinmel2000/ci_webblog
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     // 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($segment0, $segment1, $segment2) = array_pad($segments, 3, NULL);
     $segment0 = str_replace('-', '_', $segment0);
     $segment1 = str_replace('-', '_', $segment1);
     $segment2 = str_replace('-', '_', $segment2);
     // Check modules.
     foreach (Modules::$locations as $location => $offset) {
         // Module exists?
         if (is_dir($source = $location . $segment0 . '/controllers/')) {
             $is_module_default_controller = false;
             $is_module_controller = false;
             $is_module_directory = false;
             $is_module_directory_default_controller = false;
             $is_module_directory_controller = false;
             $subdirectory = '';
             $this->module = $segment0;
             $this->directory = $offset . $segment0 . '/controllers/';
             // module/controller
             if ($segment1 && ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1))) {
                 $is_module_controller = true;
             }
             // module/directory
             if ($segment1 && is_dir($source . $segment1 . '/')) {
                 $is_module_directory = true;
                 $source = $source . $segment1 . '/';
                 $subdirectory = $this->directory . $segment1 . '/';
                 // module/directory (deault_controller = directory)
                 if ($this->is_controller($source . ucfirst($segment1)) || $this->is_controller($source . $segment1)) {
                     $is_module_directory_default_controller = true;
                 }
                 // module/directory/controller
                 if ($segment2 && ($this->is_controller($source . ucfirst($segment2)) || $this->is_controller($source . $segment2))) {
                     $is_module_directory_controller = true;
                 }
             }
             // module (deault_controller = module)
             if ($this->is_controller($source . ucfirst($segment0)) || $this->is_controller($source . $segment0)) {
                 $is_module_default_controller = true;
             }
             /*
             // This is the original logic.
             if ($is_module_controller) {
                 return array_slice($segments, 1);
             } elseif ($is_module_directory) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_default_controller) {
                     return array_slice($segments, 1);
                 } elseif ($is_module_directory_controller) {
                     return array_slice($segments, 2);
                 }
             } elseif ($is_module_default_controller) {
                 return $segments;
             }
             */
             // This is the modified logic, Ivan Tcholakov, 16-JUN-2012.
             $result = false;
             if ($is_module_controller && $is_module_directory && ($is_module_directory_default_controller || $is_module_directory_controller)) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_default_controller) {
                     $result = array_slice($segments, 1);
                 } elseif ($is_module_directory_controller) {
                     $result = array_slice($segments, 2);
                 }
             } elseif ($is_module_controller) {
                 $result = array_slice($segments, 1);
             } elseif ($is_module_directory) {
                 $this->directory = $subdirectory;
                 if ($is_module_directory_controller) {
                     $result = array_slice($segments, 2);
                 } elseif ($is_module_directory_default_controller) {
                     $result = array_slice($segments, 1);
                 }
             } elseif ($is_module_default_controller) {
                 $result = $segments;
             }
             if ($result !== false) {
                 return $result;
             }
             //
         }
     }
     // Application controller exists?
     if ($this->is_controller(APPPATH . 'controllers/' . ucfirst($segment0)) || $this->is_controller(APPPATH . 'controllers/' . $segment0)) {
         return $segments;
     }
     // Application sub-directory controller exists?
     if ($segment1 && ($this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . ucfirst($segment1)) || $this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . $segment1))) {
         $this->directory = $segment0 . '/';
         return array_slice($segments, 1);
     }
     // Application sub-directory default controller exists?
     if ($this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . ucfirst($this->default_controller)) || $this->is_controller(APPPATH . 'controllers/' . $segment0 . '/' . $this->default_controller)) {
         $this->directory = $segment0 . '/';
         return array($this->default_controller);
     }
 }
コード例 #11
0
ファイル: Router.php プロジェクト: gamchantoi/sisfo-ft
 /** Locate the controller **/
 public function locate($segments)
 {
     /**
      * Load the site ref for multi-site support
      */
     if (!defined('SITE_REF')) {
         require_once BASEPATH . 'database/DB' . EXT;
         if (DB()->table_exists('core_sites')) {
             $site = DB()->where('domain', SITE_DOMAIN)->get('core_sites')->row();
             $locations = array();
             // Check to see if the site retrieval was successful. If not then
             // we will let MY_Controller handle the errors.
             if (isset($site->ref)) {
                 foreach (config_item('modules_locations') as $location => $offset) {
                     $locations[str_replace('__SITE_REF__', $site->ref, $location)] = str_replace('__SITE_REF__', $site->ref, $offset);
                 }
                 // Set the session config to the correct table using the config name (but removing 'default_')
                 $this->config->set_item('sess_table_name', $site->ref . '_' . str_replace('default_', '', config_item('sess_table_name')));
                 // The site ref. Used for building site specific paths
                 define('SITE_REF', $site->ref);
                 // Path to uploaded files for this site
                 define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
                 // Path to the addon folder for this site
                 define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
                 Modules::$locations = $locations;
             }
         }
     }
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $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 and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #12
0
ファイル: MY_Router.php プロジェクト: binaek89/cms-canvas
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     // =========================================================================
     // Replace underscores with dashes
     // -- added by Mark Price
     $module = str_replace('_', ' ', $module);
     $module = str_replace('-', '_', $module);
     $controller = str_replace('_', ' ', $controller);
     $controller = str_replace('-', '_', $controller);
     $directory = str_replace('_', ' ', $directory);
     $directory = str_replace('-', '_', $directory);
     // =========================================================================
     /* 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 and is_file($source . $directory . $ext)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     return array_slice($segments, 2);
                 }
                 // =========================================================================
                 // If a controller name matches the module name inside the admin directory dont force controller name in URI
                 // Ex: admin/module/method
                 // -- added by Mark Price
                 if ($directory == 'admin') {
                     if ($controller and is_file($source . $module . $ext)) {
                         $segments = array_slice($segments, 2);
                         array_unshift($segments, $module);
                         return $segments;
                     }
                 }
                 // =========================================================================
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #13
0
ファイル: IGO_Router.php プロジェクト: ci-blox/Ignition-Go
 /**
  * Locate the controller.
  *
  * Used by Modules::load().
  *
  * @param  array $segments The URL segments.
  *
  * @return array The segments indicating the location of the controller.
  */
 public function locate($segments)
 {
     $this->located = 0;
     $ext = $this->config->item('controller_suffix') . '.php';
     /* 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) {
                 if (is_file($source . ucfirst($directory) . $ext)) {
                     $this->located = 2;
                     return array_slice($segments, 1);
                 }
                 /* 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;
     }
     foreach (array(APPPATH, IGOPATH) as $searchPath) {
         /* application controller exists? */
         if (is_file("{$searchPath}controllers/" . ucfirst($module) . $ext)) {
             return $segments;
         }
         /* application sub-directory controller exists? */
         if ($directory) {
             if (is_file("{$searchPath}controllers/{$module}/" . ucfirst($directory) . $ext)) {
                 $this->directory = "{$module}/";
                 return array_slice($segments, 1);
             }
             /* application sub-sub-directory controller exists? */
             if ($controller) {
                 if (is_file("{$searchPath}controllers/{$module}/{$directory}/" . ucfirst($controller) . $ext)) {
                     $this->directory = "{$module}/{$directory}/";
                     return array_slice($segments, 2);
                 }
             }
         }
         /* application sub-directory default controller exists? */
         if (is_file("{$searchPath}controllers/{$module}/" . ucfirst($this->default_controller) . $ext)) {
             $this->directory = "{$module}/";
             return array($this->default_controller);
         }
     }
     $this->located = -1;
 }
コード例 #14
0
ファイル: Router.php プロジェクト: vitalik199415/ozar
 /** Locate the controller **/
 public function locate($segments)
 {
     //echo var_dump($segments).'<br>';
     $this->module = '';
     $this->directory = '';
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     if (isset($segments[0]) and $routes = Modules::parse_routes($segments[0], implode('/', $segments))) {
         $segments = $routes;
     }
     /* get the segments array elements */
     list($module, $directory, $controller) = array_pad($segments, 3, NULL);
     //echo $module.' - '.$directory.' - '.$controller.' -<BR>';
     /* check modules */
     foreach (Modules::$locations as $location => $offset) {
         /*if(is_dir(USERS_DIRECTORY.$location.$module.'/controllers/'))
         		{
         			$location = USERS_DIRECTORY.$location;
         		}*/
         //echo $location.$module.'/controllers/'.'<br>';
         /* module exists? */
         if (defined("USERS_DIRECTORY") && is_dir(USERS_DIRECTORY . $location . $module . '/controllers/') || is_dir($location . $module . '/controllers/')) {
             $source = $location . $module . '/controllers/';
             $this->module = $module;
             $this->directory = $offset . $module . '/controllers/';
             /* module sub-controller exists? */
             //echo "@@".$source.$directory.$ext."@@<br>";
             if ($directory and @fopen($source . $directory . $ext, 'r', TRUE)) {
                 return array_slice($segments, 1);
             }
             /* module sub-directory exists? */
             //echo $source.$directory.'/'.'<br>';
             if ($directory and is_dir($source . $directory . '/')) {
                 $source = $source . $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (@fopen($source . $directory . $ext, 'r', TRUE)) {
                     return array_slice($segments, 1);
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and @fopen($source . $controller . $ext, 'r', TRUE)) {
                     return array_slice($segments, 2);
                 }
             }
             //echo $source.$module.$ext.'<br>';
             /* module controller exists? */
             if (@fopen($source . $module . $ext, 'r', TRUE)) {
                 return $segments;
             }
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
         return $segments;
     }
     /* application sub-directory controller exists? */
     if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
         $this->directory = $module . '/';
         return array_slice($segments, 1);
     }
     /* application sub-directory default controller exists? */
     if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }
コード例 #15
0
    /** Locate the controller **/
    public function locate($segments)
    {
        /**
         * Load the site ref for multi-site support if the "sites" module exists
         * and the multi-site constants haven't been defined already (hmvc request)
         */
        if ($path = self::is_multisite() and !defined('SITE_REF')) {
            require_once BASEPATH . 'database/DB' . EXT;
            # deprecated Remove this for 2.3, as this was too early for a migration
            if (!DB()->table_exists('core_domains')) {
                // Create alias table
                DB()->query('	
					CREATE TABLE `core_domains` (
					  `id` int NOT NULL AUTO_INCREMENT,
					  `domain` varchar(100) NOT NULL,
					  `site_id` int NOT NULL,
					  `type` enum("park", "redirect") NOT NULL DEFAULT "park",
					  PRIMARY KEY (`id`),
					  KEY `domain` (`domain`),
					  UNIQUE `unique` (`domain`)
					) ENGINE=InnoDB DEFAULT CHARSET=utf8; ');
            }
            $site = DB()->select('site.name, site.ref, site.domain, site.active, alias.domain as alias_domain, alias.type as alias_type')->where('site.domain', SITE_DOMAIN)->or_where('alias.domain', SITE_DOMAIN)->join('core_domains alias', 'alias.site_id = site.id', 'left')->get('core_sites site')->row();
            // If the site is disabled we set the message in a constant for MY_Controller to display
            if (isset($site->active) and !$site->active) {
                $status = DB()->where('slug', 'status_message')->get('core_settings')->row();
                define('STATUS', $status ? $status->value : 'This site has been disabled by a super-administrator');
            }
            // If this domain is an alias and it is a redirect
            if ($site and $site->alias_domain !== null and $site->alias_type === 'redirect' and str_replace(array('http://', 'https://'), '', trim(strtolower(BASE_URL), '/')) !== $site->domain) {
                $protocol = !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
                // Send them off to the original domain
                header("Location: {$protocol}://{$site->domain}{$_SERVER['REQUEST_URI']}");
                exit;
            }
            // Check to see if the site retrieval was successful. If not then
            // we will let MY_Controller handle the errors.
            if (isset($site->ref)) {
                // Set the session config to the correct table using the config name (but removing 'default_')
                $this->config->set_item('sess_table_name', $site->ref . '_' . str_replace('default_', '', config_item('sess_table_name')));
                // The site ref. Used for building site specific paths
                define('SITE_REF', $site->ref);
                // Path to uploaded files for this site
                define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
                // Path to the addon folder for this site
                define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
                // the path to the MSM module
                define('MSMPATH', str_replace('__SITE_REF__', SITE_REF, $path));
            }
        }
        // we aren't running the Multi-Site Manager so define the defaults
        if (!defined('SITE_REF')) {
            // The site ref. Used for building site specific paths
            define('SITE_REF', 'default');
            // Path to uploaded files for this site
            define('UPLOAD_PATH', 'uploads/' . SITE_REF . '/');
            // Path to the addon folder for this site
            define('ADDONPATH', ADDON_FOLDER . SITE_REF . '/');
        }
        // update the config paths with the site specific paths
        self::update_module_locations(SITE_REF);
        $this->module = '';
        $this->directory = '';
        $ext = $this->config->item('controller_suffix') . EXT;
        /* use module route if available */
        if (isset($segments[0]) and $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 and is_file($source . $directory . $ext)) {
                    return array_slice($segments, 1);
                }
                /* module sub-directory exists? */
                if ($directory and is_dir($source . $directory . '/')) {
                    $source = $source . $directory . '/';
                    $this->directory .= $directory . '/';
                    /* module sub-directory controller exists? */
                    if (is_file($source . $directory . $ext)) {
                        return array_slice($segments, 1);
                    }
                    /* module sub-directory sub-controller exists? */
                    if ($controller and is_file($source . $controller . $ext)) {
                        return array_slice($segments, 2);
                    }
                }
                /* module controller exists? */
                if (is_file($source . $module . $ext)) {
                    return $segments;
                }
            }
        }
        /* application controller exists? */
        if (is_file(APPPATH . 'controllers/' . $module . $ext)) {
            return $segments;
        }
        /* application sub-directory controller exists? */
        if ($directory and is_file(APPPATH . 'controllers/' . $module . '/' . $directory . $ext)) {
            $this->directory = $module . '/';
            return array_slice($segments, 1);
        }
        /* application sub-directory default controller exists? */
        if (is_file(APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext)) {
            $this->directory = $module . '/';
            return array($this->default_controller);
        }
    }
コード例 #16
0
ファイル: Router.php プロジェクト: jpasosa/global
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->located = 0;
     $ext = $this->config->item('controller_suffix') . EXT;
     /* use module route if available */
     // habría que ver por qué entra acá . . . .
     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);
     // Agrego esta sección para controlar el frontend y el backend.
     if (isset($segments[0]) && $segments[0] != 'admin') {
         // si no figura admin, FRONTEND
         $prev_locations = Modules::$locations;
         if (is_array($prev_locations) and array_key_exists('application/backend/', $prev_locations)) {
             unset($prev_locations['application/backend/']);
             Modules::$locations = $prev_locations;
         }
         $this->config->config['modules_locations'] = array(APPPATH . 'frontend/' => '../frontend/');
     } else {
         // si dice /admin/xxxx BACKEND
         $prev_locations = Modules::$locations;
         if (is_array($prev_locations) and array_key_exists('application/frontend/', $prev_locations)) {
             unset($prev_locations['application/frontend/']);
             Modules::$locations = $prev_locations;
         }
         //unset($segments[0]);
         $this->config->config['modules_locations'] = array(APPPATH . 'backend/' => '../backend/');
     }
     // FIN
     /* check modules */
     foreach (Modules::$locations as $location => $offset) {
         if (isset($segments[0]) && $segments[0] == 'admin' && $offset == '../backend/') {
             if (isset($segments[1])) {
                 $source = $location . 'controllers/';
                 if (isset($segments[2]) and !is_dir($source . $directory . "/")) {
                     $module = $segments[1];
                     $controller = $segments[2];
                 } else {
                     $module = $segments[1];
                     if (isset($segments[2])) {
                         $controller = $segments[2];
                     }
                 }
             } else {
                 if (isset($this->routes['default_controller_admin'])) {
                     $module = $this->routes['default_controller_admin'];
                     $source = $location . 'controllers/';
                 }
             }
             /* 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;
                             }
                         }
                     } else {
                         if (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;
                 }
             }
         } else {
             /* 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;
                             }
                         }
                     } else {
                         if (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);
             }
             /* 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);
                 }
             }
         }
         /* application controllers sub-directory exists? */
         if (is_dir(APPPATH . 'controllers/' . $module . '/')) {
             $this->directory = $module . '/';
             return array_slice($segments, 1);
         }
     }
     /* application controller exists? */
     if (is_file(APPPATH . 'controllers/' . ucfirst($module) . $ext)) {
         return $segments;
     }
     $this->located = -1;
 }
コード例 #17
0
ファイル: Router.php プロジェクト: RCMmedia/rubicon
 /** Locate the controller **/
 public function locate($segments)
 {
     $this->module = '';
     $this->directory = '';
     $this->reldirectory = '';
     $ext = EXT;
     /* use module route if available */
     if (isset($segments[0]) and $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/';
             $this->reldirectory = '';
             $check_file = $source . $directory . '/';
             // echo "CHECK FILE 22 '$check_file'<br>";
             /* module sub-directory exists? */
             if ($directory and is_dir($check_file)) {
                 $source = $source . $directory . '/';
                 $this->reldirectory .= $directory . '/';
                 $this->directory .= $directory . '/';
                 /* module sub-directory controller exists? */
                 if (is_file($source . $directory . $ext)) {
                     $add_to_controller = join('/', array_slice($segments, 0, 1));
                     $return = array_slice($segments, 1);
                     $return[0] = $add_to_controller . '/' . $return[0];
                     return $return;
                 }
                 /* module sub-directory sub-controller exists? */
                 if ($controller and is_file($source . $controller . $ext)) {
                     $add_to_controller = join('/', array_slice($segments, 0, 2));
                     $return = array_slice($segments, 2);
                     $return[0] = $add_to_controller . '/' . $return[0];
                     return $return;
                 }
             }
             /* module sub-controller exists? */
             $check_file = $source . $directory . $ext;
             // echo "CHECK FILE 11 '$check_file'<br>";
             if ($directory and is_file($check_file)) {
                 $add_to_controller = join('/', array_slice($segments, 0, 1));
                 $return = array_slice($segments, 1);
                 $return[0] = $add_to_controller . '/' . $return[0];
                 return $return;
             }
             /* module controller exists? */
             if (is_file($source . $module . $ext)) {
                 return $segments;
             }
         }
     }
     /* APP PATH */
     /* application controller exists? */
     $check_file = APPPATH . 'controllers/' . $module . $ext;
     // echo "CHECK FILE 1 '$check_file'<br>";
     if (is_file($check_file)) {
         return $segments;
     }
     if ($directory && $controller) {
         $check_file = APPPATH . 'controllers/' . $module . '/' . $directory . '/' . $controller . $ext;
         // echo "CHECK FILE 3 '$check_file'<br>";
         if (is_file($check_file)) {
             $this->directory = $module . '/' . $directory . '/';
             $add_to_controller = join('/', array_slice($segments, 0, 2));
             $return = array_slice($segments, 2);
             $return[0] = $add_to_controller . '/' . $return[0];
             return $return;
         }
     }
     /* application sub-directory controller exists? */
     if ($directory) {
         $check_file = APPPATH . 'controllers/' . $module . '/' . $directory . $ext;
         // echo "CHECK FILE 2 '$check_file'<br>";
         if (is_file($check_file)) {
             $this->directory = $module . '/';
             $add_to_controller = join('/', array_slice($segments, 0, 1));
             $return = array_slice($segments, 1);
             $return[0] = $add_to_controller . '/' . $return[0];
             return $return;
         }
     }
     /* application sub-directory default controller exists? */
     $check_file = APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext;
     // echo "CHECK FILE 4 '$check_file'<br>";
     if (is_file($check_file)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
     /* SYSTEM PATH */
     /* application controller exists? */
     $check_file = NTS_SYSTEM_APPPATH . 'controllers/' . $module . $ext;
     // echo "CHECK FILE 5 '$check_file'<br>";
     if (is_file($check_file)) {
         return $segments;
     }
     if ($directory && $controller) {
         // echo "CHECK FILE 7 '$check_file'<br>";
         $check_file = NTS_SYSTEM_APPPATH . 'controllers/' . $module . '/' . $directory . '/' . $controller . $ext;
         if (is_file($check_file)) {
             $this->directory = $module . '/' . $directory . '/';
             $add_to_controller = join('/', array_slice($segments, 0, 2));
             $return = array_slice($segments, 2);
             $return[0] = $add_to_controller . '/' . $return[0];
             return $return;
         }
     }
     /* application sub-directory controller exists? */
     if ($directory) {
         // echo "CHECK FILE 6 '$check_file'<br>";
         $check_file = NTS_SYSTEM_APPPATH . 'controllers/' . $module . '/' . $directory . $ext;
         if (is_file($check_file)) {
             $this->directory = $module . '/';
             $add_to_controller = join('/', array_slice($segments, 0, 1));
             $return = array_slice($segments, 1);
             $return[0] = $add_to_controller . '/' . $return[0];
             return $return;
         }
     }
     /* application sub-directory default controller exists? */
     $check_file = NTS_SYSTEM_APPPATH . 'controllers/' . $module . '/' . $this->default_controller . $ext;
     // echo "CHECK FILE 8 '$check_file'<br>";
     if (is_file($check_file)) {
         $this->directory = $module . '/';
         return array($this->default_controller);
     }
 }