Project

General

Profile

Download (15.8 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
 * @todo Please document this function.
9
 * @see http://drupal.org/node/1354
10
 */
11
function DISABLED_garland_cichorieae_cdm_descriptionElementTextData($variables) {
12
  $element = $variables['element'];
13
  $asListElement = $variables['asListElement'];
14
  $feature_uuid = $variables['feature_uuid'];
15

    
16
  $sourceRefs = '';
17

    
18
  $description = '';
19
  if (isset($element->multilanguageText_L10n->text)) {
20
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
21
  }
22

    
23
  // annotations footnotes.
24
  $annotation_fkeys = theme('cdm_annotations_as_footnotekeys',
25
    array(
26
      'cdmBase_list' => $element,
27
      'footnote_list_key' => $feature_uuid,
28
    )
29
  );
30

    
31
  // ---------------------------------------------------------------------------
32
  // CUSTOM CODE (1) the below needs to become configurable in the settings
33
  $default_theme = variable_get('theme_default', 'garland_cichorieae');
34

    
35
  if (($default_theme == 'flora_malesiana' || $default_theme == 'flore_afrique_centrale' || $default_theme == 'flore_gabon') && $element->feature->titleCache == 'Citation') {
36
    $asListElement = TRUE;
37
  }
38
  elseif ($element->feature->uuid == UUID_CHROMOSOMES_NUMBERS) {
39
    $asListElement = TRUE;
40
  }
41
  else {
42
    $asListElement = FALSE;
43
  }
44

    
45
  // END CUSTOM CODE (1)
46
  // ---------------------------------------------------------------------------
47

    
48
  // original sources
49
  if (is_array($element->sources)) {
50
    foreach ($element->sources as $source) {
51
      // ---------------------------------------------------------------------------
52
      // CUSTOM CODE (2)
53
      if ($feature_uuid == UUID_CITATION) {
54
        $referenceCitation = cdm_ws_get(
55
          CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
56
          array($source->citation->uuid),
57
          "microReference=" . urlencode($source->citationMicroReference
58
        ));
59
        $referenceCitation = $referenceCitation->String;
60
      }
61
      // END CUSTOM CODE (2)
62
      // ---------------------------------------------------------------------------
63
      else {
64
        $referenceCitation = theme('cdm_OriginalSource', array(
65
          'source' => $source,
66
          'doLink' => ($feature_uuid != UUID_CITATION && $feature_uuid != UUID_CHROMOSOMES), // CUSTOM CODE (3): always show links exept for NAME_USAGE, CHROMOSOMES
67
        ));
68
      }
69
      if ($description && strlen($description) > 0 && $referenceCitation) {
70
        $sourceRefs .= ' (' . $referenceCitation . ')';
71
      }
72
      elseif ($referenceCitation) {
73
        $sourceRefs = $referenceCitation;
74
      }
75

    
76
      if (strlen($sourceRefs) > 0) {
77
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
78
      }
79
      // ----------------------------------------------------------------------------
80
      // CITATION special cases - needs to go into core code
81

    
82
      // link the nameUsedInSource to the according name page
83
      $name_used_in_source_link_to_show = '';
84
      if (isset($source->nameUsedInSource->uuid) && ($feature_uuid != UUID_CITATION)) {
85
        // It is a DescriptionElementSource && !CITATION
86
        // Do a link to name page.
87
        $name_used_in_source_link_to_show = l(
88
            $source->nameUsedInSource->titleCache,
89
            path_to_name($source->nameUsedInSource->uuid),
90
            array(
91
                'attributes' => array(),
92
                'absolute' => TRUE,
93
                'html' => TRUE)
94
            );
95
      }
96
      else if (isset($source->nameUsedInSource->uuid) && ($feature_uuid == UUID_CITATION)) {
97
        // It is a DescriptionElementSource && CITATION
98
        // Do not do link for CITATION feature.
99
        $name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
100
      }
101
      elseif (isset($source->nameUsedInSource->originalNameString)
102
        && strlen($source->nameUsedInSource->originalNameString) > 0) {
103
        // It is NOT a DescriptionElementSource!
104
        // ReferencedEntityBase.originalNameString
105
        // Show a text without link.
106
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
107
      }
108
      // ----------------------------------------------------------------------------
109

    
110
      // final composition of the TextData element
111
      if ($asListElement && ($feature_uuid == UUID_CITATION)) {
112
        $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
113
        // Adding ":" if necessary.
114
        if (!empty($name_used_in_source_link_to_show) &&
115
          (!empty($description) || !empty($sourceRefs))) {
116
          $out .= ': ';
117
        }
118

    
119
        $out .= $description . $sourceRefs
120
        // THIS IS NONSENSE, should be already in $annotation_fkeys:
121
//          . theme('cdm_annotations_as_footnotekeys',
122
//              array(
123
//                'cdmBase_list' => $element,
124
//                'footnote_list_key' => $feature_uuid,
125
//              )
126
//            )
127
          . $annotation_fkeys . '</li>';
128
      }
129
      elseif ($asListElement) {
130
        // this for sure only accounts to UUID_CHROMOSOME and UUID_CHROMOSOMES_NUMBERS
131

    
132
        $out = '<li class="descriptionText DescriptionElement">';
133
        // displayed like: Cerastium fontanum Baumg.: in Fl. Ceylon: 60. 1996
134
        // Adding ":" if necessary.
135
        if (!empty($name_used_in_source_link_to_show)) {
136
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
137
            $out .= $name_used_in_source_link_to_show . ': ';
138
          } else {
139
            $out .= $name_used_in_source_link_to_show . ' ';
140
          }
141
        }
142

    
143
        $out .= $description . $sourceRefs
144
          // THIS IS NONSENSE, should be already in $annotation_fkeys:
145
//          . theme('cdm_annotations_as_footnotekeys', array(
146
//          'cdmBase_list' => $element,
147
//          'footnote_list_key' => $feature_uuid,
148
//        ))
149
          . $annotation_fkeys . '</li>';
150
        // Special handling for flora malesiana.
151
        // TODO: possible better way to implement this case?
152
      }
153
      else {
154
        if (isset($name_used_in_source_link_to_show)) {
155
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
156
        }
157
        $out = '<span class="' . html_class_attribute_ref($element) . '"> '
158
          . $description . $sourceRefs . $name_used_in_source_link_to_show . $annotation_fkeys . '</span>';
159
      }
160
    }
161
  }
162

    
163
  // If no sources, print the description.
164
  if (!isset($out)) {
165
    $out = '<span class="' . html_class_attribute_ref($element) . '"> '
166
      . $description . $annotation_fkeys . '</span>';
167
  }
168

    
169
  // Add annotations as footnote key.
170
  //  $out .= theme('cdm_annotations_as_footnotekeys', $element);
171
  return $out;
172
}
173

    
174
/*
175
  ***** GARLAND OVERRIDES *****
176
*/
177

    
178
/**
179
 * Sets the body-tag class attribute.
180
 *
181
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
182
 */
