Zeile 6 | Zeile 6 |
---|
* Website: http://mybb.com * License: http://mybb.com/about/license *
|
* Website: http://mybb.com * License: http://mybb.com/about/license *
|
* $Id: class_parser.php 5380 2011-02-21 12:04:43Z Tomm $
| * $Id$
|
*/
/*
| */
/*
|
Zeile 114 | Zeile 114 |
---|
} else {
|
} else {
|
while(preg_match("#<script(.*)>(.*)</script(.*)>#is", $message))
| while(preg_match("#<s(cript|tyle)(.*)>(.*)</s(cript|tyle)(.*)>#is", $message))
|
{
|
{
|
$message = preg_replace("#<script(.*)>(.*)</script(.*)>#is", "<script$1>$2</script$3>", $message);
| $message = preg_replace("#<s(cript|tyle)(.*)>(.*)</s(cript|tyle)(.*)>#is", "<s$1$2>$3</s$4$5>", $message);
|
}
|
}
|
$message = str_replace(array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"), array('<?php', '<!--', '-->', '?>', "\n", "\n"), $message);
| $find = array('<?php', '<!--', '-->', '?>', "<br />\n", "<br>\n"); $replace = array('<?php', '<!--', '-->', '?>', "\n", "\n"); $message = str_replace($find, $replace, $message);
|
} // If MyCode needs to be replaced, first filter out [code] and [php] tags. if($this->options['allow_mycode']) {
|
} // If MyCode needs to be replaced, first filter out [code] and [php] tags. if($this->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 155 | Zeile 156 |
---|
} // Parse Highlights
|
} // Parse Highlights
|
if($this->options['highlight'])
| if(!empty($this->options['highlight']))
|
{ $message = $this->highlight_message($message, $this->options['highlight']); }
| { $message = $this->highlight_message($message, $this->options['highlight']); }
|
Zeile 170 | Zeile 171 |
---|
{ foreach($code_matches as $text) {
|
{ foreach($code_matches as $text) {
|
if(my_strtolower($text[1]) == "code")
| // 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")
|
{ $code = $this->mycode_parse_code($text[2]);
|
{ $code = $this->mycode_parse_code($text[2]);
|
}
| }
|
elseif(my_strtolower($text[1]) == "php") { $code = $this->mycode_parse_php($text[2]);
| elseif(my_strtolower($text[1]) == "php") { $code = $this->mycode_parse_php($text[2]);
|
Zeile 183 | Zeile 190 |
---|
} }
|
} }
|
| // Replace meta and base tags in our post - these are > dangerous <
|
if($this->options['allow_html'])
|
if($this->options['allow_html'])
|
{
| {
|
$message = preg_replace_callback("#<((m[^a])|(b[^diloru>])|(s[^aemptu>]))(\s*[^>]*)>#si", create_function( '$matches',
|
$message = preg_replace_callback("#<((m[^a])|(b[^diloru>])|(s[^aemptu>]))(\s*[^>]*)>#si", create_function( '$matches',
|
'return htmlspecialchars($matches[0]);'
| 'return htmlspecialchars_uni($matches[0]);'
|
), $message); }
|
), $message); }
|
if($options['nl2br'] !== 0)
| if(!isset($options['nl2br']) || $options['nl2br'] != 0)
|
{ $message = nl2br($message); // Fix up new lines and block level elements
| { $message = nl2br($message); // Fix up new lines and block level elements
|
Zeile 291 | Zeile 299 |
---|
// If there is custom MyCode, load it. if(is_array($custom_mycode))
|
// If there is custom MyCode, load it. if(is_array($custom_mycode))
|
{
| {
|
foreach($custom_mycode as $key => $mycode) { $mycode['regex'] = str_replace("\x0", "", $mycode['regex']);
| foreach($custom_mycode as $key => $mycode) { $mycode['regex'] = str_replace("\x0", "", $mycode['regex']);
|
Zeile 306 | Zeile 314 |
---|
// Assign the MyCode to the cache. foreach($mycode as $code)
|
// Assign the MyCode to the cache. foreach($mycode as $code)
|
{
| {
|
$this->mycode_cache['standard']['find'][] = $code['regex']; $this->mycode_cache['standard']['replacement'][] = $code['replacement']; }
| $this->mycode_cache['standard']['find'][] = $code['regex']; $this->mycode_cache['standard']['replacement'][] = $code['replacement']; }
|
Zeile 351 | Zeile 359 |
---|
while(preg_match($mycode['find'], $message)) { $message = preg_replace($mycode['find'], $mycode['replacement'], $message);
|
while(preg_match($mycode['find'], $message)) { $message = preg_replace($mycode['find'], $mycode['replacement'], $message);
|
}
| }
|
}
// Special code requiring special attention
| }
// Special code requiring special attention
|
Zeile 391 | Zeile 399 |
---|
*/ private function cache_smilies() {
|
*/ private function cache_smilies() {
|
global $cache;
| global $cache, $mybb;
|
$this->smilies_cache = array();
$smilies = $cache->read("smilies");
| $this->smilies_cache = array();
$smilies = $cache->read("smilies");
|
Zeile 399 | Zeile 407 |
---|
{ foreach($smilies as $sid => $smilie) {
|
{ foreach($smilies as $sid => $smilie) {
|
| if(defined("IN_ARCHIVE") && substr($smilie['image'], 0, 4) != "http") { // We're in the archive and not using an outside image, add in our address $smilie['image'] = $mybb->settings['bburl']."/".$smilie['image']; }
|
$this->smilies_cache[$smilie['find']] = "<img src=\"{$smilie['image']}\" style=\"vertical-align: middle;\" border=\"0\" alt=\"{$smilie['name']}\" title=\"{$smilie['name']}\" />"; } }
| $this->smilies_cache[$smilie['find']] = "<img src=\"{$smilie['image']}\" style=\"vertical-align: middle;\" border=\"0\" alt=\"{$smilie['name']}\" title=\"{$smilie['name']}\" />"; } }
|
Zeile 410 | Zeile 424 |
---|
* @param string The message being parsed. * @param string Base URL for the image tags created by smilies. * @param string Yes/No if HTML is allowed in the post
|
* @param string The message being parsed. * @param string Base URL for the image tags created by smilies. * @param string Yes/No if HTML is allowed in the post
|
* @return string The parsed message. */
| * @return string The parsed message. */
|
function parse_smilies($message, $allow_html=0) { if($this->smilies_cache == 0)
| function parse_smilies($message, $allow_html=0) { if($this->smilies_cache == 0)
|
Zeile 422 | Zeile 436 |
---|
$message = ' ' . $message . ' '; // First we take out any of the tags we don't want parsed between (url= etc)
|
$message = ' ' . $message . ' '; // First we take out any of the tags we don't want parsed between (url= etc)
|
preg_match_all("#\[(url(=[^\]]*])?\](.*?)\[\/url\]|quote=([^\]]*)?\])#i", $message, $bad_matches, PREG_PATTERN_ORDER); $message = preg_replace("#\[(url(=[^\]]*])?\](.*?)\[\/url\]|quote=([^\]]*)?\])#si", "<mybb-bad-sm>", $message);
| preg_match_all("#\[(url(=[^\]]*)?\]|quote=([^\]]*)?\])#i", $message, $bad_matches, PREG_PATTERN_ORDER); $message = preg_replace("#\[(url(=[^\]]*)?\]|quote=([^\]]*)?\])#si", "<mybb-bad-sm>", $message);
|
// Impose a hard limit of 500 smilies per message as to not overload the parser $remaining = 500;
|
// Impose a hard limit of 500 smilies per message as to not overload the parser $remaining = 500;
|
|
|
if(is_array($this->smilies_cache)) { foreach($this->smilies_cache as $find => $replace)
| if(is_array($this->smilies_cache)) { foreach($this->smilies_cache as $find => $replace)
|
Zeile 435 | Zeile 449 |
---|
$orig_message = $message; $find = $this->parse_html($find); $find = preg_quote($find, "#");
|
$orig_message = $message; $find = $this->parse_html($find); $find = preg_quote($find, "#");
|
| $replace = strip_tags($replace, "<img>");
|
// Fix issues for smileys starting with a ";" $orig_find = $find;
| // Fix issues for smileys starting with a ";" $orig_find = $find;
|
Zeile 519 | Zeile 535 |
---|
} } }
|
} } }
|
if($options['strip_tags'] == 1)
| if(isset($options['strip_tags']) && $options['strip_tags'] == 1)
|
{ $message = strip_tags($message); }
| { $message = strip_tags($message); }
|
Zeile 550 | Zeile 566 |
---|
"#(o)(nfocus\s?=)#i", "#(o)(nselect\s?=)#i", "#(o)(nunload\s?=)#i",
|
"#(o)(nfocus\s?=)#i", "#(o)(nselect\s?=)#i", "#(o)(nunload\s?=)#i",
|
"#(o)(nkeypress\s?=)#i"
| "#(o)(nkeypress\s?=)#i", "#(o)(nerror\s?=)#i", "#(o)(nreset\s?=)#i", "#(o)(nabort\s?=)#i"
|
); $message = preg_replace($js_array, "$1<strong></strong>$2$4", $message);
| ); $message = preg_replace($js_array, "$1<strong></strong>$2$4", $message);
|
Zeile 592 | Zeile 611 |
---|
// Assign pattern and replace values. $pattern = array(
|
// Assign pattern and replace values. $pattern = array(
|
"#\[quote=(?:"|\"|')?(.*?)[\"']?(?:"|\"|')?\](.*?)\[\/quote\](\r\n?|\n?)#esi",
| "#\[quote=([\"']|"|)(.*?)(?:\\1)(.*?)(?:[\"']|")?\](.*?)\[/quote\](\r\n?|\n?)#esi",
|
"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si" );
if($text_only == false) { $replace = array(
|
"#\[quote\](.*?)\[\/quote\](\r\n?|\n?)#si" );
if($text_only == false) { $replace = array(
|
"\$this->mycode_parse_post_quotes('$2','$1')",
| "\$this->mycode_parse_post_quotes('$4','$2$3')",
|
"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n" ); } else { $replace = array(
|
"<blockquote><cite>$lang->quote</cite>$1</blockquote>\n" ); } else { $replace = array(
|
"\$this->mycode_parse_post_quotes('$2', '$1', true)",
| "\$this->mycode_parse_post_quotes('$4','$2$3', true)",
|
"\n{$lang->quote}\n--\n$1\n--\n" ); }
|
"\n{$lang->quote}\n--\n$1\n--\n" ); }
|
while(preg_match($pattern[0], $message) || preg_match($pattern[1], $message))
| do
|
{
|
{
|
$message = preg_replace($pattern, $replace, $message); }
| // preg_replace has erased the message? Restore it... if(!$message) { $message = $previous_message; break; } $previous_message = $message; $message = preg_replace($pattern, $replace, $message, -1, $count); } while($count);
|
if($text_only == false) {
| if($text_only == false) {
|
Zeile 860 | Zeile 886 |
---|
$name = my_substr($url, 0, 40)."...".my_substr($url, -10); } }
|
$name = my_substr($url, 0, 40)."...".my_substr($url, -10); } }
|
| $nofollow = ''; if(isset($this->options['nofollow_on'])) { $nofollow = " rel=\"nofollow\""; }
|
// 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);
|
// 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
|
$name = preg_replace("#&\#([0-9]+);#si", "&#$1;", $name); // Fix & but allow unicode
|
$link = "<a href=\"$fullurl\" target=\"_blank\">$name</a>";
| $link = "<a href=\"$fullurl\" target=\"_blank\"{$nofollow}>$name</a>";
|
return $link; }
| return $link; }
|
Zeile 885 | Zeile 917 |
---|
if($align == "right") { $css_align = " style=\"float: right;\"";
|
if($align == "right") { $css_align = " style=\"float: right;\"";
|
}
| }
|
else if($align == "left") { $css_align = " style=\"float: left;\"";
| else if($align == "left") { $css_align = " style=\"float: left;\"";
|
Zeile 899 | Zeile 931 |
---|
if($dimensions[0] > 0 && $dimensions[1] > 0) { return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
|
if($dimensions[0] > 0 && $dimensions[1] > 0) { return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
|
} else
| } else
|
{ return "<img src=\"{$url}\" border=\"0\" alt=\"{$alt}\"{$css_align} />"; }
| { return "<img src=\"{$url}\" border=\"0\" alt=\"{$alt}\"{$css_align} />"; }
|
Zeile 940 | Zeile 972 |
---|
return "[video={$video}]{$url}[/video]"; }
|
return "[video={$video}]{$url}[/video]"; }
|
$parsed_url = @parse_url($url);
| $parsed_url = @parse_url(urldecode($url));
|
if($parsed_url == false) {
|
if($parsed_url == false) {
|
return "[video={$video}]{$url}[/video]";;
| return "[video={$video}]{$url}[/video]";
|
} $fragments = array();
| } $fragments = array();
|
Zeile 960 | Zeile 992 |
---|
list($key, $value) = explode("=", $query); $key = str_replace("amp;", "", $key); $input[$key] = $value;
|
list($key, $value) = explode("=", $query); $key = str_replace("amp;", "", $key); $input[$key] = $value;
|
} $path = explode('/', $parsed_url['path']);
| } $path = explode('/', $parsed_url['path']);
|
switch($video) { case "dailymotion": list($id, ) = split("_", $path[2], 1); // http://www.dailymotion.com/video/fds123_title-goes-here
|
switch($video) { case "dailymotion": list($id, ) = split("_", $path[2], 1); // http://www.dailymotion.com/video/fds123_title-goes-here
|
break; case "googlevideo": $id = $input['docid']; // http://video.google.com/videoplay?docid=fds123
| |
break; case "metacafe": $id = $path[2]; // http://www.metacafe.com/watch/fds123/title_goes_here/ $title = htmlspecialchars_uni($path[3]); break; case "myspacetv":
|
break; case "metacafe": $id = $path[2]; // http://www.metacafe.com/watch/fds123/title_goes_here/ $title = htmlspecialchars_uni($path[3]); break; case "myspacetv":
|
$id = $input['videoid']; // http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=fds123
| $id = $path[4]; // http://www.myspace.com/video/fds/fds/123
|
break; case "yahoo":
|
break; case "yahoo":
|
$id = $path[3]; // http://video.yahoo.com/watch/fds123/abc567 $vid = htmlspecialchars_uni($path[2]); break;
| $id = $path[1]; // http://xy.screen.yahoo.com/fds-123.html // Support for localized portals $domain = explode('.', $parsed_url['host']); if($domain[0] != 'screen') { $local = $domain[0].'.'; } else { $local = ''; } break;
|
case "vimeo": $id = $path[1]; // http://vimeo.com/fds123 break; case "youtube": if($fragments[0])
|
case "vimeo": $id = $path[1]; // http://vimeo.com/fds123 break; case "youtube": if($fragments[0])
|
{
| {
|
$id = str_replace('!v=', '', $fragments[0]); // http://www.youtube.com/watch#!v=fds123
|
$id = str_replace('!v=', '', $fragments[0]); // http://www.youtube.com/watch#!v=fds123
|
| } elseif($input['v']) { $id = $input['v']; // http://www.youtube.com/watch?v=fds123
|
} else {
|
} else {
|
$id = $input['v']; // http://www.youtube.com/watch?v=fds123
| $id = $path[1]; // http://www.youtu.be/fds123
|
} break; default: return "[video={$video}]{$url}[/video]"; }
|
} break; default: return "[video={$video}]{$url}[/video]"; }
|
if(empty($id) || ($video == "yahoo" && empty($vid)))
| if(empty($id))
|
{ return "[video={$video}]{$url}[/video]"; }
| { return "[video={$video}]{$url}[/video]"; }
|
Zeile 1024 | Zeile 1066 |
---|
$message = preg_replace("#([\>\s\(\)])(http|https|ftp|news){1}://([^\/\"\s\<\[\.]+\.([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message); $message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2.$3[/url]", $message); $message = my_substr($message, 1);
|
$message = preg_replace("#([\>\s\(\)])(http|https|ftp|news){1}://([^\/\"\s\<\[\.]+\.([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message); $message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2.$3[/url]", $message); $message = my_substr($message, 1);
|
return $message; }
/**
| return $message; }
/**
|
* Parses list MyCode. * * @param string The message to be parsed
| * Parses list MyCode. * * @param string The message to be parsed
|
Zeile 1043 | Zeile 1085 |
---|
$message .= "</li>";
if($type)
|
$message .= "</li>";
if($type)
|
{
| {
|
$list = "\n<ol type=\"$type\">$message</ol>\n"; } else
| $list = "\n<ol type=\"$type\">$message</ol>\n"; } else
|
Zeile 1073 | Zeile 1115 |
---|
return $message; }
|
return $message; }
|
/**
| /**
|
* Highlights a string * * @param string The message to be highligted
| * Highlights a string * * @param string The message to be highligted
|
Zeile 1088 | Zeile 1130 |
---|
} if(is_array($this->highlight_cache) && !empty($this->highlight_cache))
|
} if(is_array($this->highlight_cache) && !empty($this->highlight_cache))
|
{
| {
|
$message = preg_replace(array_keys($this->highlight_cache), $this->highlight_cache, $message); }
| $message = preg_replace(array_keys($this->highlight_cache), $this->highlight_cache, $message); }
|
Zeile 1096 | Zeile 1138 |
---|
}
/**
|
}
/**
|
* Parses message to plain text equivilents of MyCode.
| * Parses message to plain text equivalents of MyCode.
|
* * @param string The message to be parsed * @return string The parsed message.
| * * @param string The message to be parsed * @return string The parsed message.
|
Zeile 1104 | Zeile 1146 |
---|
function text_parse_message($message, $options=array()) { global $plugins;
|
function text_parse_message($message, $options=array()) { global $plugins;
|
|
|
// Filter bad words if requested. if($options['filter_badwords'] != 0) {
| // Filter bad words if requested. if($options['filter_badwords'] != 0) {
|
Zeile 1116 | Zeile 1158 |
---|
$find = array( "#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",
|
$find = array( "#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",
|
"#\[code\](.*?)\[/code\](\r\n?|\n?)#ise",
| |
"#\[php\](.*?)\[/php\](\r\n?|\n?)#ise",
|
"#\[php\](.*?)\[/php\](\r\n?|\n?)#ise",
|
| "#\[code\](.*?)\[/code\](\r\n?|\n?)#ise",
|
"#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", "#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si", "#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",
| "#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is", "#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si", "#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",
|
Zeile 1143 | Zeile 1185 |
---|
}
// Special code requiring special attention
|
}
// Special code requiring special attention
|
while(preg_match("#\[list\](.*?)\[/list\]#si", $message)) { $message = preg_replace("#\[list\](.*?)\[/list\](\r\n?|\n?)#esi", "\$this->mycode_parse_list('$1', '', true)\n", $message);
| while(preg_match("#\[list\](.*?)\[/list\]#esi", $message)) { $message = preg_replace("#\s?\[list\](.*?)\[/list\](\r\n?|\n?)#esi", "\$this->mycode_parse_list('$1')\n", $message);
|
}
// Replace lists. while(preg_match("#\[list=(a|A|i|I|1)\](.*?)\[/list\](\r\n?|\n?)#esi", $message)) {
|
}
// Replace lists. while(preg_match("#\[list=(a|A|i|I|1)\](.*?)\[/list\](\r\n?|\n?)#esi", $message)) {
|
$message = preg_replace("#\[list=(a|A|i|I|1)\](.*?)\[/list\]#esi", "\$this->mycode_parse_list('$2', '$1', true)\n", $message);
| $message = preg_replace("#\s?\[list=(a|A|i|I|1)\](.*?)\[/list\]#esi", "\$this->mycode_parse_list('$2', '$1')\n", $message);
|
}
// Run plugin hooks
| }
// Run plugin hooks
|