2 /* vim: set expandtab sw=4 ts=4 sts=4: */
9 * Sanitizes $message, taking into account our special codes
12 * If you want to include result in element attribute, you should escape it.
16 * <p><?php echo PMA_sanitize($foo); ?></p>
18 * <a title="<?php echo PMA_sanitize($foo, true); ?>">bar</a>
20 * @uses preg_replace()
22 * @param string the message
23 * @param boolean whether to escape html in result
25 * @return string the sanitized message
29 function PMA_sanitize($message, $escape = false)
31 $replace_pairs = array(
34 '[i]' => '<em>', // deprecated by em
35 '[/i]' => '</em>', // deprecated by em
38 '[b]' => '<strong>', // deprecated by strong
39 '[/b]' => '</strong>', // deprecated by strong
40 '[strong]' => '<strong>',
41 '[/strong]' => '</strong>',
42 '[tt]' => '<code>', // deprecated by CODE or KBD
43 '[/tt]' => '</code>', // deprecated by CODE or KBD
45 '[/code]' => '</code>',
53 $message = strtr($message, $replace_pairs);
55 $pattern = '/\[a@([^"@]*)@([^]"]*)\]/';
57 if (preg_match_all($pattern, $message, $founds, PREG_SET_ORDER
)) {
59 'http', // default http:// links (and https://)
60 './Do', // ./Documentation
63 foreach ($founds as $found) {
64 // only http... and ./Do... allowed
65 if (! in_array(substr($found[1], 0, 4), $valid_links)) {
68 // a-z and _ allowed in target
69 if (! empty($found[2]) && preg_match('/[^a-z_]+/i', $found[2])) {
74 $message = preg_replace($pattern, '<a href="\1" target="\2">', $message);
78 $message = htmlspecialchars($message);