Example #1
0
 /**
  * @see	\wcf\form\IForm::validate()
  */
 public function validate()
 {
     parent::validate();
     // validate title
     if (!I18nHandler::getInstance()->validateValue('title')) {
         if (I18nHandler::getInstance()->isPlainValue('title')) {
             throw new UserInputException('title');
         } else {
             throw new UserInputException('title', 'multilingual');
         }
     }
     // validate alias
     $this->validateAlias();
     // validate description
     if (!I18nHandler::getInstance()->validateValue('description', false, true)) {
         throw new UserInputException('description', 'multilingual');
     }
     // validate meta description
     if (!I18nHandler::getInstance()->validateValue('metaDescription', false, true)) {
         throw new UserInputException('metaDescription', 'multilingual');
     }
     // validate meta keywords
     if (!I18nHandler::getInstance()->validateValue('metaKeywords', false, true)) {
         throw new UserInputException('metaKeywords', 'multilingual');
     }
     // validate parent page
     if ($this->parentID) {
         $parentPage = PageCache::getInstance()->getPage($this->parentID);
         if ($parentPage === null) {
             $this->parentID = 0;
         }
     }
     // validate publication date
     if ($this->enableDelayedPublication) {
         $publicationDateTimestamp = @strtotime($this->publicationDate);
         if ($publicationDateTimestamp === false || $publicationDateTimestamp <= TIME_NOW) {
             throw new UserInputException('publicationDate', 'notValid');
         }
         // integer overflow
         if ($publicationDateTimestamp > 2147483647) {
             throw new UserInputException('publicationDate', 'notValid');
         }
     }
     // validate deactivation date
     if ($this->enableDelayedDeactivation) {
         $deactivationDateTimestamp = @strtotime($this->deactivationDate);
         if ($deactivationDateTimestamp === false || $deactivationDateTimestamp <= TIME_NOW) {
             throw new UserInputException('deactivationDate', 'notValid');
         }
         // integer overflow
         if ($deactivationDateTimestamp > 2147483647) {
             throw new UserInputException('deactivationDate', 'notValid');
         }
         // deactivation date needs to be after publication date
         if ($this->enableDelayedPublication && $deactivationDateTimestamp < $publicationDateTimestamp) {
             throw new UserInputException('deactivationDate', 'beforePublication');
         }
     }
     // validate menu item
     if ($this->createMenuItem) {
         $this->menuItemID = 0;
     }
     if ($this->menuItemID) {
         $menuItem = new PageMenuItem($this->menuItemID);
         if (!$menuItem->menuItemID) {
             // silently ignore menu item, user shouldn't be
             // able to select this menu item in first place
             $this->menuItemID = 0;
         }
     }
     // validate style
     if ($this->styleID && !isset($this->availableStyles[$this->styleID])) {
         throw new UserInputException('styleID', 'notValid');
     }
     // validate stylesheets
     $stylesheetList = new StylesheetList();
     $stylesheetList->setObjectIDs($this->stylesheetIDs);
     $stylesheetList->readObjects();
     $this->stylesheetIDs = array();
     foreach ($stylesheetList as $stylesheet) {
         $this->stylesheetIDs[] = $stylesheet->stylesheetID;
     }
     // validate sidebar orientation
     if (!in_array($this->sidebarOrientation, array('left', 'right'))) {
         // force default value if invalid sidebar orientation
         // specified
         $this->sidebarOrientation = 'right';
     }
 }