Example #1
0
 public function Tinhte_XenTag_getMaximumHashtags(array $forum, array $nodePermissions = null, array $viewingUser = null)
 {
     if (!Tinhte_XenTag_Option::get('useHashtag')) {
         return 0;
     }
     $this->standardizeViewingUserReferenceForNode($forum['node_id'], $viewingUser, $nodePermissions);
     return XenForo_Permission::hasContentPermission($nodePermissions, 'Tinhte_XenTag_maximumHts');
 }
Example #2
0
 public function updateThreadViews()
 {
     parent::updateThreadViews();
     if (Tinhte_XenTag_Option::get('logView')) {
         /** @var Tinhte_XenTag_Model_TagView $tagViewModel */
         $tagViewModel = $this->getModelFromCache('Tinhte_XenTag_Model_TagView');
         $tagViewModel->updateTagViews();
     }
 }
    protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
    {
        $core = WidgetFramework_Core::getInstance();
        /** @var Tinhte_XenTag_XenForo_Model_Tag $tagModel */
        $tagModel = $core->getModelFromCache('XenForo_Model_Tag');
        if (!empty($widget['options']['days'])) {
            $days = $widget['options']['days'];
        } else {
            $days = Tinhte_XenTag_Option::get('trendingDays');
        }
        $cutoff = XenForo_Application::$time - $days * 86400;
        if (!empty($widget['options']['limit'])) {
            $limit = $widget['options']['limit'];
        } else {
            $limit = Tinhte_XenTag_Option::get('trendingMax');
        }
        $forumIds = array();
        if (!empty($widget['options']['forums'])) {
            $forumIds = $this->_helperGetForumIdsFromOption($widget['options']['forums'], $params, true);
        }
        $db = XenForo_Application::getDb();
        $counts = $db->fetchPairs('
			SELECT tag_content.tag_id, COUNT(*) AS tagged_count
			FROM `xf_tag_content` AS tag_content
			' . (!empty($forumIds) ? 'INNER JOIN `xf_thread` AS thread
				ON (thread.thread_id = tag_content.content_id)' : '') . '
			WHERE tag_content.content_type = "thread" AND tag_content.add_date > ?
				' . (!empty($forumIds) ? 'AND thread.node_id IN (' . $db->quote($forumIds) . ')' : '') . '
			GROUP BY tag_content.tag_id
			ORDER BY tagged_count DESC
			LIMIT ?;
		', array($cutoff, $limit));
        $tags = array();
        if (!empty($counts)) {
            $tagsDb = $tagModel->fetchAllKeyed('
                SELECT *
                FROM `xf_tag`
                WHERE tag_id IN (' . $db->quote(array_keys($counts)) . ')
            ', 'tag_id');
            foreach ($counts as $tagId => $count) {
                if (isset($tagsDb[$tagId])) {
                    $tags[$tagId] = $tagsDb[$tagId];
                    $tags[$tagId]['use_count'] = $count;
                }
            }
        }
        $tagsLevels = $tagModel->getTagCloudLevels($tags);
        $template->setParam('tags', $tags);
        $template->setParam('tagsLevels', $tagsLevels);
        return $template->render();
    }
Example #4
0
 public function rebuildIndex(XenForo_Search_Indexer $indexer, $lastId, $batchSize)
 {
     if (!Tinhte_XenTag_Option::xfrmFound()) {
         // XFRM is not installed/enabled
         // do not rebuild index
         return false;
     }
     $ids = $this->_getResourceModel()->getResourceIdsInRange($lastId, $batchSize);
     if (!$ids) {
         return false;
     }
     $this->quickIndex($indexer, $ids);
     return max($ids);
 }
Example #5
0
 protected function _postSaveAfterTransaction()
 {
     $response = parent::_postSaveAfterTransaction();
     if ($this->get('resource_state') == 'visible' and $this->get('description_update_id') > 0) {
         $contentData = array_merge(array('content_type' => 'resource_update', 'content_id' => $this->get('description_update_id')), $this->getMergedData(), $this->getDescriptionDw()->getMergedData());
         if (Tinhte_XenTag_Option::xfrmFound() >= 1010000) {
             // XenForo Resource Manager 1.1 introduces category permission
             $contentPermissionConfig = array('content_type' => 'resource_category', 'content_id' => $this->get('resource_category_id'), 'permissions' => array('view'));
         } else {
             $contentPermissionConfig = array();
         }
         Tinhte_XenTag_Integration::sendNotificationToWatchUsersOnTagged(Tinhte_XenTag_Constants::CONTENT_TYPE_RESOURCE, $this->get('resource_id'), $contentData, $this, $contentPermissionConfig);
     }
     return $response;
 }
Example #6
0
 public function render()
 {
     if ($this->_useGlobalTags) {
         $globalTags = $this->_getTagModel()->Tinhte_XenTag_getTagsFromCache();
         foreach ($globalTags as $tag) {
             $this->_tags[$tag['tag_id']] = $tag;
         }
     }
     if (!empty($this->_tags)) {
         $autoTagOptions = array('onceOnly' => Tinhte_XenTag_Option::get('autoTagOnceOnly'));
         return Tinhte_XenTag_Integration::autoTag($this->_html, $this->_tags, $autoTagOptions);
     } else {
         return $this->_html;
     }
 }
Example #7
0
    protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
    {
        $core = WidgetFramework_Core::getInstance();
        $tagModel = $core->getModelFromCache('Tinhte_XenTag_Model_Tag');
        if (!empty($widget['options']['days'])) {
            $days = $widget['options']['days'];
        } else {
            $days = Tinhte_XenTag_Option::get('trendingDays');
        }
        $cutoff = XenForo_Application::$time - $days * 86400;
        $createdCutoff = 0;
        if (!empty($widget['options']['created_days'])) {
            $createdCutoff = XenForo_Application::$time - $widget['options']['created_days'] * 86400;
        }
        if (!empty($widget['options']['limit'])) {
            $limit = $widget['options']['limit'];
        } else {
            $limit = Tinhte_XenTag_Option::get('trendingMax');
        }
        $forumIds = $this->_helperGetForumIdsFromOption($widget['options']['forums'], $params, true);
        $db = XenForo_Application::getDb();
        $taggedCount = $db->fetchPairs('
			SELECT tagged.tag_id, count(*) AS tagged_count
			FROM `xf_tinhte_xentag_tagged_content` AS tagged
			INNER JOIN `xf_thread` AS thread
				ON (thread.thread_id = tagged.content_id)
			' . ($createdCutoff > 0 ? 'INNER JOIN `xf_tinhte_xentag_tag` AS tag ON (tag.tag_id = tagged.tag_id AND tag.created_date > ' . $createdCutoff . ')' : '') . '
			WHERE tagged.content_type = "thread" AND tagged.tagged_date > ?
				' . (!empty($forumIds) ? 'AND thread.node_id IN (' . $db->quote($forumIds) . ')' : '') . '
			GROUP BY tagged.tag_id
			ORDER BY tagged_count DESC
			LIMIT ?;
		', array($cutoff, $limit));
        $tags = array();
        if (!empty($taggedCount)) {
            $tagsDb = $tagModel->getAllTag(array('tag_id' => array_keys($taggedCount)));
            foreach ($taggedCount as $tagId => $count) {
                if (isset($tagsDb[$tagId])) {
                    $tags[$tagId] = $tagsDb[$tagId];
                    $tags[$tagId]['tagged_count'] = $count;
                }
            }
        }
        $tagModel->calculateCloudLevel($tags);
        $template->setParam('tags', $tags);
        return $template->render();
    }
Example #8
0
 public function getPrioritizedContents()
 {
     $contents = array();
     $forums = intval(Tinhte_XenTag_Option::get('prioritizeForums'));
     if ($forums > 0) {
         $contents[Tinhte_XenTag_Constants::CONTENT_TYPE_FORUM] = $forums;
     }
     $pages = intval(Tinhte_XenTag_Option::get('prioritizePages'));
     if ($pages > 0) {
         $contents[Tinhte_XenTag_Constants::CONTENT_TYPE_PAGE] = $pages;
     }
     $resources = intval(Tinhte_XenTag_Option::get('prioritizeResources'));
     if ($resources > 0) {
         $contents[Tinhte_XenTag_Constants::CONTENT_TYPE_RESOURCE] = $resources;
     }
     return $contents;
 }
Example #9
0
 public function Tinhte_XenTag_actionTag($tagUrl, $tag)
 {
     if (empty($tag)) {
         return;
     }
     if (Tinhte_XenTag_Option::get('logView')) {
         /** @var Tinhte_XenTag_Model_TagView $tagViewModel */
         $tagViewModel = $this->getModelFromCache('Tinhte_XenTag_Model_TagView');
         $tagViewModel->logTagView($tag['tag_id']);
     }
     if ($this->_input->filterSingle('tag_url', XenForo_Input::STRING) !== $tagUrl || $this->_noRedirect()) {
         return;
     }
     if (!empty($tag['tinhte_xentag_url'])) {
         throw $this->responseException($this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL_PERMANENT, $tag['tinhte_xentag_url']));
     }
 }
Example #10
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;
     }
 }
