public function posts($id)
 {
     $this->load->helper('form');
     $this->load->model(['post', 'comment']);
     $post = NULL;
     try {
         $post = Post::findOrFail($id);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         show_404();
     }
     $data = ['menu' => 'blog', 'post' => $post];
     $this->load->library('form_validation');
     $this->form_validation->set_error_delimiters('<p class="text-danger"><strong><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> ', '</strong></p>');
     if ($this->form_validation->run('create-comment') == FALSE) {
         $this->load->view('front/blog-post', $data);
     } else {
         $comment = new Comment();
         $comment->post_id = $this->input->post('id');
         $comment->name = $this->input->post('name');
         $comment->content = $this->input->post('comment');
         $comment->save();
         $this->session->set_flashdata('message', 'Successfully save!');
         redirect('posts/' . $id . '#comments');
     }
 }
Example #2
0
 public function postComment($id)
 {
     $input = Input::all();
     Log::info($input);
     $validator = Comment::validate($input);
     if ($validator->fails()) {
         FlashHelper::message("Null title", FlashHelper::DANGER);
         return;
     }
     $post = Post::findOrFail($id);
     if (!$post->can_comment || !PrivacyHelper::checkPermission(Auth::user(), $post)) {
         throw new Exception("Don't have permision");
     }
     $comment = new Comment();
     $Parsedown = new Parsedown();
     $comment->post_id = $id;
     $comment->parrent_id = $input['parrent_id'];
     $comment->markdown = $input['markdown'];
     Log::info($comment);
     $comment->HTML = $Parsedown->text($comment->markdown);
     $comment->save();
     $comment->comments = array();
     $data['html'] = View::make('posts._comment')->with('data', $comment)->with('level', count($comment->parents()))->with('can_comment', true)->render();
     $data['status'] = true;
     $data['parent_id'] = $comment->parrent_id;
     return Response::json($data);
 }
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $this->authorOrAdminPermissioinRequire($post->user_id);
     Post::destroy($id);
     Flash::success(lang('Operation succeeded.'));
     return Redirect::route('posts.index');
 }
 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $post->update($data);
     return Redirect::route('admin.posts.index');
 }
 /**
  * Return the field values from the model
  *
  * @param integer $id
  * @param array $fields
  * @return array
  */
 protected function fieldsFromModel($id, array $fields)
 {
     $post = Post::findOrFail($id);
     $fieldNames = array_keys(array_except($fields, ['tags']));
     $fields = ['id' => $id];
     foreach ($fieldNames as $field) {
         $fields[$field] = $post->{$field};
     }
     $fields['tags'] = $post->tags()->lists('tag')->all();
     return $fields;
 }
Example #6
0
 public function accept_a_post($id)
 {
     if (!Auth::check() || !Auth::user()->isAdmin()) {
         return Redirect::route('login');
     } else {
         $postReference = Post::findOrFail($id);
         $postReference->moderated = true;
         $postReference->save();
         return Redirect::route('admin_panel');
     }
 }
Example #7
0
 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $slug = str_replace(' ', '-', Input::get('title'));
     $data['slug'] = $slug;
     $post->update($data);
     return Redirect::route('admin.posts.list');
 }
Example #8
0
 public function applyVote($user, $type, $type_id, $updown)
 {
     //deal with item table
     $item = "";
     switch ($type) {
         case Constant::POST_TYPE:
             $item = Post::findOrFail($type_id);
             break;
         case Constant::COMMENT_TYPE:
             $item = Comment::findOrFail($type_id);
             Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $item->post_id);
             break;
         case Constant::SECTION_TYPE:
             $item = Section::findOrFail($type_id);
             break;
         default:
             throw new UnexpectedValueException("type: {$type} not enumerated");
     }
     //increment our total vote counter
     $user->increment('votes');
     //decrement one point for voting
     $user->decrement('points');
     //double decrement for self upvote
     if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
         if ($item->user_id == Auth::user()->id && $updown == Constant::VOTE_UP) {
             $user->decrement('points');
         }
     }
     //upvote/downvote the item itself
     if ($updown == Constant::VOTE_UP) {
         $item->increment('upvotes');
     } else {
         if ($updown == Constant::VOTE_DOWN) {
             $item->increment('downvotes');
         }
     }
     //upvote/downvote user who posted (ignore for sections)
     if ($type == Constant::POST_TYPE || $type == Constant::COMMENT_TYPE) {
         $rec_user = User::findOrFail($item->user_id);
         if ($updown == Constant::VOTE_UP) {
             $rec_user->increment('points');
         } else {
             if ($updown == Constant::VOTE_DOWN) {
                 $rec_user->decrement('points');
             }
         }
     }
     //deal with votes table
     $vote = new Vote(array('type' => $type, 'user_id' => Auth::user()->id, 'item_id' => $type_id, 'updown' => $updown));
     $vote->save();
 }