183
function phptemplate_body_class($sidebar_left, $sidebar_right) {
184
  if ($sidebar_left != '' && $sidebar_right != '') {
185
    $class = 'sidebars';
186
  }
187
  else {
188
    if ($sidebar_left != '') {
189
      $class = 'sidebar-left';
190
    }
191
    if ($sidebar_right != '') {
192
      $class = 'sidebar-right';
193
    }
194
  }
195

    
196
  if (isset($class)) {
197
    print ' class="' . $class . '"';
198
  }
199
}
200

    
201

    
202
/**
203
 * Override or insert PHPTemplate variables into the templates.
204
 */
205
function _phptemplate_variables($hook, $vars) {
206
  if ($hook == 'page') {
207

    
208
    if ($secondary = menu_secondary_local_tasks()) {
209
      $output = '<span class="clear"></span>';
210
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
211
      $vars['tabs2'] = $output;
212
    }
213

    
214
    // Hook into color.module
215
    if (module_exists('color')) {
216
      _color_page_alter($vars);
217
    }
218
    return $vars;
219
  }
220
  return array();
221
}
222

    
223
/**
224
 * Returns HTML for the rendered local tasks.
225
 *
226
 * The default implementation renders them as tabs.
227
 *
228
 * @ingroup themeable
229
 */
