[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 [email protected] so we can send you a copy immediately. 15 * 16 * @category Zend 17 * @package Zend_Gdata 18 * @subpackage YouTube 19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 20 * @license http://framework.zend.com/license/new-bsd New BSD License 21 * @version $Id$ 22 */ 23 24 /** 25 * @see Zend_Gdata_Extension_Comments 26 */ 27 require_once 'Zend/Gdata/Extension/Comments.php'; 28 29 /** 30 * @see Zend_Gdata_Extension_FeedLink 31 */ 32 require_once 'Zend/Gdata/Extension/FeedLink.php'; 33 34 /** 35 * @see Zend_Gdata_YouTube_MediaEntry 36 */ 37 require_once 'Zend/Gdata/YouTube/MediaEntry.php'; 38 39 /** 40 * @see Zend_Gdata_YouTube_Extension_MediaGroup 41 */ 42 require_once 'Zend/Gdata/YouTube/Extension/MediaGroup.php'; 43 44 /** 45 * @see Zend_Gdata_YouTube_Extension_NoEmbed 46 */ 47 require_once 'Zend/Gdata/YouTube/Extension/NoEmbed.php'; 48 49 /** 50 * @see Zend_Gdata_YouTube_Extension_Statistics 51 */ 52 require_once 'Zend/Gdata/YouTube/Extension/Statistics.php'; 53 54 /** 55 * @see Zend_Gdata_YouTube_Extension_Link 56 */ 57 require_once 'Zend/Gdata/YouTube/Extension/Link.php'; 58 59 /** 60 * @see Zend_Gdata_YouTube_Extension_Racy 61 */ 62 require_once 'Zend/Gdata/YouTube/Extension/Racy.php'; 63 64 /** 65 * @see Zend_Gdata_Extension_Rating 66 */ 67 require_once 'Zend/Gdata/Extension/Rating.php'; 68 69 /** 70 * @see Zend_Gdata_Geo_Extension_GeoRssWhere 71 */ 72 require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php'; 73 74 /** 75 * @see Zend_Gdata_YouTube_Extension_Control 76 */ 77 require_once 'Zend/Gdata/YouTube/Extension/Control.php'; 78 79 /** 80 * @see Zend_Gdata_YouTube_Extension_Recorded 81 */ 82 require_once 'Zend/Gdata/YouTube/Extension/Recorded.php'; 83 84 /** 85 * @see Zend_Gdata_YouTube_Extension_Location 86 */ 87 require_once 'Zend/Gdata/YouTube/Extension/Location.php'; 88 89 /** 90 * Represents the YouTube video flavor of an Atom entry 91 * 92 * @category Zend 93 * @package Zend_Gdata 94 * @subpackage YouTube 95 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 96 * @license http://framework.zend.com/license/new-bsd New BSD License 97 */ 98 class Zend_Gdata_YouTube_VideoEntry extends Zend_Gdata_YouTube_MediaEntry 99 { 100 101 const YOUTUBE_DEVELOPER_TAGS_SCHEMA = 'http://gdata.youtube.com/schemas/2007/developertags.cat'; 102 const YOUTUBE_CATEGORY_SCHEMA = 'http://gdata.youtube.com/schemas/2007/categories.cat'; 103 protected $_entryClassName = 'Zend_Gdata_YouTube_VideoEntry'; 104 105 /** 106 * If null, the video can be embedded 107 * 108 * @var Zend_Gdata_YouTube_Extension_NoEmbed|null 109 */ 110 protected $_noEmbed = null; 111 112 /** 113 * Specifies the statistics relating to the video. 114 * 115 * @var Zend_Gdata_YouTube_Extension_Statistics 116 */ 117 protected $_statistics = null; 118 119 /** 120 * If not null, specifies that the video has racy content. 121 * 122 * @var Zend_Gdata_YouTube_Extension_Racy|null 123 */ 124 protected $_racy = null; 125 126 /** 127 * If not null, specifies that the video is private. 128 * 129 * @var Zend_Gdata_YouTube_Extension_Private|null 130 */ 131 protected $_private = null; 132 133 /** 134 * Specifies the video's rating. 135 * 136 * @var Zend_Gdata_Extension_Rating 137 */ 138 protected $_rating = null; 139 140 /** 141 * Specifies the comments associated with a video. 142 * 143 * @var Zend_Gdata_Extensions_Comments 144 */ 145 protected $_comments = null; 146 147 /** 148 * Nested feed links 149 * 150 * @var array 151 */ 152 protected $_feedLink = array(); 153 154 /** 155 * Geo location for the video 156 * 157 * @var Zend_Gdata_Geo_Extension_GeoRssWhere 158 */ 159 protected $_where = null; 160 161 /** 162 * Recording date for the video 163 * 164 * @var Zend_Gdata_YouTube_Extension_Recorded|null 165 */ 166 protected $_recorded = null; 167 168 /** 169 * Location informtion for the video 170 * 171 * @var Zend_Gdata_YouTube_Extension_Location|null 172 */ 173 protected $_location = null; 174 175 /** 176 * Creates a Video entry, representing an individual video 177 * 178 * @param DOMElement $element (optional) DOMElement from which this 179 * object should be constructed. 180 */ 181 public function __construct($element = null) 182 { 183 $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces); 184 parent::__construct($element); 185 } 186 187 /** 188 * Retrieves a DOMElement which corresponds to this element and all 189 * child properties. This is used to build an entry back into a DOM 190 * and eventually XML text for sending to the server upon updates, or 191 * for application storage/persistence. 192 * 193 * @param DOMDocument $doc The DOMDocument used to construct DOMElements 194 * @return DOMElement The DOMElement representing this element and all 195 * child properties. 196 */ 197 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) 198 { 199 $element = parent::getDOM($doc, $majorVersion, $minorVersion); 200 if ($this->_noEmbed != null) { 201 $element->appendChild($this->_noEmbed->getDOM( 202 $element->ownerDocument)); 203 } 204 if ($this->_statistics != null) { 205 $element->appendChild($this->_statistics->getDOM( 206 $element->ownerDocument)); 207 } 208 if ($this->_racy != null) { 209 $element->appendChild($this->_racy->getDOM( 210 $element->ownerDocument)); 211 } 212 if ($this->_recorded != null) { 213 $element->appendChild($this->_recorded->getDOM( 214 $element->ownerDocument)); 215 } 216 if ($this->_location != null) { 217 $element->appendChild($this->_location->getDOM( 218 $element->ownerDocument)); 219 } 220 if ($this->_rating != null) { 221 $element->appendChild($this->_rating->getDOM( 222 $element->ownerDocument)); 223 } 224 if ($this->_comments != null) { 225 $element->appendChild($this->_comments->getDOM( 226 $element->ownerDocument)); 227 } 228 if ($this->_feedLink != null) { 229 foreach ($this->_feedLink as $feedLink) { 230 $element->appendChild($feedLink->getDOM( 231 $element->ownerDocument)); 232 } 233 } 234 if ($this->_where != null) { 235 $element->appendChild($this->_where->getDOM( 236 $element->ownerDocument)); 237 } 238 return $element; 239 } 240 241 /** 242 * Creates individual Entry objects of the appropriate type and 243 * stores them in the $_entry array based upon DOM data. 244 * 245 * @param DOMNode $child The DOMNode to process 246 */ 247 protected function takeChildFromDOM($child) 248 { 249 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; 250 251 switch ($absoluteNodeName) { 252 case $this->lookupNamespace('yt') . ':' . 'statistics': 253 $statistics = new Zend_Gdata_YouTube_Extension_Statistics(); 254 $statistics->transferFromDOM($child); 255 $this->_statistics = $statistics; 256 break; 257 case $this->lookupNamespace('yt') . ':' . 'racy': 258 $racy = new Zend_Gdata_YouTube_Extension_Racy(); 259 $racy->transferFromDOM($child); 260 $this->_racy = $racy; 261 break; 262 case $this->lookupNamespace('yt') . ':' . 'recorded': 263 $recorded = new Zend_Gdata_YouTube_Extension_Recorded(); 264 $recorded->transferFromDOM($child); 265 $this->_recorded = $recorded; 266 break; 267 case $this->lookupNamespace('yt') . ':' . 'location': 268 $location = new Zend_Gdata_YouTube_Extension_Location(); 269 $location->transferFromDOM($child); 270 $this->_location = $location; 271 break; 272 case $this->lookupNamespace('gd') . ':' . 'rating': 273 $rating = new Zend_Gdata_Extension_Rating(); 274 $rating->transferFromDOM($child); 275 $this->_rating = $rating; 276 break; 277 case $this->lookupNamespace('gd') . ':' . 'comments': 278 $comments = new Zend_Gdata_Extension_Comments(); 279 $comments->transferFromDOM($child); 280 $this->_comments = $comments; 281 break; 282 case $this->lookupNamespace('yt') . ':' . 'noembed': 283 $noEmbed = new Zend_Gdata_YouTube_Extension_NoEmbed(); 284 $noEmbed->transferFromDOM($child); 285 $this->_noEmbed = $noEmbed; 286 break; 287 case $this->lookupNamespace('gd') . ':' . 'feedLink': 288 $feedLink = new Zend_Gdata_Extension_FeedLink(); 289 $feedLink->transferFromDOM($child); 290 $this->_feedLink[] = $feedLink; 291 break; 292 case $this->lookupNamespace('georss') . ':' . 'where': 293 $where = new Zend_Gdata_Geo_Extension_GeoRssWhere(); 294 $where->transferFromDOM($child); 295 $this->_where = $where; 296 break; 297 case $this->lookupNamespace('atom') . ':' . 'link'; 298 $link = new Zend_Gdata_YouTube_Extension_Link(); 299 $link->transferFromDOM($child); 300 $this->_link[] = $link; 301 break; 302 case $this->lookupNamespace('app') . ':' . 'control': 303 $control = new Zend_Gdata_YouTube_Extension_Control(); 304 $control->transferFromDOM($child); 305 $this->_control = $control; 306 break; 307 default: 308 parent::takeChildFromDOM($child); 309 break; 310 } 311 } 312 313 /** 314 * Sets when the video was recorded. 315 * 316 * @param Zend_Gdata_YouTube_Extension_Recorded $recorded When the video was recorded 317 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 318 */ 319 public function setRecorded($recorded = null) 320 { 321 $this->_recorded = $recorded; 322 return $this; 323 } 324 325 /** 326 * Gets the date that the video was recorded. 327 * 328 * @return Zend_Gdata_YouTube_Extension_Recorded|null 329 */ 330 public function getRecorded() 331 { 332 return $this->_recorded; 333 } 334 335 /** 336 * Sets the location information. 337 * 338 * @param Zend_Gdata_YouTube_Extension_Location $location Where the video 339 * was recorded 340 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 341 */ 342 public function setLocation($location = null) 343 { 344 $this->_location = $location; 345 return $this; 346 } 347 348 /** 349 * Gets the location where the video was recorded. 350 * 351 * @return Zend_Gdata_YouTube_Extension_Location|null 352 */ 353 public function getLocation() 354 { 355 return $this->_location; 356 } 357 358 /** 359 * If an instance of Zend_Gdata_YouTube_Extension_NoEmbed is passed in, 360 * the video cannot be embedded. Otherwise, if null is passsed in, the 361 * video is able to be embedded. 362 * 363 * @param Zend_Gdata_YouTube_Extension_NoEmbed $noEmbed Whether or not the 364 * video can be embedded. 365 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 366 */ 367 public function setNoEmbed($noEmbed = null) 368 { 369 $this->_noEmbed = $noEmbed; 370 return $this; 371 } 372 373 /** 374 * If the return value is an instance of 375 * Zend_Gdata_YouTube_Extension_NoEmbed, this video cannot be embedded. 376 * 377 * @return Zend_Gdata_YouTube_Extension_NoEmbed|null Whether or not the video can be embedded 378 */ 379 public function getNoEmbed() 380 { 381 return $this->_noEmbed; 382 } 383 384 /** 385 * Checks whether the video is embeddable. 386 * 387 * @return bool Returns true if the video is embeddable. 388 */ 389 public function isVideoEmbeddable() 390 { 391 if ($this->getNoEmbed() == null) { 392 return true; 393 } else { 394 return false; 395 } 396 } 397 398 /** 399 * Sets the statistics relating to the video. 400 * 401 * @param Zend_Gdata_YouTube_Extension_Statistics $statistics The statistics relating to the video 402 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 403 */ 404 public function setStatistics($statistics = null) 405 { 406 $this->_statistics = $statistics; 407 return $this; 408 } 409 410 /** 411 * Returns the statistics relating to the video. 412 * 413 * @return Zend_Gdata_YouTube_Extension_Statistics The statistics relating to the video 414 */ 415 public function getStatistics() 416 { 417 return $this->_statistics; 418 } 419 420 /** 421 * Specifies that the video has racy content. 422 * 423 * @param Zend_Gdata_YouTube_Extension_Racy $racy The racy flag object 424 * @throws Zend_Gdata_App_VersionException 425 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 426 */ 427 public function setRacy($racy = null) 428 { 429 if ($this->getMajorProtocolVersion() == 2) { 430 require_once 'Zend/Gdata/App/VersionException.php'; 431 throw new Zend_Gdata_App_VersionException( 432 'Calling getRacy() on a YouTube VideoEntry is deprecated ' . 433 'as of version 2 of the API.'); 434 } 435 436 $this->_racy = $racy; 437 return $this; 438 } 439 440 /** 441 * Returns the racy flag object. 442 * 443 * @throws Zend_Gdata_App_VersionException 444 * @return Zend_Gdata_YouTube_Extension_Racy|null The racy flag object 445 */ 446 public function getRacy() 447 { 448 if ($this->getMajorProtocolVersion() == 2) { 449 require_once 'Zend/Gdata/App/VersionException.php'; 450 throw new Zend_Gdata_App_VersionException( 451 'Calling getRacy() on a YouTube VideoEntry is deprecated ' . 452 'as of version 2 of the API.'); 453 } 454 return $this->_racy; 455 } 456 457 /** 458 * Sets the rating relating to the video. 459 * 460 * @param Zend_Gdata_Extension_Rating $rating The rating relating to the video 461 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 462 */ 463 public function setRating($rating = null) 464 { 465 $this->_rating = $rating; 466 return $this; 467 } 468 469 /** 470 * Returns the rating relating to the video. 471 * 472 * @return Zend_Gdata_Extension_Rating The rating relating to the video 473 */ 474 public function getRating() 475 { 476 return $this->_rating; 477 } 478 479 /** 480 * Sets the comments relating to the video. 481 * 482 * @param Zend_Gdata_Extension_Comments $comments The comments relating to the video 483 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 484 */ 485 public function setComments($comments = null) 486 { 487 $this->_comments = $comments; 488 return $this; 489 } 490 491 /** 492 * Returns the comments relating to the video. 493 * 494 * @return Zend_Gdata_Extension_Comments The comments relating to the video 495 */ 496 public function getComments() 497 { 498 return $this->_comments; 499 } 500 501 /** 502 * Sets the array of embedded feeds related to the video 503 * 504 * @param array $feedLink The array of embedded feeds relating to the video 505 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 506 */ 507 public function setFeedLink($feedLink = null) 508 { 509 $this->_feedLink = $feedLink; 510 return $this; 511 } 512 513 /** 514 * Get the feed link property for this entry. 515 * 516 * @see setFeedLink 517 * @param string $rel (optional) The rel value of the link to be found. 518 * If null, the array of links is returned. 519 * @return mixed If $rel is specified, a Zend_Gdata_Extension_FeedLink 520 * object corresponding to the requested rel value is returned 521 * if found, or null if the requested value is not found. If 522 * $rel is null or not specified, an array of all available 523 * feed links for this entry is returned, or null if no feed 524 * links are set. 525 */ 526 public function getFeedLink($rel = null) 527 { 528 if ($rel == null) { 529 return $this->_feedLink; 530 } else { 531 foreach ($this->_feedLink as $feedLink) { 532 if ($feedLink->rel == $rel) { 533 return $feedLink; 534 } 535 } 536 return null; 537 } 538 } 539 540 /** 541 * Returns the link element relating to video responses. 542 * 543 * @return Zend_Gdata_App_Extension_Link 544 */ 545 public function getVideoResponsesLink() 546 { 547 return $this->getLink(Zend_Gdata_YouTube::VIDEO_RESPONSES_REL); 548 } 549 550 /** 551 * Returns the link element relating to video ratings. 552 * 553 * @return Zend_Gdata_App_Extension_Link 554 */ 555 public function getVideoRatingsLink() 556 { 557 return $this->getLink(Zend_Gdata_YouTube::VIDEO_RATINGS_REL); 558 } 559 560 /** 561 * Returns the link element relating to video complaints. 562 * 563 * @return Zend_Gdata_App_Extension_Link 564 */ 565 public function getVideoComplaintsLink() 566 { 567 return $this->getLink(Zend_Gdata_YouTube::VIDEO_COMPLAINTS_REL); 568 } 569 570 /** 571 * Gets the YouTube video ID based upon the atom:id value 572 * 573 * @return string The video ID 574 */ 575 public function getVideoId() 576 { 577 if ($this->getMajorProtocolVersion() == 2) { 578 $videoId = $this->getMediaGroup()->getVideoId()->text; 579 } else { 580 $fullId = $this->getId()->getText(); 581 $position = strrpos($fullId, '/'); 582 if ($position === false) { 583 require_once 'Zend/Gdata/App/Exception.php'; 584 throw new Zend_Gdata_App_Exception( 585 'Slash not found in atom:id of ' . $fullId); 586 } else { 587 $videoId = substr($fullId, $position + 1); 588 } 589 } 590 return $videoId; 591 } 592 593 /** 594 * Gets the date that the video was recorded. 595 * 596 * @return string|null The date that the video was recorded 597 */ 598 public function getVideoRecorded() 599 { 600 $recorded = $this->getRecorded(); 601 if ($recorded != null) { 602 return $recorded->getText(); 603 } else { 604 return null; 605 } 606 } 607 608 /** 609 * Sets the date that the video was recorded. 610 * 611 * @param string $recorded The date that the video was recorded, in the 612 * format of '2001-06-19' 613 */ 614 public function setVideoRecorded($recorded) 615 { 616 $this->setRecorded( 617 new Zend_Gdata_YouTube_Extension_Recorded($recorded)); 618 return $this; 619 } 620 621 /** 622 * Gets the georss:where element 623 * 624 * @return Zend_Gdata_Geo_Extension_GeoRssWhere 625 */ 626 public function getWhere() 627 { 628 return $this->_where; 629 } 630 631 /** 632 * Sets the georss:where element 633 * 634 * @param Zend_Gdata_Geo_Extension_GeoRssWhere $value The georss:where class value 635 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 636 */ 637 public function setWhere($value) 638 { 639 $this->_where = $value; 640 return $this; 641 } 642 643 /** 644 * Gets the title of the video as a string. null is returned 645 * if the video title is not available. 646 * 647 * @return string|null The title of the video 648 */ 649 public function getVideoTitle() 650 { 651 $this->ensureMediaGroupIsNotNull(); 652 if ($this->getMediaGroup()->getTitle() != null) { 653 return $this->getMediaGroup()->getTitle()->getText(); 654 } else { 655 return null; 656 } 657 } 658 659 /** 660 * Sets the title of the video as a string. 661 * 662 * @param string $title Title for the video 663 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 664 */ 665 public function setVideoTitle($title) 666 { 667 $this->ensureMediaGroupIsNotNull(); 668 $this->getMediaGroup()->setTitle( 669 new Zend_Gdata_Media_Extension_MediaTitle($title)); 670 return $this; 671 } 672 673 /** 674 * Sets the description of the video as a string. 675 * 676 * @param string $description Description for the video 677 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 678 */ 679 public function setVideoDescription($description) 680 { 681 $this->ensureMediaGroupIsNotNull(); 682 $this->getMediaGroup()->setDescription( 683 new Zend_Gdata_Media_Extension_MediaDescription($description)); 684 return $this; 685 } 686 687 688 /** 689 * Gets the description of the video as a string. null is returned 690 * if the video description is not available. 691 * 692 * @return string|null The description of the video 693 */ 694 public function getVideoDescription() 695 { 696 $this->ensureMediaGroupIsNotNull(); 697 if ($this->getMediaGroup()->getDescription() != null) { 698 return $this->getMediaGroup()->getDescription()->getText(); 699 } else { 700 return null; 701 } 702 } 703 704 /** 705 * Gets the URL of the YouTube video watch page. null is returned 706 * if the video watch page URL is not available. 707 * 708 * @return string|null The URL of the YouTube video watch page 709 */ 710 public function getVideoWatchPageUrl() 711 { 712 $this->ensureMediaGroupIsNotNull(); 713 if ($this->getMediaGroup()->getPlayer() != null && 714 array_key_exists(0, $this->getMediaGroup()->getPlayer())) { 715 $players = $this->getMediaGroup()->getPlayer(); 716 return $players[0]->getUrl(); 717 } else { 718 return null; 719 } 720 } 721 722 /** 723 * Gets an array of the thumbnails representing the video. 724 * Each thumbnail is an element of the array, and is an 725 * array of the thumbnail properties - time, height, width, 726 * and url. For convient usage inside a foreach loop, an 727 * empty array is returned if there are no thumbnails. 728 * 729 * @return array An array of video thumbnails. 730 */ 731 public function getVideoThumbnails() 732 { 733 $this->ensureMediaGroupIsNotNull(); 734 if ($this->getMediaGroup()->getThumbnail() != null) { 735 736 $thumbnailArray = array(); 737 738 foreach ($this->getMediaGroup()->getThumbnail() as $thumbnailObj) { 739 $thumbnail = array(); 740 $thumbnail['time'] = $thumbnailObj->time; 741 $thumbnail['height'] = $thumbnailObj->height; 742 $thumbnail['width'] = $thumbnailObj->width; 743 $thumbnail['url'] = $thumbnailObj->url; 744 $thumbnailArray[] = $thumbnail; 745 } 746 return $thumbnailArray; 747 } else { 748 return array(); 749 } 750 } 751 752 /** 753 * Gets the URL of the flash player SWF. null is returned if the 754 * duration value is not available. 755 * 756 * @return string|null The URL of the flash player SWF 757 */ 758 public function getFlashPlayerUrl() 759 { 760 $this->ensureMediaGroupIsNotNull(); 761 foreach ($this->getMediaGroup()->getContent() as $content) { 762 if ($content->getType() === 'application/x-shockwave-flash') { 763 return $content->getUrl(); 764 } 765 } 766 return null; 767 } 768 769 /** 770 * Gets the duration of the video, in seconds. null is returned 771 * if the duration value is not available. 772 * 773 * @return string|null The duration of the video, in seconds. 774 */ 775 public function getVideoDuration() 776 { 777 $this->ensureMediaGroupIsNotNull(); 778 if ($this->getMediaGroup()->getDuration() != null) { 779 return $this->getMediaGroup()->getDuration()->getSeconds(); 780 } else { 781 return null; 782 } 783 } 784 785 /** 786 * Checks whether the video is private. 787 * 788 * @return bool Return true if video is private 789 */ 790 public function isVideoPrivate() 791 { 792 $this->ensureMediaGroupIsNotNull(); 793 if ($this->getMediaGroup()->getPrivate() != null) { 794 return true; 795 } else { 796 return false; 797 } 798 } 799 800 /** 801 * Sets video to private. 802 * 803 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 804 */ 805 public function setVideoPrivate() 806 { 807 $this->ensureMediaGroupIsNotNull(); 808 $this->getMediaGroup()->setPrivate(new Zend_Gdata_YouTube_Extension_Private()); 809 return $this; 810 } 811 812 /** 813 * Sets a private video to be public. 814 * 815 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 816 */ 817 public function setVideoPublic() 818 { 819 $this->ensureMediaGroupIsNotNull(); 820 $this->getMediaGroup()->private = null; 821 return $this; 822 } 823 824 /** 825 * Gets an array of the tags assigned to this video. For convient 826 * usage inside a foreach loop, an empty array is returned when there 827 * are no tags assigned. 828 * 829 * @return array An array of the tags assigned to this video 830 */ 831 public function getVideoTags() 832 { 833 $this->ensureMediaGroupIsNotNull(); 834 if ($this->getMediaGroup()->getKeywords() != null) { 835 836 $keywords = $this->getMediaGroup()->getKeywords(); 837 $keywordsString = $keywords->getText(); 838 if (strlen(trim($keywordsString)) > 0) { 839 return preg_split('/(, *)|,/', $keywordsString); 840 } 841 } 842 return array(); 843 } 844 845 /** 846 * Sets the keyword tags for a video. 847 * 848 * @param mixed $tags Either a comma-separated string or an array 849 * of tags for the video 850 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 851 */ 852 public function setVideoTags($tags) 853 { 854 $this->ensureMediaGroupIsNotNull(); 855 $keywords = new Zend_Gdata_Media_Extension_MediaKeywords(); 856 if (is_array($tags)) { 857 $tags = implode(', ', $tags); 858 } 859 $keywords->setText($tags); 860 $this->getMediaGroup()->setKeywords($keywords); 861 return $this; 862 } 863 864 /** 865 * Gets the number of views for this video. null is returned if the 866 * number of views is not available. 867 * 868 * @return string|null The number of views for this video 869 */ 870 public function getVideoViewCount() 871 { 872 if ($this->getStatistics() != null) { 873 return $this->getStatistics()->getViewCount(); 874 } else { 875 return null; 876 } 877 } 878 879 /** 880 * Gets the location specified for this video, if available. The location 881 * is returned as an array containing the keys 'longitude' and 'latitude'. 882 * null is returned if the location is not available. 883 * 884 * @return array|null The location specified for this video 885 */ 886 public function getVideoGeoLocation() 887 { 888 if ($this->getWhere() != null && 889 $this->getWhere()->getPoint() != null && 890 ($position = $this->getWhere()->getPoint()->getPos()) != null) { 891 892 $positionString = $position->__toString(); 893 894 if (strlen(trim($positionString)) > 0) { 895 $positionArray = explode(' ', trim($positionString)); 896 if (count($positionArray) == 2) { 897 $returnArray = array(); 898 $returnArray['latitude'] = $positionArray[0]; 899 $returnArray['longitude'] = $positionArray[1]; 900 return $returnArray; 901 } 902 } 903 } 904 return null; 905 } 906 907 /** 908 * Gets the rating information for this video, if available. The rating 909 * is returned as an array containing the keys 'average' and 'numRaters'. 910 * null is returned if the rating information is not available. 911 * 912 * @return array|null The rating information for this video 913 */ 914 public function getVideoRatingInfo() 915 { 916 if ($this->getRating() != null) { 917 $returnArray = array(); 918 $returnArray['average'] = $this->getRating()->getAverage(); 919 $returnArray['numRaters'] = $this->getRating()->getNumRaters(); 920 return $returnArray; 921 } else { 922 return null; 923 } 924 } 925 926 /** 927 * Gets the category of this video, if available. The category is returned 928 * as a string. Valid categories are found at: 929 * http://gdata.youtube.com/schemas/2007/categories.cat 930 * If the category is not set, null is returned. 931 * 932 * @return string|null The category of this video 933 */ 934 public function getVideoCategory() 935 { 936 $this->ensureMediaGroupIsNotNull(); 937 $categories = $this->getMediaGroup()->getCategory(); 938 if ($categories != null) { 939 foreach($categories as $category) { 940 if ($category->getScheme() == self::YOUTUBE_CATEGORY_SCHEMA) { 941 return $category->getText(); 942 } 943 } 944 } 945 return null; 946 } 947 948 /** 949 * Sets the category of the video as a string. 950 * 951 * @param string $category Categories for the video 952 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 953 */ 954 public function setVideoCategory($category) 955 { 956 $this->ensureMediaGroupIsNotNull(); 957 $this->getMediaGroup()->setCategory(array(new Zend_Gdata_Media_Extension_MediaCategory($category, self::YOUTUBE_CATEGORY_SCHEMA))); 958 return $this; 959 } 960 961 /** 962 * Gets the developer tags for the video, if available and if client is 963 * authenticated with a valid developerKey. The tags are returned 964 * as an array. 965 * If no tags are set, null is returned. 966 * 967 * @return array|null The developer tags for this video or null if none were set. 968 */ 969 public function getVideoDeveloperTags() 970 { 971 $developerTags = null; 972 $this->ensureMediaGroupIsNotNull(); 973 974 $categoryArray = $this->getMediaGroup()->getCategory(); 975 if ($categoryArray != null) { 976 foreach ($categoryArray as $category) { 977 if ($category instanceof Zend_Gdata_Media_Extension_MediaCategory) { 978 if ($category->getScheme() == self::YOUTUBE_DEVELOPER_TAGS_SCHEMA) { 979 $developerTags[] = $category->getText(); 980 } 981 } 982 } 983 return $developerTags; 984 } 985 return null; 986 } 987 988 /** 989 * Adds a developer tag to array of tags for the video. 990 * 991 * @param string $developerTag DeveloperTag for the video 992 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 993 */ 994 public function addVideoDeveloperTag($developerTag) 995 { 996 $this->ensureMediaGroupIsNotNull(); 997 $newCategory = new Zend_Gdata_Media_Extension_MediaCategory($developerTag, self::YOUTUBE_DEVELOPER_TAGS_SCHEMA); 998 999 if ($this->getMediaGroup()->getCategory() == null) { 1000 $this->getMediaGroup()->setCategory($newCategory); 1001 } else { 1002 $categories = $this->getMediaGroup()->getCategory(); 1003 $categories[] = $newCategory; 1004 $this->getMediaGroup()->setCategory($categories); 1005 } 1006 return $this; 1007 } 1008 1009 /** 1010 * Set multiple developer tags for the video as strings. 1011 * 1012 * @param array $developerTags Array of developerTag for the video 1013 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface 1014 */ 1015 public function setVideoDeveloperTags($developerTags) 1016 { 1017 foreach($developerTags as $developerTag) { 1018 $this->addVideoDeveloperTag($developerTag); 1019 } 1020 return $this; 1021 } 1022 1023 1024 /** 1025 * Get the current publishing state of the video. 1026 * 1027 * @return Zend_Gdata_YouTube_Extension_State|null The publishing state of this video 1028 */ 1029 public function getVideoState() 1030 { 1031 $control = $this->getControl(); 1032 if ($control != null && 1033 $control->getDraft() != null && 1034 $control->getDraft()->getText() == 'yes') { 1035 1036 return $control->getState(); 1037 } 1038 return null; 1039 } 1040 1041 /** 1042 * Get the VideoEntry's Zend_Gdata_YouTube_Extension_MediaGroup object. 1043 * If the mediaGroup does not exist, then set it. 1044 * 1045 * @return void 1046 */ 1047 public function ensureMediaGroupIsNotNull() 1048 { 1049 if ($this->getMediagroup() == null) { 1050 $this->setMediagroup(new Zend_Gdata_YouTube_Extension_MediaGroup()); 1051 } 1052 } 1053 1054 /** 1055 * Helper function to conveniently set a video's rating. 1056 * 1057 * @param integer $ratingValue A number representing the rating. Must 1058 * be between 1 and 5 inclusive. 1059 * @throws Zend_Gdata_Exception 1060 * @return Zend_Gdata_YouTube_VideoEntry Provides a fluent interface. 1061 */ 1062 public function setVideoRating($ratingValue) 1063 { 1064 if ($ratingValue < 1 || $ratingValue > 5) { 1065 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 1066 throw new Zend_Gdata_App_InvalidArgumentException( 1067 'Rating for video entry must be between 1 and 5 inclusive.'); 1068 } 1069 1070 require_once 'Zend/Gdata/Extension/Rating.php'; 1071 $rating = new Zend_Gdata_Extension_Rating(null, 1, 5, null, 1072 $ratingValue); 1073 $this->setRating($rating); 1074 return $this; 1075 } 1076 1077 /** 1078 * Retrieve the URL for a video's comment feed. 1079 * 1080 * @return string|null The URL if found, or null if not found. 1081 */ 1082 public function getVideoCommentFeedUrl() 1083 { 1084 $commentsExtension = $this->getComments(); 1085 $commentsFeedUrl = null; 1086 if ($commentsExtension) { 1087 $commentsFeedLink = $commentsExtension->getFeedLink(); 1088 if ($commentsFeedLink) { 1089 $commentsFeedUrl = $commentsFeedLink->getHref(); 1090 } 1091 } 1092 return $commentsFeedUrl; 1093 } 1094 1095 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |