Apache Zeta Components Manual :: File Source for georss_module.php

Source for file georss_module.php

Documentation is available at georss_module.php

  1. <?php
  2. /**
  3.  * File containing the ezcFeedGeoRssModule class.
  4.  *
  5.  * @package Feed
  6.  * @version //autogentag//
  7.  * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
  8.  * @license http://ez.no/licenses/new_bsd New BSD License
  9.  * @filesource
  10.  */
  11.  
  12. /**
  13.  * Support for the GeoRss module: data container, generator, parser.
  14.  *
  15.  * Specifications: {@link http://www.w3.org/2003/01/geo/}.
  16.  *
  17.  * Create example:
  18.  *
  19.  * <code>
  20.  * <?php
  21.  * // $feed is an ezcFeed object
  22.  * $item = $feed->add( 'item' );
  23.  * $module = $item->addModule( 'GeoRss' );
  24.  * $module->lat = 26.58;
  25.  * $module->long = -97.83;
  26.  * ?>
  27.  * </code>
  28.  *
  29.  * Parse example:
  30.  *
  31.  * <code>
  32.  * <?php
  33.  * // $item is an ezcFeedEntryElement object
  34.  * $lat = isset( $item->GeoRss->lat ) ? $item->GeoRss->lat->__toString() : null;
  35.  * $long = isset( $item->GeoRss->long ) ? $item->GeoRss->long->__toString() : null;
  36.  * ?>
  37.  * </code>
  38.  *
  39.  * @property ezcFeedTextElement $lat 
  40.  *                               {@link http://en.wikipedia.org/wiki/WGS84 WGS84} latitude
  41.  *                               on the globe as decimal degrees
  42.  *                               (eg. 25.03358300). Can also be negative.
  43.  * @property ezcFeedTextElement $long 
  44.  *                               {@link http://en.wikipedia.org/wiki/WGS84 WGS84} longitude
  45.  *                               on the globe as decimal degrees
  46.  *                               (eg. 121.56430000). Can also be negative.
  47.  *
  48.  * @package Feed
  49.  * @version //autogentag//
  50.  */
  51. {
  52.     /**
  53.      * Constructs a new ezcFeedContentModule object.
  54.      *
  55.      * @param string $level The level of the data container ('feed' or 'item')
  56.      */
  57.     public function __construct$level 'feed' )
  58.     {
  59.         parent::__construct$level );
  60.     }
  61.  
  62.     /**
  63.      * Sets the property $name to $value.
  64.      *
  65.      * @throws ezcBasePropertyNotFoundException
  66.      *          if the property $name is not defined
  67.      *
  68.      * @param string $name The property name
  69.      * @param mixed $value The property value
  70.      * @ignore
  71.      */
  72.     public function __set$name$value )
  73.     {
  74.         if $this->isElementAllowed$name ) )
  75.         {
  76.             $node $this->add$name );
  77.             $node->text $value;
  78.         }
  79.         else
  80.         {
  81.             parent::__set$name$value );
  82.         }
  83.     }
  84.  
  85.     /**
  86.      * Returns the value of property $name.
  87.      *
  88.      * @throws ezcBasePropertyNotFoundException
  89.      *          if the property $name is not defined
  90.      *
  91.      * @param string $name The property name
  92.      * @return mixed 
  93.      * @ignore
  94.      */
  95.     public function __get$name )
  96.     {
  97.         if $this->isElementAllowed$name ) )
  98.         {
  99.             return $this->properties[$name];
  100.         }
  101.         else
  102.         {
  103.             return parent::__get$name );
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * Returns if the property $name is set.
  109.      *
  110.      * @param string $name The property name
  111.      * @return bool 
  112.      * @ignore
  113.      */
  114.     public function __isset$name )
  115.     {
  116.         if $this->isElementAllowed$name ) )
  117.         {
  118.             return isset$this->properties[$name);
  119.         }
  120.         else
  121.         {
  122.             return parent::__isset$name );
  123.         }
  124.     }
  125.  
  126.     /**
  127.      * Returns true if the element $name is allowed in the current module at the
  128.      * current level (feed or item), and false otherwise.
  129.      *
  130.      * @param string $name The element name to check if allowed in the current module and level (feed or item)
  131.      * @return bool 
  132.      */
  133.     public function isElementAllowed$name )
  134.     {
  135.         switch $this->level )
  136.         {
  137.             case 'feed':
  138.                 if in_array$namearray'lat''long''point''where''box' ) ) )
  139.                 {
  140.                     return true;
  141.                 }
  142.                 break;
  143.  
  144.             case 'item':
  145.                 if in_array$namearray'lat''long''point''where''box' ) ) )
  146.                 {
  147.                     return true;
  148.                 }
  149.                 break;
  150.         }
  151.         return false;
  152.     }
  153.  
  154.     /**
  155.      * Adds a new ezcFeedElement element with name $name to this module and
  156.      * returns it.
  157.      *
  158.      * @throws ezcFeedUnsupportedElementException
  159.      *          if trying to add an element which is not supported.
  160.      *
  161.      * @param string $name The element name
  162.      * @return ezcFeedElement 
  163.      */
  164.     public function add$name )
  165.     {
  166.         if $this->isElementAllowed$name ) )
  167.         {
  168.             switch $name )
  169.             {
  170.                 case 'lat':
  171.                 case 'long':
  172.                 case 'point':
  173.                 case 'where':
  174.                 case 'box':
  175.                     $node new ezcFeedTextElement();
  176.                     break;
  177.             }
  178.  
  179.             $this->properties[$name$node;
  180.             return $node;
  181.         }
  182.         else
  183.         {
  184.             throw new ezcFeedUnsupportedElementException$name );
  185.         }
  186.     }
  187.  
  188.     /**
  189.      * Adds the module elements to the $xml XML document, in the container $root.
  190.      *
  191.      * @param DOMDocument $xml The XML document in which to add the module elements
  192.      * @param DOMNode $root The parent node which will contain the module elements
  193.      */
  194.     public function generateDOMDocument $xmlDOMNode $root )
  195.     {
  196.         if isset$this->lat && isset$this->long ) )
  197.         {
  198.             $elementTag $xml->createElement$this->getNamespacePrefix(':' 'point' );
  199.             $root->appendChild$elementTag );
  200.  
  201.             $elementTag->nodeValue "{$this->lat{$this->long}";
  202.         }
  203.     }
  204.  
  205.     /**
  206.      * Parses the XML element $node and creates a feed element in the current
  207.      * module with name $name.
  208.      *
  209.      * @param string $name The name of the element belonging to the module
  210.      * @param DOMElement $node The XML child from which to take the values for $name
  211.      */
  212.     public function parse( $name, DOMElement $node )
  213.     {
  214.         if ( $this->isElementAllowed$name ) )
  215.         {
  216.             switch ( $name )
  217.             {
  218.                 case 'where':
  219.                     $children = $node->childNodes;
  220.                     $value trim$children->item(1)->textContent );
  221.                     list$lat$long explode' '$value );
  222.  
  223.                     $element $this->add'lat' );
  224.                     $element->text $lat;
  225.                     $element $this->add'long' );
  226.                     $element->text $long;
  227.                     break;
  228.                 case 'point':
  229.                     $value $node->textContent;
  230.                     list$lat$long explode' '$value );
  231.                     $element $this->add'lat' );
  232.                     $element->text $lat;
  233.                     $element $this->add'long' );
  234.                     $element->text $long;
  235.                     break;
  236.                 case 'box':
  237.                     $value $node->textContent;
  238.                     list$lat1$long1$lat2$long2 explode' '$value );
  239.                     $element $this->add'lat' );
  240.                     $element->text $lat1 $lat2 2;
  241.                     $element $this->add'long' );
  242.                     $element->text $long1 $long2 /2;
  243.                     break;
  244.             }
  245.         }
  246.     }
  247.  
  248.     /**
  249.      * Returns the module name (GeoRss').
  250.      *
  251.      * @return string
  252.      */
  253.     public static function getModuleName()
  254.     {
  255.         return 'GeoRss';
  256.     }
  257.  
  258.     /**
  259.      * Returns the namespace for this module ('http://www.w3.org/2003/01/geo/wgs84_pos#').
  260.      *
  261.      * @return string
  262.      */
  263.     public static function getNamespace()
  264.     {
  265.         return 'http://www.georss.org/georss';
  266.     }
  267.  
  268.     /**
  269.      * Returns the namespace prefix for this module ('georss').
  270.      *
  271.      * @return string
  272.      */
  273.     public static function getNamespacePrefix()
  274.     {
  275.         return 'georss';
  276.     }
  277. }
Documentation generated by phpDocumentor 1.4.3