mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
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
This commit is contained in:
parent
8b79b227cc
commit
ed28c3187b
2 changed files with 18 additions and 35 deletions
|
@ -423,7 +423,7 @@ class Router extends Overloadable {
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (is_numeric($keys[$i]) || $keys[$i] == 'id') {
|
if (is_numeric($keys[$i]) || $keys[$i] == 'id') {
|
||||||
$args[] = $url[$keys[$i]];
|
$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]]);
|
$named[] = array($keys[$i], $url[$keys[$i]]);
|
||||||
} else if ($match === false) {
|
} else if ($match === false) {
|
||||||
$args[] = $keys[$i] . $path['argSeparator'] .$url[$keys[$i]];
|
$args[] = $keys[$i] . $path['argSeparator'] .$url[$keys[$i]];
|
||||||
|
@ -435,17 +435,15 @@ class Router extends Overloadable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$combined = '';
|
|
||||||
if (!empty($path['namedArgs'])) {
|
if (!empty($path['namedArgs'])) {
|
||||||
$count = count($named);
|
$count = count($named);
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$named[$i] = join($path['argSeparator'], $named[$i]);
|
$named[$i] = join($path['argSeparator'], $named[$i]);
|
||||||
}
|
}
|
||||||
$combined = join('/', $named);
|
$named = join('/', $named);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($match === false) {
|
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']) {
|
if($url['plugin'] == $url['controller']) {
|
||||||
array_shift($urlOut);
|
array_shift($urlOut);
|
||||||
}
|
}
|
||||||
|
@ -453,8 +451,8 @@ class Router extends Overloadable {
|
||||||
array_unshift($urlOut, CAKE_ADMIN);
|
array_unshift($urlOut, CAKE_ADMIN);
|
||||||
}
|
}
|
||||||
$output = join('/', $urlOut);
|
$output = join('/', $urlOut);
|
||||||
} elseif (!empty($combined)) {
|
} else if (!empty($named)) {
|
||||||
$output .= $combined;
|
$output .= $named;
|
||||||
}
|
}
|
||||||
$output = $base . '/' . $output;
|
$output = $base . '/' . $output;
|
||||||
} else {
|
} else {
|
||||||
|
@ -491,12 +489,6 @@ class Router extends Overloadable {
|
||||||
$defaults = am(array('controller'=> null, 'plugin' => null), $route[3]);
|
$defaults = am(array('controller'=> null, 'plugin' => null), $route[3]);
|
||||||
$required = array_diff_key($defaults, $params);
|
$required = array_diff_key($defaults, $params);
|
||||||
$url = am(array('controller'=> null,'action' => 'index', 'plugin' => null), $url);
|
$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($defaults);
|
||||||
ksort($url);
|
ksort($url);
|
||||||
if ($defaults == $url) {
|
if ($defaults == $url) {
|
||||||
|
@ -522,21 +514,6 @@ class Router extends Overloadable {
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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])){
|
if(!empty($route[4])){
|
||||||
foreach ($route[4] as $key => $reg) {
|
foreach ($route[4] as $key => $reg) {
|
||||||
if (isset($url[$key]) && !preg_match('/' . $reg . '/', $url[$key])) {
|
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);
|
return array(Router::__mapRoute($route, $url), $url);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -246,10 +246,18 @@ class HtmlHelper extends AppHelper {
|
||||||
* @return string An <a /> element.
|
* @return string An <a /> element.
|
||||||
*/
|
*/
|
||||||
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
|
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
|
||||||
if ($escapeTitle) {
|
if($url !== null) {
|
||||||
$title = htmlspecialchars($title, ENT_QUOTES);
|
$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) {
|
if ($confirmMessage) {
|
||||||
$confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES);
|
$confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES);
|
||||||
|
@ -258,7 +266,7 @@ class HtmlHelper extends AppHelper {
|
||||||
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
|
$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);
|
return $this->output($output);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue