Exemplo n.º 1
0
 function process()
 {
     global $_G;
     //1. try to get user mask
     $authority = array();
     if ($_G['uid'] && !empty($_G['member']['accessmasks'])) {
         loadcache('plugin');
         $bucketNum = 100003;
         $expire = 5;
         $userBucket = $_G['uid'] % $bucketNum;
         loadcache('bigapp_authority_' . $userBucket);
         if (!isset($_G['cache']['bigapp_authority_' . $userBucket]) || TIMESTAMP - $_G['cache']['bigapp_authority_' . $userBucket]['expiration'] > $expire) {
             $sql = 'SELECT uid, fid, allowview FROM ' . DB::table('forum_access') . ' WHERE uid % ' . $bucketNum . ' = ' . $userBucket;
             $query = DB::query($sql);
             $authorities = array();
             while ($tmp = DB::fetch($query)) {
                 $authorities[$tmp['uid']][$tmp['fid']] = $tmp['allowview'];
             }
             savecache('bigapp_authority_' . $userBucket, array('variable' => $authorities, 'expiration' => TIMESTAMP));
         } else {
             $authorities = $_G['cache']['bigapp_authority_' . $userBucket]['variable'];
         }
         if (isset($authorities[$_G['uid']])) {
             $authority = $authorities[$_G['uid']];
         }
     }
     //2. try to get all forums
     $forums = array();
     loadcache('bigapp_forumnav');
     $expire = 5;
     if (!isset($_G['cache']['bigapp_forumnav']) || empty($_G['cache']['bigapp_forumnav']) || TIMESTAMP - $_G['cache']['bigapp_forumnav']['expiration'] > $expire) {
         //need update all forums from database
         $sql = "SELECT f.fid, f.type, f.name, f.fup, f.status, f.threads, f.posts, f.todayposts, " . "ff.password, ff.redirect, ff.viewperm, ff.postperm, ff.threadtypes, ff.threadsorts, ff.icon, ff.description, ff.moderators FROM " . DB::table('forum_forum') . " f LEFT JOIN " . DB::table('forum_forumfield') . " ff USING(fid) WHERE f.status='1' ORDER BY f.type, f.displayorder";
         $query = DB::query($sql);
         while ($forum = DB::fetch($query)) {
             if ($forum['redirect'] || $forum['password']) {
                 continue;
             }
             if (!$forum['viewperm'] || $forum['viewperm'] && forumperm($forum['viewperm'])) {
                 if ($forum['threadsorts']) {
                     $forum['threadsorts'] = bigapp_core::getvalues(unserialize($forum['threadsorts']), array('required', 'types'));
                 }
                 if ($forum['threadtypes']) {
                     $forum['threadtypes'] = unserialize($forum['threadtypes']);
                     $unsetthreadtype = false;
                     if ($_G['adminid'] == 3 && strpos($forum['moderators'], $_G['username']) === false) {
                         $unsetthreadtype = true;
                     }
                     if ($_G['adminid'] == 0) {
                         $unsetthreadtype = true;
                     }
                     if ($unsetthreadtype) {
                         foreach ($forum['threadtypes']['moderators'] as $k => $v) {
                             if (!empty($v)) {
                                 unset($forum['threadtypes']['types'][$k]);
                             }
                         }
                     }
                     $flag = 0;
                     foreach ($forum['threadtypes']['types'] as $k => $v) {
                         if ($k == 0) {
                             $flag = 1;
                             break;
                         }
                     }
                     if ($flag == 1) {
                         krsort($forum['threadtypes']['types']);
                     }
                     $forum['threadtypes'] = bigapp_core::getvalues($forum['threadtypes'], array('required', 'types'));
                 }
                 $moderators = explode("\t", $forum['moderators']);
                 if (!is_array($moderators) || 0 === count($moderators)) {
                     $forum['moderators'] = array();
                 } else {
                     foreach ($moderators as &$_v) {
                         $_v = "'{$_v}'";
                     }
                     unset($_v);
                     $sql = 'SELECT username, uid FROM ' . DB::table('common_member') . ' WHERE username IN (' . implode(', ', $moderators) . ')';
                     $subQuery = DB::query($sql);
                     $forum['moderators'] = array();
                     while ($moderator = DB::fetch($subQuery)) {
                         $forum['moderators'][] = array('uid' => $moderator['uid'], 'username' => $moderator['username']);
                     }
                 }
                 $forums[] = bigapp_core::getvalues($forum, array('fid', 'type', 'name', 'fup', 'viewperm', 'postperm', 'status', 'threadsorts', 'threadtypes', 'icon', 'description', 'threads', 'posts', 'todayposts', 'moderators'));
             }
         }
         //add result to syscache
         savecache('bigapp_forumnav', array('variable' => $forums, 'expiration' => TIMESTAMP));
     } else {
         $forums = $_G['cache']['bigapp_forumnav']['variable'];
     }
     //3. judge which forum should be displayed
     $retData = array();
     if (!empty($authority)) {
         foreach ($forums as $forum) {
             if (isset($authority[$forum['fid']]) && -1 == $authority[$forum['fid']]) {
                 continue;
             }
             $retData[] = $forum;
         }
     } else {
         $retData = $forums;
     }
     foreach ($retData as &$value) {
         BigAppAPI::_textDescription($value);
     }
     unset($value);
     $variable['forums'] = array_values(BigAppAPI::_sortResult($retData));
     $variable['forum_list'] = array();
     BigAppAPI::_doSearch($variable, 'forums', $variable['forum_list']);
     unset($variable['forums']);
     bigapp_core::result(bigapp_core::variable($variable));
 }
