Author: as
Date: Wed Oct 10 14:03:18 2007
New Revision: 6413

Log:
- The RSS2 image node is created and parsed correctly.

Added:
    trunk/Feed/src/interfaces/node.php
      - copied, changed from r6394, trunk/Feed/src/feed_item.php
    trunk/Feed/src/nodes/
    trunk/Feed/src/nodes/image.php   (with props)
    trunk/Feed/src/nodes/item.php   (with props)
    trunk/Feed/tests/rss2/data/rss2-05_optional.xml
Removed:
    trunk/Feed/src/feed_item.php
Modified:
    trunk/Feed/ChangeLog
    trunk/Feed/design/class_diagram.png
    trunk/Feed/src/feed.php
    trunk/Feed/src/feed_autoload.php
    trunk/Feed/src/interfaces/processor.php
    trunk/Feed/src/processors/atom.php
    trunk/Feed/src/processors/rss.php
    trunk/Feed/src/processors/rss1.php
    trunk/Feed/src/processors/rss2.php
    trunk/Feed/tests/feed_test.php
    trunk/Feed/tests/rss2/data/rss2-05.xml
    trunk/Feed/tests/rss2/rss2_test.php

Modified: trunk/Feed/ChangeLog
==============================================================================
--- trunk/Feed/ChangeLog [iso-8859-1] (original)
+++ trunk/Feed/ChangeLog [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -1,3 +1,11 @@
+1.1alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- In RSS2 the title, link and description nodes of item nodes are not all
+  required, but at least one of title or description nodes is required.
+- The RSS2 image node is created and parsed correctly.
+
+
 1.0beta1 - Monday 18 December 2006
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: trunk/Feed/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/Feed/src/feed.php
==============================================================================
--- trunk/Feed/src/feed.php [iso-8859-1] (original)
+++ trunk/Feed/src/feed.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -244,12 +244,13 @@
             case 'category':
             case 'generator':
             case 'ttl':
-            case 'image': // icon in ATOM
+            //case 'image': // icon in ATOM
             case 'id': // ATOM only, required in ATOM
                 $this->feedProcessor->setFeedElement( $property, $value );
                 break;
 
             case 'items':
+            case 'image':
                 throw new ezcBasePropertyPermissionException( $property, 
ezcBasePropertyPermissionException::READ );
 
             default:
@@ -293,12 +294,15 @@
             case 'category':
             case 'generator':
             case 'ttl':
-            case 'image': // icon in ATOM
+            //case 'image': // icon in ATOM
             case 'id': // ATOM only, required in ATOM
                 return $this->feedProcessor->getFeedElement( $property );
 
             case 'items':
                 return (array) $this->feedProcessor->getItems();
+
+            case 'image':
+                return $this->feedProcessor->getImage();
 
             default:
                 throw new ezcBasePropertyNotFoundException( $property );
@@ -345,6 +349,23 @@
         $item = new ezcFeedItem( $this->feedProcessor );
         $this->feedProcessor->addItem( $item );
         return $item;
+    }
+
+    /**
+     * Creates and returns a new feed image for this feed.
+     *
+     * Example:
+     * <code>
+     * $image = $feed->newImage();
+     * </code>
+     *
+     * @return ezcFeedImage
+     */
+    public function newImage()
+    {
+        $image = new ezcFeedImage( $this->feedProcessor );
+        $this->feedProcessor->setImage( $image );
+        return $image;
     }
 
     /**

Modified: trunk/Feed/src/feed_autoload.php
==============================================================================
--- trunk/Feed/src/feed_autoload.php [iso-8859-1] (original)
+++ trunk/Feed/src/feed_autoload.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -24,10 +24,12 @@
     'ezcFeedParser'                                => 
'Feed/interfaces/parser.php',
     'ezcFeedProcessor'                             => 
'Feed/interfaces/processor.php',
     'ezcFeedModule'                                => 
'Feed/interfaces/module.php',
+    'ezcFeedNode'                                  => 
'Feed/interfaces/node.php',
     'ezcFeedRss'                                   => 
'Feed/processors/rss.php',
     'ezcFeed'                                      => 'Feed/feed.php',
     'ezcFeedAtom'                                  => 
'Feed/processors/atom.php',
-    'ezcFeedItem'                                  => 'Feed/feed_item.php',
+    'ezcFeedImage'                                 => 'Feed/nodes/image.php',
+    'ezcFeedItem'                                  => 'Feed/nodes/item.php',
     'ezcFeedItemModuleData'                        => 
'Feed/structs/item_module_data.php',
     'ezcFeedModuleContent'                         => 
'Feed/modules/content.php',
     'ezcFeedModuleData'                            => 
'Feed/structs/module_data.php',

Copied: trunk/Feed/src/interfaces/node.php (from r6394, 
trunk/Feed/src/feed_item.php)
==============================================================================
--- trunk/Feed/src/feed_item.php [iso-8859-1] (original)
+++ trunk/Feed/src/interfaces/node.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -1,6 +1,6 @@
 <?php
 /**
- * File containing the ezcFeedItem class.
+ * File containing the ezcFeedNode class.
  *
  * @package Feed
  * @version //autogentag//
@@ -10,13 +10,12 @@
  */
 
 /**
- * Class defining an item in a feed.
+ * Class defining a node in a feed.
  *
  * @package Feed
  * @version //autogentag//
- * @mainclass
  */
