27 '@<iframe[^>]*?>.*?</iframe>@si',
28 '@<script[^>]*?>.*?</script>@si',
29 '@<style[^>]*?>.*?</style>@si',
30 '@<html[^>]*?>.*?</html>@si',
31 '@<body[^>]*?>.*?</body>@si',
32 '@<meta[^>]*?>.*?</meta>@si'
39 if (!isset($instance)) {
56 if (!empty($this->emots))
61 $this->emots[] = array(
'code'=>array(
':)',
':-)'),
'icon'=>
$url.
'/smile.png');
62 $this->emots[] = array(
'code'=>array(
':-S',
'O.o'),
'icon'=>
$url.
'/confused.png');
63 $this->emots[] = array(
'code'=>array(
":'("),
'icon'=>
$url.
'/cry.png');
64 $this->emots[] = array(
'code'=>array(
':->',
':>'),
'icon'=>
$url.
'/grin.png');
65 $this->emots[] = array(
'code'=>array(
':D',
':-D'),
'icon'=>
$url.
'/happy.png');
66 $this->emots[] = array(
'code'=>array(
':-O',
':-o',
':O',
':o'),
'icon'=>
$url.
'/surprised.png');
67 $this->emots[] = array(
'code'=>array(
':p',
':-p',
':-P',
':P'),
'icon'=>
$url.
'/tongue.png');
68 $this->emots[] = array(
'code'=>array(
':-(',
':('),
'icon'=>
$url.
'/unhappy.png');
69 $this->emots[] = array(
'code'=>array(
';)',
';-)'),
'icon'=>
$url.
'/wink.png');
70 $this->emots[] = array(
'code'=>array(
':-|'),
'icon'=>
$url.
'/neutral.png');
71 $this->emots[] = array(
'code'=>array(
'8)',
'8-)',
'B)',
'B-)'),
'icon'=>
$url.
'/cool.png');
72 $this->emots[] = array(
'code'=>array(
'>:(',
'>:-('),
'icon'=>
$url.
'/mad.png');
73 $this->emots[] = array(
'code'=>array(
':oops:'),
'icon'=>
$url.
'/red.png');
74 $this->emots[] = array(
'code'=>array(
':roll:'),
'icon'=>
$url.
'/roll.png');
75 $this->emots[] = array(
'code'=>array(
'X-D',
'x-D'),
'icon'=>
$url.
'/yell.png');
78 $this->emots =
RMEvents::get()->run_event(
'rmcommon.get_emotions', $this->emots);
94 foreach ($v[
'code'] as $code){
96 $icons[] =
'<img src="'.$v[
'icon'].
'" alt="" />';
99 $message = str_replace($codes,$icons,$message);
110 $string =
' ' . $string;
112 $string = preg_replace_callback(
'#(?<=[\s>])(\()?([\w]+?://(?:[\w\\x80-\\xff\#$%&~/\-=?@\[\](+]|[.,;:](?![\s<])|(?(1)\)(?![\s<])|\)))+)#is',
"url_clickable", $string);
113 $string = preg_replace_callback(
'#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]+)#is',
'ftp_clickable', $string);
114 $string = preg_replace_callback(
'#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i',
'mail_clickable', $string);
116 $string = preg_replace(
"#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i",
"$1$3</a>", $string);
117 $string = trim($string);
125 $text = preg_replace_callback(
'|<a (.+?)>|i',
'rel_nofollow', $text);
130 $text = preg_replace(
'/<a (.+?)>/i',
"<a $1 target='_blank' rel='external'>", $text);
146 return $matches[1] .
"<a href=\"$url\" rel=\"nofollow\">$url</a>";
152 $dest =
'http://' . $dest;
153 $dest = self::clean_url($dest);
157 if ( in_array(substr($dest, -1), array(
'.',
',',
';',
':')) ===
true ) {
158 $ret = substr($dest, -1);
159 $dest = substr($dest, 0, strlen($dest)-1);
161 return $matches[1] .
"<a href=\"$dest\" rel=\"nofollow\">$dest</a>" .
$ret;
164 $email = $matches[2] .
'@' . $matches[3];
165 return $matches[1] .
"<a href=\"mailto:$email\">$email</a>";
182 $original_url =
$url;
185 $url = preg_replace(
'|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]|i',
'',
$url);
186 $strip = array(
'%0d',
'%0a',
'%0D',
'%0A');
188 $url = str_replace(
';//',
'://',
$url);
193 if ( strpos(
$url,
':') ===
false &&
194 substr(
$url, 0, 1 ) !=
'/' && substr(
$url, 0, 1 ) !=
'#' && !preg_match(
'/^[a-z0-9-]+?\.php/i',
$url) )
198 if (
'display' == $context ) {
199 $url = preg_replace(
'/&([^#])(?![a-z]{2,8};)/',
'&$1',
$url);
200 $url = str_replace(
"'",
''',
$url );
204 $protocols = array(
'http',
'https',
'ftp',
'ftps',
'mailto',
'news',
'irc',
'gopher',
'nntp',
'feed',
'telnet');
211 return RMEvents::get()->run_event(
'rmcommon.clean_url',
$url, $original_url, $context);
216 $string2 = $string.
'a';
218 while ($string != $string2) {
228 $string2 = preg_split(
'/:|:|:/i', $string, 2);
229 if ( isset($string2[1]) && !preg_match(
'%/\?%', $string2[0]) )
232 $string = preg_replace_callback(
'/^((&[^;]*;|[\sA-Za-z0-9])*)'.
'(:|:|&#[Xx]3[Aa];)\s*/',
'bad_protocol_once2', $string);
241 if ( is_array($matches) ) {
242 if ( ! isset($matches[1]) || empty($matches[1]) )
245 $string = $matches[1];
251 $string2 = preg_replace(
'/\s/',
'', $string2);
253 $string2 = strtolower($string2);
256 foreach ( (array) $allowed_protocols as $one_protocol)
257 if (strtolower($one_protocol) == $string2) {
269 $string = preg_replace_callback(
'/&#([0-9]+);/',
'decode_entities_chr', $string);
270 $string = preg_replace_callback(
'/&#[Xx]([0-9A-Fa-f]+);/',
'decode_entities_chr_hexdec', $string);
276 return chr( $match[1] );
280 return chr( hexdec( $match[1] ) );
284 $string = preg_replace(
'/\0+/',
'', $string);
285 $string = preg_replace(
'/(\\\\0)+/',
'', $string);
294 foreach( (array) $search as $val ) {
295 while(strpos($subject, $val) !==
false) {
297 $subject = str_replace($val,
'', $subject);
312 $text = preg_replace(
"[\n|\r|\n\r]",
' ', $text);
313 $ret = substr(strip_tags($text), 0, $len);
315 if (strlen($text)>$len)
$ret .=
'...';
330 $replacements = array();
335 $patterns[
'patterns'][] =
"/\[siteurl=(['\"]?)([^\"'<>]*)\\1](.*)\[\/siteurl\]/sU";
336 $patterns[
'replacements'][] =
'<a href="'.XOOPS_ROOT_PATH.
'/\\2">\\3</a>';
337 $patterns[
'patterns'][] =
"/\[url=(['\"]?)(http[s]?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
338 $patterns[
'replacements'][] =
'<a href="\\2" target="_blank">\\3</a>';
339 $patterns[
'patterns'][] =
"/\[url=(['\"]?)(ftp?:\/\/[^\"'<>]*)\\1](.*)\[\/url\]/sU";
340 $patterns[
'replacements'][] =
'<a href="\\2" target="_blank">\\3</a>';
341 $patterns[
'patterns'][] =
"/\[url=(['\"]?)([^\"'<>]*)\\1](.*)\[\/url\]/sU";
342 $patterns[
'replacements'][] =
'<a href="http://\\2" target="_blank">\\3</a>';
343 $patterns[
'patterns'][] =
"/\[color=(['\"]?)([a-zA-Z0-9]*)\\1](.*)\[\/color\]/sU";
344 $patterns[
'replacements'][] =
'<span style="color: #\\2;">\\3</span>';
345 $patterns[
'patterns'][] =
"/\[size=(['\"]?)([a-z0-9-]*)\\1](.*)\[\/size\]/sU";
346 $patterns[
'replacements'][] =
'<span style="font-size: \\2;">\\3</span>';
347 $patterns[
'patterns'][] =
"/\[font=(['\"]?)([^;<>\*\(\)\"']*)\\1](.*)\[\/font\]/sU";
348 $patterns[
'replacements'][] =
'<span style="font-family: \\2;">\\3</span>';
349 $patterns[
'patterns'][] =
"/\[email]([^;<>\*\(\)\"']*)\[\/email\]/sU";
350 $patterns[
'replacements'][] =
'<a href="mailto:\\1">\\1</a>';
352 $patterns[
'patterns'][] =
"/\[b](.*)\[\/b\]/sU";
353 $patterns[
'replacements'][] =
'<b>\\1</b>';
354 $patterns[
'patterns'][] =
"/\[i](.*)\[\/i\]/sU";
355 $patterns[
'replacements'][] =
'<i>\\1</i>';
356 $patterns[
'patterns'][] =
"/\[u](.*)\[\/u\]/sU";
357 $patterns[
'replacements'][] =
'<u>\\1</u>';
358 $patterns[
'patterns'][] =
"/\[d](.*)\[\/d\]/sU";
359 $patterns[
'replacements'][] =
'<del>\\1</del>';
361 $patterns[
'patterns'][] =
"/\[quote(=(.*)){0,1}\](.*)\[\/quote\]/";
362 $patterns[
'replacements'][] =
'<blockquote>$3<p class="citeby">$2</p></blockquote>';
364 $patterns[
'patterns'][] =
"/\[img align=(['\"]?)(left|center|right)\\1]([^\"\(\)'<>]*)\[\/img\]/sU";
365 $patterns[
'patterns'][] =
"/\[img]([^\"\(\)'<>]*)\[\/img\]/sU";
366 $patterns[
'patterns'][] =
"/\[img align=(['\"]?)(left|center|right)\\1 id=(['\"]?)([0-9]*)\\3]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
367 $patterns[
'patterns'][] =
"/\[img id=(['\"]?)([0-9]*)\\1]([^\"\(\)\?\&'<>]*)\[\/img\]/sU";
369 if ($allowimage != 1) {
370 $patterns[
'replacements'][] =
'<a href="\\3" target="_blank">\\3</a>';
371 $patterns[
'replacements'][] =
'<a href="\\1" target="_blank">\\1</a>';
372 $patterns[
'replacements'][] =
'<a href="'.XOOPS_ROOT_PATH.
'/image.php?id=\\4" target="_blank">\\4</a>';
373 $patterns[
'replacements'][] =
'<a href="'.XOOPS_ROOT_PATH.
'/image.php?id=\\2" target="_blank">\\3</a>';
375 $patterns[
'replacements'][] =
'<img src="\\3" align="\\2" alt="" />';
376 $patterns[
'replacements'][] =
'<img src="\\1" alt="" />';
377 $patterns[
'replacements'][] =
'<img src="'.XOOPS_ROOT_PATH.
'/image.php?id=\\4" align="\\2" alt="\\4" />';
378 $patterns[
'replacements'][] =
'<img src="'.XOOPS_ROOT_PATH.
'/image.php?id=\\2" alt="\\3" />';
381 $text = str_replace(
"\x00",
"", $text );
383 $patterns[
'patterns'][] =
"/j{$c}a{$c}v{$c}a{$c}s{$c}c{$c}r{$c}i{$c}p{$c}t{$c}:/si";
384 $patterns[
'replacements'][] =
"(script removed)";
385 $patterns[
'patterns'][] =
"/a{$c}b{$c}o{$c}u{$c}t{$c}:/si";
386 $patterns[
'replacements'][] =
"about :";
389 $patterns =
RMEvents::get()->run_event(
'rmcommon.get.replace.patterns', $patterns, $this);
391 $text = preg_replace($patterns[
'patterns'], $patterns[
'replacements'], $text);
393 $text =
RMEvents::get()->run_event(
'rmcommon.code.decode',$text);
407 return preg_replace(
"/(\015\012)|(\015)|(\012)/",
"<br />",$text);
418 if (get_magic_quotes_gpc()) {
432 if (get_magic_quotes_gpc()) {
445 function specialchars($string, $quote_style = ENT_NOQUOTES, $charset =
'UTF-8')
447 if ( 0 === strlen( $string ) ) {
451 if ( !preg_match(
'/[&<>"\']/', $string ) ) {
455 if ( empty( $quote_style ) ) {
456 $quote_style = ENT_NOQUOTES;
457 }
elseif ( !in_array( $quote_style, array( 0, 2, 3,
'single',
'double' ),
true ) ) {
458 $quote_style = ENT_QUOTES;
461 if ( in_array( $charset, array(
'utf8',
'utf-8',
'UTF8' ) ) ) {
465 if ( $quote_style ===
'double' ) {
466 $quote_style = ENT_COMPAT;
467 $_quote_style = ENT_COMPAT;
468 }
elseif ( $quote_style ===
'single' ) {
469 $quote_style = ENT_NOQUOTES;
472 $string = @htmlspecialchars( $string, $quote_style, $charset );
475 return preg_replace(array(
"/&/i",
"/ /i"), array(
'&',
'&nbsp;'), htmlspecialchars($string, ENT_QUOTES));
486 if ( 0 === strlen( $string ) ) {
491 if ( strpos( $string,
'&' ) ===
false ) {
495 if ( empty( $quote_style ) ) {
496 $quote_style = ENT_NOQUOTES;
497 }
elseif ( !in_array( $quote_style, array( 0, 2, 3,
'single',
'double' ),
true ) ) {
498 $quote_style = ENT_QUOTES;
502 $single = array(
''' =>
'\'',
''' =>
'\'' );
503 $single_preg = array(
'/�*39;/' =>
''',
'/�*27;/i' =>
''' );
504 $double = array(
'"' =>
'"',
'"' =>
'"',
'"' =>
'"' );
505 $double_preg = array(
'/�*34;/' =>
'"',
'/�*22;/i' =>
'"' );
506 $others = array(
'<' =>
'<',
'<' =>
'<',
'>' =>
'>',
'>' =>
'>',
'&' =>
'&',
'&' =>
'&',
'&' =>
'&' );
507 $others_preg = array(
'/�*60;/' =>
'<',
'/�*62;/' =>
'>',
'/�*38;/' =>
'&',
'/�*26;/i' =>
'&' );
509 if ( $quote_style === ENT_QUOTES ) {
510 $translation = array_merge( $single, $double, $others );
511 $translation_preg = array_merge( $single_preg, $double_preg, $others_preg );
512 }
elseif ( $quote_style === ENT_COMPAT || $quote_style ===
'double' ) {
513 $translation = array_merge( $double, $others );
514 $translation_preg = array_merge( $double_preg, $others_preg );
515 }
elseif ( $quote_style ===
'single' ) {
516 $translation = array_merge( $single, $others );
517 $translation_preg = array_merge( $single_preg, $others_preg );
518 }
elseif ( $quote_style === ENT_NOQUOTES ) {
519 $translation = $others;
520 $translation_preg = $others_preg;
523 $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string );
525 return strtr( $string, $translation );
544 if ( trim($string) ===
'' )
546 $string = $string .
"\n";
547 $string = preg_replace(
'|<br />\s*<br />|',
"\n\n", $string);
549 $allblocks =
'(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
550 $string = preg_replace(
'!(<' . $allblocks .
'[^>]*>)!',
"\n$1", $string);
551 $string = preg_replace(
'!(</' . $allblocks .
'>)!',
"$1\n\n", $string);
552 $string = str_replace(array(
"\r\n",
"\r"),
"\n", $string);
553 if ( strpos($string,
'<object') !==
false ) {
554 $string = preg_replace(
'|\s*<param([^>]*)>\s*|',
"<param$1>", $string);
555 $string = preg_replace(
'|\s*</embed>\s*|',
'</embed>', $string);
557 $string = preg_replace(
"/\n\n+/",
"\n\n", $string);
559 $strings = preg_split(
'/\n\s*\n/', $string, -1, PREG_SPLIT_NO_EMPTY);
561 foreach ( $strings as $tinkle )
562 $string .=
'<p>' . trim($tinkle,
"\n") .
"</p>\n";
563 $string = preg_replace(
'|<p>\s*</p>|',
'', $string);
564 $string = preg_replace(
'!<p>([^<]+)</(div|address|form)>!',
"<p>$1</p></$2>", $string);
565 $string = preg_replace(
'!<p>\s*(</?' . $allblocks .
'[^>]*>)\s*</p>!',
"$1", $string);
566 $string = preg_replace(
"|<p>(<li.+?)</p>|",
"$1", $string);
567 $string = preg_replace(
'|<p><blockquote([^>]*)>|i',
"<blockquote$1><p>", $string);
568 $string = str_replace(
'</blockquote></p>',
'</p></blockquote>', $string);
569 $string = preg_replace(
'!<p>\s*(</?' . $allblocks .
'[^>]*>)!',
"$1", $string);
570 $string = preg_replace(
'!(</?' . $allblocks .
'[^>]*>)\s*</p>!',
"$1", $string);
572 $string = preg_replace_callback(
'/<(script|style).*?<\/\\1>/s', create_function(
'$matches',
'return str_replace("\n", "<EXMPreserveNewline />", $matches[0]);'), $string);
573 $string = preg_replace(
'|(?<!<br />)\s*\n|',
"<br />\n", $string);
574 $string = str_replace(
'<EXMPreserveNewline />',
"\n", $string);
576 $string = preg_replace(
'!(</?' . $allblocks .
'[^>]*>)\s*<br />!',
"$1", $string);
577 $string = preg_replace(
'!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!',
'$1', $string);
578 if (strpos($string,
'<pre') !==
false)
579 $string = preg_replace_callback(
'!(<pre[^>]*>)(.*?)</pre>!is',
'TextCleaner::clean_pre', $string );
596 function to_display($text, $dbr =
true, $clean_tags =
true, $paragraph =
true){
600 $original_text = $text;
609 $text = $this->
smiley($text);
617 $text = $this->
nl2Br($text);
622 if($paragraph) $text = $this->
double_br($text);
626 $text = $rmCodes->doCode($text);
629 return RMEvents::get()->run_event(
'rmcommon.text.todisplay', $text, $original_text);
634 $this->disable_tags =
RMEvents::get()->run_event(
'rmcommon.more.disabled.tags', $this->disable_tags);
636 $text = preg_replace_callback($this->disable_tags,
"preg_striptags",$text);
646 $patterns =
"/\[code([^\]]*?)\](.*)\[\/code\]/esU";
647 $replacements =
"'[code$1]'.base64_encode('$2').'[/code]'";
648 $text = preg_replace($patterns, $replacements, $text);
657 $patterns =
"/\[code([^\]]*?)\](.*)\[\/code\]/esU";
658 $replacements =
"'<div class=\"xoopsCode\"><code>'.\$this->call_code_modifiers(\$this->specialchars(str_replace('\\\"', '\"', base64_decode('$2'))), '$1').'</code></div>'";
659 $text = preg_replace($patterns, $replacements, $text);
687 if ( is_array($matches) )
688 $text = $matches[1] . $matches[2] .
"</pre>";
692 $text = str_replace(
'<br />',
'', $text);
693 $text = str_replace(
'<p>',
"\n", $text);
694 $text = str_replace(
'</p>',
'', $text);
706 public function encrypt($string, $encode64 =
true){
710 $string = $crypt->encrypt($string);
722 public function decrypt($string, $encode64 =
true){
727 $string = $crypt->decrypt($string);
739 $rtn = $lower ? strtolower(utf8_decode($value)) : $value;
742 $find = array(
'á',
'é',
'í',
'ó',
'ú',
'ñ');
743 $repl = array(
'a',
'e',
'i',
'o',
'u',
'n');
744 $rtn = str_replace ($find, $repl, utf8_encode(
$rtn));
747 $find = array(
' ',
'&',
'\r\n',
'\n',
'+');
748 $rtn = str_replace ($find,
'-',
$rtn);
751 $find = array(
'/[^a-zA-Z0-9\-<>_]/',
'/[\-]+/',
'/<[^>]*>/');
752 $repl = array(
'',
'-',
'');
753 $url = preg_replace ($find, $repl,
$rtn);
783 $text = str_replace(array(
' rel="nofollow"',
" rel='nofollow'"),
'', $text);
784 return "<a $text rel=\"nofollow\">";
789 if(is_array($match)){
790 foreach($match as
$i => $t){