Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Contains the theme's functions to manipulate Drupal's default markup.
5
 *
6
 * A QUICK OVERVIEW OF DRUPAL THEMING
7
 *
8
 *   The default HTML for all of Drupal's markup is specified by its modules.
9
 *   For example, the comment.module provides the default HTML markup and CSS
10
 *   styling that is wrapped around each comment. Fortunately, each piece of
11
 *   markup can optionally be overridden by the theme.
12
 *
13
 *   Drupal deals with each chunk of content using a "theme hook". The raw
14
 *   content is placed in PHP variables and passed through the theme hook, which
15
 *   can either be a template file (which you should already be familiary with)
16
 *   or a theme function. For example, the "comment" theme hook is implemented
17
 *   with a comment.tpl.php template file, but the "breadcrumb" theme hooks is
18
 *   implemented with a theme_breadcrumb() theme function. Regardless if the
19
 *   theme hook uses a template file or theme function, the template or function
20
 *   does the same kind of work; it takes the PHP variables passed to it and
21
 *   wraps the raw content with the desired HTML markup.
22
 *
23
 *   Most theme hooks are implemented with template files. Theme hooks that use
24
 *   theme functions do so for performance reasons - theme_field() is faster
25
 *   than a field.tpl.php - or for legacy reasons - theme_breadcrumb() has "been
26
 *   that way forever."
27
 *
28
 *   The variables used by theme functions or template files come from a handful
29
 *   of sources:
30
 *   - the contents of other theme hooks that have already been rendered into
31
 *     HTML. For example, the HTML from theme_breadcrumb() is put into the
32
 *     $breadcrumb variable of the page.tpl.php template file.
33
 *   - raw data provided directly by a module (often pulled from a database)
34
 *   - a "render element" provided directly by a module. A render element is a
35
 *     nested PHP array which contains both content and meta data with hints on
36
 *     how the content should be rendered. If a variable in a template file is a
37
 *     render element, it needs to be rendered with the render() function and
38
 *     then printed using:
39
 *       <?php print render($variable); ?>
40
 *
41
 * ABOUT THE TEMPLATE.PHP FILE
42
 *
43
 *   The template.php file is one of the most useful files when creating or
44
 *   modifying Drupal themes. With this file you can do three things:
45
 *   - Modify any theme hooks variables or add your own variables, using
46
 *     preprocess or process functions.
47
 *   - Override any theme function. That is, replace a module's default theme
48
 *     function with one you write.
49
 *   - Call hook_*_alter() functions which allow you to alter various parts of
50
 *     Drupal's internals, including the render elements in forms. The most
51
 *     useful of which include hook_form_alter(), hook_form_FORM_ID_alter(),
52
 *     and hook_page_alter(). See api.drupal.org for more information about
53
 *     _alter functions.
54
 *
55
 * OVERRIDING THEME FUNCTIONS
56
 *
57
 *   If a theme hook uses a theme function, Drupal will use the default theme
58
 *   function unless your theme overrides it. To override a theme function, you
59
 *   have to first find the theme function that generates the output. (The
60
 *   api.drupal.org website is a good place to find which file contains which
61
 *   function.) Then you can copy the original function in its entirety and
62
 *   paste it in this template.php file, changing the prefix from theme_ to
63
 *   STARTERKIT_. For example:
64
 *
65
 *     original, found in modules/field/field.module: theme_field()
66
 *     theme override, found in template.php: STARTERKIT_field()
67
 *
68
 *   where STARTERKIT is the name of your sub-theme. For example, the
69
 *   zen_classic theme would define a zen_classic_field() function.
70
 *
71
 *   Note that base themes can also override theme functions. And those
72
 *   overrides will be used by sub-themes unless the sub-theme chooses to
73
 *   override again.
74
 *
75
 *   Zen core only overrides one theme function. If you wish to override it, you
76
 *   should first look at how Zen core implements this function:
77
 *     theme_breadcrumbs()      in zen/template.php
