public function getMore($excludes)
 {
     $excludes = explode("SEPARATOR", $excludes);
     $whereString = "";
     foreach ($excludes as $exclude) {
         $whereString = $whereString . "slug != ? AND ";
     }
     $whereString = substr($whereString, 0, -5);
     $posts = Post::whereRaw($whereString, $excludes)->take(3)->orderBy("created_at", "desc")->get();
     return view("posts.ajax")->with("posts", $posts);
 }
Example #2
0
 public function postsList($nodeId = '')
 {
     $nodeIds = DB::table('node_hierarchy')->where('node_parent_id', '=', $nodeId)->lists('node_id');
     $nodeIds = array_merge($nodeIds, [$nodeId]);
     $nodeIds = implode(',', $nodeIds);
     //        if($nodeId==''){
     //            $posts = Post::paginate(10);
     //            $node = '';
     //        }else{
     $posts = Post::whereRaw("node_id in ({$nodeIds})")->orderBy('created_at', 'DESC')->paginate(6);
     $node = Node::find($nodeId);
     //        }
     //dd(response()->json(view('home.post.posts',compact('posts'))->render()));
     if (Request::ajax()) {
         return response()->json(view('home.post.posts', compact('posts'))->render());
     }
     return view('home.post.index', compact('posts', 'node'));
 }
Example #3
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     # Share variable cross views
     if (Schema::hasTable('posts')) {
         $totalnewposts = Post::whereRaw('DATE(created_at) >= DATE_SUB(NOW(),INTERVAL 30 DAY)')->count();
     } else {
         $totalnewposts = 0;
     }
     # Get all backgrounds filenames in an array
     # For random Background $backgrounds->random()
     $backgrounds = collect(Storage::disk('backgrounds')->allFiles());
     view()->share(['totalnewposts' => $totalnewposts, 'backgrounds' => $backgrounds]);
     Validator::extend('farsi', function ($attribute, $value, $parameters) {
         return preg_match('/^[اآإأبپتثجچحخدذرزژسشصضظطعغفقکگلمنوؤهةۀیئيءـًٌٍَُِِّ\\s]+$/', $value);
     });
     Blade::extend(function ($value) {
         return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value);
     });
 }
Example #4
0
 /**
  * @param $pid
  * @return \Response
  */
 public function show($pid)
 {
     if (empty($pid) || is_null($pid)) {
         abort(404);
     }
     $post = Post::findOrFail($pid);
     $prevPost = Post::whereRaw('id = (select max(id) from posts where id < ' . $pid . ')')->limit(1)->orderBy('id', 'asc')->first();
     $nextPost = Post::whereRaw('id = (select min(id) from posts where id > ' . $pid . ')')->limit(1)->orderBy('id', 'asc')->first();
     $data = ['post' => $post, 'photos' => [], 'videos' => [], 'links' => [], 'audios' => [], 'polls' => [], 'prevPostUrl' => is_null($prevPost) ? null : route('post_show', ['pid' => $prevPost->id]), 'nextPostUrl' => is_null($nextPost) ? null : route('post_show', ['pid' => $nextPost->id])];
     if (!is_null($post->attachments)) {
         foreach ($post->attachments as $attachment) {
             if ($attachment->type === 'album') {
                 $photos = $attachment->childs;
                 foreach ($photos as $photo) {
                     array_push($data['photos'], $photo);
                 }
                 continue;
             }
             array_push($data[$attachment->type . 's'], $attachment);
         }
     }
     return view('post.post', $data);
 }
Example #5
0
 /**
  * just a small API request to find the next slug
  * @param  Request $request [description]
  * @return [type]           [description]
  */
 public function slug(Request $request)
 {
     if (!$request->has('slug')) {
         return response()->json(['valid' => false, 'slug' => '']);
     }
     // generate the default slug
     $slug = str_slug($request->input('slug'));
     // check to see if one already exists
     $lastSlug = Post::whereRaw("slug RLIKE '^" . $slug . "(-[0-9]*)?\$'")->latest('created_at')->value('slug');
     if ($lastSlug) {
         // explode the parts
         $parts = explode('-', $lastSlug);
         $number = end($parts);
         $slug .= '-' . ($number + 1);
     }
     return response()->json(['valid' => true, 'slug' => $slug]);
 }
Example #6
0
 public function filterCategory(Request $request)
 {
     $posts = \App\Post::whereRaw('published_at <= ? and category_id = ?', array(Carbon::now(), $request->input("category")->value))->paginate(config('blog.posts_per_page'));
     return view('blog.index', compact('posts'));
 }