RSS Library

  • Use this library to create RSS feeds in your modules.
  • You should use xml streaming library in order to stream the created RSS Feed to the user.
  • Include the following function in the script to load the library.
   require_once($global['approot']."/inc/lib_rss.inc");

Starting a RSS Feed

    shn_rss_open();

Open a RSS channel

  • Use shn_rss_channel_open() function to open a channel.
  • Parameters as follow
    1. $title : Title of the RSS Feed.
    2. $desc : A Description about the RSS Feed.
    shn_rss_channel_open($title,$desc);

Add an Item to Channel

  • Use shn_rss_item() to add an item to a channel
  • You can add any number of items to a single channel.
  • Parameters as follow
    1. $title : Title of the item
    2. $link : Link where the Item should point to
    3. $description : Description of the Item
    4. $extra_opt : If you have other tags which should come under item parse them as an array with tag name and the value as pares array('tag_name'⇒'value').
    shn_rss_item($title,$link,$description,$extra_opt=array())

Close a Channel

Close a RSS Feed

Adding a Feed icon to a module page

  • Use shn_rss_add_feed() to add a RSS Feed icon and a link to a web page.
  • Parameters as follow
  1. $act : action
  2. $title : Title of the Feed
  3. $desc : This is an optional field where you give a description of a feed.
    shn_rss_add_feed($act,$title,$desc=null);
  • When you add a Feed link it will look as follows.

Example of Usage

Following is a code segment used to create a RSS Feed that notify Expired items in the inventory management system.

function shn_xml_ims_rss_expired_list(){
    global $global;
    _shn_ims_expire_date_check(); // ignore this function
    require_once($global['approot']."/inc/lib_rss.inc");
    shn_rss_open();
    shn_rss_channel_open(_('Expired item List'),_('Following are a list of items which have been expired recently in SAHANA inventory.'));
 
 
    $sql="SELECT item_id,inv_id,item_name,amount,ct_unit.name as unit,manufactured_date,expire_date FROM ims_item_records as i INNER JOIN ct_unit ON ct_unit.unit_uuid = i.unit WHERE state='expired' ORDER BY expire_date LIMIT 0, 30;";
    define('ADODB_FETCH_ASSOC',2);
    $global['db']->SetFetchMode(ADODB_FETCH_ASSOC);
    $res = $global['db']->Execute($sql);
    if (!$res){add_error($global['db']->ErrorMsg());}
    //remember the link used in items should be a full uri in order for the readers to access it.
    $url="http://".$_SERVER[HTTP_HOST].$_SERVER['PHP_SELF']."?mod=ims&act=report_expired";
    foreach($res as $record){
        $desc=_("This item is manufactured on ").$record['manufactured_date']._(" and expired on ").$record['expire_date']."."._(" And Currently there are ").$record['amount']." ".$record['unit']._(" left in the inventory.");
        shn_rss_item($record['item_name'],$url,$desc);
    }
 
    shn_rss_channel_close();
    shn_rss_close();
}

To add a link to the above feed the following function has been used.

    require_once($global['approot']."/inc/lib_rss.inc");
    shn_rss_add_feed('rss_expired_list',_('Expired item List'),"A list of expired items in the inventories.");

Navigation
QR Code
QR Code swat:rss_library (generated for current page)