public function process() { $intRange = @intval($_GET['range']); if (empty($intRange) || $intRange < 1 || self::MAX_RANGE < $intRange) { $intRange = 3; } $db = Reetsee_Db::initDb('reetsee_news', '127.0.0.1', 3306, 'root', '123abc', 'utf8'); if (NULL === $db) { echo "get db error\n"; return -1; } //+--------------+------------------+------+-----+----------+----------------+ //| Field | Type | Null | Key | Default | Extra | //+--------------+------------------+------+-----+----------+----------------+ //| id | int(11) unsigned | NO | PRI | NULL | auto_increment | //| title | varchar(128) | NO | | | | //| source_names | varchar(1024) | NO | | NULL | | //| day_time | int(11) unsigned | NO | MUL | 19700101 | | //| preview_pic | varchar(1024) | NO | | | | //| abstract_ids | varchar(1024) | NO | | | | //+--------------+------------------+------+-----+----------+----------------+ $HTML_DIR = implode(DIRECTORY_SEPARATOR, array(MODULE_PATH, 'html')); $intEarliestTs = strtotime("-{$intRange} days"); $strEarliestDay = date("Ymd", $intEarliestTs); $arrSql = array('table' => 'news_category', 'fields' => array('id', ' title', 'source_names', 'day_time', 'preview_pic', 'abstract_ids'), 'conds' => array('day_time>=' => $strEarliestDay), 'appends' => " ORDER BY `day_time` DESC"); $res = $db->select($arrSql['table'], $arrSql['fields'], $arrSql['conds'], $arrSql['appends']); if (false === $res) { Reetsee_Log::error('Select abstract error:' . $db->error . ' ' . $db->errno); include implode(DIRECTORY_SEPARATOR, array($HTML_DIR, 'reetsee_news_404.html')); return -1; } $data = array(); foreach ($res as $entry) { $entry['arr_uni_sources'] = array_unique(explode(',', $entry['source_names'])); $data[$entry['day_time']][] = $entry; } foreach ($data as $day_time => &$news_entries) { usort($news_entries, function ($a, $b) { $bolRtsInA = in_array('reetsee', $a['arr_uni_sources']); $bolRtsInB = in_array('reetsee', $b['arr_uni_sources']); if ($bolRtsInA && !$bolRtsInB) { return false; } else { if (!$bolRtsInA && $bolRtsInB) { return true; } } return count($a['arr_uni_sources']) < count($b['arr_uni_sources']); }); } unset($news_entries); include implode(DIRECTORY_SEPARATOR, array($HTML_DIR, 'index.html')); return 0; }
public function process() { $intCategory = intval($_GET['category']); $db = Reetsee_Db::initDb('reetsee_news', '127.0.0.1', 3306, 'root', '123abc', 'utf8'); if (NULL === $db) { Reetsee_Log::error('get db error'); return -1; } //+--------------+------------------+------+-----+----------+----------------+ //| Field | Type | Null | Key | Default | Extra | //+--------------+------------------+------+-----+----------+----------------+ //| id | int(11) unsigned | NO | PRI | NULL | auto_increment | //| title | varchar(128) | NO | | | | //| source_names | varchar(1024) | NO | | NULL | | //| day_time | int(11) unsigned | NO | MUL | 19700101 | | //| preview_pic | varchar(1024) | NO | | | | //| abstract_ids | varchar(1024) | NO | | | | //+--------------+------------------+------+-----+----------+----------------+ //$HTML_DIR = implode(DIRECTORY_SEPARATOR, array(MODULE_PATH, 'html')); $arrSql = array('table' => 'news_category', 'fields' => array('id', 'title', 'source_names', 'day_time', 'preview_pic', 'abstract_ids'), 'conds' => array('id=' => $intCategory)); $res = $db->select($arrSql['table'], $arrSql['fields'], $arrSql['conds']); if (false === $res) { Reetsee_Log::error('Select abstract error:' . $db->error . ' ' . $db->errno); $this->display(array(), $strErrDst); //include implode(DIRECTORY_SEPARATOR, array($HTML_DIR, 'reetsee_news_404.html')); return -1; } $arrCategory = $res[0]; //$arrCategory['arr_uni_sources'] = array_unique(explode(',', $entry['source_names'])); $arrNews = array(); if (!empty($arrCategory)) { //$arrAbstractIds = explode(',', $res[0]['abstract_ids']); $strAbstractIds = $arrCategory['abstract_ids']; //+---------------------+------------------+------+-----+-----------------------------+----------------+ //| Field | Type | Null | Key | Default | Extra | //+---------------------+------------------+------+-----+-----------------------------+----------------+ //| id | int(11) unsigned | NO | PRI | NULL | auto_increment | //| title | varchar(128) | NO | | | | //| source_name | varchar(32) | NO | | | | //| content | text | NO | | NULL | | //| source_news_link | varchar(1024) | NO | | http://blog.reetsee.com/404 | | //| source_comment_link | varchar(1024) | NO | | http://blog.reetsee.com/404 | | //| source_news_id | varchar(64) | NO | UNI | NULL | | //| source_comment_id | varchar(64) | NO | | | | //| abstract_id | int(11) unsigned | NO | UNI | 0 | | //| timestamp | int(11) unsigned | NO | | 0 | | //| ext | varchar(2048) | YES | | | | //+---------------------+------------------+------+-----+-----------------------------+----------------+ $arrSql = array('table' => 'news_content', 'fields' => array('id', 'title', 'source_name', 'content', 'source_news_link', 'source_comment_link', 'source_news_id', 'source_comment_id', 'abstract_id', 'timestamp', 'ext'), 'appends' => " WHERE `abstract_id` IN ({$strAbstractIds})"); $res = $db->select($arrSql['table'], $arrSql['fields'], NULL, $arrSql['appends']); if (false === $res) { Reetsee_Log::error('Select abstract error:' . $db->error . ' ' . $db->errno); $this->display(array(), $strErrDst); //include implode(DIRECTORY_SEPARATOR, array($HTML_DIR, 'reetsee_news_404.html')); return -1; } foreach ($res as &$row) { $row['ext'] = unserialize($row['ext']); } unset($row); $arrNews = $res; } unset($res); //TODO 获取实时评论 //$arrComments = $this->getComments($arrNews); $arrTpl = array('category' => $arrCategory, 'news' => $arrNews); $this->display($arrTpl, $this->strTplDst); return 0; }