예제 #1
0
 /**
  *	This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can
  *	optionally convert line breaks as well as convert the remaining HTML tags to their entities.
  *
  *	@param $data			The data you want to convert.
  *	@param $convertBr		(optional) Boolean to indicate that new lines should be converted to <br/> tags.
  *							This is turned on by default.
  *	@param $convertTags		(optional) Boolean to indicate that tags should be converted to HTML. This is turned
  *							on by default.
  *	@param $convertLinks	(optional) Boolean to indicate if links should be automatically highlighted or not.
  *							This is turned on by default.
  *  @param $baseUrl         (optional) If you give this a non-null value, it will convert all links to absolute
  *                          links using this url as the base url.
  *
  *	@returns	The HTML equivalent of the string with all the BBCode's converted according to the conversion table
  *				of this class.
  */
 function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null)
 {
     // Encode the references
     $data = YDStringUtil::encodeString($data);
     // Convert the links to BBcode
     if ($convertLinks === true) {
         $data = $this->convertLinks($data);
     }
     // Convert tags if needed
     if ($convertTags === true) {
         $data = str_replace('<', '&lt;', $data);
         $data = str_replace('>', '&gt;', $data);
     }
     // Fix common problems
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = str_replace("[/quote]\n\n", "[/quote]\n", $data);
     // Convert the tags
     $data = $this->parser->parse($data);
     // Strip the leftover tags
     $data = trim(preg_replace('/\\[\\/[a-z]+\\]/i', '', $data));
     // Open http links in a new window
     $data = str_replace(' href="http://', ' target="_blank" href="http://', $data);
     // Convert tags if needed
     if ($convertBr === true) {
         $data = nl2br(trim($data));
     }
     // Convert smilies if needed
     $smilies_path = YDConfig::get('YD_BBCODE_SMILIES_DIR', '');
     $smilies_url = YDConfig::get('YD_BBCODE_SMILIES_URL', '');
     if (is_dir($smilies_path)) {
         foreach ($this->smilies as $smilie => $file) {
             $data = str_replace($smilie, '<img src="' . $smilies_url . '/' . $file . '" width="15" height="15" />', $data);
         }
     }
     // Make links absolute if needed
     if (!is_null($baseUrl)) {
         include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php';
         $data = YDUrl::makeLinksAbsolute($data, $baseUrl);
     }
     // Return the data
     return $data;
 }
 /**
  *	This function will add a new item to the feed. You need to at least give in a title, link. A description is
  *	advised but optional. Also a GUID is optional. If no GUID is given, an automatic one will be created which
  *	is the md5 checksum of the different elememts.
  *
  *	@param $title	        The title of the feed item.
  *	@param $link	        The link to the feed item.
  *	@param $desc	        (optional) The description for the feed item.
  *	@param $guid	        (optional) The guid for the feed item.
  *  @param $enclosure       (optional) The url of the enclosure.
  *  @param $enclosure_size  (optional) The size in bytes of the enclosure.
  *  @param $enclosure_type  (optional) The mime-type of the enclosure.
  *  @param $commentlink     (optional) The link to the comment page for the item.
  *
  *  @remark
  *      Enclosures are only supported for ATOM and RSS 2.0 feeds.
  */
 function addItem($title, $link, $desc = null, $guid = null, $enclosure = null, $enclosure_size = null, $enclosure_type = null, $commentlink = null)
 {
     $link = YDUrl::makeLinkAbsolute($link, $this->_link);
     $desc = YDUrl::makeLinksAbsolute($desc, $this->_link);
     if (empty($guid)) {
         $checkSum = $this->_link . $title . $link;
         if ($desc != null) {
             $checkSum .= $desc;
         }
         $guid = md5($checkSum);
     }
     if (!is_null($enclosure) && (is_null($enclosure_size) || is_null($enclosure_type))) {
         trigger_error('Enclosures must have both type and size specified!', YD_ERROR);
     }
     $item = array('title' => $this->_encodeStrings ? YDStringUtil::encodeString($title) : $title, 'link' => $link, 'description' => $this->_encodeStrings ? YDStringUtil::encodeString($desc) : $desc, 'guid' => $guid, 'enclosure' => $enclosure, 'enclosure_size' => $enclosure_size, 'enclosure_type' => $enclosure_type, 'comments' => $commentlink);
     $this->_items[$guid] = $item;
 }
예제 #3
0
 /**
  *	This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can
  *	optionally convert line breaks as well as convert the remaining HTML tags to their entities.
  *
  *	@param $data			The data you want to convert.
  *	@param $convertBr		(optional) Boolean to indicate that new lines should be converted to <br/> tags.
  *							This is turned on by default.
  *	@param $convertTags		(optional) Boolean to indicate that tags should be converted to HTML. This is turned
  *							on by default.
  *	@param $convertLinks	(optional) Boolean to indicate if links should be automatically highlighted or not.
  *							This is turned on by default.
  *  @param $baseUrl         (optional) If you give this a non-null value, it will convert all links to absolute
  *                          links using this url as the base url.
  *
  *	@returns	The HTML equivalent of the string with all the BBCode's converted according to the conversion table
  *				of this class.
  */
 function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null)
 {
     // Encode the references
     $data = YDStringUtil::encodeString($data);
     // Convert the links to BBcode
     if ($convertLinks === true) {
         $data = $this->convertLinks($data);
     }
     // Convert tags if needed
     if ($convertTags === true) {
         $data = str_replace('<', '&lt;', $data);
         $data = str_replace('>', '&gt;', $data);
     }
     // Convert the tags
     $data = preg_replace(array_keys($this->_conversions), array_values($this->_conversions), $data);
     // Open http links in a new window
     $data = str_replace(' href="http://', ' target="_blank" href="http://', $data);
     // Convert tags if needed
     if ($convertBr === true) {
         $data = nl2br(trim($data));
     }
     // Make links absolute if needed
     if (!is_null($baseUrl)) {
         include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php';
         $data = YDUrl::makeLinksAbsolute($data, $baseUrl);
     }
     // Return the data
     return $data;
 }