/**
  * Marks all news categories as read.
  */
 public function markAllAsRead()
 {
     VisitTracker::getInstance()->trackTypeVisit('de.incendium.linklist.entry');
     // reset the user storage data and delete notifications
     if (WCF::getUser()->userID) {
         // user storage data
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'linklistUnreadEntries');
     }
 }
 /**
  * Marks all news categories as read.
  */
 public function markAllAsRead()
 {
     VisitTracker::getInstance()->trackTypeVisit('de.incendium.cms.news.entry');
     // reset the user storage data and delete notifications
     if (WCF::getUser()->userID) {
         // user storage data
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'cmsUnreadNewsEntries');
         // user notifications
         UserNotificationHandler::getInstance()->markAsConfirmed('news', 'de.incendium.cms.news.entry', array(WCF::getUser()->userID));
     }
 }
 /**
  * Marks all news categories as read.
  */
 public function markAllAsRead()
 {
     VisitTracker::getInstance()->trackTypeVisit('de.voolia.news.entry');
     // reset the user storage data and delete notifications
     if (WCF::getUser()->userID) {
         // user storage data
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'newsUnreadEntries');
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'newsUnreadWatchedEntries');
         // user notifications
         UserNotificationHandler::getInstance()->deleteNotifications('news', 'de.voolia.news.entry', array(WCF::getUser()->userID));
     }
 }
Esempio n. 4
0
 /**
  * Dismisses a certain notice.
  * 
  * @return	array<integer>
  */
 public function dismiss()
 {
     if (WCF::getUser()->userID) {
         $sql = "INSERT INTO\twcf" . WCF_N . "_notice_dismissed\n\t\t\t\t\t\t(noticeID, userID)\n\t\t\t\tVALUES\t\t(?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(reset($this->objectIDs), WCF::getUser()->userID));
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'dismissedNotices');
     } else {
         $dismissedNotices = WCF::getSession()->getVar('dismissedNotices');
         if ($dismissedNotices !== null) {
             $dismissedNotices = @unserialize($dismissedNotices);
             $dismissedNotices[] = reset($this->objectIDs);
         } else {
             $dismissedNotices = array(reset($this->objectIDs));
         }
         WCF::getSession()->register('dismissedNotices', serialize($dismissedNotices));
     }
     return array('noticeID' => reset($this->objectIDs));
 }
 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;
 }
 /**
  * Uninstalls node components and returns next node.
  * 
  * @param	string		$node
  * @return	string
  */
 public function uninstall($node)
 {
     $nodes = $this->nodeBuilder->getNodeData($node);
     // invoke node-specific actions
     foreach ($nodes as $data) {
         $nodeData = unserialize($data['nodeData']);
         switch ($data['nodeType']) {
             case 'package':
                 $this->uninstallPackage($nodeData);
                 break;
             case 'pip':
                 $this->executePIP($nodeData);
                 break;
         }
     }
     // mark node as completed
     $this->nodeBuilder->completeNode($node);
     $node = $this->nodeBuilder->getNextNode($node);
     // perform post-uninstall actions
     if ($node == '') {
         // update options.inc.php if uninstallation is completed
         OptionEditor::resetCache();
         // clear cache
         CacheHandler::getInstance()->flushAll();
         // reset language cache
         LanguageFactory::getInstance()->clearCache();
         LanguageFactory::getInstance()->deleteLanguageCache();
         // reset stylesheets
         StyleHandler::resetStylesheets();
         // rebuild application paths
         ApplicationHandler::rebuild();
         // clear user storage
         UserStorageHandler::getInstance()->clear();
         EventHandler::getInstance()->fireAction($this, 'postUninstall');
     }
     if ($this->requireRestructureVersionTables) {
         $this->restructureVersionTables();
     }
     // return next node
     return $node;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save the news update
     $this->objectAction = new EntryUpdateAction(array($this->update), 'update', array('data' => array('subject' => $this->subject, 'message' => $this->text)));
     $this->objectAction->executeAction();
     // set news as new
     if ($this->setEntryAsNew) {
         $sql = "UPDATE    cms" . WCF_N . "_news_entry\n                    SET    time = ?\n                    WHERE    entryID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(TIME_NOW, $this->entryID));
         $sql = "DELETE FROM    wcf" . WCF_N . "_tracked_visit\n                    WHERE        objectTypeID = ?\n                    AND        objectID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(VisitTracker::getInstance()->getObjectTypeID('de.incendium.cms.news.entry'), $this->entryID));
         // reset the user storage data
         UserStorageHandler::getInstance()->resetAll('cmsUnreadNewsEntries');
     }
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('NewsEntry', array('application' => 'cms', 'object' => $this->entry)));
     exit;
 }
