本文整理汇总了PHP中Gdn_Validation::AddValidationResult方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Validation::AddValidationResult方法的具体用法?PHP Gdn_Validation::AddValidationResult怎么用?PHP Gdn_Validation::AddValidationResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Validation
的用法示例。
在下文中一共展示了Gdn_Validation::AddValidationResult方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Index
public function Index()
{
$this->Permission('Garden.Import');
// This permission doesn't exist, so only users with Admin == '1' will succeed.
$Timer = new Gdn_Timer();
// Determine the current step.
$this->Form = new Gdn_Form();
$Imp = new ImportModel();
$Imp->LoadState();
if ($Imp->CurrentStep < 1) {
// Check to see if there is a file.
$ImportPath = Gdn::Config('Garden.Import.ImportPath');
$Validation = new Gdn_Validation();
if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
$Upload = new Gdn_Upload();
$Validation = new Gdn_Validation();
$TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
if ($TmpFile) {
$Filename = $_FILES['ImportFile']['name'];
$Extension = pathinfo($Filename, PATHINFO_EXTENSION);
$TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
if (!file_exists($TargetFolder)) {
mkdir($TargetFolder, 0777, TRUE);
}
$ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
$Upload->SaveAs($TmpFile, $ImportPath);
$Imp->ImportPath = $ImportPath;
$Imp->Data['OriginalFilename'] = basename($Filename);
} elseif (!$Imp->ImportPath) {
// There was no file uploaded this request or before.
$Validation->AddValidationResult('ImportFile', $Upload->Exception);
}
// Validate the overwrite.
if (strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
$Validation->ApplyRule('Email', 'Required');
$Validation->ApplyRule('Password', 'Required');
}
if ($Validation->Validate($this->Form->FormValues())) {
$Imp->Overwrite($this->Form->GetFormValue('Overwrite', 'Overwrite'), $this->Form->GetFormValue('Email'), $this->Form->GetFormValue('Password'));
$this->View = 'Info';
} else {
$this->Form->SetValidationResults($Validation->Results());
}
} else {
// Search for an existing file that was uploaded by the web admin.
$ImportPaths = SafeGlob(PATH_ROOT . DS . 'uploads' . DS . 'import' . DS . 'import.*');
if ($ImportPaths) {
$ImportPath = $ImportPaths[0];
if (in_array(pathinfo($ImportPath, PATHINFO_EXTENSION), array('gz', 'txt'))) {
$Imp->ImportPath = $ImportPath;
$Imp->Data['OriginalFilename'] = basename($ImportPath);
}
}
}
$Imp->SaveState();
} else {
$this->View = 'Info';
}
$this->SetData('Header', $Imp->GetImportHeader());
$this->SetData('ImportPath', $Imp->ImportPath);
$this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
$this->Render();
}
示例2: Index
/**
* Main import page.
*
* @since 2.0.0
* @access public
*/
public function Index()
{
$this->Permission('Garden.Import');
// This permission doesn't exist, so only users with Admin == '1' will succeed.
$Timer = new Gdn_Timer();
// Determine the current step.
$this->Form = new Gdn_Form();
$Imp = new ImportModel();
$Imp->LoadState();
// Search for the list of acceptable imports.
$ImportPaths = array();
$ExistingPaths = SafeGlob(PATH_ROOT . '/uploads/export*', array('gz', 'txt'));
foreach ($ExistingPaths as $Path) {
$ImportPaths[$Path] = basename($Path);
}
// Add the database as a path.
$ImportPaths = array_merge(array('db:' => T('This Database')), $ImportPaths);
if ($Imp->CurrentStep < 1) {
// Check to see if there is a file.
$ImportPath = C('Garden.Import.ImportPath');
$Validation = new Gdn_Validation();
if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
$Upload = new Gdn_Upload();
$Validation = new Gdn_Validation();
if (count($ImportPaths) > 0) {
$Validation->ApplyRule('PathSelect', 'Required', T('You must select a file to import.'));
}
if (count($ImportPaths) == 0 || $this->Form->GetFormValue('PathSelect') == 'NEW') {
$TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
} else {
$TmpFile = '';
}
if ($TmpFile) {
$Filename = $_FILES['ImportFile']['name'];
$Extension = pathinfo($Filename, PATHINFO_EXTENSION);
$TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
if (!file_exists($TargetFolder)) {
mkdir($TargetFolder, 0777, TRUE);
}
$ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
$Upload->SaveAs($TmpFile, $ImportPath);
$Imp->ImportPath = $ImportPath;
$this->Form->SetFormValue('PathSelect', $ImportPath);
$UploadedFiles = GetValue('UploadedFiles', $Imp->Data);
$UploadedFiles[$ImportPath] = basename($Filename);
$Imp->Data['UploadedFiles'] = $UploadedFiles;
} elseif ($PathSelect = $this->Form->GetFormValue('PathSelect')) {
if ($PathSelect == 'NEW') {
$Validation->AddValidationResult('ImportFile', 'ValidateRequired');
} else {
$Imp->ImportPath = $PathSelect;
}
} elseif (!$Imp->ImportPath && count($ImportPaths) == 0) {
// There was no file uploaded this request or before.
$Validation->AddValidationResult('ImportFile', $Upload->Exception);
}
// Validate the overwrite.
if (TRUE || strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
if (!StringBeginsWith($this->Form->GetFormValue('PathSelect'), 'Db:', TRUE)) {
$Validation->ApplyRule('Email', 'Required');
if (!$this->Form->GetFormValue('UseCurrentPassword')) {
$Validation->ApplyRule('Password', 'Required');
}
}
}
if ($Validation->Validate($this->Form->FormValues())) {
$this->Form->SetFormValue('Overwrite', 'overwrite');
$Imp->FromPost($this->Form->FormValues());
$this->View = 'Info';
} else {
$this->Form->SetValidationResults($Validation->Results());
}
} else {
$this->Form->SetFormValue('PathSelect', $Imp->ImportPath);
}
$Imp->SaveState();
} else {
$this->SetData('Steps', $Imp->Steps());
$this->View = 'Info';
}
if (!StringBeginsWith($Imp->ImportPath, 'db:') && !file_exists($Imp->ImportPath)) {
$Imp->DeleteState();
}
try {
$UploadedFiles = GetValue('UploadedFiles', $Imp->Data, array());
$ImportPaths = array_merge($ImportPaths, $UploadedFiles);
$this->SetData('ImportPaths', $ImportPaths);
$this->SetData('Header', $Imp->GetImportHeader());
$this->SetData('Stats', GetValue('Stats', $Imp->Data, array()));
$this->SetData('GenerateSQL', GetValue('GenerateSQL', $Imp->Data));
$this->SetData('ImportPath', $Imp->ImportPath);
$this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
$this->SetData('CurrentStep', $Imp->CurrentStep);
$this->SetData('LoadSpeedWarning', $Imp->LoadTableType(FALSE) == 'LoadTableWithInsert');
//.........这里部分代码省略.........
示例3: CheckUser
/**
* Add ban data to all Get requests.
*
* @since 2.0.18
* @access public
*
* @param mixed User data (array or object).
* @param Gdn_Validation $Validation
* @param bool $UpdateBlocks
* @return bool Whether user is banned.
*/
public static function CheckUser($User, $Validation = NULL, $UpdateBlocks = FALSE, &$BansFound = NULL)
{
$Bans = self::AllBans();
$Fields = array('Name' => 'Name', 'Email' => 'Email', 'IPAddress' => 'LastIPAddress');
$Banned = array();
if (!$BansFound) {
$BansFound = array();
}
foreach ($Bans as $Ban) {
// Convert ban to regex.
$Parts = explode('*', str_replace('%', '*', $Ban['BanValue']));
$Parts = array_map('preg_quote', $Parts);
$Regex = '`^' . implode('.*', $Parts) . '$`i';
if (preg_match($Regex, GetValue($Fields[$Ban['BanType']], $User))) {
$Banned[$Ban['BanType']] = TRUE;
$BansFound[] = $Ban;
if ($UpdateBlocks) {
Gdn::SQL()->Update('Ban')->Set('CountBlockedRegistrations', 'CountBlockedRegistrations + 1', FALSE, FALSE)->Where('BanID', $Ban['BanID'])->Put();
}
}
}
// Add the validation results.
if ($Validation) {
foreach ($Banned as $BanType => $Value) {
$Validation->AddValidationResult(Gdn_Form::LabelCode($BanType), 'ValidateBanned');
}
}
return count($Banned) == 0;
}