コード例 #1
0
 /**
  * @Route("/{id}", name="id")
  */
 public function postAction($id = 0)
 {
     if (!($post = Post::where(['id = ?', 'status = ?', 'date < ?'], [$id, Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->first())) {
         App::abort(404, __('Post not found!'));
     }
     if (!$post->hasAccess(App::user())) {
         App::abort(403, __('Insufficient User Rights.'));
     }
     $post->excerpt = App::content()->applyPlugins($post->excerpt, ['post' => $post, 'markdown' => $post->get('markdown')]);
     $post->content = App::content()->applyPlugins($post->content, ['post' => $post, 'markdown' => $post->get('markdown')]);
     $user = App::user();
     return ['$view' => ['title' => __($post->title), 'name' => 'blog/post.php'], '$comments' => ['config' => ['post' => $post->id, 'enabled' => $post->isCommentable(), 'requireinfo' => $this->blog->config('comments.require_email'), 'max_depth' => $this->blog->config('comments.max_depth')], 'user' => ['name' => $user->name, 'isAuthenticated' => $user->isAuthenticated(), 'canComment' => $user->hasAccess('blog: post comments'), 'skipApproval' => $user->hasAccess('blog: skip comment approval')]], 'blog' => $this->blog, 'post' => $post];
 }
コード例 #2
0
 /**
  * @Route("/{id}", name="id")
  */
 public function postAction($id = 0)
 {
     if (!($post = Post::where(['id = ?', 'status = ?', 'date < ?'], [$id, Post::STATUS_PUBLISHED, new \DateTime()])->related('user')->first())) {
         App::abort(404, __('Post not found!'));
     }
     if (!$post->hasAccess(App::user())) {
         App::abort(403, __('Insufficient User Rights.'));
     }
     $post->excerpt = App::content()->applyPlugins($post->excerpt, ['post' => $post, 'markdown' => $post->get('markdown')]);
     $post->content = App::content()->applyPlugins($post->content, ['post' => $post, 'markdown' => $post->get('markdown')]);
     $user = App::user();
     $description = $post->get('meta.og:description');
     if (!$description) {
         $description = strip_tags($post->excerpt ?: $post->content);
         $description = rtrim(mb_substr($description, 0, 150), " \t\n\r\v.,") . '...';
     }
     return ['$view' => ['title' => __($post->title), 'name' => 'blog/post.php', 'og:type' => 'article', 'article:published_time' => $post->date->format(\DateTime::ATOM), 'article:modified_time' => $post->modified->format(\DateTime::ATOM), 'article:author' => $post->user->name, 'og:title' => $post->get('meta.og:title') ?: $post->title, 'og:description' => $description, 'og:image' => $post->get('image.src') ? App::url()->getStatic($post->get('image.src'), [], 0) : false], '$comments' => ['config' => ['post' => $post->id, 'enabled' => $post->isCommentable(), 'requireinfo' => $this->blog->config('comments.require_email'), 'max_depth' => $this->blog->config('comments.max_depth'), 'user' => ['name' => $user->name, 'isAuthenticated' => $user->isAuthenticated(), 'canComment' => $user->hasAccess('blog: post comments'), 'skipApproval' => $user->hasAccess('blog: skip comment approval')]]], 'blog' => $this->blog, 'post' => $post];
 }
コード例 #3
0
ファイル: UrlResolver.php プロジェクト: vanclist/spatoday
 /**
  * {@inheritdoc}
  */
 public function generate(array $parameters = [])
 {
     $id = $parameters['id'];
     if (!isset($this->cacheEntries[$id])) {
         if (!($post = Post::where(compact('id'))->first())) {
             throw new RouteNotFoundException('Post not found!');
         }
         $this->addCache($post);
     }
     $meta = $this->cacheEntries[$id];
     preg_match_all('#{([a-z]+)}#i', self::getPermalink(), $matches);
     if ($matches) {
         foreach ($matches[1] as $attribute) {
             if (isset($meta[$attribute])) {
                 $parameters[$attribute] = $meta[$attribute];
             }
         }
     }
     unset($parameters['id']);
     return $parameters;
 }
コード例 #4
0
 /**
  * @Route(methods="POST")
  * @Request({"ids": "int[]"}, csrf=true)
  */
 public function copyAction($ids = [])
 {
     foreach ($ids as $id) {
         if ($post = Post::find((int) $id)) {
             if (!App::user()->hasAccess('blog: manage all posts') && !App::user()->hasAccess('blog: manage own posts') && $post->user_id !== App::user()->id) {
                 continue;
             }
             $post = clone $post;
             $post->id = null;
             $post->status = Post::STATUS_DRAFT;
             $post->title = $post->title . ' - ' . __('Copy');
             $post->comment_count = 0;
             $post->date = new \DateTime();
             $post->save();
         }
     }
     return ['message' => 'success'];
 }
コード例 #5
0
 /**
  * @Request({"ids": "int[]"}, csrf=true)
  */
 public function copyAction($ids = [])
 {
     $count = 0;
     foreach ($ids as $id) {
         if ($post = Post::find((int) $id)) {
             if (!App::user()->hasAccess('blog: manage all posts') && $post->user_id !== App::user()->id) {
                 continue;
             }
             $post = clone $post;
             $post->id = null;
             $post->status = Post::STATUS_DRAFT;
             $post->title = $post->title . ' - ' . __('Copy');
             $post->comment_count = 0;
             $post->save();
             $count++;
         }
     }
     return ['message' => _c('{0} No post copied.|{1} Post copied.|]1,Inf[ Posts copied.', $count)];
 }
コード例 #6
0
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"comment": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!$id) {
         if (!$this->user->hasAccess('blog: post comments')) {
             App::abort(403, __('Insufficient User Rights.'));
         }
         $comment = Comment::create();
         if ($this->user->isAuthenticated()) {
             $data['author'] = $this->user->name;
             $data['email'] = $this->user->email;
             $data['url'] = $this->user->url;
         } elseif ($this->blog->config('comments.require_email') && (!@$data['author'] || !@$data['email'])) {
             App::abort(400, __('Please provide valid name and email.'));
         }
         $comment->user_id = $this->user->isAuthenticated() ? (int) $this->user->id : 0;
         $comment->ip = App::request()->getClientIp();
         $comment->created = new \DateTime();
     } else {
         if (!$this->user->hasAccess('blog: manage comments')) {
             App::abort(403, __('Insufficient User Rights.'));
         }
         $comment = Comment::find($id);
         if (!$comment) {
             App::abort(404, __('Comment not found.'));
         }
     }
     unset($data['created']);
     // check minimum idle time in between user comments
     if (!$this->user->hasAccess('blog: skip comment min idle') and $minidle = $this->blog->config('comments.minidle') and $commentIdle = Comment::where($this->user->isAuthenticated() ? ['user_id' => $this->user->id] : ['ip' => App::request()->getClientIp()])->orderBy('created', 'DESC')->first()) {
         $diff = $commentIdle->created->diff(new \DateTime("- {$minidle} sec"));
         if ($diff->invert) {
             App::abort(403, __('Please wait another %seconds% seconds before commenting again.', ['%seconds%' => $diff->s + $diff->i * 60 + $diff->h * 3600]));
         }
     }
     if (@$data['parent_id'] && !($parent = Comment::find((int) $data['parent_id']))) {
         App::abort(404, __('Parent not found.'));
     }
     if (!@$data['post_id'] || !($post = Post::where(['id' => $data['post_id']])->first()) or !($this->user->hasAccess('blog: manage comments') || $post->isCommentable() && $post->isPublished())) {
         App::abort(404, __('Post not found.'));
     }
     $approved_once = (bool) Comment::where(['user_id' => $this->user->id, 'status' => Comment::STATUS_APPROVED])->first();
     $comment->status = $this->user->hasAccess('blog: skip comment approval') ? Comment::STATUS_APPROVED : $this->user->hasAccess('blog: comment approval required once') && $approved_once ? Comment::STATUS_APPROVED : Comment::STATUS_PENDING;
     // check the max links rule
     if ($comment->status == Comment::STATUS_APPROVED && $this->blog->config('comments.maxlinks') <= preg_match_all('/<a [^>]*href/i', @$data['content'])) {
         $comment->status = Comment::STATUS_PENDING;
     }
     // check for spam
     //App::trigger('system.comment.spam_check', new CommentEvent($comment));
     $comment->save($data);
     return ['message' => 'success', 'comment' => $comment];
 }
コード例 #7
0
 /**
  * @Access("blog: manage comments")
  * @Request({"filter": "array", "post":"int", "page":"int"})
  */
 public function commentAction($filter = [], $post = 0, $page = null)
 {
     $post = Post::find($post);
     $filter['order'] = 'created DESC';
     return ['$view' => ['title' => $post ? __('Comments on %title%', ['%title%' => $post->title]) : __('Comments'), 'name' => 'blog/admin/comment-index.php'], '$data' => ['statuses' => Comment::getStatuses(), 'config' => ['filter' => (object) $filter, 'page' => $page, 'post' => $post, 'limit' => App::module('blog')->config('comments.comments_per_page')]]];
 }
コード例 #8
0
ファイル: PostListener.php プロジェクト: vanclist/spatoday
 public function onRoleDelete($event, $role)
 {
     Post::removeRole($role);
 }