Project

General

Profile

Download (23.3 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
 * Returns HTML for a cdm_taxon_page_profile.
9
 *
10
 * The description page is supposed to be the front page for a taxon.
11
 *
12
 * @param array $variables
13
 *   An associative array containing:
14
 *   - taxon: The taxon object displayed on the taxon page.
15
 *   - mergedTrees
16
 *   - media:
17
 *   - hideImages: boolean, FALSE if images should be hided.
18
 *
19
 * @ingroup themeable
20
 */
21
function garland_cichorieae_cdm_taxon_page_profile($variables) {
22
  $taxon = $variables['taxon'];
23
  $mergedTrees = $variables['mergedTrees'];
24
  $media = $variables['media'];
25
  $hideImages = $variables['hideImages'];
26

    
27
  $out = '';
28
  global $base_url;
29

    
30
  RenderHints::pushToRenderStack('taxon_page_description');
31
  // Description TOC.
32
  $out = theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
33

    
34
  // Preferred image.
35
  // 2 lines hard coded for testing.
36
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
37

    
38
    // $defaultPreferredImage = drupal_get_path('theme',
39
    // 'garland_cichorieae').'/images/nopic_400x300.jpg';
40
    $defaultRepresentationPart = FALSE;
41
    $defaultRepresentationPart->width = 400;
42
    $defaultRepresentationPart->height = 300;
43
    $defaultRepresentationPart->uri = $base_url . '/' . drupal_get_path('theme', 'garland_cichorieae') . '/images/nopic_400x300_4x3cm.jpg';
44

    
45
    $imageUriParams = '&width=400&height=300&quality=95&format=jpeg';
46

    
47
    $imageMaxExtend = 400;
48
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
49
      'media' => $media,
50
      'defaultRepresentationPart' => $defaultRepresentationPart,
51
      'imageMaxExtend' => $imageMaxExtend,
52
      'parameters' => $imageUriParams,
53
      )) . '</div>';
54
  }
55

    
56
  // Description.
57
  $out .= theme('cdm_featureTrees', array(
58
    'mergedTrees' => $mergedTrees,
59
    'taxon' => $taxon,
60
  ));
61
  RenderHints::popFromRenderStack();
62

    
63
  return $out;
64
}
65

    
66
/**
67
 * @todo Please document this function.
68
 * @see http://drupal.org/node/1354
69
 */
