diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index c0fb15898..b09f27b46 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -380,7 +380,7 @@ class SecurityComponent extends Object { * @access private */ function __requireMethod($method, $actions = array()) { - $this->{'require' . $method} = ife(empty($actions), array('*'), $actions); + $this->{'require' . $method} = (empty($actions)) ? array('*'): $actions; } /** * Check if HTTP methods are required diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 5889a2975..d352c269e 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -505,53 +505,58 @@ class Controller extends Object { if (!empty($status)) { $codes = array( - 100 => "Continue", - 101 => "Switching Protocols", - 200 => "OK", - 201 => "Created", - 202 => "Accepted", - 203 => "Non-Authoritative Information", - 204 => "No Content", - 205 => "Reset Content", - 206 => "Partial Content", - 300 => "Multiple Choices", - 301 => "Moved Permanently", - 302 => "Found", - 303 => "See Other", - 304 => "Not Modified", - 305 => "Use Proxy", - 307 => "Temporary Redirect", - 400 => "Bad Request", - 401 => "Unauthorized", - 402 => "Payment Required", - 403 => "Forbidden", - 404 => "Not Found", - 405 => "Method Not Allowed", - 406 => "Not Acceptable", - 407 => "Proxy Authentication Required", - 408 => "Request Time-out", - 409 => "Conflict", - 410 => "Gone", - 411 => "Length Required", - 412 => "Precondition Failed", - 413 => "Request Entity Too Large", - 414 => "Request-URI Too Large", - 415 => "Unsupported Media Type", - 416 => "Requested range not satisfiable", - 417 => "Expectation Failed", - 500 => "Internal Server Error", - 501 => "Not Implemented", - 502 => "Bad Gateway", - 503 => "Service Unavailable", - 504 => "Gateway Time-out" + 100 => 'Continue', + 101 => 'Switching Protocols', + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + 307 => 'Temporary Redirect', + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Time-out', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Large', + 415 => 'Unsupported Media Type', + 416 => 'Requested range not satisfiable', + 417 => 'Expectation Failed', + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Time-out' ); if (is_string($status)) { $codes = array_combine(array_values($codes), array_keys($codes)); } if (isset($codes[$status])) { - $code = ife(is_numeric($status), $status, $codes[$status]); - $msg = ife(is_string($status), $status, $codes[$status]); + $code = $status = $codes[$status]; + if (is_numeric($status)) { + $code = $status; + } + if (is_string($status)) { + $msg = $status; + } $status = "HTTP/1.1 {$code} {$msg}"; } else { $status = null; diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index e506ce0b8..88b6630bc 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -349,7 +349,7 @@ class Debugger extends Object { $_this = Debugger::getInstance(); switch(strtolower(gettype($var))) { case 'boolean': - return ife($var, 'true', 'false'); + return ($var) ? 'true' : 'false'; break; case 'integer': case 'double': diff --git a/cake/libs/folder.php b/cake/libs/folder.php index f5d9ecea9..c84a9282c 100644 --- a/cake/libs/folder.php +++ b/cake/libs/folder.php @@ -741,7 +741,10 @@ class Folder extends Object{ } $parts = explode(DS, $path); $newparts = array(); - $newpath = ife($path[0] == DS, DS, ''); + $newpath = ''; + if ($path[0] == DS) { + $newpath = DS; + } while (($part = array_shift($parts)) !== NULL) { if ($part == '.' || $part == '') { diff --git a/cake/libs/model/behaviors/containable.php b/cake/libs/model/behaviors/containable.php index 3fb520cc1..87fbe2e71 100644 --- a/cake/libs/model/behaviors/containable.php +++ b/cake/libs/model/behaviors/containable.php @@ -70,7 +70,10 @@ class ContainableBehavior extends ModelBehavior { if (!isset($this->settings[$Model->alias])) { $this->settings[$Model->alias] = array('recursive' => true, 'notices' => true, 'autoFields' => true); } - $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], ife(is_array($settings), $settings, array())); + if (!is_array($settings)) { + $settings = array(); + } + $this->settings[$Model->alias] = array_merge($this->settings[$Model->alias], $settings); } /** * Runs before a find() operation. Used to allow 'contain' setting diff --git a/cake/libs/model/behaviors/translate.php b/cake/libs/model/behaviors/translate.php index 4fc8f3119..f88426159 100644 --- a/cake/libs/model/behaviors/translate.php +++ b/cake/libs/model/behaviors/translate.php @@ -121,7 +121,7 @@ class TranslateBehavior extends ModelBehavior { $addFields = array(); if (is_array($query['fields'])) { foreach ($fields as $key => $value) { - $field = ife(is_numeric($key), $value, $key); + $field = (is_numeric($key)) ? $value : $key; if (in_array($model->alias.'.*', $query['fields']) || $autoFields || in_array($model->alias.'.'.$field, $query['fields']) || in_array($field, $query['fields'])) { $addFields[] = $field; @@ -194,7 +194,7 @@ class TranslateBehavior extends ModelBehavior { $beforeFind = $this->runtime[$model->alias]['beforeFind']; foreach ($results as $key => $row) { - $results[$key][$model->alias]['locale'] = ife(is_array($locale), @$locale[0], $locale); + $results[$key][$model->alias]['locale'] = (is_array($locale)) ? @$locale[0] : $locale; foreach ($beforeFind as $field) { if (is_array($locale)) { @@ -209,7 +209,10 @@ class TranslateBehavior extends ModelBehavior { $results[$key][$model->alias][$field] = ''; } } else { - $value = ife(empty($results[$key]['I18n__'.$field]['content']), '', $results[$key]['I18n__'.$field]['content']); + $value = ''; + if (!empty($results[$key]['I18n__'.$field]['content'])) { + $value = $results[$key]['I18n__'.$field]['content']; + } $results[$key][$model->alias][$field] = $value; unset($results[$key]['I18n__'.$field]); } @@ -229,7 +232,7 @@ class TranslateBehavior extends ModelBehavior { $tempData = array(); foreach ($fields as $key => $value) { - $field = ife(is_numeric($key), $value, $key); + $field = (is_numeric($key)) ? $value : $key; if (isset($model->data[$model->alias][$field])) { $tempData[$field] = $model->data[$model->alias][$field]; diff --git a/cake/libs/model/behaviors/tree.php b/cake/libs/model/behaviors/tree.php index 8cf3799c8..68048197b 100644 --- a/cake/libs/model/behaviors/tree.php +++ b/cake/libs/model/behaviors/tree.php @@ -886,7 +886,7 @@ class TreeBehavior extends ModelBehavior { 'fields' => $db->calculate($model, 'max', array($right)), 'recursive' => $recursive ))); - return ife(empty ($edge[$right]), 0, $edge[$right]); + return (empty($edge[$right])) ? 0 : $edge[$right]; } /** * get the minimum index value in the table. @@ -904,7 +904,7 @@ class TreeBehavior extends ModelBehavior { 'fields' => $db->calculate($model, 'min', array($left)), 'recursive' => $recursive ))); - return ife(empty($edge[$left]), 0, $edge[$left]); + return (empty($edge[$left])) ? 0 : $edge[$left]; } /** * Table sync method. diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index b871bd669..3fb26e31e 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -514,7 +514,7 @@ class DboMysql extends DboSource { foreach ($keys as $i => $key) { if(!isset($index[$key['Key_name']])) { $index[$key['Key_name']]['column'] = $key['Column_name']; - $index[$key['Key_name']]['unique'] = ife($key['Non_unique'] == 0, 1, 0); + $index[$key['Key_name']]['unique'] = intval($key['Non_unique'] == 0); } else { if(!is_array($index[$key['Key_name']]['column'])) { $col[] = $index[$key['Key_name']]['column']; diff --git a/cake/libs/model/datasources/dbo/dbo_oracle.php b/cake/libs/model/datasources/dbo/dbo_oracle.php index 9c9ab262b..1338b5767 100644 --- a/cake/libs/model/datasources/dbo/dbo_oracle.php +++ b/cake/libs/model/datasources/dbo/dbo_oracle.php @@ -343,7 +343,7 @@ class DboOracle extends DboSource { $this->_setError($this->_statementId); return false; } - + $this->_setError(null, true); switch(ocistatementtype($this->_statementId)) { @@ -395,7 +395,7 @@ class DboOracle extends DboSource { $this->_currentRow++; return $resultRow; } - + function fetchResult() { return $this->fetchRow(); } @@ -473,7 +473,7 @@ class DboOracle extends DboSource { $this->_sequenceMap[$model->table] = $model->sequence; } elseif (!empty($model->table)) { $this->_sequenceMap[$model->table] = $model->table . '_seq'; - } + } $cache = parent::describe($model); @@ -650,7 +650,7 @@ class DboOracle extends DboSource { } if(!isset($index[$key])) { $index[$key]['column'] = strtolower($idx['cc']['column_name']); - $index[$key]['unique'] = ife($idx['i']['uniqueness'] == 'UNIQUE', 1, 0); + $index[$key]['unique'] = intval($idx['i']['uniqueness'] == 'UNIQUE'); } else { if(!is_array($index[$key]['column'])) { $col[] = $index[$key]['column']; diff --git a/cake/libs/multibyte.php b/cake/libs/multibyte.php index 324b8b97a..17235a05f 100644 --- a/cake/libs/multibyte.php +++ b/cake/libs/multibyte.php @@ -292,7 +292,7 @@ class Multibyte extends Object { } else { if (count($values) == 0) { - $find = ife($value < 224, 2, 3); + $find = ($value < 224) ? 2 : 3; } $values[] = $value; @@ -639,8 +639,7 @@ class Multibyte extends Object { } $position++; } - $return = ife($found, $position, false); - return $return; + return ($found) ? $position : false; } return strripos($haystack, $needle, $offset); } @@ -689,8 +688,7 @@ class Multibyte extends Object { } $position++; } - $return = ife($found, $position, false); - return $return; + return ($found) ? $position : false; } return strrpos($haystack, $needle, $offset); } diff --git a/cake/libs/router.php b/cake/libs/router.php index 5252d866e..017cc8f51 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -298,10 +298,11 @@ class Router extends Object { foreach ($_this->__resourceMap as $params) { extract($params); - $id = ife($id, '/:id', ''); - - Router::connect( - "{$prefix}{$urlName}{$id}", + $url = $prefix . $urlName; + if ($id) { + $url .= '/:id'; + } + Router::connect($url, array('controller' => $urlName, 'action' => $action, '[method]' => $params['method']), array('id' => $options['id'], 'pass' => array('id')) ); diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index bce1ca9c3..b5488d826 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -297,7 +297,10 @@ class Helper extends Overloadable { $attribute = sprintf($attributeFormat, $key, $key); } } else { - $attribute = sprintf($attributeFormat, $key, ife($escape, h($value), $value)); + if ($escape) { + $value = htmlspecialchars($value); + } + $attribute = sprintf($attributeFormat, $key, $value); } return $attribute; } diff --git a/cake/libs/view/helpers/ajax.php b/cake/libs/view/helpers/ajax.php index 2e9ec2613..e5c3b38ab 100644 --- a/cake/libs/view/helpers/ajax.php +++ b/cake/libs/view/helpers/ajax.php @@ -682,10 +682,10 @@ class AjaxHelper extends AppHelper { foreach ($options as $key => $value) { switch($key) { case 'type': - $jsOptions['asynchronous'] = ife(($value == 'synchronous'), 'false', 'true'); + $jsOptions['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true'; break; case 'evalScripts': - $jsOptions['evalScripts'] = ife($value, 'true', 'false'); + $jsOptions['evalScripts'] = ($value) ? 'true' : 'false'; break; case 'position': $jsOptions['insertion'] = "Insertion." . Inflector::camelize($options['position']); diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 9e30e8e77..e701ecff3 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -171,7 +171,7 @@ class FormHelper extends AppHelper { } } if (empty($options['action'])) { - $options['action'] = ife($created, 'edit', 'add'); + $options['action'] = ($created) ? 'edit' : 'add'; } $actionDefaults = array( @@ -195,7 +195,7 @@ class FormHelper extends AppHelper { break; case 'file': $htmlAttributes['enctype'] = 'multipart/form-data'; - $options['type'] = ife($created, 'put', 'post'); + $options['type'] = ($created) ? 'put' : 'post'; case 'post': case 'put': case 'delete': @@ -1579,7 +1579,9 @@ class FormHelper extends AppHelper { } if ($showParents || (!in_array($title, $parents))) { - $title = ife($attributes['escape'], h($title), $title); + if ($attributes['escape']) { + $title = htmlspecialchars($title); + } if ($attributes['style'] === 'checkbox') { $htmlOptions['value'] = $name; diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index e82e92b73..a7b9e559e 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -196,8 +196,10 @@ class JavascriptHelper extends AppHelper { if ($options['inline']) { if ($block) { return sprintf($this->tags['javascriptblock'], $script); + } elseif ($safe) { + return $this->tags['javascriptstart'] . "\n" . '//tags['javascriptstart']).ife($safe, "\n" . '//tags['javascriptstart']; } } elseif ($block) { $view =& ClassRegistry::getObject('view'); @@ -230,7 +232,10 @@ class JavascriptHelper extends AppHelper { $this->_cachedEvents[] = $script; return null; } - return ife($safe, "\n" . '//]]>' . "\n", '').$this->tags['javascriptend']; + if ($safe) { + return "\n" . '//]]>' . "\n" . $this->tags['javascriptend']; + } + return $this->tags['javascriptend']; } /** * Returns a JavaScript include tag (SCRIPT element). If the filename is prefixed with "/", @@ -549,7 +554,7 @@ class JavascriptHelper extends AppHelper { $val = 'null'; break; case (is_bool($val)): - $val = ife($val, 'true', 'false'); + $val = ($val) ? 'true' : 'false'; break; case (is_int($val)): $val = $val; diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index dd573c8f6..ac208d84f 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -408,10 +408,17 @@ class PaginatorHelper extends AppHelper { $options); $paging = $this->params($options['model']); - $paging['pageCount'] = ife($paging['pageCount'] == 0, 1, $paging['pageCount']); - - $start = ife($paging['count'] >= 1, ($paging['page'] - 1) * ($paging['options']['limit']) + 1, '0'); - $end = ife(($paging['count'] < ($start + $paging['options']['limit'] - 1)), $paging['count'], ($start + $paging['options']['limit'] - 1)); + if ($paging['pageCount'] == 0) { + $paging['pageCount'] = 1; + } + $start = 0; + if ($paging['count'] >= 1) { + $start = (($paging['page'] - 1) * $paging['options']['limit']) + 1; + } + $end = $start + $paging['options']['limit'] - 1; + if ($paging['count'] < $end) { + $end = $paging['count']; + } switch ($options['format']) { case 'range': diff --git a/cake/libs/view/helpers/text.php b/cake/libs/view/helpers/text.php index 44fd1abed..450768042 100644 --- a/cake/libs/view/helpers/text.php +++ b/cake/libs/view/helpers/text.php @@ -77,14 +77,14 @@ class TextHelper extends AppHelper { $replace[] = '|' . $key . '|iu'; $with[] = empty($value) ? $highlighter : $value; } - + return preg_replace($replace, $with, $text); } else { $phrase = '(' . $phrase . ')'; if ($considerHtml) { $phrase = '(?![^<]+>)' . $phrase . '(?![^<]+>)'; } - + return preg_replace('|'.$phrase.'|iu', $highlighter, $text); } } @@ -178,7 +178,7 @@ class TextHelper extends AppHelper { preg_match_all('/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER); foreach ($tags as $tag) { if (preg_match('/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2])) { - + } else if (preg_match('/<[\w]+[^>]*>/s', $tag[0])) { array_unshift($openTags, $tag[2]); } else if (preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag)) { @@ -202,7 +202,7 @@ class TextHelper extends AppHelper { break; } } - } + } $truncate .= substr($tag[3], 0 , $left + $entitiesLength); break; @@ -236,13 +236,13 @@ class TextHelper extends AppHelper { } } } - $truncate = substr($truncate, 0, $spacepos); + $truncate = substr($truncate, 0, $spacepos); } } $truncate .= $ending; - - if ($considerHtml) { + + if ($considerHtml) { foreach ($openTags as $tag) { $truncate .= ''; } @@ -275,21 +275,29 @@ class TextHelper extends AppHelper { return $this->truncate($text, $radius * 2, $ending); } - if ($radius < strlen($phrase)) { - $radius = strlen($phrase); + $phraseLen = strlen($phrase); + if ($radius < $phraseLen) { + $radius = $phraseLen; } $pos = strpos(strtolower($text), strtolower($phrase)); - $startPos = ife($pos <= $radius, 0, $pos - $radius); - $endPos = ife($pos + strlen($phrase) + $radius >= strlen($text), strlen($text), $pos + strlen($phrase) + $radius); + $startPos = 0; + if ($pos > $radius) { + $startPos = $pos - $radius; + } + $textLen = strlen($text); + $endPos = $pos + $phraseLen + $radius; + if ($endPos >= $textLen) { + $endPos = $textLen; + } $excerpt = substr($text, $startPos, $endPos - $startPos); if ($startPos != 0) { - $excerpt = substr_replace($excerpt, $ending, 0, strlen($phrase)); + $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); } - if ($endPos != strlen($text)) { - $excerpt = substr_replace($excerpt, $ending, -strlen($phrase)); + if ($endPos != $textLen) { + $excerpt = substr_replace($excerpt, $ending, -$phraseLen); } return $excerpt; diff --git a/cake/libs/view/helpers/time.php b/cake/libs/view/helpers/time.php index f50d608fb..6cddb0fcb 100644 --- a/cake/libs/view/helpers/time.php +++ b/cake/libs/view/helpers/time.php @@ -91,7 +91,7 @@ class TimeHelper extends AppHelper { $date = time(); } - $ret = date("D, M jS Y, H:i", $date); + $ret = i18n::strftime('%A, %B %e %Y, H:i', $date); return $this->output($ret); } /** diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 4c27edb80..55100c37b 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -557,10 +557,8 @@ class View extends Object { * @return array An array containing the identity elements of an entity */ function entity() { - return array_values(Set::filter(array( - ife($this->association, $this->association, $this->model), - $this->modelId, $this->field, $this->fieldSuffix - ))); + $assoc = ($this->association) ? $this->association : $this->model; + return array_values(Set::filter(array($assoc, $this->modelId, $this->field, $this->fieldSuffix))); } /** * Allows a template or element to set a variable that will be available in