-class ezcFeedItem
+abstract class ezcFeedNode
 {
     /**
      * Holds the feed processor.
@@ -35,93 +34,13 @@
     protected $metaData = array();
 
     /**
-     * Holds the module meta data.
+     * Constructs a new feed node object.
      *
-     * @var array(string=>mixed)
-     * @ignore
-     */
-    protected $moduleMetaData = array();
-
-    /**
-     * Constructs a new feed item object.
-     *
-     * @param ezcFeedProcessor $processor The processor used by the feed item
+     * @param ezcFeedProcessor $processor The processor used by the feed node
      */
     public function __construct( $processor )
     {
         $this->feedProcessor = $processor;
-
-        $modules = $this->feedProcessor->getModules();
-        foreach ( $modules as $moduleName => $moduleObj )
-        {
-            $this->$moduleName = $this->feedProcessor->addItemModule( 
$moduleName, ezcFeed::getModule( $moduleName, 
$this->feedProcessor->getFeedType() ), $this );
-        }
-    }
-
-    /**
-     * Sets the property $property to $value.
-     *
-     * @param string $property The property name
-     * @param mixed $value The property value
-     * @ignore
-     */
-    public function __set( $property, $value )
-    {
-        switch ( $property )
-        {
-            case 'title': // required in RSS2
-            case 'link': // required in RSS2
-            case 'description': // required in RSS2
-            case 'author':
-            case 'category':
-            case 'comments':
-            case 'enclosure':
-            case 'guid':
-            case 'published': // pubDate in RSS2
-            case 'source': // original rss source
-                $this->feedProcessor->setFeedItemElement( $this, $property, 
$value );
-                break;
-        }
-
-        $modules = $this->feedProcessor->getModules();
-        foreach ( $modules as $moduleName => $moduleObj )
-        {
-            if ( $property == $moduleName )
-            {
-                $this->$moduleName = $value;
-            }
-        }
-    }
-
-    /**
-     * Returns the value of property $property.
-     *
-     * @throws ezcBasePropertyNotFoundException
-     *         If the property $property does not exist.
-     *
-     * @param string $property The property name
-     * @return mixed
-     * @ignore
-     */
-    public function __get( $property )
-    {
-        switch ( $property )
-        {
-            case 'title': // required in RSS2
-            case 'link': // required in RSS2
-            case 'description': // required in RSS2
-            case 'author':
-            case 'category':
-            case 'comments':
-            case 'enclosure':
-            case 'guid':
-            case 'published': // pubDate in RSS2
-            case 'source': // original rss source
-                return $this->feedProcessor->getFeedItemElement( $this, 
$property );
-
-            default:
-                throw new ezcBasePropertyNotFoundException( $property );
-        }
     }
 
     public function setMetaData( $element, $value )
@@ -154,21 +73,6 @@
         }
     }
 
-    public function setModuleMetaData( $moduleName, $moduleObj, $element, 
$value )
-    {
-        $value = $moduleObj->prepareMetaData( $element, $value );
-        $this->moduleMetaData[$moduleName][$element] = $value;
-    }
-
-    public function getModuleMetaData( $module, $element )
-    {
-        if ( isset( $this->moduleMetaData[$module][$element] ) )
-        {
-            return $this->moduleMetaData[$module][$element];
-        }
-        return null;
-    }
-
     public function getMetaData( $element )
     {
         if ( isset( $this->metaData[$element] ) )
@@ -177,14 +81,5 @@
         }
         return null;
     }
-
-    public function getAllModuleMetaData( $module )
-    {
-        if ( isset( $this->moduleMetaData[$module] ) )
-        {
-            return $this->moduleMetaData[$module];
-        }
-        return array();
-    }
 }
 ?>

