/** * Set the route mapping * * This function determines what should be served based on the URI request, * as well as any "routes" that have been set in the routing config file. * * @access private * @return void */ function _set_routing() { // REMOVED: query string support detection - query strings are supported, but routes are required // Fetch the complete URI string $this->uri->_fetch_uri_string(); // Do we need to remove the URL suffix? $this->uri->_remove_url_suffix(); // Compile the segments into an array $this->uri->_explode_segments(); // bottom line: we don't do anything unless we're inside a CI request if (!count($this->uri->segments) || !($gateway = $this->uri->segments[0]) || $gateway != wpci_get_slug()) { return FALSE; } // attempt to activate pluggable application (might not actually exist...) WPCI::activate($this->uri->segments); // Load the routes.php file. $routes_path = WPCI::routes(); if (file_exists($routes_path)) { @(include $routes_path); } $this->routes = (!isset($route) or !is_array($route)) ? array() : $route; // Set the default controller so we can display it in the event // the URI doesn't correlate to a valid controller. $this->default_controller = (!isset($this->routes['default_controller']) or $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); unset($this->routes['default_controller']); // pluggable application is active, but no controller specified - go default if (WPCI::active_app_path() != APPPATH && count($this->uri->segments) < 3) { $this->go_default(); return; } else { if (WPCI::active_app_path() == APPPATH && count($this->uri->segments) < 2) { $this->go_default(); return; } } // Parse any custom routing that may exist $this->_parse_routes(); // Re-index the segment array so that it starts with 1 rather than 0 $this->uri->_reindex_segments(); }
private static function execute_admin() { global $RTR, $CI, $EXT, $BM, $URI, $OUT; // process annotations so that tokens are defined WPCI::process_menu_annotations(); if ($token = isset($_REQUEST['page']) ? $_REQUEST['page'] : null) { $class = null; $method = null; $app = null; $directory = null; $app_path = null; // exact match for token? if (isset(WPCI::$app_index[$token])) { // load the menu settings $menu = WPCI::$app_index[$token]; // tell WPCI which app is active $app = $menu['app']; WPCI::activate($app); // load the application controller $app_path = $menu['app_path']; require_once $app_path; $BM->mark('loading_time_base_classes_end'); // create an instance of the controller $class = $menu['class']; $method = $menu['method_name']; } else { if ($token == 'wp-ci') { $app = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $class = isset($_REQUEST['c']) ? strtolower($_REQUEST['c']) : 'settings'; $method = isset($_REQUEST['m']) ? $_REQUEST['m'] : 'index'; $directory = isset($_REQUEST['d']) ? $_REQUEST['d'] : null; // if app is specified, activate it... (otherwise the core application will be used) if ($app) { WPCI::activate($app); } if ($directory) { $app_path = WPCI::active_app_path() . "/controllers/{$directory}/{$class}" . EXT; } else { $app_path = WPCI::active_app_path() . "/controllers/{$class}" . EXT; } if (!file_exists($app_path)) { wp_die("I don't know how to do <b>{$class}/{$method}</b>."); } // load the contorller require_once $app_path; } } if ($class && $method) { // fake the router into thinking he did his job... $RTR->set_app($app); $RTR->set_class($class); $RTR->set_method($method); $RTR->set_directory($directory); $BM->mark('loading_time_base_classes_end'); if (!class_exists($class)) { wp_die("I can't find <b>{$class}/{$method}</b>."); } // make sure app class is at the top of the annotations stack $ann = Annotations::get("{$app}/{$class}", $app_path); // evaluate permissions, but only when they are specified for evaluation $user_can = true; if (count($ann->for_class('user_must') + $ann->for_class('user_can') + $ann->for_method($method, 'user_must') + $ann->for_method($method, 'user_can'))) { // first, test all user_must annotations foreach ($ann->for_class('user_must') as $cap) { if (!current_user_can($cap)) { $user_can = false; break; } } // next, test for method if ($user_can) { foreach ($ann->for_method($method, 'user_must') as $cap) { if (!current_user_can($cap)) { $user_can = false; break; } } // then, test user_can if ($user_can) { $user_can = false; foreach ($ann->for_class('user_can') as $cap) { $user_can = $user_can || current_user_can($cap); } foreach ($ann->for_method($method, 'user_can') as $cap) { $user_can = $user_can || current_user_can($cap); } } } } if ($method == 'controller' or strncmp($method, '_', 1) == 0 or in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller'))) or !$user_can) { wp_die("You're not allowed to do <b>{$class}/{$method}</b>."); } $EXT->_call_hook('pre_controller'); $BM->mark('controller_execution_time_( ' . $class . ' / ' . $method . ' )_start'); $CI = new $class(); $CI->method = strtoupper($_SERVER['REQUEST_METHOD']); $EXT->_call_hook('post_controller_constructor'); // ajax annotation = no header $is_ajax = $ann->for_class('ajax') || $ann->for_method($method, 'ajax'); $no_chrome = $ann->for_class('no_chrome') || $ann->for_method($method, 'chrome'); if ($is_ajax || $no_chrome) { $_GET['noheader'] = 1; } $ajax_content = null; // Is there a "remap" function? if (method_exists($CI, '_remap')) { $CI->_remap($method); } else { // is_callable() returns TRUE on some versions of PHP 5 for private and protected // methods, so we'll use this workaround for consistent behavior if (!in_array(strtolower($method), array_map('strtolower', get_class_methods($CI)))) { wp_die("I'm not allowed to do <b>{$class}/{$method}</b>."); } log_message('debug', "Executing {$class}/{$method}()"); // Call the requested method. // Any URI segments present (besides the class/function) will be passed to the method for convenience if ($is_ajax || $no_chrome) { ob_start(); } call_user_func_array(array(&$CI, $method), array()); if ($is_ajax || $no_chrome) { $ajax_content = ob_get_clean(); } } $BM->mark('controller_execution_time_( ' . $class . ' / ' . $method . ' )_end'); $EXT->_call_hook('post_controller'); $EXT->_call_hook('post_system'); if (class_exists('CI_DB') and isset($CI->db)) { $CI->db->close(); } // if this was an ajax request, then we display the output and terminate if ($is_ajax || $no_chrome) { if ($is_ajax) { header('Content-type: application/json', true); } echo $ajax_content; $OUT->_display(); exit(0); } } } }