Skip to content

Commit

Permalink
Merge pull request #44 from NetCommons3/bugfix
Browse files Browse the repository at this point in the history
Update Nc2ToNc3PageBaseBehavior.php
  • Loading branch information
akagane99 committed Dec 14, 2018
2 parents c6a7763 + a3d60fe commit ded973e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Model/Behavior/Nc2ToNc3PageBaseBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ protected function _convertPermalink($nc2Permalink) {
$url = '/' . $nc2Permalink;
$route = $this->__CakeRouter->parse($url);
if (!$route['pass']) {
$nc2Permalink = $this->__replacePermalink($nc2Permalink);
return $nc2Permalink;
}

Expand All @@ -139,7 +140,32 @@ protected function _convertPermalink($nc2Permalink) {
unset($route['pass'][0]);
}

return implode('/', $route['pass']);
$permalink = implode('/', $route['pass']);
$permalink = $this->__replacePermalink($permalink);
return $permalink;
}

/**
* Replace Converted permalink.
*
* @param string $permalink Converted Nc2Page permalink.
* @return string Replaced permalink.
* @see https://github.com/NetCommons3/Pages/blob/master/Model/Page.php#L235-L270
* @see https://github.com/NetCommons3/Pages/blob/master/Model/Page.php#L300-L311
*/
private function __replacePermalink($permalink) {
// 半角を全角に置換
// 置換の羅列のため、phpcs除外
// @codingStandardsIgnoreStart
$search = ['%', ' ', '#', '<', '>', '+', '\\', '"', "'", '&', '?', '=', '~', ':', ';', ',', '$', '@', './', '/.', '|', ']', '[', '!', '(', ')', '*'];
$replace = ['%', ' ', '#', '<', '>', '+', '¥¥', '”', '’', '&', '?', '=', '~', ':', ';', ',', '$', '@', './', '/.', '|', ']', '[', '!', '(', ')', '*'];
// @codingStandardsIgnoreEnd
$permalink = str_replace($search, $replace, $permalink);

// 「^/(最初にスラッシュ)」「/$(最後にスラッシュ)」「.$(最後にドット)」「^.(最初にドット)」は取り除く
// @see https://regexper.com/#%2F%28%5E%5C%2F%7C%5C%2F%24%7C%5C.%24%7C%5E%5C.%29%2F
$pattern = '/(^\/|\/$|\.$|^\.)/';
return preg_replace($pattern, '', $permalink);
}

/**
Expand Down

0 comments on commit ded973e

Please sign in to comment.