Topic: RSS feed for GetSimple
I write RSS feed for GetSimple.
Somebody need it? :P
Last edited by Alexey (2010-01-25 16:56:25)
You are not logged in. Please login or register.
I write RSS feed for GetSimple.
Somebody need it? :P
Last edited by Alexey (2010-01-25 16:56:25)
I don't have any use for it right now, but I would live to see it...
You can see it here http://www.manage-projects.ru
This is buildrss.php. I placed it in theme/yourthemename/plugins
<?php
// Begin Function
function createRSSFile($post_title,$post_description,$post_link,$guid)
{
$returnITEM = "<item>\n";
$returnITEM .= "<guid>".$guid."</guid>\n";
# this will return the Title of the Article.
$returnITEM .= "<title>".$post_title."</title>\n";
# this will return the Description of the Article.
$returnITEM .= "<description>".$post_description."</description>\n";
# this will return the URL to the post.
$returnITEM .= "<link>".$post_link."</link>\n";
$returnITEM .= "</item>\n";
return $returnITEM;
}
// rss_categories - category to rss
// items number
// lenght of descrip)
function buildrssfile($rss_categories,$itemsnumber,$descl)
{
if (empty($rss_categories)) { $rss_categories ='news'; }
if (empty($descl)) { $descl =256; }
if (empty($itemsnumber)) { $itemsnumber =5; }
$TITLE_OF_YOUR_RSS_FEED = "Управление проектами";
$DESCRIPTION_OF_YOUR_FEED = "Все об управлении проектами в одном месте";
$path = tsl('data/pages/');
$counter = '0';
$table = '';
//display all pages
$filenames = getFiles($path);
$count="0";
$pagesArray = array();
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if (isFile($file, $path, 'xml')) {
$data = getXML($path .$file);
if ($data->parent == $rss_categories) {
$status = $data->menuStatus;
//$pagesArray[$count]['title'] = $data->title;
$pagesArray[$count]['title'] = html_entity_decode($data->title, ENT_QUOTES, 'UTF-8');
$pagesArray[$count]['parent'] = $data->parent;
$pagesArray[$count]['menuStatus'] = $data->menuStatus;
$pagesArray[$count]['private'] = $data->private;
$pagesArray[$count]['content'] = htmlspecialchars($data->content, ENT_QUOTES, 'UTF-8');
//$pagesArray[$count]['content'] = $data->content;
if ($data->parent != '') {
$parentdata = getXML($path . $data->parent .'.xml');
$parentTitle = $parentdata->title;
$pagesArray[$count]['sort'] = $parentTitle .' '. $data->title;
} else {
$pagesArray[$count]['sort'] = $data->title;
}
$pagesArray[$count]['url'] = $data->url;
$pagesArray[$count]['date'] = $data->pubDate;
$parentTitle = '';
$count++;
}
}
}
}
// Lets build the page
$filename = "feeds/index.xml";
$rootURL = "http://www.manage-projects.ru/feeds/";
$webroot = "http://www.manage-projects.ru/";
$latestBuild = date("r");
// Lets define the the type of doc we're creating.
$createXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$createXML .= "<rss version=\"0.92\">\n";
$createXML .= "<channel>
<title>".$TITLE_OF_YOUR_RSS_FEED."</title>
<link>".$rootURL."</link>
<description>".$DESCRIPTION_OF_YOUR_FEED."</description>
<lastBuildDate>".$latestBuild."</lastBuildDate>
<docs></docs>
<language>ru</language>
";
// Lets get the results
$ff=0;
while ($pagesArray[$ff]<>'') {
$item = $pagesArray[$ff];
if (empty($item['parent'])) {
$page = $webroot.$item['url'];
} else {
$page = $webroot.$item['parent']."/".$item['url'];
}
$pieces = explode(" ", $item['content']);
$feedcontent = '';
$rr=0;
while (strlen($feedcontent)<$descl) {
$feedcontent .= $pieces[$rr]." ";
$rr++;
}
$description = $feedcontent;
$title = $item['title'];
$guid = $item['date'];
$createXML .= createRSSFile($title,$description,$page,$guid);
$ff++;
}
$createXML .= "</channel>\n </rss>";
// Finish it up
$filehandle = fopen($filename,"w") or die("Can't open the file");
fwrite($filehandle,$createXML);
fclose($filehandle);
echo "XML Sitemap updated!";
}
?>I include it in function.php in theme.
<?php
require_once('plugins/buildrss.php');
?>Than in template.php i put next code
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}where first parametr - name of parent page for news for example.
second - quantity of items add in rss (it is not work yet :D )
third - qty of symbols in description.
I make cron task to generate rss file.
What about support rss feed in next versions?
What about support rss feed in next versions?
Seconded! RSS should not be hard and it's definitely a nice feature. Thanks, Alexey. I'll try out your code.
Alexey wrote:What about support rss feed in next versions?
Seconded! RSS should not be hard and it's definitely a nice feature. Thanks, Alexey. I'll try out your code.
Thank you!
Since publication this code i've already change it.
If somebody know how can minimize this code please let me know.
<?php
// Begin Function
function createRSSFile($post_title,$post_description,$post_link,$guid)
{
$returnITEM = "<item>\n";
$returnITEM .= "<title>".$post_title."</title>\n";
$returnITEM .= "<link>".$post_link."</link>\n";
$returnITEM .= "<description>".$post_description."</description>\n";
$returnITEM .= "<pubDate>".$guid."</pubDate>\n";
$returnITEM .= "<guid>".$post_link."</guid>\n";
$returnITEM .= "</item>\n";
return $returnITEM;
}
// rss_categories - what category public to rss
// items number
// lenght of descrip)
function buildrssfile($rss_categories,$itemsnumber,$descl)
{
if (empty($rss_categories)) { $rss_categories ='news'; } // only pages from news category
if (empty($descl)) { $descl =256; } //lenght of description
if (empty($itemsnumber)) { $itemsnumber =5; } // number of items in rss
$TITLE_OF_YOUR_RSS_FEED = "YOUR_TITLE_OF_RSS";
$DESCRIPTION_OF_YOUR_FEED = "DESCRIPTION_OF_RSS";
$path = tsl('data/pages/');
$counter = '0';
$table = '';
//display all pages
$filenames = getFiles($path);
$count="0";
$pagesArray = array();
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if (isFile($file, $path, 'xml')) {
$data = getXML($path .$file);
if ($data->parent == $rss_categories) {
if ($data->private<>'Y') {
$status = $data->menuStatus;
//$pagesArray[$count]['title'] = $data->title;
$pagesArray[$count]['title'] = html_entity_decode($data->title, ENT_QUOTES, 'UTF-8');
$pagesArray[$count]['parent'] = $data->parent;
$pagesArray[$count]['menuStatus'] = $data->menuStatus;
$pagesArray[$count]['private'] = $data->private;
$pagesArray[$count]['content'] = htmlspecialchars($data->content, ENT_QUOTES, 'UTF-8');
//$pagesArray[$count]['content'] = $data->content;
if ($data->parent != '') {
$parentdata = getXML($path . $data->parent .'.xml');
$parentTitle = $parentdata->title;
$pagesArray[$count]['sort'] = $parentTitle .' '. $data->title;
} else {
$pagesArray[$count]['sort'] = $data->title;
}
$pagesArray[$count]['url'] = $data->url;
$pagesArray[$count]['date'] = $data->pubDate;
$pagesArray[$count]['sortdate'] = strtotime($data->pubDate);
$parentTitle = '';
$count++;
}
}
}
}
}
//sort items by date
$allt = $count;
$timest =0;
$ddd=0;
while ($ddd < $allt) {
$count=1;
while ($count < $allt) { // this block need to sort pages by publication date if you have better way please let me know
if ($pagesArray[$count]['sortdate']>$pagesArray[$count-1]['sortdate']) {
$temp_title = $pagesArray[$count]['title'];
$temp_parent = $pagesArray[$count]['parent'];
$temp_menuStatus = $pagesArray[$count]['menuStatus'] ;
$temp_private = $pagesArray[$count]['private'];
$temp_content = $pagesArray[$count]['content'];
$temp_sort = $pagesArray[$count]['sort'];
$temp_url = $pagesArray[$count]['url'];
$temp_date = $pagesArray[$count]['date'];
$temp_sortdate = $pagesArray[$count]['sortdate'];
$pagesArray[$count]['title'] = $pagesArray[$count-1]['title'];
$pagesArray[$count]['parent'] = $pagesArray[$count-1]['parent'];
$pagesArray[$count]['menuStatus'] = $pagesArray[$count-1]['menuStatus'] ;
$pagesArray[$count]['private'] = $pagesArray[$count-1]['private'];
$pagesArray[$count]['content'] = $pagesArray[$count-1]['content'];
$pagesArray[$count]['sort'] = $pagesArray[$count-1]['sort'];
$pagesArray[$count]['url'] = $pagesArray[$count-1]['url'];
$pagesArray[$count]['date'] = $pagesArray[$count-1]['date'];
$pagesArray[$count]['sortdate'] = $pagesArray[$count-1]['sortdate'];
$pagesArray[$count-1]['title'] =$temp_title;
$pagesArray[$count-1]['parent'] = $temp_parent;
$pagesArray[$count-1]['menuStatus'] =$temp_menuStatus;
$pagesArray[$count-1]['private'] = $temp_private;
$pagesArray[$count-1]['content'] = $temp_content;
$pagesArray[$count-1]['sort'] = $temp_sort;
$pagesArray[$count-1]['url'] = $temp_url ;
$pagesArray[$count-1]['date'] = $temp_date;
$pagesArray[$count-1]['sortdate'] = $temp_sortdate;
}
//}
//print_r($pagesArray);
$count++;
}
$ddd++;
}
// Lets build the page
$filename = "feeds/index.xml";
$rootURL = "YOUR_DOMAIN/feeds/";
$webroot = "YOUR_DOMAIN";
$latestBuild = date("r");
// Lets define the the type of doc we're creating.
$createXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$createXML .= "<rss version=\"2.0\">\n";
$createXML .= "<channel>
<title>".$TITLE_OF_YOUR_RSS_FEED."</title>
<link>".$rootURL."</link>
<description>".$DESCRIPTION_OF_YOUR_FEED."</description>
<lastBuildDate>".$latestBuild."</lastBuildDate>
<docs></docs>
<language>ru</language>
";
// Lets get the results
$ff=0;
while ($pagesArray[$ff]<>'') {
$item = $pagesArray[$ff];
if (empty($item['parent'])) {
$page = $webroot.$item['url'];
} else {
$page = $webroot.$item['parent']."/".$item['url'];
}
$pieces = explode(" ", $item['content']);
$feedcontent = '';
$rr=0;
while (strlen($feedcontent)<$descl) {
$feedcontent .= $pieces[$rr]." ";
$rr++;
}
$description = $feedcontent;
$title = $item['title'];
$guid = $item['date'];
$createXML .= createRSSFile($title,$description,$page,$guid);
$ff++;
}
$createXML .= "</channel>\n </rss>";
// Finish it up
$filehandle = fopen($filename,"w") or die("Can't open the file");
fwrite($filehandle,$createXML);
fclose($filehandle);
echo "RSS FEED updated!";
}
?>Last edited by Alexey (2010-01-25 16:54:33)
will this work in getsimple 2.0?
the only file name "function.php" is in admin/inc/function.php and it is
"# discontinued as of version 2.0"
Do I now place buildrss.php admin/plugins/ or make a new plugins directory in theme/Default_Simple
Last edited by madguy (2010-02-17 22:43:39)
will this work in getsimple 2.0?
the only file name "function.php" is in admin/inc/function.php and it is
"# discontinued as of version 2.0"
Do I now place buildrss.php admin/plugins/ or make a new plugins directory in theme/Default_Simple
Hi
I have not try it on 2.0 yet.
Do I now place buildrss.php admin/plugins/ or make a new plugins directory in theme/Default_Simple
I don’t know whether it will still work with version 2.0, but unless you rewrite the code to be an actual plugin you don’t want it in /admin/plugins/.
You should just follow the original installation instructions:
Create a new folder in your theme called ‘plugins’.
Create buildrss.php in this folder with the script as found here.
Create functions.php in your theme folder and put this in it:
<?php
require_once('plugins/buildrss.php');
?>Edit your theme’s template.php to generate the RSS:
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}All of this could be found in this topic, but I thought I’d list it here for you.
thnx Zegnåt I will try later today and report back.
I cant seemto get this to work
1) create a folder name "feeds" at GetSimple root
2) creat a blank "index.xml" in "feeds"
3) set the above two to 777
4) made a new page "news" in admin panel with some text "blah blah blah"
5) add
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}in default theme "template.php" right after comments before html
<?php
/****************************************************
*
* @File: template.php
* @Package: GetSimple
* @Action: Default theme for the GetSimple CMS
*
*****************************************************/
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}
?>6) create a folder "plugins" in theme and place "buildrss.php" there
7) Create functions.php in your theme folder and put this in it
<?php
require_once('plugins/buildrss.php');
?>GRRRRR
This script collect in RSS only childs of 'news' page.
You need to create some.
and than you type in browser www.yoursite.com?rss=1
I make it because i generate my feed with cron.
If you can't run a cron job, how do you manually generate feeds?
I followed the same steps as madguy, and I have child pages under News, but I am not seeing any generated feeds.
it does not really make it work as the plugins to generate rss
if someone could explain or send larger files because I have tried and do not know how to operate it.
Not that some of my template paste this code:
$ GeneratRSS = $ _GET ['rss'];
if ($ generatRSS == 1) (
buildrssfile ('news', 5.256);
)
if ($ generatRSS == 1) ( buildrssfile ('news', 5.256); )
5.256 would be wrong, it has to be a comma:
buildrssfile('news', 5, 256);That might be why it’s not working correctly.
Apart from what Zegnåt points, there are some other errors: there shouldn't be a blank space between $ and the variable name. Also check that uppercase G letter in GeneratRSS -- it should be lower case.
webget wrote:if ($ generatRSS == 1) ( buildrssfile ('news', 5.256); )5.256 would be wrong, it has to be a comma:
buildrssfile('news', 5, 256);That might be why it’s not working correctly.
Yes, I also think same as her. it has to use comma.
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 9 official extensions. Copyright © 2003–2009 PunBB.