Modified: trunk/Feed/src/interfaces/processor.php
==============================================================================
--- trunk/Feed/src/interfaces/processor.php [iso-8859-1] (original)
+++ trunk/Feed/src/interfaces/processor.php [iso-8859-1] Wed Oct 10 14:03:18 
2007
@@ -347,6 +347,14 @@
     abstract public function setFeedElement( $element, $value );
 
     /**
+     * Returns the value of the feed element $element.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    abstract public function getFeedElement( $element );
+
+    /**
      * Sets the value of the feed element $element of feed item $item to 
$value.
      *
      * The hook [EMAIL PROTECTED] self::processModuleItemSetHook()} can be 
used in the
@@ -359,14 +367,6 @@
     abstract public function setFeedItemElement( ezcFeedItem $item, $element, 
$value );
 
     /**
-     * Returns the value of the feed element $element.
-     *
-     * @param string $element The feed element
-     * @return mixed
-     */
-    abstract public function getFeedElement( $element );
-
-    /**
      * Returns the value of the element $element of feed item $item.
      *
      * @param ezcFeedItem $item The feed item object
@@ -374,6 +374,22 @@
      * @return mixed
      */
     abstract public function getFeedItemElement( ezcFeedItem $item, $element );
+
+    /**
+     * Sets the value of the feed element $element of the feed image to $value.
+     *
+     * @param string $element The feed element
+     * @param mixed $value The new value of $element
+     */
+    abstract public function setFeedImageElement( $element, $value );
+
+    /**
+     * Returns the value of the element $element of the feed image.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    abstract public function getFeedImageElement( $element );
 
     /**
      * Returns an XML string from the feed information contained in this

Added: trunk/Feed/src/nodes/image.php
==============================================================================
--- trunk/Feed/src/nodes/image.php (added)
+++ trunk/Feed/src/nodes/image.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -1,0 +1,79 @@
+<?php
+/**
+ * File containing the ezcFeedItem class.
+ *
+ * @package Feed
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ */
+
+/**
+ * Class defining an image node in a feed.
+ *
+ * @package Feed
+ * @version //autogentag//
+ */
+class ezcFeedImage extends ezcFeedNode
+{
+    /**
+     * Constructs a new feed image object.
+     *
+     * @param ezcFeedProcessor $processor The processor used by the feed image
+     */
+    public function __construct( $processor )
+    {
+        parent::__construct( $processor );
+    }
+
+    /**
+     * Sets the property $property to $value.
+     *
+     * @param string $property The property name
+     * @param mixed $value The property value
+     * @ignore
+     */
+    public function __set( $property, $value )
+    {
+        switch ( $property )
+        {
+            case 'title': // required in RSS2
+            case 'link': // required in RSS2
+            case 'url': // required in RSS2
+            case 'description':
+            case 'width':
+            case 'height':
+                $this->feedProcessor->setFeedImageElement( $property, $value );
+                break;
+        }
+    }
+
+    /**
+     * Returns the value of property $property.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         If the property $property does not exist.
+     *
+     * @param string $property The property name
+     * @return mixed
+     * @ignore
+     */
+    public function __get( $property )
+    {
+        switch ( $property )
+        {
+            case 'title': // required in RSS2
+            case 'link': // required in RSS2
+            case 'url': // required in RSS2
+            case 'description':
+            case 'width':
+            case 'height':
+                return $this->feedProcessor->getFeedImageElement( $property );
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $property );
+        }
+    }
+}
+?>

