/** * * @see XenResource_DataWriter_Resource::_insertDiscussionThread() */ protected function _insertDiscussionThread($nodeId, $prefixId = 0) { /* @var $nodeModel XenForo_Model_Node */ $nodeModel = $this->getModelFromCache('XenForo_Model_Node'); $node = $nodeModel->getNodeById($nodeId); if (!$node) { return false; } if ($node['node_type_id'] == 'SocialCategory') { $socialForumId = 0; if (isset($GLOBALS['XenResource_ControllerPublic_Resource'])) { /* @var $controller XenResource_ControllerPublic_Resource */ $controller = $GLOBALS['XenResource_ControllerPublic_Resource']; $socialForumId = $controller->getInput()->filterSingle('social_forum_id', XenForo_Input::UINT); } if ($socialForumId) { $socialForumModel = ThemeHouse_SocialGroups_SocialForum::getSocialForumModel(); $socialForum = $socialForumModel->getSocialForumById($socialForumId); } if (!empty($socialForum) && $socialForum['node_id'] == $node['node_id']) { ThemeHouse_SocialGroups_SocialForum::setup($socialForum); // TODO check permissions } else { $writer = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForum'); $writer->bulkSet(array('node_id' => $nodeId, 'user_id' => XenForo_Visitor::getUserId(), 'title' => $this->_getThreadTitle(), 'description' => $this->get('tag_line'), 'social_forum_type' => 'resource')); $writer->save(); ThemeHouse_SocialGroups_SocialForum::setup($writer->getMergedData()); $this->set('social_forum_id', $writer->get('social_forum_id'), '', array('setAfterPreSave' => true)); } } return parent::_insertDiscussionThread($nodeId, $prefixId); }
/** * * @see XenForo_ControllerHelper_ForumThreadPost::assertThreadValidAndViewable() */ public function assertThreadValidAndViewable($threadId, array $threadFetchOptions = array(), array $forumFetchOptions = array()) { $thread = $this->getThreadOrError($threadId, $threadFetchOptions); if ($thread['social_forum_id']) { $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($thread['social_forum_id']); if ($socialForum) { $this->_thread['social_forum_user_id'] = $socialForum['user_id']; } } return parent::assertThreadValidAndViewable($threadId, $threadFetchOptions, $forumFetchOptions); }
/** * * @see XenForo_ControllerPublic_Forum::_preDispatch() */ protected function _preDispatch($action) { $socialForumId = $this->_input->filterSingle('social_forum_id', XenForo_Input::UINT); $urlPortion = $this->_input->filterSingle('url_portion', XenForo_Input::STRING); $socialForum = null; if ($socialForumId) { $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($socialForumId); } elseif ($urlPortion) { $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($urlPortion); } if (($socialForumId || $urlPortion) && !ThemeHouse_SocialGroups_SocialForum::hasInstance()) { throw new XenForo_ControllerResponse_Exception($this->responseError(new XenForo_Phrase('th_social_forum_not_found_socialgroups'))); } $this->_request->setParam('node_id', $socialForum['node_id']); $xenOptions = XenForo_Application::get('options'); if ($socialForum['style_id'] && $xenOptions->th_socialGroups_allowStyleOverride) { $this->setViewStateChange('styleId', $socialForum['style_id']); } parent::_preDispatch($action); }
protected function _postSave() { $this->_updateModerationQueue(); ThemeHouse_SocialGroups_SocialForum::setup($this->getMergedData()); if ($this->isInsert()) { $this->addCreatorAsMember(); $xenOptions = XenForo_Application::get('options'); if ($xenOptions->th_socialGroups_createToSecondary) { $createToSecondary = $xenOptions->th_socialGroups_createToSecondary; if (!empty($createToSecondary['type']) && ($createToSecondary == '_all' || $createToSecondary == '_some' && !empty($createToSecondary[$this->get('node_id')]))) { $this->addToSecondarySocialForumIds(); } } } if ($this->isChanged('title') || $this->isChanged('logo_date') || $this->isChanged('logo_width') || $this->isChanged('logo_height') || $this->isChanged('logo_crop_x') || $this->isChanged('logo_crop_y')) { /* @var $socialForumCombinationModel ThemeHouse_SocialGroups_Model_SocialForumCombination */ $socialForumCombinationModel = $this->getModelFromCache('ThemeHouse_SocialGroups_Model_SocialForumCombination'); $socialForumCombinationModel->rebuildExistingSocialForumCombinationForSocialForumId($this->get('social_forum_id')); } if ($this->isChanged('user_id')) { if ($this->get('user_id')) { $this->_db->query(' UPDATE xf_user_profile AS user_profile SET user_profile.social_forums_created = user_profile.social_forums_created + 1 WHERE user_profile.user_id = ? ', $this->get('user_id')); $this->_getSocialForumMemberModel()->checkJoinRestrictionsForUser($this->get('user_id'), $this->get('node_id')); } if ($this->getExisting('user_id')) { $this->_db->query(' UPDATE xf_user_profile AS user_profile SET user_profile.social_forums_created = IF(user_profile.social_forums_created > 0, user_profile.social_forums_created - 1, 0) WHERE user_profile.user_id = ? ', $this->getExisting('user_id')); } } }
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'); }
/** * * @see XenForo_Model_Post::canViewAttachmentOnPost() */ public function canViewAttachmentOnPost(array $post, array $thread, array $forum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null) { if (isset($thread['social_forum_id']) && $thread['social_forum_id']) { $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($thread['social_forum_id']); /* @var $socialForumModel ThemeHouse_SocialGroups_Model_SocialForum */ $socialForumModel = XenForo_Model::create('ThemeHouse_SocialGroups_Model_SocialForum'); $nodePermissions = $socialForumModel->getNodePermissions($socialForum->toArray(), $socialForum->getSocialForumMembers()); XenForo_Visitor::getInstance()->setNodePermissions($forum['node_id'], $nodePermissions); } return parent::canViewAttachmentOnPost($post, $thread, $forum, $errorPhraseKey, $nodePermissions, $viewingUser); }
public function stepMembers($start, array $options) { $model = $this->_importModel; $socialForumMap = $model->getImportContentMap('socialForum'); $options = array_merge(array('limit' => 100, 'max' => false), $options); if ($options['max'] === false) { $options['max'] = $this->_db->fetchOne(' SELECT MAX(member_id) FROM xf_cz_group_member '); } $members = $this->_db->fetchAll($this->_db->limit(' SELECT * FROM xf_cz_group_member WHERE member_id > ' . $this->_db->quote($start) . ' ORDER BY member_id ', $options['limit'])); if (!$members) { return true; } $next = 0; $total = 0; XenForo_Db::beginTransaction(); foreach ($members as $member) { $next = $member['member_id']; $socialForumId = $this->_mapLookUp($socialForumMap, $member['group_id']); if ($socialForumId) { if ($member['user_id']) { $socialForum = ThemeHouse_SocialGroups_SocialForum::setup($socialForumId); $writer = XenForo_DataWriter::create('ThemeHouse_SocialGroups_DataWriter_SocialForumMember'); $writer->set('social_forum_id', $socialForumId); $writer->set('user_id', $member['user_id']); $writer->set('join_date', $member['join_date']); $writer->set('is_approved', 1); $writer->save(); $total++; } } } XenForo_Db::commit(); $this->_session->incrementStepImportTotal($total); return array($next, $options, $this->_getProgressOutput($next, $options['max'])); }
/** * Post-delete handling. */ protected function _postDelete() { if (XenForo_Application::$versionId >= 1020000) { /* @var $forumWatchModel XenForo_Model_ForumWatch */ $forumWatchModel = XenForo_Model::create('XenForo_Model_ForumWatch'); if (!ThemeHouse_SocialGroups_SocialForum::hasInstance()) { ThemeHouse_SocialGroups_SocialForum::setup($this->get('social_forum_id')); } if (ThemeHouse_SocialGroups_SocialForum::hasInstance()) { $socialForum = ThemeHouse_SocialGroups_SocialForum::getInstance()->toArray(); $forumWatchModel->setForumWatchState($this->get('user_id'), $socialForum['node_id'], 'delete'); } } if ($this->getExisting('is_approved') && !$this->getExisting('is_invited')) { $this->_db->query(' UPDATE xf_social_forum AS social_forum SET social_forum.member_count = IF(social_forum.member_count > 0, social_forum.member_count - 1, 0) WHERE social_forum.social_forum_id = ? ', $this->get('social_forum_id')); $this->_db->query(' UPDATE xf_user_profile AS user_profile SET user_profile.social_forums_joined = IF(user_profile.social_forums_joined > 0, user_profile.social_forums_joined - 1, 0) WHERE user_profile.user_id = ? ', $this->getExisting('user_id')); } }