-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
192 lines (179 loc) · 7.7 KB
/
template.php
File metadata and controls
192 lines (179 loc) · 7.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
<?php
/**
* Remove and add elements in head
*/
function makeitso_html_head_alter(&$head_elements) {
// remove generator meta tag
unset($head_elements['system_meta_generator']);
// add following meta tags
$head_elements['viewporttag'] = array('#type' => 'html_tag','#tag' => 'meta','#attributes' => array('name' => 'viewport','content' => 'width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=10.0',),'#weight' => 0,);
$head_elements['x-ua-compat'] = array('#type' => 'html_tag','#tag' => 'meta','#attributes' => array('http_equiv' => 'X-UA-Compatible','content' => 'IE=edge,chrome=1',),'#weight' => 0,);
$head_elements['apple_icon'] = array('#type' => 'html_tag','#tag' => 'link','#attributes' => array('href' => base_path() . path_to_theme() .'/apple-touch-icon.png','rel' => 'apple-touch-icon-precomposed',),'#weight' => 2,);
$head_elements['gen_favicon'] = array('#type' => 'html_tag','#tag' => 'link','#attributes' => array('href' => base_path() . path_to_theme() .'/favicon.ico','rel' => 'shortcut icon',),'#weight' => 1,);
$head_elements['system_meta_content_type']['#attributes'] = array('charset' => 'utf-8');
drupal_add_html_head($head_elements, 'gen_favicon');
drupal_add_html_head($head_elements, 'apple_icon');
drupal_add_html_head($head_elements, 'viewporttag');
drupal_add_html_head($head_elements, 'x-ua-compat');
// do not allow IOS/Android to alter telephone links automagically, by setting this meta tag
$meta_ios_tel_links = array('#type' => 'html_tag','#tag' => 'meta','#attributes' => array('name' => 'format-detection','content' => 'telephone=no'));
drupal_add_html_head($meta_ios_tel_links, 'meta_ios_tel_links');
}
/**
* Alter html(.tpl.php)
*/
function makeitso_preprocess_html (&$variables) {
// add old_ie.css stylesheet for old Internet Explorer browsers support
drupal_add_css(drupal_get_path('theme', 'makeitso') . '/css/old_ie.css', array('group' => CSS_THEME,'browsers' => array('IE' => 'lte IE 8','!IE' => FALSE),'preprocess' => FALSE));
// add aside class to body if aside region is present. Used for theming purposes
if (!empty($variables['page']['aside'])) {$variables['classes_array'][] = 'aside';}
}
/**
* Unset drupal base theming if needed for custom front-end theme
*/
function makeitso_css_alter(&$css) {
//unset($css[drupal_get_path('module','system').'/system.base.css']);
unset($css[drupal_get_path('module','system').'/system.menus.css']);
unset($css[drupal_get_path('module','system').'/system.theme.css']);
}
/**
* Override or insert variables into the page template.
*/
function makeitso_preprocess_page(&$variables) {
// page template suggestions base on node type: page--type--interview, page--type--cursus, etc.
if (!empty($variables['node'])) {
$variables['theme_hook_suggestions'][] = 'page__type__' . $variables['node']->type;
}
// move secondary tabs into a separate variable.
$variables['tabs2'] = array(
'#theme' => 'menu_local_tasks',
'#secondary' => $variables['tabs']['#secondary'],
);
unset($variables['tabs']['#secondary']);
// template suggestions to target specific taxonomy voc. pages based on voc.id page--vocabulary--id
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$tid = arg(2);
$vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
$variables['theme_hook_suggestions'][] = 'page__vocabulary__' . $vid;
}
// put the search block form in a separate variable '$searchblock' for use in page.tpl
$customsearchblock = module_invoke('search','block_view','search');
$customsearchrendered_block = render($customsearchblock);
$variables['searchblock'] = $customsearchrendered_block;
}
/**
* Override or insert variables into the node template.
*/
function makeitso_preprocess_node(&$variables) {
// add node-full class to node
if ($variables['elements']['#view_mode'] == 'full') {
$variables['classes_array'][] = 'main-content node-full';
}
// add node-teaser class to node if teaser
if ($variables['elements']['#view_mode'] == 'teaser') {
$variables['classes_array'][] = 'node-teaser';
}
}
/**
* Override or insert variables into the block template.
*/
function makeitso_preprocess_block(&$variables) {
$block = $variables['block'];
// add a simple edit link to blocks for priviliged users
if (user_access('administer blocks') && $block->module == "block"){
$variables['content'] = l(t('edit'), 'admin/structure/block/manage/block/' . $block->delta, array('attributes'=>array('class'=>'block_edit', 'title'=>'edit '.$block->subject.' block'), 'query'=>drupal_get_destination())). $variables['content'];
}
}
/**
* Remove wrapping div excess from drupal fields-module fields
*/
function makeitso_field(&$variables) {
$output = '';
// Render the label, if it's not hidden.
if (!$variables ['label_hidden']) {
$output .= '<div class="field-label"' . $variables ['title_attributes'] . '>' . $variables ['label'] . ': </div>';
}
foreach ($variables ['items'] as $delta => $item) {
$output .= drupal_render($item);
}
return $output;
}
/**
* Return a themed breadcrumb trail. Simple and conscise, links in a div
*/
function makeitso_breadcrumb(&$variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$output = '<div class="breadcrumb">' . implode('', $breadcrumb) . '</div>';
return $output;
}
}
/**
* Remove width and height fro the equasion. For responsiveness'ess
*/
function makeitso_image(&$variables) {
$attributes = $variables['attributes'];
$attributes['src'] = file_create_url($variables['path']);
// remove attributes height and width
// foreach (array('width', 'height', 'alt', 'title') as $key) {
foreach (array('alt', 'title') as $key) {
if (isset($variables[$key])) {
$attributes[$key] = $variables[$key];
}
}
return '<img' . drupal_attributes($attributes) . ' />';
}
/**
* Remove wrapping div around item-list
*/
function makeitso_item_list(&$variables) {
$items = $variables['items'];
$title = $variables['title'];
$type = $variables['type'];
$attributes = $variables['attributes'];
$output = '';
if (isset($title) && $title !== '') {
$output .= '<h3>' . $title . '</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
$i = 0;
foreach ($items as $item) {
$attributes = array();
$children = array();
$data = '';
$i++;
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (count($children) > 0) {
// Render nested list.
$data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
}
if ($i == 1) {
$attributes['class'][] = 'first';
}
if ($i == $num_items) {
$attributes['class'][] = 'last';
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
$output .= "</$type>";
}
$output .= '';
return $output;
}