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

Source for file rss2.php

Documentation is available at rss2.php

  1. <?php
  2. /**
  3.  * File containing the ezcFeedRss2 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.  * Class providing parsing and generating of RSS2 feeds.
  30.  *
  31.  * Specifications:
  32.  * {@link http://www.rssboard.org/rss-specification RSS2 Specifications}.
  33.  *
  34.  * @package Feed
  35.  * @version //autogentag//
  36.  */
  37. class ezcFeedRss2 extends ezcFeedProcessor implements ezcFeedParser
  38. {
  39.     /**
  40.      * Defines the feed type of this processor.
  41.      */
  42.     const FEED_TYPE = 'rss2';
  43.  
  44.     /**
  45.      * Defines the feed content type of this processor.
  46.      */
  47.     const CONTENT_TYPE = 'application/rss+xml';
  48.  
  49.     /**
  50.      * Creates a new RSS2 processor.
  51.      *
  52.      * @param ezcFeed $container The feed data container used when generating
  53.      */
  54.     public function __constructezcFeed $container )
  55.     {
  56.         $this->feedContainer $container;
  57.         $this->feedType self::FEED_TYPE;
  58.         $this->contentType self::CONTENT_TYPE;
  59.  
  60.         // initialize docs and pubDate with default values
  61.         if !isset$this->docs ) )
  62.         {
  63.             $this->docs 'http://www.rssboard.org/rss-specification';
  64.         }
  65.  
  66.         if !isset$this->published ) )
  67.         {
  68.             $this->published time();
  69.         }
  70.     }
  71.  
  72.     /**
  73.      * Returns an XML string from the feed information contained in this
  74.      * processor.
  75.      *
  76.      * @return string 
  77.      */
  78.     public function generate()
  79.     {
  80.         $this->xml new DOMDocument'1.0''utf-8' );
  81.         $this->xml->formatOutput 1;
  82.  
  83.         $rss $this->xml->createElement'rss' );
  84.  
  85.         $rssVersionTag $this->xml->createAttribute'version' );
  86.         $rssVersionContent $this->xml->createTextNode'2.0' );
  87.         $rssVersionTag->appendChild$rssVersionContent );
  88.         $rss->appendChild$rssVersionTag );
  89.  
  90.         $this->channel $this->xml->createElement'channel' );
  91.         $rss->appendChild$this->channel );
  92.         $this->root $this->xml->appendChild$rss );
  93.  
  94.         $this->generateRequired();
  95.         $this->generateOptional();
  96.         $this->generateFeedModules$this->channel );
  97.         $this->generateItems();
  98.  
  99.         return $this->xml->saveXML();
  100.     }
  101.  
  102.     /**
  103.      * Returns true if the parser can parse the provided XML document object,
  104.      * false otherwise.
  105.      *
  106.      * @param DOMDocument $xml The XML document object to check for parseability
  107.      * @return bool 
  108.      */
  109.     public static function canParseDOMDocument $xml )
  110.     {
  111.         if $xml->documentElement->tagName !== 'rss' )
  112.         {
  113.             return false;
  114.         }
  115.         if !$xml->documentElement->hasAttribute'version' ) )
  116.         {
  117.             return false;
  118.         }
  119.         if !in_array$xml->documentElement->getAttribute'version' )array'0.91''0.92''0.93''0.94''2.0' ) ) )
  120.         {
  121.             return false;
  122.         }
  123.         return true;
  124.     }
  125.  
  126.     /**
  127.      * Parses the provided XML document object and returns an ezcFeed object
  128.      * from it.
  129.      *
  130.      * @throws ezcFeedParseErrorException
  131.      *          If an error was encountered during parsing.
  132.      *
  133.      * @param DOMDocument $xml The XML document object to parse
  134.      * @return ezcFeed 
  135.      */
  136.     public function parseDOMDocument $xml )
  137.     {
  138.         $feed new ezcFeedself::FEED_TYPE );
  139.         $rssChildren $xml->documentElement->childNodes;
  140.         $channel null;
  141.  
  142.         $this->usedPrefixes $this->fetchUsedPrefixes$xml );
  143.  
  144.         foreach $rssChildren as $rssChild )
  145.         {
  146.             if $rssChild->nodeType === XML_ELEMENT_NODE
  147.                  && $rssChild->tagName === 'channel' )
  148.             {
  149.                 $channel $rssChild;
  150.             }
  151.         }
  152.  
  153.         if $channel === null )
  154.         {
  155.             throw new ezcFeedParseErrorExceptionnull"No channel tag" );
  156.         }
  157.  
  158.         foreach $channel->childNodes as $channelChild )
  159.         {
  160.             if $channelChild->nodeType == XML_ELEMENT_NODE )
  161.             {
  162.                 $tagName $channelChild->tagName;
  163.  
  164.                 switch $tagName )
  165.                 {
  166.                     case 'title':
  167.                     case 'description':
  168.                     case 'copyright':
  169.                         $element $feed->add$tagName );
  170.                         $element->text $channelChild->textContent;
  171.                         break;
  172.  
  173.                     case 'language':
  174.                     case 'ttl':
  175.                     case 'docs':
  176.                     case 'rating':
  177.                         $element $feed->add$tagName );
  178.                         $element->text $channelChild->textContent;
  179.                         break;
  180.  
  181.                     case 'generator':
  182.                         $element $feed->add$tagName );
  183.                         $element->name $channelChild->textContent;
  184.                         break;
  185.  
  186.                     case 'managingEditor':
  187.                         $element $feed->add'author' );
  188.                         $element->name $channelChild->textContent;
  189.                         // @todo parse $name to see if it has the structure
  190.                         // email@address (name) to fill the ->email field from it
  191.                         break;
  192.  
  193.                     case 'webMaster':
  194.                         $element $feed->add'webMaster' );
  195.                         $element->name $channelChild->textContent;
  196.                         // @todo parse $name to see if it has the structure
  197.                         // email@address (name) to fill the ->email field from it
  198.                         break;
  199.  
  200.                     case 'category':
  201.                         $element $feed->add$tagName );
  202.                         $element->term $channelChild->textContent;
  203.                         if $channelChild->hasAttribute'domain' ) )
  204.                         {
  205.                             $element->scheme $channelChild->getAttribute'domain' );
  206.                         }
  207.                         break;
  208.  
  209.                     case 'link':
  210.                         $element $feed->add$tagName );
  211.                         $element->href $channelChild->textContent;
  212.                         break;
  213.  
  214.                     case 'cloud':
  215.                         $element $feed->add$tagName );
  216.  
  217.                         $attributes array'domain' => 'domain''port' => 'port''path' => 'path',
  218.                                              'registerProcedure' => 'registerProcedure''protocol' => 'protocol' );
  219.                         foreach $attributes as $name => $alias )
  220.                         {
  221.                             if $channelChild->hasAttribute$name ) )
  222.                             {
  223.                                 $element->$alias $channelChild->getAttribute$name );
  224.                             }
  225.                         }
  226.                         break;
  227.  
  228.                     case 'pubDate':
  229.                         $feed->published $channelChild->textContent;
  230.                         break;
  231.  
  232.                     case 'lastBuildDate':
  233.                         $feed->updated $channelChild->textContent;
  234.                         break;
  235.  
  236.                     case 'item':
  237.                         $element $feed->add$tagName );
  238.                         $this->parseItem$element$channelChild );
  239.                         break;
  240.  
  241.                     case 'image':
  242.                         $image $feed->add'image' );
  243.                         $this->parseImage$image$channelChild );
  244.                         break;
  245.  
  246.                     case 'skipHours':
  247.                         $element $feed->add$tagName );
  248.                         $this->parseSkipHours$element$channelChild );
  249.                         break;
  250.  
  251.                     case 'skipDays':
  252.                         $element $feed->add$tagName );
  253.                         $this->parseSkipDays$element$channelChild );
  254.                         break;
  255.  
  256.                     case 'textInput':
  257.                         $element $feed->add$tagName );
  258.                         $this->parseTextInput$element$channelChild );
  259.                         break;
  260.  
  261.                     default:
  262.                         // check if it's part of a known module/namespace
  263.                         $this->parseModules$feed$channelChild$tagName );
  264.                 }
  265.             }
  266.         }
  267.         return $feed;
  268.     }
  269.  
  270.     /**
  271.      * Adds the required feed elements to the XML document being generated.
  272.      */
  273.     private function generateRequired()
  274.     {
  275.         $elements array'title''link''description' );
  276.         foreach $elements as $element )
  277.         {
  278.             $data $this->$element;
  279.             if is_null$data ) )
  280.             {
  281.                 throw new ezcFeedRequiredMetaDataMissingException"/{$this->root->nodeName}/{$element});
  282.             }
  283.  
  284.             if !is_array$data ) )
  285.             {
  286.                 $data array$data );
  287.             }
  288.  
  289.             switch $element )
  290.             {
  291.                 case 'link':
  292.                     foreach $data as $dataNode )
  293.                     {
  294.                         $this->generateMetaData$this->channel$element$dataNode->href );
  295.                     }
  296.                     break;
  297.  
  298.                 default:
  299.                     foreach $data as $dataNode )
  300.                     {
  301.                         $this->generateMetaData$this->channel$element$dataNode );
  302.                     }
  303.                     break;
  304.             }
  305.         }
  306.     }
  307.  
  308.     /**
  309.      * Adds the optional feed elements to the XML document being generated.
  310.      */
  311.     private function generateOptional()
  312.     {
  313.         $elements array'language''copyright''author',
  314.                            'webMaster''published''updated',
  315.                            'category''generator''docs',
  316.                            'ttl''image''rating',
  317.                            'textInput''skipHours''skipDays',
  318.                            'cloud''id' );
  319.  
  320.         foreach $elements as $element )
  321.         {
  322.             $data $this->$element;
  323.  
  324.             if !is_null$data ) )
  325.             {
  326.                 switch $element )
  327.                 {
  328.                     case 'updated':
  329.                         $this->generateMetaData$this->channel'lastBuildDate'$data->date->format'D, d M Y H:i:s O' ) );
  330.                         break;
  331.  
  332.                     case 'published':
  333.                         $this->generateMetaData$this->channel'pubDate'$data->date->format'D, d M Y H:i:s O' ) );
  334.                         break;
  335.  
  336.                     case 'image':
  337.                         $this->generateImage$this->image );
  338.                         break;
  339.  
  340.                     case 'skipHours':
  341.                         $this->generateSkipHours$this->skipHours );
  342.                         break;
  343.  
  344.                     case 'skipDays':
  345.                         $this->generateSkipDays$this->skipDays );
  346.                         break;
  347.  
  348.                     case 'textInput':
  349.                         $this->generateTextInput$this->textInput );
  350.                         break;
  351.  
  352.                     case 'cloud':
  353.                         $this->generateCloud$this->cloud );
  354.                         break;
  355.  
  356.                     case 'category':
  357.                         foreach $this->category as $category )
  358.                         {
  359.                             $this->generateCategory$category$this->channel );
  360.                         }
  361.                         break;
  362.  
  363.                     case 'generator':
  364.                         $this->generateGenerator$data$this->channel );
  365.                         break;
  366.  
  367.                     case 'author':
  368.                         foreach $this->author as $person )
  369.                         {
  370.                             $this->generatePerson$person$this->channel'managingEditor' );
  371.                         }
  372.                         break;
  373.  
  374.                     case 'webMaster':
  375.                         foreach $this->webMaster as $person )
  376.                         {
  377.                             $this->generatePerson$person$this->channel'webMaster' );
  378.                         }
  379.                         break;
  380.  
  381.                     case 'id':
  382.                         $this->generateAtomSelfLink$this->id );
  383.                         break;
  384.  
  385.                     default:
  386.                         if !is_array$data ) )
  387.                         {
  388.                             $data array$data );
  389.                         }
  390.  
  391.                         foreach $data as $dataNode )
  392.                         {
  393.                             $this->generateMetaData$this->channel$element$dataNode );
  394.                         }
  395.                         break;
  396.                 }
  397.             }
  398.         }
  399.     }
  400.  
  401.     /**
  402.      * Adds a category node to the XML document being generated.
  403.      *
  404.      * @param ezcFeedCategoryElement $category The category feed element
  405.      * @param DOMElement $root The XML element where to store the category element
  406.      */
  407.     private function generateCategoryezcFeedCategoryElement $categoryDOMElement $root )
  408.     {
  409.         $data $category->term;
  410.  
  411.         $element $this->xml->createElement'category'$data );
  412.         $root->appendChild$element );
  413.  
  414.         $data $category->scheme;
  415.         if !is_null$data ) )
  416.         {
  417.             $this->addAttribute$element'domain'$data );
  418.         }
  419.     }
  420.  
  421.     /**
  422.      * Adds a person node to the XML document being generated.
  423.      *
  424.      * @param ezcFeedPersonElement $person The person feed element
  425.      * @param DOMElement $root The XML element where to store the person element
  426.      * @param string $elementName The feed element name (eg 'author')
  427.      */
  428.     private function generatePersonezcFeedPersonElement $personDOMElement $root$elementName )
  429.     {
  430.         $name $person->name;
  431.         $email $person->email;
  432.  
  433.         $data $name;
  434.         if $email !== null )
  435.         {
  436.             $data "{$email} ({$name})";
  437.         }
  438.  
  439.         $element $this->xml->createElement$elementName$data );
  440.         $root->appendChild$element );
  441.     }
  442.  
  443.     /**
  444.      * Adds a generator node to the XML document being generated.
  445.      *
  446.      * @param ezcFeedGeneratorElement $generator The generator feed element
  447.      * @param DOMElement $root The XML element where to store the generator element
  448.      */
  449.     private function generateGeneratorezcFeedGeneratorElement $generatorDOMElement $root )
  450.     {
  451.         $name $generator->name;
  452.         $version $generator->version;
  453.         $url $generator->url;
  454.  
  455.         $data $name;
  456.         if $version !== null )
  457.         {
  458.             $data $data " {$version}";
  459.         }
  460.  
  461.         if $url !== null )
  462.         {
  463.             $data $data " ({$url})";
  464.         }
  465.  
  466.         $element $this->xml->createElement'generator'$data );
  467.         $root->appendChild$element );
  468.     }
  469.  
  470.     /**
  471.      * Adds an image node to the XML document being generated.
  472.      *
  473.      * @param ezcFeedImageElement $feedElement The image feed element
  474.      */
  475.     private function generateImageezcFeedImageElement $feedElement )
  476.     {
  477.         $image $this->xml->createElement'image' );
  478.         $this->channel->appendChild$image );
  479.  
  480.         $elements array'url''title''link' );
  481.         foreach $elements as $element )
  482.         {
  483.             $data $feedElement->$element;
  484.             if is_null$data ) )
  485.             {
  486.                 throw new ezcFeedRequiredMetaDataMissingException"/{$this->root->nodeName}/image/{$element});
  487.             }
  488.  
  489.             $this->generateMetaData$image$element$data );
  490.         }
  491.  
  492.         $elements array'description''width''height' );
  493.         foreach $elements as $element )
  494.         {
  495.             $data $feedElement->$element;
  496.             if !is_null$data ) )
  497.             {
  498.                 $this->generateMetaData$image$element$data );
  499.             }
  500.         }
  501.     }
  502.  
  503.     /**
  504.      * Adds a skipHours node to the XML document being generated.
  505.      *
  506.      * @param ezcFeedSkipHoursElement $feedElement The skipHours feed element
  507.      */
  508.     private function generateSkipHoursezcFeedSkipHoursElement $feedElement )
  509.     {
  510.         $tag $this->xml->createElement'skipHours' );
  511.         $this->channel->appendChild$tag );
  512.  
  513.         $data $feedElement->hours;
  514.         if !is_null$data ) )
  515.         {
  516.             foreach $data as $dataNode )
  517.             {
  518.                 $this->generateMetaData$tag'hour'$dataNode );
  519.             }
  520.         }
  521.     }
  522.  
  523.     /**
  524.      * Adds a skipDays node to the XML document being generated.
  525.      *
  526.      * @param ezcFeedSkipDaysElement $feedElement The skipDays feed element
  527.      */
  528.     private function generateSkipDaysezcFeedSkipDaysElement $feedElement )
  529.     {
  530.         $tag $this->xml->createElement'skipDays' );
  531.         $this->channel->appendChild$tag );
  532.  
  533.         $data $feedElement->days;
  534.         if !is_null$data ) )
  535.         {
  536.             foreach $data as $dataNode )
  537.             {
  538.                 $this->generateMetaData$tag'day'$dataNode );
  539.             }
  540.         }
  541.     }
  542.  
  543.     /**
  544.      * Adds an textInput node to the XML document being generated.
  545.      *
  546.      * @param ezcFeedTextInputElement $feedElement The textInput feed element
  547.      */
  548.     private function generateTextInputezcFeedTextInputElement $feedElement )
  549.     {
  550.         $image $this->xml->createElement'textInput' );
  551.         $this->channel->appendChild$image );
  552.  
  553.         $elements array'title''description''name''link' );
  554.         foreach $elements as $element )
  555.         {
  556.             $data $feedElement->$element;
  557.             if is_null$data ) )
  558.             {
  559.                 throw new ezcFeedRequiredMetaDataMissingException"/{$this->root->nodeName}/textInput/{$element});
  560.             }
  561.  
  562.             $this->generateMetaData$image$element$data );
  563.         }
  564.     }
  565.  
  566.     /**
  567.      * Adds a cloud node to the XML document being generated.
  568.      *
  569.      * @param ezcFeedCloudElement $feedElement The cloud feed element
  570.      */
  571.     private function generateCloudezcFeedCloudElement $feedElement )
  572.     {
  573.         $attributes array();
  574.         $elements array'domain''port''path''registerProcedure''protocol' );
  575.         foreach $elements as $element )
  576.         {
  577.             $data $feedElement->$element;
  578.             if is_null$data ) )
  579.             {
  580.                 throw new ezcFeedRequiredMetaDataMissingException"/{$this->root->nodeName}/cloud/{$element});
  581.             }
  582.             $attributes[$element$data;
  583.         }
  584.  
  585.         $this->generateMetaDataWithAttributes$this->channel'cloud'false$attributes );
  586.     }
  587.  
  588.     /**
  589.      * Adds an atom:link node to the XML document being generated, plus the namespace.
  590.      *
  591.      * @param ezcFeedIdElement $feedElement The link feed element
  592.      */
  593.     private function generateAtomSelfLinkezcFeedIdElement $feedElement )
  594.     {
  595.         $this->addAttribute$this->root'xmlns:atom'ezcFeedAtom::NAMESPACE_URI );
  596.  
  597.         $link $this->xml->createElement'atom:link' );
  598.         $this->channel->appendChild$link );
  599.  
  600.         $this->addAttribute$link'href'$feedElement->id );
  601.         $this->addAttribute$link'rel''self' );
  602.         $this->addAttribute$link'type'self::CONTENT_TYPE );
  603.     }
  604.  
  605.     /**
  606.      * Adds the feed items to the XML document being generated.
  607.      */
  608.     private function generateItems()
  609.     {
  610.         $items $this->item;
  611.         if $items === null )
  612.         {
  613.             return;
  614.         }
  615.  
  616.         foreach $items as $item )
  617.         {
  618.             $itemTag $this->xml->createElement'item' );
  619.             $this->channel->appendChild$itemTag );
  620.  
  621.             $atLeastOneRequiredFeedItemPresent false;
  622.             $elements array'title''description' );
  623.             foreach $elements as $attribute )
  624.             {
  625.                 $data $item->$attribute;
  626.                 if !is_null$data ) )
  627.                 {
  628.                     $atLeastOneRequiredFeedItemPresent true;
  629.                     break;
  630.                 }
  631.             }
  632.  
  633.             if $atLeastOneRequiredFeedItemPresent === false )
  634.             {
  635.                 $requiredElements $elements;
  636.                 for $i 0$i count$requiredElements )$i++ )
  637.                 {
  638.                     $requiredElements[$i"/{$this->root->nodeName}/item/{$requiredElements[$i]}";
  639.                 }
  640.                 throw new ezcFeedAtLeastOneItemDataRequiredException$requiredElements );
  641.             }
  642.  
  643.             $optional array'title''link''description',
  644.                                'author''category''comments',
  645.                                'enclosure''id''published',
  646.                                'source''language' );
  647.  
  648.             foreach $optional as $attribute )
  649.             {
  650.                 $metaData $item->$attribute;
  651.  
  652.                 if !is_null$metaData ) )
  653.                 {
  654.                     switch $attribute )
  655.                     {
  656.                         case 'comments':
  657.                             $this->generateMetaData$itemTag'comments'$metaData );
  658.                             break;
  659.  
  660.                         case 'id':
  661.                             $attributes array();
  662.                             if isset$metaData->isPermaLink ) )
  663.                             {
  664.                                 $permaLink $metaData->isPermaLink === true 'true' 'false';
  665.                                 $attributes array'isPermaLink' => $permaLink );
  666.                             }
  667.  
  668.                             $this->generateMetaDataWithAttributes$itemTag'guid'$metaData->id$attributes );
  669.                             break;
  670.  
  671.                         case 'category':
  672.                             foreach $metaData as $dataNode )
  673.                             {
  674.                                 $this->generateCategory$dataNode$itemTag );
  675.                             }
  676.                             break;
  677.  
  678.                         case 'author':
  679.                             foreach $metaData as $person )
  680.                             {
  681.                                 $this->generatePerson$person$itemTag'author' );
  682.                             }
  683.                             break;
  684.  
  685.                         case 'published':
  686.                             $this->generateMetaData$itemTag'pubDate'$metaData->date->format'D, d M Y H:i:s O' ) );
  687.                             break;
  688.  
  689.                         case 'enclosure':
  690.                             foreach $metaData as $dataNode )
  691.                             {
  692.                                 $attributes array();
  693.                                 $elements array'url''length''type' );
  694.                                 foreach $elements as $key )
  695.                                 {
  696.                                     if isset$dataNode->$key ) )
  697.                                     {
  698.                                         $attributes[$key$dataNode->$key;
  699.                                     }
  700.                                 }
  701.  
  702.                                 $this->generateMetaDataWithAttributes$itemTag'enclosure'false$attributes );
  703.                             }
  704.  
  705.                             break;
  706.  
  707.                         case 'source':
  708.                             if !isset$metaData->url ) )
  709.                             {
  710.                                 throw new ezcFeedRequiredMetaDataMissingException'/rss/item/source/@url' );
  711.                             }
  712.  
  713.                             $attributes array'url' => $metaData->url );
  714.                             $this->generateMetaDataWithAttributes$itemTag'source'$metaData$attributes );
  715.                             break;
  716.  
  717.                         case 'language':
  718.                            $this->addAttribute$itemTag'xml:lang'$metaData );
  719.                            break;
  720.  
  721.                         default:
  722.                             $this->generateMetaData$itemTag$attribute$metaData );
  723.                     }
  724.                 }
  725.             }
  726.  
  727.             $this->generateItemModules$item$itemTag );
  728.         }
  729.     }
  730.  
  731.     /**
  732.      * Parses the provided XML element object and stores it as a feed item in
  733.      * the provided ezcFeed object.
  734.      *
  735.      * @param ezcFeedElement $element The feed element object that will contain the feed item
  736.      * @param DOMElement $xml The XML element object to parse
  737.      */
  738.     private function parseItemezcFeedElement $elementDOMElement $xml )
  739.     {
  740.         foreach $xml->childNodes as $itemChild )
  741.         {
  742.             if $itemChild->nodeType === XML_ELEMENT_NODE )
  743.             {
  744.                 $tagName $itemChild->tagName;
  745.  
  746.                 switch $tagName )
  747.                 {
  748.                     case 'title':
  749.                     case 'description':
  750.                     case 'comments':
  751.                         $subElement $element->add$tagName );
  752.                         $subElement->text $itemChild->textContent;
  753.                         break;
  754.  
  755.                     case 'author':
  756.                         $subElement $element->add$tagName );
  757.                         $subElement->name $itemChild->textContent;
  758.                         // @todo parse textContent if it has the format: email@host (name)
  759.                         break;
  760.  
  761.                     case 'pubDate':
  762.                         $element->published $itemChild->textContent;
  763.                         break;
  764.  
  765.                     case 'enclosure':
  766.                         $subElement $element->add$tagName );
  767.  
  768.                         $attributes array'url' => 'url''type' => 'type''length' => 'length' );
  769.                         foreach $attributes as $name => $alias )
  770.                         {
  771.                             if $itemChild->hasAttribute$name ) )
  772.                             {
  773.                                 $subElement->$alias $itemChild->getAttribute$name );
  774.                             }
  775.                         }
  776.                         break;
  777.  
  778.                     case 'link':
  779.                         $subElement $element->add$tagName );
  780.                         $subElement->href $itemChild->textContent;
  781.                         break;
  782.  
  783.                     case 'source':
  784.                         $subElement $element->add$tagName );
  785.                         $subElement->source $itemChild->textContent;
  786.                         if $itemChild->hasAttribute'url' ) )
  787.                         {
  788.                             $subElement->url $itemChild->getAttribute'url' );
  789.                         }
  790.                         break;
  791.  
  792.                     case 'category':
  793.                         $subElement $element->add$tagName );
  794.                         $subElement->term $itemChild->textContent;
  795.                         if $itemChild->hasAttribute'domain' ) )
  796.                         {
  797.                             $subElement->scheme $itemChild->getAttribute'domain' );
  798.                         }
  799.                         break;
  800.  
  801.                     case 'guid':
  802.                         $subElement $element->add'id' );
  803.                         $subElement->id $itemChild->textContent;
  804.                         if $itemChild->hasAttribute'isPermaLink' ) )
  805.                         {
  806.                             $value $itemChild->getAttribute'isPermaLink' );
  807.                             $subElement->isPermaLink strtolower$value === 'true' true false;
  808.                         }
  809.                         break;
  810.  
  811.                     default:
  812.                         // check if it's part of a known module/namespace
  813.                         $this->parseModules$element$itemChild$tagName );
  814.                         break;
  815.                 }
  816.             }
  817.         }
  818.  
  819.         if $xml->hasAttribute'xml:lang' ) )
  820.         {
  821.             $element->language $xml->getAttribute'xml:lang' );
  822.         }
  823.     }
  824.  
  825.     /**
  826.      * Parses the provided XML element object and stores it as a feed image in
  827.      * the provided ezcFeedImageElement object.
  828.      *
  829.      * @param ezcFeedImageElement $element The feed element object that will contain the feed image
  830.      * @param DOMElement $xml The XML element object to parse
  831.      */
  832.     private function parseImageezcFeedImageElement $elementDOMElement $xml )
  833.     {
  834.         foreach $xml->childNodes as $itemChild )
  835.         {
  836.             if $itemChild->nodeType === XML_ELEMENT_NODE )
  837.             {
  838.                 $tagName $itemChild->tagName;
  839.  
  840.                 switch $tagName )
  841.                 {
  842.                     case 'title':
  843.                     case 'link':
  844.                     case 'url':
  845.                     case 'description':
  846.                     case 'width':
  847.                     case 'height':
  848.                         $element->$tagName $itemChild->textContent;
  849.                         break;
  850.                 }
  851.             }
  852.         }
  853.     }
  854.  
  855.     /**
  856.      * Parses the provided XML element object and stores it as a feed element
  857.      * of type skipHours in the provided ezcFeedSkipHoursElement object.
  858.      *
  859.      * @param ezcFeedSkipHoursElement $element The feed element object that will contain skipHours
  860.      * @param DOMElement $xml The XML element object to parse
  861.      */
  862.     private function parseSkipHoursezcFeedSkipHoursElement $elementDOMElement $xml )
  863.     {
  864.         $values array();
  865.         foreach $xml->childNodes as $itemChild )
  866.         {
  867.             if $itemChild->nodeType === XML_ELEMENT_NODE )
  868.             {
  869.                 $tagName $itemChild->tagName;
  870.  
  871.                 if $tagName === 'hour' )
  872.                 {
  873.                     $values[$itemChild->textContent;
  874.                 }
  875.             }
  876.         }
  877.  
  878.         $element->hours $values;
  879.     }
  880.  
  881.     /**
  882.      * Parses the provided XML element object and stores it as a feed element
  883.      * of type skipDays in the provided ezcFeedSkipDaysElement object.
  884.      *
  885.      * @param ezcFeedSkipDaysElement $element The feed element object that will contain skipDays
  886.      * @param DOMElement $xml The XML element object to parse
  887.      */
  888.     private function parseSkipDaysezcFeedSkipDaysElement $elementDOMElement $xml )
  889.     {
  890.         $values array();
  891.         foreach $xml->childNodes as $itemChild )
  892.         {
  893.             if $itemChild->nodeType === XML_ELEMENT_NODE )
  894.             {
  895.                 $tagName $itemChild->tagName;
  896.  
  897.                 if $tagName === 'day' )
  898.                 {
  899.                     $values[$itemChild->textContent;
  900.                 }
  901.             }
  902.         }
  903.  
  904.         $element->days $values;
  905.     }
  906.  
  907.     /**
  908.      * Parses the provided XML element object and stores it as a textInput in
  909.      * the provided ezcFeedTextInputElement object.
  910.      *
  911.      * @param ezcFeedTextInputElement $element The feed element object that will contain the textInput
  912.      * @param DOMElement $xml The XML element object to parse
  913.      */
  914.     private function parseTextInputezcFeedTextInputElement $elementDOMElement $xml )
  915.     {
  916.         foreach $xml->childNodes as $itemChild )
  917.         {
  918.             if $itemChild->nodeType === XML_ELEMENT_NODE )
  919.             {
  920.                 $tagName $itemChild->tagName;
  921.  
  922.                 switch $tagName )
  923.                 {
  924.                     case 'title':
  925.                     case 'description':
  926.                     case 'name':
  927.                     case 'link':
  928.                         $element->$tagName $itemChild->textContent;
  929.                         break;
  930.                 }
  931.             }
  932.         }
  933.     }
  934. }
  935. ?>
Documentation generated by phpDocumentor 1.4.3