Project

General

Profile

Download (9.27 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Overrides of generic themeing functions in cdm_dataportal.theme.php.
5
 */
6

    
7
/*
8
  ***** GARLAND OVERRIDES *****
9
*/
10

    
11
/**
12
 * Sets the body-tag class attribute.
13
 *
14
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
15
 */
16
function phptemplate_body_class($sidebar_left, $sidebar_right) {
17
  if ($sidebar_left != '' && $sidebar_right != '') {
18
    $class = 'sidebars';
19
  }
20
  else {
21
    if ($sidebar_left != '') {
22
      $class = 'sidebar-left';
23
    }
24
    if ($sidebar_right != '') {
25
      $class = 'sidebar-right';
26
    }
27
  }
28

    
29
  if (isset($class)) {
30
    print ' class="' . $class . '"';
31
  }
32
}
33

    
34

    
35
/**
36
 * Override or insert PHPTemplate variables into the templates.
37
 */
38
function _phptemplate_variables($hook, $vars) {
39
  if ($hook == 'page') {
40

    
41
    if ($secondary = menu_secondary_local_tasks()) {
42
      $output = '<span class="clear"></span>';
43
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
44
      $vars['tabs2'] = $output;
45
    }
46

    
47
    // Hook into color.module
48
    if (module_exists('color')) {
49
      _color_page_alter($vars);
50
    }
51
    return $vars;
52
  }
53
  return array();
54
}
55

    
56
/**
57
 * Returns HTML for the rendered local tasks.
58
 *
59
 * The default implementation renders them as tabs.
60
 *
61
 * @ingroup themeable
62
 */
63
function phptemplate_menu_local_tasks() {
64
  $output = '';
65

    
66
  if ($primary = menu_primary_local_tasks()) {
67
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
68
  }
69

    
70
  return $output;
71
}
72

    
73
/**
74
 * Returns HTML for taxon list thumbnails.
75
 *
76
 * Theme specific mods:
77
 * $captionElements = array('title', '#uri'=>t('open Image'));
78
 * $mediaLinkType:
79
 * "NORMAL": link to the image page or to the $alternativeMediaUri if it is
80
 * defined instead of
81
 * "LIGHTBOX": open the link in a light box,
82
 * TODO expose those in admin section, by adding 'em to gallery_settings see
83
 * http://dev.e-taxonomy.eu/trac/ticket/2494.
84
 *
85
 * @param array $variables
86
 *   An associative array containing:
87
 *   - taxon: The taxon object for which to theme the thumbnails.
88
 *
89
 * @ingroup themeable
90
 */
91
function garland_cichorieae_cdm_taxon_list_thumbnails($variables) {
92
  $out = '';
93
  $taxon = $variables['taxon'];
94

    
95
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
96

    
97
  $mediaLinkType = 'NORMAL';
98
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
99
  $captionElements = array();
100
  if ($showCaption) {
101
    $captionElements = array('title', '#uri' => t('open Image'));
102
  }
103

    
104
  $gallery_name = $taxon->uuid;
105

    
106
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
107

    
108
  $mediaList = $mediaList = _load_media_for_taxon($taxon);
109

    
110
  $out .= theme('cdm_media_gallerie', array(
111
    'mediaList' => $mediaList,
112
    'galleryName' => $gallery_name,
113
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
114
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
115
    'maxRows' => $gallery_settings['cdm_dataportal_media_maxRows'],
116
    'captionElements' => $captionElements,
117
    'mediaLinkType' => $mediaLinkType,
118
    'alternativeMediaUri' => $galleryLinkUri,
119
    'showCaption' => NULL,
120
  ));
121

    
122
  return $out;
123
}
124

    
125
/**
126
 * @todo Please document this function.
127
 * @see http://drupal.org/node/1354
128
 */
129
function garland_cichorieae_cdm_feature_name($variables) {
130
  $feature_name = $variables['feature_name'];
131
  switch ($feature_name) {
132
    case "Protologue":
133
      return t("Original Publication");
134
    default:
135
      return ucfirst($feature_name);
136
  }
137
}
138

    
139
/*
140
======== Special functions for subtheme handling=============
141
*/
142

    
143
/**
144
 * @todo Please document this function.
145
 * @see http://drupal.org/node/1354
146
 */
147
function sub_theme() {
148
  global $user, $custom_theme;
149

    
150
  // Only select the user selected theme if it is available in the
151
  // list of enabled themes.
152
  $themes = list_themes();
153
  $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'garland');
154

    
155
  // Allow modules to override the present theme... only select custom theme
156
  // if it is available in the list of installed themes.
157
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
158

    
159
  return $theme;
160
}
161

    
162
/**
163
 * Return the path to the currently selected sub theme.
164
 */
165
function path_to_sub_theme() {
166
  $themes = list_themes();
167
  $theme = sub_theme();
168
  return dirname($themes[$theme]->filename);
169
}
170

    
171
/**
172
 * Implements hook_preprocess_HOOK() for theme_page().
173
 *
174
 * Assign the css classes primary-links and secondary-links to the menus.
175
 * Modify primary-links if cdm_api module exists.
176
 */
