logo

Feeds API
As of v0.9.0 eoCMS uses a simple API for displaying feeds on your website.
Currently it supports the following:
  • RSS 0.92

  • RSS 2

  • JSON


Adding a feed is simple. Here you can see the news feed. Below is where the magic happens.

Code:
while ($fetch = call('sql_fetch_array', $query)) {
$feeds[] = array('link' => $settings['site_url'] . '/news/&readmore=' . $fetch[0],
'title' => html_entity_decode(htmlspecialchars_decode($fetch[1], ENT_QUOTES), ENT_QUOTES),
'description' => $fetch[2],
'category' => $fetch[3],
'date' => $fetch[4],
'guid' => $settings['site_url'] . '/news/&readmore=' . $fetch[0]);
}


As you can see, all the data is assigned to a variable named $feeds[] inside an array. Inside $feeds we need 5 keys: link, title, description, category, date and guid. Usually guid and link will be the same. Link/guid is the location of where the item exists. In this case it is:

Code:
$settings['site_url'] . '/news/&readmore=' . $fetch[0]


The title is the text to go above the description; the description is what you want the content to be. The category is to allow browsers to sort each item, this is optional but must be set so if you do not have a category, then leave category as:

Code:
'category'=>''


The date is the unixtimestamp which is then formatted by eoCMS into the appropriate date.

You may have noticed that we have $fetch[number here]. This you may not have seen before. The number represents the column in the query; note: these start at 0.
Here is the query:

Code:
$query = call('sql_query', "SELECT n.id, n.subject, n.content, nc.name, n.time_created, n.visibility FROM news AS n LEFT OUTER JOIN news_categories AS nc ON n.cat=nc.id WHERE (n.start_time='0' || n.start_time<=" . time() . ") AND (n.end_time='0' || n.end_time>=" . time() . ")" . $cat . " ORDER BY n.time_created DESC LIMIT " . $_GET['limit'] . "");


As you can see, n.id is the first column we select therefore to use that data we use $fetch[0]. n.subject is the second so it will be $fetch[1] and so on. This must be done due to the nature of joins with SQLite. Which adds the table name or the name you set I.E: n to the key in the array. MySQL does not do this and so the numbers are used by your feed to work with both databases.

Lastly, we have the $atom_link which is required by RSS 2. This goes after the while().

Code:
$atom_link = $settings['site_url'] . '/index.php?act=feeds&type=news';

The $atom_link is the URL of the location of the feed. It will always be
Code:
$settings['site_url'] . '/index.php?act=feeds&

With type= after. The type is the name of your file. For example if the feed's file name is "hello.php" then type=hello. This means you must be careful about what characters you use in the filename.

Formatted by: Jake
Ratings
Rating: 5/5 (3 Votes)

Comments
Demonic on 2nd May, 2009, 02:03:48 AM
Looks good.
smooch1502 on 14th May, 2009, 04:58:11 AM
:D Grin Grin Grin
James on 18th May, 2009, 09:17:21 PM
does this include the bbc news and weather would all of this work ?
eva on 25th June, 2009, 11:20:49 AM
Oh... nice  Surprised
smooch1502 on 26th June, 2009, 06:37:49 AM
cool great guide
Arwym on 10th October, 2009, 12:02:20 AM
Any support for Atom feeds in the near future?  Many blogging services (like Vox) use Atom, and allow users to import their Atom feeds from other blog platforms.  Smile
Arwym on 10th October, 2009, 12:12:22 AM
@James: This is not a feed aggregator; it only generates feeds of your website's content.



0.54 seconds Queries: 10