Esempio n. 8
0
 /**
  * Returns true if the active user has dismissed the notice.
  * 
  * @return	boolean
  */
 public function isDismissed()
 {
     if (!$this->isDismissible) {
         return false;
     }
     if ($this->isDismissed === null) {
         if (WCF::getUser()->userID) {
             $dismissedNotices = UserStorageHandler::getInstance()->getField('dismissedNotices');
             if ($dismissedNotices === null) {
                 $sql = "SELECT\tnoticeID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_notice_dismissed\n\t\t\t\t\t\tWHERE\tuserID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array(WCF::getUser()->userID));
                 $noticeIDs = array();
                 while ($noticeID = $statement->fetchColumn()) {
                     $noticeIDs[] = $noticeID;
                     if ($noticeID == $this->noticeID) {
                         $this->isDismissed = true;
                     }
                 }
                 UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'dismissedNotices', serialize($noticeIDs));
             } else {
                 $dismissedNoticeIDs = @unserialize($dismissedNotices);
                 $this->isDismissed = in_array($this->noticeID, $dismissedNoticeIDs);
             }
         } else {
             $dismissedNotices = WCF::getSession()->getVar('dismissedNotices');
             if ($dismissedNotices !== null) {
                 $dismissedNotices = @unserialize($dismissedNotices);
                 $this->isDismissed = in_array($this->noticeID, $dismissedNotices);
             } else {
                 $this->isDismissed = false;
             }
         }
     }
     return $this->isDismissed;
 }
Esempio n. 9
0
 /**
  * Replacement of the "__destruct()" method.
  * Seems that under specific conditions (windows) the destructor is not called automatically.
  * So we use the php register_shutdown_function to register an own destructor method.
  * Flushs the output, closes caches and updates the session.
  */
 public static function destruct()
 {
     try {
         // database has to be initialized
         if (!is_object(self::$dbObj)) {
             return;
         }
         // flush output
         if (ob_get_level() && ini_get('output_handler')) {
             ob_flush();
         } else {
             flush();
         }
         // update session
         if (is_object(self::getSession())) {
             self::getSession()->update();
         }
         // execute shutdown actions of user storage handler
         UserStorageHandler::getInstance()->shutdown();
     } catch (\Exception $exception) {
         die("<pre>WCF::destruct() Unhandled exception: " . $exception->getMessage() . "\n\n" . $exception->getTraceAsString());
     }
 }
