protected static function _autoTag_isBetweenHtmlTags($html, $position) { $htmlLength = utf8_strlen($html); // look for <a> and </a> $aBefore = Tinhte_XenTag_Helper::utf8_strripos($html, '<a', $position - $htmlLength); if ($aBefore !== false) { $aAfter = Tinhte_XenTag_Helper::utf8_stripos($html, '</a>', $aBefore); if ($aAfter > $position) { // too bad, this position is between <a> and </a> return true; } } // now that we are not inside <a /> // we have to make sure we are not in the middle of any tag $symbolBefore = Tinhte_XenTag_Helper::utf8_strrpos($html, '<', $position - $htmlLength); if ($symbolBefore !== false) { $symbolAfter = utf8_strpos($html, '>', $symbolBefore); if ($symbolAfter > $position) { // now this is extremly bad, get out of here now! return true; } } return false; }
protected function _filterHashtagsFromMessage($message) { $bbCodeOpen = '[HASHTAG]'; $bbCodeClose = '[/HASHTAG]'; $dbTags = $this->getModelFromCache('Tinhte_XenTag_Model_Tag')->getTagsOfContent('post', $this->get('post_id')); $dbTagTexts = Tinhte_XenTag_Helper::getTextsFromTagsOrTexts($dbTags); $dbSafeTags = Tinhte_XenTag_Helper::getSafeTagsTextArrayForSearch($dbTagTexts); $offset = 0; while (true) { $posOpen = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeOpen, $offset); if ($posOpen === false) { break; } $posClose = Tinhte_XenTag_Helper::utf8_stripos($message, $bbCodeClose, $posOpen); if ($posClose === false) { break; } $offset = $posOpen + 1; $posTagTextOffset = $posOpen + utf8_strlen($bbCodeOpen) + 1; $posTagTextLength = $posClose - $posTagTextOffset; $posTagText = utf8_substr($message, $posTagTextOffset, $posTagTextLength); $posSafeTag = Tinhte_XenTag_Helper::getSafeTagTextForSearch($posTagText); if (!in_array($posSafeTag, $dbSafeTags)) { $message = utf8_substr_replace($message, '#' . $posTagText, $posOpen, $posClose + utf8_strlen($bbCodeClose) - $posOpen); } } return $message; }