Exemple #1
0
 /**
  * Default, empty string filterer.
  *
  * @see XenForo_BbCode_Formatter_Base::filterString()
  */
 public function filterString($string, array $rendererStates)
 {
     if ($this->_censorString) {
         $string = XenForo_Helper_String::censorString($string);
     }
     return $string;
 }
Exemple #2
0
 public function renderTagCode(array $tag, array $rendererStates)
 {
     if (strtolower(strval($tag['option'])) == 'html') {
         $tag['option'] = 'html5';
     }
     if (!$tag['option']) {
         $tag['option'] = 'text';
     }
     $content = $this->stringifyTree($tag['children']);
     $content = XenForo_Helper_String::censorString($content);
     $geshi = new GeSHi($content, $tag['option']);
     if (XenForo_Application::get('options')->get('dpSyntaxHighlighterShowLines')) {
         $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
     }
     $geshi->set_link_target('_blank" rel="nofollow');
     $geshi->set_header_type(GESHI_HEADER_NONE);
     $geshi->set_tab_width(4);
     $content = $geshi->parse_code();
     if ($this->_view) {
         $template = $this->_view->createTemplateObject('dp_bb_code_tag_code', array('content' => $content, 'language' => $geshi->get_language_name()));
         return $template->render();
     } else {
         return '<div style="margin: 1em auto" title="Code">' . $content . '</div>';
     }
 }
Exemple #3
0
 public function prepareCollection(array $collection, $viewingUser = null)
 {
     $this->standardizeViewingUserReference($viewingUser);
     if (!empty($collection)) {
         $collection['title'] = XenForo_Helper_String::censorString($collection['title']);
         $collection['description'] = XenForo_Helper_String::censorString($collection['description']);
     }
     return $collection;
 }
Exemple #4
0
 /**
  * Fetches the content required by alerts.
  *
  * @param array $contentIds
  * @param XenForo_Model_Alert $model Alert model invoking this
  * @param integer $userId User ID the alerts are for
  * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
 {
     $updateModel = $this->_getUpdateModel();
     $updates = $updateModel->getUpdatesByIds($contentIds, array('join' => XenResource_Model_Update::FETCH_RESOURCE | XenResource_Model_Update::FETCH_CATEGORY, 'permissionCombinationId' => $viewingUser['permission_combination_id']));
     foreach ($updates as &$update) {
         $update['resource_title'] = XenForo_Helper_String::censorString($update['resource_title']);
         $update['title'] = XenForo_Helper_String::censorString($update['title']);
     }
     return $updates;
 }
 /**
  * Prepares the news feed item for display
  *
  * @param array $item News feed item
  * @param array $content News feed item content
  * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 protected function _prepareNewsFeedItemAfterAction(array $item, $content, array $viewingUser)
 {
     $item['content'] = array('title' => XenForo_Helper_String::censorString($content['title']));
     foreach ($this->_getContentPrimaryKeynames() as $key) {
         if (isset($content[$key])) {
             $item['content'][$key] = $content[$key];
         }
     }
     return $item;
 }
Exemple #6
0
 /**
  * Prepares the news feed item for display
  *
  * @param array $item News feed item
  * @param array $content News feed item content
  * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 protected function _prepareNewsFeedItemAfterAction(array $item, $content, array $viewingUser)
 {
     if (isset($item[$item['action']]['old'])) {
         $item[$item['action']]['old'] = XenForo_Helper_String::censorString($item[$item['action']]['old']);
     }
     if (isset($item[$item['action']]['new'])) {
         $item[$item['action']]['new'] = XenForo_Helper_String::censorString($item[$item['action']]['new']);
     }
     return $item;
 }
 /**
  * Gets the title of the specified content.
  *
  * @see XenForo_ReportHandler_Abstract:getContentTitle()
  */
 public function getContentTitle(array $report, array $contentInfo)
 {
     if (!empty($contentInfo['media']['album_id']) && isset($contentInfo['media']['album_title'])) {
         return new XenForo_Phrase('xengallery_media_x_in_album_y', array('title' => XenForo_Helper_String::censorString($contentInfo['media']['media_title']), 'album' => $contentInfo['media']['album_title']));
     } else {
         if (!empty($contentInfo['media']['category_id']) && isset($contentInfo['media']['category_title'])) {
             return new XenForo_Phrase('xengallery_media_x_in_category_y', array('title' => XenForo_Helper_String::censorString($contentInfo['media']['media_title']), 'category' => $contentInfo['media']['category_title']));
         }
     }
     return new XenForo_Phrase('xengallery_media');
 }
