Example #1
0
 /**
  * Converts WYSIWYG editor HTML back to BB code
  *
  * @param string $messageTextHtml HTML to convert
  * @param XenForo_Input $input
  * @param integer $htmlCharacterLimit Max length of HTML before processing; defaults to 4 * message length option
  *
  * @return string BB code input
  */
 public function convertEditorHtmlToBbCode($messageTextHtml, XenForo_Input $input, $htmlCharacterLimit = -1)
 {
     if ($htmlCharacterLimit < 0) {
         $htmlCharacterLimit = 4 * XenForo_Application::get('options')->messageMaxLength;
         // quadruple the limit as HTML can be a lot more verbose
     }
     if ($htmlCharacterLimit && utf8_strlen($messageTextHtml) > $htmlCharacterLimit) {
         throw new XenForo_Exception(new XenForo_Phrase('submitted_message_is_too_long_to_be_processed'), true);
     }
     $options = array();
     $requestPaths = XenForo_Application::get('requestPaths');
     $options['baseUrl'] = $requestPaths['fullBasePath'];
     $relativeResolver = $input->filterSingle('_xfRelativeResolver', XenForo_Input::STRING);
     if ($relativeResolver && isset($_SERVER['HTTP_USER_AGENT'])) {
         if (preg_match('#Firefox/([0-9]+)\\.([0-9]+)\\.([0-9]+)#i', $_SERVER['HTTP_USER_AGENT'], $match)) {
             // FF versions sometime before 3.6.12 have an issue with respecting the base tag of the editor,
             // 3.6.8 is a known version that has problems
             $useResolver = $match[1] <= 3 && $match[2] <= 6 && $match[3] <= 8;
         } else {
             $useResolver = false;
         }
         if ($useResolver) {
             // take off query string and then up to the last directory
             $relativeResolver = preg_replace('/\\?.*$/', '', $relativeResolver);
             $relativeResolver = preg_replace('#/[^/]+$#', '', $relativeResolver);
             $options['baseUrl'] = $relativeResolver;
         }
     }
     $rendered = XenForo_Html_Renderer_BbCode::renderFromHtml($messageTextHtml, $options);
     return trim(XenForo_Input::cleanString($rendered));
 }
Example #2
0
 public function actionToBbCode()
 {
     $html = $this->_input->filterSingle('html', XenForo_Input::STRING);
     $options = array('stripLinkPathTraversal' => XenForo_Visitor::isBrowsingWith('firefox'));
     $bbCode = trim(XenForo_Html_Renderer_BbCode::renderFromHtml($html, $options));
     return $this->responseView('XenForo_ViewPublic_Editor_ToBbCode', '', array('bbCode' => $bbCode));
 }
Example #3
0
 public function renderHtml()
 {
     $buttonConfig = array('basic' => true);
     $categoryDescription = XenForo_Html_Renderer_BbCode::renderFromHtml($this->_params['category']['category_description']);
     /* @var $formatter ThemeHouse_ResCats_BbCode_Formatter_BbCode_Description */
     $formatter = XenForo_BbCode_Formatter_Base::create('ThemeHouse_ResCats_BbCode_Formatter_BbCode_Description');
     $formatter->configureForDescription();
     $parser = XenForo_BbCode_Parser::create($formatter);
     $categoryDescription = $parser->render($categoryDescription);
     $this->_params['descriptionEditor'] = XenForo_ViewPublic_Helper_Editor::getEditorTemplate($this, 'category_description', $categoryDescription, array('json' => array('buttonConfig' => $buttonConfig)));
 }
Example #4
0
 /**
  * Attempts to read HTML that has been selected from XenForo messages,
  * and turn it back into its source BB code.
  *
  * @param $html
  *
  * @return string
  */
 public function getBbCodeFromSelectionHtml($html)
 {
     // attempt to parse the selected HTML into BB code
     $html = trim(strip_tags($html, '<b><i><u><a><img><span><ul><ol><li><pre><code><br>'));
     // handle PHP/CODE/HTML output and turn it back into BB code
     $html = preg_replace_callback('/<(pre|code) data-type="(\\w+)">(.*)<\\/\\1>/siU', array($this, '_bbCodeTagsHtmlToBbCode'), $html);
     $html = XenForo_Html_Renderer_BbCode::renderFromHtml($html);
     return trim(XenForo_Input::cleanString($html));
 }
Example #5
0
 /**
  * Prepares the data from a single feed entry for use in posts
  *
  * @param array $entry
  * @param array $feedData
  * @param array $feed
  *
  * @return array
  */
 public function prepareFeedEntry(array $entry, array $feedData, array $feed)
 {
     $html = $entry['content_html'];
     $html = preg_replace('#<p#i', '<br>$0', $html);
     $html = preg_replace('#</p>(?!\\s*<br)#i', '$0<br>', $html);
     $entry['content'] = XenForo_Html_Renderer_BbCode::renderFromHtml($html, array('baseUrl' => $feed['baseUrl']));
     $entry['author'] = $this->_getAuthorNamesFromArray($entry['authors']);
     if (empty($feed['message_template'])) {
         $entry['message'] = $entry['content'];
     } else {
         $entry['message'] = $this->_replaceTokens($feed['message_template'], $entry);
     }
     $entry['message'] = trim($entry['message']);
     if ($entry['message'] === '') {
         $entry['message'] = '[url]' . $entry['link'] . '[/url]';
     }
     if (!empty($feed['title_template'])) {
         $entry['title'] = $this->_replaceTokens($feed['title_template'], $entry);
     }
     return $entry;
 }