Beispiel #1
0
 /**
  * @Response("extension://blog/views/admin/post/edit.razr")
  */
 public function addAction()
 {
     $post = new Post();
     $post->setUser($this['user']);
     $post->setCommentStatus((bool) $this->extension->getParams('posts.comments_enabled'));
     $post->set('title', $this->extension->getParams('posts.show_title'));
     $post->set('markdown', $this->extension->getParams('posts.markdown_enabled'));
     return ['head.title' => __('Add Post'), 'post' => $post, 'statuses' => Post::getStatuses(), 'roles' => $this->roles->findAll(), 'users' => $this->users->findAll()];
 }
 /**
  * @Request({"filter": "array", "post":"int", "page":"int"})
  * @Response("extension://blog/views/admin/comment/index.razr")
  */
 public function indexAction($filter = [], $post_id = 0, $page = 0)
 {
     if ($filter) {
         $this['session']->set('blog.comments.filter', $filter);
     } else {
         $filter = $this['session']->get('blog.comments.filter', []);
     }
     $query = $this->comments->query()->related(['post']);
     $post = null;
     if ($post_id) {
         $query->where(['post_id = ?'], [$post_id]);
         $post = $this->posts->find($post_id);
     }
     if (isset($filter['status']) && is_numeric($status = $filter['status'])) {
         $query->where(['status = ?'], [intval($filter['status'])]);
     } else {
         $query->where(function ($query) use($filter) {
             $query->orWhere(['status = ?', 'status = ?'], [CommentInterface::STATUS_APPROVED, CommentInterface::STATUS_PENDING]);
         });
     }
     if (isset($filter['search']) && strlen($filter['search'])) {
         $query->where(function ($query) use($filter) {
             $query->orWhere(['author LIKE :search', 'email LIKE :search', 'url LIKE :search', 'ip LIKE :search', 'content LIKE :search'], ['search' => "%{$filter['search']}%"]);
         });
     }
     $limit = $this->extension->getParams('comments.comments_per_page');
     $count = $query->count();
     $total = ceil($count / $limit);
     $page = max(0, min($total - 1, $page));
     $comments = $query->offset($page * $limit)->limit($limit)->orderBy('created', 'DESC')->get();
     if ($comments) {
         $pending = $this['db']->createQueryBuilder()->from('@blog_comment')->where(['status' => CommentInterface::STATUS_PENDING])->whereIn('post_id', array_unique(array_map(function ($comment) {
             return $comment->getPostId();
         }, $comments)))->groupBy('post_id')->execute('post_id, count(id)')->fetchAll(\PDO::FETCH_KEY_PAIR);
     } else {
         $pending = [];
     }
     foreach ($comments as $comment) {
         $comment->setContent($this['content']->applyPlugins($comment->getContent(), ['comment' => true]));
     }
     if ($this['request']->isXmlHttpRequest()) {
         return $this['response']->json(['table' => $this['view']->render('extension://blog/views/admin/comment/table.razr', ['count' => $count, 'comments' => $comments, 'post' => $post, 'pending' => $pending]), 'total' => $total]);
     }
     $title = $post ? __('Comments on %title%', ['%title%' => $post->getTitle()]) : __('Comments');
     return ['head.title' => $title, 'comments' => $comments, 'post' => $post, 'statuses' => Comment::getStatuses(), 'filter' => $filter, 'total' => $total, 'count' => $count, 'pending' => $pending];
 }
 /**
  * @Route("/feed")
  * @Route("/feed/{type}")
  */
 public function feedAction($type = '')
 {
     $feed = $this['feed']->create($type ?: $this->extension->getParams('feed.type'), ['title' => $this['option']->get('system:app.site_title'), 'link' => $this['url']->route('@blog/site', [], true), 'description' => $this['option']->get('system:app.site_description'), 'element' => ['language', $this['option']->get('system:app.locale')], 'selfLink' => $this['url']->route('@blog/site/feed', [], true)]);
     if ($last = $this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->limit(1)->orderBy('modified', 'DESC')->first()) {
         $feed->setDate($last->getModified());
     }
     foreach ($this->posts->query()->where(['status = ?', 'date < ?'], [Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->limit($this->extension->getParams('feed.limit'))->orderBy('date', 'DESC')->get() as $post) {
         $feed->addItem($feed->createItem(['title' => $post->getTitle(), 'link' => $this['url']->route('@blog/id', ['id' => $post->getId()], true), 'description' => $this['content']->applyPlugins($post->getContent(), ['post' => $post, 'markdown' => $post->get('markdown'), 'readmore' => true]), 'date' => $post->getDate(), 'author' => [$post->getUser()->getName(), $post->getUser()->getEmail()], 'id' => $this['url']->route('@blog/id', ['id' => $post->getId()], true)]));
     }
     return $this['response']->create($feed->generate(), Response::HTTP_OK, ['Content-Type' => $feed->getMIMEType()]);
 }
 /**
  * @param  string $type
  * @return Feed
  */
 protected function getFeed($type = '')
 {
     if (!$type) {
         $type = $this->extension->getParams('feed.type');
     }
     switch ($type) {
         case 'atom':
             return new ATOM();
         case 'rss':
             return new RSS1();
         default:
             return new RSS2();
     }
 }