function_forum.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  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_forum.php 36345 2017-01-12 01:55:04Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function discuz_uc_avatar($uid, $size = '', $returnsrc = FALSE) {
  12. global $_G;
  13. return avatar($uid, $size, $returnsrc, FALSE, $_G['setting']['avatarmethod'], $_G['setting']['ucenterurl']);
  14. }
  15. function dunlink($attach) {
  16. global $_G;
  17. $filename = $attach['attachment'];
  18. $havethumb = $attach['thumb'];
  19. $remote = $attach['remote'];
  20. if($remote) {
  21. ftpcmd('delete', 'forum/'.$filename);
  22. $havethumb && ftpcmd('delete', 'forum/'.getimgthumbname($filename));
  23. } else {
  24. @unlink($_G['setting']['attachdir'].'/forum/'.$filename);
  25. $havethumb && @unlink($_G['setting']['attachdir'].'/forum/'.getimgthumbname($filename));
  26. }
  27. if($attach['aid']) {
  28. @unlink($_G['setting']['attachdir'].'image/'.$attach['aid'].'_100_100.jpg');
  29. }
  30. }
  31. function formulaperm($formula) {
  32. global $_G;
  33. if($_G['forum']['ismoderator']) {
  34. return TRUE;
  35. }
  36. $formula = dunserialize($formula);
  37. $medalperm = $formula['medal'];
  38. $permusers = $formula['users'];
  39. $permmessage = $formula['message'];
  40. if($_G['setting']['medalstatus'] && $medalperm) {
  41. $exists = 1;
  42. $_G['forum_formulamessage'] = '';
  43. $medalpermc = $medalperm;
  44. if($_G['uid']) {
  45. $memberfieldforum = C::t('common_member_field_forum')->fetch($_G['uid']);
  46. $medals = explode("\t", $memberfieldforum['medals']);
  47. unset($memberfieldforum);
  48. foreach($medalperm as $k => $medal) {
  49. foreach($medals as $r) {
  50. list($medalid) = explode("|", $r);
  51. if($medalid == $medal) {
  52. $exists = 0;
  53. unset($medalpermc[$k]);
  54. }
  55. }
  56. }
  57. } else {
  58. $exists = 0;
  59. }
  60. if($medalpermc) {
  61. loadcache('medals');
  62. foreach($medalpermc as $medal) {
  63. if($_G['cache']['medals'][$medal]) {
  64. $_G['forum_formulamessage'] .= '<img src="'.STATICURL.'image/common/'.$_G['cache']['medals'][$medal]['image'].'" style="vertical-align:middle;" />&nbsp;'.$_G['cache']['medals'][$medal]['name'].'&nbsp; ';
  65. }
  66. }
  67. showmessage('forum_permforum_nomedal', NULL, array('forum_permforum_nomedal' => $_G['forum_formulamessage']), array('login' => 1));
  68. }
  69. }
  70. $formulatext = $formula[0];
  71. $formula = $formula[1];
  72. if($_G['adminid'] == 1 || $_G['forum']['ismoderator'] || in_array($_G['groupid'], explode("\t", $_G['forum']['spviewperm']))) {
  73. return FALSE;
  74. }
  75. if($permusers) {
  76. $permusers = str_replace(array("\r\n", "\r"), array("\n", "\n"), $permusers);
  77. $permusers = explode("\n", trim($permusers));
  78. if(!in_array($_G['member']['username'], $permusers)) {
  79. showmessage('forum_permforum_disallow', NULL, array(), array('login' => 1));
  80. }
  81. }
  82. if(!$formula) {
  83. return FALSE;
  84. }
  85. if(strexists($formula, '$memberformula[')) {
  86. preg_match_all("/\\\$memberformula\['(\w+?)'\]/", $formula, $a);
  87. $profilefields = array();
  88. foreach($a[1] as $field) {
  89. switch($field) {
  90. case 'regdate':
  91. $formula = preg_replace_callback("/\{(\d{4})\-(\d{1,2})\-(\d{1,2})\}/", 'formulaperm_callback_123', $formula);
  92. case 'regday':
  93. break;
  94. case 'regip':
  95. case 'lastip':
  96. $formula = preg_replace("/\{([\d\.]+?)\}/", "'\\1'", $formula);
  97. $formula = preg_replace('/(\$memberformula\[\'(regip|lastip)\'\])\s*=+\s*\'([\d\.]+?)\'/', "strpos(\\1, '\\3')===0", $formula);
  98. case 'buyercredit':
  99. case 'sellercredit':
  100. space_merge($_G['member'], 'status');break;
  101. case substr($field, 0, 5) == 'field':
  102. space_merge($_G['member'], 'profile');
  103. $profilefields[] = $field;break;
  104. }
  105. }
  106. $memberformula = array();
  107. if($_G['uid']) {
  108. $memberformula = $_G['member'];
  109. if(in_array('regday', $a[1])) {
  110. $memberformula['regday'] = intval((TIMESTAMP - $memberformula['regdate']) / 86400);
  111. }
  112. if(in_array('regdate', $a[1])) {
  113. $memberformula['regdate'] = date('Y-m-d', $memberformula['regdate']);
  114. }
  115. $memberformula['lastip'] = $memberformula['lastip'] ? $memberformula['lastip'] : $_G['clientip'];
  116. } else {
  117. if(isset($memberformula['regip'])) {
  118. $memberformula['regip'] = $_G['clientip'];
  119. }
  120. if(isset($memberformula['lastip'])) {
  121. $memberformula['lastip'] = $_G['clientip'];
  122. }
  123. }
  124. }
  125. @eval("\$formulaperm = ($formula) ? TRUE : FALSE;");
  126. if(!$formulaperm) {
  127. if(!$permmessage) {
  128. $language = lang('forum/misc');
  129. $search = array('regdate', 'regday', 'regip', 'lastip', 'buyercredit', 'sellercredit', 'digestposts', 'posts', 'threads', 'oltime');
  130. $replace = array($language['formulaperm_regdate'], $language['formulaperm_regday'], $language['formulaperm_regip'], $language['formulaperm_lastip'], $language['formulaperm_buyercredit'], $language['formulaperm_sellercredit'], $language['formulaperm_digestposts'], $language['formulaperm_posts'], $language['formulaperm_threads'], $language['formulaperm_oltime']);
  131. for($i = 1; $i <= 8; $i++) {
  132. $search[] = 'extcredits'.$i;
  133. $replace[] = $_G['setting']['extcredits'][$i]['title'] ? $_G['setting']['extcredits'][$i]['title'] : $language['formulaperm_extcredits'].$i;
  134. }
  135. if($profilefields) {
  136. loadcache(array('fields_required', 'fields_optional'));
  137. foreach($profilefields as $profilefield) {
  138. $search[] = $profilefield;
  139. $replace[] = !empty($_G['cache']['fields_optional']['field_'.$profilefield]) ? $_G['cache']['fields_optional']['field_'.$profilefield]['title'] : $_G['cache']['fields_required']['field_'.$profilefield]['title'];
  140. }
  141. }
  142. $i = 0;$_G['forum_usermsg'] = '';
  143. foreach($search as $s) {
  144. if(in_array($s, array('digestposts', 'posts', 'threads', 'oltime', 'extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8'))) {
  145. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return intval(getuserprofile(\''.$s.'\'));')) : '';
  146. } elseif(in_array($s, array('regdate', 'regip', 'regday'))) {
  147. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return $memberformula[\''.$s.'\'];')) : '';
  148. }
  149. $i++;
  150. }
  151. $search = array_merge($search, array('and', 'or', '>=', '<=', '=='));
  152. $replace = array_merge($replace, array('&nbsp;&nbsp;<b>'.$language['formulaperm_and'].'</b>&nbsp;&nbsp;', '&nbsp;&nbsp;<b>'.$language['formulaperm_or'].'</b>&nbsp;&nbsp;', '&ge;', '&le;', '='));
  153. $_G['forum_formulamessage'] = str_replace($search, $replace, $formulatext);
  154. } else {
  155. $_G['forum_formulamessage'] = $permmessage;
  156. }
  157. if(!$permmessage) {
  158. showmessage('forum_permforum_nopermission', NULL, array('formulamessage' => $_G['forum_formulamessage'], 'usermsg' => $_G['forum_usermsg']), array('login' => 1));
  159. } else {
  160. showmessage('forum_permforum_nopermission_custommsg', NULL, array('formulamessage' => $_G['forum_formulamessage']), array('login' => 1));
  161. }
  162. }
  163. return TRUE;
  164. }
  165. function formulaperm_callback_123($matches) {
  166. return '\''.$matches[1].'-'.sprintf('%02d', $matches[2]).'-'.sprintf('%02d', $matches[3]).'\'';
  167. }
  168. function medalformulaperm($formula, $type) {
  169. global $_G;
  170. $formula = dunserialize($formula);
  171. $permmessage = $formula['message'];
  172. $formula = $formula['medal'];
  173. if(!empty($formula['usergroupallow']) && is_array($formula['usergroups']) && !in_array($_G['groupid'], $formula['usergroups'])) {
  174. loadcache('usergroups');
  175. $message = array();
  176. foreach($formula['usergroups'] as $groupid) {
  177. $message[] = $_G['cache']['usergroups'][$groupid]['grouptitle'].' ';
  178. }
  179. $_G['forum_formulamessage'] = implode(', ', $message);
  180. $_G['forum_usermsg'] = $_G['cache']['usergroups'][$_G['groupid']]['grouptitle'];
  181. return FALSE;
  182. }
  183. $formulatext = $formula[0];
  184. $formula = $formula[1];
  185. if(!$formula) {
  186. return FALSE;
  187. }
  188. if(strexists($formula, '$memberformula[')) {
  189. preg_match_all("/\\\$memberformula\['(\w+?)'\]/", $formula, $a);
  190. $profilefields = array();
  191. foreach($a[1] as $field) {
  192. switch($field) {
  193. case 'regdate':
  194. $formula = preg_replace_callback("/\{(\d{4})\-(\d{1,2})\-(\d{1,2})\}/", 'medalformulaperm_callback_123', $formula);
  195. case 'regday':
  196. break;
  197. case 'regip':
  198. case 'lastip':
  199. $formula = preg_replace("/\{([\d\.]+?)\}/", "'\\1'", $formula);
  200. $formula = preg_replace('/(\$memberformula\[\'(regip|lastip)\'\])\s*=+\s*\'([\d\.]+?)\'/', "strpos(\\1, '\\3')===0", $formula);
  201. case 'buyercredit':
  202. case 'sellercredit':
  203. space_merge($_G['member'], 'status');break;
  204. case substr($field, 0, 5) == 'field':
  205. space_merge($_G['member'], 'profile');
  206. $profilefields[] = $field;break;
  207. }
  208. }
  209. $memberformula = array();
  210. if($_G['uid']) {
  211. $memberformula = $_G['member'];
  212. if(in_array('regday', $a[1])) {
  213. $memberformula['regday'] = intval((TIMESTAMP - $memberformula['regdate']) / 86400);
  214. }
  215. if(in_array('regdate', $a[1])) {
  216. $memberformula['regdate'] = date('Y-m-d', $memberformula['regdate']);
  217. }
  218. $memberformula['lastip'] = $memberformula['lastip'] ? $memberformula['lastip'] : $_G['clientip'];
  219. } else {
  220. if(isset($memberformula['regip'])) {
  221. $memberformula['regip'] = $_G['clientip'];
  222. }
  223. if(isset($memberformula['lastip'])) {
  224. $memberformula['lastip'] = $_G['clientip'];
  225. }
  226. }
  227. }
  228. @eval("\$formulaperm = ($formula) ? TRUE : FALSE;");
  229. if(!$formulaperm || $type == 2) {
  230. if(!$permmessage) {
  231. $language = lang('forum/misc');
  232. $search = array('regdate', 'regday', 'regip', 'lastip', 'buyercredit', 'sellercredit', 'digestposts', 'posts', 'threads', 'oltime');
  233. $replace = array($language['formulaperm_regdate'], $language['formulaperm_regday'], $language['formulaperm_regip'], $language['formulaperm_lastip'], $language['formulaperm_buyercredit'], $language['formulaperm_sellercredit'], $language['formulaperm_digestposts'], $language['formulaperm_posts'], $language['formulaperm_threads'], $language['formulaperm_oltime']);
  234. for($i = 1; $i <= 8; $i++) {
  235. $search[] = 'extcredits'.$i;
  236. $replace[] = $_G['setting']['extcredits'][$i]['title'] ? $_G['setting']['extcredits'][$i]['title'] : $language['formulaperm_extcredits'].$i;
  237. }
  238. if($profilefields) {
  239. loadcache(array('fields_required', 'fields_optional'));
  240. foreach($profilefields as $profilefield) {
  241. $search[] = $profilefield;
  242. $replace[] = !empty($_G['cache']['fields_optional']['field_'.$profilefield]) ? $_G['cache']['fields_optional']['field_'.$profilefield]['title'] : $_G['cache']['fields_required']['field_'.$profilefield]['title'];
  243. }
  244. }
  245. $i = 0;$_G['forum_usermsg'] = '';
  246. foreach($search as $s) {
  247. if(in_array($s, array('digestposts', 'posts', 'threads', 'oltime', 'extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8'))) {
  248. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return intval(getuserprofile(\''.$s.'\'));')) : '';
  249. } elseif(in_array($s, array('regdate', 'regip'))) {
  250. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return $memberformula[\''.$s.'\'];')) : '';
  251. }
  252. $i++;
  253. }
  254. $search = array_merge($search, array('and', 'or', '>=', '<=', '=='));
  255. $replace = array_merge($replace, array('&nbsp;&nbsp;<b>'.$language['formulaperm_and'].'</b>&nbsp;&nbsp;', '&nbsp;&nbsp;<b>'.$language['formulaperm_or'].'</b>&nbsp;&nbsp;', '&ge;', '&le;', '='));
  256. $_G['forum_formulamessage'] = str_replace($search, $replace, $formulatext);
  257. } else {
  258. $_G['forum_formulamessage'] = $permmessage;
  259. }
  260. return $_G['forum_formulamessage'];
  261. } elseif($formulaperm && $type == 1) {
  262. return FALSE;
  263. }
  264. return TRUE;
  265. }
  266. function medalformulaperm_callback_123($matches) {
  267. return '\''.$matches[1].'-'.sprintf('%02d', $matches[2]).'-'.sprintf('%02d', $matches[3]).'\'';
  268. }
  269. function groupexpiry($terms) {
  270. $terms = is_array($terms) ? $terms : dunserialize($terms);
  271. $groupexpiry = isset($terms['main']['time']) ? intval($terms['main']['time']) : 0;
  272. if(is_array($terms['ext'])) {
  273. foreach($terms['ext'] as $expiry) {
  274. if((!$groupexpiry && $expiry) || $expiry < $groupexpiry) {
  275. $groupexpiry = $expiry;
  276. }
  277. }
  278. }
  279. return $groupexpiry;
  280. }
  281. function typeselect($curtypeid = 0) {
  282. global $_G;
  283. if($threadtypes = $_G['forum']['threadtypes']) {
  284. $html = '<select name="typeid" id="typeid"><option value="0">&nbsp;</option>';
  285. foreach($threadtypes['types'] as $typeid => $name) {
  286. $html .= '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected' : '').'>'.strip_tags($name).'</option>';
  287. }
  288. $html .= '</select>';
  289. return $html;
  290. } else {
  291. return '';
  292. }
  293. }
  294. function updatemodworks($modaction, $posts = 1) {
  295. global $_G;
  296. $today = dgmdate(TIMESTAMP, 'Y-m-d');
  297. if($_G['setting']['modworkstatus'] && $modaction && $posts) {
  298. $affect_rows = C::t('forum_modwork')->increase_count_posts_by_uid_modaction_dateline(1, $posts, $_G['uid'], $modaction, $today);
  299. if(!$affect_rows) {
  300. C::t('forum_modwork')->insert(array(
  301. 'uid' => $_G['uid'],
  302. 'modaction' => $modaction,
  303. 'dateline' => $today,
  304. 'count' => 1,
  305. 'posts' => $posts,
  306. ));
  307. }
  308. }
  309. }
  310. function buildbitsql($fieldname, $position, $value) {
  311. $t = " `$fieldname`=`$fieldname`";
  312. if($value) {
  313. $t .= ' | '.setstatus($position, 1);
  314. } else {
  315. $t .= ' & '.setstatus($position, 0);
  316. }
  317. return $t.' ';
  318. }
  319. function showmessagenoperm($type, $fid, $formula = '') {
  320. global $_G;
  321. loadcache('usergroups');
  322. if($formula) {
  323. $formula = dunserialize($formula);
  324. $permmessage = stripslashes($formula['message']);
  325. }
  326. $usergroups = $nopermgroup = $forumnoperms = array();
  327. $nopermdefault = array(
  328. 'viewperm' => array(),
  329. 'getattachperm' => array(),
  330. 'postperm' => array(7),
  331. 'replyperm' => array(7),
  332. 'postattachperm' => array(7),
  333. );
  334. $perms = array('viewperm', 'postperm', 'replyperm', 'getattachperm', 'postattachperm');
  335. foreach($_G['cache']['usergroups'] as $gid => $usergroup) {
  336. $usergroups[$gid] = $usergroup['type'];
  337. $grouptype = $usergroup['type'] == 'member' ? 0 : 1;
  338. $nopermgroup[$grouptype][] = $gid;
  339. }
  340. if($fid == $_G['forum']['fid']) {
  341. $forum = $_G['forum'];
  342. } else {
  343. $forum = C::t('forum_forumfield')->fetch($fid);
  344. }
  345. foreach($perms as $perm) {
  346. $permgroups = explode("\t", $forum[$perm]);
  347. $membertype = $forum[$perm] ? array_intersect($nopermgroup[0], $permgroups) : TRUE;
  348. $forumnoperm = $forum[$perm] ? array_diff(array_keys($usergroups), $permgroups) : $nopermdefault[$perm];
  349. foreach($forumnoperm as $groupid) {
  350. $nopermtype = $membertype && $groupid == 7 ? 'login' : ($usergroups[$groupid] == 'system' || $usergroups[$groupid] == 'special' ? 'none' : ($membertype ? 'upgrade' : 'none'));
  351. $forumnoperms[$fid][$perm][$groupid] = array($nopermtype, $permgroups);
  352. }
  353. }
  354. $v = $forumnoperms[$fid][$type][$_G['groupid']][0];
  355. $gids = $forumnoperms[$fid][$type][$_G['groupid']][1];
  356. $comma = $permgroups = '';
  357. if(is_array($gids)) {
  358. foreach($gids as $gid) {
  359. if($gid && $_G['cache']['usergroups'][$gid]) {
  360. $permgroups .= $comma.$_G['cache']['usergroups'][$gid]['grouptitle'];
  361. $comma = ', ';
  362. } elseif($_G['setting']['verify']['enabled'] && substr($gid, 0, 1) == 'v') {
  363. $vid = substr($gid, 1);
  364. $permgroups .= $comma.$_G['setting']['verify'][$vid]['title'];
  365. $comma = ', ';
  366. }
  367. }
  368. }
  369. $custom = 0;
  370. if($permmessage) {
  371. $message = $permmessage;
  372. $custom = 1;
  373. } else {
  374. if($v) {
  375. $message = $type.'_'.$v.'_nopermission';
  376. } else {
  377. $message = 'group_nopermission';
  378. }
  379. }
  380. showmessage($message, NULL, array('fid' => $fid, 'permgroups' => $permgroups, 'grouptitle' => $_G['group']['grouptitle']), array('login' => 1), $custom);
  381. }
  382. function loadforum($fid = null, $tid = null) {
  383. global $_G;
  384. $tid = intval(isset($tid) ? $tid : getgpc('tid'));
  385. if(isset($fid)) {
  386. $fid = intval($fid);
  387. } else {
  388. $fid = getgpc('fid');
  389. if(!$fid && getgpc('gid')) {
  390. $fid = intval(getgpc('gid'));
  391. }
  392. }
  393. if(isset($_G['forum']['fid']) && $_G['forum']['fid'] == $fid || isset($_G['thread']['tid']) && $_G['thread']['tid'] == $tid){
  394. return null;
  395. }
  396. if(!empty($_GET['archiver'])) {//X1.5的Archiver兼容
  397. if($fid) {
  398. dheader('location: archiver/?fid-'.$fid.'.html');
  399. } elseif($tid) {
  400. dheader('location: archiver/?tid-'.$tid.'.html');
  401. } else {
  402. dheader('location: archiver/');
  403. }
  404. }
  405. if(defined('IN_ARCHIVER') && $_G['setting']['archiverredirect'] && !IS_ROBOT) {
  406. dheader('location: ../forum.php'.($_G['mod'] ? '?mod='.$_G['mod'].(!empty($_GET['fid']) ? '&fid='.$_GET['fid'] : (!empty($_GET['tid']) ? '&tid='.$_GET['tid'] : '')) : ''));
  407. }
  408. if($_G['setting']['forumpicstyle']) {
  409. $_G['setting']['forumpicstyle'] = dunserialize($_G['setting']['forumpicstyle']);
  410. empty($_G['setting']['forumpicstyle']['thumbwidth']) && $_G['setting']['forumpicstyle']['thumbwidth'] = 203;
  411. empty($_G['setting']['forumpicstyle']['thumbheight']) && $_G['setting']['forumpicstyle']['thumbheight'] = 999;
  412. } else {
  413. $_G['setting']['forumpicstyle'] = array('thumbwidth' => 203, 'thumbheight' => 999);
  414. }
  415. if($fid) {
  416. $fid = is_numeric($fid) ? intval($fid) : (!empty($_G['setting']['forumfids'][$fid]) ? $_G['setting']['forumfids'][$fid] : 0);
  417. }
  418. $modthreadkey = isset($_GET['modthreadkey']) && $_GET['modthreadkey'] == modauthkey($tid) ? $_GET['modthreadkey'] : '';
  419. $_G['forum_auditstatuson'] = $modthreadkey ? true : false;
  420. $metadescription = $hookscriptmessage = '';
  421. $adminid = $_G['adminid'];
  422. if(!empty($tid) || !empty($fid)) {
  423. if(!empty ($tid)) {
  424. $archiveid = !empty($_GET['archiveid']) ? intval($_GET['archiveid']) : null;
  425. $_G['thread'] = get_thread_by_tid($tid, $archiveid);
  426. $_G['thread']['allreplies'] = $_G['thread']['replies'] + $_G['thread']['comments'];
  427. if(!$_G['forum_auditstatuson'] && !empty($_G['thread'])
  428. && !($_G['thread']['displayorder'] >= 0 || (in_array($_G['thread']['displayorder'], array(-4,-3,-2)) && $_G['uid'] && $_G['thread']['authorid'] == $_G['uid']))) {
  429. $_G['thread'] = null;
  430. }
  431. $_G['forum_thread'] = & $_G['thread'];
  432. if(empty($_G['thread'])) {
  433. $fid = $tid = 0;
  434. } else {
  435. $fid = $_G['thread']['fid'];
  436. $tid = $_G['thread']['tid'];
  437. }
  438. }
  439. if($fid) {
  440. $forum = C::t('forum_forum')->fetch_info_by_fid($fid);
  441. }
  442. if($forum) {
  443. if($_G['uid']) {
  444. if($_G['member']['accessmasks']) {
  445. $query = C::t('forum_access')->fetch_all_by_fid_uid($fid, $_G['uid']);
  446. $forum['allowview'] = $query[0]['allowview'];
  447. $forum['allowpost'] = $query[0]['allowpost'];
  448. $forum['allowreply'] = $query[0]['allowreply'];
  449. $forum['allowgetattach'] = $query[0]['allowgetattach'];
  450. $forum['allowgetimage'] = $query[0]['allowgetimage'];
  451. $forum['allowpostattach'] = $query[0]['allowpostattach'];
  452. $forum['allowpostimage'] = $query[0]['allowpostimage'];
  453. }
  454. if($adminid == 3) {
  455. $forum['ismoderator'] = C::t('forum_moderator')->fetch_uid_by_fid_uid($fid, $_G['uid']);
  456. }
  457. }
  458. $forum['ismoderator'] = !empty($forum['ismoderator']) || $adminid == 1 || $adminid == 2 ? 1 : 0;
  459. $fid = $forum['fid'];
  460. $gorup_admingroupids = $_G['setting']['group_admingroupids'] ? dunserialize($_G['setting']['group_admingroupids']) : array('1' => '1');
  461. if($forum['status'] == 3) {
  462. if(!empty($forum['moderators'])) {
  463. $forum['moderators'] = dunserialize($forum['moderators']);
  464. } else {
  465. require_once libfile('function/group');
  466. $forum['moderators'] = update_groupmoderators($fid);
  467. }
  468. if($_G['uid'] && $_G['adminid'] != 1) {
  469. $forum['ismoderator'] = !empty($forum['moderators'][$_G['uid']]) ? 1 : 0;
  470. $_G['adminid'] = 0;
  471. if($forum['ismoderator'] || $gorup_admingroupids[$_G['groupid']]) {
  472. $_G['adminid'] = $_G['adminid'] ? $_G['adminid'] : 3;
  473. if(!empty($gorup_admingroupids[$_G['groupid']])) {
  474. $forum['ismoderator'] = 1;
  475. $_G['adminid'] = 2;
  476. }
  477. $group_userperm = dunserialize($_G['setting']['group_userperm']);
  478. if(is_array($group_userperm)) {
  479. $_G['group'] = array_merge($_G['group'], $group_userperm);
  480. $_G['group']['allowmovethread'] = $_G['group']['allowcopythread'] = $_G['group']['allowedittypethread']= 0;
  481. }
  482. }
  483. }
  484. }
  485. foreach(array('threadtypes', 'threadsorts', 'creditspolicy', 'modrecommend') as $key) {
  486. $forum[$key] = !empty($forum[$key]) ? dunserialize($forum[$key]) : array();
  487. if(!is_array($forum[$key])) {
  488. $forum[$key] = array();
  489. }
  490. }
  491. if($forum['threadtypes']['types']) {
  492. safefilter($forum['threadtypes']['types']);
  493. }
  494. if($forum['threadtypes']['options']['name']) {
  495. safefilter($forum['threadtypes']['options']['name']);
  496. }
  497. if($forum['threadsorts']['types']) {
  498. safefilter($forum['threadsorts']['types']);
  499. }
  500. if($forum['status'] == 3) {
  501. $_G['isgroupuser'] = 0;
  502. $_G['basescript'] = 'group';
  503. if($forum['level'] == 0) {
  504. $levelinfo = C::t('forum_grouplevel')->fetch_by_credits($forum['commoncredits']);
  505. $levelid = $levelinfo['levelid'];
  506. $forum['level'] = $levelid;
  507. C::t('forum_forum')->update_group_level($levelid, $fid);
  508. }
  509. if($forum['level'] != -1) {
  510. loadcache('grouplevels');
  511. $grouplevel = $_G['grouplevels'][$forum['level']];
  512. if(!empty($grouplevel['icon'])) {
  513. $valueparse = parse_url($grouplevel['icon']);
  514. if(!isset($valueparse['host'])) {
  515. $grouplevel['icon'] = $_G['setting']['attachurl'].'common/'.$grouplevel['icon'];
  516. }
  517. }
  518. }
  519. $group_postpolicy = $grouplevel['postpolicy'];
  520. if(is_array($group_postpolicy)) {
  521. $forum = array_merge($forum, $group_postpolicy);
  522. }
  523. $forum['allowfeed'] = $_G['setting']['group_allowfeed'];
  524. if($_G['uid']) {
  525. if(!empty($forum['moderators'][$_G['uid']])) {
  526. $_G['isgroupuser'] = 1;
  527. } else {
  528. $groupuserinfo = C::t('forum_groupuser')->fetch_userinfo($_G['uid'], $fid);
  529. $_G['isgroupuser'] = $groupuserinfo['level'];
  530. if($_G['isgroupuser'] <= 0 && empty($forum['ismoderator'])) {
  531. $_G['group']['allowrecommend'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowrecommend'] = 0;
  532. $_G['group']['allowcommentpost'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentpost'] = 0;
  533. $_G['group']['allowcommentitem'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentitem'] = 0;
  534. $_G['group']['raterange'] = $_G['cache']['usergroup_'.$_G['groupid']]['raterange'] = array();
  535. $_G['group']['allowvote'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowvote'] = 0;
  536. } else {
  537. $_G['isgroupuser'] = 1;
  538. }
  539. }
  540. }
  541. }
  542. } else {
  543. $fid = 0;
  544. }
  545. }
  546. $_G['fid'] = $fid;
  547. $_G['tid'] = $tid;
  548. $_G['forum'] = &$forum;
  549. $_G['current_grouplevel'] = &$grouplevel;
  550. if(empty($_G['uid'])) {
  551. $_G['group']['allowpostactivity'] = $_G['group']['allowpostpoll'] = $_G['group']['allowvote'] = $_G['group']['allowpostreward'] = $_G['group']['allowposttrade'] = $_G['group']['allowpostdebate'] = $_G['group']['allowpostrushreply'] = 0;
  552. }
  553. if(!empty($_G['forum']['widthauto'])) {
  554. $_G['widthauto'] = $_G['forum']['widthauto'];
  555. }
  556. }
  557. function get_thread_by_tid($tid, $forcetableid = null) {
  558. global $_G;
  559. $ret = array();
  560. if(!is_numeric($tid)) {
  561. return $ret;
  562. }
  563. loadcache('threadtableids');
  564. $threadtableids = array(0);
  565. if(!empty($_G['cache']['threadtableids'])) {
  566. if($forcetableid === null || ($forcetableid > 0 && !in_array($forcetableid, $_G['cache']['threadtableids']))) {
  567. $threadtableids = array_merge($threadtableids, $_G['cache']['threadtableids']);
  568. } else {
  569. $threadtableids = array(intval($forcetableid));
  570. }
  571. }
  572. $threadtableids = array_unique($threadtableids);
  573. foreach($threadtableids as $tableid) {
  574. $tableid = $tableid > 0 ? $tableid : 0;
  575. $ret = C::t('forum_thread')->fetch($tid, $tableid);
  576. if($ret) {
  577. $ret['threadtable'] = C::t('forum_thread')->get_table_name($tableid);
  578. $ret['threadtableid'] = $tableid;
  579. $ret['posttable'] = 'forum_post'.($ret['posttableid'] ? '_'.$ret['posttableid'] : '');
  580. break;
  581. }
  582. }
  583. if(!is_array($ret)) {
  584. $ret = array();
  585. } elseif($_G['setting']['optimizeviews']) {
  586. if(($row = C::t('forum_threadaddviews')->fetch($tid))) {
  587. $ret['addviews'] = intval($row['addviews']);
  588. $ret['views'] += $ret['addviews'];
  589. }
  590. }
  591. return $ret;
  592. }
  593. function get_post_by_pid($pid, $fields = '*', $addcondiction = '', $forcetable = null) {
  594. global $_G;
  595. $ret = array();
  596. if(!is_numeric($pid)) {
  597. return $ret;
  598. }
  599. loadcache('posttable_info');
  600. $posttableids = array(0);
  601. if($_G['cache']['posttable_info']) {
  602. if(isset($forcetable)) {
  603. if(is_numeric($forcetable) && array_key_exists($forcetable, $_G['cache']['posttable_info'])) {
  604. $posttableids[] = $forcetable;
  605. } elseif(substr($forcetable, 0, 10) == 'forum_post') {
  606. $posttableids[] = $forcetable;
  607. }
  608. } else {
  609. $posttableids = array_keys($_G['cache']['posttable_info']);
  610. }
  611. }
  612. foreach ($posttableids as $id) {
  613. $table = empty($id) ? 'forum_post' : (is_numeric($id) ? 'forum_post_'.$id : $id);
  614. $ret = C::t('forum_post')->fetch_by_pid_condition($id, $pid, $addcondiction, $fields);
  615. if($ret) {
  616. $ret['posttable'] = $table;
  617. break;
  618. }
  619. }
  620. if(!is_array($ret)) {
  621. $ret = array();
  622. }
  623. return $ret;
  624. }
  625. function get_post_by_tid_pid($tid, $pid) {
  626. static $postlist = array();
  627. if(empty($postlist[$pid])) {
  628. $postlist[$pid] = C::t('forum_post')->fetch('tid:'.$tid, $pid, false);
  629. if($postlist[$pid] && $postlist[$pid]['tid'] == $tid) {
  630. $user = getuserbyuid($postlist[$pid]['authorid']);
  631. $postlist[$pid]['adminid'] = $user['adminid'];
  632. } else {
  633. $postlist[$pid] = array();
  634. }
  635. }
  636. return $postlist[$pid];
  637. }
  638. function set_rssauth() {
  639. global $_G;
  640. if($_G['setting']['rssstatus'] && $_G['uid']) {
  641. $auth = authcode($_G['uid']."\t".($_G['fid'] ? $_G['fid'] : '').
  642. "\t".substr(md5($_G['member']['password']), 0, 8), 'ENCODE', md5($_G['config']['security']['authkey']));
  643. } else {
  644. $auth = '0';
  645. }
  646. $_G['rssauth'] = rawurlencode($auth);
  647. }
  648. function rssforumperm($forum) {
  649. $is_allowed = $forum['type'] != 'group' && (!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'], 7)));
  650. return $is_allowed;
  651. }
  652. function upload_icon_banner(&$data, $file, $type) {
  653. global $_G;
  654. $data['extid'] = empty($data['extid']) ? $data['fid'] : $data['extid'];
  655. if(empty($data['extid'])) return '';
  656. if($data['status'] == 3 && $_G['setting']['group_imgsizelimit']) {
  657. $file['size'] > ($_G['setting']['group_imgsizelimit'] * 1024) && showmessage('file_size_overflow', '', array('size' => $_G['setting']['group_imgsizelimit'] * 1024));
  658. }
  659. $upload = new discuz_upload();
  660. $uploadtype = $data['status'] == 3 ? 'group' : 'common';
  661. if(!$upload->init($file, $uploadtype, $data['extid'], $type)) {
  662. return false;
  663. }
  664. if(!$upload->save()) {
  665. if(!defined('IN_ADMINCP')) {
  666. showmessage($upload->errormessage());
  667. } else {
  668. cpmsg($upload->errormessage(), '', 'error');
  669. }
  670. }
  671. if($data['status'] == 3 && $type == 'icon') {
  672. require_once libfile('class/image');
  673. $img = new image;
  674. $img->Thumb($upload->attach['target'], './'.$uploadtype.'/'.$upload->attach['attachment'], 48, 48, 'fixwr');
  675. }
  676. return $upload->attach['attachment'];
  677. }
  678. function arch_multi($total, $perpage, $page, $link) {
  679. $pages = @ceil($total / $perpage) + 1;
  680. $pagelink = '';
  681. if($pages > 1) {
  682. $pagelink .= lang('forum/archiver', 'page') . ": \n";
  683. $pagestart = $page - 10 < 1 ? 1 : $page - 10;
  684. $pageend = $page + 10 >= $pages ? $pages : $page + 10;
  685. for($i = $pagestart; $i < $pageend; $i++) {
  686. $pagelink .= ($i == $page ? "<strong>[$i]</strong>" : "<a href=\"$link&page=$i\">$i</a>")." \n";
  687. }
  688. }
  689. return $pagelink;
  690. }
  691. function loadarchiver($path) {
  692. global $_G;
  693. if(!$_G['setting']['archiver']) {
  694. require_once DISCUZ_ROOT . "./source/archiver/common/header.php";
  695. echo '<div id="content">'.lang('message', 'forum_archiver_disabled').'</div>';
  696. require_once DISCUZ_ROOT . "./source/archiver/common/footer.php";
  697. exit;
  698. }
  699. $filename = $path . '.php';
  700. return DISCUZ_ROOT . "./source/archiver/$filename";
  701. }
  702. function update_threadpartake($tid, $getsetarr = false) {
  703. global $_G;
  704. $setarr = array();
  705. if($_G['uid'] && $tid) {
  706. if($_G['setting']['heatthread']['period']) {
  707. $partaked = C::t('forum_threadpartake')->fetch($tid, $_G['uid']);
  708. $partaked = $partaked['uid'];
  709. if(!$partaked) {
  710. C::t('forum_threadpartake')->insert(array('tid' => $tid, 'uid' => $_G['uid'], 'dateline' => TIMESTAMP));
  711. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  712. }
  713. } else {
  714. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  715. }
  716. }
  717. if($getsetarr) {
  718. return $setarr;
  719. }
  720. }
  721. function getthreadcover($tid, $cover = 0, $getfilename = 0) {
  722. global $_G;
  723. if(empty($tid)) {
  724. return '';
  725. }
  726. $coverpath = '';
  727. $covername = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/'.$tid.'.jpg';
  728. if($getfilename) {
  729. return $covername;
  730. }
  731. if($cover) {
  732. $coverpath = ($cover < 0 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$covername;
  733. }
  734. return $coverpath;
  735. }
  736. function convertunusedattach($aid, $tid, $pid) {
  737. if(!$aid) {
  738. return;
  739. }
  740. global $_G;
  741. $attach = C::t('forum_attachment_n')->fetch_by_aid_uid(127, $aid, $_G['uid']);
  742. if(!$attach) {
  743. return;
  744. }
  745. $attach = daddslashes($attach);
  746. $attach['tid'] = $tid;
  747. $attach['pid'] = $pid;
  748. C::t('forum_attachment_n')->insert('tid:'.$tid, $attach);
  749. C::t('forum_attachment')->update($attach['aid'], array('tid' => $tid, 'pid' => $pid, 'tableid' => getattachtableid($tid)));
  750. C::t('forum_attachment_unused')->delete($attach['aid']);
  751. }
  752. function updateattachtid($idtype, $ids, $oldtid, $newtid) {
  753. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$oldtid, $idtype, $ids) as $attach) {
  754. $attach['tid'] = $newtid;
  755. C::t('forum_attachment_n')->insert('tid:'.$newtid, $attach);
  756. }
  757. C::t('forum_attachment_n')->delete_by_id('tid:'.$oldtid, $idtype, $ids);
  758. C::t('forum_attachment')->update_by_id($idtype, $ids, $newtid);
  759. }
  760. function updatepost($data, $condition, $unbuffered = false, $posttableid = false) {
  761. return false;
  762. }
  763. function insertpost($data) {
  764. if(isset($data['tid'])) {
  765. $thread = C::t('forum_thread')->fetch($data['tid']);
  766. $tableid = $thread['posttableid'];
  767. } else {
  768. $tableid = $data['tid'] = 0;
  769. }
  770. $pid = C::t('forum_post_tableid')->insert(array('pid' => null), true);
  771. $data = array_merge($data, array('pid' => $pid));
  772. C::t('forum_post')->insert($tableid, $data);
  773. if($pid % 1024 == 0) {
  774. C::t('forum_post_tableid')->delete_by_lesspid($pid);
  775. }
  776. savecache('max_post_id', $pid);
  777. return $pid;
  778. }
  779. function threadmodstatus($string) {
  780. global $_G;
  781. $postmodperiods = periodscheck('postmodperiods', 0);
  782. if($postmodperiods) {
  783. $modnewthreads = $modnewreplies = 1;
  784. } else {
  785. $censormod = censormod($string);
  786. $modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $_G['forum']['modnewposts'] || $censormod ? 1 : 0;
  787. $modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $_G['forum']['modnewposts'] == 2 || $censormod ? 1 : 0;
  788. if($_G['forum']['status'] == 3) {
  789. $modnewthreads = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 1 || $censormod ? 1 : 0;
  790. $modnewreplies = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 2 || $censormod ? 1 : 0;
  791. }
  792. }
  793. $_G['group']['allowposturl'] = $_G['forum']['status'] != 3 ? $_G['group']['allowposturl'] : $_G['group']['allowgroupposturl'];
  794. if($_G['group']['allowposturl'] == 1) {
  795. if(!$postmodperiods) {
  796. $censormod = censormod($string);
  797. }
  798. if($censormod) {
  799. $modnewthreads = $modnewreplies = 1;
  800. }
  801. }
  802. return array($modnewthreads, $modnewreplies);
  803. }
  804. function threadpubsave($tid, $passapproval = false) {
  805. global $_G;
  806. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  807. $hookparam = func_get_args();
  808. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'threadpubsave');
  809. }
  810. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, -4, '=', !$passapproval ? $_G['uid'] : null);
  811. if(!$thread) {
  812. return 0;
  813. }
  814. $threadpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
  815. $thread['message'] = $threadpost['message'];
  816. $modworksql = 0;
  817. $displayorder = 0;
  818. $dateline = $_G['timestamp'];
  819. $moderatepids = $saveposts = array();
  820. $return = 1;
  821. list($modnewthreads) = threadmodstatus($thread['subject']."\t".$thread['message']);
  822. if($modnewthreads && $passapproval === false) {
  823. updatemoderate('tid', $tid);
  824. manage_addnotify('verifythread');
  825. $displayorder = -2;
  826. $modworksql = 1;
  827. $return = -1;
  828. } else {
  829. C::t('forum_post')->update_by_tid('tid:'.$tid, $tid, array('dateline' => $dateline, 'invisible' => '0'), false, false, 1);
  830. }
  831. C::t('forum_thread')->update($tid, array('displayorder'=>$displayorder, 'dateline'=>$_G['timestamp'], 'lastpost'=>$_G['timestamp']));
  832. $posts = $thread['replies'] + 1;
  833. if($thread['replies']) {
  834. $saveposts = C::t('forum_post')->fetch_all_by_tid('tid:'.$tid, $tid, true, '', 0, 0, 0);
  835. foreach($saveposts as $post) {
  836. $dateline++;
  837. $invisible = 0;
  838. list(, $modnewreplies) = threadmodstatus($post['subject']."\t".$post['message']);
  839. if($modnewreplies) {
  840. $moderatepids[] = $post['pid'];
  841. $verifypost = true;
  842. $invisible = -2;
  843. $modworksql = 1;
  844. $return = -2;
  845. }
  846. C::t('forum_post')->update('tid:'.$tid, $post['pid'], array('dateline' => $dateline, 'invisible' => $invisible));
  847. updatepostcredits('+', $thread['authorid'], 'reply', $thread['fid']);
  848. }
  849. }
  850. if($moderatepids) {
  851. updatemoderate('pid', $moderatepids);
  852. manage_addnotify('verifypost');
  853. }
  854. updatepostcredits('+', $thread['authorid'], 'post', $thread['fid']);
  855. $attachcount = C::t('forum_attachment_n')->count_by_id('tid:'.$thread['tid'], 'tid', $thread['tid']);
  856. updatecreditbyaction('postattach', $thread['authorid'], array(), '', $attachcount, 1, $thread['fid']);
  857. if($_G['forum']['status'] == 3) {
  858. C::t('forum_groupuser')->update_counter_for_user($thread['authorid'], $thread['fid'], 1);
  859. }
  860. $subject = str_replace("\t", ' ', $thread['subject']);
  861. $lastpost = $thread['tid']."\t".$subject."\t".$thread['lastpost']."\t".$thread['lastposter'];
  862. C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
  863. C::t('forum_forum')->update_forum_counter($thread['fid'], 1, $posts, $posts, $modworksql);
  864. if($_G['forum']['type'] == 'sub') {
  865. C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
  866. }
  867. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  868. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'save', 'posts' => $saveposts), 'threadpubsave');
  869. }
  870. return $return;
  871. }
  872. function getrelatecollection($tid, $all = false, &$num, &$more) {
  873. global $_G;
  874. $maxdisplay = $_G['setting']['collectionnum'];
  875. if(!$maxdisplay) return;
  876. $tidrelate = C::t('forum_collectionrelated')->fetch($tid);
  877. $ctids = explode("\t", $tidrelate['collection'], -1);
  878. $num = count($ctids);
  879. if(!$ctids || !$num) {
  880. $more = $num = 0;
  881. return null;
  882. }
  883. if($all !== true && $num > $maxdisplay) {
  884. $more = 1;
  885. } else {
  886. $maxdisplay = 0;
  887. }
  888. return C::t('forum_collection')->fetch_all($ctids, 'follownum', 'DESC', 0, $maxdisplay, '', $tid);
  889. }
  890. function set_atlist_cookie($uids) {
  891. global $_G;
  892. $atlist = $tmp = array();
  893. $num = 0;
  894. $maxlist = 10;
  895. if(empty($uids)) {
  896. return;
  897. }
  898. $newnum = count($uids);
  899. if($newnum >= $maxlist) {
  900. $uids = array_slice($uids, 0, $maxlist);
  901. dsetcookie('atlist', implode(',', $uids), 86400 * 360);
  902. return;
  903. }
  904. if($_G['cookie']['atlist']) {
  905. $atlist = explode(',', $_G['cookie']['atlist']);
  906. foreach($atlist as $key => $val) {
  907. if(!in_array($val, $uids)) {
  908. $num++;
  909. if($num == ($maxlist - $newnum)) {
  910. break;
  911. }
  912. $tmp[$key] = $val;
  913. }
  914. }
  915. }
  916. dsetcookie('atlist', implode(',', $uids).($tmp ? ','.implode(',', $tmp) : ''), 86400 * 360);
  917. }
  918. function cloud_referer_related() {
  919. global $_G;
  920. $my_search_data = $_G['setting']['my_search_data'];
  921. if (viewthread_is_search_referer() && $my_search_data['status']) {
  922. $appService = Cloud::loadClass('Service_App');
  923. if($appService->getCloudAppStatus('search')) {
  924. $_params = array('s_site_gid' => $_G['groupid'],
  925. 'response_type' => 'js',
  926. 'referer' => $_SERVER['HTTP_REFERER'],
  927. );
  928. $utilService = Cloud::loadClass('Service_Util');
  929. $signUrl = $utilService->generateSiteSignUrl($_params);
  930. $my_search_se_url = 'http://search.discuz.qq.com/api/site/se?' . $signUrl . "";
  931. }
  932. }
  933. return $my_search_se_url;
  934. }
  935. function viewthread_is_search_referer() {
  936. $regex = "((http|https)\:\/\/)?";
  937. $regex .= "([a-z]*.)?(ask.com|yahoo.com|cn.yahoo.com|bing.com|baidu.com|soso.com|google.com|google.cn)(.[a-z]{2,3})?\/";
  938. if(preg_match("/^$regex/", $_SERVER['HTTP_REFERER'])) {
  939. return true;
  940. }
  941. return false;
  942. }
  943. function stringtopic($value, $key = '', $force = false, $rlength = 0) {
  944. if($key === '') {
  945. $key = $value;
  946. }
  947. $basedir = !getglobal('setting/attachdir') ? './data/attachment' : getglobal('setting/attachdir');
  948. $url = !getglobal('setting/attachurl') ? './data/attachment/' : getglobal('setting/attachurl');
  949. $subdir1 = substr(md5($key), 0, 2);
  950. $subdir2 = substr(md5($key), 2, 2);
  951. $target = 'temp/'.$subdir1.'/'.$subdir2.'/';
  952. $targetname = substr(md5($key), 8, 16).'.png';
  953. discuz_upload::check_dir_exists('temp', $subdir1, $subdir2);
  954. if(!$force && file_exists($basedir.'/'.$target.$targetname)) {
  955. return $url.$target.$targetname;
  956. }
  957. $value = str_replace("\n", '', $value);
  958. $fontfile = $fontname = '';
  959. $ttfenabled = false;
  960. $size = 10;
  961. $w = 130;
  962. $rowh = 25;
  963. $value = explode("\r", $value);
  964. if($rlength) {
  965. $temp = array();
  966. foreach($value as $str) {
  967. $strlen = dstrlen($str);
  968. if($strlen > $rlength) {
  969. for($i = 0; $i < $strlen; $i++) {
  970. $sub = cutstr($str, $rlength, '');
  971. $temp[] = $sub;
  972. $str = substr($str, strlen($sub));
  973. $strlen = $strlen - $rlength;
  974. }
  975. } else {
  976. $temp[] = $str;
  977. }
  978. }
  979. $value = $temp;
  980. unset($temp);
  981. }
  982. if(function_exists('imagettftext')) {
  983. $fontroot = DISCUZ_ROOT.'./static/image/seccode/font/ch/';
  984. $dirs = opendir($fontroot);
  985. while($entry = readdir($dirs)) {
  986. if($entry != '.' && $entry != '..' && in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) {
  987. $fontname = $entry;
  988. break;
  989. }
  990. }
  991. if(!empty($fontname)) {
  992. $fontfile = DISCUZ_ROOT.'./static/image/seccode/font/ch/'.$fontname;
  993. }
  994. if($fontfile) {
  995. if(strtoupper(CHARSET) != 'UTF-8') {
  996. include DISCUZ_ROOT.'./source/class/class_chinese.php';
  997. $cvt = new Chinese(CHARSET, 'utf8');
  998. $value = $cvt->Convert(implode("\r", $value));
  999. $value = explode("\r", $value);
  1000. }
  1001. $ttfenabled = true;
  1002. }
  1003. }
  1004. foreach($value as $str) {
  1005. if($ttfenabled) {
  1006. $box = imagettfbbox($size, 0, $fontfile, $str);
  1007. $height = max($box[1], $box[3]) - min($box[5], $box[7]);
  1008. $len = (max($box[2], $box[4]) - min($box[0], $box[6]));
  1009. $rowh = max(array($height, $rowh));
  1010. } else {
  1011. $len = strlen($str) * 12;
  1012. }
  1013. $w = max(array($len, $w));
  1014. }
  1015. $h = $rowh * count($value) + count($value) * 2;
  1016. $im = @imagecreate($w, $h);
  1017. $background_color = imagecolorallocate($im, 255, 255, 255);
  1018. $text_color = imagecolorallocate($im, 60, 60, 60);
  1019. $h = $ttfenabled ? $rowh : 4;
  1020. foreach($value as $str) {
  1021. if($ttfenabled) {
  1022. imagettftext($im, $size, 0, 0, $h, $text_color, $fontfile, $str);
  1023. $h += 2;
  1024. } else {
  1025. imagestring($im, $size, 0, $h, $str, $text_color);
  1026. }
  1027. $h += $rowh;
  1028. }
  1029. imagepng($im, $basedir.'/'.$target.$targetname);
  1030. imagedestroy($im);
  1031. return $url.$target.$targetname;
  1032. }
  1033. function getreplybg($replybg = '') {
  1034. global $_G;
  1035. $style = '';
  1036. if($_G['setting']['allowreplybg']) {
  1037. if($replybg) {
  1038. $bgurl = $replybg;
  1039. if(file_exists($_G['setting']['attachurl'].'common/'.$replybg)) {
  1040. $bgurl = $_G['setting']['attachurl'].'common/'.$replybg;
  1041. }
  1042. } elseif($_G['setting']['globalreplybg']) {
  1043. $bgurl = $_G['setting']['globalreplybg'];
  1044. if(file_exists($_G['setting']['attachurl'].'common/'.$_G['setting']['globalreplybg'])) {
  1045. $bgurl = $_G['setting']['attachurl'].'common/'.$_G['setting']['globalreplybg'];
  1046. }
  1047. }
  1048. if($bgurl) {
  1049. $style = ' style="background-image: url('.$bgurl.');"';
  1050. }
  1051. }
  1052. return $style;
  1053. }
  1054. function safefilter(&$data) {
  1055. if(is_array($data)) {
  1056. foreach($data as $k => $v) {
  1057. safefilter($data[$k]);
  1058. }
  1059. } else {
  1060. $data = str_replace(array(
  1061. '[/color]', '[b]', '[/b]', '[s]', '[/s]', '[i]', '[/i]', '[u]', '[/u]',
  1062. ), array(
  1063. '</font>', '<b>', '</b>', '<strike>', '</strike>', '<i>', '</i>', '<u>', '</u>'
  1064. ), preg_replace(array(
  1065. "/\[color=([#\w]+?)\]/i",
  1066. "/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
  1067. ), array(
  1068. "<font color=\"\\1\">",
  1069. "<font style=\"color:\\1\">",
  1070. ), strip_tags($data)));
  1071. }
  1072. }
  1073. ?>