Propchange: trunk/Feed/src/nodes/image.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Feed/src/nodes/item.php
==============================================================================
--- trunk/Feed/src/nodes/item.php (added)
+++ trunk/Feed/src/nodes/item.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -1,0 +1,135 @@
+<?php
+/**
+ * File containing the ezcFeedItem class.
+ *
+ * @package Feed
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ */
+
+/**
+ * Class defining an item in a feed.
+ *
+ * @package Feed
+ * @version //autogentag//
+ * @mainclass
+ */
+class ezcFeedItem extends ezcFeedNode
+{
+    /**
+     * Holds the module meta data.
+     *
+     * @var array(string=>mixed)
+     * @ignore
+     */
+    protected $moduleMetaData = array();
+
+    /**
+     * Constructs a new feed item object.
+     *
+     * @param ezcFeedProcessor $processor The processor used by the feed item
+     */
+    public function __construct( $processor )
+    {
+        parent::__construct( $processor );
+
+        $modules = $this->feedProcessor->getModules();
+        foreach ( $modules as $moduleName => $moduleObj )
+        {
+            $this->$moduleName = $this->feedProcessor->addItemModule( 
$moduleName, ezcFeed::getModule( $moduleName, 
$this->feedProcessor->getFeedType() ), $this );
+        }
+    }
+
+    /**
+     * Sets the property $property to $value.
+     *
+     * @param string $property The property name
+     * @param mixed $value The property value
+     * @ignore
+     */
+    public function __set( $property, $value )
+    {
+        switch ( $property )
+        {
+            case 'title': // required in RSS2
+            case 'link': // required in RSS2
+            case 'description': // required in RSS2
+            case 'author':
+            case 'category':
+            case 'comments':
+            case 'enclosure':
+            case 'guid':
+            case 'published': // pubDate in RSS2
+            case 'source': // original rss source
+                $this->feedProcessor->setFeedItemElement( $this, $property, 
$value );
+                break;
+        }
+
+        $modules = $this->feedProcessor->getModules();
+        foreach ( $modules as $moduleName => $moduleObj )
+        {
+            if ( $property == $moduleName )
+            {
+                $this->$moduleName = $value;
+            }
+        }
+    }
+
+    /**
+     * Returns the value of property $property.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         If the property $property does not exist.
+     *
+     * @param string $property The property name
+     * @return mixed
+     * @ignore
+     */
+    public function __get( $property )
+    {
+        switch ( $property )
+        {
+            case 'title': // required in RSS2
+            case 'link': // required in RSS2
+            case 'description': // required in RSS2
+            case 'author':
+            case 'category':
+            case 'comments':
+            case 'enclosure':
+            case 'guid':
+            case 'published': // pubDate in RSS2
+            case 'source': // original rss source
+                return $this->feedProcessor->getFeedItemElement( $this, 
$property );
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $property );
+        }
+    }
+
+    public function setModuleMetaData( $moduleName, $moduleObj, $element, 
$value )
+    {
+        $value = $moduleObj->prepareMetaData( $element, $value );
+        $this->moduleMetaData[$moduleName][$element] = $value;
+    }
+
+    public function getModuleMetaData( $module, $element )
+    {
+        if ( isset( $this->moduleMetaData[$module][$element] ) )
+        {
+            return $this->moduleMetaData[$module][$element];
+        }
+        return null;
+    }
+
+    public function getAllModuleMetaData( $module )
+    {
+        if ( isset( $this->moduleMetaData[$module] ) )
+        {
+            return $this->moduleMetaData[$module];
+        }
+        return array();
+    }
+}
+?>

Propchange: trunk/Feed/src/nodes/item.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Feed/src/processors/atom.php
==============================================================================
--- trunk/Feed/src/processors/atom.php [iso-8859-1] (original)
+++ trunk/Feed/src/processors/atom.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -49,6 +49,16 @@
     }
 
     /**
+     * Returns the value of the feed element $element.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedElement( $element )
+    {
+    }
+
+    /**
      * Sets the value of the feed element $element of feed item $item to 
$value.
      *
      * The hook [EMAIL PROTECTED] 
ezcFeedProcessor::processModuleItemSetHook()} is called
@@ -63,16 +73,6 @@
     }
 
     /**
-     * Returns the value of the feed element $element.
-     *
-     * @param string $element The feed element
-     * @return mixed
-     */
-    public function getFeedElement( $element )
-    {
-    }
-
-    /**
      * Returns the value of the element $element of feed item $item.
      *
      * @param ezcFeedItem $item The feed item object
@@ -80,6 +80,26 @@
      * @return mixed
      */
     public function getFeedItemElement( ezcFeedItem $item, $element )
+    {
+    }
+
+    /**
+     * Sets the value of the feed element $element of the feed image to $value.
+     *
+     * @param string $element The feed element
+     * @param mixed $value The new value of $element
+     */
+    public function setFeedImageElement( $element, $value )
+    {
+    }
+
+    /**
+     * Returns the value of the element $element of the feed image.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedImageElement( $element )
     {
     }
 

Modified: trunk/Feed/src/processors/rss.php
==============================================================================
--- trunk/Feed/src/processors/rss.php [iso-8859-1] (original)
+++ trunk/Feed/src/processors/rss.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -37,6 +37,13 @@
     protected $channel;
 
     /**
+     * Holds the image node of the XML document being generated.
+     *
+     * @var ezcFeedImage
+     */
+    protected $image;
+
+    /**
      * Holds the item nodes of the XML document being generated.
      *
      * @var array(ezcFeedItem)
@@ -157,18 +164,33 @@
      * @param string $title The title of the image element
      * @param string $link The link of the image element
      * @param string $imageUrl The image URL of the image element
-     */
-    public function generateImage( DOMNode $item, $title, $link, $imageUrl )
+
+    public function generateImage( DOMNode $item, $title, $link, $imageUrl, 
$description = null, $width = null, $height = null )
     {
         $image = $this->xml->createElement( 'image' );
-        $title = $this->xml->createElement( 'title', $title );
-        $link = $this->xml->createElement( 'link', $link );
-        $url = $this->xml->createElement( 'url', $imageUrl );
-        $image->appendChild( $title );
-        $image->appendChild( $link );
-        $image->appendChild( $url );
+
+        $image->appendChild( $this->xml->createElement( 'title', $title ) );
+        $image->appendChild( $this->xml->createElement( 'link', $link ) );
+        $image->appendChild( $this->xml->createElement( 'url', $imageUrl ) );
+
+        if ( $description !== null )
+        {
+            $image->appendChild( $this->xml->createElement( 'description', 
$description ) );
+        }
+
+        if ( $width !== null )
+        {
+            $image->appendChild( $this->xml->createElement( 'width', $width ) 
);
+        }
+
+        if ( $height !== null )
+        {
+            $image->appendChild( $this->xml->createElement( 'height', $height 
) );
+        }
+
         $item->appendChild( $image );
     }