Exemplo n.º 2
0
 function process()
 {
     global $_G;
     //1. try to get user mask
     $authority = array();
     if ($_G['uid'] && !empty($_G['member']['accessmasks'])) {
         loadcache('plugin');
         $bucketNum = 100003;
         $expire = 5;
         $userBucket = $_G['uid'] % $bucketNum;
         loadcache('bigapp_authority_' . $userBucket);
         if (!isset($_G['cache']['bigapp_authority_' . $userBucket]) || TIMESTAMP - $_G['cache']['bigapp_authority_' . $userBucket]['expiration'] > $expire) {
             $sql = 'SELECT uid, fid, allowview FROM ' . DB::table('forum_access') . ' WHERE uid % ' . $bucketNum . ' = ' . $userBucket;
             $query = DB::query($sql);
             $authorities = array();
             while ($tmp = DB::fetch($query)) {
                 $authorities[$tmp['uid']][$tmp['fid']] = $tmp['allowview'];
             }
             savecache('bigapp_authority_' . $userBucket, array('variable' => $authorities, 'expiration' => TIMESTAMP));
         } else {
             $authorities = $_G['cache']['bigapp_authority_' . $userBucket]['variable'];
         }
         if (isset($authorities[$_G['uid']])) {
             $authority = $authorities[$_G['uid']];
         }
     }
     //2. try to get all forums
     $forums = array();
     $cacheKey = 'bigapp_forumnav';
     if (isset($_G['adminid'])) {
         $cacheKey = 'bigapp_forumnav_' . $_G['adminid'];
     }
     loadcache($cacheKey);
     $expire = 5;
     if (!isset($_G['cache'][$cacheKey]) || empty($_G['cache'][$cacheKey]) || TIMESTAMP - $_G['cache'][$cacheKey]['expiration'] > $expire) {
         //need update all forums from database
         $sql = "SELECT f.fid, f.type, f.name, f.fup, f.status, f.threads, f.posts, f.todayposts, f.allowpostspecial, f.allowspecialonly, " . "ff.password, ff.redirect, ff.viewperm, ff.postperm, ff.threadtypes, ff.threadsorts, ff.icon, ff.description, ff.moderators FROM " . DB::table('forum_forum') . " f LEFT JOIN " . DB::table('forum_forumfield') . " ff USING(fid) WHERE f.status='1' ORDER BY f.type, f.displayorder";
         $query = DB::query($sql);
         while ($forum = DB::fetch($query)) {
             if ($forum['redirect'] || $forum['password']) {
                 continue;
             }
             if (!$forum['viewperm'] || $forum['viewperm'] && forumperm($forum['viewperm'])) {
                 if ($forum['threadsorts']) {
                     $forum['threadsorts'] = bigapp_core::getvalues(unserialize($forum['threadsorts']), array('required', 'types'));
                 }
                 if ($forum['threadtypes']) {
                     $forum['threadtypes'] = unserialize($forum['threadtypes']);
                     $unsetthreadtype = false;
                     if ($_G['adminid'] == 3 && strpos($forum['moderators'], $_G['username']) === false) {
                         $unsetthreadtype = true;
                     }
                     if ($_G['adminid'] == 0) {
                         $unsetthreadtype = true;
                     }
                     if ($unsetthreadtype) {
                         foreach ($forum['threadtypes']['moderators'] as $k => $v) {
                             if (!empty($v)) {
                                 unset($forum['threadtypes']['types'][$k]);
                             }
                         }
                     }
                     $flag = 0;
                     foreach ($forum['threadtypes']['types'] as $k => $v) {
                         if ($k == 0) {
                             $flag = 1;
                             break;
                         }
                     }
                     if ($flag == 1) {
                         krsort($forum['threadtypes']['types']);
                     }
                     $forum['threadtypes'] = bigapp_core::getvalues($forum['threadtypes'], array('required', 'types'));
                 }
                 loadforum($forum['fid'], null);
                 if (!empty($_G['forum']['threadtypes']) || !empty($_GET['debug'])) {
                     $forum['threadtypes_detail'] = $_G['forum']['threadtypes'];
                     unset($forum['threadtypes_detail']['types']);
                     foreach ($_G['forum']['threadtypes']['types'] as $typeId => $typeValue) {
                         $typeValue = preg_replace('/<.*?>/', '', $typeValue);
                         if (isset($_G['forum']['threadtypes']['moderators'][$typeId]) && !empty($_G['forum']['threadtypes']['moderators'][$typeId])) {
                             if (isset($_G['adminid']) && $_G['adminid'] != $_G['forum']['threadtypes']['moderators'][$typeId]) {
                                 continue;
                             }
                         }
                         $forum['threadtypes_detail']['types'][] = array('typeid' => $typeId, 'typename' => $typeValue);
                     }
                     unset($forum['threadtypes_detail']['icons']);
                     foreach ($_G['forum']['threadtypes']['icons'] as $typeId => $icon) {
                         $forum['threadtypes_detail']['icons'][] = array('typeid' => $typeId, 'typeicon' => $icon);
                     }
                 }
                 $moderators = explode("\t", $forum['moderators']);
                 if (!is_array($moderators) || 0 === count($moderators)) {
                     $forum['moderators'] = array();
                 } else {
                     foreach ($moderators as &$_v) {
                         $_v = "'{$_v}'";
                     }
                     unset($_v);
                     $sql = 'SELECT username, uid FROM ' . DB::table('common_member') . ' WHERE username IN (' . implode(', ', $moderators) . ')';
                     $subQuery = DB::query($sql);
                     $forum['moderators'] = array();
                     while ($moderator = DB::fetch($subQuery)) {
                         $forum['moderators'][] = array('uid' => $moderator['uid'], 'username' => $moderator['username']);
                     }
                 }
                 $forums[] = bigapp_core::getvalues($forum, array('fid', 'type', 'name', 'fup', 'viewperm', 'postperm', 'status', 'threadsorts', 'threadtypes', 'threadtypes_detail', 'icon', 'description', 'threads', 'allowpostspecial', 'allowspecialonly', 'posts', 'todayposts', 'moderators'));
             }
         }
         //add result to syscache
         savecache($cacheKey, array('variable' => $forums, 'expiration' => TIMESTAMP));
     } else {
         $forums = $_G['cache'][$cacheKey]['variable'];
     }
     //3. judge which forum should be displayed
     $retData = array();
     if (!empty($authority)) {
         foreach ($forums as $forum) {
             if (isset($authority[$forum['fid']]) && -1 == $authority[$forum['fid']]) {
                 continue;
             }
             $retData[] = $forum;
         }
     } else {
         $retData = $forums;
     }
     //4. AppDegin 论坛视图设置过滤
     $res = C::t('common_setting')->fetch("bigapp_view_2", true);
     if (isset($res['displayid']) && isset($res['forbiddenid'])) {
         //获取论坛视图配置
         $displayArr = array();
         $forbiddenArr = array();
         if (!empty($res['displayid'])) {
             $displayArr = explode(',', $res['displayid']);
         }
         if (!empty($res['forbiddenid'])) {
             $forbiddenArr = explode(',', $res['forbiddenid']);
         }
         $retData = BigAppAPI::_filterResult($retData, $displayArr, $forbiddenArr);
     }
     $activityForum = array();
     foreach ($retData as $forum) {
         if (isset($_G['group']['allowpostactivity']) && $_G['group']['allowpostactivity'] && $forum['allowpostspecial'] & 8) {
             $activityForum[] = $forum;
         }
     }
     foreach ($retData as &$value) {
         BigAppAPI::_textDescription($value);
     }
     unset($value);
     $variable['forums'] = array_values(BigAppAPI::_sortResult($retData));
     $variable['activity_forums'] = $activityForum;
     if (isset($_G['setting']['bigapp_settings'])) {
         $_G['setting']['bigapp_settings'] = unserialize($_G['setting']['bigapp_settings']);
     }
     $res = C::t('common_setting')->fetch("bigapp_view_2", true);
     if (isset($res[0]) && empty($res[0])) {
         //没有获取论坛视图配置
         $variable['display_style'] = strval(isset($_G['setting']['bigapp_settings']['display_style']) ? $_G['setting']['bigapp_settings']['display_style'] : 0);
     } else {
         $variable['display_style'] = isset($res["type"]) ? strval(intval($res["type"]) - 1) : '0';
     }
     bigapp_core::result(bigapp_core::variable($variable));
 }