Project

General

Profile

Download (11 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 $css_selector
110
 *   The dom element to apply the image as background image
111
 * @param $background_style
112
 *   Addtional css setting for the background css attribute, default is  'scroll repeat'
113
 *
114
 * @see _zen_dataportal_imagenames() for possible values
115
 */
116
function _set_image_url($which_image, &$variables, $css_selector = NULL, $background_style = 'scroll repeat') {
117

    
118

    
119
  if (!theme_get_setting('default_' . $which_image)) {
120
    $path = theme_get_setting($which_image . '_path');
121
    if(isset($path)){
122
      if (file_uri_scheme($path) == 'public') {
123
        $url = file_create_url($path);
124
      }
125
      if(isset($url)) {
126
        $variables[$which_image . '_url'] = $url;
127

    
128
        if($css_selector) {
129
          if(!isset($variables['inline_styles'])) {
130
            $variables['inline_styles'] = array();
131
          }
132
          // FIXME is not save only works if no other style given e.g. html.php $attributes
133
          $variables['inline_styles'][] = $css_selector . ' {background: white url(' . $url .')  ' . $background_style . ';}';
134
        }
135
      }
136

    
137
    }
138
  }
139
}
140
/**
141
 *
142
 */
143
function _add_inline_styles(&$variables) {
144

    
145
  $css = array();
146
  if(!isset($variables['inline_styles'])) {
147
    $variables['inline_styles'] = array();
148
  }
149

    
150
  // site_name
151
  if(theme_get_setting('site_name_color')) {
152
      $variables['inline_styles'][] = "#site-name a span {color:" . theme_get_setting('site_name_color') . ';}';
153
  }
154
  if(theme_get_setting('logo_size')) {
155
    $logo_size = theme_get_setting('logo_size');
156
    $variables['inline_styles'][] = '#header {background-position:' . $logo_size['width'] . 'px 0;}';
157
    $variables['inline_styles'][] = '#main-menu {padding-left:' . $logo_size['width'] . 'px;}';
158
  }
159
}
160

    
161

    
162
/**
163
 * Override or insert variables into the maintenance page template.
164
 *
165
 * @param $variables
166
 *   An array of variables to pass to the theme template.
167
 * @param $hook
168
 *   The name of the template being rendered ("maintenance_page" in this case.)
169
 */
170
/* -- Delete this line if you want to use this function
171
function STARTERKIT_preprocess_maintenance_page(&$variables, $hook) {
172
  // When a variable is manipulated or added in preprocess_html or
173
  // preprocess_page, that same work is probably needed for the maintenance page
174
  // as well, so we can just re-use those functions to do that work here.
175
  STARTERKIT_preprocess_html($variables, $hook);
176
  STARTERKIT_preprocess_page($variables, $hook);
177
}
178
// */
179

    
180
/**
181
 * Override or insert variables into the html templates.
182
 *
183
 * @param $variables
184
 *   An array of variables to pass to the theme template.
185
 * @param $hook
186
 *   The name of the template being rendered ("html" in this case.)
187
 */
188
function zen_dataportal_preprocess_html(&$variables, $hook) {
189
  _set_image_url('body_background', $variables, 'body');
190
  _set_image_url('page_background', $variables, '#page');
191
  _set_image_url('banner', $variables, '#header', 'scroll no-repeat content-box');
192
  _add_inline_styles($variables);
193
}
194

    
195
/**
196
 * Override or insert variables into the page templates.
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 ("page" in this case.)
202
 */
203
function zen_dataportal_preprocess_page(&$variables, $hook) {
204
}
205

    
206
/**
207
 * Override or insert variables into the node templates.
208
 *
209
 * @param $variables
210
 *   An array of variables to pass to the theme template.
211
 * @param $hook
212
 *   The name of the template being rendered ("node" in this case.)
213
 */
214
/* -- Delete this line if you want to use this function
215
function STARTERKIT_preprocess_node(&$variables, $hook) {
216
  $variables['sample_variable'] = t('Lorem ipsum.');
217

    
218
  // Optionally, run node-type-specific preprocess functions, like
219
  // STARTERKIT_preprocess_node_page() or STARTERKIT_preprocess_node_story().
220
  $function = __FUNCTION__ . '_' . $variables['node']->type;
221
  if (function_exists($function)) {
222
    $function($variables, $hook);
223
  }
224
}
225
// */
226

    
227
/**
228
 * Override or insert variables into the comment templates.
229
 *
230
 * @param $variables
231
 *   An array of variables to pass to the theme template.
232
 * @param $hook
233
 *   The name of the template being rendered ("comment" in this case.)
234
 */
235
/* -- Delete this line if you want to use this function
236
function STARTERKIT_preprocess_comment(&$variables, $hook) {
237
  $variables['sample_variable'] = t('Lorem ipsum.');
238
}
239
// */
240

    
241
/**
242
 * Override or insert variables into the region templates.
243
 *
244
 * @param $variables
245
 *   An array of variables to pass to the theme template.
246
 * @param $hook
247
 *   The name of the template being rendered ("region" in this case.)
248
 */
249
/* -- Delete this line if you want to use this function
250
function STARTERKIT_preprocess_region(&$variables, $hook) {
251
  // Don't use Zen's region--sidebar.tpl.php template for sidebars.
252
  //if (strpos($variables['region'], 'sidebar_') === 0) {
253
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('region__sidebar'));
254
  //}
255
}
256
// */
257

    
258
/**
259
 * Override or insert variables into the block templates.
260
 *
261
 * @param $variables
262
 *   An array of variables to pass to the theme template.
263
 * @param $hook
264
 *   The name of the template being rendered ("block" in this case.)
265
 */
266
/* -- Delete this line if you want to use this function
267
function STARTERKIT_preprocess_block(&$variables, $hook) {
268
  // Add a count to all the blocks in the region.
269
  // $variables['classes_array'][] = 'count-' . $variables['block_id'];
270

    
271
  // By default, Zen will use the block--no-wrapper.tpl.php for the main
272
  // content. This optional bit of code undoes that:
273
  //if ($variables['block_html_id'] == 'block-system-main') {
274
  //  $variables['theme_hook_suggestions'] = array_diff($variables['theme_hook_suggestions'], array('block__no_wrapper'));
275
  //}
276
}
277
// */
(6-6/8)