Newer
Older
/**
* @file template.php
* Main template file for Magazeen.
*/
/*
* Initialize theme settings
*/
if (is_null(theme_get_setting('user_notverified_display'))) {
global $theme_key;
/**
* The default values for the theme variables. Make sure $defaults exactly
* matches the $defaults in the theme-settings.php file.
*/
$defaults = array(
'breadcrumb_display' => 'yes',
'breadcrumb_separator' => ' › ',
'breadcrumb_home' => 1,
'breadcrumb_trailing' => 0,
'breadcrumb_title' => 0,
'search_snippet' => 1,
'search_info_type' => 1,
'search_info_user' => 1,
'search_info_date' => 1,
'search_info_comment' => 1,
'search_info_upload' => 1,
'front_page_title_display' => 'title_slogan',
'page_title_display_custom' => '',
'other_page_title_display' => 'ptitle_slogan',
'other_page_title_display_custom' => '',
'configurable_separator' => ' | ',
'meta_keywords' => '',
'meta_description' => '',
'rebuild_registry' => 0,
'block_editing' => 1,
);
// Get default theme settings.
$settings = theme_get_settings($theme_key);
// Don't save the toggle_node_info_ variables
if (module_exists('node')) {
foreach (node_get_types() as $type => $name) {
unset($settings['toggle_node_info_'. $type]);
}
}
// Save default theme settings
variable_set(
str_replace('/', '_', 'theme_'. $theme_key .'_settings'),
array_merge($defaults, $settings)
);
// Force refresh of Drupal internals
theme_get_setting('', TRUE);
}
/**
* Modify theme variables
*/
function phptemplate_preprocess_page(&$vars) {
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
// Set site title, slogan, mission, page title & separator
$title = t(variable_get('site_name', ''));
$slogan = t(variable_get('site_slogan', ''));
$mission = t(variable_get('site_mission', ''));
$page_title = t(drupal_get_title());
$title_separator = theme_get_setting('configurable_separator');
if (drupal_is_front_page()) { // Front page title settings
switch (theme_get_setting('front_page_title_display')) {
case 'title_slogan':
$vars['head_title'] = drupal_set_title($title . $title_separator . $slogan);
break;
case 'slogan_title':
$vars['head_title'] = drupal_set_title($slogan . $title_separator . $title);
break;
case 'title_mission':
$vars['head_title'] = drupal_set_title($title . $title_separator . $mission);
break;
case 'custom':
if (theme_get_setting('page_title_display_custom') !== '') {
$vars['head_title'] = drupal_set_title(t(theme_get_setting('page_title_display_custom')));
}
}
}
else { // Non-front page title settings
switch (theme_get_setting('other_page_title_display')) {
case 'ptitle_slogan':
$vars['head_title'] = drupal_set_title($page_title . $title_separator . $slogan);
break;
case 'ptitle_stitle':
$vars['head_title'] = drupal_set_title($page_title . $title_separator . $title);
break;
case 'ptitle_smission':
$vars['head_title'] = drupal_set_title($page_title . $title_separator . $mission);
break;
case 'ptitle_custom':
if (theme_get_setting('other_page_title_display_custom') !== '') {
$vars['head_title'] = drupal_set_title($page_title . $title_separator . t(theme_get_setting('other_page_title_display_custom')));
}
break;
case 'custom':
if (theme_get_setting('other_page_title_display_custom') !== '') {
$vars['head_title'] = drupal_set_title(t(theme_get_setting('other_page_title_display_custom')));
}
}
}
$vars['head_title'] = strip_tags($vars['head_title']); // Remove any potential html tags
// Add meta tag on all pages
if (!module_exists('nodewords')) {
if (theme_get_setting('meta_keywords') !== '') {
$keywords = '<meta name="keywords" content="'. theme_get_setting('meta_keywords') .'" />';
$vars['head'] .= $keywords ."\n";
}
if (theme_get_setting('meta_description') !== '') {
$keywords = '<meta name="description" content="'. theme_get_setting('meta_description') .'" />';
$vars['head'] .= $keywords ."\n";
}
}
}
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
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function magazeen_breadcrumb($breadcrumb) {
// Determine if we are to display the breadcrumb
$show_breadcrumb = theme_get_setting('breadcrumb_display');
if ($show_breadcrumb == 'yes' || $show_breadcrumb == 'admin' && arg(0) == 'admin') {
// Optionally get rid of the homepage link
$show_breadcrumb_home = theme_get_setting('breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
// Return the breadcrumb with separators
if (!empty($breadcrumb)) {
$breadcrumb_separator = theme_get_setting('breadcrumb_separator');
$trailing_separator = (theme_get_setting('breadcrumb_trailing') || theme_get_setting('breadcrumb_title')) ? $breadcrumb_separator : '';
return '<div class="breadcrumb">' . implode($breadcrumb_separator, $breadcrumb) . "$trailing_separator</div>";
}
}
// Otherwise, return an empty string
return '';
}
/**
* Modify search results based on theme settings
*/
function phptemplate_preprocess_search_result(&$variables) {
static $search_zebra = 'even';
$search_zebra = ($search_zebra == 'even') ? 'odd' : 'even';
$variables['search_zebra'] = $search_zebra;
$result = $variables['result'];
$variables['url'] = check_url($result['link']);
$variables['title'] = check_plain($result['title']);
// Check for existence. User search does not include snippets.
$variables['snippet'] = '';
if (isset($result['snippet']) && theme_get_setting('search_snippet')) {
$variables['snippet'] = $result['snippet'];
}
$info = array();
if (!empty($result['type']) && theme_get_setting('search_info_type')) {
$info['type'] = check_plain($result['type']);
}
if (!empty($result['user']) && theme_get_setting('search_info_user')) {
$info['user'] = $result['user'];
}
if (!empty($result['date']) && theme_get_setting('search_info_date')) {
$info['date'] = format_date($result['date'], 'small');
}
if (isset($result['extra']) && is_array($result['extra'])) {
// $info = array_merge($info, $result['extra']); Drupal bug? [extra] array not keyed with 'comment' & 'upload'
if (!empty($result['extra'][0]) && theme_get_setting('search_info_comment')) {
$info['comment'] = $result['extra'][0];
}
if (!empty($result['extra'][1]) && theme_get_setting('search_info_upload')) {
$info['upload'] = $result['extra'][1];
}
}
// Provide separated and grouped meta information.
$variables['info_split'] = $info;
$variables['info'] = implode(' - ', $info);
// Provide alternate search result template.
$variables['template_files'][] = 'search-result-'. $variables['type'];
}
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
/**
* Override username theming to display/hide 'not verified' text
*/
function phptemplate_username($object) {
if ($object->uid && $object->name) {
// Shorten the name when it is too long or it will break many tables.
if (drupal_strlen($object->name) > 20) {
$name = drupal_substr($object->name, 0, 15) .'...';
}
else {
$name = $object->name;
}
if (user_access('access user profiles')) {
$output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
}
else {
$output = check_plain($name);
}
}
else if ($object->name) {
// Sometimes modules display content composed by people who are
// not registered members of the site (e.g. mailing list or news
// aggregator modules). This clause enables modules to display
// the true author of the content.
if (!empty($object->homepage)) {
$output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
}
else {
$output = check_plain($object->name);
}
// Display or hide 'not verified' text
if (theme_get_setting('user_notverified_display') == 1) {
$output .= ' ('. t('not verified') .')';
}
}
else {
$output = variable_get('anonymous', t('Anonymous'));
}
return $output;
}
*/
function phptemplate_comment_count($comment_count, $node_url) {
switch (theme_get_setting('display_teaser_comment')) {
case 'hide':
$output = '';
break;
case 'addnew':
$output = '<div class="comment-count">';
$output .= '<a title="'. $comment_count .' '. t('comments') .'" href="'. $node_url .'#comments" >';
$output .= '</a>';
$output .= '</div>';
break;
default:
$output = '<div class="comment-count">';
$output .= '<a title="'. $comment_count .' '. t('comments') .'" href="'. $node_url .'#comments" >';
$output .= $comment_count .' '. t('comments');
$output .= '</a>';
$output .= '</div>';
}
/**
* Display author name in page
*/
function phptemplate_display_author($name) {
if (theme_get_setting('display_author') == 0) {
$output = '';
}
else {
$output = '<span>'. t('By') .' '. $name .'</span>';
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
/**
* Override or insert variables into the block templates.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function magazeen_preprocess_block(&$vars, $hook) {
$block = $vars['block'];
// Special classes for blocks.
$classes = array('block');
$classes[] = 'block-' . $block->module;
$classes[] = 'region-' . $vars['block_zebra'];
$classes[] = $vars['zebra'];
$classes[] = 'region-count-' . $vars['block_id'];
$classes[] = 'count-' . $vars['id'];
$vars['edit_links_array'] = array();
$vars['edit_links'] = '';
if (theme_get_setting('block_editing') && user_access('administer blocks')) {
include_once './' . drupal_get_path('theme', 'magazeen') . '/include/template.block-editing.inc';
magazeen_preprocess_block_editing($vars, $hook);
$classes[] = 'with-block-editing';
}
// Render block classes.
$vars['classes'] = implode(' ', $classes);
}
/**
* Adds 'width940' or 'width580' classes to the main content as needed.
*/
function phptemplate_mainwidth_class($right) {
$mainwidth = 'width940';
if ( $right ) {
$mainwidth = 'width580';}
print $mainwidth;
}
/**
* Generates IE CSS links for .
*/
function phptemplate_get_ie_styles() {
global $language;
$iecss = '<link type="text/css" rel="stylesheet" media="all" href="'. base_path() . path_to_theme() .'/ie.css" />';
return $iecss;
}
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('rebuild_registry')) {
drupal_rebuild_theme_registry();
}
function magazeen_theme(&$existing, $type, $theme, $path){
// If we are auto-rebuilding the theme registry, warn about the feature.
// Always display the warning in the admin section, otherwise limit to three
// warnings per hour.
if (user_access('administer site configuration') && theme_get_setting('rebuild_registry') && $theme == $GLOBALS['theme'] && (arg(0) == 'admin' || flood_is_allowed($GLOBALS['theme'] . '_rebuild_registry_warning', 3))) {
flood_register_event($GLOBALS['theme'] . '_rebuild_registry_warning');
drupal_set_message(t('For easier theme development, the theme registry is being rebuilt on every page request. It is <em>extremely</em> important to <a href="!link">turn off this feature</a> on production websites.', array('!link' => url('admin/build/themes/settings/' . $GLOBALS['theme']))), 'warning', FALSE);
}
return array(
'comment_form' => array(
'arguments' => array('form' => NULL),
'template' => 'comment-form',
),
);
}
function magazeen_preprocess_comment_form(&$vars) {
$vars['submit'] = drupal_render($vars['form']['submit']);
$vars['preview'] = drupal_render($vars['form']['preview']);
$vars['subject'] = drupal_render($vars['form']['subject']);
$vars['comment'] = drupal_render($vars['form']['comment_filter']['comment']);
$vars['form']['name']['#title'] = t('Name (required)');
$vars['name'] = drupal_render($vars['form']['name']);
$vars['form']['mail']['#title'] = t('Mail (will not be published) (required)');
$vars['mail'] = drupal_render($vars['form']['mail']);
$vars['form']['homepage']['#title'] = t('Website');
$vars['homepage'] = drupal_render($vars['form']['homepage']);
$vars['comment_preview'] = drupal_render($vars['form']['comment_preview']);
}