The branch, master has been updated via 17cd1ebe2ba549b575f47f9a3bba512b8358ea7a (commit) from c3daf8bc52fde16549e5672061febfa1e03a4ae6 (commit)
- Log ----------------------------------------------------------------- commit 17cd1ebe2ba549b575f47f9a3bba512b8358ea7a Author: Michal Čihař mcihar@suse.cz Date: Mon Jul 25 12:11:17 2011 +0200
Use single function for bbcode implementation
-----------------------------------------------------------------------
Summary of changes: libraries/config/config_functions.lib.php | 30 +--------------------------- libraries/sanitizing.lib.php | 19 +++++++++++++---- 2 files changed, 16 insertions(+), 33 deletions(-)
diff --git a/libraries/config/config_functions.lib.php b/libraries/config/config_functions.lib.php index 31d4305..7b71748 100644 --- a/libraries/config/config_functions.lib.php +++ b/libraries/config/config_functions.lib.php @@ -17,35 +17,9 @@ */ function PMA_lang($lang_key) { - static $search, $replace; - - // some quick cache'ing - if ($search === null) { - $replace_pairs = array( - '<' => '<', - '>' => '>', - '[em]' => '<em>', - '[/em]' => '</em>', - '[strong]' => '<strong>', - '[/strong]' => '</strong>', - '[code]' => '<code>', - '[/code]' => '</code>', - '[kbd]' => '<kbd>', - '[/kbd]' => '</kbd>', - '[br]' => '<br />', - '[sup]' => '<sup>', - '[/sup]' => '</sup>'); - if (defined('PMA_SETUP')) { - $replace_pairs['[a@Documentation.html'] = '[a@../Documentation.html'; - } - $search = array_keys($replace_pairs); - $replace = array_values($replace_pairs); - } $message = isset($GLOBALS["strConfig$lang_key"]) ? $GLOBALS["strConfig$lang_key"] : $lang_key; - $message = str_replace($search, $replace, $message); - // replace [a@"$1"]$2[/a] with <a href="$1">$2</a> - $message = preg_replace('#[a@("?)([^]]+)\1]([^[]+)[/a]#e', - "PMA_lang_link_replace('$2', '$3')", $message); + + $message = PMA_sanitize($message);
if (func_num_args() == 1) { return $message; diff --git a/libraries/sanitizing.lib.php b/libraries/sanitizing.lib.php index b308f1c..d0d3ba8 100644 --- a/libraries/sanitizing.lib.php +++ b/libraries/sanitizing.lib.php @@ -50,15 +50,24 @@ function PMA_sanitize($message, $escape = false, $safe = false) '[sup]' => '<sup>', '[/sup]' => '</sup>', ); + if (defined('PMA_SETUP')) { + $replace_pairs['[a@Documentation.html'] = '[a@../Documentation.html'; + } else { + $replace_pairs['[a@Documentation.html'] = '[a@./Documentation.html'; + } $message = strtr($message, $replace_pairs);
- $pattern = '/[a@([^"@]*)@([^]"]*)]/'; + $pattern = '/[a@([^"@]*)(@([^]"]*))?]/';
if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER)) { $valid_links = array( 'http', // default http:// links (and https://) - './Do', // ./Documentation ); + if (defined('PMA_SETUP')) { + $valid_links[] = '../D'; // ./Documentation + } else { + $valid_links[] = './Do'; // ./Documentation + }
foreach ($founds as $found) { // only http... and ./Do... allowed @@ -66,15 +75,15 @@ function PMA_sanitize($message, $escape = false, $safe = false) return $message; } // a-z and _ allowed in target - if (! empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) { + if (! empty($found[3]) && preg_match('/[^a-z_]+/i', $found[3])) { return $message; } }
if (substr($found[1], 0, 4) == 'http') { - $message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\2">', $message); + $message = preg_replace($pattern, '<a href="' . PMA_linkURL($found[1]) . '" target="\3">', $message); } else { - $message = preg_replace($pattern, '<a href="\1" target="\2">', $message); + $message = preg_replace($pattern, '<a href="\1" target="\3">', $message); } }
hooks/post-receive