230
function phptemplate_menu_local_tasks() {
231
  $output = '';
232

    
233
  if ($primary = menu_primary_local_tasks()) {
234
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
235
  }
236

    
237
  return $output;
238
}
239

    
240
/**
241
 * Returns HTML for taxon list thumbnails.
242
 *
243
 * Theme specific mods:
244
 * $captionElements = array('title', '#uri'=>t('open Image'));
245
 * $mediaLinkType:
246
 * "NORMAL": link to the image page or to the $alternativeMediaUri if it is
247
 * defined instead of
248
 * "LIGHTBOX": open the link in a light box,
249
 * TODO expose those in admin section, by adding 'em to gallery_settings see
250
 * http://dev.e-taxonomy.eu/trac/ticket/2494.
251
 *
252
 * @param array $variables
253
 *   An associative array containing:
254
 *   - taxon: The taxon object for which to theme the thumbnails.
255
 *
256
 * @ingroup themeable
257
 */
258
function garland_cichorieae_cdm_taxon_list_thumbnails($variables) {
259
  $out = '';
260
  $taxon = $variables['taxon'];
261

    
262
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
263

    
264
  $mediaLinkType = 'NORMAL';
265
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
266
  $captionElements = array();
267
  if ($showCaption) {
268
    $captionElements = array('title', '#uri' => t('open Image'));
269
  }
270

    
271
  $gallery_name = $taxon->uuid;
272

    
273
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
274

    
275
  $mediaList = $mediaList = _load_media_for_taxon($taxon);
276

    
277
  $out .= theme('cdm_media_gallerie', array(
278
    'mediaList' => $mediaList,
279
    'galleryName' => $gallery_name,
280
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
281
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
282
    'maxRows' => $gallery_settings['cdm_dataportal_media_maxRows'],
283
    'captionElements' => $captionElements,
284
    'mediaLinkType' => $mediaLinkType,
285
    'alternativeMediaUri' => $galleryLinkUri,
286
    'showCaption' => NULL,
287
  ));
288

    
289
  return $out;
290
}
291

    
292
/**
293
 * @todo Please document this function.
294
 * @see http://drupal.org/node/1354
295
 */
296
function garland_cichorieae_cdm_feature_name($variables) {
297
  $feature_name = $variables['feature_name'];
298
  switch ($feature_name) {
299
    case "Protologue":
300
      return t("Original Publication");
301
    default:
302
      return ucfirst($feature_name);
303
  }
304
}
305

    
306
/*
307
======== Special functions for subtheme handling=============
308
*/
309

    
310
/**
311
 * @todo Please document this function.
312
 * @see http://drupal.org/node/1354
313
 */
314
function sub_theme() {
315
  global $user, $custom_theme;
316

    
317
  // Only select the user selected theme if it is available in the
318
  // list of enabled themes.
319
  $themes = list_themes();
320
  $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'garland');
321

    
322
  // Allow modules to override the present theme... only select custom theme
323
  // if it is available in the list of installed themes.
324
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
325

    
326
  return $theme;
327
}
328

    
329
/**
330
 * Return the path to the currently selected sub theme.
331
 */
332
function path_to_sub_theme() {
333
  $themes = list_themes();
334
  $theme = sub_theme();
335
  return dirname($themes[$theme]->filename);
336
}
337

    
338
/**
339
 * Implements hook_preprocess_HOOK() for theme_page().
340
 *
341
 * Assign the css classes primary-links and secondary-links to the menus.
342
 * Modify primary-links if cdm_api module exists.
343
 */
344
function garland_cichorieae_preprocess_page(&$vars) {
345
  if (isset($vars['main_menu'])) {
346
    /*
347
    obsolete, see http://dev.e-taxonomy.eu/trac/ticket/2191
348
    if(module_exists('cdm_api')){ foreach($vars['main_menu'] as $key =>
349
    $menu_item){ // nb this makes each menu item you click opening a new
350
    browser window..
351
    $menu_item['attributes']['target']=generalizeString($menu_item['title']);
352
    $main_menu[] = $menu_item; }; }else{ $main_menu = $vars['main_menu'] ; };
353
    */
354
    $vars['primary_nav'] = theme('links__system_main_menu', array(
355
      'links' => $vars['main_menu'], 'attributes' => array(
356
        'class' => array(
357
          'links', 'inline', 'main-menu', 'primary-links',
358
        )),
359
        'heading' => array(
360
          'text' => t('Main menu'), 'level' => 'h2', 'class' => array(
361
            'element-invisible',
362
          ))));
363
  }
364
  else {
365
    $vars['primary_nav'] = FALSE;
366
  }
367
  if (isset($vars['secondary_menu'])) {
368
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
369
      'links' => $vars['secondary_menu'], 'attributes' => array(
370
        'class' => array(
371
          'links',
372
          'inline',
373
          'secondary-menu',
374
          'secondary-links',
375
        )),
376
        'heading' => array(
377
          'text' => t('Secondary menu'),
378
          'level' => 'h2',
379
          'class' => array('element-invisible'),
380
        )));