70
function garland_cichorieae_cdm_descriptionElementTextData($variables) {
71
  $element = $variables['element'];
72
  $asListElement = $variables['asListElement'];
73
  $feature_uuid = $variables['feature_uuid'];
74

    
75
  $description = '';
76
  if (isset($element->multilanguageText_L10n->text)) {
77
    $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
78
  }
79
  $sourceRefs = '';
80
  $result = array();
81
  $res_author;
82
  $res_date;
83
  $do_links = TRUE;
84
  $default_theme = variable_get('theme_default', 'garland_cichorieae');
85

    
86
  if (($default_theme == 'flora_malesiana' || $default_theme == 'flore_afrique_centrale' || $default_theme == 'flore_gabon') && $element->feature->titleCache == 'Citation') {
87
    $asListElement = TRUE;
88
  }
89
  elseif ($element->feature->uuid == UUID_CHROMOSOMES_NUMBERS) {
90
    $asListElement = TRUE;
91
  }
92
  else {
93
    $asListElement = FALSE;
94
  }
95

    
96
  // Printing annotations footnotes.
97
  $annotation_fkeys = theme('cdm_annotations_as_footnotekeys', array(
98
    'cdmBase_list' => $element,
99
    'footnote_list_key' => $feature_uuid,
100
  ));
101

    
102
  if ($feature_uuid == UUID_NAME_USAGE || $feature_uuid == UUID_CHROMOSOMES) {
103
    $do_links = FALSE;
104
  }
105

    
106
  if (is_array($element->sources)) {
107
    foreach ($element->sources as $source) {
108
      // Initialize some variables.
109
      if ($feature_uuid == UUID_NAME_USAGE) {
110
        $referenceCitation = cdm_ws_get(
111
          CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
112
          array($source->citation->uuid),
113
          "microReference=" . urlencode($source->citationMicroReference
114
        ));
115
        $referenceCitation = $referenceCitation->String;
116
      }
117
      else {
118
        $referenceCitation = theme('cdm_DescriptionElementSource', array(
119
          'descriptionElementSource' => $source,
120
          'doLink' => $do_links,
121
        ));
122
      }
123
      if ($description && strlen($description) > 0 && $referenceCitation) {
124
        $sourceRefs .= ' (' . $referenceCitation . ')';
125
      }
126
      elseif ($referenceCitation) {
127
        $sourceRefs = $referenceCitation;
128
      }
129
      // Generate the output.
130
      if (strlen($sourceRefs) > 0) {
131
        $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
132
      }
133
      $name_used_in_source_link_to_show = '';
134
      if (isset($source->nameUsedInSource->uuid) && ($feature_uuid != UUID_NAME_USAGE)) {
135
        // Do a link to name page.
136
        $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache, path_to_name($source->nameUsedInSource->uuid), array(), NULL, NULL, FALSE, TRUE);
137
      }
138
      elseif (isset($source->nameUsedInSource->uuid) && ($feature_uuid == UUID_NAME_USAGE)) {
139
        // Do not do link for NAME USAGE feature.
140
        $name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
141
      }
142
      elseif (isset($source->nameUsedInSource->originalNameString) && strlen($source->nameUsedInSource->originalNameString) > 0) {
143
        // Show a text without link.
144
        $name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
145
      }
146

    
147
      if ($asListElement && ($feature_uuid == UUID_NAME_USAGE)) {
148
        $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
149
        // Adding ":" if necesary.
150
        if (!empty($name_used_in_source_link_to_show) && (!empty($description) || !empty($sourceRefs))) {
151
          $out .= ': ';
152
        }
153

    
154
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array(
155
          'cdmBase_list' => $element,
156
          'footnote_list_key' => $feature_uuid,
157
        )) . $annotation_fkeys . '</li>';
158
      }
159
      elseif ($asListElement) {
160

    
161
        $out = '<li class="descriptionText DescriptionElement">';
162
        // Adding ":" if necessary.
163
        if (!empty($name_used_in_source_link_to_show)) {
164
          if ( (!empty($description)|| !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
165
            $out .= $name_used_in_source_link_to_show . ': ';
166
          } else {
167
            $out .= $name_used_in_source_link_to_show . ' ';
168
          }
169
        }
170

    
171
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array(
172
          'cdmBase_list' => $element,
173
          'footnote_list_key' => $feature_uuid,
174
        )) . $annotation_fkeys . '</li>';
175
        // Special handling for flora malesiana.
176
        // TODO: possible better way to implement this case?
177
      }
178
      else {
179
        if (isset($name_used_in_source_link_to_show)) {
180
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
181
        }
182
        if (!isset($description)) {
183
          $description = '';
184
        }
185
        if (!isset($sourceRefs)) {
186
            $sourceRefs = '';
187
        }
188
        if (!isset($name_used_in_source_link_to_show)) {
189
            $name_used_in_source_link_to_show = '';
190
        }
191
        if (!isset($annotation_fkeys)) {
192
            $annotation_fkeys = '';
193
        }
194
        $out = '<span class="' . html_class_atttibute_ref($element) . '"> ' . $description . $sourceRefs . $name_used_in_source_link_to_show . $annotation_fkeys . '</span>';
195
      }
196
    }
197
  }
198

    
199
  // If no sources, print the description.
200
  if (!isset($out)) {
201
    $out = '<span class="' . html_class_atttibute_ref($element) . '"> ' . $description . $annotation_fkeys . '</span>';
202
  }
