Project

General

Profile

Download (30.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Page theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * Returns HTML for the default title of a taxon page.
18
 *  * The returned title is a formatted taxon name.
19
 *
20
 * @param array $variables
21
 *   An associative array containing:
22
 *   - taxon: The taxon name being formatted for the title.
23
 *   - uuid: UUID for the taxon.
24
 *
25
 * @ingroup themeable
26
 */
27
function theme_cdm_taxon_page_title($variables) {
28
  $taxon = $variables['taxon'];
29
  $uuid = $variables['uuid'];
30
  RenderHints::pushToRenderStack('taxon_page_title');
31
  $referenceUri = '';
32
  $out = '';
33
  if (isset($taxon->name->nomenclaturalReference)) {
34
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
35
  }
36

    
37
  $out .= theme('cdm_taxonName', array(
38
    'taxonName' => $taxon->name,
39
    'nameLink' => NULL,
40
    'refenceLink' => $referenceUri,
41
    'show_annotations' => FALSE,
42
  ));
43
  RenderHints::popFromRenderStack();
44

    
45
  return '<span class="' . $taxon->class . '">' . $out . '</span>';
46
}
47

    
48
/**
49
 * Returns HTML for the default title for a name page.
50
 *
51
 * The returned title is a formatted name.
52
 *
53
 * @param array $variables
54
 *   An associative array containing:
55
 *   - taxon_name: The taxon name object.
56
 *
57
 * @ingroup themeable
58
 */
59
function theme_cdm_name_page_title($variables) {
60
  $taxon_name = $variables['taxon_name'];
61
  RenderHints::pushToRenderStack('taxon_page_title');
62
  if (isset($taxon_name->nomenclaturalReference)) {
63
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
64
  }
65

    
66
  $out = '<span class="' . $taxon_name->class . '">' . theme('cdm_taxonName', array(
67
    'taxonName' => $taxon_name,
68
    'nameLink' => NULL,
69
    'refenceLink' => $referenceUri,
70
    'show_annotations' => FALSE,
71
  )) . '</span>';
72
  RenderHints::popFromRenderStack();
73
  return $out;
74
}
75

    
76
/**
77
 * Returns HTML for a taxon page.
78
 *
79
 * A wrapper function that groups available information to show by default,
80
 * when a taxon page is requested by the browser.
81
 * Individual themeing has to decide what this page should include (see methods
82
 * beneath) and what information should go into tabs or should not be shown
83
 * at all.
84
 *
85
 * It is headed by the name of the accepted taxon without author and reference.
86
 *
87
 * @param array $variables
88
 *   An associative array containing:
89
 *   - taxon: The taxon object for which to theme the page.
90
 *   - page_part: Name of the part to display, valid values are:
91
 *   'description', 'images', 'synonymy', 'all'.
92
 *
93
 * @ingroup themeable
94
 */
95
function theme_cdm_taxon_page($variables) {
96

    
97
  $taxon = $variables['taxon'];
98
  $page_part = $variables['page_part'];
99
  global $theme;
100

    
101
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
102

    
103
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
104

    
105
  $hideTabs = array();
106

    
107
  // --- GET Images --- //
108
  $mediaQueryParameters = array(
109
    "type" => "ImageFile",
110
  );
111

    
112
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
113
  if ($selectShowMedia == 0) {
114
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array(
115
      $taxon->uuid,
116
    ), queryString($mediaQueryParameters));
117
  }
118
  else {
119
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array(
120
      $taxon->uuid,
121
    ), queryString($mediaQueryParameters));
122
  }
123
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
124
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Images'));
125
  }
126
  // HideImage flag depending on administative preset.
127
  $hideImages = FALSE;
128
  if (variable_get('image_hide_rank', '0') != '0') {
129
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
130
    $hideImages = ($rankCompare > -1);
131
  }
132

    
133
  // --- GET specimensOrObservations --- //
134
  // Comment @WA Note the spelling error!
135
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array(
136
    $taxon->uuid,
137
    'specimensOrObersvations',
138
  ));
139

    
140
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
141
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
142
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Specimens'));
143
  }
144

    
145
  // --- GET polytomousKeys --- //
146
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
147
  $identificationKeyCount = 0;
148
  if ($polytomousKeysPager) {
149
    $identificationKeyCount += $polytomousKeysPager->count;
150
  }
