public function singlePost($id)
 {
     $post = Post::find($id);
     $data['date'] = $this->getBaseDateTime();
     if ($post == null) {
         return null;
     }
     if (Auth::check()) {
         if ($post->type == '0') {
             $post = Post::join('users', 'users.id', '=', 'posts.user_id')->select('posts.*')->where('posts.id', $id)->where('users.disable', '0')->whereType('0')->whereIn('posts.user_id', function ($query) {
                 $query->select('friend_id')->from('friend_list')->whereUserId(Auth::user()->id);
             })->orWhere('posts.user_id', Auth::user()->id)->where('users.disable', '0')->whereType('0')->where('posts.id', $id)->first();
             if ($post == null) {
                 return null;
             }
         }
         //
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = Following::whereFollowerId(Auth::user()->id)->whereFollowingId($post->user_id)->get()->count();
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession = $confession->confess;
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // 9-2-Start
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         // 9-2-End
         $data['post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'ago' => $now->diffForHumans());
         $data['notifications'] = $this->getNotification();
         //
     } else {
         if ($post->type == '0') {
             return null;
         }
         //
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = null;
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession = $confession->confess;
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // 9-2-Start
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         //9-2-End
         $data['post'] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => 0, 'disliked' => 0, 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'ago' => $now->diffForHumans());
         //
         $data['notifications'] = ['length' => 0, 'notifications' => null];
     }
     $data['single'] = 1;
     $data['reports'] = Report::get();
     // return json_encode($data['']);
     return View::make('single')->withData($data);
 }
 public function postProcess($posts)
 {
     $data = null;
     $i = 0;
     foreach ($posts as $post) {
         $post = Post::find($post->id);
         //if ($i == 5) break;	///////////////////06-May-2015-Ehsan
         $now = Carbon::parse($post->created_at);
         $feeling = DB::table('feelings')->find($post->feeling)->name;
         $following = Following::whereFollowerId(Auth::user()->id)->whereFollowingId($post->user_id)->get()->count();
         $confession = Confession::whereUserId($post->user_id)->first();
         if ($confession) {
             $confess_time = Carbon::parse($confession->created_at);
             $confess_time = $confess_time->diffInHours();
             //$confess_time = $confess_time->diffInSeconds();
             if ($confess_time < 24) {
                 if ($confession->updated_at < $post->created_at) {
                     $confession_view = ConfessionView::whereConfessionId($confession->id)->whereIsValid(1)->get()->count();
                     $confession = ['id' => $confession->id, 'confess' => $confession->confess, 'view' => $confession_view];
                 } else {
                     $confession = null;
                 }
             } else {
                 $confession = null;
             }
         }
         $user = User::find($post->user_id);
         if ($user->disable == 1) {
             continue;
         }
         $url = Picture::find($user->picture);
         $url = $url->url;
         $text = htmlentities($post->post);
         // Youtube Video Searching
         $pos = strpos($text, 'watch?v=');
         if ($pos != 0) {
             $pos = $pos + 8;
             $str = substr($text, $pos, 11);
             # code...
         } else {
             $str = null;
         }
         //
         $name = null;
         if (($post->type == 1 || $post->type == 3) && !$post->hide_name) {
             $user = User::find($post->user_id);
             $name = $user->username;
         }
         $text = preg_replace('/#([a-zA-Z0-9\\x{0980}-\\x{09FF}_])+/u', '<a href="" class="tags">$0</a>', $text);
         /* Eve-26-May-Ehsan */
         $text = preg_replace('#((https?|ftp)://(\\S*?\\.\\S*?))([\\s)\\[\\]{},;"\':<]|\\.\\s|$)#i', '<a target="_blank" href="$1">$1</a>', $text);
         /* !!!!Eve-26-May-Ehsan */
         $text = nl2br($text);
         $text = Emojione::shortnameToImage($text);
         $data[$i++] = array('id' => $post->id, 'post' => $text, 'user_id' => $post->user_id, 'img' => asset($url), 'confess' => $confession, 'following' => $following, 'type' => $post->type, 'like' => Like::wherePostId($post->id)->get()->count(), 'dislike' => Dislike::wherePostId($post->id)->get()->count(), 'liked' => Like::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'disliked' => Dislike::wherePostId($post->id)->whereUserId(Auth::user()->id)->get()->count(), 'comment' => Comment::wherePostId($post->id)->get()->count(), 'feeling' => $feeling, 'vidsrc' => $str, 'name' => $name, 'ago' => $now->diffForHumans());
     }
     return $data;
 }