203

    
204
  /* Dead code:
205
   *
206
   * Disabled code; can this be removed?
207
  if ($feature_uuid == UUID_NAME_USAGE){ foreach($element->sources as
208
  $source){ $referenceCitation =
209
  cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
210
  array($source->citation->uuid),
211
  "microReference=".urlencode($source->citationMicroReference));
212
  $referenceCitation = $referenceCitation->String; if($description &&
213
  strlen($description) > 0 && $referenceCitation ){ $sourceRefs .= '
214
  ('.$referenceCitation.')' ; }else if ($referenceCitation){ $sourceRefs =
215
  $referenceCitation; } } }else{ foreach($element->sources as $source){
216
  $referenceCitation = theme('cdm_DescriptionElementSource', $source,
217
  ($feature_uuid == UUID_NAME_USAGE) ? FALSE : TRUE); if($description &&
218
  strlen($description) > 0 && $referenceCitation ){ $sourceRefs .= '
219
  ('.$referenceCitation.')' ; }else if ($referenceCitation){ $sourceRefs =
220
  $referenceCitation; } } } if(strlen($sourceRefs) > 0){ $sourceRefs = '<span
221
  class="sources">' . $sourceRefs . '</span>'; } if
222
  ($source->nameUsedInSource->uuid && ($feature_uuid != UUID_NAME_USAGE)){
223
  //do a link to name page $name_used_in_source_link_to_show =
224
  l($source->nameUsedInSource->titleCache,
225
  path_to_name($source->nameUsedInSource->uuid), array(), NULL, NULL, FALSE
226
  ,TRUE); }else if ($source->nameUsedInSource->uuid && ($feature_uuid ==
227
  UUID_NAME_USAGE)){ //do not do link for NAME USAGE feature
228
  $name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
229
  }else if (strlen($source->nameUsedInSource->originalNameString) > 0){
230
  //show a text without link $name_used_in_source_link_to_show =
231
  $source->nameUsedInSource->originalNameString; } if($asListElement &&
232
  ($feature_uuid == UUID_NAME_USAGE)){ $out = '<li class="descriptionText">'
233
  . $name_used_in_source_link_to_show; //adding ":" if necesary if
234
  ($name_used_in_source_link_to_show && ($description || $sourceRefs)){ $out
235
  .= ': '; } $out .= $description . $sourceRefs .
236
  theme('cdm_annotations_as_footnotekeys', $element) . '</li>'; }else if
237
  ($asListElement){ $out = '<li class="descriptionText">' .
238
  $name_used_in_source_link_to_show; //adding ":" if necesary if
239
  ($name_used_in_source_link_to_show && ($description || $sourceRefs)){ $out
240
  .= ': '; } $out .= $description . $sourceRefs .
241
  theme('cdm_annotations_as_footnotekeys', $element) . '</li>'; //special
242
  handling for flora malesiana TODO: possible better way to implement this
243
  case? }else{ if ($name_used_in_source_link_to_show){
244
  $name_used_in_source_link_to_show = ' (name in source: '.
245
  $name_used_in_source_link_to_show . ')'; } $out = $description .
246
  $sourceRefs . $name_used_in_source_link_to_show; $out .=
247
  theme('cdm_annotations_as_footnotekeys', $element); }
248
  */
249
  // Add annotations as footnote key.
250
  // $out .= theme('cdm_annotations_as_footnotekeys', $element); move above.
251
  return $out;