151
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
152
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Keys'));
153
  }
154

    
155
  if ($tabsToDisplay["Synonymy"] == '0') {
156
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Synonymy'));
157
  }
158

    
159
  // -------------------------------------------- //
160
  // Hide tabs.
161
  $tabhide_js = '';
162
  foreach ($hideTabs as $tabText) {
163
    $tabhide_js .= "jQuery('.tabs.primary').children('li').children('a:contains(\"$tabText\")').hide();\n";
164
  }
165
  drupal_add_js("
166
  jQuery(document).ready(function(){
167
  $tabhide_js
168
    });", array('type' => 'inline'));
169

    
170
  $out = '';
171
  $out .= theme('cdm_back_to_search_result_button');
172

    
173
  // var_dump(variable_get('cdm_dataportal_display_is_accepted_for',
174
  // CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR));
175
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
176
    $out .= theme('cdm_acceptedFor', 'page_general');
177
  }
178

    
179
  // --- PAGE PART: DESCRIPTION --- //
180
  if ($page_part == 'description' || $page_part == 'all') {
181

    
182
    $markerTypesEmpty = array();
183
    $markerTypesEmpty['markerTypes'] = '';
184
    // Retrieve all descriptions for the taxon.
185
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, queryString($markerTypesEmpty));
186

    
187
    $nonStructuredDescriptions = array();
188
    if ($taxonDescriptions != NULL) {
189
      foreach ($taxonDescriptions as $taxonDescription) {
190
        // Check if structured description.
191
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
192
        if (isset($hasStructuredData->Boolean)) {
193
          $hasStructuredData = $hasStructuredData->Boolean == 'TRUE';
194
        }
195
        if ($hasStructuredData) {
196
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, FALSE);
197
          if($structured_description_featuretree_uuid) {
198
            // if a feature tree for natural language generation has been defined use it,
199
            // otherwise natural language generation is skipped
200
            $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array(
201
              $taxonDescription->uuid,
202
              $structured_description_featuretree_uuid,
203
            ));
204

    
205
            if (!isset($naturallanguage_textData)) {
206
              drupal_set_message(
207
                t(
208
                "The 'FeatureTree' for the generation of natural language representations is not configured correctly,"
209
                ." please select a 'FeatureTree' in the !settings",
210
                array(
211
              		'!settings' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/layout/taxon'))
212
              		),
213
              	'warning');
214
            } else {
215
              $taxonDescription->elements = NULL;
216
              $taxonDescription->elements = array(
217
                $naturallanguage_textData,
218
              );
219
            }
220
          }
221
        }
222
        $nonStructuredDescriptions[] = $taxonDescription;
223
      }
224
      // Release memory.
225
      $taxonDescriptions = NULL;
226
    }
227

    
228
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
229

    
230
    $out .= '<div id="general">';
231
    $out .= theme('cdm_taxon_page_profile', array(
232
      'taxon' => $taxon,
233
      'mergedTrees' => $mergedTrees,
234
      'media' => $media,
235
      'hideImages' => $hideImages,
236
      ));
237
    $out .= '</div>';
238
  }
239

    
240
  // --- PAGE PART: IMAGES --- //
241
  if ((!$hideImages && $page_part == 'images' || $page_part == 'all')) {
242
    $out .= '<div id="images">';
243
    if ($page_part == 'all') {
244
      $out .= '<h2>' . t('Images') . '</h2>';
245
    }
246
    // Get the image gallery as configured by the admin.
247
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
248
      $taxon,
249
      $media,
250
    ));
251
    $out .= $taxon_image_gallery;
252

    
253
    $out .= '</div>';
254
  }
255

    
256
  // --- PAGE PART: SYNONYMY --- //
257
  if (($page_part == 'synonymy' || $page_part == 'all')) {
258
    $out .= '<div id="synonymy">';
259
    if ($page_part == 'all') {
260
      $out .= '<h2>' . t('Synonymy') . '</h2>';
261
    }
262
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
263
    $out .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
264

    
265
    $out .= '</div>';
266
  }
267

    
268
  // --- PAGE PART: SPECIMENS --- //
269
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
270
    $out .= '<div id="specimens">';
271
    if ($page_part == 'all') {
272
      $out .= '<h2>' . t('Specimens') . '</h2>';
273
    }