Esempio n. 10
0
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     AbstractForm::save();
     $this->objectAction = new NoticeAction(array($this->notice), 'update', array('data' => array_merge($this->additionalFields, array('cssClassName' => $this->cssClassName == 'custom' ? $this->customCssClassName : $this->cssClassName, 'isDisabled' => $this->isDisabled, 'isDismissible' => $this->isDismissible, 'notice' => I18nHandler::getInstance()->isPlainValue('notice') ? I18nHandler::getInstance()->getValue('notice') : 'wcf.notice.notice.notice' . $this->notice->noticeID, 'noticeName' => $this->noticeName, 'noticeUseHtml' => $this->noticeUseHtml, 'showOrder' => $this->showOrder))));
     $this->objectAction->executeAction();
     if (I18nHandler::getInstance()->isPlainValue('notice')) {
         if ($this->notice->notice == 'wcf.notice.notice.notice' . $this->notice->noticeID) {
             I18nHandler::getInstance()->remove($this->notice->notice);
         }
     } else {
         I18nHandler::getInstance()->save('notice', 'wcf.notice.notice.notice' . $this->notice->noticeID, 'wcf.notice', 1);
     }
     // transform conditions array into one-dimensional array
     $conditions = array();
     foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
         foreach ($groupedObjectTypes as $objectTypes) {
             if (is_array($objectTypes)) {
                 $conditions = array_merge($conditions, $objectTypes);
             } else {
                 $conditions[] = $objectTypes;
             }
         }
     }
     ConditionHandler::getInstance()->updateConditions($this->notice->noticeID, $this->notice->getConditions(), $conditions);
     if ($this->resetIsDismissed) {
         $sql = "DELETE FROM\twcf" . WCF_N . "_notice_dismissed\n\t\t\t\tWHERE\t\tnoticeID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->notice->noticeID));
         $this->resetIsDismissed = 0;
         UserStorageHandler::getInstance()->resetAll('dismissedNotices');
     }
     $this->saved();
     // reload notice object for proper 'isDismissible' value
     $this->notice = new Notice($this->noticeID);
     WCF::getTPL()->assign('success', true);
 }
 /**
  * Returns the number of unread entries.
  * 
  * @return    integer
  */
 public static function getUnreadEntries()
 {
     if (self::$unreadEntries === null) {
         self::$unreadEntries = 0;
         if (WCF::getUser()->userID) {
             $data = UserStorageHandler::getInstance()->getField('filebaseUnreadEntries');
             // cache does not exist or is outdated
             if ($data === null) {
                 $categoryIDs = FilebaseCategory::getAccessibleCategoryIDs();
                 // removed ignored boards
                 if (!empty($categoryIDs)) {
                     $conditionBuilder = new PreparedStatementConditionBuilder();
                     $conditionBuilder->add("entry.entryID IN (SELECT entryID FROM filebase" . WCF_N . "_entry_to_category WHERE categoryID IN (?))", array($categoryIDs));
                     $conditionBuilder->add("entry.lastChangeTime > ?", array(VisitTracker::getInstance()->getVisitTime('de.incendium.filebase.entry')));
                     $conditionBuilder->add("entry.isDisabled = 0 AND entry.isDeleted = 0");
                     $conditionBuilder->add("(entry.lastChangeTime > tracked_visit.visitTime OR tracked_visit.visitTime IS NULL)");
                     // apply language filter
                     if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
                         $conditionBuilder->add('(entry.languageID IN (?) OR entry.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
                     }
                     $sql = "SELECT        COUNT(*) AS count\n                            FROM        filebase" . WCF_N . "_entry entry\n                            LEFT JOIN    wcf" . WCF_N . "_tracked_visit tracked_visit\n                            ON        (tracked_visit.objectTypeID = " . VisitTracker::getInstance()->getObjectTypeID('de.incendium.filebase.entry') . " AND tracked_visit.objectID = entry.entryID AND tracked_visit.userID = " . WCF::getUser()->userID . ")\n                            " . $conditionBuilder;
                     $statement = WCF::getDB()->prepareStatement($sql);
                     $statement->execute($conditionBuilder->getParameters());
                     $row = $statement->fetchArray();
                     self::$unreadEntries = $row['count'];
                 }
                 // update storage data
                 UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'filebaseUnreadEntries', self::$unreadEntries);
             } else {
                 self::$unreadEntries = $data;
             }
         }
     }
     return self::$unreadEntries;
 }
 /**
  * Returns the number of conversations for given user.
  * 
  * @param	integer		$userID
  * @return	integer
  */
 public function getConversationCount($userID = null)
 {
     if ($userID === null) {
         $userID = WCF::getUser()->userID;
     }
     if (!isset($this->conversationCount[$userID])) {
         $this->conversationCount[$userID] = 0;
         // load storage data
         UserStorageHandler::getInstance()->loadStorage(array($userID));
         // get ids
         $data = UserStorageHandler::getInstance()->getStorage(array($userID), 'conversationCount');
         // cache does not exist or is outdated
         if ($data[$userID] === null) {
             $conditionBuilder1 = new PreparedStatementConditionBuilder();
             $conditionBuilder1->add('conversation_to_user.participantID = ?', array($userID));
             $conditionBuilder1->add('conversation_to_user.hideConversation IN (0,1)');
             $conditionBuilder2 = new PreparedStatementConditionBuilder();
             $conditionBuilder2->add('conversation.userID = ?', array($userID));
             $conditionBuilder2->add('conversation.isDraft = 1');
             $sql = "SELECT (SELECT\tCOUNT(*)\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\t\t\t\t" . $conditionBuilder1->__toString() . ")\n\t\t\t\t\t\t+\n\t\t\t\t\t\t(SELECT\tCOUNT(*)\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_conversation conversation\n\t\t\t\t\t\t" . $conditionBuilder2->__toString() . ") AS count";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array_merge($conditionBuilder1->getParameters(), $conditionBuilder2->getParameters()));
             $row = $statement->fetchArray();
             $this->conversationCount[$userID] = $row['count'];
             // update storage data
             UserStorageHandler::getInstance()->update($userID, 'conversationCount', serialize($this->conversationCount[$userID]));
         } else {
             $this->conversationCount[$userID] = unserialize($data[$userID]);
         }
     }
     return $this->conversationCount[$userID];
 }
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     // count attachments
     if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
         $this->parameters['data']['attachments'] = count($this->parameters['attachmentHandler']);
     }
     if (LOG_IP_ADDRESS) {
         // add ip address
         if (!isset($this->parameters['data']['ipAddress'])) {
             $this->parameters['data']['ipAddress'] = WCF::getSession()->ipAddress;
         }
     } else {
         // do not track ip address
         if (isset($this->parameters['data']['ipAddress'])) {
             unset($this->parameters['data']['ipAddress']);
         }
     }
     // create message
     $message = parent::create();
     $messageEditor = new ConversationMessageEditor($message);
     // get conversation
     $conversation = isset($this->parameters['converation']) ? $this->parameters['converation'] : new Conversation($message->conversationID);
     $conversationEditor = new ConversationEditor($conversation);
     if (empty($this->parameters['isFirstPost'])) {
         // update last message
         $conversationEditor->addMessage($message);
         // fire notification event
         if (!$conversation->isDraft) {
             $notificationRecipients = array_diff($conversation->getParticipantIDs(true), array($message->userID));
             // don't notify message author
             if (!empty($notificationRecipients)) {
                 UserNotificationHandler::getInstance()->fireEvent('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', new ConversationMessageUserNotificationObject($message), $notificationRecipients);
             }
         }
         $userConversation = Conversation::getUserConversation($conversation->conversationID, $message->userID);
         if ($userConversation !== null && $userConversation->isInvisible) {
             // make invisible participant visible
             $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\t\tSET\tisInvisible = 0\n\t\t\t\t\tWHERE\tparticipantID = ?\n\t\t\t\t\t\tAND conversationID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array($message->userID, $conversation->conversationID));
             $conversationEditor->updateParticipantSummary();
             $conversationEditor->updateParticipantCount();
         }
         // reset visibility if it was hidden but not left
         $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\tSET\thideConversation = ?\n\t\t\t\tWHERE\tconversationID = ?\n\t\t\t\t\tAND hideConversation = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(Conversation::STATE_DEFAULT, $conversation->conversationID, Conversation::STATE_HIDDEN));
     }
     // reset storage
     UserStorageHandler::getInstance()->reset($conversation->getParticipantIDs(), 'unreadConversationCount');
     // update search index
     SearchIndexManager::getInstance()->add('com.woltlab.wcf.conversation.message', $message->messageID, $message->message, !empty($this->parameters['isFirstPost']) ? $conversation->subject : '', $message->time, $message->userID, $message->username);
     // update attachments
     if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
         $this->parameters['attachmentHandler']->updateObjectID($message->messageID);
     }
     // save embedded objects
     if (MessageEmbeddedObjectManager::getInstance()->registerObjects('com.woltlab.wcf.conversation.message', $message->messageID, $message->message)) {
         $messageEditor->update(array('hasEmbeddedObjects' => 1));
     }
     // clear quotes
     if (isset($this->parameters['removeQuoteIDs']) && !empty($this->parameters['removeQuoteIDs'])) {
         MessageQuoteManager::getInstance()->markQuotesForRemoval($this->parameters['removeQuoteIDs']);
     }
     MessageQuoteManager::getInstance()->removeMarkedQuotes();
     // return new message
     return $message;
 }
 /**
  * Removes a participant from a conversation.
  */
 public function removeParticipant()
 {
     $this->conversation->removeParticipant($this->parameters['userID']);
     $this->conversation->updateParticipantSummary();
     ConversationModificationLogHandler::getInstance()->removeParticipant($this->conversation->getDecoratedObject(), $this->parameters['userID']);
     // reset storage
     UserStorageHandler::getInstance()->reset(array($this->parameters['userID']), 'unreadConversationCount');
     return array('userID' => $this->parameters['userID']);
 }
