/** * Helper to get the tab rule add/edit form controller response. * * @param array $tabRule * * @return XenForo_ControllerResponse_View */ protected function _getTabRuleAddEditResponse(array $tabRule) { /* @var $tabNameModel Waindigo_Tabs_Model_TabName */ $tabNameModel = $this->getModelFromCache('Waindigo_Tabs_Model_TabName'); $tabNames = $tabNameModel->prepareTabNames($tabNameModel->getTabNames()); $tabModel = $this->_getTabModel(); $matchContentTypes = $tabModel->getMatchContentTypes(); $createContentTypes = $tabModel->getCreateContentTypes(); $viewParams = array('tabRule' => $tabRule, 'matchCriteria' => array($tabRule['match_content_type'] => XenForo_Helper_Criteria::prepareCriteriaForSelection($tabRule['match_criteria'])), 'matchCriteriaData' => Waindigo_Tabs_Helper_Criteria::getDataForMatchCriteriaSelection(), 'matchContentTypes' => $matchContentTypes, 'createCriteria' => array($tabRule['create_content_type'] => $tabRule['create_criteria'] ? unserialize($tabRule['create_criteria']) : array()), 'createCriteriaData' => Waindigo_Tabs_Helper_Criteria::getDataForCreateCriteriaSelection(), 'createContentTypes' => $createContentTypes, 'tabNames' => $tabNames, 'customMessage' => $this->_getTabRuleModel()->getTabRuleMasterCustomMessagePhraseValue($tabRule['tab_rule_id'])); return $this->responseView('Waindigo_Tabs_ViewAdmin_TabRule_Edit', 'waindigo_tab_rule_edit_tabs', $viewParams); }
/** * * @see XenGallery_ViewPublic_Media_Add::renderHtml() */ public function renderHtml() { parent::renderHtml(); /* @var $tabModel Waindigo_Tabs_Model_Tab */ $tabModel = XenForo_Model::create('Waindigo_Tabs_Model_Tab'); /* @var $tabRuleModel Waindigo_Tabs_Model_TabRule */ $tabRuleModel = XenForo_Model::create('Waindigo_Tabs_Model_TabRule'); $tabRules = $tabRuleModel->getTabRules(array('match_content_type' => 'resource')); $resource = array('resource_category_id' => $this->_params['category']['resource_category_id']); $tabCreateTemplates = array(); foreach ($tabRules as $tabRuleId => $tabRule) { if (Waindigo_Tabs_Helper_Criteria::resourceMatchesCriteria($tabRule['match_criteria'], true, $resource)) { $tabCreateTemplates[$tabRuleId] = $tabModel->getCreateTemplate($tabRule, $this); } } $this->_params['tabCreateTemplates'] = $tabCreateTemplates; }
/** * * @see XenForo_ViewPublic_Conversation_Add::renderHtml() */ public function renderHtml() { parent::renderHtml(); /* @var $tabModel Waindigo_Tabs_Model_Tab */ $tabModel = XenForo_Model::create('Waindigo_Tabs_Model_Tab'); /* @var $tabRuleModel Waindigo_Tabs_Model_TabRule */ $tabRuleModel = XenForo_Model::create('Waindigo_Tabs_Model_TabRule'); $tabRules = $tabRuleModel->getTabRules(array('match_content_type' => 'conversation')); $visitor = XenForo_Visitor::getInstance(); $conversation = array('username' => $visitor['username']); $tabCreateTemplates = array(); foreach ($tabRules as $tabRuleId => $tabRule) { if (Waindigo_Tabs_Helper_Criteria::conversationMatchesCriteria($tabRule['match_criteria'], true, $conversation)) { $tabCreateTemplates[$tabRuleId] = $tabModel->getCreateTemplate($tabRule, $this); } } $this->_params['tabCreateTemplates'] = $tabCreateTemplates; }
/** * * @see XenGallery_ViewPublic_Media_Add::renderJson() */ public function renderJson() { if (!empty($this->_params['container']['category_id'])) { /* @var $tabModel Waindigo_Tabs_Model_Tab */ $tabModel = XenForo_Model::create('Waindigo_Tabs_Model_Tab'); /* @var $tabRuleModel Waindigo_Tabs_Model_TabRule */ $tabRuleModel = XenForo_Model::create('Waindigo_Tabs_Model_TabRule'); $tabRules = $tabRuleModel->getTabRules(array('match_content_type' => 'xengallery_media')); $media = array('category_id' => $this->_params['container']['category_id']); $tabCreateTemplates = array(); foreach ($tabRules as $tabRuleId => $tabRule) { if (Waindigo_Tabs_Helper_Criteria::mediaMatchesCriteria($tabRule['match_criteria'], true, $media)) { $tabCreateTemplates[$tabRuleId] = $tabModel->getCreateTemplate($tabRule, $this); } } $this->_params['tabCreateTemplates'] = $tabCreateTemplates; } return parent::renderJson(); }
/** * * @see XenForo_DataWriter_ConversationMaster::_postSave() */ protected function _postSave() { parent::_postSave(); $postSaveChanges = array(); if ($this->isInsert() && $this->getOption(self::OPTION_CHECK_TAB_RULES)) { /* @var $tabModel Waindigo_Tabs_Model_Tab */ $tabModel = $this->getModelFromCache('Waindigo_Tabs_Model_Tab'); /* @var $tabRuleModel Waindigo_Tabs_Model_TabRule */ $tabRuleModel = $this->getModelFromCache('Waindigo_Tabs_Model_TabRule'); $tabRules = $tabRuleModel->getTabRules(array('match_content_type' => 'conversation')); $tabId = $this->get('tab_id'); $extraTabData = array(); if (isset($GLOBALS['XenForo_ControllerPublic_Conversation'])) { /* @var $controller XenForo_ControllerPublic_Conversation */ $controller = $GLOBALS['XenForo_ControllerPublic_Conversation']; $extraTabData = $controller->getInput()->filterSingle('extra_tab_data', XenForo_Input::ARRAY_SIMPLE); } $conversation = $this->getMergedData(); $firstMessage = $this->_firstMessageDw; if ($firstMessage) { $messageText = $firstMessage->get('message'); $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)); $messageParams = array('title' => $this->get('title'), 'username' => $this->get('username'), 'contentLink' => XenForo_Link::buildPublicLink('canonical:conversations', $conversation), 'snippet' => $snippet); $defaultMessage = new XenForo_Phrase('waindigo_conversation_message_create_tabs', $messageParams, false); $params = array('user_id' => $this->get('user_id'), 'username' => $this->get('username'), 'title' => $this->get('title'), 'content_type' => 'conversation', 'content_id' => $this->get('conversation_id'), 'tag_line' => XenForo_Helper_String::wholeWordTrim(XenForo_Helper_string::bbCodeStrip($messageText), 100)); $tabNameId = ''; foreach ($tabRules as $tabRuleId => $tabRule) { if (Waindigo_Tabs_Helper_Criteria::conversationMatchesCriteria($tabRule['match_criteria'], true, $conversation)) { if ($tabRule['create_criteria']) { $createCriteria = unserialize($tabRule['create_criteria']); } else { $createCriteria = array(); } if (!empty($createCriteria['use_custom_message'])) { $params['message'] = new XenForo_Phrase($tabRuleModel->getTabRuleCustomMessagePhraseName($tabRuleId), $messageParams, false); } else { $params['message'] = $defaultMessage; } if (!empty($extraTabData[$tabRuleId])) { $params = array_merge($extraTabData[$tabRuleId], $params); } $tabId = $tabModel->createNewTab($tabRule['create_content_type'], $tabId, $tabRule['tab_name_id'], $createCriteria, $params); if ($tabId && !$tabNameId) { $tabNameId = $tabRule['match_tab_name_id']; } } } if ($tabId && $tabId != $this->get('tab_id')) { $this->set('tab_id', $tabId, '', array('setAfterPreSave' => true)); $postSaveChanges['tab_id'] = $tabId; if ($tabNameId) { $tabModel->insertTab($this->get('tab_id'), 'conversation', $this->get('conversation_id'), $tabNameId); } } } } if (isset($GLOBALS['XenForo_ControllerPublic_Conversation'])) { /* @var $controller XenForo_ControllerPublic_Conversation */ $controller = $GLOBALS['XenForo_ControllerPublic_Conversation']; // TODO: check permissions? $tabNameId = $controller->getInput()->filterSingle('tab_name_id', XenForo_Input::UINT); if ($tabNameId) { $this->_db->update('xf_tab_content', array('tab_name_id' => $tabNameId), 'content_id = ' . $this->_db->quote($this->get('conversation_id')) . ' AND content_type = \'conversation\''); } } if ($postSaveChanges) { $this->_db->update('xf_conversation_master', $postSaveChanges, 'conversation_id = ' . $this->_db->quote($this->get('conversation_id'))); } if ($this->isChanged('tab_id') && $this->getExisting('tab_id') && $this->get('tab_id')) { $this->_db->update('xf_tab_content', array('tab_id' => $this->get('tab_id')), 'content_id = ' . $this->_db->quote($this->getExisting('conversation_id')) . ' AND content_type = \'conversation\''); } }