274
    $out .= theme('cdm_taxon_page_specimens', array('taxon' => $taxon));
275
    $out .= '</div>';
276
  }
277

    
278
  // --- PAGE PART: KEYS --- //
279
  if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
280
    $out .= '<div id="keys">';
281
    if ($page_part == 'all') {
282
      $out .= '<h2>' . t('Keys') . '</h2>';
283
    }
284
    $out .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
285
    $out .= '</div>';
286
  }
287
  return $out;
288
}
289

    
290
/**
291
 * Returns HTML containing descriptive data and preferred picture.
292
 *
293
 * Outputs all descriptive data and shows the preferred picture of the
294
 * accepted taxon.
295
 *
296
 * @param array $variables
297
 *   An associative array containing:
298
 *   - taxon
299
 *   - mergedTrees
300
 *   - media:
301
 *   - hideImages
302
 *
303
 * @ingroup themeable
304
 */
305
function theme_cdm_taxon_page_profile($variables) {
306
  $taxon = $variables['taxon'];
307
  $mergedTrees = $variables['mergedTrees'];
308
  $media = $variables['media'];
309
  $hideImages = $variables['hideImages'];
310
  $out = '';
311
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
312

    
313
    // Preferred image hardcoded for testing.
314
    $defaultRepresentationPart = new stdClass();
315
    $defaultRepresentationPart->width = 184;
316
    $defaultRepresentationPart->height = 144;
317
    $defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2') . '/images/no_picture.png';
318

    
319
    // Preferred image size 184px × 144.
320
    $imageMaxExtend = 184;
321
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
322
      'media' => $media,
323
      'defaultRepresentationPart' => $defaultRepresentationPart,
324
      'imageMaxExtend' => $imageMaxExtend,
325
      )) . '</div>';
326
  }
327

    
328
  // Description TOC.
329
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
330

    
331
  // Description.
332
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
333

    
334
  return $out;
335
}
336

    
337
/**
338
 * @todo Please document this function.
339
 * @see http://drupal.org/node/1354
340
 */
341
function theme_cdm_taxon_page_specimens($variables) {
342
  $out = '';
343
  $taxon = $variables['taxon'];
344
  RenderHints::pushToRenderStack('taxon_page_specimens');
345

    
346
  // Comment @WA: Note the spelling error.
347
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array(
348
    $taxon->uuid,
349
    'specimensOrObersvations',
350
  ));
351

    
352
  // Collect media (fieldObjectMedia, derivedUnitMedia) and add as fields.
353
  foreach ($specimensOrObservations as &$occurrence) {
354
    $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
355
      $occurrence->uuid,
356
      'fieldObjectMedia',
357
    ));
358
    $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
359
      $occurrence->uuid,
360
      'derivedUnitMedia',
361
    ));
362
    /*
363
    $derivedUnitFacde = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE,
364
    array($descriptionElement->associatedSpecimenOrObservation->uuid) );
365
    $descriptionElement->_titleCache = $derivedUnitFacde->titleCache;
366
    */
367
  }
368

    
369
  if (count($specimensOrObservations) > 0) {
370
    $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid);
371

    
372
    if( isset($occurrenceQuery->String) ) {
373
      // os=&od=&legend=0&recalculate=false&image=false
374
      $occurrenceQuery = $occurrenceQuery->String;
375

    
376
      if (variable_get('cdm_dataportal_map_openlayers', 1)) {
377

    
378
        $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', FALSE), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
379
            // Comment @WA: not defined.
380
            // $legendFormatQueryStr,
381
            NULL, variable_get('cdm_dataportal_geoservice_map_caption', ''));
382
      }
383
      else {
384
        // get_image_map($width, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE )
385
        $out .= get_image_map(variable_get('cdm_dataportal_geoservice_display_width', FALSE), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
386
            // @WA: not defined
387
            // $legendFormatQueryStr,
388
            NULL, variable_get('cdm_dataportal_geoservice_map_caption', ''));
389
      }
390
    }
391
  }
392
  $out_specimenList = '';
