Part of the EllisLab Network
   
2 of 3
2
RSS Feed plugin
Posted: 20 September 2006 09:31 PM   [ Ignore ]   [ # 16 ]  
Administrator
Avatar
RankRankRankRankRank
Total Posts:  2512
Joined  12-21-2001

The reason there’s no RSS library is becuase RSS files are super easy to generate.  Just create a view file with the appropriate RSS template.  For example, here’s an RSS 2.0 template:

<?xml version="1.0" encoding="<?php echo $encoding; ?>"?>
<rss version="2.0"
    
xmlns:dc="http://purl.org/dc/elements/1.1/"
    
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    
xmlns:admin="http://webns.net/mvcb/"
    
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    
xmlns:content="http://purl.org/rss/1.0/modules/content/">

    <
channel>
    
    <
title><?php echo $feed_name; ?></title>
    <
link><?php echo $feed_url; ?></link>
    <
description><?php echo $page_description; ?></description>
    <
dc:language><?php echo $page_language; ?></dc:language>
    <
dc:creator><?php echo $creator_email; ?></dc:creator>
    <
dc:rights>Copyright <?php echo gmdate("%Y", time()); ?></dc:rights>
    <
dc:date><?php gmdate("%Y-%m-&#xdT;%H:%i:%s%Q" time()); ?></dc:date>
    <
admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />

    
<?php foreach($data as $row): ?>
    
        
<item>
          <
title><?php echo xml_convert($row->title); ?></title>
          <
link><?php echo $row->permalink; ?></link>
          <
guid><?php echo $row->permalink; ?>#When:<?php echo gmdate("%H:%i:&#xsZ;", $row->date); ?></guid>
          
<description><?php echo xml_convert($row->description); ?></description>
          <
dc:subject><?php echo xml_convert($row->category); ?></dc:subject>
          <
dc:date><?php echo gmdate"%Y-%m-&#xdT;%H:%i:%s%Q", $row->date); ?></dc:date>
        </
item>
        
    
<?php endforeach; ?>
    
    
</channel>
</
rss>

Obviously the variables will need to be swapped with real values, and the foreach loop needs to contain a valid query result, but the concept is no different then creating any other type of view file.  You can do the same with atom feeds or whatever. 

The only issue to be aware of with dynamically generated RSS feeds is you need to remember to send the appropriate server header or some browsers will not treat the file as an RSS feed:

@header("Content-Type: text/xml");

The only reason one might want an RSS class is to do “if-modified-since” headers, but other than than, RSS files are a piece of cake.

 Signature 
