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() . '&nbsp;&nbsp;&nbsp;最后更新: ' . $article->get_updatetime() . '&nbsp;&nbsp;&nbsp;访问数量:' . ($article->get_access_count() + 1);
     return $params;
 }
Exemple #2
0
 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;
 }