252
}
253

    
254
// NO LONGER NEEDED - since term representation is changed now in the cdm for
255
// the cichorieae
256
// ====> delete
257
// /**
258
// * @overrides theme_cdm_taggedtext2html in order to replace t.infr and
259
// t.infgen. with '[unranked]'
260
// */
261
// function garland_cichorieae_cdm_taggedtext2html(array &$taggedtxt, $tag =
262
// 'span', $glue = ' ', $skiptags = array()){
263
// $out = '';
264
// $i = 0;
265
// foreach($taggedtxt as $tt){
266
// if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
267
// $out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.'
268
// class="'.$tt->type.'">';
269
// if($tt->type == "rank" && ($tt->text == "t.infr." || $tt->text ==
270
// "t.infgen.")){
271
// $out .= t('[unranked]');
272
// }else{
273
// $out .= t($tt->text);
274
// }
275
// $out .= '</'.$tag.'>';
276
// }
277
// }
278
// return $out;
279
// }
280
/**
281
 * Returns HTML for a cdm_descriptionElementArray.
282
 *
283
 * @param array $variables
284
 *   An associative array containing:
285
 *   - elementArray: The array with CDM description elements being formatted.
286
 *   - feature: The description feature container object for the
287
 *     description element array.
288
 *   - glue: String for joining the description elements together.
289
 *   - sortArray: Boolean, TRUE if the array should be sorted before themeing.
290
 *   - enclosingHTML: HTML tag, e.g. 'div', in which to wrap the description.
291
 *
292
 * @ingroup themeable
293
 */
294
function garland_cichorieae_cdm_descriptionElementArray($variables) {
295
  $elementArray = $variables['elementArray'];
296
  $feature = $variables['feature'];
297
  $glue = $variables['glue'];
298
  $sortArray = $variables['sortArray'];
299
  $enclosingHtml = $variables['enclosingHtml'];
300

    
301
  $enclosingHtml = 'div';
302
  $out = '<' . $enclosingHtml . ' class="description" id="' . $feature->representation_L10n . '">';
303

    
304
  if ($sortArray) {
305
    sort($elementArray);
306
  }
307

    
308
  $out .= join($elementArray, $glue);
309

    
310
  $out .= '</' . $enclosingHtml . '>';
311
  return $out;
312
}
313

    
314
/*
315
  ***** GARLAND OVERRIDES *****
316
*/
317

    
318
/**
319
 * Sets the body-tag class attribute.
320
 *
321
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
322
 */
323
function phptemplate_body_class($sidebar_left, $sidebar_right) {
324
  if ($sidebar_left != '' && $sidebar_right != '') {
325
    $class = 'sidebars';
326
  }
327
  else {
328
    if ($sidebar_left != '') {
329
      $class = 'sidebar-left';
330
    }
331
    if ($sidebar_right != '') {
332
      $class = 'sidebar-right';
333
    }
334
  }
335

    
336
  if (isset($class)) {
337
    print ' class="' . $class . '"';
338
  }
339
}
340

    
341
/**
342
 * Allow themable wrapping of all comments.
343
 */
344
/*
345
function phptemplate_comment_wrapper($content, $type = NULL) {
346
  static $node_type;
347
  if (isset($type)) $node_type = $type;
348

    
349
  if (! $content || $node_type == 'forum') {
350
    return '<div id="comments">' . $content . '</div>';
351
  }
352
  else {
353
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
354
  }
355
}
356
*/
357

    
358
/**
359
 * Override or insert PHPTemplate variables into the templates.
360
 */
361
function _phptemplate_variables($hook, $vars) {
362
  if ($hook == 'page') {
363

    
364
    if ($secondary = menu_secondary_local_tasks()) {
365
      $output = '<span class="clear"></span>';
366
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
367
      $vars['tabs2'] = $output;
368
    }
369

    
370
    // Hook into color.module
371
    if (module_exists('color')) {
372
      _color_page_alter($vars);
373
    }
374
    return $vars;
375
  }
376
  return array();
377
}
378

    
379
/**
380
 * Returns HTML for the rendered local tasks.
381
 *
382
 * The default implementation renders them as tabs.
383
 *
384
 * @ingroup themeable
385
 */
386
function phptemplate_menu_local_tasks() {
387
  $output = '';
388

    
389
  if ($primary = menu_primary_local_tasks()) {
390
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
391
  }
392

    
393
  return $output;
394
}
395

    
396
/**
397
 * @todo Please document this function.
398
 * @see http://drupal.org/node/1354
399
 */
