/** * Apply a thread prefix to the specified threads if permissions are sufficient. * * @param array $threadIds List of thread IDs to change * @param integer $prefixId ID of the thread prefix to apply * @param array $unchangedThreadIds Array of thread IDs that were not updated by this action * @param array $options Options that control the action. Nothing supported at this time. * @param string $errorKey Modified by reference. If no permission, may include a key of a phrase that gives more info * @param array|null $viewingUser * * @return boolean True if permissions were ok */ public function applyThreadPrefix(array $threadIds, $prefixId, &$unchangedThreadIds = array(), array $options = array(), &$errorKey = '', array $viewingUser = null) { $prefixModel = $this->_getPrefixModel(); $prefixPerms = array(); if (!$this->canEditThreads($threadIds, $errorKey, $viewingUser)) { return false; } foreach ($threadIds as $threadId) { $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); if (!$dw->setExistingData($threadId)) { continue; } $thread = $dw->getMergedData(); $nodeId = $dw->get('node_id'); if (!isset($prefixPerms[$nodeId])) { $prefixPerms[$nodeId] = $prefixModel->verifyPrefixIsUsable($prefixId, $nodeId, $viewingUser); } if (!$prefixPerms[$nodeId]) { $unchangedThreadIds[] = $threadId; continue; } $dw->set('prefix_id', $prefixId); $dw->save(); if ($thread['prefix_id'] != $prefixId) { if ($thread['prefix_id']) { $phrase = new XenForo_Phrase('thread_prefix_' . $thread['prefix_id']); $oldValue = $phrase->render(); } else { $oldValue = '-'; } XenForo_Model_Log::logModeratorAction('thread', $thread, 'prefix', array('old' => $oldValue)); } } return true; }
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); } }
public function actionMeta() { list($content, $album) = $this->_getPhotoOrError(); if (empty($content['photo_exif'])) { return $this->responseMessage(new XenForo_Phrase('sonnb_xengallery_this_photo_does_not_contain_any_exif_information')); } if (!empty($content['photo_exif']['ExposureProgram']) && is_int($content['photo_exif']['ExposureProgram']) && $content['photo_exif']['ExposureProgram'] > 0) { $phrase = @sonnb_XenGallery_Model_Photo::$exifExposureProgram[$content['photo_exif']['ExposureProgram']]; if ($phrase) { $phrase = new XenForo_Phrase($phrase); $content['photo_exif']['ExposureProgram'] = $phrase->render(); } } if (!empty($content['photo_exif']['ExposureTime'])) { $content['photo_exif']['ExposureTime'] .= ' (' . $content['photo_exif']['ExposureTimeOrigin'] . ')'; } if (isset($content['photo_exif']['Software'])) { $content['photo_exif']['Software'] = utf8_bad_replace($content['photo_exif']['Software'], ''); } if (isset($content['photo_exif']['ImageDescription'])) { $content['photo_exif']['ImageDescription'] = utf8_bad_replace($content['photo_exif']['ImageDescription'], ''); } if (isset($content['photo_exif']['Artist'])) { $content['photo_exif']['Artist'] = utf8_bad_replace($content['photo_exif']['Artist'], ''); } if (isset($content['photo_exif']['Copyright'])) { $content['photo_exif']['Copyright'] = utf8_bad_replace($content['photo_exif']['Copyright'], ''); } $viewParams = array('album' => $album, 'content' => $content, 'breadCrumbs' => $this->_getPhotoModel()->getContentBreadCrumbs($content, $album)); return $this->responseView('sonnb_XenGallery_ViewPublic_Photo_Exif', 'sonnb_xengallery_photo_exif', $viewParams); }
/** * * @see XenForo_Model_Report::reportContent() */ public function reportContent($contentType, array $content, $message, array $viewingUser = null) { $reportForumId = XenForo_Application::getOptions()->th_postOnReport_reportIntoForumId; if (XenForo_Application::$versionId < 1020000) { $this->standardizeViewingUserReference($viewingUser); if (!$viewingUser['user_id']) { return false; } $handler = $this->getReportHandler($contentType); if (!$handler) { return false; } list($contentId, $contentUserId, $contentInfo) = $handler->getReportDetailsFromContent($content); if (!$contentId) { return false; } if ($reportForumId) { /** * @var $forumModel XenForo_Model_Forum */ $forumModel = $this->getModelFromCache('XenForo_Model_Forum'); $reportForum = $forumModel->getForumById($reportForumId); if ($reportForum) { $report = array('content_type' => $contentType, 'content_id' => $contentId, 'content_user_id' => $contentUserId, 'content_info' => $contentInfo, 'first_report_date' => XenForo_Application::$time, 'report_state' => 'open', 'assigned_user_id' => 0, 'comment_count' => 0, 'report_count' => 0); $params = $this->_getContentForThread($report, $contentInfo, $handler); $user = $this->getModelFromCache('XenForo_Model_User')->getUserById($contentUserId); if ($user) { $params['username'] = $user['username']; } $params['userLink'] = XenForo_Link::buildPublicLink('canonical:members', $user); $params['reporter'] = $viewingUser['username']; $params['reporterLink'] = XenForo_Link::buildPublicLink('canonical:members', $viewingUser); $params['reportReason'] = $message; $threadTitle = new XenForo_Phrase('th_reported_thread_title_postonreport', $params, false); /** * @var $threadDw XenForo_DataWriter_Discussion_Thread */ $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); $threadDw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $reportForum); $threadDw->bulkSet(array('node_id' => $reportForum['node_id'], 'title' => $threadTitle->render(), 'user_id' => $viewingUser['user_id'], 'username' => $viewingUser['username'])); $threadDw->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $reportForum)); $message = new XenForo_Phrase('th_reported_thread_message_postonreport', $params, false); $postWriter = $threadDw->getFirstMessageDw(); $postWriter->set('message', $message->render()); $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $reportForum); $threadDw->save(); } } return parent::reportContent($contentType, $content, $message, $viewingUser); } XenForo_Application::getOptions()->set('reportIntoForumId', $reportForumId); if (parent::reportContent($contentType, $content, $message, $viewingUser)) { XenForo_Application::getOptions()->set('reportIntoForumId', 0); return parent::reportContent($contentType, $content, $message, $viewingUser); } }
public function renderTagMedia(array $tag, array $rendererStates) { $mediaSiteId = strtolower($tag['option']); if (isset($this->_mediaSites[$mediaSiteId])) { $phrase = new XenForo_Phrase('embedded_media'); return '<table cellpadding="0" cellspacing="0" border="0" width="100%"' . ' style="background-color: #F0F7FC; border: 1px solid #A5CAE4; border-radius: 5px; margin: 5px 0; padding: 5px; font-size: 11px; text-align: center">' . '<tr><td>' . $phrase->render() . '</td></tr></table>'; } else { return ''; } }
protected static function _getPhrasedTextIfPossible($fallbackText, $phraseName, array $params = array()) { $output = false; ini_set('display_errors', true); if (XenForo_Application::isRegistered('db') && XenForo_Application::get('db')->isConnected()) { try { $phrase = new XenForo_Phrase($phraseName, $params); $output = $phrase->render(); } catch (Exception $e) { } } if ($output === false) { $output = $fallbackText; } return $output; }
public function actionDeleteAttachment() { $vals = $this->_input->filter(array('attachmentid' => XenForo_Input::UINT, 'poststarttime' => XenForo_Input::STRING)); try { $attachment = $this->_getAttachmentOrError($vals['attachmentid']); } catch (Exception $e) { $error = new XenForo_Phrase('do_not_have_permission'); json_error($error->render()); } if (!$this->_getAttachmentModel()->canDeleteAttachment($attachment, $vals['poststarttime'])) { $error = new XenForo_Phrase('do_not_have_permission'); json_error($error->render()); } $dw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment'); $dw->setExistingData($attachment, true); $dw->delete(); return array('success' => true); }
public function renderRss() { $options = XenForo_Application::getOptions(); $title = new XenForo_Phrase('xengallery_media'); $description = new XenForo_Phrase('xengallery_check_out_all_media_from_x', array('board' => $options->boardTitle)); $buggyXmlNamespace = defined('LIBXML_DOTTED_VERSION') && LIBXML_DOTTED_VERSION == '2.6.24'; $feed = new Zend_Feed_Writer_Feed(); $feed->setEncoding('utf-8'); $feed->setTitle($title->render()); $feed->setDescription($description->render()); $feed->setLink(XenForo_Link::buildPublicLink('canonical:xengallery')); if (!$buggyXmlNamespace) { $feed->setFeedLink(XenForo_Link::buildPublicLink('canonical:xengallery.rss'), 'rss'); } $feed->setDateModified(XenForo_Application::$time); $feed->setLastBuildDate(XenForo_Application::$time); $feed->setGenerator($title->render()); $bbCodeParser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $this))); foreach ($this->_params['media'] as $media) { $entry = $feed->createEntry(); $entry->setTitle($media['media_title'] ? $media['media_title'] : $media['media_title'] . ' '); $entry->setLink(XenForo_Link::buildPublicLink('canonical:xengallery', $media)); $entry->setDateCreated(new Zend_Date($media['media_date'], Zend_Date::TIMESTAMP)); $entry->setDateModified(new Zend_Date($media['last_edit_date'], Zend_Date::TIMESTAMP)); if (!empty($media['media_description'])) { $entry->setDescription($media['media_description']); } XenGallery_ViewPublic_Helper_VideoHtml::addVideoHtml($media, $bbCodeParser); $content = $this->_renderer->createTemplateObject('xengallery_rss_content', array('media' => $media)); $entry->setContent($content->render()); if (!$buggyXmlNamespace) { $entry->addAuthor(array('name' => $media['username'], 'email' => '*****@*****.**', 'uri' => XenForo_Link::buildPublicLink('canonical:xengallery/users', $media))); if ($media['comment_count']) { $entry->setCommentCount($media['comment_count']); } } $feed->addEntry($entry); } return $feed->export('rss'); }
public function renderJson() { $teams = $this->_params['teams']; if (empty($teams)) { $content = new XenForo_Phrase('Teams_there_currently_no_teams_to_display'); $description = ' <dt><label for="ctrl_team_id">' . new XenForo_Phrase('Teams_team') . ':</label></dt> <dd> ' . $content . ' </dd>'; } else { $notFound = new XenForo_Phrase('no_results_found'); $openTag = ' <script> $(document).ready(function() { $(".choosen").chosen( { disable_search_threshold: 10, no_results_text: "' . $notFound->render() . '", width: "100%" }); }); </script> <dt><label for="ctrl_team_id">' . new XenForo_Phrase('Teams_team') . ':</label></dt> <dd> <select name="team_id" class="textCtrl choosen" id="ctrl_team_id"> '; $closeTag = '</select></dd>'; $content = ''; foreach ($teams as $team) { $content .= '<option value="' . $team['team_id'] . '">' . $team['title'] . '</option>'; } $description = $openTag . $content . $closeTag; } return array('description' => $description); }
protected function _updateSocialForum($resource) { if (!$this->_isFirstVisible || !$resource || !$resource['social_forum_id']) { return false; } $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($resource['social_forum_id'])->toArray(); if (!$socialForum) { return false; } $forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById($socialForum['node_id']); if (!$forum) { return false; } $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); $threadDw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum); $threadDw->bulkSet(array('node_id' => $socialForum['node_id'], 'title' => $this->get('title'), 'user_id' => $resource['user_id'], 'username' => $resource['username'], 'discussion_type' => 'resource')); $threadDw->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $forum)); $threadDw->setOption(XenForo_DataWriter_Discussion::OPTION_PUBLISH_FEED, false); $messageText = $this->get('message'); // note: this doesn't actually strip the BB code - it will fix the BB code in the snippet though $parser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false)); $snippet = $parser->render(XenForo_Helper_String::wholeWordTrim($messageText, 500)); $message = new XenForo_Phrase('resource_message_create_update', array('title' => $this->get('title'), 'username' => $resource['username'], 'userId' => $resource['user_id'], 'snippet' => $snippet, 'updateLink' => XenForo_Link::buildPublicLink('canonical:resources/update', $resource, array('update' => $this->get('resource_update_id'))), 'resourceTitle' => $resource['title'], 'resourceLink' => XenForo_Link::buildPublicLink('canonical:resources', $resource)), false); $postWriter = $threadDw->getFirstMessageDw(); $postWriter->set('message', $message->render()); $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum); $postWriter->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_PUBLISH_FEED, false); if (!$threadDw->save()) { return false; } $this->set('discussion_thread_id', $threadDw->get('thread_id'), '', array('setAfterPreSave' => true)); $postSaveChanges['discussion_thread_id'] = $threadDw->get('thread_id'); $this->getModelFromCache('XenForo_Model_Thread')->markThreadRead($threadDw->getMergedData(), $forum, XenForo_Application::$time); $this->getModelFromCache('XenForo_Model_ThreadWatch')->setThreadWatchStateWithUserDefault($this->get('user_id'), $threadDw->get('thread_id'), $this->getExtraData(XenResource_DataWriter_Resource::DATA_THREAD_WATCH_DEFAULT)); return $postWriter->get('post_id'); }
private function noResults() { $no_results = new XenForo_Phrase('no_results_found'); return array('threads' => array(array('error' => $no_results->render())), 'total_threads' => 1); }
public function actionRegister() { $this->_assertRegistrationActive(); $vals = $this->_input->filter(array('username' => XenForo_Input::STRING, 'email' => XenForo_Input::STRING, 'password' => XenForo_Input::STRING, 'password_md5' => XenForo_Input::STRING, 'birthday' => XenForo_Input::STRING, 'timezone_name' => XenForo_Input::STRING)); $options = XenForo_Application::get('options'); if (!$options->forumrunnerRegistration) { $p = new XenForo_Phrase('do_not_have_permission'); json_error($p->render()); } $out = array(); if ($vals['username']) { $writer = XenForo_DataWriter::create('XenForo_DataWriter_User'); if ($options->registrationDefaults) { $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true)); } $day = $month = $year = ''; if ($vals['birthday']) { $parts = preg_split('#/#', $vals['birthday']); if ($parts[0]) { $month = intval($parts[0]); } if ($parts[1]) { $day = intval($parts[1]); } if ($parts[2]) { $year = intval($parts[2]); } } // Figure out Time Zone $data = array('username' => $vals['username'], 'email' => $vals['email'], 'gender' => '', 'dob_day' => $day, 'dob_month' => $month, 'dob_year' => $year, 'timezone' => $vals['timezone_name']); $writer->bulkSet($data); $writer->setPassword($vals['password'], $vals['password']); // verified by client // if the email corresponds to an existing Gravatar, use it if ($options->gravatarEnable && XenForo_Model_Avatar::gravatarExists($data['email'])) { $writer->set('gravatar', $data['email']); } $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId); $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id')); $writer->advanceRegistrationUserState(); $writer->preSave(); if ($options->get('registrationSetup', 'requireDob')) { // dob required if (!$data['dob_day'] || !$data['dob_month'] || !$data['dob_year']) { $p = new XenForo_Phrase('please_enter_valid_date_of_birth'); json_error($p->render()); } $userAge = $this->_getUserProfileModel()->getUserAge($writer->getMergedData(), true); if ($userAge < 1) { $p = new XenForo_Phrase('please_enter_valid_date_of_birth'); json_error($p->render()); } if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) { $p = new XenForo_Phrase('sorry_you_too_young_to_create_an_account'); json_error($p->render()); } } $errors = $writer->getErrors(); if (count($errors)) { // only show first $errors = array_values($errors); json_error($errors[0]->render()); } $writer->save(); $user = $writer->getMergedData(); // log the ip of the user registering XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register'); if ($user['user_state'] == 'email_confirm') { $this->_getUserConfirmationModel()->sendEmailConfirmation($user); $out['emailverify'] = true; } else { $out['emailverify'] = false; } XenForo_Visitor::setup(0); } else { $p = new XenForo_Phrase('fr_register_forum_rules'); $out += array('rules' => preg_replace('/<a href=\\"(.*?)\\">(.*?)<\\/a>/', "\\2", $p->render()), 'birthday' => $options->get('registrationSetup', 'requireDob') ? true : false); } return $out; }
/** * Reports a piece of content. * * @param string $contentType * @param array $content Information about content * @param string $message * @param array|null $viewingUser User reporting; null means visitor * * @return bool|integer Report ID or false if no report was made, true if reported into a forum */ public function reportContent($contentType, array $content, $message, array $viewingUser = null) { $this->standardizeViewingUserReference($viewingUser); if (!$viewingUser['user_id']) { return false; } $handler = $this->getReportHandler($contentType); if (!$handler) { return false; } list($contentId, $contentUserId, $contentInfo) = $handler->getReportDetailsFromContent($content); if (!$contentId) { return false; } $reportForumId = XenForo_Application::getOptions()->reportIntoForumId; if ($reportForumId) { /** @var $forumModel XenForo_Model_Forum */ $forumModel = $this->getModelFromCache('XenForo_Model_Forum'); $reportForum = $forumModel->getForumById($reportForumId); if ($reportForum) { $report = array('content_type' => $contentType, 'content_id' => $contentId, 'content_user_id' => $contentUserId, 'content_info' => $contentInfo, 'first_report_date' => XenForo_Application::$time, 'report_state' => 'open', 'assigned_user_id' => 0, 'comment_count' => 0, 'report_count' => 0); $params = $handler->getContentForThread($report, $contentInfo); $user = $this->getModelFromCache('XenForo_Model_User')->getUserById($contentUserId); if ($user) { $params['username'] = $user['username']; } $params['userLink'] = XenForo_Link::buildPublicLink('canonical:members', $user); $params['reporter'] = $viewingUser['username']; $params['reporterLink'] = XenForo_Link::buildPublicLink('canonical:members', $viewingUser); $params['reportReason'] = $message; foreach ($params as &$param) { if ($param instanceof XenForo_Phrase) { // make sure that params in phrases don't get escaped $newParam = clone $param; $newParam->setEscapeCallback(false); $param = $newParam; } } $threadTitle = new XenForo_Phrase('reported_thread_title', $params, false); /** @var $threadDw XenForo_DataWriter_Discussion_Thread */ $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); $threadDw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $reportForum); $threadDw->setOption(XenForo_DataWriter_Discussion::OPTION_TRIM_TITLE, true); $threadDw->bulkSet(array('node_id' => $reportForum['node_id'], 'title' => $threadTitle->render(), 'user_id' => $viewingUser['user_id'], 'username' => $viewingUser['username'])); $threadDw->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $reportForum)); $message = new XenForo_Phrase('reported_thread_message', $params, false); $postWriter = $threadDw->getFirstMessageDw(); $postWriter->set('message', $message->render()); $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $reportForum); return $threadDw->save(); } return false; } $newReportState = ''; $report = $this->getReportByContent($contentType, $contentId); if ($report) { $reportId = $report['report_id']; if ($report['report_state'] == 'resolved' || $report['report_state'] == 'rejected') { // re-open an existing report $reportDw = XenForo_DataWriter::create('XenForo_DataWriter_Report'); $reportDw->setExistingData($report, true); $reportDw->set('report_state', 'open'); $reportDw->save(); $newReportState = 'open'; } } else { $reportDw = XenForo_DataWriter::create('XenForo_DataWriter_Report'); $reportDw->bulkSet(array('content_type' => $contentType, 'content_id' => $contentId, 'content_user_id' => $contentUserId, 'content_info' => $contentInfo)); $reportDw->save(); $reportId = $reportDw->get('report_id'); } $reasonDw = XenForo_DataWriter::create('XenForo_DataWriter_ReportComment'); $reasonDw->bulkSet(array('report_id' => $reportId, 'user_id' => $viewingUser['user_id'], 'username' => $viewingUser['username'], 'message' => $message, 'state_change' => $newReportState, 'is_report' => 1)); $reasonDw->save(); return $reportId; }
private function processSearch(&$search) { $vals = $this->_input->filter(array('page' => XenForo_Input::UINT, 'perpage' => XenForo_Input::UINT, 'previewtype' => XenForo_Input::UINT, 'starteronly' => XenForo_Input::UINT)); $vals['page'] = max($vals['page'], 1); $vals['perpage'] = min(XenForo_Application::get('options')->discussionsPerPage, $vals['perpage']); if (!$vals['perpage']) { $vals['perpage'] = XenForo_Application::get('options')->discussionsPerPage; } if (!$vals['previewtype']) { $vals['previewtype'] = 2; } if ($vals['starteronly']) { $vals['previewtype'] = 1; } $search_model = $this->_getSearchModel(); $search_id = $search['search_id']; $resultids = $search_model->sliceSearchResultsToPage($search, $vals['page'], $vals['perpage']); $results = $search_model->getSearchResultsForDisplay($resultids); if (!$results) { return $this->sendError(new XenForo_Phrase('no_results_found')); } $post_model = $this->getModelFromCache('XenForo_Model_Post'); $user_model = $this->getModelFromCache('XenForo_Model_User'); $thread_data = array(); $preview_length = XenForo_Application::get('options')->discussionPreviewLength; foreach ($results['results'] as $result) { $thread = $result['content']; $is_post = $result['content_type'] == 'post'; if ($is_post) { $post = $post_model->getPostById($thread['post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); } else { $post = $post_model->getPostById($thread[$vals['previewtype'] == 1 ? 'first_post_id' : 'last_post_id'], array('join' => XenForo_Model_Post::FETCH_USER)); } $preview = ''; if ($preview_length) { $preview = preview_chop(XenForo_Helper_String::bbCodeStrip(XenForo_Helper_String::censorString($thread['message']), true), $preview_length); } $out = array('thread_id' => $thread['thread_id'], 'new_posts' => $thread['isNew'], 'forum_id' => $thread['node_id'], 'total_posts' => $thread['reply_count'] + 1, 'forum_title' => prepare_utf8_string(strip_tags($thread['node_title'])), 'thread_title' => prepare_utf8_string(XenForo_Helper_String::censorString($thread['title']))); if ($is_post) { $out += array('post_id' => $thread['post_id'], 'jump_to_post' => 1, 'post_username' => prepare_utf8_string(strip_tags($thread['username'])), 'post_userid' => $thread['user_id'], 'post_lastposttime' => prepare_utf8_string(XenForo_Locale::dateTime($thread['post_date'], 'absolute'))); } else { if ($vals['previewtype'] == 1) { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['username'])), 'post_userid' => $thread['user_id']); } else { $out += array('post_username' => prepare_utf8_string(strip_tags($thread['last_post_username'])), 'post_userid' => $thread['last_post_user_id']); } $out['post_lastposttime'] = prepare_utf8_string(XenForo_Locale::dateTime($thread['last_post_date'], 'absolute')); } $user = $user_model->getUserById($out['post_userid']); if ($user !== false) { $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm')); if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) { $avatarurl = ''; } if ($avatarurl != '') { $out['avatarurl'] = $avatarurl; } } if ($preview != '') { $out['thread_preview'] = prepare_utf8_string(html_entity_decode($preview)); } if ($thread['discussion_type'] == 'poll') { $out['poll'] = true; } if ($thread['prefix_id']) { $phrase = new XenForo_Phrase('thread_prefix_' . $thread['prefix_id']); $out['prefix'] = prepare_utf8_string(strip_tags($phrase->render(false))); } $thread_data[] = $out; } $out = array('threads' => $thread_data, 'total_threads' => $search['result_count'], 'searchid' => $search_id); return $out; }
function get_xf_lang($lang_key, $params = array()) { $phrase = new XenForo_Phrase($lang_key, $params); return $phrase->render(); }
/** * Fetches the text of the specified phrase * * @param string $phraseName * * @return string */ protected static function _getPhraseText($phraseName) { if (self::$_language && isset(self::$_language['phrase_cache'])) { $cache = self::$_language['phrase_cache']; return isset($cache[$phraseName]) ? $cache[$phraseName] : ''; } else { $phrase = new XenForo_Phrase($phraseName); return $phrase->render(false); } }
public function assertTeamValidAndViewable($teamIdOrName = null, array $teamFetchOptions = array(), array $categoryFetchOptions = array()) { if (!isset($teamFetchOptions['join'])) { $teamFetchOptions['join'] = 0; } $teamFetchOptions['join'] |= Nobita_Teams_Model_Team::FETCH_PRIVACY | Nobita_Teams_Model_Team::FETCH_PROFILE | Nobita_Teams_Model_Team::FETCH_FEATURED; if ($this->_visitor->hasPermission('Teams', 'viewDeleted')) { $teamFetchOptions['join'] |= Nobita_Teams_Model_Team::FETCH_DELETION_LOG; } $visitor = XenForo_Visitor::getInstance(); $teamFetchOptions['banUserId'] = $visitor['user_id']; $teamFetchOptions['memberUserId'] = $visitor['user_id']; $team = $this->getTeamOrError($teamIdOrName, $teamFetchOptions); $category = $this->assertCategoryValidAndViewable($team['team_category_id'], $categoryFetchOptions); $teamModel = $this->_controller->getModelFromCache('Nobita_Teams_Model_Team'); if (!$teamModel->canViewTeam($team, $category, $errorPhraseKey)) { throw $this->_controller->getErrorOrNoPermissionResponseException($errorPhraseKey); } $team = $teamModel->prepareTeam($team, $category); $team = $teamModel->prepareTeamCustomFields($team, $category); if (!empty($team['ban_expired_date']) && $team['ban_expired_date'] > XenForo_Application::$time) { $banLift = new XenForo_Phrase('ban_will_be_automatically_lifted_on_x', array('date' => XenForo_Locale::date($team['ban_expired_date'])), false); throw $this->_controller->responseException($this->_controller->responseError($team['user_reason'] . '. ' . $banLift->render())); } return array($team, $category); }
public function actionStartConversation() { if (!$this->_getConversationModel()->canStartConversations($error_phrase)) { $error = new XenForo_Phrase($error_phrase); json_error($error->render()); } $visitor = XenForo_Visitor::getInstance(); $vals = $this->_input->filter(array('title' => XenForo_Input::STRING, 'recipients' => XenForo_Input::STRING, 'message' => XenForo_Input::STRING, 'sig' => XenForo_Input::STRING)); // TODO: Allow invites, lock conversation if (XenForo_Application::get('options')->forumrunnerSignatures && $vals['sig']) { $vals['message'] .= "\n\n" . $vals['sig']; } $vals['message'] = XenForo_Helper_String::autoLinkBbCode($vals['message']); $c = XenForo_DataWriter::create('XenForo_DataWriter_ConversationMaster'); $c->set('user_id', $visitor['user_id']); $c->set('username', $visitor['username']); $c->set('title', $vals['title']); $c->set('open_invite', 0); // XXX RKJ $c->set('conversation_open', 1); // XXX RKJ $c->addRecipientUserNames(explode(';', $vals['recipients'])); if ($c->hasErrors()) { $error_text = ''; foreach ($c->getErrors() as $error) { $error_text .= $error->render() . "\n"; } json_error($error_text); } $m = $c->getFirstMessageDw(); $m->set('message', $vals['message']); $c->preSave(); if (!$c->hasErrors()) { try { $this->assertNotFlooding('conversation'); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } } try { $c->save(); } catch (Exception $e) { $error_text = ''; foreach ($e->getMessages() as $error) { $error_text .= $error->render() . "\n"; } json_error($error_text); } return array('success' => true); }
protected static function _replacePhrasedTextCallback(array $match) { // This will cause extra queries, but it shouldn't be a particularly big deal. It's pretty rare. $phrase = new XenForo_Phrase($match[2]); return $phrase->render(); }
public function stepAlbums($start, array $options) { $options = array_merge(array('limit' => 50, 'processed' => 0, 'max' => false), $options); $model = $this->_importModel; $db = $this->_db; if ($this->_config['importType'] == self::XENMEDIO_IMPORT_TYPE_CATEGORY_AS_ALBUM) { if ($options['max'] === false) { $data = $db->fetchRow(' SELECT MAX(category_id) AS max, COUNT(category_id) AS rows FROM EWRmedio_categories WHERE category_disabled = 0 '); $options = array_merge($options, $data); return array(0, $options, "Processing Albums ..."); } $albums = $db->fetchAll($db->limit(' SELECT category.* FROM EWRmedio_categories AS category WHERE category_disabled = 0 AND category_id > ' . $this->_db->quote($start) . ' ORDER BY category_id ASC ', $options['limit'])); if (!$albums) { return true; } $next = 0; $last = 0; $total = 0; $admin = XenForo_Visitor::getInstance(); foreach ($albums as $album) { $next = $album['category_id']; if ($last != $next) { $last = $next; $albumPrivacy = array('allow_view' => 'everyone', 'allow_view_data' => array(), 'allow_comment' => 'everyone', 'allow_comment_data' => array(), 'allow_add_photo' => 'everyone', 'allow_add_photo_data' => array(), 'allow_add_video' => 'everyone', 'allow_add_video_data' => array(), 'allow_download' => 'none', 'allow_download_data' => array()); $import = array('title' => $album['category_name'], 'description' => $album['category_description'], 'user_id' => $admin['user_id'], 'username' => $admin['username'], 'album_state' => 'visible', 'view_count' => 0, 'photo_count' => 0, 'video_count' => 0, 'content_count' => 0, 'album_date' => XenForo_Application::$time, 'album_updated_date' => XenForo_Application::$time, 'album_privacy' => serialize($albumPrivacy), 'category_id' => 0, 'album_type' => sonnb_XenGallery_Model_Album::ALBUM_TYPE_NORMAL); if ($this->_config['retainKeys']) { $import['album_id'] = $album['category_id']; } $albumId = $model->importXenGalleryAlbum($album['category_id'], $import); $model->logImportData('sonnb_xengallery_album', $album['category_id'], $albumId); } $total++; } } else { if ($options['max'] === false) { $data = array(); $data['max'] = $db->fetchOne(' SELECT MAX(user_id) AS max FROM EWRmedio_media GROUP BY user_id '); $data['rows'] = $db->fetchOne(' SELECT COUNT(*) AS rows FROM (SELECT media.* FROM EWRmedio_media as media GROUP BY user_id) AS count '); $options = array_merge($options, $data); return array(0, $options, "Processing Albums ..."); } $albums = $db->fetchAll($db->limit(' SELECT media.user_id, media.username FROM EWRmedio_media AS media WHERE media.user_id > ' . $this->_db->quote($start) . ' GROUP BY user_id ORDER BY user_id ASC ', $options['limit'])); if (!$albums) { return true; } $next = 0; $last = 0; $total = 0; foreach ($albums as $album) { $next = $album['user_id']; if ($last != $next) { $last = $next; $albumPrivacy = array('allow_view' => 'everyone', 'allow_view_data' => array(), 'allow_comment' => 'everyone', 'allow_comment_data' => array(), 'allow_add_photo' => 'none', 'allow_add_photo_data' => array(), 'allow_add_video' => 'none', 'allow_add_video_data' => array(), 'allow_download' => 'none', 'allow_download_data' => array()); $title = new XenForo_Phrase('sonnb_xengallery_xenmedio_x_videos', array('username' => $album['username'])); $import = array('title' => $title->render(true), 'description' => '', 'user_id' => $album['user_id'], 'username' => $album['username'], 'album_state' => 'visible', 'view_count' => 0, 'photo_count' => 0, 'video_count' => 0, 'content_count' => 0, 'album_date' => XenForo_Application::$time, 'album_updated_date' => XenForo_Application::$time, 'album_privacy' => serialize($albumPrivacy), 'category_id' => 0, 'album_type' => sonnb_XenGallery_Model_Album::ALBUM_TYPE_NORMAL); if ($this->_config['retainKeys']) { //$import['album_id'] = $album['user_id']; } $albumId = $model->importXenGalleryAlbum($album['user_id'], $import); $model->logImportData('sonnb_xengallery_album', $album['user_id'], $albumId); } $total++; } } $options['processed'] += $total; $this->_session->incrementStepImportTotal($total); return array($next, $options, $this->_getProgressOutput($options['processed'], $options['rows'])); }
public function actionSubscribe() { $threadid = $this->_input->filterSingle('threadid', XenForo_Input::UINT); $emailupdate = $this->_input->filterSingle('emailupdate', XenForo_Input::UINT); $thread_model = $this->getModelFromCache('XenForo_Model_Thread'); $helper = $this->getHelper('ForumThreadPost'); try { list($thread_info, $forum_info) = $helper->assertThreadValidAndViewable($threadid); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } if (!$this->_getThreadModel()->canWatchThread($thread_info, $forum_info)) { $p = new XenForo_Phrase('do_not_have_permission'); json_error($p->render()); } $this->_getThreadWatchModel()->setThreadWatchState(XenForo_Visitor::getUserId(), $threadid, $emailupdate ? 'watch_email' : 'watch_no_email'); return array('success' => true); }
/** * Logs the moderator actions for thread edits. * * @param array $thread * @param XenForo_DataWriter_Discussion_Thread $dw * @param array $skip Array of keys to skip logging for */ 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 'sticky': XenForo_Model_Log::logModeratorAction('thread', $thread, $value ? 'stick' : 'unstick'); break; case 'discussion_open': XenForo_Model_Log::logModeratorAction('thread', $thread, $value ? 'unlock' : 'lock'); break; case 'discussion_state': if ($value == 'visible' && $oldValue == 'moderated') { XenForo_Model_Log::logModeratorAction('thread', $thread, 'approve'); } else { if ($value == 'visible' && $oldValue == 'deleted') { XenForo_Model_Log::logModeratorAction('thread', $thread, 'undelete'); } else { if ($value == 'deleted') { XenForo_Model_Log::logModeratorAction('thread', $thread, 'delete_soft', array('reason' => '')); } else { if ($value == 'moderated') { XenForo_Model_Log::logModeratorAction('thread', $thread, 'unapprove'); } } } } break; case 'title': XenForo_Model_Log::logModeratorAction('thread', $thread, 'title', array('old' => $oldValue)); break; case 'prefix_id': if ($oldValue) { $phrase = new XenForo_Phrase('thread_prefix_' . $oldValue); $oldValue = $phrase->render(); } else { $oldValue = '-'; } XenForo_Model_Log::logModeratorAction('thread', $thread, 'prefix', array('old' => $oldValue)); break; default: if (!in_array($key, $skip)) { $basicLog[$key] = $oldValue; } } } if ($basicLog) { XenForo_Model_Log::logModeratorAction('thread', $thread, 'edit', $basicLog); } } }
protected function _insertDiscussionThread($nodeId, $prefixId = 0) { if (!$nodeId) { return false; } $forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById($nodeId); if (!$forum) { return false; } $threadDw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread', XenForo_DataWriter::ERROR_SILENT); $threadDw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum); $threadDw->bulkSet(array('node_id' => $nodeId, 'title' => $this->_getThreadTitle(), 'user_id' => $this->get('user_id'), 'username' => $this->get('username'), 'discussion_type' => 'team', 'prefix_id' => $prefixId)); $threadDw->set('discussion_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState(array(), $forum)); $threadDw->setOption(XenForo_DataWriter_Discussion::OPTION_PUBLISH_FEED, false); $messageText = $this->get('about'); // note: this doesn't actually strip the BB code - it will fix the BB code in the snippet though $parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false)); $snippet = $parser->render(XenForo_Helper_String::wholeWordTrim($messageText, 500)); $message = new XenForo_Phrase('Teams_message_create_team', array('title' => $this->get('title'), 'tagLine' => $this->get('tag_line'), 'username' => $this->get('username'), 'userId' => $this->get('user_id'), 'snippet' => $snippet, 'teamLink' => XenForo_Link::buildPublicLink('canonical:' . Nobita_Teams_Model_Team::routePrefix(), $this->getMergedData())), false); $postWriter = $threadDw->getFirstMessageDw(); $postWriter->set('message', $message->render()); $postWriter->setExtraData(XenForo_DataWriter_DiscussionMessage_Post::DATA_FORUM, $forum); $postWriter->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_PUBLISH_FEED, false); if (!$threadDw->save()) { return false; } $this->set('discussion_thread_id', $threadDw->get('thread_id'), '', array('setAfterPreSave' => true)); $postSaveChanges['discussion_thread_id'] = $threadDw->get('thread_id'); $this->getModelFromCache('XenForo_Model_Thread')->markThreadRead($threadDw->getMergedData(), $forum, \XenForo_Application::$time); $this->getModelFromCache('XenForo_Model_ThreadWatch')->setThreadWatchStateWithUserDefault($this->get('user_id'), $threadDw->get('thread_id'), $this->getExtraData(self::DATA_THREAD_WATCH_DEFAULT)); return $threadDw->get('thread_id'); }
protected function _updateThread(array $resource) { if (!$this->_isFirstVisible || !$resource || !$resource['discussion_thread_id']) { return false; } $thread = $this->getModelFromCache('XenForo_Model_Thread')->getThreadById($resource['discussion_thread_id']); if (!$thread || $thread['discussion_type'] != 'resource') { return false; } $forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById($thread['node_id']); if (!$forum) { return false; } $messageText = $this->get('message'); // note: this doesn't actually strip the BB code - it will fix the BB code in the snippet though $parser = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_AutoLink', false)); $snippet = $parser->render(XenForo_Helper_String::wholeWordTrim($messageText, 500)); $message = new XenForo_Phrase('resource_message_create_update', array('title' => $this->get('title'), 'username' => $resource['username'], 'userId' => $resource['user_id'], 'snippet' => $snippet, 'updateLink' => XenForo_Link::buildPublicLink('canonical:resources/update', $resource, array('update' => $this->get('resource_update_id'))), 'resourceTitle' => $resource['title'], 'resourceLink' => XenForo_Link::buildPublicLink('canonical:resources', $resource)), false); $writer = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post', XenForo_DataWriter::ERROR_SILENT); $writer->bulkSet(array('thread_id' => $thread['thread_id'], 'user_id' => $resource['user_id'], 'username' => $resource['username'])); $writer->set('message', $message->render()); $writer->set('message_state', $this->getModelFromCache('XenForo_Model_Post')->getPostInsertMessageState($thread, $forum)); $writer->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_IS_AUTOMATED, true); $writer->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_PUBLISH_FEED, false); $writer->save(); $threadReadDate = $this->getModelFromCache('XenForo_Model_Thread')->getUserThreadReadDate($resource['user_id'], $thread['thread_id']); $forumReadDate = $this->getModelFromCache('XenForo_Model_Forum')->getUserForumReadDate($resource['user_id'], $forum['node_id']); if (max($threadReadDate, $forumReadDate) >= $thread['last_post_date']) { $this->getModelFromCache('XenForo_Model_Thread')->markThreadRead($thread, $forum, XenForo_Application::$time); } return $writer->get('post_id'); }
function getContentTypeKeyPhrase() { $phrase = new XenForo_Phrase('thread'); return $phrase->render(); }
protected function _importAlbum(array $album, array $options) { $model = $this->_getMediaGalleryImportersModel(); $db = $this->_sourceDb; $xfDb = $this->_xfDb; $dates = $db->fetchCol(' SELECT date FROM ' . $this->_prefix . 'photos WHERE cat = ? ORDER BY date ASC ', $album['id']); $albumCreateDate = reset($dates); $albumLastUpdateDate = end($dates); $user = $xfDb->fetchRow(' SELECT user_id, username FROM xf_user WHERE user_id = ? ', $album['parent']); if (!$user) { return false; } $albumPrivacy = $album['private'] == 'yes' ? 'private' : 'public'; $noTitle = new XenForo_Phrase('xengallery_imported_item'); $xengalleryAlbum = array('album_title' => $album['catname'] ? $this->_convertToUtf8($album['catname'], true) : $noTitle->render(), 'album_description' => XenForo_Template_Helper_Core::helperSnippet($this->_convertToUtf8($album['description'], true), 0, array('stripHtml' => true)), 'album_create_date' => $albumCreateDate ? $albumCreateDate : XenForo_Application::$time, 'last_update_date' => $albumLastUpdateDate ? $albumLastUpdateDate : XenForo_Application::$time, 'media_cache' => array(), 'album_state' => 'visible', 'album_user_id' => $album['parent'], 'album_username' => $user['username'], 'ip_id' => $model->getLatestIpIdFromUserId($user['user_id']), 'album_like_users' => array(), 'album_media_count' => $album['photos'], 'album_likes' => false); $importedAlbumId = $model->importAlbum($album['id'], $xengalleryAlbum, $albumPrivacy); return $importedAlbumId; }
protected function _importMedia(array $item, array $options) { $originalFilePath = sprintf('%s/%d/%d-%s.data', $options['path'], floor($item['data_id'] / 1000), $item['data_id'], $item['file_hash']); if (!file_exists($originalFilePath)) { return false; } $tempFile = tempnam(XenForo_Helper_File::getTempDir(), 'xfmg'); copy($originalFilePath, $tempFile); $model = $this->_getMediaGalleryImportersModel(); $categoryId = 0; $albumId = $model->mapAlbumId($item['album_id']); if (strstr($albumId, 'category_')) { $categoryId = str_replace('category_', '', $albumId); $albumId = 0; } $mediaPrivacy = $item['album_type'] == 'global' ? 'public' : $item['album_type']; if ($mediaPrivacy == 'selected') { $mediaPrivacy = 'shared'; } $noTitle = new XenForo_Phrase('xengallery_imported_item'); $lastCommentDate = $model->getLastCommentDateFromImageIdXFRUA($item['image_id']); $xengalleryMedia = array('media_title' => $item['filename'] ? $item['filename'] : $noTitle->render(), 'media_description' => $item['description'], 'media_date' => $item['upload_date'], 'last_edit_date' => XenForo_Application::$time, 'last_comment_date' => $lastCommentDate ? $lastCommentDate : 0, 'media_type' => 'image_upload', 'media_state' => $item['moderation'] ? 'moderated' : 'visible', 'album_id' => $albumId, 'category_id' => $categoryId, 'media_privacy' => $mediaPrivacy, 'attachment_id' => 0, 'user_id' => $item['user_id'], 'username' => $model->getUsernameByUserId($item['user_id']), 'ip_id' => $model->getLatestIpIdFromUserId($item['user_id']), 'likes' => $item['likes'], 'like_users' => unserialize($item['like_users']), 'comment_count' => $item['comment_count'], 'rating_count' => 0, 'media_view_count' => $item['view_count']); $xfAttachment = array('data_id' => 0, 'content_type' => 'xengallery_media', 'content_id' => 0, 'attach_date' => $item['upload_date'], 'temp_hash' => '', 'unassociated' => 0, 'view_count' => $item['view_count']); $xfAttachmentData = array('user_id' => $item['user_id'], 'upload_date' => $item['upload_date'], 'filename' => $item['filename'], 'attach_count' => $item['attach_count']); $importedMediaId = $model->importMedia($item['image_id'], $tempFile, 'xfr_useralbum_image', $xengalleryMedia, $xfAttachment, $xfAttachmentData); @unlink($tempFile); return $importedMediaId; }
public function actionGetForums() { $forumid = $this->_input->filterSingle('forumid', XenForo_Input::UINT); $page = max($this->_input->filterSingle('page', XenForo_Input::UINT), 1); $perpage = $this->_input->filterSingle('perpage', XenForo_Input::UINT); if (!$perpage) { $perpage = XenForo_Application::get('options')->discussionsPerPage; } $previewtype = $this->_input->filterSingle('previewtype', XenForo_Input::UINT); if (!$previewtype) { $previewtype = 2; } // Check for Thread Prefixes (XenForo 1.1.x+) $prefixes = array(); if (method_exists($this, '_getPrefixModel')) { $prefix_groups = $this->_getPrefixModel()->getUsablePrefixesInForums($forumid); foreach ($prefix_groups as $group) { foreach ($group['prefixes'] as $prefix_data) { $phrase = new XenForo_Phrase('thread_prefix_' . $prefix_data['prefix_id']); $prefixes[$prefix_data['prefix_id']] = $phrase->render(); } } } $this->_prefixes = $prefixes; $visitor = XenForo_Visitor::getInstance(); $node_data = $this->_getNodeModel()->getNodeDataForListDisplay(false, 0); $is_category = false; $out = false; foreach ($node_data['nodesGrouped'] as $node_id => $node) { foreach ($node as $subforum_id => $subforum) { if ($subforum_id == $forumid) { if ($subforum['node_type_id'] == 'Category') { $is_category = true; } $out = true; break; } } if ($out) { break; } } $exclude = XenForo_Application::get('options')->forumrunnerExcludeForums; if (!$exclude) { $exclude = array(); } $forum_data = array(); if (isset($node_data['nodesGrouped'][$forumid])) { foreach ($node_data['nodesGrouped'][$forumid] as $forum_info) { if (in_array($forum_info['node_id'], $exclude)) { continue; } $out = array('id' => $forum_info['node_id'], 'new' => $forum_info['hasNew'], 'name' => prepare_utf8_string(strip_tags($forum_info['title']))); $icon = fr_get_forum_icon($forum_info['node_id'], $forum_info['hasNew']); if ($icon) { $out['icon'] = $icon; } if ($forum_info['node_type_id'] == 'LinkForum') { $link_forum_model = $this->getModelFromCache('XenForo_Model_LinkForum'); $link_data = $link_forum_model->getLinkForumById($forum_info['node_id']); $link = fr_fix_url($link_data['link_url']); if (is_int($link)) { $out['id'] = $link; } else { $out['link'] = $link; } $linkicon = fr_get_forum_icon($forum_info['node_id'], false, true); if ($linkicon) { $out['icon'] = $linkicon; } } else { if ($forum_info['node_type_id'] == 'Page') { $page_model = $this->getModelFromCache('XenForo_Model_Page'); $page_data = $page_model->getPageById($forum_info['node_id']); $link = fr_fix_url(XenForo_Link::buildPublicLink('pages', $page_data)); $out['link'] = $link; $linkicon = fr_get_forum_icon($forum_info['node_id'], false, true); if ($linkicon) { $out['icon'] = $linkicon; } } } if ($forum_info['description'] != '') { $desc = prepare_utf8_string(strip_tags($forum_info['description'])); if (strlen($desc)) { $out['desc'] = $desc; } } $forum_data[] = $out; /* * RKJ XXX * * Still TODO: Password FOrum? * Link Forums */ } } $thread_data = $sticky_thread_data = array(); $total_threads = 0; $canpost = $canattach = false; if ($forumid && !$is_category) { $helper = $this->getHelper('ForumThreadPost'); $forum_model = $this->_getForumModel(); $forum_info = null; try { $forum_info = $helper->assertForumValidAndViewable($forumid, array('readUserId' => $visitor['user_id'])); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } if ($forum_info) { $canpost = $forum_model->canPostThreadInForum($forum_info); $canattach = $forum_model->canUploadAndManageAttachment($forum_info); $thread_model = $this->_getThreadModel(); $thread_conditions = array_merge($thread_model->getPermissionBasedThreadFetchConditions($forum_info), array('sticky' => 0)); $thread_options = array('perPage' => $perpage, 'page' => $page, 'join' => XenForo_Model_Thread::FETCH_USER, 'readUserId' => $visitor['user_id'], 'postCountUserId' => $visitor['user_id'], 'order' => 'last_post_date', 'orderDirection' => 'desc'); if (!empty($thread_conditions['deleted'])) { $thread_options['join'] |= XenForo_Model_Thread::FETCH_DELETION_LOG; } $total_threads = $thread_model->countThreadsInForum($forumid, $thread_conditions); $this->canonicalizePageNumber($page, $perpage, $total_threads, 'forums', $forum_info); $threads = $thread_model->getThreadsInForum($forumid, $thread_conditions, $thread_options); // Remove sticky threads from the first page $sticky_threads = array(); if ($page == 1) { $sticky_threads = $thread_model->getStickyThreadsInForum($forumid, $thread_conditions, $thread_options); foreach (array_keys($sticky_threads) as $sticky_threadid) { unset($threads[$sticky_threadid]); } } $perms = $visitor->getNodePermissions($forumid); foreach ($threads as &$thread) { $thread = $thread_model->prepareThread($thread, $forum_info, $perms); } foreach ($sticky_threads as &$thread) { $thread = $thread_model->prepareThread($thread, $forum_info, $perms); } unset($thread); if ($visitor['user_id'] && $page == 1 && $forum_info['forum_read_date'] < $forum_info['last_post_date']) { $hasNew = false; foreach ($threads as $thread) { if ($thread['isNew']) { $hasNew = true; break; } } if (!$hasNew) { $this->_getForumModel()->markForumReadIfNeeded($forum_info, $visitor['user_id']); } } $thread_data = $this->processThreads($threads, $previewtype); $sticky_thread_data = $this->processThreads($sticky_threads, $previewtype); } } $out = array('forums' => $forum_data, 'threads' => $thread_data, 'total_threads' => $total_threads, 'threads_sticky' => $sticky_thread_data, 'total_sticky_threads' => count($sticky_thread_data), 'canpost' => $canpost, 'canattach' => $canattach); // Output Prefixes (XenForo 1.1.x+) if (count($this->_prefixes)) { $out_prefixes = array(); foreach ($this->_prefixes as $id => $prefix) { $out_prefixes[] = array('prefixid' => $id, 'prefixcaption' => prepare_utf8_string($prefix)); } $out += array('prefixes' => $out_prefixes, 'prefixrequired' => false); } return $out; }
public function actionLike() { $postid = $this->_input->filterSingle('postid', XenForo_Input::UINT); $helper = $this->getHelper('ForumThreadPost'); try { list($post_info, $thread_info, $forum_info) = $helper->assertPostValidAndViewable($postid); } catch (Exception $e) { json_error($e->getControllerResponse()->errorText->render()); } if (!$this->_getPostModel()->canLikePost($post_info, $thread_info, $forum_info, $error)) { $phrase = new XenForo_Phrase($error); json_error($phrase->render()); } $like_model = $this->_getLikeModel(); $existing_like = $like_model->getContentLikeByLikeUser('post', $postid, XenForo_Visitor::getUserId()); if ($existing_like) { $like_model->unlikeContent($existing_like); } else { $like_model->likeContent('post', $postid, $post_info['user_id']); } return array('success' => true); }
public function prepareMedia($media) { if (!empty($media['thumbnail_width'])) { if ($media['thumbnail_width']) { $media['thumbnailUrl'] = $this->getMediaThumbnailUrl($media); } else { $media['thumbnailUrl'] = ''; } $media['deleteUrl'] = XenForo_Link::buildPublicLink('attachments/delete', $media); $media['viewUrl'] = XenForo_Link::buildPublicLink('attachments', $media); $media['extension'] = strtolower(substr(strrchr($media['filename'], '.'), 1)); } $this->standardizeViewingUserReference($viewingUser); if (isset($media['user_id'])) { $media['isIgnored'] = array_key_exists($media['user_id'], $viewingUser['ignoredUsers']); $media['customUserFields'] = @unserialize($media['custom_fields']); } if (isset($media['media_title'])) { $media['media_title'] = XenForo_Helper_String::censorString($media['media_title']); } if (isset($media['media_description'])) { $media['media_description'] = XenForo_Helper_String::censorString($media['media_description']); } if (isset($media['data_id']) && isset($media['media_type']) && $media['media_type'] == 'video_upload') { $media['videoUrl'] = $this->getVideoUrl($media); } $media['mediaTag'] = false; if (!empty($media['media_type']) && $media['media_type'] == 'video_embed' && isset($media['media_tag'])) { preg_match('/\\[media=(.*?)\\](.*?)\\[\\/media\\]/is', $media['media_tag'], $parts); $media['mediaSite'] = "{$parts['1']}.{$parts['2']}"; $videoThumbnail = $this->getVideoThumbnailUrlFromParts($parts); $media['thumbnailUrl'] = $videoThumbnail; if (!$videoThumbnail) { $media['noThumb'] = true; } } if (empty($media['username'])) { $deletedUserPhrase = new XenForo_Phrase('xengallery_deleted_user'); $media['username'] = $deletedUserPhrase->render(); } $media['likeUsers'] = false; $media['liked'] = false; if (!empty($media['like_users'])) { $media['likeUsers'] = @unserialize($media['like_users']); if (is_array($media['likeUsers'])) { foreach ($media['likeUsers'] as $likeUser) { if ($likeUser['user_id'] == $viewingUser['user_id']) { $media['liked'] = true; } } } } $media['canLikeMedia'] = $this->canLikeMedia($media, $null, $viewingUser); $media['canRateMedia'] = $this->canRateMedia($media, $null, $viewingUser); if (!empty($media['findNewPage'])) { if (!isset($media['media_view_date'])) { $media['media_view_date'] = 0; } if (!isset($media['last_comment_date'])) { $media['last_comment_date'] = 0; } $media['newComment'] = $media['last_comment_date'] > $media['media_view_date']; } if (!empty($media['tags'])) { $media['tagsList'] = $media['tags'] ? @unserialize($media['tags']) : array(); } return $media; }