RSS feed
A website can return an RSS feed automatically generated with the abstracts or the contents of one or more threads.
You just need to assign thread numbers to the parameter $rss_thread
and set the parameter $rss_description
to 'abstract'
or 'content'
in config.inc.
The action rssfeed
builds each entry of the feed by extracting the title, the creation date and the abstracts or the contents of type text
of all the active nodes of the threads defined by $rss_thread
.
rssfeed.php
- require_once 'filemimetype.php';
- function rssfeed($lang) {
- global $rss_thread, $rss_description;
- $feed_content = $rss_description == 'content';
- $itemlist = array();
- if ($rss_thread) {
- $sqllang=db_sql_arg($lang, false);
- $tabthreadnode=db_prefix_table('thread_node');
- $tabnode=db_prefix_table('node');
- $tabnodelocale=db_prefix_table('node_locale');
- $where=(is_array($rss_thread) ? 'tn.thread_id IN (' . implode(',', $rss_thread) . ')' : "tn.thread_id=$rss_thread") . ' AND tn.ignored=FALSE';
- if ($feed_content) {
- $tabnodecontent=db_prefix_table('node_content');
- $tabcontenttext=db_prefix_table('content_text');
- $sql="SELECT nl.name AS node_name, nl.title AS node_title, UNIX_TIMESTAMP(n.created) AS node_created, nl.image AS node_image, ct.text AS content_text FROM $tabthreadnode tn JOIN $tabnode n ON n.node_id=tn.node_id JOIN $tabnodelocale nl ON nl.node_id=tn.node_id AND nl.locale=$sqllang LEFT JOIN $tabnodecontent nc ON nc.node_id=n.node_id AND nc.content_type='text' AND nc.ignored=FALSE LEFT JOIN $tabcontenttext ct ON ct.content_id=nc.content_id AND ct.locale=nl.locale WHERE $where ORDER BY tn.number";
- }
- else {
- $sql="SELECT nl.name AS node_name, nl.title AS node_title, UNIX_TIMESTAMP(n.created) AS node_created, nl.image AS node_image, nl.abstract AS node_abstract FROM $tabthreadnode tn JOIN $tabnode n ON n.node_id=tn.node_id JOIN $tabnodelocale nl ON nl.node_id=tn.node_id AND nl.locale=$sqllang WHERE $where ORDER BY n.created DESC";
- }
- $r = db_query($sql);
- if ($r) {
- foreach ($r as $node) {
- extract($node);
- $title = $node_title;
- $uri = false; // "/$lang/$node_name";
- $created = $node_created;
- $description = preg_replace('/(\r\n|\r|\n)+/', ' - ', preg_replace('/[\t ]+/', ' ', strip_tags($feed_content ? $content_text : $node_abstract)));
- $image_uri = false; // $node_image;
- $image_size = $image_uri ? filesize(ROOT_DIR . $image_uri) : 0;
- $image_type = $image_uri ? file_mime_type(ROOT_DIR . $image_uri) : false;
- $itemlist[] = compact('title', 'uri', 'created', 'description', 'image_uri', 'image_size', 'image_type');
- }
- }
- }
- $description = translate('description', $lang);
- $output = view('rssfeed', false, compact('lang', 'description', 'itemlist'));
- return $output;
- }
If $rss_description
is 'content'
, the feed is built with the contents of type text of the nodes of the threads defined by $rss_thread
and sorted by their numbers, otherwise, the feed is directly built with the abstracts of the nodes and sorted by their creation dates.
The description of the feed is taken from the description of the website defined in strings.inc.
To associate the simplified URL of each node to its title in the list of items, set $uri
to "/$lang/$node_name"
.
IMPORTANT: Add the thread numbers in $rss_thread
to the configuration parameter $default_folder
in config.inc.
If nodes have images, set $image_uri
to $node_name
to add them to the feed.
The tag <head>
of the HTML document of a page always contains a link to the RSS feed:
To give access to the RSS feed in a page, add a link like in the views link
and social
, views which can be simply inserted in the home page with a content of type insertion
:
The logo displayed on the page of the RSS feed is the image contained in the file siteqr.png in the folder logos.
See the tag <image>
generated by the view rssfeed
:
- <image>
- <title><?php echo $sitename; ?></title>
- <?php if ($lang): ?>
- <link><?php echo $base_url; ?>/<?php echo $lang; ?></link>
- <?php else: ?>
- <link><?php echo $base_url; ?></link>
- <?php endif; ?>
- <url><?php echo $base_url; ?>/logos/siteqr.png</url>
- <width>50</width>
- </image>
Comments