Beispiel #1
0
 public function actionRotate()
 {
     $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
     $newTitle = $this->_input->filterSingle('newTitle', XenForo_Input::STRING);
     $ftpHelper = $this->getHelper('ForumThreadPost');
     list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId);
     $threadModel = $this->_getThreadModel();
     if (!XenForo_Visitor::getInstance()->hasPermission('forum', 'manageAnyThread')) {
         throw $this->getErrorOrNoPermissionResponseException(false);
     }
     $viewingUser = XenForo_Visitor::getInstance();
     if ($this->isConfirmedPost()) {
         /* Let's create the DataWriter associated on Threads */
         $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
         $threadWriter->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
         $threadWriter->setOption(XenForo_DataWriter_Discussion::OPTION_TRIM_TITLE, true);
         $threadWriter->bulkSet(array('title' => $newTitle, 'user_id' => $viewingUser['user_id'], 'username' => $viewingUser['username'], 'sticky' => $thread['sticky'], 'discussion_open' => $thread['discussion_open'], 'discussion_state' => $thread['discussion_state'], 'prefix_id' => $thread['prefix_id'], 'node_id' => $thread['node_id']));
         $originalUser = $this->getModelFromCache('XenForo_Model_User')->getUserById($thread['user_id']);
         $params['title'] = $thread['title'];
         $params['username'] = $thread['username'];
         $params['userLink'] = XenForo_Link::buildPublicLink('canonical:members', $originalUser);
         $params['link'] = XenForo_Link::buildPublicLink('full:threads', $thread);
         $message = new XenForo_Phrase('llama_rt_new_rotated_thread_message', $params, false);
         $postWriter = $threadWriter->getFirstMessageDw();
         $postWriter->set('message', $message->render());
         $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum);
         /* Save all changes and we are done with new thread! */
         $result = $threadWriter->save();
         $newThreadId = $threadWriter->get('thread_id');
         list($newThread, $newForum) = $ftpHelper->assertThreadValidAndViewable($newThreadId);
         /* Add new post at end of old thread */
         $params['title'] = $newTitle;
         $params['link'] = XenForo_Link::buildPublicLink('full:threads', $newThread);
         $message = new XenForo_Phrase('llama_rt_old_rotated_thread_message', $params, false);
         $postWriter = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');
         $postWriter->set('user_id', $viewingUser['user_id']);
         $postWriter->set('username', $viewingUser['username']);
         $postWriter->set('message', $message->render());
         $postWriter->set('message_state', $this->_getPostModel()->getPostInsertMessageState($thread, $forum));
         $postWriter->set('thread_id', $threadId);
         $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum);
         $postWriter->save();
         /* Close and unstick original thread */
         $dwInput = array('discussion_open' => FALSE, 'sticky' => FALSE);
         $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
         $threadWriter->setExistingData($threadId);
         $threadWriter->bulkSet($dwInput);
         $threadWriter->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
         $threadWriter->save();
         XenForo_Model_Log::logModeratorAction('thread', $thread, 'rotate', array('new_title' => $newTitle));
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('full:threads', $newThread));
     } else {
         // Guess the new title
         $newTitleGuess = preg_replace_callback("#(\\d+)\$#", function ($m) {
             return ++$m[1];
         }, $thread['title']);
         $viewParams = array('newTitleGuess' => $newTitleGuess, 'thread' => $thread);
         return $this->responseView('Llama_ViewPublic_Thread_Rotate', 'llama_thread_rotate', $viewParams);
     }
 }
Beispiel #2
0
 protected function deleteItem(array $item, array $data, array $input)
 {
     XenForo_Model_Log::logModeratorAction($input['content_type'], $data, 'portal_remove');
     SimplePortal_Helper_Content::demote($item['content_type'], $item['content_id']);
     $redirectLink = XenForo_Link::buildPublicLink('portal/manage-items');
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $redirectLink);
 }
Beispiel #3
0
 public function actionTrash()
 {
     if (!XenForo_Visitor::getInstance()->hasPermission('forum', 'trashThreads')) {
         throw $this->getErrorOrNoPermissionResponseException(false);
     }
     if (!($targetNode = XenForo_Application::getOptions()->nixfifty_trash_can)) {
         return $this->responseError(new XenForo_Phrase('trash_can_node_not_set'));
     }
     $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
     list($thread, $forum) = $this->getHelper('ForumThreadPost')->assertThreadValidAndViewable($threadId);
     if ($this->isConfirmedPost()) {
         $softDelete = $this->_input->filterSingle('trash_type', XenForo_Input::UINT);
         $trashType = $softDelete ? 'move' : 'soft';
         $options = array('reason' => $this->_input->filterSingle('reason', XenForo_Input::STRING));
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
         $dw->setExistingData($threadId);
         $dw->set('node_id', $targetNode);
         $dw->save();
         if ($trashType == 'soft' && XenForo_Visitor::getInstance()->hasPermission('forum', 'softDeleteTrashedThreads')) {
             $this->_getThreadModel()->deleteThread($threadId, $trashType, $options);
             XenForo_Model_Log::logModeratorAction('thread', $thread, 'delete_' . $trashType, array('reason' => $options['reason']));
         }
         XenForo_Model_Log::logModeratorAction('thread', $thread, 'move', array('from' => $forum['title']));
         $this->_updateModeratorLogThreadEdit($thread, $dw, array('node_id'));
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('forums', $forum));
     } else {
         return $this->responseView('', 'trash_thread', array('thread' => $thread));
     }
 }
