/** * Returns a list with category ids of accessible filebase categories. * * @param array $permissions * @return array<integer> */ public static function getAccessibleCategoryIDs(array $permissions = array('canViewCategory')) { $categoryIDs = array(); foreach (CategoryHandler::getInstance()->getCategories('de.incendium.filebase.category') as $category) { $result = true; $category = new FilebaseCategory($category); foreach ($permissions as $permission) { $result = $result && $category->getPermission($permission); } if ($result) { $categoryIDs[] = $category->categoryID; } } return $categoryIDs; }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); $this->validateFileSubject(); // 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 FilebaseCategory($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) > FILEBASE_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 upload $this->validateFileUpload(); // validate 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'); } } }