25 public static function getInstance() {
27 if ( ! isset( $instance ) ) {
28 $instance =
new TextSanitizer();
34 public function &makeClickable( &$text ) {
36 if (!mb_check_encoding($text,
'UTF-8')) {
37 $text = mb_convert_encoding($text,
'UTF-8',
'auto');
41 "/([^]_a-z0-9-=\"'\/])([a-z]+?):\/\/([^, \r\n\"\(\)'<>]+)/iu",
42 "/([^]_a-z0-9-=\"'\/])www\.([a-z0-9\-]+)\.([^, \r\n\"\(\)'<>]+)/iu",
43 "/([^]_a-z0-9-=\"'\/])([a-z0-9\-_.]+?)@([^, \r\n\"\(\)'<>]+)/iu"
46 "\\1<a href=\"\\2://\\3\" rel=\"external\">\\2://\\3</a>",
47 "\\1<a href=\"https://www.\\2.\\3\" rel=\"external\">www.\\2.\\3</a>",
48 "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>"
50 $ret = preg_replace( $patterns, $replacements, $text );
55 public function &nl2Br( $text ) {
57 if (!mb_check_encoding($text,
'UTF-8')) {
58 $text = mb_convert_encoding($text,
'UTF-8',
'auto');
61 $ret = preg_replace(
"/(\015\012)|(\015)|(\012)/u",
'<br>', $text );
66 public function &addSlashes( $text, $force =
false ) {
68 if (!mb_check_encoding($text,
'UTF-8')) {
69 $text = mb_convert_encoding($text,
'UTF-8',
'auto');
74 if (function_exists(
'mb_ereg_replace')) {
75 $ret = mb_ereg_replace(
'([\'\"\\\\])',
'\\\\\\1', $text);
77 $ret = addslashes( $text );
88 public function &stripSlashesGPC( $text ) {
96 public function &htmlSpecialChars( $text ) {
98 if (!mb_check_encoding($text,
'UTF-8')) {
99 $text = mb_convert_encoding($text,
'UTF-8',
'auto');
102 $text = preg_replace(
'/&/i',
'&', htmlspecialchars( $text, ENT_QUOTES,
'UTF-8' ));
107 public function &undoHtmlSpecialChars( &$text ) {
108 $ret = preg_replace( [
113 ], [
'>',
'<',
'"',
"'" ], $text );
121 public function &displayText( $text, $html =
false ) {
124 $text =& $this->htmlSpecialChars( $text );
126 $text =& $this->makeClickable( $text );
127 $text =& $this->nl2Br( $text );
135 public function &previewText( $text, $html =
false ) {
136 $text =& $this->stripSlashesGPC( $text );
138 return $this->displayText( $text, $html );
141##################### Deprecated Methods ######################
143 public function sanitizeForDisplay( $text, $allowhtml = 0, $smiley = 1, $bbcode = 1 ) {
144 $text = 0 === $allowhtml ? $this->htmlSpecialChars( $text ) : $this->makeClickable( $text );
145 if ( 1 === $smiley ) {
146 $text = $this->smiley( $text );
148 if ( 1 === $bbcode ) {
149 $text = $this->xoopsCodeDecode( $text );
151 $text = $this->nl2Br( $text );
156 public function sanitizeForPreview( $text, $allowhtml = 0, $smiley = 1, $bbcode = 1 ) {
157 $text = $this->oopsStripSlashesGPC( $text );
158 $text = 0 === $allowhtml ? $this->htmlSpecialChars( $text ) : $this->makeClickable( $text );
159 if ( 1 === $smiley ) {
160 $text = $this->smiley( $text );
162 if ( 1 === $bbcode ) {
163 $text = $this->xoopsCodeDecode( $text );
165 $text = $this->nl2Br( $text );
170 public function makeTboxData4Save( $text ) {
172 return $this->addSlashes( $text );
175 public function makeTboxData4Show( $text, $smiley = 0 ) {
176 $text = $this->htmlSpecialChars( $text );
181 public function makeTboxData4Edit( $text ) {
182 return $this->htmlSpecialChars( $text );
185 public function makeTboxData4Preview( $text, $smiley = 0 ) {
186 $text = $this->stripSlashesGPC( $text );
187 $text = $this->htmlSpecialChars( $text );
192 public function makeTboxData4PreviewInForm( $text ) {
193 $text = $this->stripSlashesGPC( $text );
195 return $this->htmlSpecialChars( $text );
198 public function makeTareaData4Save( $text ) {
199 return $this->addSlashes( $text );
202 public function &makeTareaData4Show( &$text, $html = 1, $smiley = 1, $xcode = 1 ) {
203 return $this->displayTarea( $text, $html, $smiley, $xcode );
206 public function makeTareaData4Edit( $text ) {
207 return htmlSpecialChars( $text, ENT_QUOTES );
210 public function &makeTareaData4Preview( &$text, $html = 1, $smiley = 1, $xcode = 1 ) {
211 return $this->previewTarea( $text, $html, $smiley, $xcode );
214 public function makeTareaData4PreviewInForm( $text ) {
215 return htmlSpecialChars( $text, ENT_QUOTES );
218 public function makeTareaData4InsideQuotes( $text ) {
219 return $this->htmlSpecialChars( $text );
222 public function &oopsStripSlashesGPC( $text ) {
223 return $this->stripSlashesGPC( $text );
226 public function &oopsStripSlashesRT( $text ) {
231 public function &oopsAddSlashes( $text ) {
232 return $this->addSlashes( $text );
235 public function &oopsHtmlSpecialChars( $text ) {
236 return $this->htmlSpecialChars( $text );
239 public function &oopsNl2Br( $text ) {
240 return $this->nl2br( $text );