This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmediamosa_ck.inc
76 lines (65 loc) · 1.94 KB
/
mediamosa_ck.inc
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
<?php
/**
* @file
* All non-hooks are put in this file.
*/
/**
* Create the upload ticket and return result array in json.
*
* @return array
* Returns an associative array;
* - 'action'
* The upload URL for the file.
* - 'progress_id'
* Progress ID to use when getting upload progression from server.
* - 'asset_id'
* The asset ID of the upload.
* - 'mediafile_id'
* The mediafile ID of the upload.
*/
function _mediamosa_ck_json_create_upload_ticket($options = array()) {
$filename = !empty($_GET['filename']) ? $_GET['filename'] : '';
if (!empty($filename)) {
$options['filename'] = $filename;
}
// Create upload ticket.
$upload_ticket = MediaMosaCkConnectorWrapper::create_upload_ticket($options);
// Output as JSON.
drupal_json_output($upload_ticket);
}
/**
* Check the connector status, if connector works and is setup.
*
* @return string
* JSON containing '1' for OK, '0' for failure.
*/
function _mediamosa_ck_json_connector_status() {
// Get the connector.
$connector = mediamosa_ck::get_connector();
$result = array(
'ok' => $connector->check_connection() ? '1' : '0',
);
// Return '1' for success, '0' for failure.
drupal_json_output($result);
}
/**
* Download mediafile.
*/
function _mediamosa_ck_mediafile_download($asset_id, $mediafile_id) {
// Take user_id of current watcher.
$user_id = mediamosa_ck::session_user_id();
// Determine admin user.
if (user_access('access administration pages')) {
$options['is_app_admin'] = TRUE;
}
try {
$options['fatal'] = TRUE;
$options['response'] = 'download';
$response = MediaMosaCkConnectorWrapper::get_play_link($asset_id, $mediafile_id, $user_id, $options);
}
catch (Exception $e) {
drupal_set_message($e->getMessage(), 'warning');
drupal_goto(strtr('asset/detail/@asset_id/@mediafile_id', array('@asset_id' => $asset_id, '@mediafile_id' => $mediafile_id)));
}
drupal_goto($response);
}