Changeset 2293
- Timestamp:
- 12/11/10 07:23:51 (18 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5/libs/extensions/RSSWriterClass/rsswriter.php
r2235 r2293 1 1 <?php 2 /** 3 * RSS class 4 * 5 * @author George Petsagourakis <petsagouris@gmail.com> 6 * 7 * @package HotaruCMS 8 * @subpackage RSS 9 */ 2 10 3 11 /** 4 12 * Publishes content as an RSS feed. 13 * 5 14 * @url: http://snipplr.com/view/23/rss-writer-class/ 6 15 * @uses RSSItem 7 * @example 8 * <code> 16 * @example <code> 9 17 * $feed = new RSS(); 10 18 * $feed->title = "RSS Feed Title"; … … 27 35 class RSS { 28 36 37 /** 38 * The feed's title 39 * 40 * @var string 41 */ 29 42 public $title; 43 /** 44 * The feed's URL 45 * 46 * @var string 47 */ 30 48 public $rss_link; 49 /** 50 * The feed's atom link (for caching) 51 * 52 * @var string 53 */ 31 54 public $link; 55 /** 56 * The feed's description text 57 * 58 * @var string 59 */ 32 60 public $description; 61 /** 62 * The feed's language identifier 63 * 64 * @var string 65 */ 33 66 public $language = "en-us"; 67 /** 68 * The feed's publication date 69 * 70 * @var string 71 */ 34 72 public $pubDate; 73 /** 74 * The feed's items (an array of RSSItem objects) 75 * 76 * @var array 77 */ 35 78 public $items = array(); 79 /** 80 * Additional tag entries for the parent tag. 81 * 82 * @var array 83 */ 36 84 public $tags = array(); 37 85 86 /** 87 * The constructor set's up the object with an initial url of the feed. 88 * 89 * @param string $rss_link the link of the feed 90 */ 38 91 public function __construct($rss_link) 39 92 { … … 41 94 } 42 95 96 /** 97 * Adds RSSItem objects to the RSS::items array 98 * 99 * @param array $item An array that will be used in constructing the RSSItem object 100 */ 43 101 public function addItem($item) 44 102 { 45 103 if (is_array($item)) { 46 104 foreach ($item as $i) { 47 array_push($this->items, new RSSItem($i));105 $this->items[] = new RSSItem($i); 48 106 } 49 107 } … … 51 109 } 52 110 111 /** 112 * Publication date setter for the feed 113 * 114 * @param string $when 115 */ 53 116 public function setPubDate($when) 54 117 { … … 56 119 } 57 120 121 /** 122 * 123 * @param <type> $tag 124 * @param <type> $value 125 */ 58 126 public function addTag($tag, $value) 59 127 { … … 98 166 99 167 } 100 101 /**102 * Represents an item on the RSS feed.103 * @see RSS104 */105 class RSSItem {106 107 public $title;108 public $link;109 public $description;110 public $pubDate;111 public $guid;112 public $tags = array();113 public $attachment;114 public $length;115 public $mimetype;116 117 public function __construct($options)118 {119 if (isset($options['title'])) {120 $this->title = stripslashes(html_entity_decode(urldecode($options['title']), ENT_QUOTES, 'UTF-8'));121 }122 123 if (isset($options['link'])) {124 $this->link = html_entity_decode($options['link'], ENT_QUOTES, 'UTF-8');125 }126 127 if (isset($options['date'])) {128 $this->pubDate = date("D, d M Y H:i:s O", ((strtotime($options['date'])) ? strtotime($options['date']) : $options['date']));129 }130 131 if (isset($options['description'])) {132 $this->description = "<![CDATA[ ".stripslashes(urldecode($options['description']))." ]]>";133 }134 135 if (isset($options['enclosure'])) {136 $this->attachment = $options['enclosure']['url'];137 $this->mimetype = $options['enclosure']['type'];138 $this->length = $options['enclosure']['length'];139 }140 141 if (isset($options['author'])) {142 $this->tags['author'] = $options['author'];143 }144 }145 146 public function out()147 {148 $out = "<item>\n";149 $out .= "<title>".$this->title."</title>\n";150 $out .= "<link>".$this->link."</link>\n";151 $out .= "<description>".$this->description."</description>\n";152 $out .= "<pubDate>".((empty($this->pubDate)) ? date("D, d M Y H:i:s O") : $this->pubDate)."</pubDate>\n";153 154 if (!empty($this->attachment)) {155 $out .= "<enclosure url='{$this->attachment}' length='{$this->length}' type='{$this->mimetype}' />";156 }157 158 $this->guid = (empty($this->guid)) ? $this->link : $this->guid;159 160 $out .= "<guid>".$this->guid."</guid>\n";161 162 foreach ($this->tags as $key => $val) {163 $out .= "<$key>$val</$key\n>";164 }165 166 return $out."</item>\n";167 }168 169 }