Beispiel #4
0
 protected function _deleteContent(array $content, $reason, array $viewingUser)
 {
     $updateDw = XenForo_DataWriter::create('XenResource_DataWriter_Rating');
     $updateDw->setExistingData($content);
     $updateDw->set('rating_state', 'deleted');
     $updateDw->save();
     XenForo_Model_Log::logModeratorAction('resource_rating', $content, 'delete_soft');
 }
Beispiel #5
0
 protected function _deleteContent(array $content, $reason, array $viewingUser)
 {
     $updateDw = XenForo_DataWriter::create('XenResource_DataWriter_Update');
     $updateDw->setExistingData($content);
     $updateDw->setExtraData(XenResource_DataWriter_Update::DATA_DELETE_REASON, $reason);
     $updateDw->set('message_state', 'deleted');
     $updateDw->save();
     XenForo_Model_Log::logModeratorAction('resource_update', $content, 'delete_soft', array('reason' => $reason));
 }
 protected function _deleteContent(array $content, $reason, array $viewingUser)
 {
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_ProfilePostComment', XenForo_DataWriter::ERROR_SILENT);
     if ($dw->setExistingData($content)) {
         $dw->setExtraData(XenForo_DataWriter_DiscussionMessage::DATA_DELETE_REASON, $reason);
         $dw->set('message_state', 'deleted');
         $dw->save();
     }
     XenForo_Model_Log::logModeratorAction('profile_post_comment', $content, 'delete_soft', array('reason' => $reason), $this->_getProfilePostModel()->getProfilePostById($content['profile_post_id']));
 }
Beispiel #7
0
 /**
  * @param int $contentId
  * @return bool
  */
 public function deleteModerationQueueEntry($contentId)
 {
     $dw = XenForo_DataWriter::create('sonnb_XenGallery_DataWriter_Album', XenForo_DataWriter::ERROR_SILENT);
     $dw->setExistingData($contentId);
     $dw->set('album_state', 'deleted');
     if ($dw->save()) {
         XenForo_Model_Log::logModeratorAction(sonnb_XenGallery_Model_Album::$xfContentType, $dw->getMergedData(), 'delete_soft', array('reason' => ''));
         return true;
     } else {
         return false;
     }
 }
Beispiel #8
0
 /**
  * Deletes the specified moderation queue entry.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::deleteModerationQueueEntry()
  */
 public function deleteModerationQueueEntry($contentId)
 {
     $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource', XenForo_DataWriter::ERROR_SILENT);
     $dw->setExistingData($contentId);
     $dw->set('resource_state', 'deleted');
     if ($dw->save()) {
         XenForo_Model_Log::logModeratorAction('resource', $dw->getMergedData(), 'delete_soft', array('reason' => ''));
         return true;
     } else {
         return false;
     }
 }
Beispiel #9
0
 /**
  * Deletes the specified moderation queue entry.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::deleteModerationQueueEntry()
  */
 public function deleteModerationQueueEntry($contentId)
 {
     $dw = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForum', XenForo_DataWriter::ERROR_SILENT);
     $dw->setExistingData($contentId);
     $dw->delete();
     if ($dw->save()) {
         XenForo_Model_Log::logModeratorAction('socialForum', $dw->getMergedData(), 'delete', array('reason' => ''));
         return true;
     } else {
         return false;
     }
 }
Beispiel #10
0
 public function actionStaffShare()
 {
     $visitor = XenForo_Visitor::getInstance();
     if (!$visitor->hasPermission('general', 'bdSocialShare_staffShare')) {
         return $this->responseNoPermission();
     }
     $url = $this->_input->filterSingle('url', XenForo_Input::STRING);
     if (empty($url)) {
         return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare_UrlForm', 'bdsocialshare_staff_share_url_form');
     }
     $request = new Zend_Controller_Request_Http($url);
     $request->setParamSources(array());
     $routeMatch = bdSocialShare_Listener::getDependencies()->route($request);
     $shareable = $this->getModelFromCache('bdSocialShare_Model_Publisher')->getShareableForRouteMatchAndRequest($routeMatch, $request);
     if (empty($shareable)) {
         return $this->responseMessage(new XenForo_Phrase('bdsocialshare_url_x_is_not_supported', array('url' => $url)));
     }
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     $viewingUserGuest = $userModel->getVisitingGuestUser();
     $userModel->bdSocialShare_prepareViewingUser($viewingUserGuest);
     $shareable->setViewingUser($viewingUserGuest);
     $publisherModel = $this->getModelFromCache('bdSocialShare_Model_Publisher');
     $facebookAccounts = false;
     if (bdSocialShare_Option::hasPermissionFacebook($viewingUserGuest)) {
         $facebookAccounts = $this->getModelFromCache('bdSocialShare_Model_Facebook')->getAccounts();
     }
     $twitterAccounts = false;
     if (bdSocialShare_Option::hasPermissionTwitter($viewingUserGuest)) {
         $twitterAccounts = $this->getModelFromCache('bdSocialShare_Model_Twitter')->getAccounts();
     }
     if ($this->isConfirmedPost()) {
         $target = $this->_input->filterSingle('target', XenForo_Input::STRING);
         $targetId = $this->_input->filterSingle('target_id', XenForo_Input::STRING);
         $data = $this->_input->filter(array('userText' => XenForo_Input::STRING, 'title' => XenForo_Input::STRING, 'description' => XenForo_Input::STRING, 'image' => XenForo_Input::STRING));
         $data['link'] = $shareable->getLink($publisherModel);
         $staffShareSharable = new bdSocialShare_Shareable_StaffShare($data);
         $published = false;
         try {
             $published = $publisherModel->publish($target, $targetId, $staffShareSharable, $viewingUserGuest);
         } catch (XenForo_Exception $e) {
             XenForo_Error::logException($e);
         }
         if ($published) {
             XenForo_Model_Log::logModeratorAction('bdsocialshare_all', $data, $target, array('target_id' => $targetId));
             return $this->responseMessage(new XenForo_Phrase('bdsocialshare_staff_share_published_successfully'));
         } else {
             return $this->responseError(new XenForo_Phrase('unexpected_error_occurred'));
         }
     }
     $viewParams = array('facebookAccounts' => $facebookAccounts, 'twitterAccounts' => $twitterAccounts, 'hasAdminPermissionOption' => $visitor->hasAdminPermission('option'), 'url' => $url, 'link' => $shareable->getLink($publisherModel), 'userText' => strval($shareable->getUserText($publisherModel)), 'title' => strval($shareable->getTitle($publisherModel)), 'description' => strval($shareable->getDescription($publisherModel)), 'image' => $shareable->getImage($publisherModel));
     return $this->responseView('bdSocialShare_ViewPublic_Misc_StaffShare', 'bdsocialshare_staff_share', $viewParams);
 }
