예제 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $firstPost = Post::orderBy('post_id', 'asc')->first()->pluck('created_at');
     $nowTime = Carbon::now()->minute(0)->second(0)->timestamp;
     $boards = Board::all();
     $this->comment("Reviewing all records.");
     while ($firstPost->timestamp < $nowTime) {
         $firstPost = $firstPost->addHour();
         $hourCount = 0;
         foreach ($boards as $board) {
             if ($board->posts_total > 0) {
                 $newRows = $board->createStatsSnapshot($firstPost);
                 $hourCount += $newRows->count();
             }
         }
         if ($hourCount > 0) {
             $this->comment("\tAdded {$hourCount} new stat row(s) from " . $firstPost->diffForHumans());
         }
     }
     // Drop boardlist cache.
     Cache::forget('site.boardlist');
     // Generate boardlist again.
     Board::getBoardsForBoardlist();
 }
 protected function boardListSearch($perPage = 25)
 {
     $input = $this->boardListInput();
     $title = $input['title'];
     $lang = $input['lang'];
     $page = $input['page'];
     $tags = $input['tags'];
     $sfw = $input['sfw'];
     $sort = $input['sort'];
     $sortBy = $input['sortBy'];
     $boards = collect(Board::getBoardsForBoardlist());
     $boards = $boards->filter(function ($item) use($lang, $tags, $sfw, $title) {
         // Are we able to view unindexed boards?
         if (!$item['is_indexed'] && !$this->user->canViewUnindexedBoards()) {
             return false;
         }
         // Are we requesting SFW only?
         if ($sfw && !$item['is_worksafe']) {
             return false;
         }
         // Are we searching by language?
         if ($lang) {
             $boardLang = $item->settings['boardLanguage'];
             if ($lang != $boardLang) {
                 return false;
             }
         }
         // Are we searching tags?
         if ($tags && (!count($item['tags']) || count(array_intersect($tags, array_fetch($item['tags'], 'tag'))) < count($tags))) {
             return false;
         }
         // Are we searching titles and descriptions?
         if ($title && stripos($item['board_uri'], $title) === false && stripos($item['title'], $title) === false && stripos($item['description'], $title) === false) {
             return false;
         }
         return true;
     });
     if ($title || $sort && $sortBy) {
         $sortWeight = $sortBy == "asc" ? -1 : 1;
         $boards = $boards->sort(function ($a, $b) use($title, $sort, $sortWeight) {
             // Sort by active users, then last post time.
             $aw = 0;
             $bw = 0;
             if ($title) {
                 $aw += $a['board_uri'] === $title ? 80 : 0;
                 $aw += stripos($a['board_uri'], $title) !== false ? 40 : 0;
                 $aw += stripos($a['title'], $title) !== false ? 20 : 0;
                 $aw += stripos($a['description'], $title) !== false ? 10 : 0;
                 $bw += $b['board_uri'] === $title ? 80 : 0;
                 $aw += stripos($b['board_uri'], $title) !== false ? 40 : 0;
                 $aw += stripos($b['title'], $title) !== false ? 20 : 0;
                 $aw += stripos($b['description'], $title) !== false ? 10 : 0;
             }
             if ($sort) {
                 if ($a[$sort] > $b[$sort]) {
                     $aw += $sortWeight;
                 } else {
                     if ($a[$sort] < $b[$sort]) {
                         $bw += $sortWeight;
                     }
                 }
             }
             return $bw - $aw;
         });
     }
     $paginator = new LengthAwarePaginator($boards->forPage($page, $perPage), $boards->count(), $perPage, $page);
     $paginator->setPath(url("boards.html"));
     foreach ($input as $inputIndex => $inputValue) {
         if ($inputIndex == "sfw") {
             $inputIndex = (int) (!!$inputValue);
         }
         $paginator->appends($inputIndex, $inputValue);
     }
     return $paginator;
 }
 protected function boardListSearch($perPage = 25)
 {
     $input = $this->boardListInput();
     $title = $input['title'];
     $lang = $input['lang'];
     $page = $input['page'];
     $tags = $input['tags'];
     $sfw = $input['sfw'];
     $boards = Board::getBoardsForBoardlist();
     $boards = $boards->filter(function ($item) use($lang, $tags, $sfw, $title) {
         // Are we able to view unindexed boards?
         if (!$item->is_indexed && !$this->user->canViewUnindexedBoards()) {
             return false;
         }
         // Are we requesting SFW only?
         if ($sfw && !$item->is_worksafe) {
             return false;
         }
         // Are we searching by language?
         if ($lang) {
             $boardLang = $item->settings->where('option_name', 'boardLanguage')->pluck('option_value')->first();
             if ($lang != $boardLang) {
                 return false;
             }
         }
         // Are we searching tags?
         if ($tags && count(array_intersect($tags, $item->tags->pluck('tag')->toArray())) < count($tags)) {
             return false;
         }
         // Are we searching titles and descriptions?
         if ($title && stripos($item->board_uri, $title) === false && stripos($item->title, $title) === false && stripos($item->description, $title) === false) {
             return false;
         }
         return true;
     });
     if ($title) {
         $boards = $boards->sort(function ($a, $b) use($title) {
             // Sort by active users, then last post time.
             $aw = 0;
             $bw = 0;
             if ($a->board_uri === $title) {
                 $aw += 8;
             }
             if (stripos($a->board_uri, $title) !== false) {
                 $aw += 4;
             }
             if (stripos($a->title, $title) !== false) {
                 $aw += 2;
             }
             if (stripos($a->description, $title) !== false) {
                 $aw += 1;
             }
             if ($b->board_uri === $title) {
                 $bw += 8;
             }
             if (stripos($b->board_uri, $title) !== false) {
                 $bw += 4;
             }
             if (stripos($b->title, $title) !== false) {
                 $bw += 2;
             }
             if (stripos($b->description, $title) !== false) {
                 $bw += 1;
             }
             return $bw - $aw;
         });
     }
     $paginator = new LengthAwarePaginator($boards->forPage($page, $perPage), $boards->count(), $perPage, $page);
     $paginator->setPath("boards.html");
     foreach ($input as $inputIndex => $inputValue) {
         if ($inputIndex == "sfw") {
             $inputIndex = (int) (!!$inputValue);
         }
         $paginator->appends($inputIndex, $inputValue);
     }
     return $paginator;
 }
예제 #4
0
 /**
  * Returns the primary navigation board list.
  *
  * @return array|false  Returns false if the setting boardListShow is disabled.
  */
 public function getNavigationPrimaryBoards()
 {
     if ($this->hasDB() && $this->get('boardListShow', false)) {
         if (Cache::has("site.boardlist")) {
             return Cache::remember('site.gnav.boards', 1, function () {
                 $popularBoards = collect();
                 $recentBoards = collect();
                 $popularBoardArray = Board::getBoardsForBoardlist(0, 20);
                 foreach ($popularBoardArray as $popularBoard) {
                     $popularBoards->push(new Board($popularBoard));
                 }
                 $recentBoards = Board::where('posts_total', '>', 0)->whereNotNull('last_post_at')->wherePublic()->whereNotIn('board_uri', $popularBoards->pluck('board_uri'))->select('board_uri', 'title')->orderBy('last_post_at', 'desc')->take(20)->get();
                 return ['popular_boards' => $popularBoards, 'recent_boards' => $recentBoards];
             });
         }
         return ['popular_boards' => collect(), 'recent_boards' => collect()];
     }
     return false;
 }
예제 #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Generate an activity snapshot.
     Board::createStatsSnapshots();
     Board::getBoardsForBoardlist(0, null, true);
 }