Apache Zeta Components Manual :: File Source for itunes_module.php
Source for file itunes_module.php
Documentation is available at itunes_module.php
* File containing the ezcFeedITunesModule class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @version //autogentag//
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* Support for the iTunes module: data container, generator, parser.
* Specifications: {@link http://www.apple.com/itunes/store/podcaststechspecs.html}.
* // $feed is an ezcFeed object
* $item = $feed->add( 'item' );
* $module = $item->addModule( 'iTunes' );
* $category = $module->add( 'category' );
* $category->term = 'Category name';
* $subCategory = $category->add( 'category' );
* $subCategory->term = 'Sub-category name';
* // $feed is an ezcFeed object
* if ( isset( $feed->iTunes ) )
* $iTunes = $feed->iTunes;
* if ( isset( $iTunes->category ) )
* foreach ( $iTunes->category as $category )
* if ( isset( $category->category ) )
* foreach ( $category->category as $subCategory )
* echo $subCategory->term;
* @property ezcFeedPersonElement $author
* The author of a resource. Can appear at both
* feed-level and item-level.
* @property ezcFeedTextElement $block
* Prevents a feed or a feed item to appear. Can appear
* at both feed-level and item-level. Valid values are 'yes'
* and 'no', default 'no'.
* @property array(ezcFeedCategoryElement) $category
* Categories for a feed. Can appear at feed-level only.
* Multiple categories can be specified, and categories
* can have sub-categories. The ampersands (&) in categories
* must be escaped to &.
* {@link http://www.apple.com/itunes/store/podcaststechspecs.html#categories Valid iTunes categories}
* @property ezcFeedTextElement $duration
* The duration of a feed item. Can appear at item-level
* only. Can be specified as HH:MM:SS, H:MM:SS, MM:SS,
* M:SS or S (H = hours, M = minutes, S = seconds).
* @property ezcFeedTextElement $explicit
* Specifies if a feed or feed-item contains explicit
* content. Can appear at both feed-level and item-level.
* Valid values are 'clean', 'no' and 'yes', default 'no'.
* @property ezcFeedImageElement $image
* A link to an image for the feed. Can appear at both
* feed-level and item-level only. The
* {@link http://www.apple.com/itunes/store/podcaststechspecs.html iTunes specifications}
* says that image is supported at feed-level only, but there
* are many podcasts using image at item-level also, and there
* are software applications supporting image at item-level too.
* Use image at item-level at your own risk, as some software
* applications might not support it. The Feed component supports
* parsing and generating feeds with image at both feed-level and item-level.
* @property ezcFeedTextElement $keywords
* A list of keywords for a feed or feed item. Can appear
* at both feed-level and item-level. The keywords should
* be separated by commas.
* @property ezcFeedLinkElement $newfeedurl
* A new URL for the feed. Can appear at feed-level only. In
* XML it will appear as 'new-feed-url'.
* @property ezcFeedPersonElement $owner
* The owner of the feed. Can appear at feed-level only.
* @property ezcFeedTextElement $subtitle
* Short description of a feed or feed item. Can appear
* at both feed-level and item-level.
* @property ezcFeedTextElement $summary
* Longer description of a feed or feed item. Can appear
* at both feed-level and item-level.
* @version //autogentag//
* Constructs a new ezcFeedITunesModule object.
* @param string $level The level of the data container ('feed' or 'item')
* 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
public function __set( $name, $value )
$node =
$this->add( $name );
$node =
$this->add( $name );
$node =
$this->add( $name );
$node =
$this->add( $name );
$node =
$this->add( $name );
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
public function __get( $name )
return parent::__get( $name );
* Returns if the property $name is set.
* @param string $name The property name
public function __isset( $name )
return parent::__isset( $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 )
$elements =
array( 'author', 'block', 'category',
'explicit', 'image', 'keywords',
'newfeedurl', 'owner', 'subtitle',
$elements =
array( 'author', 'block', 'duration',
'explicit', 'image', 'keywords',
foreach ( $elements as $element )
if ( isset
( $this->$element ) )
$values =
$this->$element;
foreach ( $this->category as $values )
$root->appendChild( $elementTag );
// generate sub-categories
if ( isset
( $values->category ) )
$subCategory =
$values->category;
$this->addAttribute( $xml, $subTag, 'text', $subCategory->term );
$elementTag->appendChild( $subTag );
if ( isset
( $values->term ) )
$this->addAttribute( $xml, $elementTag, 'text', $values->term );
$root->appendChild( $elementTag );
if ( isset
( $values->link ) )
$this->addAttribute( $xml, $elementTag, 'href', $values->link );
$root->appendChild( $elementTag );
foreach ( array( 'email', 'name' ) as $subElement )
if ( isset
( $values->$subElement ) )
$val =
$xml->createTextNode( $values->$subElement );
$tag->appendChild( $val );
$elementTag->appendChild( $tag );
$root->appendChild( $elementTag );
$elementTag->nodeValue =
$values->href;
$root->appendChild( $elementTag );
$elementTag->nodeValue =
$values->__toString();
* 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 ( $name ===
'new-feed-url' )
$element =
$this->add( $name );
$value =
$node->textContent;
foreach ( $node->childNodes as $subNode )
if ( get_class( $subNode ) ===
'DOMElement' )
$subCategory =
$element->add( $name );
if ( $subNode->hasAttribute( 'text' ) )
$subCategory->term =
$subNode->getAttribute( 'text' );
if ( $node->hasAttribute( 'text' ) )
$element->term =
$node->getAttribute( 'text' );
// no textContent in $node
if ( $node->hasAttribute( 'href' ) )
$element->link =
$node->getAttribute( 'href' );
$element->href =
$node->textContent;
$namespace =
self::getNamespace();
$nodes =
$node->getElementsByTagNameNS( $namespace, 'email' );
if ( $nodes->length >=
1 )
$element->email =
$nodes->item( 0 )->textContent;
$nodes =
$node->getElementsByTagNameNS( $namespace, 'name' );
if ( $nodes->length >=
1 )
$element->name =
$nodes->item( 0 )->textContent;
* 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)
if ( in_array( $name, array( 'author', 'block', 'category',
'explicit', 'image', 'keywords',
'newfeedurl', 'owner', 'subtitle',
if ( in_array( $name, array( 'author', 'block', 'duration',
'explicit', 'image', 'keywords',
'subtitle', 'summary' ) ) )
* Adds a new ezcFeedElement element with name $name to this module and
* @throws ezcFeedUnsupportedElementException
* if trying to add an element which is not supported.
* @param string $name The element name
public function add( $name )
* Returns the module name ('iTunes').
* Returns the namespace for this module ('http://www.itunes.com/dtds/podcast-1.0.dtd').
return 'http://www.itunes.com/dtds/podcast-1.0.dtd';
* Returns the namespace prefix for this module ('itunes').