Exemple #8
0
 /**
  * Prepares a news feed item for rendering.
  * Designed to be overriden by extended classes, while retaining the call to _prepareAlert.
  *
  * @param array $alert
  * @param array $viewingUser Information about the viewing user (keys: user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 public function prepareAlert(array $item, array $viewingUser)
 {
     $methodName = '_prepare' . ucfirst($item['action']);
     $item = $this->_prepareAlertBeforeAction($item, $item['content'], $viewingUser);
     if (isset($item['content']['title'])) {
         $item['content']['title'] = XenForo_Helper_String::censorString($item['content']['title']);
     }
     if (method_exists($this, $methodName)) {
         $item = call_user_func(array($this, $methodName), $item, $viewingUser);
     }
     return $this->_prepareAlertAfterAction($item, $item['content'], $viewingUser);
 }
Exemple #9
0
 public final function prepareEntry(array $entry)
 {
     $entry['content_title'] = XenForo_Helper_String::censorString($entry['content_title']);
     $entry['ipAddress'] = $entry['ip_address'] ? XenForo_Helper_Ip::convertIpBinaryToString($entry['ip_address']) : '';
     $entry = $this->_prepareEntry($entry);
     if (!isset($entry['actionText'])) {
         $entry['actionText'] = new XenForo_Phrase('moderator_log_' . $entry['content_type'] . '_' . $entry['action'], json_decode($entry['action_params'], true));
     }
     if (!isset($entry['contentUser'])) {
         $entry['contentUser'] = array('user_id' => $entry['content_user_id'], 'username' => $entry['content_username']);
     }
     return $entry;
 }
 public function processTagImg(array $tag, array $rendererStates)
 {
     $url = $this->stringifyTree($tag['children']);
     $validUrl = $this->_getValidUrl($url);
     if (!$validUrl) {
         return $this->filterString($url, $rendererStates);
     }
     $censored = XenForo_Helper_String::censorString($validUrl);
     if ($censored != $validUrl) {
         return $this->filterString($url, $rendererStates);
     }
     $this->_urls[$url] = $validUrl;
     return '[IMG]' . $this->_urlPrefix . $url . $this->_urlSuffix . '[/IMG]';
 }
Exemple #11
0
 /**
  * Gets the HTML value of the resource field.
  *
  * @param array $field
  * @param mixed $value Value of the field; if null, pulls from field_value
  *        in field
  */
 public static function getResourceFieldValueHtml(XenForo_View $view, array $field, $value = null)
 {
     if ($value === null && isset($field['field_value'])) {
         $value = $field['field_value'];
     }
     if ($value === '' || $value === null) {
         return '';
     }
     $multiChoice = false;
     $choice = '';
     switch ($field['field_type']) {
         case 'radio':
         case 'select':
             $choice = $value;
             $value = new XenForo_Phrase("resource_field_{$field['field_id']}_choice_{$value}");
             $value->setPhraseNameOnInvalid(false);
             break;
         case 'checkbox':
         case 'multiselect':
             $multiChoice = true;
             if (!is_array($value) || count($value) == 0) {
                 return '';
             }
             $newValues = array();
             foreach ($value as $id => $choice) {
                 $phrase = new XenForo_Phrase("resource_field_{$field['field_id']}_choice_{$choice}");
                 $phrase->setPhraseNameOnInvalid(false);
                 $newValues[$choice] = $phrase;
             }
             $value = $newValues;
             break;
         case 'textbox':
         case 'textarea':
         default:
             $value = nl2br(htmlspecialchars(XenForo_Helper_String::censorString($value)));
     }
     if (!empty($field['display_callback_class']) && !empty($field['display_callback_method'])) {
         $value = call_user_func_array(array($field['display_callback_class'], $field['display_callback_method']), array($view, $field, $value));
     } elseif (!empty($field['display_template'])) {
         if ($multiChoice && is_array($value)) {
             foreach ($value as $choice => &$thisValue) {
                 $thisValue = strtr($field['display_template'], array('{$fieldId}' => $field['field_id'], '{$value}' => $thisValue, '{$valueUrl}' => urlencode($thisValue), '{$choice}' => $choice));
             }
         } else {
             $value = strtr($field['display_template'], array('{$fieldId}' => $field['field_id'], '{$value}' => $value, '{$valueUrl}' => urlencode($value), '{$choice}' => $choice));
         }
     }
     return $value;
 }
Exemple #12
0
 public function bretiPrepareThread(array $thread, array $nodePermissions = null, array $viewingUser = null)
 {
     $forum = array('node_id' => $thread['node_id']);
     if (isset($thread['node_title'])) {
         $forum['title'] = $thread['node_title'];
         $thread['forum'] = $forum;
     }
     $thread['title'] = XenForo_Helper_String::censorString($thread['title']);
     $thread['titleCensored'] = true;
     $options = XenForo_Application::get('options');
     if ($options->BRETI_showPreview) {
         $thread['hasPreview'] = $this->hasPreview($thread, $forum, $nodePermissions, $viewingUser);
     }
     return $thread;
 }
 /**
  * Fetches the content required by alerts.
  *
  * @param array $contentIds
  * @param XenForo_Model_Alert $model Alert model invoking this
  * @param integer $userId User ID the alerts are for
  * @param array $viewingUser Information about the viewing user (keys:
  * user_id, permission_combination_id, permissions)
  *
  * @return array
  */
 public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
 {
     $checkOutModel = $this->_getCheckOutModel();
     $checkOuts = $checkOutModel->getCheckOutsByIds($contentIds);
     $resourceIds = array();
     foreach ($checkOuts as $checkOut) {
         $resourceIds[$checkOut['resource_id']] = $checkOut['resource_id'];
     }
     $resources = XenForo_Model::create('XenResource_Model_Resource')->getResourcesByIds($resourceIds, array('permissionCombinationId' => $viewingUser['permission_combination_id']));
     foreach ($checkOuts as $key => &$checkOut) {
         if (!isset($resources[$checkOut['resource_id']])) {
             unset($checkOuts[$key]);
         } else {
             $checkOut['resource'] = $resources[$checkOut['resource_id']];
             $checkOut['resource']['title'] = XenForo_Helper_String::censorString($checkOut['resource']['title']);
         }
     }
     return $checkOuts;
 }