Example #11
0
 public function actionIndex()
 {
     $model = $this->_getTagModel();
     $conditions = array();
     $fetchOptions = array('order' => 'tag_text');
     $page = $this->_input->filterSingle('page', XenForo_Input::UINT);
     $perPage = Tinhte_XenTag_Option::get('perPage');
     $fetchOptions['page'] = $page;
     $fetchOptions['limit'] = $perPage;
     $filter = $this->_input->filterSingle('_filter', XenForo_Input::ARRAY_SIMPLE);
     if ($filter && isset($filter['value'])) {
         $conditions['tag_text_like'] = array($filter['value'], empty($filter['prefix']) ? 'lr' : 'r');
         $filterView = true;
     } else {
         $filterView = false;
     }
     $total = $model->countAllTag($conditions, $fetchOptions);
     $tags = $model->getAllTag($conditions, $fetchOptions);
     $viewParams = array('tags' => $tags, 'page' => $page, 'perPage' => $perPage, 'total' => $total, 'filterView' => $filterView, 'filterMore' => $filterView && $total > $perPage);
     return $this->responseView('Tinhte_XenTag_ViewAdmin_Tag_List', 'tinhte_xentag_tag_list', $viewParams);
 }
Example #12
0
 protected function _render(array $widget, $positionCode, array $params, XenForo_Template_Abstract $template)
 {
     $core = WidgetFramework_Core::getInstance();
     /** @var Tinhte_XenTag_XenForo_Model_Tag $tagModel */
     $tagModel = $core->getModelFromCache('XenForo_Model_Tag');
     if (!empty($widget['options']['days'])) {
         $days = $widget['options']['days'];
     } else {
         $days = Tinhte_XenTag_Option::get('trendingDays');
     }
     $cutoff = XenForo_Application::$time - $days * 86400;
     if (!empty($widget['options']['limit'])) {
         $limit = $widget['options']['limit'];
     } else {
         $limit = Tinhte_XenTag_Option::get('trendingMax');
     }
     $tags = $tagModel->Tinhte_XenTag_getTrendingTags($cutoff, $limit);
     $tagsLevels = $tagModel->getTagCloudLevels($tags);
     $template->setParam('tags', $tags);
     $template->setParam('tagsLevels', $tagsLevels);
     return $template->render();
 }
