Updated VERSION file

Merging:

Revision: [1647]
Commit to fix auto render using requestAction()

Revision: [1646]
Added fix for the date select forms in scaffold when using date field type in the database.
Added fix for Ticket #132.
Added @ to stop warning in php if a call to gethostbyaddr fails with a bad ip sent.
Performance increased more with changes the View::_loadHelpers.
  Each helper would load the config file whan an instance was created and parse, change now reads it once.
  Fixed previous fix I added to only load helpers once, this time it works.
Change the constructor in View to use __construct() like other classes in the core.
Added $this->autoRender = false; in PagesController::display() after $this->render() is called.
PHP 5 would work fine without it, PHP 4 would display a view under the rendered layout.


git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1648 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-12-28 01:52:56 +00:00
parent f0fe2102ec
commit f247cae56c
8 changed files with 137 additions and 114 deletions

View file

@ -229,10 +229,12 @@ class Dispatcher extends Object
$output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); $output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
if ($controller->autoRender) if ($controller->autoRender)
{ {
$controller->render(); return $controller->render();
exit; }
else
{
return $output;
} }
return $output;
} }
/** /**

View file

@ -58,23 +58,20 @@ class PagesController extends AppController{
*/ */
function display() function display()
{ {
if (!func_num_args()) if (!func_num_args())
{ {
$this->redirect('/'); $this->redirect('/');
} }
$path = func_get_args();
$path = func_get_args(); if (!count($path))
{
if (!count($path)) $this->redirect('/');
{ }
$this->redirect('/'); $this->set('page', $path[0]);
} $this->set('subpage', empty($path[1])? null: $path[1]);
$this->set('page', $path[0]); $this->set('title', ucfirst($path[count($path)-1]));
$this->set('subpage', empty($path[1])? null: $path[1]); $this->render(join('/', $path));
$this->set('title', ucfirst($path[count($path)-1])); $this->autoRender = false;
$this->render(join('/', $path));
} }
} }
?> ?>

View file

