Posts: 31
Threads: 5
Joined: Oct 2009
2009-10-24, 08:49:14
(This post was last modified: 2010-01-26, 06:56:25 by modulok30.)
I write RSS feed for GetSimple.
Somebody need it?
Posts: 1,848
Threads: 86
Joined: Aug 2009
I don't have any use for it right now, but I would live to see it...
- Chris
Thanks for using GetSimple! - Download
Please do not email me directly for help regarding GetSimple. Please post all your questions/problems in the forum!
Posts: 31
Threads: 5
Joined: Oct 2009
You can see it here http://www.manage-projects.ru
This is buildrss.php. I placed it in theme/yourthemename/plugins
Code: <?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.
Code: <?php
require_once('plugins/buildrss.php');
?>
Than in template.php i put next code
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 )
third - qty of symbols in description.
I make cron task to generate rss file.
Posts: 31
Threads: 5
Joined: Oct 2009
What about support rss feed in next versions?
Posts: 3
Threads: 1
Joined: Jan 2010
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.
Posts: 31
Threads: 5
Joined: Oct 2009
2010-01-26, 06:44:47
(This post was last modified: 2010-01-26, 06:54:33 by modulok30.)
oobx Wrote: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.
Code: <?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!";
}
?>
Posts: 9
Threads: 1
Joined: Feb 2010
2010-02-18, 12:38:11
(This post was last modified: 2010-02-18, 12:43:39 by linden.)
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
Posts: 31
Threads: 5
Joined: Oct 2009
madguy Wrote: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.
Posts: 972
Threads: 27
Joined: Aug 2009
madguy Wrote: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:
Code: <?php
require_once('plugins/buildrss.php');
?>
- Edit your theme’s template.php to generate the RSS:
Code: $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.
Posts: 9
Threads: 1
Joined: Feb 2010
thnx Zegnåt I will try later today and report back.
Posts: 9
Threads: 1
Joined: Feb 2010
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
Code: $generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}
in default theme "template.php" right after comments before html
Code: <?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
Code: <?php
require_once('plugins/buildrss.php');
?>
GRRRRR
Posts: 31
Threads: 5
Joined: Oct 2009
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.
Posts: 4
Threads: 0
Joined: Apr 2010
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.
Posts: 8
Threads: 3
Joined: May 2010
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);
)
Posts: 972
Threads: 27
Joined: Aug 2009
webget Wrote:Code: if ($ generatRSS == 1) (
buildrssfile ('news', 5.256);
)
5.256 would be wrong, it has to be a comma:
Code: buildrssfile('news', 5, 256);
That might be why it’s not working correctly.
Posts: 3,491
Threads: 106
Joined: Mar 2010
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.
Posts: 1
Threads: 0
Joined: Aug 2010
Zegnåt Wrote:webget Wrote:Code: if ($ generatRSS == 1) (
buildrssfile ('news', 5.256);
)
5.256 would be wrong, it has to be a comma:
Code: 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.
Posts: 1
Threads: 0
Joined: May 2011
2011-05-19, 22:53:53
(This post was last modified: 2011-05-19, 23:05:08 by chrisdel62.)
this is the good process for good run :
create a new directory /{root}/feeds
place blank "index.xml" in this dir /feeds
set 777 acces to this file "index.xml"
create a new directory /{root}/theme/{your_theme}/plugins
copy buildrss.php to in this dir /plugins
include this code behind, in the file "function.php" from your theme manager
Code: <?php
require_once('plugins/buildrss.php');
?>
Than in a new template.php (you have to put a new file in directory /{root}/theme/{your_theme}/)
put this next code
Code: <?php
$generatRSS = $_GET['rss'];
if ($generatRSS==1) {
buildrssfile('news',5,256);
}
?>
enter "http://www.{yoursite}.com/index.php?rss=1&id=rss" in your browser
then you should have this message "RSS FEED updated!"
at end, create a link to "feeds/index.xml"
that's it
after you have to change this codes in the file "buildrss.php" in line
Code: 25 $TITLE_OF_YOUR_RSS_FEED = "{your title}";
26 $DESCRIPTION_OF_YOUR_FEED = "{your description}";
...
128 $rootURL = "{YOUR_DOMAIN}/feeds/";
129 $webroot = "{YOUR_DOMAIN}";
Posts: 2,094
Threads: 54
Joined: Jan 2011
This topic has prompted me to finally implement the creation of RSS feeds in my I18N Search plugin: - you can generate RSS feeds based on any search term (tags or words), see here for a description and this example
- currently the feeds are generated on request. If you experience performance problems I might implement caching - new generation on request, if the last generation is older than x minutes, otherwise the cached feed is used
Posts: 3
Threads: 0
Joined: Dec 2011
@mvicek
Excellent. I've already been using your i8ln plugins to create a news style page and I wanted to make an rss feed of the same. I am able to make the links, but I find I can't really put them (or anything else) on the same page I use to display the searchresults. So I can't put a link to the RSS feed on the home page.
I ultimately want to put it in the sidebar. Is there a public php function I can access to generate that link?
Posts: 3
Threads: 0
Joined: Dec 2011
Actually, after posting that I thought about it some more and came up with a working solution.
I changed my test rss page to a page simply called "rss" so it shows up on my site as /rss/. I then visited that page and viewed the source. At that point, it was a simple matter of copying the a record and img tag into my sidebar.
For anyone trying this, it would look something like this:
Quote:<a href="http://www.bcars.org/rss/?logbook"><img src="http://www.bcars.org/plugins/i18n_search/images/rss.gif" alt="rss"/>Logbook RSS</a>
Posts: 3
Threads: 0
Joined: Dec 2011
One final thought... Google Chrome doesn't display it as an RSS feed, but rather as the raw xml.
I think it's because of how headers or mime-types are sent, but I'm not sure how to fix that. I tried the old trick of adding &filename=rss.xml to the end of the url, but no luck there.
Firefox has no issue showing it as a live bookmark.
Posts: 1,108
Threads: 70
Joined: Aug 2009
put this at the start of you rss.php file before you output anything.
Code: header('Content-type: application/rss+xml');
You might also need to add atom to validate your feed proper;y...
Code: header('Content-type: application/rss+xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
echo '<channel>';
echo '<atom:link href="http://www.yoursite.com/rss" rel="self" type="application/rss+xml" />';
this is mine for my site...
Posts: 2,094
Threads: 54
Joined: Jan 2011
n00dles101 Wrote:put this at the start of you rss.php file before you output anything.
Code: header('Content-type: application/rss+xml');
You might also need to add atom to validate your feed proper;y...
Code: header('Content-type: application/rss+xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
echo '<channel>';
echo '<atom:link href="http://www.yoursite.com/rss" rel="self" type="application/rss+xml" />';
this is mine for my site...
The only part missing was the atom ns and link, http://feed1.w3.org/check.cgi now validates it as fully valid, but still Chrome only shows the XML. Does Chrome handle RSS feeds?
Posts: 1,909
Threads: 86
Joined: Apr 2010
2011-12-01, 18:32:45
(This post was last modified: 2011-12-01, 18:33:45 by jhondavis.)
What's this?
Code: <description><br />
<b>Notice</b>: Undefined index: content in <b>/home/p30318/www/u-la-la.ru/plugins/i18n_search/rss.php</b> on line <b>40</b><br />
<![CDATA[]]></description>
http://u-la-la.ru/rss.html?news
|