Example #13
0
 public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
 {
     if (!empty($data)) {
         if (!is_array($data)) {
             $data = array('tag_text' => $data);
         }
         if (!empty($data['tag_text'])) {
             if (Tinhte_XenTag_Option::get('linkFormat') == Tinhte_XenTag_Option::LINK_FORMAT_BEAUTIFUL) {
                 // try to use the beautiful format
                 if (self::_isSafeText($data['tag_text'])) {
                     $encodedData = array('tag_text' => urlencode($data['tag_text']));
                     $action = XenForo_Link::getPageNumberAsAction($action, $extraParams);
                     return XenForo_Link::buildBasicLinkWithStringParam($outputPrefix, $action, $extension, $encodedData, 'tag_text');
                 }
             }
             // use the ugly format
             $extraParams[Tinhte_XenTag_Constants::URI_PARAM_TAG_TEXT] = $data['tag_text'];
             return XenForo_Link::buildBasicLink($outputPrefix, $action, $extension);
         }
     }
     return XenForo_Link::buildBasicLink($outputPrefix, $action, $extension);
 }
Example #14
0
 public function render()
 {
     if ($this->_useGlobalTags) {
         $globalTagsOrTexts = $this->_getTagModel()->getTagsOrTextsFromCache();
         $tagsOrTexts = array();
         foreach ($this->_tagsOrTexts as $tagOrText) {
             $tagText = Tinhte_XenTag_Helper::getTextFromTagOrText($tagOrText);
             $tagsOrTexts[Tinhte_XenTag_Helper::getNormalizedTagText($tagText)] = $tagOrText;
         }
         foreach ($globalTagsOrTexts as $globalTagOrText) {
             $globalTagText = Tinhte_XenTag_Helper::getTextFromTagOrText($globalTagOrText);
             $tagsOrTexts[Tinhte_XenTag_Helper::getNormalizedTagText($globalTagText)] = $globalTagOrText;
         }
         $this->_tagsOrTexts = $tagsOrTexts;
     }
     if (!empty($this->_tagsOrTexts)) {
         $autoTagOptions = array('onceOnly' => Tinhte_XenTag_Option::get('autoTagOnceOnly'));
         return Tinhte_XenTag_Integration::autoTag($this->_html, $this->_tagsOrTexts, $autoTagOptions);
     } else {
         return $this->_html;
     }
 }
