Changeset 2235 for branches

Show
Ignore:
Timestamp:
11/22/10 12:20:55 (18 months ago)
Author:
petsagouris
Message:

[Branch 1.5] Some code care on the RSS writer class.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.5/libs/extensions/RSSWriterClass/rsswriter.php

    r2143 r2235  
    11<?php 
    2 /* Publishes content as an RSS feed 
    3   http://snipplr.com/view/23/rss-writer-class/ 
    42 
    5   E X A M P L E ----------------------------------------------- 
    6   $feed = new RSS(); 
    7   $feed->title       = "RSS Feed Title"; 
    8   $feed->link        = "http://website.com"; 
    9   $feed->description = "Recent articles on your website."; 
    10  
    11   $db->query($query); 
    12   $result = $db->result; 
    13   while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    14   { 
    15   $item = new RSSItem(); 
    16   $item->title = $title; 
    17   $item->link  = $link; 
    18   $item->setPubDate($create_date); 
    19   $item->description = "<![CDATA[ $html ]]>"; 
    20   $feed->addItem($item); 
    21   } 
    22   echo $feed->serve(); 
    23   ---------------------------------------------------------------- */ 
    24  
     3/** 
     4 * Publishes content as an RSS feed. 
     5 * @url: http://snipplr.com/view/23/rss-writer-class/ 
     6 * @uses RSSItem 
     7 * @example 
     8 * <code> 
     9 * $feed = new RSS(); 
     10 * $feed->title = "RSS Feed Title"; 
     11 * $feed->link = "http://website.com"; 
     12 * $feed->description = "Recent articles on your website."; 
     13 * $db->query($query); 
     14 * $result = $db->result; 
     15 * while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
     16 * { 
     17 *   $item = new RSSItem(); 
     18 *   $item->title = $title; 
     19 *   $item->link  = $link; 
     20 *   $item->setPubDate($create_date); 
     21 *   $item->description = "<![CDATA[ $html ]]>"; 
     22 *   $feed->addItem($item); 
     23 * } 
     24 * echo $feed->serve(); 
     25 * </code> 
     26 */ 
    2527class RSS { 
    2628 
     
    3436        public $tags = array(); 
    3537 
    36         public function __construct($rss_link) { 
    37                 $this->rss_link = (empty($rss_link))? SITEURL.'index.php?page=rss' : $rss_link ; 
     38        public function __construct($rss_link) 
     39        { 
     40                $this->rss_link = (empty($rss_link)) ? SITEURL.'index.php?page=rss' : $rss_link; 
    3841        } 
    3942 
    40         public function addItem($item) { 
     43        public function addItem($item) 
     44        { 
    4145                if (is_array($item)) { 
    4246                        foreach ($item as $i) { 
     
    4751        } 
    4852 
    49         public function setPubDate($when) { 
     53        public function setPubDate($when) 
     54        { 
    5055                $this->pubDate = date("D, d M Y H:i:s O", ((strtotime($when)) ? strtotime($when) : $when)); 
    5156        } 
    5257 
    53         public function addTag($tag, $value) { 
     58        public function addTag($tag, $value) 
     59        { 
    5460                $this->tags[$tag] = $value; 
    5561        } 
    5662 
    57         public function out($serve_contentType = FALSE) { 
     63        public function out($serve_contentType = FALSE) 
     64        { 
    5865 
    5966                if (is_string($serve_contentType)) { 
     
    9299} 
    93100 
     101/** 
     102 * Represents an item on the RSS feed. 
     103 * @see RSS 
     104 */ 
    94105class RSSItem { 
    95106 
     
    104115        public $mimetype; 
    105116 
    106         public function __construct($options) { 
     117        public function __construct($options) 
     118        { 
    107119                if (isset($options['title'])) { 
    108120                        $this->title = stripslashes(html_entity_decode(urldecode($options['title']), ENT_QUOTES, 'UTF-8')); 
     
    132144        } 
    133145 
    134         public function out() { 
     146        public function out() 
     147        { 
    135148                $out = "<item>\n"; 
    136149                $out .= "<title>".$this->title."</title>\n"; 
     
    143156                } 
    144157 
    145                 $this->guid = (empty($this->guid)) ?  $this->link : $this->guid; 
     158                $this->guid = (empty($this->guid)) ? $this->link : $this->guid; 
    146159 
    147160                $out .= "<guid>".$this->guid."</guid>\n"; 
     
    155168 
    156169} 
    157  
    158 ?>