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']);
if ($controller->autoRender)
{
$controller->render();
exit;
return $controller->render();
}
else
{
return $output;
}
return $output;
}
/**

View file

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

View file

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

View file

@ -82,6 +82,12 @@ class CakeSession extends Object
*/
var $sessionId = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $security = null;
/**
* Enter description here...
*
@ -106,8 +112,25 @@ class CakeSession extends Object
$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'];
$this->userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$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->_begin();
parent::__construct();
@ -309,7 +332,7 @@ class CakeSession extends Object
function _initSession()
{
switch (CAKE_SECURITY)
switch ($this->security)
{
case 'high':
$this->cookieLifeTime = 0;
@ -393,7 +416,7 @@ class CakeSession extends Object
function _new()
{
if(!ereg("proxy\.aol\.com$", gethostbyaddr($this->ip)))
if(!ereg("proxy\.aol\.com$", @gethostbyaddr($this->ip)))
{
if($this->readSessionVar("Config"))
{
@ -428,7 +451,7 @@ class CakeSession extends Object
$this->valid = true;
}
if(CAKE_SECURITY == 'high')
if($this->security == 'high')
{
$this->_regenerateId();
}
@ -479,13 +502,14 @@ class CakeSession extends Object
$newSessid = session_id();
if (function_exists('session_write_close'))
{
if(CAKE_SECURITY == 'high')
if($this->security == 'high')
{
if (isset($_COOKIE[session_name()]))
{
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);
}
session_write_close();

View file

@ -3,20 +3,20 @@
/**
* Backend for helpers.
*
*
* Internal methods for the Helpers.
*
* PHP versions 4 and 5
*
* 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
* Las Vegas, Nevada 89104
*
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @filesource
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
* @package cake
@ -76,7 +76,11 @@ class Helper extends Object
*/
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),
$this->tags[$keyName]);
}
/**
* 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 )
{
$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 );
$divClass = "optional";

View file

@ -129,7 +129,7 @@ class HtmlHelper extends Helper
* @return mixed Either string or boolean value, depends on AUTO_OUTPUT
* and $return.
*/
function charset($charset, $return)
function charset($charset, $return = false)
{
return $this->output(sprintf($this->tags['charset'], $charset), $return);
}
@ -547,7 +547,7 @@ class HtmlHelper extends Helper
function tagValue ($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))
{
$pos = strpos($v, '"');
if($pos === false)
{
$out[] = "{$k}=\"{$v}\"";
}
else
{
$out[] = "{$k}='{$v}'";
}
$out[] = "{$k}=\"{$v}\"";
}
}
$out = join(' ', $out);
@ -1443,57 +1434,61 @@ class HtmlHelper extends Helper
}
$meridian = 'am';
$date = explode('-',$selected);
$day = explode(' ',$date[2]);
$time = explode(':',$day[1]);
$days = explode(' ',$date[2]);
if(($time[0] > 12) && $timeFormat == '12')
{
$time[0] = $time[0] - 12;
$meridian = 'pm';
}
elseif($time[0] > 12)
{
$meridian = 'pm';
}
$day = $day[0];
$day = $days[0];
$month = $date[1];
$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 )
{
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;
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;
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;
case 'NONE':
$opt ='';
$opt ='';
break;
default:
$opt = '';
$opt = '';
break;
}
switch ($timeFormat)
{
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;
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;
case 'NONE':
$opt .='';
$opt .='';
break;
default :
$opt .='';
break;
}
return $opt;

View file

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