-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvimeo_source.php
More file actions
246 lines (229 loc) · 6.29 KB
/
vimeo_source.php
File metadata and controls
246 lines (229 loc) · 6.29 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
/**
* Vimeo Datasource 0.2
*
* Vimeo datasource to communicate with the Vimeo Simple API (Advanced on the way...)
* Also utilizes the Vimeo oEmbed API for generating embed code.
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
*
* @author Jon (pointlessjon) Adams <jon@anti-gen.com>
* @copyright (c) n/a
* @link http://github.com/pointlessjon/CakePHP-Vimeo-Datasource/tree/master
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @created May 7, 2009
* @updated June 18, 2009
* @version 0.1 *
*/
App::import('Core', array('HttpSocket'));
class VimeoSource extends DataSource {
var $description = 'Vimeo Simple API';
var $Http = null;
var $allowedRequests = array(
'user' => array(
'info',
'clips',
'likes',
'appears_in',
'all_clips',
'subscriptions',
'albums',
'channels',
'groups',
'contacts_clips',
'contacts_like'
),
'activity' => array(
'user_did',
'happened_to_user',
'contacts_did',
'happened_to_contacts',
'everyone_did'
),
'group' => array(
'clips',
'users',
'info'
),
'channel' => array(
'clips',
'info'
),
'album' => array(
'clips',
'info'
)
);
/**
* Constructor sets configuration and instantiates HttpSocket
*
* @param array config Optional.
* @see http://www.vimeo.com/api/docs/simple-api
*/
function __construct($config = null) {
parent::__construct($config);
$this->Http =& new HttpSocket();
Cache::config('vimeo', array('engine' => 'File', 'duration'=> '+1 days', 'path' => CACHE . DS . 'vimeo' . DS,'prefix' => 'vimeo_cache_'));
}
/**
* Shortcut to retrieve only the embed code of the oembed object for a specific video.
*
* @param string videoId Required.
* @param array options Optional.
* @see http://www.vimeo.com/api/docs/oembed
*/
function embed($videoId = null, $options = null) {
if (!empty($videoId)) {
$_oembed = $this->oembed($videoId, $options);
return $_oembed->html;
}
return false;
}
/**
* Retrieve oembed object for a specific video
*
* @param string videoId Required.
* @param array options Optional.
* @see http://www.vimeo.com/api/docs/oembed
*/
function oembed($videoId = null, $options = null) {
if (!empty($videoId)) {
$request = "http://vimeo.com/api/oembed.json?url=http://vimeo.com/{$videoId}";
if (!empty($options)) {
foreach ($options as $key => $value) {
$request .= "&{$key}={$value}";
}
}
if ($cached = $this->_getCache($request)) {
// keep it going...
} else {
$response = $this->Http->get($request);
$data = json_decode($response);
$cached = $this->_createCache($request, $data);
}
return $cached;
}
return false;
}
/**
* Retrieve data about a specific video
*
* @param string videoId Required.
* @see http://www.vimeo.com/api/docs/simple-api
*/
function video($videoId = null) {
if (!empty($videoId)) {
return $this->__vimeoApiRequest("clip/{$videoId}");
}
return false;
}
/**
* Retrieve data for a specific user
*
* @param string username Required.
* @param string request Required. See allowed requests in api documentation
* @see http://www.vimeo.com/api/docs/simple-api
*/
function userRequest($username = null, $request = null) {
if (!empty($username) && !empty($request)) {
if (in_array($request, $this->allowedRequests['user'])) {
return $this->__vimeoApiRequest("{$username}/{$request}");
}
}
return false;
}
/**
* Retrieve activity data for a specific user
*
* @param string username Required.
* @param string request Required. See allowed requests in api documentation
* @see http://www.vimeo.com/api/docs/simple-api
*/
function activityRequest($username = null, $request = null) {
if (!empty($username) && !empty($request)) {
if (in_array($request, $this->allowedRequests['activity'])) {
return $this->__vimeoApiRequest("activity/{$username}/{$request}");
}
}
return false;
}
/**
* Retrieve data for a specific group
*
* @param string groupname Required.
* @param string request Required. See allowed requests in api documentation
* @see http://www.vimeo.com/api/docs/simple-api
*/
function groupRequest($groupname = null, $request = null) {
if (!empty($groupname) && !empty($request)) {
if (in_array($request, $this->allowedRequests['group'])) {
return $this->__vimeoApiRequest("group/{$groupname}/{$request}");
}
}
return false;
}
/**
* Retrieve data for a specific channel
*
* @param string channelname Required.
* @param string request Required. See allowed requests in api documentation
* @see http://www.vimeo.com/api/docs/simple-api
*/
function channelRequest($channelname = null, $request = null) {
if (!empty($channelname) && !empty($request)) {
if (in_array($request, $this->allowedRequests['channel'])) {
return $this->__vimeoApiRequest("channel/{$channelname}/{$request}");
}
}
return false;
}
/**
* Retrieve data for a specific album
*
* @param string albumname Required.
* @param string request Required. See allowed requests in api documentation
* @see http://www.vimeo.com/api/docs/simple-api
*/
function albumRequest($albumname = null, $request = null) {
if (!empty($albumname) && !empty($request)) {
if (in_array($request, $this->allowedRequests['album'])) {
return $this->__vimeoApiRequest("album/{$albumname}/{$request}");
}
}
return false;
}
/**
* Internal function to make the requests to the Vimeo Simple API
*
* @param string data Required.
* @see http://www.vimeo.com/api/docs/simple-api
*/
function __vimeoApiRequest($request = null) {
if (!empty($request)) {
$request = "http://vimeo.com/api/{$request}.php";
if ($cached = $this->_getCache($request)) {
// keep it going...
} else {
$data = unserialize($this->Http->get($request, null));
$cached = $this->_createCache($request, $data);
}
return $cached;
}
return false;
}
function _getCache($request = null) {
return Cache::read($this->_requestToCacheKey($request), 'vimeo');
}
function _createCache($request = null, $data = null) {
if (!empty($request) && !empty($data)) {
Cache::write($this->_requestToCacheKey($request), $data, 'vimeo');
}
return $data;
}
function _requestToCacheKey($request = null) {
return md5($request);
}
}
?>