Beispiel #11
0
 /**
  * Deletes the specified moderation queue entry.
  *
  * @see XenForo_ModerationQueueHandler_Abstract::deleteModerationQueueEntry()
  */
 public function deleteModerationQueueEntry($contentId)
 {
     $dw = XenForo_DataWriter::create('XenGallery_DataWriter_Comment', XenForo_DataWriter::ERROR_SILENT);
     $dw->setExistingData($contentId);
     $dw->set('comment_state', 'deleted');
     if ($dw->save()) {
         $comment = $this->_getCommentModel()->getCommentById($contentId, array('join' => XenGallery_Model_Comment::FETCH_MEDIA | XenGallery_Model_Comment::FETCH_ALBUM_CONTENT | XenGallery_Model_Comment::FETCH_USER));
         XenForo_Model_Log::logModeratorAction('xengallery_comment', $comment, 'delete_soft', array('reason' => ''));
         return true;
     } else {
         return false;
     }
 }
Beispiel #12
0
 /**
  * Executes the spam cleaner against the specified user
  *
  * @param array Spam user
  * @param array Usually the result of the choices made on the spam cleaner options form
  * @param array Will be populated with a log of actions performed
  * @param string If a problem occurs, this will be populated with an error phrase key
  *
  * @return boolean
  */
 public function cleanUp(array $user, array $actions, &$log = array(), &$errorKey = '')
 {
     $db = $this->_getDb();
     XenForo_Db::beginTransaction($db);
     $options = XenForo_Application::get('options');
     $log = array();
     if (!empty($actions['ban_user'])) {
         if (!$this->_banUser($user, $log, $errorKey)) {
             XenForo_Db::rollback($db);
             return false;
         }
         if ($user['user_state'] == 'moderated') {
             // they're banned now, so we can approve them so we don't have to manually deal with them
             $this->_getUserModel()->update($user, 'user_state', 'valid');
         }
         if ($options->stopForumSpam['submitRejections'] && $options->stopForumSpam['apiKey']) {
             $registrationIps = $this->getModelFromCache('XenForo_Model_User')->getRegistrationIps($user['user_id']);
             $spamCheckData = $user;
             $spamCheckData['ip'] = reset($registrationIps);
             $this->getModelFromCache('XenForo_Model_SpamPrevention')->submitSpamUserData($spamCheckData);
         }
     }
     foreach ($this->getSpamHandlers() as $contentType => $spamHandler) {
         if ($spamHandler->cleanUpConditionCheck($user, $actions)) {
             if (!$spamHandler->cleanUp($user, $log, $errorKey)) {
                 XenForo_Db::rollback($db);
                 return false;
             }
         }
     }
     if (!empty($actions['delete_messages'])) {
         /** @var $reportModel XenForo_Model_Report */
         $reportModel = $this->getModelFromCache('XenForo_Model_Report');
         $reports = $reportModel->getReportsByContentUserId($user['user_id']);
         $reportModel->updateReports($reports, 'resolved', true);
     }
     if (!empty($log)) {
         if (!empty($actions['email_user'])) {
             $this->_emailUser($user, $actions['email'], $log);
         }
         $visitor = XenForo_Visitor::getInstance();
         // log progress
         $db->insert('xf_spam_cleaner_log', array('user_id' => $user['user_id'], 'username' => $user['username'], 'applying_user_id' => $visitor['user_id'], 'applying_username' => $visitor['username'], 'application_date' => XenForo_Application::$time, 'data' => $log ? serialize($log) : ''));
         XenForo_Model_Log::logModeratorAction('user', $user, 'spam_clean');
     }
     XenForo_Db::commit($db);
     return true;
 }
