예제 #1
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
         $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
파일: 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;
 }
예제 #4
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')));
         }
     }
 }
예제 #5
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);
 }
예제 #6
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);
 }
예제 #7
0
 /**
  * Inserts tag links into an HTML-formatted text.
  *
  * @param string $html
  * @param array $tags
  * @param array $options
  */
 public static function autoTag($html, array $tagsOrTexts, array &$options = array())
 {
     if (empty($tagsOrTexts)) {
         return $html;
     }
     $html = strval($html);
     $tagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($tagsOrTexts);
     // prepare the options
     $onceOnly = empty($options['onceOnly']) ? false : true;
     $options['autoTagged'] = array();
     // reset this
     // sort tags with the longest one first
     // since 1.0.3
     usort($tagTexts, array(__CLASS__, '_autoTag_sortTagsByLength'));
     foreach ($tagTexts as $tagText) {
         $offset = 0;
         $tagLength = utf8_strlen($tagText);
         while (true) {
             $pos = Tinhte_XenTag_Helper::utf8_stripos($html, $tagText, $offset);
             if ($pos !== false) {
                 // the tag has been found
                 if (!self::_autoTag_isBetweenHtmlTags($html, $pos) and self::_autoTag_hasValidCharacterAround($html, $pos, $tagText)) {
                     // and it's not between HTML tags,
                     // with good surrounding characters
                     // start replacing
                     $template = new XenForo_Template_Public('tinhte_xentag_bb_code_tag_tag');
                     $template->setParam('tag', $tagText);
                     $template->setParam('displayText', utf8_substr($html, $pos, $tagLength));
                     $replacement = $template->render();
                     $html = utf8_substr_replace($html, $replacement, $pos, $tagLength);
                     // sondh@2012-09-20
                     // keep track of the auto tagged tags
                     $options['autoTagged'][$tagText][$pos] = $replacement;
                     $offset = $pos + utf8_strlen($replacement);
                     if ($onceOnly) {
                         // auto link only once per tag
                         // break the loop now
                         break;
                         // while (true)
                     }
                 } else {
                     $offset = $pos + $tagLength;
                 }
             } else {
                 // no match has been found, stop working with this tag
                 break;
                 // while (true)
             }
         }
     }
     return $html;
 }
예제 #8
0
 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();
         }
     }
 }
예제 #9
0
파일: Post.php 프로젝트: Sywooch/forums
 public static function updateThreadDwFromPostDw(XenForo_DataWriter_Discussion_Thread $threadDw, XenForo_DataWriter_DiscussionMessage_Post $postDw)
 {
     if (!Tinhte_XenTag_Option::get('tagThreadWithHashtags')) {
         return false;
     }
     $message = $postDw->get('message');
     $tagTexts = Tinhte_XenTag_Integration::parseHashtags($message);
     $threadTags = $threadDw->Tinhte_XenTag_getTags();
     $threadTagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($threadTags);
     $threadSafes = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($threadTagTexts);
     $isChanged = false;
     foreach ($tagTexts as $tagText) {
         $safe = Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText);
         if (!in_array($safe, $threadSafes)) {
             $threadTags[] = $tagText;
             $threadSafes[] = $safe;
             $isChanged = true;
         }
     }
     if ($isChanged) {
         $threadDw->Tinhte_XenTag_setTags($threadTags);
         return true;
     }
     return false;
 }