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


PHP Gdn_Validation::addValidationResult方法代码示例

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


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

示例1: 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_UPLOADS . '/export*', array('gz', 'txt'));
     $ExistingPaths2 = SafeGlob(PATH_UPLOADS . '/porter/export*', array('gz'));
     $ExistingPaths = array_merge($ExistingPaths, $ExistingPaths2);
     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 = val('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 ($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 = val('UploadedFiles', $Imp->Data, array());
         $ImportPaths = array_merge($ImportPaths, $UploadedFiles);
         $this->setData('ImportPaths', $ImportPaths);
         $this->setData('Header', $Imp->getImportHeader());
         $this->setData('Stats', val('Stats', $Imp->Data, array()));
         $this->setData('GenerateSQL', val('GenerateSQL', $Imp->Data));
         $this->setData('ImportPath', $Imp->ImportPath);
         $this->setData('OriginalFilename', val('OriginalFilename', $Imp->Data));
         $this->setData('CurrentStep', $Imp->CurrentStep);
         $this->setData('LoadSpeedWarning', $Imp->loadTableType(false) == 'LoadTableWithInsert');
     } catch (Gdn_UserException $Ex) {
//.........这里部分代码省略.........
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:101,代码来源:class.importcontroller.php

示例2: 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, val($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;
 }
开发者ID:sitexa,项目名称:vanilla,代码行数:40,代码来源:class.banmodel.php

示例3: validate

 /**
  * Validate data to be used as class properties.
  *
  * @param array $Parameters .
  * @return string|true True on success or string (message) on error.
  */
 public function validate($Parameters = array())
 {
     $validation = new Gdn_Validation();
     // Validate integer properties.
     $validation->applyRule('expiry', 'Integer');
     $validation->applyRule('limit', 'Integer');
     $validation->applyRule('bodylimit', 'Integer');
     $validation->applyRule('titlelimit', 'Integer');
     $validation->applyRule('group', 'Integer');
     // Validate selection.
     $validation->applyRule('selection', 'String');
     // Validate selector.
     $validation->applyRule('selector', 'Required');
     $selectorWhitelist = array('role', 'rank', 'category', 'score', 'promoted');
     if (isset($Parameters['selector']) && !in_array($Parameters['selector'], $selectorWhitelist)) {
         $validation->addValidationResult('selector', 'Invalid selector.');
     }
     // Validate ContentType.
     $typeWhitelist = array('all', 'discussions', 'comments');
     if (isset($Parameters['contenttype']) && !in_array($Parameters['contenttype'], $typeWhitelist)) {
         $validation->addValidationResult('contenttype', 'Invalid contenttype.');
     }
     $result = $validation->validate($Parameters);
     return $result === true ? true : $validation->resultsText();
 }
开发者ID:caidongyun,项目名称:vanilla,代码行数:31,代码来源:class.promotedcontentmodule.php

示例4: enablePlugin

 /**
  *
  *
  * @param $pluginName
  * @param Gdn_Validation $validation
  * @param bool $setup
  * @return bool
  * @throws Exception
  * @throws Gdn_UserException
  */
 public function enablePlugin($pluginName, $validation, $setup = true)
 {
     // Check to see if the plugin is already enabled.
     if ($this->addonManager->isEnabled($pluginName, Addon::TYPE_ADDON)) {
         throw new Gdn_UserException(t('The plugin is already enabled.'));
     }
     $addon = $this->addonManager->lookupAddon($pluginName);
     if (!$addon) {
         throw notFoundException('Plugin');
     }
     if (!$validation instanceof Gdn_Validation) {
         $validation = new Gdn_Validation();
     }
     try {
         $this->addonManager->checkRequirements($addon, true);
         $addon->test(true);
     } catch (\Exception $ex) {
         $validation->addValidationResult('addon', '@' . $ex->getMessage());
         return false;
     }
     // Enable this addon's requirements.
     $requirements = $this->addonManager->lookupRequirements($addon, AddonManager::REQ_DISABLED);
     foreach ($requirements as $addonKey => $row) {
         $requiredAddon = $this->addonManager->lookupAddon($addonKey);
         $this->enableAddon($requiredAddon, $setup);
     }
     // Enable the addon.
     $this->enableAddon($addon, $setup);
     // Refresh the locale just in case there are some translations needed this request.
     Gdn::locale()->refresh();
     $this->EventArguments['AddonName'] = $addon->getRawKey();
     $this->fireEvent('AddonEnabled');
     return true;
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:44,代码来源:class.pluginmanager.php


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