2

RSS feed

RSS

Configuring a RSS feed can be limited to creating a dedicated thread whose nodes will be used to automatically build the XML document. You just need to assign the thread number to the configuration parameter $rss_thread in config.inc. This behavior is coded by the action rssfeed which extracts the title, the creation date and the contents of type text of all the active nodes of the thread $rss_thread to build each entry of the feed.

rssfeed.php
  1. function rssfeed($lang) {
  2.     global $rss_thread;
  3.  
  4.     $itemlist = array();
  5.  
  6.     if ($rss_thread) {
  7.         $sqllang=db_sql_arg($lang, false);
  8.  
  9.         $tabthreadnode=db_prefix_table('thread_node');
  10.         $tabnode=db_prefix_table('node');
  11.         $tabnodelocale=db_prefix_table('node_locale');
  12.         $tabnodecontent=db_prefix_table('node_content');
  13.         $tabcontenttext=db_prefix_table('content_text');
  14.  
  15.         $where="tn.thread_id=$rss_thread AND tn.ignored=FALSE";
  16.  
  17.         $sql="SELECT nl.name AS node_name, nl.title AS node_title, UNIX_TIMESTAMP(n.created) AS node_created, 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";
  18.  
  19.         $r = db_query($sql);
  20.  
  21.         if ($r) {
  22.             foreach ($r as $node) {
  23.                 extract($node);
  24.                 $title = $node_title;
  25.                 $uri = false;   // $lang . '/' . $node_name;
  26.                 $created = $node_created;
  27.                 $description = strip_tags($content_text);
  28.                 $itemlist[] = compact('title', 'uri', 'created', 'description');
  29.             }
  30.         }
  31.     }
  32.  
  33.     $description = translate('description', $lang);
  34.  
  35.     $output = view('rssfeed', false, compact('lang', 'description', 'itemlist'));
  36.  
  37.     return $output;
  38. }

The description of the feed is taken from the description of the website defined in strings.inc.

You can modify the action rssfeed to display just the titles of the nodes of a thread with no particular structure and add a link to each title.

  1.         $tabthreadnode=db_prefix_table('thread_node');
  2.         $tabnode=db_prefix_table('node');
  3.         $tabnodelocale=db_prefix_table('node_locale');
  4.  
  5.         $where="tn.thread_id=$rss_thread AND tn.ignored=FALSE";
  6.  
  7.         $sql="SELECT nl.name AS node_name, nl.title AS node_title, nl.abstract AS node_abstract, UNIX_TIMESTAMP(n.created) AS node_created 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 tn.number";

Extracts the name, the title, the creation date and the abstract of all the active nodes of the thread $rss_thread. The result is sorted by node number.

  1.         if ($r) {
  2.             foreach ($r as $node) {
  3.                 extract($node);
  4.                 $title = $node_title;
  5.                 $uri = $lang . '/' . $node_name;
  6.                 $created = $node_created;
  7.                 $description = preg_replace('/(\r\n|\r|\n)+/', ' - ', preg_replace('/[\t ]+/', ' ', $node_abstract));
  8.                 $itemlist[] = compact('title', 'uri', 'created', 'description');
  9.             }
  10.         }

Adds the simplified URL of each node to the list of items. IMPORTANT: Add the thread number $rss_thread to the configuration parameter $default_folder in config.inc.

To build the RSS feed from the contents of several threads, modify the WHERE clause:

  1.         $where='tn.thread_id IN (' . (is_array($rss_thread) ? implode(',', $rss_thread) : $rss_thread) . ') AND tn.ignored=FALSE';

You can insert in the feed the image associated to a node.

  1.         $sql="SELECT nl.name AS node_name, nl.title AS node_title, nl.abstract AS node_abstract, nl.image AS node_image, UNIX_TIMESTAMP(n.created) AS node_created 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 tn.number";

Adds the selection of the field node_name to the SQL order.

  1.         if ($r) {
  2.             foreach ($r as $node) {
  3.                 extract($node);
  4.                 $title = $node_title;
  5.                 $uri = $lang . '/' . $node_name;
  6.                 $created = $node_created;
  7.                 $description = preg_replace('/(\r\n|\r|\n)+/', ' - ', preg_replace('/[\t ]+/', ' ', $node_abstract));
  8.                 $image_url=$node_image;
  9.                 $image_size=$image_url ? filesize(ROOT_DIR . $node_created) : 0;
  10.                 $itemlist[] = compact('title', 'uri', 'created', 'description', 'image_url', 'image_size');
  11.             }
  12.         }
  13.     }

Adds the URL of the image and the size of the image of each node to the list of items.

Finish by adding a tag <enclosure> of type image/png to the view rssfeed:

  1. <?php if ($image_url): ?>
  2.         <enclosure type="image/png" url="<?php echo $base_url; ?><?php echo $image_url; ?>" length="<?php echo $image_size; ?>" />
  3. <?php endif; ?>
  4.         <pubDate><?php echo date('r', $created); ?></pubDate>
  5.     </item>

The tag <head> of the HTML document of a page always contains a link to the RSS feed:

<link rel="alternate" href="http://www.izend.org/en/rss" type="application/rss+xml" title="izend.org RSS" />

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:

<a href="<?php echo $base_path; ?>/en/rss" title="Subscribe to the RSS feed"><span class="icon_rss">RSS</span></a>

RSS

<a class="rss" href="<?php echo $base_path; ?>/en/rss" target="_blank" rel="nofollow" title="Subscribe to the RSS feed"><span>RSS</span></a>

RSS

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:

  1.     <image>
  2.         <title><?php echo $sitename; ?></title>
  3. <?php if ($lang): ?>
  4.         <link><?php echo $base_url; ?>/<?php echo $lang; ?></link>
  5. <?php else: ?>
  6.         <link><?php echo $base_url; ?></link>
  7. <?php endif; ?>
  8.         <url><?php echo $base_url; ?>/logos/siteqr.png</url>
  9.         <width>50</width>
  10.     </image>
SEE ALSO

translate, head

Comments

To add a comment, click here.