400
function garland_cichorieae_get_partDefinition($variables) {
401
  if ($variables['nameType'] == 'BotanicalName') {
402
    return array(
403
      'namePart' => array('name' => TRUE),
404
      'nameAuthorPart' => array('name' => TRUE, 'authors' => TRUE),
405
      'referencePart' => array('reference' => TRUE, 'microreference' => TRUE),
406
      'statusPart' => array('status' => TRUE),
407
      'descriptionPart' => array('description' => TRUE),
408
    );
409
  }
410
  return FALSE;
411
}
412

    
413
/**
414
 * @todo Please document this function.
415
 * @see http://drupal.org/node/1354
416
 */
417
function garland_cichorieae_get_nameRenderTemplate($variables) {
418
  $template = array();
419

    
420
  switch ($variables['renderPath']) {
421
    case 'taxon_page_title':
422
    case 'polytomousKey':
423
      $template = array(
424
        'namePart' => array('#uri' => TRUE),
425
      );
426
      break;
427
    case 'taxon_page_synonymy':
428
    case 'related_taxon':
429
      $template = array(
430
        'nameAuthorPart' => array('#uri' => TRUE),
431
        'referencePart' => TRUE,
432
        'statusPart' => TRUE,
433
        'descriptionPart' => TRUE,
434
      );
435
      break;
436
    case 'acceptedFor':
437
      $template = array(
438
        'nameAuthorPart' => array('#uri' => TRUE),
439
        'referencePart' => TRUE,
440
      );
441
      break;
442
    case 'typedesignations':
443
    case 'list_of_taxa':
444
    case '#DEFAULT':
445
      $template = array(
446
        'nameAuthorPart' => array('#uri' => TRUE),
447
        'referencePart' => TRUE,
448
      );
449
  }
450
  return $template;
451
}
452

    
453
/**
454
 * Returns HTML for taxon list thumbnails.
455
 *
456
 * Theme specific mods:
457
 * $captionElements = array('title', '#uri'=>t('open Image'));
458
 * $mediaLinkType:
459
 * "NORMAL": link to the image page or to the $alternativeMediaUri if it is
460
 * defined instead of
461
 * "LIGHTBOX": open the link in a light box,
462
 * TODO expose those in admin section, by adding 'em to gallery_settings see
463
 * http://dev.e-taxonomy.eu/trac/ticket/2494.
464
 *
465
 * @param array $variables
466
 *   An associative array containing:
467
 *   - taxon: The taxon object for which to theme the thumbnails.
468
 *
469
 * @ingroup themeable
470
 */
471
function garland_cichorieae_cdm_taxon_list_thumbnails($variables) {
472
  $out = '';
473
  $taxon = $variables['taxon'];
474

    
475
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
476

    
477
  $mediaLinkType = 'NORMAL';
478
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
479
  $captionElements = array();
480
  if ($showCaption) {
481
    $captionElements = array('title', '#uri' => t('open Image'));
482
  }
483

    
484
  $gallery_name = $taxon->uuid;
485

    
486
  $mediaQueryParameters = array("type" => "ImageFile");
487
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
488

    
489
  // TODO cdm_dataportal_show_media = ????
490
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
491
  if ($selectShowMedia == 0) {
492
    $mediaList = cdm_ws_get(
493
      CDM_WS_PORTAL_TAXON_MEDIA,
494
      array($taxon->uuid),
495
      queryString($mediaQueryParameters
496
    ));
497
  }
498
  else {
499
    $mediaList = cdm_ws_get(
500
      CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA,
501
      array($taxon->uuid),
502
      queryString($mediaQueryParameters
503
    ));
504
  }
505
  $out .= theme('cdm_media_gallerie', array(
506
    'mediaList' => $mediaList,
507
    'galleryName' => $gallery_name,
508
    'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
509
    'cols' => $gallery_settings['cdm_dataportal_media_cols'],
510
    'maxRows' => $gallery_settings['cdm_dataportal_media_maxRows'],
511
    'captionElements' => $captionElements,
512
    'mediaLinkType' => $mediaLinkType,
513
    'alternativeMediaUri' => $galleryLinkUri,
514
    'showCaption' => NULL,
515
  ));
516

    
517
  return $out;
518
}
519

    
520
/**
521
 * @todo Please document this function.
522
 * @see http://drupal.org/node/1354
523
 */
