当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::getLastPostForIP方法代码示例

本文整理汇总了PHP中app\Post::getLastPostForIP方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::getLastPostForIP方法的具体用法?PHP Post::getLastPostForIP怎么用?PHP Post::getLastPostForIP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Post的用法示例。


在下文中一共展示了Post::getLastPostForIP方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $thread = $this->thread;
     $user = $this->user;
     $validator = $this->getValidatorInstance();
     $messages = $validator->errors();
     $isReply = $this->thread instanceof Post;
     if ($isReply) {
         $floodTime = site_setting('postFloodTime');
         // Check global flood.
         $lastPost = Post::select('created_at')->whereAuthorIP($this->ip())->where('created_at', '>=', \Carbon\Carbon::now()->subSeconds($floodTime))->first();
         if ($lastPost instanceof Post) {
             $timeDiff = $floodTime - $lastPost->created_at->diffInSeconds() + 1;
             $messages->add("flood", trans_choice("validation.custom.post_flood", $timeDiff, ['time_left' => $timeDiff]));
             $this->failedValidation($validator);
             return;
         }
     } else {
         $floodTime = site_setting('threadFloodTime');
         // Check global flood.
         $lastThread = Post::select('created_at')->whereAuthorIP($this->ip())->where('created_at', '>=', \Carbon\Carbon::now()->subSeconds($floodTime))->op()->first();
         if ($lastThread instanceof Post) {
             $timeDiff = $floodTime - $lastThread->created_at->diffInSeconds() + 1;
             $messages->add("flood", trans_choice("validation.custom.thread_flood", $timeDiff, ['time_left' => $timeDiff]));
             $this->failedValidation($validator);
             return;
         }
     }
     // Board-level setting validaiton.
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         if (!$this->user->canAdminConfig() && $board->canPostWithoutCaptcha($this->user)) {
             // Check last post time for flood.
             $floodTime = site_setting('postFloodTime');
             if ($floodTime > 0) {
                 $lastPost = Post::getLastPostForIP();
                 if ($lastPost) {
                     $floodTimer = clone $lastPost->created_at;
                     $floodTimer->addSeconds($floodTime);
                     if ($floodTimer->isFuture()) {
                         $messages->add("body", trans("validation.custom.post_flood", ['time_left' => $floodTimer->diffInSeconds()]));
                     }
                 }
             }
         }
         // Validate individual files being uploaded right now.
         $this->validateOriginality();
     }
     if (count($validator->errors())) {
         $this->failedValidation($validator);
     } else {
         if (!$this->passesAuthorization()) {
             $this->failedAuthorization();
         }
     }
 }
开发者ID:GodOfConquest,项目名称:infinity-next,代码行数:67,代码来源:PostRequest.php

示例2: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $user = $this->user;
     if (is_null($board) || is_null($user)) {
         return parent::validate();
     }
     $validator = $this->getValidatorInstance();
     $messages = $validator->errors();
     // Check global flood.
     $lastPost = Post::where('author_ip', inet_pton($this->ip()))->where('created_at', '>', \Carbon\Carbon::now()->subSeconds(30))->op()->first();
     if ($lastPost instanceof Post) {
         $timeDiff = 30 - $lastPost->created_at->diffInSeconds();
         $messages = $validator->errors();
         $messages->add("flood", trans_choice("validation.custom.thread_flood", $timeDiff, ['time_left' => $timeDiff]));
         $this->failedValidation($validator);
         return;
     }
     // Ban check.
     $ban = Ban::getBan($this->ip(), $board->board_uri);
     if ($ban) {
         $messages = $validator->errors();
         $messages->add("body", trans("validation.custom.banned"));
         $this->ban = $ban;
         $this->failedValidation($validator);
         return;
     }
     // Board-level setting validaiton.
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         if (!$this->user->canAdminConfig() && $board->canPostWithoutCaptcha($this->user)) {
             // Check last post time for flood.
             $floodTime = site_setting('postFloodTime');
             if ($floodTime > 0) {
                 $lastPost = Post::getLastPostForIP();
                 if ($lastPost) {
                     $floodTimer = clone $lastPost->created_at;
                     $floodTimer->addSeconds($floodTime);
                     if ($floodTimer->isFuture()) {
                         $messages->add("body", trans("validation.custom.post_flood", ['time_left' => $floodTimer->diffInSeconds()]));
                     }
                 }
             }
         }
         // Validate individual files.
         $input = $this->all();
         // Process uploads.
         if (isset($input['files'])) {
             $uploads = $input['files'];
             if (count($uploads) > 0) {
                 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())) {
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                     }
                 }
             }
         }
     }
     if (count($validator->errors())) {
         $this->failedValidation($validator);
     }
 }
开发者ID:spanishtech,项目名称:infinity-next,代码行数:73,代码来源:PostRequest.php

示例3: validate

 /**
  * Validate the class instance.
  * This overrides the default invocation to provide additional rules after the controller is setup.
  *
  * @return void
  */
 public function validate()
 {
     $board = $this->board;
     $user = $this->user;
     if (!$board || !$user) {
         return parent::validate();
     }
     $validator = $this->getValidatorInstance();
     $validator->sometimes('captcha', "required|captcha", function ($input) use($board) {
         return !$board->canPostWithoutCaptcha($this->user);
     });
     if (!$validator->passes()) {
         $this->failedValidation($validator);
     } else {
         if (!$this->user->canAdminConfig() && $board->canPostWithoutCaptcha($this->user)) {
             // Check last post time for flood.
             $floodTime = site_setting('postFloodTime');
             if ($floodTime > 0) {
                 $lastPost = Post::getLastPostForIP();
                 if ($lastPost) {
                     $floodTimer = clone $lastPost->created_at;
                     $floodTimer->addSeconds($floodTime);
                     if ($floodTimer->isFuture()) {
                         $messages = $validator->errors();
                         $messages->add("body", trans("validation.custom.post_flood", ['time_left' => $floodTimer->diffInSeconds()]));
                         $this->failedValidation($validator);
                     }
                 }
             }
         }
         // This is a hack, but ...
         // If a file is uploaded that has a specific filename, it breaks the process.
         $input = $this->all();
         // Process uploads.
         if (isset($inpput['files'])) {
             $uploads = $input['files'];
             if (count($uploads) > 0) {
                 foreach ($uploads as $uploadIndex => $upload) {
                     if (method_exists($upload, "getPathname") && !file_exists($upload->getPathname())) {
                         $messages = $validator->errors();
                         $messages->add("files.{$uploadIndex}", trans("validation.custom.file_corrupt", ["filename" => $upload->getClientOriginalName()]));
                         $this->failedValidation($validator);
                         break;
                     }
                 }
             }
         }
     }
 }
开发者ID:Ryangr0,项目名称:infinity-next,代码行数:55,代码来源:PostRequest.php


注:本文中的app\Post::getLastPostForIP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。