393
  if ($specimensOrObservations) {
394
    $out_specimenList = '<table class="specimens">';
395
    $i = 1;
396
    foreach ($specimensOrObservations as $specimensOrObservation) {
397
      $i++;
398

    
399
      $mediaList = array();
400
      if (is_array($specimensOrObservation->_fieldObjectMedia)) {
401
        $mediaList = array_merge($mediaList, $specimensOrObservation->_fieldObjectMedia);
402
      }
403
      if (is_array($specimensOrObservation->_derivedUnitMedia)) {
404
        $mediaList = array_merge($mediaList, $specimensOrObservation->_derivedUnitMedia);
405
      }
406

    
407
      // --- Render the title cache.
408
      $out_row = '<tr class="descriptionElement descriptionElement_IndividualsAssociation ' . ($i % 2 ? 'odd' : 'even') . '">';
409
      if ($specimensOrObservation->class != 'FieldObservation') {
410
        $label_html = cdm_dynabox($specimensOrObservation->titleCache, cdm_compose_url('portal/' . CDM_WS_DERIVEDUNIT_FACADE, array(
411
          $specimensOrObservation->uuid,
412
        )), 'cdm_derivedUnitFacade', 'Click for details', array(
413
          'div',
414
          'div',
415
        ));
416
      }
417
      else {
418
        $label_html = $specimensOrObservation->titleCache;
419
      }
420
      $out_row .= '<td>' . $label_html . '</td>';
421

    
422
      // --- Render associated media.
423
      if (count($mediaList) > 0) {
424
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
425
        $gallery_name = $specimensOrObservation->uuid;
426
        $captionElements = array(
427
          '#uri' => t('open media'),
428
        );
429

    
430
        $gallery_html = theme('cdm_media_gallerie', array(
431
          'mediaList' => $mediaList,
432
          'galleryName' => $gallery_name,
433
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
434
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
435
          'maxRows' => $gallery_settings['cdm_dataportal_media_maxRows'],
436
          'captionElements' => $captionElements,
437
          'mediaLinkType' => 'LIGHTBOX',
438
          'alternativeMediaUri' => NULL,
439
          'galleryLinkUri' => NULL,
440
          ));
441
      }
442
      else {
443
        $gallery_html = '';
444
      }
445
      $out_row .= '<td>' . $gallery_html . '</td></tr>';
446
      $out_specimenList .= $out_row;
447
    }
448
    $out_specimenList .= '</table>';
449
  }
450

    
451
  $out .= $out_specimenList;
452

    
453
  RenderHints::popFromRenderStack();
454
  return $out;
455
}
456

    
457
/**
458
 * Returns HTML containing the synonymy for the accepted taxon.
459
 *
460
 * Shows the whole synonymy for the accepted taxon.
461
 * The synonymy list is headed by the complete scientific name
462
 * of the accepted taxon with nomenclatural reference.
463
 *
464
 * @param array $variables
465
 *   An associative array containing:
466
 *   - taxon
467
 *   - addAcceptedTaxon
468
 *
469
 * @ingroup themeable
470
 */
471
function theme_cdm_taxon_page_synonymy($variables) {
472
  $taxon = $variables['taxon'];
473
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
474
  RenderHints::pushToRenderStack('taxon_page_synonymy');
475
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
476
  $skip = array(
477
    UUID_BASIONYM,
478
  );
479
  $out = '';
480

    
481
  // Render accepted taxon.
482
  $referenceUri = '';
483
  if ($addAcceptedTaxon) {
484
    if (isset($taxon->name->nomenclaturalReference)) {
485
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
486
    }
487

    
488
    $accepted_name = '<span class="accepted-name">';
489
    $accepted_name .= theme('cdm_taxonName', array(
490
      'taxonName' => $taxon->name,
491
      'nameLink' => NULL,
492
      'refenceLink' => $referenceUri,
493
      ));
494
    $accepted_name .= '</span>';
495

    
496
    $special_annotations_array = array();
497
    $special_annotations_array[] = $taxon->name;
498
    $special_annotations_array[] = $taxon;
499
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $special_annotations_array, 'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
500
    RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
501
  }
502

    
503
  // Render homotypic synonymy group.
504
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
505

    
506
  if (!empty($accepted_name)) {
507
    $out .= $accepted_name;
508
  }
509

    
510
  if (!$hasHomotypicSynonyms) {
511
    // Show typeDesignations even if the homotypic synonymy group is empty.
512
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
513
    if ($typeDesignations) {
514
      $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
515
    }
516
    if (!empty($typeDesignations) || !empty($accepted_name)) {
517
      // Add empty list for coherent layout.
518
      $out .= '<ul class="homotypicSynonyms"></ul>';
519
    }
520
  }
521
  else {
522
    // Render the homotypicSynonymyGroup including the type information.
523
    $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
524
  }
525

    
526
  // Render accepted taxon heterotypic synonymy groups.
527
  if ($synomymie->heterotypicSynonymyGroups) {
528
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
529
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
530
    }
531
  }