Beispiel #13
0
 public function trashThreads(array $threadIds, array $options = array(), &$errorKey = '', array $viewingUser = null)
 {
     if (!($targetNode = XenForo_Application::getOptions()->nixfifty_trash_can)) {
         return $this->responseError(new XenForo_Phrase('trash_can_node_not_set'));
     }
     $options = array_merge(array('deleteType' => '', 'reason' => ''), $options);
     if (!$options['deleteType']) {
         throw new XenForo_Exception('No deletion type specified.');
     }
     list($threads, $forums) = $this->getThreadsAndParentData($threadIds, $viewingUser);
     if (!XenForo_Visitor::getInstance()->hasPermission('forum', 'trashThreads')) {
         return false;
     }
     foreach ($threads as $thread) {
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
         if (!$dw->setExistingData($thread)) {
             continue;
         }
         if (array_key_exists($dw->get('node_id'), $forums)) {
             $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forums[$dw->get('node_id')]);
         }
         $dw->set('node_id', $targetNode);
         $dw->save();
         if ($options['deleteType'] == 'soft') {
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
             if (!$dw->setExistingData($thread)) {
                 continue;
             }
             $dw->setExtraData(XenForo_DataWriter_Discussion::DATA_DELETE_REASON, $options['reason']);
             $dw->set('discussion_state', 'deleted');
             $dw->save();
         }
         if ($this->enableLogging) {
             if ($thread['node_id'] != $targetNode) {
                 $forum = $this->_getForumFromThread($thread, $forums);
                 $forumTitle = $forum ? $forum['title'] : '';
                 XenForo_Model_Log::logModeratorAction('thread', $thread, 'move', array('from' => $forumTitle));
             }
             if ($options['deleteType'] == 'soft' && !$thread['discussion_state'] == 'deleted') {
                 XenForo_Model_Log::logModeratorAction('thread', $thread, 'delete_soft', array('reason' => $options['reason']));
             }
         }
     }
     return true;
 }
Beispiel #14
0
 /**
  * Adds a poll to this thread.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionPollAdd()
 {
     $threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
     $ftpHelper = $this->getHelper('ForumThreadPost');
     list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId);
     $threadModel = $this->_getThreadModel();
     if (!$threadModel->canAddPoll($thread, $forum, $errorPhraseKey)) {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     if ($this->_request->isPost()) {
         /** @var XenForo_Model_Poll $pollModel */
         $pollModel = $this->getModelFromCache('XenForo_Model_Poll');
         $pollInput = $this->_input->filterSingle('poll', XenForo_Input::ARRAY_SIMPLE);
         $pollDw = $pollModel->setupNewPollFromForm(new XenForo_Input($pollInput));
         $pollDw->set('content_type', 'thread');
         $pollDw->set('content_id', $thread['thread_id']);
         $pollDw->save();
         $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
         $threadWriter->setExistingData($thread['thread_id']);
         $threadWriter->set('discussion_type', 'poll');
         $threadWriter->save();
         if (XenForo_Visitor::getUserId() != $thread['user_id']) {
             XenForo_Model_Log::logModeratorAction('thread', $thread, 'poll_add');
         }
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('threads', $thread));
     } else {
         $maxResponses = XenForo_Application::get('options')->pollMaximumResponses;
         if ($maxResponses == 0) {
             $maxResponses = 10;
             // number to create for non-JS users
         }
         if ($maxResponses > 2) {
             $pollExtraArray = array_fill(0, $maxResponses - 2, true);
         } else {
             $pollExtraArray = array();
         }
         $viewParams = array('thread' => $thread, 'forum' => $forum, 'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum), 'pollExtraArray' => $pollExtraArray);
         return $this->responseView('XenForo_ViewPublic_Thread_PollAdd', 'thread_poll_add', $viewParams);
     }
 }
Beispiel #15
0
 protected function _deleteContent(array $content, $reason, array $viewingUser)
 {
     $this->_getPostModel()->deletePost($content['post_id'], 'soft', array('reason' => $reason));
     XenForo_Model_Log::logModeratorAction('post', $content, 'delete_soft', array('reason' => $reason), $content);
     XenForo_Helper_Cookie::clearIdFromCookie($content['post_id'], 'inlinemod_posts');
 }
Beispiel #16
0
 protected function _updateCommentsBulk(array $comments, array $updates, $logAction = '')
 {
     foreach ($comments as $comment) {
         $dw = XenForo_DataWriter::create('sonnb_XenGallery_DataWriter_Comment', XenForo_DataWriter::ERROR_SILENT);
         $dw->setExistingData($comment);
         $dw->bulkSet($updates);
         $dw->save();
         if ($dw->hasChanges() && $this->enableLogging && $logAction) {
             XenForo_Model_Log::logModeratorAction('sonnb_xengallery_comment', $comment, $logAction);
         }
     }
 }
