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