+     */
 
     /**
      * Returns the provided $date in timestamp format.
@@ -308,7 +330,7 @@
     {
         $this->items[] = $item;
     }
-    
+
     /**
      * Returns the feed items in this processor.
      *
@@ -317,6 +339,26 @@
     public function getItems()
     {
         return $this->items;
+    }
+
+    /**
+     * Adds a new feed image to this processor.
+     *
+     * @param ezcFeedImage $image The feed image object to add
+     */
+    public function setImage( ezcFeedImage $image )
+    {
+        $this->image = $image;
+    }
+
+    /**
+     * Returns the feed image in this processor.
+     *
+     * @return ezcFeedImage
+     */
+    public function getImage()
+    {
+        return ( isset( $this->image ) ) ? $this->image : null;
     }
 }
 ?>

Modified: trunk/Feed/src/processors/rss1.php
==============================================================================
--- trunk/Feed/src/processors/rss1.php [iso-8859-1] (original)
+++ trunk/Feed/src/processors/rss1.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -51,6 +51,16 @@
     }
 
     /**
+     * Returns the value of the feed element $element.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedElement( $element )
+    {
+    }
+
+    /**
      * Sets the value of the feed element $element of feed item $item to 
$value.
      *
      * The hook [EMAIL PROTECTED] 
ezcFeedProcessor::processModuleItemSetHook()} is called
@@ -65,16 +75,6 @@
     }
 
     /**
-     * Returns the value of the feed element $element.
-     *
-     * @param string $element The feed element
-     * @return mixed
-     */
-    public function getFeedElement( $element )
-    {
-    }
-
-    /**
      * Returns the value of the element $element of feed item $item.
      *
      * @param ezcFeedItem $item The feed item object
@@ -82,6 +82,26 @@
      * @return mixed
      */
     public function getFeedItemElement( ezcFeedItem $item, $element )