Exemple #14
0
 public static function getPlainText($bbCode)
 {
     $config = XenForo_Application::getConfig();
     $useSnippet = $config->get('bdApi_useSnippet');
     if (!empty($useSnippet)) {
         return XenForo_Template_Helper_Core::callHelper('snippet', array($bbCode, 0, array('stripQuote' => true, 'stripHtml' => false)));
     } else {
         // from XenForo_Helper_String::bbCodeStrip
         $string = $bbCode;
         $string = preg_replace('#\\[(attach|media|img)[^\\]]*\\].*\\[/\\1\\]#siU', '', $string);
         while ($string != ($newString = preg_replace('#\\[([a-z0-9]+)(=[^\\]]*)?\\](.*)\\[/\\1\\]#siU', '\\3', $string))) {
             $string = $newString;
         }
         $string = str_replace('[*]', '', $string);
         $string = trim($string);
         $string = XenForo_Helper_String::censorString($string);
         return htmlspecialchars($string);
     }
 }
Exemple #15
0
 public function isValidTag($tag)
 {
     $length = utf8_strlen($tag);
     $lengthLimits = XenForo_Application::getOptions()->tagLength;
     $minLength = max($lengthLimits['min'], 1);
     $maxLength = $lengthLimits['max'] <= 0 ? 100 : min($lengthLimits['max'], 100);
     if ($length < $minLength) {
         return false;
     }
     if ($length > $maxLength) {
         return false;
     }
     $validation = XenForo_Application::getOptions()->tagValidation;
     $disallowed = preg_split('/\\r?\\n/', $validation['disallowedWords']);
     if ($disallowed) {
         foreach ($disallowed as $disallowedCheck) {
             $disallowedCheck = trim($disallowedCheck);
             if ($disallowedCheck === '') {
                 continue;
             }
             if (stripos($tag, $disallowedCheck) !== false) {
                 return false;
             }
         }
     }
     if ($validation['matchRegex'] && !preg_match('/\\W[\\s\\w]*e[\\s\\w]*$/', $validation['matchRegex'])) {
         try {
             if (!preg_match($validation['matchRegex'], $tag)) {
                 return false;
             }
         } catch (Exception $e) {
             XenForo_Error::logException($e, false);
         }
     }
     $censored = XenForo_Helper_String::censorString($tag);
     if ($censored != $tag) {
         return false;
     }
     return true;
 }
Exemple #16
0
 public function renderTagUrl(array $tag, array $rendererStates)
 {
     if (!empty($tag['option'])) {
         $url = $tag['option'];
         $text = $this->renderSubTree($tag['children'], $rendererStates);
     } else {
         $url = $this->stringifyTree($tag['children']);
         $text = urldecode($url);
         if (!preg_match('/./u', $text)) {
             $text = $url;
         }
         $text = XenForo_Helper_String::censorString($text);
         if (!empty($rendererStates['shortenUrl'])) {
             $length = utf8_strlen($text);
             if ($length > 100) {
                 $text = utf8_substr_replace($text, '...', 35, $length - 35 - 45);
             }
         }
         $text = htmlspecialchars($text);
     }
     $url = $this->_getValidUrl($url);
     if (!$url) {
         return $text;
     } else {
         list($class, $target, $type) = XenForo_Helper_String::getLinkClassTarget($url);
         $class = $class ? " class=\"{$class}\"" : '';
         $target = $target ? " target=\"{$target}\"" : '';
         if ($type == 'internal') {
             $noFollow = '';
         } else {
             $noFollow = empty($rendererStates['noFollowDefault']) ? '' : ' rel="nofollow"';
         }
         $url = XenForo_Helper_String::censorString($url);
         $test = $this->isImage($url);
         if ($test) {
             return sprintf($this->_imageTemplate, htmlspecialchars($url), $rendererStates['lightBox'] ? ' LbImage' : '');
         }
         return $this->_wrapInHtml('<a href="' . htmlspecialchars($url) . '"' . $target . $class . $noFollow . '>', '</a>', $text);
     }
 }
Exemple #17
0
 public function modernStatisticPrepareThread(array $thread, $modernStatistic, array $nodePermissions = null, array $viewingUser = null)
 {
     $thread['lastPostInfo'] = array('post_date' => $thread['last_post_date'], 'post_id' => $thread['last_post_id'], 'user_id' => $thread['last_post_user_id'], 'username' => $thread['last_post_username']);
     $forum = array('node_id' => $thread['node_id']);
     if (isset($thread['node_title'])) {
         $forum['title'] = $thread['node_title'];
         $thread['forum'] = $forum;
     }
     if ($thread['view_count'] <= $thread['reply_count']) {
         $thread['view_count'] = $thread['reply_count'] + 1;
     }
     $thread['title'] = XenForo_Helper_String::censorString($thread['title']);
     $thread['titleCensored'] = true;
     //$thread['lastPageNumbers'] = $this->getLastPageNumbers($thread['reply_count']);
     if (empty($thread['user_group_id'])) {
         $thread['display_style_group_id'] = XenForo_Model_User::$defaultGuestGroupId;
     }
     if (!empty($thread['user_group_id'])) {
         $thread['lastPostInfo']['user_group_id'] = $thread['user_group_id'];
     }
     if (!empty($thread['display_style_group_id'])) {
         $thread['lastPostInfo']['display_style_group_id'] = $thread['display_style_group_id'];
     }
     if (!empty($thread['is_banned'])) {
         $thread['lastPostInfo']['is_banned'] = $thread['is_banned'];
     }
     $options = XenForo_Application::get('options');
     if ($modernStatistic['preview_tooltip'] == 'thread_preview') {
         $thread['hasPreview'] = $this->hasPreview($thread, $forum, $nodePermissions, $viewingUser);
     }
     $thread['isNew'] = $this->isNew($thread, $forum);
     if ($thread['isNew']) {
         $readDate = $this->getMaxThreadReadDate($thread, $forum);
         $thread['haveReadData'] = $readDate > XenForo_Application::$time - $options->readMarkingDataLifetime * 86400;
     } else {
         $thread['haveReadData'] = false;
     }
     return $thread;
 }
