-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.inc
287 lines (256 loc) · 8.83 KB
/
preprocess.inc
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
<?php
// vim: set ts=4 sw=4 sts=4 et:
/**
* @file
* Preprocess functions
*
* @category LiteCommerce themes
* @package LiteCommerce3 theme
* @author Creative Development LLC <[email protected]>
* @copyright Copyright (c) 2011 Creative Development LLC <[email protected]>. All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @link http://www.litecommerce.com/
* @since 1.0.0
*/
/**
* Preprocess function for html.tpl.php
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_preprocess_html(array &$vars) {
// Add conditional stylesheets for IE
drupal_add_css(
path_to_theme() . '/css/ie.css',
array(
'group' => CSS_THEME,
'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE),
'preprocess' => FALSE,
)
);
// Add a special CSS class to the page when there no breadcrumb is going to be displayed
if (2 > count(drupal_get_breadcrumb())) {
$vars['classes_array'][] = 'no-breadcrumbs';
}
}
/**
* Add conditional JavaScript for IE
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_process_html(array &$vars) {
$vars['scripts'] .= '<!--[if lte IE 7]><script type="text/javascript src="'
. base_path() . path_to_theme() . '/js/ie.js"></script><![endif]-->' . "\n";
}
/**
* Preprocess function for page.tpl.php
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_preprocess_page(array &$vars) {
// Render social links
$twitter = check_plain(theme_get_setting('theme_social_link_twitter'));
$facebook = check_plain(theme_get_setting('theme_social_link_facebook'));
$vars['twitter_link'] = $twitter ? l(t('Follow us on Twitter'), 'http://www.twitter.com/#!/' . $twitter) : '';
$vars['facebook_link'] = $facebook ? l(t('Find us on Facebook'), 'http://www.facebook.com/' . $facebook) : '';
// Render the main menu
if ($vars['main_menu'] && ($pid = variable_get('menu_main_links_source', 'main-menu'))) {
$vars['main_menu']['header'] = array(
'#markup' => '<h2 class="element-invisible">' . t('Main menu') . '</h2>',
);
$vars['main_menu']['tree'] = menu_tree($pid);
$vars['main_menu']['tree']['#attributes'] = array(
'id' => 'main-menu',
'class' => 'clearfix',
);
}
// Add a hidden title for accessibility reasons
if ($vars['page']['search']) {
$vars['page']['search'] = array_merge(
array(
'header' => array('#markup' => '<h2 class="element-invisible">' . t('Search') . '</h2>'),
),
$vars['page']['search']
);
}
}
/**
* Preprocess function for node.tpl.php
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_preprocess_node(array &$vars) {
// Display only the first uploaded image in teasers
if ($vars['teaser'] && isset($vars['content']['field_image'])) {
$vars['content']['field_image']['#items'] = array($vars['content']['field_image'][0]);
}
// Reorder and rename node links
if ($vars['teaser']) {
// Move "Read more" link to the end of the list
if (isset($vars['content']['links']['node'])) {
$node = $vars['content']['links']['node'];
unset($vars['content']['links']['node']);
$vars['content']['links']['node'] = $node;
}
}
// Render the comment count as a link
// NOTE: do not change "!=" to the "!==" operator:
// it's compared string and integer values here
if (defined('COMMENT_NODE_CLOSED') && COMMENT_NODE_CLOSED != $vars['node']->comment) {
$vars['linked_comment_count'] = (isset($vars['comment_count']))
? l(
format_plural(
$vars['comment_count'],
'1<span> comment</span>',
'@count<span> comments</span>'
),
'node/' . $vars['node']->nid,
array(
'html' => TRUE,
'attributes' => array(
'title' => format_plural($vars['comment_count'], '1 comment', '@count comments'),
'class' => array('comment-count'),
),
),
'#comments'
)
: '';
}
else {
$vars['linked_comment_count'] = '';
}
$comment_location = variable_get('comment_form_location_' . $vars['node']->type, COMMENT_FORM_BELOW);
// Link "Add new comment" to the form on the node page
if (isset($vars['content']['links']['comment']['#links']['comment-add']) && COMMENT_FORM_SEPARATE_PAGE !== $comment_location) {
if ($vars['node']->teaser) {
$vars['content']['links']['comment']['#links']['comment-add']['href'] = drupal_lookup_path('alias', 'node/' . $vars['node']->nid);
}
elseif ('forum' !== $vars['node']->type) {
// Remove the link if it is the node page
unset($vars['content']['links']['comment']['#links']['comment-add']);
}
}
// Forum nodes
if ('forum' == $vars['node']->type) {
$vars['classes_array'][] = 'forum-post';
$vars['classes_array'][] = 'forum-top';
$vars['classes_array'][] = 'comment';
$vars['submitted'] = '<span>' . t('Posted:') . '</span> ' . format_date($vars['node']->created, 'custom', 'M j, Y, H:i');
if (isset($vars['content']['links']['comment']['#links']['comment-add'])) {
$vars['content']['links']['comment']['#links']['comment-add']['title'] = t('Reply');
}
}
else {
// Render the submission date in a custom format
$vars['submitted'] = t(
'Submitted by !username on !datetime',
array(
'!username' => $vars['name'],
'!datetime' => format_date($vars['node']->created, 'custom', 'M j, Y &\n\d\a\s\h; H:i'),
)
);
}
}
/**
* Preprocess function for comment.tpl.php
*
* Available variables:
* - elements
* - theme_hook_suggestions
* - zebra
* - id
* - directory
* - classes_array
* - attributes_array
* - title_attributes_array
* - content_attributes_array
* - title_prefix
* - title_suffix
* - user
* - db_is_active
* - is_admin
* - logged_in
* - is_front
* - comment
* - node
* - author
* - created
* - changed
* - new
* - picture
* - signature
* - title
* - permalink
* - submitted
* - comment_body
* - content
* - status
* - rdf_template_variable_attributes_array
* - rdf_metadata_attributes_array
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_preprocess_comment(array &$vars) {
$vars['title_attributes_array']['class'][] = 'subject';
$vars['title'] = variable_get('comment_subject_field_' . $vars['node']->type, 1) ? $vars['comment']->subject : '';
if (!$vars['title']) {
$vars['classes_array'][] = 'comment-no-subject';
}
$uri = entity_uri('comment', $vars['comment']);
$uri['options'] += array('attributes' => array('class' => 'permalink', 'rel' => 'bookmark'));
$vars['permalink'] = l(t('#'), $uri['path'], $uri['options']);
$vars['submitted'] = '<span>' . t('Posted:') . '</span> ' . format_date($vars['comment']->created, 'custom', 'M j, Y, H:i');
}
/**
* Preprocess forum topic list
*
* @param array $vars Variables
*
* @return void
* @since 1.0.0
*/
function lc3_clean_preprocess_forum_topic_list(array &$vars) {
// Remove the first "icon" column header because now icons are inside the title column
global $forum_topic_list_header;
$forum_topic_list_header = array(
array('data' => t('Topic'), 'field' => 'n.title'),
array('data' => t('Replies'), 'field' => 'l.comment_count'),
array('data' => t('Last reply'), 'field' => 'l.last_comment_timestamp'),
);
$ts = tablesort_init($forum_topic_list_header);
$header = '';
foreach ($forum_topic_list_header as $cell) {
$cell = tablesort_header($cell, $forum_topic_list_header, $ts);
$header .= _theme_table_cell($cell, TRUE);
}
$vars['header'] = $header;
// Display topic creation dates differently
if (!empty($vars['topics'])) {
$row = 0;
foreach ($vars['topics'] as $id => $topic) {
$created = isset($topic->created) ? format_interval(REQUEST_TIME - $topic->created) : '';
$user = user_load($vars['topics'][$id]->uid);
$vars['topics'][$id]->created = t(
'Created !date by !user',
array(
'!date' => '<span class="submitted-date">' . $created . '</span> ago',
'!user' => l($user->name, drupal_lookup_path('alias', 'user' . $user->uid)),
)
);
}
}
}