- Timestamp:
- 11/22/10 12:20:55 (18 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5/libs/extensions/RSSWriterClass/rsswriter.php
r2143 r2235 1 1 <?php 2 /* Publishes content as an RSS feed3 http://snipplr.com/view/23/rss-writer-class/4 2 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 */ 25 27 class RSS { 26 28 … … 34 36 public $tags = array(); 35 37 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; 38 41 } 39 42 40 public function addItem($item) { 43 public function addItem($item) 44 { 41 45 if (is_array($item)) { 42 46 foreach ($item as $i) { … … 47 51 } 48 52 49 public function setPubDate($when) { 53 public function setPubDate($when) 54 { 50 55 $this->pubDate = date("D, d M Y H:i:s O", ((strtotime($when)) ? strtotime($when) : $when)); 51 56 } 52 57 53 public function addTag($tag, $value) { 58 public function addTag($tag, $value) 59 { 54 60 $this->tags[$tag] = $value; 55 61 } 56 62 57 public function out($serve_contentType = FALSE) { 63 public function out($serve_contentType = FALSE) 64 { 58 65 59 66 if (is_string($serve_contentType)) { … … 92 99 } 93 100 101 /** 102 * Represents an item on the RSS feed. 103 * @see RSS 104 */ 94 105 class RSSItem { 95 106 … … 104 115 public $mimetype; 105 116 106 public function __construct($options) { 117 public function __construct($options) 118 { 107 119 if (isset($options['title'])) { 108 120 $this->title = stripslashes(html_entity_decode(urldecode($options['title']), ENT_QUOTES, 'UTF-8')); … … 132 144 } 133 145 134 public function out() { 146 public function out() 147 { 135 148 $out = "<item>\n"; 136 149 $out .= "<title>".$this->title."</title>\n"; … … 143 156 } 144 157 145 $this->guid = (empty($this->guid)) ? $this->link : $this->guid;158 $this->guid = (empty($this->guid)) ? $this->link : $this->guid; 146 159 147 160 $out .= "<guid>".$this->guid."</guid>\n"; … … 155 168 156 169 } 157 158 ?>