public function get(UserOnline $user, $languageVariable = '') { if ($category = CategoryHandler::getInstance()->getCategory($user->objectID)) { $category = new NewsCategory($category); if ($category->getPermission('canView')) { return WCF::getLanguage()->getDynamicVariable($languageVariable, array('category' => $category)); } } return ''; }
public static function getAccessibleCategoryIDs($permissions = array('canViewCategory')) { $categoryIDs = array(); foreach (CategoryHandler::getInstance()->getCategories(self::OBJECT_TYPE_NAME) as $category) { $result = true; $category = new NewsCategory($category); foreach ($permissions as $permission) { $result = $result && $category->getPermission($permission); } if ($result) { $categoryIDs[] = $category->categoryID; } } return $categoryIDs; }
/** * Returns a list with category ids of accessible news categories. * * @param array $permissions * @return array<integer> */ public static function getAccessibleCategoryIDs(array $permissions = array('canManageCategory')) { $categoryIDs = array(); foreach (CategoryHandler::getInstance()->getCategories('de.incendium.cms.news.category') as $category) { $result = true; $category = new NewsCategory($category); foreach ($permissions as $permission) { $result = $result && $category->getPermission($permission); } if ($result) { $categoryIDs[] = $category->categoryID; } } return $categoryIDs; }
public function __construct() { parent::__construct(); // accessible news categories $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (!empty($accessibleCategoryIDs)) { $this->getConditionBuilder()->add('news.newsID IN (SELECT newsID FROM cms' . WCF_N . '_news_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs)); } else { $this->getConditionBuilder()->add('1=0'); } //get default settings if (!WCF::getSession()->getPermission('mod.cms.news.canModerateNews')) { $this->getConditionBuilder()->add('news.isDisabled = 0'); } if (!WCF::getSession()->getPermission('mod.cms.news.canModerateNews')) { $this->getConditionBuilder()->add('news.isDeleted = 0'); } //can view delayed news if (!WCF::getSession()->getPermission('user.cms.news.canViewDelayedNews')) { $this->getConditionBuilder()->add('news.isDisabled = ?', array(0)); } // language Filter if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) { $this->getConditionBuilder()->add('(news.languageID IN (?) OR news.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs())); } }
/** * Creates the AccessibleEntryList object. */ public function __construct() { parent::__construct(); // accessible news categories $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (!empty($accessibleCategoryIDs)) { $this->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs)); } else { $this->getConditionBuilder()->add('1=0'); } // default conditions if (!WCF::getSession()->getPermission('mod.news.canModerateEntry')) { $this->getConditionBuilder()->add('news_entry.isDisabled = 0'); } if (!WCF::getSession()->getPermission('mod.news.canViewDeletedEntry')) { $this->getConditionBuilder()->add('news_entry.isDeleted = 0'); } if (WCF::getUser()->userID) { $this->getConditionBuilder()->add('(news_entry.isPublished = 1 OR news_entry.userID = ?)', array(WCF::getUser()->userID)); } else { $this->getConditionBuilder()->add('news_entry.isPublished = 1'); } // apply language filter if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) { $this->getConditionBuilder()->add('(news_entry.languageID IN (?) OR news_entry.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs())); } }
public function __construct(array $categoryIDs) { parent::__construct(); if (!empty($categoryIDs)) { $this->getConditionBuilder()->add('news_to_category.categoryID IN (?)', array($categoryIDs)); $this->getConditionBuilder()->add('news.newsID = news_to_category.newsID'); } else { $this->getConditionBuilder()->add('1=0'); } foreach ($categoryIDs as $categoryID) { $category = new NewsCategory(CategoryHandler::getInstance()->getCategory($categoryID)); if (!$category->getPermission('canViewDelayedNews')) { $this->getConditionBuilder()->add('news.isDisabled = ?', array(0)); } } }
public function getFormTemplate() { $excludedCategoryIDs = array_diff(NewsCategory::getAccessibleCategoryIDs(), NewsCategory::getAccessibleCategoryIDs(array('canAddNews'))); $categoryTree = new NewsCategoryNodeTree('de.codequake.cms.category.news', 0, false, $excludedCategoryIDs); $categoryList = $categoryTree->getIterator(); $categoryList->setMaxDepth(0); WCF::getTPL()->assign('categoryList', $categoryList); return 'newsContentType'; }
/** * Creates a new DeletedEntryList object. */ public function __construct() { parent::__construct(); // accessible news categories $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (!empty($accessibleCategoryIDs)) { $this->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs)); } else { $this->getConditionBuilder()->add('1=0'); } // load only deleted news $this->getConditionBuilder()->add('news_entry.isDeleted = ?', array(1)); }
/** * Creates a new TaggedNewsList object. * * @param \wcf\data\tag\Tag $tag */ public function __construct(Tag $tag) { ViewableEntryList::__construct(); $this->getConditionBuilder()->add('tag_to_object.objectTypeID = ? AND tag_to_object.languageID = ? AND tag_to_object.tagID = ?', array(TagEngine::getInstance()->getObjectTypeID('de.incendium.cms.news.entry'), $tag->languageID, $tag->tagID)); $this->getConditionBuilder()->add('news_entry.entryID = tag_to_object.objectID'); // accessible news categories $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (!empty($accessibleCategoryIDs)) { $this->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array(NewsCategory::getAccessibleCategoryIDs())); } else { $this->getConditionBuilder()->add('1=0'); } }
public function readParameters() { parent::readParameters(); if (empty($this->objectIDs)) { $this->objectIDs = NewsCategory::getAccessibleCategoryIDs(); } else { foreach ($this->objectIDs as $objectID) { $category = NewsCategory::getCategory($objectID); if (!$category->isAccessible()) { throw new PermissionDeniedException(); } if ($category === null) { throw new IllegalLinkException(); } } } }
public function getConditions(IForm $form = null) { $conditionBuilder = new PreparedStatementConditionBuilder(); // accessible category ids $categoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (empty($categoryIDs)) { throw new PermissionDeniedException(); } $conditionBuilder->add($this->getTableName() . '.newsID IN (SELECT newsID FROM cms' . WCF_N . '_news_to_category WHERE categoryID IN (?))', array($categoryIDs)); // default conditions $conditionBuilder->add($this->getTableName() . '.isDisabled = 0'); $conditionBuilder->add($this->getTableName() . '.isDeleted = 0'); // language if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) { $conditionBuilder->add('(' . $this->getTableName() . '.languageID IN (?) OR ' . $this->getTableName() . '.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs())); } return $conditionBuilder; }
/** * Loads the news entries. */ protected function loadEntries() { $this->entry = array(); if (empty($this->entryIDs)) { return; } $this->entryIDs = array_unique($this->entryIDs); $categoryIDs = NewsCategory::getAccessibleCategoryIDs(); if (empty($categoryIDs)) { return; } $entryList = new EntryList(); $entryList->getConditionBuilder()->add('news_entry.entryID IN (?)', array($this->entryIDs)); $entryList->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array($categoryIDs)); $entryList->getConditionBuilder()->add('news_entry.isDisabled = 0 AND news_entry.isDeleted = 0 AND news_entry.isPublished = 1'); $entryList->readObjects(); $this->entry = $entryList->getObjects(); }
public function getNotifications() { if ($this->notifications === null) { $this->notifications = 0; if (WCF::getUser()->userID) { // load storage data UserStorageHandler::getInstance()->loadStorage(array(WCF::getUser()->userID)); // get ids $data = UserStorageHandler::getInstance()->getStorage(array(WCF::getUser()->userID), 'cmsUnreadNews'); // cache does not exist or is outdated if ($data[WCF::getUser()->userID] === null) { $categoryIDs = NewsCategory::getAccessibleCategoryIDs(); // removed ignored boards foreach ($categoryIDs as $key => $categoryID) { $category = CategoryHandler::getInstance()->getCategory($categoryID); } if (!empty($categoryIDs)) { $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add("news.lastChangeTime > ?", array(VisitTracker::getInstance()->getVisitTime('de.codequake.cms.news'))); $conditionBuilder->add("news.newsID IN (SELECT newsID FROM cms" . WCF_N . "_news_to_category WHERE categoryID IN (?))", array($categoryIDs)); $conditionBuilder->add("news.isDeleted = 0 AND news.isDisabled = 0"); $conditionBuilder->add("tracked_visit.visitTime IS NULL"); // apply language filter if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) { $conditionBuilder->add('(news.languageID IN (?) OR news.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs())); } $sql = "SELECT\t\tCOUNT(*) AS count\n\t\t\t\t\t\t\tFROM\t\tcms" . WCF_N . "_news news\n\t\t\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_tracked_visit tracked_visit\n\t\t\t\t\t\t\tON\t\t(tracked_visit.objectTypeID = " . VisitTracker::getInstance()->getObjectTypeID('de.codequake.cms.news') . " AND tracked_visit.objectID = news.newsID AND tracked_visit.userID = " . WCF::getUser()->userID . ")\n\t\t\t\t\t\t\t" . $conditionBuilder; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); $row = $statement->fetchArray(); $this->notifications = $row['count']; } // update storage data UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'cmsUnreadNews', $this->notifications); } else { $this->notifications = $data[WCF::getUser()->userID]; } } } return $this->notifications; }
public function validate() { parent::validate(); // categories 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 NewsCategory($category); if (!$category->isAccessible() || !$category->getPermission('canAddNews')) { throw new UserInputException('categoryIDs'); } } if (MODULE_POLL && WCF::getSession()->getPermission('user.cms.news.canStartPoll')) { PollManager::getInstance()->validate(); } }
/** * @see \wcf\form\IForm::validate() */ public function validate() { parent::validate(); // validate the news category ids if (empty($this->categoryIDs)) { throw new UserInputException('categoryIDs', 'empty'); } foreach ($this->categoryIDs as $categoryID) { $category = CategoryHandler::getInstance()->getCategory($categoryID); if ($category === null) { throw new UserInputException('categoryIDs'); } // get category $category = new NewsCategory($category); // check, if the current user can use this category if (!$category->canUseCategory()) { throw new UserInputException('categoryIDs'); } } // validate publication date if ($this->enableDelayedPublication) { $publicationDateTimestamp = @strtotime($this->publicationDate); if ($publicationDateTimestamp === false || $publicationDateTimestamp > 2147483647) { throw new UserInputException('publicationDate', 'invalid'); } } // validate poll if ($this->canCreatePoll()) { PollManager::getInstance()->validate(); } }