Beispiel #1
0
 public function processConstraint(XenForo_Search_SourceHandler_Abstract $sourceHandler, $constraint, $constraintInfo, array $constraints)
 {
     $result = Tinhte_XenTag_Integration::processConstraint($sourceHandler, $constraint, $constraintInfo, $constraints);
     if ($result !== false) {
         return $result;
     }
     return parent::processConstraint($sourceHandler, $constraint, $constraintInfo, $constraints);
 }
 public function sendNotificationToWatchUsersOnMessage(array $post, array $thread = null, array $noAlerts = array(), array $noEmail = array())
 {
     $result = parent::sendNotificationToWatchUsersOnMessage($post, $thread, $noAlerts, $noEmail);
     Tinhte_XenTag_Integration::updateNoEmailAndAlert('post', $post['post_id'], $noEmail, $noAlerts);
     $emailed = array();
     if (!empty($result['emailed'])) {
         $emailed = $result['emailed'];
     }
     $alerted = array();
     if (!empty($result['alerted'])) {
         $alerted = $result['alerted'];
     }
     Tinhte_XenTag_Integration::updateNoEmailAndAlert('post', $post['post_id'], $emailed, $alerted);
     return $result;
 }
 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;
     }
 }
Beispiel #4
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;
     }
 }
Beispiel #5
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);
 }
Beispiel #6
0
 protected function _postDelete()
 {
     Tinhte_XenTag_Integration::deleteTags(Tinhte_XenTag_Constants::CONTENT_TYPE_PAGE, $this->get('node_id'), $this);
     $this->_Tinhte_XenTag_unindexFromSearch();
     return parent::_postDelete();
 }
Beispiel #7
0
 public function sendNotificationToWatchUsersOnTagged($tag, array $contentData = array(), array $contentPermissionConfig = array())
 {
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     list($noEmail, $noAlert) = Tinhte_XenTag_Integration::getNoEmailAndAlert($contentData['content_type'], $contentData['content_id']);
     $emailed = array();
     $alerted = array();
     $emailTemplate = 'tinhte_xentag_watch_tag_' . $contentData['content_type'];
     if (XenForo_Application::get('options')->emailWatchedThreadIncludeMessage) {
         $parseBbCode = true;
     } else {
         $parseBbCode = false;
     }
     // fetch a full user record if we don't have one already
     if (!isset($contentData['avatar_width']) or !isset($contentData['custom_title'])) {
         $contentUser = $userModel->getUserById($contentData['user_id']);
         if ($contentUser) {
             $contentData = array_merge($contentUser, $contentData);
         } else {
             $contentData['avatar_width'] = 0;
             $contentData['custom_title'] = '';
         }
     }
     if (!empty($contentPermissionConfig['content_type']) and !empty($contentPermissionConfig['content_id'])) {
         $users = $this->getUsersWatchingTag($tag['tag_id'], $contentPermissionConfig['content_type'], $contentPermissionConfig['content_id']);
     } else {
         $users = $this->getUsersWatchingTag($tag['tag_id']);
     }
     foreach ($users as $user) {
         if ($user['user_id'] == $contentData['user_id']) {
             // self notification? That's silly
             continue;
         }
         if ($userModel->isUserIgnored($user, $contentData['user_id'])) {
             continue;
         }
         $globalPermissions = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
         if (!XenForo_Permission::hasPermission($globalPermissions, 'general', Tinhte_XenTag_Constants::PERM_USER_WATCH)) {
             // no tag watch permission (or revoked)
             continue;
         }
         if (!empty($contentPermissionConfig['content_type']) and !empty($contentPermissionConfig['content_id']) and !empty($contentPermissionConfig['permissions'])) {
             $contentPermissions = XenForo_Permission::unserializePermissions($user['content_permission_cache']);
             $contentPermissionFound = true;
             foreach ($contentPermissionConfig['permissions'] as $contentPermissionRequired) {
                 if (!XenForo_Permission::hasContentPermission($contentPermissions, $contentPermissionRequired)) {
                     $contentPermissionFound = false;
                 }
             }
             if (!$contentPermissionFound) {
                 // no content permission
                 continue;
             }
         }
         if ($user['send_email'] and $user['email'] and $user['user_state'] == 'valid' and !in_array($user['user_id'], $noEmail)) {
             if (!empty($contentData['message']) and !isset($contentData['messageText']) and $parseBbCode) {
                 $bbCodeParserText = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Text'));
                 $contentData['messageText'] = new XenForo_BbCode_TextWrapper($contentData['message'], $bbCodeParserText);
                 $bbCodeParserHtml = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
                 $contentData['messageHtml'] = new XenForo_BbCode_TextWrapper($contentData['message'], $bbCodeParserHtml);
             }
             if (!empty($contentData['title']) and !isset($contentData['titleCensored'])) {
                 $contentData['titleCensored'] = XenForo_Helper_String::censorString($contentData['title']);
             }
             $user['email_confirm_key'] = $userModel->getUserEmailConfirmKey($user);
             $mail = XenForo_Mail::create($emailTemplate, array('tag' => $tag, 'contentType' => $contentData['content_type'], 'contentId' => $contentData['content_id'], 'contentData' => $contentData, 'receiver' => $user), $user['language_id']);
             $mail->enableAllLanguagePreCache();
             $mail->queue($user['email'], $user['username']);
             $emailed[] = $user['user_id'];
         }
         if ($user['send_alert'] and !in_array($user['user_id'], $noAlert)) {
             call_user_func_array(array('XenForo_Model_Alert', 'alert'), array($user['user_id'], $contentData['user_id'], $contentData['username'], $contentData['content_type'], $contentData['content_id'], 'tinhte_xentag_tag_watch', array('tag' => $tag)));
             $alerted[] = $user['user_id'];
         }
     }
     Tinhte_XenTag_Integration::updateNoEmailAndAlert($contentData['content_type'], $contentData['content_id'], $emailed, $alerted);
 }
Beispiel #8
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;
 }