Beispiel #1
0
 /**
  * 根据标签名称获取相关文章
  *
  * @param Request $request
  * @param Tags $tagModel
  * @param Post $postModel
  * @param SmpJsonView $jsonView
  *
  * @return SmpJsonView
  */
 public function relatedPostsAction(Request $request, Tags $tagModel, Post $postModel, SmpJsonView $jsonView)
 {
     $tags = $tagModel->getTagsByNames(explode(',', $request->get('tags', '')));
     $tag_ids = [];
     foreach ($tags as $tag) {
         $tag_ids[] = $tag['id'];
     }
     $posts = $postModel->getPostsInfoByTags($tag_ids, 10);
     $jsonView->assign('posts', $posts);
     $jsonView->assign('status', true);
     return $jsonView;
 }
Beispiel #2
0
 public function showAction(Post $postModel)
 {
     $posts = $postModel->getRecentlyPosts(1, 20);
     $feed = new Feed();
     $channel = new Channel();
     $channel->title('Aicode')->description('爱生活,爱代码')->url('http://aicode.cc')->lastBuildDate($posts['data'][0]['publish_date'])->appendTo($feed);
     foreach ($posts['data'] as $art) {
         $item = new Item();
         $item->title($art['title'])->description('<p><img src="' . $art['feature_img'] . '" /></p>' . (new \Parsedown())->parse($art['content']))->url('http://aicode.cc/article/' . $art['id'] . '.html')->pubDate($art['publish_date'])->guid('http://aicode.cc/article/' . $art['id'] . '.html')->appendTo($channel);
     }
     header('Content-Type:text/xml; charset=utf-8');
     return $feed->render();
 }
Beispiel #3
0
 /**
  * 首页
  *
  * @param Request $request
  * @param Post $postModel
  *
  * @return string
  */
 public function indexAction(Request $request, Post $postModel)
 {
     $current = intval($request->get('page', 1));
     $key = "list_{$current}";
     $html = $this->getCache()->get($key);
     if (false === $html) {
         $posts = $postModel->getRecentlyPosts($current, 10);
         $this->assign('posts', $posts['data']);
         $this->assign('page', $posts['page']);
         $this->assign('parsedown', new \Parsedown());
         $this->assign('catModel', new Category());
         $html = $this->view('index')->render();
         $this->getCache()->set($key, $html);
     }
     return $html;
 }
Beispiel #4
0
 /**
  * 文章列表页 (标签)
  *
  * @param Request $request
  * @param \Demo\Models\Post $postModel
  * @param \Demo\Models\Tags $tagModel
  *
  * @return string
  */
 public function tagAction(Request $request, \Demo\Models\Post $postModel, \Demo\Models\Tags $tagModel)
 {
     $tagName = $request->get('tag');
     $current = intval($request->get('page', 1));
     $key = "tag_{$tagName}_{$current}";
     $html = $this->getCache()->get($key);
     if (false === $html) {
         $tag = $tagModel->getTagByName($tagName);
         $posts = $postModel->getPostsByTag($tag['id'], $current);
         $this->assign('posts', $posts['data']);
         $this->assign('page', $posts['page']);
         $this->assign('__tag__', $tag);
         $this->assign('__navcur__', '技不压身');
         $this->assign('parsedown', new \Parsedown());
         $this->assign('catModel', new Category());
         $html = $this->view('index')->render();
         $this->getCache()->set($key, $html);
     }
     return $html;
 }