incubator-zeta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From der...@apache.org
Subject [zeta-commits] svn commit: r1001189 - in /incubator/zetacomponents/trunk/Feed: ChangeLog src/feed.php src/feed_autoload.php src/interfaces/module.php src/modules/georss_module.php
Date Sat, 25 Sep 2010 10:40:52 GMT
Author: derick
Date: Sat Sep 25 10:40:52 2010
New Revision: 1001189

URL: http://svn.apache.org/viewvc?rev=1001189&view=rev
Log:
- Added the GeoRSS module.
#- Iteration one, tests and more stuff still needs to follow.

Added:
    incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php   (with props)
Modified:
    incubator/zetacomponents/trunk/Feed/ChangeLog
    incubator/zetacomponents/trunk/Feed/src/feed.php
    incubator/zetacomponents/trunk/Feed/src/feed_autoload.php
    incubator/zetacomponents/trunk/Feed/src/interfaces/module.php

Modified: incubator/zetacomponents/trunk/Feed/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Feed/ChangeLog?rev=1001189&r1=1001188&r2=1001189&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Feed/ChangeLog (original)
+++ incubator/zetacomponents/trunk/Feed/ChangeLog Sat Sep 25 10:40:52 2010
@@ -1,3 +1,9 @@
+1.4alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Added the GeoRSS module.
+
+
 1.3 - Monday 21 December 2009
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: incubator/zetacomponents/trunk/Feed/src/feed.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Feed/src/feed.php?rev=1001189&r1=1001188&r2=1001189&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Feed/src/feed.php (original)
+++ incubator/zetacomponents/trunk/Feed/src/feed.php Sat Sep 25 10:40:52 2010
@@ -53,6 +53,8 @@
  *    {@link http://dublincore.org/documents/dces/ Specifications}
  *  - Geo ({@link ezcFeedGeoModule}) -
  *    {@link http://www.w3.org/2003/01/geo/ Specifications}
+ *  - GeoRss ({@link ezcFeedGeoRssModule}) -
+ *    {@link http://www.georss.org/georss/ Specifications}
  *  - iTunes ({@link ezcFeedITunesModule}) -
  *    {@link http://www.apple.com/itunes/store/podcaststechspecs.html Specifications}
  *
@@ -973,6 +975,7 @@ class ezcFeed
      *    'CreativeCommons' => 'ezcFeedCreativeCommonsModule',
      *    'DublinCore'      => 'ezcFeedDublinCoreModule',
      *    'Geo'             => 'ezcFeedGeoModule',
+     *    'GeoRss'          => 'ezcFeedGeoRssModule',
      *    'iTunes'          => 'ezcFeedITunesModule'
      * );
      * </code>
@@ -997,6 +1000,7 @@ class ezcFeed
      *    'creativeCommons' => 'CreativeCommons',
      *    'dc'              => 'DublinCore',
      *    'geo'             => 'Geo',
+     *    'georss'          => 'GeoRss',
      *    'itunes'          => 'iTunes'
      * );
      * </code>
@@ -1164,6 +1168,7 @@ class ezcFeed
         self::registerModule( 'CreativeCommons', 'ezcFeedCreativeCommonsModule', 'creativeCommons'
);
         self::registerModule( 'DublinCore', 'ezcFeedDublinCoreModule', 'dc' );
         self::registerModule( 'Geo', 'ezcFeedGeoModule', 'geo' );
+        self::registerModule( 'GeoRss', 'ezcFeedGeoRssModule', 'georss' );
         self::registerModule( 'iTunes', 'ezcFeedITunesModule', 'itunes' );
     }
 }

