/** * 获取微语列表 * * @param int $page * @param int $spot 0:前台 1:后台 * @return array */ function getTwitters($page = 1, $spot = 0) { $perpage_num = $spot == 1 ? Option::get('admin_perpage_num') : Option::get('index_twnum'); $start_limit = !empty($page) ? ($page - 1) * $perpage_num : 0; $author = ROLE == ROLE_ADMIN || ROLE == ROLE_VISITOR || $spot == 0 ? '' : 'and author=' . UID; $limit = "LIMIT {$start_limit}, " . $perpage_num; $sql = "SELECT * FROM " . DB_PREFIX . "twitter WHERE 1=1 {$author} ORDER BY id DESC {$limit}"; $res = $this->db->query($sql); $tws = array(); while ($row = $this->db->fetch_array($res)) { $row['id'] = $row['id']; $row['t'] = emoFormat($row['content']); $row['date'] = smartDate($row['date']); $row['replynum'] = $row['replynum']; $tws[] = $row; } return $tws; }
/** * 最新微语 */ private function mc_newtw() { $row = $this->db->fetch_array($this->db->query("SELECT option_value FROM " . DB_PREFIX . "options where option_name='index_newtwnum'")); $index_newtwnum = $row['option_value']; $sql = "SELECT * FROM " . DB_PREFIX . "twitter ORDER BY id DESC LIMIT 0, {$index_newtwnum}"; $res = $this->db->query($sql); $tws = array(); while ($row = $this->db->fetch_array($res)) { $row['id'] = $row['id']; $row['t'] = emoFormat($row['content']); $row['date'] = $row['date']; $row['replynum'] = $row['replynum']; $tws[] = $row; } $cacheData = serialize($tws); $this->cacheWrite($cacheData, 'newtw'); }