532
  // Render taxon relationships.
533
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
534
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
535
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
536
  }
537
  // Render name relationships.
538
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
539
  $skip = array();
540
  if ($name_rels_to_show) {
541
    foreach ($name_rels_to_show as $key => $value) {
542
      if ($value === 0) {
543
        $skip[] = $key;
544
      }
545
    }
546
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
547
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
548
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
549
    }
550
  }
551

    
552
  // Render the annontations text for the accepted taxa.
553
  if ($addAcceptedTaxon) {
554
    $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
555
  }
556
  RenderHints::popFromRenderStack();
557

    
558
  return $out;
559
}
560

    
561
/**
562
 * TODO Implementation of Hook taxon_image_gallery()
563
 *
564
 * @param unknown_type $taxon
565
 * @param unknown_type $media
566
 *
567
 * @return unknown_type
568
 */
569
function taxon_image_gallery_default($taxon, $media) {
570
  $hasImages = isset($media[0]);
571

    
572
  if ($hasImages) {
573

    
574
    $maxExtend = 150;
575
    $cols = 3;
576
    $maxRows = FALSE;
577
    $alternativeMediaUri = NULL;
578
    /* Comment @WA: was in D5:
579
    $captionElements = array(
580
      'title',
581
      'rights',
582
      '#uri' => t('open Image'),
583
    );
584
    */
585
    $captionElements = array(
586
      'title',
587
      'description',
588
      'artist',
589
      'location',
590
      'rights',
591
      '#uri' => t('open Image'),
592
    );
593
    $gallery_name = $taxon->uuid;
594
    $mediaLinkType = 'LIGHTBOX';
595

    
596
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
597

    
598
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
599

    
600
    $out = '<div class="image-gallerie">';
601
    $out .= theme('cdm_media_gallerie', array(
602
      'mediaList' => $media,
603
      'galleryName' => $gallery_name,
604
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
605
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
606
      'maxRows' => 0, // Ignore maxrows settings.
607
      'captionElements' => $captionElements,
608
      'mediaLinkType' => $mediaLinkType,
609
      'alternativeMediaUri' => NULL,
610
      'galleryLinkUri' => NULL,
611
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
612
    ));
613
    $out .= '</div>';
614
  }
615
  else {
616
    $out = 'No images available.';
617
  }
618
  return $out;
619
}
620

    
621
/**
622
 * TODO Implementation of Hook taxon_image_gallery()
623
 *
624
 * @param unknown_type $taxon
625
 * @param unknown_type $media
626
 *
627
 * @return unknown_type
628
 */
629
function taxon_image_gallery_fsi($taxon, $media) {
630
  $flashLink = isset($media[0]);
631

    
632
  if ($flashLink) {
633

    
634
    if (module_exists("fsi_gallery")) {
635
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
636
    }
637
    else {
638
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
639
      drupal_set_message($message, "error");
640
      $out = '<h3>' . $message . '</h3>';
641
    }
642
  }
643
  else {
644
    $out = 'No images available.';
645
  }
646
  return $out;
647
}
648

    
649
/**
650
 * Returns HTML for a single reference page.
651
 *
652
 * Renders a page with all data on a single reference.
653
 *
654
 * @param array $variables
655
 *   An associative array containing:
656
 *   - reference: Object.
657
 *
658
 * @ingroup themeable
659
 */