Modified: incubator/zetacomponents/trunk/Feed/src/feed_autoload.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Feed/src/feed_autoload.php?rev=1001189&r1=1001188&r2=1001189&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Feed/src/feed_autoload.php (original)
+++ incubator/zetacomponents/trunk/Feed/src/feed_autoload.php Sat Sep 25 10:40:52 2010
@@ -53,6 +53,7 @@ return array(
     'ezcFeedEntryElement'                        => 'Feed/structs/entry.php',
     'ezcFeedGeneratorElement'                    => 'Feed/structs/generator.php',
     'ezcFeedGeoModule'                           => 'Feed/modules/geo_module.php',
+    'ezcFeedGeoRssModule'                        => 'Feed/modules/georss_module.php',
     'ezcFeedITunesModule'                        => 'Feed/modules/itunes_module.php',
     'ezcFeedIdElement'                           => 'Feed/structs/id.php',
     'ezcFeedImageElement'                        => 'Feed/structs/image.php',

Modified: incubator/zetacomponents/trunk/Feed/src/interfaces/module.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Feed/src/interfaces/module.php?rev=1001189&r1=1001188&r2=1001189&view=diff
==============================================================================
--- incubator/zetacomponents/trunk/Feed/src/interfaces/module.php (original)
+++ incubator/zetacomponents/trunk/Feed/src/interfaces/module.php Sat Sep 25 10:40:52 2010
@@ -37,6 +37,8 @@
  *    {@link http://www.apple.com/itunes/store/podcaststechspecs.html Specifications}
  *  - Geo ({@link ezcFeedGeoModule}) -
  *    {@link http://www.w3.org/2003/01/geo/ Specifications}
+ *  - GeoRss ({@link ezcFeedGeoModule}) -
+ *    {@link http://www.georss.org/georss/ Specifications}
  *  - CreativeCommons ({@link ezcFeedCreativeCommonsModule}) -
  *    {@link http://backend.userland.com/creativeCommonsRssModule Specifications}
  *

Added: incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php
URL: http://svn.apache.org/viewvc/incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php?rev=1001189&view=auto
==============================================================================
--- incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php (added)
+++ incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php Sat Sep 25 10:40:52
2010
@@ -0,0 +1,270 @@
+<?php
+/**
+ * File containing the ezcFeedGeoRssModule class.
+ *
+ * @package Feed
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ */
+
+/**
+ * Support for the GeoRss module: data container, generator, parser.
+ *
+ * Specifications: {@link http://www.w3.org/2003/01/geo/}.
+ *
+ * Create example:
+ *
+ * <code>
+ * <?php
+ * // $feed is an ezcFeed object
+ * $item = $feed->add( 'item' );
+ * $module = $item->addModule( 'GeoRss' );
+ * $module->lat = 26.58;
+ * $module->long = -97.83;
+ * ?>
+ * </code>
+ *
+ * Parse example:
+ *
+ * <code>
+ * <?php
+ * // $item is an ezcFeedEntryElement object
+ * $lat = isset( $item->GeoRss->lat ) ? $item->GeoRss->lat->__toString() :
null;
+ * $long = isset( $item->GeoRss->long ) ? $item->GeoRss->long->__toString()
: null;
+ * ?>
+ * </code>
+ *
+ * @property ezcFeedTextElement $lat
+ *                              {@link http://en.wikipedia.org/wiki/WGS84 WGS84} latitude
+ *                              on the globe as decimal degrees
+ *                              (eg. 25.03358300). Can also be negative.
+ * @property ezcFeedTextElement $long
+ *                              {@link http://en.wikipedia.org/wiki/WGS84 WGS84} longitude
+ *                              on the globe as decimal degrees
+ *                              (eg. 121.56430000). Can also be negative.
+ *
+ * @package Feed
+ * @version //autogentag//
+ */
+class ezcFeedGeoRssModule extends ezcFeedModule
+{
+    /**
+     * Constructs a new ezcFeedContentModule object.
+     *
+     * @param string $level The level of the data container ('feed' or 'item')
+     */
+    public function __construct( $level = 'feed' )
+    {
+        parent::__construct( $level );
+    }
+
+    /**
+     * Sets the property $name to $value.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name is not defined
+     *
+     * @param string $name The property name
+     * @param mixed $value The property value
+     * @ignore
+     */
+    public function __set( $name, $value )
+    {
+        if ( $this->isElementAllowed( $name ) )
+        {
+            $node = $this->add( $name );
+            $node->text = $value;
+        }
+        else
+        {
+            parent::__set( $name, $value );
+        }
+    }
+
+    /**
+     * Returns the value of property $name.
+     *
+     * @throws ezcBasePropertyNotFoundException
+     *         if the property $name is not defined
+     *
+     * @param string $name The property name
+     * @return mixed
+     * @ignore
+     */
+    public function __get( $name )
+    {
+        if ( $this->isElementAllowed( $name ) )
+        {
+            return $this->properties[$name];
+        }
+        else
+        {
+            return parent::__get( $name );
+        }
+    }
+
+    /**
+     * Returns if the property $name is set.
+     *
+     * @param string $name The property name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        if ( $this->isElementAllowed( $name ) )
+        {
+            return isset( $this->properties[$name] );
+        }
+        else
+        {
+            return parent::__isset( $name );
+        }
+    }
+
+    /**
+     * Returns true if the element $name is allowed in the current module at the
+     * current level (feed or item), and false otherwise.
+     *
+     * @param string $name The element name to check if allowed in the current module and
level (feed or item)
+     * @return bool
+     */
+    public function isElementAllowed( $name )
+    {
+        switch ( $this->level )
+        {
+            case 'feed':
+                if ( in_array( $name, array( 'lat', 'long', 'point', 'where' ) ) )
+                {
+                    return true;
+                }
+                break;
+
+            case 'item':
+                if ( in_array( $name, array( 'lat', 'long', 'point', 'where' ) ) )
+                {
+                    return true;
+                }
+                break;
+        }
+        return false;
+    }
+
+    /**
+     * Adds a new ezcFeedElement element with name $name to this module and
+     * returns it.
+     *
+     * @throws ezcFeedUnsupportedElementException
+     *         if trying to add an element which is not supported.
+     *
+     * @param string $name The element name
+     * @return ezcFeedElement
+     */
+    public function add( $name )
+    {
+        if ( $this->isElementAllowed( $name ) )
+        {
+            switch ( $name )
+            {
+                case 'lat':
+                case 'long':
+                case 'point':
+                case 'where':
+                    $node = new ezcFeedTextElement();
+                    break;
+            }
+
+            $this->properties[$name] = $node;
+            return $node;
+        }
+        else
+        {
+            throw new ezcFeedUnsupportedElementException( $name );
+        }
+    }
+
+    /**
+     * Adds the module elements to the $xml XML document, in the container $root.
+     *
+     * @param DOMDocument $xml The XML document in which to add the module elements
+     * @param DOMNode $root The parent node which will contain the module elements
+     */
+    public function generate( DOMDocument $xml, DOMNode $root )
+    {
+        if ( isset( $this->lat ) && isset( $this->long ) )
+        {
+            $elementTag = $xml->createElement( $this->getNamespacePrefix() . ':' .
'point' );
+            $root->appendChild( $elementTag );
+
+            $elementTag->nodeValue = "{$this->lat} {$this->long}";
+        }
+    }
+
+    /**
+     * Parses the XML element $node and creates a feed element in the current
+     * module with name $name.
+     *
+     * @param string $name The name of the element belonging to the module
+     * @param DOMElement $node The XML child from which to take the values for $name
+     */
+    public function parse( $name, DOMElement $node )
+    {
+        if ( $this->isElementAllowed( $name ) )
+        {
+            switch ( $name )
+            {
+                case 'where':
+                    $children = $node->childNodes;
+                    $value = trim( $children->item(1)->textContent );
+                    list( $lat, $long ) = explode( ' ', $value );
+
+                    $element = $this->add( 'lat' );
+                    $element->text = $lat;
+                    $element = $this->add( 'long' );
+                    $element->text = $long;
+                    break;
+                case 'point':
+                    $value = $node->textContent;
+                    list( $lat, $long ) = explode( ' ', $value );
+                    $element = $this->add( 'lat' );
+                    $element->text = $lat;
+                    $element = $this->add( 'long' );
+                    $element->text = $long;
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Returns the module name (GeoRss').
+     *
+     * @return string
+     */
+    public static function getModuleName()
+    {
+        return 'GeoRss';
+    }
+
+    /**
+     * Returns the namespace for this module ('http://www.w3.org/2003/01/geo/wgs84_pos#').
+     *
+     * @return string
+     */
+    public static function getNamespace()
+    {
+        return 'http://www.georss.org/georss';
+    }
+
+    /**
+     * Returns the namespace prefix for this module ('georss').
+     *
+     * @return string
+     */
+    public static function getNamespacePrefix()
+    {
+        return 'georss';
+    }
+}
+?>

Propchange: incubator/zetacomponents/trunk/Feed/src/modules/georss_module.php
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message