Beispiel #17
0
 public function actionCommentUnapprove()
 {
     $csrfToken = $this->_input->filterSingle('t', XenForo_Input::STRING);
     $this->_checkCsrfFromToken($csrfToken);
     $commentId = $this->_input->filterSingle('profile_post_comment_id', XenForo_Input::UINT);
     list($comment, $profilePost, $user) = $this->getHelper('UserProfile')->assertProfilePostCommentValidAndViewable($commentId);
     $profilePostModel = $this->_getProfilePostModel();
     if (!$profilePostModel->canApproveUnapproveProfilePostComment($comment, $profilePost, $user, $errorPhraseKey) || $comment['message_state'] == 'moderated') {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_ProfilePostComment');
     $dw->setExistingData($comment);
     $dw->set('message_state', 'moderated');
     $dw->save();
     XenForo_Model_Log::logModeratorAction('profile_post_comment', $comment, 'unapprove', array(), $profilePost);
     return $this->getProfilePostSpecificRedirect($profilePost, $user);
 }
Beispiel #18
0
 /**
  * Internal helper to update the message_state of a collection of posts.
  *
  * @param array $posts Information about the posts to update
  * @param array $threads Information about the threads that the posts are in
  * @param array $forums Information about the forums that the threads/posts are in
  * @param string $newState New message state (visible, moderated, deleted)
  * @param string|false $expectedOldState If specified, only updates if the old state matches
  */
 protected function _updatePostsMessageState(array $posts, array $threads, array $forums, $newState, $expectedOldState = false)
 {
     switch ($newState) {
         case 'visible':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     return;
                 case 'moderated':
                     $logAction = 'approve';
                     break;
                 case 'deleted':
                     $logAction = 'undelete';
                     break;
                 default:
                     $logAction = 'undelete';
                     break;
             }
             break;
         case 'moderated':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'unapprove';
                     break;
                 case 'moderated':
                     return;
                 case 'deleted':
                     $logAction = 'unapprove';
                     break;
                 default:
                     $logAction = 'unapprove';
                     break;
             }
             break;
         case 'deleted':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'delete_soft';
                     break;
                 case 'moderated':
                     $logAction = 'delete_soft';
                     break;
                 case 'deleted':
                     return;
                 default:
                     $logAction = 'delete_soft';
                     break;
             }
             break;
         default:
             return;
     }
     foreach ($posts as $post) {
         list($thread, $forum) = $this->_getThreadAndForumFromPost($post, $threads, $forums);
         if ($post['post_id'] == $thread['first_post_id']) {
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
             $dw->setExistingData($thread);
             if ($expectedOldState && $dw->get('discussion_state') != $expectedOldState) {
                 continue;
             }
             $dw->set('discussion_state', $newState);
             $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
             $dw->save();
             if ($this->enableLogging) {
                 XenForo_Model_Log::logModeratorAction('thread', $thread, $logAction);
             }
         } else {
             if ($expectedOldState && $post['message_state'] != $expectedOldState) {
                 continue;
             }
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post', XenForo_DataWriter::ERROR_SILENT);
             $dw->setExistingData($post);
             $dw->set('message_state', $newState);
             $dw->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum);
             $dw->save();
             if ($this->enableLogging) {
                 XenForo_Model_Log::logModeratorAction('post', $post, $logAction, array(), $thread);
             }
         }
     }
 }
Beispiel #19
0
 protected function _updateModeratorLogThreadEdit(array $thread, XenForo_DataWriter_Discussion_Thread $dw, array $skip = array())
 {
     $newData = $dw->getMergedNewData();
     if ($newData) {
         $oldData = $dw->getMergedExistingData();
         $basicLog = array();
         foreach ($newData as $key => $value) {
             $oldValue = isset($oldData[$key]) ? $oldData[$key] : '-';
             switch ($key) {
                 case 'moderate_replies_th':
                     XenForo_Model_Log::logModeratorAction('thread', $thread, $value ? 'enable_moderate_replies' : 'disable_moderate_replies');
                     $skip[] = 'moderate_replies_th';
                     break;
             }
         }
     }
     return parent::_updateModeratorLogThreadEdit($thread, $dw, $skip);
 }
Beispiel #20
0
 /**
  * Bulk update 1 or more fields in the given threads.
  *
  * @param array $threads List of threads to update
  * @param array $forums List of forums threads are in
  * @param array $updates Key-value pairs to update
  * @param string $logAction If specified, this action will be logged with this action
  */
 protected function _updateThreadsBulk(array $threads, array $forums, array $updates, $logAction = '')
 {
     foreach ($threads as $thread) {
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT);
         if (!$dw->setExistingData($thread)) {
             continue;
         }
         $dw->bulkSet($updates);
         if (array_key_exists($dw->get('node_id'), $forums)) {
             $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forums[$dw->get('node_id')]);
         }
         $dw->save();
         if ($dw->hasChanges() && $this->enableLogging && $logAction) {
             XenForo_Model_Log::logModeratorAction('thread', $thread, $logAction);
         }
     }
 }
