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;
|
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-07-25 04:38:28 +00:00
|
|
|
function __construct($url = null) {
|
2006-05-26 05:29:17 +00:00
|
|
|
parent::__construct();
|
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()) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$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 04:38:28 +00:00
|
|
|
$pluginPath = null;
|
|
|
|
if (!empty($params['plugin'])) {
|
|
|
|
$this->plugin = $params['plugin'];
|
|
|
|
$pluginPath = Inflector::camelize($this->plugin).'.';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($params['controller'])) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$ctrlName = Inflector::camelize($params['controller']);
|
|
|
|
$ctrlClass = $ctrlName.'Controller';
|
2006-06-14 18:02:37 +00:00
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (!loadController($pluginPath . $ctrlName)) {
|
|
|
|
if (preg_match('/([\\.]+)/', $ctrlName)) {
|
|
|
|
Router::setRequestInfo(array($params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
|
|
|
|
|
|
|
return $this->cakeError('error404', array(array('url' => strtolower($ctrlName),
|
|
|
|
'message' => 'Was not found on this server',
|
|
|
|
'base' => $this->base)));
|
|
|
|
} else {
|
|
|
|
Router::setRequestInfo(array($params, array('base' => $this->base, 'webroot' => $this->webroot)));
|
|
|
|
return $this->cakeError('missingController', array(
|
|
|
|
array(
|
|
|
|
'className' => Inflector::camelize($params['controller']."Controller"),
|
|
|
|
'webroot' => $this->webroot,
|
|
|
|
'url' => $url,
|
|
|
|
'base' => $this->base
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
} else {
|
|
|
|
$controller =& new $ctrlClass();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 07:25:48 +00:00
|
|
|
if (empty($params['action'])) {
|
|
|
|
$params['action'] = 'index';
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (defined('CAKE_ADMIN')) {
|
|
|
|
if (isset($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-04-04 07:25:48 +00:00
|
|
|
$params['action'] = CAKE_ADMIN.'_'.$params['action'];
|
2006-08-07 11:51:10 +00:00
|
|
|
} elseif (strpos($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));
|
|
|
|
|
|
|
|
if (in_array(low($params['action']), $protected) || strpos($params['action'], '_', 0) === 0) {
|
|
|
|
$privateAction = true;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (!in_array(low($params['action']), $classMethods)) {
|
2006-05-26 05:29:17 +00:00
|
|
|
$missingAction = true;
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
if (in_array('return', array_keys($params)) && $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;
|
|
|
|
$controller->params = $params;
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->plugin = $this->plugin;
|
2006-05-26 05:29:17 +00:00
|
|
|
$controller->action = $params['action'];
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->webservices = $params['webservices'];
|
|
|
|
|
|
|
|
list($passedArgs, $namedArgs) = Router::getArgs($params, $controller->namedArgs, $controller->argSeparator);
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($params['bare'])) {
|
2007-07-25 04:38:28 +00:00
|
|
|
$controller->autoLayout = false;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2006-08-25 17:38:53 +00:00
|
|
|
if (isset($params['layout'])) {
|
|
|
|
if ($params['layout'] === '') {
|
|
|
|
$controller->autoLayout = false;
|
|
|
|
} else {
|
|
|
|
$controller->layout = $params['layout'];
|
|
|
|
}
|
|
|
|
}
|
2007-07-08 21:01:31 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (isset($params['viewPath'])) {
|
|
|
|
$controller->viewPath = $params['viewPath'];
|
|
|
|
}
|
|
|
|
|
2007-06-20 06:15:35 +00:00
|
|
|
foreach (array('components', 'helpers') as $var) {
|
2006-08-25 17:38:53 +00:00
|
|
|
if (isset($params[$var]) && !empty($params[$var]) && is_array($controller->{$var})) {
|
|
|
|
$diff = array_diff($params[$var], $controller->{$var});
|
|
|
|
$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-02-23 00:14:51 +00:00
|
|
|
Router::setRequestInfo(array($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();
|
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(
|
|
|
|
'className' => Inflector::camelize($params['controller']."Controller"),
|
|
|
|
'action' => $params['action'],
|
|
|
|
'webroot' => $this->webroot,
|
|
|
|
'url' => $url,
|
|
|
|
'base' => $this->base
|
|
|
|
)
|
|
|
|
));
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-09-22 16:39:15 +00:00
|
|
|
|
2006-05-26 05:29:17 +00:00
|
|
|
return $this->_invoke($controller, $params, $missingAction);
|
|
|
|
}
|
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-07-25 04:38:28 +00:00
|
|
|
$base = $this->base;
|
|
|
|
$this->webroot = '/';
|
|
|
|
|
|
|
|
$baseUrl = Configure::read('baseUrl');
|
|
|
|
$app = Configure::read('app');
|
|
|
|
$webroot = Configure::read('webroot');
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$file = $script = null;
|
|
|
|
if (!$baseUrl && $this->base == false) {
|
|
|
|
$docRoot = env('DOCUMENT_ROOT');
|
|
|
|
$script = env('SCRIPT_FILENAME');
|
|
|
|
$base = r($docRoot, '', $script);
|
|
|
|
} elseif ($baseUrl && $this->base == false) {
|
|
|
|
$base = $baseUrl;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$file = basename($base);
|
|
|
|
if (($baseUrl || $this->base) && strpos($file, '.php') !== false) {
|
|
|
|
$baseUrl = true;
|
|
|
|
$file = '/'. $file;
|
|
|
|
}
|
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-07-25 04:38:28 +00:00
|
|
|
if ($base == '/' || $base == '.') {
|
|
|
|
$base = '';
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
if (!$baseUrl && strpos($script, $app) !== false && $app === 'app') {
|
|
|
|
$base = str_replace($app.'/', '', $base);
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
|
2007-07-25 04:38:28 +00:00
|
|
|
$base = str_replace('//', '/', 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-07-25 04:38:28 +00:00
|
|
|
if ($baseUrl && $base == '') {
|
|
|
|
return $file;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-07-25 04:38:28 +00:00
|
|
|
|
|
|
|
if (strpos($base, $app) === false) {
|
|
|
|
$this->webroot .= '/' . $app . '/' ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($baseUrl && strpos($this->webroot, $webroot) === false) {
|
|
|
|
$this->webroot .= $webroot . '/';
|
|
|
|
}
|
|
|
|
$this->webroot = str_replace('//', '/', $this->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) {
|
|
|
|
$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;
|
|
|
|
}
|
2005-07-21 04:02:32 +00:00
|
|
|
}
|
2006-06-15 15:51:34 +00:00
|
|
|
|
2007-05-03 04:35:25 +00:00
|
|
|
?>
|