78
 *
79
 *   For more information, please visit the Theme Developer's Guide on
80
 *   Drupal.org: http://drupal.org/node/173880
81
 *
82
 * CREATE OR MODIFY VARIABLES FOR YOUR THEME
83
 *
84
 *   Each tpl.php template file has several variables which hold various pieces
85
 *   of content. You can modify those variables (or add new ones) before they
86
 *   are used in the template files by using preprocess functions.
87
 *
88
 *   This makes THEME_preprocess_HOOK() functions the most powerful functions
89
 *   available to themers.
90
 *
91
 *   It works by having one preprocess function for each template file or its
92
 *   derivatives (called theme hook suggestions). For example:
93
 *     THEME_preprocess_page    alters the variables for page.tpl.php
94
 *     THEME_preprocess_node    alters the variables for node.tpl.php or
95
 *                              for node--forum.tpl.php
96
 *     THEME_preprocess_comment alters the variables for comment.tpl.php
97
 *     THEME_preprocess_block   alters the variables for block.tpl.php
98
 *
99
 *   For more information on preprocess functions and theme hook suggestions,
100
 *   please visit the Theme Developer's Guide on Drupal.org:
101
 *   http://drupal.org/node/223440 and http://drupal.org/node/1089656
102
 */
103

    
104
/**
105
 * @param $which_image
106
 *   name of the image, see _zen_dataportal_imagenames() for possible values
107
 * @param $variables
108
 *   An array of variables to pass to the theme template.
109
 * @param $default_image
110
 *  An file path relative to the theme folder
111
 * @param $css_selector
112
 *   The dom element to apply the image as background image
113
 * @param $background_style
114
 *   Addtional css setting for the background css attribute, default is  'scroll repeat'
115
 *
116
 * @see _zen_dataportal_imagenames() for possible values
117
 */
118
function _set_image_url($which_image, &$variables, $default_image = null, $css_selector = NULL, $background_style = 'scroll repeat') {
119

    
120

    
121
  if (!theme_get_setting('default_' . $which_image)) {
122
    $path = theme_get_setting($which_image . '_path');
123
    if(isset($path)){
124
      if (file_uri_scheme($path) == 'public') {
125
        $url = file_create_url($path);
126
      }
127
    }
128
  }
129

    
130
  if(!isset($url) && isset($default_image)) {
131
      $url = base_path() . path_to_theme() . '/' . $default_image;
132
  }
133

    
134
  if(isset($url)) {
135
    $variables[$which_image . '_url'] = $url;
136

    
137
    if($css_selector) {
138
      if(!isset($variables['inline_styles'])) {
139
        $variables['inline_styles'] = array();
140
      }
141
      $variables['inline_styles'][] = $css_selector . ' {' . "\n"
142
          . ' background: white url(\'' . check_url($url) .'\')  ' . $background_style  . ";\n"
143
          . '}';
144
    }
145
  }
146
}
147

    
148
function _color_gradient($color_1, $color_2) {
149

    
150
  $css = '';
151
  $css .= sprintf('background: %1$s; /* for non-css3 browsers */', $color_1) . "\n";
152
  $css .= sprintf('filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=\'%1$s\', endColorstr=\'%2$s\'); /* for IE */', $color_1, $color_2) . "\n";
153
  $css .= sprintf('background: -webkit-gradient(linear, left top, left bottom, from(%1$s), to(%2$s)); /* for webkit browsers */', $color_1, $color_2) . "\n";
154
  $css .= sprintf('background: -moz-linear-gradient(top,  %1$s,  %2$s); /* for firefox 3.6+ */', $color_1, $color_2) . "\n";
155
  return $css;
156
}
157

    
158
/**
159
 *
160
 */
