public static function getText($channelid)
 {
     if (empty($channelid)) {
         return false;
     }
     $cacheKey = "vB_Announcements_{$channelid}";
     // first try with cache
     $api = Api_InterfaceAbstract::instance();
     $cache = $api->cacheInstance(0);
     $found = $cache->read($cacheKey);
     if ($found !== false) {
         return $found;
     }
     $announcements = $api->callApi('announcement', 'fetch', array($channelid));
     $parser = new vB5_Template_BbCode();
     $bbCodeOptions = array('allowimages', 'allowimagebbcode', 'allowbbcode', 'allowhtml', 'allowsmilies');
     foreach ($announcements as $key => $announcement) {
         $announcements[$key]['pagetext'] = $parser->doParse($announcement['pagetext'], $announcement['dohtml'], $announcement['dosmilies'], $announcement['dobbcode'], $announcement['dobbimagecode']);
     }
     $events = array('nodeChg_' . $channelid, 'vB_AnnouncementChg');
     $cache->write($cacheKey, $announcements, 10080, $events);
     return $announcements;
 }
示例#2
0
 /**
  * @param $textDataArray
  * @param $nodeId
  * @param $bbcodeOptions
  * @return array
  */
 protected function parseNode($textDataArray, $nodeId, $bbcodeOptions)
 {
     $textData = $textDataArray[$nodeId];
     $skipBbCodeParsing = $textData['disable_bbcode'];
     // if disable_bbcode is set (static pages), just use the rawtext
     $parser = new vB5_Template_BbCode();
     $parser->setRenderImmediate(true);
     $parser->setMultiPageRender($textData['channeltype'] == 'article');
     if (isset($textData['attachments'])) {
         $parser->setAttachments($textData['attachments']);
     }
     if (isset($textData['attachments']) and empty($textData['attachments'])) {
         $parser->getAndSetAttachments($nodeId);
     }
     //make sure we have values for all the necessary options
     foreach (array('allowimages', 'allowimagebbcode', 'allowbbcode', 'allowsmilies') as $option) {
         if (!empty($bbcodeOptions) and isset($bbcodeOptions[$option])) {
             $textData['bbcodeoptions'][$option] = $bbcodeOptions[$option];
         } else {
             if (!isset($textData['bbcodeoptions'][$option])) {
                 $textData['bbcodeoptions'][$option] = false;
             }
         }
     }
     /*
     	bbcodeOptions['allowhtml'] comes from channel.options & 256 (bf_misc_forumoptions.allowhtml),
     	except for public_preview > 0 articles that the user can't view... (see function vB_Api_Content_Text->getDataForParse() & queryef vBForum:getDataForParse)
     	so we should actually be ignoring that, and using htmlstate only.
     	Unfortunately, we can't just ignore it in the parser's doParse() function, because there is at least 1 other thing that seems to use allowhtml: announcements. I'm placing
     	the change here instead of the parser in order to minimize risk.
     	Alternatively, we could just make sure that every single channel is created with allowhtml set, but that'd also mean we're keeping this option, and adding
     	an upgrade step to fix all old channels that may have been created with allowhtml unset.
     */
     $textData['bbcodeoptions']['allowhtml'] = in_array($textData['htmlstate'], array('on', 'on_nl2br'));
     $allowimages = false;
     if (!empty($bbcodeOptions) and !empty($bbcodeOptions['allowimages'])) {
         $allowimages = $bbcodeOptions['allowimages'];
     } else {
         if (!empty($bbcodeOptions['cangetimgattachment'])) {
             $allowimages = $bbcodeOptions['cangetimgattachment'];
         } else {
             if (!empty($textData['bbcodeoptions']['allowimages'])) {
                 $allowimages = $textData['bbcodeoptions']['allowimages'];
             } else {
                 if (!empty($textData['bbcodeoptions']['allowimagecode'])) {
                     $allowimages = $textData['bbcodeoptions']['allowimagecode'];
                 }
             }
         }
     }
     if ($textData['channeltype'] == 'article') {
         if (!$skipBbCodeParsing) {
             //If it's paginated we parse it here.
             $matches = array();
             $check = preg_match_all('#\\[page\\].*\\[\\/page\\]#siU', $textData['rawtext'], $matches, PREG_OFFSET_CAPTURE);
             $start = 0;
             $title = $textData['title'];
             $parsed = array();
             // If [page] is at the beginning of the text, use it for the first page title
             // instead of using the article title for the first one.
             $hasFirstPageTitle = (bool) preg_match('#^\\s*\\[PAGE\\]#siU', $textData['rawtext']);
             if (!empty($matches[0])) {
                 foreach ($matches[0] as $match) {
                     if ($hasFirstPageTitle) {
                         $hasFirstPageTitle = false;
                         $start = strlen($match[0]) + $match[1];
                         $title = vB_String::stripBbcode($match[0]);
                         continue;
                     }
                     $rawtext = substr($textData['rawtext'], $start, $match[1] - $start);
                     $currentText = $parser->doParse($rawtext, $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate'], false, $textData['rawtext']);
                     $parsed[] = array('title' => $title, 'pageText' => $currentText);
                     $start = strlen($match[0]) + $match[1];
                     $title = vB_String::stripBbcode($match[0]);
                 }
                 if (!empty($start) and $start < strlen($textData['rawtext'])) {
                     $rawtext = substr($textData['rawtext'], $start);
                     $currentText = $parser->doParse($rawtext, $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate'], false, $textData['rawtext']);
                     $parsed[] = array('title' => $title, 'pageText' => $currentText);
                 }
             }
             $paging = array();
             $pageNo = 1;
             $phrases = vB5_Template_Phrase::instance();
             foreach ($parsed as $page) {
                 if (empty($page['title'])) {
                     $page['title'] = $phrases->getPhrase('page_x', $pageNo);
                 }
                 $paging[$pageNo] = $page['title'];
                 $pageNo++;
             }
             Api_InterfaceAbstract::instance()->cacheInstance(0)->write($this->getPagingCacheKey($nodeId), $paging, 1440, 'nodeChg_' . $nodeId);
         } else {
             $parsed = $textData['rawtext'];
             $matches[0] = 1;
             // skip re-parsing below.
         }
     }
     if (empty($matches[0])) {
         // Get full text
         $parsed = $parser->doParse($textData['rawtext'], $textData['bbcodeoptions']['allowhtml'], $textData['bbcodeoptions']['allowsmilies'], $textData['bbcodeoptions']['allowbbcode'], $allowimages, true, false, $textData['htmlstate']);
     }
     // Get preview text
     if (empty($this->previewLength)) {
         if (isset($textData['previewLength'])) {
             $this->previewLength = $textData['previewLength'];
         } else {
             $options = Api_InterfaceAbstract::instance()->callApiStatic('options', 'fetchStatic', array('previewLength'));
             $this->previewLength = $options['previewLength'];
         }
     }
     // if textData has previewLength set, we always want to use it (articles)
     if (isset($textData['previewLength'])) {
         $previewLength = $textData['previewLength'];
     } else {
         $previewLength = $this->previewLength;
     }
     if ($skipBbCodeParsing) {
         // static pages from vb4 should always have text.previewtext set, taken from cms_nodeconfig.value where name = 'previewtext'
         // As such, we should always set the previewtext for static pages created in vB5.
         $previewText = $textData['previewtext'];
     } else {
         $previewText = $parser->get_preview($textData['rawtext'], $previewLength, $textData['bbcodeoptions']['allowhtml'], true, $textData['htmlstate'], array('do_smilies' => $textData['bbcodeoptions']['allowsmilies'], 'allowPRBREAK' => !empty($textData['disableBBCodes']['prbreak'])));
     }
     if (is_array($parsed)) {
         // for multi-paged articles, $parsed is an array, let's check the length
         // of the first page of that article for purposes of appending the ellipsis
         $parsedLength = strlen($parsed[0]['pageText']);
     } else {
         $parsedLength = strlen($parsed);
     }
     // Append ellipsis if preview text is shorter than parsed full text.
     // One special case to note is if previewText has 0 length. This could happen if the previewText is entirely composed of bbcodes that are stripped via parsing
     // If we want special behavior, we should check for that case here and not append the ellipsis
     if ($parsedLength > strlen($previewText)) {
         $previewText .= '...';
     }
     return array($previewText, $parsed);
 }
示例#3
0
 /**
  * Handles an [img] tag.
  *
  * @param	string	The text to search for an image in.
  * @param	string	Whether to parse matching images into pictures or just links.
  *
  * @return	string	HTML representation of the tag.
  */
 function handle_bbcode_img($bbcode, $do_imgcode, $has_img_code = false, $fulltext = '', $forceShowImages = false)
 {
     $bbcode = parent::handle_bbcode_img($bbcode, $do_imgcode, $has_img_code, $fulltext, true);
     return $bbcode;
 }
示例#4
0
 /**
  * Constructor. Sets up the tag list.
  *
  * @param	bool		Whether to append customer user tags to the tag list
  */
 public function __construct($appendCustomTags = true)
 {
     if (!self::$initialized) {
         self::$config = vB5_Config::instance();
         $response = Api_InterfaceAbstract::instance()->callApi('bbcode', 'initInfo');
         self::$defaultTags = $response['defaultTags'];
         self::$customTags = $response['customTags'];
         self::$defaultOptions = $response['defaultOptions'];
         self::$smilies = $response['smilies'];
         self::$censorship = $response['censorship'];
         self::$sessionUrl = $response['sessionUrl'];
         self::$blankAsciiStrip = $response['blankAsciiStrip'];
         self::$wordWrap = $response['wordWrap'];
         self::$bbUrl = $response['bbUrl'];
         self::$viewAttachedImages = $response['viewAttachedImages'];
         self::$urlNoFollow = $response['urlNoFollow'];
         self::$urlNoFollowWhiteList = $response['urlNoFollowWhiteList'];
         self::$vBHttpHost = $response['vBHttpHost'];
         self::$useFileAvatar = $response['useFileAvatar'];
         self::$sigpicUrl = $response['sigpicUrl'];
         self::$initialized = true;
     }
     $this->tag_list = self::$defaultTags;
     if ($appendCustomTags) {
         $this->tag_list = vB5_Array::arrayReplaceRecursive($this->tag_list, self::$customTags);
     }
     // Legacy Hook 'bbcode_create' Removed //
 }
示例#5
0
 /**
  * Handles an [img] tag.
  *
  * NOTE: This calls the parent implementation so that the [ATTACH] and [IMG]
  * bbcodes render (nearly) the same when editing the post as when displaying
  * the post. The main difference is that the surrounding anchor tags are
  * removed for images in the WYSIWYG editor, via turnOffSurroundingAnchor.
  * See comment before parent function call.
  *
  * @param	string	The text to search for an image in.
  * @param	string	Whether to parse matching images into pictures or just links.
  *
  * @return	string	Text representation of the tag.
  */
 function handle_bbcode_img($bbcode, $do_imgcode, $has_img_code = false, $fulltext = '', $forceShowImages = false)
 {
     // the bbcode parser surrounds images in an anchor if the image is not fullsize.
     // In order to have the images show the ckeditor's Image Dialog instead of the Link dialog,
     // we need the images to show up without the surrounding anchor tag.
     // So this is a dirty hacky workaround.
     $this->turnOffSurroundingAnchor = true;
     return parent::handle_bbcode_img($bbcode, $do_imgcode, $has_img_code, $fulltext, $forceShowImages);
 }
示例#6
0
 public function actionPreviewSignature()
 {
     $parser = new vB5_Template_BbCode();
     $userInfo = Api_InterfaceAbstract::instance()->callApi('user', 'fetchUserInfo', array());
     $sigInfo = Api_InterfaceAbstract::instance()->callApi('user', 'fetchSignature', array($userInfo['userid']));
     $signature = empty($_REQUEST['signature']) ? $sigInfo['raw'] : $_REQUEST['signature'];
     $signature = $parser->doParse($signature, $sigInfo['permissions']['dohtml'], $sigInfo['permissions']['dosmilies'], $sigInfo['permissions']['dobbcode'], $sigInfo['permissions']['dobbimagecode']);
     $this->sendAsJson($signature);
 }
示例#7
0
 private static function parseInternal(vB5_Template_BbCode $parser, $text, $options = array(), $attachments = array())
 {
     if (!isset($options['allowhtml'])) {
         $options['allowhtml'] = false;
     }
     if (!isset($options['allowsmilies'])) {
         $options['allowsmilies'] = true;
     }
     if (!isset($options['allowbbcode'])) {
         $options['allowbbcode'] = true;
     }
     if (!isset($options['allowimagebbcode'])) {
         $options['allowimagebbcode'] = true;
     }
     if (isset($options['userid'])) {
         $parser->setParseUserinfo($options['userid']);
     }
     $parser->setAttachments($attachments);
     /*
      * If we have new attachments, we need to know whether it's an image or not so we can choose the correct
      * tag (img or a). We need to grab & check the file extension for that, which is saved in the filedata table.
      * Let's prefetch all of them so we don't have to hit the DB one at a time.
      */
     preg_match_all('#\\[attach(?:=(right|left|config))?\\]temp_(\\d+)_(\\d+)_(\\d+)\\[/attach\\]#i', $text, $matches);
     if (!empty($matches[2])) {
         $filedataids = array();
         foreach ($matches[2] as $filedataid) {
             $filedataids[$filedataid] = $filedataid;
         }
         $parser->prefetchFiledata($filedataids);
     }
     // Parse the bbcode
     $result = $parser->doParse($text, $options['allowhtml'], $options['allowsmilies'], $options['allowbbcode'], $options['allowimagebbcode']);
     return $result;
 }