1
33

RSS feed

RSS

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
  1. require_once 'filemimetype.php';
  2.  
  3. function rssfeed($lang) {
  4.     global $rss_thread, $rss_description;
  5.  
  6.     $feed_content = $rss_description == 'content';
  7.  
  8.     $itemlist = array();
  9.  
  10.     if ($rss_thread) {
  11.         $sqllang=db_sql_arg($lang, false);
  12.  
  13.         $tabthreadnode=db_prefix_table('thread_node');
  14.         $tabnode=db_prefix_table('node');
  15.         $tabnodelocale=db_prefix_table('node_locale');
  16.  
  17.         $where=(is_array($rss_thread) ? 'tn.thread_id IN (' . implode(',', $rss_thread) . ')' : "tn.thread_id=$rss_thread") . ' AND tn.ignored=FALSE';
  18.  
  19.         if ($feed_content) {
  20.             $tabnodecontent=db_prefix_table('node_content');
  21.             $tabcontenttext=db_prefix_table('content_text');
  22.  
  23.             $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";
  24.         }
  25.         else {
  26.             $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";
  27.         }
  28.  
  29.         $r = db_query($sql);
  30.  
  31.         if ($r) {
  32.             foreach ($r as $node) {
  33.                 extract($node);
  34.                 $title = $node_title;
  35.                 $uri = false;   // "/$lang/$node_name";
  36.                 $created = $node_created;
  37.                 $description = preg_replace('/(\r\n|\r|\n)+/', ' - ', preg_replace('/[\t ]+/', ' ', strip_tags($feed_content ? $content_text : $node_abstract)));
  38.                 $image_uri = false; // $node_image;
  39.                 $image_size = $image_uri ? filesize(ROOT_DIR . $image_uri) : 0;
  40.                 $image_type = $image_uri ? file_mime_type(ROOT_DIR . $image_uri) : false;
  41.                 $itemlist[] = compact('title', 'uri', 'created', 'description', 'image_uri', 'image_size', 'image_type');
  42.             }
  43.         }
  44.     }
  45.  
  46.     $description = translate('description', $lang);
  47.  
  48.     $output = view('rssfeed', false, compact('lang', 'description', 'itemlist'));
  49.  
  50.     return $output;
  51. }

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:

<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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].