Project

General

Profile

Download (23.2 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
        $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
161
        // Adding ":" if necesary.
162
        if (isset($name_used_in_source_link_to_show) && (!empty($description) || !empty($sourceRefs)) && $feature_uuid != UUID_CHROMOSOMES_NUMBERS) {
163
          $out .= ': ';
164
        }
165
        $out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', array(
166
          'cdmBase_list' => $element,
167
          'footnote_list_key' => $feature_uuid,
168
        )) . $annotation_fkeys . '</li>';
169
        // Special handling for flora malesiana.
170
        // TODO: possible better way to implement this case?
171
      }
172
      else {
173
        if (isset($name_used_in_source_link_to_show)) {
174
          $name_used_in_source_link_to_show = ' (name in source: ' . $name_used_in_source_link_to_show . ')';
175
        }
176
        if (!isset($description)) {
177
          $description = '';
178
        }
179
        if (!isset($sourceRefs)) {
180
            $sourceRefs = '';
181
        }
182
        if (!isset($name_used_in_source_link_to_show)) {
183
            $name_used_in_source_link_to_show = '';
184
        }
185
        if (!isset($annotation_fkeys)) {
186
            $annotation_fkeys = '';
187
        }
188
        $out = '<span class="' . html_class_atttibute_ref($element) . '"> ' . $description . $sourceRefs . $name_used_in_source_link_to_show . $annotation_fkeys . '</span>';
189
      }
190
    }
191
  }
192

    
193
  // If no sources, print the description.
194
  if (!isset($out)) {
195
    $out = '<span class="' . html_class_atttibute_ref($element) . '"> ' . $description . $annotation_fkeys . '</span>';
196
  }
197

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

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

    
295
  $enclosingHtml = 'div';
296
  $out = '<' . $enclosingHtml . ' class="description" id="' . $feature->representation_L10n . '">';
297

    
298
  if ($sortArray) {
299
    sort($elementArray);
300
  }
301

    
302
  $out .= join($elementArray, $glue);
303

    
304
  $out .= '</' . $enclosingHtml . '>';
305
  return $out;
306
}
307

    
308
/*
309
  ***** GARLAND OVERRIDES *****
310
*/
311

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

    
330
  if (isset($class)) {
331
    print ' class="' . $class . '"';
332
  }
333
}
334

    
335
/**
336
 * Allow themable wrapping of all comments.
337
 */
338
/*
339
function phptemplate_comment_wrapper($content, $type = NULL) {
340
  static $node_type;
341
  if (isset($type)) $node_type = $type;
342

    
343
  if (! $content || $node_type == 'forum') {
344
    return '<div id="comments">' . $content . '</div>';
345
  }
346
  else {
347
    return '<div id="comments"><h2 class="comments">' . t('Comments') . '</h2>' . $content . '</div>';
348
  }
349
}
350
*/
351

    
352
/**
353
 * Override or insert PHPTemplate variables into the templates.
354
 */
355
function _phptemplate_variables($hook, $vars) {
356
  if ($hook == 'page') {
357

    
358
    if ($secondary = menu_secondary_local_tasks()) {
359
      $output = '<span class="clear"></span>';
360
      $output .= "<ul class=\"tabs secondary\">\n" . $secondary . "</ul>\n";
361
      $vars['tabs2'] = $output;
362
    }
363

    
364
    // Hook into color.module
365
    if (module_exists('color')) {
366
      _color_page_alter($vars);
367
    }
368
    return $vars;
369
  }
370
  return array();
371
}
372

    
373
/**
374
 * Returns HTML for the rendered local tasks.
375
 *
376
 * The default implementation renders them as tabs.
377
 *
378
 * @ingroup themeable
379
 */
380
function phptemplate_menu_local_tasks() {
381
  $output = '';
382

    
383
  if ($primary = menu_primary_local_tasks()) {
384
    $output .= "<ul class=\"tabs primary\">\n" . $primary . "</ul>\n";
385
  }
386

    
387
  return $output;
388
}
389

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

    
407
/**
408
 * @todo Please document this function.
409
 * @see http://drupal.org/node/1354
410
 */
411
function garland_cichorieae_get_nameRenderTemplate($variables) {
412
  $template = array();
413

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

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

    
469
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
470

    
471
  $mediaLinkType = 'NORMAL';
472
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
473
  $captionElements = array();
474
  if ($showCaption) {
475
    $captionElements = array('title', '#uri' => t('open Image'));
476
  }
477

    
478
  $gallery_name = $taxon->uuid;
479

    
480
  $mediaQueryParameters = array("type" => "ImageFile");
481
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
482

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

    
511
  return $out;
512
}
513

    
514
/**
515
 * @todo Please document this function.
516
 * @see http://drupal.org/node/1354
517
 */
518
function garland_cichorieae_cdm_feature_name($variables) {
519
  $feature_name = $variables['feature_name'];
520
  switch ($feature_name) {
521
    case "Protologue":
522
      return t("Original Publication");
523
    default:
524
      return ucfirst($feature_name);
525
  }
526
}
527

    
528
/*
529
======== Special functions for subtheme handling=============
530
*/
531

    
532
/**
533
 * @todo Please document this function.
534
 * @see http://drupal.org/node/1354
535
 */
536
function sub_theme() {
537
  global $user, $custom_theme;
538

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

    
543
  // Allow modules to override the present theme... only select custom theme
544
  // if it is available in the list of installed themes.
545
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
546

    
547
  return $theme;
548
}
549

    
550
/**
551
 * Return the path to the currently selected sub theme.
552
 */
553
function path_to_sub_theme() {
554
  $themes = list_themes();
555
  $theme = sub_theme();
556
  return dirname($themes[$theme]->filename);
557
}
558

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

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

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

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

    
659
  $vars['fixed_body'] = $body;
660
}
661

    
662
/**
663
 * Implements hook_form_FORM_ID_alter() for comment_form().
664
 *
665
 * Alter the comment form to make it look like a D5 style comment form.
666
 *
667
 * @author W.Addink <w.addink@eti.uva.nl>
668
 */
669
function garland_cichorieae_form_comment_form_alter(&$form, &$form_state) {
670

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

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