-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.php
569 lines (510 loc) · 18.9 KB
/
template.php
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<?php
/*
* Implements hook_preprocess_html().
*/
function ae_admin_preprocess_html() {
if (module_exists('views')) {
drupal_add_css(drupal_get_path('module', 'views') . '/css/views-admin.seven.css', 'theme');
}
}
/**
* Implements hook_css_alter().
* @TODO: Do this in .info once http://drupal.org/node/575298 is committed.
*/
function ae_admin_css_alter(&$css) {
if (isset($css['modules/overlay/overlay-child.css'])) {
$css['modules/overlay/overlay-child.css']['data'] = drupal_get_path('theme', 'ae_admin') . '/overlay-child.css';
}
if (isset($css['modules/shortcut/shortcut.css'])) {
$css['modules/shortcut/shortcut.css']['data'] = drupal_get_path('theme', 'ae_admin') . '/shortcut.css';
}
// This can be removed once http://drupal.org/node/1221560 is released
if (isset($css['sites/all/modules/views/css/views-admin.ae_admin.css'])) {
$css['sites/all/modules/views/css/views-admin.ae_admin.css']['data'] = drupal_get_path('theme', 'ae_admin') . '/views-admin.ae_admin.css';
}
}
/**
* Implementation of hook_theme().
*/
function ae_admin_theme() {
$items = array();
// Content theming.
$items['help'] =
$items['node'] =
$items['comment'] =
$items['comment_wrapper'] = array(
'path' => drupal_get_path('theme', 'ae_admin') .'/templates',
'template' => 'object',
);
$items['node']['template'] = 'node';
// Help pages really need help. See preprocess_page().
$items['help_page'] = array(
'variables' => array('content' => array()),
'path' => drupal_get_path('theme', 'ae_admin') .'/templates',
'template' => 'object',
'preprocess functions' => array(
'template_preprocess',
'ae_admin_preprocess_help_page',
),
'process functions' => array('template_process'),
);
// Form layout: default (2 column).
$items['block_add_block_form'] =
$items['block_admin_configure'] =
$items['comment_form'] =
$items['contact_admin_edit'] =
$items['contact_mail_page'] =
$items['contact_mail_user'] =
$items['filter_admin_format_form'] =
$items['forum_form'] =
$items['locale_languages_edit_form'] =
$items['menu_edit_menu'] =
$items['menu_edit_item'] =
$items['node_type_form'] =
$items['path_admin_form'] =
$items['system_settings_form'] =
$items['system_themes_form'] =
$items['system_modules'] =
$items['system_actions_configure'] =
$items['taxonomy_form_term'] =
$items['taxonomy_form_vocabulary'] =
$items['user_profile_form'] =
$items['user_admin_access_add_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'ae_admin') .'/templates',
'template' => 'form-default',
'preprocess functions' => array(
'ae_admin_preprocess_form_buttons',
),
);
// These forms require additional massaging.
$items['confirm_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'ae_admin') .'/templates',
'template' => 'form-simple',
'preprocess functions' => array(
'ae_admin_preprocess_form_confirm'
),
);
$items['node_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'ae_admin') .'/templates',
'template' => 'form-default',
'preprocess functions' => array(
'ae_admin_preprocess_form_buttons',
'ae_admin_preprocess_form_node',
),
);
$items['export_download_links'] = array(
'variables' => array(
'node' => NULL,
),
'function' => 'theme_export_download_links',
);
return $items;
}
/**
* Preprocessor for theme('page').
*/
function ae_admin_preprocess_page(&$vars) {
// Show a warning if base theme is not present.
if (!function_exists('tao_theme') && user_access('administer site configuration')) {
drupal_set_message(t('The advocacy engine admin theme requires the !tao base theme in order to work properly.', array('!tao' => l('Tao', 'http://code.developmentseed.org/tao'))), 'warning');
}
// Set a page icon class.
$vars['page_icon_class'] = ($item = menu_get_item()) ? implode(' ' , _ae_admin_icon_classes($item['href'])) : '';
// Help pages. They really do need help.
if (strpos($_GET['q'], 'admin/help/') === 0 && isset($vars['page']['content']['system_main']['main']['#markup'])) {
$vars['page']['content']['system_main']['main']['#markup'] = theme('help_page', array('content' => $vars['page']['content']['system_main']['main']['#markup']));
}
// Clear out help text if empty.
if (empty($vars['help']) || !(strip_tags($vars['help']))) {
$vars['help'] = '';
}
// Process local tasks. Only do this processing if the current theme is
// indeed ae_admin. Subthemes must reimplement this call.
global $theme;
if ($theme === 'ae_admin') {
_ae_admin_local_tasks($vars);
}
// Overlay is enabled.
$vars['overlay'] = (module_exists('overlay') && overlay_get_mode() === 'child');
}
/**
* Preprocessor for theme('fieldset').
*/
function ae_admin_preprocess_fieldset(&$vars) {
if (!empty($vars['element']['#collapsible'])) {
$vars['title'] = "<span class='icon'></span>" . $vars['title'];
}
}
/**
* Preprocessor for handling form button for most forms.
*/
function ae_admin_preprocess_form_buttons(&$vars) {
if (!empty($vars['form']['actions'])) {
$vars['actions'] = $vars['form']['actions'];
unset($vars['form']['actions']);
}
}
/**
* Preprocessor for theme('confirm_form').
*/
function ae_admin_preprocess_form_confirm(&$vars) {
// Move the title from the page title (usually too big and unwieldy)
$title = filter_xss_admin(drupal_get_title());
$vars['form']['description']['#type'] = 'item';
$vars['form']['description']['#value'] = empty($vars['form']['description']['#value']) ?
"<strong>{$title}</strong>" :
"<strong>{$title}</strong><p>{$vars['form']['description']['#value']}</p>";
drupal_set_title(t('Please confirm'));
}
/**
* Preprocessor for theme('node_form').
*/
function ae_admin_preprocess_form_node(&$vars) {
$vars['sidebar'] = isset($vars['sidebar']) ? $vars['sidebar'] : array();
// Support nodeformcols if present.
if (module_exists('nodeformcols')) {
$map = array(
'nodeformcols_region_right' => 'sidebar',
'nodeformcols_region_footer' => 'footer',
'nodeformcols_region_main' => NULL,
);
foreach ($map as $region => $target) {
if (isset($vars['form'][$region])) {
if (isset($vars['form'][$region]['#prefix'], $vars['form'][$region]['#suffix'])) {
unset($vars['form'][$region]['#prefix']);
unset($vars['form'][$region]['#suffix']);
}
if (isset($vars['form'][$region]['actions'], $vars['form'][$region]['actions'])) {
$vars['actions'] = $vars['form'][$region]['actions'];
unset($vars['form'][$region]['actions']);
}
if (isset($target)) {
$vars[$target] = $vars['form'][$region];
unset($vars['form'][$region]);
}
}
}
}
// Default to showing taxonomy in sidebar if nodeformcols is not present.
elseif (isset($vars['form']['taxonomy']) && empty($vars['sidebar'])) {
$vars['sidebar']['taxonomy'] = $vars['form']['taxonomy'];
unset($vars['form']['taxonomy']);
}
}
/**
* Preprocessor for theme('button').
*/
function ae_admin_preprocess_button(&$vars) {
if (isset($vars['element']['#value'])) {
$classes = array(
t('Save') => 'yes',
t('Submit') => 'yes',
t('Add') => 'yes',
t('Delete') => 'no',
t('Cancel') => 'no',
);
foreach ($classes as $search => $class) {
if (strpos($vars['element']['#value'], $search) !== FALSE) {
$vars['element']['#attributes']['class'][] = 'button-' . $class;
break;
}
}
}
}
/**
* Preprocessor for theme('help').
*/
function ae_admin_preprocess_help(&$vars) {
$vars['hook'] = 'help';
$vars['attr']['id'] = 'help-text';
$class = 'path-admin-help clear-block toggleable';
$vars['attr']['class'] = isset($vars['attr']['class']) ? "{$vars['attr']['class']} $class" : $class;
$help = menu_get_active_help();
if (($test = strip_tags($help)) && !empty($help)) {
// Thankfully this is static cached.
$vars['attr']['class'] .= menu_secondary_local_tasks() ? ' with-tabs' : '';
$vars['is_prose'] = TRUE;
$vars['layout'] = TRUE;
$vars['content'] = "<span class='icon'></span>" . $help;
// Link to help section.
$item = menu_get_item('admin/help');
if ($item && $item['path'] === 'admin/help' && $item['access']) {
$vars['links'] = l(t('More help topics'), 'admin/help');
}
}
}
/**
* Preprocessor for theme('help_page').
*/
function ae_admin_preprocess_help_page(&$vars) {
$vars['hook'] = 'help-page';
$vars['title_attributes_array']['class'][] = 'help-page-title';
$vars['title_attributes_array']['class'][] = 'clearfix';
$vars['content_attributes_array']['class'][] = 'help-page-content';
$vars['content_attributes_array']['class'][] = 'clearfix';
$vars['content_attributes_array']['class'][] = 'prose';
$vars['layout'] = TRUE;
// Truly hackish way to navigate help pages.
$module_info = system_rebuild_module_data();
$modules = array();
foreach (module_implements('help', TRUE) as $module) {
if (module_invoke($module, 'help', "admin/help#$module", NULL)) {
$modules[$module] = $module_info[$module]->info['name'];
}
}
asort($modules);
$links = array();
foreach ($modules as $module => $name) {
$links[] = array('title' => $name, 'href' => "admin/help/{$module}");
}
$vars['links'] = theme('links', array('links' => $links));
}
/**
* Preprocessor for theme('node').
*/
function ae_admin_preprocess_node(&$vars) {
$vars['layout'] = TRUE;
$vars['submitted'] = _ae_admin_submitted($vars['node']);
}
/**
* Preprocessor for theme('comment').
*/
function ae_admin_preprocess_comment(&$vars) {
$vars['layout'] = TRUE;
$vars['submitted'] = _ae_admin_submitted($vars['comment']);
}
/**
* Preprocessor for theme('comment_wrapper').
*/
function ae_admin_preprocess_comment_wrapper(&$vars) {
$vars['hook'] = 'box';
$vars['layout'] = FALSE;
$vars['title'] = t('Comments');
$vars['attributes_array']['id'] = 'comments';
$vars['title_attributes_array']['class'][] = 'box-title';
$vars['title_attributes_array']['class'][] = 'clearfix';
$vars['content_attributes_array']['class'][] = 'box-content';
$vars['content_attributes_array']['class'][] = 'clearfix';
$vars['content_attributes_array']['class'][] = 'prose';
$vars['content'] = drupal_render_children($vars['content']);
}
/**
* Preprocessor for theme('admin_block').
*/
function ae_admin_preprocess_admin_block(&$vars) {
// Add icon and classes to admin block titles.
if (isset($vars['block']['href'])) {
$vars['block']['localized_options']['attributes']['class'] = _ae_admin_icon_classes($vars['block']['href']);
}
$vars['block']['localized_options']['html'] = TRUE;
if (isset($vars['block']['link_title'])) {
$vars['block']['title'] = l("<span class='icon'></span>" . filter_xss_admin($vars['block']['link_title']), $vars['block']['href'], $vars['block']['localized_options']);
}
if (empty($vars['block']['content'])) {
$vars['block']['content'] = "<div class='admin-block-description description'>{$vars['block']['description']}</div>";
}
}
/**
* Override of theme('breadcrumb').
*/
function ae_admin_breadcrumb($vars) {
$output = '';
// Add current page onto the end.
if (!drupal_is_front_page()) {
$item = menu_get_item();
$end = end($vars['breadcrumb']);
if ($end && strip_tags($end) !== $item['title']) {
$vars['breadcrumb'][] = "<strong>". check_plain($item['title']) ."</strong>";
}
}
// Optional: Add the site name to the front of the stack.
if (!empty($vars['prepend'])) {
$site_name = empty($vars['breadcrumb']) ? "<strong>". check_plain(variable_get('site_name', '')) ."</strong>" : l(variable_get('site_name', ''), '<front>', array('purl' => array('disabled' => TRUE)));
array_unshift($vars['breadcrumb'], $site_name);
}
$depth = 0;
foreach ($vars['breadcrumb'] as $link) {
$output .= "<span class='breadcrumb-link breadcrumb-depth-{$depth}'>{$link}</span>";
$depth++;
}
return $output;
}
/**
* Override of theme('filter_guidelines').
*/
function ae_admin_filter_guidelines($variables) {
return '';
}
/**
* Override of theme('node_add_list').
*/
function ae_admin_node_add_list($vars) {
$content = $vars['content'];
$output = "<ul class='admin-list'>";
if ($content) {
foreach ($content as $item) {
$item['title'] = "<span class='icon'></span>" . filter_xss_admin($item['title']);
if (isset($item['localized_options']['attributes']['class'])) {
$item['localized_options']['attributes']['class'] += _ae_admin_icon_classes($item['href']);
}
else {
$item['localized_options']['attributes']['class'] = _ae_admin_icon_classes($item['href']);
}
$item['localized_options']['html'] = TRUE;
$output .= "<li>";
$output .= l($item['title'], $item['href'], $item['localized_options']);
$output .= '<div class="description">'. filter_xss_admin($item['description']) .'</div>';
$output .= "</li>";
}
}
$output .= "</ul>";
return $output;
}
/**
* Override of theme_admin_block_content().
*/
function ae_admin_admin_block_content($vars) {
$content = $vars['content'];
$output = '';
if (!empty($content)) {
foreach ($content as $k => $item) {
//-- Safety check for invalid clients of the function
if (empty($content[$k]['localized_options']['attributes']['class'])) {
$content[$k]['localized_options']['attributes']['class'] = array();
}
if (!is_array($content[$k]['localized_options']['attributes']['class'])) {
$content[$k]['localized_options']['attributes']['class'] = array($content[$k]['localized_options']['attributes']['class']);
}
$content[$k]['title'] = "<span class='icon'></span>" . filter_xss_admin($item['title']);
$content[$k]['localized_options']['html'] = TRUE;
if (!empty($content[$k]['localized_options']['attributes']['class'])) {
$content[$k]['localized_options']['attributes']['class'] += _ae_admin_icon_classes($item['href']);
}
else {
$content[$k]['localized_options']['attributes']['class'] = _ae_admin_icon_classes($item['href']);
}
}
$output = system_admin_compact_mode() ? '<ul class="admin-list admin-list-compact">' : '<ul class="admin-list">';
foreach ($content as $item) {
$output .= '<li class="leaf">';
$output .= l($item['title'], $item['href'], $item['localized_options']);
if (isset($item['description']) && !system_admin_compact_mode()) {
$output .= "<div class='description'>{$item['description']}</div>";
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
/**
* Override of theme('admin_drilldown_menu_item_link').
*/
function ae_admin_admin_drilldown_menu_item_link($link) {
$link['localized_options'] = empty($link['localized_options']) ? array() : $link['localized_options'];
$link['localized_options']['html'] = TRUE;
if (!isset($link['localized_options']['attributes']['class'])) {
$link['localized_options']['attributes']['class'] = _ae_admin_icon_classes($link['href']);
}
else {
$link['localized_options']['attributes']['class'] += _ae_admin_icon_classes($link['href']);
}
$link['description'] = check_plain(truncate_utf8(strip_tags($link['description']), 150, TRUE, TRUE));
$link['description'] = "<span class='icon'></span>" . $link['description'];
$link['title'] .= !empty($link['description']) ? "<span class='menu-description'>{$link['description']}</span>" : '';
$link['title'] = filter_xss_admin($link['title']);
return l($link['title'], $link['href'], $link['localized_options']);
}
/**
* Preprocessor for theme('textfield').
*/
function ae_admin_preprocess_textfield(&$vars) {
if ($vars['element']['#size'] >= 30 && empty($vars['element']['#field_prefix']) && empty($vars['element']['#field_suffix'])) {
$vars['element']['#size'] = '';
if (!isset($vars['element']['#attributes']['class'])
|| !is_array($vars['element']['#attributes']['class'])) {
$vars['element']['#attributes']['class'] = array();
}
$vars['element']['#attributes']['class'][] = 'fluid';
}
}
/**
* Override of theme('menu_local_task').
*/
function ae_admin_menu_local_task($variables) {
$link = $variables['element']['#link'];
$link_text = $link['title'];
if (!empty($variables['element']['#active'])) {
// Add text to indicate active tab for non-visual users.
$active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
// If the link does not contain HTML already, check_plain() it now.
// After we set 'html'=TRUE the link will not be sanitized by l().
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
}
// Render child tasks if available.
$children = '';
if (element_children($variables['element'])) {
$children = drupal_render_children($variables['element']);
$children = "<ul class='secondary-tabs links clearfix'>{$children}</ul>";
}
return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . $children . "</li>\n";
}
/**
* Helper function for cloning and drupal_render()'ing elements.
*/
function ae_admin_render_clone($elements) {
static $instance;
if (!isset($instance)) {
$instance = 1;
}
foreach (element_children($elements) as $key) {
if (isset($elements[$key]['#id'])) {
$elements[$key]['#id'] = "{$elements[$key]['#id']}-{$instance}";
}
}
$instance++;
return drupal_render($elements);
}
/**
* Helper function to submitted info theming functions.
*/
function _ae_admin_submitted($node) {
$byline = t('Posted by !username', array('!username' => theme('username', array('account' => $node))));
$date = format_date($node->created, 'small');
return "<div class='byline'>{$byline}</div><div class='date'>$date</div>";
}
/**
* Generate an icon class from a path.
*/
function _ae_admin_icon_classes($path) {
$classes = array();
$args = explode('/', $path);
if ($args[0] === 'admin' || (count($args) > 1 && $args[0] === 'node' && $args[1] === 'add')) {
// Add a class specifically for the current path that allows non-cascading
// style targeting.
$classes[] = 'path-'. str_replace('/', '-', implode('/', $args)) . '-';
while (count($args)) {
$classes[] = drupal_html_class('path-'. str_replace('/', '-', implode('/', $args)));
array_pop($args);
}
return $classes;
}
return array();
}
function _ae_admin_local_tasks(&$vars) {
if (!empty($vars['secondary_local_tasks']) && is_array($vars['primary_local_tasks'])) {
foreach ($vars['primary_local_tasks'] as $key => $element) {
if (!empty($element['#active'])) {
$vars['primary_local_tasks'][$key] = $vars['primary_local_tasks'][$key];
break;
}
}
}
}