This repository has been archived by the owner on Aug 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.php
284 lines (259 loc) · 9.64 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
<?php
// $Id: template.php,v 1.17.2.1 2009/02/13 06:47:44 johnalbin Exp $
/**
* @file
* Contains theme override functions and preprocess functions for the theme.
*
* ABOUT THE TEMPLATE.PHP FILE
*
* The template.php file is one of the most useful files when creating or
* modifying Drupal themes. You can add new regions for block content, modify
* or override Drupal's theme functions, intercept or make additional
* variables available to your theme, and create custom PHP logic. For more
* information, please visit the Theme Developer's Guide on Drupal.org:
* http://drupal.org/theme-guide
*
* OVERRIDING THEME FUNCTIONS
*
* The Drupal theme system uses special theme functions to generate HTML
* output automatically. Often we wish to customize this HTML output. To do
* this, we have to override the theme function. You have to first find the
* theme function that generates the output, and then "catch" it and modify it
* here. The easiest way to do it is to copy the original function in its
* entirety and paste it here, changing the prefix from theme_ to STARTERKIT_.
* For example:
*
* original: theme_breadcrumb()
* theme override: STARTERKIT_breadcrumb()
*
* where STARTERKIT is the name of your sub-theme. For example, the
* zen_classic theme would define a zen_classic_breadcrumb() function.
*
* If you would like to override any of the theme functions used in Zen core,
* you should first look at how Zen core implements those functions:
* theme_breadcrumbs() in zen/template.php
* theme_menu_item_link() in zen/template.php
* theme_menu_local_tasks() in zen/template.php
*
* For more information, please visit the Theme Developer's Guide on
* Drupal.org: http://drupal.org/node/173880
*
* CREATE OR MODIFY VARIABLES FOR YOUR THEME
*
* Each tpl.php template file has several variables which hold various pieces
* of content. You can modify those variables (or add new ones) before they
* are used in the template files by using preprocess functions.
*
* This makes THEME_preprocess_HOOK() functions the most powerful functions
* available to themers.
*
* It works by having one preprocess function for each template file or its
* derivatives (called template suggestions). For example:
* THEME_preprocess_page alters the variables for page.tpl.php
* THEME_preprocess_node alters the variables for node.tpl.php or
* for node-forum.tpl.php
* THEME_preprocess_comment alters the variables for comment.tpl.php
* THEME_preprocess_block alters the variables for block.tpl.php
*
* For more information on preprocess functions and template suggestions,
* please visit the Theme Developer's Guide on Drupal.org:
* http://drupal.org/node/223440
* and http://drupal.org/node/190815#template-suggestions
*/
/*
* Add any conditional stylesheets you will need for this sub-theme.
*
* To add stylesheets that ALWAYS need to be included, you should add them to
* your .info file instead. Only use this section if you are including
* stylesheets based on certain conditions.
*/
/* -- Delete this line if you want to use and modify this code
// Example: optionally add a fixed width CSS file.
if (theme_get_setting('danablu_fixed')) {
drupal_add_css(path_to_theme() . '/layout-fixed.css', 'theme', 'all');
}
// */
/**
* Implementation of HOOK_theme().
*/
function danablu_theme(&$existing, $type, $theme, $path) {
$hooks = zen_theme($existing, $type, $theme, $path);
// Define our own theming function for creating tab-style links.
$hooks['tab_links'] = array(
'arguments' => array('links' => array(), 'attributes' => array()),
);
return $hooks;
}
/**
* Override or insert variables into all templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered (name of the .tpl.php file.)
*/
/* -- Delete this line if you want to use this function
function danablu_preprocess(&$vars, $hook) {
$vars['sample_variable'] = t('Lorem ipsum.');
}
// */
/**
* Override or insert variables into the page templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("page" in this case.)
*/
function danablu_preprocess_page(&$vars, $hook) {
if ($vars['primary_links'] || $vars['secondary_links'] || $vars['navbar']) {
$vars['body_classes_array'][] = 'with-navbar';
}
if ($vars['preface_first'] || $vars['preface_middle'] || $vars['preface_last']) {
$vars['body_classes_array'][] = 'has-preface';
}
if ($vars['postscript_first'] || $vars['postscript_middle'] || $vars['postscript_last']) {
$vars['body_classes_array'][] = 'has-postscript';
}
$vars['body_classes'] = implode(' ', $vars['body_classes_array']);
}
/**
* Override or insert variables into the location templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("location" in this case.)
*/
function danablu_preprocess_location(&$vars, $hook) {
if ($vars['latitude'] && $vars['longitude']) {
$map_url = url('http://maps.google.com/maps/api/staticmap', array(
'external' => TRUE,
'query' => array(
'markers' => 'color:0x0077C0|' . $vars['latitude'] . ',' . $vars['longitude'],
'language' => 'da',
'size' => '180x200',
'zoom' => 15,
'sensor' => 'false',
)));
$vars['location_map_image'] = theme('image', $map_url, '', '', array('height' => 200, 'width' => 180), FALSE);
}
}
/**
* Override or insert variables into the comment 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.)
*/
/* -- Delete this line if you want to use this function
function danablu_preprocess_comment(&$vars, $hook) {
$vars['sample_variable'] = t('Lorem ipsum.');
}
// */
/**
* Override or insert 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 ("block" in this case.)
*/
/* -- Delete this line if you want to use this function
function danablu_preprocess_block(&$vars, $hook) {
$vars['sample_variable'] = t('Lorem ipsum.');
}
// */
/**
* Theme tabbed links
*
* Copy of Drupal's theme_links function with a few extra tricks.
*
* @param array $links
* A keyed array of links to be themed.
* @param array $attributes
* A keyed array of attributes.
* @return string
* An HTML string containing an unordered list of links.
*/
function danablu_tab_links($links, $attributes = array('class' => 'links tab-links')) {
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href'])) {
// Add some spans to the content of a-tag
$link_content = '<span class="tab-icon"> </span><span class="tab-text"><span>' . check_plain($link['title']) . '</span></span>';
// Set html TRUE so that our spans are preserved in the final a-tag.
$link['html'] = TRUE;
// Pass in $link as $options, they share the same keys.
$output .= l($link_content, $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
function danablu_node_form($form) {
// Add js for job node form.
if (isset($form['#node']->type) && $form['#node']->type == 'job') {
drupal_add_js(drupal_get_path('theme', 'danablu') . '/js/job-node-form.js');
}
$output = "\n<div class=\"node-form\">\n";
// Admin form fields and submit buttons must be rendered first, because
// they need to go to the bottom of the form, and so should not be part of
// the catch-all call to drupal_render().
$admin = '';
if (isset($form['author'])) {
$admin .= " <div class=\"authored\">\n";
$admin .= drupal_render($form['author']);
$admin .= " </div>\n";
}
if (isset($form['options'])) {
$admin .= " <div class=\"options\">\n";
$admin .= drupal_render($form['options']);
$admin .= " </div>\n";
}
$buttons = drupal_render($form['buttons']);
// Everything else gets rendered here, and is displayed before the admin form
// field and the submit buttons.
$output .= " <div class=\"standard\">\n";
$output .= drupal_render($form);
$output .= " </div>\n";
if (!empty($admin)) {
$output .= " <div class=\"admin\">\n";
$output .= $admin;
$output .= " </div>\n";
}
$output .= $buttons;
$output .= "</div>\n";
return $output;
}