660
function theme_cdm_reference_page($variables) {
661
  $reference = $variables['reference'];
662

    
663
  $out = '';
664

    
665
  if (isset($reference->titleCache)) {
666
    drupal_set_title($reference->titleCache, PASS_THROUGH);
667
  }
668

    
669
  $field_order = array(
670
    "title",
671
    // "titleCache",
672
    // "citation",
673
    "authorTeam",
674
    "editor",
675
    "publisher",
676
    "placePublished",
677
    "datePublished",
678
    "year",
679
    "edition",// Class Book.
680
    "volume",// Class Article.
681
    "seriesPart",
682
    "inReference",
683
    "nomRefBase", // Class BookSection, Book, Article.
684
    "pages",// Class Article.
685
    "series",// Class Article, PrintSeries.
686
    "school",// Class Thesis.
687
    "institution",// Class Report.
688
    "organization",// Class Proceedings.
689
    "nextVersion",
690
    "previousVersion",
691
    "isbn",// Class Book.
692
    "issn",// Class Journal.
693
    "uri",
694
  );
695

    
696
  $header = array(
697
    t('Field'),
698
    t('Value'),
699
  );
700
  $table_rows = array();
701

    
702
  if (!isset($reference->authorTeam)) {
703
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
704
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
705
  }
706

    
707
  if (!isset($reference->inReference)) {
708
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
709
      $reference->uuid,
710
      "inReference",
711
    ));
712
  }
713

    
714
  foreach ($field_order as $fieldname) {
715

    
716
    if (isset($reference->$fieldname)) {
717

    
718
      if ($fieldname == "datePublished") {
719
        $period = $reference->$fieldname;
720
        $datePublished = timePeriodToString($period);
721
        if (isset($datePublished) && $datePublished != '') {
722
          $table_rows[] = array(
723
            t(ucfirst(strtolower($fieldname))),
724
            $datePublished,
725
          );
726
        }
727
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
728
        // $datePublished);
729
      }
730
      elseif (is_object($reference->$fieldname)) {
731
        if ($fieldname == "authorTeam") {
732
          $dump = $reference->$fieldname;
733
          $teammembers = "teamMembers";
734
          $team = $dump->$teammembers;
735
          $nameArray = array();
736

    
737
          foreach ($team as $member) {
738
            if (strlen($member->lastname) > 0) {
739
              $nname = $member->lastname;
740
              $name = $nname;
741
              if (strlen($member->firstname) > 0) {
742
                $vname = $member->firstname;
743
                $name = $vname . " " . $nname;
744
              }
745
              $nameArray[] = $name;
746
            }
747
            else {
748
              if (strlen($member->titleCache) > 0) {
749
                $nameArray[] = $member->titleCache;
750
              }
751
            }
752
          }
753
          $value = join($nameArray, ", ");
754
        }
755
        elseif ($fieldname == "inReference") {
756
          $type = $reference->$fieldname->type;
757
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
758
          switch ($type) {
759
            case "Book":
760
              $fieldname = "in book";
761
              break;
762
            case "Journal":
763
              $fieldname = "in journal";
764
              break;
765
            case "Proceedings":
766
              $fieldname = "in proceedings";
767
              break;
768
          }
769
        }
770
        else {
771
          $value = $reference->$fieldname->titleCache;
772
        }
773
        if (isset($value) && $value != '') {
774
          $table_rows[] = array(
775
            t(ucfirst(strtolower($fieldname))),
776
            $value,
777
          );
778
        }
779
      }
780
      else {
781
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
782
          $table_rows[] = array(
783
            t(ucfirst(strtolower($fieldname))),
784
            $reference->$fieldname,
785
          );
786
        }
787
      }
788
    }
789
  }
790

    
791
  $out = theme_table(array(
792
      'header' => array(),
793
      'rows' => $table_rows,
794
      'attributes' => array(),
795
      'caption' => NULL,
796
      'colgroups' => NULL,
797
      'sticky' => NULL,
798
     'empty' => NULL,
799
  ));
800

    
801
  // Annotations below the table.
802
  $annotations = cdm_ws_getAnnotationsFor($reference);
803
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
804

    
805
  return $out;
806
}
807

    
808
/**
809
 * @todo Please document this function.
810
 * @see http://drupal.org/node/1354
811
 */
