Merging fixes and enhancements into trunk

Revision: [1948]
Added fix for Ticket #376

Revision: [1947]
Renamed log.php to cake_log.php

Revision: [1946]
Added fix for Ticket #371;
Moved LogError to bascis.php from log.php
Renaming Log class to CakeLog to avoid conflicts with Pear Log class or any other Log class.
Added check to File class to load Folder class if it is not in memory already
Moved LOG_ERROR define to app/config/core.php

Revision: [1945]
Updated Inflector::pluralize(); and Inflector::singularize(); to use some code that is in the new Inflector class from version 1.x.x.x
Added fix for Ticket #373
Added fix for Ticket #357
Added patch from Ticket #363

Revision: [1944]
Added fix for Ticket #349 PHP 5 version

Revision: [1943]
Added fix for Ticket #349

Revision: [1942]
Adding patches from Ticket #377

Revision: [1941]
Quick URL fix for AjaxHelper::editor

Revision: [1940]
Fixing Ticket #375

Revision: [1939]
Adding fix for Ticket #369, plus slider control and Ajax In-Place editor

Revision: [1938]
diff patched applied from gwoo



git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1949 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-02-08 15:25:34 +00:00
parent ab34891751
commit e51b3d4915
14 changed files with 332 additions and 145 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.8.1937 RC 4
0.10.8.1949 RC 4

View file

@ -53,6 +53,11 @@
*
*/
define('DEBUG', 1);
/**
* Error constant. Used for differentiating error logging and debugging.
* Currently PHP supports LOG_DEBUG
*/
define ('LOG_ERROR', 2);
/**
* Set the name of session cookie
*

View file

@ -900,4 +900,19 @@ function countdim($array)
return $return;
}
/**
* Shortcut to Log::write.
*/
function LogError ($message)
{
if(!class_exists('CakeLog'))
{
uses('cake_log');
}
$bad = array("\n", "\r", "\t");
$good = ' ';
CakeLog::write('error', str_replace($bad, $good, $message));
}
?>

View file

