PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/src/application/libraries/Zend/Gdata/YouTube/VideoEntry.php

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