Exemple #18
0
 public function modernStatisticPrepareThread(array $thread, array $nodePermissions = null, array $viewingUser = null)
 {
     $thread['lastPostInfo'] = array('post_date' => $thread['last_post_date'], 'post_id' => $thread['last_post_id'], 'user_id' => $thread['last_post_user_id'], 'username' => $thread['last_post_username']);
     if (isset($thread['node_title'])) {
         $thread['forum'] = array('node_id' => $thread['node_id'], 'title' => $thread['node_title']);
     }
     if ($thread['view_count'] <= $thread['reply_count']) {
         $thread['view_count'] = $thread['reply_count'] + 1;
     }
     if (!empty($thread['delete_date'])) {
         $thread['deleteInfo'] = array('user_id' => $thread['delete_user_id'], 'username' => $thread['delete_username'], 'date' => $thread['delete_date'], 'reason' => $thread['delete_reason']);
     }
     if (isset($thread['forum_id'])) {
         $forum = array('node_id' => $thread['forum_id'], 'title' => $thread['forum_title']);
     } else {
         $forum = array('node_id' => $thread['node_id']);
     }
     $thread['isRedirect'] = $this->isRedirect($thread);
     $thread['isDeleted'] = $this->isDeleted($thread);
     $thread['isModerated'] = $this->isModerated($thread);
     $thread['title'] = XenForo_Helper_String::censorString($thread['title']);
     $thread['titleCensored'] = true;
     $thread['lastPageNumbers'] = $this->getLastPageNumbers($thread['reply_count']);
     if (array_key_exists('user_group_id', $thread)) {
         $thread = $this->getModelFromCache('XenForo_Model_User')->prepareUser($thread);
     }
     $options = XenForo_Application::get('options');
     if ($options->BRMS_usePreviewTooltip == 'thread_preview') {
         $thread['hasPreview'] = $this->hasPreview($thread, $forum, $nodePermissions, $viewingUser);
     }
     $thread['isNew'] = $this->isNew($thread, $forum);
     if ($thread['isNew']) {
         $readDate = $this->getMaxThreadReadDate($thread, $forum);
         $thread['haveReadData'] = $readDate > XenForo_Application::$time - XenForo_Application::get('options')->readMarkingDataLifetime * 86400;
     } else {
         $thread['haveReadData'] = false;
     }
     return $thread;
 }
Exemple #19
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;
 }
