-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.php
176 lines (160 loc) · 5.48 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
<?php
/**
* @file
* Template overrides as well as (pre-)process and alter hooks for the
* ofen theme.
*/
/**
* Search backwards starting from haystack length characters from the end
*/
function ofen_starts_with($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;
}
/**
* hook_form_FORM_ID_alter
*/
function ofen_form_search_block_form_alter(&$form, &$form_state, $form_id) {
// Alternative (HTML5) placeholder attribute instead of using the javascript
$form['search_block_form']['#attributes']['placeholder'] = t('Search');
}
/**
* Returns HTML for a form.
*
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #action, #method, #attributes, #children
*
* @ingroup themeable
*/
function ofen_form($variables) {
$element = $variables['element'];
if (isset($element['#action'])) {
$element['#attributes']['action'] = drupal_strip_dangerous_protocols($element['#action']);
}
element_set_attributes($element, array('method', 'id'));
if (empty($element['#attributes']['accept-charset'])) {
$element['#attributes']['accept-charset'] = "UTF-8";
}
// CHANGED: Anonymous DIV to satisfy XHTML compliance.
// return '<form' . drupal_attributes($element['#attributes']) . '><div>' . $element['#children'] . '</div></form>';
return '<form' . drupal_attributes($element['#attributes']) . '>' . $element['#children'] . '</form>';
}
/**
* Returns HTML for a list or nested list of items.
*
* CHANGE:
* If it is a pager__item whitespaces between li elements are removed
* @ingroup themeable
*/
function ofen_item_list($variables) {
$items = $variables['items'];
$title = $variables['title'];
$type = $variables['type'];
$attributes = $variables['attributes'];
// Only output the list container and title, if there are any list items.
// Check to see whether the block title exists before adding a header.
// Empty headers are not semantic and present accessibility challenges.
$output = '';
if (isset($title) && $title !== '') {
$output .= '<h3>' . $title . '</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$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 (in_array('pager__item', $attributes['class'])) {
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>";
} else {
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
}
$output .= "</$type>";
}
return $output;
}
/**
* Format date on search result page: 10. Januar 2018
*/
function ofen_preprocess_search_result(&$variables) {
$date = $variables['result']['date'];
$variables['info_split']['date'] = format_date($date, 'custom', 'j. F Y');
}
/**
* Open PDF file in new window
* See: https://www.drupal.org/node/301234
*/
function ofen_file_link($variables) {
$file = $variables['file'];
$icon_directory = drupal_get_path('theme', 'ofen') . '/images/icons';
$url = file_create_url($file->uri);
$file_size = format_size($file->filesize);
$icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));
// Set options as per anchor format described at
// http://microformats.org/wiki/file-format-examples
$options = array(
'attributes' => array(
'type' => $file->filemime . '; length=' . $file->filesize,
),
);
// Use the description as the link text if available.
if (empty($file->description)) {
$link_text = $file->filename;
}
else {
$link_text = $file->description;
$options['attributes']['title'] = check_plain($file->filename);
}
// Open files of particular mime types in new window
$new_window_mimetypes = array('application/pdf','text/plain');
if (in_array($file->filemime, $new_window_mimetypes)) {
$options['attributes']['target'] = '_blank';
}
// File size
$link_text .= '<br />'. $file_size;
$options['html'] = TRUE;
return '<div class="file">'.
'<div class="file-icon">' . $icon . '</div>'.
'<div class="file-link">' . l($link_text, $url, $options) .'</div>'.
'</div>';
}
/**
* Implements hook_owlcarousel_settings_alter().
*/
function ofen_owlcarousel_settings_alter(&$settings, $instance) {
switch ($instance) {
case 'owl-carousel-block':
break;
default:
$settings['navigationText'] = array('<i class="fa fa-angle-left"></i>', '<i class="fa fa-angle-right"></i>');
}
}