Changeset 9792
- Timestamp:
- 06/23/08 11:41:23 (2 months ago)
- Files:
-
- plugins/sfFeed2Plugin/README (modified) (4 diffs)
- plugins/sfFeed2Plugin/lib/sfAtom1Feed.class.php (modified) (2 diffs)
- plugins/sfFeed2Plugin/lib/sfFeed.class.php (modified) (5 diffs)
- plugins/sfFeed2Plugin/lib/sfFeedImage.class.php (added)
- plugins/sfFeed2Plugin/lib/sfRssFeed.class.php (modified) (2 diffs)
- plugins/sfFeed2Plugin/test/unit/sfAtom1FeedTest.php (modified) (4 diffs)
- plugins/sfFeed2Plugin/test/unit/sfFeedImageTest.php (added)
- plugins/sfFeed2Plugin/test/unit/sfRssFeedTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfFeed2Plugin/README
r9699 r9792 13 13 == Contents == 14 14 15 This plugin contains threedata structure classes:15 This plugin contains four data structure classes: 16 16 17 17 * `sfFeed` 18 18 * `sfFeedItem` 19 * `sfFeedImage` 19 20 * `sfFeedEnclosure` 20 21 … … 123 124 </author> 124 125 <id>4543D55FF756G734</id> 125 126 <icon>http://www.myblog.com/favicon.ico</icon> 126 127 <entry> 127 128 <title>I love mice</title> … … 164 165 $feed->setAuthorEmail('pclive@myblog.com'); 165 166 $feed->setAuthorName('Peter Clive'); 167 168 $feedImage = new sfFeedImage(); 169 $feedImage->setFavicon('http://www.myblog.com/favicon.ico'); 170 $feed->setImage($feedImage); 166 171 167 172 $c = new Criteria; … … 461 466 * fabien: added the possibility to pass arguments to methods that convert an object to an item 462 467 * Pascal.Borreli : symfony coding practices : removed lib closing tag (#2657) 468 * Fabian Lange : added image capabilities (#2551) 463 469 464 470 === 2007-04-15 | 0.9.4 Beta === plugins/sfFeed2Plugin/lib/sfAtom1Feed.class.php
r9136 r9792 71 71 $this->setAuthorEmail((string) $feedXml->author->email); 72 72 $this->setAuthorLink((string) $feedXml->author->uri); 73 74 $image = new sfFeedImage(array( 75 "favicon" => (string)$feedXml->icon, 76 "image" => (string)$feedXml->logo, 77 )); 78 $this->setImage($image); 79 73 80 $categories = array(); 74 81 foreach($feedXml->category as $category) … … 209 216 } 210 217 218 if ($this->getImage()) 219 { 220 $xml[] = ' <icon>'.$this->getImage()->getFavicon().'</icon>'; 221 $xml[] = ' <logo>'.$this->getImage()->getImage().'</logo>'; 222 } 223 211 224 if(is_array($this->getCategories())) 212 225 { plugins/sfFeed2Plugin/lib/sfFeed.class.php
r6626 r9792 23 23 protected 24 24 $items = array(), 25 $image, 25 26 $title, 26 27 $link, … … 53 54 { 54 55 $this->setItems(isset($feed_array['items']) ? $feed_array['items'] : ''); 56 $this->setImage(isset($feed_array['image']) ? $feed_array['image'] : ''); 55 57 $this->setTitle(isset($feed_array['title']) ? $feed_array['title'] : ''); 56 58 $this->setLink(isset($feed_array['link']) ? $feed_array['link'] : ''); … … 165 167 $this->items = array_slice($this->items, 0, $count); 166 168 } 167 169 return $this; 170 } 171 172 /** 173 * Retrieves the feed image 174 * 175 * @return sfFeedImage actual sfFeedImage object 176 */ 177 public function getImage() 178 { 179 return $this->image; 180 } 181 182 /** 183 * Defines the image/icon of the feed 184 * 185 * @param image sfFeedImage object 186 * 187 * @return sfFeed the current sfFeed object 188 */ 189 public function setImage($image) 190 { 191 $this->image = $image; 192 168 193 return $this; 169 194 } … … 172 197 { 173 198 $this->title = $title; 199 //if an image is there that has no title yet set it as well 200 if ($this->image instanceof sfFeedImage && !$this->image->getTitle()) 201 { 202 $this->image->setTitle($title); 203 } 174 204 } 175 205 … … 182 212 { 183 213 $this->link = $link; 214 //if an image is there that has no link yet set it as well 215 if ($this->image instanceof sfFeedImage && !$this->image->getLink()) 216 { 217 $this->image->setLink($link); 218 } 184 219 } 185 220 plugins/sfFeed2Plugin/lib/sfRssFeed.class.php
r9136 r9792 72 72 $this->setLanguage((string) $feedXml->channel[0]->language); 73 73 74 if ($feedXml->channel[0]->image) 75 { 76 $image = new sfFeedImage(array( 77 "image" => (string)$feedXml->channel[0]->image->url, 78 "imageX" => (int)$feedXml->channel[0]->image->width, 79 "imageY" => (int)$feedXml->channel[0]->image->height, 80 "link" => (string)$feedXml->channel[0]->image->link, 81 "title" => (string)$feedXml->channel[0]->image->title 82 )); 83 $this->setImage($image); 84 } 85 74 86 $categories = array(); 75 87 foreach($feedXml->channel[0]->category as $category) … … 190 202 $xml[] = ' <language>'.$this->getLanguage().'</language>'; 191 203 } 204 if ($this->getImage()) 205 { 206 $xml[] = ' <image>'; 207 $xml[] = ' <url>'.$this->getImage()->getImage().'</url>'; 208 $xml[] = ' <title>'.$this->getImage()->getTitle().'</title>'; 209 $xml[] = ' <link>'.$this->context->getController()->genUrl($this->getImage()->getLink(), true).'</link>'; 210 $xml[] = ' <width>'.$this->getImage()->getImageX().'</width>'; 211 $xml[] = ' <height>'.$this->getImage()->getImageY().'</height>'; 212 $xml[] = ' </image>'; 213 } 192 214 if(strpos($this->version, '2.') !== false) 193 215 { plugins/sfFeed2Plugin/test/unit/sfAtom1FeedTest.php
r9136 r9792 52 52 ); 53 53 54 $image_params = array( 55 'title' => 'symfony project', 56 'link' => 'http://www.symfony-project.org', 57 'favicon' => 'http://www.symfony-project.org/favicon.ico', 58 'image' => 'http://www.symfony-project.org/images/symfony_logo.gif', 59 'faviconX' => '16', 60 'faviconY' => '16', 61 'imageX' => '176', 62 'imageY' => '37', 63 ); 64 54 65 $feed = new sfAtom1Feed(); 55 66 $feed->initialize($feedParams); … … 60 71 $feedItem2->initialize($item2Params); 61 72 $feed->addItem($feedItem2); 73 $feedImage = new sfFeedImage(); 74 $feedImage->initialize($image_params); 75 $feed->setImage($feedImage); 62 76 63 $t = new lime_test(5 2, new lime_output_color());77 $t = new lime_test(56, new lime_output_color()); 64 78 65 79 $t->diag('toXML() - generated feed'); … … 83 97 $t->is((string) $feedXml->category[0]['term'], $feedParams['categories'][0], '<category> contains the feed category'); 84 98 $t->is((string) $feedXml->category[1]['term'], $feedParams['categories'][1], '<category> contains the feed category'); 99 $t->is((string) $feedXml->icon, $image_params['favicon'], '<favicon> contains the proper favicon'); 100 $t->is((string) $feedXml->logo, $image_params['image'], '<logo> contains the proper logo'); 85 101 86 102 $t->diag('toXML() - generated feed items'); … … 118 134 $t->is($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property is properly set'); 119 135 $t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set'); 136 $t->is($generatedFeed->getImage()->getFavicon(), $feed->getImage()->getFavicon(), 'The feed favicon property is properly set'); 137 $t->is($generatedFeed->getImage()->getImage(), $feed->getImage()->getImage(), 'The feed logo property is properly set'); 120 138 121 139 $t->diag('fromXML() - generated feed items'); plugins/sfFeed2Plugin/test/unit/sfRssFeedTest.php
r9136 r9792 53 53 ); 54 54 55 $image_params = array( 56 'title' => 'symfony project', 57 'link' => 'http://www.symfony-project.org', 58 'favicon' => 'http://www.symfony-project.org/favicon.ico', 59 'image' => 'http://www.symfony-project.org/images/symfony_logo.gif', 60 'faviconX' => '16', 61 'faviconY' => '16', 62 'imageX' => '176', 63 'imageY' => '37', 64 ); 65 55 66 $feed = new sfRssFeed(); 56 67 $feed->initialize($feedParams); … … 61 72 $feedItem2->initialize($item2Params); 62 73 $feed->addItem($feedItem2); 74 $feedImage = new sfFeedImage(); 75 $feedImage->initialize($image_params); 76 $feed->setImage($feedImage); 63 77 64 $t = new lime_test( 52, new lime_output_color());78 $t = new lime_test(62, new lime_output_color()); 65 79 66 80 $t->diag('toXML() - generated feed'); … … 76 90 $t->is((string) $feedXml->channel[0]->language, $feedParams['language'], '<language> contains the feed language'); 77 91 $t->is((string) $feedXml->channel[0]->managingEditor, $feedParams['authorEmail'].' ('.$feedParams['authorName'].')', '<managingEditor> contains the author email and name'); 78 $t->is((string) $feedXml->channel[0]->pubDate, date(DATE_RFC822, $item2Params['pubDate']), '<pubDate> contains the latest publication date of all feed items');92 $t->is((string) $feedXml->channel[0]->pubDate, strftime('%Y-%m-%dT%H:%M:%SZ', $item2Params['pubDate']), '<pubDate> contains the latest publication date of all feed items'); 79 93 $t->is_deeply(array((string) $feedXml->channel[0]->category[0], (string) $feedXml->channel[0]->category[1]), $feedParams['categories'], '<category> contains the correct categories'); 94 $t->is((string) $feedXml->channel[0]->image->url, $image_params['image'], '<image><url> contains the proper image'); 95 $t->is((string) $feedXml->channel[0]->image->width, $image_params['imageX'], '<image><width> contains the proper image x'); 96 $t->is((string) $feedXml->channel[0]->image->height, $image_params['imageY'], '<image><height> contains the proper image y'); 97 $t->is((string) $feedXml->channel[0]->image->link, $image_params['link'], '<image><link> contains the proper image link'); 98 $t->is((string) $feedXml->channel[0]->image->title, $image_params['title'], '<image><title> contains the proper image title'); 80 99 81 100 $t->diag('toXML() - generated feed items'); 82 101 $t->is((string) $feedXml->channel[0]->item[0]->title, $itemParams['title'], '<item><title> contains the item title'); 83 102 $t->is((string) $feedXml->channel[0]->item[0]->link, $itemParams['link'], '<item><link> contains the proper item link'); 84 $t->is((string) $feedXml->channel[0]->item[0]->pubDate, date(DATE_RFC822, $itemParams['pubDate']), '<item><pubDate> contains the proper item publication date');103 $t->is((string) $feedXml->channel[0]->item[0]->pubDate, strftime('%Y-%m-%dT%H:%M:%SZ', $itemParams['pubDate']), '<item><pubDate> contains the proper item publication date'); 85 104 preg_match('/(.*?)\s*\((.*?)\)/', (string) $feedXml->channel[0]->item[0]->author, $matches); 86 105 $t->is_deeply(array($matches[1], $matches[2]), array($itemParams['authorEmail'], $itemParams['authorName']), '<entry><author> contains the item author with the pattern email (name)'); … … 116 135 $t->isnt($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property cannot be set from a RSS feed'); 117 136 $t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set'); 137 $t->is($generatedFeed->getImage()->getImage(), $feed->getImage()->getImage(), 'The feed image url is correctly set'); 138 $t->is($generatedFeed->getImage()->getImageX(), $feed->getImage()->getImageX(), 'The feed image x is correctly set'); 139 $t->is($generatedFeed->getImage()->getImageY(), $feed->getImage()->getImageY(), 'The feed image y is correctly set'); 140 $t->is($generatedFeed->getImage()->getLink(), $feed->getImage()->getLink(), 'The feed image link is correctly set'); 141 $t->is($generatedFeed->getImage()->getTitle(), $feed->getImage()->getTitle(), 'The feed image title is correctly set'); 118 142 119 143 $t->diag('fromXML() - generated feed items');