Exemple #20
0
    public function actionGetPost()
    {
        // Whole function is an ugly hack.  Revisit later.
        global $dependencies, $zresponse;
        $postid = $this->_input->filterSingle('postid', XenForo_Input::UINT);
        $type = $this->_input->filterSingle('type', XenForo_Input::STRING);
        $signature = $this->_input->filterSingle('signature', XenForo_Input::UINT);
        if (!$type || $type == '') {
            $type = 'html';
        }
        $user_model = $this->getModelFromCache('XenForo_Model_User');
        $session_model = $this->getModelFromCache('XenForo_Model_Session');
        $thread_model = $this->getModelFromCache('XenForo_Model_Thread');
        $forum_model = $this->getModelFromCache('XenForo_Model_Forum');
        $attachment_model = $this->getModelFromCache('XenForo_Model_Attachment');
        $helper = $this->getHelper('ForumThreadPost');
        try {
            list($post, $thread, $forum) = $helper->assertPostValidAndViewable($postid);
        } catch (Exception $e) {
            json_error($e->getControllerResponse()->errorText->render());
        }
        $post_model = $this->_getPostModel();
        $post = $post_model->getPostById($postid, array('join' => XenForo_Model_Post::FETCH_THREAD | XenForo_Model_Post::FETCH_FORUM | XenForo_Model_Post::FETCH_USER | XenForo_Model_Post::FETCH_USER_PROFILE));
        $user = $user_model->getUserById($post['user_id']);
        $online_info = $session_model->getSessionActivityRecords(array('user_id' => $post['user_id'], 'cutOff' => array('>', $session_model->getOnlineStatusTimeout())));
        $is_online = false;
        if (count($online_info) == 1) {
            $is_online = true;
        }
        $avatarurl = '';
        if ($user !== false) {
            $avatarurl = process_avatarurl(XenForo_Template_Helper_Core::getAvatarUrl($user, 'm'));
            if (strpos($avatarurl, '/xenforo/avatars/avatar_') !== false) {
                $avatarurl = '';
            }
        }
        $attachments = $attachment_model->getAttachmentsByContentId('post', $postid);
        $message = fr_strip_smilies($this, $post['message']);
        list($text, $nuked_quotes, $images) = parse_post($message, true, array());
        $image = '';
        if ($type == 'html') {
            $css = <<<EOF
<style type="text/css">
body {
  margin: 0;
  padding: 3;
  font: 13px Arial, Helvetica, sans-serif;
}
.alt2 {
  background-color: #e6edf5;
  font: 13px Arial, Helvetica, sans-serif;
}
html {
    -webkit-text-size-adjust: none;
}
</style>
EOF;
            $formatter = XenForo_BbCode_Formatter_Base::create('ForumRunner_BbCode_Formatter_BbCode_Post', array('smilies' => XenForo_Application::get('smilies')));
            $parser = new XenForo_BbCode_Parser($formatter);
            $html = $css . $parser->render($message);
            if ($signature && $post['signature']) {
                $html .= '<div style="border-top: 1px dashed grey; font-size: 9pt; margin-top: 5px; padding: 5px 0 0;">' . $parser->render(fr_strip_smilies($this, $post['signature'])) . '</div>';
            }
        } else {
            if ($type == 'facebook') {
                $html = XenForo_Helper_String::censorString(XenForo_Helper_String::bbCodeStrip($message, true));
                if (count($attachments)) {
                    $attachments = array_values($attachments);
                    $link = XenForo_Link::buildPublicLink('attachments', $attachments[0]);
                    $image = fr_get_xenforo_bburl() . '/' . $link;
                }
            }
        }
        $post_page = floor($post['position'] / XenForo_Application::get('options')->messagesPerPage) + 1;
        $out = array('post_id' => $post['post_id'], 'thread_id' => $post['thread_id'], 'forum_id' => $post['node_id'], 'forum_title' => prepare_utf8_string(strip_tags($post['node_title'])), 'username' => prepare_utf8_string(strip_tags($post['username'])), 'joindate' => prepare_utf8_string(XenForo_Locale::date($post['register_date'], 'absolute')), 'usertitle' => XenForo_Template_Helper_Core::helperUserTitle($user), 'numposts' => $user ? $user['message_count'] : 0, 'userid' => $post['user_id'], 'title' => prepare_utf8_string($post['title']), 'online' => $is_online, 'post_timestamp' => prepare_utf8_string(XenForo_Locale::dateTime($post['post_date'], 'absolute')), 'html' => prepare_utf8_string($html), 'quotable' => $nuked_quotes, 'canpost' => $thread_model->canReplyToThread($thread, $forum), 'canattach' => $forum_model->canUploadAndManageAttachment($forum), 'post_link' => fr_get_xenforo_bburl() . '/' . XenForo_Link::buildPublicLink('threads', $thread, array('page' => $post_page)) . '#post-' . $post['post_id']);
        if ($image != '') {
            $out['image'] = $image;
        }
        if ($avatarurl != '') {
            $out['avatarurl'] = $avatarurl;
        }
        return $out;
    }
 /**
  * Send a notification to the users watching the thread.
  *
  * @param array $reply The reply that has been added
  * @param array|null $thread Info about the thread the reply is in; fetched if null
  * @param array List of user ids to NOT alert (but still send email)
  */
 public function sendNotificationToWatchUsersOnReply(array $reply, array $thread = null, array $noAlerts = array())
 {
     if ($reply['message_state'] != 'visible') {
         return;
     }
     $threadModel = $this->_getThreadModel();
     if (!$thread) {
         $thread = $threadModel->getThreadById($reply['thread_id'], array('join' => XenForo_Model_Thread::FETCH_FORUM));
     }
     if (!$thread || $thread['discussion_state'] != 'visible') {
         return;
     }
     $latestPosts = $this->getModelFromCache('XenForo_Model_Post')->getNewestPostsInThreadAfterDate($thread['thread_id'], 0, array('limit' => 2));
     if (!$latestPosts) {
         return;
     }
     // the reply is likely the last post, so get the one before that and only
     // alert again if read since; note these posts are in newest first order,
     // so end() is last
     $previousPost = end($latestPosts);
     $autoReadDate = XenForo_Application::$time - XenForo_Application::get('options')->readMarkingDataLifetime * 86400;
     $users = $this->getUsersWatchingThread($thread['thread_id'], $thread['node_id']);
     foreach ($users as $user) {
         if ($user['user_id'] == $reply['user_id']) {
             continue;
         }
         if ($previousPost['post_date'] < $autoReadDate) {
             // always alert
         } else {
             if ($previousPost['post_date'] > $user['thread_read_date']) {
                 // user hasn't read the thread since the last alert, don't send another one
                 continue;
             }
         }
         $permissions = XenForo_Permission::unserializePermissions($user['node_permission_cache']);
         if (!$threadModel->canViewThreadAndContainer($thread, $thread, $null, $permissions, $user)) {
             continue;
         }
         if ($user['email_subscribe'] && $user['email'] && $user['user_state'] == 'valid') {
             if (!isset($thread['titleCensored'])) {
                 $thread['titleCensored'] = XenForo_Helper_String::censorString($thread['title']);
             }
             $mail = XenForo_Mail::create('watched_thread_reply', array('reply' => $reply, 'thread' => $thread, 'forum' => $thread, 'receiver' => $user), $user['language_id']);
             $mail->enableAllLanguagePreCache();
             $mail->queue($user['email'], $user['username']);
         }
         if (!in_array($user['user_id'], $noAlerts)) {
             $alertType = $reply['attach_count'] ? 'insert_attachment' : 'insert';
             if (XenForo_Model_Alert::userReceivesAlert($user, 'post', $alertType)) {
                 XenForo_Model_Alert::alert($user['user_id'], $reply['user_id'], $reply['username'], 'post', $reply['post_id'], $alertType);
             }
         }
     }
 }
