Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public function postSearch()
 {
     $query = Input::get('query');
     // find from user
     $data = $user_result = User::where('username', 'LIKE', '%' . $query . '%')->orWhere('full_name', 'LIKE', '%' . $query . '%')->get();
     // find from blog post
     $post_result = Post::where('makrdown', 'LIKE', '%' . $query . '%')->orWhere('title', 'LIKE', '%' . $query . '%')->get();
     foreach ($post_result as $k => $post) {
         if (!PrivacyHelper::checkPermission(Auth::user(), $post)) {
             unset($post_result[$k]);
         } else {
             $post->makrdown = str_limit($post->makrdown, $limit = 500, $end = '...');
             $Parsedown = new Parsedown();
             $post->HTML = $Parsedown->text($post->makrdown);
         }
     }
     $data = $data->merge($post_result);
     // find from task card
     if (Auth::check()) {
         $task_result = Taskcard::where('created_by', Auth::user()->id)->where(function ($q) use($query) {
             $q->where('title', 'LIKE', '%' . $query . '%')->orWhere('content', 'LIKE', '%' . $query . '%');
         })->get();
         foreach ($task_result as $k => $task) {
             $task->content = str_limit($task->content, $limit = 500, $end = '...');
         }
         $data = $data->merge($task_result);
     }
     //$result = json_encode(array_merge(json_decode($user_result, true),json_decode($post_result, true)));
     return View::make('posts.list')->with('data', $data);
     return Response::json($result);
 }