Example #15
0
 protected function _setInternal($table, $field, $newValue, $forceSet = false)
 {
     if ($table === 'xf_post' && $field === 'message' && Tinhte_XenTag_Option::get('useHashtag')) {
         $tagTexts = Tinhte_XenTag_Integration::parseHashtags($newValue, true);
         if ($this->_tagger === null) {
             /** @var XenForo_Model_Tag $tagModel */
             $tagModel = $this->getModelFromCache('XenForo_Model_Tag');
             $this->_tagger = $tagModel->getTagger('post');
             if ($this->isUpdate()) {
                 $this->_tagger->setPermissionsFromContext($this->getDiscussionData(), $this->_Tinhte_XenTag_getForumInfo());
                 $this->_tagger->setContent($this->get('post_id'), false);
             } else {
                 $this->_tagger->setPermissionsFromContext($this->_Tinhte_XenTag_getForumInfo());
             }
         }
         $this->_tagger->setTags($tagTexts);
         $errors = $this->_tagger->getErrors();
         if (!empty($errors)) {
             $this->mergeErrors($errors);
         }
     }
     parent::_setInternal($table, $field, $newValue, $forceSet);
 }
Example #16
0
 protected function _verifyText(&$text)
 {
     $text = Tinhte_XenTag_Helper::getNormalizedTagText($text);
     $censored = XenForo_Helper_String::censorString($text);
     if ($censored !== $text) {
         $this->error(new XenForo_Phrase('tinhte_xentag_tag_no_contain_censored'), 'tag_text');
         return false;
     }
     if (Tinhte_XenTag_Helper::isTagContainingSeparator($text)) {
         $this->error(new XenForo_Phrase('tinhte_xentag_tag_can_not_contain_comma'), 'tag_text');
         return false;
     }
     $textLength = utf8_strlen($text);
     if ($textLength < Tinhte_XenTag_Option::get('tagMinLength')) {
         $this->error(new XenForo_Phrase('tinhte_xentag_tag_must_be_at_least_x_length', array('minLength' => Tinhte_XenTag_Option::get('tagMinLength'))), 'tag_text');
         return false;
     }
     if ($textLength > Tinhte_XenTag_Option::get('tagMaxLength')) {
         $this->error(new XenForo_Phrase('tinhte_xentag_tag_can_not_longer_than_x', array('maxLength' => Tinhte_XenTag_Option::get('tagMaxLength'))), 'tag_text');
         return false;
     }
     return true;
 }
