private function getArticle($article_id) { $params = array(); $params = array('eq' => array('article_id' => $article_id)); if (!$this->is_root) { $params['lt'] = array('category_id' => 5); } $article = Repository::findOneFromArticle($params); if ($article == false) { header("Location: /index/notfound"); return; } $params['tags'] = SqlRepository::getTags($article_id); $params['title'] = $article->get_title(); $params['indexs'] = json_decode($article->get_indexs()); $params['contents'] = \TechlogTools::pre_treat_article($article->get_draft()); $params['title_desc'] = $article->get_title_desc(); $params['article_category_id'] = $article->get_category_id(); if (StringOpt::spider_string($params['contents'], '"page-header"', '</div>') === null) { $params['contents'] = '<div class="page-header"><h1>' . $article->get_title() . '</h1></div>' . $params['contents']; } $article->set_access_count($article->get_access_count() + 1); Repository::persist($article); $params['inserttime'] = $article->get_inserttime() . ' 最后更新: ' . $article->get_updatetime() . ' 访问数量:' . ($article->get_access_count() + 1); return $params; }
continue; } $title = Repository::findTitleFromArticle(array('eq' => array('article_id' => $article_id))); if ($title == false) { LogOpt::set('exception', '草稿原文不存在', 'article_id', $article_id); continue; } echo '是否加载该草稿到日志原文?《' . $title . '》' . '(arctile_id:' . $article_id . ') [y/N]'; $sure = fgets(STDIN); if (trim($sure[0]) != 'Y' && trim($sure[0]) != 'y') { continue; } $draft_file = DRAFT_PATH . '/draft' . $article_id . '.tpl'; $infos = array(); $infos['draft'] = file_get_contents($draft_file); $contents = TechlogTools::pre_treat_article($infos['draft']); $indexs = json_encode(TechlogTools::get_index($contents)); if ($indexs != null) { $infos['indexs'] = $indexs; } $infos['updatetime'] = 'now()'; $image_ids = array(); while (1) { $image_path = StringOpt::spider_string($contents, 'img<![&&]>src="', '"', $contents); if ($image_path === null || $image_path === false || trim($image_path) == '') { break; } $image_path = trim($image_path); if (!file_exists(WEB_PATH . '/resource/' . $image_path)) { LogOpt::set('exception', '文中目标图片不存在', 'image_path', $image_path); return;
private function getArticleInfos($articles, $is_moode = false) { if (empty($articles)) { return array(); } $ret = array(); foreach ($articles as $article) { $ret_infos = array(); preg_match('/^(?<month>\\d{4}-\\d{2})-(?<date>\\d{2})/is', $article->get_inserttime(), $arr); $ret_infos['month'] = str_replace('-', '/', $arr['month']); $ret_infos['date'] = $arr['date']; $tags = SqlRepository::getTags($article->get_article_id()); if (is_array($tags)) { $ret_infos['tags'] = array_slice($tags, 0, 4); } $contents = TechlogTools::pre_treat_article($article->get_draft()); $imgpath = StringOpt::spider_string($contents, 'img<![&&]>src="', '"'); if ($imgpath == null) { $ret_infos['contents'] = strip_tags($contents); $ret_infos['contents'] = mb_substr($ret_infos['contents'], 0, 500, 'utf-8'); } else { $ret_infos['contents'] = '<p><a href="/article/list/' . $article->get_article_id() . '" target="_blank">' . '<img class="img-thumbnail" alt="200x200" style="height: 200px;"' . ' src="' . $imgpath . '"></a></p><br /><p>' . mb_substr(strip_tags($contents), 0, 100, 'utf-8') . '</p>'; } $ret_infos['title'] = $article->get_title(); $ret_infos['article_id'] = $article->get_article_id(); $ret[] = $ret_infos; } return $ret; }