-
Notifications
You must be signed in to change notification settings - Fork 1
/
sl7_control_panel.module
executable file
·292 lines (256 loc) · 8.08 KB
/
sl7_control_panel.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?php
/**
* @file
* SL7 Control panel.
*
* @author Semyon Dragunov <sam.dragunov@gmail.com>
* https://github.com/SemyonDragunov
*/
define('SL7_CONTROL_PANEL_ADMIN_PATH', 'admin/control-panel');
require_once(__DIR__ . '/includes/sl7_date.inc');
/**
* Implement hook_menu().
*/
function sl7_control_panel_menu() {
$items[SL7_CONTROL_PANEL_ADMIN_PATH] = array(
'title' => t('Control panel'),
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('view'),
'page callback' => 'sl7_control_panel_page',
'type' => MENU_NORMAL_ITEM,
'menu_name' => 'management',
'weight' => -20,
);
$items[SL7_CONTROL_PANEL_ADMIN_PATH . '/content'] = array(
'title' => t('Materials'),
'position' => 'left',
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('view'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => -20,
);
$items[SL7_CONTROL_PANEL_ADMIN_PATH . '/apps'] = array(
'title' => t('Apps'),
'position' => 'left',
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('view'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
);
$items[SL7_CONTROL_PANEL_ADMIN_PATH . '/settings'] = array(
'title' => t('Settings'),
'position' => 'right',
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('view'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => -10,
);
$items[SL7_CONTROL_PANEL_ADMIN_PATH . '/settings/cache-clear'] = array(
'title' => t('Clear cache'),
'description' => t('Clear all cache on site.'),
'page callback' => 'drupal_flush_all_caches',
'page arguments' => array('admin'),
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('cache_clear'),
'weight' => 30,
);
$items[SL7_CONTROL_PANEL_ADMIN_PATH . '/social'] = array(
'title' => t('Social'),
'position' => 'right',
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'sl7_control_panel_access',
'access arguments' => array('view'),
'file path' => drupal_get_path('module', 'system'),
'file' => 'system.admin.inc',
'weight' => 0,
);
$items['ajax/sl7/entityform/get'] = array(
'page callback' => 'sl7_control_panel_entityform_ajax_get',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['ajax/sl7/entityform/submit'] = array(
'page callback' => 'sl7_control_panel_entityform_ajax_submit',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'delivery callback' => 'ajax_deliver',
);
return $items;
}
/**
* Implement hook_admin_paths().
*/
function sl7_control_panel_admin_paths() {
return array(
SL7_CONTROL_PANEL_ADMIN_PATH => TRUE,
SL7_CONTROL_PANEL_ADMIN_PATH . '/*' => TRUE,
);
}
/**
* Implement hook_permission().
*/
function sl7_control_panel_permission() {
return array(
'sl7_control_panel view' => array('title' => t('Access for control panel.')),
'sl7_control_panel cache_clear' => array('title' => t('Access to clear cache on control panel.')),
);
}
function sl7_control_panel_access($op, $account = NULL) {
if (user_access("sl7_control_panel $op", $account)) {
return TRUE;
}
return FALSE;
}
/**
* Implements hook_theme().
*/
function sl7_control_panel_theme() {
$items = array(
'sl7_user_controls' => array(
'template' => 'templates/sl7-user-controls',
'variables' => array(
'inline' => NULL,
),
),
);
return $items;
}
/**
* Implements hook_preprocess_html().
*/
function sl7_control_panel_preprocess_html(&$vars) {
// Add css class if exist control panel.
if (module_exists('sl7_control_panel') && $vars['logged_in'] == TRUE && user_access('sl7_control_panel view')) {
$vars['classes_array'][] = "control-panel";
}
}
/**
* Implements hook_preprocess_page().
*/
function sl7_control_panel_preprocess_page(&$variables) {
$site_frontpage = variable_get('site_frontpage');
// Add meta-tags on front page.
if (drupal_is_front_page() && ('node' == $site_frontpage || '' == $site_frontpage)) {
$element = array(
'#type' => 'markup',
'#markup' => render($variables['page']['content']['metatags']),
);
drupal_add_html_head($element, 'front-metatags');
}
}
function sl7_control_panel_page() {
$blocks = array();
$control_panel_path = SL7_CONTROL_PANEL_ADMIN_PATH;
if ($admin = db_query("SELECT menu_name, mlid FROM {menu_links} WHERE link_path = '{$control_panel_path}' AND module = 'system'")->fetchAssoc()) {
$result = db_query("
SELECT m.*, ml.*
FROM {menu_links} ml
INNER JOIN {menu_router} m ON ml.router_path = m.path
WHERE ml.link_path <> 'admin/help' AND menu_name = :menu_name AND ml.plid = :mlid AND hidden = 0", $admin, array('fetch' => PDO::FETCH_ASSOC));
foreach ($result as $item) {
_menu_link_translate($item);
if (!$item['access']) {
continue;
}
if (!empty($item['localized_options']['attributes']['title'])) {
$item['description'] = $item['localized_options']['attributes']['title'];
unset($item['localized_options']['attributes']['title']);
}
$block = $item;
$block['content'] = '';
$block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($item)));
if (!empty($block['content'])) {
$block['show'] = TRUE;
}
$blocks[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $block;
}
}
if ($blocks) {
ksort($blocks);
return theme('admin_page', array('blocks' => $blocks));
}
else {
return t('You do not have any administrative items.');
}
}
/**
* Implements hook_block_info().
*/
function sl7_control_panel_block_info() {
$blocks['user_controls'] = array(
'info' => t('User controls'),
'status' => 1,
'region' => 'user_controls',
'weight' => 1,
'cache' => DRUPAL_CACHE_GLOBAL,
'visibility' => BLOCK_VISIBILITY_NOTLISTED,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function sl7_control_panel_block_view($delta = '') {
$block = array();
if ($delta == 'user_controls') {
$block['subject'] = '';
$block['content'] = array(
'#markup' => theme('sl7_user_controls'),
);
}
return $block;
}
/**
* AJAX form loading through JS.
*
* AJAX form loading.
* @code
* $.get('/ajax/sl7/entityform/get', { name: 'sl7_call_me' }).done(function(form) {
* // Code after get. form - inputs from form.
* });
* @endcode
*
* Callback for altering AJAX form before process.
* @code
* $.get('/ajax/sl7/entityform/get', { name: 'sl7_call_me', callback: 'MYMODULE_ajax_form_alter' }).done(function(form) {
* // Code.
* });
* @endcode
*
* @internal param $get_parameters
*/
function sl7_control_panel_entityform_ajax_get() {
$form_id = $_GET['name'];
module_load_include('inc', 'entityform', 'entityform.admin');
$entityform_name = $form_id;
$entityform = entityform_form_wrapper(entityform_empty_load($entityform_name), 'submit', 'embedded');
if (!empty($_GET['callback'])) {
$callback = $_GET['callback'];
if (function_exists($callback)) {
$callback($entityform);
}
}
drupal_add_library('system', 'jquery.form');
drupal_add_library('system', 'drupal.form');
drupal_add_library('system', 'drupal.ajax');
drupal_add_library('system', 'drupal.progress');
$html = render($entityform);
print $html;
drupal_exit();
}
/**
* Ajax submit Entityform.
*/
function sl7_control_panel_entityform_ajax_submit() {
module_load_include('inc', 'entityform', 'entityform.admin');
list($form, $form_state) = ajax_get_form();
drupal_process_form($form['#form_id'], $form, $form_state);
$commands = array();
$commands[] = ajax_command_html('.messages', theme('status_messages'));
return array('#type' => 'ajax', '#commands' => $commands);
}