Example #17
0
 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;
     }
 }
Example #18
0
 public function Tinhte_XenTag_actionTags(XenForo_DataWriter_Discussion_Thread $threadDw)
 {
     if (Tinhte_XenTag_Option::get('modLog')) {
         $this->_updateModeratorLogThreadEdit($threadDw->getMergedExistingData(), $threadDw);
     }
 }
Example #19
0
 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;
 }
Example #20
0
 protected function _doSearch($tagText)
 {
     $visitorUserId = XenForo_Visitor::getUserId();
     /* @var $searchModel XenForo_Model_Search */
     $searchModel = $this->getModelFromCache('XenForo_Model_Search');
     /* @var $tagSearchModel Tinhte_XenTag_Model_Search */
     $tagSearchModel = $this->getModelFromCache('Tinhte_XenTag_Model_Search');
     $input = array('type' => Tinhte_XenTag_Constants::SEARCH_TYPE_TAG, 'keywords' => '', Tinhte_XenTag_Constants::SEARCH_INPUT_TAGS => $tagText, 'order' => 'date', 'group_discussion' => 0);
     $constraints = $searchModel->getGeneralConstraintsFromInput($input, $errors);
     if ($errors) {
         return $this->responseError($errors);
     }
     $forceRefresh = $this->_input->filterSingle('force_refresh', XenForo_Input::UINT) > 0;
     if ($forceRefresh) {
         if (XenForo_Visitor::getInstance()->get('isTrusted')) {
             // good, this is a trusted user (admin or mod)
         } else {
             // do not accept force refresh request from not-trusted users
             $forceRefresh = false;
         }
     }
     if ($forceRefresh == false) {
         // force to use cache to have a nice and clean url
         $search = $searchModel->getExistingSearch($input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], $visitorUserId, Tinhte_XenTag_Option::get('searchForceUseCache'));
     } else {
         // skip getting existing results, this will cause a real search to be made
         $search = false;
     }
     if (empty($search)) {
         $searcher = new XenForo_Search_Searcher($searchModel);
         $typeHandler = XenForo_Search_DataHandler_Abstract::create('Tinhte_XenTag_Search_DataHandler_General');
         $results = $searcher->searchType($typeHandler, $input['keywords'], $constraints, $input['order']);
         if (empty($results)) {
             return $this->_getNoResultsResponse($tagText);
         } else {
             $tagSearchModel->prioritizeResults($results, $searcher, $input['keywords'], $constraints, $input['order']);
         }
         $warnings = $searcher->getErrors() + $searcher->getWarnings();
         $search = $searchModel->insertSearch($results, $input['type'], $input['keywords'], $constraints, $input['order'], $input['group_discussion'], array(), $warnings, $visitorUserId);
     }
     return $search;
 }
Example #21
0
 public function Tinhte_XenTag_getTrendingFromCache()
 {
     $cache = $this->_getDataRegistryModel()->get(Tinhte_XenTag_Constants::DATA_REGISTRY_KEY_TRENDING);
     if (!isset($cache['version']) || $cache['version'] < Tinhte_XenTag_Constants::DATA_REGISTRY_TRENDING_VERSION || !isset($cache['time']) || XenForo_Application::$time - $cache['time'] > Tinhte_XenTag_Option::get('trendingTtl') * 86400) {
         // cache not found or expired
         $tags = $this->Tinhte_XenTag_rebuildTrendingCache();
     } else {
         $tags = $cache['tags'];
     }
     return $tags;
 }
