| 1 |
<?php
|
| 2 |
|
| 3 |
// $Id$
|
| 4 |
|
| 5 |
/**
|
| 6 |
* @file video_upload.pages.inc
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Menu callback: YouTube redirect, or in the case of direct upload method,
|
| 11 |
* the Drupal form ajax callback.
|
| 12 |
*/
|
| 13 |
function video_upload_js() {
|
| 14 |
$status = TRUE;
|
| 15 |
|
| 16 |
$field_name = arg(2);
|
| 17 |
|
| 18 |
// rudimentary node object
|
| 19 |
$node->type = arg(3);
|
| 20 |
|
| 21 |
// load field definition
|
| 22 |
$field = content_fields($field_name, $node->type);
|
| 23 |
|
| 24 |
// check status
|
| 25 |
$status = $_GET['status'];
|
| 26 |
$id = $_GET['id'];
|
| 27 |
|
| 28 |
if (!empty($_POST)) {
|
| 29 |
// local request, not a redirect from YouTube, thus
|
| 30 |
// a direct upload
|
| 31 |
|
| 32 |
// Make node from POST data
|
| 33 |
$node = (object)$_POST;
|
| 34 |
|
| 35 |
$items = array();
|
| 36 |
$values = content_field('load', $node, $field, $items, FALSE, FALSE);
|
| 37 |
$items = $values[$field_name];
|
| 38 |
|
| 39 |
// any 'load' operations
|
| 40 |
video_upload_field('load', $node, $field, $items, FALSE, FALSE);
|
| 41 |
_video_upload_widget_prepare_form_values($node, $field, $items);
|
| 42 |
_video_upload_widget_validate($node, $field, $items);
|
| 43 |
}
|
| 44 |
elseif ($id && $status == '200') {
|
| 45 |
// success, coming from YouTube
|
| 46 |
|
| 47 |
// fake _POST so as not to wipe-out video upload sessions
|
| 48 |
$_POST['video_upload_fake'] = 1;
|
| 49 |
|
| 50 |
drupal_set_message(t('Video has been uploaded, and is being processed, please continue to save this post.'));
|
| 51 |
|
| 52 |
$items = array(
|
| 53 |
array(
|
| 54 |
'id' => $id,
|
| 55 |
'status' => VIDEO_UPLOAD_STATUS_UNKNOWN,
|
| 56 |
'status_ts' => time(),
|
| 57 |
'fid' => 0,
|
| 58 |
),
|
| 59 |
);
|
| 60 |
|
| 61 |
$node->{$field_name}[0]['id'] = $id;
|
| 62 |
$values = content_field('load', $node, $field, $items, FALSE, FALSE);
|
| 63 |
}
|
| 64 |
else {
|
| 65 |
// failure
|
| 66 |
drupal_set_message(t('No file uploaded'), 'error');
|
| 67 |
$status = 2;
|
| 68 |
// this variable will prevent any existing item from being overwritten
|
| 69 |
$save = true;
|
| 70 |
}
|
| 71 |
|
| 72 |
$form = _video_upload_widget_form($node, $field, $items, $save);
|
| 73 |
$form = form_builder('video_upload_js', $form);
|
| 74 |
|
| 75 |
$output = theme('status_messages') . drupal_render($form);
|
| 76 |
print drupal_to_js(array('status' => $status, 'data' => $output));
|
| 77 |
exit;
|
| 78 |
}
|
| 79 |
|