Project

General

Profile

Download (13.1 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 . ' {background: white url(' . check_url($url) .')  ' . $background_style . ';}';
142
    }
143
  }
144
}
145

    
146
function _color_gradient($color_1, $color_2) {
147

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

    
156
/**
157
 *
158
 */
159
function _add_inline_styles(&$variables) {
160

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

    
166
  // site_name
167
  if(theme_get_setting('site-name_color')) {
168
      $variables['inline_styles'][] = '#site-name a span {color:' . check_plain(theme_get_setting('site-name_color')) . ';}';
169
  }
170
  if(theme_get_setting('main-menu_background-color')) {
171
    if(theme_get_setting('main-menu_background-color-2')) {
172
      // with gradient
173
      $variables['inline_styles'][] = '#main-menu {'
174
        . _color_gradient(
175
              theme_get_setting('main-menu_background-color'),
176
              theme_get_setting('main-menu_background-color-2'))
177
        . '}';
178
    } else {
179
      $variables['inline_styles'][] = '#main-menu {background-color:' . check_plain(theme_get_setting('main-menu_background-color')) . ';}';
180
    }
181
  }
182
  if(theme_get_setting('sub-header_background-color')) {
183
    $variables['inline_styles'][] = '#sub-header {background-color:' . check_plain(theme_get_setting('sub-header_background-color')) . ';}';
184
  }
185
  if(theme_get_setting('header_margin_bottom') && theme_get_setting('site_name_position') != 'below_banner') {
186
    $variables['inline_styles'][] = '#sub-header {min-height: 0; height:' . check_plain(theme_get_setting('header_margin_bottom')) . ';}';
187
  }
188
  if(theme_get_setting('logo_size')) {
189
    $logo_size = theme_get_setting('logo_size');
190
    $variables['inline_styles'][] = '#header {background-position:' . $logo_size['width'] . 'px 0;}';
191
    $variables['inline_styles'][] = '#main-menu, #sub-header {padding-left:' . $logo_size['width'] . 'px;}';
192
  }
193
}
194

    
195
/**
196
 * Override or insert variables into the maintenance page template.
197
 *
198
 * @param $variables
199
 *   An array of variables to pass to the theme template.
200
 * @param $hook
201
 *   The name of the template being rendered ("maintenance_page" in this case.)
202
 */
203
/* -- Delete this line if you want to use this function
204
function STARTERKIT_preprocess_maintenance_page(&$variables, $hook) {
205
  // When a variable is manipulated or added in preprocess_html or
206
  // preprocess_page, that same work is probably needed for the maintenance page
207
  // as well, so we can just re-use those functions to do that work here.
208
  STARTERKIT_preprocess_html($variables, $hook);
209
  STARTERKIT_preprocess_page($variables, $hook);
210
}
211
// */
212

    
213
/**
214
 * Override or insert variables into the html templates.
215
 *
216
 * @param $variables
217
 *   An array of variables to pass to the theme template.
218
 * @param $hook
219
 *   The name of the template being rendered ("html" in this case.)
220
 */
221
function zen_dataportal_preprocess_html(&$variables, $hook) {
222
  _set_image_url('body_background', $variables, NULL, 'body');
223
  _set_image_url('page_background', $variables, NULL, '#page');
224
  _set_image_url('banner', $variables, 'banner.jpg', '#header', 'scroll no-repeat content-box');
225
  _add_inline_styles($variables);
226

    
227
}
228

    
229
/**
230
 * Override or insert variables into the page templates.
231
 *
232
 * @param $variables
233
 *   An array of variables to pass to the theme template.
234
 * @param $hook
235
 *   The name of the template being rendered ("page" in this case.)
236
 */
237
function zen_dataportal_preprocess_page(&$variables, $hook) {
238

    
239
  $variables['site_name_position'] = 'over_banner';
240
  if(theme_get_setting('site_name_position')) {
241
    $variables['site_name_position'] = check_plain(theme_get_setting('site_name_position'));
242
  }
243
  $variables['header_margin_bottom'] = 'over_banner';
244
  if(theme_get_setting('header_margin_bottom')) {
245
    $variables['header_margin_bottom'] = check_plain(theme_get_setting('header_margin_bottom'));
246
  }
247

    
248
}
249

    
250
/**
251
 * Override or insert variables into the node templates.
252
 *
253
 * @param $variables
254
 *   An array of variables to pass to the theme template.
255
 * @param $hook
256
 *   The name of the template being rendered ("node" in this case.)
257
 */
258
/* -- Delete this line if you want to use this function
259
function STARTERKIT_preprocess_node(&$variables, $hook) {
260
  $variables['sample_variable'] = t('Lorem ipsum.');
261

    
262
  // Optionally, run node-type-specific preprocess functions, like
263
  // STARTERKIT_preprocess_node_page() or STARTERKIT_preprocess_node_story().
264
  $function = __FUNCTION__ . '_' . $variables['node']->type;
265
  if (function_exists($function)) {
266
    $function($variables, $hook);
267
  }
268
}
269
// */
270

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

    
285
/**
286
 * Override or insert variables into the region templates.
287
 *
288
 * @param $variables
289
 *   An array of variables to pass to the theme template.
290
 * @param $hook
291
 *   The name of the template being rendered ("region" in this case.)
292
 */
293
/* -- Delete this line if you want to use this function
294
function STARTERKIT_preprocess_region(&$variables, $hook) {
295
  // Don't use Zen's region--sidebar.tpl.php template for sidebars.
296
  //if (strpos($variables['region'], 'sidebar_') === 0) {
297
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('region__sidebar'));
298
  //}
299
}
300
// */
301

    
302
/**
303
 * Override or insert variables into the block templates.
304
 *
305
 * @param $variables
306
 *   An array of variables to pass to the theme template.
307
 * @param $hook
308
 *   The name of the template being rendered ("block" in this case.)
309
 */
310
/* -- Delete this line if you want to use this function
311
function STARTERKIT_preprocess_block(&$variables, $hook) {
312
  // Add a count to all the blocks in the region.
313
  // $variables['classes_array'][] = 'count-' . $variables['block_id'];
314

    
315
  // By default, Zen will use the block--no-wrapper.tpl.php for the main
316
  // content. This optional bit of code undoes that:
317
  //if ($variables['block_html_id'] == 'block-system-main') {
318
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
319
  //}
320
}
321
// */
(7-7/9)