Contao\Feed::generateRss PHP Method

generateRss() public method

Generate an RSS 2.0 feed and return it as XML string
public generateRss ( ) : string
return string The RSS feed markup
    public function generateRss()
    {
        $this->adjustPublicationDate();
        $xml = '<?xml version="1.0" encoding="' . \Config::get('characterSet') . '"?>';
        $xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
        $xml .= '<channel>';
        $xml .= '<title>' . \StringUtil::specialchars($this->title) . '</title>';
        $xml .= '<description>' . \StringUtil::specialchars($this->description) . '</description>';
        $xml .= '<link>' . \StringUtil::specialchars($this->link) . '</link>';
        $xml .= '<language>' . $this->language . '</language>';
        $xml .= '<pubDate>' . date('r', $this->published) . '</pubDate>';
        $xml .= '<generator>Contao Open Source CMS</generator>';
        $xml .= '<atom:link href="' . \StringUtil::specialchars(\Environment::get('base') . 'share/' . $this->strName) . '.xml" rel="self" type="application/rss+xml" />';
        foreach ($this->arrItems as $objItem) {
            $xml .= '<item>';
            $xml .= '<title>' . \StringUtil::specialchars(strip_tags($objItem->title)) . '</title>';
            $xml .= '<description><![CDATA[' . preg_replace('/[\\n\\r]+/', ' ', $objItem->description) . ']]></description>';
            $xml .= '<link>' . \StringUtil::specialchars($objItem->link) . '</link>';
            $xml .= '<pubDate>' . date('r', $objItem->published) . '</pubDate>';
            // Add the GUID
            if ($objItem->guid) {
                // Add the isPermaLink attribute if the guid is not a link (see #4930)
                if (strncmp($objItem->guid, 'http://', 7) !== 0 && strncmp($objItem->guid, 'https://', 8) !== 0) {
                    $xml .= '<guid isPermaLink="false">' . $objItem->guid . '</guid>';
                } else {
                    $xml .= '<guid>' . $objItem->guid . '</guid>';
                }
            } else {
                $xml .= '<guid>' . \StringUtil::specialchars($objItem->link) . '</guid>';
            }
            // Enclosures
            if (is_array($objItem->enclosure)) {
                foreach ($objItem->enclosure as $arrEnclosure) {
                    $xml .= '<enclosure url="' . $arrEnclosure['url'] . '" length="' . $arrEnclosure['length'] . '" type="' . $arrEnclosure['type'] . '" />';
                }
            }
            $xml .= '</item>';
        }
        $xml .= '</channel>';
        $xml .= '</rss>';
        return $xml;
    }