コード例 #1
0
 /**
  * Validates the file subject.
  */
 protected function validateFileSubject()
 {
     if (empty($this->fileSubject)) {
         throw new UserInputException('fileSubject');
     }
     if (mb_strlen($this->fileSubject) > 255) {
         $this->fileSubject = mb_substr($this->fileSubject, 0, 255);
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($this->fileSubject);
         if ($result) {
             WCF::getTPL()->assign('censoredWords', $result);
             throw new UserInputException('fileSubject', 'censoredWordsFound');
         }
     }
 }
コード例 #2
0
 /**
  * @see    \wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     $this->validateUsername();
     // validate category ids
     if (empty($this->categoryIDs)) {
         throw new UserInputException('categoryIDs');
     }
     foreach ($this->categoryIDs as $categoryID) {
         $category = CategoryHandler::getInstance()->getCategory($categoryID);
         if ($category === null) {
             throw new UserInputException('categoryIDs');
         }
         $category = new LinklistCategory($category);
         if (!$category->isAccessible() || !$category->getPermission('canUseCategory')) {
             throw new UserInputException('categoryIDs');
         }
     }
     // validate teaser
     if (empty($this->teaser)) {
         throw new UserInputException('teaser');
     }
     if (mb_strlen($this->teaser) > LINKLIST_MAX_TEASER_LENGTH) {
         throw new UserInputException('teaser', 'tooLong');
     }
     // search for censored words
     if (ENABLE_CENSORSHIP) {
         $result = Censorship::getInstance()->test($this->teaser);
         if ($result) {
             WCF::getTPL()->assign('censoredWords', $result);
             throw new UserInputException('teaser', 'censoredWordsFound');
         }
     }
     // validate website
     if (empty($this->website)) {
         throw new UserInputException('website');
     }
     if (!empty($this->website)) {
         if (!preg_match('~^(https?|ftps?)://~', $this->website)) {
             $this->website = 'http://' . $this->website;
         }
         if (filter_var($this->website, FILTER_VALIDATE_URL) === false) {
             throw new UserInputException('website', 'invalid');
         }
     }
 }