2014-06-27, 17:06:04
Update RSS generation function.
If you create a post with a future date of publish, this appears in RSS.
This modification of Blog.php file solves the problem, but there are some things to improve:
Here the Blog.php code for RSS feed generation:
If you create a post with a future date of publish, this appears in RSS.
This modification of Blog.php file solves the problem, but there are some things to improve:
- The RSS only updates when create, modify and save any post.
- So, when deleting a post, it remains on RSS feed
- So, you can publish any post with future date and it will neve be included on RSS feed until you create or save any time
- It will be a better solution to allow rss feed to be a dinamic PHP instead a single generated file... this will solve all the bugs
Here the Blog.php code for RSS feed generation:
PHP Code:
/**
* Generates RSS Feed of posts
*
* @return bool
*/
public function generateRSSFeed($save=true, $filtered=false)
{
global $SITEURL;
$post_array = glob(BLOGPOSTSFOLDER . "/*.xml");
if($save == true)
{
$locationOfFeed = $SITEURL."rss.rss";
$posts = $this->listPosts(true, true);
}
else
{
$locationOfFeed = $SITEURL."plugins/blog/rss.php";
if($filtered != false)
{
$posts = $this->filterPosts($filtered['filter'], $filtered['value']);
}
else
{
$posts = $this->listPosts(true, true);
}
}
$RSSString = "";
$RSSString .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$RSSString .= "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n";
$RSSString .= "<channel>\n";
$RSSString .= "<title>".$this->getSettingsData("rsstitle")."</title>\n";
$RSSString .= "<link>".$locationOfFeed."</link>\n";
$RSSString .= "<description>".$this->getSettingsData("rssdescription")."</description>\n";
$RSSString .= "<lastBuildDate>".date("D, j M Y H:i:s T")."</lastBuildDate>\n";
$RSSString .= "<language>".str_replace("_", "-",$this->getSettingsData("lang"))."</language>\n";
$RSSString .= '<atom:link href="'.$locationOfFeed."\" rel=\"self\" type=\"application/rss+xml\" />\n";
$limit = $this->getSettingsData("rssfeedposts");
array_multisort(array_map('filemtime', $post_array), SORT_DESC, $post_array);
$post_array = array_slice($post_array, 0, $limit);
foreach ($posts as $post)
{
$blog_post = simplexml_load_file($post['filename']);
$RSSDate = $blog_post->date;
// This solves the problem to publish post with
// a date higer than now.
// get the actual time.
$date_now = strtotime(date("d-m-Y H:i:00",time()));
// get the post time.
$date = strtotime($RSSDate);
// if post time is lower than actual time, then save data in feed.
if ($date <= $date_now)
{
$RSSTitle = $blog_post->title;
$RSSBody = html_entity_decode(str_replace(" ", " ", substr(htmlspecialchars(strip_tags($blog_post->content)),0,200)));
$ID = $blog_post->slug;
$RSSString .= "<item>\n";
$RSSString .= "\t <title>".$RSSTitle."</title>\n";
$RSSString .= "\t <pubDate>".$RSSDate."</pubDate>\n";
$RSSString .= "\t <link>".$this->get_blog_url('post').$ID."</link>\n";
$RSSString .= "\t <guid>".$this->get_blog_url('post').$ID."</guid>\n";
$RSSString .= "\t <description>".htmlspecialchars($RSSBody)."</description>\n";
if(isset($blog_post->category) and !empty($blog_post->category) and $blog_post->category!='')
{
$RSSString .= "\t <category>".$blog_post->category."</category>\n";
}
$RSSString .= "</item>\n";
}// end if $date <= $date_now
}
$RSSString .= "</channel>\n";
$RSSString .= "</rss>\n";
if($save==true)
{
if(!$fp = fopen(GSROOTPATH."rss.rss",'w'))
{
echo "Could not open the rss.rss file";
exit();
}
if(!fwrite($fp,$RSSString))
{
echo "Could not write to rss.rss file";
exit();
}
fclose($fp);
}
else
{
return $RSSString;
}
}