177
function garland_cichorieae_preprocess_page(&$vars) {
178
  if (isset($vars['main_menu'])) {
179
    /*
180
    obsolete, see http://dev.e-taxonomy.eu/trac/ticket/2191
181
    if(module_exists('cdm_api')){ foreach($vars['main_menu'] as $key =>
182
    $menu_item){ // nb this makes each menu item you click opening a new
183
    browser window..
184
    $menu_item['attributes']['target']=generalizeString($menu_item['title']);
185
    $main_menu[] = $menu_item; }; }else{ $main_menu = $vars['main_menu'] ; };
186
    */
187
    $vars['primary_nav'] = theme('links__system_main_menu', array(
188
      'links' => $vars['main_menu'], 'attributes' => array(
189
        'class' => array(
190
          'links', 'inline', 'main-menu', 'primary-links',
191
        )),
192
        'heading' => array(
193
          'text' => t('Main menu'), 'level' => 'h2', 'class' => array(
194
            'element-invisible',
195
          ))));
196
  }
197
  else {
198
    $vars['primary_nav'] = FALSE;
199
  }
200
  if (isset($vars['secondary_menu'])) {
201
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
202
      'links' => $vars['secondary_menu'], 'attributes' => array(
203
        'class' => array(
204
          'links',
205
          'inline',
206
          'secondary-menu',
207
          'secondary-links',
208
        )),
209
        'heading' => array(
210
          'text' => t('Secondary menu'),
211
          'level' => 'h2',
212
          'class' => array('element-invisible'),
213
        )));
214
  }
215
  else {
216
    $vars['secondary_nav'] = FALSE;
217
  }
218

    
219
  /*
220
  Display node title as page title for the comment form.
221
  Comment @WA: it would probably be better to select $uuid from node_cdm
222
  table and link to cdm_dataportal/taxon/%uuid instead.
223
  */
224
  if (arg(0) == 'comment' && arg(1) == 'reply') {
225
    $node = $vars['page']['content']['system_main']['comment_node']['#node'];
226
    $vars['title'] = l(check_plain($node->title), 'node/' . $node->nid);
227
  }
228
}
229

    
230
/**
231
 * Implements hook_preprocess_HOOK() for theme_node().
232
 *
233
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
234
 * like <img src="/files/..
235
 *
236
 * Portals can be installed in configurations with
237
 * sub-directories however, in which case these urls need to be adjusted.
238
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
239
 *
240
 * Therefore preprocess nodes and replace these urls with a the appropriate url
241
 * for the current setup.
242
 *
243
 * @author W.Addink <w.addink@eti.uva.nl>
244
 */
245
function garland_cichorieae_preprocess_node(&$vars) {
246
  $body = '';
247
  // Warning: use #markup value, for which filters like php, html etc are applied!
248
  if (isset($vars['content']['body'][0]['#markup'])) {
249
    $body = $vars['content']['body'][0]['#markup'];
250
  }
251
  else {
252
    $vars['fixed_body'] = '';
253
    return;
254
  }
255

    
256
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
257
  global $base_url;
258
  if ($base_url == '/') {
259
    drupal_set_message(t('
260
      The $base_url in this portal could not be set, please set the $base_url
261
      manually your Drupal settings.php file.', 'error'
262
    ));
263
  }
264
  $fixed_file_path = $base_url . $file_path;
265
  $preg_file_path = preg_quote($file_path, '/');
266
  $body = preg_replace('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path, $body);
267
  $body = preg_replace('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path, $body);
268
  $body = preg_replace('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path, $body);
269
  $body = preg_replace('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path, $body);
270

    
271
  $vars['fixed_body'] = $body;
272
}
273

    
274
/**
275
 * Implements hook_form_FORM_ID_alter() for comment_form().
276
 *
277
 * Alter the comment form to make it look like a D5 style comment form.
278
 *
279
 * @author W.Addink <w.addink@eti.uva.nl>
280
 */
281
function garland_cichorieae_form_comment_form_alter(&$form, &$form_state) {
282

    
283
  if (!isset($form['comment_preview'])) {
284
    $form['header'] = array(
285
      '#markup' => '<h2>' . t('Reply') . '</h2>',
286
      '#weight' => -2,
287
    );
288
  }
289
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
290
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
291
  if (isset($form['author']['_author']['#title'])) {
292
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
293
  }
294
  $form['actions']['submit']['#value'] = t('Post comment');
295
  $form['actions']['submit']['#weight'] = 1000;
296
  $form['actions']['preview']['#value'] = t('Preview comment');
297
}
298

    
299
/**
300
 * Implements hook_preprocess_HOOK() for theme_comment().
301
 *
302
 * Alter the comment display to make it look like a D5 style comment.
303
 *
304
 * @author W.Addink <w.addink@eti.uva.nl>
305
 */
306
function garland_cichorieae_preprocess_comment(&$variables) {
307
  $comment = $variables['elements']['#comment'];
308
  if (isset($comment->subject)) {
309
    // Print title without link.
310
    $variables['title'] = $comment->subject;
311
    if ($variables['status'] == 'comment-preview') {
312
      // Add 'new' to preview.
313
      $variables['new'] = t('new');
314
    }
315
  }
316
}
(12-12/13)