-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasyopac_status.module
More file actions
108 lines (99 loc) · 2.95 KB
/
easyopac_status.module
File metadata and controls
108 lines (99 loc) · 2.95 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
<?php
/**
* @file
* Define hooks for the status bar functionality.
*/
/**
* Implements hook_menu().
*/
function easyopac_status_menu() {
$items = [];
$items['admin/reports/easyopac_status'] = [
'title' => 'easyOPAC Status Admin Page',
'description' => 'easyOPAC Status cron report',
'page callback' => 'drupal_get_form',
'page arguments' => ['easyopac_status_admin_settings_form'],
'access arguments' => ['access administration pages'],
'type' => MENU_NORMAL_ITEM,
'file' => 'easyopac_status.admin.inc',
];
$items['easyopac_status/close'] = [
'title' => 'easyOPAC Close status bar',
'description' => 'easyOPAC close Status bar',
'page callback' => 'easyopac_status_close_bar',
'access arguments' => ['access content'],
'type' => MENU_CALLBACK,
];
$items['easyopac_status/status'] = [
'title' => 'easyOPAC Status Request',
'description' => 'easyOPAC Status cURL Reques',
'page callback' => 'easyopac_status_request',
'access arguments' => ['access content'],
'type' => MENU_CALLBACK,
];
return $items;
}
/**
* Implements hook_cron().
*/
function easyopac_status_cron() {
variable_set('easyopac_status_display', ['content' => '', 'status' => 1, 'indicator' => '']);
}
/**
* Implements hook_page_build().
*/
function easyopac_status_page_build(&$page) {
$path = drupal_get_path('module', 'easyopac_status');
drupal_add_js($path . '/js/easyopac_status.js');
if (arg(0) == 'admin') {
return;
}
$page['page_top']['status'] = [
'#markup' => '<div id="easyddb-status-wrapper" class="hidden"><div class="easyddb-status-inner"><div class="icon"></div><div class="message"></div><div class="close-container"><a href="#" class="close-button"></a></div></div></div>',
'#attached' => [
'js' => [
['data' => [
'easyopac_status' => variable_get('easyopac_status', []),
'easyopac_status_display' => variable_get('easyopac_status_display', []),
],
'type' => 'setting',
],
],
'css' => [
$path . '/css/easyopac_status.css'
],
],
];
}
/**
* Save current status of the site.
*/
function easyopac_status_close_bar() {
variable_set('easyopac_status_display', ['content' => check_plain($_GET['content']), 'status' => 0, 'indicator' => '']
);
}
/**
* Make cURL request to get the status of the service.
*/
function easyopac_status_request() {
$configs = &drupal_static(__FUNCTION__);
if (empty($configs)) {
$configs = variable_get('easyopac_status', []);
}
$options = [];
if (!empty($configs['admin'])) {
$url = 'https://' . $configs['admin']['page'] . '.' . $configs['admin']['url'];
$options = [
'method' => 'GET',
'headers' => [
'Authorization' => 'OAuth ' . $configs['admin']['key'],
],
];
}
$result = drupal_http_request($url, $options);
$data = '';
if (!empty($result)) {
$data = drupal_json_decode($result->data);
}
drupal_json_output($data);
}