Example #22
0
 public static function getSafeTagTextForSearch($tagText)
 {
     switch (Tinhte_XenTag_Option::get('searchIndexType')) {
         case 'plaintext':
             return self::getNormalizedTagText($tagText);
         case 'md5':
             return md5(self::getNormalizedTagText($tagText));
         default:
             return sprintf('_%s_', md5(self::getNormalizedTagText($tagText)));
     }
 }
Example #23
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();
         }
     }
 }
Example #24
0
 public static function template_hook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
 {
     switch ($hookName) {
         case 'admin_forum_edit_tabs':
         case 'admin_forum_edit_panes':
         case 'admin_page_edit_basic_information':
         case 'message_below':
         case 'message_content':
         case 'message_notices':
         case 'navigation_tabs_forums':
         case 'pagenode_container_article':
         case 'post_private_controls':
         case 'post_public_controls':
         case 'resource_view_sidebar_resource_info':
         case 'thread_view_pagenav_before':
         case 'thread_view_form_before':
         case 'thread_view_qr_before':
         case 'thread_view_qr_after':
             $ourTemplate = $template->create(substr('tinhte_xentag_hook_' . $hookName, 0, 50), $template->getParams());
             $ourTemplate->setParams($hookParams);
             $rendered = $ourTemplate->render();
             self::injectRendered($contents, $rendered);
             break;
     }
     if ($hookName == 'tinhte_xentag_tag_cloud_item') {
         // our special hook to populate data to the sidebar
         // doing this will make it super-easy to use the sidebar template
         // just put the include statement in the target page and you are done!
         // <xen:include template="tinhte_xentag_sidebar_cloud" />
         // supported parameters:
         // - max: maximum number of links
         $tagModel = XenForo_Model::create('Tinhte_XenTag_Model_Tag');
         $conditions = array();
         $fetchOptions = array('order' => 'content_count', 'direction' => 'desc', 'limit' => isset($hookParams['max']) ? $hookParams['max'] : Tinhte_XenTag_Option::get('cloudMax'));
         $tags = $tagModel->getAllTag($conditions, $fetchOptions);
         $tagModel->calculateCloudLevel($tags);
         $results = '';
         foreach ($tags as $tag) {
             if (empty($tag['content_count'])) {
                 continue;
             }
             $search = array('{TAG_TEXT}', '{TAG_LINK}', '{TAG_CONTENT_COUNT}', '{TAG_LEVEL}');
             $replace = array(htmlspecialchars($tag['tag_text']), XenForo_Link::buildPublicLink('tags', $tag), XenForo_Template_Helper_Core::numberFormat($tag['content_count']), $tag['cloudLevel']);
             $results .= str_replace($search, $replace, $contents);
         }
         $contents = $results;
     }
 }
Example #25
0
 public function Tinhte_XenTag_getContentTagCacheOnSave(XenForo_Model_Tag $model, array $cache)
 {
     if (!Tinhte_XenTag_Option::get('keepOrder') || empty($this->_Tinhte_XenTag_orderedTags)) {
         return $cache;
     }
     $cacheOrdered = $model->getFoundTagsInList($this->_Tinhte_XenTag_orderedTags, $cache);
     foreach ($cache as $tagId => $tag) {
         if (!isset($cacheOrdered[$tagId])) {
             $cacheOrdered[$tagId] = $tag;
         }
     }
     return $cacheOrdered;
 }
