コード例 #1
0
 /**
  * Shows the home page for the authenticated user.
  * @return Response
  */
 public function home()
 {
     $subscriptions = explode(',', Auth::user()->subscriptions);
     $hubs = Hub::whereIn('name', $subscriptions)->get();
     $posts = [];
     $ids = [];
     foreach ($hubs as $hub) {
         $ids[] = $hub->id;
     }
     $posts = Post::whereIn('hub_id', $ids)->get()->sortByDesc('upvotes');
     foreach ($posts as $post) {
         $hub = Hub::find($post->hub_id);
         if (in_array($post->user_id, explode(',', $hub->moderators))) {
             $post->user_is_mod = true;
         } else {
             $post->user_is_mod = false;
         }
         $user = User::find($post->user_id);
         if ($user->is_admin) {
             $post->user_is_admin = true;
         } else {
             $post->user_is_admin = false;
         }
         $post->username = User::where('id', '=', $post->user_id)->firstOrFail()->username;
         $post->comment_count = Comment::where('post_id', '=', $post->id)->count();
         $post->hub_name = Hub::where('id', '=', $post->hub_id)->firstOrFail()->name;
     }
     return view('user.home', ['posts' => $posts]);
 }
コード例 #2
0
ファイル: Category.php プロジェクト: ALIKALANAD/classifieds
 /**
  * count the total number of posts
  * @return mixed
  */
 public function count_total_posts()
 {
     $id = $this->id;
     return Post::whereIn('category_id', function ($query) use($id) {
         $query->select('id')->from($this->getTable())->where('parent_id', $id);
     })->orWhere('category_id', $id)->whereNull('deleted_at')->count();
 }
コード例 #3
0
ファイル: EsporteController.php プロジェクト: ronal2do/stq001
 /**
  * Display a listing of the resource.
  * @return Response
  */
 public function index()
 {
     $titulo = 'Esporte, cultura e lazer';
     $video = 'https://www.youtube.com/embed/G9wYHaTmpFI';
     $video_nome = 'Feira Literária de São Bernardo no Cenforpe já é sucesso de público';
     $cor = '#ad4b9e';
     $posts = Post::whereIn('categoria_id', [3, 5, 8])->get();
     $rand = array_rand(["#f77985" => "saude", "#be1039" => "educacao", "#69b843" => "infra", "#f87e3a" => "cidadania", "#2a9fe0" => "meio", "#ad4b9e" => "esporte"]);
     return view('programas.categoria', compact('posts', 'titulo', 'cor', 'rand', 'video', 'video_nome'));
 }
コード例 #4
0
ファイル: Post.php プロジェクト: kamyh/KBlog
 public static function get($category, $page)
 {
     $maxPerPage = Config::get('app.max_post_per_page');
     if ($category == null) {
         return Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->skip($maxPerPage * ($page - 1))->take($maxPerPage)->get();
     } else {
         $ids = Category::where('name', '=', $category)->lists('post_id');
         return Post::whereIn('id', $ids)->where('lang', '=', Lang::getLocale())->where('published', '=', 1)->skip($maxPerPage * ($page - 1))->take($maxPerPage)->get();
     }
 }
コード例 #5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     //        $posts = Post::where('category_id', $id)->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
     if ($id == 0) {
         $posts = Post::whereNull('deleted_at')->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
         $category = null;
     } else {
         $category = Category::find($id);
         $posts = Post::whereIn('category_id', function ($query) use($id) {
             //$query->orWhere('category_id', $id);
             $query->select('id')->from(with(new Category())->getTable())->where('parent_id', $id);
         })->orWhere('category_id', $id)->whereNull('deleted_at')->orderBy('created_at', 'desc')->paginate(config('classifieds.posts_per_page'));
     }
     return view('home.category.show', ['posts' => $posts, 'category' => $category]);
 }