161
function _add_inline_styles(&$variables) {
162

    
163
  $css = array();
164
  if(!isset($variables['inline_styles'])) {
165
    $variables['inline_styles'] = array();
166
  }
167

    
168
  // site_name
169
  if(theme_get_setting('site-name_color')) {
170
      $variables['inline_styles'][] = '#site-name a span {color:' . check_plain(theme_get_setting('site-name_color')) . ';}';
171
  }
172
  // main-menu_color
173
  if(theme_get_setting('main-menu_color')) {
174
    $variables['inline_styles'][] = '#main-menu a:link, #main-menu a:visited, #main-menu a.active:link {color:' . check_plain(theme_get_setting('main-menu_color')) . ';} ';
175
    $variables['inline_styles'][] = '#navigation #main-menu ul.links li {border-color:' . check_plain(theme_get_setting('main-menu_color')) . ';}';
176
  }
177
  if(theme_get_setting('main-menu_background-color')) {
178
    if(theme_get_setting('main-menu_background-color-2')) {
179
      // with gradient
180
      $variables['inline_styles'][] = '#main-menu {'
181
        . _color_gradient(
182
              theme_get_setting('main-menu_background-color'),
183
              theme_get_setting('main-menu_background-color-2'))
184
        . '}';
185
    } else {
186
      $variables['inline_styles'][] = '#main-menu {background-color:' . check_plain(theme_get_setting('main-menu_background-color')) . ';}';
187
    }
188
  }
189
  if(theme_get_setting('sub-header_background-color')) {
190
    $variables['inline_styles'][] = '#sub-header {background-color:' . check_plain(theme_get_setting('sub-header_background-color')) . ';}';
191
  }
192
  if(theme_get_setting('header_margin_bottom') && theme_get_setting('site_name_position') != 'below_banner') {
193
    $variables['inline_styles'][] = '#sub-header {min-height: 0; height:' . check_plain(theme_get_setting('header_margin_bottom')) . ';}';
194
  }
195
  if(theme_get_setting('logo_size')) {
196
    $logo_size = theme_get_setting('logo_size');
197
    $zen_gutter_width = 40; // in px; must be same as $zen-gutter-width in zen_dataportal/sass/layouts/responsive-sidebars.scss
198
    $variables['inline_styles'][] = '#header {background-position:' . ($logo_size['width'] + $zen_gutter_width / 2) . 'px 0;}';
199
    $variables['inline_styles'][] = '
200
    /**
201
     * On small displays the main menu and sub-header must not have extra padding
202
     * on the left side.
203
     */
204
     @media all and (min-width: 480px) {
205
       #main-menu, #sub-header {padding-left:' . $logo_size['width'] . 'px;}
206
     }';
207
  }
208
  // as last styles the user_defined_styles which can be entered into a text field
209
  if(theme_get_setting('user_defined_styles')) {
210
    $variables['inline_styles'][] = check_plain(theme_get_setting('user_defined_styles'));
211
  }
212
}
213

    
214
/**
215
 * Override or insert variables into the maintenance page template.
216
 *
217
 * @param $variables
218
 *   An array of variables to pass to the theme template.
219
 * @param $hook
220
 *   The name of the template being rendered ("maintenance_page" in this case.)
221
 */
222
/* -- Delete this line if you want to use this function
223
function STARTERKIT_preprocess_maintenance_page(&$variables, $hook) {
224
  // When a variable is manipulated or added in preprocess_html or
225
  // preprocess_page, that same work is probably needed for the maintenance page
226
  // as well, so we can just re-use those functions to do that work here.
227
  STARTERKIT_preprocess_html($variables, $hook);
228
  STARTERKIT_preprocess_page($variables, $hook);
229
}
230
// */
231

    
232
/**
233
 * Override or insert variables into the html templates.
234
 *
235
 * @param $variables
236
 *   An array of variables to pass to the theme template.
237
 * @param $hook
238
 *   The name of the template being rendered ("html" in this case.)
239
 */
