-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
485 lines (438 loc) · 13.7 KB
/
Copy pathtemplate.php
File metadata and controls
485 lines (438 loc) · 13.7 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
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
<?php
/**
* @file
* Overrides and any custom code for the compro theme.
*/
/**
* Implements template_preprocess_html().
*/
function compro_theme_preprocess_html(&$vars) {
// Add an X-UA-COMPATIBLE meta tag.
drupal_add_html_head(array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-COMPATIBLE',
'content' => 'IE=edge',
),
), 'compro_theme_xua_compatible');
// Add a viewport meta tag.
drupal_add_html_head(array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1',
),
), 'compro_theme_viewport');
// Skip link.
$vars['skip_link'] = array(
'#type' => 'container',
'#attributes' => array(
'id' => 'skip-link',
'class' => array(
'hide',
),
),
'skip_link' => array(
'#markup' => l(t('Skip to main content'), '', array(
'attributes' => array(
'class' => array(
'element-invisible',
'element-focusable',
),
),
'external' => TRUE,
'fragment' => 'content-regions',
)),
),
);
}
/**
* Implements template_preprocess_region().
*/
function compro_theme_preprocess_region(&$vars) {
$vars['attributes'] = drupal_attributes($vars['attributes_array']);
}
/**
* Implements template_preprocess_entity().
*/
function compro_theme_preprocess_entity(&$vars) {
$vars['classes_array'][] = drupal_html_class('view-mode-' . $vars['view_mode']);
}
/**
* Implements template_preprocess_node().
*/
function compro_theme_preprocess_node(&$vars) {
$vars['classes_array'][] = drupal_html_class('view-mode-' . $vars['view_mode']);
unset($vars['content']['links']);
}
/**
* Override or insert variables into the block templates.
*/
function compro_theme_preprocess_block(&$vars) {
// Classes describing the position of the block within the region.
if ($vars['block_id'] == 1) {
$vars['classes_array'][] = 'first';
}
// The last_in_region property is set in compro_theme_page_alter().
if (isset($vars['block']->last_in_region)) {
$vars['classes_array'][] = 'last';
}
}
/**
* Implementation of hook_theme().
*/
function compro_theme_theme() {
$items = array();
// Split out pager list into separate theme function.
$items['pager_list'] = array('arguments' => array(
'tags' => array(),
'limit' => 10,
'element' => 0,
'parameters' => array(),
'quantity' => 9,
));
return $items;
}
/**
* Implements hook_page_alter().
*/
function compro_theme_page_alter(&$page) {
// Look in each visible region for blocks.
foreach (system_region_list($GLOBALS['theme'], REGIONS_VISIBLE) as $region => $name) {
if (!empty($page[$region])) {
// Find the last block in the region.
$blocks = array_reverse(element_children($page[$region]));
while ($blocks && !isset($page[$region][$blocks[0]]['#block'])) {
array_shift($blocks);
}
if ($blocks) {
$page[$region][$blocks[0]]['#block']->last_in_region = TRUE;
}
}
}
}
/**
* Override of theme('breadcrumb').
*/
function compro_theme_breadcrumb($vars) {
$output = '<div class="breadcrumb">';
// 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;
$count = count($vars['breadcrumb']);
foreach ($vars['breadcrumb'] as $link) {
$output .= "<span class='breadcrumb-link breadcrumb-depth-{$depth}'>{$link}</span>";
$output .= ($depth < ($count - 1)) ? '<span class="delimiter">»</span>': '';
$depth++;
}
return $output . '</div>';
}
/**
* Override the default button theming to actually use buttons.
*/
function compro_theme_button($vars) {
$element = $vars['element'];
$element['#attributes']['type'] = 'submit';
element_set_attributes($element, array('id', 'name', 'value'));
$element['#attributes']['class'][] = 'form-' . $element['#button_type'];
if (!empty($element['#attributes']['disabled'])) {
$element['#attributes']['class'][] = 'form-button-disabled';
}
return '<button' . drupal_attributes($element['#attributes']) . '>' . $element['#value'] . '</button>';
}
/**
* Override of theme_image().
*/
function compro_theme_image($vars) {
$attributes = $vars['attributes'];
$attributes['src'] = file_create_url($vars['path']);
foreach (array('alt', 'title') as $key) {
if (isset($vars[$key])) {
$attributes[$key] = $vars[$key];
}
}
// Just in case there isn't an alt attribute by this point.
if (!isset($attributes['alt'])) {
$attributes['alt'] = '';
}
return '<img' . drupal_attributes($attributes) . ' />';
}
/**
* Override of theme_pager().
*/
function compro_theme_pager($vars) {
$tags = $vars['tags'];
$element = $vars['element'];
$parameters = $vars['parameters'];
$quantity = $vars['quantity'];
$pager_list = theme('pager_list', $vars);
$links = array();
$links['pager-first'] = theme('pager_first', array(
'text' => (isset($tags[0]) ? $tags[0] : t('First')),
'element' => $element,
'parameters' => $parameters
));
$links['pager-previous'] = theme('pager_previous', array(
'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
'element' => $element,
'interval' => 1,
'parameters' => $parameters
));
$links['pager-next'] = theme('pager_next', array(
'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
'element' => $element,
'interval' => 1,
'parameters' => $parameters
));
$links['pager-last'] = theme('pager_last', array(
'text' => (isset($tags[4]) ? $tags[4] : t('Last')),
'element' => $element,
'parameters' => $parameters
));
$links = array_filter($links);
$pager_links = theme('links', array(
'links' => $links,
'attributes' => array('class' => 'links pager pager-links')
));
if ($pager_list) {
return '<div class="pager clearfix">' . $pager_list . ' ' . $pager_links . '</div>';
}
}
/**
* Return an array suitable for theme_links() rather than marked up HTML link.
*/
function compro_theme_pager_link($vars) {
$text = $vars['text'];
$page_new = $vars['page_new'];
$element = $vars['element'];
$parameters = $vars['parameters'];
$attributes = $vars['attributes'];
$page = isset($_GET['page']) ? $_GET['page'] : '';
if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
$parameters['page'] = $new_page;
}
$query = array();
if (count($parameters)) {
$query = drupal_get_query_parameters($parameters, array());
}
if ($query_pager = pager_get_query_parameters()) {
$query = array_merge($query, $query_pager);
}
// Set each pager link title
if (!isset($attributes['title'])) {
static $titles = NULL;
if (!isset($titles)) {
$titles = array(
t('« first') => t('Go to first page'),
t('‹ previous') => t('Go to previous page'),
t('next ›') => t('Go to next page'),
t('last »') => t('Go to last page'),
);
}
if (isset($titles[$text])) {
$attributes['title'] = $titles[$text];
}
else if (is_numeric($text)) {
$attributes['title'] = t('Go to page @number', array('@number' => $text));
}
}
return array(
'title' => $text,
'href' => $_GET['q'],
'attributes' => $attributes,
'query' => count($query) ? $query : NULL,
);
}
/**
* Split out page list generation into its own function.
*/
function compro_theme_pager_list($vars) {
$tags = $vars['tags'];
$element = $vars['element'];
$parameters = $vars['parameters'];
$quantity = $vars['quantity'];
global $pager_page_array, $pager_total;
if ($pager_total[$element] > 1) {
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// first is the first page listed by this pager piece (re quantity)
$pager_first = $pager_current - $pager_middle + 1;
// last is the last page listed by this pager piece (re quantity)
$pager_last = $pager_current + $quantity - $pager_middle;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
// Prepare for generation loop.
$i = $pager_first;
if ($pager_last > $pager_max) {
// Adjust "center" if at end of query.
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
// Adjust "center" if at start of query.
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
// End of generation loop preparation.
$links = array();
// When there is more than one page, create the pager list.
if ($i != $pager_max) {
// Now generate the actual pager piece.
for ($i; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
$links["$i pager-item"] = theme('pager_previous', array(
'text' => $i,
'element' => $element,
'interval' => ($pager_current - $i),
'parameters' => $parameters
));
}
if ($i == $pager_current) {
$links["$i pager-current"] = array('title' => $i);
}
if ($i > $pager_current) {
$links["$i pager-item"] = theme('pager_next', array(
'text' => $i,
'element' => $element,
'interval' => ($i - $pager_current),
'parameters' => $parameters
));
}
}
return theme('links', array(
'links' => $links,
'attributes' => array('class' => 'links pager pager-list')
));
}
}
return '';
}
/**
* Override of theme('status_messages').
*/
function compro_theme_status_messages($vars) {
$output = '';
if (!isset($vars['messages'])) {
$display = $vars['display'];
$vars['messages'] = drupal_get_messages($display);
}
$status_heading = array(
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
);
if (count($vars['messages']) === 0) {
return '';
}
foreach ($vars['messages'] as $type => $messages) {
$output .= "<div class=\"messages $type\">\n";
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
}
else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
/**
* Override of theme('textarea').
* Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property.
*/
function compro_theme_textarea($vars) {
$element = $vars['element'];
$element['#attributes']['name'] = $element['#name'];
$element['#attributes']['id'] = $element['#id'];
$element['#attributes']['cols'] = $element['#cols'];
$element['#attributes']['rows'] = $element['#rows'];
_form_set_class($element, array('form-textarea'));
$wrapper_attributes = array(
'class' => array('form-textarea-wrapper'),
);
// Add resizable behavior.
if (!empty($element['#resizable'])) {
$wrapper_attributes['class'][] = 'resizable';
}
$output = '<div' . drupal_attributes($wrapper_attributes) . '>';
$output .= '<textarea' . drupal_attributes($element['#attributes']) . '>' . check_plain($element['#value']) . '</textarea>';
$output .= '</div>';
return $output;
}
/**
* Override of theme_views_mini_pager().
*/
function compro_theme_views_mini_pager($vars) {
$tags = $vars['tags'];
$quantity = $vars['quantity'];
$element = $vars['element'];
$parameters = $vars['parameters'];
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
$links = array();
if ($pager_total[$element] > 1) {
$links['pager-previous'] = theme('pager_previous', array(
'text' => (isset($tags[1]) ? $tags[1] : t('Prev')),
'element' => $element,
'interval' => 1,
'parameters' => $parameters
));
$links['pager-current'] = array(
'title' => t('@current of @max', array(
'@current' => $pager_current,
'@max' => $pager_max)
)
);
$links['pager-next'] = theme('pager_next', array(
'text' => (isset($tags[3]) ? $tags[3] : t('Next')),
'element' => $element,
'interval' => 1,
'parameters' => $parameters
));
return theme('links', array('links' => $links, 'attributes' => array('class' => array('links', 'pager', 'views-mini-pager'))));
}
}
/**
* Implements hook_css_alter()
*/
function compro_theme_css_alter(&$css) {
// Remove Drupal core CSS.
if (theme_get_setting('compro_theme_disable_core_css')) {
foreach($css as $path => $values) {
if(strpos($path, 'modules/') === 0) {
unset($css[$path]);
}
}
}
}