812
function theme_cdm_media_page($variables) {
813
  $media = $variables['media'];
814
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
815
  $partId = $variables['partId'];
816
  $out = '';
817
  // Determine which reprresentation and which part to show.
818
  $representationIdx = 0;
819
  if ($mediarepresentation_uuid) {
820
    $i = 0;
821
    foreach ($media->representations as $representation) {
822
      if ($representation->uuid == $mediarepresentation_uuid) {
823
        $representationIdx = $i;
824
      }
825
      $i++;
826
    }
827
  }
828
  else {
829
    $mediarepresentation_uuid = $media->representations[0]->uuid;
830
  }
831

    
832
  $partIdx = 0;
833
  if (!is_numeric($partId)) {
834
    // Assuming it is an uuid.
835
    $i = 0;
836
    foreach ($media->representations[$representationIdx]->parts as $part) {
837
      if ($part->uuid == $partId) {
838
        $partIdx = $i;
839
      }
840
      $i++;
841
    }
842
  }
843
  else {
844
    // Assuming it is an index.
845
    $partIdx = $partId;
846
  }
847

    
848
  $media_metadata = cdm_read_media_metadata($media);
849
  // $title = $media->titleCache;
850
  $title = $media_metadata['title'];
851

    
852
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
853

    
854
  if (!$title) {
855
    $title = 'Media ' . $media->uuid . '';
856
  }
857

    
858
  drupal_set_title($title, PASS_THROUGH);
859

    
860
  $out .= '<div class="media cdm_media_viewer_image">';
861

    
862
  // $out .= '<div class="viewer">';
863
  $out .= theme('cdm_back_to_image_gallery_button', array());
864
  $out .= '<div class="viewer">';
865
  // $out .= theme('cdm_media_gallerie_image', $representation->parts[$partIdx],
866
  // $imageMaxExtend);
867
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
868
  $out .= '</div>';
869

    
870
  // General media metadata.
871
  /*
872
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
873
  vardump("PRINTING MEDIA METADATA");
874
  vardump($media_metadata);
875
  vardump("PRINTING MEDIA");
876
  vardump($media);
877
  */
878
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
879
  $out .= $metadataToPrint;
880

    
881
  // Tabs for the different representations.
882
  // ul.secondary
883
  $out .= '<ul class="primary">';
884
  foreach ($media->representations as $representation) {
885
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
886
  }
887
  $out .= '</ul>';
888

    
889
  // Representation(-part) specific metadata.
890
  $thumbnailMaxExtend = 100;
891
  $out .= '<table>';
892
  // $out .= '<tr><th colspan="3">'.t('MimeType').':
893
  // '.$media->representations[$representationIdx]->mimeType.'</th></tr>';
894
  $i = 0;
895
  foreach ($media->representations[$representationIdx]->parts as $part) {
896
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
897
    switch ($part->class) {
898
      case 'ImageFile':
899
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
900
        break;
901
      case 'AudioFile':
902
      case 'MovieFile':
903
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
904
        break;
905
      default:
906
        $out .= $part->size . 'k';
907
    }
908

    
909
    $out .= '</td><td><a href="' . url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)) . '">' . theme('cdm_media_gallerie_image', array('mediaRepresentationPart' => $part, 'maxExtend' => $thumbnailMaxExtend, 'addPassePartout' => TRUE));
910
    $i++;
911
  }
912
  $out .= '</table>';
913
  $out .= '</div>';
914

    
915
  return $out;
916
}
917

    
918
/**
919
 * @todo Please document this function.
920
 * @see http://drupal.org/node/1354
921
 */
922
function theme_cdm_polytomousKey_page($variables) {
923
  $polytomousKey = $variables['polytomousKey'];
924
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
925

    
926
  $out = theme("cdm_IdentificationKey", array(
927
    'identificationKey' => $polytomousKey,
928
    'doLinkToKeyPage' => FALSE,
929
    'showIdentificationKeyTitle' => FALSE,
930
    ));
931

    
932
  // Key nodes in linked style.
933
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
934
  /*
935
  FIXME implement node type for keys !!! (wrapping the content in the
936
  cdm_dataportal.node becomes obsolete then).
937
  */
938
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
939
}
940

    
941
/**
942
 * Returns HTML for taxon page tabs.
943
 *
944
 * Allows theming of the taxon page tabs.
945
 *
946
 * @param array $variables
947
 *   An associative array containing:
948
 *   - tabname
949
 *
950
 * @ingroup themeable
951
 */
952
function theme_cdm_taxonpage_tab($variables) {
953
  $tabname = $variables['tabname'];
954
  // TODO replace by using translations or theme the menue tabs itself instead?
955
  switch ($tabname) {
956
    default:
957
      return t($tabname);
958
  }
959
}
(7-7/9)