Esempio n. 1
0
 function getThreads($tIds, $isReturnPostId = true)
 {
     global $_G;
     $tables = array();
     $infos = unserialize($_G['setting']['threadtable_info']);
     if ($infos) {
         foreach ($infos as $id => $row) {
             $suffix = $id ? "_{$id}" : '';
             $tables[] = 'forum_thread' . $suffix;
         }
     } else {
         $tables = array('forum_thread');
     }
     $tableNum = count($tables);
     $res = $data = $_tableInfo = array();
     for ($i = 0; $i < $tableNum; $i++) {
         $_threads = SearchHelper::preGetThreads(DB::table($tables[$i]), $tIds);
         if ($_threads) {
             if (!$data) {
                 $data = $_threads;
             } else {
                 $data = $data + $_threads;
             }
             if (count($data) == count($tIds)) {
                 break;
             }
         }
     }
     if ($isReturnPostId) {
         $threadIds = array();
         foreach ($data as $tId => $thread) {
             $postTableId = $thread['postTableId'];
             $threadIds[$postTableId][] = $tId;
         }
         $threadPosts = SearchHelper::getThreadPosts($threadIds);
         foreach ($data as $tId => $thread) {
             $data[$tId]['pId'] = $threadPosts[$tId]['pId'];
         }
     }
     return $data;
 }
Esempio n. 2
0
 function onSearchGetAllThreads($num, $tId = 0, $orderType = 'ASC')
 {
     $orderType = strtoupper($orderType);
     $tables = array();
     global $_G;
     $infos = unserialize($_G['setting']['threadtable_info']);
     if ($infos) {
         foreach ($infos as $id => $row) {
             $suffix = $id ? "_{$id}" : '';
             $tables[] = 'forum_thread' . $suffix;
         }
     } else {
         $tables = array('forum_thread');
     }
     $tableNum = count($tables);
     $res = $data = $_tableInfo = array();
     $minTid = $maxTid = 0;
     for ($i = 0; $i < $tableNum; $i++) {
         $_threads = $this->_getAllThreads(DB::table($tables[$i]), $num, $tId, $orderType);
         if ($_threads['data']) {
             if (!$data) {
                 $data = $_threads['data'];
             } else {
                 $data = $data + $_threads['data'];
             }
             if ($orderType == 'DESC') {
                 if (!$minTid) {
                     $minTid = $_threads['minTid'];
                 }
                 if ($minTid > $_threads['minTid']) {
                     $minTid = $_threads['minTid'];
                 }
                 $_tableInfo['minTids'][] = array('current_index' => $i, 'minTid' => $_threads['minTid']);
             } else {
                 if ($maxTid < $_threads['maxTid']) {
                     $maxTid = $_threads['maxTid'];
                 }
                 $_tableInfo['maxTids'][] = array('current_index' => $i, 'maxTid' => $_threads['maxTid']);
             }
         }
     }
     $_threadNum = 0;
     if ($orderType == 'DESC') {
         for ($j = $tId - 1; $j >= $minTid; $j--) {
             if ($j == 0) {
                 break;
             }
             if (array_key_exists($j, $data)) {
                 $_threadNum++;
                 $res['minTid'] = $j;
                 $res['data'][$j] = $data[$j];
                 if ($_threadNum == $num) {
                     break;
                 }
             }
         }
     } else {
         for ($j = $tId + 1; $j <= $maxTid; $j++) {
             if (array_key_exists($j, $data)) {
                 $_threadNum++;
                 $res['data'][$j] = $data[$j];
                 $res['maxTid'] = $j;
                 if ($_threadNum == $num) {
                     break;
                 }
             }
         }
     }
     if ($res['data']) {
         $_tableInfo['tables'] = $tables;
         $res['table'] = $_tableInfo;
         $_tIds = array();
         $authors = array();
         foreach ($res['data'] as $tId => $thread) {
             $_tIds[$thread['postTableId']][] = $tId;
             $authors[$thread['authorId']][] = $thread['tId'];
         }
         if ($_tIds) {
             $threadPosts = SearchHelper::getThreadPosts($_tIds);
             foreach ($res['data'] as $tId => $v) {
                 $res['data'][$tId]['pId'] = $threadPosts[$tId]['pId'];
             }
         }
         $authorids = array_keys($authors);
         if ($authorids) {
             $banuids = $uids = array();
             $sql = sprintf('SELECT uid, username, groupid FROM %s WHERE uid IN (%s)', DB::table('common_member'), implode($authorids, ', '));
             $query = DB::query($sql);
             while ($author = DB::fetch($query)) {
                 $uids[$author['uid']] = $author['uid'];
                 if ($author['groupid'] == 4 || $author['groupid'] == 5) {
                     $banuids[] = $author['uid'];
                 }
             }
             $deluids = array_diff($authorids, $uids);
             foreach ($deluids as $deluid) {
                 if (!$deluid) {
                     continue;
                 }
                 foreach ($authors[$deluid] as $tid) {
                     $res['data'][$tid]['authorStatus'] = 'delete';
                 }
             }
             foreach ($banuids as $banuid) {
                 foreach ($authors[$banuid] as $tid) {
                     $res['data'][$tid]['authorStatus'] = 'ban';
                 }
             }
         }
     }
     return $res;
 }
