1 | <?php
|
---|
2 |
|
---|
3 | function vimeo_settings() {
|
---|
4 | $service_config = Array(
|
---|
5 | 'service' => "vimeo", //File with actions must be named like $service
|
---|
6 | 'service_url' => "vimeo.com",
|
---|
7 | 'username' => "email@domain.com",
|
---|
8 | 'password' => "passwd",
|
---|
9 | 'devkey' => "api_key",
|
---|
10 | 'api_secret' => "api_secret",
|
---|
11 | 'enabled' => false
|
---|
12 | );
|
---|
13 | return $service_config;
|
---|
14 | }
|
---|
15 |
|
---|
16 | function vimeo_extras() {
|
---|
17 | $extras = array('privacy'=> array( 'anybody' => 'Anybody can view the video',
|
---|
18 | 'contacts' => 'Only the the uploaders contacts can view the video',
|
---|
19 | 'nobody' => 'Only the uploader can view the video'
|
---|
20 | )
|
---|
21 | );
|
---|
22 | return $extras;
|
---|
23 | }
|
---|
24 |
|
---|
25 | function upload_vimeo($settings,$entry) {
|
---|
26 | $error = false; $retry = 0;
|
---|
27 | $upload_status = '';
|
---|
28 | $mail = $settings['username'];
|
---|
29 | $pass = $settings['password'];
|
---|
30 | $api_key = $settings['devkey'];
|
---|
31 | $api_secret = $settings['api_secret'];
|
---|
32 | $permisos = $settings['privacy'];
|
---|
33 |
|
---|
34 | $file = $entry['fileinfo'];
|
---|
35 | @set_time_limit(0);
|
---|
36 | $title = htmlentities($entry['titulo'], ENT_NOQUOTES, 'UTF-8');
|
---|
37 | $descripcion = htmlentities($entry['desc'], ENT_NOQUOTES, 'UTF-8');
|
---|
38 | $tags = htmlspecialchars(stripslashes($entry['tags']));
|
---|
39 | $cookie = tempnam (ABSPATH . get_option('upload_path') . '/', "VIMEO");
|
---|
40 | $api_login_url = "http://www.vimeo.com/log_in";
|
---|
41 | $api_rest_url = "http://www.vimeo.com/api/rest/";
|
---|
42 | $api_auth_url = "http://www.vimeo.com/services/auth/";
|
---|
43 | $api_upload_url = "http://www.vimeo.com/services/upload/";
|
---|
44 |
|
---|
45 | if($file){
|
---|
46 | #login
|
---|
47 | $args = array(
|
---|
48 | 'sign_in[email]' => $mail,
|
---|
49 | 'sign_in[password]' => $pass
|
---|
50 | );
|
---|
51 | $login = source_extract($api_login_url, $args, '', '', true, $cookie);
|
---|
52 | #frob
|
---|
53 | $args = $_args = array(
|
---|
54 | 'api_key' => $api_key,
|
---|
55 | 'perms' => 'write',
|
---|
56 | 'format' => 'php'
|
---|
57 | );
|
---|
58 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
59 | $frob = source_extract($api_auth_url, '', $args, '', true, $cookie);
|
---|
60 | if(!$frob['header']['Location']){ //si aun no fue aceptada la autorizacion
|
---|
61 | $frob = source_extract($api_auth_url, $_args, '', '', true, $cookie); #lo autorizamos por POST
|
---|
62 | $frob = source_extract($api_auth_url, '', $args, '', true, $cookie); #y pedimos el frob de nuevo
|
---|
63 | }
|
---|
64 | $frob = substr($frob['header']['Location'], strpos($frob['header']['Location'], 'frob=')+strlen('frob=') );
|
---|
65 | $frobge = $frob;
|
---|
66 | #token
|
---|
67 | $args = array(
|
---|
68 | 'api_key' => $api_key,
|
---|
69 | 'format' => 'php',
|
---|
70 | 'frob' => $frob,
|
---|
71 | 'method' => 'vimeo.auth.getToken'
|
---|
72 | );
|
---|
73 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
74 | $token = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
75 | $token = unserialize($token['content']);
|
---|
76 | $token = $token->auth->token;
|
---|
77 | #tiket
|
---|
78 | $args = array(
|
---|
79 | 'api_key' => $api_key,
|
---|
80 | 'format' => 'php',
|
---|
81 | 'frob' => $frob,
|
---|
82 | 'method' => 'vimeo.videos.getUploadTicket'
|
---|
83 | );
|
---|
84 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
85 | $tiket = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
86 | $tiket = unserialize($tiket['content']);
|
---|
87 | $tiket = $tiket->ticket->id;
|
---|
88 | #upload video
|
---|
89 | $file = array('video'=>$file);
|
---|
90 | $args = array(
|
---|
91 | 'api_key' => $api_key,
|
---|
92 | 'format' => 'php',
|
---|
93 | 'auth_token' => $token,
|
---|
94 | 'ticket_id' => $tiket
|
---|
95 | );
|
---|
96 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
97 | $upload = source_extract($api_upload_url, $args, '', $file, true, $cookie);
|
---|
98 | #check
|
---|
99 | $args = array(
|
---|
100 | 'api_key' => $api_key,
|
---|
101 | 'format' => 'php',
|
---|
102 | 'frob' => $frob,
|
---|
103 | 'method' => 'vimeo.videos.checkUploadStatus',
|
---|
104 | 'ticket_id' => $tiket
|
---|
105 | );
|
---|
106 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
107 | $check = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
108 | $check = unserialize($check['content']);
|
---|
109 | #title
|
---|
110 | $args = array(
|
---|
111 | 'api_key' => $api_key,
|
---|
112 | 'format' => 'php',
|
---|
113 | 'method' => 'vimeo.videos.setTitle',
|
---|
114 | 'title' => $title,
|
---|
115 | 'video_id' => $check->ticket->video_id,
|
---|
116 | );
|
---|
117 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
118 | $title = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
119 | $title = unserialize($title['content']);
|
---|
120 | #caption
|
---|
121 | $args = array(
|
---|
122 | 'api_key' => $api_key,
|
---|
123 | 'caption' => $descripcion,
|
---|
124 | 'format' => 'php',
|
---|
125 | 'method' => 'vimeo.videos.setCaption',
|
---|
126 | 'video_id' => $check->ticket->video_id,
|
---|
127 | );
|
---|
128 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
129 | $caption = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
130 | $caption = unserialize($caption['content']);
|
---|
131 | #tags
|
---|
132 | $args = array(
|
---|
133 | 'api_key' => $api_key,
|
---|
134 | 'format' => 'php',
|
---|
135 | 'method' => 'vimeo.videos.addTags',
|
---|
136 | 'tags' => $tags,
|
---|
137 | 'video_id' => $check->ticket->video_id,
|
---|
138 | );
|
---|
139 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
140 | $tags = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
141 | $tags = unserialize($tags['content']);
|
---|
142 | #privacidad
|
---|
143 | if($permisos){
|
---|
144 | $permisos = strtolower($permisos);
|
---|
145 | if( $permisos!='anybody' && $permisos!='nobody' && $permisos!='contacts' && !strpos($permisos, ',')){
|
---|
146 | $error = true;
|
---|
147 | $error_desc = _('ERROR: Los permisos permitidos son "nobody" para que sea privado, "anybody",'.
|
---|
148 | ' para que sea publico, "contacts" para que solo lo puedan ver los contactos del'.
|
---|
149 | ' usuario registrado o una lista de usuarios separada por comas para que solo esos'.
|
---|
150 | ' usuarios puedan ver el video. (la funcion requiere que si se usa esta ultima'.
|
---|
151 | ' opcin se ponga al menos una coma final.');
|
---|
152 | $retry = 0;
|
---|
153 | }
|
---|
154 | if(strpos($permisos, ',')) {
|
---|
155 | $args = array(
|
---|
156 | 'api_key' => $api_key,
|
---|
157 | 'format' => 'php',
|
---|
158 | 'method' => 'vimeo.videos.setPrivacy',
|
---|
159 | 'privacy' => 'users',
|
---|
160 | 'users' => (substr($permisos, -1)==',') ? substr($permisos, 0, -1) : $permisos,
|
---|
161 | 'video_id' => $check->ticket->video_id,
|
---|
162 | );
|
---|
163 | } else {
|
---|
164 | $args = array(
|
---|
165 | 'api_key' => $api_key,
|
---|
166 | 'format' => 'php',
|
---|
167 | 'method' => 'vimeo.videos.setPrivacy',
|
---|
168 | 'privacy' => $permisos,
|
---|
169 | 'video_id' => $check->ticket->video_id,
|
---|
170 | );
|
---|
171 | }
|
---|
172 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
173 | $permisos = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
174 | $permisos = unserialize($permisos['content']);
|
---|
175 | }
|
---|
176 |
|
---|
177 | if ($check->ticket->video_id) {
|
---|
178 | $videoid = $check->ticket->video_id;
|
---|
179 | $upload_status_desc = 'processing';
|
---|
180 | $retry = false;
|
---|
181 | } else {
|
---|
182 | $upload_status = 'error';
|
---|
183 | $error = true;
|
---|
184 | $upload_status_desc = "Error";
|
---|
185 | $retry = true;
|
---|
186 | }
|
---|
187 |
|
---|
188 | //Preparar la respuesta
|
---|
189 | $service_response = array();
|
---|
190 | $service_response['service'] = 'vimeo';
|
---|
191 | $service_response['video_id'] = $videoid;
|
---|
192 | $service_response['status'] = $upload_status;
|
---|
193 | $service_response['status_description'] = $upload_status_desc;
|
---|
194 | $service_response['error'] = $error;
|
---|
195 | $service_response['error_description'] = $error_desc;
|
---|
196 | $service_response['retry'] = $retry;
|
---|
197 | //Sending the ticket
|
---|
198 | $service_response['ticket'] = $tiket;
|
---|
199 | $service_response['cookie'] = $cookie;
|
---|
200 |
|
---|
201 | return $service_response;
|
---|
202 |
|
---|
203 | /*return array(
|
---|
204 | 'login' => $login,
|
---|
205 | 'frob' => $frobge,
|
---|
206 | 'token' => $token,
|
---|
207 | 'tiket' => $tiket,
|
---|
208 | 'cookie' => $cookie,
|
---|
209 | 'upload' => $upload,
|
---|
210 | 'check' => $check,
|
---|
211 | 'title' => $title,
|
---|
212 | 'caption' => $caption,
|
---|
213 | 'tags' => $tags,
|
---|
214 | 'privacity' => $permisos,
|
---|
215 | 'video_id' => $check->ticket->video_id
|
---|
216 | );*/
|
---|
217 | }
|
---|
218 |
|
---|
219 | }
|
---|
220 |
|
---|
221 | function getembed_vimeo($settings,$videodata) {
|
---|
222 | $error = false; $embed_code = ''; $retry = true;
|
---|
223 | $api_rest_url = "http://www.vimeo.com/api/rest/";
|
---|
224 | $api_auth_url = "http://www.vimeo.com/services/auth/";
|
---|
225 | $frob = false;
|
---|
226 | $api_key = $settings['devkey'];
|
---|
227 | $api_secret = $settings['api_secret'];
|
---|
228 | $tiket = $videodata['ticket'];
|
---|
229 | $cookie = $videodata['cookie'];
|
---|
230 | $video_id = $videodata['video_id'];
|
---|
231 | #check
|
---|
232 | $args = array(
|
---|
233 | 'api_key' => $api_key,
|
---|
234 | 'format' => 'php',
|
---|
235 | 'frob' => $frob,
|
---|
236 | 'method' => 'vimeo.videos.checkUploadStatus',
|
---|
237 | 'ticket_id' => $tiket
|
---|
238 | );
|
---|
239 | $s=$api_secret; foreach($args as $k=>$v){ $s .= $k.$v; } $args['api_sig'] = md5($s);
|
---|
240 | $check = source_extract($api_rest_url, '', $args, '', true, $cookie);
|
---|
241 | $check = unserialize($check['content']);
|
---|
242 |
|
---|
243 | if (isset($check->ticket->transcoding_progress) && ($check->ticket->transcoding_progress == "100")) {
|
---|
244 | $args_info = array(
|
---|
245 | 'api_key' => $api_key,
|
---|
246 | 'format' => 'php',
|
---|
247 | 'frob' => $frob,
|
---|
248 | 'method' => 'vimeo.videos.getInfo',
|
---|
249 | 'video_id' => $video_id
|
---|
250 | );
|
---|
251 | //$video_id = $check->ticket->video_id;
|
---|
252 | $s=$api_secret; foreach($args_info as $k=>$v){ $s .= $k.$v; } $args_info['api_sig'] = md5($s);
|
---|
253 | $check = source_extract($api_rest_url, '', $args_info, '', true, $cookie);
|
---|
254 | $check = unserialize($check['content']);
|
---|
255 | $retry = 0;
|
---|
256 | $error = false;
|
---|
257 | $upload_status = 'completed';
|
---|
258 | $upload_status_desc = _('completed');
|
---|
259 | $embed_code = '<object width="640" height="390"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='.$video_id.'&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='.$video_id.'&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="390"></embed></object>';
|
---|
260 | $video_url = $check->video->urls->url->_content;
|
---|
261 |
|
---|
262 | } else {
|
---|
263 | $retry = 1;
|
---|
264 | $error = false;
|
---|
265 | $upload_status = 'processing';
|
---|
266 | $upload_status_desc = _('transcoding video');
|
---|
267 |
|
---|
268 | }
|
---|
269 |
|
---|
270 | //Preparar la respuesta
|
---|
271 | $service_response = array();
|
---|
272 | $service_response['service'] = 'vimeo';
|
---|
273 | $service_response['status'] = $upload_status;
|
---|
274 | $service_response['status_description'] = $upload_status_desc;
|
---|
275 | $service_response['error'] = $error;
|
---|
276 | $service_response['error_description'] = $error_desc;
|
---|
277 | $service_response['embed'] = $embed_code;
|
---|
278 | $service_response['watch_url'] = $video_url;
|
---|
279 | $service_response['retry'] = $retry;
|
---|
280 | $service_response['video_id'] = $video_id;
|
---|
281 | //Optional data
|
---|
282 | if (!$retry) {
|
---|
283 | $service_response['flv_source'] = 'http://vimeo.com/moogaloop.swf?clip_id='.$video_id;
|
---|
284 | $service_response['views'] = $check->video->number_of_plays;
|
---|
285 | $service_response['duration'] = $check->video->duration;
|
---|
286 | $service_response['thumbnail'] = $check->video->thumbnails->thumbnail[2]->_content;
|
---|
287 | }
|
---|
288 | return $service_response;
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | //Include source_extract library from tierra0.com
|
---|
293 | //http://www.tierra0.com/2009/03/27/source_extract-version2-envio-y-extraccion-de-datos-desde-php-como-si-fuera-un-navegador/
|
---|
294 | function source_extract(
|
---|
295 | $url,
|
---|
296 | $POSTdata='',
|
---|
297 | $GETdata='',
|
---|
298 | $file_upload='',
|
---|
299 | $header=false,
|
---|
300 | $cookie=false
|
---|
301 | ){
|
---|
302 | $user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9';
|
---|
303 | #get
|
---|
304 | if(is_array($GETdata)){
|
---|
305 | foreach($GETdata as $k => $v){ $GETdata[$k] = $k.'='.urlencode($v); }
|
---|
306 | $GETdata = implode('&', $GETdata);
|
---|
307 | }
|
---|
308 | if($GETdata!='') $url .= strpos($url, '?') ? '&'.$GETdata : '?'.$GETdata;
|
---|
309 | #post+files
|
---|
310 | if(is_array($POSTdata)&&!is_array($file_upload)){
|
---|
311 | foreach($POSTdata as $k => $v){ $POSTdata[$k] = $k.'='.$v; }
|
---|
312 | $POSTdata = implode('&', $POSTdata);
|
---|
313 | } elseif(count($POSTdata)==0){
|
---|
314 | $POSTdata = array();
|
---|
315 | }
|
---|
316 | if(is_array($file_upload)){
|
---|
317 | foreach($file_upload as $k=>$v){
|
---|
318 | $v = (substr($v,0,1)!='.'&&substr($v,0,1)!='/') ? './'.$v : ''.$v;
|
---|
319 | $path_v = realpath(dirname($v));
|
---|
320 | $file_v = basename($v);
|
---|
321 | $file_upload[$k] = '@'.$path_v.(substr($path_v,-1)!='/' ? '/' : '').$file_v;
|
---|
322 | }
|
---|
323 | $file_upload = array_merge($POSTdata, $file_upload);
|
---|
324 | }
|
---|
325 | $ch = curl_init($url);
|
---|
326 | if(is_array($file_upload)|| $POSTdata!=''){
|
---|
327 | curl_setopt($ch, CURLOPT_POST, 1);
|
---|
328 | curl_setopt($ch, CURLOPT_POSTFIELDS, (is_array($file_upload) ? $file_upload : $POSTdata));
|
---|
329 | }
|
---|
330 | if($cookie){
|
---|
331 | curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
|
---|
332 | curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
|
---|
333 | }
|
---|
334 | if($header){
|
---|
335 | curl_setopt ($ch, CURLOPT_HEADER, 1);
|
---|
336 | }
|
---|
337 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
---|
338 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (substr($url,0,5)=='https'));
|
---|
339 | curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
|
---|
340 | $_url_content = $url_content = curl_exec ($ch);
|
---|
341 | curl_close($ch);
|
---|
342 | $url_content = array(
|
---|
343 | 'url' =>$url,
|
---|
344 | 'post' =>$file_upload ? $file_upload : $POSTdata,
|
---|
345 | 'content' =>$_url_content
|
---|
346 | );
|
---|
347 | if($header){
|
---|
348 | $_url_content = explode("\r\n\r\n", $_url_content,3);
|
---|
349 | $url_content['header'] = (count($_url_content)>2) ? $_url_content[0]."\r\n".$_url_content[1] : $_url_content[0];
|
---|
350 | $url_content['header'] = explode("\r\n", $url_content['header']);
|
---|
351 | foreach($url_content['header'] as $k=>$v){ $o[$k] = explode(': ', $v,2); $o[$o[$k][0]] = $o[$k][1]; unset($o[$k]); }
|
---|
352 | $url_content['header'] = $o;
|
---|
353 | $url_content['content'] = (count($_url_content)>2) ? $_url_content[2] : $_url_content[1];
|
---|
354 | }
|
---|
355 | return $url_content;
|
---|
356 | }
|
---|
357 |
|
---|
358 | ?>
|
---|