524
function garland_cichorieae_cdm_feature_name($variables) {
525
  $feature_name = $variables['feature_name'];
526
  switch ($feature_name) {
527
    case "Protologue":
528
      return t("Original Publication");
529
    default:
530
      return ucfirst($feature_name);
531
  }
532
}
533

    
534
/*
535
======== Special functions for subtheme handling=============
536
*/
537

    
538
/**
539
 * @todo Please document this function.
540
 * @see http://drupal.org/node/1354
541
 */
542
function sub_theme() {
543
  global $user, $custom_theme;
544

    
545
  // Only select the user selected theme if it is available in the
546
  // list of enabled themes.
547
  $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'garland');
548

    
549
  // Allow modules to override the present theme... only select custom theme
550
  // if it is available in the list of installed themes.
551
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
552

    
553
  return $theme;
554
}
555

    
556
/**
557
 * Return the path to the currently selected sub theme.
558
 */
559
function path_to_sub_theme() {
560
  $themes = list_themes();
561
  $theme = sub_theme();
562
  return dirname($themes[$theme]->filename);
563
}
564

    
565
/**
566
 * Implements hook_preprocess_HOOK() for theme_page().
567
 *
568
 * Assign the css classes primary-links and secondary-links to the menus.
569
 * Modify primary-links if cdm_api module exists.
570
 */
571
function garland_cichorieae_preprocess_page(&$vars) {
572
  if (isset($vars['main_menu'])) {
573
    /*
574
    obsolete, see http://dev.e-taxonomy.eu/trac/ticket/2191
575
    if(module_exists('cdm_api')){ foreach($vars['main_menu'] as $key =>
576
    $menu_item){ // nb this makes each menu item you click opening a new
577
    browser window..
578
    $menu_item['attributes']['target']=generalizeString($menu_item['title']);
579
    $main_menu[] = $menu_item; }; }else{ $main_menu = $vars['main_menu'] ; };
580
    */
581
    $vars['primary_nav'] = theme('links__system_main_menu', array(
582
      'links' => $vars['main_menu'], 'attributes' => array(
583
        'class' => array(
584
          'links', 'inline', 'main-menu', 'primary-links',
585
        )),
586
        'heading' => array(
587
          'text' => t('Main menu'), 'level' => 'h2', 'class' => array(
588
            'element-invisible',
589
          ))));
590
  }
591
  else {
592
    $vars['primary_nav'] = FALSE;
593
  }
594
  if (isset($vars['secondary_menu'])) {
595
    $vars['secondary_nav'] = theme('links__system_secondary_menu', array(
596
      'links' => $vars['secondary_menu'], 'attributes' => array(
597
        'class' => array(
598
          'links',
599
          'inline',
600
          'secondary-menu',
601
          'secondary-links',
602
        )),
603
        'heading' => array(
604
          'text' => t('Secondary menu'),
605
          'level' => 'h2',
606
          'class' => array('element-invisible'),
607
        )));
608
  }
609
  else {
610
    $vars['secondary_nav'] = FALSE;
611
  }
612

    
613
  /*
614
  Display node title as page title for the comment form.
615
  Comment @WA: it would probably be better to select $uuid from node_cdm
616
  table and link to cdm_dataportal/taxon/%uuid instead.
617
  */
618
  if (arg(0) == 'comment' && arg(1) == 'reply') {
619
    $node = $vars['page']['content']['system_main']['comment_node']['#node'];
620
    $vars['title'] = l(check_plain($node->title), 'node/' . $node->nid);
621
  }
622
}
623

    
624
/**
625
 * Implements hook_preprocess_HOOK() for theme_node().
626
 *
627
 * Fixes file urls in nodes. In nodes, relative urls are used to include files
628
 * like <img src="/files/..
629
 *
630
 * Portals can be installed in configurations with
631
 * sub-directories however, in which case these urls need to be adjusted.
632
 * Examples: mysite.org, mysite.org/myportal, mysite.org/portals/myportal.
633
 *
634
 * Therefore preprocess nodes and replace these urls with a the appropriate url
635
 * for the current setup.
636
 *
637
 * @author W.Addink <w.addink@eti.uva.nl>
638
 */
