Exemplo n.º 1
0
 /**
  * 删除缓存,从新生成所有文章
  * 只有在登录后才有效,但是当前尚未实现登录
  *
  * @return $this
  * @throws Exception
  */
 public function Update()
 {
     global $postHelper;
     // 删除所有缓存的文章
     $files = glob(CACHE_DIR . '/*.post');
     foreach ($files as $file) {
         if (is_file($file)) {
             unlink($file);
         }
     }
     $postHelper->Clear();
     // 生成所有文章
     $list = $this->getPostFileList();
     foreach ($list as $file) {
         if (mb_check_encoding($file, 'gbk')) {
             echo "add post ", mb_convert_encoding($file, 'utf-8', 'gbk'), " <br>\n";
         }
         $post = ParserFactory::TryParseFile($file);
         if ($post) {
             $postHelper->addPost($post);
         } else {
             throw new Exception("Parse file '{$file}' to post filed.");
         }
     }
     return $this;
 }