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

Source for file creativecommons_module.php

Documentation is available at creativecommons_module.php

  1. <?php
  2. /**
  3.  * File containing the ezcFeedCreativeCommonsModule class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @package Feed
  23.  * @version //autogentag//
  24.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25.  * @filesource
  26.  */
  27.  
  28. /**
  29.  * Support for the CreativeCommons module: data container, generator, parser.
  30.  *
  31.  * Specifications: {@link http://backend.userland.com/creativeCommonsRssModule}.
  32.  *
  33.  * Create example:
  34.  *
  35.  * <code>
  36.  * <?php
  37.  * // $feed is an ezcFeed object
  38.  * $item = $feed->add( 'item' );
  39.  * $module = $item->addModule( 'CreativeCommons' );
  40.  * $module->license = 'text content';
  41.  * ?>
  42.  * </code>
  43.  *
  44.  * Parse example:
  45.  *
  46.  * <code>
  47.  * <?php
  48.  * // $item is an ezcFeedEntryElement object
  49.  * $text = $item->CreativeCommons->license;
  50.  * ?>
  51.  * </code>
  52.  *
  53.  * @property ezcFeedElement $license 
  54.  *                           An URL to a license description. Can appear at both
  55.  *                           feed-level and item-level. A list of possible licenses
  56.  *                           are found here {@link http://creativecommons.org/licenses/},
  57.  *                           but other licenses can be used as well.
  58.  *
  59.  * @package Feed
  60.  * @version //autogentag//
  61.  */
  62. {
  63.     /**
  64.      * Constructs a new ezcFeedCreativeCommonsModule object.
  65.      *
  66.      * @param string $level The level of the data container ('feed' or 'item')
  67.      */
  68.     public function __construct$level 'feed' )
  69.     {
  70.         parent::__construct$level );
  71.     }
  72.  
  73.     /**
  74.      * Sets the property $name to $value.
  75.      *
  76.      * @throws ezcBasePropertyNotFoundException
  77.      *          if the property $name is not defined
  78.      *
  79.      * @param string $name The property name
  80.      * @param mixed $value The property value
  81.      * @ignore
  82.      */
  83.     public function __set$name$value )
  84.     {
  85.         if $this->isElementAllowed$name ) )
  86.         {
  87.             $node $this->add$name );
  88.             $node->text $value;
  89.         }
  90.         else
  91.         {
  92.             parent::__set$name$value );
  93.         }
  94.     }
  95.  
  96.     /**
  97.      * Returns the value of property $name.
  98.      *
  99.      * @throws ezcBasePropertyNotFoundException
  100.      *          if the property $name is not defined
  101.      *
  102.      * @param string $name The property name
  103.      * @return mixed 
  104.      * @ignore
  105.      */
  106.     public function __get$name )
  107.     {
  108.         if $this->isElementAllowed$name ) )
  109.         {
  110.             return $this->properties[$name];
  111.         }
  112.         else
  113.         {
  114.             return parent::__get$name );
  115.         }
  116.     }
  117.  
  118.     /**
  119.      * Returns if the property $name is set.
  120.      *
  121.      * @param string $name The property name
  122.      * @return bool 
  123.      * @ignore
  124.      */
  125.     public function __isset$name )
  126.     {
  127.         if $this->isElementAllowed$name ) )
  128.         {
  129.             return isset$this->properties[$name);
  130.         }
  131.         else
  132.         {
  133.             return parent::__isset$name );
  134.         }
  135.     }
  136.  
  137.     /**
  138.      * Returns true if the element $name is allowed in the current module at the
  139.      * current level (feed or item), and false otherwise.
  140.      *
  141.      * @param string $name The element name to check if allowed in the current module and level (feed or item)
  142.      * @return bool 
  143.      */
  144.     public function isElementAllowed$name )
  145.     {
  146.         switch $this->level )
  147.         {
  148.             case 'feed':
  149.                 if in_array$namearray'license' ) ) )
  150.                 {
  151.                     return true;
  152.                 }
  153.                 break;
  154.  
  155.             case 'item':
  156.                 if in_array$namearray'license' ) ) )
  157.                 {
  158.                     return true;
  159.                 }
  160.                 break;
  161.         }
  162.         return false;
  163.     }
  164.  
  165.     /**
  166.      * Adds a new ezcFeedElement element with name $name to this module and
  167.      * returns it.
  168.      *
  169.      * @throws ezcFeedUnsupportedElementException
  170.      *          if trying to add an element which is not supported.
  171.      *
  172.      * @param string $name The element name
  173.      * @return ezcFeedElement 
  174.      */
  175.     public function add$name )
  176.     {
  177.         if $this->isElementAllowed$name ) )
  178.         {
  179.             switch $name )
  180.             {
  181.                 case 'license':
  182.                     $node new ezcFeedTextElement();
  183.                     break;
  184.             }
  185.  
  186.             $this->properties[$name$node;
  187.             return $node;
  188.         }
  189.         else
  190.         {
  191.             throw new ezcFeedUnsupportedElementException$name );
  192.         }
  193.     }
  194.  
  195.     /**
  196.      * Adds the module elements to the $xml XML document, in the container $root.
  197.      *
  198.      * @param DOMDocument $xml The XML document in which to add the module elements
  199.      * @param DOMNode $root The parent node which will contain the module elements
  200.      */
  201.     public function generateDOMDocument $xmlDOMNode $root )
  202.     {
  203.         if isset$this->license ) )
  204.         {
  205.             $elementTag $xml->createElement$this->getNamespacePrefix(':' 'license' );
  206.             $root->appendChild$elementTag );
  207.  
  208.             $elementTag->nodeValue $this->license->__toString();
  209.         }
  210.     }
  211.  
  212.     /**
  213.      * Parses the XML element $node and creates a feed element in the current
  214.      * module with name $name.
  215.      *
  216.      * @param string $name The name of the element belonging to the module
  217.      * @param DOMElement $node The XML child from which to take the values for $name
  218.      */
  219.     public function parse$nameDOMElement $node )
  220.     {
  221.         if $this->isElementAllowed$name ) )
  222.         {
  223.             $element $this->add$name );
  224.             $value $node->textContent;
  225.  
  226.             switch $name )
  227.             {
  228.                 case 'license':
  229.                     $element->text $value;
  230.                     break;
  231.             }
  232.         }
  233.     }
  234.  
  235.     /**
  236.      * Returns the module name ('CreativeCommons').
  237.      *
  238.      * @return string 
  239.      */
  240.     public static function getModuleName()
  241.     {
  242.         return 'CreativeCommons';
  243.     }
  244.  
  245.     /**
  246.      * Returns the namespace for this module ('http://backend.userland.com/creativeCommonsRssModule').
  247.      *
  248.      * @return string 
  249.      */
  250.     public static function getNamespace()
  251.     {
  252.         return 'http://backend.userland.com/creativeCommonsRssModule';
  253.     }
  254.  
  255.     /**
  256.      * Returns the namespace prefix for this module ('creativeCommons').
  257.      *
  258.      * @return string 
  259.      */
  260.     public static function getNamespacePrefix()
  261.     {
  262.         return 'creativeCommons';
  263.     }
  264. }
  265. ?>
Documentation generated by phpDocumentor 1.4.3