639
function garland_cichorieae_preprocess_node(&$vars) {
640
  $body = '';
641
  // Warning: use #markup value, for which filters like php, html etc are applied!
642
  if (isset($vars['content']['body'][0]['#markup'])) {
643
    $body = $vars['content']['body'][0]['#markup'];
644
  }
645
  else {
646
    $vars['fixed_body'] = '';
647
    return;
648
  }
649

    
650
  $file_path = '/' . variable_get('file_public_path', conf_path() . '/files');
651
  global $base_url;
652
  if ($base_url == '/') {
653
    drupal_set_message(t('
654
      The $base_url in this portal could not be set, please set the $base_url
655
      manually your Drupal settings.php file.', 'error'
656
    ));
657
  }
658
  $fixed_file_path = $base_url . $file_path;
659
  $preg_file_path = preg_quote($file_path, '/');
660
  $body = preg_replace('/src\s*=\s*["]\s*' . $preg_file_path . '/', 'src="' . $fixed_file_path, $body);
661
  $body = preg_replace('/src\s*=\s*[\']\s*' . $preg_file_path . '/', 'src=\'' . $fixed_file_path, $body);
662
  $body = preg_replace('/href\s*=\s*["]\s*' . $preg_file_path . '/', 'href="' . $fixed_file_path, $body);
663
  $body = preg_replace('/href\s*=\s*[\']\s*' . $preg_file_path . '/', 'href=\'' . $fixed_file_path, $body);
664

    
665
  $vars['fixed_body'] = $body;
666
}
667

    
668
/**
669
 * Implements hook_form_FORM_ID_alter() for comment_form().
670
 *
671
 * Alter the comment form to make it look like a D5 style comment form.
672
 *
673
 * @author W.Addink <w.addink@eti.uva.nl>
674
 */
675
function garland_cichorieae_form_comment_form_alter(&$form, &$form_state) {
676

    
677
  if (!isset($form['comment_preview'])) {
678
    $form['header'] = array(
679
      '#markup' => '<h2>' . t('Reply') . '</h2>',
680
      '#weight' => -2,
681
    );
682
  }
683
  $form['subject']['#title'] = $form['subject']['#title'] . ':';
684
  $form['comment_body']['und'][0]['#title'] = $form['comment_body']['und'][0]['#title'] . ':';
685
  if (isset($form['author']['_author']['#title'])) {
686
    $form['author']['_author']['#title'] = $form['author']['_author']['#title'] . ':';
687
  }
688
  $form['actions']['submit']['#value'] = t('Post comment');
689
  $form['actions']['submit']['#weight'] = 1000;
690
  $form['actions']['preview']['#value'] = t('Preview comment');
691
}
692

    
693
/**
694
 * Implements hook_preprocess_HOOK() for theme_comment().
695
 *
696
 * Alter the comment display to make it look like a D5 style comment.
697
 *
698
 * @author W.Addink <w.addink@eti.uva.nl>
699
 */
700
function garland_cichorieae_preprocess_comment(&$variables) {
701
  $comment = $variables['elements']['#comment'];
702
  if (isset($comment->subject)) {
703
    // Print title without link.
704
    $variables['title'] = $comment->subject;
705
    if ($variables['status'] == 'comment-preview') {
706
      // Add 'new' to preview.
707
      $variables['new'] = t('new');
708
    }
709
  }
710
}
(12-12/13)