-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
441 lines (401 loc) · 14.5 KB
/
Copy pathtemplate.php
File metadata and controls
441 lines (401 loc) · 14.5 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
<?php
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('dclv2012_rebuild_registry')) {
drupal_rebuild_theme_registry();
}
// Add Zen Tabs styles
if (theme_get_setting('dclv2012_zen_tabs')) {
drupal_add_css( drupal_get_path('theme', 'dclv2012') .'/css/tabs.css', 'theme', 'screen');
}
/**
* This function creates the body classes that are relative to each page
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called ("page" in this case.)
*/
function dclv2012_preprocess_page(&$vars, $hook) {
// Don't display empty help from node_help().
if ($vars['help'] == "<div class=\"help\"><p></p>\n</div>") {
$vars['help'] = '';
}
// Classes for body element. Allows advanced theming based on context
// (home page, node of certain type, etc.)
$body_classes = array($vars['body_classes']);
if (user_access('administer blocks')) {
$body_classes[] = 'admin';
}
if (theme_get_setting('dclv2012_wireframe')) {
$body_classes[] = 'with-wireframes'; // Optionally add the wireframes style.
}
if (!empty($vars['primary_links']) or !empty($vars['secondary_links'])) {
$body_classes[] = 'with-navigation';
}
if (!empty($vars['secondary_links'])) {
$body_classes[] = 'with-secondary';
}
if (module_exists('taxonomy') && $vars['node']->nid) {
foreach (taxonomy_node_get_terms($vars['node']) as $term) {
$body_classes[] = 'tax-' . eregi_replace('[^a-z0-9]', '-', $term->name);
}
}
if (!$vars['is_front']) {
// Add unique classes for each page and website section
$path = drupal_get_path_alias($_GET['q']);
list($section, ) = explode('/', $path, 2);
$body_classes[] = dclv2012_id_safe('page-'. $path);
$body_classes[] = dclv2012_id_safe('section-'. $section);
if (arg(0) == 'node') {
if (arg(1) == 'add') {
if ($section == 'node') {
array_pop($body_classes); // Remove 'section-node'
}
$body_classes[] = 'section-node-add'; // Add 'section-node-add'
}
elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
if ($section == 'node') {
array_pop($body_classes); // Remove 'section-node'
}
$body_classes[] = 'section-node-'. arg(2); // Add 'section-node-edit' or 'section-node-delete'
}
}
}
/*// Check what the user's browser is and add it as a body class
// DEACTIVATED - Only works if page cache is deactivated
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if($user_agent) {
if (strpos($user_agent, 'MSIE')) {
$body_classes[] = 'browser-ie';
} else if (strpos($user_agent, 'MSIE 6.0')) {
$body_classes[] = 'browser-ie6';
} else if (strpos($user_agent, 'MSIE 7.0')) {
$body_classes[] = 'browser-ie7';
} else if (strpos($user_agent, 'MSIE 8.0')) {
$body_classes[] = 'browser-ie8';
} else if (strpos($user_agent, 'Firefox/2')) {
$body_classes[] = 'browser-firefox2';
} else if (strpos($user_agent, 'Firefox/3')) {
$body_classes[] = 'browser-firefox3';
}else if (strpos($user_agent, 'Safari')) {
$body_classes[] = 'browser-safari';
} else if (strpos($user_agent, 'Opera')) {
$body_classes[] = 'browser-opera';
}
}
/**
* Add template suggestions based on content type
* You can use a different page template depending on the
* content type or the node ID
* For example, if you wish to have a different page template
* for the story content type, just create a page template called
* page-type-story.tpl.php
* For a specific node, use the node ID in the name of the page template
* like this : page-node-22.tpl.php (if the node ID is 22)
*/
if ($vars['node']->type != "") {
$vars['template_files'][] = "page-type-" . $vars['node']->type;
}
if ($vars['node']->nid != "") {
$vars['template_files'][] = "page-node-" . $vars['node']->nid;
}
$vars['body_classes'] = implode(' ', $body_classes); // Concatenate with spaces
}
/**
* This function creates the NODES classes, like 'node-unpublished' for nodes
* that are not published, or 'node-mine' for node posted by the connected user...
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called ("node" in this case.)
*/
function dclv2012_preprocess_node(&$vars, $hook) {
// Special classes for nodes
$classes = array('node');
if ($vars['sticky']) {
$classes[] = 'sticky';
}
// support for Skinr Module
if (module_exists('skinr')) {
$classes[] = $vars['skinr'];
}
if (!$vars['status']) {
$classes[] = 'node-unpublished';
$vars['unpublished'] = TRUE;
}
else {
$vars['unpublished'] = FALSE;
}
if ($vars['uid'] && $vars['uid'] == $GLOBALS['user']->uid) {
$classes[] = 'node-mine'; // Node is authored by current user.
}
if ($vars['teaser']) {
$classes[] = 'node-teaser'; // Node is displayed as teaser.
}
$classes[] = 'clearfix';
// Class for node type: "node-type-page", "node-type-story", "node-type-my-custom-type", etc.
$classes[] = dclv2012_id_safe('node-type-' . $vars['type']);
$vars['classes'] = implode(' ', $classes); // Concatenate with spaces
}
function dclv2012_preprocess_comment_wrapper(&$vars) {
$classes = array();
$classes[] = 'comment-wrapper';
// Provide skinr support.
if (module_exists('skinr')) {
$classes[] = $vars['skinr'];
}
$vars['classes'] = implode(' ', $classes);
}
/**
* This function create the EDIT LINKS for blocks and menus blocks.
* When overing a block (except in IE6), some links appear to edit
* or configure the block. You can then edit the block, and once you are
* done, brought back to the first page.
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called ("block" in this case.)
*/
function dclv2012_preprocess_block(&$vars, $hook) {
$block = $vars['block'];
// special block classes
$classes = array('block');
$classes[] = dclv2012_id_safe('block-' . $vars['block']->module);
$classes[] = dclv2012_id_safe('block-' . $vars['block']->region);
$classes[] = dclv2012_id_safe('block-id-' . $vars['block']->bid);
$classes[] = 'clearfix';
// support for Skinr Module
if (module_exists('skinr')) {
$classes[] = $vars['skinr'];
}
$vars['block_classes'] = implode(' ', $classes); // Concatenate with spaces
if (theme_get_setting('dclv2012_block_editing') && user_access('administer blocks')) {
// Display 'edit block' for custom blocks.
if ($block->module == 'block') {
$edit_links[] = l('<span>' . t('edit block') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
array(
'attributes' => array(
'title' => t('edit the content of this block'),
'class' => 'block-edit',
),
'query' => drupal_get_destination(),
'html' => TRUE,
)
);
}
// Display 'configure' for other blocks.
else {
$edit_links[] = l('<span>' . t('configure') . '</span>', 'admin/build/block/configure/' . $block->module . '/' . $block->delta,
array(
'attributes' => array(
'title' => t('configure this block'),
'class' => 'block-config',
),
'query' => drupal_get_destination(),
'html' => TRUE,
)
);
}
// Display 'edit menu' for Menu blocks.
if (($block->module == 'menu' || ($block->module == 'user' && $block->delta == 1)) && user_access('administer menu')) {
$menu_name = ($block->module == 'user') ? 'navigation' : $block->delta;
$edit_links[] = l('<span>' . t('edit menu') . '</span>', 'admin/build/menu-customize/' . $menu_name,
array(
'attributes' => array(
'title' => t('edit the menu that defines this block'),
'class' => 'block-edit-menu',
),
'query' => drupal_get_destination(),
'html' => TRUE,
)
);
}
// Display 'edit menu' for Menu block blocks.
elseif ($block->module == 'menu_block' && user_access('administer menu')) {
list($menu_name, ) = split(':', variable_get("menu_block_{$block->delta}_parent", 'navigation:0'));
$edit_links[] = l('<span>' . t('edit menu') . '</span>', 'admin/build/menu-customize/' . $menu_name,
array(
'attributes' => array(
'title' => t('edit the menu that defines this block'),
'class' => 'block-edit-menu',
),
'query' => drupal_get_destination(),
'html' => TRUE,
)
);
}
$vars['edit_links_array'] = $edit_links;
$vars['edit_links'] = '<div class="edit">' . implode(' ', $edit_links) . '</div>';
}
// Add first/last block classes
$first_last = "";
// If block id (count) is 1, it's first in region.
if ($vars['block_id'] == '1') {
$first_last = " first";
$vars['block_classes'] .= $first_last;
}
// Count amount of blocks about to be rendered in that region.
$block_count = count(block_list($vars['block']->region));
if ($vars['block_id'] == $block_count) {
$first_last = " last";
$vars['block_classes'] .= $first_last;
}
}
/**
* Override or insert PHPTemplate variables into the block templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("comment" in this case.)
*/
function dclv2012_preprocess_comment(&$vars, $hook) {
// Add an "unpublished" flag.
$vars['unpublished'] = ($vars['comment']->status == COMMENT_NOT_PUBLISHED);
// If comment subjects are disabled, don't display them.
if (variable_get('comment_subject_field_' . $vars['node']->type, 1) == 0) {
$vars['title'] = '';
}
// Special classes for comments.
$classes = array('comment');
if ($vars['comment']->new) {
$classes[] = 'comment-new';
}
$classes[] = $vars['status'];
$classes[] = $vars['zebra'];
if ($vars['id'] == 1) {
$classes[] = 'first';
}
if ($vars['id'] == $vars['node']->comment_count) {
$classes[] = 'last';
}
if ($vars['comment']->uid == 0) {
// Comment is by an anonymous user.
$classes[] = 'comment-by-anon';
}
else {
if ($vars['comment']->uid == $vars['node']->uid) {
// Comment is by the node author.
$classes[] = 'comment-by-author';
}
if ($vars['comment']->uid == $GLOBALS['user']->uid) {
// Comment was posted by current user.
$classes[] = 'comment-mine';
}
}
$vars['classes'] = implode(' ', $classes);
}
/**
* Customize the PRIMARY and SECONDARY LINKS, to allow the admin tabs to work on all browsers
* An implementation of theme_menu_item_link()
*
* @param $link
* array The menu item to render.
* @return
* string The rendered menu item.
*/
function dclv2012_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
// If an item is a LOCAL TASK, render it as a tab
if ($link['type'] & MENU_IS_LOCAL_TASK) {
$link['title'] = '<span class="tab">' . check_plain($link['title']) . '</span>';
$link['localized_options']['html'] = TRUE;
}
return l($link['title'], $link['href'], $link['localized_options']);
}
/**
* Duplicate of theme_menu_local_tasks() but adds clear-block to tabs.
*/
function dclv2012_menu_local_tasks() {
$output = '';
if ($primary = menu_primary_local_tasks()) {
if(menu_secondary_local_tasks()) {
$output .= '<ul class="tabs primary with-secondary clearfix">' . $primary . '</ul>';
}
else {
$output .= '<ul class="tabs primary clearfix">' . $primary . '</ul>';
}
}
if ($secondary = menu_secondary_local_tasks()) {
$output .= '<ul class="tabs secondary clearfix">' . $secondary . '</ul>';
}
return $output;
}
/**
* Add custom classes to menu item
*/
function dclv2012_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
if ($in_active_trail) {
$class .= ' active-trail';
}
// New line added to get unique classes for each menu item
$css_class = dclv2012_id_safe(str_replace(' ', '_', strip_tags($link)));
return '<li class="'. $class . ' ' . $css_class . '">' . $link . $menu ."</li>\n";
}
/**
* Converts a string to a suitable html ID attribute.
*
* http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
* valid ID attribute in HTML. This function:
*
* - Ensure an ID starts with an alpha character by optionally adding an 'n'.
* - Replaces any character except A-Z, numbers, and underscores with dashes.
* - Converts entire string to lowercase.
*
* @param $string
* The string
* @return
* The converted string
*/
function dclv2012_id_safe($string) {
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
// If the first character is not a-z, add 'n' in front.
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
$string = 'id'. $string;
}
return $string;
}
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function dclv2012_breadcrumb($breadcrumb) {
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('dclv2012_breadcrumb');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('dclv2012_breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
// Return the breadcrumb with separators.
if (!empty($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('dclv2012_breadcrumb_separator');
$trailing_separator = $title = '';
if (theme_get_setting('dclv2012_breadcrumb_title')) {
if ($title = drupal_get_title()) {
$trailing_separator = $breadcrumb_separator;
}
}
elseif (theme_get_setting('dclv2012_breadcrumb_trailing')) {
$trailing_separator = $breadcrumb_separator;
}
return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator$title</div>";
}
}
// Otherwise, return an empty string.
return '';
}