Skip to content

Commit cd5f2c4

Browse files
committed
add feed_url property
The W3C feed validator recommends adding an atom:link tag with the URL of the feed itself. This adds a feed_url property to Channel which is used in an atom:link tag.
1 parent de25f01 commit cd5f2c4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

examples/simple-feed.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
->title('Channel Title')
1818
->description('Channel Description')
1919
->url('http://blog.example.com')
20+
->feed_url('http://blog.example.com/rss')
2021
->language('en-US')
2122
->copyright('Copyright 2012, Foo Bar')
2223
->pubDate(strtotime('Tue, 21 Aug 2012 19:50:37 +0900'))

src/Suin/RSSWriter/Channel.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Channel implements ChannelInterface
1414
/** @var string */
1515
protected $url;
1616

17+
/** @var feed_url */
18+
protected $feed_url;
19+
1720
/** @var string */
1821
protected $description;
1922

@@ -60,6 +63,17 @@ public function url($url)
6063
return $this;
6164
}
6265

66+
/**
67+
* Set URL of this feed
68+
* @param string $url
69+
* @return $this;
70+
*/
71+
public function feed_url($url)
72+
{
73+
$this->feed_url = $url;
74+
return $this;
75+
}
76+
6377
/**
6478
* Set channel description
6579
* @param string $description
@@ -180,6 +194,13 @@ public function asXML()
180194
$xml->addChild('link', $this->url);
181195
$xml->addChild('description', $this->description);
182196

197+
if($this->feed_url !== null) {
198+
$link = $xml->addChild('atom:link', '', "http://www.w3.org/2005/Atom");
199+
$link->addAttribute('href',$this->feed_url);
200+
$link->addAttribute('type','application/rss+xml');
201+
$link->addAttribute('rel','self');
202+
}
203+
183204
if ($this->language !== null) {
184205
$xml->addChild('language', $this->language);
185206
}

0 commit comments

Comments
 (0)