forked from iliyat/drupal-airtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
airtime.module
92 lines (80 loc) · 2.54 KB
/
airtime.module
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
<?
/* Модуль в процессе создания, много лишних вещей.
* методы апи:
* live-info
* week-info
* schedule - расписание текущего шоу
* version - Airtime version, example 2.4.0
* status
* get-media/file/$file_id - возвращает файл для сохранения\просмотра
*
*/
/* Пока используем вариант с шифрованием объекта с параметрами в base64*/
include('includes/airtime.base64.class.php');
function airtime_js_init()
{
/*для прямых кросс-доменных запросов, надо править эйртайм*/
drupal_add_js(drupal_get_path('module', 'airtime').'/js/api.airtime.js');
}
function airtime_menu()
{
$items = array();
$items['airtime/api'] = array(
'title' => 'Airtime API',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'airtime_api',
'access callback' => 'user_access',
'access arguments' => array('access content')
);
return $items;
}
function airtime_api_old() /* вывод обращений к апи в пространстве друпала, что-то типа посредника*/
{
if(arg(2) != '')
{
if(arg(3)!= '')
{
//TODO: унифицировать выбор адреса airtime
$node = node_load(arg(3));
if($node->field_airtime_api['und'][0]['value'] != '')
{
/*TODO передавать ключ как аргкмент в ссылке*/
/* Указываем с какого хоста брать данные*/
$airtime = new Airtime($node->field_airtime_api['und'][0]['value']);
/* Устанавливаем api_key, если есть*/
$airtime->api->api_key = $_GET['api_key'];
$data = $airtime->api->get(arg(2));
}
else
{
$data['error'] = 'Airtime API not set in this chanel';
}
}
else
{
$data['error'] = "Select chanel ID";
}
}
else
{
$data['error'] = "Select API method";
}
return drupal_json_output($data);
}
function airtime_api()
{
if(arg(2) != '')
{
if($hash = base64_decode(arg(2)))
{
$options = json_decode($hash);
$node = node_load($options->nid);
if($node->field_airtime_api['und'][0]['value'] != '')
{
$options->host = $node->field_airtime_api['und'][0]['value'];
$airtime = new Airtime($options);
drupal_json_output($airtime->json());
}
}
}
}