PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/public/zf-demos/Zend/Gdata/YouTubeVideoApp/index.php

https://bitbucket.org/hieronim1981/tunethemusic
PHP | 193 lines | 128 code | 7 blank | 58 comment | 7 complexity | c2a5238c82b4f8129b717df3b56b6995 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. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * PHP sample code for the YouTube data API. Utilizes the Zend Framework
  22. * Zend_Gdata component to communicate with the YouTube data API.
  23. *
  24. * Requires the Zend Framework Zend_Gdata component and PHP >= 5.1.4
  25. * This sample is run from within a web browser. These files are required:
  26. * session_details.php - a script to view log output and session variables
  27. * operations.php - the main logic, which interfaces with the YouTube API
  28. * index.php - the HTML to represent the web UI, contains some PHP
  29. * video_app.css - the CSS to define the interface style
  30. * video_app.js - the JavaScript used to provide the video list AJAX interface
  31. *
  32. * NOTE: If using in production, some additional precautions with regards
  33. * to filtering the input data should be used. This code is designed only
  34. * for demonstration purposes.
  35. */
  36. session_start();
  37. /**
  38. * Set your developer key here.
  39. *
  40. * NOTE: In a production application you may want to store this information in
  41. * an external file.
  42. */
  43. $_SESSION['developerKey'] = '<YOUR DEVELOPER KEY>';
  44. /**
  45. * Convert HTTP status into normal text.
  46. *
  47. * @param number $status HTTP status received after posting syndicated upload
  48. * @param string $code Alphanumeric description of error
  49. * @param string $videoId (optional) Video id received back to which the status
  50. * code refers to
  51. */
  52. function uploadStatus($status, $code = null, $videoId = null)
  53. {
  54. switch ($status) {
  55. case $status < 400:
  56. echo 'Success ! Entry created (id: '. $videoId .
  57. ') <a href="#" onclick=" ytVideoApp.checkUploadDetails(\''.
  58. $videoId .'\'); ">(check details)</a>';
  59. break;
  60. default:
  61. echo 'There seems to have been an error: '. $code .
  62. '<a href="#" onclick=" ytVideoApp.checkUploadDetails(\''.
  63. $videoId . '\'); ">(check details)</a>';
  64. }
  65. }
  66. /**
  67. * Helper function to check whether a session token has been set
  68. *
  69. * @return boolean Returns true if a session token has been set
  70. */
  71. function authenticated()
  72. {
  73. if (isset($_SESSION['sessionToken'])) {
  74. return true;
  75. }
  76. }
  77. /**
  78. * Helper function to print a list of authenticated actions for a user.
  79. */
  80. function printAuthenticatedActions()
  81. {
  82. print <<<END
  83. <div id="actions"><h3>Authenticated Actions</h3>
  84. <ul>
  85. <li><a href="#" onclick="ytVideoApp.listVideos('search_owner', '', 1);
  86. return false;">retrieve my videos</a></li>
  87. <li><a href="#" onclick="ytVideoApp.prepareUploadForm();
  88. return false;">upload a video</a><br />
  89. <div id="syndicatedUploadDiv"></div><div id="syndicatedUploadStatusDiv">
  90. </div></li>
  91. <li><a href="#" onclick="ytVideoApp.retrievePlaylists();
  92. return false;">manage my playlists</a><br /></li>
  93. </ul></div>
  94. END;
  95. }
  96. ?>
  97. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  98. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  99. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  100. <head>
  101. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  102. <title>YouTube data API Video Browser in PHP</title>
  103. <link href="video_app.css" type="text/css" rel="stylesheet" />
  104. <script src="video_app.js" type="text/javascript"></script>
  105. </head>
  106. <body>
  107. <div id="main">
  108. <div id="titleBar">
  109. <h2>YouTube data API Video App in PHP</h2>
  110. <a href="session_details.php">click to examine session variables</a><br/>
  111. <div id="searchBox">
  112. <form id="searchForm" onsubmit="ytVideoApp.listVideos(this.queryType.value, this.searchTerm.value, 1); return false;" action="javascript:void();" >
  113. <div id="searchBoxTop"><select name="queryType" onchange="ytVideoApp.queryTypeChanged(this.value, this.form.searchTerm);" >
  114. <option value="search_all" selected="selected">All Videos</option>
  115. <option value="search_top_rated">Top Rated Videos</option>
  116. <option value="search_most_viewed">Most Viewed Videos</option>
  117. <option value="search_recently_featured">Recently Featured Videos</option>
  118. <option value="search_username">Videos from a specific user</option>
  119. <?php
  120. if (authenticated()) {
  121. echo '<option value="search_owner">Display my videos</option>';
  122. }
  123. ?>
  124. </select></div>
  125. <div><input name="searchTerm" type="text" value="YouTube Data API" />
  126. <input type="submit" value="Search" /></div>
  127. </form>
  128. </div>
  129. <br />
  130. </div>
  131. <br />
  132. <!-- Authentication status -->
  133. <div id="authStatus">Authentication status:
  134. <?php
  135. if (authenticated()) {
  136. print <<<END
  137. authenticated <br />
  138. END;
  139. } else {
  140. print <<<END
  141. <div id="generateAuthSubLink"><a href="#"
  142. onclick="ytVideoApp.presentAuthLink();
  143. return false;">Click here to generate authentication link</a>
  144. </div>
  145. END;
  146. }
  147. ?>
  148. </div>
  149. <!-- end Authentication status -->
  150. <br clear="all" />
  151. <?php
  152. // if $_GET['status'] is populated then we have a response
  153. // about a syndicated upload from YouTube's servers
  154. if (isset($_GET['status'])) {
  155. (isset($_GET['code']) ? $code = $_GET['code'] : $code = null);
  156. (isset($_GET['id']) ? $id = $_GET['id'] : $id = null);
  157. print '<div id="generalStatus">' .
  158. uploadStatus($_GET['status'], $code, $id) .
  159. '<div id="detailedUploadStatus"></div></div>';
  160. }
  161. ?>
  162. <!-- General status -->
  163. <?php
  164. if (authenticated()) {
  165. printAuthenticatedActions();
  166. }
  167. ?>
  168. <!-- end General status -->
  169. <br clear="all" />
  170. <div id="searchResults">
  171. <div id="searchResultsListColumn">
  172. <div id="searchResultsVideoList"></div>
  173. <div id="searchResultsNavigation">
  174. <form id="navigationForm" action="javascript:void();">
  175. <input type="button" id="previousPageButton" onclick="ytVideoApp.listVideos(ytVideoApp.previousQueryType, ytVideoApp.previousSearchTerm, ytVideoApp.previousPage);" value="Back" style="display: none;" />
  176. <input type="button" id="nextPageButton" onclick="ytVideoApp.listVideos(ytVideoApp.previousQueryType, ytVideoApp.previousSearchTerm, ytVideoApp.nextPage);" value="Next" style="display: none;" />
  177. </form>
  178. </div>
  179. </div>
  180. <div id="searchResultsVideoColumn">
  181. <div id="videoPlayer"></div>
  182. </div>
  183. </div>
  184. </div>
  185. </body>
  186. </html>