Esempio n. 15
0
 /**
  * @see	\wcf\form\AbstractForm::save()
  */
 public function save()
 {
     parent::save();
     $saveOptions = $this->optionHandler->save();
     $parameters = array('options' => $saveOptions);
     // static options
     if ($this->category == 'general') {
         $parameters['data'] = array_merge($this->additionalFields, array('languageID' => $this->languageID, 'styleID' => $this->styleID));
         $parameters['languageIDs'] = $this->contentLanguageIDs;
     }
     $this->objectAction = new UserAction(array(WCF::getUser()), 'update', $parameters);
     $this->objectAction->executeAction();
     // static options
     if ($this->category == 'general') {
         // reset user language ids cache
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'languageIDs');
     }
     $this->saved();
     WCF::getTPL()->assign('success', true);
 }
Esempio n. 16
0
 /**
  * Updates user ranks.
  */
 public function updateUserRank()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     $resetUserIDs = array();
     foreach ($this->objects as $user) {
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add('user_rank.groupID IN (?)', array($user->getGroupIDs()));
         $conditionBuilder->add('user_rank.requiredPoints <= ?', array($user->activityPoints));
         if ($user->gender) {
             $conditionBuilder->add('user_rank.requiredGender IN (?)', array(array(0, $user->gender)));
         } else {
             $conditionBuilder->add('user_rank.requiredGender = ?', array(0));
         }
         $sql = "SELECT\t\tuser_rank.rankID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_user_rank user_rank\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_group user_group\n\t\t\t\tON\t\t(user_group.groupID = user_rank.groupID)\n\t\t\t\t" . $conditionBuilder . "\n\t\t\t\tORDER BY\tuser_group.priority DESC, user_rank.requiredPoints DESC, user_rank.requiredGender DESC";
         $statement = WCF::getDB()->prepareStatement($sql, 1);
         $statement->execute($conditionBuilder->getParameters());
         $row = $statement->fetchArray();
         if ($row === false) {
             if ($user->rankID) {
                 $user->update(array('rankID' => null));
                 $resetUserIDs[] = $user->userID;
             }
         } else {
             if ($row['rankID'] != $user->rankID) {
                 $user->update(array('rankID' => $row['rankID']));
                 $resetUserIDs[] = $user->userID;
             }
         }
     }
     if (!empty($resetUserIDs)) {
         UserStorageHandler::getInstance()->reset($resetUserIDs, 'userRank');
     }
 }
 /**
  * Restores given entries.
  * 
  * @return	array<array>
  */
 public function restore()
 {
     $entryIDs = array();
     foreach ($this->objects as $entry) {
         $entry->update(array('deleteTime' => 0, 'isDeleted' => 0));
         $entryIDs[] = $entry->entryID;
         $this->addEntryData($entry->getDecoratedObject(), 'isDeleted', 0);
         EntryModificationLogHandler::getInstance()->restore($entry->getDecoratedObject());
     }
     $this->restoreFiles($entryIDs);
     EntryEditor::rebuildEntryData($entryIDs);
     $this->unmarkItems();
     UserStorageHandler::getInstance()->resetAll('filebaseUnreadEntries');
     UserStorageHandler::getInstance()->resetAll('filebaseUnreadWatchedEntries');
     return $this->getEntryData();
 }
