Skip to content
Browse files

Permalinks: better behavior to release 1.3 - Ticket #309

  • Loading branch information...
1 parent 84799bc commit c3636a717111ffb0ce39964163c381d0ba231118 @nmpetkov committed Mar 27, 2012
Showing with 23 additions and 1 deletion.
  1. +23 −1 src/lib/util/DataUtil.php
View
24 src/lib/util/DataUtil.php
@@ -469,20 +469,42 @@ public static function formatPermalink($var)
$permasearch = explode(',', System::getVar('permasearch'));
$permareplace = explode(',', System::getVar('permareplace'));
foreach ($permasearch as $key => $value) {
- $var = mb_ereg_replace("[$value]", $permareplace[$key], $var);
+ $var = mb_ereg_replace($value, $permareplace[$key], $var);
}
$var = preg_replace("#(\s*\/\s*|\s*\+\s*|\s+)#", '-', strtolower($var));
// final clean
$permalinksseparator = System::getVar('shorturlsseparator');
$var = mb_ereg_replace("[^a-z0-9_{$permalinksseparator}]", '', $var, "imsr");
+ $var = preg_replace('/'.$permalinksseparator.'+/', $permalinksseparator, $var); // remove replicated separator
$var = trim($var, $permalinksseparator);
return $var;
}
/**
+ * Transliterate a variable.
+ *
+ * @param string $var The variable to format.
+ *
+ * @return string The formatted variable.
+ */
+ public static function formatTransliterate($var)
+ {
+ $strIsUpper = (strcmp($var, mb_strtoupper($var)) == 0);
+ // replace all chars $permasearch with the one in $permareplace
+ $permasearch = explode(',', System::getVar('permasearch'));
+ $permareplace = explode(',', System::getVar('permareplace'));
+ foreach ($permasearch as $key => $value) {
+ $var = mb_ereg_replace($value, $permareplace[$key], $var);
+ }
+ if ($strIsUpper) $var = mb_strtoupper($var);
+
+ return $var;
+ }
+
+ /**
* Censor variable contents. This method is recursive array safe.
*
* @param string $var The variable to censor.

0 comments on commit c3636a7

Please sign in to comment.
Something went wrong with that request. Please try again.