/**
  * @see	\wcf\system\user\activity\event\IUserActivityEvent::prepare()
  */
 public function prepare(array $events)
 {
     $commentIDs = array();
     foreach ($events as $event) {
         $commentIDs[] = $event->objectID;
     }
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add('comment.commentID IN (?)', array($objectIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     foreach ($events as $event) {
         if (isset($comments[$event->objectID])) {
             $comment = $comments[$event->objectID];
             $page = PageCache::getInstance()->getPage($comment->objectID);
             if ($page !== null) {
                 if (!$page->canRead()) {
                     continue;
                 }
                 $event->setIsAccessible();
                 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.pageComment', array('page' => $page));
                 $event->setTitle($text);
                 $event->setDescription($comment->getFormattedMessage());
                 continue;
             }
         }
         $event->setIsOrphaned();
     }
 }
Exemple #2
0
 /**
  * Finds and activates the related menu item for the given page. This
  * function handles inherited menu items from parent pages and
  * activates the most important menu item for the given page.
  * Do notice that only header menu items are relevant for the search.
  * 
  * @param	\cms\data\page\Page	$page
  */
 public static function setActiveMenuItem(Page $page)
 {
     $menuItemIDs = $menuItems = array();
     // 1) Create an array with all menu item ids of all parent
     //    pages. Menu items are sorted by their importance. The
     //    first entry is the most important, the last the least
     //    important.
     if ($page->menuItemID) {
         $menuItemIDs[] = $page->menuItemID;
     }
     while ($page->parentPageID && ($page = PageCache::getInstance()->getPage($page->parentPageID))) {
         if ($page->menuItemID) {
             $menuItemIDs[] = $page->menuItemID;
         }
     }
     // 2) Search through all header menu items and check whether
     //    they are related to the page or its parent pages. Found
     //    menu items are again sorted by their importance.
     foreach (PageMenu::getInstance()->getMenuItems('header') as $menuItem) {
         if (($position = array_search($menuItem->menuItemID, $menuItemIDs)) !== false) {
             $menuItems[$position] = $menuItem->menuItem;
         }
         foreach (PageMenu::getInstance()->getMenuItems($menuItem->menuItem) as $subMenuItem) {
             if (($position = array_search($subMenuItem->menuItemID, $menuItemIDs)) !== false) {
                 $menuItems[$position] = $subMenuItem->menuItem;
             }
         }
     }
     // 3) Active the most important menu item for this page.
     if (!empty($menuItems)) {
         $menuItem = array_shift($menuItems);
         PageMenu::getInstance()->setActiveMenuItem($menuItem);
     }
 }
 /**
  * @see	\wcf\system\option\IOptionType::validate()
  */
 public function validate(Option $option, $newValue)
 {
     if (!empty($newValue)) {
         if (PageCache::getInstance()->getPage($newValue) === null) {
             throw new UserInputException($option->optionName, 'validationFailed');
         }
     }
 }
Exemple #4
0
 /**
  * @see	\wcf\system\user\online\location\IUserOnlineLocation::get()
  */
 public function get(UserOnline $user, $languageVariable = '')
 {
     $page = PageCache::getInstance()->getPage($user->objectID);
     if (!$page || !$page->canRead()) {
         return '';
     }
     return WCF::getLanguage()->getDynamicVariable($languageVariable, array('page' => $page));
 }
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['pageID'])) {
         $this->pageID = intval($_REQUEST['pageID']);
     }
     $this->page = PageCache::getInstance()->getPage($this->pageID);
     if ($this->page === null) {
         throw new IllegalLinkException();
     }
 }
 /**
  * @see	\wcf\system\user\object\watch\IUserObjectWatch::validateObjectID()
  */
 public function validateObjectID($objectID)
 {
     $page = PageCache::getInstance()->getPage($objectID);
     if ($page === null) {
         throw new IllegalLinkException();
     }
     // check permission
     if (!$page->canRead()) {
         throw new PermissionDeniedException();
     }
 }
 /**
  * @see	\wcf\system\option\IOptionType::validate()
  */
 public function validate(Option $option, $newValue)
 {
     if (!is_array($newValue)) {
         $newValue = array();
     }
     $newValue = ArrayUtil::toIntegerArray($newValue);
     foreach ($newValue as $pageID) {
         if (PageCache::getInstance()->getPage($pageID) === null) {
             throw new UserInputException($option->optionName, 'validationFailed');
         }
     }
 }
 /**
  * Returns the page this menu item links to.
  * 
  * @var	\cms\data\page\Page
  */
 public function getPage()
 {
     if ($this->page === null) {
         $matches = array();
         preg_match('/id=(\\d+)/', $this->menuItemLink, $matches);
         if (isset($matches[1])) {
             $this->page = PageCache::getInstance()->getPage($matches[1]);
         } else {
             $this->page = PageCache::getInstance()->getHomePage();
         }
     }
     return $this->page;
 }
