forked from developmentseed/jake
/
template.php
299 lines (271 loc) · 9.11 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
<?php
/**
* Implementation of hook_theme().
*/
function jake_theme($existing, $type, $theme, $path) {
return array(
'site_name' => array(),
'print_logo' => array(),
);
}
/**
* Move taxonomy back to first node edit page.
*/
function jake_preprocess_node_form(&$vars) {
$vars['form']['taxonomy'] = $vars['sidebar']['taxonomy'];
unset($vars['sidebar']['taxonomy']);
}
/**
* Preprocessor for theme('help').
*/
function jake_preprocess_help(&$vars) {
$vars['title'] = t('Need help?');
$vars['layout'] = FALSE;
$vars['attr'] = array();
$vars['links'] = '';
}
/**
* Preprocessor for theme('page').
*/
function jake_preprocess_page(&$vars) {
// Help link
if (!empty($vars['help'])) {
$vars['help_link'] = l('?', $_GET['q'], array('fragment' => 'help', 'attributes' => array('class' => 'help-link')));
}
// Admin link
if (user_access('administer mn')) {
$vars['admin_link'] = l(t('Admin'), 'admin/settings/site-information', array('attributes' => array('class' => 'admin-link')));
}
// Add body class for layout.
$vars['attr']['class'] .= !empty($vars['template_files']) ? ' '. end($vars['template_files']) : '';
// Site name
$vars['site_name'] = theme('site_name');
// Display mission in a block
if (!empty($vars['mission']) && drupal_is_front_page()) {
$mission_block = new stdClass();
$mission_block->content = $vars['mission'];
$vars['mission_block'] = theme('block', $mission_block);
}
// Truncate the slogan so it doesn't break the header
$vars['site_slogan'] = truncate_utf8($vars['site_slogan'], 35);
// Determine stack height for fullscreen views.
$class = array();
if ($stackclass = context_get('theme', 'stackclass')) {
$class[] = $stackclass;
}
if (!empty($vars['tabs'])) {
$class[] = 'tabs';
}
if (!empty($class)) {
$vars['attr']['class'] .= ' with-'. implode('-', $class);
}
}
/**
* Preprocessor for theme('block').
*/
function jake_preprocess_block(&$vars) {
if ($vars['block']->region === 'palette') {
if (!empty($vars['title'])) {
$toggler = l($vars['title'], $_GET['q'], array('fragment' => "{$vars['block']->module}-{$vars['block']->delta}", 'attributes' => array('class' => 'palette-link', 'title' => $vars['block']->subject)));
$vars['pre_object'] = "<div class='widget widget-toggle widget-{$vars['block']->module}-{$vars['block']->delta}'>{$toggler}</div>";
$vars['attr']['class'] .= ' block-toggle';
}
else {
$vars['attr']['class'] .= ' widget';
}
}
$classgroups = array(
'utility-block' => array(
'mn_search-status',
'data_node-data_table_feedapi_feed',
'stored_views-save',
),
);
$bid = "{$vars['block']->module}-{$vars['block']->delta}";
if ($bid == 'stored_views-save') {
context_set('theme', 'stackclass', 'search');
}
foreach ($classgroups as $class => $blocks) {
if (in_array($bid, $blocks)) {
$vars['attr']['class'] .= " {$class}";
}
}
}
/**
* Preprocessor for theme_context_block_editable_region().
*/
function jake_preprocess_context_block_editable_region(&$vars) {
if (in_array($vars['region'], array('page_title', 'palette', 'page_tools'))) {
$vars['editable'] = FALSE;
}
}
/**
* Helper function to render views fields.
*/
function jake_views_render_field(&$field, $skip = TRUE) {
$output = '';
if (is_array($field) && count($field) && is_object(current($field))) {
foreach ($field as $k => $f) {
$output .= jake_views_render_field($field[$k]);
}
}
else if (is_object($field)) {
// Skip rendered fields
if (empty($field->rendered) || !$skip) {
if (!empty($field->content)) {
$output .= !empty($field->separator) ? $field->separator : '';
$output .= "<{$field->inline_html} class='views-field-{$field->class}'>";
$output .= !empty($field->label) ? "<label class='views-label-{$field->class};'>{$field->label}</label>" : '';
$output .= "<{$field->element_type} class='field-content'>{$field->content}</{$field->element_type}>";
$output .= "</{$field->inline_html}>";
}
$field->rendered = TRUE;
}
}
return $output;
}
/**
* Preprocessor for theme('node').
*/
function jake_preprocess_node(&$vars) {
$vars['layout'] = FALSE;
// Don't show node title on page views
if (menu_get_object() === $vars['node']) {
if (!isset($_GET['print'])) {
unset($vars['title']);
}
$vars['attr']['class'] .= ' node-page';
}
else {
$vars['attr']['class'] .= ' node-teaser';
}
// We don't want the print friendly header on individual nodes.
if (isset($vars['pre_object'])) {
unset($vars['pre_object']);
}
}
/**
* Preprocessor for theme('flot_views_style').
* Supply DesignKit colors to OpenLayers styles.
*/
function jake_preprocess_flot_views_style(&$vars) {
static $id = 0;
$id++;
$color = variable_get('designkit_color', array());
$vars['options']->colors = array(!empty($color['foreground_color']) ? $color['foreground_color'] : '#ace');
$vars['options']->lines->fill = .25;
$vars['options']->grid->tickColor = '#eee';
$vars['options']->grid->backgroundColor = '#fff';
$id_string = $vars['element']['id'] = "jake-flot-{$id}";
// Add js to vars rather than calling drupal_add_js() directly.
// This gives subthemes a chance to override this JS or omit it altogether
// by overriding via preprocess or altering the flot-views-style template.
$vars['js'] = array();
// Label js.
$labels = array();
foreach ($vars['data'][0]->data as $point) {
$labels[$point[0]] = format_date($point[0], 'custom', 'g:00a F j Y');
}
$vars['js']['flot_labels'] = $labels;
// Hover tips.
$inline_js = "$('#{$id_string}').bind('plothover', function (event, pos, item) {
if (item) {
var parent = $('#{$id_string}').offset();
if (Drupal.settings.flot_labels[item.datapoint[0]]) {
var date = Drupal.settings.flot_labels[item.datapoint[0]];
if (item.datapoint[1] == 1) {
var text = '<strong>' + item.datapoint[1] + ' story</strong> ' + date;
}
else {
var text = '<strong>' + item.datapoint[1] + ' stories</strong> ' + date;
}
$('#{$id_string}').siblings('div.flot-caption').html(text);
}
}
else {
$('#{$id_string}').siblings('div.flot-caption').html('');
}
});";
$vars['js']['inline'] = $inline_js;
}
/**
* Override of theme_openlayers_styles().
* Supply DesignKit colors to OpenLayers styles.
*/
function jake_openlayers_styles($styles = array(), $map = array()) {
$color = variable_get('designkit_color', array());
if (isset($styles['default'])) {
$styles['default']['fillColor'] = !empty($color['foreground_color']) ? $color['foreground_color'] : '#ace';
$styles['default']['strokeColor'] = !empty($color['foreground_color']) ? $color['foreground_color'] : '#ace';
}
return $styles;
}
/**
* Override of theme_status_message().
*/
function jake_status_messages($display = NULL) {
$output = '';
$first = TRUE;
$autoclose = array('status' => 1, 'warning' => 0, 'error' => 0);
foreach (drupal_get_messages($display) as $type => $messages) {
$class = $first ? 'first' : '';
$class .= !empty($autoclose[$type]) || !isset($autoclose[$type]) ? ' autoclose' : '';
$first = FALSE;
$output .= "<div class='messages clear-block $type $class'>";
$output .= l(t('Close'), $_GET['q'], array('fragment' => 'close', 'attributes' => array('class' => 'close')));
$output .= "<div class='message-content'>";
if (count($messages) > 1) {
$output .= "<ul>";
foreach ($messages as $k => $message) {
if ($k == 0) {
$output .= "<li class='message-item first'>$message</li>";
}
else if ($k == count($messages) - 1) {
$output .= "<li class='message-item last'>$message</li>";
}
else {
$output .= "<li class='message-item'>$message</li>";
}
}
$output .= "</ul>";
}
else {
$output .= $messages[0];
}
$output .= "</div>";
$output .= "</div>";
}
return $output;
}
/**
* Theme function for generating a site logo/name.
*/
function jake_site_name() {
$image = variable_get('designkit_image', array());
$name = check_plain(variable_get('site_name', 'Drupal'));
if (!empty($image['logo'])) {
return l(t($name), '<front>', array('attributes' => array('class' => 'logo')));
}
return l(t($name), '<front>');
}
/**
* Preprocess for theme('print_header').
*/
function jake_preprocess_print_header(&$vars) {
$vars['site_name'] = theme('print_logo');
$vars['date'] = format_date(time(), 'large');
}
/**
* Print logo.
*/
function jake_print_logo() {
$settings = theme_get_settings('jake');
$name = check_plain(variable_get('site_name', 'Drupal'));
if (!empty($settings['printlogo_path']) && file_exists($settings['printlogo_path']) && module_exists('imagecache') && imagecache_preset_by_name('logo_print')) {
$url = imagecache_create_url('logo_print', $settings['printlogo_path']);
$image = "<img src='{$url}' title='{$name}' class='logo'/>";
return l($image, '<front>', array('html' => TRUE, 'attributes' => array('class' => 'logo')));
}
// Last resort, use just the name
return l(t($name), '<front>');
}