+    {
+    }
+
+    /**
+     * Sets the value of the feed element $element of the feed image to $value.
+     *
+     * @param string $element The feed element
+     * @param mixed $value The new value of $element
+     */
+    public function setFeedImageElement( $element, $value )
+    {
+    }
+
+    /**
+     * Returns the value of the element $element of the feed image.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedImageElement( $element )
     {
     }
 

Modified: trunk/Feed/src/processors/rss2.php
==============================================================================
--- trunk/Feed/src/processors/rss2.php [iso-8859-1] (original)
+++ trunk/Feed/src/processors/rss2.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -93,6 +93,28 @@
     );
 
     /**
+     * Holds a list of required attributes for image definitions.
+     *
+     * @var array(string)
+     */
+    protected static $requiredFeedImageAttributes = array( 'url', 'title', 
'link' );
+
+    /**
+     * Holds a list of optional attributes for image definitions.
+     *
+     * @var array(string)
+     */
+    protected static $optionalFeedImageAttributes = array( 'description', 
'width', 'height' );
+
+    /**
+     * Holds a mapping of the common names for image attributes to feed 
specific
+     * names.
+     *
+     * @var array(string=>string)
+     */
+    protected static $feedImageAttributesMap = array();
+
+    /**
      * Holds the prefixes used in the feed generation process.
      *
      * @var array(string)
@@ -145,6 +167,18 @@
     }
 
     /**
+     * Returns the value of the feed element $element.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedElement( $element )
+    {
+        $element = $this->normalizeName( $element, self::$feedAttributesMap );
+        return $this->getMetaData( $element );
+    }
+
+    /**
      * Sets the value of the feed element $element of feed item $item to 
$value.
      *
      * The hook [EMAIL PROTECTED] 
ezcFeedProcessor::processModuleItemSetHook()} is called
@@ -177,18 +211,6 @@
     }
 
     /**
-     * Returns the value of the feed element $element.
-     *
-     * @param string $element The feed element
-     * @return mixed
-     */
-    public function getFeedElement( $element )
-    {
-        $element = $this->normalizeName( $element, self::$feedAttributesMap );
-        return $this->getMetaData( $element );
-    }
-
-    /**
      * Returns the value of the element $element of feed item $item.
      *
      * @param ezcFeedItem $item The feed item object
@@ -199,6 +221,33 @@
     {
         $element = $this->normalizeName( $element, 
self::$feedItemAttributesMap );
         return $item->getMetaData( $element );
+    }
+
+    /**
+     * Sets the value of the feed element $element of the feed image to $value.
+     *
+     * @param string $element The feed element
+     * @param mixed $value The new value of $element
+     */
+    public function setFeedImageElement( $element, $value )
+    {
+        if ( in_array( $element, self::$requiredFeedImageAttributes )
+             || in_array( $element, self::$optionalFeedImageAttributes ) )
+        {
+            $this->image->setMetaData( $element, $value );
+        }
+    }
+
+    /**
+     * Returns the value of the element $element of the feed image.
+     *
+     * @param string $element The feed element
+     * @return mixed
+     */
+    public function getFeedImageElement( $element )
+    {
+        $element = $this->normalizeName( $element, 
self::$feedImageAttributesMap );
+        return $this->image->getMetaData( $element );
     }
 
     /**
@@ -274,6 +323,40 @@
     }
 
     /**
+     * Generates the required data for the feed image and includes it in
+     * the XML document which is being generated.
+     *
+     * @param ezcFeedImage $image The feed image object
+     * @return string
+     */
+    protected function generateImage( ezcFeedImage $image )
+    {
+        $imageTag = $this->xml->createElement( 'image' );
+        $this->channel->appendChild( $imageTag );
+
+        foreach ( self::$requiredFeedImageAttributes as $attribute )
+        {
+            $data = $image->$attribute;
+            if ( is_null( $data ) )
+            {
+                throw new ezcFeedRequiredItemDataMissingException( $attribute 
);
+            }
+            $this->generateItemData( $imageTag, $attribute, $data );
+        }
+
+        foreach ( self::$optionalFeedImageAttributes as $attribute )
+        {
+            $normalizedAttribute = $this->normalizeName( $attribute, 
self::$feedImageAttributesMap );
+
+            $metaData = $image->getMetaData( $attribute );
+            if ( !is_null( $metaData ) )
+            {
+                $this->generateItemData( $imageTag, $normalizedAttribute, 
$metaData );
+            }
+        }
+    }
+
+    /**
      * Returns an XML string from the feed information contained in this
      * processor.
      *
@@ -313,9 +396,10 @@
                 {
                     switch ( $attribute )
                     {
-                        case 'image':
-                            $this->generateImage( $this->channel, 
$this->getMetaData( 'title' ), $this->getMetaData( 'link' ), $data );
-                            break;
+                        //case 'image':
+                        //    $this->generateImage( $this->image ); 
//$this->channel, $this->getMetaData( 'title' ), $this->getMetaData( 'link' ), 
$data,
+                                //$this->getMetaData( 'description' ), 
$this->getMetaData( 'width' ), $this->getMetaData( 'height' ) );
+                        //    break;
 
                         case 'published':
                         case 'updated':
@@ -340,6 +424,11 @@
             {
                 $moduleDescription->moduleObj->generateMetaData( $this, 
$element, $value );
             }
+        }
+
+        if ( isset( $this->image ) )
+        {
+            $this->generateImage( $this->image );
         }
 
         foreach ( $this->items as $item )
@@ -453,6 +542,10 @@
                         $this->parseItem( $feed, $channelChild );
                         break;
 
+                    case 'image':
+                        $this->parseImage( $feed, $channelChild );
+                        break;
+
                     default:
                         // check if it's part of a known module/namespace
                         $parts = explode( ':', $tagName );
@@ -475,10 +568,10 @@
      * @param ezcFeed $feed The feed object in which to store the parsed XML 
element as a feed item
      * @param DOMElement $xml The XML element object to parse
      */
-    public function parseItem( ezcFeed $feed, DOMElement $item )
+    public function parseItem( ezcFeed $feed, DOMElement $xml )
     {
         $feedItem = $feed->newItem();
-        foreach ( $item->childNodes as $itemChild )
+        foreach ( $xml->childNodes as $itemChild )
         {
             if ( $itemChild->nodeType == XML_ELEMENT_NODE )
             {
@@ -521,5 +614,39 @@
             }
         }
     }
