Zeile 6 | Zeile 6 |
---|
* Website: http://www.mybboard.net * License: http://www.mybboard.net/about/license *
|
* Website: http://www.mybboard.net * License: http://www.mybboard.net/about/license *
|
* $Id: class_parser.php 4322 2009-02-21 23:00:49Z Tikitiki $
| * $Id: class_parser.php 5379 2011-02-21 11:06:42Z Tomm $
|
*/
/*
| */
/*
|
Zeile 18 | Zeile 18 |
---|
filter_badwords me_username shorten_urls
|
filter_badwords me_username shorten_urls
|
| highlight
|
) */
| ) */
|
Zeile 50 | Zeile 51 |
---|
* @var string */ var $base_url;
|
* @var string */ var $base_url;
|
| /** * Parsed Highlights cache * * @access private * @var array */ var $highlight_cache = array();
|
/** * Options for this parsed message (Private - set by parse_message argument)
| /** * Options for this parsed message (Private - set by parse_message argument)
|
Zeile 58 | Zeile 67 |
---|
* @var array */ var $options;
|
* @var array */ var $options;
|
|
|
/** * Parses a message with the specified options. *
| /** * Parses a message with the specified options. *
|
Zeile 78 | Zeile 87 |
---|
if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/") { $this->base_url = $this->base_url."/";
|
if(my_substr($this->base_url, my_strlen($this->base_url) -1) != "/") { $this->base_url = $this->base_url."/";
|
} }
| } }
|
// Set the options $this->options = $options;
|
// Set the options $this->options = $options;
|
$message = $plugins->run_hooks("parse_message_start", $message);
| $message = $plugins->run_hooks("parse_message_start", $message);
|
// Get rid of cartridge returns for they are the workings of the devil $message = str_replace("\r", "", $message);
| // Get rid of cartridge returns for they are the workings of the devil $message = str_replace("\r", "", $message);
|
Zeile 93 | Zeile 102 |
---|
if($options['filter_badwords']) { $message = $this->parse_badwords($message);
|
if($options['filter_badwords']) { $message = $this->parse_badwords($message);
|
}
| }
|
if($options['allow_html'] != 1) {
| if($options['allow_html'] != 1) {
|
Zeile 105 | Zeile 114 |
---|
{ $message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "<script$1>$2</script$3>", $message); }
|
{ $message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "<script$1>$2</script$3>", $message); }
|
// Remove these completely $message = preg_replace("#\s*<base[^>]*>\s*#is", "", $message); $message = preg_replace("#\s*<meta[^>]*>\s*#is", "", $message);
|
|
$message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('<?php', '<!--', '-->', '?>', "\n", "\n"), $message);
|
$message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('<?php', '<!--', '-->', '?>', "\n", "\n"), $message);
|
}
| }
|
// If MyCode needs to be replaced, first filter out [code] and [php] tags. if($options['allow_mycode']) {
|
// If MyCode needs to be replaced, first filter out [code] and [php] tags. if($options['allow_mycode']) {
|
// First we split up the contents of code and php tags to ensure they're not parsed.
| |
preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER); $message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "<mybb-code>\n", $message); }
| preg_match_all("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", $message, $code_matches, PREG_SET_ORDER); $message = preg_replace("#\[(code|php)\](.*?)\[/\\1\](\r\n?|\n?)#si", "<mybb-code>\n", $message); }
|
Zeile 138 | Zeile 144 |
---|
}
// Replace MyCode if requested.
|
}
// Replace MyCode if requested.
|
if($options['allow_mycode']) {
| if($options['allow_mycode']) {
|
$message = $this->parse_mycode($message, $options);
|
$message = $this->parse_mycode($message, $options);
|
| } // Parse Highlights if($options['highlight']) { $message = $this->highlight_message($message, $options['highlight']);
|
}
// Run plugin hooks
| }
// Run plugin hooks
|
Zeile 153 | Zeile 165 |
---|
{ foreach($code_matches as $text) {
|
{ foreach($code_matches as $text) {
|
// Fix up HTML inside the code tags so it is clean if($options['allow_html'] != 0) { $text[2] = $this->parse_html($text[2]); }
| |
if(my_strtolower($text[1]) == "code")
|
if(my_strtolower($text[1]) == "code")
|
{
| {
|
$code = $this->mycode_parse_code($text[2]); } elseif(my_strtolower($text[1]) == "php")
| $code = $this->mycode_parse_code($text[2]); } elseif(my_strtolower($text[1]) == "php")
|
Zeile 170 | Zeile 176 |
---|
$message = preg_replace("#\<mybb-code>\n?#", $code, $message, 1); } }
|
$message = preg_replace("#\<mybb-code>\n?#", $code, $message, 1); } }
|
| }
// Replace meta and base tags in our post - these are > dangerous < if($this->options['allow_html']) { $message = preg_replace_callback("#<((m[^a])|(b[^diloru>])|(s[^aemptu>]))(\s*[^>]*)>#si", create_function( '$matches', 'return htmlspecialchars($matches[0]);' ), $message);
|
}
if($options['nl2br'] !== 0)
| }
if($options['nl2br'] !== 0)
|
Zeile 290 | Zeile 305 |
---|
{ $this->mycode_cache['find'][] = $code['regex']; $this->mycode_cache['replacement'][] = $code['replacement'];
|
{ $this->mycode_cache['find'][] = $code['regex']; $this->mycode_cache['replacement'][] = $code['replacement'];
|
}
| }
|
}
/**
| }
/**
|
Zeile 472 | Zeile 487 |
---|
{ $badword['replacement'] = "*****"; }
|
{ $badword['replacement'] = "*****"; }
|
$badword['badword'] = preg_quote($badword['badword']);
| $badword['badword'] = preg_quote($badword['badword'], "#");
|
$message = preg_replace("#(\b|^)".$badword['badword']."(\b|$)#i", "\\1".$badword['replacement']."\\2", $message); } }
| $message = preg_replace("#(\b|^)".$badword['badword']."(\b|$)#i", "\\1".$badword['replacement']."\\2", $message); } }
|
Zeile 523 | Zeile 538 |
---|
* @return string The parsed text. */ function mycode_handle_size($size, $text)
|
* @return string The parsed text. */ function mycode_handle_size($size, $text)
|
{
| {
|
$size = intval($size)+10;
|
$size = intval($size)+10;
|
|
|
if($size > 50) { $size = 50;
| if($size > 50) { $size = 50;
|
Zeile 538 | Zeile 553 |
---|
/** * Parses quote MyCode.
|
/** * Parses quote MyCode.
|
*
| *
|
* @param string The message to be parsed * @param boolean Are we formatting as text? * @return string The parsed message.
| * @param string The message to be parsed * @param boolean Are we formatting as text? * @return string The parsed message.
|
Zeile 546 | Zeile 561 |
---|
function mycode_parse_quotes($message, $text_only=false) { global $lang, $templates, $theme, $mybb;
|
function mycode_parse_quotes($message, $text_only=false) { global $lang, $templates, $theme, $mybb;
|
|
|
// Assign pattern and replace values. $pattern = array( "#\[quote=(?:"|\"|')?(.*?)[\"']?(?:"|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi", "#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"
|
// Assign pattern and replace values. $pattern = array( "#\[quote=(?:"|\"|')?(.*?)[\"']?(?:"|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi", "#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si"
|
);
| );
|
if($text_only == false)
|
if($text_only == false)
|
{
| {
|
$replace = array( "\$this->mycode_parse_post_quotes('$2','$1')", "<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
|
$replace = array( "\$this->mycode_parse_post_quotes('$2','$1')", "<blockquote><cite>$lang->quote</cite>$1</blockquote>\n"
|
); }
| ); }
|
else { $replace = array( "\$this->mycode_parse_post_quotes('$2', '$1', true)", "\n{$lang->quote}\n--\n$1\n--\n"
|
else { $replace = array( "\$this->mycode_parse_post_quotes('$2', '$1', true)", "\n{$lang->quote}\n--\n$1\n--\n"
|
); }
| ); }
|
while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message)) { $message = preg_replace($pattern, $replace, $message);
| while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message)) { $message = preg_replace($pattern, $replace, $message);
|
Zeile 639 | Zeile 654 |
---|
$postdate = my_date($mybb->settings['dateformat'], intval($match[1])); $posttime = my_date($mybb->settings['timeformat'], intval($match[1])); $date = " ({$postdate} {$posttime})";
|
$postdate = my_date($mybb->settings['dateformat'], intval($match[1])); $posttime = my_date($mybb->settings['timeformat'], intval($match[1])); $date = " ({$postdate} {$posttime})";
|
}
| }
|
$username = preg_replace("#(?:"|\"|')? dateline=(?:"|\"|')?[0-9]+(?:"|\"|')?#i", '', $username); $delete_quote = false;
|
$username = preg_replace("#(?:"|\"|')? dateline=(?:"|\"|')?[0-9]+(?:"|\"|')?#i", '', $username); $delete_quote = false;
|
}
| }
|
if($delete_quote)
|
if($delete_quote)
|
{
| {
|
$username = my_substr($username, 0, my_strlen($username)-1);
|
$username = my_substr($username, 0, my_strlen($username)-1);
|
}
| }
|
if($text_only) { return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";
|
if($text_only) { return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";
|
} else
| } else
|
{ $span = ""; if(!$delete_quote)
| { $span = ""; if(!$delete_quote)
|
Zeile 667 | Zeile 682 |
---|
/** * Parses code MyCode.
|
/** * Parses code MyCode.
|
*
| *
|
* @param string The message to be parsed * @param boolean Are we formatting as text? * @return string The parsed message.
| * @param string The message to be parsed * @param boolean Are we formatting as text? * @return string The parsed message.
|
Zeile 696 | Zeile 711 |
---|
$code = str_replace('\\', '\', $code); $code = str_replace("\t", ' ', $code); $code = str_replace(" ", ' ', $code);
|
$code = str_replace('\\', '\', $code); $code = str_replace("\t", ' ', $code); $code = str_replace(" ", ' ', $code);
|
|
|
return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n"; }
| return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n"; }
|
Zeile 738 | Zeile 753 |
---|
{ $added_open_tag = true; $str = "<?php \n".$str;
|
{ $added_open_tag = true; $str = "<?php \n".$str;
|
}
| }
|
$added_end_tag = false; if(!preg_match("#\?>\s*$#si", $str)) { $added_end_tag = true; $str = $str." \n?>";
|
$added_end_tag = false; if(!preg_match("#\?>\s*$#si", $str)) { $added_end_tag = true; $str = $str." \n?>";
|
}
| }
|
// If the PHP version < 4.2, catch highlight_string() output. if(version_compare(PHP_VERSION, "4.2.0", "<"))
| // If the PHP version < 4.2, catch highlight_string() output. if(version_compare(PHP_VERSION, "4.2.0", "<"))
|
Zeile 754 | Zeile 769 |
---|
@highlight_string($str); $code = ob_get_contents(); ob_end_clean();
|
@highlight_string($str); $code = ob_get_contents(); ob_end_clean();
|
} else
| } else
|
{ $code = @highlight_string($str, true); }
| { $code = @highlight_string($str, true); }
|
Zeile 788 | Zeile 803 |
---|
if($added_open_tag) { $code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\"><\?php( | )(<br />?)#", "<code><span style=\"color: #$1\">", $code);
|
if($added_open_tag) { $code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\"><\?php( | )(<br />?)#", "<code><span style=\"color: #$1\">", $code);
|
}
| }
|
if($added_end_tag) {
| if($added_end_tag) {
|
Zeile 823 | Zeile 838 |
---|
if(!preg_match("#^[a-z0-9]+://#i", $url)) { $url = "http://".$url;
|
if(!preg_match("#^[a-z0-9]+://#i", $url)) { $url = "http://".$url;
|
}
| }
|
$fullurl = $url;
|
$fullurl = $url;
|
|
|
$url = str_replace('&', '&', $url); $name = str_replace('&', '&', $name);
|
$url = str_replace('&', '&', $url); $name = str_replace('&', '&', $name);
|
if(!preg_match("#[a-z0-9]+://#i", $fullurl)) { $fullurl = "http://".$fullurl; }
|
|
if(!$name) { $name = $url;
| if(!$name) { $name = $url;
|
Zeile 851 | Zeile 861 |
---|
} }
|
} }
|
// fix some entities in URLs $fullurl = strtr($fullurl, array('$' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20'));
| // Fix some entities in URLs $entities = array('$' => '%24', '$' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20'); $fullurl = str_replace(array_keys($entities), array_values($entities), $fullurl);
|
$name = preg_replace("#&\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode $link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>"; return $link;
| $name = preg_replace("#&\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode $link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>"; return $link;
|
Zeile 992 | Zeile 1003 |
---|
{ $message = str_replace($this->smilies_cache, array_keys($this->smilies_cache), $message); }
|
{ $message = str_replace($this->smilies_cache, array_keys($this->smilies_cache), $message); }
|
| return $message; } /** * Highlights a string * * @param string The message to be highligted * @param string The highlight keywords * @return string The message with highlight bbcodes */ function highlight_message($message, $highlight) { if(empty($this->highlight_cache)) { $this->highlight_cache = build_highlight_array($highlight); } if(is_array($this->highlight_cache) && !empty($this->highlight_cache)) { $message = preg_replace(array_keys($this->highlight_cache), $this->highlight_cache, $message); }
|
return $message; }
| return $message; }
|