PageRenderTime 61ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_discuzcode.php

https://github.com/kuaileshike/upload
PHP | 653 lines | 615 code | 32 blank | 6 comment | 136 complexity | 7b27d2b77aa1eb5056fdf714a90db1ef MD5 | raw file
  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_discuzcode.php 30926 2012-07-02 05:48:08Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. include template('forum/discuzcode');
  12. $_G['forum_discuzcode'] = array(
  13. 'pcodecount' => -1,
  14. 'codecount' => 0,
  15. 'codehtml' => '',
  16. 'smiliesreplaced' => 0,
  17. 'seoarray' => array(
  18. 0 => '',
  19. 1 => $_SERVER['HTTP_HOST'],
  20. 2 => $_G['setting']['bbname'],
  21. 3 => str_replace('{bbname}', $_G['setting']['bbname'], $_G['setting']['seotitle']),
  22. 4 => $_G['setting']['seokeywords'],
  23. 5 => $_G['setting']['seodescription']
  24. )
  25. );
  26. $authorreplyexist = '';
  27. if(!isset($_G['cache']['bbcodes']) || !is_array($_G['cache']['bbcodes']) || !is_array($_G['cache']['smilies'])) {
  28. loadcache(array('bbcodes', 'smilies', 'smileytypes'));
  29. }
  30. function creditshide($creditsrequire, $message, $pid, $authorid) {
  31. global $_G;
  32. if($_G['member']['credits'] >= $creditsrequire || $_G['forum']['ismoderator'] || $_G['uid'] && $authorid == $_G['uid']) {
  33. return tpl_hide_credits($creditsrequire, str_replace('\\"', '"', $message));
  34. } else {
  35. return tpl_hide_credits_hidden($creditsrequire);
  36. }
  37. }
  38. function expirehide($expiration, $creditsrequire, $message, $dateline) {
  39. $expiration = $expiration ? substr($expiration, 1) : 0;
  40. if($expiration && $dateline && (TIMESTAMP - $dateline) / 86400 > $expiration) {
  41. return str_replace('\\"', '"', $message);
  42. }
  43. return '[hide'.($creditsrequire ? "=$creditsrequire" : '').']'.str_replace('\\"', '"', $message).'[/hide]';
  44. }
  45. function codedisp($code) {
  46. global $_G;
  47. $_G['forum_discuzcode']['pcodecount']++;
  48. $code = dhtmlspecialchars(str_replace('\\"', '"', $code));
  49. $code = str_replace("\n", "<li>", $code);
  50. $_G['forum_discuzcode']['codehtml'][$_G['forum_discuzcode']['pcodecount']] = tpl_codedisp($code);
  51. $_G['forum_discuzcode']['codecount']++;
  52. return "[\tDISCUZ_CODE_".$_G['forum_discuzcode']['pcodecount']."\t]";
  53. }
  54. function karmaimg($rate, $ratetimes) {
  55. $karmaimg = '';
  56. if($rate && $ratetimes) {
  57. $image = $rate > 0 ? 'agree.gif' : 'disagree.gif';
  58. for($i = 0; $i < ceil(abs($rate) / $ratetimes); $i++) {
  59. $karmaimg .= '<img src="'.$_G['style']['imgdir'].'/'.$image.'" border="0" alt="" />';
  60. }
  61. }
  62. return $karmaimg;
  63. }
  64. function discuzcode($message, $smileyoff, $bbcodeoff, $htmlon = 0, $allowsmilies = 1, $allowbbcode = 1, $allowimgcode = 1, $allowhtml = 0, $jammer = 0, $parsetype = '0', $authorid = '0', $allowmediacode = '0', $pid = 0, $lazyload = 0, $pdateline = 0) {
  65. global $_G;
  66. static $authorreplyexist;
  67. if($parsetype != 1 && !$bbcodeoff && $allowbbcode && (strpos($message, '[/code]') || strpos($message, '[/CODE]')) !== FALSE) {
  68. $message = preg_replace("/\s?\[code\](.+?)\[\/code\]\s?/ies", "codedisp('\\1')", $message);
  69. }
  70. $msglower = strtolower($message);
  71. $htmlon = $htmlon && $allowhtml ? 1 : 0;
  72. if(!$htmlon) {
  73. $message = dhtmlspecialchars($message);
  74. } else {
  75. $message = preg_replace("/<script[^\>]*?>(.*?)<\/script>/i", '', $message);
  76. }
  77. if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  78. $_G['discuzcodemessage'] = & $message;
  79. $param = func_get_args();
  80. hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'discuzcode'), 'discuzcode');
  81. }
  82. if(!$smileyoff && $allowsmilies) {
  83. $message = parsesmiles($message);
  84. }
  85. if($_G['setting']['allowattachurl'] && strpos($msglower, 'attach://') !== FALSE) {
  86. $message = preg_replace("/attach:\/\/(\d+)\.?(\w*)/ie", "parseattachurl('\\1', '\\2', 1)", $message);
  87. }
  88. if($allowbbcode) {
  89. if(strpos($msglower, 'ed2k://') !== FALSE) {
  90. $message = preg_replace("/ed2k:\/\/(.+?)\//e", "parseed2k('\\1')", $message);
  91. }
  92. }
  93. if(!$bbcodeoff && $allowbbcode) {
  94. if(strpos($msglower, '[/url]') !== FALSE) {
  95. $message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/ies", "parseurl('\\1', '\\5', '\\2')", $message);
  96. }
  97. if(strpos($msglower, '[/email]') !== FALSE) {
  98. $message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message);
  99. }
  100. $nest = 0;
  101. while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){
  102. $message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "parsetable('\\1', '\\2', '\\3')", $message);
  103. if(++$nest > 4) break;
  104. }
  105. $message = str_replace(array(
  106. '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
  107. '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
  108. '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
  109. ), array(
  110. '</font>', '</font>', '</font>', '</font>', '</div>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="l" />', '</p>', '<i class="pstatus">', '<i>',
  111. '</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
  112. '<ul type="A" class="litype_3">', '<li>', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
  113. ), preg_replace(array(
  114. "/\[color=([#\w]+?)\]/i",
  115. "/\[color=(rgb\([\d\s,]+?\))\]/i",
  116. "/\[backcolor=([#\w]+?)\]/i",
  117. "/\[backcolor=(rgb\([\d\s,]+?\))\]/i",
  118. "/\[size=(\d{1,2}?)\]/i",
  119. "/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
  120. "/\[font=([^\[\<]+?)\]/i",
  121. "/\[align=(left|center|right)\]/i",
  122. "/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i",
  123. "/\[float=left\]/i",
  124. "/\[float=right\]/i"
  125. ), array(
  126. "<font color=\"\\1\">",
  127. "<font style=\"color:\\1\">",
  128. "<font style=\"background-color:\\1\">",
  129. "<font style=\"background-color:\\1\">",
  130. "<font size=\"\\1\">",
  131. "<font style=\"font-size:\\1\">",
  132. "<font face=\"\\1\">",
  133. "<div align=\"\\1\">",
  134. "<p style=\"line-height:\\1px;text-indent:\\2em;text-align:\\3\">",
  135. "<span style=\"float:left;margin-right:5px\">",
  136. "<span style=\"float:right;margin-left:5px\">"
  137. ), $message));
  138. if($parsetype != 1) {
  139. if(strpos($msglower, '[/quote]') !== FALSE) {
  140. $message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", tpl_quote(), $message);
  141. }
  142. if(strpos($msglower, '[/free]') !== FALSE) {
  143. $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message);
  144. }
  145. }
  146. if(strpos($msglower, '[/media]') !== FALSE) {
  147. $message = preg_replace("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/ies", $allowmediacode ? "parsemedia('\\1', '\\2')" : "bbcodeurl('\\2', '<a href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
  148. }
  149. if(strpos($msglower, '[/audio]') !== FALSE) {
  150. $message = preg_replace("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/ies", $allowmediacode ? "parseaudio('\\2', 400)" : "bbcodeurl('\\2', '<a href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
  151. }
  152. if(strpos($msglower, '[/flash]') !== FALSE) {
  153. $message = preg_replace("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/ies", $allowmediacode ? "parseflash('\\2', '\\3', '\\4');" : "bbcodeurl('\\4', '<a href=\"{url}\" target=\"_blank\">{url}</a>')", $message);
  154. }
  155. if($parsetype != 1 && $allowbbcode < 0 && isset($_G['cache']['bbcodes'][-$allowbbcode])) {
  156. $message = preg_replace($_G['cache']['bbcodes'][-$allowbbcode]['searcharray'], $_G['cache']['bbcodes'][-$allowbbcode]['replacearray'], $message);
  157. }
  158. if($parsetype != 1 && strpos($msglower, '[/hide]') !== FALSE && $pid) {
  159. if($_G['setting']['hideexpiration'] && $pdateline && (TIMESTAMP - $pdateline) / 86400 > $_G['setting']['hideexpiration']) {
  160. $message = preg_replace("/\[hide[=]?(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/is", "\\3", $message);
  161. $msglower = strtolower($message);
  162. }
  163. if(strpos($msglower, '[hide=d') !== FALSE) {
  164. $message = preg_replace("/\[hide=(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/ies", "expirehide('\\1','\\2','\\3', $pdateline)", $message);
  165. $msglower = strtolower($message);
  166. }
  167. if(strpos($msglower, '[hide]') !== FALSE) {
  168. if($authorreplyexist === null) {
  169. if(!$_G['forum']['ismoderator']) {
  170. if($_G['uid']) {
  171. $authorreplyexist = C::t('forum_post')->fetch_pid_by_tid_authorid($_G['tid'], $_G['uid']);
  172. }
  173. } else {
  174. $authorreplyexist = TRUE;
  175. }
  176. }
  177. if($authorreplyexist) {
  178. $message = preg_replace("/\[hide\]\s*(.*?)\s*\[\/hide\]/is", tpl_hide_reply(), $message);
  179. } else {
  180. $message = preg_replace("/\[hide\](.*?)\[\/hide\]/is", tpl_hide_reply_hidden(), $message);
  181. $message .= '<script type="text/javascript">replyreload += \',\' + '.$pid.';</script>';
  182. }
  183. }
  184. if(strpos($msglower, '[hide=') !== FALSE) {
  185. $message = preg_replace("/\[hide=(\d+)\]\s*(.*?)\s*\[\/hide\]/ies", "creditshide(\\1,'\\2', $pid, $authorid)", $message);
  186. }
  187. }
  188. }
  189. if(!$bbcodeoff) {
  190. if($parsetype != 1 && strpos($msglower, '[swf]') !== FALSE) {
  191. $message = preg_replace("/\[swf\]\s*([^\[\<\r\n]+?)\s*\[\/swf\]/ies", "bbcodeurl('\\1', ' <img src=\"'.STATICURL.'image/filetype/flash.gif\" align=\"absmiddle\" alt=\"\" /> <a href=\"{url}\" target=\"_blank\">Flash: {url}</a> ')", $message);
  192. }
  193. if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  194. $allowimgcode = false;
  195. $viewimg = lang('template', 'viewimg');
  196. }
  197. $attrsrc = !IS_ROBOT && $lazyload ? 'file' : 'src';
  198. if(strpos($msglower, '[/img]') !== FALSE) {
  199. $message = preg_replace(array(
  200. "/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
  201. "/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies"
  202. ), $allowimgcode ? array(
  203. "parseimg(0, 0, '\\1', ".intval($lazyload).", ".intval($pid).", 'onmouseover=\"img_onmouseoverfunc(this)\" onload=\"thumbImg(this)\"')",
  204. "parseimg('\\1', '\\2', '\\3', ".intval($lazyload).", ".intval($pid).")"
  205. ) : array(
  206. (!defined('IN_MOBILE') ? "bbcodeurl('\\1', '<a href=\"{url}\" target=\"_blank\">{url}</a>')" : "bbcodeurl('\\1', '<a href=\"{url}\" target=\"_blank\">[$viewimg]</a>')"),
  207. (!defined('IN_MOBILE') ? "bbcodeurl('\\3', '<a href=\"{url}\" target=\"_blank\">{url}</a>')" : "bbcodeurl('\\3', '<a href=\"{url}\" target=\"_blank\">[$viewimg]</a>')"),
  208. ), $message);
  209. }
  210. }
  211. for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
  212. $message = str_replace("[\tDISCUZ_CODE_$i\t]", $_G['forum_discuzcode']['codehtml'][$i], $message);
  213. }
  214. unset($msglower);
  215. if($jammer) {
  216. $message = preg_replace("/\r\n|\n|\r/e", "jammer()", $message);
  217. }
  218. return $htmlon ? $message : nl2br(str_replace(array("\t", ' ', ' '), array('&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;'), $message));
  219. }
  220. function parseurl($url, $text, $scheme) {
  221. global $_G;
  222. if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
  223. $url = $matches[0];
  224. $length = 65;
  225. if(strlen($url) > $length) {
  226. $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  227. }
  228. return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
  229. } else {
  230. $url = substr($url, 1);
  231. if(substr(strtolower($url), 0, 4) == 'www.') {
  232. $url = 'http://'.$url;
  233. }
  234. $url = !$scheme ? $_G['siteurl'].$url : $url;
  235. return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
  236. }
  237. }
  238. function parseflash($w, $h, $url) {
  239. $w = !$w ? 550 : $w;
  240. $h = !$h ? 400 : $h;
  241. preg_match("/((https?){1}:\/\/|www\.)[^\[\"']+/i", $url, $matches);
  242. $url = $matches[0];
  243. $randomid = 'swf_'.random(3);
  244. if(fileext($url) != 'flv') {
  245. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$w.'\', \'height\', \''.$h.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.$url.'\', \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  246. } else {
  247. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$w.'\', \'height\', \''.$h.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.STATICURL.'image/common/flvplayer.swf\', \'flashvars\', \'file='.rawurlencode($url).'\', \'quality\', \'high\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  248. }
  249. }
  250. function parseed2k($url) {
  251. global $_G;
  252. list(,$type, $name, $size,) = explode('|', $url);
  253. $url = 'ed2k://'.$url.'/';
  254. $name = addslashes($name);
  255. if($type == 'file') {
  256. $ed2kid = 'ed2k_'.random(3);
  257. return '<a id="'.$ed2kid.'" href="'.$url.'" target="_blank">'.dhtmlspecialchars(urldecode($name)).' ('.sizecount($size).')</a><script language="javascript">$(\''.$ed2kid.'\').innerHTML=htmlspecialchars(unescape(decodeURIComponent(\''.$name.'\')))+\' ('.sizecount($size).')\';</script>';
  258. } else {
  259. return '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  260. }
  261. }
  262. function parseattachurl($aid, $ext, $ignoretid = 0) {
  263. global $_G;
  264. $_G['forum_skipaidlist'][] = $aid;
  265. return $_G['siteurl'].'forum.php?mod=attachment&aid='.aidencode($aid, $ext, $ignoretid ? '' : $_G['tid']).($ext ? '&request=yes&_f=.'.$ext : '');
  266. }
  267. function parseemail($email, $text) {
  268. $text = str_replace('\"', '"', $text);
  269. if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
  270. $email = trim($matches[0]);
  271. return '<a href="mailto:'.$email.'">'.$email.'</a>';
  272. } else {
  273. return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
  274. }
  275. }
  276. function parsetable($width, $bgcolor, $message) {
  277. if(strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
  278. $rows = explode("\n", $message);
  279. $s = '<table cellspacing="0" class="t_table" '.
  280. ($width == '' ? NULL : 'style="width:'.$width.'"').
  281. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>');
  282. foreach($rows as $row) {
  283. $s .= '<tr><td>'.str_replace(array('\|', '|', '\n'), array('&#124;', '</td><td>', "\n"), $row).'</td></tr>';
  284. }
  285. $s .= '</table>';
  286. return $s;
  287. } else {
  288. if(!preg_match("/^\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td([=\d,%]+)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
  289. return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)\s%,#\w]+))?\]|\[td([=\d,%]+)?\]|\[\/td\]|\[\/tr\]/", '', $message));
  290. }
  291. if(substr($width, -1) == '%') {
  292. $width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%';
  293. } else {
  294. $width = intval($width);
  295. $width = $width ? ($width <= 560 ? $width.'px' : '98%') : '';
  296. }
  297. return '<table cellspacing="0" class="t_table" '.
  298. ($width == '' ? NULL : 'style="width:'.$width.'"').
  299. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>').
  300. str_replace('\\"', '"', preg_replace(array(
  301. "/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,4}%?))?\]/ie",
  302. "/\[\/td\]\s*\[td(?:=(\d{1,4}%?))?\]/ie",
  303. "/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
  304. "/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
  305. "/\[\/td\]\s*\[\/tr\]\s*/i"
  306. ), array(
  307. "parsetrtd('\\1', '0', '0', '\\2')",
  308. "parsetrtd('td', '0', '0', '\\1')",
  309. "parsetrtd('\\1', '\\2', '\\3', '\\4')",
  310. "parsetrtd('td', '\\1', '\\2', '\\3')",
  311. '</td></tr>'
  312. ), $message)
  313. ).'</table>';
  314. }
  315. }
  316. function parsetrtd($bgcolor, $colspan, $rowspan, $width) {
  317. return ($bgcolor == 'td' ? '</td>' : '<tr'.($bgcolor ? ' style="background-color:'.$bgcolor.'"' : '').'>').'<td'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').($rowspan > 1 ? ' rowspan="'.$rowspan.'"' : '').($width ? ' width="'.$width.'"' : '').'>';
  318. }
  319. function parseaudio($url, $width = 400) {
  320. $ext = strtolower(substr(strrchr($url, '.'), 1, 5));
  321. switch($ext) {
  322. case 'mp3':
  323. $randomid = 'mp3_'.random(3);
  324. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'FlashVars\', \'soundFile='.urlencode($url).'\', \'width\', \'290\', \'height\', \'24\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.STATICURL.'image/common/player.swf\', \'quality\', \'high\', \'bgcolor\', \'#FFFFFF\', \'menu\', \'false\', \'wmode\', \'transparent\', \'allowscriptaccess\', \'none\', \'allowNetworking\', \'internal\');</script>';
  325. case 'wma':
  326. case 'mid':
  327. case 'wav':
  328. return '<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'.$width.'" height="64"><param name="invokeURLs" value="0"><param name="autostart" value="0" /><param name="url" value="'.$url.'" /><embed src="'.$url.'" autostart="0" type="application/x-mplayer2" width="'.$width.'" height="64"></embed></object>';
  329. case 'ra':
  330. case 'rm':
  331. case 'ram':
  332. $mediaid = 'media_'.random(3);
  333. return '<object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'.$width.'" height="32"><param name="autostart" value="0" /><param name="src" value="'.$url.'" /><param name="controls" value="controlpanel" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" autostart="0" type="audio/x-pn-realaudio-plugin" controls="ControlPanel" console="'.$mediaid.'_" width="'.$width.'" height="32"></embed></object>';
  334. }
  335. }
  336. function parsemedia($params, $url) {
  337. $params = explode(',', $params);
  338. $width = intval($params[1]) > 800 ? 800 : intval($params[1]);
  339. $height = intval($params[2]) > 600 ? 600 : intval($params[2]);
  340. $url = addslashes($url);
  341. if($flv = parseflv($url, $width, $height)) {
  342. return $flv;
  343. }
  344. if(in_array(count($params), array(3, 4))) {
  345. $type = $params[0];
  346. $url = str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url));
  347. switch($type) {
  348. case 'mp3':
  349. case 'wma':
  350. case 'ra':
  351. case 'ram':
  352. case 'wav':
  353. case 'mid':
  354. return parseaudio($url, $width);
  355. case 'rm':
  356. case 'rmvb':
  357. case 'rtsp':
  358. $mediaid = 'media_'.random(3);
  359. return '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'.$width.'" height="'.$height.'"><param name="autostart" value="0" /><param name="src" value="'.$url.'" /><param name="controls" value="imagewindow" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" autostart="0" type="audio/x-pn-realaudio-plugin" controls="imagewindow" console="'.$mediaid.'_" width="'.$width.'" height="'.$height.'"></embed></object><br /><object classid="clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" width="'.$width.'" height="32"><param name="src" value="'.$url.'" /><param name="controls" value="controlpanel" /><param name="console" value="'.$mediaid.'_" /><embed src="'.$url.'" autostart="0" type="audio/x-pn-realaudio-plugin" controls="controlpanel" console="'.$mediaid.'_" width="'.$width.'" height="32"></embed></object>';
  360. case 'flv':
  361. $randomid = 'flv_'.random(3);
  362. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.STATICURL.'image/common/flvplayer.swf\', \'flashvars\', \'file='.rawurlencode($url).'\', \'quality\', \'high\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  363. case 'swf':
  364. $randomid = 'swf_'.random(3);
  365. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.$url.'\', \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  366. case 'asf':
  367. case 'asx':
  368. case 'wmv':
  369. case 'mms':
  370. case 'avi':
  371. case 'mpg':
  372. case 'mpeg':
  373. return '<object classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="'.$width.'" height="'.$height.'"><param name="invokeURLs" value="0"><param name="autostart" value="0" /><param name="url" value="'.$url.'" /><embed src="'.$url.'" autostart="0" type="application/x-mplayer2" width="'.$width.'" height="'.$height.'"></embed></object>';
  374. case 'mov':
  375. return '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'.$width.'" height="'.$height.'"><param name="autostart" value="false" /><param name="src" value="'.$url.'" /><embed src="'.$url.'" autostart="false" type="video/quicktime" controller="true" width="'.$width.'" height="'.$height.'"></embed></object>';
  376. default:
  377. return '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  378. }
  379. }
  380. return;
  381. }
  382. function bbcodeurl($url, $tags) {
  383. if(!preg_match("/<.+?>/s", $url)) {
  384. if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://')) && !preg_match('/^static\//', $url) && !preg_match('/^data\//', $url)) {
  385. $url = 'http://'.$url;
  386. }
  387. return str_replace(array('submit', 'member.php?mod=logging'), array('', ''), str_replace('{url}', addslashes($url), $tags));
  388. } else {
  389. return '&nbsp;'.$url;
  390. }
  391. }
  392. function jammer() {
  393. $randomstr = '';
  394. for($i = 0; $i < mt_rand(5, 15); $i++) {
  395. $randomstr .= chr(mt_rand(32, 59)).' '.chr(mt_rand(63, 126));
  396. }
  397. return mt_rand(0, 1) ? '<font class="jammer">'.$randomstr.'</font>'."\r\n" :
  398. "\r\n".'<span style="display:none">'.$randomstr.'</span>';
  399. }
  400. function highlightword($text, $words, $prepend) {
  401. $text = str_replace('\"', '"', $text);
  402. foreach($words AS $key => $replaceword) {
  403. $text = str_replace($replaceword, '<highlight>'.$replaceword.'</highlight>', $text);
  404. }
  405. return "$prepend$text";
  406. }
  407. function parseflv($url, $width = 0, $height = 0) {
  408. $lowerurl = strtolower($url);
  409. $flv = '';
  410. $imgurl = '';
  411. if($lowerurl != str_replace(array('player.youku.com/player.php/sid/','tudou.com/v/','player.ku6.com/refer/'), '', $lowerurl)) {
  412. $flv = $url;
  413. } elseif(strpos($lowerurl, 'v.youku.com/v_show/') !== FALSE) {
  414. $ctx = stream_context_create(array('http' => array('timeout' => 10)));
  415. if(preg_match("/http:\/\/v.youku.com\/v_show\/id_([^\/]+)(.html|)/i", $url, $matches)) {
  416. $flv = 'http://player.youku.com/player.php/sid/'.$matches[1].'/v.swf';
  417. if(!$width && !$height) {
  418. $api = 'http://v.youku.com/player/getPlayList/VideoIDS/'.$matches[1];
  419. $str = stripslashes(file_get_contents($api, false, $ctx));
  420. if(!empty($str) && preg_match("/\"logo\":\"(.+?)\"/i", $str, $image)) {
  421. $url = substr($image[1], 0, strrpos($image[1], '/')+1);
  422. $filename = substr($image[1], strrpos($image[1], '/')+2);
  423. $imgurl = $url.'0'.$filename;
  424. }
  425. }
  426. }
  427. } elseif(strpos($lowerurl, 'tudou.com/programs/view/') !== FALSE) {
  428. if(preg_match("/http:\/\/(www.)?tudou.com\/programs\/view\/([^\/]+)/i", $url, $matches)) {
  429. $flv = 'http://www.tudou.com/v/'.$matches[2];
  430. if(!$width && !$height) {
  431. $str = file_get_contents($url, false, $ctx);
  432. if(!empty($str) && preg_match("/<span class=\"s_pic\">(.+?)<\/span>/i", $str, $image)) {
  433. $imgurl = trim($image[1]);
  434. }
  435. }
  436. }
  437. } elseif(strpos($lowerurl, 'v.ku6.com/show/') !== FALSE) {
  438. if(preg_match("/http:\/\/v.ku6.com\/show\/([^\/]+).html/i", $url, $matches)) {
  439. $flv = 'http://player.ku6.com/refer/'.$matches[1].'/v.swf';
  440. if(!$width && !$height) {
  441. $api = 'http://vo.ku6.com/fetchVideo4Player/1/'.$matches[1].'.html';
  442. $str = file_get_contents($api, false, $ctx);
  443. if(!empty($str) && preg_match("/\"picpath\":\"(.+?)\"/i", $str, $image)) {
  444. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  445. }
  446. }
  447. }
  448. } elseif(strpos($lowerurl, 'v.ku6.com/special/show_') !== FALSE) {
  449. if(preg_match("/http:\/\/v.ku6.com\/special\/show_\d+\/([^\/]+).html/i", $url, $matches)) {
  450. $flv = 'http://player.ku6.com/refer/'.$matches[1].'/v.swf';
  451. if(!$width && !$height) {
  452. $api = 'http://vo.ku6.com/fetchVideo4Player/1/'.$matches[1].'.html';
  453. $str = file_get_contents($api, false, $ctx);
  454. if(!empty($str) && preg_match("/\"picpath\":\"(.+?)\"/i", $str, $image)) {
  455. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  456. }
  457. }
  458. }
  459. } elseif(strpos($lowerurl, 'www.youtube.com/watch?') !== FALSE) {
  460. if(preg_match("/http:\/\/www.youtube.com\/watch\?v=([^\/&]+)&?/i", $url, $matches)) {
  461. $flv = 'http://www.youtube.com/v/'.$matches[1].'&hl=zh_CN&fs=1';
  462. if(!$width && !$height) {
  463. $str = file_get_contents($url, false, $ctx);
  464. if(!empty($str) && preg_match("/'VIDEO_HQ_THUMB':\s'(.+?)'/i", $str, $image)) {
  465. $url = substr($image[1], 0, strrpos($image[1], '/')+1);
  466. $filename = substr($image[1], strrpos($image[1], '/')+3);
  467. $imgurl = $url.$filename;
  468. }
  469. }
  470. }
  471. } elseif(strpos($lowerurl, 'tv.mofile.com/') !== FALSE) {
  472. if(preg_match("/http:\/\/tv.mofile.com\/([^\/]+)/i", $url, $matches)) {
  473. $flv = 'http://tv.mofile.com/cn/xplayer.swf?v='.$matches[1];
  474. if(!$width && !$height) {
  475. $str = file_get_contents($url, false, $ctx);
  476. if(!empty($str) && preg_match("/thumbpath=\"(.+?)\";/i", $str, $image)) {
  477. $imgurl = trim($image[1]);
  478. }
  479. }
  480. }
  481. } elseif(strpos($lowerurl, 'v.mofile.com/show/') !== FALSE) {
  482. if(preg_match("/http:\/\/v.mofile.com\/show\/([^\/]+).shtml/i", $url, $matches)) {
  483. $flv = 'http://tv.mofile.com/cn/xplayer.swf?v='.$matches[1];
  484. if(!$width && !$height) {
  485. $str = file_get_contents($url, false, $ctx);
  486. if(!empty($str) && preg_match("/thumbpath=\"(.+?)\";/i", $str, $image)) {
  487. $imgurl = trim($image[1]);
  488. }
  489. }
  490. }
  491. } elseif(strpos($lowerurl, 'video.sina.com.cn/v/b/') !== FALSE) {
  492. if(preg_match("/http:\/\/video.sina.com.cn\/v\/b\/(\d+)-(\d+).html/i", $url, $matches)) {
  493. $flv = 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid='.$matches[1];
  494. if(!$width && !$height) {
  495. $api = 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?vid='.$matches[1];
  496. $str = file_get_contents($api, false, $ctx);
  497. if(!empty($str)) {
  498. $imgurl = str_replace('imgurl=', '', trim($str));
  499. }
  500. }
  501. }
  502. } elseif(strpos($lowerurl, 'you.video.sina.com.cn/b/') !== FALSE) {
  503. if(preg_match("/http:\/\/you.video.sina.com.cn\/b\/(\d+)-(\d+).html/i", $url, $matches)) {
  504. $flv = 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid='.$matches[1];
  505. if(!$width && !$height) {
  506. $api = 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?vid='.$matches[1];
  507. $str = file_get_contents($api, false, $ctx);
  508. if(!empty($str)) {
  509. $imgurl = str_replace('imgurl=', '', trim($str));
  510. }
  511. }
  512. }
  513. } elseif(strpos($lowerurl, 'http://my.tv.sohu.com/u/') !== FALSE) {
  514. if(preg_match("/http:\/\/my.tv.sohu.com\/u\/[^\/]+\/(\d+)/i", $url, $matches)) {
  515. $flv = 'http://v.blog.sohu.com/fo/v4/'.$matches[1];
  516. if(!$width && !$height) {
  517. $api = 'http://v.blog.sohu.com/videinfo.jhtml?m=view&id='.$matches[1].'&outType=3';
  518. $str = file_get_contents($api, false, $ctx);
  519. if(!empty($str) && preg_match("/\"cutCoverURL\":\"(.+?)\"/i", $str, $image)) {
  520. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  521. }
  522. }
  523. }
  524. } elseif(strpos($lowerurl, 'http://v.blog.sohu.com/u/') !== FALSE) {
  525. if(preg_match("/http:\/\/v.blog.sohu.com\/u\/[^\/]+\/(\d+)/i", $url, $matches)) {
  526. $flv = 'http://v.blog.sohu.com/fo/v4/'.$matches[1];
  527. if(!$width && !$height) {
  528. $api = 'http://v.blog.sohu.com/videinfo.jhtml?m=view&id='.$matches[1].'&outType=3';
  529. $str = file_get_contents($api, false, $ctx);
  530. if(!empty($str) && preg_match("/\"cutCoverURL\":\"(.+?)\"/i", $str, $image)) {
  531. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  532. }
  533. }
  534. }
  535. } elseif(strpos($lowerurl, 'http://www.ouou.com/fun_funview') !== FALSE) {
  536. $str = file_get_contents($url, false, $ctx);
  537. if(!empty($str) && preg_match("/var\sflv\s=\s'(.+?)';/i", $str, $matches)) {
  538. $flv = $_G['style']['imgdir'].'/flvplayer.swf?&autostart=true&file='.urlencode($matches[1]);
  539. if(!$width && !$height && preg_match("/var\simga=\s'(.+?)';/i", $str, $image)) {
  540. $imgurl = trim($image[1]);
  541. }
  542. }
  543. } elseif(strpos($lowerurl, 'http://www.56.com') !== FALSE) {
  544. if(preg_match("/http:\/\/www.56.com\/\S+\/play_album-aid-(\d+)_vid-(.+?).html/i", $url, $matches)) {
  545. $flv = 'http://player.56.com/v_'.$matches[2].'.swf';
  546. $matches[1] = $matches[2];
  547. } elseif(preg_match("/http:\/\/www.56.com\/\S+\/([^\/]+).html/i", $url, $matches)) {
  548. $flv = 'http://player.56.com/'.$matches[1].'.swf';
  549. }
  550. if(!$width && !$height && !empty($matches[1])) {
  551. $api = 'http://vxml.56.com/json/'.str_replace('v_', '', $matches[1]).'/?src=out';
  552. $str = file_get_contents($api, false, $ctx);
  553. if(!empty($str) && preg_match("/\"img\":\"(.+?)\"/i", $str, $image)) {
  554. $imgurl = trim($image[1]);
  555. }
  556. }
  557. }
  558. if($flv) {
  559. if(!$width && !$height) {
  560. return array('flv' => $flv, 'imgurl' => $imgurl);
  561. } else {
  562. $width = addslashes($width);
  563. $height = addslashes($height);
  564. $flv = addslashes($flv);
  565. $randomid = 'flv_'.random(3);
  566. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.$flv.'\', \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  567. }
  568. } else {
  569. return FALSE;
  570. }
  571. }
  572. function parseimg($width, $height, $src, $lazyload, $pid, $extra = '') {
  573. global $_G;
  574. if(strstr($src, 'file:') || substr($src, 1, 1) == ':') {
  575. return $src;
  576. }
  577. if($width > $_G['setting']['imagemaxwidth']) {
  578. $height = intval($_G['setting']['imagemaxwidth'] * $height / $width);
  579. $width = $_G['setting']['imagemaxwidth'];
  580. if(defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
  581. $extra = '';
  582. } else {
  583. $extra = 'onmouseover="img_onmouseoverfunc(this)" onclick="zoom(this)" style="cursor:pointer"';
  584. }
  585. }
  586. $attrsrc = !IS_ROBOT && $lazyload ? 'file' : 'src';
  587. $rimg_id = random(5);
  588. $GLOBALS['aimgs'][$pid][] = $rimg_id;
  589. return bbcodeurl($src, '<img id="aimg_'.$rimg_id.'" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" class="zoom"'.($width > 0 ? ' width="'.$width.'"' : '').($height > 0 ? ' height="'.$height.'"' : '').' '.$attrsrc.'="'.$src.'" '.($extra ? $extra.' ' : '').'border="0" alt="" />');
  590. }
  591. function parsesmiles(&$message) {
  592. global $_G;
  593. static $enablesmiles;
  594. if($enablesmiles === null) {
  595. $enablesmiles = false;
  596. if(!empty($_G['cache']['smilies']) && is_array($_G['cache']['smilies'])) {
  597. foreach($_G['cache']['smilies']['replacearray'] AS $key => $smiley) {
  598. $_G['cache']['smilies']['replacearray'][$key] = '<img src="'.STATICURL.'image/smiley/'.$_G['cache']['smileytypes'][$_G['cache']['smilies']['typearray'][$key]]['directory'].'/'.$smiley.'" smilieid="'.$key.'" border="0" alt="" />';
  599. }
  600. $enablesmiles = true;
  601. }
  602. }
  603. $enablesmiles && $message = preg_replace($_G['cache']['smilies']['searcharray'], $_G['cache']['smilies']['replacearray'], $message, $_G['setting']['maxsmilies']);
  604. return $message;
  605. }
  606. ?>