Пример #1
0
 protected function validateOriginality()
 {
     $board = $this->board;
     $thread = $this->thread;
     $user = $this->user;
     $input = $this->all();
     $validated = true;
     $validator = $this->getValidatorInstance();
     $messages = $validator->errors();
     // Process uploads.
     if (isset($input['files'])) {
         $uploads = $input['files'];
         if (count($uploads) > 0) {
             // Standard upload originality and integrity checks.
             if (!$this->dropzone) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     // If a file is uploaded that has a specific filename, it breaks the process.
                     if (method_exists($upload, "getPathname") && !file_exists($upload->getPathname())) {
                         $validated = false;
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                     }
                 }
             }
             if ($board->getConfig('originalityImages')) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     if (!$upload instanceof UploadedFile) {
                         continue;
                     }
                     if ($board->getConfig('originalityImages') == "thread") {
                         if ($thread instanceof Post && ($originalPost = FileStorage::checkUploadExists($upload, $board, $thread))) {
                             $validated = false;
                             $messages->add("files.{$uploadIndex}", trans("validation.custom.unoriginal_image_thread", ["filename" => $upload->getClientOriginalName(), "url" => $originalPost->getURL()]));
                         }
                     } else {
                         if ($originalPost = FileStorage::checkUploadExists($upload, $board)) {
                             $validated = false;
                             $messages->add("files.{$uploadIndex}", trans("validation.custom.unoriginal_image_board", ["filename" => $upload->getClientOriginalName(), "url" => $originalPost->getURL()]));
                         }
                     }
                 }
             }
         } else {
             if ($board->getConfig('originalityImages')) {
                 foreach ($uploads['hash'] as $uploadIndex => $upload) {
                     if ($board->getConfig('originalityImages') == "thread") {
                         if ($thread instanceof Post && ($originalPost = FileStorage::checkHashExists($upload, $board, $thread))) {
                             $validated = false;
                             $messages->add("files.{$uploadIndex}", trans("validation.custom.unoriginal_image_thread", ["filename" => $uploads['name'][$uploadIndex], "url" => $originalPost->getURL()]));
                         }
                     } else {
                         if ($originalPost = FileStorage::checkHashExists($upload, $board)) {
                             $validated = false;
                             $messages->add("files.{$uploadIndex}", trans("validation.custom.unoriginal_image_board", ["filename" => $uploads['name'][$uploadIndex], "url" => $originalPost->getURL()]));
                         }
                     }
                 }
             }
         }
     }
     // Process body checksum for origianlity.
     $strictness = $board->getConfig('originalityPosts');
     if (isset($input['body']) && $strictness) {
         $checksum = Post::makeChecksum($input['body']);
         if ($strictness == "board" || $strictness == "boardr9k") {
             $checksums = PostChecksum::getChecksum($checksum, $board);
         } else {
             if ($strictness == "site" || $strictness == "siter9k") {
                 $checksums = PostChecksum::getChecksum($checksum);
             }
         }
         //dd($checksums);
         if ($checksums->count()) {
             $validated = false;
             $messages->add("body", trans("validation.custom.unoriginal_content"));
             // If we are in R9K mode, set $respectTheRobot property to to false.
             // This will trigger a Robot ban in failedValidation.
             $this->respectTheRobot = !($strictness == "boardr9k" || $strictness == "siter9k");
         }
     }
     if ($validated !== true) {
         $this->failedValidation($validator);
         return;
     }
 }