Example #26
0
 public function filterString($string, array $rendererStates)
 {
     $isString = true;
     if (is_array($string)) {
         // array is our way of marking tag originals prepend/append text
         $isString = false;
         $string = reset($string);
     }
     if ($isString) {
         // checks if the string is an URI of some kind
         $isString = !Zend_Uri::check($string);
     }
     if ($isString) {
         // checks if the parent tag has some strange requirements
         $tagDataStack = $rendererStates['tagDataStack'];
         $lastTagDataStack = array_pop($tagDataStack);
         if ($lastTagDataStack['tag'] === 'hashtag') {
             // well, this is a hashtag already...
             $isString = false;
         } else {
             $parentTagInfo = $this->_parent__getTagRule($lastTagDataStack['tag']);
             if (!empty($parentTagInfo['plainChildren'])) {
                 // parent tag asks for plain children, we should do nothing
                 $isString = false;
             } elseif (!empty($parentTagInfo['stopSmilies']) or !empty($parentTagInfo['stopLineBreakConversion'])) {
                 // parent tag asks for some functionalities disabled, we should disable ourself
                 // too
                 $isString = false;
             }
         }
     }
     if ($isString) {
         $offset = 0;
         while (true) {
             $pos = utf8_strpos($string, '#', $offset);
             if ($pos === false) {
                 break;
             }
             $offset = $pos + 1;
             if ($pos > 0) {
                 $beforeTagText = utf8_substr($string, $pos - 1, 1);
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $beforeTagText)) {
                     // the before character of tag text is not a valid character, dismiss the found
                     // tag text
                     continue;
                 }
             }
             $stringForPregMatch = utf8_substr($string, $pos + 1);
             if (preg_match('/[^a-zA-Z0-9]/', $stringForPregMatch, $matches, PREG_OFFSET_CAPTURE)) {
                 $nonTagTextPos = $matches[0][1];
             } else {
                 // get all of the remaining characters
                 $nonTagTextPos = utf8_strlen($stringForPregMatch);
             }
             $nonTagTextPos += $pos + 1;
             $tagText = utf8_trim(utf8_substr($string, $pos + 1, $nonTagTextPos - 1 - $pos));
             if (utf8_strlen($tagText) < Tinhte_XenTag_Option::get('tagMinLength')) {
                 // too short
                 continue;
             }
             $afterTagText = utf8_substr($string, $nonTagTextPos, 1);
             if (!empty($afterTagText)) {
                 if (!preg_match(Tinhte_XenTag_Integration::REGEX_VALID_CHARACTER_AROUND, $afterTagText)) {
                     // the after character of tag text is not a valid character, dismiss the found
                     // tag text
                     $tagText = '';
                 }
             }
             if (!empty($tagText)) {
                 $this->_Tinhte_XenTag_autoHashtagTexts[Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText)] = $tagText;
                 // add bb code wrapping
                 $replacement = sprintf('[HASHTAG]#%s[/HASHTAG]', $tagText);
                 $string = utf8_substr_replace($string, $replacement, $pos, $nonTagTextPos - $pos);
                 $pos += utf8_strlen($replacement) - 1;
             }
             $offset = $pos + 1;
         }
     }
     return parent::filterString($string, $rendererStates);
 }
Example #27
0
 public function calculateCloudLevel(array &$tags)
 {
     $levelCount = Tinhte_XenTag_Option::get('cloudLevelCount');
     // sort by content count
     uasort($tags, create_function('$tag1, $tag2', 'return $tag1["content_count"] > $tag2["content_count"] ? 1 : -1;'));
     $i = 0;
     $levelEach = ceil(count($tags) / $levelCount);
     foreach ($tags as &$tag) {
         for ($j = 1; $j <= $levelCount; $j++) {
             if ($i < $j * $levelEach) {
                 $tag['cloudLevel'] = $j;
                 break;
             }
         }
         $i++;
     }
     // sort by tag text
     uasort($tags, create_function('$tag1, $tag2', 'return strcmp($tag1["tag_text"], $tag2["tag_text"]);'));
 }