コード例 #1
0
ファイル: HashtagPick.php プロジェクト: Sywooch/forums
 public function renderTagHashtag(array $tag, array $rendererStates)
 {
     $tagText = $this->stringifyTree($tag['children']);
     if (substr($tagText, 0, 1) === '#') {
         $tagText = substr($tagText, 1);
     }
     $this->_Tinhte_XenTag_tagTexts[Tinhte_XenTag_Helper::getSafeTagTextForSearch($tagText)] = $tagText;
     return $this->renderTagUnparsed($tag, $rendererStates);
 }
コード例 #2
0
ファイル: AutoHashtag.php プロジェクト: Sywooch/forums
 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);
 }
コード例 #3
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;
 }