Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/zend/Zend/Gdata/YouTube/VideoEntry.php
Go to the documentation of this file.
00001 <?php
00002 
00027 require_once 'Zend/Gdata/Extension/Comments.php';
00028 
00032 require_once 'Zend/Gdata/Extension/FeedLink.php';
00033 
00037 require_once 'Zend/Gdata/YouTube/MediaEntry.php';
00038 
00042 require_once 'Zend/Gdata/YouTube/Extension/MediaGroup.php';
00043 
00047 require_once 'Zend/Gdata/YouTube/Extension/NoEmbed.php';
00048 
00052 require_once 'Zend/Gdata/YouTube/Extension/Statistics.php';
00053 
00057 require_once 'Zend/Gdata/YouTube/Extension/Link.php';
00058 
00062 require_once 'Zend/Gdata/YouTube/Extension/Racy.php';
00063 
00067 require_once 'Zend/Gdata/Extension/Rating.php';
00068 
00072 require_once 'Zend/Gdata/Geo/Extension/GeoRssWhere.php';
00073 
00077 require_once 'Zend/Gdata/YouTube/Extension/Control.php';
00078 
00082 require_once 'Zend/Gdata/YouTube/Extension/Recorded.php';
00083 
00087 require_once 'Zend/Gdata/YouTube/Extension/Location.php';
00088 
00098 class Zend_Gdata_YouTube_VideoEntry extends Zend_Gdata_YouTube_MediaEntry
00099 {
00100 
00101     const YOUTUBE_DEVELOPER_TAGS_SCHEMA = 'http://gdata.youtube.com/schemas/2007/developertags.cat';
00102     const YOUTUBE_CATEGORY_SCHEMA = 'http://gdata.youtube.com/schemas/2007/categories.cat';
00103     protected $_entryClassName = 'Zend_Gdata_YouTube_VideoEntry';
00104 
00110     protected $_noEmbed = null;
00111 
00117     protected $_statistics = null;
00118 
00124     protected $_racy = null;
00125 
00131     protected $_private = null;
00132 
00138     protected $_rating = null;
00139 
00145     protected $_comments = null;
00146 
00152     protected $_feedLink = array();
00153 
00159     protected $_where = null;
00160 
00166     protected $_recorded = null;
00167 
00173     protected $_location = null;
00174 
00181     public function __construct($element = null)
00182     {
00183         $this->registerAllNamespaces(Zend_Gdata_YouTube::$namespaces);
00184         parent::__construct($element);
00185     }
00186 
00197     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
00198     {
00199         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
00200         if ($this->_noEmbed != null) {
00201             $element->appendChild($this->_noEmbed->getDOM(
00202                 $element->ownerDocument));
00203         }
00204         if ($this->_statistics != null) {
00205             $element->appendChild($this->_statistics->getDOM(
00206                 $element->ownerDocument));
00207         }
00208         if ($this->_racy != null) {
00209             $element->appendChild($this->_racy->getDOM(
00210                 $element->ownerDocument));
00211         }
00212         if ($this->_recorded != null) {
00213             $element->appendChild($this->_recorded->getDOM(
00214                 $element->ownerDocument));
00215         }
00216         if ($this->_location != null) {
00217             $element->appendChild($this->_location->getDOM(
00218                 $element->ownerDocument));
00219         }
00220         if ($this->_rating != null) {
00221             $element->appendChild($this->_rating->getDOM(
00222                 $element->ownerDocument));
00223         }
00224         if ($this->_comments != null) {
00225             $element->appendChild($this->_comments->getDOM(
00226                 $element->ownerDocument));
00227         }
00228         if ($this->_feedLink != null) {
00229             foreach ($this->_feedLink as $feedLink) {
00230                 $element->appendChild($feedLink->getDOM(
00231                     $element->ownerDocument));
00232             }
00233         }
00234         if ($this->_where != null) {
00235            $element->appendChild($this->_where->getDOM(
00236                 $element->ownerDocument));
00237         }
00238         return $element;
00239     }
00240 
00247     protected function takeChildFromDOM($child)
00248     {
00249         $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
00250 
00251         switch ($absoluteNodeName) {
00252         case $this->lookupNamespace('yt') . ':' . 'statistics':
00253             $statistics = new Zend_Gdata_YouTube_Extension_Statistics();
00254             $statistics->transferFromDOM($child);
00255             $this->_statistics = $statistics;
00256             break;
00257         case $this->lookupNamespace('yt') . ':' . 'racy':
00258             $racy = new Zend_Gdata_YouTube_Extension_Racy();
00259             $racy->transferFromDOM($child);
00260             $this->_racy = $racy;
00261             break;
00262         case $this->lookupNamespace('yt') . ':' . 'recorded':
00263             $recorded = new Zend_Gdata_YouTube_Extension_Recorded();
00264             $recorded->transferFromDOM($child);
00265             $this->_recorded = $recorded;
00266             break;
00267         case $this->lookupNamespace('yt') . ':' . 'location':
00268             $location = new Zend_Gdata_YouTube_Extension_Location();
00269             $location->transferFromDOM($child);
00270             $this->_location = $location;
00271             break;
00272         case $this->lookupNamespace('gd') . ':' . 'rating':
00273             $rating = new Zend_Gdata_Extension_Rating();
00274             $rating->transferFromDOM($child);
00275             $this->_rating = $rating;
00276             break;
00277         case $this->lookupNamespace('gd') . ':' . 'comments':
00278             $comments = new Zend_Gdata_Extension_Comments();
00279             $comments->transferFromDOM($child);
00280             $this->_comments = $comments;
00281             break;
00282         case $this->lookupNamespace('yt') . ':' . 'noembed':
00283             $noEmbed = new Zend_Gdata_YouTube_Extension_NoEmbed();
00284             $noEmbed->transferFromDOM($child);
00285             $this->_noEmbed = $noEmbed;
00286             break;
00287         case $this->lookupNamespace('gd') . ':' . 'feedLink':
00288             $feedLink = new Zend_Gdata_Extension_FeedLink();
00289             $feedLink->transferFromDOM($child);
00290             $this->_feedLink[] = $feedLink;
00291             break;
00292         case $this->lookupNamespace('georss') . ':' . 'where':
00293             $where = new Zend_Gdata_Geo_Extension_GeoRssWhere();
00294             $where->transferFromDOM($child);
00295             $this->_where = $where;
00296             break;
00297         case $this->lookupNamespace('atom') . ':' . 'link';
00298             $link = new Zend_Gdata_YouTube_Extension_Link();
00299             $link->transferFromDOM($child);
00300             $this->_link[] = $link;
00301             break;
00302         case $this->lookupNamespace('app') . ':' . 'control':
00303             $control = new Zend_Gdata_YouTube_Extension_Control();
00304             $control->transferFromDOM($child);
00305             $this->_control = $control;
00306             break;
00307         default:
00308             parent::takeChildFromDOM($child);
00309             break;
00310         }
00311     }
00312 
00319     public function setRecorded($recorded = null)
00320     {
00321         $this->_recorded = $recorded;
00322         return $this;
00323     }
00324 
00330     public function getRecorded()
00331     {
00332         return $this->_recorded;
00333     }
00334 
00342     public function setLocation($location = null)
00343     {
00344         $this->_location = $location;
00345         return $this;
00346     }
00347 
00353     public function getLocation()
00354     {
00355         return $this->_location;
00356     }
00357 
00367     public function setNoEmbed($noEmbed = null)
00368     {
00369         $this->_noEmbed = $noEmbed;
00370         return $this;
00371     }
00372 
00379     public function getNoEmbed()
00380     {
00381         return $this->_noEmbed;
00382     }
00383 
00389     public function isVideoEmbeddable()
00390     {
00391         if ($this->getNoEmbed() == null) {
00392             return true;
00393         } else {
00394             return false;
00395         }
00396     }
00397 
00404     public function setStatistics($statistics = null)
00405     {
00406         $this->_statistics = $statistics;
00407         return $this;
00408     }
00409 
00415     public function getStatistics()
00416     {
00417         return $this->_statistics;
00418     }
00419 
00427     public function setRacy($racy = null)
00428     {
00429         if ($this->getMajorProtocolVersion() == 2) {
00430             require_once 'Zend/Gdata/App/VersionException.php';
00431             throw new Zend_Gdata_App_VersionException(
00432                 'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
00433                 'as of version 2 of the API.');
00434         }
00435 
00436         $this->_racy = $racy;
00437         return $this;
00438     }
00439 
00446     public function getRacy()
00447     {
00448         if ($this->getMajorProtocolVersion() == 2) {
00449             require_once 'Zend/Gdata/App/VersionException.php';
00450             throw new Zend_Gdata_App_VersionException(
00451                 'Calling getRacy() on a YouTube VideoEntry is deprecated ' .
00452                 'as of version 2 of the API.');
00453         }
00454         return $this->_racy;
00455     }
00456 
00463     public function setRating($rating = null)
00464     {
00465         $this->_rating = $rating;
00466         return $this;
00467     }
00468 
00474     public function getRating()
00475     {
00476         return $this->_rating;
00477     }
00478 
00485     public function setComments($comments = null)
00486     {
00487         $this->_comments = $comments;
00488         return $this;
00489     }
00490 
00496     public function getComments()
00497     {
00498         return $this->_comments;
00499     }
00500 
00507     public function setFeedLink($feedLink = null)
00508     {
00509         $this->_feedLink = $feedLink;
00510         return $this;
00511     }
00512 
00526     public function getFeedLink($rel = null)
00527     {
00528         if ($rel == null) {
00529             return $this->_feedLink;
00530         } else {
00531             foreach ($this->_feedLink as $feedLink) {
00532                 if ($feedLink->rel == $rel) {
00533                     return $feedLink;
00534                 }
00535             }
00536             return null;
00537         }
00538     }
00539 
00545     public function getVideoResponsesLink()
00546     {
00547         return $this->getLink(Zend_Gdata_YouTube::VIDEO_RESPONSES_REL);
00548     }
00549 
00555     public function getVideoRatingsLink()
00556     {
00557         return $this->getLink(Zend_Gdata_YouTube::VIDEO_RATINGS_REL);
00558     }
00559 
00565     public function getVideoComplaintsLink()
00566     {
00567         return $this->getLink(Zend_Gdata_YouTube::VIDEO_COMPLAINTS_REL);
00568     }
00569 
00575     public function getVideoId()
00576     {
00577         if ($this->getMajorProtocolVersion() == 2) {
00578             $videoId = $this->getMediaGroup()->getVideoId()->text;
00579         } else {
00580             $fullId = $this->getId()->getText();
00581             $position = strrpos($fullId, '/');
00582             if ($position === false) {
00583                 require_once 'Zend/Gdata/App/Exception.php';
00584                 throw new Zend_Gdata_App_Exception(
00585                     'Slash not found in atom:id of ' . $fullId);
00586             } else {
00587                 $videoId = substr($fullId, $position + 1);
00588             }
00589         }
00590         return $videoId;
00591     }
00592 
00598     public function getVideoRecorded()
00599     {
00600         $recorded = $this->getRecorded();
00601         if ($recorded != null) {
00602           return $recorded->getText();
00603         } else {
00604           return null;
00605         }
00606     }
00607 
00614     public function setVideoRecorded($recorded)
00615     {
00616         $this->setRecorded(
00617             new Zend_Gdata_YouTube_Extension_Recorded($recorded));
00618         return $this;
00619     }
00620 
00626     public function getWhere()
00627     {
00628         return $this->_where;
00629     }
00630 
00637     public function setWhere($value)
00638     {
00639         $this->_where = $value;
00640         return $this;
00641     }
00642 
00649     public function getVideoTitle()
00650     {
00651         $this->ensureMediaGroupIsNotNull();
00652         if ($this->getMediaGroup()->getTitle() != null) {
00653             return $this->getMediaGroup()->getTitle()->getText();
00654         } else {
00655             return null;
00656         }
00657     }
00658 
00665     public function setVideoTitle($title)
00666     {
00667         $this->ensureMediaGroupIsNotNull();
00668         $this->getMediaGroup()->setTitle(
00669             new Zend_Gdata_Media_Extension_MediaTitle($title));
00670         return $this;
00671     }
00672 
00679     public function setVideoDescription($description)
00680     {
00681         $this->ensureMediaGroupIsNotNull();
00682         $this->getMediaGroup()->setDescription(
00683             new Zend_Gdata_Media_Extension_MediaDescription($description));
00684         return $this;
00685     }
00686 
00687 
00694     public function getVideoDescription()
00695     {
00696         $this->ensureMediaGroupIsNotNull();
00697         if ($this->getMediaGroup()->getDescription() != null) {
00698             return $this->getMediaGroup()->getDescription()->getText();
00699         } else {
00700             return null;
00701         }
00702     }
00703 
00710     public function getVideoWatchPageUrl()
00711     {
00712         $this->ensureMediaGroupIsNotNull();
00713         if ($this->getMediaGroup()->getPlayer() != null &&
00714              array_key_exists(0, $this->getMediaGroup()->getPlayer())) {
00715             $players = $this->getMediaGroup()->getPlayer();
00716             return $players[0]->getUrl();
00717         } else {
00718             return null;
00719         }
00720     }
00721 
00731     public function getVideoThumbnails()
00732     {
00733         $this->ensureMediaGroupIsNotNull();
00734         if ($this->getMediaGroup()->getThumbnail() != null) {
00735 
00736             $thumbnailArray = array();
00737 
00738             foreach ($this->getMediaGroup()->getThumbnail() as $thumbnailObj) {
00739                 $thumbnail = array();
00740                 $thumbnail['time'] = $thumbnailObj->time;
00741                 $thumbnail['height'] = $thumbnailObj->height;
00742                 $thumbnail['width'] = $thumbnailObj->width;
00743                 $thumbnail['url'] = $thumbnailObj->url;
00744                 $thumbnailArray[] = $thumbnail;
00745             }
00746             return $thumbnailArray;
00747         } else {
00748             return array();
00749         }
00750     }
00751 
00758     public function getFlashPlayerUrl()
00759     {
00760         $this->ensureMediaGroupIsNotNull();
00761         foreach ($this->getMediaGroup()->getContent() as $content) {
00762                 if ($content->getType() === 'application/x-shockwave-flash') {
00763                     return $content->getUrl();
00764                 }
00765             }
00766         return null;
00767     }
00768 
00775     public function getVideoDuration()
00776     {
00777         $this->ensureMediaGroupIsNotNull();
00778         if ($this->getMediaGroup()->getDuration() != null) {
00779             return $this->getMediaGroup()->getDuration()->getSeconds();
00780         } else {
00781             return null;
00782         }
00783     }
00784 
00790     public function isVideoPrivate()
00791     {
00792         $this->ensureMediaGroupIsNotNull();
00793         if ($this->getMediaGroup()->getPrivate() != null) {
00794             return true;
00795         } else {
00796             return false;
00797         }
00798     }
00799 
00805     public function setVideoPrivate()
00806     {
00807         $this->ensureMediaGroupIsNotNull();
00808         $this->getMediaGroup()->setPrivate(new Zend_Gdata_YouTube_Extension_Private());
00809         return $this;
00810     }
00811 
00817     public function setVideoPublic()
00818     {
00819         $this->ensureMediaGroupIsNotNull();
00820         $this->getMediaGroup()->private = null;
00821         return $this;
00822     }
00823 
00831     public function getVideoTags()
00832     {
00833         $this->ensureMediaGroupIsNotNull();
00834         if ($this->getMediaGroup()->getKeywords() != null) {
00835 
00836             $keywords = $this->getMediaGroup()->getKeywords();
00837             $keywordsString = $keywords->getText();
00838             if (strlen(trim($keywordsString)) > 0) {
00839                 return preg_split('/(, *)|,/', $keywordsString);
00840             }
00841         }
00842         return array();
00843     }
00844 
00852     public function setVideoTags($tags)
00853     {
00854         $this->ensureMediaGroupIsNotNull();
00855         $keywords = new Zend_Gdata_Media_Extension_MediaKeywords();
00856         if (is_array($tags)) {
00857             $tags = implode(', ', $tags);
00858         }
00859         $keywords->setText($tags);
00860         $this->getMediaGroup()->setKeywords($keywords);
00861         return $this;
00862     }
00863 
00870     public function getVideoViewCount()
00871     {
00872         if ($this->getStatistics() != null) {
00873             return $this->getStatistics()->getViewCount();
00874         } else {
00875             return null;
00876         }
00877     }
00878 
00886     public function getVideoGeoLocation()
00887     {
00888         if ($this->getWhere() != null &&
00889             $this->getWhere()->getPoint() != null &&
00890             ($position = $this->getWhere()->getPoint()->getPos()) != null) {
00891 
00892             $positionString = $position->__toString();
00893 
00894             if (strlen(trim($positionString)) > 0) {
00895                 $positionArray = explode(' ', trim($positionString));
00896                 if (count($positionArray) == 2) {
00897                     $returnArray = array();
00898                     $returnArray['latitude'] = $positionArray[0];
00899                     $returnArray['longitude'] = $positionArray[1];
00900                     return $returnArray;
00901                 }
00902             }
00903         }
00904         return null;
00905     }
00906 
00914     public function getVideoRatingInfo()
00915     {
00916         if ($this->getRating() != null) {
00917             $returnArray = array();
00918             $returnArray['average'] = $this->getRating()->getAverage();
00919             $returnArray['numRaters'] = $this->getRating()->getNumRaters();
00920             return $returnArray;
00921         } else {
00922             return null;
00923         }
00924     }
00925 
00934     public function getVideoCategory()
00935     {
00936         $this->ensureMediaGroupIsNotNull();
00937         $categories = $this->getMediaGroup()->getCategory();
00938         if ($categories != null) {
00939             foreach($categories as $category) {
00940                 if ($category->getScheme() == self::YOUTUBE_CATEGORY_SCHEMA) {
00941                     return $category->getText();
00942                 }
00943             }
00944         }
00945         return null;
00946     }
00947 
00954     public function setVideoCategory($category)
00955     {
00956         $this->ensureMediaGroupIsNotNull();
00957         $this->getMediaGroup()->setCategory(array(new Zend_Gdata_Media_Extension_MediaCategory($category, self::YOUTUBE_CATEGORY_SCHEMA)));
00958         return $this;
00959     }
00960 
00969     public function getVideoDeveloperTags()
00970     {
00971         $developerTags = null;
00972         $this->ensureMediaGroupIsNotNull();
00973 
00974         $categoryArray = $this->getMediaGroup()->getCategory();
00975         if ($categoryArray != null) {
00976             foreach ($categoryArray as $category) {
00977                 if ($category instanceof Zend_Gdata_Media_Extension_MediaCategory) {
00978                     if ($category->getScheme() == self::YOUTUBE_DEVELOPER_TAGS_SCHEMA) {
00979                         $developerTags[] = $category->getText();
00980                     }
00981                 }
00982             }
00983             return $developerTags;
00984         }
00985         return null;
00986     }
00987 
00994     public function addVideoDeveloperTag($developerTag)
00995     {
00996         $this->ensureMediaGroupIsNotNull();
00997         $newCategory = new Zend_Gdata_Media_Extension_MediaCategory($developerTag, self::YOUTUBE_DEVELOPER_TAGS_SCHEMA);
00998 
00999         if ($this->getMediaGroup()->getCategory() == null) {
01000             $this->getMediaGroup()->setCategory($newCategory);
01001         } else {
01002             $categories = $this->getMediaGroup()->getCategory();
01003             $categories[] = $newCategory;
01004             $this->getMediaGroup()->setCategory($categories);
01005         }
01006         return $this;
01007     }
01008 
01015     public function setVideoDeveloperTags($developerTags)
01016     {
01017         foreach($developerTags as $developerTag) {
01018             $this->addVideoDeveloperTag($developerTag);
01019         }
01020         return $this;
01021     }
01022 
01023 
01029     public function getVideoState()
01030     {
01031         $control = $this->getControl();
01032         if ($control != null &&
01033             $control->getDraft() != null &&
01034             $control->getDraft()->getText() == 'yes') {
01035 
01036             return $control->getState();
01037         }
01038         return null;
01039     }
01040 
01047     public function ensureMediaGroupIsNotNull()
01048     {
01049         if ($this->getMediagroup() == null) {
01050             $this->setMediagroup(new Zend_Gdata_YouTube_Extension_MediaGroup());
01051         }
01052     }
01053 
01062     public function setVideoRating($ratingValue)
01063     {
01064         if ($ratingValue < 1 || $ratingValue > 5) {
01065             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
01066             throw new Zend_Gdata_App_InvalidArgumentException(
01067                 'Rating for video entry must be between 1 and 5 inclusive.');
01068         }
01069 
01070          require_once 'Zend/Gdata/Extension/Rating.php';
01071          $rating = new Zend_Gdata_Extension_Rating(null, 1, 5, null,
01072             $ratingValue);
01073         $this->setRating($rating);
01074         return $this;
01075     }
01076 
01082     public function getVideoCommentFeedUrl()
01083     {
01084         $commentsExtension = $this->getComments();
01085         $commentsFeedUrl = null;
01086         if ($commentsExtension) {
01087             $commentsFeedLink = $commentsExtension->getFeedLink();
01088             if ($commentsFeedLink) {
01089                 $commentsFeedUrl = $commentsFeedLink->getHref();
01090             }
01091         }
01092         return $commentsFeedUrl;
01093     }
01094 
01095 }
 All Data Structures Namespaces Files Functions Variables Enumerations