function_followcode.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_followcode.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $_G['post_attach'] = array();
  12. function fcodedisp($code, $type='codehtml') {
  13. global $_G;
  14. $_G['forum_discuzcode']['pcodecount']++;
  15. $_G['forum_discuzcode'][$type][$_G['forum_discuzcode']['pcodecount']] = $code;
  16. $_G['forum_discuzcode']['codecount']++;
  17. return "[\tD_".$_G['forum_discuzcode']['pcodecount']."\t]";
  18. }
  19. function followcode($message, $tid = 0, $pid = 0, $length = 0, $allowimg = true) {
  20. global $_G;
  21. include_once libfile('function/post');
  22. $message = strip_tags($message);
  23. $message = messagesafeclear($message);
  24. if((strpos($message, '[/code]') || strpos($message, '[/CODE]')) !== FALSE) {
  25. $message = preg_replace("/\s?\[code\](.+?)\[\/code\]\s?/is", "", $message);
  26. }
  27. $msglower = strtolower($message);
  28. $htmlon = 0;
  29. $message = dhtmlspecialchars($message);
  30. if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  31. $_G['discuzcodemessage'] = & $message;
  32. $param = func_get_args();
  33. hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'discuzcode'), 'discuzcode');
  34. }
  35. $_G['delattach'] = array();
  36. $message = fparsesmiles($message);
  37. if(strpos($msglower, 'attach://') !== FALSE) {
  38. $message = preg_replace("/attach:\/\/(\d+)\.?(\w*)/i", '', $message);
  39. }
  40. if(strpos($msglower, 'ed2k://') !== FALSE) {
  41. $message = preg_replace("/ed2k:\/\/(.+?)\//", '', $message);
  42. }
  43. if(strpos($msglower, '[/i]') !== FALSE) {
  44. $message = preg_replace("/\s*\[i=s\][\n\r]*(.+?)[\n\r]*\[\/i\]\s*/is", '', $message);
  45. }
  46. $message = str_replace('[/p]', "\n", $message);
  47. $message = str_replace(array(
  48. '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]',
  49. '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
  50. '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
  51. ), '', preg_replace(array(
  52. "/\[color=([#\w]+?)\]/i",
  53. "/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
  54. "/\[backcolor=([#\w]+?)\]/i",
  55. "/\[backcolor=((rgb|rgba)\([\d\s,]+?\))\]/i",
  56. "/\[size=(\d{1,2}?)\]/i",
  57. "/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
  58. "/\[font=([^\[\<]+?)\]/i",
  59. "/\[align=(left|center|right)\]/i",
  60. "/\[float=left\]/i",
  61. "/\[float=right\]/i"
  62. ), '', $message));
  63. if(strpos($msglower, '[/p]') !== FALSE) {
  64. $message = preg_replace("/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i", "<p style=\"line-height:\\1px;text-indent:\\2em;text-align:left;\">", $message);
  65. $message = str_replace('[/p]', '</p>', $message);
  66. }
  67. if(strpos($msglower, '[/quote]') !== FALSE) {
  68. $message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", '', $message);
  69. }
  70. if(strpos($msglower, '[/free]') !== FALSE) {
  71. $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", '', $message);
  72. }
  73. if(isset($_G['cache']['bbcodes'][-$allowbbcode])) {
  74. $message = preg_replace($_G['cache']['bbcodes'][-$allowbbcode]['searcharray'], '', $message);
  75. }
  76. if(strpos($msglower, '[/hide]') !== FALSE) {
  77. preg_replace_callback("/\[hide.*?\]\s*(.*?)\s*\[\/hide\]/is", 'followcode_callback_hideattach_1', $message);
  78. if(strpos($msglower, '[hide]') !== FALSE) {
  79. $message = preg_replace("/\[hide\]\s*(.*?)\s*\[\/hide\]/is", '', $message);
  80. }
  81. if(strpos($msglower, '[hide=') !== FALSE) {
  82. $message = preg_replace("/\[hide=(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/is", '', $message);
  83. }
  84. }
  85. if(strpos($msglower, '[/url]') !== FALSE) {
  86. $message = preg_replace_callback("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/is", 'followcode_callback_fparseurl_152', $message);
  87. }
  88. if(strpos($msglower, '[/email]') !== FALSE) {
  89. $message = preg_replace_callback("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/is", 'followcode_callback_fparseemail_14', $message);
  90. }
  91. $nest = 0;
  92. while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){
  93. $message = preg_replace_callback("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/is", 'followcode_callback_fparsetable_123', $message);
  94. if(++$nest > 4) break;
  95. }
  96. if(strpos($msglower, '[/media]') !== FALSE) {
  97. $message = preg_replace_callback("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/is", 'followcode_callback_fparsemedia_12', $message);
  98. }
  99. if(strpos($msglower, '[/audio]') !== FALSE) {
  100. $message = preg_replace_callback("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/is", 'followcode_callback_fparseaudio_2', $message);
  101. }
  102. if(strpos($msglower, '[/flash]') !== FALSE) {
  103. $message = preg_replace_callback("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", 'followcode_callback_fparseflash_4', $message);
  104. }
  105. if($parsetype != 1 && strpos($msglower, '[swf]') !== FALSE) {
  106. $message = preg_replace_callback("/\[swf\]\s*([^\[\<\r\n]+?)\s*\[\/swf\]/is", 'followcode_callback_bbcodeurl_1', $message);
  107. }
  108. $flag = $length ? 1 : 0;
  109. if($tid) {
  110. $extra = "onclick=\"changefeed($tid, $pid, $flag, this)\"";
  111. }
  112. if(strpos($msglower, '[/img]') !== FALSE) {
  113. $message = preg_replace_callback("/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", create_function('$matches', 'return '.intval($allowimg).' ? fparseimg($matches[1], \''.addslashes($extra).'\') : \'\';'), $message);
  114. $message = preg_replace_callback("/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", create_function('$matches', 'return '.intval($allowimg).' ? fparseimg($matches[3], \''.addslashes($extra).'\') : \'\';'), $message);
  115. }
  116. if($tid && $pid) {
  117. $_G['post_attach'] = C::t('forum_attachment_n')->fetch_all_by_id(getattachtableid($tid), 'pid', $pid);
  118. foreach($_G['post_attach'] as $aid => $attach) {
  119. if(!empty($_G['delattach']) && in_array($aid, $_G['delattach'])) {
  120. continue;
  121. }
  122. $message .= "[attach]$attach[aid][/attach]";
  123. $message = preg_replace("/\[attach\]$attach[aid]\[\/attach\]/i", fparseattach($attach['aid'], $length, $extra), $message, 1);
  124. }
  125. }
  126. if(strpos($msglower, '[/attach]') !== FALSE) {
  127. $message = preg_replace("/\[attach\]\s*([^\[\<\r\n]+?)\s*\[\/attach\]/is", '', $message);
  128. }
  129. $message = clearnl($message);
  130. if($length) {
  131. $sppos = strpos($message, chr(0).chr(0).chr(0));
  132. if($sppos !== false) {
  133. $message = substr($message, 0, $sppos);
  134. }
  135. $checkstr = cutstr($message, $length, '');
  136. if(strpos($checkstr, '[') && strpos(strrchr($checkstr, "["), ']') === FALSE) {
  137. $length = strpos($message, ']', strrpos($checkstr, strrchr($checkstr, "[")));
  138. }
  139. $message = cutstr($message, $length+1, ' <a href="javascript:;" class="flw_readfull xi2 xs1"'.$extra.'>'.lang('space', 'follow_view_fulltext').'</a>');
  140. } elseif($allowimg && !empty($extra)) {
  141. $message .= '<div class="ptm cl"><a href="javascript:;" class="flw_readfull y xi2 xs1"'.$extra.'>'.lang('space', 'follow_retract').'</a></div>';
  142. }
  143. for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
  144. $code = '';
  145. if(isset($_G['forum_discuzcode']['codehtml'][$i]) && !empty($_G['forum_discuzcode']['codehtml'][$i])) {
  146. $code = $_G['forum_discuzcode']['codehtml'][$i];
  147. } elseif(!$length) {
  148. if(isset($_G['forum_discuzcode']['audio'][$i]) && !empty($_G['forum_discuzcode']['audio'][$i])) {
  149. $code = $_G['forum_discuzcode']['audio'][$i];
  150. } elseif(isset($_G['forum_discuzcode']['video'][$i]) && !empty($_G['forum_discuzcode']['video'][$i])) {
  151. $code = $_G['forum_discuzcode']['video'][$i];
  152. } elseif(isset($_G['forum_discuzcode']['media'][$i]) && !empty($_G['forum_discuzcode']['media'][$i])) {
  153. $code = $_G['forum_discuzcode']['media'][$i];
  154. } elseif(isset($_G['forum_discuzcode']['image'][$i]) && !empty($_G['forum_discuzcode']['image'][$i])) {
  155. $code = $_G['forum_discuzcode']['image'][$i];
  156. } elseif(isset($_G['forum_discuzcode']['attach'][$i]) && !empty($_G['forum_discuzcode']['attach'][$i])) {
  157. $code = $_G['forum_discuzcode']['attach'][$i];
  158. }
  159. }
  160. $message = str_replace("[\tD_$i\t]", $code, $message);
  161. }
  162. $message = clearnl($message);
  163. if(!empty($_GET['highlight'])) {
  164. $highlightarray = explode('+', $_GET['highlight']);
  165. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  166. if($sppos !== FALSE) {
  167. $specialextra = substr($message, $sppos + 3);
  168. $message = substr($message, 0, $sppos);
  169. }
  170. followcode_callback_highlightword_21($highlightarray, 1);
  171. $message = preg_replace_callback("/(^|>)([^<]+)(?=<|$)/sU", 'followcode_callback_highlightword_21', $message);
  172. $message = preg_replace("/<highlight>(.*)<\/highlight>/siU", "<strong><font color=\"#FF0000\">\\1</font></strong>", $message);
  173. if($sppos !== FALSE) {
  174. $message = $message.chr(0).chr(0).chr(0).$specialextra;
  175. }
  176. }
  177. unset($msglower);
  178. if($length) {
  179. $count = 0;
  180. $imagecode = $mediacode = $videocode = $audiocode = $mediahtml = '';
  181. for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
  182. if(isset($_G['forum_discuzcode']['audio'][$i]) && !empty($_G['forum_discuzcode']['audio'][$i])) {
  183. $audiocode .= '<li>'.$_G['forum_discuzcode']['audio'][$attachcodei].'</li>';
  184. } elseif(isset($_G['forum_discuzcode']['video'][$i]) && !empty($_G['forum_discuzcode']['video'][$i])) {
  185. $videocode .= '<li>'.$_G['forum_discuzcode']['video'][$i].'</li>';
  186. } elseif(isset($_G['forum_discuzcode']['media'][$i]) && !empty($_G['forum_discuzcode']['media'][$i])) {
  187. $mediacode .= '<li>'.$_G['forum_discuzcode']['media'][$i].'</li>';
  188. } elseif(isset($_G['forum_discuzcode']['image'][$i]) && !empty($_G['forum_discuzcode']['image'][$i]) && $count < 4) {
  189. $imagecode .= '<li>'.$_G['forum_discuzcode']['image'][$i].'</li>';
  190. $count++;
  191. } elseif(isset($_G['forum_discuzcode']['attach'][$i]) && !empty($_G['forum_discuzcode']['attach'][$i])) {
  192. $attachcode .= '<li>'.$_G['forum_discuzcode']['attach'][$i].'</li>';
  193. }
  194. }
  195. if(!empty($audiocode)) {
  196. $message .= '<div class="flw_music"><ul>'.$audiocode.'</ul></div>';
  197. }
  198. if(!empty($videocode)) {
  199. $message .= '<div class="flw_video"><ul>'.$videocode.'</ul></div>';
  200. }
  201. if(!empty($mediacode)) {
  202. $message .= '<div class="flw_video"><ul>'.$mediacode.'</ul></div>';
  203. }
  204. if(!empty($imagecode)) {
  205. $message = '<div class="flw_image'.($count < 2 ? ' flw_image_1' : '').'"><ul>'.$imagecode.'</ul></div>'.$message;
  206. }
  207. if(!empty($attachcode)) {
  208. $message .= '<div class="flw_attach"><ul>'.$attachcode.'</ul></div>';
  209. }
  210. }
  211. return $htmlon ? $message : nl2br(str_replace(array("\t", ' ', ' '), ' ', $message));
  212. }
  213. function followcode_callback_hideattach_1($matches) {
  214. return hideattach($matches[1]);
  215. }
  216. function followcode_callback_fparseurl_152($matches) {
  217. return fparseurl($matches[1], $matches[5], $matches[2]);
  218. }
  219. function followcode_callback_fparseemail_14($matches) {
  220. return fparseemail($matches[1], $matches[4]);
  221. }
  222. function followcode_callback_fparsetable_123($matches) {
  223. return fparsetable($matches[1], $matches[2], $matches[3]);
  224. }
  225. function followcode_callback_fparsemedia_12($matches) {
  226. return fparsemedia($matches[1], $matches[2]);
  227. }
  228. function followcode_callback_fparseaudio_2($matches) {
  229. return fparseaudio($matches[2]);
  230. }
  231. function followcode_callback_fparseflash_4($matches) {
  232. return fparseflash($matches[4]);
  233. }
  234. function followcode_callback_bbcodeurl_1($matches) {
  235. return bbcodeurl($matches[1], ' <img src="'.STATICURL.'image/filetype/flash.gif" align="absmiddle" alt="" /> <a href="{url}" target="_blank">Flash: {url}</a> ');
  236. }
  237. function followcode_callback_highlightword_21($matches, $action = 0) {
  238. static $highlightarray = array();
  239. if($action == 1) {
  240. $highlightarray = $matches;
  241. } else {
  242. return highlightword($matches[2], $highlightarray, $matches[1]);
  243. }
  244. }
  245. function clearnl($message) {
  246. $message = preg_replace("/[\r\n|\n|\r]\s*[\r\n|\n|\r]/i", "\n", $message);
  247. $message = preg_replace("/^[\r\n|\n|\r]{1,}/i", "", $message);
  248. $message = preg_replace("/[\r\n|\n|\r]{2,}/i", "\n", $message);
  249. return $message;
  250. }
  251. function hideattach($hidestr) {
  252. global $_G;
  253. preg_match_all("/\[attach\]\s*(.*?)\s*\[\/attach\]/is", $hidestr, $del);
  254. foreach($del[1] as $aid) {
  255. $_G['delattach'][$aid] = $aid;
  256. }
  257. }
  258. function fparseurl($url, $text, $scheme) {
  259. global $_G;
  260. $html = '';
  261. if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
  262. $url = $matches[0];
  263. $length = 65;
  264. if(strlen($url) > $length) {
  265. $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  266. }
  267. $html = '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
  268. } else {
  269. $url = substr($url, 1);
  270. if(substr(strtolower($url), 0, 4) == 'www.') {
  271. $url = 'http://'.$url;
  272. }
  273. $url = !$scheme ? $_G['siteurl'].$url : $url;
  274. $atclass = substr(strtolower($text), 0, 1) == '@' ? ' class="xi2" ' : '';
  275. $html = '<a href="'.$url.'" target="_blank" '.$atclass.'>'.$text.'</a>';
  276. }
  277. return fcodedisp($html);
  278. }
  279. function fparseattach($aid, $length = 0, $extra = '') {
  280. global $_G;
  281. $html = '';
  282. if(!empty($_G['post_attach']) && !empty($_G['post_attach'][$aid])) {
  283. $attach = $_G['post_attach'][$aid];
  284. unset($_G['post_attach'][$attach['aid']]);
  285. $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
  286. $attach['isimage'] = $attach['isimage'] && !$attach['price'] ? $attach['isimage'] : 0;
  287. $attach['refcheck'] = (!$attach['remote'] && $_G['setting']['attachrefcheck']) || ($attach['remote'] && ($_G['setting']['ftp']['hideurl'] || ($attach['isimage'] && $_G['setting']['attachimgpost'] && strtolower(substr($_G['setting']['ftp']['attachurl'], 0, 3)) == 'ftp')));
  288. $rimg_id = random(5).$attach['aid'];
  289. if($attach['isimage'] && !$attach['price'] && !$attach['readperm']) {
  290. $nothumb = $length ? 0 : 1;
  291. $src = $attach['url'].(!$attach['thumb'] ? $attach['attachment'] : getimgthumbname($attach['attachment']));
  292. $html = bbcodeurl($src, '<img id="aimg_'.$rimg_id.'" src="'.$src.'" border="0" alt="'.$attach['filename'].'" '.$extra.' style="cursor: pointer;" />');
  293. return fcodedisp($html, 'image');
  294. } else {
  295. if($attach['price'] || $attach['readperm']) {
  296. $html = '<a href="forum.php?mod=viewthread&tid='.$attach['tid'].'" id="attach_'.$rimg_id.'" target="_blank" class="flw_attach_price"><strong>'.$attach['filename'].'</strong><span>'.sizecount($attach['filesize']).'</span></a>';
  297. } else {
  298. require_once libfile('function/attachment');
  299. $aidencode = packaids($attach);
  300. $attachurl = "forum.php?mod=attachment&aid=$aidencode";
  301. $html = '<a href="'.$attachurl.'" id="attach_'.$rimg_id.'"><strong>'.$attach['filename'].'</strong><span>'.sizecount($attach['filesize']).'</span></a>';
  302. }
  303. return fcodedisp($html, 'attach');
  304. }
  305. }
  306. return '';
  307. }
  308. function fparseflash($url) {
  309. preg_match("/((https?){1}:\/\/|www\.)[^\[\"']+/i", $url, $matches);
  310. $url = $matches[0];
  311. if(fileext($url) != 'flv') {
  312. $rimg_id = 'swf_'.random(5);
  313. $html = bbcodeurl($url, '<img src="'.IMGDIR.'/flash.gif" alt="'.lang('space', 'follow_click_play').'" onclick="javascript:showFlash(\'flash\', \''.$url.'\', this, \''.$rimg_id.'\');" class="tn" style="cursor: pointer;" />');
  314. return fcodedisp($html, 'media');
  315. } else {
  316. $url = STATICURL.'image/common/flvplayer.swf?&autostart=true&file='.urlencode($matches[0]);
  317. return fmakeflv($url);
  318. }
  319. }
  320. function fparseemail($email, $text) {
  321. global $_G;
  322. $text = str_replace('\"', '"', $text);
  323. $html = '';
  324. if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
  325. $email = trim($matches[0]);
  326. $html = '<a href="mailto:'.$email.'">'.$email.'</a>';
  327. } else {
  328. $html = '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
  329. }
  330. return fcodedisp($html);
  331. }
  332. function fparsetable($width, $bgcolor, $message) {
  333. global $_G;
  334. $html = '';
  335. if(strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
  336. $rows = explode("\n", $message);
  337. $html = '<table cellspacing="0" class="t_table" '.
  338. ($width == '' ? NULL : 'style="width:'.$width.'"').
  339. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>');
  340. foreach($rows as $row) {
  341. $html .= '<tr><td>'.str_replace(array('\|', '|', '\n'), array('&#124;', '</td><td>', "\n"), $row).'</td></tr>';
  342. }
  343. $html .= '</table>';
  344. } else {
  345. if(!preg_match("/^\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td([=\d,%]+)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
  346. return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)\s%,#\w]+))?\]|\[td([=\d,%]+)?\]|\[\/td\]|\[\/tr\]/", '', $message));
  347. }
  348. if(substr($width, -1) == '%') {
  349. $width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%';
  350. } else {
  351. $width = intval($width);
  352. $width = $width ? ($width <= 560 ? $width.'px' : '98%') : '';
  353. }
  354. $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'fparsetable_callback_parsetrtd_12', $message);
  355. $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'fparsetable_callback_parsetrtd_1', $message);
  356. $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'fparsetable_callback_parsetrtd_1234', $message);
  357. $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'fparsetable_callback_parsetrtd_123', $message);
  358. $html = '<table cellspacing="0" class="t_table" '.
  359. ($width == '' ? NULL : 'style="width:'.$width.'"').
  360. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>').
  361. str_replace('\\"', '"', preg_replace("/\[\/td\]\s*\[\/tr\]\s*/i", '</td></tr>', $message)
  362. ).'</table>';
  363. }
  364. return fcodedisp($html);
  365. }
  366. function fparsetable_callback_parsetrtd_12($matches) {
  367. return parsetrtd($matches[1], 0, 0, $matches[2]);
  368. }
  369. function fparsetable_callback_parsetrtd_1($matches) {
  370. return parsetrtd('td', 0, 0, $matches[1]);
  371. }
  372. function fparsetable_callback_parsetrtd_1234($matches) {
  373. return parsetrtd($matches[1], $matches[2], $matches[3], $matches[4]);
  374. }
  375. function fparsetable_callback_parsetrtd_123($matches) {
  376. return parsetrtd('td', $matches[1], $matches[2], $matches[3]);
  377. }
  378. function fparseaudio($url) {
  379. $url = addslashes($url);
  380. if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://')) && !preg_match('/^static\//', $url) && !preg_match('/^data\//', $url)) {
  381. return dhtmlspecialchars($url);
  382. }
  383. if(fileext($url) == 'mp3') {
  384. $randomid = 'music_'.random(3);
  385. $html = '<img src="'.IMGDIR.'/music.gif" alt="'.lang('space', 'follow_click_play').'" onclick="javascript:showFlash(\'music\', \''.$url.'\', this, \''.$randomid.'\');" class="tn" style="cursor: pointer;" />';
  386. return fcodedisp($html, 'audio');
  387. } else {
  388. $html = '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  389. return $html;
  390. }
  391. }
  392. function fmakeflv($flv) {
  393. $randomid = 'video_'.random(3);
  394. $flv = is_array($flv) ? $flv : array('flv' => $flv);
  395. if(!preg_match("/^((https?){1}:\/\/|www\.)[^\[\"']+$/i", $flv['flv'])) {
  396. return fcodedisp('', 'video');
  397. }
  398. if(!empty($flv['imgurl'])) {
  399. if(!preg_match("/^((https?){1}:\/\/|www\.)[^\[\"']+$/i", $flv['imgurl'])) {
  400. $html = '';
  401. } else {
  402. $html = '<table class="mtm" title="'.lang('space', 'follow_click_play').'" onclick="javascript:showFlash(\'flash\', \''.$flv['flv'].'\', this, \''.$randomid.'\');"><tr><td class="vdtn hm" style="background: url('.$flv['imgurl'].') no-repeat; border: 1px solid #CDCDCD; cursor: pointer; height: 95px; width: 126px;"><img src="'.IMGDIR.'/vds.png" alt="'.lang('space', 'follow_click_play').'" /> </td></tr></table>';
  403. }
  404. } else {
  405. $html = '<img src="'.IMGDIR.'/vd.gif" alt="'.lang('space', 'follow_click_play').'" onclick="javascript:showFlash(\'flash\', \''.$flv['flv'].'\', this, \''.$randomid.'\');" class="tn" style="cursor: pointer;" />';
  406. }
  407. return fcodedisp($html, 'video');
  408. }
  409. function fparsemedia($params, $url) {
  410. $params = explode(',', $params);
  411. $url = addslashes($url);
  412. $html = '';
  413. if($flv = parseflv($url, 0, 0)) {
  414. return fmakeflv($flv);
  415. }
  416. if(in_array(count($params), array(3, 4))) {
  417. $type = $params[0];
  418. $url = str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url));
  419. switch($type) {
  420. case 'mp3':
  421. return fparseaudio($url);
  422. break;
  423. case 'flv':
  424. $url = STATICURL.'image/common/flvplayer.swf?&autostart=true&file='.urlencode($url);
  425. return fmakeflv($url);
  426. break;
  427. case 'swf':
  428. return fparseflash($url);
  429. break;
  430. default:
  431. $html = '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  432. break;
  433. }
  434. }
  435. return fcodedisp($html, 'media');
  436. }
  437. function fparseimg($src, $extra = '') {
  438. global $_G;
  439. $rimg_id = random(5);
  440. $html = bbcodeurl($src, '<img id="iimg_'.$rimg_id.'" src="'.$src.'" border="0" alt="" '.$extra.' style="cursor: pointer;" />');
  441. return fcodedisp($html, 'image');
  442. }
  443. function fparsesmiles(&$message) {
  444. global $_G;
  445. static $enablesmiles;
  446. if($enablesmiles === null) {
  447. $enablesmiles = false;
  448. if(!empty($_G['cache']['smilies']) && is_array($_G['cache']['smilies'])) {
  449. foreach($_G['cache']['smilies']['replacearray'] AS $key => $smiley) {
  450. if(substr($_G['cache']['smilies']['replacearray'][$key], 0, 1) == '<') {
  451. break;
  452. }
  453. $_G['cache']['smilies']['replacearray'][$key] = '<img src="'.STATICURL.'image/smiley/'.$_G['cache']['smileytypes'][$_G['cache']['smilies']['typearray'][$key]]['directory'].'/'.$smiley.'" smilieid="'.$key.'" border="0" class="s" alt="" />';
  454. }
  455. $enablesmiles = true;
  456. }
  457. }
  458. $enablesmiles && $message = preg_replace($_G['cache']['smilies']['searcharray'], $_G['cache']['smilies']['replacearray'], $message, $_G['setting']['maxsmilies']);
  459. return $message;
  460. }
  461. ?>