예제 #1
0
 /**
  * Tests the board model and depndant views.
  *
  * @return void
  */
 public function testModelAndViews()
 {
     // Get a board.
     $boards = Board::take(1)->get();
     // Get a board that cannot exist.
     // The maximum `board_uri` length should be, at most, 31.
     $noBoards = Board::where('board_uri', "12345678901234567890123456789012")->take(1)->get();
     $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Collection", $boards);
     $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Collection", $noBoards);
     $this->assertEquals(0, count($noBoards));
     if (count($boards)) {
         $this->board = $board = $boards[0];
         $this->assertInstanceOf("App\\Board", $board);
         // Test relationships
         $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Relations\\HasMany", $board->posts());
         $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Relations\\HasMany", $board->logs());
         $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Relations\\HasMany", $board->threads());
         $this->assertInstanceOf("Illuminate\\Database\\Eloquent\\Relations\\HasMany", $board->roles());
         // Test modern routes
         $response = $this->call('GET', url("{$board->board_uri}"));
         $this->assertEquals(200, $response->getStatusCode());
         $this->doBoardIndexAssertions();
         $response = $this->call('GET', url("{$board->board_uri}/1"));
         $this->assertEquals(200, $response->getStatusCode());
         $this->doBoardIndexAssertions();
         $response = $this->call('GET', url("{$board->board_uri}/catalog"));
         $this->assertEquals(200, $response->getStatusCode());
         $response = $this->call('GET', url("{$board->board_uri}/logs"));
         $this->assertEquals(200, $response->getStatusCode());
         $this->assertViewHas('board');
         $this->assertViewHas('logs');
         // Test legacy routes
         $legacyCode = env('LEGACY_ROUTES', false) ? 302 : 404;
         $response = $this->call('GET', url("{$board->board_uri}/index.html"));
         $this->assertEquals($legacyCode, $response->getStatusCode());
         $response = $this->call('GET', url("{$board->board_uri}/1.html"));
         $this->assertEquals($legacyCode, $response->getStatusCode());
         $response = $this->call('GET', url("{$board->board_uri}/catalog.html"));
         $this->assertEquals($legacyCode, $response->getStatusCode());
     } else {
         $this->assertEquals(0, Board::count());
     }
 }
예제 #2
0
 /**
  * Returns a list of board_uris where the canEditConfig permission is given.
  *
  * @return Collection  of Board
  */
 public function getBoardsWithConfigRights()
 {
     $whitelist = true;
     $boardlist = [];
     if ($this->canEditConfig(null)) {
         $whitelist = false;
     }
     foreach ($this->getPermissions() as $board_uri => $permission) {
         if ($this->canEditConfig($board_uri) === $whitelist) {
             $boardlist[] = $board_uri;
         }
     }
     $boardlist = array_unique($boardlist);
     return Board::where(function ($query) use($whitelist, $boardlist) {
         if ($whitelist) {
             $query->whereIn('board_uri', $boardlist);
         } else {
             $query->whereNotIn('board_uri', $boardlist);
         }
     })->andCreator()->andOperator()->andStaffAssignments()->get();
 }
예제 #3
0
 /**
  * Imports board attachments.
  *
  * @return void
  */
 public function importInfinityAttachments()
 {
     $this->info("\tImporting attachments ...");
     Board::where('board_uri', '>=', "jonimu")->orderBy('board_uri', 'asc')->chunk(1, function ($boards) {
         foreach ($boards as $board) {
             FileAttachment::whereForBoard($board)->forceDelete();
             $this->line("\t\tImporting attachments from /{$board->board_uri}/");
             $tTable = $this->tcon->table("posts_{$board->board_uri}");
             $storageLinked = 0;
             $attachmentsMade = 0;
             // Threads first, replies by id.
             $tTable->where('num_files', '>', 0)->orderByRaw('thread asc, id asc')->chunk(200, function ($posts) use(&$board, &$attachmentsMade, &$storageLinked) {
                 $this->line("\t\t\tImporting 200 more posts's attachments ...");
                 $aModels = [];
                 $fModels = [];
                 $skips = 0;
                 // [{
                 // 	"name":"1417727856564.png",
                 // 	"type":"image\/png",
                 // 	"tmp_name":"\/tmp\/php05oN25",
                 // 	"error":0,
                 // 	"size":13034,
                 // 	"filename":"1417727856564.png",
                 // 	"extension":"png",
                 // 	"file_id":"1423141860833",
                 // 	"file":"1423141860833.png",
                 // 	"thumb":"1423141860833.jpg",
                 // 	"is_an_image":true,
                 // 	"hash":"8c63f0b812657c38966ddc7d387a9a4b",
                 // 	"width":223,
                 // 	"height":200,
                 // 	"thumbwidth":223,
                 // 	"thumbheight":200,
                 // 	"file_path":"b\/src\/1423141860833.png",
                 // 	"thumb_path":"b\/thumb\/1423141860833.jpg"
                 // }]
                 // files, num_files, filehash
                 foreach ($posts as $post) {
                 }
                 if (FileAttachment::insert($aModels)) {
                     $attachmentsMade += count($aModels);
                 }
             });
             $this->line("\t\t\tImported {$storageLinked} files with {$attachmentsMade} attachments.");
         }
     });
 }
 /**
  * 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)) {
         return Cache::remember('site.gnav.boards', 1, function () {
             $popularBoards = Board::where('posts_total', '>', 0)->wherePublic()->select('board_uri', 'title')->orderBy('posts_total', 'desc')->take(20)->get();
             $recentBoards = Board::where('posts_total', '>', 0)->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 false;
 }
예제 #5
0
 /**
  * Returns a list of board_uris where the canEditConfig permission is given.
  *
  * @return Collection  of Board
  */
 public function getBoardsWithConfigRights()
 {
     $whitelist = true;
     $boardlist = [];
     if ($this->canEditConfig(null)) {
         $whitelist = false;
     }
     $boardlist = $this->canInBoards('board.config');
     $boardlist = array_unique($boardlist);
     if (empty($boardlist)) {
         return collect();
     }
     return Board::where(function ($query) use($whitelist, $boardlist) {
         if ($whitelist && !in_array(null, $boardlist)) {
             $query->whereIn('board_uri', $boardlist);
         }
     })->andAssets()->andCreator()->andOperator()->andStaffAssignments()->paginate(25);
 }
예제 #6
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;
 }