public function editAction($args = null)
 {
     global $tpl;
     //$id = isset($_GET['id']) ? $_GET['id'] : '';    //这里以后改进成$params['id']
     $id = isset($args['id']) ? (int) $args['id'] : '';
     //如果为空 提示出错
     $article = new Article('id', $id);
     $content_part = ContentPart::findById($id);
     $article->content = $content_part->content;
     $article->tags = $article->getTags();
     $tpl->assign('article', $article);
     //查出所有分类
     $categories = Category::findAll();
     $tpl->assign('cats', $categories);
     $tpl->display('admin/article_add.html');
     del_cache();
 }
 public function createAction()
 {
     global $tpl;
     set_time_limit(100);
     //删除data/chache目录
     $path = DATA_DIR . 'cache/';
     //缓存目录
     if ($handle = opendir($path)) {
         while (false !== ($file = readdir($handle))) {
             if ($file != "." && $file != "..") {
                 //$files[] = $file;
                 @unlink($path . $file);
             }
         }
         closedir($handle);
     }
     //删除首页
     del_cache();
     //文章
     $total = Cache::getTotal();
     $start = 0;
     $limit = 20;
     $start_id = 0;
     $i = 0;
     $tablename_content = Record::tableFromClass('Article');
     $tablename_contentpart = Record::tableFromClass('ContentPart');
     $previous = null;
     while ($i < $total) {
         $sql = "select * from {$tablename_content} where type='post' and id > {$start_id} order by id asc limit {$limit}";
         Record::$__CONN__->query($sql);
         $articles = array();
         $articles = Record::$__CONN__->last_result;
         if (is_array($articles) && count($articles) > 0) {
             foreach ($articles as $k => $data) {
                 $article = new Article(get_object_vars($data));
                 //上一页
                 $previous = isset($previous) ? $previous : '';
                 $tpl->assign('previous', $previous);
                 $previous = $article;
                 //下一页
                 if (isset($articles[$k + 1])) {
                     //$next = new Article(get_object_vars($articles[$k+1]));
                     $next = $articles[$k + 1];
                 } else {
                     $next = $article->next();
                 }
                 $tpl->assign('next', $next);
                 $content_part = ContentPart::findById($article->id);
                 $article->content = processContent($content_part->content);
                 $article->tags = isset($this->cahce_tags[$article->id]) ? $this->cahce_tags[$article->id] : array();
                 $article->category = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['name'] : '无分类';
                 $article->category_slug = isset($this->cahce_categories[$article->cid]) ? $this->cahce_categories[$article->cid]['slug'] : 'uncategory';
                 $this->createHtml($article);
                 if ($k == $limit - 1) {
                     $start_id = $article->id;
                 }
             }
         }
         $i += $limit;
     }
     //while
     flush();
     echo 'create cache over!';
     echo '<a href="index.php">Index</a>';
 }
Example #3
0
 public function showAction($args = null)
 {
     global $tpl, $app;
     $id = isset($args['id']) ? (int) $args['id'] : '';
     //如果为空 提示出错
     try {
         $article = new Article('id', $id);
         if (!$article->id) {
             throw new Exception('文章不存在');
         }
         $content_part = ContentPart::findById($id);
         //语法加亮处理
         $article->content = processContent($content_part->content);
         $article->tags = $article->getTags();
         $article->category = $this->categories[$article->cid]->name;
         $article->category_slug = $this->categories[$article->cid]->slug;
         //上一篇文章
         $previous = $article->previous();
         //下一篇文章
         $next = $article->next();
         //首页最近文章
         //$recent_post = Article::getPost(5, true);
     } catch (Exception $e) {
         //die($e->getMessage());
         $app->error($e->getMessage(), SITE_URL);
     }
     $tpl->assign('post', $article);
     $tpl->assign('next', $next);
     $tpl->assign('previous', $previous);
     //首页post静态页
     if (DEBUG === false) {
         $fp = fopen(SYSTEM_ROOT . "post/{$id}.html", 'w');
         fputs($fp, $tpl->fetch(DEFAULT_TEMPLATE . '/post.html'));
         fclose($fp);
     }
     $tpl->display(DEFAULT_TEMPLATE . '/post.html');
 }