1<?php 2 3/* 4 [UCenter] (C)2001-2099 Comsenz Inc. 5 This is NOT a freeware, use is subject to license terms 6 7 $Id: uccode.class.php 1166 2014-11-03 01:49:32Z hypowang $ 8*/ 9 10class uccode { 11 var $uccodes; 12 13 function __construct() { 14 $this->uccode(); 15 } 16 17 function uccode() { 18 $this->uccode = array( 19 'pcodecount' => -1, 20 'codecount' => 0, 21 'codehtml' => '' 22 ); 23 } 24 25 function codedisp($code) { 26 $this->uccode['pcodecount']++; 27 $code = str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)); 28 $this->uccode['codehtml'][$this->uccode['pcodecount']] = $this->tpl_codedisp($code); 29 $this->uccode['codecount']++; 30 return "[\tUCENTER_CODE_".$this->uccode[pcodecount]."\t]"; 31 } 32 33 function complie($message) { 34 $message = dhtmlspecialchars($message); 35 if(strpos($message, '[/code]') !== FALSE) { 36 $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "\$this->codedisp('\\1')", $message); 37 } 38 if(strpos($message, '[/url]') !== FALSE) { 39 $message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)([^\[\"']+?))?\](.+?)\[\/url\]/ies", "\$this->parseurl('\\1', '\\5')", $message); 40 } 41 if(strpos($message, '[/email]') !== FALSE) { 42 $message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "\$this->parseemail('\\1', '\\4')", $message); 43 } 44 $message = str_replace(array( 45 '[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', 46 '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]', 47 '[list=A]', '[*]', '[/list]', '[indent]', '[/indent]', '[/float]' 48 ), array( 49 '</font>', '</font>', '</font>', '</p>', '<strong>', '</strong>', '<i>', 50 '</i>', '<u>', '</u>', '<ul>', '<ul type="1">', '<ul type="a">', 51 '<ul type="A">', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>' 52 ), preg_replace(array( 53 "/\[color=([#\w]+?)\]/i", 54 "/\[size=(\d+?)\]/i", 55 "/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i", 56 "/\[font=([^\[\<]+?)\]/i", 57 "/\[align=(left|center|right)\]/i", 58 "/\[float=(left|right)\]/i" 59 ), array( 60 "<font color=\"\\1\">", 61 "<font size=\"\\1\">", 62 "<font style=\"font-size: \\1\">", 63 "<font face=\"\\1 \">", 64 "<p align=\"\\1\">", 65 "<span style=\"float: \\1;\">" 66 ), $message)); 67 if(strpos($message, '[/quote]') !== FALSE) { 68 $message = preg_replace("/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", $this->tpl_quote(), $message); 69 } 70 if(strpos($message, '[/img]') !== FALSE) { 71 $message = preg_replace(array( 72 "/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies", 73 "/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies" 74 ), array( 75 "\$this->bbcodeurl('\\1', '<img src=\"%s\" border=\"0\" alt=\"\" />')", 76 "\$this->bbcodeurl('\\3', '<img width=\"\\1\" height=\"\\2\" src=\"%s\" border=\"0\" alt=\"\" />')" 77 ), $message); 78 } 79 for($i = 0; $i <= $this->uccode['pcodecount']; $i++) { 80 $message = str_replace("[\tUCENTER_CODE_$i\t]", $this->uccode['codehtml'][$i], $message); 81 } 82 return nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message)); 83 } 84 85 function parseurl($url, $text) { 86 if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) { 87 $url = $matches[0]; 88 $length = 65; 89 if(strlen($url) > $length) { 90 $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3)); 91 } 92 return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>'; 93 } else { 94 $url = substr($url, 1); 95 if(substr(strtolower($url), 0, 4) == 'www.') { 96 $url = 'http://'.$url; 97 } 98 return '<a href="'.$url.'" target="_blank">'.$text.'</a>'; 99 } 100 } 101 102 function parseemail($email, $text) { 103 $text = str_replace('\"', '"', $text); 104 if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) { 105 $email = trim($matches[0]); 106 return '<a href="mailto:'.$email.'">'.$email.'</a>'; 107 } else { 108 return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>'; 109 } 110 } 111 112 function bbcodeurl($url, $tags) { 113 if(!preg_match("/<.+?>/s", $url)) { 114 if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) { 115 $url = 'http://'.$url; 116 } 117 return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url))); 118 } else { 119 return ' '.$url; 120 } 121 } 122 123 function tpl_codedisp($code) { 124 return '<div class="blockcode"><code id="code'.$this->uccodes['codecount'].'">'.$code.'</code></div>'; 125 } 126 127 function tpl_quote() { 128 return '<div class="quote"><blockquote>\\1</blockquote></div>'; 129 } 130} 131 132 133?>