2005-06-21 23:44:49 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-21 23:44:49 +00:00
|
|
|
/**
|
2005-12-24 07:56:48 +00:00
|
|
|
* Dispatcher takes the URL information, parses it for paramters and
|
2005-09-17 02:22:07 +00:00
|
|
|
* tells the involved controllers what to do.
|
2005-12-24 07:56:48 +00:00
|
|
|
*
|
|
|
|
* This is the heart of Cake's operation.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-24 07:56:48 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-06-21 23:44:49 +00:00
|
|
|
*/
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* List of helpers to include
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
uses('router', DS.'controller'.DS.'controller');
|
2005-06-21 23:44:49 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Dispatcher translates URLs to controller-action-paramter triads.
|
2005-12-22 01:07:28 +00:00
|
|
|
*
|
2005-06-21 23:44:49 +00:00
|
|
|
* Dispatches the request, creating appropriate models and controllers.
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake
|
2005-06-21 23:44:49 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
class Dispatcher extends Object {
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Base URL
|
2007-06-19 13:28:55 +00:00
|
|
|
*
|
2005-07-10 05:08:19 +00:00
|
|
|
* @var string
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $base = false;
|
2006-11-21 22:03:52 +00:00
|
|
|
/**
|
|
|
|
* Current URL
|
2007-06-19 13:28:55 +00:00
|
|
|
*
|
2006-11-21 22:03:52 +00:00
|
|
|
* @var string
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2006-11-21 22:03:52 +00:00
|
|
|
*/
|
|
|
|
var $here = false;
|
2005-10-28 08:25:31 +00:00
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Admin route (if on it)
|
|
|
|
*
|
2005-10-28 08:25:31 +00:00
|
|
|
* @var string
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2005-10-28 08:25:31 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $admin = false;
|
2005-12-22 01:07:28 +00:00
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Webservice route
|
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* @var string
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2005-12-22 01:07:28 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $webservices = null;
|
2006-02-01 13:26:23 +00:00
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Plugin being served (if any)
|
|
|
|
*
|
2006-02-01 13:26:23 +00:00
|
|
|
* @var string
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2006-02-01 13:26:23 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
var $plugin = null;
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the params for this request
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $params = null;
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Constructor.
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-08-02 00:16:28 +00:00
|
|
|
function __construct($url = null, $base = false) {
|
2006-05-26 05:29:17 +00:00
|
|
|
parent::__construct();
|
2007-08-02 00:16:28 +00:00
|
|
|
|
|
|
|
if($base !== false) {
|
|
|
|
Configure::write('App.base', $base);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->base = Configure::read('App.base');
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if ($url !== null) {
|
|
|
|
return $this->dispatch($url);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set).
|
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* 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
|
2005-09-17 02:22:07 +00:00
|
|
|
* Actions).
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @param string $url URL information to work on.
|
2006-07-29 15:50:03 +00:00
|
|
|
* @param array $additionalParams Settings array ("bare", "return"),
|
2006-07-21 08:03:03 +00:00
|
|
|
* which is melded with the GET and POST params.
|
2006-05-26 05:29:17 +00:00
|
|
|
* @return boolean Success
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-09-22 16:39:15 +00:00
|
|
|
function dispatch($url, $additionalParams = array()) {
|
2007-07-25 19:42:58 +00:00
|
|
|
$this->params = array_merge($this->parseParams($url), $additionalParams);
|
2007-07-25 04:38:28 +00:00
|
|
|
$missingAction = $missingView = $privateAction = false;
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->base = $this->baseUrl();
|
2007-07-25 21:08:12 +00:00
|
|
|
$controller = $this->__getController();
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if(!is_object($controller)) {
|
|
|
|
if (preg_match('/([\\.]+)/', $controller)) {
|
|
|
|
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
return $this->cakeError('error404', array(array('url' => strtolower($controller),
|
2007-07-25 04:38:28 +00:00
|
|
|
'message' => 'Was not found on this server',
|
|
|
|
'base' => $this->base)));
|
|
|
|
} else {
|
2007-07-25 19:42:58 +00:00
|
|
|
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
2007-07-25 04:38:28 +00:00
|
|
|
return $this->cakeError('missingController', array(
|
|
|
|
array(
|
2007-07-25 19:42:58 +00:00
|
|
|
'className' => $controller.'Controller',
|
2007-07-25 04:38:28 +00:00
|
|
|
'webroot' => $this->webroot,
|
|
|
|
'url' => $url,
|
|
|
|
'base' => $this->base
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (empty($this->params['action'])) {
|
|
|
|
$this->params['action'] = 'index';
|
2007-04-04 07:25:48 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (defined('CAKE_ADMIN')) {
|
2007-07-25 19:42:58 +00:00
|
|
|
if (isset($this->params[CAKE_ADMIN])) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$this->admin = '/'.CAKE_ADMIN ;
|
2007-06-20 07:59:41 +00:00
|
|
|
$url = preg_replace('/'.CAKE_ADMIN.'(\/|$)/', '', $url);
|
2007-07-25 19:42:58 +00:00
|
|
|
$this->params['action'] = CAKE_ADMIN.'_'.$this->params['action'];
|
|
|
|
} elseif (strpos($this->params['action'], CAKE_ADMIN) === 0) {
|
2006-10-20 17:24:37 +00:00
|
|
|
$privateAction = true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->here = $this->base . $this->admin . '/' . $url;
|
2006-05-26 05:29:17 +00:00
|
|
|
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$protected = array('constructclasses', 'redirect', 'set', 'setAction', 'isauthorized', 'validate', 'validateerrors',
|
|
|
|
'render', 'referer', 'disablecache', 'flash', 'generatefieldnames', 'postconditions', 'cleanupfields',
|
|
|
|
'paginate', 'beforefilter', 'beforerender', 'afterfilter', 'object', 'tostring', 'requestaction', 'log',
|
|
|
|
'cakeerror');
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$classMethods = array_map("low", get_class_methods($controller));
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (in_array(low($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$privateAction = true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (!in_array(low($this->params['action']), $classMethods)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$missingAction = true;
|
|
|
|
}
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->autoRender = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$controller->base = $this->base;
|
2006-11-21 22:03:52 +00:00
|
|
|
$controller->here = $this->here;
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->webroot = $this->webroot;
|
2007-07-25 19:42:58 +00:00
|
|
|
$controller->params = $this->params;
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->plugin = $this->plugin;
|
2007-07-25 19:42:58 +00:00
|
|
|
$controller->action = $this->params['action'];
|
|
|
|
$controller->webservices = $this->params['webservices'];
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
list($passedArgs, $namedArgs) = Router::getArgs($this->params, $controller->namedArgs, $controller->argSeparator);
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->passedArgs = $passedArgs;
|
|
|
|
$controller->namedArgs = $namedArgs;
|
2006-05-26 05:29:17 +00:00
|
|
|
|
|
|
|
if (!empty($controller->params['data'])) {
|
|
|
|
$controller->data =& $controller->params['data'];
|
|
|
|
} else {
|
|
|
|
$controller->data = null;
|
|
|
|
}
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (!empty($this->params['bare'])) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->autoLayout = false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (isset($this->params['layout'])) {
|
|
|
|
if ($this->params['layout'] === '') {
|
2006-08-25 17:38:53 +00:00
|
|
|
$controller->autoLayout = false;
|
|
|
|
} else {
|
2007-07-25 19:42:58 +00:00
|
|
|
$controller->layout = $this->params['layout'];
|
2006-08-25 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-08 21:01:31 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
if (isset($this->params['viewPath'])) {
|
|
|
|
$controller->viewPath = $this->params['viewPath'];
|
2007-07-25 04:38:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach (array('components', 'helpers') as $var) {
|
2007-07-25 19:42:58 +00:00
|
|
|
if (isset($this->params[$var]) && !empty($this->params[$var]) && is_array($controller->{$var})) {
|
|
|
|
$diff = array_diff($this->params[$var], $controller->{$var});
|
2006-08-25 17:38:53 +00:00
|
|
|
$controller->{$var} = array_merge($controller->{$var}, $diff);
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (!is_null($controller->webservices)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
array_push($controller->components, $controller->webservices);
|
|
|
|
array_push($controller->helpers, $controller->webservices);
|
|
|
|
}
|
2007-08-02 00:16:28 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
Router::setRequestInfo(array($this->params, array('base' => $this->base, 'here' => $this->here, 'webroot' => $this->webroot, 'passedArgs' => $controller->passedArgs, 'argSeparator' => $controller->argSeparator, 'namedArgs' => $controller->namedArgs, 'webservices' => $controller->webservices)));
|
2006-07-29 17:08:23 +00:00
|
|
|
$controller->_initComponents();
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
if(isset($this->plugin)) {
|
|
|
|
loadPluginModels($this->plugin);
|
|
|
|
}
|
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->constructClasses();
|
|
|
|
|
2006-07-23 16:13:05 +00:00
|
|
|
if ($privateAction) {
|
2006-09-18 20:28:34 +00:00
|
|
|
$this->start($controller);
|
2006-07-15 03:36:53 +00:00
|
|
|
return $this->cakeError('privateAction', array(
|
2006-10-20 17:24:37 +00:00
|
|
|
array(
|
2007-07-25 19:42:58 +00:00
|
|
|
'className' => Inflector::camelize($this->params['controller']."Controller"),
|
|
|
|
'action' => $this->params['action'],
|
2006-10-20 17:24:37 +00:00
|
|
|
'webroot' => $this->webroot,
|
|
|
|
'url' => $url,
|
|
|
|
'base' => $this->base
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-09-22 16:39:15 +00:00
|
|
|
|
2007-07-25 19:42:58 +00:00
|
|
|
return $this->_invoke($controller, $this->params, $missingAction);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-09-19 20:07:16 +00:00
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Invokes given controller's render action if autoRender option is set. Otherwise the
|
|
|
|
* contents of the operation are returned as a string.
|
2005-09-19 20:07:16 +00:00
|
|
|
*
|
2007-06-19 13:28:55 +00:00
|
|
|
* @param object $controller Controller to invoke
|
|
|
|
* @param array $params Parameters with at least the 'action' to invoke
|
|
|
|
* @param boolean $missingAction Set to true if missing action should be rendered, false otherwise
|
|
|
|
* @return string Output as sent by controller
|
|
|
|
* @access protected
|
2005-09-19 20:07:16 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function _invoke (&$controller, $params, $missingAction = false) {
|
|
|
|
$this->start($controller);
|
|
|
|
$classVars = get_object_vars($controller);
|
|
|
|
|
|
|
|
if ($missingAction && in_array('scaffold', array_keys($classVars))) {
|
2006-11-25 04:31:26 +00:00
|
|
|
uses('controller'. DS . 'scaffold');
|
2006-05-26 05:29:17 +00:00
|
|
|
return new Scaffold($controller, $params);
|
2007-07-25 04:38:28 +00:00
|
|
|
} elseif ($missingAction && !in_array('scaffold', array_keys($classVars))) {
|
|
|
|
return $this->cakeError('missingAction', array(
|
|
|
|
array(
|
|
|
|
'className' => Inflector::camelize($params['controller']."Controller"),
|
|
|
|
'action' => $params['action'],
|
|
|
|
'webroot' => $this->webroot,
|
|
|
|
'url' => $this->here,
|
|
|
|
'base' => $this->base
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
|
|
|
$output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
if ($controller->autoRender) {
|
|
|
|
$output = $controller->render();
|
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->output =& $output;
|
2007-01-23 15:20:33 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($controller->components as $c) {
|
2007-03-23 10:34:21 +00:00
|
|
|
$path = preg_split('/\/|\./', $c);
|
|
|
|
$c = $path[count($path) - 1];
|
2007-01-23 15:20:33 +00:00
|
|
|
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'shutdown'))) {
|
|
|
|
if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) {
|
|
|
|
$controller->{$c}->shutdown($controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->afterFilter();
|
|
|
|
return $controller->output;
|
|
|
|
}
|
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Starts up a controller (by calling its beforeFilter methods and
|
|
|
|
* starting its components)
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-06-19 13:28:55 +00:00
|
|
|
* @param object $controller Controller to start
|
|
|
|
* @access public
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
2006-07-23 16:13:05 +00:00
|
|
|
function start(&$controller) {
|
2006-05-26 05:29:17 +00:00
|
|
|
if (!empty($controller->beforeFilter)) {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_array($controller->beforeFilter)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($controller->beforeFilter as $filter) {
|
|
|
|
if (is_callable(array($controller,$filter)) && $filter != 'beforeFilter') {
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->$filter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-20 06:15:35 +00:00
|
|
|
if (is_callable(array($controller, $controller->beforeFilter)) && $controller->beforeFilter != 'beforeFilter') {
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->{$controller->beforeFilter}();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$controller->beforeFilter();
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach ($controller->components as $c) {
|
2007-03-23 10:34:21 +00:00
|
|
|
$path = preg_split('/\/|\./', $c);
|
|
|
|
$c = $path[count($path) - 1];
|
2006-05-26 05:29:17 +00:00
|
|
|
if (isset($controller->{$c}) && is_object($controller->{$c}) && is_callable(array($controller->{$c}, 'startup'))) {
|
2007-01-20 15:29:06 +00:00
|
|
|
if (!array_key_exists('enabled', get_object_vars($controller->{$c})) || $controller->{$c}->enabled == true) {
|
|
|
|
$controller->{$c}->startup($controller);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-07-15 03:36:53 +00:00
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
|
|
|
|
*
|
2007-06-19 13:28:55 +00:00
|
|
|
* @param string $fromUrl URL to mine for parameter information.
|
2005-07-10 05:08:19 +00:00
|
|
|
* @return array Parameters found in POST and GET.
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2007-06-19 13:28:55 +00:00
|
|
|
function parseParams($fromUrl) {
|
2006-08-12 13:02:51 +00:00
|
|
|
$Route = Router::getInstance();
|
2006-09-10 17:25:44 +00:00
|
|
|
extract(Router::getNamedExpressions());
|
2006-05-26 05:29:17 +00:00
|
|
|
include CONFIGS.'routes.php';
|
2007-06-19 13:28:55 +00:00
|
|
|
$params = Router::parse($fromUrl);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (isset($_POST)) {
|
|
|
|
if (ini_get('magic_quotes_gpc') == 1) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$params['form'] = stripslashes_deep($_POST);
|
2007-07-25 04:38:28 +00:00
|
|
|
} else {
|
|
|
|
$params['form'] = $_POST;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['form']['data'])) {
|
2007-05-21 03:29:49 +00:00
|
|
|
$params['data'] = Router::stripEscape($params['form']['data']);
|
2006-11-12 19:53:42 +00:00
|
|
|
unset($params['form']['data']);
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_GET)) {
|
|
|
|
if (ini_get('magic_quotes_gpc') == 1) {
|
2006-08-12 17:03:40 +00:00
|
|
|
$url = stripslashes_deep($_GET);
|
2006-05-26 05:29:17 +00:00
|
|
|
} else {
|
2006-08-12 17:03:40 +00:00
|
|
|
$url = $_GET;
|
|
|
|
}
|
|
|
|
if (isset($params['url'])) {
|
|
|
|
$params['url'] = am($params['url'], $url);
|
|
|
|
} else {
|
|
|
|
$params['url'] = $url;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($_FILES as $name => $data) {
|
|
|
|
if ($name != 'data') {
|
|
|
|
$params['form'][$name] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_FILES['data'])) {
|
|
|
|
foreach ($_FILES['data'] as $key => $data) {
|
|
|
|
foreach ($data as $model => $fields) {
|
|
|
|
foreach ($fields as $field => $value) {
|
|
|
|
$params['data'][$model][$field][$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
$params['bare'] = empty($params['ajax']) ? (empty($params['bare']) ? 0: 1) : 1;
|
2006-05-26 05:29:17 +00:00
|
|
|
$params['webservices'] = empty($params['webservices']) ? null : $params['webservices'];
|
|
|
|
return $params;
|
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2007-07-25 04:38:28 +00:00
|
|
|
* Returns a base URL and sets the proper webroot
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @return string Base URL
|
2007-06-19 13:28:55 +00:00
|
|
|
* @access public
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
|
|
|
function baseUrl() {
|
2007-08-02 00:16:28 +00:00
|
|
|
if($this->base !== false) {
|
|
|
|
$this->webroot = $this->base .'/';
|
|
|
|
return $this->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
$base = '';
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->webroot = '/';
|
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
$baseUrl = Configure::read('App.baseUrl');
|
|
|
|
$app = Configure::read('App.dir');
|
|
|
|
$webroot = Configure::read('App.webroot');
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$file = $script = null;
|
2007-08-02 19:12:19 +00:00
|
|
|
if (!$baseUrl) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$docRoot = env('DOCUMENT_ROOT');
|
|
|
|
$script = env('SCRIPT_FILENAME');
|
|
|
|
$base = r($docRoot, '', $script);
|
2007-08-02 19:12:19 +00:00
|
|
|
} elseif ($baseUrl) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$base = $baseUrl;
|
2007-08-02 19:12:19 +00:00
|
|
|
$file = '/' . basename($base);
|
2007-07-25 04:38:28 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$base = dirname($base);
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-08-02 00:16:28 +00:00
|
|
|
if (in_array($base, array(DS, '.'))) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$base = '';
|
2007-08-02 19:12:19 +00:00
|
|
|
$this->webroot = '/';
|
|
|
|
return $base . $file;
|
2007-07-25 04:38:28 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-08-02 19:12:19 +00:00
|
|
|
if(strpos($script, $app) !== false && $app === 'app') {
|
|
|
|
$base = str_replace('/'.$app, '', $base);
|
2007-07-25 04:38:28 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-08-02 19:12:19 +00:00
|
|
|
if ($webroot === 'webroot') {
|
|
|
|
$base = str_replace('/'.$webroot, '', $base);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->webroot = $base .'/';
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (!$baseUrl) {
|
|
|
|
return $base;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-08-02 19:12:19 +00:00
|
|
|
if (strpos($this->webroot, $app) === false) {
|
|
|
|
$this->webroot .= $app . '/' ;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
|
2007-08-02 19:12:19 +00:00
|
|
|
if (strpos($this->webroot, $webroot) === false) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$this->webroot .= $webroot . '/';
|
|
|
|
}
|
|
|
|
return $base . $file;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
/**
|
2007-06-19 13:28:55 +00:00
|
|
|
* Restructure params in case we're serving a plugin.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-06-19 13:28:55 +00:00
|
|
|
* @param array $params Array on where to re-set 'controller', 'action', and 'pass' indexes
|
|
|
|
* @return array Restructured array
|
|
|
|
* @access protected
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
function _restructureParams($params) {
|
2007-07-25 19:42:58 +00:00
|
|
|
$params['plugin'] = $params['controller'];
|
2006-05-26 05:29:17 +00:00
|
|
|
$params['controller'] = $params['action'];
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (isset($params['pass'][0])) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$params['action'] = $params['pass'][0];
|
|
|
|
array_shift($params['pass']);
|
|
|
|
} else {
|
|
|
|
$params['action'] = null;
|
|
|
|
}
|
|
|
|
return $params;
|
|
|
|
}
|
2007-07-25 19:42:58 +00:00
|
|
|
/**
|
|
|
|
* Get controller to use, either plugin controller or application controller
|
|
|
|
*
|
|
|
|
* @param array $params Array on where to re-set 'controller', 'action', and 'pass' indexes
|
|
|
|
* @return mixed name of controller if not loaded, or object if loaded
|
|
|
|
* @access protected
|
|
|
|
*/
|
2007-08-02 19:12:19 +00:00
|
|
|
function __getController($params = null, $continue = true) {
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
if(!$params) {
|
|
|
|
$params = $this->params;
|
|
|
|
}
|
|
|
|
|
2007-07-25 21:08:12 +00:00
|
|
|
$pluginPath = $controller = $ctrlClass = null;
|
2007-07-25 19:42:58 +00:00
|
|
|
|
|
|
|
if (!empty($params['controller'])) {
|
|
|
|
$controller = Inflector::camelize($params['controller']);
|
|
|
|
$ctrlClass = $controller.'Controller';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($params['plugin'])) {
|
|
|
|
$this->plugin = $params['plugin'];
|
|
|
|
$pluginPath = Inflector::camelize($this->plugin).'.';
|
|
|
|
|
2007-07-25 21:08:12 +00:00
|
|
|
}
|
2007-08-02 00:16:28 +00:00
|
|
|
|
2007-07-25 21:08:12 +00:00
|
|
|
if ($pluginPath . $controller && loadController($pluginPath . $controller)) {
|
2007-08-02 19:12:19 +00:00
|
|
|
if(!class_exists(low($ctrlClass)) && $this->plugin) {
|
2007-07-25 19:42:58 +00:00
|
|
|
$controller = Inflector::camelize($params['plugin']);
|
|
|
|
$ctrlClass = $controller.'Controller';
|
2007-07-25 21:08:12 +00:00
|
|
|
$params = am($this->params, array('plugin'=> $params['plugin'], 'controller'=> $params['plugin']));
|
2007-07-25 19:42:58 +00:00
|
|
|
}
|
2007-08-02 19:12:19 +00:00
|
|
|
if(class_exists(low($ctrlClass))) {
|
2007-07-25 21:08:12 +00:00
|
|
|
$controller =& new $ctrlClass();
|
|
|
|
}
|
|
|
|
} elseif ($continue == true){
|
|
|
|
$params = $this->_restructureParams($params);
|
|
|
|
$controller = $this->__getController($params, false);
|
|
|
|
return $controller;
|
2007-07-25 19:42:58 +00:00
|
|
|
}
|
|
|
|
|
2007-08-02 19:12:19 +00:00
|
|
|
if(!class_exists(low($ctrlClass))) {
|
2007-08-02 00:16:28 +00:00
|
|
|
$controller = Inflector::camelize($this->params['controller']);
|
2007-07-31 05:39:01 +00:00
|
|
|
$this->plugin = null;
|
|
|
|
return $controller;
|
2007-07-25 19:42:58 +00:00
|
|
|
}
|
2007-07-25 21:08:12 +00:00
|
|
|
|
|
|
|
$this->params = $params;
|
2007-07-25 19:42:58 +00:00
|
|
|
return $controller;
|
|
|
|
}
|
2005-07-21 04:02:32 +00:00
|
|
|
}
|
2006-06-15 15:51:34 +00:00
|
|
|
|
2007-07-25 21:08:12 +00:00
|
|
|
?>
|