Exemple #22
0
 public function search($keywords, $order = 'asc', $type = NULL)
 {
     $keywords = strtolower(XenForo_Helper_String::censorString($keywords, null, ''));
     $this->getModels()->checkModel('search', XenForo_Model::create('XenForo_Model_Search'));
     $searcher = new XenForo_Search_Searcher($this->getModels()->getModel('search'));
     $xenforo_results = $searcher->searchGeneral($keywords, array(), $order);
     $results = array();
     foreach ($xenforo_results as &$result) {
         if ($type !== NULL) {
             if (strtolower($result[0]) != strtolower($type) && !(strtolower($result[0]) == 'thread' && strtolower($type) == 'thread_title')) {
                 continue;
             }
         }
         $result = array('type' => $result[0], 'data' => $result[1]);
         switch ($result['type']) {
             case 'post':
                 $result['data'] = $this->getPost($result['data']);
                 break;
             case 'thread':
                 $result['data'] = $this->getThread($result['data']);
                 if ($type !== NULL && strtolower($type) == 'thread_title' && ($titleFound = $result['data']['title'] != $keywords)) {
                     continue 2;
                 }
                 break;
             case 'resource_update':
                 // TODO
                 $result['data'] = array('resource_update_id' => $result['data']);
                 break;
         }
         $results[] = $result;
     }
     return $results;
 }
 public function sendNotificationToWatchUsersOnCommentInsert(array $comment, array $album, $alreadyAlerted = array())
 {
     if ($comment['comment_state'] != 'visible') {
         return array();
     }
     /* @var $userModel XenForo_Model_User */
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     if (!$album || $album['album_state'] != 'visible') {
         return array();
     }
     $album['titleCensored'] = XenForo_Helper_String::censorString($album['album_title']);
     $album['descCensored'] = XenForo_Helper_String::censorString($album['album_description']);
     $comment['messageCensored'] = XenForo_Helper_String::censorString($comment['message']);
     $bbCodeParserText = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Text'));
     $comment['messageText'] = new XenForo_BbCode_TextWrapper($comment['messageCensored'], $bbCodeParserText);
     $bbCodeParserHtml = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
     $comment['messageHtml'] = new XenForo_BbCode_TextWrapper($comment['messageCensored'], $bbCodeParserHtml);
     // fetch a full user record if we don't have one already
     if (!isset($comment['avatar_width']) || !isset($comment['custom_title'])) {
         $commentUser = $this->getModelFromCache('XenForo_Model_User')->getUserById($comment['user_id']);
         if ($commentUser) {
             $comment = array_merge($commentUser, $comment);
         } else {
             $comment['avatar_width'] = 0;
             $comment['custom_title'] = '';
         }
     }
     $alerted = array();
     $emailed = array();
     $users = $this->getUsersWatchingAlbum($album['album_id'], 'comment');
     foreach ($users as $user) {
         if ($user['user_id'] == $comment['user_id']) {
             continue;
         }
         if ($userModel->isUserIgnored($user, $comment['user_id'])) {
             continue;
         }
         if (in_array($user['user_id'], $alreadyAlerted)) {
             continue;
         }
         if (isset(self::$_preventDoubleNotify[$album['album_id']][$user['user_id']])) {
             continue;
         }
         self::$_preventDoubleNotify[$album['album_id']][$user['user_id']] = true;
         if ($user['send_email'] && $user['email'] && $user['user_state'] == 'valid') {
             $user['email_confirm_key'] = $userModel->getUserEmailConfirmKey($user);
             $mail = XenForo_Mail::create('xengallery_watched_album_comment', array('comment' => $comment, 'album' => $album, 'receiver' => $user), $user['language_id']);
             $mail->enableAllLanguagePreCache();
             $mail->queue($user['email'], $user['username']);
             $emailed[] = $user['user_id'];
         }
         if ($user['send_alert']) {
             XenForo_Model_Alert::alert($user['user_id'], $comment['user_id'], $comment['username'], 'xengallery_comment', $comment['comment_id'], 'watch_comment');
             $alerted[] = $user['user_id'];
         }
     }
     return array('emailed' => $emailed, 'alerted' => $alerted);
 }
Exemple #24
0
 /**
  * Validates a custom user title, checking for blocked terms, banned markup etc.
  *
  * @param string $title
  *
  * @return boolean
  */
 protected function _verifyCustomTitle(&$title)
 {
     if (!$this->getOption(self::OPTION_ADMIN_EDIT)) {
         if ($title === $this->getExisting('custom_title')) {
             return true;
             // can always keep the existing value
         }
         if ($title !== XenForo_Helper_String::censorString($title)) {
             $this->error(new XenForo_Phrase('please_enter_custom_title_that_does_not_contain_any_censored_words'), 'custom_title');
             return false;
         }
         $disallowed = $this->getOption(self::OPTION_CUSTOM_TITLE_DISALLOWED);
         if ($disallowed && !$this->get('is_moderator') && !$this->get('is_admin')) {
             foreach ($disallowed as $value) {
                 $value = trim($value);
                 if ($value === '') {
                     continue;
                 }
                 if (stripos($title, $value) !== false) {
                     $this->error(new XenForo_Phrase('please_enter_another_custom_title_disallowed_words'), 'custom_title');
                     return false;
                 }
             }
         }
     }
     return true;
 }
