Development

Changeset 9792

You must first sign up to be able to contribute.

Changeset 9792

Show
Ignore:
Timestamp:
06/23/08 11:41:23 (2 months ago)
Author:
FabianLange
Message:

added Image support to sfFeed2Plugin. Fixes #2551

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfFeed2Plugin/README

    r9699 r9792  
    1313== Contents == 
    1414 
    15 This plugin contains three data structure classes: 
     15This plugin contains four data structure classes: 
    1616 
    1717 * `sfFeed` 
    1818 * `sfFeedItem` 
     19 * `sfFeedImage` 
    1920 * `sfFeedEnclosure` 
    2021 
     
    123124  </author> 
    124125  <id>4543D55FF756G734</id> 
    125  
     126  <icon>http://www.myblog.com/favicon.ico</icon> 
    126127  <entry> 
    127128    <title>I love mice</title> 
     
    164165  $feed->setAuthorEmail('pclive@myblog.com'); 
    165166  $feed->setAuthorName('Peter Clive'); 
     167 
     168  $feedImage = new sfFeedImage(); 
     169  $feedImage->setFavicon('http://www.myblog.com/favicon.ico'); 
     170  $feed->setImage($feedImage); 
    166171 
    167172  $c = new Criteria; 
     
    461466 * fabien: added the possibility to pass arguments to methods that convert an object to an item 
    462467 * Pascal.Borreli : symfony coding practices : removed lib closing tag (#2657) 
     468 * Fabian Lange : added image capabilities (#2551) 
    463469 
    464470=== 2007-04-15 | 0.9.4 Beta === 
  • plugins/sfFeed2Plugin/lib/sfAtom1Feed.class.php

    r9136 r9792  
    7171    $this->setAuthorEmail((string) $feedXml->author->email); 
    7272    $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 
    7380    $categories = array(); 
    7481    foreach($feedXml->category as $category) 
     
    209216    } 
    210217 
     218    if ($this->getImage()) 
     219    { 
     220      $xml[] = '  <icon>'.$this->getImage()->getFavicon().'</icon>'; 
     221      $xml[] = '  <logo>'.$this->getImage()->getImage().'</logo>'; 
     222    } 
     223 
    211224    if(is_array($this->getCategories())) 
    212225    { 
  • plugins/sfFeed2Plugin/lib/sfFeed.class.php

    r6626 r9792  
    2323  protected 
    2424    $items = array(), 
     25    $image, 
    2526    $title, 
    2627    $link, 
     
    5354  { 
    5455    $this->setItems(isset($feed_array['items']) ? $feed_array['items'] : ''); 
     56    $this->setImage(isset($feed_array['image']) ? $feed_array['image'] : ''); 
    5557    $this->setTitle(isset($feed_array['title']) ? $feed_array['title'] : ''); 
    5658    $this->setLink(isset($feed_array['link']) ? $feed_array['link'] : ''); 
     
    165167      $this->items = array_slice($this->items, 0, $count); 
    166168    } 
    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     
    168193    return $this; 
    169194  } 
     
    172197  { 
    173198    $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    } 
    174204  } 
    175205 
     
    182212  { 
    183213    $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    } 
    184219  } 
    185220 
  • plugins/sfFeed2Plugin/lib/sfRssFeed.class.php

    r9136 r9792  
    7272    $this->setLanguage((string) $feedXml->channel[0]->language); 
    7373 
     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 
    7486    $categories = array(); 
    7587    foreach($feedXml->channel[0]->category as $category) 
     
    190202      $xml[] = '    <language>'.$this->getLanguage().'</language>'; 
    191203    } 
     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    } 
    192214    if(strpos($this->version, '2.') !== false) 
    193215    { 
  • plugins/sfFeed2Plugin/test/unit/sfAtom1FeedTest.php

    r9136 r9792  
    5252); 
    5353 
     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 
    5465$feed = new sfAtom1Feed(); 
    5566$feed->initialize($feedParams); 
     
    6071$feedItem2->initialize($item2Params); 
    6172$feed->addItem($feedItem2); 
     73$feedImage = new sfFeedImage(); 
     74$feedImage->initialize($image_params); 
     75$feed->setImage($feedImage); 
    6276 
    63 $t = new lime_test(52, new lime_output_color()); 
     77$t = new lime_test(56, new lime_output_color()); 
    6478 
    6579$t->diag('toXML() - generated feed'); 
     
    8397$t->is((string) $feedXml->category[0]['term'], $feedParams['categories'][0], '<category> contains the feed category'); 
    8498$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'); 
    85101 
    86102$t->diag('toXML() - generated feed items'); 
     
    118134$t->is($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property is properly set'); 
    119135$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'); 
    120138 
    121139$t->diag('fromXML() - generated feed items'); 
  • plugins/sfFeed2Plugin/test/unit/sfRssFeedTest.php

    r9136 r9792  
    5353); 
    5454 
     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 
    5566$feed = new sfRssFeed(); 
    5667$feed->initialize($feedParams); 
     
    6172$feedItem2->initialize($item2Params); 
    6273$feed->addItem($feedItem2); 
     74$feedImage = new sfFeedImage(); 
     75$feedImage->initialize($image_params); 
     76$feed->setImage($feedImage); 
    6377 
    64 $t = new lime_test(52, new lime_output_color()); 
     78$t = new lime_test(62, new lime_output_color()); 
    6579 
    6680$t->diag('toXML() - generated feed'); 
     
    7690$t->is((string) $feedXml->channel[0]->language, $feedParams['language'], '<language> contains the feed language'); 
    7791$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'); 
    7993$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'); 
    8099 
    81100$t->diag('toXML() - generated feed items'); 
    82101$t->is((string) $feedXml->channel[0]->item[0]->title, $itemParams['title'], '<item><title> contains the item title'); 
    83102$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'); 
    85104preg_match('/(.*?)\s*\((.*?)\)/', (string) $feedXml->channel[0]->item[0]->author, $matches); 
    86105$t->is_deeply(array($matches[1], $matches[2]), array($itemParams['authorEmail'], $itemParams['authorName']), '<entry><author> contains the item author with the pattern email (name)'); 
     
    116135$t->isnt($generatedFeed->getFeedUrl(), $feed->getFeedUrl(), 'The feedUrl property cannot be set from a RSS feed'); 
    117136$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'); 
    118142 
    119143$t->diag('fromXML() - generated feed items');