Ticket #2551: sfFeed2Plugin_with_image.patch
| File sfFeed2Plugin_with_image.patch, 17.2 kB (added by FabianLange, 10 months ago) |
|---|
-
lib/sfAtom1Feed.class.php
old new 70 70 $this->setAuthorName((string) $feedXml->author->name); 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) 75 82 { … … 200 207 $xml[] = ' <subtitle>'.$this->getSubtitle().'</subtitle>'; 201 208 } 202 209 210 if ($this->getImage()) 211 { 212 $xml[] = ' <icon>'.$this->getImage()->getFavicon().'</icon>'; 213 $xml[] = ' <logo>'.$this->getImage()->getImage().'</logo>'; 214 } 215 203 216 if(is_array($this->getCategories())) 204 217 { 205 218 foreach ($this->getCategories() as $category) -
lib/sfFeed.class.php
old new 22 22 { 23 23 protected 24 24 $items = array(), 25 $image, 25 26 $title, 26 27 $link, 27 28 $description, … … 52 53 public function initialize($feed_array) 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'] : ''); 57 59 $this->setDescription(isset($feed_array['description']) ? $feed_array['description'] : ''); … … 164 166 { 165 167 $this->items = array_slice($this->items, 0, $count); 166 168 } 169 return $this; 170 } 167 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 } 170 195 171 196 public function setTitle ($title) 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 176 206 public function getTitle () … … 181 211 public function setLink ($link) 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 186 221 public function getLink () -
lib/sfFeedImage.class.php
old new 1 <?php 2 3 /* 4 * This file is part of the sfFeed2 package. 5 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * (c) 2004-2007 Francois Zaninotto <francois.zaninotto@symfony-project.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 /** 13 * 14 * Adds support for icons/images for atom and rss feeds in an unified extensible way. 15 * Both (rss and atom) specs are quite limited, but this class should cope with possible enhancements. 16 * Note that not everything is used. Atom at the moment only takes favicon (1:1 ratio) and 17 * image (approx 2:1 ratio) image urls. 18 * Rss only takes the image, but expects additionally the size of that image. 19 * 20 * @package sfFeed2 21 * @author Fabian Lange <fabian.lange@web.de> 22 */ 23 class sfFeedImage 24 { 25 private 26 $favicon, 27 $image, 28 $faviconX, 29 $faviconY, 30 $imageX, 31 $imageY, 32 $title, 33 $link, 34 $feed; 35 36 public function __construct($item_array = array()) 37 { 38 if($item_array) 39 { 40 $this->initialize($item_array); 41 } 42 } 43 44 /** 45 * Sets the feed image parameters, based on an associative array 46 * 47 * @param array an associative array 48 * 49 * @return sfFeedImage the current sfFeedImage object 50 */ 51 public function initialize($item_array) 52 { 53 $this->setFavicon(isset($item_array['favicon']) ? $item_array['favicon'] : ''); 54 $this->setImage(isset($item_array['image']) ? $item_array['image'] : ''); 55 $this->setFaviconX(isset($item_array['faviconX']) ? $item_array['faviconX'] : ''); 56 $this->setFaviconY(isset($item_array['faviconY']) ? $item_array['faviconY'] : ''); 57 $this->setImageX(isset($item_array['imageX']) ? $item_array['imageX'] : ''); 58 $this->setImageY(isset($item_array['imageY']) ? $item_array['imageY'] : ''); 59 $this->setTitle(isset($item_array['title']) ? $item_array['title'] : ''); 60 $this->setLink(isset($item_array['link']) ? $item_array['link'] : ''); 61 $this->setFeed(isset($item_array['feed']) ? $item_array['feed'] : ''); 62 63 return $this; 64 } 65 66 public function setFavicon ($favicon) 67 { 68 $this->favicon = $favicon; 69 } 70 71 public function getFavicon () 72 { 73 return $this->favicon; 74 } 75 76 public function setImage ($image) 77 { 78 $this->image = $image; 79 } 80 81 public function getImage () 82 { 83 return $this->image; 84 } 85 86 public function setFaviconX ($faviconX) 87 { 88 $this->faviconX = $faviconX; 89 } 90 91 public function getFaviconX () 92 { 93 return $this->faviconX; 94 } 95 96 public function setFaviconY ($faviconY) 97 { 98 $this->faviconY = $faviconY; 99 } 100 101 public function getFaviconY () 102 { 103 return $this->faviconY; 104 } 105 106 public function setImageX ($imageX) 107 { 108 $this->imageX = $imageX; 109 } 110 111 public function getImageX () 112 { 113 return $this->imageX; 114 } 115 116 public function setImageY ($imageY) 117 { 118 $this->imageY = $imageY; 119 } 120 121 public function getImageY () 122 { 123 return $this->imageY; 124 } 125 126 public function setTitle ($title) 127 { 128 $this->title = $title; 129 } 130 131 public function getTitle () 132 { 133 return $this->title; 134 } 135 136 public function setLink ($link) 137 { 138 $this->link = $link; 139 } 140 141 public function getLink () 142 { 143 return $this->link; 144 } 145 146 public function setFeed ($feed) 147 { 148 $this->feed = $feed; 149 } 150 151 public function getFeed () 152 { 153 return $this->feed; 154 } 155 156 } -
lib/sfRssFeed.class.php
old new 71 71 $this->setDescription((string) $feedXml->channel[0]->description); 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) 76 88 { … … 189 201 { 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 { 194 216 if(is_array($this->getCategories())) -
README
old new 12 12 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 21 22 It also contains specific classes containing specific input/output methods based on specific feed formats: … … 122 123 <author_email>pclive@myblog.com</author_email> 123 124 </author> 124 125 <id>4543D55FF756G734</id> 125 126 <icon>http://www.myblog.com/favicon.ico</icon> 127 126 128 <entry> 127 129 <title>I love mice</title> 128 130 <link href="http://www.myblog.com/permalink/i-love-mice" /> … … 164 166 $feed->setAuthorEmail('pclive@myblog.com'); 165 167 $feed->setAuthorName('Peter Clive'); 166 168 169 $feedImage = new sfFeedImage(); 170 $feedImage->setFavicon('http://www.myblog.com/favicon.ico'); 171 $feed->setImage($feedImage); 172 167 173 $c = new Criteria; 168 174 $c->addDescendingOrderByColumn(PostPeer::CREATED_AT); 169 175 $c->setLimit(5); … … 446 452 == Trunk == 447 453 448 454 * Pascal.Borreli : symfony coding practices : removed lib closing tag (#2657) 455 * Fabian Lange : added image capabilities (#2551) 449 456 450 457 === 2007-04-15 | 0.9.4 Beta === 451 458 -
test/unit/sfAtom1FeedTest.php
old new 50 50 'pubDate' => '123456', 51 51 ); 52 52 53 $image_params = array( 54 'title' => 'symfony project', 55 'link' => 'http://www.symfony-project.org', 56 'favicon' => 'http://www.symfony-project.org/favicon.ico', 57 'image' => 'http://www.symfony-project.org/images/symfony_logo.gif', 58 'faviconX' => '16', 59 'faviconY' => '16', 60 'imageX' => '176', 61 'imageY' => '37', 62 ); 63 53 64 $feed = new sfAtom1Feed(); 54 65 $feed->initialize($feedParams); 55 66 $feedItem = new sfFeedItem(); … … 58 69 $feedItem2 = new sfFeedItem(); 59 70 $feedItem2->initialize($item2Params); 60 71 $feed->addItem($feedItem2); 72 $feedImage = new sfFeedImage(); 73 $feedImage->initialize($image_params); 74 $feed->setImage($feedImage); 61 75 62 $t = new lime_test(5 2, new lime_output_color());76 $t = new lime_test(56, new lime_output_color()); 63 77 64 78 $t->diag('toXML() - generated feed'); 65 79 $feedString = $feed->toXml(); … … 81 95 $t->is((string) $feedXml->subtitle, $feedParams['subtitle'], '<subtitle> contains the proper subtitle'); 82 96 $t->is((string) $feedXml->category[0]['term'], $feedParams['categories'][0], '<category> contains the feed category'); 83 97 $t->is((string) $feedXml->category[1]['term'], $feedParams['categories'][1], '<category> contains the feed category'); 98 $t->is((string) $feedXml->icon, $image_params['favicon'], '<favicon> contains the proper favicon'); 99 $t->is((string) $feedXml->logo, $image_params['image'], '<logo> contains the proper logo'); 84 100 85 101 $t->diag('toXML() - generated feed items'); 86 102 $t->is((string) $feedXml->entry[0]->title, $itemParams['title'], '<entry><title> contains the item title'); … … 116 132 $t->is($generatedFeed->getCategories(), $feed->getCategories(), 'The categories property is properly set'); 117 133 $t->is($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property is properly set'); 118 134 $t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set'); 135 $t->is($generatedFeed->getImage()->getFavicon(), $feed->getImage()->getFavicon(), 'The feed favicon property is properly set'); 136 $t->is($generatedFeed->getImage()->getImage(), $feed->getImage()->getImage(), 'The feed logo property is properly set'); 119 137 120 138 $t->diag('fromXML() - generated feed items'); 121 139 $items = $generatedFeed->getItems(); -
test/unit/sfFeedImageTest.php
old new 1 <?php 2 3 define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/../../../..')); 4 define('SF_APP', 'frontend'); 5 include(dirname(__FILE__).'/../../../../test/bootstrap/functional.php'); 6 7 $b = new sfTestBrowser(); 8 $b->initialize(); 9 10 $t = new lime_test(9, new lime_output_color()); 11 12 $image_params = array( 13 'title' => 'symfony project', 14 'link' => 'http://www.symfony-project.org', 15 'favicon' => 'http://www.symfony-project.org/favicon.ico', 16 'image' => 'http://www.symfony-project.org/images/symfony_logo.gif', 17 'faviconX' => '16', 18 'faviconY' => '16', 19 'imageX' => '176', 20 'imageY' => '37', 21 ); 22 23 $item = new sfFeedImage(); 24 $t->isa_ok($item->initialize($image_params), 'sfFeedImage', 'initialize() returns the current feed image object'); 25 $t->is($item->getTitle(), $image_params['title'], 'getTitle() gets the feed image title'); 26 $t->is($item->getLink(), $image_params['link'], 'getLink() gets the feed image link'); 27 $t->is($item->getFavicon(), $image_params['favicon'], 'getFavicon() gets the feed favicon url'); 28 $t->is($item->getImage(), $image_params['image'], 'getImage() gets the feed image url'); 29 $t->is($item->getFaviconX(), $image_params['faviconX'], 'getFaviconX() gets the feed favicon x size'); 30 $t->is($item->getFaviconY(), $image_params['faviconY'], 'getFaviconY() gets the feed favicon y size'); 31 $t->is($item->getImageX(), $image_params['imageX'], 'getImageX() gets the feed image x size'); 32 $t->is($item->getImageY(), $image_params['imageY'], 'getImageY() gets the feed image y size'); 33 -
test/unit/sfRssFeedTest.php
old new 51 51 'authorEmail' => 'fooitem2@bar.com', 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 sfRssFeed(); 55 66 $feed->initialize($feedParams); 56 67 $feedItem = new sfFeedItem(); … … 59 70 $feedItem2 = new sfFeedItem(); 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( 52, new lime_output_color());77 $t = new lime_test(62, new lime_output_color()); 64 78 65 79 $t->diag('toXML() - generated feed'); 66 80 $feedString = $feed->toXml(); … … 76 90 $t->is((string) $feedXml->channel[0]->managingEditor, $feedParams['authorEmail'].' ('.$feedParams['authorName'].')', '<managingEditor> contains the author email and name'); 77 91 $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'); 78 92 $t->is_deeply(array((string) $feedXml->channel[0]->category[0], (string) $feedXml->channel[0]->category[1]), $feedParams['categories'], '<category> contains the correct categories'); 93 $t->is((string) $feedXml->channel[0]->image->url, $image_params['image'], '<image><url> contains the proper image'); 94 $t->is((string) $feedXml->channel[0]->image->width, $image_params['imageX'], '<image><width> contains the proper image x'); 95 $t->is((string) $feedXml->channel[0]->image->height, $image_params['imageY'], '<image><height> contains the proper image y'); 96 $t->is((string) $feedXml->channel[0]->image->link, $image_params['link'], '<image><link> contains the proper image link'); 97 $t->is((string) $feedXml->channel[0]->image->title, $image_params['title'], '<image><title> contains the proper image title'); 79 98 80 99 $t->diag('toXML() - generated feed items'); 81 100 $t->is((string) $feedXml->channel[0]->item[0]->title, $itemParams['title'], '<item><title> contains the item title'); … … 114 133 $t->is($generatedFeed->getCategories(), $feed->getCategories(), 'The categories property is properly set'); 115 134 $t->isnt($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property cannot be set from a RSS feed'); 116 135 $t->is($generatedFeed->getEncoding(), $feed->getEncoding(), 'The encoding property is properly set'); 136 $t->is($generatedFeed->getImage()->getImage(), $feed->getImage()->getImage(), 'The feed image url is correctly set'); 137 $t->is($generatedFeed->getImage()->getImageX(), $feed->getImage()->getImageX(), 'The feed image x is correctly set'); 138 $t->is($generatedFeed->getImage()->getImageY(), $feed->getImage()->getImageY(), 'The feed image y is correctly set'); 139 $t->is($generatedFeed->getImage()->getLink(), $feed->getImage()->getLink(), 'The feed image link is correctly set'); 140 $t->is($generatedFeed->getImage()->getTitle(), $feed->getImage()->getTitle(), 'The feed image title is correctly set'); 117 141 118 142 $t->diag('fromXML() - generated feed items'); 119 143 $items = $generatedFeed->getItems();