Esempio n. 18
0
 /**
  * Returns a list of language ids for this user.
  * 
  * @return	array<integer>
  */
 public function getLanguageIDs()
 {
     if ($this->languageIDs === null) {
         $this->languageIDs = array();
         if ($this->userID) {
             // load storage data
             UserStorageHandler::getInstance()->loadStorage(array($this->userID));
             // get language ids
             $data = UserStorageHandler::getInstance()->getStorage(array($this->userID), 'languageIDs');
             // cache does not exist or is outdated
             if ($data[$this->userID] === null) {
                 $sql = "SELECT\tlanguageID\n\t\t\t\t\t\tFROM\twcf" . WCF_N . "_user_to_language\n\t\t\t\t\t\tWHERE\tuserID = ?";
                 $statement = WCF::getDB()->prepareStatement($sql);
                 $statement->execute(array($this->userID));
                 while ($row = $statement->fetchArray()) {
                     $this->languageIDs[] = $row['languageID'];
                 }
                 // update storage data
                 UserStorageHandler::getInstance()->update($this->userID, 'languageIDs', serialize($this->languageIDs), 1);
             } else {
                 $this->languageIDs = unserialize($data[$this->userID]);
             }
         }
     }
     return $this->languageIDs;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new PreparedStatementConditionBuilder();
     // deny self delete
     if ($this->action == 'delete') {
         $this->conditions->add("user_table.userID <> ?", array(WCF::getUser()->userID));
     }
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user_table.username LIKE ?", array('%' . addcslashes($this->username, '_%') . '%'));
     }
     if (!empty($this->email)) {
         $this->conditions->add("user_table.email LIKE ?", array('%' . addcslashes($this->email, '_%') . '%'));
     }
     if (!empty($this->groupIDs)) {
         $this->conditions->add("user_table.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_group WHERE groupID IN (?))", array($this->groupIDs));
     }
     if (!empty($this->languageIDs)) {
         $this->conditions->add("user_table.languageID IN (?)", array($this->languageIDs));
     }
     // registration date
     if ($startDate = @strtotime($this->registrationDateStart)) {
         $this->conditions->add('user_table.registrationDate >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->registrationDateEnd)) {
         $this->conditions->add('user_table.registrationDate <= ?', array($endDate));
     }
     if ($this->banned) {
         $this->conditions->add('user_table.banned = ?', array(1));
     }
     if ($this->notBanned) {
         $this->conditions->add('user_table.banned = ?', array(0));
     }
     // last activity time
     if ($startDate = @strtotime($this->lastActivityTimeStart)) {
         $this->conditions->add('user_table.lastActivityTime >= ?', array($startDate));
     }
     if ($endDate = @strtotime($this->lastActivityTimeEnd)) {
         $this->conditions->add('user_table.lastActivityTime <= ?', array($endDate));
     }
     if ($this->enabled) {
         $this->conditions->add('user_table.activationCode = ?', array(0));
     }
     if ($this->disabled) {
         $this->conditions->add('user_table.activationCode <> ?', array(0));
     }
     // dynamic fields
     foreach ($this->activeOptions as $name => $option) {
         $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
         $this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
     }
     // call buildConditions event
     EventHandler::getInstance()->fireAction($this, 'buildConditions');
     // execute action
     switch ($this->action) {
         case 'sendMail':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // get user ids
             $userIDs = array();
             $sql = "SELECT\t\tuser_table.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             while ($row = $statement->fetchArray()) {
                 $userIDs[] = $row['userID'];
                 $this->affectedUsers++;
             }
             if (!empty($userIDs)) {
                 // save config in session
                 $userMailData = WCF::getSession()->getVar('userMailData');
                 if ($userMailData === null) {
                     $userMailData = array();
                 }
                 $mailID = count($userMailData);
                 $userMailData[$mailID] = array('action' => '', 'userIDs' => $userIDs, 'groupIDs' => '', 'subject' => $this->subject, 'text' => $this->text, 'from' => $this->from, 'enableHTML' => $this->enableHTML);
                 WCF::getSession()->register('userMailData', $userMailData);
                 WCF::getTPL()->assign('mailID', $mailID);
             }
             break;
         case 'exportMailAddress':
             WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
             // send content type
             header('Content-Type: text/' . $this->fileType . '; charset=UTF-8');
             header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
             if ($this->fileType == 'xml') {
                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
             }
             // count users
             $sql = "SELECT\t\tCOUNT(*) AS count\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions;
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $count = $statement->fetchArray();
             // get users
             $sql = "SELECT\t\tuser_table.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user_table\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value\n\t\t\t\t\tON\t\t(option_value.userID = user_table.userID)\n\t\t\t\t\t" . $this->conditions . "\n\t\t\t\t\tORDER BY\tuser_table.email";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute($this->conditions->getParameters());
             $i = 0;
             while ($row = $statement->fetchArray()) {
                 if ($this->fileType == 'xml') {
                     echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
                 } else {
                     echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
                 }
                 $i++;
                 $this->affectedUsers++;
             }
             if ($this->fileType == 'xml') {
                 echo "</addresses>";
             }
             $this->saved();
             exit;
             break;
         case 'assignToGroup':
             WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
             $_this = $this;
             $userIDs = $this->fetchUsers(function ($userID, array $userData) use($_this) {
                 $user = new UserEditor(new User(null, $userData));
                 $user->addToGroups($_this->assignToGroupIDs, false, false);
             });
             if (!empty($userIDs)) {
                 UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
             }
             break;
         case 'delete':
             WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
             $userIDs = $this->fetchUsers();
             if (!empty($userIDs)) {
                 $userAction = new UserAction($userIDs, 'delete');
                 $userAction->executeAction();
             }
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
Esempio n. 20
0
 /**
  * @see	\wcf\data\IEditableCachedObject::resetCache()
  */
 public static function resetCache()
 {
     UserStorageHandler::getInstance()->resetAll('userRank');
 }
 /**
  * Restores entries.
  */
 public function restore()
 {
     $entryIDs = array();
     foreach ($this->objects as $entry) {
         $entry->update(array('deleteTime' => 0, 'isDeleted' => 0));
         $this->addEntryData($entry->getDecoratedObject(), 'isDeleted', 0);
         EntryModificationLogHandler::getInstance()->restore($entry->getDecoratedObject());
     }
     $this->unmarkItems();
     UserStorageHandler::getInstance()->resetAll('linklistUnreadEntries');
     return $this->getEntryData();
 }
Esempio n. 22
0
 /**
  * Resets session-specific storage data.
  * 
  * @param	array<integer>	$userIDs
  */
 public static function resetSessions(array $userIDs = array())
 {
     if (!empty($userIDs)) {
         UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);
         UserStorageHandler::getInstance()->reset($userIDs, 'languageIDs', 1);
     } else {
         UserStorageHandler::getInstance()->resetAll('groupIDs', 1);
         UserStorageHandler::getInstance()->resetAll('languageIDs', 1);
     }
 }
