PageRenderTime 80ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_forum.php

https://github.com/kuaileshike/upload
PHP | 985 lines | 897 code | 82 blank | 6 comment | 268 complexity | b5f5fd5927e49d4afbf104386e11e3a6 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_forum.php 30837 2012-06-25 08:24:29Z zhangguosheng $
  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', $_G['setting']['ftp']['attachdir'].'/forum/'.$filename);
  22. $havethumb && ftpcmd('delete', $_G['setting']['ftp']['attachdir'].'/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("/\{(\d{4})\-(\d{1,2})\-(\d{1,2})\}/e", "'\'\\1-'.sprintf('%02d', '\\2').'-'.sprintf('%02d', '\\3').'\''", $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 medalformulaperm($formula, $type) {
  166. global $_G;
  167. $formula = dunserialize($formula);
  168. $permmessage = $formula['message'];
  169. $formula = $formula['medal'];
  170. if(!empty($formula['usergroupallow']) && is_array($formula['usergroups']) && !in_array($_G['groupid'], $formula['usergroups'])) {
  171. loadcache('usergroups');
  172. $message = array();
  173. foreach($formula['usergroups'] as $groupid) {
  174. $message[] = $_G['cache']['usergroups'][$groupid]['grouptitle'].' ';
  175. }
  176. $_G['forum_formulamessage'] = implode(', ', $message);
  177. $_G['forum_usermsg'] = $_G['cache']['usergroups'][$_G['groupid']]['grouptitle'];
  178. return FALSE;
  179. }
  180. $formulatext = $formula[0];
  181. $formula = $formula[1];
  182. if(!$formula) {
  183. return FALSE;
  184. }
  185. if(strexists($formula, '$memberformula[')) {
  186. preg_match_all("/\\\$memberformula\['(\w+?)'\]/", $formula, $a);
  187. $profilefields = array();
  188. foreach($a[1] as $field) {
  189. switch($field) {
  190. case 'regdate':
  191. $formula = preg_replace("/\{(\d{4})\-(\d{1,2})\-(\d{1,2})\}/e", "'\'\\1-'.sprintf('%02d', '\\2').'-'.sprintf('%02d', '\\3').'\''", $formula);
  192. case 'regday':
  193. break;
  194. case 'regip':
  195. case 'lastip':
  196. $formula = preg_replace("/\{([\d\.]+?)\}/", "'\\1'", $formula);
  197. $formula = preg_replace('/(\$memberformula\[\'(regip|lastip)\'\])\s*=+\s*\'([\d\.]+?)\'/', "strpos(\\1, '\\3')===0", $formula);
  198. case 'buyercredit':
  199. case 'sellercredit':
  200. space_merge($_G['member'], 'status');break;
  201. case substr($field, 0, 5) == 'field':
  202. space_merge($_G['member'], 'profile');
  203. $profilefields[] = $field;break;
  204. }
  205. }
  206. $memberformula = array();
  207. if($_G['uid']) {
  208. $memberformula = $_G['member'];
  209. if(in_array('regday', $a[1])) {
  210. $memberformula['regday'] = intval((TIMESTAMP - $memberformula['regdate']) / 86400);
  211. }
  212. if(in_array('regdate', $a[1])) {
  213. $memberformula['regdate'] = date('Y-m-d', $memberformula['regdate']);
  214. }
  215. $memberformula['lastip'] = $memberformula['lastip'] ? $memberformula['lastip'] : $_G['clientip'];
  216. } else {
  217. if(isset($memberformula['regip'])) {
  218. $memberformula['regip'] = $_G['clientip'];
  219. }
  220. if(isset($memberformula['lastip'])) {
  221. $memberformula['lastip'] = $_G['clientip'];
  222. }
  223. }
  224. }
  225. @eval("\$formulaperm = ($formula) ? TRUE : FALSE;");
  226. if(!$formulaperm || $type == 2) {
  227. if(!$permmessage) {
  228. $language = lang('forum/misc');
  229. $search = array('regdate', 'regday', 'regip', 'lastip', 'buyercredit', 'sellercredit', 'digestposts', 'posts', 'threads', 'oltime');
  230. $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']);
  231. for($i = 1; $i <= 8; $i++) {
  232. $search[] = 'extcredits'.$i;
  233. $replace[] = $_G['setting']['extcredits'][$i]['title'] ? $_G['setting']['extcredits'][$i]['title'] : $language['formulaperm_extcredits'].$i;
  234. }
  235. if($profilefields) {
  236. loadcache(array('fields_required', 'fields_optional'));
  237. foreach($profilefields as $profilefield) {
  238. $search[] = $profilefield;
  239. $replace[] = !empty($_G['cache']['fields_optional']['field_'.$profilefield]) ? $_G['cache']['fields_optional']['field_'.$profilefield]['title'] : $_G['cache']['fields_required']['field_'.$profilefield]['title'];
  240. }
  241. }
  242. $i = 0;$_G['forum_usermsg'] = '';
  243. foreach($search as $s) {
  244. if(in_array($s, array('digestposts', 'posts', 'threads', 'oltime', 'extcredits1', 'extcredits2', 'extcredits3', 'extcredits4', 'extcredits5', 'extcredits6', 'extcredits7', 'extcredits8'))) {
  245. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return intval(getuserprofile(\''.$s.'\'));')) : '';
  246. } elseif(in_array($s, array('regdate', 'regip'))) {
  247. $_G['forum_usermsg'] .= strexists($formulatext, $s) ? '<br />&nbsp;&nbsp;&nbsp;'.$replace[$i].': '.(@eval('return $memberformula[\''.$s.'\'];')) : '';
  248. }
  249. $i++;
  250. }
  251. $search = array_merge($search, array('and', 'or', '>=', '<=', '=='));
  252. $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;', '='));
  253. $_G['forum_formulamessage'] = str_replace($search, $replace, $formulatext);
  254. } else {
  255. $_G['forum_formulamessage'] = $permmessage;
  256. }
  257. return $_G['forum_formulamessage'];
  258. } elseif($formulaperm && $type == 1) {
  259. return FALSE;
  260. }
  261. return TRUE;
  262. }
  263. function groupexpiry($terms) {
  264. $terms = is_array($terms) ? $terms : dunserialize($terms);
  265. $groupexpiry = isset($terms['main']['time']) ? intval($terms['main']['time']) : 0;
  266. if(is_array($terms['ext'])) {
  267. foreach($terms['ext'] as $expiry) {
  268. if((!$groupexpiry && $expiry) || $expiry < $groupexpiry) {
  269. $groupexpiry = $expiry;
  270. }
  271. }
  272. }
  273. return $groupexpiry;
  274. }
  275. function typeselect($curtypeid = 0) {
  276. global $_G;
  277. if($threadtypes = $_G['forum']['threadtypes']) {
  278. $html = '<select name="typeid" id="typeid"><option value="0">&nbsp;</option>';
  279. foreach($threadtypes['types'] as $typeid => $name) {
  280. $html .= '<option value="'.$typeid.'" '.($curtypeid == $typeid ? 'selected' : '').'>'.strip_tags($name).'</option>';
  281. }
  282. $html .= '</select>';
  283. return $html;
  284. } else {
  285. return '';
  286. }
  287. }
  288. function updatemodworks($modaction, $posts = 1) {
  289. global $_G;
  290. $today = dgmdate(TIMESTAMP, 'Y-m-d');
  291. if($_G['setting']['modworkstatus'] && $modaction && $posts) {
  292. $affect_rows = C::t('forum_modwork')->increase_count_posts_by_uid_modaction_dateline(1, $posts, $_G['uid'], $modaction, $today);
  293. if(!$affect_rows) {
  294. C::t('forum_modwork')->insert(array(
  295. 'uid' => $_G['uid'],
  296. 'modaction' => $modaction,
  297. 'dateline' => $today,
  298. 'count' => 1,
  299. 'posts' => $posts,
  300. ));
  301. }
  302. }
  303. }
  304. function buildbitsql($fieldname, $position, $value) {
  305. $t = " `$fieldname`=`$fieldname`";
  306. if($value) {
  307. $t .= ' | '.setstatus($position, 1);
  308. } else {
  309. $t .= ' & '.setstatus($position, 0);
  310. }
  311. return $t.' ';
  312. }
  313. function showmessagenoperm($type, $fid, $formula = '') {
  314. global $_G;
  315. loadcache('usergroups');
  316. if($formula) {
  317. $formula = dunserialize($formula);
  318. $permmessage = stripslashes($formula['message']);
  319. }
  320. $usergroups = $nopermgroup = $forumnoperms = array();
  321. $nopermdefault = array(
  322. 'viewperm' => array(),
  323. 'getattachperm' => array(),
  324. 'postperm' => array(7),
  325. 'replyperm' => array(7),
  326. 'postattachperm' => array(7),
  327. );
  328. $perms = array('viewperm', 'postperm', 'replyperm', 'getattachperm', 'postattachperm');
  329. foreach($_G['cache']['usergroups'] as $gid => $usergroup) {
  330. $usergroups[$gid] = $usergroup['type'];
  331. $grouptype = $usergroup['type'] == 'member' ? 0 : 1;
  332. $nopermgroup[$grouptype][] = $gid;
  333. }
  334. if($fid == $_G['forum']['fid']) {
  335. $forum = $_G['forum'];
  336. } else {
  337. $forum = C::t('forum_forumfield')->fetch($fid);
  338. }
  339. foreach($perms as $perm) {
  340. $permgroups = explode("\t", $forum[$perm]);
  341. $membertype = $forum[$perm] ? array_intersect($nopermgroup[0], $permgroups) : TRUE;
  342. $forumnoperm = $forum[$perm] ? array_diff(array_keys($usergroups), $permgroups) : $nopermdefault[$perm];
  343. foreach($forumnoperm as $groupid) {
  344. $nopermtype = $membertype && $groupid == 7 ? 'login' : ($usergroups[$groupid] == 'system' || $usergroups[$groupid] == 'special' ? 'none' : ($membertype ? 'upgrade' : 'none'));
  345. $forumnoperms[$fid][$perm][$groupid] = array($nopermtype, $permgroups);
  346. }
  347. }
  348. $v = $forumnoperms[$fid][$type][$_G['groupid']][0];
  349. $gids = $forumnoperms[$fid][$type][$_G['groupid']][1];
  350. $comma = $permgroups = '';
  351. if(is_array($gids)) {
  352. foreach($gids as $gid) {
  353. if($gid && $_G['cache']['usergroups'][$gid]) {
  354. $permgroups .= $comma.$_G['cache']['usergroups'][$gid]['grouptitle'];
  355. $comma = ', ';
  356. } elseif($_G['setting']['verify']['enabled'] && substr($gid, 0, 1) == 'v') {
  357. $vid = substr($gid, 1);
  358. $permgroups .= $comma.$_G['setting']['verify'][$vid]['title'];
  359. $comma = ', ';
  360. }
  361. }
  362. }
  363. $custom = 0;
  364. if($permmessage) {
  365. $message = $permmessage;
  366. $custom = 1;
  367. } else {
  368. if($v) {
  369. $message = $type.'_'.$v.'_nopermission';
  370. } else {
  371. $message = 'group_nopermission';
  372. }
  373. }
  374. showmessage($message, NULL, array('fid' => $fid, 'permgroups' => $permgroups, 'grouptitle' => $_G['group']['grouptitle']), array('login' => 1), $custom);
  375. }
  376. function loadforum() {
  377. global $_G;
  378. $tid = intval(getgpc('tid'));
  379. $fid = getgpc('fid');
  380. if(!$fid && getgpc('gid')) {
  381. $fid = intval(getgpc('gid'));
  382. }
  383. if(!empty($_GET['archiver'])) {//X1.5的Archiver兼容
  384. if($fid) {
  385. dheader('location: archiver/?fid-'.$fid.'.html');
  386. } elseif($tid) {
  387. dheader('location: archiver/?tid-'.$tid.'.html');
  388. } else {
  389. dheader('location: archiver/');
  390. }
  391. }
  392. if(defined('IN_ARCHIVER') && $_G['setting']['archiverredirect'] && !IS_ROBOT) {
  393. dheader('location: ../forum.php'.($_G['mod'] ? '?mod='.$_G['mod'].(!empty($_GET['fid']) ? '&fid='.$_GET['fid'] : (!empty($_GET['tid']) ? '&tid='.$_GET['tid'] : '')) : ''));
  394. }
  395. if($_G['setting']['forumpicstyle']) {
  396. $_G['setting']['forumpicstyle'] = dunserialize($_G['setting']['forumpicstyle']);
  397. empty($_G['setting']['forumpicstyle']['thumbwidth']) && $_G['setting']['forumpicstyle']['thumbwidth'] = 214;
  398. empty($_G['setting']['forumpicstyle']['thumbheight']) && $_G['setting']['forumpicstyle']['thumbheight'] = 160;
  399. } else {
  400. $_G['setting']['forumpicstyle'] = array('thumbwidth' => 214, 'thumbheight' => 160);
  401. }
  402. if($fid) {
  403. $fid = is_numeric($fid) ? intval($fid) : (!empty($_G['setting']['forumfids'][$fid]) ? $_G['setting']['forumfids'][$fid] : 0);
  404. }
  405. $modthreadkey = isset($_GET['modthreadkey']) && $_GET['modthreadkey'] == modauthkey($tid) ? $_GET['modthreadkey'] : '';
  406. $_G['forum_auditstatuson'] = $modthreadkey ? true : false;
  407. $metadescription = $hookscriptmessage = '';
  408. $adminid = $_G['adminid'];
  409. if(!empty($tid) || !empty($fid)) {
  410. if(!empty ($tid)) {
  411. $archiveid = !empty($_GET['archiveid']) ? intval($_GET['archiveid']) : null;
  412. $_G['thread'] = get_thread_by_tid($tid, $archiveid);
  413. if(!$_G['forum_auditstatuson'] && !empty($_G['thread'])
  414. && !($_G['thread']['displayorder'] >= 0 || (in_array($_G['thread']['displayorder'], array(-4,-3,-2)) && $_G['uid'] && $_G['thread']['authorid'] == $_G['uid']))) {
  415. $_G['thread'] = null;
  416. }
  417. $_G['forum_thread'] = & $_G['thread'];
  418. if(empty($_G['thread'])) {
  419. $fid = $tid = 0;
  420. } else {
  421. $fid = $_G['thread']['fid'];
  422. $tid = $_G['thread']['tid'];
  423. }
  424. }
  425. if($fid) {
  426. $forum = C::t('forum_forum')->fetch_info_by_fid($fid);
  427. }
  428. if($forum) {
  429. if($_G['uid']) {
  430. if($_G['member']['accessmasks']) {
  431. $query = C::t('forum_access')->fetch_all_by_fid_uid($fid, $_G['uid']);
  432. $forum['allowview'] = $query[0]['allowview'];
  433. $forum['allowpost'] = $query[0]['allowpost'];
  434. $forum['allowreply'] = $query[0]['allowreply'];
  435. $forum['allowgetattach'] = $query[0]['allowgetattach'];
  436. $forum['allowgetimage'] = $query[0]['allowgetimage'];
  437. $forum['allowpostattach'] = $query[0]['allowpostattach'];
  438. $forum['allowpostimage'] = $query[0]['allowpostimage'];
  439. }
  440. if($adminid == 3) {
  441. $forum['ismoderator'] = C::t('forum_moderator')->fetch_uid_by_fid_uid($fid, $_G['uid']);
  442. }
  443. }
  444. $forum['ismoderator'] = !empty($forum['ismoderator']) || $adminid == 1 || $adminid == 2 ? 1 : 0;
  445. $fid = $forum['fid'];
  446. $gorup_admingroupids = $_G['setting']['group_admingroupids'] ? dunserialize($_G['setting']['group_admingroupids']) : array('1' => '1');
  447. if($forum['status'] == 3) {
  448. if(!empty($forum['moderators'])) {
  449. $forum['moderators'] = dunserialize($forum['moderators']);
  450. } else {
  451. require_once libfile('function/group');
  452. $forum['moderators'] = update_groupmoderators($fid);
  453. }
  454. if($_G['uid'] && $_G['adminid'] != 1) {
  455. $forum['ismoderator'] = !empty($forum['moderators'][$_G['uid']]) ? 1 : 0;
  456. $_G['adminid'] = 0;
  457. if($forum['ismoderator'] || $gorup_admingroupids[$_G['groupid']]) {
  458. $_G['adminid'] = $_G['adminid'] ? $_G['adminid'] : 3;
  459. if(!empty($gorup_admingroupids[$_G['groupid']])) {
  460. $forum['ismoderator'] = 1;
  461. $_G['adminid'] = 2;
  462. }
  463. $group_userperm = dunserialize($_G['setting']['group_userperm']);
  464. if(is_array($group_userperm)) {
  465. $_G['group'] = array_merge($_G['group'], $group_userperm);
  466. $_G['group']['allowmovethread'] = $_G['group']['allowcopythread'] = $_G['group']['allowedittypethread']= 0;
  467. }
  468. }
  469. }
  470. }
  471. foreach(array('threadtypes', 'threadsorts', 'creditspolicy', 'modrecommend') as $key) {
  472. $forum[$key] = !empty($forum[$key]) ? dunserialize($forum[$key]) : array();
  473. if(!is_array($forum[$key])) {
  474. $forum[$key] = array();
  475. }
  476. }
  477. if($forum['status'] == 3) {
  478. $_G['isgroupuser'] = 0;
  479. $_G['basescript'] = 'group';
  480. if($forum['level'] == 0) {
  481. $levelinfo = C::t('forum_grouplevel')->fetch_by_credits($forum['commoncredits']);
  482. $levelid = $levelinfo['levelid'];
  483. $forum['level'] = $levelid;
  484. C::t('forum_forum')->update_group_level($levelid, $fid);
  485. }
  486. if($forum['level'] != -1) {
  487. loadcache('grouplevels');
  488. $grouplevel = $_G['grouplevels'][$forum['level']];
  489. if(!empty($grouplevel['icon'])) {
  490. $valueparse = parse_url($grouplevel['icon']);
  491. if(!isset($valueparse['host'])) {
  492. $grouplevel['icon'] = $_G['setting']['attachurl'].'common/'.$grouplevel['icon'];
  493. }
  494. }
  495. }
  496. $group_postpolicy = $grouplevel['postpolicy'];
  497. if(is_array($group_postpolicy)) {
  498. $forum = array_merge($forum, $group_postpolicy);
  499. }
  500. $forum['allowfeed'] = $_G['setting']['group_allowfeed'];
  501. if($_G['uid']) {
  502. if(!empty($forum['moderators'][$_G['uid']])) {
  503. $_G['isgroupuser'] = 1;
  504. } else {
  505. $groupuserinfo = C::t('forum_groupuser')->fetch_userinfo($_G['uid'], $fid);
  506. $_G['isgroupuser'] = $groupuserinfo['level'];
  507. if($_G['isgroupuser'] <= 0 && empty($forum['ismoderator'])) {
  508. $_G['group']['allowrecommend'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowrecommend'] = 0;
  509. $_G['group']['allowcommentpost'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentpost'] = 0;
  510. $_G['group']['allowcommentitem'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentitem'] = 0;
  511. $_G['group']['raterange'] = $_G['cache']['usergroup_'.$_G['groupid']]['raterange'] = array();
  512. $_G['group']['allowvote'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowvote'] = 0;
  513. } else {
  514. $_G['isgroupuser'] = 1;
  515. }
  516. }
  517. }
  518. }
  519. } else {
  520. $fid = 0;
  521. }
  522. }
  523. $_G['fid'] = $fid;
  524. $_G['tid'] = $tid;
  525. $_G['forum'] = &$forum;
  526. $_G['current_grouplevel'] = &$grouplevel;
  527. if(!empty($_G['forum']['widthauto'])) {
  528. $_G['widthauto'] = $_G['forum']['widthauto'];
  529. }
  530. }
  531. function get_thread_by_tid($tid, $forcetableid = null) {
  532. global $_G;
  533. $ret = array();
  534. if(!is_numeric($tid)) {
  535. return $ret;
  536. }
  537. loadcache('threadtableids');
  538. $threadtableids = array(0);
  539. if(!empty($_G['cache']['threadtableids'])) {
  540. if($forcetableid === null || ($forcetableid > 0 && !in_array($forcetableid, $_G['cache']['threadtableids']))) {
  541. $threadtableids = array_merge($threadtableids, $_G['cache']['threadtableids']);
  542. } else {
  543. $threadtableids = array(intval($forcetableid));
  544. }
  545. }
  546. $threadtableids = array_unique($threadtableids);
  547. foreach($threadtableids as $tableid) {
  548. $tableid = $tableid > 0 ? $tableid : 0;
  549. $ret = C::t('forum_thread')->fetch($tid, $tableid);
  550. if($ret) {
  551. $ret['threadtable'] = C::t('forum_thread')->get_table_name($tableid);
  552. $ret['threadtableid'] = $tableid;
  553. $ret['posttable'] = 'forum_post'.($ret['posttableid'] ? '_'.$ret['posttableid'] : '');
  554. break;
  555. }
  556. }
  557. if(!is_array($ret)) {
  558. $ret = array();
  559. } elseif($_G['setting']['optimizeviews']) {
  560. $row = C::t('forum_threadaddviews')->fetch($tid);
  561. $ret['addviews'] = intval($row['addviews']);
  562. $ret['views'] += $ret['addviews'];
  563. }
  564. return $ret;
  565. }
  566. function get_post_by_pid($pid, $fields = '*', $addcondiction = '', $forcetable = null) {
  567. global $_G;
  568. $ret = array();
  569. if(!is_numeric($pid)) {
  570. return $ret;
  571. }
  572. loadcache('posttable_info');
  573. $posttableids = array(0);
  574. if($_G['cache']['posttable_info']) {
  575. if(isset($forcetable)) {
  576. if(is_numeric($forcetable) && array_key_exists($forcetable, $_G['cache']['posttable_info'])) {
  577. $posttableids[] = $forcetable;
  578. } elseif(substr($forcetable, 0, 10) == 'forum_post') {
  579. $posttableids[] = $forcetable;
  580. }
  581. } else {
  582. $posttableids = array_keys($_G['cache']['posttable_info']);
  583. }
  584. }
  585. foreach ($posttableids as $id) {
  586. $table = empty($id) ? 'forum_post' : (is_numeric($id) ? 'forum_post_'.$id : $id);
  587. $ret = C::t('forum_post')->fetch_by_pid_condition($id, $pid, $addcondiction, $fields);
  588. if($ret) {
  589. $ret['posttable'] = $table;
  590. break;
  591. }
  592. }
  593. if(!is_array($ret)) {
  594. $ret = array();
  595. }
  596. return $ret;
  597. }
  598. function set_rssauth() {
  599. global $_G;
  600. if($_G['setting']['rssstatus'] && $_G['uid']) {
  601. $auth = authcode($_G['uid']."\t".($_G['fid'] ? $_G['fid'] : '').
  602. "\t".substr(md5($_G['member']['password']), 0, 8), 'ENCODE', md5($_G['config']['security']['authkey']));
  603. } else {
  604. $auth = '0';
  605. }
  606. $_G['rssauth'] = rawurlencode($auth);
  607. }
  608. function rssforumperm($forum) {
  609. $is_allowed = $forum['type'] != 'group' && (!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'], 7)));
  610. return $is_allowed;
  611. }
  612. function upload_icon_banner(&$data, $file, $type) {
  613. global $_G;
  614. $data['extid'] = empty($data['extid']) ? $data['fid'] : $data['extid'];
  615. if(empty($data['extid'])) return '';
  616. if($data['status'] == 3 && $_G['setting']['group_imgsizelimit']) {
  617. $file['size'] > ($_G['setting']['group_imgsizelimit'] * 1024) && showmessage('file_size_overflow', '', array('size' => $_G['setting']['group_imgsizelimit'] * 1024));
  618. }
  619. $upload = new discuz_upload();
  620. $uploadtype = $data['status'] == 3 ? 'group' : 'common';
  621. if(!$upload->init($file, $uploadtype, $data['extid'], $type)) {
  622. return false;
  623. }
  624. if(!$upload->save()) {
  625. if(!defined('IN_ADMINCP')) {
  626. showmessage($upload->errormessage());
  627. } else {
  628. cpmsg($upload->errormessage(), '', 'error');
  629. }
  630. }
  631. if($data['status'] == 3 && $type == 'icon') {
  632. require_once libfile('class/image');
  633. $img = new image;
  634. $img->Thumb($upload->attach['target'], './'.$uploadtype.'/'.$upload->attach['attachment'], 48, 48, 'fixwr');
  635. }
  636. return $upload->attach['attachment'];
  637. }
  638. function arch_multi($total, $perpage, $page, $link) {
  639. $pages = @ceil($total / $perpage) + 1;
  640. $pagelink = '';
  641. if($pages > 1) {
  642. $pagelink .= lang('forum/archiver', 'page') . ": \n";
  643. $pagestart = $page - 10 < 1 ? 1 : $page - 10;
  644. $pageend = $page + 10 >= $pages ? $pages : $page + 10;
  645. for($i = $pagestart; $i < $pageend; $i++) {
  646. $pagelink .= ($i == $page ? "<strong>[$i]</strong>" : "<a href=\"$link&page=$i\">$i</a>")." \n";
  647. }
  648. }
  649. return $pagelink;
  650. }
  651. function loadarchiver($path) {
  652. global $_G;
  653. if(!$_G['setting']['archiver']) {
  654. require_once DISCUZ_ROOT . "./source/archiver/common/header.php";
  655. echo '<div id="content">'.lang('message', 'forum_archiver_disabled').'</div>';
  656. require_once DISCUZ_ROOT . "./source/archiver/common/footer.php";
  657. exit;
  658. }
  659. $filename = $path . '.php';
  660. return DISCUZ_ROOT . "./source/archiver/$filename";
  661. }
  662. function update_threadpartake($tid, $getsetarr = false) {
  663. global $_G;
  664. $setarr = array();
  665. if($_G['uid'] && $tid) {
  666. if($_G['setting']['heatthread']['period']) {
  667. $partaked = C::t('forum_threadpartake')->fetch($tid, $_G['uid']);
  668. $partaked = $partaked['uid'];
  669. if(!$partaked) {
  670. C::t('forum_threadpartake')->insert(array('tid' => $tid, 'uid' => $_G['uid'], 'dateline' => TIMESTAMP));
  671. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  672. }
  673. } else {
  674. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  675. }
  676. }
  677. if($getsetarr) {
  678. return $setarr;
  679. }
  680. }
  681. function getthreadcover($tid, $cover = 0, $getfilename = 0) {
  682. global $_G;
  683. if(empty($tid)) {
  684. return '';
  685. }
  686. $coverpath = '';
  687. $covername = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/'.$tid.'.jpg';
  688. if($getfilename) {
  689. return $covername;
  690. }
  691. if($cover) {
  692. $coverpath = ($cover < 0 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$covername;
  693. }
  694. return $coverpath;
  695. }
  696. function convertunusedattach($aid, $tid, $pid) {
  697. if(!$aid) {
  698. return;
  699. }
  700. global $_G;
  701. $attach = C::t('forum_attachment_n')->fetch_by_aid_uid(127, $aid, $_G['uid']);
  702. if(!$attach) {
  703. return;
  704. }
  705. $attach = daddslashes($attach);
  706. $attach['tid'] = $tid;
  707. $attach['pid'] = $pid;
  708. C::t('forum_attachment_n')->insert('tid:'.$tid, $attach);
  709. C::t('forum_attachment')->update($attach['aid'], array('tid' => $tid, 'pid' => $pid, 'tableid' => getattachtableid($tid)));
  710. C::t('forum_attachment_unused')->delete($attach['aid']);
  711. }
  712. function updateattachtid($idtype, $ids, $oldtid, $newtid) {
  713. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$oldtid, $idtype, $ids) as $attach) {
  714. $attach['tid'] = $newtid;
  715. C::t('forum_attachment_n')->insert('tid:'.$newtid, $attach);
  716. }
  717. C::t('forum_attachment_n')->delete_by_id('tid:'.$oldtid, $idtype, $ids);
  718. C::t('forum_attachment')->update_by_id($idtype, $ids, $newtid);
  719. }
  720. function updatepost($data, $condition, $unbuffered = false, $posttableid = false) {
  721. return false;
  722. }
  723. function insertpost($data) {
  724. if(isset($data['tid'])) {
  725. $thread = C::t('forum_thread')->fetch($data['tid']);
  726. $tableid = $thread['posttableid'];
  727. } else {
  728. $tableid = $data['tid'] = 0;
  729. }
  730. $pid = C::t('forum_post_tableid')->insert(array('pid' => null), true);
  731. $data = array_merge($data, array('pid' => $pid));
  732. C::t('forum_post')->insert($tableid, $data);
  733. if($pid % 1024 == 0) {
  734. C::t('forum_post_tableid')->delete_by_lesspid($pid);
  735. }
  736. savecache('max_post_id', $pid);
  737. return $pid;
  738. }
  739. function threadmodstatus($string) {
  740. global $_G;
  741. $postmodperiods = periodscheck('postmodperiods', 0);
  742. if($postmodperiods) {
  743. $modnewthreads = $modnewreplies = 1;
  744. } else {
  745. $censormod = censormod($string);
  746. $modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $_G['forum']['modnewposts'] || $censormod ? 1 : 0;
  747. $modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $_G['forum']['modnewposts'] == 2 || $censormod ? 1 : 0;
  748. if($_G['forum']['status'] == 3) {
  749. $modnewthreads = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 1 || $censormod ? 1 : 0;
  750. $modnewreplies = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 2 || $censormod ? 1 : 0;
  751. }
  752. }
  753. $_G['group']['allowposturl'] = $_G['forum']['status'] != 3 ? $_G['group']['allowposturl'] : $_G['group']['allowgroupposturl'];
  754. if($_G['group']['allowposturl'] == 1) {
  755. if(!$postmodperiods) {
  756. $censormod = censormod($string);
  757. }
  758. if($censormod) {
  759. $modnewthreads = $modnewreplies = 1;
  760. }
  761. }
  762. return array($modnewthreads, $modnewreplies);
  763. }
  764. function threadpubsave($tid, $passapproval = false) {
  765. global $_G;
  766. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  767. $hookparam = func_get_args();
  768. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'threadpubsave');
  769. }
  770. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, -4, '=', !$passapproval ? $_G['uid'] : null);
  771. if(!$thread) {
  772. return 0;
  773. }
  774. $threadpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
  775. $thread['message'] = $threadpost['message'];
  776. $modworksql = 0;
  777. $displayorder = 0;
  778. $dateline = $_G['timestamp'];
  779. $moderatepids = $saveposts = array();
  780. $return = 1;
  781. list($modnewthreads) = threadmodstatus($thread['subject']."\t".$thread['message']);
  782. if($modnewthreads && $passapproval === false) {
  783. updatemoderate('tid', $tid);
  784. manage_addnotify('verifythread');
  785. $displayorder = -2;
  786. $modworksql = 1;
  787. $return = -1;
  788. } else {
  789. C::t('forum_post')->update_by_tid('tid:'.$tid, $tid, array('dateline' => $dateline, 'invisible' => '0'), false, false, 1);
  790. }
  791. C::t('forum_thread')->update($tid, array('displayorder'=>$displayorder, 'dateline'=>$_G['timestamp'], 'lastpost'=>$_G['timestamp']));
  792. $posts = $thread['replies'] + 1;
  793. if($thread['replies']) {
  794. $saveposts = C::t('forum_post')->fetch_all_by_tid('tid:'.$tid, $tid, true, '', 0, 0, 0);
  795. foreach($saveposts as $post) {
  796. $dateline++;
  797. $invisible = 0;
  798. list(, $modnewreplies) = threadmodstatus($post['subject']."\t".$post['message']);
  799. if($modnewreplies) {
  800. $moderatepids[] = $post['pid'];
  801. $verifypost = true;
  802. $invisible = -2;
  803. $modworksql = 1;
  804. $return = -2;
  805. }
  806. C::t('forum_post')->update('tid:'.$tid, $post['pid'], array('dateline' => $dateline, 'invisible' => $invisible));
  807. updatepostcredits('+', $thread['authorid'], 'reply', $thread['fid']);
  808. }
  809. }
  810. if($moderatepids) {
  811. updatemoderate('pid', $moderatepids);
  812. manage_addnotify('verifypost');
  813. }
  814. updatepostcredits('+', $thread['authorid'], 'post', $thread['fid']);
  815. $attachcount = C::t('forum_attachment_n')->count_by_id('tid:'.$thread['tid'], 'tid', $thread['tid']);
  816. updatecreditbyaction('postattach', $thread['authorid'], array(), '', $attachcount, 1, $thread['fid']);
  817. if($_G['forum']['status'] == 3) {
  818. C::t('forum_groupuser')->update_counter_for_user($thread['authorid'], $thread['fid'], 1);
  819. }
  820. $subject = str_replace("\t", ' ', $thread['subject']);
  821. $lastpost = $thread['tid']."\t".$subject."\t".$thread['lastpost']."\t".$thread['lastposter'];
  822. C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
  823. C::t('forum_forum')->update_forum_counter($thread['fid'], 1, $posts, $posts, $modworksql);
  824. if($_G['forum']['type'] == 'sub') {
  825. C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
  826. }
  827. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  828. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'save', 'posts' => $saveposts), 'threadpubsave');
  829. }
  830. return $return;
  831. }
  832. function getrelatecollection($tid, $all = false, &$num, &$more) {
  833. global $_G;
  834. $maxdisplay = $_G['setting']['collectionnum'];
  835. if(!$maxdisplay) return;
  836. $tidrelate = C::t('forum_collectionrelated')->fetch($tid);
  837. $ctids = explode("\t", $tidrelate['collection'], -1);
  838. $num = count($ctids);
  839. if(!$ctids || !$num) {
  840. $more = $num = 0;
  841. return null;
  842. }
  843. if($all !== true && $num > $maxdisplay) {
  844. $more = 1;
  845. } else {
  846. $maxdisplay = 0;
  847. }
  848. return C::t('forum_collection')->fetch_all($ctids, 'follownum', 'DESC', 0, $maxdisplay, '', $tid);
  849. }
  850. function set_atlist_cookie($uids) {
  851. global $_G;
  852. $atlist = $tmp = array();
  853. $num = 0;
  854. $maxlist = 10;
  855. if(empty($uids)) {
  856. return;
  857. }
  858. $newnum = count($uids);
  859. if($newnum >= $maxlist) {
  860. $uids = array_slice($uids, 0, $maxlist);
  861. dsetcookie('atlist', implode(',', $uids), 86400 * 360);
  862. return;
  863. }
  864. if($_G['cookie']['atlist']) {
  865. $atlist = explode(',', $_G['cookie']['atlist']);
  866. foreach($atlist as $key => $val) {
  867. if(!in_array($val, $uids)) {
  868. $num++;
  869. if($num == ($maxlist - $newnum)) {
  870. break;
  871. }
  872. $tmp[$key] = $val;
  873. }
  874. }
  875. }
  876. dsetcookie('atlist', implode(',', $uids).($tmp ? ','.implode(',', $tmp) : ''), 86400 * 360);
  877. }
  878. function cloud_referer_related() {
  879. global $_G;
  880. $my_search_data = $_G['setting']['my_search_data'];
  881. if (viewthread_is_search_referer() && $my_search_data['status']) {
  882. $appService = Cloud::loadClass('Service_App');
  883. if($appService->getCloudAppStatus('search')) {
  884. $_params = array('s_site_gid' => $_G['groupid'],
  885. 'response_type' => 'js',
  886. 'referer' => $_SERVER['HTTP_REFERER'],
  887. );
  888. $utilService = Cloud::loadClass('Service_Util');
  889. $signUrl = $utilService->generateSiteSignUrl($_params);
  890. $my_search_se_url = 'http://search.discuz.qq.com/api/site/se?' . $signUrl . "";
  891. }
  892. }
  893. return $my_search_se_url;
  894. }
  895. function viewthread_is_search_referer() {
  896. $regex = "((http|https)\:\/\/)?";
  897. $regex .= "([a-z]*.)?(ask.com|yahoo.com|cn.yahoo.com|bing.com|baidu.com|soso.com|google.com|google.cn)(.[a-z]{2,3})?\/";
  898. if(preg_match("/^$regex/", $_SERVER['HTTP_REFERER'])) {
  899. return true;
  900. }
  901. return false;
  902. }
  903. ?>