Profile
MSG
 
 
Posted: 21 September 2006 01:07 AM   [ Ignore ]   [ # 17 ]  
Lab Assistant
RankRank
Total Posts:  144
Joined  09-08-2006

nice rick certainly didnt think about that smile

Profile
 
 
Posted: 21 September 2006 02:32 AM   [ Ignore ]   [ # 18 ]  
Grad Student
Avatar
Rank
Total Posts:  38
Joined  05-12-2006

Yeah, it’s even more delicious than a piece of cake dude;
and if you want to use the date/timezone helper in CI; you will only need to convert it UTC to GMT, (for reason or another with UTC my feed wont get validated )

 Signature 

Your freedom is worth more than you think. Take advantage of it while you can.

Profile
 
 
Posted: 22 September 2006 01:41 PM   [ Ignore ]   [ # 19 ]  
Summer Student
Total Posts:  18
Joined  09-20-2006

Yeah, that is a good point.  I didn’t really think about it, but is pretty simple.  You could probably use the same rss view over again. 

Thanks for pointing that out.

Profile
 
 
Posted: 15 October 2006 05:55 PM   [ Ignore ]   [ # 20 ]  
Grad Student
Avatar
Rank
Total Posts:  63
Joined  03-02-2006

I’m using

header("Content-Type: application/rss+xml");

since text/xml wasn’t validated

Hope this helps

Profile
 
 
Posted: 06 November 2006 04:10 PM   [ Ignore ]   [ # 21 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  320
Joined  04-25-2006

Hi to every here:
I generate the following RSS types:
* OPML
* RSS 0.91
* RSS 1.0
* RSS 2.0
* ATOM
I need to know how set up the correct header and encoding for each of these. Any tip or URL where find?

Cheers and thanks in advance

 Signature 

ReynierPM

Profile
 
 
Posted: 06 November 2006 04:20 PM   [ Ignore ]   [ # 22 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

First result in google is useful.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 06 November 2006 08:01 PM   [ Ignore ]   [ # 23 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  320
Joined  04-25-2006

Hi again:
I have a problem and not know how fix it. I follow all the step posted here and create a view for RSS 0.91 and save it as rss091.php. See the code below:

<?php @header("Content-Type: text/rss+xml"); ?>
<?xml version
="1.0" encoding="utf-8"?>
<rss version="0.91">
<
channel>
<
title><?=($title)?$title:'RSS Portal de Simuladores y Realidad Virtual'?></title>
<
description><?=($description)?$description:'Rich Site Summary Portal de Simuladores y Realidad Virtual'?></description>
<
link><?=anchor(base_url().'/modules/rss/rss_091')?></link>
<
generator>Portal de Simuladores y Realidad Virtual</generator>
<?php foreach($rss_content as $value):?>
<item>
    <
title><?=xml_convert($value->titulo_noticia)?></title>
    <
link><?=xml_convert(base_url().'modules/news/get_current_new/'.$value->id_categoria.'/'.$value->id_noticia)?></link>
    <
description><?=xml_convert($value->resumen_noticia)?></description>
    <
author><?=xml_convert($value->autor)?></author>
    <
category><?=xml_convert($value->id_categoria)?></category>
</
item>
<?php endforeach; ?>
</channel>
</
rss>

In my controller I have this other code:

$data['rss_content'] = $this->news->get_for_rss();
$this->load->view('smp_sindicate/rss091', $data);

But when I load the controller I get this error:

Parse error: parse error, unexpected T_STRING in /var/www/simpro/system/application/views/smp_sindicate/rss091.php on line 2

Where line 2 is:

<?xml version="1.0" encoding="utf-8"?>

What I’m doing wrong?
Cheers and thanks in advance

 Signature 

ReynierPM

Profile
 
 
Posted: 06 November 2006 08:15 PM   [ Ignore ]   [ # 24 ]  
Research Assistant
RankRankRank
Total Posts:  303
Joined  10-17-2006

Nasty error. The xml starts with <?, this is however interpreted by php as the start of a line of code. Obviously this line doesn’t make sense and so the error is triggered.

Simple solution would of course be to echo the second line in php. Then you bypass the problem. I don’t whether the <? can be escaped so php doesn’t see it.

Profile
 
 
Posted: 06 November 2006 08:18 PM   [ Ignore ]   [ # 25 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  320
Joined  04-25-2006

Thanks for your reply. I know that this is the cause for the error but don’t know how to fix it. Is this my question.
Cheers

 Signature 

ReynierPM

Profile
 
 
Posted: 06 November 2006 08:29 PM   [ Ignore ]   [ # 26 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

make line two

echo '<?xml version="1.0" encoding="utf-8"?>';
 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 06 November 2006 08:37 PM   [ Ignore ]   [ # 27 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  320
Joined  04-25-2006

Well I solve this problem but surprise, when I call the controller as:

http://www.site.com/modules/rss/rss_200

Firefox automatically load a window for bookmark this RSS. I add the bookmark but the XML is not loaded correctly or better nothing is obtained as RSS. Any tip for why happen this?
Cheers and thanks for the replies

 Signature 

ReynierPM

Profile
 
 
Posted: 07 November 2006 05:26 AM   [ Ignore ]   [ # 28 ]  
Grad Student
Avatar
Rank
Total Posts:  63
Joined  03-02-2006

i guess it depends on the header type you defined

Profile
 
 
Posted: 03 December 2006 06:21 PM   [ Ignore ]   [ # 29 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  7337
Joined  03-23-2006

To anyone following this thread.  I outlined how I did RSS on my blog.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 04 December 2006 09:49 PM   [ Ignore ]   [ # 30 ]  
Grad Student
Avatar
Rank
Total Posts:  75
Joined  03-06-2006

Very nice Derek…

Profile
 
 
   
2 of 3
2
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120129 Total Logged-in Users: 48
Total Topics: 126266 Total Anonymous Users: 3
Total Replies: 664089 Total Guests: 357
Total Posts: 790355    
Members ( View Memberlist )