本文整理汇总了PHP中app\Board::hasBannedUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::hasBannedUri方法的具体用法?PHP Board::hasBannedUri怎么用?PHP Board::hasBannedUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Board
的用法示例。
在下文中一共展示了Board::hasBannedUri方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putCreate
/**
* Allows for the creation of a new board.
*
* @return Response
*/
public function putCreate(Request $request)
{
if (!$this->user->canCreateBoard()) {
return abort(403);
}
$configErrors = [];
// Check time and quantity restraints.
if (!$this->user->canAdminConfig()) {
$boardLastCreated = null;
$boardsOwned = 0;
$boardCreateTimer = $this->option('boardCreateTimer');
$boardsCreateMax = $this->option('boardCreateMax');
if (!$this->user->isAnonymous()) {
foreach ($this->user->createdBoards as $board) {
++$boardsOwned;
if (is_null($boardLastCreated) || $board->created_at->timestamp > $boardLastCreated->timestamp) {
$boardLastCreated = $board->created_at;
}
}
} else {
if (!$this->user->canCreateUser()) {
return abort(403);
}
}
if ($boardsCreateMax > 0 && $boardsOwned >= $boardsCreateMax) {
$configErrors[] = Lang::choice("panel.error.board.create_more_than_max", $boardsCreateMax, ['boardsCreateMax' => $boardsCreateMax]);
}
if ($boardCreateTimer > 0 && (!is_null($boardLastCreated) && $boardLastCreated->diffInMinutes() < $boardCreateTimer)) {
$configErrors[] = Lang::choice("panel.error.board.create_so_soon", $boardLastCreated->addMinutes($boardCreateTimer)->diffInMinutes() + 1, ['boardCreateTimer' => $boardLastCreated->diffInMinutes()]);
}
}
if (count($configErrors)) {
return redirect()->back()->withInput()->withErrors($configErrors);
}
// Validate input.
// If the user is anonymous, we must also be creating an account.
$input = Input::all();
if ($this->user->isAnonymous()) {
$validator = $this->registrationValidator();
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
}
// Generate a list of banned URIs.
$bannedUris = array_filter(explode("\n", $this->option('boardUriBanned')));
$bannedUris[] = "cp";
$bannedUris = implode(",", $bannedUris);
// Validate the basic boardconstraints.
$input['board_uri'] = strtolower((string) $input['board_uri']);
$requirements = ['board_uri' => ["required", "unique:boards,board_uri", "string", "regex:(" . Board::URI_PATTERN . ")"], 'title' => "required|string|between:1,255", 'description' => "string|between:0,255"];
$validator = Validator::make($input, $requirements);
$validator->sometimes('captcha', "required|captcha", function ($input) {
return !$this->user->isAnonymous();
});
// Create the board model.
$board = new Board(['board_uri' => $input['board_uri'], 'title' => $input['title'], 'description' => $input['description'], 'created_by' => $this->user->user_id, 'operated_by' => $this->user->user_id]);
if (!$this->user->canCreateBoardWithBannedUri() && $board->hasBannedUri()) {
$validator->errors()->add('board_uri', 'validation.custom.board_uri_banned');
}
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
// Create user if we have to.
if ($this->user->isAnonymous()) {
$this->auth->login($this->registrar->create($request->all()));
$this->user = $this->auth->user();
}
// Save the board.
$board->save();
// Seed board ownership permissions.
$board->setOwner($this->user);
$this->log("log.board.create", $board->board_uri);
return redirect("cp/board/{$board->board_uri}");
}