コード例 #6
0
 /**
  * Select recipies by filter
  *
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function filterRecipies(Request $request)
 {
     $recipies = Session::get('recipies');
     $idr = $recipies->pluck('id');
     foreach ($request->filtergroup as $idMarker) {
         if ($idMarker > 0) {
             $recipies = Post::whereIn('id', $idr)->where('postStatus_id', '=', 3)->whereHas('markers', function ($q) use($idMarker, $idr) {
                 $q->where('markers.id', '=', $idMarker);
             })->get();
             $idr = $recipies->pluck('id');
         }
     }
     Session::put('recipies', $recipies);
     $title = CmsOption::getValue('Название сайта');
     $metaOptions = ['filter' => $request->filtergroup];
     return view('recipieGrid', ['recipies' => $recipies, 'page_title' => 'Выборка по фильтру', 'title' => $title, 'metaOptions' => $metaOptions]);
 }
コード例 #7
0
 /**
  * 
  */
 public function getMod(Request $request, Board $board, Post $post)
 {
     if (!$post->exists) {
         abort(404);
     }
     // Take trailing arguments,
     // compare them against a list of real actions,
     // intersect the liss to find the true commands.
     $actions = ["delete", "ban", "all", "global"];
     $argList = func_get_args();
     $modActions = array_intersect($actions, array_splice($argList, 2));
     sort($modActions);
     $ban = in_array("ban", $modActions);
     $delete = in_array("delete", $modActions);
     $all = in_array("all", $modActions);
     $global = in_array("global", $modActions);
     if (!$ban && !$delete) {
         return abort(404);
     }
     if ($ban) {
         if ($global && !$this->user->canBanGlobally()) {
             return abort(403);
         } else {
             if (!$this->user->canBan($board)) {
                 return abort(403);
             }
         }
         return $this->view(static::VIEW_MOD, ["actions" => $modActions, "form" => "ban", "board" => $board, "post" => $post, "banMaxLength" => $this->option('banMaxLength')]);
     } else {
         if ($delete) {
             if ($global) {
                 if (!$this->user->canDeleteGlobally()) {
                     return abort(403);
                 }
                 $posts = Post::whereAuthorIP($post->author_ip)->with('reports')->get();
                 $this->log('log.post.delete.global', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
                 Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
                 foreach ($posts as $post) {
                     Event::fire(new PostWasModerated($post, $this->user));
                 }
             } else {
                 if (!$this->user->canDelete($post)) {
                     return abort(403);
                 }
                 if ($all) {
                     $posts = Post::whereAuthorIP($post->author_ip)->where('board_uri', $board->board_uri)->with('reports')->get();
                     $this->log('log.post.delete.local', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "ip" => $post->getAuthorIpAsString(), "posts" => $posts->count()]);
                     Post::whereIn('post_id', $posts->pluck('post_id'))->delete();
                     foreach ($posts as $post) {
                         Event::fire(new PostWasModerated($post, $this->user));
                     }
                 } else {
                     if (!$post->isAuthoredByClient()) {
                         if ($post->reply_to) {
                             $this->log('log.post.delete.reply', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "op_id" => $post->op->board_id]);
                         } else {
                             $this->log('log.post.delete.op', $post, ["board_id" => $post->board_id, "board_uri" => $post->board_uri, "replies" => $post->replies()->count()]);
                         }
                     }
                     $post->delete();
                     Event::fire(new PostWasModerated($post, $this->user));
                 }
             }
             return back();
         }
     }
     return abort(403);
 }
コード例 #8
0
 public function index(Request $request, Post $post)
 {
     $allPosts = $post->whereIn('user_id', $request->user()->following()->lists('users.id')->push($request->user()->id))->with('user');
     $posts = $allPosts->orderBy('created_at', 'desc')->take($request->get('limit', 20))->get();
     return response()->json(['posts' => $posts, 'total' => $allPosts->count()]);
 }
コード例 #9
0
ファイル: PostRepository.php プロジェクト: Jemok/skoolspace
 public function feedForUser($user, $howMany = 10)
 {
     $groupIds = $user->follows()->lists('group_id');
     return Post::whereIn('group_id', $groupIds)->latest()->simplePaginate($howMany);
 }
コード例 #10
0
ファイル: ProfileController.php プロジェクト: vizovteam/vizov
 public function showMyFavorites(Request $request)
 {
     $favorites = $this->getFavorites($request);
     $favorites = $favorites ? $favorites : [];
     $profiles = Profile::take(5)->get();
     $posts = Post::whereIn('id', array_values($favorites))->orderBy('id', 'DESC')->get();
     return view('profile.my_favorites', compact('posts', 'favorites', 'profiles'));
 }
コード例 #11
0
 public static function getFriendsAndUsersPosts()
 {
     $friends = Friend::where('user1_id', Auth::id())->where('is_accepted', 1)->get(['user2_id']);
     $friends->push(['user2_id' => Auth::id()]);
     $posts = Post::whereIn('author_id', $friends)->get();
     return $posts;
 }
コード例 #12
0
ファイル: WelcomeController.php プロジェクト: kamyh/KBlog
 /**
  * @param $category
  * @param $page
  * @return $this
  */
 public function build($category, $page)
 {
     $morePage = 0;
     $posts = Post::get($category, $page);
     if ($category == null) {
         if (Config::get('app.max_post_per_page') * $page < Post::where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
             $morePage = 1;
         }
     } else {
         $ids = Category::where('name', '=', $category)->lists('post_id');
         if (Config::get('app.max_post_per_page') * $page < Post::whereIn('id', $ids)->where('lang', '=', Lang::getLocale())->where('published', '=', 1)->count()) {
             $morePage = 1;
         }
     }
     $this->statistics->incrementPage('welcome');
     return view('welcome')->with(array('posts' => $posts, 'page' => $page, 'category' => $category, 'morePage' => $morePage));
 }
コード例 #13
0
ファイル: Category.php プロジェクト: larabox/larabox
 /**
  * @return mixed
  */
 public function getItemsChildeAndSelf()
 {
     return Post::whereIn('category_id', $this->getChildeAndSelf())->active()->sort()->paginate(15);
 }