PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/web raovat.vn php/az24/source/function/function_forumlist.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 386 lines | 343 code | 37 blank | 6 comment | 111 complexity | b8d8c1f8e1d7daa043f2e5cd06784e3b 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_forumlist.php 31131 2012-07-18 09:44:21Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function checkautoclose($thread) {
  12. global $_G;
  13. if(!$_G['forum']['ismoderator'] && $_G['forum']['autoclose']) {
  14. $closedby = $_G['forum']['autoclose'] > 0 ? 'dateline' : 'lastpost';
  15. $_G['forum']['autoclose'] = abs($_G['forum']['autoclose']);
  16. if(TIMESTAMP - $thread[$closedby] > $_G['forum']['autoclose'] * 86400) {
  17. return 'post_thread_closed_by_'.$closedby;
  18. }
  19. }
  20. return FALSE;
  21. }
  22. function forum(&$forum) {
  23. global $_G;
  24. $lastvisit = $_G['member']['lastvisit'];
  25. if(!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'])) || !empty($forum['allowview']) || (isset($forum['users']) && strstr($forum['users'], "\t$_G[uid]\t"))) {
  26. $forum['permission'] = 2;
  27. } elseif(!$_G['setting']['hideprivate']) {
  28. $forum['permission'] = 1;
  29. } else {
  30. return FALSE;
  31. }
  32. if($forum['icon']) {
  33. $forum['icon'] = get_forumimg($forum['icon']);
  34. $forum['icon'] = '<a href="forum.php?mod=forumdisplay&fid='.$forum['fid'].'"><img src="'.$forum['icon'].'" align="left" alt="" /></a>';
  35. }
  36. $lastpost = array(0, 0, '', '');
  37. $forum['lastpost'] = is_string($forum['lastpost']) ? explode("\t", $forum['lastpost']) : $forum['lastpost'];
  38. $forum['lastpost'] =count($forum['lastpost']) != 4 ? $lastpost : $forum['lastpost'];
  39. list($lastpost['tid'], $lastpost['subject'], $lastpost['dateline'], $lastpost['author']) = $forum['lastpost'];
  40. $thisforumlastvisit = array();
  41. if($_G['cookie']['forum_lastvisit']) {
  42. preg_match("/D\_".$forum['fid']."\_(\d+)/", $_G['cookie']['forum_lastvisit'], $thisforumlastvisit);
  43. }
  44. $forum['folder'] = ($thisforumlastvisit && $thisforumlastvisit[1] > $lastvisit ? $thisforumlastvisit[1] : $lastvisit) < $lastpost['dateline'] ? ' class="new"' : '';
  45. if($lastpost['tid']) {
  46. $lastpost['dateline'] = dgmdate($lastpost['dateline'], 'u');
  47. $lastpost['authorusername'] = $lastpost['author'];
  48. if($lastpost['author']) {
  49. $lastpost['author'] = '<a href="home.php?mod=space&username='.rawurlencode($lastpost['author']).'">'.$lastpost['author'].'</a>';
  50. }
  51. $forum['lastpost'] = $lastpost;
  52. } else {
  53. $forum['lastpost'] = $lastpost['authorusername'] = '';
  54. }
  55. $forum['moderators'] = moddisplay($forum['moderators'], $_G['setting']['moddisplay'], !empty($forum['inheritedmod']));
  56. if(isset($forum['subforums'])) {
  57. $forum['subforums'] = implode(', ', $forum['subforums']);
  58. }
  59. return TRUE;
  60. }
  61. function forumselect($groupselectable = FALSE, $arrayformat = 0, $selectedfid = 0, $showhide = FALSE, $evalue = FALSE, $special = 0) {
  62. global $_G;
  63. if(!isset($_G['cache']['forums'])) {
  64. loadcache('forums');
  65. }
  66. $forumcache = &$_G['cache']['forums'];
  67. $forumlist = $arrayformat ? array() : '<optgroup label="&nbsp;">';
  68. foreach($forumcache as $forum) {
  69. if(!$forum['status'] && !$showhide) {
  70. continue;
  71. }
  72. if($selectedfid) {
  73. if(!is_array($selectedfid)) {
  74. $selected = $selectedfid == $forum['fid'] ? ' selected' : '';
  75. } else {
  76. $selected = in_array($forum['fid'], $selectedfid) ? ' selected' : '';
  77. }
  78. }
  79. if($forum['type'] == 'group') {
  80. if($arrayformat) {
  81. $forumlist[$forum['fid']]['name'] = $forum['name'];
  82. } else {
  83. $forumlist .= $groupselectable ? '<option value="'.($evalue ? 'gid_' : '').$forum['fid'].'" class="bold">--'.$forum['name'].'</option>' : '</optgroup><optgroup label="--'.$forum['name'].'">';
  84. }
  85. $visible[$forum['fid']] = true;
  86. } elseif($forum['type'] == 'forum' && isset($visible[$forum['fup']]) && (!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'])) || strstr($forum['users'], "\t$_G[uid]\t")) && (!$special || (substr($forum['allowpostspecial'], -$special, 1)))) {
  87. if($arrayformat) {
  88. $forumlist[$forum['fup']]['sub'][$forum['fid']] = $forum['name'];
  89. } else {
  90. $forumlist .= '<option value="'.($evalue ? 'fid_' : '').$forum['fid'].'"'.$selected.'>'.$forum['name'].'</option>';
  91. }
  92. $visible[$forum['fid']] = true;
  93. } elseif($forum['type'] == 'sub' && isset($visible[$forum['fup']]) && (!$forum['viewperm'] || ($forum['viewperm'] && forumperm($forum['viewperm'])) || strstr($forum['users'], "\t$_G[uid]\t")) && (!$special || substr($forum['allowpostspecial'], -$special, 1))) {
  94. if($arrayformat) {
  95. $forumlist[$forumcache[$forum['fup']]['fup']]['child'][$forum['fup']][$forum['fid']] = $forum['name'];
  96. } else {
  97. $forumlist .= '<option value="'.($evalue ? 'fid_' : '').$forum['fid'].'"'.$selected.'>&nbsp; &nbsp; &nbsp; '.$forum['name'].'</option>';
  98. }
  99. }
  100. }
  101. if(!$arrayformat) {
  102. $forumlist .= '</optgroup>';
  103. $forumlist = str_replace('<optgroup label="&nbsp;"></optgroup>', '', $forumlist);
  104. }
  105. return $forumlist;
  106. }
  107. function visitedforums() {
  108. global $_G;
  109. $count = 0;
  110. $visitedforums = '';
  111. $fidarray = array($_G['forum']['fid']);
  112. $_G['cookie']['visitedfid'] = isset($_G['cookie']['visitedfid']) ? $_G['cookie']['visitedfid'] : '';
  113. if(!empty($_G['cookie']['visitedfid'])) {
  114. foreach(explode('D', $_G['cookie']['visitedfid']) as $fid) {
  115. if(isset($_G['cache']['forums'][$fid]) && !in_array($fid, $fidarray)) {
  116. if($fid != $_G['forum']['fid']) {
  117. $visitedforums .= '<li><a href="forum.php?mod=forumdisplay&fid='.$fid.'">'.$_G['cache']['forums'][$fid]['name'].'</a></li>';
  118. if(++$count >= $_G['setting']['visitedforums']) {
  119. break;
  120. }
  121. }
  122. $fidarray[] = $fid;
  123. }
  124. }
  125. }
  126. if(($visitedfid = implode('D', $fidarray)) != $_G['cookie']['visitedfid']) {
  127. dsetcookie('visitedfid', $visitedfid, 2592000);
  128. }
  129. return $visitedforums;
  130. }
  131. function moddisplay($moderators, $type, $inherit = 0) {
  132. if($moderators) {
  133. $modlist = $comma = '';
  134. foreach(explode("\t", $moderators) as $moderator) {
  135. $modlist .= $comma.'<a href="home.php?mod=space&username='.rawurlencode($moderator).'" class="notabs" c="1">'.($inherit ? '<strong>'.$moderator.'</strong>' : $moderator).'</a>';
  136. $comma = ', ';
  137. }
  138. } else {
  139. $modlist = '';
  140. }
  141. return $modlist;
  142. }
  143. function getcacheinfo($tid) {
  144. global $_G;
  145. $tid = intval($tid);
  146. $cachethreaddir2 = DISCUZ_ROOT.'./'.$_G['setting']['cachethreaddir'];
  147. $cache = array('filemtime' => 0, 'filename' => '');
  148. $tidmd5 = substr(md5($tid), 3);
  149. $fulldir = $cachethreaddir2.'/'.$tidmd5[0].'/'.$tidmd5[1].'/'.$tidmd5[2].'/';
  150. $cache['filename'] = $fulldir.$tid.'.htm';
  151. if(file_exists($cache['filename'])) {
  152. $cache['filemtime'] = filemtime($cache['filename']);
  153. } else {
  154. if(!is_dir($fulldir)) {
  155. dmkdir($fulldir);
  156. }
  157. }
  158. return $cache;
  159. }
  160. function recommendupdate($fid, &$modrecommend, $force = '', $position = 0) {
  161. global $_G;
  162. $recommendlist = $recommendimagelist = $modedtids = array();
  163. $num = $modrecommend['num'] ? intval($modrecommend['num']) : 10;
  164. $imagenum = $modrecommend['imagenum'] = $modrecommend['imagenum'] ? intval($modrecommend['imagenum']) : 0;
  165. $imgw = $modrecommend['imagewidth'] = $modrecommend['imagewidth'] ? intval($modrecommend['imagewidth']) : 200;
  166. $imgh = $modrecommend['imageheight'] = $modrecommend['imageheight'] ? intval($modrecommend['imageheight']) : 150;
  167. if($modrecommend['sort'] && (TIMESTAMP - $modrecommend['updatetime'] > $modrecommend['cachelife'] || $force)) {
  168. foreach(C::t('forum_forumrecommend')->fetch_all_by_fid($fid) as $row) {
  169. if($modrecommend['sort'] == 2 && $row['moderatorid']) {
  170. $modedtids[] = $row['tid'];
  171. }
  172. }
  173. C::t('forum_forumrecommend')->delete_by_fid($fid, $modrecommend['sort'] == 2 ? 0 : false);
  174. $orderby = 'dateline';
  175. $dateline = $modrecommend['dateline'] ? (TIMESTAMP - $modrecommend['dateline'] * 3600) : null;
  176. $recommends = null;
  177. switch($modrecommend['orderby']) {
  178. case '':
  179. case '1':$orderby = 'lastpost';break;
  180. case '2':$orderby = 'views';break;
  181. case '3':$orderby = 'replies';break;
  182. case '4':$orderby = 'digest';break;
  183. case '5':$orderby = 'recommends';$recommends = 0;break;
  184. case '6':$orderby = 'heats';break;
  185. }
  186. $i = 0;
  187. $addthread = $addimg = $recommendlist = $recommendimagelist = $tids = array();
  188. foreach(C::t('forum_thread')->fetch_all_by_fid_displayorder($fid, 0, $dateline, $recommends, 0, $num, $orderby) as $thread) {
  189. $recommendlist[$thread['tid']] = $thread;
  190. $tids[] = $thread['tid'];
  191. if(!$modedtids || !in_array($thread['tid'], $modedtids)) {
  192. $addthread[$thread['tid']] = array(
  193. 'fid' => $thread['fid'],
  194. 'tid' => $thread['tid'],
  195. 'position' => 1,
  196. 'displayorder' => $i,
  197. 'subject' => $thread['subject'],
  198. 'author' => $thread['author'],
  199. 'authorid' => $thread['authorid'],
  200. 'moderatorid' => 0,
  201. 'expiration' => 0,
  202. 'highlight' => $thread['highlight']
  203. );
  204. $i++;
  205. }
  206. }
  207. if($tids && $imagenum) {
  208. $attachtables = array();
  209. foreach($tids as $tid) {
  210. $attachtables[getattachtablebytid($tid)][] = $tid;
  211. }
  212. foreach($attachtables as $attachtable => $tids) {
  213. $attachmentpost = array();
  214. $postlist = C::t('forum_post')->fetch_all_by_tid(0, $tids, false, '', 0, 0, 1);
  215. if($postlist) {
  216. $pids = array();
  217. foreach($postlist as $post) {
  218. $pids[] = $post['pid'];
  219. }
  220. $attachmentlist = C::t('forum_attachment_n')->fetch_all_by_pid_width('tid:'.$tids[0], $pids, $imgw);
  221. if($attachmentlist) {
  222. foreach($attachmentlist as $k => $attachment) {
  223. $attachmentpost[$k]['fid'] = $postlist[$attachment['pid']]['fid'];
  224. $attachmentpost[$k]['tid'] = $postlist[$attachment['pid']]['tid'];
  225. $attachmentpost[$k]['aid'] = $attachment['aid'];
  226. }
  227. }
  228. unset($postlist, $attachmentlist, $pids);
  229. }
  230. foreach($attachmentpost as $attachment) {
  231. if(isset($recommendimagelist[$attachment['tid']])) {
  232. continue;
  233. }
  234. $key = md5($attachment['aid'].'|'.$imgw.'|'.$imgh);
  235. $recommendlist[$attachment['tid']]['filename'] = $attachment['aid']."\t".$imgw."\t".$imgh."\t".$key;
  236. $recommendimagelist[$attachment['tid']] = $recommendlist[$attachment['tid']];
  237. $recommendimagelist[$attachment['tid']]['subject'] = addslashes($recommendimagelist[$attachment['tid']]['subject']);
  238. $addthread[$attachment['tid']]['aid'] = '';
  239. $addthread[$attachment['tid']]['filename'] = $recommendlist[$attachment['tid']]['filename'];
  240. $addthread[$attachment['tid']]['typeid'] = 1;
  241. if(count($recommendimagelist) == $imagenum) {
  242. break;
  243. }
  244. }
  245. }
  246. }
  247. unset($recommendimagelist);
  248. if($addthread) {
  249. foreach($addthread as $row) {
  250. C::t('forum_forumrecommend')->insert($row, false, true);
  251. }
  252. $modrecommend['updatetime'] = TIMESTAMP;
  253. $modrecommendnew = serialize($modrecommend);
  254. C::t('forum_forumfield')->update($fid, array('modrecommend' => $modrecommendnew));
  255. }
  256. }
  257. $recommendlists = $recommendlist = array();
  258. foreach(C::t('forum_forumrecommend')->fetch_all_by_fid($fid, $position) as $recommend) {
  259. if(($recommend['expiration'] && $recommend['expiration'] > TIMESTAMP) || !$recommend['expiration']) {
  260. if($recommend['filename'] && strexists($recommend['filename'], "\t")) {
  261. $imgd = explode("\t", $recommend['filename']);
  262. if($imgd[0] && $imgd[3]) {
  263. $recommend['filename'] = 'forum.php?mod=image&aid='.$imgd[0].'&size='.$imgd[1].'x'.$imgd[2].'&key='.rawurlencode($imgd[3]);
  264. }
  265. }
  266. $recommendlist[] = $recommend;
  267. if($recommend['typeid'] && count($recommendimagelist) < $imagenum) {
  268. $recommendimagelist[] = $recommend;
  269. }
  270. }
  271. if(count($recommendlist) == $num) {
  272. break;
  273. }
  274. }
  275. if($recommendlist) {
  276. $_G['forum_colorarray'] = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
  277. foreach($recommendlist as $thread) {
  278. if($thread['highlight']) {
  279. $string = sprintf('%02d', $thread['highlight']);
  280. $stylestr = sprintf('%03b', $string[0]);
  281. $thread['highlight'] = ' style="';
  282. $thread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
  283. $thread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
  284. $thread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
  285. $thread['highlight'] .= $string[1] ? 'color: '.$_G['forum_colorarray'][$string[1]] : '';
  286. $thread['highlight'] .= '"';
  287. } else {
  288. $thread['highlight'] = '';
  289. }
  290. $recommendlists[$thread['tid']]['author'] = $thread['author'];
  291. $recommendlists[$thread['tid']]['authorid'] = $thread['authorid'];
  292. $recommendlists[$thread['tid']]['subject'] = $modrecommend['maxlength'] ? cutstr($thread['subject'], $modrecommend['maxlength']) : $thread['subject'];
  293. $recommendlists[$thread['tid']]['subjectstyles'] = $thread['highlight'];
  294. }
  295. }
  296. if($recommendimagelist && $recommendlist) {
  297. $recommendlists['images'] = $recommendimagelist;
  298. }
  299. return $recommendlists;
  300. }
  301. function showstars($num) {
  302. global $_G;
  303. $alt = 'alt="Rank: '.$num.'"';
  304. if(empty($_G['setting']['starthreshold'])) {
  305. for($i = 0; $i < $num; $i++) {
  306. echo '<img src="'.$_G['style']['imgdir'].'/star_level1.gif" '.$alt.' />';
  307. }
  308. } else {
  309. for($i = 3; $i > 0; $i--) {
  310. $numlevel = intval($num / pow($_G['setting']['starthreshold'], ($i - 1)));
  311. $num = ($num % pow($_G['setting']['starthreshold'], ($i - 1)));
  312. for($j = 0; $j < $numlevel; $j++) {
  313. echo '<img src="'.$_G['style']['imgdir'].'/star_level'.$i.'.gif" '.$alt.' />';
  314. }
  315. }
  316. }
  317. }
  318. function get_forumimg($imgname) {
  319. global $_G;
  320. if($imgname) {
  321. $parse = parse_url($imgname);
  322. if(isset($parse['host'])) {
  323. $imgpath = $imgname;
  324. } else {
  325. if($_G['forum']['status'] != 3) {
  326. $imgpath = $_G['setting']['attachurl'].'common/'.$imgname;
  327. } else {
  328. $imgpath = $_G['setting']['attachurl'].'group/'.$imgname;
  329. }
  330. }
  331. return $imgpath;
  332. }
  333. }
  334. function forumleftside() {
  335. global $_G;
  336. $leftside = array('favorites' => array(), 'forums' => array());
  337. $leftside['forums'] = forumselect(FALSE, 1);
  338. if($_G['uid']) {
  339. foreach(C::t('home_favorite')->fetch_all_by_uid_idtype($_G['uid'], 'fid') as $id => $forum) {
  340. if($_G['fid'] == $forum['id']) {
  341. $_G['forum_fidinfav'] = $forum['favid'];
  342. }
  343. $leftside['favorites'][$forum['id']] = array($forum['title'], $forum['favid']);
  344. }
  345. }
  346. $_G['leftsidewidth_mwidth'] = $_G['setting']['leftsidewidth'] + 15;
  347. return $leftside;
  348. }
  349. ?>