/** * @see Form::validate() */ public function validate() { if (!count($this->groupIDs)) { throw new UserInputException('groupIDs', 'empty'); } if (!@is_int($this->maxLifeTime)) { throw new UserInputException('maxLifeTime', 'isNoInteger'); } if (empty($this->subject)) { throw new UserInputException('subject', 'empty'); } if (empty($this->text)) { throw new UserInputException('text', 'empty'); } else { if (StringUtil::length($this->text) > $this->maxTextLength) { throw new UserInputException('text', 'tooLong'); } else { if (defined('ENABLE_CENSORSHIP') && ENABLE_CENSORSHIP) { require_once WCF_DIR . 'lib/data/message/censorship/Censorship.class.php'; $result = Censorship::test($this->text); if ($result) { WCF::getTPL()->assign('censoredWords', $result); throw new UserInputException('text', 'censoredWordsFound'); } } } } parent::validate(); }
/** * Validates message text. */ protected function validateText() { if (empty($this->text)) { throw new UserInputException('text'); } // check text length if ($this->maxTextLength !== null && StringUtil::length($this->text) > $this->maxTextLength) { throw new UserInputException('text', 'tooLong'); } // search for censored words if (ENABLE_CENSORSHIP) { require_once WCF_DIR . 'lib/data/message/censorship/Censorship.class.php'; $result = Censorship::test($this->text); if ($result) { WCF::getTPL()->assign('censoredWords', $result); throw new UserInputException('text', 'censoredWordsFound'); } } }
/** * @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'); } } }
/** * 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'); } } }
/** * Returns censored words from a text. * * @param string $text * @return mixed $matches / false */ public static function test($text) { // reset matches self::$matches = array(); // get words which should be censored $censoredWords = explode("\n", StringUtil::unifyNewlines(StringUtil::toLowerCase(CENSORED_WORDS))); // format censored words $censoredWords = ArrayUtil::trim($censoredWords); // string to lower case $text = StringUtil::toLowerCase($text); // ignore bbcode tags $text = preg_replace('~\\[/?[a-z]+[^\\]]*\\]~i', '', $text); // split the text in single words self::$words = preg_split("!" . self::$delimiters . "+!", $text, -1, PREG_SPLIT_NO_EMPTY); // check each word if it censored. for ($i = 0, $count = count(self::$words); $i < $count; $i++) { $word = self::$words[$i]; foreach ($censoredWords as $censoredWord) { // check for direct matches ("badword" == "badword") if ($censoredWord == $word) { // store censored word if (isset(self::$matches[$word])) { self::$matches[$word]++; } else { self::$matches[$word] = 1; } continue 2; } else { if (StringUtil::indexOf($censoredWord, '*') !== false) { $censoredWord = StringUtil::replace('\\*', '.*', preg_quote($censoredWord)); if (preg_match('!^' . $censoredWord . '$!', $word)) { // store censored word if (isset(self::$matches[$word])) { self::$matches[$word]++; } else { self::$matches[$word] = 1; } continue 2; } } else { if (StringUtil::indexOf($censoredWord, '~') !== false) { $censoredWord = StringUtil::replace('~', '', $censoredWord); if (($position = StringUtil::indexOf($censoredWord, $word)) !== false) { if ($position > 0) { // look behind if (!self::lookBehind($i - 1, StringUtil::substring($censoredWord, 0, $position))) { continue; } } if ($position + StringUtil::length($word) < StringUtil::length($censoredWord)) { // look ahead if ($newIndex = self::lookAhead($i + 1, StringUtil::substring($censoredWord, $position + StringUtil::length($word)))) { $i = $newIndex; } else { continue; } } // store censored word if (isset(self::$matches[$censoredWord])) { self::$matches[$censoredWord]++; } else { self::$matches[$censoredWord] = 1; } continue 2; } } } } } } // at least one censored word was found if (count(self::$matches) > 0) { return self::$matches; } else { return false; } }