@ -98,11 +98,11 @@ class Object
{ {
if(in_array('render', $extra)) if(in_array('render', $extra))
{ {
$extra['render'] = 0; $extra['render'] = 1;
} }
else else
{ {
$extra['render'] = 1; $extra['render'] = 0;
} }
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
return $dispatcher->dispatch($url, $extra); return $dispatcher->dispatch($url, $extra);

View file

@ -82,6 +82,12 @@ class CakeSession extends Object
*/ */
var $sessionId = null; var $sessionId = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $security = null;
/** /**
* Enter description here... * Enter description here...
* *
@ -106,8 +112,25 @@ class CakeSession extends Object
$this->host = substr($this->host,0, strpos($this->host, ':')); $this->host = substr($this->host,0, strpos($this->host, ':'));
} }
$this->ip = !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$this->userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; {
$this->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$this->ip = $_SERVER['REMOTE_ADDR'];
}
if(!empty($_SERVER['HTTP_USER_AGENT']))
{
$this->userAgent = md5($_SERVER['HTTP_USER_AGENT']);
}
else
{
$this->userAgent = "";
}
$this->security = CAKE_SECURITY;
$this->_initSession(); $this->_initSession();
$this->_begin(); $this->_begin();
parent::__construct(); parent::__construct();
@ -309,7 +332,7 @@ class CakeSession extends Object
function _initSession() function _initSession()
{ {
switch (CAKE_SECURITY) switch ($this->security)
{ {
case 'high': case 'high':
$this->cookieLifeTime = 0; $this->cookieLifeTime = 0;
@ -393,7 +416,7 @@ class CakeSession extends Object
function _new() function _new()
{ {
if(!ereg("proxy\.aol\.com$", gethostbyaddr($this->ip))) if(!ereg("proxy\.aol\.com$", @gethostbyaddr($this->ip)))
{ {
if($this->readSessionVar("Config")) if($this->readSessionVar("Config"))
{ {
@ -428,7 +451,7 @@ class CakeSession extends Object
$this->valid = true; $this->valid = true;
} }
if(CAKE_SECURITY == 'high') if($this->security == 'high')
{ {
$this->_regenerateId(); $this->_regenerateId();
} }
@ -479,13 +502,14 @@ class CakeSession extends Object
$newSessid = session_id(); $newSessid = session_id();
if (function_exists('session_write_close')) if (function_exists('session_write_close'))
{ {
if(CAKE_SECURITY == 'high') if($this->security == 'high')
{ {
if (isset($_COOKIE[session_name()])) if (isset($_COOKIE[session_name()]))
{ {
setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path); setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path);
} }
$file = ini_get('session.save_path')."/sess_$oldSessionId"; $sessionpath = session_save_path();
$file = $sessionpath."/sess_$oldSessionId";
@unlink($file); @unlink($file);
} }
session_write_close(); session_write_close();

View file

@ -3,20 +3,20 @@
/** /**
* Backend for helpers. * Backend for helpers.
* *
* Internal methods for the Helpers. * Internal methods for the Helpers.
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* CakePHP : Rapid Development Framework <http://www.cakephp.org/> * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, Cake Software Foundation, Inc. * Copyright (c) 2005, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204 * 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104 * Las Vegas, Nevada 89104
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @filesource * @filesource
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc. * @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake * @package cake
@ -76,7 +76,11 @@ class Helper extends Object
*/ */
function Helper() function Helper()
{ {
$this->tags = $this->readConfigFile(CAKE.'config'.DS.'tags.ini.php'); }
function loadConfig()
{
return $this->readConfigFile(CAKE.'config'.DS.'tags.ini.php');
} }
/** /**
@ -125,7 +129,7 @@ class Helper extends Object
return str_replace('%%'.array_keys($values).'%%', array_values($values), return str_replace('%%'.array_keys($values).'%%', array_values($values),
$this->tags[$keyName]); $this->tags[$keyName]);
} }
/** /**
* Returns an array of settings in given INI file. * Returns an array of settings in given INI file.
* *

View file

@ -215,7 +215,7 @@ class FormHelper extends Helper
function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected ) function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected )
{ {
$htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName));; $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName));;
$str = $this->Html->dateTimeOptionTag( $tagName, 'MDY' , 'NONE', '', $selected, $htmlOptions); $str = $this->Html->dateTimeOptionTag( $tagName, 'MDY' , 'NONE', $selected, $htmlOptions);
$strLabel = $this->labelTag( $tagName, $prompt ); $strLabel = $this->labelTag( $tagName, $prompt );
$divClass = "optional"; $divClass = "optional";

View file

@ -129,7 +129,7 @@ class HtmlHelper extends Helper
* @return mixed Either string or boolean value, depends on AUTO_OUTPUT * @return mixed Either string or boolean value, depends on AUTO_OUTPUT
* and $return. * and $return.
*/ */
function charset($charset, $return) function charset($charset, $return = false)
{ {
return $this->output(sprintf($this->tags['charset'], $charset), $return); return $this->output(sprintf($this->tags['charset'], $charset), $return);
} }
@ -547,7 +547,7 @@ class HtmlHelper extends Helper
function tagValue ($fieldName) function tagValue ($fieldName)
{ {
$this->setFormTag($fieldName); $this->setFormTag($fieldName);
return isset($this->params['data'][$this->model][$this->field])? $this->params['data'][$this->model][$this->field]: false; return isset($this->params['data'][$this->model][$this->field])? htmlspecialchars($this->params['data'][$this->model][$this->field]): false;
} }
/** /**
@ -934,16 +934,7 @@ class HtmlHelper extends Helper
{ {
if (!in_array($k, $exclude)) if (!in_array($k, $exclude))
{ {
$pos = strpos($v, '"'); $out[] = "{$k}=\"{$v}\"";
if($pos === false)
{
$out[] = "{$k}=\"{$v}\"";
}
else
{
$out[] = "{$k}='{$v}'";
}
} }
} }
$out = join(' ', $out); $out = join(' ', $out);
@ -1443,57 +1434,61 @@ class HtmlHelper extends Helper
} }
$meridian = 'am'; $meridian = 'am';
$date = explode('-',$selected); $date = explode('-',$selected);
$day = explode(' ',$date[2]); $days = explode(' ',$date[2]);
$time = explode(':',$day[1]);
if(($time[0] > 12) && $timeFormat == '12') $day = $days[0];
{
$time[0] = $time[0] - 12;
$meridian = 'pm';
}
elseif($time[0] > 12)
{
$meridian = 'pm';
}
$day = $day[0];
$month = $date[1]; $month = $date[1];
$year = $date[0]; $year = $date[0];
$hour = $time[0];
$min = $time[1]; if($timeFormat != 'NONE' && !empty($timeFormat))
{
$time = explode(':',$days[1]);
if(($time[0] > 12) && $timeFormat == '12')
{
$time[0] = $time[0] - 12;
$meridian = 'pm';
}
elseif($time[0] > 12)
{
$meridian = 'pm';
}
$hour = $time[0];
$min = $time[1];
}
} }
switch ( $dateFormat ) switch ( $dateFormat )
{ {
case 'DMY' : case 'DMY' :
$opt = $this->dayOptionTag( $tagName ,null ,$day) . '-' . $this->monthOptionTag( $tagName, null, $month ) . '-' . $this->yearOptionTag( $tagName, null, null, null, $year ); $opt = $this->dayOptionTag( $tagName ,null ,$day) . '-' . $this->monthOptionTag( $tagName, null, $month ) . '-' . $this->yearOptionTag( $tagName, null, null, null, $year );
break; break;
case 'MDY' : case 'MDY' :
$opt = $this->monthOptionTag($tagName, null, $month) .'-'.$this->dayOptionTag( $tagName, null, $day ) . '-' . $this->yearOptionTag($tagName, null, null, null, $year); $opt = $this->monthOptionTag($tagName, null, $month) .'-'.$this->dayOptionTag( $tagName, null, $day ) . '-' . $this->yearOptionTag($tagName, null, null, null, $year);
break; break;
case 'YMD' : case 'YMD' :
$opt = $this->yearOptionTag($tagName, null, null, null, $year) . '-' . $this->monthOptionTag( $tagName, null, $month ) . '-' . $this->dayOptionTag( $tagName, null, $day ); $opt = $this->yearOptionTag($tagName, null, null, null, $year) . '-' . $this->monthOptionTag( $tagName, null, $month ) . '-' . $this->dayOptionTag( $tagName, null, $day );
break; break;
case 'NONE': case 'NONE':
$opt =''; $opt ='';
break; break;
default: default:
$opt = ''; $opt = '';
break; break;
} }
switch ($timeFormat) switch ($timeFormat)
{ {
case '24': case '24':
$opt .= $this->hourOptionTag( $tagName, null , true, $hour) . ':' . $this->minuteOptionTag( $tagName, null, $min ); $opt .= $this->hourOptionTag( $tagName, null , true, $hour) . ':' . $this->minuteOptionTag( $tagName, null, $min );
break; break;
case '12': case '12':
$opt .= $this->hourOptionTag( $tagName, null, false, $hour) . ':' . $this->minuteOptionTag( $tagName, null, $min) . ' ' . $this->meridianOptionTag($tagName, null, $meridian); $opt .= $this->hourOptionTag( $tagName, null, false, $hour) . ':' . $this->minuteOptionTag( $tagName, null, $min) . ' ' . $this->meridianOptionTag($tagName, null, $meridian);
break; break;
case 'NONE': case 'NONE':
$opt .=''; $opt .='';
break; break;
default : default :
$opt .='';
break; break;
} }
return $opt; return $opt;

View file

@ -173,12 +173,19 @@ class View extends Object
*/ */
var $controller = null; var $controller = null;
/**
* Enter description here...
*
* @var array
*/
var $loaded = array();
/** /**
* Constructor * Constructor
* *
* @return View * @return View
*/ */
function View(&$controller) function __construct (&$controller)
{ {
$this->controller =& $controller; $this->controller =& $controller;
$this->_viewVars =& $this->controller->_viewVars; $this->_viewVars =& $this->controller->_viewVars;
@ -199,24 +206,9 @@ class View extends Object
$this->data =& $this->controller->data; $this->data =& $this->controller->data;
$this->displayFields =& $this->controller->displayFields; $this->displayFields =& $this->controller->displayFields;
$this->webservices =& $this->controller->webservices; $this->webservices =& $this->controller->webservices;
parent::__construct();
} }
/**
* Returns a view instance (singleton)
*
* @return object
*/
function getInstance()
{
static $instance;
if (!isset($instance))
{
$instance[0] =& new View();
}
return $instance[0];
}
/** /**
* Renders view for given action and layout. If $file is given, that is used * Renders view for given action and layout. If $file is given, that is used
* for a view filename (e.g. customFunkyView.thtml). * for a view filename (e.g. customFunkyView.thtml).
@ -247,11 +239,14 @@ class View extends Object
$this->setLayout($layout); $this->setLayout($layout);
} }
$viewFileName = $this->_getViewFileName($action);
if ($file) if ($file)
{ {
$viewFileName = $file; $viewFileName = $file;
} }
else
{
$viewFileName = $this->_getViewFileName($action);
}
if (!is_file($viewFileName)) if (!is_file($viewFileName))
{ {
@ -389,8 +384,8 @@ class View extends Object
if (is_file($layout_fn)) if (is_file($layout_fn))
{ {
$data_for_layout = array_merge($data_for_layout,$this->loaded); # load all view variables)
$out = $this->_render($layout_fn, $data_for_layout, true, false); $out = $this->_render($layout_fn, $data_for_layout, true, false);
if ($out === false) if ($out === false)
{ {
$out = $this->_render($layout_fn, $data_for_layout, false); $out = $this->_render($layout_fn, $data_for_layout, false);
@ -463,6 +458,10 @@ class View extends Object
{ {
$viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml'; $viewFileName = VIEWS.$this->viewPath.DS.$type.$action.'.thtml';
} }
elseif(file_exists(VIEWS.'errors'.DS.$type.$action.'.thtml'))
{
$viewFileName = VIEWS.'errors'.DS.$type.$action.'.thtml';
}
elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml')) elseif(file_exists(LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'))
{ {
$viewFileName = LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml'; $viewFileName = LIBS.'view'.DS.'templates'.DS.'errors'.DS.$type.$action.'.thtml';
@ -521,31 +520,30 @@ class View extends Object
* @return string Rendered output * @return string Rendered output
* @access private * @access private
*/ */
function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true) function _render($___viewFn, $___data_for_view, $___play_safe = true, $loadHelpers = true)
{ {
/** if ($this->helpers != false && $loadHelpers === true)
* Fetching helpers {
*/ $loadedHelpers = array();
if ($this->helpers != false && $loadHelpers = true) $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
{
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach(array_keys($loadedHelpers) as $helper) foreach(array_keys($loadedHelpers) as $helper)
{ {
$replace = strtolower(substr($helper, 0, 1)); $replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1); $camelBackedHelper = preg_replace('/\\w/', $replace, $helper, 1);
${$camelBackedHelper} =& $loadedHelpers[$helper]; ${$camelBackedHelper} =& $loadedHelpers[$helper];
if(isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers))
{ if(isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers))
foreach(${$camelBackedHelper}->helpers as $subHelper) {
{ foreach(${$camelBackedHelper}->helpers as $subHelper)
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper]; {
} ${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
} }
} }
} $this->loaded[$camelBackedHelper] = (${$camelBackedHelper});
}
}
extract($___data_for_view, EXTR_SKIP); # load all view variables extract($___data_for_view, EXTR_SKIP); # load all view variables
/** /**
@ -579,6 +577,8 @@ class View extends Object
*/ */
function &_loadHelpers(&$loaded, $helpers) function &_loadHelpers(&$loaded, $helpers)
{ {
$helperTags = new Helper();
$tags = $helperTags->loadConfig();
foreach ($helpers as $helper) foreach ($helpers as $helper)
{ {
$helperCn = $helper.'Helper'; $helperCn = $helper.'Helper';
@ -622,6 +622,7 @@ class View extends Object
${$camelBackedHelper}->params = $this->params; ${$camelBackedHelper}->params = $this->params;
${$camelBackedHelper}->action = $this->action; ${$camelBackedHelper}->action = $this->action;
${$camelBackedHelper}->data = $this->data; ${$camelBackedHelper}->data = $this->data;
${$camelBackedHelper}->tags = $tags;
if(!empty($this->validationErrors)) if(!empty($this->validationErrors))
{ {