function_discuzcode.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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 36331 2016-12-28 01:08:45Z nemohou $
  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' => array(),
  16. 'passwordlock' => array(),
  17. 'smiliesreplaced' => 0,
  18. 'seoarray' => array(
  19. 0 => '',
  20. 1 => $_SERVER['HTTP_HOST'],
  21. 2 => $_G['setting']['bbname'],
  22. 3 => str_replace('{bbname}', $_G['setting']['bbname'], $_G['setting']['seotitle']),
  23. 4 => $_G['setting']['seokeywords'],
  24. 5 => $_G['setting']['seodescription']
  25. )
  26. );
  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 = false, $bbcodeoff = false, $htmlon = 0, $allowsmilies = 1, $allowbbcode = 1, $allowimgcode = 1, $allowhtml = 0, $jammer = 0, $parsetype = '0', $authorid = '0', $allowmediacode = '0', $pid = 0, $lazyload = 0, $pdateline = 0, $first = 0) {
  65. global $_G;
  66. static $authorreplyexist;
  67. if($pid && strpos($message, '[/password]') !== FALSE) {
  68. if($authorid != $_G['uid'] && !$_G['forum']['ismoderator']) {
  69. $message = preg_replace_callback("/\s?\[password\](.+?)\[\/password\]\s?/i", create_function('$matches', 'return parsepassword($matches[1], '.intval($pid).');'), $message);
  70. if($_G['forum_discuzcode']['passwordlock'][$pid]) {
  71. return '';
  72. }
  73. } else {
  74. $message = preg_replace("/\s?\[password\](.+?)\[\/password\]\s?/i", "", $message);
  75. $_G['forum_discuzcode']['passwordauthor'][$pid] = 1;
  76. }
  77. }
  78. if($parsetype != 1 && !$bbcodeoff && $allowbbcode && (strpos($message, '[/code]') || strpos($message, '[/CODE]')) !== FALSE) {
  79. $message = preg_replace_callback("/\s?\[code\](.+?)\[\/code\]\s?/is", 'discuzcode_callback_codedisp_1', $message);
  80. }
  81. $msglower = strtolower($message);
  82. $htmlon = $htmlon && $allowhtml ? 1 : 0;
  83. if(!$htmlon) {
  84. $message = dhtmlspecialchars($message);
  85. } else {
  86. $message = preg_replace("/<script[^\>]*?>(.*?)<\/script>/i", '', $message);
  87. }
  88. if($_G['setting']['plugins']['func'][HOOKTYPE]['discuzcode']) {
  89. $_G['discuzcodemessage'] = & $message;
  90. $param = func_get_args();
  91. hookscript('discuzcode', 'global', 'funcs', array('param' => $param, 'caller' => 'discuzcode'), 'discuzcode');
  92. }
  93. if(!$smileyoff && $allowsmilies) {
  94. $message = parsesmiles($message);
  95. }
  96. if($_G['setting']['allowattachurl'] && strpos($msglower, 'attach://') !== FALSE) {
  97. $message = preg_replace_callback("/attach:\/\/(\d+)\.?(\w*)/i", 'discuzcode_callback_parseattachurl_12', $message);
  98. }
  99. if($allowbbcode) {
  100. if(strpos($msglower, 'ed2k://') !== FALSE) {
  101. $message = preg_replace_callback("/ed2k:\/\/(.+?)\//", 'discuzcode_callback_parseed2k_1', $message);
  102. }
  103. }
  104. if(!$bbcodeoff && $allowbbcode) {
  105. if(strpos($msglower, '[/url]') !== FALSE) {
  106. $message = preg_replace_callback("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.|mailto:)?([^\r\n\[\"']+?))?\](.+?)\[\/url\]/is", 'discuzcode_callback_parseurl_152', $message);
  107. }
  108. if(strpos($msglower, '[/email]') !== FALSE) {
  109. $message = preg_replace_callback("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/is", 'discuzcode_callback_parseemail_14', $message);
  110. }
  111. $nest = 0;
  112. while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){
  113. $message = preg_replace_callback("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/is", 'discuzcode_callback_parsetable_123', $message);
  114. if(++$nest > 4) break;
  115. }
  116. $message = str_replace(array(
  117. '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
  118. '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
  119. '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
  120. ), array(
  121. '</font>', '</font>', '</font>', '</font>', '</div>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="l" />', '</p>', '<i class="pstatus">', '<i>',
  122. '</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
  123. '<ul type="A" class="litype_3">', '<li>', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
  124. ), preg_replace(array(
  125. "/\[color=([#\w]+?)\]/i",
  126. "/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
  127. "/\[backcolor=([#\w]+?)\]/i",
  128. "/\[backcolor=((rgb|rgba)\([\d\s,]+?\))\]/i",
  129. "/\[size=(\d{1,2}?)\]/i",
  130. "/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
  131. "/\[font=([^\[\<]+?)\]/i",
  132. "/\[align=(left|center|right)\]/i",
  133. "/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i",
  134. "/\[float=left\]/i",
  135. "/\[float=right\]/i"
  136. ), array(
  137. "<font color=\"\\1\">",
  138. "<font style=\"color:\\1\">",
  139. "<font style=\"background-color:\\1\">",
  140. "<font style=\"background-color:\\1\">",
  141. "<font size=\"\\1\">",
  142. "<font style=\"font-size:\\1\">",
  143. "<font face=\"\\1\">",
  144. "<div align=\"\\1\">",
  145. "<p style=\"line-height:\\1px;text-indent:\\2em;text-align:\\3\">",
  146. "<span style=\"float:left;margin-right:5px\">",
  147. "<span style=\"float:right;margin-left:5px\">"
  148. ), $message));
  149. if($pid && !defined('IN_MOBILE')) {
  150. $message = preg_replace_callback("/\s?\[postbg\]\s*([^\[\<\r\n;'\"\?\(\)]+?)\s*\[\/postbg\]\s?/is", create_function('$matches', 'return parsepostbg($matches[1], '.intval($pid).');'), $message);
  151. } else {
  152. $message = preg_replace("/\s?\[postbg\]\s*([^\[\<\r\n;'\"\?\(\)]+?)\s*\[\/postbg\]\s?/is", "", $message);
  153. }
  154. if($parsetype != 1) {
  155. if(strpos($msglower, '[/quote]') !== FALSE) {
  156. $message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", tpl_quote(), $message);
  157. }
  158. if(strpos($msglower, '[/free]') !== FALSE) {
  159. $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message);
  160. }
  161. }
  162. if(!defined('IN_MOBILE')) {
  163. if(strpos($msglower, '[/media]') !== FALSE) {
  164. $message = preg_replace_callback("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/is", $allowmediacode ? 'discuzcode_callback_parsemedia_12' : 'discuzcode_callback_bbcodeurl_2', $message);
  165. }
  166. if(strpos($msglower, '[/audio]') !== FALSE) {
  167. $message = preg_replace_callback("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/is", $allowmediacode ? 'discuzcode_callback_parseaudio_2' : 'discuzcode_callback_bbcodeurl_2', $message);
  168. }
  169. if(strpos($msglower, '[/flash]') !== FALSE) {
  170. $message = preg_replace_callback("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", $allowmediacode ? 'discuzcode_callback_parseflash_234' : 'discuzcode_callback_bbcodeurl_4', $message);
  171. }
  172. } else {
  173. if(strpos($msglower, '[/media]') !== FALSE) {
  174. $message = preg_replace("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/is", "[media]\\2[/media]", $message);
  175. }
  176. if(strpos($msglower, '[/audio]') !== FALSE) {
  177. $message = preg_replace("/\[audio(=1)*\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/is", "[media]\\2[/media]", $message);
  178. }
  179. if(strpos($msglower, '[/flash]') !== FALSE) {
  180. $message = preg_replace("/\[flash(=(\d+),(\d+))?\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", "[media]\\4[/media]", $message);
  181. }
  182. }
  183. if($parsetype != 1 && $allowbbcode < 0 && isset($_G['cache']['bbcodes'][-$allowbbcode])) {
  184. $message = preg_replace($_G['cache']['bbcodes'][-$allowbbcode]['searcharray'], $_G['cache']['bbcodes'][-$allowbbcode]['replacearray'], $message);
  185. }
  186. if($parsetype != 1 && strpos($msglower, '[/hide]') !== FALSE && $pid) {
  187. if($_G['setting']['hideexpiration'] && $pdateline && (TIMESTAMP - $pdateline) / 86400 > $_G['setting']['hideexpiration']) {
  188. $message = preg_replace("/\[hide[=]?(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/is", "\\3", $message);
  189. $msglower = strtolower($message);
  190. }
  191. if(strpos($msglower, '[hide=d') !== FALSE) {
  192. $message = preg_replace_callback("/\[hide=(d\d+)?[,]?(\d+)?\]\s*(.*?)\s*\[\/hide\]/is", create_function('$matches', 'return expirehide($matches[1], $matches[2], $matches[3], '.intval($pdateline).');'), $message);
  193. $msglower = strtolower($message);
  194. }
  195. if(strpos($msglower, '[hide]') !== FALSE) {
  196. if($authorreplyexist === null) {
  197. if(!$_G['forum']['ismoderator']) {
  198. if($_G['uid']) {
  199. $_post = C::t('forum_post')->fetch('tid:'.$_G['tid'], $pid);
  200. $authorreplyexist = $_post['tid'] == $_G['tid'] ? C::t('forum_post')->fetch_pid_by_tid_authorid($_G['tid'], $_G['uid']) : FALSE;
  201. }
  202. } else {
  203. $authorreplyexist = TRUE;
  204. }
  205. }
  206. if($authorreplyexist) {
  207. $message = preg_replace("/\[hide\]\s*(.*?)\s*\[\/hide\]/is", tpl_hide_reply(), $message);
  208. } else {
  209. $message = preg_replace("/\[hide\](.*?)\[\/hide\]/is", tpl_hide_reply_hidden(), $message);
  210. $message = '<script type="text/javascript">replyreload += \',\' + '.$pid.';</script>'.$message;
  211. }
  212. }
  213. if(strpos($msglower, '[hide=') !== FALSE) {
  214. $message = preg_replace_callback("/\[hide=(\d+)\]\s*(.*?)\s*\[\/hide\]/is", create_function('$matches', 'return creditshide($matches[1], $matches[2], '.intval($pid).', '.intval($authorid).');'), $message);
  215. }
  216. }
  217. }
  218. if(!$bbcodeoff) {
  219. if($parsetype != 1 && strpos($msglower, '[swf]') !== FALSE) {
  220. $message = preg_replace_callback("/\[swf\]\s*([^\[\<\r\n]+?)\s*\[\/swf\]/is", 'discuzcode_callback_bbcodeurl_1', $message);
  221. }
  222. if(defined('IN_MOBILE') && !defined('TPL_DEFAULT') && !defined('IN_MOBILE_API')) {
  223. $allowimgcode = false;
  224. }
  225. $attrsrc = !IS_ROBOT && $lazyload ? 'file' : 'src';
  226. if(strpos($msglower, '[/img]') !== FALSE) {
  227. $message = preg_replace_callback("/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", create_function('$matches', 'return '.intval($allowimgcode).' ? parseimg(0, 0, $matches[1], '.intval($lazyload).', '.intval($pid).', \'onmouseover="img_onmouseoverfunc(this)" \'.('.intval($lazyload).' ? \'lazyloadthumb="1"\' : \'onload="thumbImg(this)"\')) : ('.intval($allowbbcode).' ? (!defined(\'IN_MOBILE\') ? bbcodeurl($matches[1], \'<a href="{url}" target="_blank">{url}</a>\') : bbcodeurl($matches[1], \'\')) : bbcodeurl($matches[1], \'{url}\'));'), $message);
  228. $message = preg_replace_callback("/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/is", create_function('$matches', 'return '.intval($allowimgcode).' ? parseimg($matches[1], $matches[2], $matches[3], '.intval($lazyload).', '.intval($pid).') : ('.intval($allowbbcode).' ? (!defined(\'IN_MOBILE\') ? bbcodeurl($matches[3], \'<a href="{url}" target="_blank">{url}</a>\') : bbcodeurl($matches[3], \'\')) : bbcodeurl($matches[3], \'{url}\'));'), $message);
  229. }
  230. }
  231. for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
  232. $message = str_replace("[\tDISCUZ_CODE_$i\t]", $_G['forum_discuzcode']['codehtml'][$i], $message);
  233. }
  234. unset($msglower);
  235. if($jammer) {
  236. $message = preg_replace_callback("/\r\n|\n|\r/", 'discuzcode_callback_jammer', $message);
  237. }
  238. if($first) {
  239. if(helper_access::check_module('group')) {
  240. $message = preg_replace("/\[groupid=(\d+)\](.*)\[\/groupid\]/i", lang('forum/template', 'fromgroup').': <a href="forum.php?mod=forumdisplay&fid=\\1" target="_blank">\\2</a>', $message);
  241. } else {
  242. $message = preg_replace("/(\[groupid=\d+\].*\[\/groupid\])/i", '', $message);
  243. }
  244. }
  245. return $htmlon ? $message : nl2br(str_replace(array("\t", ' ', ' '), array('&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;'), $message));
  246. }
  247. function discuzcode_callback_codedisp_1($matches) {
  248. return codedisp($matches[1]);
  249. }
  250. function discuzcode_callback_parseattachurl_12($matches) {
  251. return parseattachurl($matches[1], $matches[2], 1);
  252. }
  253. function discuzcode_callback_parseed2k_1($matches) {
  254. return parseed2k($matches[1]);
  255. }
  256. function discuzcode_callback_parseurl_152($matches) {
  257. return parseurl($matches[1], $matches[5], $matches[2]);
  258. }
  259. function discuzcode_callback_parseemail_14($matches) {
  260. return parseemail($matches[1], $matches[4]);
  261. }
  262. function discuzcode_callback_parsetable_123($matches) {
  263. return parsetable($matches[1], $matches[2], $matches[3]);
  264. }
  265. function discuzcode_callback_parsemedia_12($matches) {
  266. return parsemedia($matches[1], $matches[2]);
  267. }
  268. function discuzcode_callback_bbcodeurl_2($matches) {
  269. return bbcodeurl($matches[2], '<a href="{url}" target="_blank">{url}</a>');
  270. }
  271. function discuzcode_callback_parseaudio_2($matches) {
  272. return parseaudio($matches[2], 400);
  273. }
  274. function discuzcode_callback_parseflash_234($matches) {
  275. return parseflash($matches[2], $matches[3], $matches[4]);
  276. }
  277. function discuzcode_callback_bbcodeurl_4($matches) {
  278. return bbcodeurl($matches[4], '<a href="{url}" target="_blank">{url}</a>');
  279. }
  280. function discuzcode_callback_bbcodeurl_1($matches) {
  281. return bbcodeurl($matches[1], ' <img src="'.STATICURL.'image/filetype/flash.gif" align="absmiddle" alt="" /> <a href="{url}" target="_blank">Flash: {url}</a> ');
  282. }
  283. function discuzcode_callback_jammer($matches) {
  284. return jammer();
  285. }
  286. function parseurl($url, $text, $scheme) {
  287. global $_G;
  288. if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
  289. $url = $matches[0];
  290. $length = 65;
  291. if(strlen($url) > $length) {
  292. $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  293. }
  294. return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
  295. } else {
  296. $url = substr($url, 1);
  297. if(substr(strtolower($url), 0, 4) == 'www.') {
  298. $url = 'http://'.$url;
  299. }
  300. $url = !$scheme ? $_G['siteurl'].$url : $url;
  301. return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
  302. }
  303. }
  304. function parseflash($w, $h, $url) {
  305. $w = !$w ? 550 : $w;
  306. $h = !$h ? 400 : $h;
  307. preg_match("/((https?){1}:\/\/|www\.)[^\r\n\[\"'\?]+(\.swf|\.flv)(\?[^\r\n\[\"'\?]+)?/i", $url, $matches);
  308. $url = $matches[0];
  309. $randomid = 'swf_'.random(3);
  310. if(fileext($url) != 'flv') {
  311. 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\', encodeURI(\''.$url.'\'), \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  312. } else {
  313. 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>';
  314. }
  315. }
  316. function parseed2k($url) {
  317. global $_G;
  318. list(,$type, $name, $size,) = explode('|', $url);
  319. $url = 'ed2k://'.$url.'/';
  320. $name = addslashes($name);
  321. if($type == 'file') {
  322. $ed2kid = 'ed2k_'.random(3);
  323. 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>';
  324. } else {
  325. return '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  326. }
  327. }
  328. function parseattachurl($aid, $ext, $ignoretid = 0) {
  329. global $_G;
  330. $_G['forum_skipaidlist'][] = $aid;
  331. return $_G['siteurl'].'forum.php?mod=attachment&aid='.aidencode($aid, $ext, $ignoretid ? '' : $_G['tid']).($ext ? '&request=yes&_f=.'.$ext : '');
  332. }
  333. function parseemail($email, $text) {
  334. $text = str_replace('\"', '"', $text);
  335. if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
  336. $email = trim($matches[0]);
  337. return '<a href="mailto:'.$email.'">'.$email.'</a>';
  338. } else {
  339. return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
  340. }
  341. }
  342. function parsetable($width, $bgcolor, $message) {
  343. if(strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
  344. $rows = explode("\n", $message);
  345. $s = !defined('IN_MOBILE') ? '<table cellspacing="0" class="t_table" '.
  346. ($width == '' ? NULL : 'style="width:'.$width.'"').
  347. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>') : '<table>';
  348. foreach($rows as $row) {
  349. $s .= '<tr><td>'.str_replace(array('\|', '|', '\n'), array('&#124;', '</td><td>', "\n"), $row).'</td></tr>';
  350. }
  351. $s .= '</table>';
  352. return $s;
  353. } else {
  354. if(!preg_match("/^\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td([=\d,%]+)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
  355. return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)\s%,#\w]+))?\]|\[td([=\d,%]+)?\]|\[\/td\]|\[\/tr\]/", '', $message));
  356. }
  357. if(substr($width, -1) == '%') {
  358. $width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%';
  359. } else {
  360. $width = intval($width);
  361. $width = $width ? ($width <= 560 ? $width.'px' : '98%') : '';
  362. }
  363. $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'parsetable_callback_parsetrtd_12', $message);
  364. $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'parsetable_callback_parsetrtd_1', $message);
  365. $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'parsetable_callback_parsetrtd_1234', $message);
  366. $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'parsetable_callback_parsetrtd_123', $message);
  367. $message = preg_replace("/\[\/td\]\s*\[\/tr\]\s*/i", '</td></tr>', $message);
  368. return (!defined('IN_MOBILE') ? '<table cellspacing="0" class="t_table" '.
  369. ($width == '' ? NULL : 'style="width:'.$width.'"').
  370. ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>') : '<table>').
  371. str_replace('\\"', '"', $message).'</table>';
  372. }
  373. }
  374. function parsetable_callback_parsetrtd_12($matches) {
  375. return parsetrtd($matches[1], 0, 0, $matches[2]);
  376. }
  377. function parsetable_callback_parsetrtd_1($matches) {
  378. return parsetrtd('td', 0, 0, $matches[1]);
  379. }
  380. function parsetable_callback_parsetrtd_1234($matches) {
  381. return parsetrtd($matches[1], $matches[2], $matches[3], $matches[4]);
  382. }
  383. function parsetable_callback_parsetrtd_123($matches) {
  384. return parsetrtd('td', $matches[1], $matches[2], $matches[3]);
  385. }
  386. function parsetrtd($bgcolor, $colspan, $rowspan, $width) {
  387. return ($bgcolor == 'td' ? '</td>' : '<tr'.($bgcolor && !defined('IN_MOBILE') ? ' style="background-color:'.$bgcolor.'"' : '').'>').'<td'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').($rowspan > 1 ? ' rowspan="'.$rowspan.'"' : '').($width && !defined('IN_MOBILE') ? ' width="'.$width.'"' : '').'>';
  388. }
  389. function parseaudio($url, $width = 400) {
  390. $url = addslashes($url);
  391. if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://')) && !preg_match('/^static\//', $url) && !preg_match('/^data\//', $url)) {
  392. return dhtmlspecialchars($url);
  393. }
  394. $ext = fileext($url);
  395. switch($ext) {
  396. case 'mp3':
  397. $randomid = 'mp3_'.random(3);
  398. 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\', \'allowNetworking\', \'internal\');</script>';
  399. case 'wma':
  400. case 'mid':
  401. case 'wav':
  402. 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>';
  403. case 'ra':
  404. case 'rm':
  405. case 'ram':
  406. $mediaid = 'media_'.random(3);
  407. 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>';
  408. }
  409. }
  410. function parsemedia($params, $url) {
  411. $params = explode(',', $params);
  412. $width = intval($params[1]) > 800 ? 800 : intval($params[1]);
  413. $height = intval($params[2]) > 600 ? 600 : intval($params[2]);
  414. $url = addslashes($url);
  415. if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://')) && !preg_match('/^static\//', $url) && !preg_match('/^data\//', $url)) {
  416. return dhtmlspecialchars($url);
  417. }
  418. if($flv = parseflv($url, $width, $height)) {
  419. return $flv;
  420. }
  421. if(in_array(count($params), array(3, 4))) {
  422. $type = $params[0];
  423. $url = htmlspecialchars(str_replace(array('<', '>'), '', str_replace('\\"', '\"', $url)));
  424. switch($type) {
  425. case 'mp3':
  426. case 'wma':
  427. case 'ra':
  428. case 'ram':
  429. case 'wav':
  430. case 'mid':
  431. return parseaudio($url, $width);
  432. case 'rm':
  433. case 'rmvb':
  434. case 'rtsp':
  435. $mediaid = 'media_'.random(3);
  436. 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>';
  437. case 'flv':
  438. $randomid = 'flv_'.random(3);
  439. 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>';
  440. case 'swf':
  441. $randomid = 'swf_'.random(3);
  442. 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\', encodeURI(\''.$url.'\'), \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\');</script>';
  443. case 'asf':
  444. case 'asx':
  445. case 'wmv':
  446. case 'mms':
  447. case 'avi':
  448. case 'mpg':
  449. case 'mpeg':
  450. 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>';
  451. case 'mov':
  452. 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>';
  453. default:
  454. return '<a href="'.$url.'" target="_blank">'.$url.'</a>';
  455. }
  456. }
  457. return;
  458. }
  459. function bbcodeurl($url, $tags) {
  460. if(!preg_match("/<.+?>/s", $url)) {
  461. if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://')) && !preg_match('/^static\//', $url) && !preg_match('/^data\//', $url)) {
  462. $url = 'http://'.$url;
  463. }
  464. return str_replace(array('submit', 'member.php?mod=logging'), array('', ''), str_replace('{url}', addslashes($url), $tags));
  465. } else {
  466. return '&nbsp;'.$url;
  467. }
  468. }
  469. function jammer() {
  470. $randomstr = '';
  471. for($i = 0; $i < mt_rand(5, 15); $i++) {
  472. $randomstr .= chr(mt_rand(32, 59)).' '.chr(mt_rand(63, 126));
  473. }
  474. return mt_rand(0, 1) ? '<font class="jammer">'.$randomstr.'</font>'."\r\n" :
  475. "\r\n".'<span style="display:none">'.$randomstr.'</span>';
  476. }
  477. function highlightword($text, $words, $prepend) {
  478. $text = str_replace('\"', '"', $text);
  479. foreach($words AS $key => $replaceword) {
  480. $text = str_replace($replaceword, '<highlight>'.$replaceword.'</highlight>', $text);
  481. }
  482. return "$prepend$text";
  483. }
  484. function parseflv($url, $width = 0, $height = 0) {
  485. $lowerurl = strtolower($url);
  486. $flv = $iframe = $imgurl = '';
  487. if($lowerurl != str_replace(array('player.youku.com/player.php/sid/','tudou.com/v/','player.ku6.com/refer/'), '', $lowerurl)) {
  488. $flv = $url;
  489. } elseif(strpos($lowerurl, 'v.youku.com/v_show/') !== FALSE) {
  490. $ctx = stream_context_create(array('http' => array('timeout' => 10)));
  491. if(preg_match("/^https?:\/\/v.youku.com\/v_show\/id_([^\/]+)(.html|)/i", $url, $matches)) {
  492. $flv = 'https://player.youku.com/player.php/sid/'.$matches[1].'/v.swf';
  493. $iframe = 'https://player.youku.com/embed/'.$matches[1];
  494. if(!$width && !$height) {
  495. $api = 'http://v.youku.com/player/getPlayList/VideoIDS/'.$matches[1];
  496. $str = stripslashes(file_get_contents($api, false, $ctx));
  497. if(!empty($str) && preg_match("/\"logo\":\"(.+?)\"/i", $str, $image)) {
  498. $url = substr($image[1], 0, strrpos($image[1], '/')+1);
  499. $filename = substr($image[1], strrpos($image[1], '/')+2);
  500. $imgurl = $url.'0'.$filename;
  501. }
  502. }
  503. }
  504. } elseif(strpos($lowerurl, 'tudou.com/programs/view/') !== FALSE) {
  505. if(preg_match("/^http:\/\/(www.)?tudou.com\/programs\/view\/([^\/]+)/i", $url, $matches)) {
  506. $flv = 'http://www.tudou.com/v/'.$matches[2];
  507. $iframe = 'http://www.tudou.com/programs/view/html5embed.action?code='.$matches[2];
  508. if(!$width && !$height) {
  509. $str = file_get_contents($url, false, $ctx);
  510. if(!empty($str) && preg_match("/<span class=\"s_pic\">(.+?)<\/span>/i", $str, $image)) {
  511. $imgurl = trim($image[1]);
  512. }
  513. }
  514. }
  515. } elseif(strpos($lowerurl, 'v.ku6.com/show/') !== FALSE) {
  516. if(preg_match("/^http:\/\/v.ku6.com\/show\/([^\/]+).html/i", $url, $matches)) {
  517. $flv = 'http://player.ku6.com/refer/'.$matches[1].'/v.swf';
  518. if(!$width && !$height) {
  519. $api = 'http://vo.ku6.com/fetchVideo4Player/1/'.$matches[1].'.html';
  520. $str = file_get_contents($api, false, $ctx);
  521. if(!empty($str) && preg_match("/\"picpath\":\"(.+?)\"/i", $str, $image)) {
  522. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  523. }
  524. }
  525. }
  526. } elseif(strpos($lowerurl, 'v.ku6.com/special/show_') !== FALSE) {
  527. if(preg_match("/^http:\/\/v.ku6.com\/special\/show_\d+\/([^\/]+).html/i", $url, $matches)) {
  528. $flv = 'http://player.ku6.com/refer/'.$matches[1].'/v.swf';
  529. if(!$width && !$height) {
  530. $api = 'http://vo.ku6.com/fetchVideo4Player/1/'.$matches[1].'.html';
  531. $str = file_get_contents($api, false, $ctx);
  532. if(!empty($str) && preg_match("/\"picpath\":\"(.+?)\"/i", $str, $image)) {
  533. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  534. }
  535. }
  536. }
  537. } elseif(strpos($lowerurl, 'www.youtube.com/watch?') !== FALSE) {
  538. if(preg_match("/^https?:\/\/www.youtube.com\/watch\?v=([^\/&]+)&?/i", $url, $matches)) {
  539. $flv = 'https://www.youtube.com/v/'.$matches[1].'&hl=zh_CN&fs=1';
  540. $iframe = 'https://www.youtube.com/embed/'.$matches[1];
  541. if(!$width && !$height) {
  542. $str = file_get_contents($url, false, $ctx);
  543. if(!empty($str) && preg_match("/'VIDEO_HQ_THUMB':\s'(.+?)'/i", $str, $image)) {
  544. $url = substr($image[1], 0, strrpos($image[1], '/')+1);
  545. $filename = substr($image[1], strrpos($image[1], '/')+3);
  546. $imgurl = $url.$filename;
  547. }
  548. }
  549. }
  550. } elseif(strpos($lowerurl, 'video.sina.com.cn/v/b/') !== FALSE) {
  551. if(preg_match("/^http:\/\/video.sina.com.cn\/v\/b\/(\d+)-(\d+).html/i", $url, $matches)) {
  552. $flv = 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid='.$matches[1];
  553. if(!$width && !$height) {
  554. $api = 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?vid='.$matches[1];
  555. $str = file_get_contents($api, false, $ctx);
  556. if(!empty($str)) {
  557. $imgurl = str_replace('imgurl=', '', trim($str));
  558. }
  559. }
  560. }
  561. } elseif(strpos($lowerurl, 'you.video.sina.com.cn/b/') !== FALSE) {
  562. if(preg_match("/^http:\/\/you.video.sina.com.cn\/b\/(\d+)-(\d+).html/i", $url, $matches)) {
  563. $flv = 'http://vhead.blog.sina.com.cn/player/outer_player.swf?vid='.$matches[1];
  564. if(!$width && !$height) {
  565. $api = 'http://interface.video.sina.com.cn/interface/common/getVideoImage.php?vid='.$matches[1];
  566. $str = file_get_contents($api, false, $ctx);
  567. if(!empty($str)) {
  568. $imgurl = str_replace('imgurl=', '', trim($str));
  569. }
  570. }
  571. }
  572. } elseif(strpos($lowerurl, 'http://my.tv.sohu.com/u/') !== FALSE) {
  573. if(preg_match("/^http:\/\/my.tv.sohu.com\/u\/[^\/]+\/(\d+)/i", $url, $matches)) {
  574. $flv = 'http://v.blog.sohu.com/fo/v4/'.$matches[1];
  575. if(!$width && !$height) {
  576. $api = 'http://v.blog.sohu.com/videinfo.jhtml?m=view&id='.$matches[1].'&outType=3';
  577. $str = file_get_contents($api, false, $ctx);
  578. if(!empty($str) && preg_match("/\"cutCoverURL\":\"(.+?)\"/i", $str, $image)) {
  579. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  580. }
  581. }
  582. }
  583. } elseif(strpos($lowerurl, 'http://v.blog.sohu.com/u/') !== FALSE) {
  584. if(preg_match("/^http:\/\/v.blog.sohu.com\/u\/[^\/]+\/(\d+)/i", $url, $matches)) {
  585. $flv = 'http://v.blog.sohu.com/fo/v4/'.$matches[1];
  586. if(!$width && !$height) {
  587. $api = 'http://v.blog.sohu.com/videinfo.jhtml?m=view&id='.$matches[1].'&outType=3';
  588. $str = file_get_contents($api, false, $ctx);
  589. if(!empty($str) && preg_match("/\"cutCoverURL\":\"(.+?)\"/i", $str, $image)) {
  590. $imgurl = str_replace(array('\u003a', '\u002e'), array(':', '.'), $image[1]);
  591. }
  592. }
  593. }
  594. } elseif(strpos($lowerurl, 'http://www.56.com') !== FALSE) {
  595. if(preg_match("/^http:\/\/www.56.com\/\S+\/play_album-aid-(\d+)_vid-(.+?).html/i", $url, $matches)) {
  596. $flv = 'http://player.56.com/v_'.$matches[2].'.swf';
  597. $matches[1] = $matches[2];
  598. } elseif(preg_match("/^http:\/\/www.56.com\/\S+\/([^\/]+).html/i", $url, $matches)) {
  599. $flv = 'http://player.56.com/'.$matches[1].'.swf';
  600. }
  601. if(!$width && !$height && !empty($matches[1])) {
  602. $api = 'http://vxml.56.com/json/'.str_replace('v_', '', $matches[1]).'/?src=out';
  603. $str = file_get_contents($api, false, $ctx);
  604. if(!empty($str) && preg_match("/\"img\":\"(.+?)\"/i", $str, $image)) {
  605. $imgurl = trim($image[1]);
  606. }
  607. }
  608. }
  609. if($flv) {
  610. if(!$width && !$height) {
  611. return array('flv' => $flv, 'imgurl' => $imgurl);
  612. } else {
  613. $width = addslashes($width);
  614. $height = addslashes($height);
  615. $flv = addslashes($flv);
  616. $iframe = addslashes($iframe);
  617. $randomid = 'flv_'.random(3);
  618. $enablemobile = $iframe ? 'mobileplayer() ? "<iframe height=\''.$height.'\' width=\''.$width.'\' src=\''.$iframe.'\' frameborder=0 allowfullscreen></iframe>" : ' : '';
  619. return '<span id="'.$randomid.'"></span><script type="text/javascript" reload="1">$(\''.$randomid.'\').innerHTML=('.$enablemobile.'AC_FL_RunContent(\'width\', \''.$width.'\', \'height\', \''.$height.'\', \'allowNetworking\', \'internal\', \'allowScriptAccess\', \'never\', \'src\', \''.$flv.'\', \'quality\', \'high\', \'bgcolor\', \'#ffffff\', \'wmode\', \'transparent\', \'allowfullscreen\', \'true\'));</script>';
  620. }
  621. } else {
  622. return FALSE;
  623. }
  624. }
  625. function parseimg($width, $height, $src, $lazyload, $pid, $extra = '') {
  626. global $_G;
  627. static $styleoutput = null;
  628. if($_G['setting']['domainwhitelist_affectimg']) {
  629. $tmp = parse_url($src);
  630. if(!empty($tmp['host']) && !iswhitelist($tmp['host'])) {
  631. return $src;
  632. }
  633. }
  634. if(strstr($src, 'file:') || substr($src, 1, 1) == ':') {
  635. return $src;
  636. }
  637. if($width > $_G['setting']['imagemaxwidth']) {
  638. $height = intval($_G['setting']['imagemaxwidth'] * $height / $width);
  639. $width = $_G['setting']['imagemaxwidth'];
  640. if(defined('IN_MOBILE')) {
  641. $extra = '';
  642. } else {
  643. $extra = 'onmouseover="img_onmouseoverfunc(this)" onclick="zoom(this)" style="cursor:pointer"';
  644. }
  645. }
  646. $attrsrc = !IS_ROBOT && $lazyload ? 'file' : 'src';
  647. $rimg_id = random(5);
  648. $GLOBALS['aimgs'][$pid][] = $rimg_id;
  649. $guestviewthumb = !empty($_G['setting']['guestviewthumb']['flag']) && empty($_G['uid']);
  650. $img = '';
  651. if($guestviewthumb) {
  652. if(!isset($styleoutput)) {
  653. $img .= guestviewthumbstyle();
  654. $styleoutput = true;
  655. }
  656. $img .= '<div class="guestviewthumb"><img id="aimg_'.$rimg_id.'" class="guestviewthumb_cur" onclick="showWindow(\'login\', \'{loginurl}\'+\'&referer=\'+encodeURIComponent(location))" '.$attrsrc.'="{url}" border="0" alt="" />
  657. <br><a href="{loginurl}" onclick="showWindow(\'login\', this.href+\'&referer=\'+encodeURIComponent(location));">'.lang('forum/template', 'guestviewthumb').'</a></div>';
  658. } else {
  659. if(defined('IN_MOBILE')) {
  660. $img = '<img'.($width > 0 ? ' width="'.$width.'"' : '').($height > 0 ? ' height="'.$height.'"' : '').' src="{url}" border="0" alt="" />';
  661. } else {
  662. $img = '<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.'="{url}" '.($extra ? $extra.' ' : '').'border="0" alt="" />';
  663. }
  664. }
  665. $code = bbcodeurl($src, $img);
  666. if($guestviewthumb) {
  667. $code = str_replace('{loginurl}', 'member.php?mod=logging&action=login', $code);
  668. }
  669. return $code;
  670. }
  671. function parsesmiles(&$message) {
  672. global $_G;
  673. static $enablesmiles;
  674. if($enablesmiles === null) {
  675. $enablesmiles = false;
  676. if(!empty($_G['cache']['smilies']) && is_array($_G['cache']['smilies'])) {
  677. foreach($_G['cache']['smilies']['replacearray'] AS $key => $smiley) {
  678. $_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="" />';
  679. }
  680. $enablesmiles = true;
  681. }
  682. }
  683. $enablesmiles && $message = preg_replace($_G['cache']['smilies']['searcharray'], $_G['cache']['smilies']['replacearray'], $message, $_G['setting']['maxsmilies']);
  684. return $message;
  685. }
  686. function parsepostbg($bgimg, $pid) {
  687. global $_G;
  688. static $postbg;
  689. if($postbg[$pid]) {
  690. return '';
  691. }
  692. loadcache('postimg');
  693. foreach($_G['cache']['postimg']['postbg'] as $postbg) {
  694. if($postbg['url'] != $bgimg) {
  695. continue;
  696. }
  697. $bgimg = dhtmlspecialchars(basename($bgimg), ENT_QUOTES);
  698. $postbg[$pid] = true;
  699. $_G['forum_posthtml']['header'][$pid] .= '<style type="text/css">#pid'.$pid.'{background-image:url("'.STATICURL.'image/postbg/'.$bgimg.'");}</style>';
  700. break;
  701. }
  702. return '';
  703. }
  704. function parsepassword($password, $pid) {
  705. global $_G;
  706. static $postpw;
  707. if($postpw[$pid]) {
  708. return '';
  709. }
  710. $postpw[$pid] = true;
  711. if(empty($_G['cookie']['postpw_'.$pid]) || $_G['cookie']['postpw_'.$pid] != md5($password)) {
  712. $_G['forum_discuzcode']['passwordlock'][$pid] = 1;
  713. }
  714. return '';
  715. }
  716. function guestviewthumbstyle() {
  717. static $styleoutput = null;
  718. $return = '';
  719. if ($styleoutput === null) {
  720. global $_G;
  721. $return = '<style>.guestviewthumb {margin:10px auto; text-align:center;}.guestviewthumb a {font-size:12px;}.guestviewthumb_cur {cursor:url('.IMGDIR.'/scf.cur), default; max-width:'.$_G['setting']['guestviewthumb']['width'].'px;}.ie6 .guestviewthumb_cur { width:'.$_G['setting']['guestviewthumb']['width'].'px !important;}</style>';
  722. $styleoutput = true;
  723. }
  724. return $return;
  725. }
  726. ?>