PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/function_forum.php

https://github.com/jinbo51/DiscuzX
PHP | 1126 lines | 1033 code | 87 blank | 6 comment | 309 complexity | 43bc115a33ecea969eebafee45cf34ac MD5 | raw file
Possible License(s): BSD-3-Clause
  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 33118 2013-04-26 07:28:50Z theoliu $
  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("/\{(\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($fid = null, $tid = null) {
  377. global $_G;
  378. $tid = intval(isset($tid) ? $tid : getgpc('tid'));
  379. if(isset($fid)) {
  380. $fid = intval($fid);
  381. } else {
  382. $fid = getgpc('fid');
  383. if(!$fid && getgpc('gid')) {
  384. $fid = intval(getgpc('gid'));
  385. }
  386. }
  387. if(isset($_G['forum']['fid']) && $_G['forum']['fid'] == $fid || isset($_G['thread']['tid']) && $_G['thread']['tid'] == $tid){
  388. return null;
  389. }
  390. if(!empty($_GET['archiver'])) {//X1.5的Archiver兼容
  391. if($fid) {
  392. dheader('location: archiver/?fid-'.$fid.'.html');
  393. } elseif($tid) {
  394. dheader('location: archiver/?tid-'.$tid.'.html');
  395. } else {
  396. dheader('location: archiver/');
  397. }
  398. }
  399. if(defined('IN_ARCHIVER') && $_G['setting']['archiverredirect'] && !IS_ROBOT) {
  400. dheader('location: ../forum.php'.($_G['mod'] ? '?mod='.$_G['mod'].(!empty($_GET['fid']) ? '&fid='.$_GET['fid'] : (!empty($_GET['tid']) ? '&tid='.$_GET['tid'] : '')) : ''));
  401. }
  402. if($_G['setting']['forumpicstyle']) {
  403. $_G['setting']['forumpicstyle'] = dunserialize($_G['setting']['forumpicstyle']);
  404. empty($_G['setting']['forumpicstyle']['thumbwidth']) && $_G['setting']['forumpicstyle']['thumbwidth'] = 203;
  405. empty($_G['setting']['forumpicstyle']['thumbheight']) && $_G['setting']['forumpicstyle']['thumbheight'] = 999;
  406. } else {
  407. $_G['setting']['forumpicstyle'] = array('thumbwidth' => 203, 'thumbheight' => 999);
  408. }
  409. if($fid) {
  410. $fid = is_numeric($fid) ? intval($fid) : (!empty($_G['setting']['forumfids'][$fid]) ? $_G['setting']['forumfids'][$fid] : 0);
  411. }
  412. $modthreadkey = isset($_GET['modthreadkey']) && $_GET['modthreadkey'] == modauthkey($tid) ? $_GET['modthreadkey'] : '';
  413. $_G['forum_auditstatuson'] = $modthreadkey ? true : false;
  414. $metadescription = $hookscriptmessage = '';
  415. $adminid = $_G['adminid'];
  416. if(!empty($tid) || !empty($fid)) {
  417. if(!empty ($tid)) {
  418. $archiveid = !empty($_GET['archiveid']) ? intval($_GET['archiveid']) : null;
  419. $_G['thread'] = get_thread_by_tid($tid, $archiveid);
  420. $_G['thread']['allreplies'] = $_G['thread']['replies'] + $_G['thread']['comments'];
  421. if(!$_G['forum_auditstatuson'] && !empty($_G['thread'])
  422. && !($_G['thread']['displayorder'] >= 0 || (in_array($_G['thread']['displayorder'], array(-4,-3,-2)) && $_G['uid'] && $_G['thread']['authorid'] == $_G['uid']))) {
  423. $_G['thread'] = null;
  424. }
  425. $_G['forum_thread'] = & $_G['thread'];
  426. if(empty($_G['thread'])) {
  427. $fid = $tid = 0;
  428. } else {
  429. $fid = $_G['thread']['fid'];
  430. $tid = $_G['thread']['tid'];
  431. }
  432. }
  433. if($fid) {
  434. $forum = C::t('forum_forum')->fetch_info_by_fid($fid);
  435. }
  436. if($forum) {
  437. if($_G['uid']) {
  438. if($_G['member']['accessmasks']) {
  439. $query = C::t('forum_access')->fetch_all_by_fid_uid($fid, $_G['uid']);
  440. $forum['allowview'] = $query[0]['allowview'];
  441. $forum['allowpost'] = $query[0]['allowpost'];
  442. $forum['allowreply'] = $query[0]['allowreply'];
  443. $forum['allowgetattach'] = $query[0]['allowgetattach'];
  444. $forum['allowgetimage'] = $query[0]['allowgetimage'];
  445. $forum['allowpostattach'] = $query[0]['allowpostattach'];
  446. $forum['allowpostimage'] = $query[0]['allowpostimage'];
  447. }
  448. if($adminid == 3) {
  449. $forum['ismoderator'] = C::t('forum_moderator')->fetch_uid_by_fid_uid($fid, $_G['uid']);
  450. }
  451. }
  452. $forum['ismoderator'] = !empty($forum['ismoderator']) || $adminid == 1 || $adminid == 2 ? 1 : 0;
  453. $fid = $forum['fid'];
  454. $gorup_admingroupids = $_G['setting']['group_admingroupids'] ? dunserialize($_G['setting']['group_admingroupids']) : array('1' => '1');
  455. if($forum['status'] == 3) {
  456. if(!empty($forum['moderators'])) {
  457. $forum['moderators'] = dunserialize($forum['moderators']);
  458. } else {
  459. require_once libfile('function/group');
  460. $forum['moderators'] = update_groupmoderators($fid);
  461. }
  462. if($_G['uid'] && $_G['adminid'] != 1) {
  463. $forum['ismoderator'] = !empty($forum['moderators'][$_G['uid']]) ? 1 : 0;
  464. $_G['adminid'] = 0;
  465. if($forum['ismoderator'] || $gorup_admingroupids[$_G['groupid']]) {
  466. $_G['adminid'] = $_G['adminid'] ? $_G['adminid'] : 3;
  467. if(!empty($gorup_admingroupids[$_G['groupid']])) {
  468. $forum['ismoderator'] = 1;
  469. $_G['adminid'] = 2;
  470. }
  471. $group_userperm = dunserialize($_G['setting']['group_userperm']);
  472. if(is_array($group_userperm)) {
  473. $_G['group'] = array_merge($_G['group'], $group_userperm);
  474. $_G['group']['allowmovethread'] = $_G['group']['allowcopythread'] = $_G['group']['allowedittypethread']= 0;
  475. }
  476. }
  477. }
  478. }
  479. foreach(array('threadtypes', 'threadsorts', 'creditspolicy', 'modrecommend') as $key) {
  480. $forum[$key] = !empty($forum[$key]) ? dunserialize($forum[$key]) : array();
  481. if(!is_array($forum[$key])) {
  482. $forum[$key] = array();
  483. }
  484. }
  485. if($forum['status'] == 3) {
  486. $_G['isgroupuser'] = 0;
  487. $_G['basescript'] = 'group';
  488. if($forum['level'] == 0) {
  489. $levelinfo = C::t('forum_grouplevel')->fetch_by_credits($forum['commoncredits']);
  490. $levelid = $levelinfo['levelid'];
  491. $forum['level'] = $levelid;
  492. C::t('forum_forum')->update_group_level($levelid, $fid);
  493. }
  494. if($forum['level'] != -1) {
  495. loadcache('grouplevels');
  496. $grouplevel = $_G['grouplevels'][$forum['level']];
  497. if(!empty($grouplevel['icon'])) {
  498. $valueparse = parse_url($grouplevel['icon']);
  499. if(!isset($valueparse['host'])) {
  500. $grouplevel['icon'] = $_G['setting']['attachurl'].'common/'.$grouplevel['icon'];
  501. }
  502. }
  503. }
  504. $group_postpolicy = $grouplevel['postpolicy'];
  505. if(is_array($group_postpolicy)) {
  506. $forum = array_merge($forum, $group_postpolicy);
  507. }
  508. $forum['allowfeed'] = $_G['setting']['group_allowfeed'];
  509. if($_G['uid']) {
  510. if(!empty($forum['moderators'][$_G['uid']])) {
  511. $_G['isgroupuser'] = 1;
  512. } else {
  513. $groupuserinfo = C::t('forum_groupuser')->fetch_userinfo($_G['uid'], $fid);
  514. $_G['isgroupuser'] = $groupuserinfo['level'];
  515. if($_G['isgroupuser'] <= 0 && empty($forum['ismoderator'])) {
  516. $_G['group']['allowrecommend'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowrecommend'] = 0;
  517. $_G['group']['allowcommentpost'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentpost'] = 0;
  518. $_G['group']['allowcommentitem'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowcommentitem'] = 0;
  519. $_G['group']['raterange'] = $_G['cache']['usergroup_'.$_G['groupid']]['raterange'] = array();
  520. $_G['group']['allowvote'] = $_G['cache']['usergroup_'.$_G['groupid']]['allowvote'] = 0;
  521. } else {
  522. $_G['isgroupuser'] = 1;
  523. }
  524. }
  525. }
  526. }
  527. } else {
  528. $fid = 0;
  529. }
  530. }
  531. $_G['fid'] = $fid;
  532. $_G['tid'] = $tid;
  533. $_G['forum'] = &$forum;
  534. $_G['current_grouplevel'] = &$grouplevel;
  535. if(empty($_G['uid'])) {
  536. $_G['group']['allowpostactivity'] = $_G['group']['allowpostpoll'] = $_G['group']['allowvote'] = $_G['group']['allowpostreward'] = $_G['group']['allowposttrade'] = $_G['group']['allowpostdebate'] = $_G['group']['allowpostrushreply'] = 0;
  537. }
  538. if(!empty($_G['forum']['widthauto'])) {
  539. $_G['widthauto'] = $_G['forum']['widthauto'];
  540. }
  541. }
  542. function get_thread_by_tid($tid, $forcetableid = null) {
  543. global $_G;
  544. $ret = array();
  545. if(!is_numeric($tid)) {
  546. return $ret;
  547. }
  548. loadcache('threadtableids');
  549. $threadtableids = array(0);
  550. if(!empty($_G['cache']['threadtableids'])) {
  551. if($forcetableid === null || ($forcetableid > 0 && !in_array($forcetableid, $_G['cache']['threadtableids']))) {
  552. $threadtableids = array_merge($threadtableids, $_G['cache']['threadtableids']);
  553. } else {
  554. $threadtableids = array(intval($forcetableid));
  555. }
  556. }
  557. $threadtableids = array_unique($threadtableids);
  558. foreach($threadtableids as $tableid) {
  559. $tableid = $tableid > 0 ? $tableid : 0;
  560. $ret = C::t('forum_thread')->fetch($tid, $tableid);
  561. if($ret) {
  562. $ret['threadtable'] = C::t('forum_thread')->get_table_name($tableid);
  563. $ret['threadtableid'] = $tableid;
  564. $ret['posttable'] = 'forum_post'.($ret['posttableid'] ? '_'.$ret['posttableid'] : '');
  565. break;
  566. }
  567. }
  568. if(!is_array($ret)) {
  569. $ret = array();
  570. } elseif($_G['setting']['optimizeviews']) {
  571. if(($row = C::t('forum_threadaddviews')->fetch($tid))) {
  572. $ret['addviews'] = intval($row['addviews']);
  573. $ret['views'] += $ret['addviews'];
  574. }
  575. }
  576. return $ret;
  577. }
  578. function get_post_by_pid($pid, $fields = '*', $addcondiction = '', $forcetable = null) {
  579. global $_G;
  580. $ret = array();
  581. if(!is_numeric($pid)) {
  582. return $ret;
  583. }
  584. loadcache('posttable_info');
  585. $posttableids = array(0);
  586. if($_G['cache']['posttable_info']) {
  587. if(isset($forcetable)) {
  588. if(is_numeric($forcetable) && array_key_exists($forcetable, $_G['cache']['posttable_info'])) {
  589. $posttableids[] = $forcetable;
  590. } elseif(substr($forcetable, 0, 10) == 'forum_post') {
  591. $posttableids[] = $forcetable;
  592. }
  593. } else {
  594. $posttableids = array_keys($_G['cache']['posttable_info']);
  595. }
  596. }
  597. foreach ($posttableids as $id) {
  598. $table = empty($id) ? 'forum_post' : (is_numeric($id) ? 'forum_post_'.$id : $id);
  599. $ret = C::t('forum_post')->fetch_by_pid_condition($id, $pid, $addcondiction, $fields);
  600. if($ret) {
  601. $ret['posttable'] = $table;
  602. break;
  603. }
  604. }
  605. if(!is_array($ret)) {
  606. $ret = array();
  607. }
  608. return $ret;
  609. }
  610. function get_post_by_tid_pid($tid, $pid) {
  611. static $postlist = array();
  612. if(empty($postlist[$pid])) {
  613. $postlist[$pid] = C::t('forum_post')->fetch('tid:'.$tid, $pid, false);
  614. if($postlist[$pid] && $postlist[$pid]['tid'] == $tid) {
  615. $user = getuserbyuid($postlist[$pid]['authorid']);
  616. $postlist[$pid]['adminid'] = $user['adminid'];
  617. } else {
  618. $postlist[$pid] = array();
  619. }
  620. }
  621. return $postlist[$pid];
  622. }
  623. function set_rssauth() {
  624. global $_G;
  625. if($_G['setting']['rssstatus'] && $_G['uid']) {
  626. $auth = authcode($_G['uid']."\t".($_G['fid'] ? $_G['fid'] : '').
  627. "\t".substr(md5($_G['member']['password']), 0, 8), 'ENCODE', md5($_G['config']['security']['authkey']));
  628. } else {
  629. $auth = '0';
  630. }
  631. $_G['rssauth'] = rawurlencode($auth);
  632. }
  633. function rssforumperm($forum) {
  634. $is_allowed = $forum['type'] != 'group' && (!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'], 7)));
  635. return $is_allowed;
  636. }
  637. function upload_icon_banner(&$data, $file, $type) {
  638. global $_G;
  639. $data['extid'] = empty($data['extid']) ? $data['fid'] : $data['extid'];
  640. if(empty($data['extid'])) return '';
  641. if($data['status'] == 3 && $_G['setting']['group_imgsizelimit']) {
  642. $file['size'] > ($_G['setting']['group_imgsizelimit'] * 1024) && showmessage('file_size_overflow', '', array('size' => $_G['setting']['group_imgsizelimit'] * 1024));
  643. }
  644. $upload = new discuz_upload();
  645. $uploadtype = $data['status'] == 3 ? 'group' : 'common';
  646. if(!$upload->init($file, $uploadtype, $data['extid'], $type)) {
  647. return false;
  648. }
  649. if(!$upload->save()) {
  650. if(!defined('IN_ADMINCP')) {
  651. showmessage($upload->errormessage());
  652. } else {
  653. cpmsg($upload->errormessage(), '', 'error');
  654. }
  655. }
  656. if($data['status'] == 3 && $type == 'icon') {
  657. require_once libfile('class/image');
  658. $img = new image;
  659. $img->Thumb($upload->attach['target'], './'.$uploadtype.'/'.$upload->attach['attachment'], 48, 48, 'fixwr');
  660. }
  661. return $upload->attach['attachment'];
  662. }
  663. function arch_multi($total, $perpage, $page, $link) {
  664. $pages = @ceil($total / $perpage) + 1;
  665. $pagelink = '';
  666. if($pages > 1) {
  667. $pagelink .= lang('forum/archiver', 'page') . ": \n";
  668. $pagestart = $page - 10 < 1 ? 1 : $page - 10;
  669. $pageend = $page + 10 >= $pages ? $pages : $page + 10;
  670. for($i = $pagestart; $i < $pageend; $i++) {
  671. $pagelink .= ($i == $page ? "<strong>[$i]</strong>" : "<a href=\"$link&page=$i\">$i</a>")." \n";
  672. }
  673. }
  674. return $pagelink;
  675. }
  676. function loadarchiver($path) {
  677. global $_G;
  678. if(!$_G['setting']['archiver']) {
  679. require_once DISCUZ_ROOT . "./source/archiver/common/header.php";
  680. echo '<div id="content">'.lang('message', 'forum_archiver_disabled').'</div>';
  681. require_once DISCUZ_ROOT . "./source/archiver/common/footer.php";
  682. exit;
  683. }
  684. $filename = $path . '.php';
  685. return DISCUZ_ROOT . "./source/archiver/$filename";
  686. }
  687. function update_threadpartake($tid, $getsetarr = false) {
  688. global $_G;
  689. $setarr = array();
  690. if($_G['uid'] && $tid) {
  691. if($_G['setting']['heatthread']['period']) {
  692. $partaked = C::t('forum_threadpartake')->fetch($tid, $_G['uid']);
  693. $partaked = $partaked['uid'];
  694. if(!$partaked) {
  695. C::t('forum_threadpartake')->insert(array('tid' => $tid, 'uid' => $_G['uid'], 'dateline' => TIMESTAMP));
  696. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  697. }
  698. } else {
  699. $setarr = C::t('forum_thread')->increase($tid, array('heats' => 1), false, 0, $getsetarr);
  700. }
  701. }
  702. if($getsetarr) {
  703. return $setarr;
  704. }
  705. }
  706. function getthreadcover($tid, $cover = 0, $getfilename = 0) {
  707. global $_G;
  708. if(empty($tid)) {
  709. return '';
  710. }
  711. $coverpath = '';
  712. $covername = 'threadcover/'.substr(md5($tid), 0, 2).'/'.substr(md5($tid), 2, 2).'/'.$tid.'.jpg';
  713. if($getfilename) {
  714. return $covername;
  715. }
  716. if($cover) {
  717. $coverpath = ($cover < 0 ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/'.$covername;
  718. }
  719. return $coverpath;
  720. }
  721. function convertunusedattach($aid, $tid, $pid) {
  722. if(!$aid) {
  723. return;
  724. }
  725. global $_G;
  726. $attach = C::t('forum_attachment_n')->fetch_by_aid_uid(127, $aid, $_G['uid']);
  727. if(!$attach) {
  728. return;
  729. }
  730. $attach = daddslashes($attach);
  731. $attach['tid'] = $tid;
  732. $attach['pid'] = $pid;
  733. C::t('forum_attachment_n')->insert('tid:'.$tid, $attach);
  734. C::t('forum_attachment')->update($attach['aid'], array('tid' => $tid, 'pid' => $pid, 'tableid' => getattachtableid($tid)));
  735. C::t('forum_attachment_unused')->delete($attach['aid']);
  736. }
  737. function updateattachtid($idtype, $ids, $oldtid, $newtid) {
  738. foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$oldtid, $idtype, $ids) as $attach) {
  739. $attach['tid'] = $newtid;
  740. C::t('forum_attachment_n')->insert('tid:'.$newtid, $attach);
  741. }
  742. C::t('forum_attachment_n')->delete_by_id('tid:'.$oldtid, $idtype, $ids);
  743. C::t('forum_attachment')->update_by_id($idtype, $ids, $newtid);
  744. }
  745. function updatepost($data, $condition, $unbuffered = false, $posttableid = false) {
  746. return false;
  747. }
  748. function insertpost($data) {
  749. if(isset($data['tid'])) {
  750. $thread = C::t('forum_thread')->fetch($data['tid']);
  751. $tableid = $thread['posttableid'];
  752. } else {
  753. $tableid = $data['tid'] = 0;
  754. }
  755. $pid = C::t('forum_post_tableid')->insert(array('pid' => null), true);
  756. $data = array_merge($data, array('pid' => $pid));
  757. C::t('forum_post')->insert($tableid, $data);
  758. if($pid % 1024 == 0) {
  759. C::t('forum_post_tableid')->delete_by_lesspid($pid);
  760. }
  761. savecache('max_post_id', $pid);
  762. return $pid;
  763. }
  764. function threadmodstatus($string) {
  765. global $_G;
  766. $postmodperiods = periodscheck('postmodperiods', 0);
  767. if($postmodperiods) {
  768. $modnewthreads = $modnewreplies = 1;
  769. } else {
  770. $censormod = censormod($string);
  771. $modnewthreads = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 1) && $_G['forum']['modnewposts'] || $censormod ? 1 : 0;
  772. $modnewreplies = (!$_G['group']['allowdirectpost'] || $_G['group']['allowdirectpost'] == 2) && $_G['forum']['modnewposts'] == 2 || $censormod ? 1 : 0;
  773. if($_G['forum']['status'] == 3) {
  774. $modnewthreads = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 1 || $censormod ? 1 : 0;
  775. $modnewreplies = !$_G['group']['allowgroupdirectpost'] || $_G['group']['allowgroupdirectpost'] == 2 || $censormod ? 1 : 0;
  776. }
  777. }
  778. $_G['group']['allowposturl'] = $_G['forum']['status'] != 3 ? $_G['group']['allowposturl'] : $_G['group']['allowgroupposturl'];
  779. if($_G['group']['allowposturl'] == 1) {
  780. if(!$postmodperiods) {
  781. $censormod = censormod($string);
  782. }
  783. if($censormod) {
  784. $modnewthreads = $modnewreplies = 1;
  785. }
  786. }
  787. return array($modnewthreads, $modnewreplies);
  788. }
  789. function threadpubsave($tid, $passapproval = false) {
  790. global $_G;
  791. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  792. $hookparam = func_get_args();
  793. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'check'), 'threadpubsave');
  794. }
  795. $thread = C::t('forum_thread')->fetch_by_tid_displayorder($tid, -4, '=', !$passapproval ? $_G['uid'] : null);
  796. if(!$thread) {
  797. return 0;
  798. }
  799. $threadpost = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
  800. $thread['message'] = $threadpost['message'];
  801. $modworksql = 0;
  802. $displayorder = 0;
  803. $dateline = $_G['timestamp'];
  804. $moderatepids = $saveposts = array();
  805. $return = 1;
  806. list($modnewthreads) = threadmodstatus($thread['subject']."\t".$thread['message']);
  807. if($modnewthreads && $passapproval === false) {
  808. updatemoderate('tid', $tid);
  809. manage_addnotify('verifythread');
  810. $displayorder = -2;
  811. $modworksql = 1;
  812. $return = -1;
  813. } else {
  814. C::t('forum_post')->update_by_tid('tid:'.$tid, $tid, array('dateline' => $dateline, 'invisible' => '0'), false, false, 1);
  815. }
  816. C::t('forum_thread')->update($tid, array('displayorder'=>$displayorder, 'dateline'=>$_G['timestamp'], 'lastpost'=>$_G['timestamp']));
  817. $posts = $thread['replies'] + 1;
  818. if($thread['replies']) {
  819. $saveposts = C::t('forum_post')->fetch_all_by_tid('tid:'.$tid, $tid, true, '', 0, 0, 0);
  820. foreach($saveposts as $post) {
  821. $dateline++;
  822. $invisible = 0;
  823. list(, $modnewreplies) = threadmodstatus($post['subject']."\t".$post['message']);
  824. if($modnewreplies) {
  825. $moderatepids[] = $post['pid'];
  826. $verifypost = true;
  827. $invisible = -2;
  828. $modworksql = 1;
  829. $return = -2;
  830. }
  831. C::t('forum_post')->update('tid:'.$tid, $post['pid'], array('dateline' => $dateline, 'invisible' => $invisible));
  832. updatepostcredits('+', $thread['authorid'], 'reply', $thread['fid']);
  833. }
  834. }
  835. if($moderatepids) {
  836. updatemoderate('pid', $moderatepids);
  837. manage_addnotify('verifypost');
  838. }
  839. updatepostcredits('+', $thread['authorid'], 'post', $thread['fid']);
  840. $attachcount = C::t('forum_attachment_n')->count_by_id('tid:'.$thread['tid'], 'tid', $thread['tid']);
  841. updatecreditbyaction('postattach', $thread['authorid'], array(), '', $attachcount, 1, $thread['fid']);
  842. if($_G['forum']['status'] == 3) {
  843. C::t('forum_groupuser')->update_counter_for_user($thread['authorid'], $thread['fid'], 1);
  844. }
  845. $subject = str_replace("\t", ' ', $thread['subject']);
  846. $lastpost = $thread['tid']."\t".$subject."\t".$thread['lastpost']."\t".$thread['lastposter'];
  847. C::t('forum_forum')->update($_G['fid'], array('lastpost' => $lastpost));
  848. C::t('forum_forum')->update_forum_counter($thread['fid'], 1, $posts, $posts, $modworksql);
  849. if($_G['forum']['type'] == 'sub') {
  850. C::t('forum_forum')->update($_G['forum']['fup'], array('lastpost' => $lastpost));
  851. }
  852. if($_G['setting']['plugins']['func'][HOOKTYPE]['threadpubsave']) {
  853. hookscript('threadpubsave', 'global', 'funcs', array('param' => $hookparam, 'step' => 'save', 'posts' => $saveposts), 'threadpubsave');
  854. }
  855. return $return;
  856. }
  857. function getrelatecollection($tid, $all = false, &$num, &$more) {
  858. global $_G;
  859. $maxdisplay = $_G['setting']['collectionnum'];
  860. if(!$maxdisplay) return;
  861. $tidrelate = C::t('forum_collectionrelated')->fetch($tid);
  862. $ctids = explode("\t", $tidrelate['collection'], -1);
  863. $num = count($ctids);
  864. if(!$ctids || !$num) {
  865. $more = $num = 0;
  866. return null;
  867. }
  868. if($all !== true && $num > $maxdisplay) {
  869. $more = 1;
  870. } else {
  871. $maxdisplay = 0;
  872. }
  873. return C::t('forum_collection')->fetch_all($ctids, 'follownum', 'DESC', 0, $maxdisplay, '', $tid);
  874. }
  875. function set_atlist_cookie($uids) {
  876. global $_G;
  877. $atlist = $tmp = array();
  878. $num = 0;
  879. $maxlist = 10;
  880. if(empty($uids)) {
  881. return;
  882. }
  883. $newnum = count($uids);
  884. if($newnum >= $maxlist) {
  885. $uids = array_slice($uids, 0, $maxlist);
  886. dsetcookie('atlist', implode(',', $uids), 86400 * 360);
  887. return;
  888. }
  889. if($_G['cookie']['atlist']) {
  890. $atlist = explode(',', $_G['cookie']['atlist']);
  891. foreach($atlist as $key => $val) {
  892. if(!in_array($val, $uids)) {
  893. $num++;
  894. if($num == ($maxlist - $newnum)) {
  895. break;
  896. }
  897. $tmp[$key] = $val;
  898. }
  899. }
  900. }
  901. dsetcookie('atlist', implode(',', $uids).($tmp ? ','.implode(',', $tmp) : ''), 86400 * 360);
  902. }
  903. function cloud_referer_related() {
  904. global $_G;
  905. $my_search_data = $_G['setting']['my_search_data'];
  906. if (viewthread_is_search_referer() && $my_search_data['status']) {
  907. $appService = Cloud::loadClass('Service_App');
  908. if($appService->getCloudAppStatus('search')) {
  909. $_params = array('s_site_gid' => $_G['groupid'],
  910. 'response_type' => 'js',
  911. 'referer' => $_SERVER['HTTP_REFERER'],
  912. );
  913. $utilService = Cloud::loadClass('Service_Util');
  914. $signUrl = $utilService->generateSiteSignUrl($_params);
  915. $my_search_se_url = 'http://search.discuz.qq.com/api/site/se?' . $signUrl . "";
  916. }
  917. }
  918. return $my_search_se_url;
  919. }
  920. function viewthread_is_search_referer() {
  921. $regex = "((http|https)\:\/\/)?";
  922. $regex .= "([a-z]*.)?(ask.com|yahoo.com|cn.yahoo.com|bing.com|baidu.com|soso.com|google.com|google.cn)(.[a-z]{2,3})?\/";
  923. if(preg_match("/^$regex/", $_SERVER['HTTP_REFERER'])) {
  924. return true;
  925. }
  926. return false;
  927. }
  928. function stringtopic($value, $key = '', $force = false, $rlength = 0) {
  929. if($key === '') {
  930. $key = $value;
  931. }
  932. $basedir = !getglobal('setting/attachdir') ? './data/attachment' : getglobal('setting/attachdir');
  933. $url = !getglobal('setting/attachurl') ? './data/attachment/' : getglobal('setting/attachurl');
  934. $subdir1 = substr(md5($key), 0, 2);
  935. $subdir2 = substr(md5($key), 2, 2);
  936. $target = 'temp/'.$subdir1.'/'.$subdir2.'/';
  937. $targetname = substr(md5($key), 8, 16).'.png';
  938. discuz_upload::check_dir_exists('temp', $subdir1, $subdir2);
  939. if(!$force && file_exists($basedir.'/'.$target.$targetname)) {
  940. return $url.$target.$targetname;
  941. }
  942. $value = str_replace("\n", '', $value);
  943. $fontfile = $fontname = '';
  944. $ttfenabled = false;
  945. $size = 10;
  946. $w = 130;
  947. $rowh = 25;
  948. $value = explode("\r", $value);
  949. if($rlength) {
  950. $temp = array();
  951. foreach($value as $str) {
  952. $strlen = dstrlen($str);
  953. if($strlen > $rlength) {
  954. for($i = 0; $i < $strlen; $i++) {
  955. $sub = cutstr($str, $rlength, '');
  956. $temp[] = $sub;
  957. $str = substr($str, strlen($sub));
  958. $strlen = $strlen - $rlength;
  959. }
  960. } else {
  961. $temp[] = $str;
  962. }
  963. }
  964. $value = $temp;
  965. unset($temp);
  966. }
  967. if(function_exists('imagettftext')) {
  968. $fontroot = DISCUZ_ROOT.'./static/image/seccode/font/ch/';
  969. $dirs = opendir($fontroot);
  970. while($entry = readdir($dirs)) {
  971. if($entry != '.' && $entry != '..' && in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) {
  972. $fontname = $entry;
  973. break;
  974. }
  975. }
  976. if(!empty($fontname)) {
  977. $fontfile = DISCUZ_ROOT.'./static/image/seccode/font/ch/'.$fontname;
  978. }
  979. if($fontfile) {
  980. if(strtoupper(CHARSET) != 'UTF-8') {
  981. include DISCUZ_ROOT.'./source/class/class_chinese.php';
  982. $cvt = new Chinese(CHARSET, 'utf8');
  983. $value = $cvt->Convert(implode("\r", $value));
  984. $value = explode("\r", $value);
  985. }
  986. $ttfenabled = true;
  987. }
  988. }
  989. foreach($value as $str) {
  990. if($ttfenabled) {
  991. $box = imagettfbbox($size, 0, $fontfile, $str);
  992. $height = max($box[1], $box[3]) - min($box[5], $box[7]);
  993. $len = (max($box[2], $box[4]) - min($box[0], $box[6]));
  994. $rowh = max(array($height, $rowh));
  995. } else {
  996. $len = strlen($str) * 12;
  997. }
  998. $w = max(array($len, $w));
  999. }
  1000. $h = $rowh * count($value) + count($value) * 2;
  1001. $im = @imagecreate($w, $h);
  1002. $background_color = imagecolorallocate($im, 255, 255, 255);
  1003. $text_color = imagecolorallocate($im, 60, 60, 60);
  1004. $h = $ttfenabled ? $rowh : 4;
  1005. foreach($value as $str) {
  1006. if($ttfenabled) {
  1007. imagettftext($im, $size, 0, 0, $h, $text_color, $fontfile, $str);
  1008. $h += 2;
  1009. } else {
  1010. imagestring($im, $size, 0, $h, $str, $text_color);
  1011. }
  1012. $h += $rowh;
  1013. }
  1014. imagepng($im, $basedir.'/'.$target.$targetname);
  1015. imagedestroy($im);
  1016. return $url.$target.$targetname;
  1017. }
  1018. function getreplybg($replybg = '') {
  1019. global $_G;
  1020. $style = '';
  1021. if($_G['setting']['allowreplybg']) {
  1022. if($replybg) {
  1023. $bgurl = $replybg;
  1024. if(file_exists($_G['setting']['attachurl'].'common/'.$replybg)) {
  1025. $bgurl = $_G['setting']['attachurl'].'common/'.$replybg;
  1026. }
  1027. } elseif($_G['setting']['globalreplybg']) {
  1028. $bgurl = $_G['setting']['globalreplybg'];
  1029. if(file_exists($_G['setting']['attachurl'].'common/'.$_G['setting']['globalreplybg'])) {
  1030. $bgurl = $_G['setting']['attachurl'].'common/'.$_G['setting']['globalreplybg'];
  1031. }
  1032. }
  1033. if($bgurl) {
  1034. $style = ' style="background-image: url('.$bgurl.');"';
  1035. }
  1036. }
  1037. return $style;
  1038. }
  1039. ?>