Exemple #25
0
 /**
  * Send a notification to the users watching the resource.
  *
  * @param array $update The reply that has been added
  * @param array $resource Info about the resource the update is in
  * @param array $noAlerts List of user ids to NOT alert (but still send email)
  * @param array $noEmail List of user ids to not send an email
  *
  * @return array Empty or keys: alerted: user ids alerted, emailed: user ids emailed
  */
 public function sendNotificationToWatchUsersOnUpdate(array $update, array $resource, array $noAlerts = array(), array $noEmail = array())
 {
     if ($update['message_state'] != 'visible' || $resource['resource_state'] != 'visible') {
         return array();
     }
     $resourceModel = $this->_getResourceModel();
     /* @var $userModel XenForo_Model_User */
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     if (XenForo_Application::get('options')->emailWatchedThreadIncludeMessage) {
         $parseBbCode = true;
         $emailTemplate = 'watched_resource_update_messagetext';
     } else {
         $parseBbCode = false;
         $emailTemplate = 'watched_resource_update';
     }
     $resourceUser = $userModel->getUserById($resource['user_id']);
     if (!$resourceUser) {
         $resourceUser = $userModel->getVisitingGuestUser();
     }
     if (!empty($resource['category_breadcrumb'])) {
         $category = $resource;
     } else {
         $category = $this->_getCategoryModel()->getCategoryById($resource['resource_category_id']);
         if (!$category) {
             return array();
         }
     }
     $alerted = array();
     $emailed = array();
     $users = $this->getUsersWatchingResource($resource['resource_id'], $resource['resource_category_id']);
     foreach ($users as $user) {
         if ($user['user_id'] == $resource['user_id']) {
             continue;
         }
         $user['permissions'] = XenForo_Permission::unserializePermissions($user['global_permission_cache']);
         $categoryPermissions = XenForo_Permission::unserializePermissions($user['category_permission_cache']);
         if (!$resourceModel->canViewResourceAndContainer($resource, $category, $null, $user, $categoryPermissions)) {
             continue;
         }
         if ($user['email_subscribe'] && $user['email'] && $user['user_state'] == 'valid') {
             if (!isset($update['messageText']) && $parseBbCode) {
                 $bbCodeParserText = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('Text'));
                 $update['messageText'] = new XenForo_BbCode_TextWrapper($update['message'], $bbCodeParserText);
                 $bbCodeParserHtml = XenForo_BbCode_Parser::create(XenForo_BbCode_Formatter_Base::create('HtmlEmail'));
                 $update['messageHtml'] = new XenForo_BbCode_TextWrapper($update['message'], $bbCodeParserHtml);
             }
             if (!isset($resource['titleCensored'])) {
                 $resource['titleCensored'] = XenForo_Helper_String::censorString($resource['title']);
                 $update['titleCensored'] = XenForo_Helper_String::censorString($update['title']);
             }
             $user['email_confirm_key'] = $userModel->getUserEmailConfirmKey($user);
             $mail = XenForo_Mail::create($emailTemplate, array('update' => $update, 'resource' => $resource, 'category' => $category, 'resourceUser' => $resourceUser, 'receiver' => $user), $user['language_id']);
             $mail->enableAllLanguagePreCache();
             $mail->queue($user['email'], $user['username']);
             $emailed[] = $user['user_id'];
             $noEmail[] = $user['user_id'];
         }
         if (XenForo_Model_Alert::userReceivesAlert($user, 'resource_update', 'insert')) {
             XenForo_Model_Alert::alert($user['user_id'], $resource['user_id'], $resource['username'], 'resource_update', $update['resource_update_id'], 'insert');
             $alerted[] = $user['user_id'];
             $noAlerts[] = $user['user_id'];
         }
     }
     return array('emailed' => $emailed, 'alerted' => $alerted);
 }
Exemple #26
0
 /**
  * Prepares a result for display.
  *
  * @see XenForo_Search_DataHandler_Abstract::prepareResult()
  */
 public function prepareResult(array $result, array $viewingUser)
 {
     $result = $this->_getPostModel()->preparePost($result, $result, $result, $result['permissions'], $viewingUser);
     $result['title'] = XenForo_Helper_String::censorString($result['title']);
     return $result;
 }
Exemple #27
0
 /**
  * Prepares the extra content for display.
  *
  * @see XenForo_ReportHandler_Abstract::prepareExtraContent()
  */
 public function prepareExtraContent(array $contentInfo)
 {
     $contentInfo['thread_title'] = XenForo_Helper_String::censorString($contentInfo['thread_title']);
     return $contentInfo;
 }
Exemple #28
0
 /**
  * Renders a media tag. Media tags embed rich media (usually videos). To embed a video,
  * the source must be known.
  *
  * @param array $tag Information about the tag reference; keys: tag, option, children
  * @param array $rendererStates Renderer states to push down
  *
  * @return string Rendered tag
  */
 public function renderTagMedia(array $tag, array $rendererStates)
 {
     $mediaKey = trim($this->stringifyTree($tag['children']));
     if (preg_match('#[&?"\'<>\\r\\n]#', $mediaKey) || strpos($mediaKey, '..') !== false) {
         return '';
     }
     $censored = XenForo_Helper_String::censorString($mediaKey);
     if ($censored != $mediaKey) {
         return '';
     }
     $mediaSiteId = strtolower($tag['option']);
     if ($mediaSiteId == 'youtube') {
         // youtube iframe embed bug workaround
         $mediaKey = str_replace('/', '', $mediaKey);
     }
     if (isset($this->_mediaSites[$mediaSiteId])) {
         $embedHtml = $this->_getMediaSiteHtmlFromCallback($mediaKey, $this->_mediaSites[$mediaSiteId], $mediaSiteId);
         if (!$embedHtml) {
             $embedHtml = strtr($this->_mediaSites[$mediaSiteId]['embed_html'], array('{$id}' => rawurlencode($mediaKey), '{$id:digits}' => intval($mediaKey)));
         }
         return $embedHtml;
     } else {
         return '';
     }
 }