+
+    /**
+     * Parses the provided XML element object and stores it as a feed image in
+     * the provided ezcFeed object.
+     *
+     * @param ezcFeed $feed The feed object in which to store the parsed XML 
element as a feed image
+     * @param DOMElement $xml The XML element object to parse
+     */
+    public function parseImage( ezcFeed $feed, DOMElement $xml )
+    {
+        $feedImage = $feed->newImage();
+        foreach ( $xml->childNodes as $itemChild )
+        {
+            if ( $itemChild->nodeType == XML_ELEMENT_NODE )
+            {
+                $tagName = $itemChild->tagName;
+                $tagName = $this->deNormalizeName( $tagName, 
self::$feedImageAttributesMap );
+
+                switch ( $tagName )
+                {
+                    case 'title': // required in RSS2
+                    case 'link': // required in RSS2
+                    case 'url': // required in RSS2
+                    case 'description':
+                    case 'width':
+                    case 'height':
+                        $feedImage->$tagName = $itemChild->textContent;
+                        break;
+
+                    // @todo check if there are extra subnodes in <image>
+                }
+            }
+        }
+    }
 }
 ?>

Modified: trunk/Feed/tests/feed_test.php
==============================================================================
--- trunk/Feed/tests/feed_test.php [iso-8859-1] (original)
+++ trunk/Feed/tests/feed_test.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -128,6 +128,7 @@
         $feed = new ezcFeed( 'rss2' );
 
         $this->readonlyPropertyTest( $feed, 'items' );
+        $this->readonlyPropertyTest( $feed, 'image' );
 
         try
         {
@@ -156,6 +157,24 @@
         }
     }
 
