Contributions by Keith Gable This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. In addition to being restricted by the GNU General Public License, Essence Engine may not be sold, rented, sublicensed, or leased; you are not permitted to generate revenue with the Essence Engine source code. You may, however, use Essence Engine to run a website that generates revenue via other means. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA $Id$ */ // Essense Engine Message Parser // Usage: process_post( POST_DATA_ARRAY , USER_DISPNAME ); function process_post($postdata,$username = null) { global $allowedhtml; /* $posttext = stripslashes($postdata["post_text"]); if (!$postdata["opt_html"]) $posttext = safetext($postdata["post_text"]); if (!$postdata["opt_html"]) $posttext = nl2pbr($posttext); if (!$postdata["opt_bbcode"]) $posttext = process_bbcode($posttext,$username); //$posttext = applyacronyms($posttext); if (!$postdata["opt_emoticons"]) $posttext = applyemotes($posttext); */ // Cleanup $posttext = stripslashes($postdata["post_text"]); $fcodes = array("@\r\n+@","@\n{3,}@"); $rcodes = array( "\n", "\n\n"); $posttext = preg_replace($fcodes,$rcodes,$posttext); $htmlf = array('&', '<', '>'); $htmlr = array('&', '<', '>'); $posttext = str_replace($htmlf,$htmlr,$posttext); // If not using HTML, process \n's if (!$postdata["opt_html"]) $posttext = nl2br($posttext); // Process bbcode and acronyms if (!$postdata["opt_bbcode"]) { $posttext = process_bbcode($posttext,$username); $posttext = process_acros($posttext); } // Process emoticons $posttext = process_emotes($posttext); // Reset HTML if ($postdata["opt_html"] && $allowedhtml) { $allowtags = str_replace(",","|",$allowedhtml); $posttext = preg_replace("@<(/?)(" . str_replace("*", ".*?", $allowtags) . ")>@", "<$1$2>", $posttext); } // Return result return $posttext; } function process_bbcode($text,$postby = null) { $fcodes[] = "/\[i\](.+?)\[\/i\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[b\](.+?)\[\/b\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[u\](.+?)\[\/u\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[s\](.+?)\[\/s\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[code\](.+?)\[\/code\]/sie"; $rcodes[] = "stripslashes('
Code
\n
' . str_replace('
',null,'\\1') . '
')"; $fcodes[] = "/\[color=(.+?)\](.+?)\[\/color\]/si"; $rcodes[] = '\\2'; $fcodes[] = "/\[url\](.+?)\[\/url\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[url=(.+?)\](.*?)\[\/url\]/si"; $rcodes[] = '\\2'; $fcodes[] = "/\[email\](.+?)\[\/email\]/si"; $rcodes[] = '\\1'; $fcodes[] = "/\[email=(.+?)\](.+?)\[\/email\]/si"; $rcodes[] = '\\2'; $fcodes[] = "/\[img\](.+?)\[\/img\]/si"; $rcodes[] = '' . safetext($postby) . '\'s image'; $fcodes[] = "/\[img=([^,]+?)\]/si"; $rcodes[] = '' . safetext($postby) . '\'s image'; $fcodes[] = "/\[img=(.+?),(.+?)\]/si"; $rcodes[] = '' . safetext($postby) . '\'s image'; $fcodes[] = "/\[quote\](.+?)\[\/quote\]/si"; $rcodes[] = "
Quote
\n
\\1
"; $fcodes[] = "/\[quote=([^,]+?)\](.+?)\[\/quote\]/si"; $rcodes[] = "
Quote (\\1)
\n
\\2
"; $fcodes[] = "/\[quote=(.+?),(.+?)\](.+?)\[\/quote\]/si"; $rcodes[] = "
Quote (\\1 at \\2)
\n
\\3
"; $fcodes[] = "/\[me\](.+?)\[\/me\]/si"; $rcodes[] = '
*' . safetext($postby) . ' \\1*
'; return preg_replace($fcodes,$rcodes,$text); } function process_acros($text) { /* global $db; $result = mysql_query("SELECT text,definition FROM acronyms WHERE disable=0", $db); while ($acro = mysql_fetch_array($result)) { $in[] = "/\{(" . $acro["text"] . ")\}/si"; $out[] = "\\1"; } $return = preg_replace($in,$out,$text); */ $chktxt = "/\{(\w{1,10})\|(.{1,70}?)}/ie"; $chkreplace = "'' . safetext('\\1') . ''"; $return = preg_replace($chktxt,$chkreplace,$text); return $return; } function process_emotes($text) { return $text; } function trunctext($text,$limit = 20) { $text = str_replace(array("\n","\r")," ",$text); $uptext = explode(" ",$text); if (count($uptext) > $limit) { $text = ""; for ($i = 0; $i <= ($limit - 1); $i++) $text .= $uptext[$i] . " "; $text .= "..."; } return $text; } // Strip BBCodes and/or HTML as appropriate per message flags function strip_post($text,$html = false,$bbcode = false) { if (!$bbcode) { $fcodes[] = "@\[me](.+?)\[/me]@si"; $rcodes[] = "*\\1*"; $fcodes[] = "@\[.+?]@"; $rcodes[] = ""; $fcodes[] = "@\{(\w{1,10})\|.{1,70}?}@ie"; $rcodes[] = "\\1"; } if ($html) { $fcodes[] = "@<.+?>@"; $rcodes[] = ""; } if ($fcodes) return preg_replace($fcodes,$rcodes,$text); else return $text; } ?>