Esempio n. 23
0
 /**
  * Tracks an object type visit.
  * 
  * @param	string		$objectType
  * @param	integer		$time
  */
 public function trackTypeVisit($objectType, $time = TIME_NOW)
 {
     if (WCF::getUser()->userID) {
         // save visit
         $sql = "REPLACE INTO\twcf" . WCF_N . "_tracked_visit_type\n\t\t\t\t\t\t(objectTypeID, userID, visitTime)\n\t\t\t\tVALUES\t\t(?, ?, ?)";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->getObjectTypeID($objectType), WCF::getUser()->userID, $time));
         // delete obsolete object visits
         $sql = "DELETE FROM\twcf" . WCF_N . "_tracked_visit\n\t\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\t\tAND userID = ?\n\t\t\t\t\t\tAND visitTime <= ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($this->getObjectTypeID($objectType), WCF::getUser()->userID, $time));
         // reset storage
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'trackedUserVisits');
     } else {
         $this->getVisitTime($objectType);
         $this->userVisits[$this->getObjectTypeID($objectType)] = $time;
         WCF::getSession()->register('trackedUserVisits', $this->userVisits);
     }
 }
 /**
  * Deletes all saved states for a specific object type.
  * 
  * @param	integer		$objectTypeID
  */
 public function reset($objectTypeID)
 {
     if (WCF::getUser()->userID) {
         $sql = "DELETE FROM\twcf" . WCF_N . "_user_collapsible_content\n\t\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\t\t\t\tAND userID = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array($objectTypeID, WCF::getUser()->userID));
         // reset storage
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'collapsedContent-' . $objectTypeID, 1);
     } else {
         $collapsedContent = WCF::getSession()->getVar('collapsedContent');
         if ($collapsedContent === null || !is_array($collapsedContent)) {
             $collapsedContent = array();
         }
         if (isset($collapsedContent[$objectTypeID])) {
             unset($collapsedContent[$objectTypeID]);
         }
         WCF::getSession()->register('collapsedContent', $collapsedContent);
     }
 }
 /**
  * Resets moderation count for all users or optionally only for one user.
  * 
  * @param	integer		$userID
  */
 public function resetModerationCount($userID = null)
 {
     if ($userID === null) {
         UserStorageHandler::getInstance()->resetAll('outstandingModerationCount');
         UserStorageHandler::getInstance()->resetAll('unreadModerationCount');
     } else {
         UserStorageHandler::getInstance()->reset(array($userID), 'outstandingModerationCount');
         UserStorageHandler::getInstance()->reset(array($userID), 'unreadModerationCount');
     }
 }