+    public function testFeedImageProperties()
+    {
+        $feed = new ezcFeed( 'rss2' );
+        $feedImage = $feed->newImage();
+
+        $feedImage = $feed->image;
+
+        try
+        {
+            $value = $feedImage->no_such_property;
+            $this->fail( "Expected exception was not thrown." );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name 'no_such_property'.", 
$e->getMessage() );
+        }
+    }
+
     public function testFeedItemSetMetaDataFail()
     {
         $feed = new ezcFeed( 'rss2' );

Modified: trunk/Feed/tests/rss2/data/rss2-05.xml
==============================================================================
--- trunk/Feed/tests/rss2/data/rss2-05.xml [iso-8859-1] (original)
+++ trunk/Feed/tests/rss2/data/rss2-05.xml [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -16,9 +16,9 @@
     <ttl>86400</ttl>
     <docs>http://www.rssboard.org/rss-specification</docs>
     <image>
-      <title>eZ Components test</title>
-      <link>http://components.ez.no</link>
       
<url>http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png</url>
+      <title>Downloads</title>
+      <link>http://ez.no/download</link>
     </image>
     <item>
       <title>First Item</title>

Added: trunk/Feed/tests/rss2/data/rss2-05_optional.xml
==============================================================================
--- trunk/Feed/tests/rss2/data/rss2-05_optional.xml (added)
+++ trunk/Feed/tests/rss2/data/rss2-05_optional.xml [iso-8859-1] Wed Oct 10 
14:03:18 2007
@@ -1,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0">
+  <channel>
+    <title>eZ Components test</title>
+    <link>http://components.ez.no</link>
+    <description>This is a test for the eZ Components Feed 
Generator</description>
+    <language>nl</language>
+    <copyright>eZ systems</copyright>
+    <managingEditor>[EMAIL PROTECTED] (Derick Rethans)</managingEditor>
+    <webMaster>[EMAIL PROTECTED] (Derick Rethans)</webMaster>
+    <pubDate>Fri, 26 May 2006 10:46:31 +0200</pubDate>
+    <lastBuildDate>Fri, 26 May 2006 10:46:31 +0200</lastBuildDate>
+    <category>test</category>
+    <category>eZ Components</category>
+    <generator>eZ Components TEST</generator>
+    <ttl>86400</ttl>
+    <docs>http://www.rssboard.org/rss-specification</docs>
+    <image>
+      
<url>http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png</url>
+      <title>Downloads</title>
+      <link>http://ez.no/download</link>
+      <description>Newest versions are available for download.</description>
+      <width>176</width>
+      <height>62</height>
+    </image>
+    <item>
+      <title>First Item</title>
+      <link>http://components.ez.no/1</link>
+      <description>This is the first item</description>
+    </item>
+  </channel>
+</rss>

Modified: trunk/Feed/tests/rss2/rss2_test.php
==============================================================================
--- trunk/Feed/tests/rss2/rss2_test.php [iso-8859-1] (original)
+++ trunk/Feed/tests/rss2/rss2_test.php [iso-8859-1] Wed Oct 10 14:03:18 2007
@@ -187,7 +187,11 @@
         $feed->copyright = "eZ systems";
         $feed->generator = "eZ Components TEST";
         $feed->ttl = 86400;
-        $feed->image = 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";;
+
+        $image = $feed->newImage();
+        $image->url = 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";;
+        $image->title = "Downloads";
+        $image->link = "http://ez.no/download";;
 
         $item = $feed->newItem();
         $item->title = "First Item";
@@ -196,6 +200,71 @@
 
         $expected = file_get_contents( dirname( __FILE__ ) . 
"/data/rss2-05.xml" );
         self::assertEquals( $expected, $feed->generate() );
+    }
+
+    public function testComplex1WithOptional()
+    {
+        $feed = new ezcFeed( 'rss2' );
+        $feed->title = "eZ Components test";
+        $feed->link = "http://components.ez.no";;
+        $feed->description = "This is a test for the eZ Components Feed 
Generator";
+        $feed->author = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->webMaster = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->published = 1148633191;
+        $feed->updated = "Fri May 26, 08:46:31 2006 UTC";
+        $feed->category = "test";
+        $feed->category = "eZ Components";
+        $feed->language = "nl";
+        $feed->copyright = "eZ systems";
+        $feed->generator = "eZ Components TEST";
+        $feed->ttl = 86400;
+
+        $image = $feed->newImage();
+        $image->url = 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";;
+        $image->title = "Downloads";
+        $image->link = "http://ez.no/download";;
+        $image->description = "Newest versions are available for download.";
+        $image->width = "176";
+        $image->height = "62";
+
+        $item = $feed->newItem();
+        $item->title = "First Item";
+        $item->link = "http://components.ez.no/1";;
+        $item->description = "This is the first item";
+
+        $expected = file_get_contents( dirname( __FILE__ ) . 
"/data/rss2-05_optional.xml" );
+        self::assertEquals( $expected, $feed->generate() );
+    }
+
+    public function testComplex1MissingRequired()
+    {
+        $feed = new ezcFeed( 'rss2' );
+        $feed->title = "eZ Components test";
+        $feed->link = "http://components.ez.no";;
+        $feed->description = "This is a test for the eZ Components Feed 
Generator";
+        $feed->author = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->webMaster = "[EMAIL PROTECTED] (Derick Rethans)";
+        $feed->published = 1148633191;
+        $feed->updated = "Fri May 26, 08:46:31 2006 UTC";
+        $feed->category = "test";
+        $feed->category = "eZ Components";
+        $feed->language = "nl";
+        $feed->copyright = "eZ systems";
+        $feed->generator = "eZ Components TEST";
+        $feed->ttl = 86400;
+
+        $image = $feed->newImage();
+        $image->url = 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";;
+
+        try
+        {
+            $feed->generate();
+            self::fail( 'Expected exception was not thrown.' );
+        }
+        catch ( ezcFeedRequiredItemDataMissingException $e )
+        {
+            self::assertEquals( "There was no data submitted for required 
attribute 'title'.", $e->getMessage() );
+        }
     }
 
     public function testComplex2()
@@ -345,6 +414,25 @@
         self::assertEquals( $expected, $feed->generate() );
     }
 
+    public function testParseImage1()
+    {
+        $feed = ezcFeed::parse( dirname( __FILE__ ) . "/data/rss2-05.xml" );
+        self::assertEquals( 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";,
 $feed->image->url );
+        self::assertEquals( "Downloads", $feed->image->title );
+        self::assertEquals( "http://ez.no/download";, $feed->image->link );
+    }
+
+    public function testParseImage1OptionalAttributes()
+    {
+        $feed = ezcFeed::parse( dirname( __FILE__ ) . 
"/data/rss2-05_optional.xml" );
+        self::assertEquals( 
"http://ez.no/var/ezno/storage/images/download/other_downloads/powered_by_ez_components_logos/108x31/472645-3-eng-GB/108x31.png";,
 $feed->image->url );
+        self::assertEquals( "Downloads", $feed->image->title );
+        self::assertEquals( "http://ez.no/download";, $feed->image->link );
+        self::assertEquals( "Newest versions are available for download.", 
$feed->image->description );
+        self::assertEquals( "176", $feed->image->width );
+        self::assertEquals( "62", $feed->image->height );
+    }
+
     public function testParseComplexWithModule1()
     {
         $feed = ezcFeed::parse( dirname( __FILE__ ) . "/data/rss2-09.xml" );


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to