From 6d71310f003dff832a3bc1d88d415d177400f224 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 15 Jul 2006 03:36:53 +0000 Subject: [PATCH] Beginning to port fixes to 1.2.x.x code from 1.1.x.x git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3268 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- cake/basics.php | 13 ++-- cake/dispatcher.php | 78 ++++++++++--------- cake/libs/controller/scaffold.php | 50 ++++++------ cake/libs/session.php | 4 + .../scaffolds/{new.thtml => add.thtml} | 0 cake/libs/view/templates/scaffolds/edit.thtml | 2 +- .../scaffolds/{list.thtml => index.thtml} | 4 +- .../scaffolds/{show.thtml => view.thtml} | 8 +- cake/scripts/acl.php | 29 +++++-- cake/scripts/bake.php | 38 ++++++++- 11 files changed, 146 insertions(+), 82 deletions(-) rename cake/libs/view/templates/scaffolds/{new.thtml => add.thtml} (100%) rename cake/libs/view/templates/scaffolds/{list.thtml => index.thtml} (95%) rename cake/libs/view/templates/scaffolds/{show.thtml => view.thtml} (97%) diff --git a/VERSION.txt b/VERSION.txt index d9a594c49..8ea3b8c9d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -1.2.4.3104 \ No newline at end of file +1.2.0.3268 \ No newline at end of file diff --git a/cake/basics.php b/cake/basics.php index cad5b1565..679d691b1 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -99,13 +99,16 @@ overload($pluginAppModel); } $pluginModelDir = APP . 'plugins' . DS . $plugin . DS . 'models' . DS; - + $loadedPluginModels = array(); foreach(listClasses($pluginModelDir)as $modelFileName) { - require($pluginModelDir . $modelFileName); + if (!key_exists($modelFileName, $loadedPluginModels)) { + require($pluginModelDir . $modelFileName); - if (phpversion() < 5 && function_exists("overload")) { - list($name) = explode('.', $modelFileName); - overload(Inflector::camelize($name)); + if (phpversion() < 5 && function_exists("overload")) { + list($name) = explode('.', $modelFileName); + overload(Inflector::camelize($name)); + } + $loadedPluginModels[$modelFileName] = $modelFileName; } } } diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 6be6de54d..462c1b18e 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -73,7 +73,7 @@ class Dispatcher extends Object { * @param string $url URL information to work on. * @return boolean Success */ - function dispatch($url, $additionalParams = array()) { + function dispatch($url, $additionalParams=array()) { $params = array_merge($this->parseParams($url), $additionalParams); $missingController = false; $missingAction = false; @@ -92,23 +92,25 @@ class Dispatcher extends Object { $pluginName = Inflector::camelize($params['action']); if (!loadPluginController(Inflector::underscore($ctrlName), $pluginName)) { if(preg_match('/([\\.]+)/', $ctrlName)) { - return $this->cakeError('error404', array(array( - 'url' => strtolower($ctrlName), - 'message' => 'Was not found on this server', - 'base' => $this->base - ))); - exit(); + return $this->cakeError('error404', array( + array('url' => strtolower($ctrlName), + 'message' => 'Was not found on this server', + 'base' => $this->base))); + exit(); } else { $missingController = true; } } else { $params['plugin'] = Inflector::underscore($ctrlName); } + } else { + $params['plugin'] = null; + $this->plugin = null; } } } - if(isset($params['plugin'])) { + if(isset($params['plugin'])){ $plugin = $params['plugin']; $pluginName = Inflector::camelize($params['action']); $pluginClass = $pluginName.'Controller'; @@ -122,7 +124,6 @@ class Dispatcher extends Object { if(empty($params['controller']) || !class_exists($pluginClass)) { $params['controller'] = Inflector::underscore($ctrlName); $ctrlClass = $ctrlName.'Controller'; - if (!is_null($params['action'])) { array_unshift($params['pass'], $params['action']); } @@ -149,12 +150,11 @@ class Dispatcher extends Object { } if ($missingController) { - return $this->cakeError('missingController', array(array( - 'className' => Inflector::camelize($params['controller']."Controller"), - 'webroot' => $this->webroot, - 'url' => $url, - 'base' => $this->base - ))); + return $this->cakeError('missingController', array( + array('className' => Inflector::camelize($params['controller']."Controller"), + 'webroot' => $this->webroot, + 'url' => $url, + 'base' => $this->base))); } else { $controller =& new $ctrlClass($this); } @@ -183,7 +183,12 @@ class Dispatcher extends Object { } $controller->base = $this->base; - $controller->here = $this->base.'/'.$url; + $base = strip_plugin($this->base, $this->plugin); + if(defined("BASE_URL")){ + $controller->here = $base . $this->admin . $url; + } else { + $controller->here = $base . $this->admin . '/' . $url; + } $controller->webroot = $this->webroot; $controller->params = $params; $controller->action = $params['action']; @@ -228,24 +233,22 @@ class Dispatcher extends Object { $controller->constructClasses(); - if ($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' => $url, - 'base' => $this->base - ))); + if ($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' => $url, + 'base' => $this->base))); } if ($privateAction){ - return $this->cakeError('privateAction', array(array( - 'className' => Inflector::camelize($params['controller']."Controller"), - 'action' => $params['action'], - 'webroot' => $this->webroot, - 'url' => $url, - 'base' => $this->base - ))); + return $this->cakeError('privateAction', array( + array('className' => Inflector::camelize($params['controller']."Controller"), + 'action' => $params['action'], + 'webroot' => $this->webroot, + 'url' => $url, + 'base' => $this->base))); } return $this->_invoke($controller, $params, $missingAction); } @@ -279,8 +282,8 @@ class Dispatcher extends Object { * * @param object $controller */ - function start(&$controller) { - + function start(&$controller) + { if (!empty($controller->beforeFilter)) { if(is_array($controller->beforeFilter)) { @@ -303,6 +306,7 @@ class Dispatcher extends Object { } } } + /** * Returns array of GET and POST parameters. GET parameters are taken from given URL. * @@ -342,7 +346,9 @@ class Dispatcher extends Object { 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; } @@ -378,7 +384,7 @@ class Dispatcher extends Object { if (preg_match('/^(.*)\/index\.php$/', $scriptName, $r)) { if(!empty($r[1])) { - return $base.$r[1]; + return $base.$r[1]; } } } else { @@ -395,11 +401,11 @@ class Dispatcher extends Object { $appDir = '/'.APP_DIR; } !empty($htaccess)? $this->webroot = $htaccess : $this->webroot = $regs[1].$appDir.'/'; - return $base.$regs[1].$appDir; + return $base.$regs[1].$appDir; } elseif (preg_match('/^(.*)\\/'.WEBROOT_DIR.'([^\/i]*)|index\\\.php$/', $scriptName, $regs)) { !empty($htaccess)? $this->webroot = $htaccess : $this->webroot = $regs[0].'/'; - return $base.$regs[0]; + return $base.$regs[0]; } else { !empty($htaccess)? $this->webroot = $htaccess : $this->webroot = '/'; diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index f1e4f30f1..46e16e879 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -100,35 +100,35 @@ class Scaffold extends Object{ 'Scaffold :: ' . Inflector::humanize($controller->action) . ' :: ' . Inflector::humanize( Inflector::pluralize( $this->modelKey)); - $this->__scaffoldView($params); + $this->__scaffold($params); } /** - * Renders a Show view of scaffolded Model. + * Renders a view view of scaffolded Model. * * @param array $params * @return A rendered view of a row from Models database table * @access private */ - function __scaffoldShow($params) { - if ($this->controllerClass->_beforeScaffold('show')) { + function __scaffoldView($params) { + if ($this->controllerClass->_beforeScaffold('view')) { $this->controllerClass->params['data']=$this->controllerClass->{$this->modelKey}->read(); $this->controllerClass->set('data', $this->controllerClass->params['data']); $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames( $this->controllerClass->params['data'], false)); - if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.show.thtml')) { + if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml')) { return $this->controllerClass->render($this->actionView, '', - APP . 'views' . DS . $this->viewPath . DS . 'scaffold.show.thtml'); - } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.show.thtml')) { + APP . 'views' . DS . $this->viewPath . DS . 'scaffold.view.thtml'); + } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml')) { return $this->controllerClass->render($this->actionView, '', - APP . 'views' . DS . 'scaffold' . DS . 'scaffold.show.thtml'); + APP . 'views' . DS . 'scaffold' . DS . 'scaffold.view.thtml'); } else { return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' - . DS . 'scaffolds' . DS . 'show.thtml'); + . DS . 'scaffolds' . DS . 'view.thtml'); } - } else if($this->controllerClass->_scaffoldError('show') === false) { + } else if($this->controllerClass->_scaffoldError('view') === false) { return $this->__scaffoldError(); } } @@ -147,15 +147,15 @@ class Scaffold extends Object{ $this->controllerClass->{$this->modelKey}->recursive=0; $this->controllerClass->set('data', $this->controllerClass->{$this->modelKey}->findAll()); - if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.list.thtml')) { + if (file_exists(APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml')) { return $this->controllerClass->render($this->actionView, '', - APP . 'views' . DS . $this->viewPath . DS . 'scaffold.list.thtml'); - } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.list.thtml')) { + APP . 'views' . DS . $this->viewPath . DS . 'scaffold.index.thtml'); + } elseif(file_exists(APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml')) { return $this->controllerClass->render($this->actionView, '', - APP . 'views' . DS . 'scaffold' . DS . 'scaffold.list.thtml'); + APP . 'views' . DS . 'scaffold' . DS . 'scaffold.index.thtml'); } else { return $this->controllerClass->render($this->actionView, '', LIBS . 'view' . DS . 'templates' - . DS . 'scaffolds' . DS . 'list.thtml'); + . DS . 'scaffolds' . DS . 'index.thtml'); } } else if($this->controllerClass->_scaffoldError('index') === false) { return $this->__scaffoldError(); @@ -166,7 +166,7 @@ class Scaffold extends Object{ * Renders an Add or Edit view for scaffolded Model. * * @param array $params - * @param string $params add or new + * @param string $params add or edit * @return A rendered view with a form to edit or add a record in the Models database table * @access private */ @@ -175,8 +175,8 @@ class Scaffold extends Object{ $form ='Edit'; if ($type === 'add') { - $thtml='new'; - $form ='New'; + $thtml='add'; + $form ='Add'; } if ($this->controllerClass->_beforeScaffold($type)) { @@ -213,7 +213,7 @@ class Scaffold extends Object{ * * @param array $params * @param string $type create or update - * @return success on save/update, new/edit form if data is empty or error if save or update fails + * @return success on save/update, add/edit form if data is empty or error if save or update fails * @access private */ function __scaffoldSave($params = array(), $type) { @@ -236,8 +236,8 @@ class Scaffold extends Object{ if ($type == 'create') { $this->controllerClass->{$this->modelKey}->create(); - $thtml ='new'; - $form ='New'; + $thtml ='add'; + $form ='Add'; $success='saved'; } @@ -390,7 +390,7 @@ class Scaffold extends Object{ * @since Cake v 0.10.0.172 * @access private */ - function __scaffoldView($params) { + function __scaffold($params) { if (!in_array('Form', $this->controllerClass->helpers)) { $this->controllerClass->helpers[] = 'Form'; } @@ -399,7 +399,7 @@ class Scaffold extends Object{ $db=&ConnectionManager::getDataSource($this->controllerClass->{$this->modelKey}->useDbConfig); if (isset($db)) { - if ($params['action'] === 'index' || $params['action'] === 'list' || $params['action'] === 'show' + if ($params['action'] === 'index' || $params['action'] === 'list' || $params['action'] === 'view' || $params['action'] === 'add' || $params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'update' || $params['action'] === 'delete') { @@ -410,8 +410,8 @@ class Scaffold extends Object{ break; - case 'show': - $this->__scaffoldShow($params); + case 'view': + $this->__scaffoldView($params); break; diff --git a/cake/libs/session.php b/cake/libs/session.php index d8ba45e25..86a34c2b2 100644 --- a/cake/libs/session.php +++ b/cake/libs/session.php @@ -426,6 +426,10 @@ class CakeSession extends Object{ $table = $db->fullTableName(CAKE_SESSION_TABLE, false); $row = $db->query("SELECT " . $db->name($table.'.data') . " FROM " . $db->name($table) . " WHERE " . $db->name($table.'.id') . " = " . $db->value($key), false); + if ($row && !isset($row[0][$table]) && isset($row[0][0])) { + $table = 0; + } + if ($row && $row[0][$table]['data']) { return $row[0][$table]['data']; } else { diff --git a/cake/libs/view/templates/scaffolds/new.thtml b/cake/libs/view/templates/scaffolds/add.thtml similarity index 100% rename from cake/libs/view/templates/scaffolds/new.thtml rename to cake/libs/view/templates/scaffolds/add.thtml diff --git a/cake/libs/view/templates/scaffolds/edit.thtml b/cake/libs/view/templates/scaffolds/edit.thtml index cc911e4a5..e1be1819e 100644 --- a/cake/libs/view/templates/scaffolds/edit.thtml +++ b/cake/libs/view/templates/scaffolds/edit.thtml @@ -66,7 +66,7 @@ if($type == 'Edit') { if(isset($value['foreignKey'])) { - echo "
  • ".$html->link( "View ".Inflector::humanize($value['controller']), $path.Inflector::underscore($value['controller'])."/show/".$data[$modelKey][$field] )."
  • "; + echo "
  • ".$html->link( "View ".Inflector::humanize($value['controller']), $path.Inflector::underscore($value['controller'])."/view/".$data[$modelKey][$field] )."
  • "; } } } diff --git a/cake/libs/view/templates/scaffolds/list.thtml b/cake/libs/view/templates/scaffolds/index.thtml similarity index 95% rename from cake/libs/view/templates/scaffolds/list.thtml rename to cake/libs/view/templates/scaffolds/index.thtml index 90f6fe331..42a748c13 100644 --- a/cake/libs/view/templates/scaffolds/list.thtml +++ b/cake/libs/view/templates/scaffolds/index.thtml @@ -98,7 +98,7 @@ if(is_array($data)) { $displayText = $row[$alias[$count]][$field]; } - echo $html->link( $displayText, $path.Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] ); + echo $html->link( $displayText, $path.Inflector::underscore($otherControllerName)."/view/".$row[$modelKey][$field] ); $count++; } else @@ -110,7 +110,7 @@ if(is_array($data)) - link('View',$path.$this->viewPath."/show/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?> + link('View',$path.$this->viewPath."/view/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?> link('Edit',$path.$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?> link('Delete',$path.$this->viewPath."/delete/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?> diff --git a/cake/libs/view/templates/scaffolds/show.thtml b/cake/libs/view/templates/scaffolds/view.thtml similarity index 97% rename from cake/libs/view/templates/scaffolds/show.thtml rename to cake/libs/view/templates/scaffolds/view.thtml index 03410e482..ab7800d3f 100644 --- a/cake/libs/view/templates/scaffolds/show.thtml +++ b/cake/libs/view/templates/scaffolds/view.thtml @@ -48,7 +48,7 @@ if(!empty($objModel->alias)) $count = 0; } ?> -

    Show +

    View

    @@ -65,7 +65,7 @@ foreach($fieldNames as $field => $value) if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]) && (isset($displayText))) { - echo "
    ".$html->link($displayText, $path.Inflector::underscore($value['controller']).'/show/' + echo "
    ".$html->link($displayText, $path.Inflector::underscore($value['controller']).'/view/' .$data[$objModel->tableToModel[$objModel->table]][$field] )."
    "; } else @@ -184,7 +184,7 @@ foreach($relations as $association => $relation) { ?> link('View',$path.Inflector::underscore($controller). - "/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?> + "/view/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?> link('Edit',$path.Inflector::underscore($controller). "/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?> link('Delete',$path.Inflector::underscore($controller). @@ -196,7 +196,7 @@ foreach($relations as $association => $relation) { ?> link('View',$path.Inflector::underscore($controller). - "/show/{$row[$this->controller->{$modelName}->primaryKey]}/")?> + "/view/{$row[$this->controller->{$modelName}->primaryKey]}/")?> link('Edit',$path.Inflector::underscore($controller). "/edit/{$row[$this->controller->{$modelName}->primaryKey]}/")?> link('Delete',$path.Inflector::underscore($controller). diff --git a/cake/scripts/acl.php b/cake/scripts/acl.php index 8395d2fab..f3a5eea27 100644 --- a/cake/scripts/acl.php +++ b/cake/scripts/acl.php @@ -38,7 +38,7 @@ $root = dirname(dirname(dirname(__FILE__))); $here = $argv[0]; $dataSource = 'default'; - for ($i = 1; $i < count($argv); $i += 2) + for ($i = 1; $i < count($argv); $i++) { // Process command-line modifiers here switch (strtolower($argv[$i])) @@ -57,15 +57,30 @@ break; } } + + if (strlen($app) && $app[0] == DS) { + $cnt = substr_count($root, DS); + $app = str_repeat('..' . DS, $cnt) . $app; + } define ('ROOT', $root.DS); define ('APP_DIR', $app); - define ('APP_PATH', $app.DS); - define ('DEBUG', 1); - define ('CORE_PATH', $core); - define ('CAKE_CORE_INCLUDE_PATH', ROOT); + define ('DEBUG', 1);; + define('CAKE_CORE_INCLUDE_PATH', ROOT); define('DATASOURCE', $dataSource); - define ('DEBUG', 1); - ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); + + if(function_exists('ini_set')) { + ini_set('include_path',ini_get('include_path'). + PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.DS. + PATH_SEPARATOR.CORE_PATH.DS. + PATH_SEPARATOR.ROOT.DS.APP_DIR.DS. + PATH_SEPARATOR.APP_DIR.DS. + PATH_SEPARATOR.APP_PATH); + define('APP_PATH', null); + define('CORE_PATH', null); + } else { + define('APP_PATH', ROOT . DS . APP_DIR . DS); + define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); + } require ('cake'.DS.'basics.php'); require ('cake'.DS.'config'.DS.'paths.php'); diff --git a/cake/scripts/bake.php b/cake/scripts/bake.php index d771a07d6..25cbd4ca4 100644 --- a/cake/scripts/bake.php +++ b/cake/scripts/bake.php @@ -1562,6 +1562,12 @@ class Bake { } $strFormFields = $strFormFields.$this->generateDateTime( $field['tagName'], $field['prompt'], '','','', '', $field['selected']); break; + case "time": + if( !isset( $field['selected'])) { + $field['selected'] = null; + } + $strFormFields = $strFormFields.$this->generateTime( $field['tagName'], $field['prompt'], '','','', '', $field['selected']); + break; default: break; } @@ -1621,7 +1627,7 @@ class Bake { $htmlOptions['class'] = "inputCheckbox"; $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $htmlAttributes['checked'] = "\${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'] ? 'checked' : ''"; + $htmlAttributes['checked'] = "\${$this->lowCtrl}['{$tagNameArray[0]}']['{$tagNameArray[1]}'] ? 'checked' : null"; $str = "\tcheckbox('{$tagName}', null, " . $this->attributesToArray($htmlAttributes) . ")?>\n"; $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); @@ -1674,6 +1680,36 @@ class Bake { $requiredDiv = $this->divTag( $divClass, $divTagInside ); return $this->divTag("date", $requiredDiv); } +/** + * Enter description here... + * + * @param unknown_type $tagName + * @param unknown_type $prompt + * @param unknown_type $required + * @param unknown_type $errorMsg + * @param unknown_type $size + * @param unknown_type $htmlOptions + * @param unknown_type $selected + * @return unknown + */ + function generateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) { + $htmlOptions['id']=strtolower(str_replace('/', '_', $tagName)); + $str = $this->Html->dateTimeOptionTag($tagName, 'NONE', '24', $selected, $htmlOptions); + $strLabel = $this->labelTag($tagName, $prompt); + $divClass = "optional"; + if ($required) { + $divClass = "required"; + } + $strError = ""; + + if ($this->isFieldError($tagName)) { + $strError = $this->pTag('error', $errorMsg); + $divClass = sprintf("%s error", $divClass); + } + $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); + $requiredDiv = $this->divTag($divClass, $divTagInside); + return $this->divTag("time", $requiredDiv); + } /** * Enter description here... *