function render($url = null) { if ($url === null) { $prefixes = array_flip(Router::prefixes()); array_walk($prefixes, create_function('&$item', '$item = false;')); $url = array('plugin' => 'kcaptcha', 'controller' => 'captcha', 'action' => 'render_captcha') + $prefixes; } return sprintf('<img src="%s" />', $this->url($url)); }
public static function getPrefixes($current = null) { $prefixes = Router::prefixes(); $tmp = array(); // Negative all prefixes, except the current foreach ($prefixes as $prefix) { $tmp[$prefix] = $prefix == $current ? true : false; } return $tmp; }
/** * sets the crud mappings for prefix routes. * * @return void */ protected function _setPrefixMappings() { $crud = array('create', 'read', 'update', 'delete'); $map = array_combine($crud, $crud); $prefixes = Router::prefixes(); if (!empty($prefixes)) { foreach ($prefixes as $prefix) { $map = array_merge($map, array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete')); } } $this->mapActions($map); }
/** * sets the crud mappings for prefix routes. * * @return void */ protected function _setPrefixMappings() { if (!Configure::read('Access Control.rowLevel')) { return; } $crud = array('create', 'read', 'update', 'delete'); $map = array_combine($crud, $crud); $Controller = $this->Controller(); if ($Controller->Components->attached('RowLevelAcl')) { $settings = $Controller->Components->RowLevelAcl->settings; if (isset($settings['actionMap'])) { $map = array_merge($map, $settings['actionMap']); } } $prefixes = Router::prefixes(); if (!empty($prefixes)) { foreach ($prefixes as $prefix) { $map = array_merge($map, array($prefix . '_moveup' => 'update', $prefix . '_movedown' => 'update', $prefix . '_process' => 'delete', $prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete')); } } $this->mapActions($map); }
/** * _isActive * * Determine if the current link should have the class active * * @param mixed $item * @return bool */ protected function _isActive($item) { if (is_callable($this->_activeMode)) { $callback = $this->_activeMode; return $callback($this->_View, $item); } if ($this->_activeMode === 'exact') { $url = Router::normalize($item['url']); return $this->_here['url'] === $url; } $url = $item['url']; if (is_string($url)) { $url = Router::parse($url); if (!$url) { return false; } } $url += array('prefix' => isset($this->request->params['prefix']) ? $this->request->params['prefix'] : null, 'plugin' => $this->request->params['plugin'], 'controller' => $this->request->params['controller'], 'action' => $this->request->params['action']); $keys = array('plugin', 'controller', 'action'); $keys = array_slice($keys, 0, array_search($this->_activeMode, $keys) + 1); $keys = array_merge($keys, Router::prefixes()); $keys = array_flip($keys); $here = array_filter(array_intersect_key($this->_here['params'], $keys)); $link = array_filter(array_intersect_key($url, $keys)); ksort($here); ksort($link); return $link === $here; }
/** * Get the dynamic build path for an asset. */ protected function _getRoute($file) { $url = $this->options['buildUrl']; //escape out of prefixes. $prefixes = Router::prefixes(); foreach ($prefixes as $prefix) { if (!array_key_exists($prefix, $url)) { $url[$prefix] = false; } } $params = array($file, 'base' => false); $ext = $this->_Config->getExt($file); if (isset($this->_runtime[$ext][$file])) { $hash = $this->_getHashName($file, $ext); $components = $this->_Config->files($file); if ($hash) { $params[0] = $hash; } $params['?'] = array('file' => $components); } if ($this->_Config->isThemed($file)) { $params['?']['theme'] = $this->theme; } $url = Router::url(array_merge($url, $params)); return $url; }
/** * Generates a SQL explain link for a given query * * @param string $sql SQL query string you want an explain link for. * @return string Rendered Html link or '' if the query is not a select/describe */ function explainLink($sql, $connection) { if (!preg_match('/^(SELECT)/i', $sql)) { return ''; } App::import('Core', 'Security'); $hash = Security::hash($sql . $connection, null, true); $url = array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'sql_explain', 'ds' => $connection, 'sql' => $sql, 'hash' => $hash); foreach (Router::prefixes() as $prefix) { $url[$prefix] = false; } return $this->Html->link(__d('debug_kit', 'Explain', true), $url, array('class' => 'sql-explain-link')); }
* - `/:prefix/:controller/:action/*` * * If plugins are found in your application the following routes are created: * * - `/:plugin` a plugin shortcut route. * - `/:plugin/:controller` * - `/:plugin/:controller/:action/*` * * And lastly the following catch-all routes are connected. * * - `/:controller' * - `/:controller/:action/*' * * You can disable the connection of default routes by deleting the require inside APP/Config/routes.php. */ $prefixes = Router::prefixes(); if ($plugins = CakePlugin::loaded()) { App::uses('PluginShortRoute', 'Routing/Route'); foreach ($plugins as $key => $value) { $plugins[$key] = Inflector::underscore($value); } $pluginPattern = implode('|', $plugins); $match = array('plugin' => $pluginPattern, 'defaultRoute' => true); $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern, 'defaultRoute' => true); foreach ($prefixes as $prefix) { $params = array('prefix' => $prefix, $prefix => true); $indexParams = $params + array('action' => 'index'); Router::connect("/{$prefix}/:plugin", $indexParams, $shortParams); Router::connect("/{$prefix}/:plugin/:controller", $indexParams, $match); Router::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match); }
/** * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the * results (if autoRender is set). * * If no controller of given name can be found, invoke() shows error messages in * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called * Actions). * * @param string $url URL information to work on * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params * @return boolean Success * @access public */ function dispatch($url = null, $additionalParams = array()) { if ($this->base === false) { $this->base = $this->baseUrl(); } if (is_array($url)) { $url = $this->__extractParams($url, $additionalParams); } else { if ($url) { $_GET['url'] = $url; } $url = $this->getUrl(); $this->params = array_merge($this->parseParams($url), $additionalParams); } $this->here = $this->base . '/' . $url; /* xplico: we disable cache to avoid proxy error if ($this->asset($url) || $this->cached($url)) { return; } */ /* xplico step 1: proxy implementation */ $bheader = $_SERVER['HTTP_HOST']; if (empty($this->params['controller']) || $this->params['controller'] == 'http:' || stripos($bheader, $_SERVER['SERVER_ADDR']) === false && stripos($bheader, 'localhost') === false && stripos($bheader, 'demo.xplico.org') === false) { if (strstr($_SERVER['REQUEST_URI'], '/webs/hijacking/') !== false) { $this->params['controller'] = 'webs'; $this->params['action'] = 'hijacking'; } else { $this->params['controller'] = 'webs'; $this->params['action'] = 'view'; } } /* end xplico step 1 */ $controller =& $this->__getController(); /* xplico step 2 */ if (!is_object($controller)) { $this->params['controller'] = 'webs'; $this->params['action'] = 'view'; $controller =& $this->__getController(); } /* xplico: end */ if (!is_object($controller)) { Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot))); return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $privateAction = $this->params['action'][0] === '_'; $prefixes = Router::prefixes(); if (!empty($prefixes)) { if (isset($this->params['prefix'])) { $this->params['action'] = $this->params['prefix'] . '_' . $this->params['action']; } elseif (strpos($this->params['action'], '_') > 0) { list($prefix, $action) = explode('_', $this->params['action']); $privateAction = in_array($prefix, $prefixes); } } Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot))); if ($privateAction) { return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $controller->base = $this->base; $controller->here = $this->here; $controller->webroot = $this->webroot; $controller->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null; $controller->params =& $this->params; $controller->action =& $this->params['action']; $controller->passedArgs = array_merge($this->params['pass'], $this->params['named']); if (!empty($this->params['data'])) { $controller->data =& $this->params['data']; } else { $controller->data = null; } if (isset($this->params['return']) && $this->params['return'] == 1) { $controller->autoRender = false; } if (!empty($this->params['bare'])) { $controller->autoLayout = false; } return $this->_invoke($controller, $this->params); }
/** * Generates a SQL explain link for a given query * * @param string $sql SQL query string you want an explain link for. * @return string Rendered Html link or '' if the query is not a select/describe */ function explainLink($sql, $connection) { if (!preg_match('/^(SELECT)/i', $sql)) { return ''; } App::import('Core', 'Security'); $hash = Security::hash($sql . $connection, null, true); $url = array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'sql_explain'); foreach (Router::prefixes() as $prefix) { $url[$prefix] = false; } $form = $this->Form->create('log', array('url' => $url)); $form .= $this->Form->hidden('log.ds', array('value' => $connection)); $form .= $this->Form->hidden('log.sql', array('value' => $sql)); $form .= $this->Form->hidden('log.hash', array('value' => $hash)); $form .= $this->Form->submit(__d('debug_kit', 'Explain', true), array('div' => false, 'class' => 'sql-explain-link')); $form .= $this->Form->end(); return $form; }
/** * Initializes AuthComponent for use in the controller * * @param object $controller A reference to the instantiating controller object * @return void * @access public */ function initialize(&$controller, $settings = array()) { $this->controller =& $controller; $this->params = $controller->params; $crud = array('create', 'read', 'update', 'delete'); $this->_set($settings); $this->actionMap = array_merge(array_combine($crud, $crud), $this->actionMap); $this->_methods = $controller->methods; $prefixes = Router::prefixes(); if (!empty($prefixes)) { foreach ($prefixes as $prefix) { $this->actionMap = array_merge(array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete'), $this->actionMap); } } if (Configure::read() > 0) { App::import('Debugger'); Debugger::checkSecurityKeys(); } }
/** * Attempt to match a url array. If the url matches the route parameters and settings, then * return a generated string url. If the url doesn't match the route parameters, false will be returned. * This method handles the reverse routing or conversion of url arrays into string urls. * * @param array $url An array of parameters to check matching with. * @return mixed Either a string url for the parameters if they match or false. */ public function match($url) { if (!$this->compiled()) { $this->compile(); } $defaults = $this->defaults; if (isset($defaults['prefix'])) { $url['prefix'] = $defaults['prefix']; } //check that all the key names are in the url $keyNames = array_flip($this->keys); if (array_intersect_key($keyNames, $url) !== $keyNames) { return false; } // Missing defaults is a fail. if (array_diff_key($defaults, $url) !== array()) { return false; } $namedConfig = Router::namedConfig(); $prefixes = Router::prefixes(); $greedyNamed = $namedConfig['greedyNamed']; $allowedNamedParams = $namedConfig['rules']; $named = $pass = array(); foreach ($url as $key => $value) { // keys that exist in the defaults and have different values is a match failure. $defaultExists = array_key_exists($key, $defaults); if ($defaultExists && $defaults[$key] != $value) { return false; } elseif ($defaultExists) { continue; } // If the key is a routed key, its not different yet. if (array_key_exists($key, $keyNames)) { continue; } // pull out passed args $numeric = is_numeric($key); if ($numeric && isset($defaults[$key]) && $defaults[$key] == $value) { continue; } elseif ($numeric) { $pass[] = $value; unset($url[$key]); continue; } // pull out named params if named params are greedy or a rule exists. if ( ($greedyNamed || isset($allowedNamedParams[$key])) && ($value !== false && $value !== null) && (!in_array($key, $prefixes)) ) { $named[$key] = $value; continue; } // keys that don't exist are different. if (!$defaultExists && !empty($value)) { return false; } } //if a not a greedy route, no extra params are allowed. if (!$this->_greedy && (!empty($pass) || !empty($named))) { return false; } //check patterns for routed params if (!empty($this->options)) { foreach ($this->options as $key => $pattern) { if (array_key_exists($key, $url) && !preg_match('#^' . $pattern . '$#', $url[$key])) { return false; } } } return $this->_writeUrl(array_merge($url, compact('pass', 'named'))); }
/** * testPassedArgsOrder method * * @return void */ public function testPassedArgsOrder() { Router::connect('/test-passed/*', array('controller' => 'pages', 'action' => 'display', 'home')); Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2)); Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1)); Router::parse('/'); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 1, 'whatever')); $expected = '/test/whatever'; $this->assertEquals($expected, $result); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever')); $expected = '/test2/whatever'; $this->assertEquals($expected, $result); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever')); $expected = '/test-passed/whatever'; $this->assertEquals($expected, $result); Configure::write('Routing.prefixes', array('admin')); Router::reload(); $request = new CakeRequest(); Router::setRequestInfo($request->addParams(array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'url' => array('url' => 'protected/images/index')))->addPaths(array('base' => '', 'here' => '/protected/images/index', 'webroot' => '/'))); Router::connect('/protected/:controller/:action/*', array('controller' => 'users', 'action' => 'index', 'prefix' => 'protected')); Router::parse('/'); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/protected/images/add'; $this->assertEquals($expected, $result); $result = Router::prefixes(); $expected = array('admin', 'protected'); $this->assertEquals($expected, $result); }
/** * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set). * * If no controller of given name can be found, invoke() shows error messages in * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called * Actions). * * @param string $url URL information to work on * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params * @return boolean Success * @access public */ function dispatch($url = null, $additionalParams = array()) { $parse = true; if ($this->base === false) { $this->base = $this->baseUrl(); } if (is_array($url)) { $url = $this->__extractParams($url, $additionalParams); $parse = false; } if ($url !== null) { $_GET['url'] = $url; } if ($parse) { $url = $this->getUrl(); } $this->here = $this->base . '/' . $url; if ($this->cached($url)) { $this->_stop(); } if ($parse) { $this->params = array_merge($this->parseParams($url), $additionalParams); } $controller = $this->__getController(); if (!is_object($controller)) { Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot))); return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $missingAction = $missingView = $privateAction = false; if (empty($this->params['action'])) { $this->params['action'] = 'index'; } $prefixes = Router::prefixes(); if (!empty($prefixes)) { if (isset($this->params['prefix'])) { $this->params['action'] = $this->params['prefix'] . '_' . $this->params['action']; } elseif (strpos($this->params['action'], '_') !== false) { list($prefix, $action) = explode('_', $this->params['action']); $privateAction = in_array($prefix, $prefixes); } } $protected = array_map('strtolower', get_class_methods('controller')); $classMethods = array_map('strtolower', get_class_methods($controller)); if (in_array(strtolower($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) { $privateAction = true; } if (!in_array(strtolower($this->params['action']), $classMethods)) { $missingAction = true; } if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1) { $controller->autoRender = false; } $controller->base = $this->base; $controller->here = $this->here; $controller->webroot = $this->webroot; $controller->plugin = $this->plugin; $controller->params =& $this->params; $controller->action =& $this->params['action']; $controller->passedArgs = array_merge($this->params['pass'], $this->params['named']); if (!empty($this->params['data'])) { $controller->data =& $this->params['data']; } else { $controller->data = null; } if (!empty($this->params['bare'])) { $controller->autoLayout = false; } if (isset($this->params['layout'])) { if ($this->params['layout'] === '') { $controller->autoLayout = false; } else { $controller->layout = $this->params['layout']; } } if (isset($this->params['viewPath'])) { $controller->viewPath = $this->params['viewPath']; } foreach (array('components', 'helpers') as $var) { if (isset($this->params[$var]) && !empty($this->params[$var]) && is_array($controller->{$var})) { $diff = array_diff($this->params[$var], $controller->{$var}); $controller->{$var} = array_merge($controller->{$var}, $diff); } } Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot))); $controller->constructClasses(); if ($privateAction) { return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $controller->Component->initialize($controller); $controller->beforeFilter(); $controller->Component->startup($controller); return $this->_invoke($controller, $this->params, $missingAction); }
/** * Generates the asset tag of the chosen $method * * @param string $method Method name to call on HtmlHelper * @param string $destination The destination file to be generated. * @param array $url Array of url keys for making the asset location. * @return string Asset tag. */ protected function _generateAsset($method, $destination, $files, $url) { $fileString = 'file[]=' . implode('&file[]=', $files); $iniKey = $method == '_css' ? 'Css' : 'Javascript'; if (!empty($this->_iniFile[$iniKey]['timestamp']) && Configure::read('debug') < 2) { $destination = $this->_timestampFile($destination); } //escape out of prefixes. $prefixes = Router::prefixes(); foreach ($prefixes as $prefix) { if (!array_key_exists($prefix, $url)) { $url[$prefix] = false; } } $url = Router::url(array_merge($url, array($destination, '?' => $fileString, 'base' => false))); list($base, $query) = explode('?', $url); if (file_exists(WWW_ROOT . $base)) { $url = $base; } if ($method == '_css') { return $this->Html->css($url); } else { return $this->Html->script($url); } }
/** * Check if the request's action is marked as private, with an underscore, of if the request is attempting to * directly accessing a prefixed action. * * @param CakeRequest $request The request to check * @return boolean */ protected function _isPrivateAction($request) { $privateAction = $request->params['action'][0] === '_'; $prefixes = Router::prefixes(); if (!$privateAction && !empty($prefixes)) { if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) { list($prefix, $action) = explode('_', $request->params['action']); $privateAction = in_array($prefix, $prefixes); } } return $privateAction; }
<?php $routes = Configure::read('Environment.Routes'); Router::prefixes(array(Configure::read('Environment.Names.prefix'))); foreach ($routes as $url => $route) { $route[0] = empty($route[0]) ? null : $route[0]; $route[1] = empty($route[1]) ? null : $route[1]; Router::connect("{$url}", $route[0], $route[1]); } Router::parseExtensions('json');
/** * Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set). * * If no controller of given name can be found, invoke() shows error messages in * the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called * Actions). * * @param string $url URL information to work on * @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params * @return boolean Success * @access public */ function dispatch($url = null, $additionalParams = array()) { if ($this->base === false) { $this->base = $this->baseUrl(); } if (is_array($url)) { $url = $this->__extractParams($url, $additionalParams); } else { if ($url) { $_GET['url'] = $url; } $url = $this->getUrl(); $this->params = array_merge($this->parseParams($url), $additionalParams); } $this->here = $this->base . '/' . $url; if ($this->cached($url)) { $this->_stop(); } $controller =& $this->__getController(); if (!is_object($controller)) { Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot))); return $this->cakeError('missingController', array(array('className' => Inflector::camelize($this->params['controller']) . 'Controller', 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $privateAction = $this->params['action'][0] === '_'; $prefixes = Router::prefixes(); if (!empty($prefixes)) { if (isset($this->params['prefix'])) { $this->params['action'] = $this->params['prefix'] . '_' . $this->params['action']; } elseif (strpos($this->params['action'], '_') > 0) { list($prefix, $action) = explode('_', $this->params['action']); $privateAction = in_array($prefix, $prefixes); } } Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot))); if ($privateAction) { return $this->cakeError('privateAction', array(array('className' => Inflector::camelize($this->params['controller'] . "Controller"), 'action' => $this->params['action'], 'webroot' => $this->webroot, 'url' => $url, 'base' => $this->base))); } $controller->base = $this->base; $controller->here = $this->here; $controller->webroot = $this->webroot; $controller->plugin = $this->plugin; $controller->params =& $this->params; $controller->action =& $this->params['action']; $controller->passedArgs = array_merge($this->params['pass'], $this->params['named']); if (!empty($this->params['data'])) { $controller->data =& $this->params['data']; } else { $controller->data = null; } if (array_key_exists('return', $this->params) && $this->params['return'] == 1) { $controller->autoRender = false; } if (!empty($this->params['bare'])) { $controller->autoLayout = false; } if (array_key_exists('layout', $this->params)) { if (empty($this->params['layout'])) { $controller->autoLayout = false; } else { $controller->layout = $this->params['layout']; } } if (isset($this->params['viewPath'])) { $controller->viewPath = $this->params['viewPath']; } return $this->_invoke($controller, $this->params); }
/** * Connects the default, built-in routes, including prefix and plugin routes with the i18n custom Route * Code mostly duplicated from Router::__connectDefaultRoutes * * @TODO Add Short route for plugins * @see Router::__connectDefaultRoutes * @param array $pluginExceptions Plugins ommited from the lang default routing * @return void */ public static function connectDefaultRoutes($pluginExceptions = array()) { if (!self::$__defaultsMapped) { Router::defaults(false); $options = array('routeClass' => __CLASS__); $prefixes = Router::prefixes(); if ($plugins = App::objects('plugin')) { foreach ($plugins as $key => $value) { $plugins[$key] = Inflector::underscore($value); } $plugins = array_diff($plugins, $pluginExceptions); $pluginPattern = implode('|', $plugins); $match = array('plugin' => $pluginPattern) + $options; foreach ($prefixes as $prefix) { $params = array('prefix' => $prefix, $prefix => true); $indexParams = $params + array('action' => 'index'); Router::connect("/{$prefix}/:plugin/:controller", $indexParams, $match); Router::connect("/{$prefix}/:plugin/:controller/:action/*", $params, $match); } Router::connect('/:plugin/:controller', array('action' => 'index'), $match); Router::connect('/:plugin/:controller/:action/*', array(), $match); } foreach ($prefixes as $prefix) { $params = array('prefix' => $prefix, $prefix => true); $indexParams = $params + array('action' => 'index'); Router::connect("/{$prefix}/:controller/:action/*", $params, $options); Router::connect("/{$prefix}/:controller", $indexParams, $options); } Router::connect('/:controller', array('action' => 'index'), $options); Router::connect('/:controller/:action/*', array(), $options); $Router = Router::getInstance(); if ($Router->named['rules'] === false) { $Router->connectNamed(true); } self::$__defaultsMapped = true; } }
/** * Check if the request's action is marked as private, with an underscore, * or if the request is attempting to directly accessing a prefixed action. * * @param ReflectionMethod $method The method to be invoked. * @param CakeRequest $request The request to check. * @return bool */ protected function _isPrivateAction(ReflectionMethod $method, CakeRequest $request) { $privateAction = $method->name[0] === '_' || !$method->isPublic() || !in_array($method->name, $this->methods); $prefixes = Router::prefixes(); if (!$privateAction && !empty($prefixes)) { if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) { list($prefix) = explode('_', $request->params['action']); $privateAction = in_array($prefix, $prefixes); } } return $privateAction; }
/** * Generates a SQL explain link for a given query * * @param string $sql SQL query string you want an explain link for. * @param $connection * @return string Rendered Html link or '' if the query is not a select/describe */ public function explainLink($sql, $connection) { if (!preg_match('/^[\\s()]*SELECT/i', $sql)) { return ''; } $hash = Security::hash($sql . $connection, 'sha1', true); $url = array('plugin' => 'debug_kit', 'controller' => 'toolbar_access', 'action' => 'sql_explain'); foreach (Router::prefixes() as $prefix) { $url[$prefix] = false; } $this->explainLinkUid = isset($this->explainLinkUid) ? $this->explainLinkUid + 1 : 0; $uid = $this->explainLinkUid . '_' . rand(0, 10000); $form = $this->Form->create('log', array('url' => $url, 'id' => "logForm{$uid}")); $form .= $this->Form->hidden('log.ds', array('id' => "logDs{$uid}", 'value' => $connection)); $form .= $this->Form->hidden('log.sql', array('id' => "logSql{$uid}", 'value' => $sql)); $form .= $this->Form->hidden('log.hash', array('id' => "logHash{$uid}", 'value' => $hash)); $form .= $this->Form->submit(__d('debug_kit', 'Explain'), array('div' => false, 'class' => 'sql-explain-link')); $form .= $this->Form->end(); return $form; }
/** * testPassedArgsOrder method * * @access public * @return void */ function testPassedArgsOrder() { Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2)); Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1)); Router::parse('/'); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 1, 'whatever')); $expected = '/test/whatever'; $this->assertEqual($result, $expected); $result = Router::url(array('controller' => 'pages', 'action' => 'display', 2, 'whatever')); $expected = '/test2/whatever'; $this->assertEqual($result, $expected); Configure::write('Routing.admin', 'admin'); Router::reload(); Router::setRequestInfo(array(array('plugin' => null, 'controller' => 'images', 'action' => 'index', 'pass' => array(), 'named' => array(), 'prefix' => 'protected', 'admin' => false, 'form' => array(), 'url' => array('url' => 'protected/images/index')), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '', 'here' => '/protected/images/index', 'webroot' => '/'))); Router::connect('/protected/:controller/:action/*', array('controller' => 'users', 'action' => 'index', 'prefix' => 'protected')); Router::parse('/'); $result = Router::url(array('controller' => 'images', 'action' => 'add')); $expected = '/protected/images/add'; $this->assertEqual($result, $expected); $result = Router::prefixes(); $expected = array('protected', 'admin'); $this->assertEqual($result, $expected); }
/** * Initializes AuthComponent for use in the controller * * @param object $controller A reference to the instantiating controller object * @return void */ public function initialize($controller) { $this->request = $controller->request; $this->params = $this->request; $crud = array('create', 'read', 'update', 'delete'); $this->actionMap = array_merge($this->actionMap, array_combine($crud, $crud)); $this->_methods = $controller->methods; $prefixes = Router::prefixes(); if (!empty($prefixes)) { foreach ($prefixes as $prefix) { $this->actionMap = array_merge($this->actionMap, array($prefix . '_index' => 'read', $prefix . '_add' => 'create', $prefix . '_edit' => 'update', $prefix . '_view' => 'read', $prefix . '_remove' => 'delete', $prefix . '_create' => 'create', $prefix . '_read' => 'read', $prefix . '_update' => 'update', $prefix . '_delete' => 'delete')); } } if (Configure::read('debug') > 0) { App::import('Debugger'); Debugger::checkSecurityKeys(); } }