Beispiel #21
0
 /**
  * Internal helper to update the team_state of a collection of teams.
  *
  * @param array $teams Information about the teams to update
  * @param array $categories Information about the categories that the teams are in
  * @param string $newState New message state (visible, moderated, deleted)
  * @param string|false $expectedOldState If specified, only updates if the old state matches
  */
 protected function _updateTeamState(array $teams, array $categories, $newState, $expectedOldState = false)
 {
     switch ($newState) {
         case 'visible':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     return;
                 case 'moderated':
                     $logAction = 'approve';
                     break;
                 case 'deleted':
                     $logAction = 'undelete';
                     break;
                 default:
                     $logAction = 'undelete';
                     break;
             }
             break;
         case 'moderated':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'unapprove';
                     break;
                 case 'moderated':
                     return;
                 case 'deleted':
                     $logAction = 'unapprove';
                     break;
                 default:
                     $logAction = 'unapprove';
                     break;
             }
             break;
         case 'deleted':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'delete_soft';
                     break;
                 case 'moderated':
                     $logAction = 'delete_soft';
                     break;
                 case 'deleted':
                     return;
                 default:
                     $logAction = 'delete_soft';
                     break;
             }
             break;
         default:
             return;
     }
     foreach ($teams as $team) {
         if ($expectedOldState && $team['team_state'] != $expectedOldState) {
             continue;
         }
         $dw = XenForo_DataWriter::create('Nobita_Teams_DataWriter_Team', XenForo_DataWriter::ERROR_SILENT);
         if (!$dw->setExistingData($team)) {
             continue;
         }
         $dw->set('team_state', $newState);
         $dw->save();
         if ($this->enableLogging) {
             XenForo_Model_Log::logModeratorAction('team', $team, $logAction);
         }
     }
 }
Beispiel #22
0
 public function actionDeleteVersion()
 {
     list($version, $resource, $category) = $this->_getResourceHelper()->assertVersionValidAndViewable();
     $hardDelete = $this->_input->filterSingle('hard_delete', XenForo_Input::UINT);
     $deleteType = $hardDelete ? 'hard' : 'soft';
     if (!$this->_getVersionModel()->canDeleteVersion($version, $resource, $category, $deleteType, $errorPhraseKey)) {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     if ($this->isConfirmedPost()) {
         $versionDw = XenForo_DataWriter::create('XenResource_DataWriter_Version');
         $versionDw->setExistingData($version['resource_version_id']);
         if ($hardDelete) {
             $versionDw->delete();
             XenForo_Model_Log::logModeratorAction('resource_version', $version, 'delete_hard');
         } else {
             $reason = $this->_input->filterSingle('reason', XenForo_Input::STRING);
             $versionDw->setExtraData(XenResource_DataWriter_Version::DATA_DELETE_REASON, $reason);
             $versionDw->set('version_state', 'deleted');
             $versionDw->save();
             if (XenForo_Visitor::getUserId() != $resource['user_id']) {
                 XenForo_Model_Log::logModeratorAction('resource_version', $version, 'delete_soft', array('reason' => $reason));
             }
         }
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('resources', $resource));
     } else {
         $viewParams = array('resource' => $resource, 'category' => $category, 'categoryBreadcrumbs' => $this->_getCategoryModel()->getCategoryBreadcrumb($category), 'version' => $version, 'canHardDelete' => $this->_getVersionModel()->canDeleteVersion($version, $resource, $category, 'hard'));
         return $this->responseView('XenResource_ViewPublic_Resource_DeleteVersion', 'resource_version_delete', $viewParams);
     }
 }
Beispiel #23
0
 /**
  * Internal helper to update the resource_state of a collection of resources.
  *
  * @param array $resources Information about the resources to update
  * @param array $categories List of categories the resources are in
  * @param string $newState New message state (visible, moderated, deleted)
  * @param string|bool $expectedOldState If specified, only updates if the old state matches
  */
 protected function _updateResourcesResourceState(array $resources, array $categories, $newState, $expectedOldState = false)
 {
     switch ($newState) {
         case 'visible':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     return;
                 case 'moderated':
                     $logAction = 'approve';
                     break;
                 case 'deleted':
                     $logAction = 'undelete';
                     break;
                 default:
                     $logAction = 'undelete';
                     break;
             }
             break;
         case 'moderated':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'unapprove';
                     break;
                 case 'moderated':
                     return;
                 case 'deleted':
                     $logAction = 'unapprove';
                     break;
                 default:
                     $logAction = 'unapprove';
                     break;
             }
             break;
         case 'deleted':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'delete_soft';
                     break;
                 case 'moderated':
                     $logAction = 'delete_soft';
                     break;
                 case 'deleted':
                     return;
                 default:
                     $logAction = 'delete_soft';
                     break;
             }
             break;
         default:
             return;
     }
     foreach ($resources as $resource) {
         if ($expectedOldState && $resource['resource_state'] != $expectedOldState) {
             continue;
         }
         $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource', XenForo_DataWriter::ERROR_SILENT);
         $dw->setExistingData($resource);
         $dw->set('resource_state', $newState);
         $dw->save();
         if ($this->enableLogging) {
             XenForo_Model_Log::logModeratorAction('resource', $resource, $logAction, array());
         }
     }
 }
