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