-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.php
227 lines (194 loc) · 7.43 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
<?php
function sisters_get_node_count($content_type) {
$query = "SELECT COUNT(*) amount FROM {node} n ".
"WHERE n.type = :type";
$result = db_query($query, array(':type' => $content_type))->fetch();
return $result->amount;
}
function sisters_pager($variables) {
$tags = $variables['tags'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$quantity = $variables['quantity'];
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// first is the first page listed by this pager piece (re quantity)
$pager_first = $pager_current - $pager_middle + 1;
// last is the last page listed by this pager piece (re quantity)
$pager_last = $pager_current + $quantity - $pager_middle;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
// Prepare for generation loop.
$i = $pager_first;
if ($pager_last > $pager_max) {
// Adjust "center" if at end of query.
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
// Adjust "center" if at start of query.
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
// End of generation loop preparation.
$li_first = theme('pager_first', array('text' => t('«'), 'element' => $element, 'parameters' => $parameters));
$li_previous = theme('pager_previous', array('text' => t('‹'), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
$li_next = theme('pager_next', array('text' => t('›'), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
$li_last = theme('pager_last', array('text' => t('»'), 'element' => $element, 'parameters' => $parameters));
if ($pager_total[$element] > 1) {
if ($li_first) {
/*($items[] = array(
'class' => array('pager-first'),
'data' => $li_first,
);*/
}
if ($li_previous) {
$items[] = array(
'class' => array('pager-previous'),
'data' => $li_previous,
);
if($i >= 3) {
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_first', array('text' => t('1'), 'element' => $element, 'parameters' => $parameters)),
);
$items[] = array(
'class' => array('pager-current'),
'data' => "<a href='javascript:void(0);'>...</a>",
);
}
}
// When there is more than one page, create the pager list.
if ($i != $pager_max) {
if ($i > 1) {
$items[] = array(
'class' => array('pager-ellipsis hidden'),
'data' => '…',
);
}
// Now generate the actual pager piece.
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
);
}
if ($i == $pager_current) {
$items[] = array(
'class' => array('pager-current active'),
'data' => "<a href='#'>$i</a>",
);
}
if ($i > $pager_current) {
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
);
}
}
if ($i < $pager_max) {
$items[] = array(
'class' => array('pager-current'),
'data' => "<a href='javascript:void(0);'>...</a>",
);
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_next', array('text' => $pager_max - 1, 'element' => $element, 'interval' => ($pager_max - 1), 'parameters' => $parameters)),
);
}
}
// End generation.
if ($li_next) {
$items[] = array(
'class' => array('pager-next'),
'data' => $li_next,
);
}
if ($li_last) {
/*$items[] = array(
'class' => array('pager-last'),
'data' => $li_last,
);*/
}
return '<div class="browse-page"><div class="gray-area"></p><div class="browse-paging text-center">' . theme('item_list', array(
'items' => $items,
'attributes' => array('class' => array('pagination')),
)) . '</div> <!-- ./browse-paging --> </div> <!-- browse paging --></div>';
}
}
function sisters_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['search_block_form']['#title'] = t('Search collection'); // Change the text on the label element
$form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty
$form['actions']['submit']['#value'] = t('GO!'); // Change the text on the submit button
$form['actions']['submit']['#class'] = t('GO!'); // Change the text on the submit button
// Prevent user from searching the default text
$form['#attributes']['onsubmit'] = "if(this.search_block_form.value.trim() == ''){ alert('Please enter a search'); return false; }";
// Alternative (HTML5) placeholder attribute instead of using the javascript
$form['search_block_form']['#attributes']['placeholder'] = t('Search collection');
$form['search_block_form']['#attributes']['autocomplete'] = "off";
}
}
function sisters_js_alter(&$javascript) {
//We define the path of our new jquery core file
//assuming we are using the minified version 1.8.3
$jquery_path = drupal_get_path('theme','sisters') . '/resources/js/jquery-1.11.2.min.js';
//We duplicate the important information from the Drupal one
$javascript[$jquery_path] = $javascript['misc/jquery.js'];
//..and we update the information that we care about
$javascript[$jquery_path]['version'] = '1.11.2';
$javascript[$jquery_path]['data'] = $jquery_path;
//Then we remove the Drupal core version
$javascript['misc/jquery.js'] = null;
unset($javascript['misc/jquery.js']);
}
function sisters_get_all_of_type() {
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'browse_item')
->propertyCondition('status', 1);
$result = $query->execute();
if (isset($result['node'])) {
$news_items_nids = array_keys($result['node']);
$news_items = entity_load('node', $news_items_nids);
$arr = array();
foreach ($news_items as $value) {
array_push($arr, $value);
}
return $arr;
}
return null;
}
function pn_node($node, $mode = 'n') {
if (!function_exists('prev_next_nid')) {
return NULL;
}
switch($mode) {
case 'p':
$n_nid = prev_next_nid($node->nid, 'prev');
$link_text = 'previous';
break;
case 'n':
$n_nid = prev_next_nid($node->nid, 'next');
$link_text = 'next';
break;
default:
return NULL;
}
if ($n_nid) {
$n_node = node_load($n_nid);
switch($n_node->type) {
case 'article':
if ($mode == 'n'){ $title = 'Next Post »'; } else { $title = '« Previous Post'; }
$html = l($title, 'node/'.$n_node->nid, array('html' => TRUE, 'attributes' => array('class' => array('prev-next'), 'title' => $n_node->title)));
return $html;
}
}
}
?>