Esempio n. 26
0
 /**
  * Replacement of the "__destruct()" method.
  * Seems that under specific conditions (windows) the destructor is not called automatically.
  * So we use the php register_shutdown_function to register an own destructor method.
  * Flushs the output, updates the session and executes the shutdown queries.
  */
 public static function destruct()
 {
     // flush ouput
     if (ob_get_level() && ini_get('output_handler')) {
         ob_flush();
     } else {
         flush();
     }
     // update session
     if (is_object(self::getSession())) {
         self::getSession()->update();
     }
     // close cache source
     if (is_object(CacheHandler::getInstance()) && is_object(CacheHandler::getInstance()->getCacheSource())) {
         CacheHandler::getInstance()->getCacheSource()->close();
     }
     // execute shutdown actions of user storage handler
     UserStorageHandler::getInstance()->shutdown();
 }
Esempio n. 27
0
	/**
	 * @see	wcf\form\IForm::save()
	 */
	public function save() {
		parent::save();
		
		// build conditions
		$this->conditions = new PreparedStatementConditionBuilder();
		
		// static fields
		if (!empty($this->username)) {
			$this->conditions->add("user.username LIKE ?", array('%'.addcslashes($this->username, '_%').'%'));
		}
		if (!empty($this->email)) {
			$this->conditions->add("user.email LIKE ?", array('%'.addcslashes($this->email, '_%').'%'));
		}
		if (!empty($this->groupIDArray)) {
			$this->conditions->add("user.userID ".($this->invertGroupIDs == 1 ? 'NOT ' : '')."IN (SELECT userID FROM wcf".WCF_N."_user_to_group WHERE groupID IN (?))", array($this->groupIDArray));
		}
		if (!empty($this->languageIDArray)) {
			$this->conditions->add("user.languageID IN (?)", array($this->languageIDArray));
		}
		
		// dynamic fields
		foreach ($this->activeOptions as $name => $option) {
			$value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
			$this->getTypeObject($option['optionType'])->getCondition($this->conditions, $option, $value);
		}
		
		// call buildConditions event
		EventHandler::getInstance()->fireAction($this, 'buildConditions');
		
		// execute action
		switch ($this->action) {
			case 'sendMail':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// get user ids
				$userIDArray = array();
				$sql = "SELECT		user.userID
					FROM		wcf".WCF_N."_user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)".
					$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				while ($row = $statement->fetchArray()) {
					$userIDArray[] = $row['userID'];
					$this->affectedUsers++;
				}
				
				// save config in session
				$userMailData = WCF::getSession()->getVar('userMailData');
				if ($userMailData === null) $userMailData = array();
				$mailID = count($userMailData);
				$userMailData[$mailID] = array(
					'action' => '',
					'userIDs' => implode(',', $userIDArray),
					'groupIDs' => '',
					'subject' => $this->subject,
					'text' => $this->text,
					'from' => $this->from,
					'enableHTML' => $this->enableHTML
				);
				WCF::getSession()->register('userMailData', $userMailData);
				$this->saved();
				
				$url = LinkHandler::getInstance()->getLink('UserMail', array('id' => $mailID));
				
				// show worker template
				WCF::getTPL()->assign(array(
					'pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'),
					'url' => $url
				));
				WCF::getTPL()->display('worker');
				exit;
			break;
			
			case 'exportMailAddress':
				WCF::getSession()->checkPermissions(array('admin.user.canMailUser'));
				// send content type
				header('Content-Type: text/'.$this->fileType.'; charset=UTF-8');
				header('Content-Disposition: attachment; filename="export.'.$this->fileType.'"');
				
				if ($this->fileType == 'xml') {
					echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addresses>\n";
				}
				
				// count users
				$sql = "SELECT		COUNT(*) AS count
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions;
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				$count = $statement->fetchArray();
				
				// get users
				$sql = "SELECT		user.email
					FROM		wcf".WCF_N."_user user
					LEFT JOIN	wcf".WCF_N."_user_option_value option_value
					ON		(option_value.userID = user.userID)
					".$this->conditions."
					ORDER BY	user.email";
				$statement = WCF::getDB()->prepareStatement($sql);
				$statement->execute($this->conditions->getParameters());
				
				$i = 0;
				while ($row = $statement->fetchArray()) {
					if ($this->fileType == 'xml') echo "<address><![CDATA[".StringUtil::escapeCDATA($row['email'])."]]></address>\n";
					else echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $count['count'] ? $this->separator : '');
					$i++;
					$this->affectedUsers++;
				}
				
				if ($this->fileType == 'xml') {
					echo "</addresses>";
				}
				$this->saved();
				exit;
			break;
			
			case 'assignToGroup':
				WCF::getSession()->checkPermissions(array('admin.user.canEditUser'));
				
				$userIDArray = $this->fetchUsers(function($userID, array $userData) {
					$user = new UserEditor(new User(null, $userData));
					$user->addToGroups($this->assignToGroupIDArray, false, false);
				});
				
				UserStorageHandler::getInstance()->reset($userIDArray, 'groupIDs', 1);
			break;
			
			case 'delete':
				WCF::getSession()->checkPermissions(array('admin.user.canDeleteUser'));
				
				$userIDArray = $this->fetchUsers();
				
				UserEditor::deleteUsers($userIDArray);
			break;
		}
		$this->saved();
		
		WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
	}
 /**
  * @inheritDoc
  */
 public function getOutstandingItemCount($objectID = null)
 {
     if ($this->notifications === null) {
         $this->notifications = 0;
         if (WCF::getUser()->userID) {
             $data = UserStorageHandler::getInstance()->getField('filebaseUnreaWatchedEntries');
             // cache does not exist or is outdated
             if ($data === null) {
                 $categoryIDs = FilebaseCategory::getAccessibleCategoryIDs();
                 if (!empty($categoryIDs)) {
                     $objectTypeID = UserObjectWatchHandler::getInstance()->getObjectTypeID('de.incendium.filebase.entry');
                     $conditionBuilder = new PreparedStatementConditionBuilder();
                     $conditionBuilder->add('user_object_watch.objectTypeID = ?', array($objectTypeID));
                     $conditionBuilder->add('user_object_watch.userID = ?', array(WCF::getUser()->userID));
                     $conditionBuilder->add('entry.lastChangeTime > ?', array(VisitTracker::getInstance()->getVisitTime('de.incendium.filebase.entry')));
                     $conditionBuilder->add('entry.entryID IN (SELECT entryID FROM filebase' . WCF_N . '_entry_to_category WHERE categoryID IN (?))', array($categoryIDs));
                     $conditionBuilder->add('entry.isDeleted = 0 AND entry.isDisabled = 0');
                     $conditionBuilder->add('(entry.lastChangeTime > tracked_file_visit.visitTime OR tracked_file_visit.visitTime IS NULL)');
                     $sql = "SELECT        COUNT(*) AS count\n                            FROM        wcf" . WCF_N . "_user_object_watch user_object_watch\n                            LEFT JOIN    filebase" . WCF_N . "_entry entry\n                            ON        (entry.entryID = user_object_watch.objectID)\n                            LEFT JOIN    wcf" . WCF_N . "_tracked_visit tracked_file_visit\n                            ON        (tracked_file_visit.objectTypeID = " . VisitTracker::getInstance()->getObjectTypeID('de.incendium.filebase.entry') . " AND tracked_file_visit.objectID = entry.entryID AND tracked_file_visit.userID = " . WCF::getUser()->userID . ")\n                            " . $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, 'filebaseUnreadWatchedEntries', $this->notifications);
             } else {
                 $this->notifications = $data;
             }
         }
     }
     return $this->notifications;
 }
 /**
  * Marks all notifications of current user as confirmed.
  */
 public function markAllAsConfirmed()
 {
     // remove notifications for this user
     $sql = "UPDATE\twcf" . WCF_N . "_user_notification\n\t\t\tSET\tconfirmTime = ?\n\t\t\tWHERE\tuserID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(TIME_NOW, WCF::getUser()->userID));
     // delete notification_to_user assignments (mimic legacy notification system)
     $sql = "DELETE FROM\twcf" . WCF_N . "_user_notification_to_user\n\t\t\tWHERE\t\tuserID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute(array(WCF::getUser()->userID));
     // reset notification count
     UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'userNotificationCount');
     return array('markAllAsRead' => true);
 }
 /**
  * @see	\wcf\system\user\object\watch\IUserObjectWatch::resetUserStorage()
  */
 public function resetUserStorage(array $userIDs)
 {
     UserStorageHandler::getInstance()->reset($userIDs, 'newsUnreadWatchedEntries');
     UserStorageHandler::getInstance()->reset($userIDs, 'newsSubscribedCategories');
 }