Example #9
0
 public function make($post_id, $content, $parent_id)
 {
     $block = new SuccessBlock();
     $block->data->comment_id = -1;
     if ($block->success) {
         if (Auth::user()->points < 1) {
             $block->success = false;
             $block->errors[] = 'You need at least one point to post a comment';
         }
     }
     if ($block->success) {
         if (!$this->canPost()) {
             $block->success = false;
             $block->errors[] = 'can only post ' . Utility::availableComments() . ' per day';
         }
     }
     if ($block->success) {
         $data = ['data' => Markdown::defaultTransform(e($content)), 'parent_id' => $parent_id, 'user_id' => Auth::user()->id, 'post_id' => $post_id, 'markdown' => $content];
         $rules = array('user_id' => 'required|numeric', 'parent_id' => 'required|numeric', 'post_id' => 'required|numeric', 'markdown' => 'required|max:' . Constant::COMMENT_MAX_MARKDOWN_LENGTH);
         $validate = Validator::make($data, $rules);
         if ($validate->fails()) {
             $block->success = false;
             foreach ($validate->messages()->all() as $v) {
                 $block->errors[] = $v;
             }
         }
     }
     if ($block->success) {
         $post = Post::findOrFail($data['post_id']);
         $notification = new Notification();
         if ($data['parent_id'] != Constant::COMMENT_NO_PARENT) {
             $parent = $this->findOrFail($data['parent_id']);
             $notification->type = Constant::NOTIFICATION_COMMENT_TYPE;
             $notification->user_id = $parent->user_id;
         } else {
             $notification->type = Constant::NOTIFICATION_POST_TYPE;
             $notification->user_id = $post->user_id;
         }
         $comment = new Comment($data);
         $comment->save();
         $post->increment('comment_count');
         $notification->item_id = $comment->id;
         $block->data->comment_id = $comment->id;
         if ($notification->user_id != Auth::user()->id) {
             $notification->save();
         }
         Cache::forget(Constant::COMMENT_CACHE_NEWLIST_NAME . $post_id);
     }
     return $block;
 }
