[44] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Zend Framework
|
---|
| 5 | *
|
---|
| 6 | * LICENSE
|
---|
| 7 | *
|
---|
| 8 | * This source file is subject to the new BSD license that is bundled
|
---|
| 9 | * with this package in the file LICENSE.txt.
|
---|
| 10 | * It is also available through the world-wide-web at this URL:
|
---|
| 11 | * http://framework.zend.com/license/new-bsd
|
---|
| 12 | * If you did not receive a copy of the license and are unable to
|
---|
| 13 | * obtain it through the world-wide-web, please send an email
|
---|
| 14 | * to license@zend.com so we can send you a copy immediately.
|
---|
| 15 | *
|
---|
| 16 | * @category Zend
|
---|
| 17 | * @package Zend_Gdata
|
---|
| 18 | * @subpackage YouTube
|
---|
| 19 | * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
| 20 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * @see Zend_Gdata_YouTube
|
---|
| 25 | */
|
---|
| 26 | require_once 'Zend/Gdata/YouTube.php';
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * @see Zend_Gdata_Entry
|
---|
| 30 | */
|
---|
| 31 | require_once 'Zend/Gdata/Entry.php';
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @see Zend_Gdata_Extension_FeedLink
|
---|
| 35 | */
|
---|
| 36 | require_once 'Zend/Gdata/Extension/FeedLink.php';
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * @see Zend_Gdata_YouTube_Extension_Description
|
---|
| 40 | */
|
---|
| 41 | require_once 'Zend/Gdata/YouTube/Extension/Description.php';
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * @see Zend_Gdata_YouTube_Extension_PlaylistId
|
---|
| 45 | */
|
---|
| 46 | require_once 'Zend/Gdata/YouTube/Extension/PlaylistId.php';
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * @see Zend_Gdata_YouTube_Extension_CountHint
|
---|
| 50 | */
|
---|
| 51 | require_once 'Zend/Gdata/YouTube/Extension/CountHint.php';
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | * Represents the YouTube video playlist flavor of an Atom entry
|
---|
| 55 | *
|
---|
| 56 | * @category Zend
|
---|
| 57 | * @package Zend_Gdata
|
---|
| 58 | * @subpackage YouTube
|
---|
| 59 | * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
---|
| 60 | * @license http://framework.zend.com/license/new-bsd New BSD License
|
---|
| 61 | */
|
---|
| 62 | class Zend_Gdata_YouTube_PlaylistListEntry extends Zend_Gdata_Entry
|
---|
| 63 | {
|
---|
| 64 |
|
---|
| 65 | protected $_entryClassName = 'Zend_Gdata_YouTube_PlaylistListEntry';
|
---|
| 66 |
|
---|
| 67 | /**
|
---|
| 68 | * Nested feed links
|
---|
| 69 | *
|
---|
| 70 | * @var array
|
---|
| 71 | */
|
---|
| 72 | protected $_feedLink = array();
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * Description of this playlist
|
---|
| 76 | *
|
---|
| 77 | * @deprecated Deprecated as of version 2 of the YouTube API.
|
---|
| 78 | * @var Zend_Gdata_YouTube_Extension_Description
|
---|
| 79 | */
|
---|
| 80 | protected $_description = null;
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Id of this playlist
|
---|
| 84 | *
|
---|
| 85 | * @var Zend_Gdata_YouTube_Extension_PlaylistId
|
---|
| 86 | */
|
---|
| 87 | protected $_playlistId = null;
|
---|
| 88 |
|
---|
| 89 | /**
|
---|
| 90 | * CountHint for this playlist.
|
---|
| 91 | *
|
---|
| 92 | * @var Zend_Gdata_YouTube_Extension_CountHint
|
---|
| 93 | */
|
---|
| 94 | protected $_countHint = null;
|
---|
| 95 |
|
---|
| 96 | /**
|
---|
| 97 | * Creates a Playlist list entry, representing an individual playlist
|
---|
| 98 | * in a list of playlists, usually associated with an individual user.
|
---|
| 99 | *
|
---|
| 100 | * @param DOMElement $element (optional) DOMElement from which this
|
---|
| 101 | * object should be constructed.
|
---|
| 102 | */
|
---|
| 103 | public function __construct($element = null)
|
---|
| 104 | {
|
---|
| 105 | $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
|
---|
| 106 | parent::__construct($element);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /**
|
---|
| 110 | * Retrieves a DOMElement which corresponds to this element and all
|
---|
| 111 | * child properties. This is used to build an entry back into a DOM
|
---|
| 112 | * and eventually XML text for sending to the server upon updates, or
|
---|
| 113 | * for application storage/persistence.
|
---|
| 114 | *
|
---|
| 115 | * @param DOMDocument $doc The DOMDocument used to construct DOMElements
|
---|
| 116 | * @return DOMElement The DOMElement representing this element and all
|
---|
| 117 | * child properties.
|
---|
| 118 | */
|
---|
| 119 | public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
|
---|
| 120 | {
|
---|
| 121 | $element = parent::getDOM($doc, $majorVersion, $minorVersion);
|
---|
| 122 | if ($this->_description != null) {
|
---|
| 123 | $element->appendChild($this->_description->getDOM($element->ownerDocument));
|
---|
| 124 | }
|
---|
| 125 | if ($this->_countHint != null) {
|
---|
| 126 | $element->appendChild($this->_countHint->getDOM($element->ownerDocument));
|
---|
| 127 | }
|
---|
| 128 | if ($this->_playlistId != null) {
|
---|
| 129 | $element->appendChild($this->_playlistId->getDOM($element->ownerDocument));
|
---|
| 130 | }
|
---|
| 131 | if ($this->_feedLink != null) {
|
---|
| 132 | foreach ($this->_feedLink as $feedLink) {
|
---|
| 133 | $element->appendChild($feedLink->getDOM($element->ownerDocument));
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | return $element;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Creates individual Entry objects of the appropriate type and
|
---|
| 141 | * stores them in the $_entry array based upon DOM data.
|
---|
| 142 | *
|
---|
| 143 | * @param DOMNode $child The DOMNode to process
|
---|
| 144 | */
|
---|
| 145 | protected function takeChildFromDOM($child)
|
---|
| 146 | {
|
---|
| 147 | $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
|
---|
| 148 | switch ($absoluteNodeName) {
|
---|
| 149 | case $this->lookupNamespace('yt') . ':' . 'description':
|
---|
| 150 | $description = new Zend_Gdata_YouTube_Extension_Description();
|
---|
| 151 | $description->transferFromDOM($child);
|
---|
| 152 | $this->_description = $description;
|
---|
| 153 | break;
|
---|
| 154 | case $this->lookupNamespace('yt') . ':' . 'countHint':
|
---|
| 155 | $countHint = new Zend_Gdata_YouTube_Extension_CountHint();
|
---|
| 156 | $countHint->transferFromDOM($child);
|
---|
| 157 | $this->_countHint = $countHint;
|
---|
| 158 | break;
|
---|
| 159 | case $this->lookupNamespace('yt') . ':' . 'playlistId':
|
---|
| 160 | $playlistId = new Zend_Gdata_YouTube_Extension_PlaylistId();
|
---|
| 161 | $playlistId->transferFromDOM($child);
|
---|
| 162 | $this->_playlistId = $playlistId;
|
---|
| 163 | break;
|
---|
| 164 | case $this->lookupNamespace('gd') . ':' . 'feedLink':
|
---|
| 165 | $feedLink = new Zend_Gdata_Extension_FeedLink();
|
---|
| 166 | $feedLink->transferFromDOM($child);
|
---|
| 167 | $this->_feedLink[] = $feedLink;
|
---|
| 168 | break;
|
---|
| 169 | default:
|
---|
| 170 | parent::takeChildFromDOM($child);
|
---|
| 171 | break;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | /**
|
---|
| 176 | * Sets the description relating to the playlist.
|
---|
| 177 | *
|
---|
| 178 | * @deprecated Deprecated as of version 2 of the YouTube API.
|
---|
| 179 | * @param Zend_Gdata_YouTube_Extension_Description $description The description relating to the video
|
---|
| 180 | * @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
|
---|
| 181 | */
|
---|
| 182 | public function setDescription($description = null)
|
---|
| 183 | {
|
---|
| 184 | if ($this->getMajorProtocolVersion() >= 2) {
|
---|
| 185 | $this->setSummary($description);
|
---|
| 186 | } else {
|
---|
| 187 | $this->_description = $description;
|
---|
| 188 | }
|
---|
| 189 | return $this;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /**
|
---|
| 193 | * Returns the description relating to the video.
|
---|
| 194 | *
|
---|
| 195 | * @return Zend_Gdata_YouTube_Extension_Description The description
|
---|
| 196 | * relating to the video
|
---|
| 197 | */
|
---|
| 198 | public function getDescription()
|
---|
| 199 | {
|
---|
| 200 | if ($this->getMajorProtocolVersion() >= 2) {
|
---|
| 201 | return $this->getSummary();
|
---|
| 202 | } else {
|
---|
| 203 | return $this->_description;
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | /**
|
---|
| 208 | * Returns the countHint relating to the playlist.
|
---|
| 209 | *
|
---|
| 210 | * The countHint is the number of videos on a playlist.
|
---|
| 211 | *
|
---|
| 212 | * @throws Zend_Gdata_App_VersionException
|
---|
| 213 | * @return Zend_Gdata_YouTube_Extension_CountHint The count of videos on
|
---|
| 214 | * a playlist.
|
---|
| 215 | */
|
---|
| 216 | public function getCountHint()
|
---|
| 217 | {
|
---|
| 218 | if (($this->getMajorProtocolVersion() == null) ||
|
---|
| 219 | ($this->getMajorProtocolVersion() == 1)) {
|
---|
| 220 | require_once 'Zend/Gdata/App/VersionException.php';
|
---|
| 221 | throw new Zend_Gdata_App_VersionException('The yt:countHint ' .
|
---|
| 222 | 'element is not supported in versions earlier than 2.');
|
---|
| 223 | } else {
|
---|
| 224 | return $this->_countHint;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | /**
|
---|
| 229 | * Returns the Id relating to the playlist.
|
---|
| 230 | *
|
---|
| 231 | * @throws Zend_Gdata_App_VersionException
|
---|
| 232 | * @return Zend_Gdata_YouTube_Extension_PlaylistId The id of this playlist.
|
---|
| 233 | */
|
---|
| 234 | public function getPlaylistId()
|
---|
| 235 | {
|
---|
| 236 | if (($this->getMajorProtocolVersion() == null) ||
|
---|
| 237 | ($this->getMajorProtocolVersion() == 1)) {
|
---|
| 238 | require_once 'Zend/Gdata/App/VersionException.php';
|
---|
| 239 | throw new Zend_Gdata_App_VersionException('The yt:playlistId ' .
|
---|
| 240 | 'element is not supported in versions earlier than 2.');
|
---|
| 241 | } else {
|
---|
| 242 | return $this->_playlistId;
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
| 247 | * Sets the array of embedded feeds related to the playlist
|
---|
| 248 | *
|
---|
| 249 | * @param array $feedLink The array of embedded feeds relating to the video
|
---|
| 250 | * @return Zend_Gdata_YouTube_PlaylistListEntry Provides a fluent interface
|
---|
| 251 | */
|
---|
| 252 | public function setFeedLink($feedLink = null)
|
---|
| 253 | {
|
---|
| 254 | $this->_feedLink = $feedLink;
|
---|
| 255 | return $this;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /**
|
---|
| 259 | * Get the feed link property for this entry.
|
---|
| 260 | *
|
---|
| 261 | * @see setFeedLink
|
---|
| 262 | * @param string $rel (optional) The rel value of the link to be found.
|
---|
| 263 | * If null, the array of links is returned.
|
---|
| 264 | * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink
|
---|
| 265 | * object corresponding to the requested rel value is returned
|
---|
| 266 | * if found, or null if the requested value is not found. If
|
---|
| 267 | * $rel is null or not specified, an array of all available
|
---|
| 268 | * feed links for this entry is returned, or null if no feed
|
---|
| 269 | * links are set.
|
---|
| 270 | */
|
---|
| 271 | public function getFeedLink($rel = null)
|
---|
| 272 | {
|
---|
| 273 | if ($rel == null) {
|
---|
| 274 | return $this->_feedLink;
|
---|
| 275 | } else {
|
---|
| 276 | foreach ($this->_feedLink as $feedLink) {
|
---|
| 277 | if ($feedLink->rel == $rel) {
|
---|
| 278 | return $feedLink;
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 | return null;
|
---|
| 282 | }
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | /**
|
---|
| 286 | * Returns the URL of the playlist video feed
|
---|
| 287 | *
|
---|
| 288 | * @return string The URL of the playlist video feed
|
---|
| 289 | */
|
---|
| 290 | public function getPlaylistVideoFeedUrl()
|
---|
| 291 | {
|
---|
| 292 | if ($this->getMajorProtocolVersion() >= 2) {
|
---|
| 293 | return $this->getContent()->getSrc();
|
---|
| 294 | } else {
|
---|
| 295 | return $this->getFeedLink(Zend_Gdata_YouTube::PLAYLIST_REL)->href;
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | }
|
---|