diff --git a/app/config/core.php b/app/config/core.php index 0280c5d08..186f581fb 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -83,6 +83,15 @@ define('CAKE_SECURITY', 'high'); */ define('CAKE_SESSION_SAVE', 'php'); +/** + * Uncomment the define below to use cake built in admin routes. + * You can set this value to anything you want. + * All methods related to the admin route should be prefixed with the + * name you set CAKE_ADMIN to. + * For example: admin_index, admin_edit + */ +//define('CAKE_ADMIN', 'admin'); + /** * Compress output CSS (removing comments, whitespace, repeating tags etc.) * This requires a /var/cache directory to be writable by the web server (caching). diff --git a/app/webroot/index.php b/app/webroot/index.php index 085cd6a34..2b2dcdafc 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -128,13 +128,6 @@ uses('folder'); require_once CAKE.'dispatcher.php'; require_once LIBS.'model'.DS.'dbo'.DS.'dbo_factory.php'; -if(!defined('AUTO_SESSION') || AUTO_SESSION == true) -{ - // Starts the session unless AUTO_SESSION is explicitly set to false in config/core - //session_start(); - $session =& CakeSession::getInstance(); -} - config('database'); if (class_exists('DATABASE_CONFIG')) diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 36c7b30b1..3d6b40577 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -53,6 +53,12 @@ class Dispatcher extends Object * @var string */ var $base = false; + +/** + * Base URL + * @var string + */ + var $admin = false; /** * Constructor. @@ -74,13 +80,31 @@ class Dispatcher extends Object */ function dispatch($url, $additionalParams=array()) { - $this->base = $this->baseUrl(); $params = array_merge($this->parseParams($url), $additionalParams); $missingController = false; $missingAction = false; $missingView = false; $privateAction = false; + if(defined('CAKE_ADMIN')) + { + if(isset($params[CAKE_ADMIN])) + { + $this->admin = '/'.CAKE_ADMIN ; + $url = preg_replace('/'.CAKE_ADMIN.'\//', '', $url); + if (empty($params['action'])) + { + $params['action'] = CAKE_ADMIN.'_'.'index'; + } + else + { + $params['action'] = CAKE_ADMIN.'_'.$params['action']; + } + } + } + + $this->base = $this->baseUrl(); + if(!in_array('render', array_keys($params))) { $params['render'] = 0; @@ -111,6 +135,7 @@ class Dispatcher extends Object if ($missingController) { + require_once(CAKE.'app_controller.php'); $controller =& new AppController(); $params['action'] = 'missingController'; $params['controller'] = Inflector::camelize($params['controller']."Controller"); @@ -170,7 +195,11 @@ class Dispatcher extends Object $controller->privateAction = $params['action']; $params['action'] = 'privateAction'; } - + if(!defined('AUTO_SESSION') || AUTO_SESSION == true) + { + session_write_close(); + $session =& CakeSession::getInstance(); + } return $this->_invoke($controller, $params ); } @@ -256,11 +285,11 @@ class Dispatcher extends Object function baseUrl() { $htaccess = null; - $base = null; + $base = $this->admin; $this->webroot = ''; if (defined('BASE_URL')) { - $base = BASE_URL; + $base = BASE_URL.$this->admin; } $docRoot = $_SERVER['DOCUMENT_ROOT']; diff --git a/cake/libs/controller/components/session.php b/cake/libs/controller/components/session.php index b02e883f2..88648f438 100644 --- a/cake/libs/controller/components/session.php +++ b/cake/libs/controller/components/session.php @@ -54,6 +54,8 @@ class Session extends Object /** * Enter description here... * + * Use like this. $this->session->write('Controller.sessKey', 'session value'); + * * @param unknown_type $name * @param unknown_type $value * @return unknown @@ -66,6 +68,8 @@ class Session extends Object /** * Enter description here... * + * Use like this. $this->session->read('Controller.sessKey'); + * * @param unknown_type $name * @return unknown */ @@ -77,6 +81,8 @@ class Session extends Object /** * Enter description here... * + * Use like this. $this->session->del('Controller.sessKey'); + * * @param unknown_type $name * @return unknown */ @@ -88,6 +94,8 @@ class Session extends Object /** * Enter description here... * + * Use like this. $this->session->check('Controller.sessKey'); + * * @param unknown_type $name * @return unknown */ @@ -112,9 +120,9 @@ class Session extends Object * @param unknown_type $name * @return unknown */ - function valid($name) + function valid() { - return CakeSession::isValid($name); + return CakeSession::isValid(); } } diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index b0406c9a8..205bd7960 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -297,9 +297,14 @@ class Scaffold extends Object { if(!empty($isDataBaseSet)) { $this->controllerClass->constructClasses(); + if(!defined('AUTO_SESSION') || AUTO_SESSION == true) + { + session_write_close(); + $session =& CakeSession::getInstance(); + } if($params['action'] === 'index' || $params['action'] === 'list' || - $params['action'] === 'show' || $params['action'] === 'new' || + $params['action'] === 'show' || $params['action'] === 'add' || $params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'update' || $params['action'] === 'destroy') { @@ -317,7 +322,7 @@ class Scaffold extends Object { $this->_scaffoldList($params); break; - case 'new': + case 'add': $this->_scaffoldNew($params); break; diff --git a/cake/libs/controller/templates/scaffolds/list.thtml b/cake/libs/controller/templates/scaffolds/list.thtml index 49cdeb8d1..98d4f14f4 100644 --- a/cake/libs/controller/templates/scaffolds/list.thtml +++ b/cake/libs/controller/templates/scaffolds/list.thtml @@ -93,7 +93,7 @@ diff --git a/cake/libs/controller/templates/scaffolds/show.thtml b/cake/libs/controller/templates/scaffolds/show.thtml index 2f6ff898e..c24747135 100644 --- a/cake/libs/controller/templates/scaffolds/show.thtml +++ b/cake/libs/controller/templates/scaffolds/show.thtml @@ -81,7 +81,7 @@ echo "
  • ".$html->linkTo('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."
  • "; echo "
  • ".$html->linkTo('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."
  • "; echo "
  • ".$html->linkTo('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/list')."
  • "; - echo "
  • ".$html->linkTo('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/new')."
  • "; + echo "
  • ".$html->linkTo('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."
  • "; foreach( $fieldNames as $field => $value ) { if( isset( $value['foreignKey'] ) ) { @@ -181,7 +181,7 @@ ".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/new/").""; + echo "
  • ".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/add/")."
  • "; // echo "
  • ".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."
  • "; ?> diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 86593bd14..3a2dfb0a9 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -1280,7 +1280,25 @@ class Model extends Object */ function findBySql ($sql) { - return $this->db->all($sql); + $data = $this->db->all($sql); + foreach ($data as $key => $value) + { + foreach ($this->tableToModel as $key1 => $value1) + { + if (isset($data[$key][Inflector::singularize($key1)])) + { + $newData[$key][$value1] = $data[$key][Inflector::singularize($key1)]; + } + } + } + if (!empty($newData)) + { + return $newData; + } + else + { + return $data; + } } /** diff --git a/cake/libs/router.php b/cake/libs/router.php index 91f2c0c8d..2e1a670e3 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -130,26 +130,32 @@ class Router extends Object { '/:controller/:action/* (default)', '/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/(.*))?)?))[\\/]*$/', array('controller', 'action'), - array() - ); + array()); + + if(defined('CAKE_ADMIN')) + { + $admin = CAKE_ADMIN; + if(!empty($admin)) + { + $this->routes[] = array + ( + '/:'.$admin.'/:controller/:action/* (default)', + '/^(?:\/(?:('.$admin.')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\/(.*))?)?)?))[\/]*$/', + array($admin, 'controller', 'action'), + array()); + + } + } - $admin_route = array - ( - '/:controller/:admin/:action/* (default)', - '/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/(admin)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\/(.*))?)?)?))[\/]*$/', - array('controller', 'admin', 'action'), - array() - ); - $this->connect('/bare/:controller/:action/*', array('bare'=>'1')); $this->connect('/ajax/:controller/:action/*', array('bare'=>'1')); - $this->routes[] = $admin_route; $this->routes[] = $default_route; foreach ($this->routes as $route) { list($route, $regexp, $names, $defaults) = $route; + if (preg_match($regexp, $url, $r)) { // $this->log($url.' matched '.$regexp, 'note'); diff --git a/cake/libs/security.php b/cake/libs/security.php index d933da6a8..ee6aed2d9 100644 --- a/cake/libs/security.php +++ b/cake/libs/security.php @@ -54,20 +54,20 @@ class Security extends Object function inactiveMins() { - //$security = Security::getInstance(); - switch (CAKE_SECURITY) - { - case 'high': - return; - break; - case 'medium': - return; - break; - case 'low': - default : - return; - break; - } + $security =& Security::getInstance(); + switch (CAKE_SECURITY) + { + case 'high': + return 0; + break; + case 'medium': + return ; + break; + case 'low': + default : + return; + break; + } } } diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 494fd3d88..26f9bdb62 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -166,7 +166,7 @@ class HtmlHelper extends Helper { $output = $this->base.'/'.strtolower($this->params['controller']).'/'.$url; } - + return $this->output(preg_replace('/&([^a])/', '&\1', $output), $return); } diff --git a/cake/libs/view/templates/errors/missing_view.thtml b/cake/libs/view/templates/errors/missing_view.thtml index 4ae9f6893..e2971c8c9 100644 --- a/cake/libs/view/templates/errors/missing_view.thtml +++ b/cake/libs/view/templates/errors/missing_view.thtml @@ -45,7 +45,7 @@ view file, a user-customizable error page for handling missing/invalid views dur

    Fatal: Unable to load view file missingView;?> for -action params['controller'];?>::params['action'];?> +action missingView;?>::params['action'];?>

    1):?>