@ -44,7 +44,7 @@ if(!class_exists('File'))
* @subpackage cake.cake.libs
* @since CakePHP v 0.2.9
*/
class Log
class CakeLog
{
/**
* Writes given message to a log file in the logs directory.
@ -63,20 +63,4 @@ class Log
}
}
/**
* Error constant. Used for differentiating error logging and debugging.
* Currently PHP supports LOG_DEBUG
*/
define ('LOG_ERROR', 2);
/**
* Shortcut to Log::write.
*/
function LogError ($message)
{
$bad = array("\n", "\r", "\t");
$good = ' ';
Log::write('error', str_replace($bad, $good, $message));
}
?>

View file

@ -35,6 +35,10 @@ if(!class_exists('Object'))
{
uses('object');
}
if(!class_exists('Folder'))
{
uses('folder');
}
/**
* Convenience class for reading, writing and appending to files.

View file

@ -67,36 +67,89 @@ class Inflector extends Object
*/
function pluralize ($word)
{
$plural_rules = array(
'/(s)tatus$/i' => '\1\2tatuses',
'/^(ox)$/i' => '\1\2en', # ox
'/([m|l])ouse$/i' => '\1ice', # mouse, louse
'/(matr|vert|ind)ix|ex$/i' => '\1ices', # matrix, vertex, index
'/(x|ch|ss|sh)$/i' => '\1es', # search, switch, fix, box, process, address
'/([^aeiouy]|qu)y$/i' => '\1ies', # query, ability, agency
'/(hive)$/i' => '\1s', # archive, hive
'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', # half, safe, wife
'/sis$/i' => 'ses', # basis, diagnosis
'/([ti])um$/i' => '\1a', # datum, medium
'/(p)erson$/i' => '\1eople', # person, salesperson
'/(m)an$/i' => '\1en', # man, woman, spokesman
'/(c)hild$/i' => '\1hildren', # child
'/(buffal|tomat)o$/i' => '\1\2oes', # buffalo, tomato
'/(bu)s$/i' => '\1\2ses', # bus
'/(alias)/i' => '\1es', # alias
'/(octop|vir)us$/i' => '\1i', # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
'/(ax|cri|test)is$/i' => '\1es', # axis, crisis
'/s$/' => 's', # no change (compatibility)
'/$/' => 's');
$pluralRules = array('/(s)tatus$/i' => '\1\2tatuses',
'/^(ox)$/i' => '\1\2en', # ox
'/([m|l])ouse$/i' => '\1ice', # mouse, louse
'/(matr|vert|ind)ix|ex$/i' => '\1ices', # matrix, vertex, index
'/(x|ch|ss|sh)$/i' => '\1es', # search, switch, fix, box, process, address
'/([^aeiouy]|qu)y$/i' => '\1ies', # query, ability, agency
'/(hive)$/i' => '\1s', # archive, hive
'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', # half, safe, wife
'/sis$/i' => 'ses', # basis, diagnosis
'/([ti])um$/i' => '\1a', # datum, medium
'/(p)erson$/i' => '\1eople', # person, salesperson
'/(m)an$/i' => '\1en', # man, woman, spokesman
'/(c)hild$/i' => '\1hildren', # child
'/(buffal|tomat)o$/i' => '\1\2oes', # buffalo, tomato
'/(bu)s$/i' => '\1\2ses', # bus
'/(alias)/i' => '\1es', # alias
'/(octop|vir)us$/i' => '\1i', # octopus, virus - virus has no defined plural (according to Latin/dictionary.com), but viri is better than viruses/viruss
'/(ax|cri|test)is$/i' => '\1es', # axis, crisis
'/s$/' => 's', # no change (compatibility)
'/$/' => 's');
foreach ($plural_rules as $rule => $replacement)
$uninflected = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*rice', '.*sheep', 'Amoyese',
'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese',
'Kongoese', 'Lucchese', 'mackerel', 'Maltese', 'mews', 'moose', 'mumps', 'Nankingese', 'news',
'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings',
'rabies', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears',
'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese',
'whiting', 'wildebeest', 'Yengeese',);
$irregular = array('atlas' => 'atlases',
'beef' => 'beefs',
'brother' => 'brothers',
'child' => 'children',
'corpus' => 'corpuses',
'cow' => 'cows',
'ganglion' => 'ganglions',
'genie' => 'genies',
'genus' => 'genera',
'graffito' => 'graffiti',
'hoof' => 'hoofs',
'loaf' => 'loaves',
'man' => 'men',
'money' => 'monies',
'mongoose' => 'mongooses',
'move' => 'moves',
'mythos' => 'mythoi',
'numen' => 'numina',
'occiput' => 'occiputs',
'octopus' => 'octopuses',
'opus' => 'opuses',
'ox' => 'oxen',
'penis' => 'penises',
'person' => 'people',
'sex' => 'sexes',
'soliloquy' => 'soliloquies',
'testis' => 'testes',
'trilby' => 'trilbys',
'turf' => 'turfs',);
$regexUninflected = __enclose(join( '|', $uninflected));
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
if (preg_match('/^('.$regexUninflected.')$/i', $word, $regs))
{
return $word;
}
if (preg_match('/(.*)\\b('.$regexIrregular.')$/i', $word, $regs))
{
return $regs[1] . $irregular[strtolower($regs[2])];
}
foreach ($pluralRules as $rule => $replacement)
{
if (preg_match($rule, $word))
{
if (preg_match($rule, $word))
{
return preg_replace($rule, $replacement, $word);
}
return preg_replace($rule, $replacement, $word);
}
return $word;//false;
}
return $word;
}
/**
@ -107,44 +160,97 @@ class Inflector extends Object
*/
function singularize ($word)
{
$singular_rules = array(
'/(s)tatuses$/i' => '\1\2tatus',
'/(matr)ices$/i' =>'\1ix',
'/(vert|ind)ices$/i' => '\1ex',
'/^(ox)en/i' => '\1',
'/(alias)es$/i' => '\1',
'/([octop|vir])i$/i' => '\1us',
'/(cris|ax|test)es$/i' => '\1is',
'/(shoe)s$/i' => '\1',
'/(o)es$/i' => '\1',
'/(bus)es$/i' => '\1',
'/([m|l])ice$/i' => '\1ouse',
'/(x|ch|ss|sh)es$/i' => '\1',
'/(m)ovies$/i' => '\1\2ovie',
'/(s)eries$/i' => '\1\2eries',
'/([^aeiouy]|qu)ies$/i' => '\1y',
'/([lr])ves$/i' => '\1f',
'/(tive)s$/i' => '\1',
'/(hive)s$/i' => '\1',
'/([^f])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um',
'/(p)eople$/i' => '\1\2erson',
'/(m)en$/i' => '\1an',
'/(c)hildren$/i' => '\1\2hild',
'/(n)ews$/i' => '\1\2ews',
'/s$/i' => '');
$singularRules = array('/(s)tatuses$/i' => '\1\2tatus',
'/(matr)ices$/i' =>'\1ix',
'/(vert|ind)ices$/i' => '\1ex',
'/^(ox)en/i' => '\1',
'/(alias)es$/i' => '\1',
'/([octop|vir])i$/i' => '\1us',
'/(cris|ax|test)es$/i' => '\1is',
'/(shoe)s$/i' => '\1',
'/(o)es$/i' => '\1',
'/(bus)es$/i' => '\1',
'/([m|l])ice$/i' => '\1ouse',
'/(x|ch|ss|sh)es$/i' => '\1',
'/(m)ovies$/i' => '\1\2ovie',
'/(s)eries$/i' => '\1\2eries',
'/([^aeiouy]|qu)ies$/i' => '\1y',
'/([lr])ves$/i' => '\1f',
'/(tive)s$/i' => '\1',
'/(hive)s$/i' => '\1',
'/(drive)s$/i' => '\1',
'/([^f])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um',
'/(p)eople$/i' => '\1\2erson',
'/(m)en$/i' => '\1an',
'/(c)hildren$/i' => '\1\2hild',
'/(n)ews$/i' => '\1\2ews',
'/s$/i' => '');
foreach ($singular_rules as $rule => $replacement)
$uninflected = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*rice', '.*sheep', 'Amoyese',
'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus', 'carp', 'chassis', 'clippers',
'cod', 'coitus', 'Congoese', 'contretemps', 'corps', 'debris', 'diabetes', 'djinn', 'eland', 'elk',
'equipment', 'Faroese', 'flounder', 'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese',
'Kongoese', 'Lucchese', 'mackerel', 'Maltese', 'mews', 'moose', 'mumps', 'Nankingese', 'news',
'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings',
'rabies', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears',
'siemens', 'species', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese',
'whiting', 'wildebeest', 'Yengeese',);
$irregular = array('atlas' => 'atlases',
'beefs' => 'beef',
'brothers' => 'brother',
'children' => 'child',
'corpuses' => 'corpus',
'cows' => 'cow',
'ganglions' => 'ganglion',
'genies' => 'genie',
'genera' => 'genus',
'graffiti' => 'graffito',
'hoofs' => 'hoof',
'loaves' => 'loaf',
'men' => 'man',
'monies' => 'money',
'mongooses' => 'mongoose',
'moves' => 'move',
'mythoi' => 'mythos',
'numina' => 'numen',
'occiputs' => 'occiput',
'octopuses' => 'octopus',
'opuses' => 'opus',
'oxen' => 'ox',
'penises' => 'penis',
'people' => 'person',
'sexes' => 'sex',
'soliloquies' => 'soliloquy',
'testes' => 'testis',
'trilbys' => 'trilby',
'turfs' => 'turf',);
$regexUninflected = __enclose(join( '|', $uninflected));
$regexIrregular = __enclose(join( '|', array_keys($irregular)));
if (preg_match('/^('.$regexUninflected.')$/i', $word, $regs))
{
return $word;
}
if (preg_match('/(.*)\\b('.$regexIrregular.')$/i', $word, $regs))
{
return $regs[1] . $irregular[strtolower($regs[2])];
}
foreach ($singularRules as $rule => $replacement)
{
if (preg_match($rule, $word))
{
if (preg_match($rule, $word))
{
return preg_replace($rule, $replacement, $word);
}
return preg_replace($rule, $replacement, $word);
}
// should not return false is not matched
return $word;//false;
}
return $word;
}
/**
@ -153,9 +259,9 @@ class Inflector extends Object
* @param string $lower_case_and_underscored_word Word to camelize
* @return string Camelized word. likeThis.
*/
function camelize($lower_case_and_underscored_word)
function camelize($lowerCaseAndUnderscoredWord)
{
return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word)));
return str_replace(" ","",ucwords(str_replace("_"," ",$lowerCaseAndUnderscoredWord)));
}
/**
@ -164,10 +270,9 @@ class Inflector extends Object
* @param string $camel_cased_word Camel-cased word to be "underscorized"
* @return string Underscore-syntaxed version of the $camel_cased_word
*/
function underscore($camel_cased_word)
function underscore($camelCasedWord)
{
$camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2', $camel_cased_word);
return strtolower(preg_replace('/([a-z])([A-Z])/','\1_\2', $camel_cased_word));
return strtolower (preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $camelCasedWord));
}
/**
@ -177,9 +282,9 @@ class Inflector extends Object
* @param string $lower_case_and_underscored_word String to be made more readable
* @return string Human-readable string
*/
function humanize($lower_case_and_underscored_word)
function humanize($lowerCaseAndUnderscoredWord)
{
return ucwords(str_replace("_"," ",$lower_case_and_underscored_word));
return ucwords(str_replace("_"," ",$lowerCaseAndUnderscoredWord));
}
/**
@ -188,9 +293,9 @@ class Inflector extends Object
* @param string $class_name Name of class to get database table name for
* @return string Name of the database table for given class
*/
function tableize($class_name)
function tableize($className)
{
return Inflector::pluralize(Inflector::underscore($class_name));
return Inflector::pluralize(Inflector::underscore($className));
}
/**
@ -211,9 +316,9 @@ class Inflector extends Object
* @param string $class_name
* @return string
*/
function foreignKey($class_name)
function foreignKey($className)
{
return Inflector::underscore($class_name) . "_id";
return Inflector::underscore($className) . "_id";
}
/**
@ -282,4 +387,9 @@ class Inflector extends Object
}
}
function __enclose($string)
{
return '(?:'.$string.')';
}
?>

View file

@ -256,12 +256,12 @@ class DboSource extends DataSource
{
$text = 'query';
}
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</th></tr>\n");
print("<table border=\"1\">\n<tr><th colspan=\"7\">{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</th></tr>\n");
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
foreach($log as $k => $i)
{
print("<tr><td>".($k + 1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
print("<tr><td>".($k + 1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td style=\"text-align: right\">{$i['affected']}</td><td style=\"text-align: right\">{$i['numRows']}</td><td style=\"text-align: right\">{$i['took']}</td></tr>\n");
}
print("</table>\n");
@ -340,12 +340,17 @@ class DboSource extends DataSource
$values = array_values($model->data);
}
foreach ($fields as $field)
{
$fieldInsert[] = $this->name($field);
}
foreach ($values as $value)
{
$valueInsert[] = $this->value($value);
}
if($this->execute('INSERT INTO '.$model->table.' ('.join(',', $fields).') VALUES ('.join(',', $valueInsert).')'))
if($this->execute('INSERT INTO '.$model->table.' ('.join(',', $fieldInsert).') VALUES ('.join(',', $valueInsert).')'))
{
return true;
}

View file

@ -9,7 +9,7 @@
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2006, Cake Software Foundation, Inc.
* Copyright (c) 2006, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
@ -403,12 +403,12 @@ class DBO extends Object
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
$this->_queriesLog;
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} queries took {$this->_queriesTime} ms</th></tr>\n");
print("<table border=\"1\">\n<tr><th colspan=\"7\">{$this->_queriesCnt} queries took {$this->_queriesTime} ms</th></tr>\n");
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
foreach($log AS $k=>$i)
{
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td style=\"text-align: right\">{$i['affected']}</td><td style=\"text-align: right\">{$i['numRows']}</td><td style=\"text-align: right\">{$i['took']}</td></tr>\n");
}
print("</table>\n");

View file

@ -834,14 +834,16 @@ class Model extends Object
$this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
$this->id = $this->__insertID;
if(!$this->id > 0 && isset($newID))
{
$this->id = $newID;
}
if(!empty($joined))
{
if(!$this->id > 0 && isset($newID))
{
$this->id = $newID;
}
$this->__saveMulti($joined, $this->id);
}
$this->afterSave();
$this->data = false;
return true;

View file

@ -830,14 +830,16 @@ class Model extends Object
$this->__insertID = $this->db->lastInsertId($this->table, $this->primaryKey);
$this->id = $this->__insertID;
if(!$this->id > 0 && isset($newID))
{
$this->id = $newID;
}
if(!empty($joined))
{
if(!$this->id > 0 && isset($newID))
{
$this->id = $newID;
}
$this->__saveMulti($joined, $this->id);
}
$this->afterSave();
$this->data = false;
return true;

View file

@ -125,17 +125,17 @@ class Object
* API for logging events.
*
* @param string $msg Log message
* @param int $type Error type constant. Defined in /libs/log.php.
* @param int $type Error type constant. Defined in app/config/core.php.
*/
function log ($msg, $type=LOG_ERROR)
{
if(!class_exists('Log'))
if(!class_exists('CakeLog'))
{
uses('log');
uses('cake_log');
}
if (is_null($this->_log))
{
$this->_log = new Log ();
$this->_log = new CakeLog();
}
switch ($type)

View file

@ -136,6 +136,7 @@ class CakeSession extends Object
$this->_begin();
}
$this->_checkValid();
parent::__construct();
}
@ -275,7 +276,7 @@ class CakeSession extends Object
{
session_cache_limiter("must-revalidate");
session_start();
$this->_new();
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
}
/**
@ -398,6 +399,7 @@ class CakeSession extends Object
array('CakeSession', '_gc'));
break;
case 'php':
ini_set('session.use_trans_sid', 0);
ini_set('session.name', CAKE_SESSION_COOKIE);
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
ini_set('session.cookie_path', $this->path);
@ -411,6 +413,7 @@ class CakeSession extends Object
}
else
{
ini_set('session.use_trans_sid', 0);
ini_set('session.name', CAKE_SESSION_COOKIE);
ini_set('session.cookie_lifetime', $this->cookieLifeTime);
ini_set('session.cookie_path', $this->path);
@ -426,7 +429,7 @@ class CakeSession extends Object
* @access private
*
*/
function _new()
function _checkValid()
{
if($this->readSessionVar("Config"))
{
@ -452,7 +455,6 @@ class CakeSession extends Object
$this->valid = true;
$this->_setError(1, "Session is valid");
}
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
}
/**

View file

@ -89,7 +89,14 @@ class AjaxHelper extends Helper
*
* @var array
*/
var $sliderOptions = array('axis', 'increment', 'maximum', 'minimum', 'alignX', 'alignY', 'sliderValue', 'disabled', 'handleImage', 'handleDisabled', 'values');
var $sliderOptions = array('axis', 'increment', 'maximum', 'minimum', 'alignX', 'alignY', 'sliderValue', 'disabled', 'handleImage', 'handleDisabled', 'values', 'onSlide', 'onChange');
/**
* Options for in-place editor.
*
* @var array
*/
var $editorOptions = array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'rows', 'cols', 'size', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'callback', 'ajaxOptions');
/**
* Returns link to remote action
@ -226,7 +233,7 @@ class AjaxHelper extends Helper
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}'," : "new Ajax.Request(";
$func .= "'" . $this->Html->url(isset($options['url']) ? $options['url'] : "") . "'";
$func .= "$javascript_options)";
$func .= ", $javascript_options)";
if (isset($options['before']))
{
@ -311,7 +318,7 @@ class AjaxHelper extends Helper
if(!isset($options['with']))
{
$options['with'] = 'Form.serialize(this)';
$options['with'] = "Form.serialize('{$htmlOptions['id']}')";
}
$options['url'] = $action;
@ -435,9 +442,9 @@ class AjaxHelper extends Helper
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => $options['class']);
return $this->Html->input($field, $htmlOptions) .
$this->Html->tag("div", $divOptions, true) . "</div>" .
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
$divOptions['id'] . "', '" . $this->Html->url($url) . "'" . $this->__optionsForAjax($options) . ");");
$this->Html->tag("div", $divOptions, true) . "</div>" .
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
$divOptions['id'] . "', '" . $this->Html->url($url) . "', " . $this->__optionsForAjax($options) . ");");
}
/**
@ -450,7 +457,7 @@ class AjaxHelper extends Helper
function drag($id, $options = array())
{
$options = $this->_optionsForDraggable($options);
return $this->Javascript->codeBlock("new Draggable('$id'$options);");
return $this->Javascript->codeBlock("new Draggable('$id', $options);");
}
/**
@ -476,7 +483,7 @@ class AjaxHelper extends Helper
function drop($id, $options = array())
{
$options = $this->_optionsForDroppable($options);
return $this->Javascript->codeBlock("Droppables.add('$id'$options);");
return $this->Javascript->codeBlock("Droppables.add('$id', $options);");
}
/**
@ -502,13 +509,12 @@ class AjaxHelper extends Helper
{
$options['onDrop'] = "function(element){" . $this->remoteFunction($ajaxOptions) . "}";
$options = $this->_optionsForDroppable($options);
return $this->Javascript->codeBlock("Droppables.add('$id'$options);");
return $this->Javascript->codeBlock("Droppables.add('$id', $options);");
}
/**
* Makes a slider control.
*
*
* @param string $id DOM ID of slider handle
* @param string $track_id DOM ID of slider track
* @param array $options Array of options to control the slider
@ -517,8 +523,47 @@ class AjaxHelper extends Helper
function slider($id, $track_id, $options = array())
{
$options = $this->_optionsToString($options, array('axis','handleImage','handleDisabled'));
if (isset($options['change']))
{
$options['onChange'] = $options['change'];
unset($options['change']);
}
if (isset($options['slide']))
{
$options['onSlide'] = $options['slide'];
unset($options['slide']);
}
$options = $this->_buildOptions($options, $this->sliderOptions);
return $this->Javascript->codeBlock("var $id = new Control.Slider('$id', '$track_id'$options);");
return $this->Javascript->codeBlock("var $id = new Control.Slider('$id', '$track_id', $options);");
}
/**
* Makes an Ajax In Place editor control.
*
* @param string $id DOM ID of input element
* @param string $url Postback URL of saved data
* @param array $options Array of options to control the editor, including ajaxOptions (see link).
* @link http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
*/
function editor($id, $url, $options = array())
{
$url = $this->Html->url($url);
$options['ajaxOptions'] = $this->__optionsForAjax($options);
foreach ($this->ajaxOptions as $opt)
{
if (isset($options[$opt]))
{
unset($options[$opt]);
}
}
if (isset($options['callback']))
{
$options['callback'] = 'function(form) {'.$options['callback'].'}';
}
$options = $this->_optionsToString($options, array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText'));
$options = $this->_buildOptions($options, $this->editorOptions);
return $this->Javascript->codeBlock("new Ajax.InPlaceEditor('{$id}', '{$url}', {$options});");
}
/**
@ -536,7 +581,7 @@ class AjaxHelper extends Helper
$options['onUpdate'] = 'function(sortable){' . $this->remoteFunction($options).'}';
}
$options = $this->__optionsForSortable($options);
return $this->Javascript->codeBlock("Sortable.create('$id'$options);");
return $this->Javascript->codeBlock("Sortable.create('$id', $options);");
}
/**
@ -558,8 +603,16 @@ class AjaxHelper extends Helper
function __optionsForAjax ($options = array())
{
$js_options = $this->_buildCallbacks($options);
$js_options['asynchronous'] = 'true';
$js_options['evalScripts'] = 'true';
if (!isset($js_options['asynchronous']))
{
$js_options['asynchronous'] = 'true';
}
if (!isset($js_options['evalScripts']))
{
$js_options['evalScripts'] = 'true';
}
$options = $this->_optionsToString($options, array('method'));
foreach($options as $key => $value)
@ -620,7 +673,7 @@ class AjaxHelper extends Helper
}
}
$out = join(', ', $out);
$out = ', {' . $out . '}';
$out = '{' . $out . '}';
return $out;
}
else

View file

@ -445,6 +445,11 @@ class HtmlHelper extends Helper
$htmlAttributes['value'] = $this->tagValue($fieldName);
}
if (!isset($htmlAttributes['type']))
{
$htmlAttributes['type'] = 'text';
}
if ($this->tagIsInvalid($this->model, $this->field))
{
$htmlAttributes['class'] = 'form_error';
@ -1240,7 +1245,7 @@ class HtmlHelper extends Helper
* @param boolean $show_empty Show/hide the empty select option
* @return string
*/
function dayOptionTag($tagName, $value=null, $selected=null, $optionAttr=null, $showEmpty = true)
function dayOptionTag($tagName, $value=null, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$value = isset($value)? $value : $this->tagValue($tagName."_day");
$dayValue = empty($selected) ? date('d') : $selected;
@ -1253,7 +1258,7 @@ class HtmlHelper extends Helper
'22'=>'22','23'=>'23','24'=>'24',
'25'=>'25','26'=>'26','27'=>'27',
'28'=>'28','29'=>'29','30'=>'30','31'=>'31');
$option = $this->selectTag($tagName.'_day', $days, $dayValue, null, $optionAttr, $showEmpty);
$option = $this->selectTag($tagName.'_day', $days, $dayValue, $select_attr, $optionAttr, $showEmpty);
return $option;
}
@ -1269,7 +1274,7 @@ class HtmlHelper extends Helper
* @param boolean $show_empty Show/hide the empty select option
* @return string
*/
function yearOptionTag($tagName, $value=null, $minYear=null, $maxYear=null, $selected=null, $optionAttr=null, $showEmpty = true)
function yearOptionTag($tagName, $value=null, $minYear=null, $maxYear=null, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$value = isset($value)? $value : $this->tagValue($tagName."_year");
@ -1294,7 +1299,7 @@ class HtmlHelper extends Helper
$years[$yearCounter] = $yearCounter;
}
$option = $this->selectTag($tagName.'_year', $years, $yearValue, null, $optionAttr, $showEmpty);
$option = $this->selectTag($tagName.'_year', $years, $yearValue, $select_attr, $optionAttr, $showEmpty);
return $option;
}
@ -1308,14 +1313,14 @@ class HtmlHelper extends Helper
* @param boolean $show_empty Show/hide the empty select option
* @return string
*/
function monthOptionTag($tagName, $value=null, $selected=null, $optionAttr=null, $showEmpty = true)
function monthOptionTag($tagName, $value=null, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$value = isset($value)? $value : $this->tagValue($tagName."_month");
$monthValue = empty($selected) ? date('m') : $selected ;
$months=array('01'=>'January','02'=>'February','03'=>'March',
'04'=>'April','05'=>'May','06'=>'June','07'=>'July','08'=>'August',
'09'=>'September','10'=>'October','11'=>'November','12'=>'December');
$option = $this->selectTag($tagName.'_month', $months, $monthValue, null, $optionAttr, $showEmpty);
$option = $this->selectTag($tagName.'_month', $months, $monthValue, $select_attr, $optionAttr, $showEmpty);
return $option;
}
@ -1329,7 +1334,7 @@ class HtmlHelper extends Helper
* @param array $optionAttr Attribute array for the option elements.
* @return string
*/
function hourOptionTag($tagName, $value=null, $format24Hours = false, $selected=null, $optionAttr=null )
function hourOptionTag($tagName, $value=null, $format24Hours = false, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true )
{
$value = isset($value)? $value : $this->tagValue($tagName."_hour");
if ( $format24Hours )
@ -1356,7 +1361,7 @@ class HtmlHelper extends Helper
'10'=>'10','11'=>'11','12'=>'12');
}
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue,
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue, $select_attr,
$optionAttr);
return $option;
}
@ -1370,7 +1375,7 @@ class HtmlHelper extends Helper
* @param array $optionAttr Attribute array for the option elements.
* @return string
*/
function minuteOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
function minuteOptionTag( $tagName, $value=null, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$value = isset($value)? $value : $this->tagValue($tagName."_min");
$minValue = empty($selected) ? date('i') : $selected ;
@ -1379,7 +1384,7 @@ class HtmlHelper extends Helper
$mins[$minCount] = sprintf('%02d', $minCount);
}
$option = $this->selectTag($tagName.'_min', $mins, $minValue,
$option = $this->selectTag($tagName.'_min', $mins, $minValue, $select_attr,
$optionAttr);
return $option;
}
@ -1393,13 +1398,13 @@ class HtmlHelper extends Helper
* @param array $optionAttr Attribute array for the option elements.
* @return string
*/
function meridianOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
function meridianOptionTag( $tagName, $value=null, $selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$value = isset($value)? $value : $this->tagValue($tagName."_meridian");
$merValue = empty($selected) ? date('a') : $selected ;
$meridians = array('am'=>'am','pm'=>'pm');
$option = $this->selectTag($tagName.'_meridian', $meridians, $merValue,
$option = $this->selectTag($tagName.'_meridian', $meridians, $merValue, $select_attr,
$optionAttr);
return $option;
}
@ -1414,7 +1419,7 @@ class HtmlHelper extends Helper
* @param array $optionAttr Attribute array for the option elements.
* @return string The HTML formatted OPTION element
*/
function dateTimeOptionTag( $tagName, $dateFormat = 'DMY', $timeFormat = '12',$selected=null, $optionAttr=null)
function dateTimeOptionTag( $tagName, $dateFormat = 'DMY', $timeFormat = '12',$selected=null, $select_attr=null, $optionAttr=null, $showEmpty = true)
{
$day = null;
$month = null;
@ -1458,13 +1463,13 @@ class HtmlHelper extends Helper
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, $select_attr, $optionAttr, $showEmpty) . '-' . $this->monthOptionTag( $tagName, null, $month, $select_attr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag( $tagName, null, null, null, $year, $select_attr, $optionAttr, $showEmpty);
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, $select_attr, $optionAttr, $showEmpty) .'-'.$this->dayOptionTag( $tagName, null, $day, $select_attr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $optionAttr, $select_attr, $showEmpty);
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, $select_attr, $optionAttr, $showEmpty) . '-' . $this->monthOptionTag( $tagName, null, $month, $select_attr, $optionAttr, $showEmpty) . '-' . $this->dayOptionTag( $tagName, null, $day, $optionAttr, $select_attr, $showEmpty);
break;
case 'NONE':
$opt ='';
@ -1476,10 +1481,10 @@ class HtmlHelper extends Helper
switch ($timeFormat)
{
case '24':
$opt .= $this->hourOptionTag( $tagName, null , true, $hour) . ':' . $this->minuteOptionTag( $tagName, null, $min );
$opt .= $this->hourOptionTag( $tagName, null , true, $hour, $select_attr, $optionAttr, $showEmpty) . ':' . $this->minuteOptionTag( $tagName, null, $min, $select_attr, $optionAttr, $showEmpty);
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, $select_attr, $optionAttr, $showEmpty) . ':' . $this->minuteOptionTag( $tagName, null, $min, $select_attr, $optionAttr, $showEmpty) . ' ' . $this->meridianOptionTag($tagName, null, $meridian, $select_attr, $optionAttr, $showEmpty);
break;
case 'NONE':
$opt .='';