Esempio n. 3
0
 function onSearchGetAllThreads($num, $tId = 0, $orderType = 'ASC')
 {
     $orderType = strtoupper($orderType);
     $tables = SearchHelper::getTables('thread');
     $tableNum = count($tables);
     $res = $data = $_tableInfo = array();
     $minTid = $maxTid = 0;
     for ($i = 0; $i < $tableNum; $i++) {
         $_threads = $this->_getAllThreads(DB::table($tables[$i]), $num, $tId, $orderType);
         if ($_threads['data']) {
             if (!$data) {
                 $data = $_threads['data'];
             } else {
                 $data = $data + $_threads['data'];
             }
         }
         if ($orderType == 'DESC') {
             if (!$minTid) {
                 $minTid = $_threads['minTid'];
             }
             if ($minTid > $_threads['minTid']) {
                 $minTid = $_threads['minTid'];
             }
             $_tableInfo['minTids'][] = array('current_index' => $i, 'minTid' => $_threads['minTid']);
         } else {
             if ($maxTid < $_threads['maxTid']) {
                 $maxTid = $_threads['maxTid'];
             }
             $_tableInfo['maxTids'][] = array('current_index' => $i, 'maxTid' => $_threads['maxTid']);
         }
     }
     $_threadNum = 0;
     if ($orderType == 'DESC') {
         if ($minTid) {
             for ($j = $tId - 1; $j >= $minTid; $j--) {
                 if ($j == 0) {
                     break;
                 }
                 if (array_key_exists($j, $data)) {
                     $_threadNum++;
                     $res['minTid'] = $j;
                     $res['data'][$j] = $data[$j];
                     if ($_threadNum == $num) {
                         break;
                     }
                 }
             }
             if (!$res['minTid']) {
                 $res['minTid'] = $minTid;
             }
         }
     } else {
         if ($maxTid) {
             for ($j = $tId + 1; $j <= $maxTid; $j++) {
                 if (array_key_exists($j, $data)) {
                     $_threadNum++;
                     $res['data'][$j] = $data[$j];
                     $res['maxTid'] = $j;
                     if ($_threadNum == $num) {
                         break;
                     }
                 }
             }
             if (!$res['maxTid']) {
                 $res['maxTid'] = $maxTid;
             }
         }
     }
     if ($res['data']) {
         $_tableInfo['tables'] = $tables;
         $_tIds = array();
         $authors = $gfIds = array();
         foreach ($res['data'] as $tId => $thread) {
             $_tIds[$thread['postTableId']][] = $tId;
             $authors[$thread['authorId']][] = $thread['tId'];
             if ($thread['isGroup']) {
                 $gfIds[$thread['fId']] = $thread['fId'];
             }
         }
         if ($_tIds) {
             $guestPerm = SearchHelper::getGuestPerm($gfIds);
             // GuestPerm
             $threadPosts = SearchHelper::getThreadPosts($_tIds);
             foreach ($res['data'] as $tId => $v) {
                 $res['data'][$tId]['pId'] = $threadPosts[$tId]['pId'];
                 if (in_array($v['fId'], $guestPerm['allowForumIds'])) {
                     $res['data'][$tId]['isPublic'] = true;
                 } else {
                     $res['data'][$tId]['isPublic'] = false;
                 }
             }
         }
         $authorids = array_keys($authors);
         if ($authorids) {
             $banuids = $uids = array();
             $sql = sprintf('SELECT uid, username, groupid FROM %s WHERE uid IN (%s)', DB::table('common_member'), implode($authorids, ', '));
             $query = DB::query($sql);
             while ($author = DB::fetch($query)) {
                 $uids[$author['uid']] = $author['uid'];
                 if ($author['groupid'] == 4 || $author['groupid'] == 5) {
                     $banuids[] = $author['uid'];
                 }
             }
             $deluids = array_diff($authorids, $uids);
             foreach ($deluids as $deluid) {
                 if (!$deluid) {
                     continue;
                 }
                 foreach ($authors[$deluid] as $tid) {
                     $res['data'][$tid]['authorStatus'] = 'delete';
                 }
             }
             foreach ($banuids as $banuid) {
                 foreach ($authors[$banuid] as $tid) {
                     $res['data'][$tid]['authorStatus'] = 'ban';
                 }
             }
         }
     }
     return $res;
 }