/** * This function processes the text before showing for editing, etc * * @access public * @param string Raw text * @return string Converted text */ public function preEditParse($txt = "") { //----------------------------------------- // Clean up BR tags //----------------------------------------- if (!$this->parse_html) { $txt = str_replace("\n", "", $txt); $txt = str_replace("<br>", "\n", $txt); $txt = str_replace("<br />", "\n", $txt); } //----------------------------------------- // Unconvert smilies //----------------------------------------- $txt = IPSText::unconvertSmilies($txt); //----------------------------------------- // Clean up nbsp //----------------------------------------- $txt = str_replace(' ', "\t", $txt); $txt = str_replace(' ', " ", $txt); //----------------------------------------- // Parse html //----------------------------------------- if ($this->parse_html) { $txt = str_replace("'", "'", $txt); } //----------------------------------------- // Fix "{style_images_url}" //----------------------------------------- $txt = str_replace("{style_images_url}", "{style_images_url}", $txt); /* check for missing options in bbcode tags */ $txt = preg_replace('#\\[(\\S+?)=\\]#', '[\\1]', $txt); return trim($txt); }
/** * Unconvert emoticons * * @param string Raw posted text * @return string Raw text with text emoticons */ public function unconvertSmilies($t) { return IPSText::unconvertSmilies($t); }
/** * This function processes the text before showing for editing, etc * Used for rebuilding after upgrade to 3.0 * * @access public * @param string Raw text * @return string Converted text */ public function preEditParse($txt = "") { //----------------------------------------- // Before we start, strip newlines or we'll // end up duplicating them //----------------------------------------- $txt = str_replace("\n", "", $txt); $txt = str_replace("\r", "", $txt); //----------------------------------------- // Clean up BR tags //----------------------------------------- if (!$this->parse_html or $this->parse_nl2br) { $txt = str_replace("<br>", "\n", $txt); $txt = str_replace("<br />", "\n", $txt); } # Make EMO_DIR safe so the ^> regex works $txt = str_replace("<#EMO_DIR#>", "<#EMO_DIR>", $txt); # New emo $txt = preg_replace("#(\\s)?<([^>]+?)emoid=\"(.+?)\"([^>]*?)" . ">(\\s)?#is", "\\1\\3\\5", $txt); # And convert it back again... $txt = str_replace("<#EMO_DIR>", "<#EMO_DIR#>", $txt); # Legacy $txt = preg_replace("#<!--emo&(.+?)-->.+?<!--endemo-->#", "\\1", $txt); # New (3.0) $txt = IPSText::unconvertSmilies($txt); //----------------------------------------- // Clean up nbsp //----------------------------------------- $txt = str_replace(' ', "\t", $txt); $txt = str_replace(' ', " ", $txt); if ($this->parse_bbcode) { //----------------------------------------- // Custom bbcode... //----------------------------------------- $txt = preg_replace("#<acronym title=[\"'](.+?)['\"]>(.+?)</acronym>#is", "[acronym=\"\\1\"]\\2[/acronym]", $txt); $txt = preg_replace("#<a href=[\"']index\\.php\\?automodule=blog(&|&)showentry=(.+?)['\"]>(.+?)</a>#is", "[entry=\"\\2\"]\\3[/entry]", $txt); $txt = preg_replace("#<a href=[\"']index\\.php\\?automodule=blog(&|&)blogid=(.+?)['\"]>(.+?)</a>#is", "[blog=\"\\2\"]\\3[/blog]", $txt); $txt = preg_replace("#<a href=[\"']index\\.php\\?act=findpost(&|&)pid=(.+?)['\"]>(.+?)</a>#is", "[post=\"\\2\"]\\3[/post]", $txt); $txt = preg_replace("#<a href=[\"']index\\.php\\?showtopic=(.+?)['\"]>(.+?)</a>#is", "[topic=\"\\1\"]\\2[/topic]", $txt); $txt = preg_replace("#<a href=[\"'](.*?)index\\.php\\?act=findpost(&|&)pid=(.+?)['\"]><\\{POST_SNAPBACK\\}></a>#is", "[snapback]\\3[/snapback]", $txt); $txt = preg_replace("#<div class=[\"']codetop['\"]>(.+?)</div><div class=[\"']codemain['\"] style=[\"']height:200px;white\\-space:pre;overflow:auto['\"]>(.+?)</div>#is", "[codebox]\\2[/codebox]", $txt); $txt = preg_replace("#<!--blog\\.extract\\.start-->(.+?)<!--blog\\.extract\\.end-->#is", "[extract]\\1[/extract]", $txt); $txt = preg_replace("#<span style=[\"']color:\\#000000;background:\\#000000['\"]>(.+?)</span>#is", "[spoiler]\\1[/spoiler]", $txt); //----------------------------------------- // SQL //----------------------------------------- $txt = preg_replace_callback("#<!--sql-->(.+?)<!--sql1-->(.+?)<!--sql2-->(.+?)<!--sql3-->#is", array(&$this, 'unconvert_sql'), $txt); //----------------------------------------- // HTML //----------------------------------------- $txt = preg_replace_callback("#<!--html-->(.+?)<!--html1-->(.+?)<!--html2-->(.+?)<!--html3-->#is", array(&$this, 'unconvert_htm'), $txt); //----------------------------------------- // Images / Flash //----------------------------------------- $txt = preg_replace_callback("#<!--Flash (.+?)-->.+?<!--End Flash-->#", array(&$this, 'unconvert_flash'), $txt); $txt = preg_replace("#<img(?:.+?)src=[\"'](\\S+?)['\"][^>]+?>#is", "\\[img\\]\\1\\[/img\\]", $txt); //----------------------------------------- // Email, URLs //----------------------------------------- $txt = preg_replace("#<a href=[\"']mailto:(.+?)['\"]>(.+?)</a>#s", "\\[email=\\1\\]\\2\\[/email\\]", $txt); $txt = preg_replace("#<a href=[\"'](http://|https://|ftp://|news://)?(\\S+?)['\"].*?" . ">(.+?)</a>#s", "\\[url=\"\\1\\2\"\\]\\3\\[/url\\]", $txt); //----------------------------------------- // Quote //----------------------------------------- $txt = preg_replace("#<!--QuoteBegin-->(.+?)<!--QuoteEBegin-->#", '[quote]', $txt); $txt = preg_replace("#<!--QuoteBegin-{1,2}([^>]+?)\\+([^>]+?)-->(.+?)<!--QuoteEBegin-->#", "[quote name='\\1' date='\\2']", $txt); $txt = preg_replace("#<!--QuoteBegin-{1,2}([^>]+?)\\+-->(.+?)<!--QuoteEBegin-->#", "[quote name='\\1']", $txt); $txt = preg_replace("#<!--QuoteEnd-->(.+?)<!--QuoteEEnd-->#", '[/quote]', $txt); //----------------------------------------- // Super old quotes //----------------------------------------- $txt = preg_replace("#\\[quote=(.+?),(.+?)\\]#i", "[quote name='\\1' date='\\2']", $txt); //----------------------------------------- // URL Inside Quote //----------------------------------------- $txt = preg_replace("#\\[quote=(.*?)\\[url(.*?)\\](.+?)\\[\\/url\\]\\]#i", "[quote=\\1\\3]", str_replace("\\", "", $txt)); //----------------------------------------- // New quote //----------------------------------------- $txt = preg_replace_callback("#<!--quoteo([^>]+?)?-->(.+?)<!--quotec-->#si", array(&$this, '_parse_new_quote'), $txt); //----------------------------------------- // Ident => Block quote //----------------------------------------- while (preg_match("#<blockquote>(.+?)</blockquote>#is", $txt)) { $txt = preg_replace("#<blockquote>(.+?)</blockquote>#is", "[indent]\\1[/indent]", $txt); } //----------------------------------------- // CODE //----------------------------------------- $txt = preg_replace("#<!--c1-->(.+?)<!--ec1-->#", '[code]', $txt); $txt = preg_replace("#<!--c2-->(.+?)<!--ec2-->#", '[/code]', $txt); //----------------------------------------- // left, right, center //----------------------------------------- $txt = preg_replace("#<div align=[\"'](left|right|center)['\"]>(.+?)</div>#is", "[\\1]\\2[/\\1]", $txt); //----------------------------------------- // Start off with the easy stuff //----------------------------------------- $txt = $this->parse_simple_tag_recursively('b', 'b', 0, $txt); $txt = $this->parse_simple_tag_recursively('i', 'i', 0, $txt); $txt = $this->parse_simple_tag_recursively('u', 'u', 0, $txt); $txt = $this->parse_simple_tag_recursively('strike', 's', 0, $txt); $txt = $this->parse_simple_tag_recursively('sub', 'sub', 0, $txt); $txt = $this->parse_simple_tag_recursively('sup', 'sup', 0, $txt); //----------------------------------------- // List headache //----------------------------------------- $txt = preg_replace("#(\n){0,1}<ul>#", "\\1\\[list\\]", $txt); $txt = preg_replace("#(\n){0,1}<ol>#", "\\1\\[list=1\\]", $txt); $txt = preg_replace("#(\n){0,1}<ol type=[\"'](a|A|i|I|1)[\"']>#", "\\1\\[list=\\2\\]\n", $txt); $txt = preg_replace("#(\n){0,1}<li>#", "\n\\[*\\]", $txt); $txt = preg_replace("#(\n){0,1}</ul>(\n){0,1}#", "\n\\[/list\\]\\2", $txt); $txt = preg_replace("#(\n){0,1}</ol>(\n){0,1}#", "\n\\[/list\\]\\2", $txt); //----------------------------------------- // Opening style attributes //----------------------------------------- $txt = preg_replace("#<!--sizeo:(.+?)-->(.+?)<!--/sizeo-->#", "[size=\\1]", $txt); $txt = preg_replace("#<!--coloro:(.+?)-->(.+?)<!--/coloro-->#", "[color=\"\\1\"]", $txt); $txt = preg_replace("#<!--fonto:(.+?)-->(.+?)<!--/fonto-->#", "[font=\"\\1\"]", $txt); $txt = preg_replace("#<!--backgroundo:(.+?)-->(.+?)<!--/backgroundo-->#", "[background=\\1]", $txt); //----------------------------------------- // Closing style attributes //----------------------------------------- $txt = preg_replace("#<!--sizec-->(.+?)<!--/sizec-->#", "[/size]", $txt); $txt = preg_replace("#<!--colorc-->(.+?)<!--/colorc-->#", "[/color]", $txt); $txt = preg_replace("#<!--fontc-->(.+?)<!--/fontc-->#", "[/font]", $txt); $txt = preg_replace("#<!--backgroundc-->(.+?)<!--/backgroundc-->#", "[/background]", $txt); //----------------------------------------- // LEGACY SPAN TAGS //----------------------------------------- //----------------------------------------- // WYSI-Weirdness #9923464: Opera span tags //----------------------------------------- while (preg_match("#<span style='font-family: \"(.+?)\"'>(.+?)</span>#is", $txt)) { $txt = preg_replace("#<span style='font-family: \"(.+?)\"'>(.+?)</span>#is", "\\[font=\\1\\]\\2\\[/font\\]", $txt); } while (preg_match("#<span style=['\"]font-size:?(.+?)pt;?\\s+?line-height:?\\s+?100%['\"]>(.+?)</span>#is", $txt)) { $txt = preg_replace_callback("#<span style=['\"]font-size:?(.+?)pt;?\\s+?line-height:?\\s+?100%['\"]>(.+?)</span>#is", array(&$this, 'unconvert_size'), $txt); } while (preg_match("#<span style=['\"]color:?(.+?)['\"]>(.+?)</span>#is", $txt)) { $txt = preg_replace("#<span style=['\"]color:?(.+?)['\"]>(.+?)</span>#is", "\\[color=" . trim("\\1") . "\\]\\2\\[/color\\]", $txt); } while (preg_match("#<span style=['\"]font-family:?(.+?)['\"]>(.+?)</span>#is", $txt)) { $txt = preg_replace("#<span style=['\"]font-family:?(.+?)['\"]>(.+?)</span>#is", "\\[font=\"" . trim("\\1") . "\"\\]\\2\\[/font\\]", $txt); } while (preg_match("#<span style=['\"]background-color:?\\s+?(.+?)['\"]>(.+?)</span>#is", $txt)) { $txt = preg_replace("#<span style=['\"]background-color:?\\s+?(.+?)['\"]>(.+?)</span>#is", "\\[background=\\1\\]\\2\\[/font\\]", $txt); } # Legacy <strike> $txt = preg_replace("#<s>(.+?)</s>#is", "\\[s\\]\\1\\[/s\\]", $txt); //----------------------------------------- // Tidy up the end quote stuff //----------------------------------------- $txt = preg_replace("#(\\[/QUOTE\\])\\s*?<br />\\s*#si", "\\1\n", $txt); $txt = preg_replace("#(\\[/QUOTE\\])\\s*?<br>\\s*#si", "\\1\n", $txt); $txt = preg_replace("#<!--EDIT\\|.+?\\|.+?-->#", "", $txt); $txt = str_replace("</li>", "", $txt); $txt = str_replace("™", "(tm)", $txt); } //----------------------------------------- // Unconvert custom bbcode //----------------------------------------- $txt = $this->post_db_unparse_bbcode($txt); //----------------------------------------- // Parse html //----------------------------------------- if ($this->parse_html) { $txt = str_replace("'", "'", $txt); } return trim(stripslashes($txt)); }
/** * Cleans an email message * * @param string Email content * @param bool Skip converting < and > * @param bool Fix up plain text links * @return string Cleaned email content */ public function cleanMessage($message = "", $skipAngleBrackets = false, $fixPlainTextLinks = true) { if (!$this->html_email) { $message = preg_replace_callback('#\\[url=(.+?)\\](.+?)\\[/url\\]#', array($this, "_formatUrl"), $message); } //----------------------------------------- // Unconvert smilies 'cos at this point they are img tags //----------------------------------------- $message = IPSText::unconvertSmilies($message); //----------------------------------------- // We may want to adjust this later, but for // now just strip any other html //----------------------------------------- $message = preg_replace('#</p>(\\s+?)?<p([^>]+?)?>#is', '<br />', $message); /* We need to fix links in plaintext templates so people don't get "http://some..ing" instead of "http://something" */ if ($fixPlainTextLinks) { $message = $this->fixPlaintextLinks($message); } $message = IPSText::stripTags($message, '<br>,<blockquote>'); IPSText::getTextClass('bbcode')->parse_html = 0; IPSText::getTextClass('bbcode')->parse_nl2br = 1; IPSText::getTextClass('bbcode')->parse_bbcode = 0; /* Textual representations of certain bbcodes to attempt to keep context */ $plainText = '<br /><br />------------ QUOTE ----------<br />\\1<br />-----------------------------<br /><br />'; $message = preg_replace('#\\[quote(?:[^\\]]+?)?\\](.+?)\\[/quote\\]#s', $plainText, $message); $message = preg_replace('#<blockquote(?:[^>]+?)?>(.+?)</blockquote>#s', $plainText, $message); $plainTextCode = '*CODE* \\1 */CODE*'; $message = preg_replace('#\\[code(?:[^\\]]+?)?\\](.+?)\\[/code\\]#s', $plainTextCode, $message); $message = preg_replace('#\\[member=(.+?)\\]#s', "\\1", $message); $message = IPSText::getTextClass('bbcode')->stripAllTags($message, true); //----------------------------------------- // Bear with me... //----------------------------------------- $message = str_replace("\n", "\r\n", $message); $message = str_replace("\r", "", $message); $message = str_replace("<br>", "\r\n", $message); $message = str_replace("<br />", "\r\n", $message); $message = str_replace("\r\n\r\n", "\r\n", $message); $message = str_replace(""", '"', $message); $message = str_replace("\", "\\", $message); $message = str_replace("$", "\$", $message); $message = str_replace("!", "!", $message); $message = str_replace(""", '"', $message); $message = str_replace("'", "'", $message); $message = str_replace("(", "(", $message); $message = str_replace(")", ")", $message); $message = str_replace("<", "<", $message); $message = str_replace(">", ">", $message); $message = str_replace("|", '|', $message); $message = str_replace("&", "&", $message); $message = str_replace("&", '&', $message); $message = str_replace(":", ":", $message); $message = str_replace("[", "[", $message); $message = str_replace("]", "]", $message); $message = str_replace("@", '@', $message); $message = str_replace(" ", ' ', $message); if (!$skipAngleBrackets) { $message = str_replace("<", '<', $message); $message = str_replace(">", '>', $message); } return $message; }