381
  }
382
  else {
383
    $vars['secondary_nav'] = FALSE;
384
  }
385

    
386
  /*
387
  Display node title as page title for the comment form.
388
  Comment @WA: it would probably be better to select $uuid from node_cdm
389
  table and link to cdm_dataportal/taxon/%uuid instead.
390
  */
391
  if (arg(0) == 'comment' && arg(1) == 'reply') {
392
    $node = $vars['page']['content']['system_main']['comment_node']['#node'];
393
    $vars['title'] = l(check_plain($node->title), 'node/' . $node->nid);
394
  }
395
}
396

    
397
/**
398
 * Implements hook_preprocess_HOOK() for theme_node().
399
 *
400
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
401
 * like <img src="/files/..
402
 *
403
 * Portals can be installed in configurations with
404
 * sub-directories however, in which case these urls need to be adjusted.
405
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
406
 *
407
 * Therefore preprocess nodes and replace these urls with a the appropriate url
408
 * for the current setup.
409
 *
410
 * @author W.Addink <w.addink@eti.uva.nl>
411
 */
412
function garland_cichorieae_preprocess_node(&$vars) {
413
  $body = '';
414
  // Warning: use #markup value, for which filters like php, html etc are applied!
415
  if (isset($vars['content']['body'][0]['#markup'])) {
416
    $body = $vars['content']['body'][0]['#markup'];
417
  }
418
  else {
419
    $vars['fixed_body'] = '';
420
    return;
421
  }
422

    
423
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
424
  global $base_url;
425
  if ($base_url == '/') {
426
    drupal_set_message(t('
427
      The $base_url in this portal could not be set, please set the $base_url
428
      manually your Drupal settings.php file.', 'error'
429
    ));
430
  }
431
  $fixed_file_path = $base_url . $file_path;
432
  $preg_file_path = preg_quote($file_path, '/');
433
  $body = preg_replace('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path, $body);
434
  $body = preg_replace('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path, $body);
435
  $body = preg_replace('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path, $body);
436
  $body = preg_replace('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path, $body);
437

    
438
  $vars['fixed_body'] = $body;
439
}
440

    
441
/**
442
 * Implements hook_form_FORM_ID_alter() for comment_form().
443
 *
444
 * Alter the comment form to make it look like a D5 style comment form.
445
 *
446
 * @author W.Addink <w.addink@eti.uva.nl>
447
 */
448
function garland_cichorieae_form_comment_form_alter(&$form, &$form_state) {
449

    
450
  if (!isset($form['comment_preview'])) {
451
    $form['header'] = array(
452
      '#markup' => '<h2>' . t('Reply') . '</h2>',
453
      '#weight' => -2,
454
    );
455
  }
456
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
457
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
458
  if (isset($form['author']['_author']['#title'])) {
459
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
460
  }
461
  $form['actions']['submit']['#value'] = t('Post comment');
462
  $form['actions']['submit']['#weight'] = 1000;
463
  $form['actions']['preview']['#value'] = t('Preview comment');
464
}
465

    
466
/**
467
 * Implements hook_preprocess_HOOK() for theme_comment().
468
 *
469
 * Alter the comment display to make it look like a D5 style comment.
470
 *
471
 * @author W.Addink <w.addink@eti.uva.nl>
472
 */
473
function garland_cichorieae_preprocess_comment(&$variables) {
474
  $comment = $variables['elements']['#comment'];
475
  if (isset($comment->subject)) {
476
    // Print title without link.
477
    $variables['title'] = $comment->subject;
478
    if ($variables['status'] == 'comment-preview') {
479
      // Add 'new' to preview.
480
      $variables['new'] = t('new');
481
    }
482
  }
483
}
(12-12/13)