Merge pull request #1084 from xm74/master

Harmonize RSS feed with W3C recommendations
This commit is contained in:
Diego Najar 2019-09-19 12:15:43 +02:00 committed by GitHub
commit 239da3bd40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -33,6 +33,11 @@ class pluginRSS extends Plugin {
return $html; return $html;
} }
private function encodeURL($url)
{
return preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url);
}
private function createXML() private function createXML()
{ {
global $site; global $site;
@ -54,10 +59,11 @@ class pluginRSS extends Plugin {
); );
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'; $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<rss version="2.0">'; $xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$xml .= '<channel>'; $xml .= '<channel>';
$xml .= '<atom:link href="'.DOMAIN_BASE.'rss.xml" rel="self" type="application/rss+xml" />';
$xml .= '<title>'.$site->title().'</title>'; $xml .= '<title>'.$site->title().'</title>';
$xml .= '<link>'.$site->url().'</link>'; $xml .= '<link>'.$this->encodeURL($site->url()).'</link>';
$xml .= '<description>'.$site->description().'</description>'; $xml .= '<description>'.$site->description().'</description>';
$xml .= '<lastBuildDate>'.date(DATE_RSS).'</lastBuildDate>'; $xml .= '<lastBuildDate>'.date(DATE_RSS).'</lastBuildDate>';
@ -68,9 +74,9 @@ class pluginRSS extends Plugin {
$page = new Page($pageKey); $page = new Page($pageKey);
$xml .= '<item>'; $xml .= '<item>';
$xml .= '<title>'.$page->title().'</title>'; $xml .= '<title>'.$page->title().'</title>';
$xml .= '<link>'.$page->permalink().'</link>'; $xml .= '<link>'.$this->encodeURL($page->permalink()).'</link>';
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>'; $xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>';
$xml .= '<pubDate>'.$page->date(DATE_RSS).'</pubDate>'; $xml .= '<pubDate>'.date(DATE_RSS,strtotime($page->getValue('dateRaw'))).'</pubDate>';
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>'; $xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>';
$xml .= '</item>'; $xml .= '</item>';
} catch (Exception $e) { } catch (Exception $e) {