Changeset 71
- Timestamp:
- 06/19/07 19:30:19 (19 months ago)
- Files:
-
- 1 modified
-
hacks/trunk/feedphp/feed.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hacks/trunk/feedphp/feed.php
r70 r71 6 6 * 7 7 * author: Antonio Cavedoni <http://cavedoni.com/> 8 * version: 0.1 8 * version: 0.11 9 9 * revision: $Id$ 10 10 * license: BSD 11 * 12 * acknowledgements: Ludovico Magnocavallo, Simon Willison, Adrian 13 * Holovaty, Jacob Kaplan-Moss and the Django project, Federico 14 * Marzocchi 11 15 * 12 16 * Feed::serve() outputs the feed with the proper MIME type and … … 21 25 * require_once('feed.php'); 22 26 * 23 * $feed = new AtomFeed( Array(27 * $feed = new AtomFeed(array( 24 28 * 'title' => 'My feed', 25 29 * 'link' => 'http://localhost/myfeed.php', … … 27 31 * )); 28 32 * 29 * $feed->addItem( Array(33 * $feed->addItem(array( 30 34 * 'title' => 'mytitle', 31 35 * 'link' => 'http://example.org/1', … … 37 41 * )); 38 42 * 39 * $feed->addItem( Array(43 * $feed->addItem(array( 40 44 * 'title' => 'another title', 41 45 * 'link' => 'http://example.org/2', … … 63 67 64 68 class Feed { 65 public $items = Array();69 public $items = array(); 66 70 public $writer; 67 71 public $charset = 'UTF-8'; … … 73 77 public function __construct($params) 74 78 { 75 if (array_key_exists('charset', $params)) 79 if (array_key_exists('charset', $params)) { 76 80 $this->charset = $params['charset']; 77 if (array_key_exists('title', $params)) 81 } 82 if (array_key_exists('title', $params)) { 78 83 $this->title = $params['title']; 79 if (array_key_exists('link', $params)) 84 } 85 if (array_key_exists('link', $params)) { 80 86 $this->link = $params['link']; 81 if (array_key_exists('description', $params)) 87 } 88 if (array_key_exists('description', $params)) { 82 89 $this->description = $params['description']; 90 } 83 91 } 84 92 … … 92 100 public function latestPostDate() 93 101 { 94 $updates = Array();102 $updates = array(); 95 103 foreach ($this->items as $item) { 96 array_push($updates, $item['pubDate']);104 $this->updates[] = $item['pubDate']; 97 105 } 98 106 rsort($updates); … … 102 110 public function addItem($params) 103 111 { 104 $item = Array(112 $item = array( 105 113 'title' => $params['title'], 106 114 'link' => $params['link'], … … 109 117 ); 110 118 111 if (array_key_exists('author', $params)) 119 if (array_key_exists('author', $params)) { 112 120 $item['author'] = $params['author']; 113 if (array_key_exists('authorEmail', $params)) 121 } 122 if (array_key_exists('authorEmail', $params)) { 114 123 $item['authorEmail'] = $params['authorEmail']; 115 if (array_key_exists('uniqueId', $params)) 124 } 125 if (array_key_exists('uniqueId', $params)) { 116 126 $item['uniqueId'] = $params['uniqueId']; 127 } 117 128 array_push($this->items, $item); 118 129 } … … 165 176 // See if the client has provided the required headers 166 177 $if_modified_since = $if_none_match = false; 167 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) 178 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { 168 179 $if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']); 169 if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) 180 } 181 if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 170 182 $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); 183 } 171 184 if (!$if_modified_since && !$if_none_match) { 172 185 // both are missing … … 229 242 $this->rfc3339Date($this->latestPostDate())); 230 243 $this->writer->elementWithAttrs('link', 231 Array('rel' => 'self', 'href' => $this->link));244 array('rel' => 'self', 'href' => $this->link)); 232 245 $this->writeItems(); 233 246 $this->writer->endElement(); … … 241 254 $this->writer->writeElement('title', $item['title']); 242 255 $this->writer->elementWithAttrs('link', 243 Array('rel' => 'alternate', 'href' => $item['link']));256 array('rel' => 'alternate', 'href' => $item['link'])); 244 257 $this->writer->elementWithAttrs('content', 245 Array('type' => 'html'), $item['description']);258 array('type' => 'html'), $item['description']); 246 259 $this->writer->writeElement('id', $item['link']); 247 260 $this->writer->writeElement('updated',