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 handlePage($page) { //print_r($page->getHyperLinks()); $arrExtraInfo = $page->getExtraInfo(array('job_name')); $strJobName = $arrExtraInfo['job_name']; switch ($strJobName) { case 'tencent': $arrData = $this->parseTencentNews($page); break; case 'netease': $arrData = $this->parseNeteaseNews($page); break; case 'sina': $arrData = $this->parseSinaNews($page); break; } if (!$this->checkData($arrData)) { return TRUE; } $db = Reetsee_Db::initDb('reetsee_news', '127.0.0.1', 3306, 'root', '123abc', 'utf8'); if (NULL === $db) { echo "get db error\n"; } $arrSql = array('table' => 'news_abstract', 'fields' => $arrData['news_abstract'], 'dup' => array('timestamp' => intval(time()))); $res = $db->insert($arrSql['table'], $arrSql['fields']); if (!$res) { echo 'Insert content error:' . $db->error . ' ' . $db->errno . "\n"; return FALSE; } $intLastAbsId = $db->insert_id; $arrData['news_content']['abstract_id'] = $intLastAbsId; $arrSql = array('table' => 'news_content', 'fields' => $arrData['news_content'], 'dup' => array('timestamp' => intval(time()))); $res = $db->insert($arrSql['table'], $arrSql['fields']); if (!$res) { echo 'Insert content error:' . $db->error . ' ' . $db->errno . "\n"; return FALSE; } $intLastCtId = $db->insert_id; $arrSql = array('table' => 'news_abstract', 'fields' => array('content_id' => $intLastCtId), 'conds' => array('id=' => $intLastAbsId)); $res = $db->update($arrSql['table'], $arrSql['fields'], $arrSql['conds']); if (!$res) { echo 'Update abstract error:' . $db->error . ' ' . $db->errno . "\n"; return FALSE; } return TRUE; }
function main() { $db = Reetsee_Db::initDb('reetsee_news', '127.0.0.1', 3306, 'root', '123abc', 'utf8'); if (NULL === $db) { echo "get db error\n"; return -1; } //插入文章摘要 $arrSql = array('table' => 'news_abstract', 'fields' => array('title' => '我国今日喜迎杨莹生日!', 'icon_pic' => '', 'rate_points' => 10, 'rate_counts' => 0, 'quality' => 100, 'content_id' => 0, 'source_news_id' => 1314520, 'day_time' => 20150421, 'timestamp' => 1429545601)); $res = $db->insert($arrSql['table'], $arrSql['fields']); if (!$res) { echo "Insert content error:" . $db->error . ' ' . $db->errno . "\n"; return -2; } $intLastAbsId = $db->insert_id; //构造分类 $arrSql = array('table' => 'news_category', 'fields' => array('title' => '我国今日喜迎杨莹生日!', 'source_names' => 'reetsee', 'day_time' => 20150421, 'preview_pic' => '', 'abstract_ids' => strval($intLastAbsId))); $res = $db->insert($arrSql['table'], $arrSql['fields']); if (!$res) { echo 'Insert category error:' . $db->error . ' ' . $db->errno . "\n"; return -5; } $intLastCatId = $db->insert_id; //插入文章详细内容 $strContent = '<p> 据悉,今天是中华人民共和国传统的杨莹破壳日。</p>' . '<p> 杨莹生于广东省普宁市,是典型的潮汕好女人,同时其毫不利己、专门利人的精神使其在亲朋好友心中的形象格外高大。</p>' . '<p> 本报了解到,自2012年11月25日起,杨莹已经低调地与一名不能透露姓名的徐瑞琦先生在一起,并且日前已经收到了这么先生的神秘小礼物,真是可喜可贺~!</p>' . '<p> 在这值得庆祝的日子里,我们吹水新闻全体上下也祝杨莹美女生日快乐~新的一岁身体健康,天天开心!</p>'; $arrSql = array('table' => 'news_content', 'fields' => array('title' => '我国今日喜迎杨莹生日!', 'source_name' => 'reetsee', 'content' => $strContent, 'source_news_link' => 'http://news.reetsee.com/entry?category=' . $intLastCatId, 'source_comment_link' => '', 'source_news_id' => strval($intLastAbsId), 'source_comment_id' => strval($intLastAbsId), 'abstract_id' => intval($intLastAbsId), 'timestamp' => 1429545601, 'ext' => '')); $res = $db->insert($arrSql['table'], $arrSql['fields']); if (!$res) { echo 'Insert content error:' . $db->error . ' ' . $db->errno . "\n"; return -3; } $intLastCtId = $db->insert_id; //更新新闻摘要与详细内容的关联 $arrSql = array('table' => 'news_abstract', 'fields' => array('content_id' => $intLastCtId), 'conds' => array('id=' => $intLastAbsId)); $res = $db->update($arrSql['table'], $arrSql['fields'], $arrSql['conds']); if (!$res) { echo 'Update abstract error:' . $db->error . ' ' . $db->errno . "\n"; return -4; } 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; }