Source for file module.textsanitizer.php
Documentation is available at module.textsanitizer.php
// $Id: module.textsanitizer.php 957 2007-08-06 23:40:36Z malanciault $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// 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. //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (http://www.myweb.ne.jp/, http://jp.xoops.org/) //
// Goghs Cheng (http://www.eqiao.com, http://www.devbeez.com/) //
// Project: The XOOPS Project (http://www.xoops.org/) //
// ------------------------------------------------------------------------- //
* Class to "clean up" text for various uses
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright (c) 2000-2003 The Xoops Project - www.xoops.org
* Constructor of this class
* Gets allowed html tags from admin config settings
* <br> should not be allowed since nl2br will be used
* @todo Sofar, this does nuttin' ;-)
* Access the only instance of this class
* Replace emoticons in the message with smiley images
if ($getsmiles = $db->query("SELECT * FROM ". $db->prefix("smiles"))){
while ($smiles = $db->fetchArray($getsmiles)) {
foreach ($this->smileys as $smile) {
* Make links in the text clickable
$patterns = array("/(^|[^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/])ftp\.([a-z0-9\-]+)\.([^, \r\n\"\(\)'<>]+)/i", "/(^|[^]_a-z0-9-=\"'\/:\.])([a-z0-9\-_\.]+?)@([^, \r\n\"\(\)'<>\[\]]+)/i");
$replacements = array("\\1<a href=\"\\2://\\3\" target=\"_blank\">\\2://\\3</a>", "\\1<a href=\"http://www.\\2.\\3\" target=\"_blank\">www.\\2.\\3</a>", "\\1<a href=\"ftp://ftp.\\2.\\3\" target=\"_blank\">ftp.\\2.\\3</a>", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>");
* Replace XoopsCodes with their equivalent HTML formatting
* @param bool $allowimage Allow images in the text?
* On FALSE, uses links to images.
//$patterns[] = "/\[code](.*)\[\/code\]/esU";
//$replacements[] = "'<div class=\"xoopsCode\"><code><pre>'.wordwrap(MyTextSanitizer::htmlSpecialChars('\\1'), 100).'</pre></code></div>'";
// RMV: added new markup for intrasite url (allows easier site moves)
// TODO: automatically convert other URLs to this format if XOOPS_URL matches??
$patterns[] = "/\[siteurl=(['\"]?)([^\"'<>]*)\\1](.*)\[\/siteurl\]/sU";
$replacements[] = '<a href="'. XOOPS_URL. '/\\2">\\3</a>';
$patterns[] = "/\[url=(['\"]?)(http[s]?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
$replacements[] = '<a href="\\2" target="_blank">\\3</a>';
$patterns[] = "/\[url=(['\"]?)(ftp?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
$replacements[] = '<a href="\\2" target="_blank">\\3</a>';
$patterns[] = "/\[url=(['\"]?)([^\"'<>]*)\\1](.*)\[\/url\]/sU";
$replacements[] = '<a href="http://\\2" target="_blank">\\3</a>';
$patterns[] = "/\[color=(['\"]?)([a-zA-Z0-9]*)\\1](.*)\[\/color\]/sU";
$replacements[] = '<span style="color: #\\2;">\\3</span>';
$patterns[] = "/\[size=(['\"]?)([a-z0-9-]*)\\1](.*)\[\/size\]/sU";
$replacements[] = '<span style="font-size: \\2;">\\3</span>';
$patterns[] = "/\[font=(['\"]?)([^;<>\*\(\)\"']*)\\1](.*)\[\/font\]/sU";
$replacements[] = '<span style="font-family: \\2;">\\3</span>';
$patterns[] = "/\[email]([^;<>\*\(\)\"']*)\[\/email\]/sU";
$replacements[] = '<a href="mailto:\\1">\\1</a>';
$patterns[] = "/\[b](.*)\[\/b\]/sU";
$replacements[] = '<b>\\1</b>';
$patterns[] = "/\[i](.*)\[\/i\]/sU";
$replacements[] = '<i>\\1</i>';
$patterns[] = "/\[u](.*)\[\/u\]/sU";
$replacements[] = '<u>\\1</u>';
$patterns[] = "/\[d](.*)\[\/d\]/sU";
$replacements[] = '<del>\\1</del>';
//$patterns[] = "/\[li](.*)\[\/li\]/sU";
//$replacements[] = '<li>\\1</li>';
$patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
$patterns[] = "/\[img]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
$patterns[] = "/\[img align=(['\"]?)(left|center|right)\\1 id=(['\"]?)([0-9]*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
$patterns[] = "/\[img id=(['\"]?)([0-9]*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
$replacements[] = '<a href="\\3" target="_blank">\\3</a>';
$replacements[] = '<a href="\\1" target="_blank">\\1</a>';
$replacements[] = '<a href="'. XOOPS_URL. '/image.php?id=\\4" target="_blank">\\5</a>';
$replacements[] = '<a href="'. XOOPS_URL. '/image.php?id=\\2" target="_blank">\\3</a>';
$replacements[] = '<img src="\\3" align="\\2" alt="" />';
$replacements[] = '<img src="\\1" alt="" />';
$replacements[] = '<img src="'. XOOPS_URL. '/image.php?id=\\4" align="\\2" alt="\\5" />';
$replacements[] = '<img src="'. XOOPS_URL. '/image.php?id=\\2" alt="\\3" />';
$patterns[] = "/\[quote]/sU";
$replacements[] = _QUOTEC. '<div class="xoopsQuote"><blockquote>';
//$replacements[] = 'Quote: <div class="xoopsQuote"><blockquote>';
$patterns[] = "/\[\/quote]/sU";
$replacements[] = '</blockquote></div>';
$patterns[] = "/j{$c}a{$c}v{$c}a{$c}s{$c}c{$c}r{$c}i{$c}p{$c}t{$c}:/si";
$replacements[] = "(script removed)";
$patterns[] = "/a{$c}b{$c}o{$c}u{$c}t{$c}:/si";
$replacements[] = "about :";
* Convert linebreaks to <br /> tags
return preg_replace("/(\015\012)|(\015)|(\012)/","<br />",$text);
* Add slashes to the text if magic_quotes_gpc is turned off.
* if magic_quotes_gpc is on, stirip back slashes
* for displaying data in html textbox forms
//return preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES));
* Reverses {@link htmlSpecialChars()}
return preg_replace(array("/>/i", "/</i", "/"/i", "/'/i", '/&nbsp;/i'), array(">", "<", "\"", "'", " "), $text);
* Filters textarea form data in DB for display
* @param bool $html allow html?
* @param bool $smiley allow smileys?
* @param bool $xcode allow xoopscode?
* @param bool $image allow inline images?
* @param bool $br convert linebreaks?
function &displayTarea( $text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
$text = $this->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
$text = $this->nl2Br($text);
$text = $this->codeConv($text, $xcode, $image); // Ryuji_edit(2003-11-18)
* Filters textarea form data submitted for preview
* @param bool $html allow html?
* @param bool $smiley allow smileys?
* @param bool $xcode allow xoopscode?
* @param bool $image allow inline images?
* @param bool $br convert linebreaks?
function &previewTarea( $text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1)
$text = $this->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18)
$text = $this->nl2Br($text);
$text = $this->codeConv($text, $xcode, $image); // Ryuji_edit(2003-11-18)
* Replaces banned words in a string with their replacements
$replacement = $this->censorConf['censor_replace'];
foreach ($this->censorConf['censor_words'] as $bad) {
$patterns[] = "/(\s)". $bad. "/siU";
$replacements[] = "\\1". $replacement;
$patterns[] = "/^". $bad. "/siU";
$replacements[] = $replacement;
$patterns[] = "/(\n)". $bad. "/siU";
$replacements[] = "\\1". $replacement;
$patterns[] = "/]". $bad. "/siU";
$replacements[] = "]". $replacement;
* Sanitizing of [code] tag
$patterns = "/\[code](.*)\[\/code\]/esU";
$replacements = "'[code]'.base64_encode('$1').'[/code]'";
function codeConv($text, $xcode = 1, $image = 1){
$patterns = "/\[code](.*)\[\/code\]/esU";
$replacements = "'<div class=\"xoopsCode\"><code><pre>'.MyTextSanitizer::codeSanitizer('$1').'</pre></code></div>'";
//$text =& $this->xoopsCodeDecode($text);
$replacements = "'<div class=\"xoopsCode\"><code><pre>'.MyTextSanitizer::codeSanitizer('$1', 0).'</pre></code></div>'";
//$text =& $this->xoopsCodeDecode($text, 0);
##################### Deprecated Methods ######################
//$config =& $GLOBALS['xoopsConfig'];
//$allowed = $config['allowed_html'];
//$text = strip_tags($text, $allowed);
$text = $this->nl2Br($text);
//$config =& $GLOBALS['xoopsConfig'];
//$allowed = $config['allowed_html'];
//$text = strip_tags($text, $allowed);
$text = $this->nl2Br($text);
//$text = $this->undoHtmlSpecialChars($text);
//if magic_quotes_gpc is on, do stipslashes
return $this->nl2br($text);
|