コード例 #1
0
ファイル: RelatedThreads.php プロジェクト: Sywooch/forums
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $threads = array();
     if (isset($params['thread']) and !empty($params['thread']['thread_id'])) {
         // $thread is found in the template params, try to fetch the tags
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($params['thread'][Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
     }
     if (empty($tagsOrTexts) and isset($params['page']) and !empty($params['page']['node_id'])) {
         // fetch page's tags
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($params['page'][Tinhte_XenTag_Constants::FIELD_PAGE_TAGS]);
     }
     if (empty($tagsOrTexts) and isset($params['forum']) and !empty($params['forum']['node_id'])) {
         // fetch forum's tags
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($params['forum'][Tinhte_XenTag_Constants::FIELD_FORUM_TAGS]);
     }
     if (empty($tagsOrTexts) and isset($params['resource']) and !empty($params['resource']['resource_id'])) {
         // fetch resource's tags
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($params['resource'][Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
     }
     if (!empty($tagsOrTexts)) {
         $core = WidgetFramework_Core::getInstance();
         /* @var $threadModel XenForo_Model_Thread */
         $threadModel = $core->getModelFromCache('XenForo_Model_Thread');
         /* @var $tagModel Tinhte_XenTag_Model_Tag */
         $tagModel = $core->getModelFromCache('Tinhte_XenTag_Model_Tag');
         $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
         $tags = $tagModel->getTagsByText($tagTexts);
         $threadIds = array();
         foreach ($tags as $tag) {
             $latest = Tinhte_XenTag_Helper::unserialize($tag['latest_tagged_contents']);
             if (empty($latest)) {
                 // for some reason, the latest_tagged_contents field is empty
                 // this is illogical because at least there is 1 tagged content (current thread)
                 // so we will rebuild the tag...
                 $latest = $tagModel->updateTag($tag['tag_id']);
             }
             if (!empty($latest)) {
                 foreach ($latest as $taggedContent) {
                     if ($taggedContent['content_type'] == 'thread') {
                         // ignore current thread id, obviously!!!
                         if (!empty($params['thread']['thread_id']) and $taggedContent['content_id'] == $params['thread']['thread_id']) {
                             continue;
                         }
                         $threadIds[] = $taggedContent['content_id'];
                     }
                 }
             }
         }
         if (!empty($threadIds)) {
             $threadIds = array_unique($threadIds);
             $forumIds = $this->_helperGetForumIdsFromOption(array(), $params, empty($widget['options']['as_guest']) ? false : true);
             // quick way to get all viewable forum ids
             $conditions = array('node_id' => $forumIds, Tinhte_XenTag_XenForo_Model_Thread::CONDITIONS_THREAD_ID => $threadIds, 'deleted' => false, 'moderated' => false);
             $fetchOptions = array('limit' => $widget['options']['limit'], 'join' => XenForo_Model_Thread::FETCH_AVATAR, 'order' => 'post_date', 'orderDirection' => 'desc');
             $threads = $threadModel->getThreads($conditions, $fetchOptions);
         }
     }
     $template->setParam('threads', $threads);
     return $template->render();
 }
コード例 #2
0
ファイル: Resource.php プロジェクト: Sywooch/forums
 protected function _Tinhte_XenTag_updateTagsInDatabase()
 {
     $force = $this->getExtraData(self::DATA_FORCE_UPDATE_TAGS_IN_DATABASE);
     $skip = $this->getExtraData(self::DATA_SKIP_UPDATE_TAGS_IN_DATABASE);
     if ($force or $this->isChanged(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS) and empty($skip)) {
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($this->get(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS));
         $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
         $updated = Tinhte_XenTag_Integration::updateTags(Tinhte_XenTag_Constants::CONTENT_TYPE_RESOURCE, $this->get('resource_id'), XenForo_Visitor::getUserId(), $tagTexts, $this);
         if (is_array($updated)) {
             $tagsCount = count($updated);
             $this->set(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS, $updated, '', array('setAfterPreSave' => true));
             $this->_db->update('xf_resource', array(Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS => serialize($updated)), array('resource_id = ?' => $this->get('resource_id')));
         } else {
             $tagsCount = intval($updated);
         }
         $requiresTag = Tinhte_XenTag_Option::get('resourceRequiresTag');
         $maximumTags = intval($this->getModelFromCache('XenResource_Model_Resource')->Tinhte_XenTag_getMaximumTags());
         if ($requiresTag and $maximumTags !== 0 and $tagsCount == 0) {
             throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_resource_requires_tag'), true);
         }
         if ($maximumTags !== -1 and $tagsCount > $maximumTags) {
             throw new XenForo_Exception(new XenForo_Phrase('tinhte_xentag_too_many_tags_x_of_y', array('maximum' => $maximumTags, 'count' => $tagsCount)), true);
         }
     }
 }
コード例 #3
0
ファイル: View.php プロジェクト: maitandat1507/Tinhte_XenTag
 public function prepareParams()
 {
     if (!isset($this->_params['Tinhte_XenTag_tagsList']) && !empty($this->_params['page'])) {
         $this->_params['Tinhte_XenTag_tagsList'] = $this->_params['page'][Tinhte_XenTag_Constants::FIELD_PAGE_TAGS] ? Tinhte_XenTag_Helper::unserialize($this->_params['page'][Tinhte_XenTag_Constants::FIELD_PAGE_TAGS]) : array();
     }
     parent::prepareParams();
 }
コード例 #4
0
ファイル: Thread.php プロジェクト: Sywooch/forums
 public function prepareApiDataForThread(array $thread, array $forum, array $firstPosts)
 {
     $data = parent::prepareApiDataForThread($thread, $forum, $firstPosts);
     $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
     $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
     $data['thread_tags'] = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearchMapping($tagTexts);
     return $data;
 }
コード例 #5
0
ファイル: Page.php プロジェクト: Sywooch/forums
 protected function _Tinhte_XenTag_updateTagsInDatabase()
 {
     $force = $this->getExtraData(self::DATA_FORCE_UPDATE_TAGS_IN_DATABASE);
     $skip = $this->getExtraData(self::DATA_SKIP_UPDATE_TAGS_IN_DATABASE);
     if ($force or $this->isChanged(Tinhte_XenTag_Constants::FIELD_PAGE_TAGS) and empty($skip)) {
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($this->get(Tinhte_XenTag_Constants::FIELD_PAGE_TAGS));
         $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
         $updated = Tinhte_XenTag_Integration::updateTags(Tinhte_XenTag_Constants::CONTENT_TYPE_PAGE, $this->get('node_id'), XenForo_Visitor::getUserId(), $tagTexts, $this);
         if (is_array($updated)) {
             $this->set(Tinhte_XenTag_Constants::FIELD_PAGE_TAGS, $updated, '', array('setAfterPreSave' => true));
             $this->_db->update('xf_page', array(Tinhte_XenTag_Constants::FIELD_PAGE_TAGS => serialize($updated)), array('node_id = ?' => $this->get('node_id')));
         }
     }
 }
コード例 #6
0
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $threads = array();
     if (isset($params['thread']) and !empty($params['thread']['thread_id'])) {
         // $thread is found in the template params, try to fetch the tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['thread'][Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
     }
     if (empty($tags) and isset($params['page']) and !empty($params['page']['node_id'])) {
         // fetch page's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['page'][Tinhte_XenTag_Constants::FIELD_PAGE_TAGS]);
     }
     if (empty($tags) and isset($params['forum']) and !empty($params['forum']['node_id'])) {
         // fetch forum's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['forum'][Tinhte_XenTag_Constants::FIELD_FORUM_TAGS]);
     }
     if (empty($tags) and isset($params['resource']) and !empty($params['resource']['resource_id'])) {
         // fetch resource's tags
         $tags = Tinhte_XenTag_Helper::unserialize($params['resource'][Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
     }
     if (!empty($tags)) {
         $core = WidgetFramework_Core::getInstance();
         /* @var $searchModel XenForo_Model_Search */
         $searchModel = $core->getModelFromCache('XenForo_Model_Search');
         $tagConstraint = implode(' ', array_keys($tags));
         $constraints = array(Tinhte_XenTag_Constants::SEARCH_CONSTRAINT_TAGS => $tagConstraint);
         $searcher = new XenForo_Search_Searcher($searchModel);
         $searchQuery = '';
         $order = 'date';
         $typeHandler = $searchModel->getSearchDataHandler('thread');
         $results = $searcher->searchType($typeHandler, $searchQuery, $constraints, $order, false, $widget['options']['limit'] * 10);
         if (!empty($results)) {
             $threadIds = array();
             foreach ($results as $result) {
                 if ($result[0] === 'thread') {
                     $threadIds[] = $result[1];
                 }
             }
             $threadIds = array_unique($threadIds);
             $forumIds = $this->_helperGetForumIdsFromOption(array(), $params, empty($widget['options']['as_guest']) ? false : true);
             $conditions = array('node_id' => $forumIds, Tinhte_XenTag_XenForo_Model_Thread::CONDITIONS_THREAD_ID => $threadIds, 'deleted' => false, 'moderated' => false);
             $fetchOptions = array('limit' => $widget['options']['limit'], 'join' => XenForo_Model_Thread::FETCH_AVATAR, 'order' => 'post_date', 'orderDirection' => 'desc');
             /* @var $threadModel XenForo_Model_Thread */
             $threadModel = $core->getModelFromCache('XenForo_Model_Thread');
             $threads = $threadModel->getThreads($conditions, $fetchOptions);
         }
     }
     $template->setParam('threads', $threads);
     return $template->render();
 }
コード例 #7
0
ファイル: Forum.php プロジェクト: Sywooch/forums
 public function actionEdit()
 {
     $response = parent::actionEdit();
     if ($response instanceof XenForo_ControllerResponse_View) {
         if (isset($response->params['forum'])) {
             $forum =& $response->params['forum'];
             if (isset($forum[Tinhte_XenTag_Constants::FIELD_FORUM_OPTIONS])) {
                 $forum[Tinhte_XenTag_Constants::FIELD_FORUM_OPTIONS] = Tinhte_XenTag_Helper::unserialize($forum[Tinhte_XenTag_Constants::FIELD_FORUM_OPTIONS]);
             } else {
                 $forum[Tinhte_XenTag_Constants::FIELD_FORUM_OPTIONS] = array();
             }
         }
     }
     return $response;
 }
コード例 #8
0
ファイル: TaggedThreads.php プロジェクト: Sywooch/forums
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $threads = array();
     $tags = Tinhte_XenTag_Helper::explodeTags($widget['options']['tags']);
     $tagsText = array();
     foreach ($tags as $tag) {
         $tag = trim($tag);
         if (!empty($tag)) {
             $tagsText[] = $tag;
         }
     }
     if (!empty($tagsText)) {
         $core = WidgetFramework_Core::getInstance();
         /* @var $threadModel XenForo_Model_Thread */
         $threadModel = $core->getModelFromCache('XenForo_Model_Thread');
         /* @var $tagModel Tinhte_XenTag_Model_Tag */
         $tagModel = $core->getModelFromCache('Tinhte_XenTag_Model_Tag');
         $tags = $tagModel->getTagsByText($tagsText);
         $threadIds = array();
         foreach ($tags as $tag) {
             $latest = Tinhte_XenTag_Helper::unserialize($tag['latest_tagged_contents']);
             if (empty($latest)) {
                 // for some reason, the latest_tagged_contents field is empty
                 // this is illogical because at least there is 1 tagged content (current thread)
                 // so we will rebuild the tag...
                 $latest = $tagModel->updateTag($tag['tag_id']);
             }
             if (!empty($latest)) {
                 foreach ($latest as $taggedContent) {
                     if ($taggedContent['content_type'] == 'thread') {
                         $threadIds[] = $taggedContent['content_id'];
                     }
                 }
             }
         }
         if (!empty($threadIds)) {
             $threadIds = array_unique($threadIds);
             $forumIds = $this->_helperGetForumIdsFromOption(array(), $params, empty($widget['options']['as_guest']) ? false : true);
             // quick way to get all viewable forum ids
             $conditions = array('node_id' => $forumIds, Tinhte_XenTag_XenForo_Model_Thread::CONDITIONS_THREAD_ID => $threadIds, 'deleted' => false, 'moderated' => false);
             $fetchOptions = array('limit' => $widget['options']['limit'], 'join' => XenForo_Model_Thread::FETCH_AVATAR, 'order' => 'post_date', 'orderDirection' => 'desc');
             $threads = $threadModel->getThreads($conditions, $fetchOptions);
         }
     }
     $template->setParam('threads', $threads);
     return $template->render();
 }
コード例 #9
0
 protected function __construct($html, array &$update, array &$resource)
 {
     $this->_html = $html;
     $mode = Tinhte_XenTag_Option::get('autoTagResource');
     switch ($mode) {
         case Tinhte_XenTag_Option::AUTO_TAG_RESOURCE_TAGS:
             if (!empty($resource[Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS])) {
                 $this->_tags = Tinhte_XenTag_Helper::unserialize($resource[Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
             }
             break;
         case Tinhte_XenTag_Option::AUTO_TAG_MODE_ALL_TAGS:
             if (!empty($resource[Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS])) {
                 $this->_tags = Tinhte_XenTag_Helper::unserialize($resource[Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
             }
             $this->_useGlobalTags = true;
             break;
     }
 }
コード例 #10
0
ファイル: Forum.php プロジェクト: Sywooch/forums
 protected function _insertIntoIndex(XenForo_Search_Indexer $indexer, array $data, array $parentData = null)
 {
     $metadata = array();
     if (isset($data[Tinhte_XenTag_Constants::FIELD_FORUM_TAGS])) {
         // sondh@2012-11-05
         // added isset check before trying to unserialize the tags
         // or this may raise an exception (it happens because
         // XenForo_DataWriter::getMergedData doesn't return an array with all the fields
         // the array only includes new or existing data...
         // similar to Tinhte_XenTag_Search_DataHandler_Page
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($data[Tinhte_XenTag_Constants::FIELD_FORUM_TAGS]);
     } else {
         $tagsOrTexts = array();
     }
     $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
     $metadata[Tinhte_XenTag_Constants::SEARCH_METADATA_TAGS] = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($tagTexts);
     $indexer->insertIntoIndex(Tinhte_XenTag_Constants::CONTENT_TYPE_FORUM, $data['node_id'], $data['title'], $data['description'], XenForo_Application::$time, XenForo_Visitor::getUserId(), 0, $metadata);
 }
コード例 #11
0
ファイル: Thread.php プロジェクト: Sywooch/forums
 protected function _insertIntoIndex(XenForo_Search_Indexer $indexer, array $data, array $parentData = null)
 {
     if (isset($data[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS])) {
         // sondh@2012-11-05
         // added isset check before trying to unserialize the tags
         // read more about this in
         // Tinhte_XenTag_Search_DataHandler_Page::_insertIntoIndex
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($data[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
     } else {
         $tagsOrTexts = array();
     }
     if (!empty($tagsOrTexts)) {
         $extraMetadata = array();
         $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
         $extraMetadata[Tinhte_XenTag_Constants::SEARCH_METADATA_TAGS] = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($tagTexts);
         $indexer = new Tinhte_XenTag_XenForo_Search_Indexer($indexer, $extraMetadata);
     }
     $result = parent::_insertIntoIndex($indexer, $data, $parentData);
 }
コード例 #12
0
ファイル: Post.php プロジェクト: maitandat1507/Tinhte_XenTag
 protected function __construct($html, array &$post, array &$thread)
 {
     $this->_html = $html;
     $mode = Tinhte_XenTag_Option::get('autoTagMode');
     switch ($mode) {
         case Tinhte_XenTag_Option::AUTO_TAG_MODE_THREAD_TAGS:
             if (!empty($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS])) {
                 $this->_tags = Tinhte_XenTag_Helper::unserialize($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
             }
             break;
         case Tinhte_XenTag_Option::AUTO_TAG_MODE_THREAD_TAGS_FIRST_POST_ONLY:
             if ($post['position'] == 0 && !empty($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS])) {
                 $this->_tags = Tinhte_XenTag_Helper::unserialize($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
             }
             break;
         case Tinhte_XenTag_Option::AUTO_TAG_MODE_ALL_TAGS:
             if (!empty($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS])) {
                 $this->_tags = Tinhte_XenTag_Helper::unserialize($thread[Tinhte_XenTag_Constants::FIELD_THREAD_TAGS]);
             }
             $this->_useGlobalTags = true;
             break;
     }
 }
コード例 #13
0
ファイル: Forum.php プロジェクト: maitandat1507/Tinhte_XenTag
 public function prepareForum(array $forum)
 {
     $prepared = parent::prepareForum($forum);
     $prepared['Tinhte_XenTag_tagsList'] = $forum[Tinhte_XenTag_Constants::FIELD_FORUM_TAGS] ? Tinhte_XenTag_Helper::unserialize($forum[Tinhte_XenTag_Constants::FIELD_FORUM_TAGS]) : array();
     return $prepared;
 }
コード例 #14
0
ファイル: TaggedContent.php プロジェクト: Sywooch/forums
 protected function _deleteTaggedContentsResources(array $tag, array $taggeds)
 {
     if (!Tinhte_XenTag_Option::xfrmFound()) {
         // XFRM is not installed/enabled
         return false;
     }
     $tagModel = $this->getModelFromCache('Tinhte_XenTag_Model_Tag');
     $resourceModel = $this->getModelFromCache('XenResource_Model_Resource');
     $resourceIds = array();
     foreach ($taggeds as $tagged) {
         if ($tagged['content_type'] == Tinhte_XenTag_Constants::CONTENT_TYPE_RESOURCE) {
             $resourceIds[] = $tagged['content_id'];
         }
     }
     $resources = $resourceModel->getResourcesByIds($resourceIds);
     foreach ($resources as $resource) {
         $tagsOrTexts = Tinhte_XenTag_Helper::unserialize($resource[Tinhte_XenTag_Constants::FIELD_RESOURCE_TAGS]);
         $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
         $filteredTagTexts = array();
         foreach ($tagTexts as $tagText) {
             if ($tagModel->isTagIdenticalWithText($tag, $tagText)) {
                 // drop this tag
             } else {
                 $filteredTagTexts[] = $tagText;
             }
         }
         if (count($tagTexts) != count($filteredTagTexts)) {
             /* @var $dw XenResource_DataWriter_Resource */
             $dw = XenForo_DataWriter::create('XenResource_DataWriter_Resource');
             $dw->setExistingData($resource, true);
             // save queries
             $dw->Tinhte_XenTag_setTags($filteredTagTexts);
             $dw->setExtraData(Tinhte_XenTag_XenResource_DataWriter_Resource::DATA_SKIP_UPDATE_TAGS_IN_DATABASE, true);
             $dw->save();
         }
     }
 }
コード例 #15
0
ファイル: Tag.php プロジェクト: Sywooch/forums
 public function getAllTag(array $conditions = array(), array $fetchOptions = array())
 {
     $whereConditions = $this->prepareTagConditions($conditions, $fetchOptions);
     $orderClause = $this->prepareTagOrderOptions($fetchOptions);
     $joinOptions = $this->prepareTagFetchOptions($fetchOptions);
     $limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
     $all = $this->fetchAllKeyed($this->limitQueryResults("\n\t\t\t\tSELECT tag.*\n\t\t\t\t{$joinOptions['selectFields']}\n\t\t\t\tFROM `xf_tinhte_xentag_tag` AS tag\n\t\t\t\t{$joinOptions['joinTables']}\n\t\t\t\tWHERE {$whereConditions}\n\t\t\t\t{$orderClause}\n\t\t\t\t", $limitOptions['limit'], $limitOptions['offset']), 'tag_id');
     foreach ($all as &$tag) {
         if (!empty($tag['target_data'])) {
             $tag['target_data'] = Tinhte_XenTag_Helper::unserialize($tag['target_data']);
         }
     }
     return $all;
 }