From ed28c3187b8fe0b5f5ec0de49d3cb5560558334a Mon Sep 17 00:00:00 2001 From: gwoo Date: Fri, 29 Dec 2006 04:16:53 +0000 Subject: [PATCH] adding router fix for array params, ticket #1824, removing ternary operator from HtmlHelper::link(); git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4228 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 37 ++++++--------------------------- cake/libs/view/helpers/html.php | 16 ++++++++++---- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index cef9fc72b..8ae4fd1b9 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -423,7 +423,7 @@ class Router extends Overloadable { for ($i = 0; $i < $count; $i++) { if (is_numeric($keys[$i]) || $keys[$i] == 'id') { $args[] = $url[$keys[$i]]; - } else if(!empty($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs']))){ + } else if(is_array($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs']))){ $named[] = array($keys[$i], $url[$keys[$i]]); } else if ($match === false) { $args[] = $keys[$i] . $path['argSeparator'] .$url[$keys[$i]]; @@ -435,17 +435,15 @@ class Router extends Overloadable { } } - $combined = ''; if (!empty($path['namedArgs'])) { $count = count($named); for ($i = 0; $i < $count; $i++) { $named[$i] = join($path['argSeparator'], $named[$i]); } - $combined = join('/', $named); + $named = join('/', $named); } - if ($match === false) { - $urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $combined)); + $urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $named)); if($url['plugin'] == $url['controller']) { array_shift($urlOut); } @@ -453,8 +451,8 @@ class Router extends Overloadable { array_unshift($urlOut, CAKE_ADMIN); } $output = join('/', $urlOut); - } elseif (!empty($combined)) { - $output .= $combined; + } else if (!empty($named)) { + $output .= $named; } $output = $base . '/' . $output; } else { @@ -491,12 +489,6 @@ class Router extends Overloadable { $defaults = am(array('controller'=> null, 'plugin' => null), $route[3]); $required = array_diff_key($defaults, $params); $url = am(array('controller'=> null,'action' => 'index', 'plugin' => null), $url); - // $url = am($required, $url); - /* foreach ($defaults as $key => $val) { - if (!is_numeric($key) && !isset($url[$key])) { - $url[$key] = $val; - } - }*/ ksort($defaults); ksort($url); if ($defaults == $url) { @@ -522,21 +514,6 @@ class Router extends Overloadable { } else { return false; } - - /*if (!empty($diffs)) { - if (isset($route[3]['controller']) && in_array('controller', $diffed)) { - return false; - } - if (isset($route[3]['action']) && in_array('action', $diffed)) { - return false; - } - }*/ - - //$required = array_diff(array_diff($route[2], array_keys($route[3])), array_keys($url)); - /*sort($required); - if (!empty($required)) { - return false; - }*/ if(!empty($route[4])){ foreach ($route[4] as $key => $reg) { if (isset($url[$key]) && !preg_match('/' . $reg . '/', $url[$key])) { @@ -544,8 +521,6 @@ class Router extends Overloadable { } } } - - //$out = str_replace(array('/bare', '/*', '/ajax'), '', $route[0]); return array(Router::__mapRoute($route, $url), $url); } /** @@ -567,7 +542,7 @@ class Router extends Overloadable { } else { $out = $route[0] . $params['pass']; } - + foreach ($route[2] as $key) { $out = str_replace(':' . $key, $params[$key], $out); unset($params[$key]); diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index e5fa5788b..5bc2de6ee 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -246,10 +246,18 @@ class HtmlHelper extends AppHelper { * @return string An element. */ function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) { - if ($escapeTitle) { - $title = htmlspecialchars($title, ENT_QUOTES); + if($url !== null) { + $url = $this->url($url); + } else { + $url = $this->url($title); + $title = $url; + $escapeTitle = false; + } + if($escapeTitle === true) { + $title = htmlspecialchars($title, ENT_QUOTES); + } else if (is_string($escapeTitle)) { + $title = htmlentities($title, $escapeTitle); } - $url = $url ? $url : $title; if ($confirmMessage) { $confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES); @@ -258,7 +266,7 @@ class HtmlHelper extends AppHelper { $htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');"; } - $output = sprintf($this->tags['link'], $this->url($url), $this->_parseAttributes($htmlAttributes), $title); + $output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title); return $this->output($output); } /**