示例#1
0
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $hash = $this->input('hash');
     $id = !empty($hash) ? $this->post->byHash($hash)->id : 0;
     $protected_visibility = $this->visibility->whereName('Protected')->first()->hash;
     return ['title' => 'required|min:2|max:100', 'slug' => "required|unique:posts,slug,{$id}|min:2|max:120", 'reviewer' => 'exists:users,hash', 'post' => 'required', 'category' => 'required|exists:categories,hash', 'publishdate' => 'required|date_format: d-m-Y H:i', 'password' => "required_if:visibility,{$protected_visibility}"];
 }
示例#2
0
 /**
  * @param \Illuminate\Http\Request $request
  * @return bool
  */
 private function checkIfUserCanEditPost($request)
 {
     $post = $this->post->byHash($request->segment(3));
     $user_id = $this->auth->user()->getAuthIdentifier();
     if ($user_id != $post->user_id && $user_id != $post->reviewer_id && $this->auth->user()->role->name != 'Admin') {
         return false;
     }
     return true;
 }
示例#3
0
 /**
  * Check if a given slug already exists
  * and when it exists generate a new one
  *
  * @param string $slug
  * @return string
  */
 public function checkIfSlugIsUnique($slug)
 {
     $i = 0;
     $this->base_slug = $slug;
     while ($this->post->whereSlug($slug)->get()->count() > 0) {
         $i++;
         $slug = "{$this->base_slug}-{$i}";
     }
     return $slug;
 }
示例#4
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $post = $this->post->bySlug($request->segment(2));
     if ($post->visibility_id == 2) {
         if (!$this->hash->check(Input::get('password'), $post->password)) {
             return redirect()->route('blog.askPassword', [$post->slug])->with('wrong_password', 'Please provide a valid password to view this post');
         }
     }
     return $next($request);
 }
示例#5
0
 /**
  * @param \Illuminate\Http\Request $request
  * @return bool
  */
 private function checkIfUserCanViewPost($request)
 {
     $post = $this->post->byHash($request->segment(3));
     $user_id = $this->auth->user()->getAuthIdentifier();
     if ($post->visibility_id == 'Private') {
         if (!$post->user_id == $user_id) {
             return false;
         }
     }
     return true;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $hash = $request->segment(3);
     $post = $this->post->byHash($hash);
     if ($post->being_edited_by != null && $post->being_edited_by != $this->auth->user()->getAuthIdentifier()) {
         $user = $this->user->find($post->being_edited_by)->fullName;
         session()->flash('notify', ['danger', trans('blogify::posts.notify.being_edited', ['name' => $user])]);
         return redirect()->route('admin.posts.index');
     }
     return $next($request);
 }
示例#7
0
 public function store(CommentRequest $request)
 {
     $comment = new Comment();
     $comment->hash = blogify()->makeHash('comments', 'hash', true);
     $comment->content = $request->comment;
     $comment->user_id = $this->auth->user()->id;
     $comment->post_id = $this->post->byHash($request->post)->id;
     $comment->revised = $this->config->approve_comments_first ? 1 : 2;
     $comment->save();
     tracert()->log('comments', $comment->id, $this->auth->user()->id, 'create');
     session()->flash('notify', ['success', 'Your comment has been added']);
     return back();
 }
示例#8
0
 /**
  * @return array
  */
 private function getOverviewData()
 {
     $archive = $this->post->where('publish_date', '<=', date('Y-m-d H:i:s'))->orderBy('publish_date', 'DESC')->get()->groupBy(function ($query) {
         return Carbon::parse($query->publish_date)->format('F Y');
     });
     $data = ['categories' => $this->category->all(), 'tags' => $this->tag->all(), 'archives' => $archive];
     return $data;
 }
 /**
  * @return \jorenvanhocht\Blogify\Models\Post
  */
 private function storeOrUpdatePost()
 {
     if (!empty($this->data->hash)) {
         $post = $this->post->byHash($this->data->hash);
     } else {
         $post = new Post();
         $post->hash = $this->blogify->makeHash('posts', 'hash', true);
     }
     $post->slug = $this->data->slug;
     $post->title = $this->data->title;
     $post->content = $this->data->post;
     $post->status_id = $this->status->byHash($this->data->status)->id;
     $post->publish_date = $this->data->publishdate;
     $post->user_id = $this->user->byHash($this->auth_user->hash)->id;
     $post->reviewer_id = $this->user->byHash($this->data->reviewer)->id;
     $post->visibility_id = $this->visibility->byHash($this->data->visibility)->id;
     $post->category_id = $this->category->byHash($this->data->category)->id;
     $post->being_edited_by = null;
     if (!empty($this->data->password)) {
         $post->password = $this->hash->make($this->data->password);
     }
     $post->save();
     $post->tag()->sync($this->tags);
     return $post;
 }
 /**
  * @return void
  */
 private function buildDataArrayForReviewer()
 {
     $this->data['pending_review_posts'] = $this->post->whereStatusId(2)->forReviewer()->count();
 }