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

Source for file content_module.php

Documentation is available at content_module.php

  1. <?php
  2. /**
  3.  * File containing the ezcFeedContentModule 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 Content module: data container, generator, parser.
  30.  *
  31.  * Specifications: {@link http://purl.org/rss/1.0/modules/content/}. Only support
  32.  * for the 'encoded' element of the Content module is provided.
  33.  *
  34.  * Create example:
  35.  *
  36.  * <code>
  37.  * <?php
  38.  * // $feed is an ezcFeed object
  39.  * $item = $feed->add( 'item' );
  40.  * $module = $item->addModule( 'Content' );
  41.  * $module->encoded = 'text content';
  42.  * ?>
  43.  * </code>
  44.  *
  45.  * Parse example:
  46.  *
  47.  * <code>
  48.  * <?php
  49.  * // $item is an ezcFeedEntryElement object
  50.  * $text = $item->Content->encoded;
  51.  * ?>
  52.  * </code>
  53.  *
  54.  * @property ezcFeedTextElement $encoded 
  55.  *                               Item-level container for text. The text is stored
  56.  *                               in a feed by applying htmlspecialchars() with
  57.  *                               ENT_NOQUOTES and restored from a feed with
  58.  *                               htmlspecialchars_decode() with ENT_NOQUOTES.
  59.  *
  60.  * @package Feed
  61.  * @version //autogentag//
  62.  */
  63. {
  64.     /**
  65.      * Constructs a new ezcFeedContentModule object.
  66.      *
  67.      * @param string $level The level of the data container ('feed' or 'item')
  68.      */
  69.     public function __construct$level 'feed' )
  70.     {
  71.         parent::__construct$level );
  72.     }
  73.  
  74.     /**
  75.      * Sets the property $name to $value.
  76.      *
  77.      * @throws ezcBasePropertyNotFoundException
  78.      *          if the property $name is not defined
  79.      *
  80.      * @param string $name The property name
  81.      * @param mixed $value The property value
  82.      * @ignore
  83.      */
  84.     public function __set$name$value )
  85.     {
  86.         if $this->isElementAllowed$name ) )
  87.         {
  88.             $node $this->add$name );
  89.             $node->text $value;
  90.         }
  91.         else
  92.         {
  93.             parent::__set$name$value );
  94.         }
  95.     }
  96.  
  97.     /**
  98.      * Returns the value of property $name.
  99.      *
  100.      * @throws ezcBasePropertyNotFoundException
  101.      *          if the property $name is not defined
  102.      *
  103.      * @param string $name The property name
  104.      * @return mixed 
  105.      * @ignore
  106.      */
  107.     public function __get$name )
  108.     {
  109.         if $this->isElementAllowed$name ) )
  110.         {
  111.             if isset$this->properties[$name) )
  112.             {
  113.                 return $this->properties[$name];
  114.             }
  115.         }
  116.         return parent::__get$name );
  117.     }
  118.  
  119.     /**
  120.      * Returns if the property $name is set.
  121.      *
  122.      * @param string $name The property name
  123.      * @return bool 
  124.      * @ignore
  125.      */
  126.     public function __isset$name )
  127.     {
  128.         if $this->isElementAllowed$name ) )
  129.         {
  130.             return isset$this->properties[$name);
  131.         }
  132.         else
  133.         {
  134.             return parent::__isset$name );
  135.         }
  136.     }
  137.  
  138.     /**
  139.      * Returns true if the element $name is allowed in the current module at the
  140.      * current level (feed or item), and false otherwise.
  141.      *
  142.      * @param string $name The element name to check if allowed in the current module and level (feed or item)
  143.      * @return bool 
  144.      */
  145.     public function isElementAllowed$name )
  146.     {
  147.         switch $this->level )
  148.         {
  149.             case 'feed':
  150.                 // no support yet for content:encoded element at feed-level
  151.                 return false;
  152.  
  153.             case 'item':
  154.                 if in_array$namearray'encoded' ) ) )
  155.                 {
  156.                     return true;
  157.                 }
  158.                 break;
  159.         }
  160.         return false;
  161.     }
  162.  
  163.     /**
  164.      * Adds a new ezcFeedElement element with name $name to this module and
  165.      * returns it.
  166.      *
  167.      * @throws ezcFeedUnsupportedElementException
  168.      *          if trying to add an element which is not supported.
  169.      *
  170.      * @param string $name The element name
  171.      * @return ezcFeedElement 
  172.      */
  173.     public function add$name )
  174.     {
  175.         if $this->isElementAllowed$name ) )
  176.         {
  177.             switch $name )
  178.             {
  179.                 case 'encoded':
  180.                     $node new ezcFeedTextElement();
  181.                     break;
  182.             }
  183.             $this->properties[$name$node;
  184.             return $node;
  185.         }
  186.         else
  187.         {
  188.             throw new ezcFeedUnsupportedElementException$name );
  189.         }
  190.     }
  191.  
  192.     /**
  193.      * Adds the module elements to the $xml XML document, in the container $root.
  194.      *
  195.      * @param DOMDocument $xml The XML document in which to add the module elements
  196.      * @param DOMNode $root The parent node which will contain the module elements
  197.      */
  198.     public function generateDOMDocument $xmlDOMNode $root )
  199.     {
  200.         if isset$this->encoded ) )
  201.         {
  202.             $elementTag $xml->createElement$this->getNamespacePrefix(':' 'encoded' );
  203.             $root->appendChild$elementTag );
  204.             $elementTag->nodeValue htmlspecialchars$this->encoded->__toString()ENT_NOQUOTES );
  205.         }
  206.     }
  207.  
  208.     /**
  209.      * Parses the XML element $node and creates a feed element in the current
  210.      * module with name $name.
  211.      *
  212.      * @param string $name The name of the element belonging to the module
  213.      * @param DOMElement $node The XML child from which to take the values for $name
  214.      */
  215.     public function parse$nameDOMElement $node )
  216.     {
  217.         if $this->isElementAllowed$name ) )
  218.         {
  219.             $element $this->add$name );
  220.             $value $node->textContent;
  221.  
  222.             switch $name )
  223.             {
  224.                 case 'encoded':
  225.                     $element->text htmlspecialchars_decode$valueENT_NOQUOTES );
  226.                     break;
  227.             }
  228.         }
  229.     }
  230.  
  231.     /**
  232.      * Returns the module name ('Content').
  233.      *
  234.      * @return string 
  235.      */
  236.     public static function getModuleName()
  237.     {
  238.         return 'Content';
  239.     }
  240.  
  241.     /**
  242.      * Returns the namespace for this module ('http://purl.org/rss/1.0/modules/content/').
  243.      *
  244.      * @return string 
  245.      */
  246.     public static function getNamespace()
  247.     {
  248.         return 'http://purl.org/rss/1.0/modules/content/';
  249.     }
  250.  
  251.     /**
  252.      * Returns the namespace prefix for this module ('content').
  253.      *
  254.      * @return string 
  255.      */
  256.     public static function getNamespacePrefix()
  257.     {
  258.         return 'content';
  259.     }
  260. }
  261. ?>
Documentation generated by phpDocumentor 1.4.3