Beispiel #24
0
 /**
  * Internal helper to update the message_state of a collection of profile posts.
  *
  * @param array $profilePosts Information about the profile posts to update
  * @param array $users List of users whose profiles the posts are on
  * @param string $newState New message state (visible, moderated, deleted)
  * @param string|false $expectedOldState If specified, only updates if the old state matches
  */
 protected function _updateProfilePostsMessageState(array $profilePosts, array $users, $newState, $expectedOldState = false)
 {
     switch ($newState) {
         case 'visible':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     return;
                 case 'moderated':
                     $logAction = 'approve';
                     break;
                 case 'deleted':
                     $logAction = 'undelete';
                     break;
                 default:
                     $logAction = 'undelete';
                     break;
             }
             break;
         case 'moderated':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'unapprove';
                     break;
                 case 'moderated':
                     return;
                 case 'deleted':
                     $logAction = 'unapprove';
                     break;
                 default:
                     $logAction = 'unapprove';
                     break;
             }
             break;
         case 'deleted':
             switch (strval($expectedOldState)) {
                 case 'visible':
                     $logAction = 'delete_soft';
                     break;
                 case 'moderated':
                     $logAction = 'delete_soft';
                     break;
                 case 'deleted':
                     return;
                 default:
                     $logAction = 'delete_soft';
                     break;
             }
             break;
         default:
             return;
     }
     foreach ($profilePosts as $profilePost) {
         if ($expectedOldState && $profilePost['message_state'] != $expectedOldState) {
             continue;
         }
         $user = $this->_getUserFromProfilePost($profilePost, $users);
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_ProfilePost', XenForo_DataWriter::ERROR_SILENT);
         $dw->setExistingData($profilePost);
         $dw->set('message_state', $newState);
         $dw->save();
         if ($this->enableLogging) {
             XenForo_Model_Log::logModeratorAction('profile_post', $profilePost, $logAction, array(), $user);
         }
     }
 }
Beispiel #25
0
 /**
  * Deletes an existing post.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionDelete()
 {
     $postId = $this->_input->filterSingle('post_id', XenForo_Input::UINT);
     $ftpHelper = $this->getHelper('ForumThreadPost');
     list($post, $thread, $forum) = $ftpHelper->assertPostValidAndViewable($postId);
     $hardDelete = $this->_input->filterSingle('hard_delete', XenForo_Input::UINT);
     $deleteType = $hardDelete ? 'hard' : 'soft';
     $this->_assertCanDeletePost($post, $thread, $forum, $deleteType);
     $postModel = $this->_getPostModel();
     if ($this->isConfirmedPost()) {
         $options = array('reason' => $this->_input->filterSingle('reason', XenForo_Input::STRING), 'authorAlert' => $this->_input->filterSingle('send_author_alert', XenForo_Input::BOOLEAN), 'authorAlertReason' => $this->_input->filterSingle('author_alert_reason', XenForo_Input::STRING));
         if ($thread['discussion_state'] != 'visible' || $post['message_state'] != 'visible' || $post['user_id'] == XenForo_Visitor::getUserId()) {
             $options['authorAlert'] = false;
         }
         $dw = $postModel->deletePost($postId, $deleteType, $options, $forum);
         if ($post['post_id'] == $thread['first_post_id']) {
             XenForo_Model_Log::logModeratorAction('thread', $thread, 'delete_' . $deleteType, array('reason' => $options['reason']));
         } else {
             XenForo_Model_Log::logModeratorAction('post', $post, 'delete_' . $deleteType, array('reason' => $options['reason']), $thread);
         }
         XenForo_Helper_Cookie::clearIdFromCookie($postId, 'inlinemod_posts');
         if ($dw->discussionDeleted() || !$post['position']) {
             XenForo_Helper_Cookie::clearIdFromCookie($thread['thread_id'], 'inlinemod_threads');
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildPublicLink('forums', $forum));
         } else {
             return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(XenForo_Link::buildPublicLink('threads', $thread)));
         }
     } else {
         $viewParams = array('post' => $post, 'thread' => $thread, 'forum' => $forum, 'nodeBreadCrumbs' => $ftpHelper->getNodeBreadCrumbs($forum), 'canHardDelete' => $postModel->canDeletePost($post, $thread, $forum, 'hard'), 'redirect' => $this->getDynamicRedirect(XenForo_Link::buildPublicLink('threads', $thread)));
         return $this->responseView('XenForo_ViewPublic_Post_Delete', 'post_delete', $viewParams);
     }
 }
Beispiel #26
0
 public final function warn(array $warning, array $content, $publicMessage = '', array $viewingUser = null)
 {
     $this->_standardizeViewingUser($viewingUser);
     $this->_warn($warning, $content, $publicMessage, $viewingUser);
     XenForo_Model_Log::logModeratorAction('user', $warning, 'warn', array('warning_title' => $warning['title']));
 }
Beispiel #27
0
 public function actionDeleteComments()
 {
     $profilePostId = $this->_input->filterSingle('profile_post_id', XenForo_Input::UINT);
     $commentId = $this->_input->filterSingle('comment_id', XenForo_Input::UINT);
     list($comment, $profilePost, $user) = $this->_getUserProfileHelper()->assertProfilePostCommentValidAndViewable($commentId, $this->_getProfilePostModel()->getCommentFetchOptionsToPrepareApiData());
     if ($profilePost['profile_post_id'] != $profilePostId) {
         return $this->responseNoPermission();
     }
     if (!$this->_getProfilePostModel()->canDeleteProfilePostComment($comment, $profilePost, $user, $errorPhraseKey)) {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_ProfilePostComment');
     $dw->setExistingData($commentId);
     $dw->delete();
     XenForo_Model_Log::logModeratorAction('profile_post', $profilePost, 'comment_delete', array('username' => $comment['username'], 'reason' => '[bd] API'), $user);
     return $this->responseMessage(new XenForo_Phrase('changes_saved'));
 }
Beispiel #28
0
 public function actionDeleteIndex()
 {
     $postId = $this->_input->filterSingle('post_id', XenForo_Input::UINT);
     list($post, $thread, $forum) = $this->_getForumThreadPostHelper()->assertPostValidAndViewable($postId);
     $deleteType = 'soft';
     $options = array('reason' => '[bd] API');
     if (!$this->_getPostModel()->canDeletePost($post, $thread, $forum, $deleteType, $errorPhraseKey)) {
         throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
     }
     $this->_getPostModel()->deletePost($postId, $deleteType, $options, $forum);
     if ($post['post_id'] == $thread['first_post_id']) {
         XenForo_Model_Log::logModeratorAction('thread', $thread, 'delete_' . $deleteType, array('reason' => $options['reason']));
     } else {
         XenForo_Model_Log::logModeratorAction('post', $post, 'delete_' . $deleteType, array('reason' => $options['reason']), $thread);
     }
     return $this->responseMessage(new XenForo_Phrase('changes_saved'));
 }
Beispiel #29
0
 public function deleteThreadReplyBan(array $thread, array $user)
 {
     $res = $this->_getDb()->query("\n\t\t\tDELETE FROM xf_thread_reply_ban\n\t\t\tWHERE thread_id = ?\n\t\t\t\tAND user_id = ?\n\t\t", array($thread['thread_id'], $user['user_id']));
     if ($res->rowCount()) {
         XenForo_Model_Log::logModeratorAction('thread', $thread, 'reply_ban_delete', array('name' => $user['username']));
         /** @var XenForo_Model_Alert $alertModel */
         $alertModel = $this->getModelFromCache('XenForo_Model_Alert');
         $alertModel->deleteAlerts('thread', $thread['thread_id'], $user['user_id'], 'reply_ban');
         return true;
     } else {
         return false;
     }
 }
