...
 
Commits (5)
......@@ -105,6 +105,8 @@
// Probably the same than the blog's description.
$author = 'contact+rss@yourdomain.tld (My Name)'; // author's contact informations. If you are the sole author,
// you do not need to fetch this information through MySQL.
$commentLink = '#comments'; // Pattern for commentary section.
// In this case $articleLink . '#comments'
// Header
......@@ -162,6 +164,8 @@
// There is no reason to change this item.
$rssfeed .= ' <docs>http://www.rssboard.org/rss-specification</docs>';
$rssfeed .= "\n";
$rssfeed .= ' <generator>MySQLiToRSS</generator>';
$rssfeed .= "\n";
// MySQL connect
$conn = new mysqli($servername, $username, $password, $dbname);
......@@ -178,11 +182,27 @@
// Store the SQL query in $result
$result = $conn->query($query) or die ("Could not execute query");
// Boolean used to create pubDate and lastBuildDate
// for the channel
// Because it is not clear the different between the 2,
// I set them equal.
$pubDate = false;
// For each article
while($row = $result->fetch_assoc())
{
// Extract row
extract($row);
// If pubDate is not set for the channel
if(!$pubDate)
{
// Add pubDate and lastBuildDate to match the date of last published article
$rssfeed .= ' <pubDate>' . date("D, d M Y H:i:s O", strtotime($creationdate)) . '</pubDate>';
$rssfeed .= "\n";
$rssfeed .= ' <lastBuildDate>' . date("D, d M Y H:i:s O", strtotime($creationdate)) . '</lastBuildDate>';
$rssfeed .= "\n";
// Do not add pubDate and lastBuildDate for the channel anymore
$pubDate = true;
}
// Begin <item>
$rssfeed .= ' <item>';
$rssfeed .= "\n";
......@@ -222,6 +242,9 @@
// Author's contact informations
$rssfeed .= ' <author>' . $author . '</author>';
$rssfeed .= "\n";
// URL to the commentary section of the article
$rssfeed .= ' <comments>' . $articleLink . $commentLink . '</comments>';
$rssfeed .= "\n";
// Tags
// MySQL Query to fetch all tag's ids for this article, referenced as $id
......@@ -239,7 +262,7 @@
// Extract the tag from the MySQL Query
extract($tags);
// Add tag
$rssfeed .= '<category>' . $tag . '</category>';
$rssfeed .= ' <category>' . $tag . '</category>';
$rssfeed .= "\n";
}
......@@ -253,6 +276,7 @@
$rssfeed .= "\n";
// End <rss>
$rssfeed .= '</rss>';
$rssfeed .= "\n";
// Print the string
echo $rssfeed;
......