PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 364 lines | 329 code | 29 blank | 6 comment | 100 complexity | 9b51b5eb119634e69525b4d3c3d49124 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_group.php 29394 2012-04-10 07:26:16Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function delgroupcache($fid, $cachearray) {
  12. C::t('forum_groupfield')->delete_by_type($cachearray, $fid);
  13. }
  14. function groupperm(&$forum, $uid, $action = '', $isgroupuser = '') {
  15. if($forum['status'] != 3 || $forum['type'] != 'sub') {
  16. return -1;
  17. }
  18. if(!empty($forum['founderuid']) && $forum['founderuid'] == $uid) {
  19. return 'isgroupuser';
  20. }
  21. $isgroupuser = empty($isgroupuser) && $isgroupuser !== false ? C::t('forum_groupuser')->fetch_userinfo($uid, $forum['fid']) : $isgroupuser;
  22. if($forum['ismoderator'] && !$isgroupuser) {
  23. return '';
  24. }
  25. if($forum['jointype'] < 0 && !$forum['ismoderator']) {
  26. return 1;
  27. }
  28. if(!$forum['gviewperm'] && !$isgroupuser) {
  29. return 2;
  30. }
  31. if($forum['jointype'] == 2 && !$forum['gviewperm'] && !empty($isgroupuser['uid']) && $isgroupuser['level'] == 0) {
  32. return 3;
  33. }
  34. if($action == 'post' && !$isgroupuser) {
  35. return 4;
  36. }
  37. if(is_array($isgroupuser['level']) && $isgroupuser['level'] === 0) {
  38. return 5;
  39. }
  40. return $isgroupuser ? 'isgroupuser' : '';
  41. }
  42. function grouplist($orderby = 'displayorder', $fieldarray = array(), $num = 1, $fids = array(), $sort = 0, $getcount = 0, $grouplevel = array()) {
  43. $query = C::t('forum_forum')->fetch_all_for_grouplist($orderby, $fieldarray, $num, $fids, $sort, $getcount);
  44. if($getcount) {
  45. return $query;
  46. }
  47. $grouplist = array();
  48. foreach($query as $group) {
  49. $group['iconstatus'] = $group['icon'] ? 1 : 0;
  50. isset($group['icon']) && $group['icon'] = get_groupimg($group['icon'], 'icon');
  51. isset($group['banner']) && $group['banner'] = get_groupimg($group['banner']);
  52. $group['orderid'] = $orderid ? intval($orderid) : '';
  53. isset($group['dateline']) && $group['dateline'] = $group['dateline'] ? dgmdate($group['dateline'], 'd') : '';
  54. isset($group['lastupdate']) && $group['lastupdate'] = $group['lastupdate'] ? dgmdate($group['lastupdate'], 'd') : '';
  55. $group['level'] = !empty($grouplevel) ? intval($grouplevel[$group['fid']]) : 0;
  56. isset($group['description']) && $group['description'] = cutstr($group['description'], 130);
  57. $grouplist[$group['fid']] = $group;
  58. $orderid ++;
  59. }
  60. return $grouplist;
  61. }
  62. function mygrouplist($uid, $orderby = '', $fieldarray = array(), $num = 0, $start = 0, $ismanager = 0, $count = 0) {
  63. $uid = intval($uid);
  64. if(empty($uid)) {
  65. return array();
  66. }
  67. $groupfids = $grouplevel = array();
  68. $query = C::t('forum_groupuser')->fetch_all_group_for_user($uid, $count, $ismanager, $start, $num);
  69. if($count == 1) {
  70. return $query;
  71. }
  72. foreach($query as $group) {
  73. $groupfids[] = $group['fid'];
  74. $grouplevel[$group['fid']] = $group['level'];
  75. }
  76. if(empty($groupfids)) {
  77. return false;
  78. }
  79. $mygrouplist = grouplist($orderby, $fieldarray, $num, $groupfids, 0, 0, $grouplevel);
  80. return $mygrouplist;
  81. }
  82. function get_groupimg($imgname, $imgtype = '') {
  83. global $_G;
  84. $imgpath = $_G['setting']['attachurl'].'group/'.$imgname;
  85. if($imgname) {
  86. return $imgpath;
  87. } else {
  88. if($imgtype == 'icon') {
  89. return 'static/image/common/groupicon.gif';
  90. } else {
  91. return '';
  92. }
  93. }
  94. }
  95. function get_groupselect($fup = 0, $groupid = 0, $ajax = 1) {
  96. global $_G;
  97. loadcache('grouptype');
  98. $firstgroup = $_G['cache']['grouptype']['first'];
  99. $secondgroup = $_G['cache']['grouptype']['second'];
  100. $grouptypeselect = array('first' => '', 'second' => '');
  101. if($ajax) {
  102. $fup = intval($fup);
  103. $groupid = intval($groupid);
  104. foreach($firstgroup as $gid => $group) {
  105. $selected = $fup == $gid ? 'selected="selected"' : '';
  106. $grouptypeselect['first'] .= '<option value="'.$gid.'" '.$selected.'>'.$group['name'].'</option>';
  107. }
  108. if($fup && !empty($firstgroup[$fup]['secondlist'])) {
  109. foreach($firstgroup[$fup]['secondlist'] as $sgid) {
  110. $selected = $sgid == $groupid ? 'selected="selected"' : '';
  111. $grouptypeselect['second'] .= '<option value="'.$sgid.'" '.$selected.'>'.$secondgroup[$sgid]['name'].'</option>';
  112. }
  113. }
  114. } else {
  115. foreach($firstgroup as $gid => $group) {
  116. $gselected = $groupid == $gid ? 'selected="selected"' : '';
  117. $grouptypeselect .= '<option value="'.$gid.'" '.$gselected.'>'.$group['name'].'</option>';
  118. if(is_array($group['secondlist'])) {
  119. foreach($group['secondlist'] as $secondid) {
  120. $selected = $groupid == $secondid ? 'selected="selected"' : '';
  121. $grouptypeselect .= '<option value="'.$secondid.'" '.$selected.'>&nbsp;&nbsp;'.$secondgroup[$secondid]['name'].'</option>';
  122. }
  123. }
  124. $grouptypeselect .= '</optgroup>';
  125. }
  126. }
  127. return $grouptypeselect;
  128. }
  129. function get_groupnav($forum) {
  130. global $_G;
  131. if(empty($forum) || empty($forum['fid']) || empty($forum['name'])) {
  132. return '';
  133. }
  134. loadcache('grouptype');
  135. $groupnav = '';
  136. $groupsecond = $_G['cache']['grouptype']['second'];
  137. if($forum['type'] == 'sub') {
  138. $secondtype = !empty($groupsecond[$forum['fup']]) ? $groupsecond[$forum['fup']] : array();
  139. } else {
  140. $secondtype = !empty($groupsecond[$forum['fid']]) ? $groupsecond[$forum['fid']] : array();
  141. }
  142. $firstid = !empty($secondtype) ? $secondtype['fup'] : (!empty($forum['fup']) ? $forum['fup'] : $forum['fid']);
  143. $firsttype = $_G['cache']['grouptype']['first'][$firstid];
  144. if($firsttype) {
  145. $groupnav = ' <em>&rsaquo;</em> <a href="group.php?gid='.$firsttype['fid'].'">'.$firsttype['name'].'</a>';
  146. }
  147. if($secondtype) {
  148. $groupnav .= ' <em>&rsaquo;</em> <a href="group.php?sgid='.$secondtype['fid'].'">'.$secondtype['name'].'</a>';
  149. }
  150. if($forum['type'] == 'sub') {
  151. $mod_action = $_GET['mod'] == 'forumdisplay' || $_GET['mod'] == 'viewthread' ? 'mod=forumdisplay&action=list' : 'mod=group';
  152. $groupnav .= ($groupnav ? ' <em>&rsaquo;</em> ' : '').'<a href="forum.php?'.$mod_action.'&fid='.$forum['fid'].'">'.$forum['name'].'</a>';
  153. }
  154. return array('nav' => $groupnav, 'first' => $firsttype, 'second' => $secondtype);
  155. }
  156. function get_viewedgroup() {
  157. $groupviewed_list = $list = array();
  158. $groupviewed = getcookie('groupviewed');
  159. $groupviewed = $groupviewed ? explode(',', $groupviewed) : array();
  160. if($groupviewed) {
  161. $query = C::t('forum_forum')->fetch_all_info_by_fids($groupviewed);
  162. foreach($query as $row) {
  163. $icon = get_groupimg($row['icon'], 'icon');
  164. $list[$row['fid']] = array('fid' => $row['fid'], 'name' => $row['name'], 'icon' => $icon, 'membernum' => $row['membernum']);
  165. }
  166. }
  167. foreach($groupviewed as $fid) {
  168. $groupviewed_list[$fid] = $list[$fid];
  169. }
  170. return $groupviewed_list;
  171. }
  172. function getgroupthread($fid, $type, $timestamp = 0, $num = 10) {
  173. $typearray = array('replies', 'views', 'dateline', 'lastpost', 'digest');
  174. $type = in_array($type, $typearray) ? $type : '';
  175. $groupthreadlist = array();
  176. if($type) {
  177. $dateline = $lastpost = $digest = null;
  178. if($timestamp && in_array($type, array('dateline', 'lastpost'))) {
  179. if($type == 'dateline') {
  180. $dateline = TIMESTAMP - $timestamp;
  181. } else {
  182. $lastpost = TIMESTAMP - $timestamp;
  183. }
  184. }
  185. if($type == 'digest') {
  186. $digest = 0;
  187. $type = 'dateline';
  188. }
  189. foreach(C::t('forum_thread')->fetch_all_group_thread_by_fid_displayorder($fid, 0, $dateline, $lastpost, $digest, $type, 0, $num) as $thread) {
  190. $groupthreadlist[$thread['tid']]['tid'] = $thread['tid'];
  191. $groupthreadlist[$thread['tid']]['subject'] = $thread['subject'];
  192. $groupthreadlist[$thread['tid']]['special'] = $thread['special'];
  193. $groupthreadlist[$thread['tid']]['closed'] = $thread['closed'];
  194. $groupthreadlist[$thread['tid']]['dateline'] = dgmdate($thread['dateline'], 'd');
  195. $groupthreadlist[$thread['tid']]['author'] = $thread['author'];
  196. $groupthreadlist[$thread['tid']]['authorid'] = $thread['authorid'];
  197. $groupthreadlist[$thread['tid']]['views'] = $thread['views'];
  198. $groupthreadlist[$thread['tid']]['replies'] = $thread['replies'];
  199. $groupthreadlist[$thread['tid']]['lastpost'] = dgmdate($thread['lastpost'], 'u');
  200. $groupthreadlist[$thread['tid']]['lastposter'] = $thread['lastposter'];
  201. $groupthreadlist[$thread['tid']]['lastposterenc'] = rawurlencode($thread['lastposter']);
  202. }
  203. }
  204. return $groupthreadlist;
  205. }
  206. function getgroupcache($fid, $typearray = array(), $timestamp = 0, $num = 10, $privacy = 0, $force = 0) {
  207. $groupcache = array();
  208. if(!$force) {
  209. $query = C::t('forum_groupfield')->fetch_all_group_cache($fid, $typearray, $privacy);
  210. foreach($query as $group) {
  211. $groupcache[$group['type']] = dunserialize($group['data']);
  212. $groupcache[$group['type']]['dateline'] = $group['dateline'];
  213. }
  214. }
  215. $cachetimearray = array('replies' => 3600, 'views' => 3600, 'dateline' => 900, 'lastpost' => 3600, 'digest' => 86400, 'ranking' => 86400, 'activityuser' => 3600);
  216. $userdataarray = array('activityuser' => 'lastupdate', 'newuserlist' => 'joindateline');
  217. foreach($typearray as $type) {
  218. if(empty($groupcache[$type]) || (!empty($cachetimearray[$type]) && TIMESTAMP - $groupcache[$type]['dateline'] > $cachetimearray[$type])) {
  219. if($type == 'ranking') {
  220. $groupcache[$type]['data'] = getgroupranking($fid, $groupcache[$type]['data']['today']);
  221. } elseif(in_array($type, array('activityuser', 'newuserlist'))) {
  222. $num = $type == 'activityuser' ? 50 : 8;
  223. $groupcache[$type]['data'] = C::t('forum_groupuser')->groupuserlist($fid, $userdataarray[$type], $num, '', "AND level>'0'");
  224. } else {
  225. $groupcache[$type]['data'] = getgroupthread($fid, $type, $timestamp, $num);
  226. }
  227. if(!$force && $fid) {
  228. C::t('forum_groupfield')->insert(array('fid' => $fid, 'dateline' => TIMESTAMP, 'type' => $type, 'data' => serialize($groupcache[$type])), false, true);
  229. }
  230. }
  231. }
  232. return $groupcache;
  233. }
  234. function getgroupranking($fid = '', $nowranking = '') {
  235. $topgroup = $rankingdata = $topyesterday = array();
  236. $ranking = 1;
  237. $query = C::t('forum_forum')->fetch_all_group_for_ranking();
  238. foreach($query as $group) {
  239. $topgroup[$group['fid']] = $ranking++;
  240. }
  241. if($fid && $topgroup) {
  242. $rankingdata['yesterday'] = intval($nowranking);
  243. $rankingdata['today'] = intval($topgroup[$fid]);
  244. $rankingdata['trend'] = $rankingdata['yesterday'] ? grouptrend($rankingdata['yesterday'], $rankingdata['today']) : 0;
  245. $topgroup = $rankingdata;
  246. }
  247. return $topgroup;
  248. }
  249. function grouponline($fid, $getlist = '') {
  250. $fid = intval($fid);
  251. if(empty($getlist)) {
  252. $onlinemember = C::app()->session->count_by_fid($fid);
  253. $onlinemember['count'] = $onlinemember ? intval($onlinemember) : 0;
  254. } else {
  255. $onlinemember = array('count' => 0, 'list' => array());
  256. $onlinemember['list'] = C::app()->session->fetch_all_by_fid($_G['fid']);
  257. $onlinemember['count'] = count($onlinemember['list']);
  258. }
  259. return $onlinemember;
  260. }
  261. function grouptrend($yesterday, $today) {
  262. $trend = $yesterday - $today;
  263. return $trend;
  264. }
  265. function write_groupviewed($fid) {
  266. $fid = intval($fid);
  267. if($fid) {
  268. $groupviewed_limit = 8;
  269. $groupviewed = getcookie('groupviewed');
  270. if(!strexists(",$groupviewed,", ",$fid,")) {
  271. $groupviewed = $groupviewed ? explode(',', $groupviewed) : array();
  272. $groupviewed[] = $fid;
  273. if(count($groupviewed) > $groupviewed_limit) {
  274. array_shift($groupviewed);
  275. }
  276. dsetcookie('groupviewed', implode(',', $groupviewed), 86400);
  277. }
  278. }
  279. }
  280. function update_groupmoderators($fid) {
  281. if(empty($fid)) return false;
  282. $moderators = C::t('forum_groupuser')->groupuserlist($fid, 'level_join', 0, 0, array('level' => array('1', '2')), array('username', 'level'));
  283. if(!empty($moderators)) {
  284. C::t('forum_forumfield')->update($fid, array('moderators' => serialize($moderators)));
  285. return $moderators;
  286. } else {
  287. return array();
  288. }
  289. }
  290. function update_usergroups($uids) {
  291. global $_G;
  292. if(empty($uids)) return '';
  293. if(!is_array($uids)) $uids = array($uids);
  294. foreach($uids as $uid) {
  295. $groups = $grouptype = $usergroups = array();
  296. $fids = C::t('forum_groupuser')->fetch_all_fid_by_uids($uid);
  297. $query = C::t('forum_forum')->fetch_all_info_by_fids($fids);
  298. foreach($query as $group) {
  299. $groups[$group['fid']] = $group['name'];
  300. $typegroup[$group['fup']][] = $group['fid'];
  301. }
  302. if(!empty($typegroup)) {
  303. $fups = array_keys($typegroup);
  304. $query = C::t('forum_forum')->fetch_all_info_by_fids($fups);
  305. foreach($query as $fup) {
  306. $grouptype[$fup['fid']] = array('fid' => $fup['fid'], 'fup' => $fup['fup'], 'name' => $fup['name']);
  307. $grouptype[$fup['fid']]['groups'] = implode(',', $typegroup[$fup['fid']]);
  308. }
  309. $usergroups = array('groups' => $groups, 'grouptype' => $grouptype);
  310. if(!empty($usergroups)) {
  311. $setarr = array();
  312. $member = C::t('common_member_field_forum')->fetch($uid);
  313. $attentiongroups = $member['attentiongroup'];
  314. if($attentiongroups) {
  315. $attentiongroups = explode(',', $attentiongroups);
  316. $updateattention = 0;
  317. foreach($attentiongroups as $key => $val) {
  318. if(empty($usergroups['groups'][$val])) {
  319. unset($attentiongroups[$key]);
  320. $updateattention = 1;
  321. }
  322. }
  323. if($updateattention) {
  324. $setarr['attentiongroup'] = implode(',', $attentiongroups);
  325. C::t('common_member_field_forum')->update($uid, $setarr);
  326. }
  327. $_G['member']['attentiongroup'] = implode(',', $attentiongroups);
  328. }
  329. }
  330. } else {
  331. }
  332. }
  333. return $usergroups;
  334. }
  335. ?>