Beispiel #30
0
    /**
     * Merges specified posts (from given threads) into a target post and updates the text.
     * The target post must be in the list of given posts.
     *
     * @param array $posts
     * @param array $threads
     * @param integer $targetPostId
     * @param string $newMessage
     * @param array $options
     *
     * @return boolean
     */
    public function mergePosts(array $posts, array $threads, $targetPostId, $newMessage, $options = array())
    {
        if (!isset($posts[$targetPostId])) {
            return false;
        }
        $options = array_merge(array('log' => true), $options);
        $targetPost = $posts[$targetPostId];
        unset($posts[$targetPostId]);
        if (!$posts) {
            return false;
        }
        $attachPosts = array();
        $likePosts = array();
        foreach ($posts as $postId => $post) {
            if ($post['attach_count']) {
                $attachPosts[$postId] = $post['attach_count'];
            }
            if ($post['likes']) {
                $likePosts[$postId] = $post['likes'];
            }
        }
        $db = $this->_getDb();
        XenForo_Db::beginTransaction($db);
        $forums = $this->getModelFromCache('XenForo_Model_Forum')->getForumsByThreadIds(array_keys($threads));
        $targetPostDw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');
        $targetPostDw->setExistingData($targetPost, true);
        $targetPostDw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_IS_AUTOMATED, true);
        $targetPostDw->set('message', $newMessage);
        if (array_key_exists($targetPostDw->get('thread_id'), $threads)) {
            $thread = $threads[$targetPostDw->get('thread_id')];
            if (array_key_exists($thread['node_id'], $forums)) {
                $targetPostDw->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forums[$thread['node_id']]);
            }
        }
        if ($likePosts) {
            $res = $db->query("\r\r\n\t\t\t\tUPDATE IGNORE xf_liked_content SET\r\r\n\t\t\t\t\tcontent_id = ?\r\r\n\t\t\t\tWHERE content_type = 'post' AND content_id IN (" . $db->quote(array_keys($likePosts)) . ')
			', $targetPost['post_id']);
            $likesMoved = $res->rowCount();
            // remaining likes will be deleted with the posts, should keep counts accurate
            $latestLikeUsers = $this->getModelFromCache('XenForo_Model_Like')->getLatestContentLikeUsers('post', $targetPost['post_id']);
            $targetPostDw->set('likes', $targetPostDw->get('likes') + $likesMoved);
            $targetPostDw->set('like_users', $latestLikeUsers);
        }
        if ($attachPosts) {
            $db->update('xf_attachment', array('content_id' => $targetPost['post_id']), "content_type = 'post' AND content_id IN (" . $db->quote(array_keys($attachPosts)) . ')');
        }
        $targetPostDw->set('attach_count', $targetPostDw->get('attach_count') + array_sum($attachPosts));
        $targetPostDw->save();
        foreach ($posts as $post) {
            $sourcePostDw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post');
            $sourcePostDw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_DELETE_DISCUSSION_FIRST_MESSAGE, false);
            $sourcePostDw->setExistingData($post, true);
            $sourcePostDw->set('attach_count', 0);
            // moved these away, no need to try to delete
            if (array_key_exists($sourcePostDw->get('thread_id'), $threads)) {
                $thread = $threads[$sourcePostDw->get('thread_id')];
                if (array_key_exists($thread['node_id'], $forums)) {
                    $sourcePostDw->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forums[$thread['node_id']]);
                }
            }
            $sourcePostDw->delete();
        }
        if ($options['log']) {
            XenForo_Model_Log::logModeratorAction('post', $targetPost, 'merge_target', array('ids' => implode(', ', array_keys($posts))));
        }
        XenForo_Db::commit($db);
        return true;
    }