/
template.php
369 lines (333 loc) · 12.8 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
<?php
// $Id: template.php,v 1.4.2.6 2011/02/18 05:26:30 andregriffin Exp $
/**
* Implements hook_preprocess_html().
* Adding extra meta tags to the head for iPhone, Google domain verification
*/
function webskillet14_preprocess_html(&$vars) {
$meta_xuacompatible = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge,chrome=1'
)
);
drupal_add_html_head($meta_xuacompatible, 'meta_xuacompatible');
$meta_viewport = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, maximum-scale=1.0'
)
);
drupal_add_html_head($meta_viewport, 'meta_viewport');
$q = isset($_GET['q']) ? $_GET['q'] : 'front';
$page_id = str_replace('/','-',$q);
$page_id = strtolower($page_id);
$page_id = preg_replace('/[^-_a-z0-9]/','',$page_id);
$vars['page_id'] = 'page-'.$page_id;
$googlefonts = theme_get_setting('webskillet14_google_webfonts');
if ($googlefonts) {
drupal_add_css('//fonts.googleapis.com/css?family='.$googlefonts,array(
'type' => 'external',
'group' => CSS_SYSTEM,
'every_page' => TRUE,
'weight' => -100,
));
}
if (theme_get_setting('webskillet14_load_fontawesome')) {
drupal_add_css('//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css',array(
'type' => 'external',
'group' => CSS_SYSTEM,
'every_page' => TRUE,
'weight' => -99,
));
}
/*
$meta_google_site_verification = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'google-site-verification',
'content' => 'RPsvU9KSNxdpmMt1ejPTeTAnH6DsklrG2Ic7HSpyIec'
)
);
drupal_add_html_head($meta_google_site_verification, 'meta_google_site_verification');
*/
}
/**
* Implements hook_html_head_alter().
* We are overwriting the default meta character type tag with HTML5 version.
*/
function webskillet14_html_head_alter(&$head_elements) {
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8'
);
}
/**
* Implements hook_process_html()
*/
function webskillet14_process_html(&$variables) {
// here are the witdh calculatings and some scrips addings
if (theme_get_setting('webskillet14_custom_css')) {
$variables['styles'] .= '<script type="text/javascript"></script>'; /* Needed to avoid Flash of Unstyle Content in IE */
$variables['styles'] .= '<style type="text/css">
' . theme_get_setting('webskillet14_custom_css') . '
</style>';
}
if (theme_get_setting('webskillet14_custom_js')) {
$variables['scripts'] .= '<script type="text/javascript">
' . theme_get_setting('webskillet14_custom_js') . '
</script>';
}
}
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return a string containing the breadcrumb output.
*/
function webskillet14_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$output = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
// Uncomment to add current page to breadcrumb
// $breadcrumb[] = drupal_get_title();
$output .= '<nav class="breadcrumb">' . implode(' » ', $breadcrumb) . '</nav>';
return $output;
}
}
/**
* Override or insert variables into the page template.
*/
function webskillet14_preprocess_page(&$vars) {
/* first version from framework theme, more accessible - 2nd for dropdowns */
/*
if (isset($vars['main_menu'])) {
$vars['main_menu'] = theme('links__system_main_menu', array(
'links' => $vars['main_menu'],
'attributes' => array(
'class' => array('links', 'main-menu', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
)
));
}
else {
$vars['main_menu'] = FALSE;
}
*/
/*
// for multi-lingual menus, replace the first two lines below with these 4 lines:
$src = variable_get('menu_main_links_source', 'main-menu');
$tree = function_exists('i18n_menu_translated_tree') ? i18n_menu_translated_tree($src) : menu_tree($src);
$vars['main_menu'] = drupal_render($tree);
$vars['main_menu'] = str_replace('class="menu"','class="main-menu"',$vars['main_menu']);
// for multi-lingual om_maximenu menus, see here: https://drupal.org/node/1459416
*/
if (isset($vars['main_menu'])) {
$menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
$menutitle = "Navigation";
if (theme_get_setting('webskillet14_load_fontawesome')) {
$menutitle = '<i class="fa fa-bars"></i> <span>'.$menutitle.'</span>';
}
$vars['main_menu'] = drupal_render($menu_tree);
$vars['main_menu'] = str_replace('class="menu"','class="main-menu"',$vars['main_menu']);
$vars['main_menu'] = "<h2 class=\"navigation-header\">".$menutitle."</h2>".$vars['main_menu'];
}
else {
$vars['main_menu'] = FALSE;
}
if (isset($vars['secondary_menu'])) {
$vars['secondary_menu'] = theme('links__system_secondary_menu', array(
'links' => $vars['secondary_menu'],
'attributes' => array(
'id' => 'utility-menu-links',
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => t('Utility menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
} else {
$vars['secondary_menu'] = FALSE;
}
}
/**
* Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
*/
function webskillet14_menu_local_tasks(&$variables) {
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<ul class="tabs primary clearfix">';
$variables['primary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['primary']);
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<ul class="tabs secondary clearfix">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($variables['secondary']);
}
return $output;
}
/**
* Override or insert variables into the node template.
*/
function webskillet14_preprocess_node(&$variables) {
$variables['submitted'] = t('Published by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
$variables['classes_array'][] = 'node-full';
}
$variables['twitterHashtag'] = theme_get_setting('webskillet14_twitter_hashtag');
$variables['twitterHandle'] = theme_get_setting('webskillet14_twitter_handle');
}
/**
* Changes the search form to use the "search" input element of HTML5 and the input.populate in wsutil
* also add class="search" so IE7 can find it using css selectors
*/
function webskillet14_preprocess_search_block_form(&$vars) {
$vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
$vars['search_form'] = str_replace('class="form-text"', 'class="populate form-text search"', $vars['search_form']);
$vars['search_form'] = str_replace('type="submit"', 'type="image" src="'.base_path().path_to_theme().'/images/btn-search.png" width="20" height="20"', $vars['search_form']);
}
/**
* The following functions are helper functions available to the theme,
* but do not do anything on their own
*/
/**
* Provides unique id for body element based on url
*/
function wsUtil_body_id() {
$q = isset($_GET['q']) ? $_GET['q'] : 'front';
$body_id = str_replace('/','-',$q);
$body_id = strtolower($body_id);
$body_id = preg_replace('/[^-_a-z0-9]/','',$body_id);
return 'body-'.$body_id;
}
/**
* Provides urls for Facebook sharing, tweeting and emails
*/
function wsUtil_share_url($url, $title='', $service='facebook', $options=array()) {
$site_url = 'http://' .$_SERVER['HTTP_HOST'];
if (strpos($url, $site_url) === false) { $url = $site_url.$url; }
switch ($service) {
case 'facebook':
$fbShareUrl = 'http://www.facebook.com/sharer.php?u='.urlencode($url);
if ($title) { $fbShareUrl .= '&t='.urlencode(html_entity_decode($title, ENT_QUOTES)); }
return $fbShareUrl;
break;
case 'twitter':
$twitterHashtag = isset($options['twitterHashtag']) ? $options['twitterHashtag'] : '';
$twitterHandle = isset($options['twitterHandle']) ? $options['twitterHandle'] : '';
$tweetUrl = 'https://twitter.com/intent/tweet?';
$tweetUrl .= 'url='.urlencode($url);
$tweetUrl .= $title ? '&text='.urlencode(html_entity_decode($title, ENT_QUOTES)) : '';
$tweetUrl .= $twitterHashtag ? '&hashtags='.urlencode(html_entity_decode($twitterHashtag, ENT_QUOTES)) : '';
$tweetUrl .= $twitterHandle ? '&via='.urlencode(html_entity_decode($twitterHandle, ENT_QUOTES)) : '';
return $tweetUrl;
break;
case 'email':
$emailSubject = isset($options['emailSubject']) ? $options['emailSubject'] : '';
$emailBody = (isset($options['emailBody']) && $options['emailBody']) ? $options['emailBody']."\n\n" : '';
$emailUrl = "mailto:?";
$emailUrl .= $emailSubject ? 'subject='.str_replace('+','%20',urlencode(html_entity_decode($emailSubject, ENT_QUOTES))).'&' : '';
$emailUrl .= 'body='.str_replace('+','%20',urlencode(html_entity_decode($emailBody.$url, ENT_QUOTES)));
return $emailUrl;
break;
default:
return '';
break;
}
}
/**
* Provides text or icons for facebook sharing, tweeting, and emailing
*/
function wsUtil_share_text($service = 'facebook') {
switch ($service) {
case 'facebook':
$icon = 'fa-facebook-square';
$text = 'Share on Facebook';
break;
case 'twitter':
$icon = 'fa-twitter-square';
$text = 'Tweet on Twitter';
break;
case 'email':
$icon = 'fa-envelope';
$text = 'Send by email';
break;
default:
return '';
break;
}
if (theme_get_setting('webskillet14_load_fontawesome')) {
$text = "<i class=\"fa $icon\"></i> <span class=\"element-invisible\">$text</span>";
}
return $text;
}
/**
* Handles video
*/
function wsUtil_wrap_video($embedCode) {
// first, add wmode=opaque to youtube, if it's not already there
preg_match('/src=(\'|")([^\'"]+)(\'|")/',$embedCode,$src_matches);
$src = isset($src_matches[2]) ? $src_matches[2] : '';
if (strpos($src,'youtube.com') || strpos($src,'youtu.be')) {
if (!strpos($src,'wmode=opaque')) {
$newsrc = $src . (strpos($src,'?') ? '&' : '?') . 'wmode=opaque';
$embedCode = str_replace($src, $newsrc, $embedCode);
}
}
preg_match('/height=(\'|")([0-9]+)(\'|")/',$embedCode,$height_matches);
preg_match('/width=(\'|")([0-9]+)(\'|")/',$embedCode,$width_matches);
$height = isset($height_matches[2]) ? $height_matches[2] : 0;
$width = isset($width_matches[2]) ? $width_matches[2] : 0;
if ($height && $width) {
$aspect_ratio = ($width > 0) ? $height / $width : 0;
$embedCode = preg_replace('/height=(\'|")[0-9]+(\'|")/','height="100%"',$embedCode);
$embedCode = preg_replace('/width=(\'|")[0-9]+(\'|")/','width="100%"',$embedCode);
return sprintf('<div class="video-container" style="padding-bottom: %.2f%%">%s</div>', $aspect_ratio * 100, $embedCode);
} else {
return $embedCode;
}
}
function wsUtil_get_video_thumb($embedCode, $largethumb = 0) {
$largethumb = ($largethumb == 1) ? 1 : 0;
preg_match('#//player.vimeo.com/video/([0-9]+)#',$embedCode,$vm_matches);
$vimeoId = isset($vm_matches[1]) ? $vm_matches[1] : '';
if ($vimeoId) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_URL, "http://vimeo.com/api/v2/video/$vimeoId.xml");
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
return $largethumb ? (string) $xml->video>thumbnail_large : (string) $xml->video->thumbnail_medium;
}
preg_match('#//(www\.)?youtu(be\.com|\.be)/embed/([^?"\']+)#',$embedCode,$yt_matches);
$youTubeId = isset($yt_matches[3]) ? $yt_matches[3] : '';
if ($youTubeId) { return sprintf('http://img.youtube.com/vi/%s/%d.jpg',$youTubeId,1-$largethumb); }
return base_path().path_to_theme().'/images/bg-video.png';
}
function wsUtil_get_video_link($embedCode) {
preg_match('#//player.vimeo.com/video/([0-9]+)#',$embedCode,$vm_matches);
$vimeoId = isset($vm_matches[1]) ? $vm_matches[1] : '';
if ($vimeoId) { return 'http://vimeo.com/'.$vimeoId; }
preg_match('#//(www\.)?youtu(be\.com|\.be)/embed/([^?"\']+)#',$embedCode,$yt_matches);
$youTubeId = isset($yt_matches[3]) ? $yt_matches[3] : '';
if ($youTubeId) { return 'http://youtube.com/watch?v='.$youTubeId; }
return null;
}