예제 #1
0
 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;
 }
예제 #2
0
 $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;
     }
     $image_id = Repository::findImageIdFromImages(array('eq' => array('path' => $image_path)));
     if ($image_id == false) {
         $full_path = WEB_PATH . '/resource/' . $image_path;
         $image_id = TechlogTools::load_image($full_path, 'article');
         if ($image_id == false) {
             LogOpt::set('exception', '添加图片到数据库失败', 'image_path', $image_path);
             return;
예제 #3
0
 public static function get_index($html_str)
 {
     $str = $html_str;
     $index = array();
     while (1) {
         $value = '';
         $key = StringOpt::spider_string($str, '<div', '</div>', $str);
         if ($key === null) {
             break;
         } else {
             if ($key === false) {
                 return false;
             }
         }
         $key = StringOpt::spider_string($key, 'class="page-header"<![&&]>id="', '"', $value);
         if ($key === null) {
             continue;
         }
         $value = StringOpt::spider_string($value, '>', '<');
         if ($value === null) {
             continue;
         } else {
             if ($value === false) {
                 return false;
             }
         }
         $index[$key] = $value;
     }
     return $index;
 }
예제 #4
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;
 }