Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » RSS Feed: Description Field Escaping HTML Tags

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1535 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    RSS Feed: Description Field Escaping HTML Tags Link to this post

    I am unable to get any of my local SilverStripe RSS feeds to display properly in any browser because the HTML tags are being escaped.

    Here is the markup from RSSFeed.ss:

    <description>$Description.AbsoluteLinks.EscapeXML</description>

    Why is this? I can't think of any reason I would want < and > to display as &lt; and &gt; in a browser. But when I just use $Description.XML I get parsing errors. So my workaround was to use $Description.FirstParagraph(html) but then I can't figure a way to use this with AbsoluteLinks -- which I need in order for images to show up in the feed. Can someone explain to me why we are escaping tags in this template? I just want the HTML from the content to display in the feed. Why wouldn't I??

    Thanks in advance,
    Garrett

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: RSS Feed: Description Field Escaping HTML Tags Link to this post

    I ended up adding a function to strip invalid XML:

    /**
        * Return the value of the field with relative links converted to absolute urls.
        * @return string
        */
       function AbsoluteLinks() {
          $val = $this->StripInvalidXml($this->value);
          return HTTP::absoluteURLs($val);
       }

    /**
        * Removes invalid XML
        *
        * @access public
        * @param string $value
        * @return string
        */
       function StripInvalidXml($value)
       {
        $ret = "";
        $current;
        if (empty($value))
        {
        return $ret;
        }
       
        $length = strlen($value);
        for ($i=0; $i < $length; $i++)
        {
        $current = ord($value{$i});
        if (($current == 0x9) ||
        ($current == 0xA) ||
        ($current == 0xD) ||
        (($current >= 0x20) && ($current <= 0xD7FF)) ||
        (($current >= 0xE000) && ($current <= 0xFFFD)) ||
        (($current >= 0x10000) && ($current <= 0x10FFFF)))
        {
        $ret .= chr($current);
        }
        else
        {
        $ret .= " ";
        }
        }
        return $ret;
       }

    //Garrett

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: RSS Feed: Description Field Escaping HTML Tags Link to this post

    That is in sapphire/core/model/Text.php.

  • phawley
    Avatar
    Community Member
    21 Posts

    Re: RSS Feed: Description Field Escaping HTML Tags Link to this post

    I am having this same problem, and just figured out a fix for it:

    remove .EscapeXML in line 13 of sapphire/templates/RSSFeed.ss from :

    <% if Description %><description>$Description.AbsoluteLinks.EscapeXML</description><% end_if %>

    and add HTML in line 278 of sapphire/api/RSSFeed.php:

    return $this->rssField($this->descriptionField, 'HTMLText');

    Hopefully this helps someone else.

  • tcw
    Avatar
    Community Member
    1 Post

    Re: RSS Feed: Description Field Escaping HTML Tags Link to this post

    Hey thanks @phawley this helped a lot

    1535 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.