240
function zen_dataportal_preprocess_html(&$variables, $hook) {
241
  _set_image_url('body_background', $variables, NULL, 'body');
242
  _set_image_url('page_background', $variables, NULL, '#page');
243
  _set_image_url('banner', $variables, 'banner.jpg', '#header', "scroll no-repeat; background-color: white; background-clip: content-box");
244
  _add_inline_styles($variables);
245
  // add class attribute zen_dataportal for theme detection during tests
246
  $variables['classes_array'][] = 'zen_dataportal';
247
}
248

    
249
/**
250
 * Override or insert variables into the page templates.
251
 *
252
 * @param $variables
253
 *   An array of variables to pass to the theme template.
254
 * @param $hook
255
 *   The name of the template being rendered ("page" in this case.)
256
 */
257
function zen_dataportal_preprocess_page(&$variables, $hook) {
258

    
259
  // site_name_position can be 'hidden', 'above_banner', or 'below_banner'
260
  $variables['site_name_position'] = 'above_banner';
261
  if(theme_get_setting('site_name_position')) {
262
    $variables['site_name_position'] = check_plain(theme_get_setting('site_name_position'));
263
  }
264
  // header_margin_bottom value can be any css length measurement
265
  $variables['header_margin_bottom'] = '0';
266
  if(theme_get_setting('header_margin_bottom')) {
267
    $variables['header_margin_bottom'] = check_plain(theme_get_setting('header_margin_bottom'));
268
  }
269

    
270
}
271

    
272
/**
273
 * Override or insert variables into the node templates.
274
 *
275
 * @param $variables
276
 *   An array of variables to pass to the theme template.
277
 * @param $hook
278
 *   The name of the template being rendered ("node" in this case.)
279
 */
280
/* -- Delete this line if you want to use this function
281
function STARTERKIT_preprocess_node(&$variables, $hook) {
282
  $variables['sample_variable'] = t('Lorem ipsum.');
283

    
284
  // Optionally, run node-type-specific preprocess functions, like
285
  // STARTERKIT_preprocess_node_page() or STARTERKIT_preprocess_node_story().
286
  $function = __FUNCTION__ . '_' . $variables['node']->type;
287
  if (function_exists($function)) {
288
    $function($variables, $hook);
289
  }
290
}
291
// */
292

    
293
/**
294
 * Override or insert variables into the comment templates.
295
 *
296
 * @param $variables
297
 *   An array of variables to pass to the theme template.
298
 * @param $hook
299
 *   The name of the template being rendered ("comment" in this case.)
300
 */
301
/* -- Delete this line if you want to use this function
302
function STARTERKIT_preprocess_comment(&$variables, $hook) {
303
  $variables['sample_variable'] = t('Lorem ipsum.');
304
}
305
// */
306

    
307
/**
308
 * Override or insert variables into the region templates.
309
 *
310
 * @param $variables
311
 *   An array of variables to pass to the theme template.
312
 * @param $hook
313
 *   The name of the template being rendered ("region" in this case.)
314
 */
315
/* -- Delete this line if you want to use this function
316
function STARTERKIT_preprocess_region(&$variables, $hook) {
317
  // Don't use Zen's region--sidebar.tpl.php template for sidebars.
318
  //if (strpos($variables['region'], 'sidebar_') === 0) {
319
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('region__sidebar'));
320
  //}
321
}
322
// */
323

    
324
/**
325
 * Override or insert variables into the block templates.
326
 *
327
 * @param $variables
328
 *   An array of variables to pass to the theme template.
329
 * @param $hook
330
 *   The name of the template being rendered ("block" in this case.)
331
 */
332
/* -- Delete this line if you want to use this function
333
function STARTERKIT_preprocess_block(&$variables, $hook) {
334
  // Add a count to all the blocks in the region.
335
  // $variables['classes_array'][] = 'count-' . $variables['block_id'];
336

    
337
  // By default, Zen will use the block--no-wrapper.tpl.php for the main
338
  // content. This optional bit of code undoes that:
339
  //if ($variables['block_html_id'] == 'block-system-main') {
340
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
341
  //}
342
}
343
// */
(13-13/15)