Example #1
0
 public function indexAction($args = null)
 {
     global $tpl;
     //        if(file_exists('index.html'))
     //            header('location:index.html');
     $page = new Page();
     $page->Page = isset($args['page']) ? (int) $args['page'] : 1;
     $page->PerPage = 1;
     $page->Url = SITE_URL . 'page/';
     $page->Condition = '/';
     //获得头5篇文章
     //$articles = Article::getPost(5);
     $result = Article::listPost($page);
     $page->Count = $result['count'];
     $articles = $result['res'];
     if (is_array($articles) && count($articles) > 0) {
         foreach ($articles as $key => $val) {
             $content_part = ContentPart::findById($val->id);
             $articles[$key]->content = processContent($content_part->content);
             $articles[$key]->url = SITE_URL . 'post/' . $val->id . '.html';
             $articles[$key]->category = $this->categories[$val->cid]->name;
             $articles[$key]->category_url = SITE_URL . 'category/' . $this->categories[$val->cid]->slug . '/';
         }
     }
     //mprint_r($articles, '$articles');
     //获得内容
     //$content_part = ContentPart::findById($article->id);
     //语法加亮处理
     //$article->content = processContent($content_part->content);
     //获得tags
     //$tags = Tag::findById($article->id);
     //$article->tags = $tags;
     //获得分类
     //$category = new Category('id', $article->cid);
     //$article->category = $category->name;
     //$article->category_slug = $category->slug;
     //$article->category = $this->categories[$article->cid]->name;
     //$article->category_slug = $this->categories[$article->cid]->slug;
     $tpl->assign('articles', $articles);
     $tpl->assign('page_nav', $page->getSimplePage());
     //首页生成静态页
     $index_cache = $this->cache->get('index_cache');
     if ($index_cache === false || !file_exists('index.html')) {
         if (DEBUG === false) {
             header('location:' . SITE_URL . 'page/1/');
             $fp = fopen('index.html', 'w');
             fputs($fp, $tpl->fetch(DEFAULT_TEMPLATE . '/index.html'));
             fclose($fp);
             @chmod('index.html', 0777);
             $index_cache = 'nkjnj';
             $this->cache->set('index_cache', $index_cache, 7200);
             //缓存2小时
         }
     }
     $tpl->display(DEFAULT_TEMPLATE . '/index.html');
 }