Example #10
0
 public function applyTag($post_id, $type, $updown)
 {
     $post = Post::findOrFail($post_id);
     //upvote/downvote the post itself
     if ($updown == Constant::TAG_UP) {
         $post->increment($this->getColumn($type));
     } else {
         if ($updown == Constant::TAG_DOWN) {
             $post->decrement($this->getColumn($type));
         }
     }
     //deal with votes table
     $tag = new Tag(array('type' => $type, 'user_id' => Auth::user()->id, 'post_id' => $post_id, 'updown' => $updown));
     $tag->save();
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update()
 {
     $data = Input::all();
     $id = $data['id'];
     $post = Post::findOrFail($id);
     $validator = Validator::make($data, Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if (empty($data['image'])) {
         unset($data['image']);
     } else {
         $data['image'] = ImageHandler::uploadImage($data['image'], 'images');
     }
     $post->update($data);
     return Redirect::to('admin/posts/edit' . '/' . $id)->with(array('note' => 'Successfully Updated Post!', 'note_type' => 'success'));
 }
 public function setPublish($id)
 {
     $post = \Post::findOrFail($id);
     //Conseguimos el canal puesto como principal
     if ($post->status == 1) {
         return Redirect::back()->with('error', 'Ya ha sido publicado con exito anteriormente');
     }
     $channel = Helper::getChannel($post->channel_id);
     $data = array('name' => $post->title, 'link' => $post->link, 'description' => strip_tags(HTML::decode($post->text)), 'picture' => $post->img);
     $res = $channel->Publish($data);
     if (!$res['status']) {
         $post->status = 5;
         $post->result_post = $res['error'];
         $post->save();
         return Redirect::back()->with('error', $res['error']);
     } else {
         $post->status = 1;
         $post->result_post = $res['status'];
         $post->channel_id = $channel->id;
         $post->save();
         return Redirect::back()->with('message', 'Publicado con éxito');
     }
     // die($post->result_status);
 }
Example #13
0
 public function edit($id)
 {
     $post = Post::findOrFail($id);
     return Response::json(array('error' => false, 'posts' => $post));
 }
Example #14
0
 /**
  * Update the specified post in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $file = Input::file('image');
     $category = Postcategory::find(Input::get('post_category_id'));
     $data = array('title' => ucwords(Input::get('title')), 'slug' => $this->slugify(Input::get('slug')), 'content' => Input::get('content'), 'excerpt' => Input::get('excerpt'), 'post_category_id' => Input::get('post_category_id'), 'status' => Input::get('status'), 'comment_status' => Input::get('comment_status'), 'social_status' => Input::get('social_status'), 'created_at' => Input::get('created_at'));
     $validator = Validator::make($data, Post::rules($id));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if (Input::hasFile('image')) {
         // checking file is valid.
         if (Input::file('image')->isValid()) {
             $destinationPath = '/uploads/' . $category->slug;
             // upload path
             $extension = Input::file('image')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(1, 1000) . '_' . $data['slug'] . '.' . $extension;
             // renameing image
             Input::file('image')->move(public_path() . $destinationPath, $fileName);
             // uploading file to given path
             $data['image'] = $destinationPath . "/" . $fileName;
         } else {
             // sending back with error message.
             return Redirect::back()->with('errors', 'Uploaded file is not valid')->withInput();
         }
     }
     if (Input::hasFile('documents')) {
         $documents = Input::file('documents');
         foreach ($documents as $newdocument) {
             if ($newdocument !== NULL) {
                 // dd($newdocument);
                 // checking file is valid.
                 $destinationPath = '/uploads/documents';
                 // upload path
                 $fileName = rand(1, 1000) . '_' . $newdocument->getClientOriginalName();
                 // renameing image
                 $newdocument->move(public_path() . $destinationPath, $fileName);
                 // uploading file to given path
                 // Save the photo
                 $document = new Document();
                 $document->name = $fileName;
                 $document->path = $destinationPath . "/" . $fileName;
                 $document->save();
                 $post->documents()->save($document);
             }
         }
     }
     if (Input::has('related_members')) {
         $post->members()->sync(Input::get('related_members'));
     }
     $post->update($data);
     return Redirect::route('admin.posts.edit', $post->id)->with("message", "Data berhasil disimpan");
 }
Example #15
0
 public function update($id)
 {
     $post = Post::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Post::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // We remove quotes from tag_ids with array_map intval
     $tag_ids = array_map('intval', $data['tags']);
     $post->update(['title' => $data['title'], 'content' => $data['content'], 'status' => $data['status']]);
     $post->categories()->sync([$data['category']]);
     $post->tags()->sync($tag_ids);
     return Redirect::route('posts.show', $id)->withInfo(Lang::get('larabase.post_updated'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $real_id = $this->post->findBySlug($id);
     $post = $this->post->findOrFail($real_id[0]['id']);
     return View::make('posts.show', compact('post'));
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $post = $this->post->findOrFail($id);
     return View::make('posts.show', compact('post'));
 }
 public function mod($method, $post)
 {
     $post = Post::findOrFail($post);
     $group = $post->group_name;
     self::checkMod(self::userFp(), $post->group_name);
     switch ($method) {
         case "del":
             $post->group_name = "";
             $post->save();
             break;
         case "delAll":
             Post::where('user_fp', $post->user_fp)->where('group_name', $post->group_name)->update(['group_name' => '']);
             break;
     }
     return Redirect::to("/g/{$group}?mod=true");
 }
Example #19
0
 public static function shutdown($user_fp, $post_id)
 {
     $post = Post::findOrFail($post_id);
     if ($post->parent_id != 0) {
         $parent_post = Post::find($post->parent_id);
     }
     if ($post->user_fp == $user_fp || isset($parent_post) && $parent_post->user_fp == $user_fp) {
         if ($post->parent_id == 0) {
             //delete thread comments
             $comments = DB::table('posts')->where('parent_id', $post->id)->lists('id');
             Bump::whereIn('post_id', $comments)->delete();
             Post::where('parent_id', $post->id)->delete();
         }
         Bump::where('post_id', $post->id)->delete();
         $post->delete();
     } else {
         App::abort(500, 'Illegal attempt');
     }
     if (isset($parent_post)) {
         $parent_post->timestamps = false;
         $parent_post->replies -= 1;
         $parent_post->save();
         return $parent_post->id;
     } else {
         return false;
     }
 }
 public function show($id)
 {
     $post = Post::findOrFail($id);
     return View::make('show', compact('post'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $post->delete();
     Session::flash('successMessage', 'This post was deleted.');
     return Redirect::route('posts.index');
 }
Example #22
0
    $data["category_links"] = Category::orderBy('id', 'DESC')->get()->take(5);
    $view->with('data', $data);
});
View::composer('view_user_profile', function ($view) {
    $id = $view->getData()["id"];
    $data["user"] = User::findOrFail($id);
    $data["posts"] = $data["user"]->posts()->get();
    $data["comments"] = $data["user"]->comments()->get();
    $view->with('data', $data);
});
View::composer('article_edit', function ($view) {
    $id = $view->getData()["data"]["id"];
    if (isset($view->getData()["data"]["message"])) {
        $data["message"] = $view->getData()["data"]["message"];
    }
    $data["post"] = Post::findOrFail($id);
    $view->with('data', $data);
});
View::composer('category_view', function ($view) {
    $id = $view->getData()["id"];
    $data["category"] = Category::findOrFail($id);
    $data["posts"] = $data["category"]->post()->paginate(5);
    $view->with('data', $data);
});
View::composer('admin_page', function ($view) {
    $data["posts"] = Post::orderBy('id', 'DESC')->get()->take(10);
    $data["unmoderated"] = Post::where('moderated', '=', false)->orderBY('id', 'DESC')->get()->take(10);
    $data["comments"] = Comment::orderBy('id', 'DESC')->get()->take(10);
    $view->with('data', $data);
});
View::composer('manage_users', function ($view) {
Example #23
0
 public function postDeletePost($id)
 {
     try {
         $post = Post::findOrFail($id);
         if ($post->created_by != Auth::id()) {
             return View::make('error.Unauthorized');
         }
         $post->delete();
         return Redirect::to(URL::action('BlogController@getPosts', array('username' => Auth::user()->username)));
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #24
0
 public function delete_article($id)
 {
     $postInstance = Post::findOrFail($id);
     $postAuthor = $postInstance->user()->first();
     if (!Auth::user()->isAdmin() && Auth::user()->username != $postAuthor->username) {
         return Redirect::route('login');
     } else {
         // Also delete all comments:
         $commentsArray = $postInstance->comments()->get();
         foreach ($commentsArray as $oneComment) {
             Comment::destroy($oneComment->id);
         }
         Post::destroy($id);
         return Redirect::route("home");
     }
 }
 public function showWelcome()
 {
     // Hover in your IDE to enjoy code completion.
     // Don't forget to run composer install to bring in teh Laravel IDE helper first :)
     Post::findOrFail(1);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $inputs = Input::all();
     // input validation
     $post = Post::findOrFail($id);
     $post->update($inputs);
     // field_name must match with key_name
     //return Redirect::route('posts.index')->with('failed', 'Failed!!');
     return Redirect::route('posts.index')->with('success', 'Update Ok!!');
 }
 public function upvote($id)
 {
     $post = Post::findOrFail($id);
     Post::bump($post, self::userFp());
     if (isset($_SERVER['HTTP_REFERER'])) {
         return Redirect::back();
     } else {
         return Redirect::to('p/' . $id);
     }
 }
Example #28
0
 public static function getThumbnailForPost($id, $url)
 {
     set_time_limit(120);
     $post = Post::findOrFail($id);
     if ($post->created_at->timestamp < time() - 60) {
         Log::error("post created too early: " . $id . "::" . $url);
         return;
     } else {
         if ($post->thumbnail != "") {
             Log::error("thumb already set: " . $id . "::" . $url);
             return;
         }
     }
     $uri_info = new URIInfo($url);
     $ftype = $uri_info->getContentType();
     $ftype_pieces = explode("/", $ftype);
     $is_text = count($ftype_pieces) == 2 && strcmp($ftype_pieces[0], "text") == 0;
     $image_types = ["image/gif", "image/jpeg", "image/jpg", "image/bmp", "image/png", "image/tiff", "image/svg"];
     $is_image = in_array(strtolower($ftype), $image_types);
     $generated_name = md5($url . time());
     $success = true;
     if (!self::snapThumbAndSave($url, 1024, 572, 128, 72, $is_text, $is_image, public_path() . "/assets/thumbs/small/{$generated_name}.jpg")) {
         $success = false;
     }
     if (!self::snapThumbAndSave($url, 1060, 466, 480, 211, $is_text, $is_image, public_path() . "/assets/thumbs/large/{$generated_name}.jpg")) {
         $success = false;
     }
     $post->thumbnail = $generated_name;
     $post->save();
     return $generated_name . " :: " . $success;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::findOrFail($id);
     $post->delete();
     if (Request::wantsJson()) {
         return Response::json(array('Status' => 'Request Succeeded'));
     } else {
         Session::flash('successMessage', 'This post has been successfully deleted.');
         return Redirect::action('PostsController@index');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     // define rules
     $rules = array('title' => array('required'), 'content' => array('required'));
     // pass input to validator
     $validator = Validator::make(Input::all(), $rules);
     // test if input fails
     /* @TODO : Faire fonctionner le Validator de l'Update !! (a priori, problème avec méthode Edit également) */
     if ($validator->fails()) {
         return Redirect::route('posts.edit', $id)->withErrors($validator)->withInput();
     }
     $title = Input::get('title');
     $content = Input::get('content');
     $slug = Str::slug($title);
     $draft = Input::get('draft');
     $category = Input::get('category');
     $post = Post::findOrFail($id);
     $post->title = $title;
     $post->content = $content;
     $post->slug = $slug;
     $post->draft = $draft;
     $post->category = $category;
     $post->update();
     return Redirect::route('posts.index')->withMessage("L'article a été modifié");
 }