From 114a465a36540d5443d7dffd85ac452f62065705 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 18 Oct 2006 18:07:55 +0000 Subject: [PATCH] Adding fix for Ticket #1551 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3712 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/view/helper.php | 84 ++------------------------------- cake/libs/view/helpers/html.php | 20 ++++---- 2 files changed, 15 insertions(+), 89 deletions(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index db66e29b5..2a9aa6749 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -107,83 +107,7 @@ class Helper extends Object { * @return string Full translated URL with base path. */ function url($url = null, $full = false) { - if (isset($this->plugin)) { - $base = strip_plugin($this->base, $this->plugin); - } else { - $base = $this->base; - } - $extension = null; - - if (is_array($url) && !empty($url)) { - if (!isset($url['action'])) { - $url['action'] = $this->params['action']; - } - if (!isset($url['controller'])) { - $url['controller'] = $this->params['controller']; - } - if (!isset($url['plugin'])) { - $url['plugin'] = $this->plugin; - } - if (isset($url['ext'])) { - $extension = '.' . $url['ext']; - } - if (defined('CAKE_ADMIN') && !isset($url[CAKE_ADMIN]) && isset($this->params['admin'])) { - $url[CAKE_ADMIN] = $this->params['admin']; - } - - $named = $args = array(); - $keys = array_keys($url); - $count = count($keys); - for ($i = 0; $i < $count; $i++) { - if (is_numeric($keys[$i])) { - $args[] = $url[$keys[$i]]; - } else { - if (!in_array($keys[$i], array('action', 'controller', 'plugin', 'ext'))) { - $named[] = array($keys[$i], $url[$keys[$i]]); - } - } - } - - $combined = ''; - if ($this->namedArgs) { - if ($this->namedArgs === true) { - $sep = $this->argSeparator; - } elseif (is_array($this->namedArgs)) { - $sep = '/'; - } - - $count = count($named); - for ($i = 0; $i < $count; $i++) { - $named[$i] = join($this->argSeparator, $named[$i]); - } - if (defined('CAKE_ADMIN') && isset($named[CAKE_ADMIN])) { - unset($named[CAKE_ADMIN]); - } - $combined = join('/', $named); - } - - $urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $combined)); - if (defined('CAKE_ADMIN') && isset($url[CAKE_ADMIN]) && $url[CAKE_ADMIN]) { - array_unshift($urlOut, CAKE_ADMIN); - } - $output = $base . '/' . join('/', $urlOut); - } else { - if (((strpos($url, '://')) || (strpos($url, 'javascript:') === 0) || (strpos($url, 'mailto:') === 0)) || $url == '#') { - return $this->output($url); - } - - if (empty($url)) { - return $this->here; - } elseif($url{0} == '/') { - $output = $base . $url; - } else { - $output = $base . '/' . strtolower($this->params['controller']) . '/' . $url; - } - } - if ($full) { - $output = FULL_BASE_URL . $output; - } - return $this->output($output . $extension); + return Router::url($url, $full); } /** * Returns a space-delimited string with items of the $options array. If a @@ -343,7 +267,9 @@ class Helper extends Object { * @return array */ function __value($options = array(), $field = null, $key = 'value') { - if (is_string($options)) { + if ($options === null) { + $options = array(); + } elseif (is_string($options)) { $field = $options; $options = 0; } @@ -363,7 +289,7 @@ class Helper extends Object { $result = h($this->data[$this->model()][$this->field()]); } - if ($options !== 0 && is_array($options)) { + if (is_array($options)) { $options[$key] = $result; return $options; } else { diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index 8ed03a80f..9d1176b71 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -189,7 +189,7 @@ class HtmlHelper extends Helper { * @param boolean $escapeTitle Whether or not the text in the $title variable should be HTML escaped. * @return string An element. */ - function link($title, $url = null, $htmlAttributes = null, $confirmMessage = false, $escapeTitle = true) { + function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) { if ($escapeTitle) { $title = htmlspecialchars($title, ENT_QUOTES); } @@ -240,7 +240,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function submit($caption = 'Submit', $htmlAttributes = null) { + function submit($caption = 'Submit', $htmlAttributes = array()) { $htmlAttributes['value'] = $caption; return $this->output(sprintf($this->tags['submit'], $this->_parseAttributes($htmlAttributes, null, '', ' '))); } @@ -251,7 +251,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function password($fieldName, $htmlAttributes = null) { + function password($fieldName, $htmlAttributes = array()) { $htmlAttributes = $this->__value($htmlAttributes, $fieldName); $htmlAttributes = $this->domId($htmlAttributes); if ($this->tagIsInvalid()) { @@ -289,7 +289,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function checkbox($fieldName, $title = null, $htmlAttributes = null) { + function checkbox($fieldName, $title = null, $htmlAttributes = array()) { $value = $this->tagValue($fieldName); $notCheckedValue = 0; @@ -328,7 +328,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function file($fieldName, $htmlAttributes = null) { + function file($fieldName, $htmlAttributes = array()) { if (strpos($fieldName, '/')) { $this->setFormTag($fieldName); $htmlAttributes = $this->domId($htmlAttributes); @@ -377,7 +377,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function image($path, $htmlAttributes = null) { + function image($path, $htmlAttributes = array()) { if (strpos($path, '://')) { $url = $path; } else { @@ -396,7 +396,7 @@ class HtmlHelper extends Helper { * @param array $htmlAttributes Array of HTML attributes. * @return string */ - function input($fieldName, $htmlAttributes = null) { + function input($fieldName, $htmlAttributes = array()) { $htmlAttributes = $this->__value($htmlAttributes, $fieldName); $htmlAttributes = $this->domId($htmlAttributes); @@ -606,7 +606,7 @@ class HtmlHelper extends Helper { * @return string An formatted opening FORM tag. * @deprecated This is very WYSIWYG unfriendly, use HtmlHelper::url() to get contents of "action" attribute. Version 0.9.2. */ - function formTag($target = null, $type = 'post', $htmlAttributes = null) { + function formTag($target = null, $type = 'post', $htmlAttributes = array()) { $htmlAttributes['action'] = $this->url($target); $htmlAttributes['method'] = low($type) == 'get' ? 'get' : 'post'; $type == 'file' ? $htmlAttributes['enctype'] = 'multipart/form-data' : null; @@ -629,7 +629,7 @@ class HtmlHelper extends Helper { * @return string * @deprecated This seems useless. Version 0.9.2. */ - function guiListTree($data, $htmlAttributes = null, $bodyKey = 'body', $childrenKey = 'children') { + function guiListTree($data, $htmlAttributes = array(), $bodyKey = 'body', $childrenKey = 'children') { $out="_parseAttributes($htmlAttributes) . ">\n"; foreach($data as $item) { $out .= "
  • {$item[$bodyKey]}\n"; @@ -1009,4 +1009,4 @@ class HtmlHelper extends Helper { } } -?> +?> \ No newline at end of file