-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.php
392 lines (352 loc) · 10.9 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php
// vim: set ts=2 sw=2 sts=2 et:
/**
* @file
* Theme functions.
*/
require 'preprocess.inc';
/**
* Implementats hook_theme().
* This function provides a one-stop reference for all overriden and custom theme functions.
*
* @param array &$existing
* An array of existing implementations that may be used for override purposes.
* @param string $type
* What 'type' is being processed: module, base_theme_engine, theme_engine, base_theme, theme.
* @param string $theme
* The actual name of theme that is being being checked (mostly only useful for theme engine).
* @param string $path
* The directory path of the theme or module, so that it doesn't need to be looked up.
*
* @hook theme
* @return array
*/
function lc3_clean_theme(array &$existing, $type, $theme, $path) {
return array(
// theme wrapper for the main menu
'menu_tree__main_menu' => array(
'file' => 'templates/theme.inc',
'render element' => 'tree',
),
// custom theme function for breadcrumbs
'breadcrumb' => array(
'file' => 'templates/theme.inc',
),
// taxonomy tags
'field__taxonomy_term_reference' => array(
'file' => 'templates/theme.inc',
),
// popup boxes
'popup_box' => array(
'file' => 'templates/theme.inc',
'render element' => 'popup',
),
// buttons
'button' => array(
'file' => 'templates/theme.inc',
'render element' => 'element',
),
// input with type=password
'password' => array(
'file' => 'templates/theme.inc',
'render element' => 'element',
),
// Drupal pagers
'pager' => array(
'file' => 'templates/theme.inc',
),
// popup status messages
'status_messages' => array(
'file' => 'templates/theme.inc',
),
// sort indicator for tables
'tablesort_indicator' => array(
'file' => 'templates/theme.inc',
),
);
}
/**
* Adds account links to a page.
*
* @param array &$page
* Structured array defining the page.
*/
function lc3_clean_page_alter(array &$page) {
global $user;
// Remove left sidebar
if ('store' === arg(0) && isset($page['sidebar_first']) && in_array(arg(1), array('cart', 'checkout', 'product', 'checkoutPayment'))) {
unset($page['sidebar_first']);
}
// Render the account links
$disabled_popup = 'user' === arg(0) || !empty($user->uid);
if (!empty($user->uid)) {
$page['account_links'] = array(
'greeting-message' => array(
'#markup' => '<span class="greeting-message"><span>' . t('Hello') . ',</span> ' . check_plain($user->name) . '</span>',
),
'account-links' => array(
'#theme' => 'links__account_links',
'#attributes' => array(
'class' => array('account-links'),
),
'#links' => array(
'account-link-1' => array(
'href' => 'user',
'title' => t('My account'),
'attributes' => array('class' => array('account')),
),
'account-link-2' => array(
'href' => 'user/logout',
'title' => t('Log out'),
'attributes' => array('class' => array('log-in')),
),
),
),
);
}
else {
$attributes = $disabled_popup ? array() : array('onclick' => 'javascript: lc3_clean_popup_div("login-popup-box", true); return false;');
$page['account_links'] = array(
'account-links' => array(
'#theme' => 'links__account_links',
'#attributes' => array(
'class' => array('account-links'),
),
'#links' => array(
'account-link-1' => array(
'href' => 'user',
'title' => t('Log in'),
'attributes' => $attributes + array('class' => array('log-in')),
),
'account-link-2' => array(
'href' => 'user/register',
'title' => t('Register'),
'attributes' => array('class' => array('register')),
),
),
),
);
}
// Render popup forms
if (!$disabled_popup) {
module_load_include('inc', 'user', 'user.pages');
$page['page_bottom']['blockui-popups'] = array(
'login-popup' => array(
'#theme_wrappers' => array('popup_box'),
'#id' => 'login-popup-box',
'#subject' => t('User login'),
'form' => drupal_get_form('user_login', TRUE),
),
'recovery-password-popup' => array(
'#theme_wrappers' => array('popup_box'),
'#id' => 'password-popup-box',
'#subject' => t('Request new password'),
'form' => drupal_get_form('user_pass'),
),
);
$page['page_bottom']['blockui-popups']['login-popup']['form']['#action'] = url(
'user',
array('query' => drupal_get_destination())
);
$page['page_bottom']['blockui-popups']['recovery-password-popup']['form']['#action'] = url(
'user/password',
array('query' => drupal_get_destination())
);
}
// IE8 compatibility mode
header('X-UA-Compatible: IE=8');
}
/**
* Alter the 'user-login' form.
*
* @param array &$form
* Nested array of form elements that comprise the form.
* @param array &$form_state
* A keyed array containing the current state of the form.
* @param string $form_id
* String representing the name of the form itself.
*
* @hook form_FORM_ID_alter
*
* @see hook_form_alter()
* @see drupal_prepare_form()
*/
function lc3_clean_form_user_login_alter(array &$form, array &$form_state, $form_id) {
// Check whether the form is to be displayed in a popup layer
if ('user' !== arg(0)) {
// Make the login button larger
$form['actions']['submit']['#attributes']['class'][] = 'action';
//Display the button right below the form fields
$form['actions']['#weight'] = 0.5;
// Shorten the OpenID field title
if (isset($form['openid_identifier']['#title'])) {
$form['openid_identifier']['#title'] = t('OpenID');
}
// Add the "recover password" link
$attributes = array(
'title' => t('Request new password via e-mail.'),
'onclick' => "javascript: lc3_clean_popup_div('password-popup-box'); return false;",
);
$form['account-links'] = array(
'#weight' => 2,
'#theme' => 'item_list',
'#items' => array(
array(
'data' => l(t('Forgot password?'), 'user/password', array('attributes' => $attributes)),
'class' => array('restore-password'),
),
),
'#attributes' => array(
'class' => array('user-account'),
),
);
}
}
/**
* Alter the 'user-pass' form.
*
* @param array &$form
* Nested array of form elements that comprise the form.
* @param array &$form_state
* A keyed array containing the current state of the form.
* @param string $form_id
* String representing the name of the form itself.
*
* @hook form_FORM_ID_alter
*
* @see hook_form_alter()
* @see drupal_prepare_form()
*/
function lc3_clean_form_user_pass_alter(array &$form, array &$form_state, $form_id) {
// Make the login button larger
$form['actions']['submit']['#attributes']['class'][] = 'action';
// Shorten the label
$form['name']['#title'] = t('Username or e-mail');
}
/**
* Alter the 'user-profile' form.
*
* @param array &$form
* Nested array of form elements that comprise the form.
* @param array &$form_state
* A keyed array containing the current state of the form.
* @param string $form_id
* String representing the name of the form itself.
*
* @hook form_FORM_ID_alter
*
* @see hook_form_alter()
* @see drupal_prepare_form()
*/
function lc3_clean_form_user_profile_form_alter(array &$form, array &$form_state, $form_id) {
if (isset($form['picture'])) {
if (!isset($form['picture']['#attributes'])) {
$form['picture']['#attributes'] = array();
}
if (!isset($form['picture']['#attributes']['class'])) {
$form['picture']['#attributes']['class'] = array('picture-block');
}
else {
$form['picture']['#attributes']['class'][] = ' picture-block';
}
}
if (!isset($form['actions']['#attributes'])) {
$form['actions']['#attributes'] = array();
}
if (!isset($form['actions']['#attributes']['class'])) {
$form['actions']['#attributes']['class'] = array();
}
$form['actions']['#attributes']['class'][] = 'buttons-box';
$form['actions']['#attributes']['class'][] = 'floatable-box';
if (!isset($form['actions']['submit']['#attributes'])) {
$form['actions']['submit']['#attributes'] = array();
}
if (!isset($form['actions']['submit']['#attributes']['class'])) {
$form['actions']['submit']['#attributes']['class'] = array();
}
$form['actions']['submit']['#attributes']['class'][] = 'action';
}
/**
* Hook for altering any form.
*
* @param array &$form
* Nested array of form elements that comprise the form.
* @param array &$form_state
* A keyed array containing the current state of the form.
* @param string $form_id
* String representing the name of the form itself.
*
* @hook form_alter
*
* @see hook_form_alter()
* @see drupal_prepare_form()
*/
function lc3_clean_form_alter(array &$form, array &$form_state, $form_id) {
global $user;
// Alter comment forms when the user is logged in
if (preg_match('/^comment_node_([\w\d_]+)_form$/', $form_id, $matches) && $user->uid) {
// Add an extra class to comment forms
$form['#attributes']['class'][] = 'comment-form-is-logged';
// Add ":" to the name label
$form['author']['_author']['#title'] .= ': ';
}
}
/**
* Preprocess block.
*
* @param array &$vars
* Array of variables.
*
* @hook preprocess_block
*/
function lc3_clean_preprocess_block(array &$vars) {
if (!$vars['block']->title) {
$vars['classes_array'][] = 'block-without-title';
}
}
/**
* Alter HTML head.
*
* @param array &$head_elements
* Head elements.
*
* @hook html_head_alter
*/
function lc3_clean_html_head_alter(array &$head_elements) {
$head_elements['lc3_clean_content_script_type'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'Content-Script-Type',
'content' => 'text/javascript',
),
'#weight' => -1000,
);
$head_elements['lc3_clean_content_style_type'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'Content-Style-Type',
'content' => 'text/css',
),
'#weight' => -1000,
);
$head_elements['lc3_clean_content_ie_compatibility9'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=9',
),
'#weight' => -1000,
);
$head_elements['lc3_clean_content_ie_compatibility8'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=8',
),
'#weight' => -900,
);
}