Exemple #29
0
 public function verifyUsername($username, $userId = null)
 {
     // standardize white space in names
     $username = preg_replace('/\\s+/u', ' ', $username);
     try {
         $newName = preg_replace('/\\v+/u', ' ', $username);
         if (is_string($newName)) {
             $username = $newName;
         }
     } catch (Exception $e) {
     }
     $username = trim($username);
     $usernameLength = utf8_strlen($username);
     $minLength = $this->getOption('usernameLength', 'min');
     $maxLength = $this->getOption('usernameLength', 'max');
     if ($minLength > 0 && $usernameLength < $minLength) {
         return new XenForo_Phrase('please_enter_name_that_is_at_least_x_characters_long', array('count' => $minLength));
     }
     if ($maxLength > 0 && $usernameLength > $maxLength) {
         return new XenForo_Phrase('please_enter_name_that_is_at_most_x_characters_long', array('count' => $maxLength));
     }
     $disallowedNames = preg_split('/\\r?\\n/', $this->getOption('usernameValidation', 'disallowedNames'));
     if ($disallowedNames) {
         foreach ($disallowedNames as $name) {
             $name = trim($name);
             if ($name === '') {
                 continue;
             }
             if (stripos($username, $name) !== false) {
                 return new XenForo_Phrase('please_enter_another_name_disallowed_words');
             }
         }
     }
     $matchRegex = $this->getOption('usernameValidation', 'matchRegex');
     if ($matchRegex) {
         $matchRegex = str_replace('#', '\\#', $matchRegex);
         // escape delim only
         if (!preg_match('#' . $matchRegex . '#i', $username)) {
             return new XenForo_Phrase('please_enter_another_name_required_format');
         }
     }
     $censoredUserName = XenForo_Helper_String::censorString($username);
     if ($censoredUserName !== $username) {
         return new XenForo_Phrase('please_enter_name_that_does_not_contain_any_censored_words');
     }
     // ignore check if unicode properties aren't compiled
     try {
         if (@preg_match("/\\p{C}/u", $username)) {
             return new XenForo_Phrase('please_enter_name_without_using_control_characters');
         }
     } catch (Exception $e) {
     }
     if (strpos($username, ',') !== false) {
         return new XenForo_Phrase('please_enter_name_that_does_not_contain_comma');
     }
     if (Zend_Validate::is($username, 'EmailAddress')) {
         return new XenForo_Phrase('please_enter_name_that_does_not_resemble_an_email_address');
     }
     $existingUser = XenForo_Model::create('XenForo_Model_User')->getUserByName($username);
     if ($existingUser && (!$userId || $userId && $userId != $existingUser['user_id'])) {
         return new XenForo_Phrase('usernames_must_be_unique');
     }
     // compare against romanized name to help reduce confusable issues
     $romanized = utf8_deaccent(utf8_romanize($username));
     if ($romanized != $username) {
         $existingUser = XenForo_Model::create('XenForo_Model_User')->getUserByName($romanized);
         if ($existingUser && (!$userId || $userId && $userId != $existingUser['user_id'])) {
             return new XenForo_Phrase('usernames_must_be_unique');
         }
     }
     return true;
 }
Exemple #30
0
 public function prepareEvent(array $event, array $team, array $category, array $viewingUser = null)
 {
     $this->standardizeViewingUserReference($viewingUser);
     $event = $this->prepareEventTypePhrase($event);
     if (isset($event['team_user_id'])) {
         $event['teamInfo'] = array('team_id' => $event['team_id'], 'user_id' => $event['team_user_id'], 'username' => $event['team_username'], 'title' => $event['title']);
     }
     $begin = max(0, $event['begin_date'] + XenForo_Locale::getTimeZoneOffset());
     $event['beginDate'] = date('H:i', $begin);
     if ($event['end_date']) {
         $end = max(0, $event['end_date'] + XenForo_Locale::getTimeZoneOffset());
         $event['endDate'] = date('H:i', $end);
     }
     if ($team) {
         $category = $category ? $category : $null;
         $event['canEditEvent'] = $this->canEditEvent($event, $team, $category, $null, $viewingUser);
         $event['canDeleteEvent'] = $this->canDeleteEvent($event, $team, $category, $null, $viewingUser);
         $event['canComment'] = $this->canCommentOnEvent($event, $team, $category, $null, $viewingUser);
         $event['canLikeEvent'] = $this->canLikeEvent($event, $team, $category, $null, $viewingUser);
     } else {
         $event['canEditEvent'] = false;
         $event['canDeleteEvent'] = false;
         $event['canComment'] = false;
         $event['canLikeEvent'] = false;
     }
     $event['event_title'] = XenForo_Helper_String::censorString($event['event_title']);
     $event['titleCensored'] = true;
     $event['likeUsers'] = unserialize($event['like_users']);
     return $event;
 }