Exemple #9
0
 /**
  * Returns true if the given alias is available at the given position.
  * With the optional third parameter, you can specifiy a page that is
  * excluded from checking agains. For example, you can use that to
  * exclude the page the new alias will be assigned to.
  * 
  * @param	string		$alias        	
  * @param	integer		$parentPageID        	
  * @param	integer		$excludedPageID        	
  * @return	boolean
  */
 public static function isAvailableAlias($alias, $parentPageID, $excludedPageID = null)
 {
     $childIDs = PageCache::getInstance()->getChildIDs($parentPageID);
     if (!empty($childIDs)) {
         foreach ($childIDs as $childID) {
             if ($childID == $excludedPageID) {
                 continue;
             }
             $page = PageCache::getInstance()->getPage($childID);
             if ($page->alias == $alias) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * @see	\wcf\system\user\activity\event\IUserActivityEvent::prepare()
  */
 public function prepare(array $events)
 {
     $commentsIDs = $responseIDs = $userIDs = array();
     foreach ($events as $event) {
         $responseIDs[] = $event->objectID;
     }
     $responseList = new CommentResponseList();
     $responseList->setObjectIDs($responseIDs);
     $responseList->readObjects();
     $responses = $responseList->getObjects();
     foreach ($responses as $response) {
         $commentIDs[] = $response->commentID;
     }
     $commentList = new CommentList();
     $commentList->setObjectIDs($commentIDs);
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     foreach ($comments as $comment) {
         if (!in_array($comment->userID, $userIDs)) {
             $userIDs[] = $comment->userID;
         }
     }
     $userList = new UserList();
     $userList->setObjectIDs($userIDs);
     $userList->readObjects();
     $users = $userList->getObjects();
     foreach ($events as $event) {
         if (isset($responses[$event->objectID])) {
             $response = $responses[$event->objectID];
             $comment = $comments[$response->commentID];
             $page = PageCache::getInstance()->getPage($comment->objectID);
             if ($page !== null && isset($users[$comment->userID])) {
                 if (!$page->canRead()) {
                     continue;
                 }
                 $event->setIsAccessible();
                 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.pageCommentResponse', array('author' => $users[$comment->userID], 'page' => $pages[$comment->objectID]));
                 $event->setTitle($text);
                 $event->setDescription($response->getFormattedMessage());
                 continue;
             }
         } else {
             $event->setIsOrphaned();
         }
     }
 }
Exemple #11
0
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     // set default values for author and last editor
     if (!isset($this->parameters['data']['authorID'])) {
         $this->parameters['data']['authorID'] = WCF::getUser()->userID;
         $this->parameters['data']['authorName'] = WCF::getUser()->username;
     }
     if (!isset($this->parameters['data']['lastEditorID'])) {
         $this->parameters['data']['lastEditorID'] = $this->parameters['data']['authorID'];
         $this->parameters['data']['lastEditorName'] = $this->parameters['data']['authorName'];
     }
     // set default values for creation- and last edit time
     if (!isset($this->parameters['data']['creationTime'])) {
         $this->parameters['data']['creationTime'] = TIME_NOW;
     }
     if (!isset($this->parameters['data']['lastEditTime'])) {
         $this->parameters['data']['lastEditTime'] = $this->parameters['data']['creationTime'];
     }
     // create page itself
     $page = parent::create();
     $pageEditor = new PageEditor($page);
     // handle stylesheets
     if (isset($this->parameters['stylesheetIDs']) && !empty($this->parameters['stylesheetIDs'])) {
         $pageEditor->updateStylesheetIDs($this->parameters['stylesheetIDs']);
     }
     // check if first page
     if (PageCache::getInstance()->getHomePage() === null) {
         $pageEditor->setAsHome();
     }
     // trigger publication
     if (!$page->isDisabled && $page->isPublished) {
         $action = new PageAction(array($pageEditor), 'triggerPublication');
         $action->executeAction();
     }
     return $page;
 }
Exemple #12
0
 /**
  * Returns the ids of the stylesheets of this page.
  * 
  * @return	array<integer>
  */
 public function getStylesheetIDs()
 {
     return PageCache::getInstance()->getStylesheetIDs($this->pageID);
 }
Exemple #13
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';
     }
 }
 /**
  * @see	\wcf\system\user\notification\event\IUserNotificationEvent::getLink()
  */
 public function getLink()
 {
     $comment = new Comment($this->userNotificationObject->commentID);
     $page = PageCache::getInstance()->getPage($comment->objectID);
     return $page->getLink();
 }
Exemple #15
0
 protected function getPage($pageID)
 {
     return PageCache::getInstance()->getPage($pageID);
 }
Exemple #16
0
 /**
  * Returns the page this content is assigned to.
  * 
  * @return	\cms\data\page\Page
  */
 public function getPage()
 {
     return PageCache::getInstance()->getPage($this->pageID);
 }
 /**
  * @see	\wcf\system\comment\manager\ICommentManager::updateCounter()
  */
 public function updateCounter($objectID, $value)
 {
     $page = PageCache::getInstance()->getPage($objectID);
     $editor = new PageEditor($page);
     $editor->updateCounters(array('comments' => $value));
 }
Exemple #18
0
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     // alias for indicating the requested page
     if (isset($_REQUEST['alias'])) {
         $alias = $_REQUEST['alias'];
         $this->pageID = PageCache::getInstance()->getIDByAlias($alias);
     } else {
         if (isset($_REQUEST['id'])) {
             $this->pageID = intval($_REQUEST['id']);
         } else {
             // landing page of the cms
             $page = PageCache::getInstance()->getHomePage();
             if ($page !== null) {
                 $this->pageID = $page->pageID;
             } else {
                 // redirect to system's landing page
                 HeaderUtil::redirect(Linkhandler::getInstance()->getLink(), true);
                 exit;
             }
         }
     }
     $this->page = PageCache::getInstance()->getPage($this->pageID);
     if ($this->page === null) {
         throw new IllegalLinkException();
     }
     // check if offline and view page or exit
     // @see	\wcf\system\request\RequestHandler
     if (OFFLINE) {
         if (!WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode') && !$this->page->availableDuringOfflineMode) {
             @header('HTTP/1.1 503 Service Unavailable');
             WCF::getTPL()->assign(array('templateName' => 'offline'));
             WCF::getTPL()->display('offline');
             exit;
         }
     }
     // check permissions
     if (!$this->page->canRead()) {
         throw new PermissionDeniedException();
     }
 }