Project

General

Profile

Download (30.2 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
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
135

    
136
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
137
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
138
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Specimens'));
139
  }
140

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

    
151
  if ($tabsToDisplay["Synonymy"] == '0') {
152
    $hideTabs[] = theme('cdm_taxonpage_tab', array('tabname' => 'Synonymy'));
153
  }
154

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

    
166
  $out = '';
167
  $out .= theme('cdm_back_to_search_result_button');
168

    
169
  // var_dump(variable_get('cdm_dataportal_display_is_accepted_for',
170
  // CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR));
171
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
172
    $out .= theme('cdm_acceptedFor', 'page_general');
173
  }
174

    
175
  // --- PAGE PART: DESCRIPTION --- //
176
  if ($page_part == 'description' || $page_part == 'all') {
177

    
178
    $markerTypesEmpty = array();
179
    $markerTypesEmpty['markerTypes'] = '';
180
    // Retrieve all descriptions for the taxon.
181
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, queryString($markerTypesEmpty));
182

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

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

    
224
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
225

    
226
    $out .= '<div id="general">';
227
    $out .= theme('cdm_taxon_page_profile', array(
228
      'taxon' => $taxon,
229
      'mergedTrees' => $mergedTrees,
230
      'media' => $media,
231
      'hideImages' => $hideImages,
232
      ));
233
    $out .= '</div>';
234
  }
235

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

    
249
    $out .= '</div>';
250
  }
251

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

    
261
    $out .= '</div>';
262
  }
263

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

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

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

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

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

    
324
  // Description TOC.
325
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
326

    
327
  // Description.
328
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
329

    
330
  return $out;
331
}
332

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

    
342
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array(
343
    $taxon->uuid,
344
    'specimensOrObservations',
345
  ));
346

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

    
364
  if (count($specimensOrObservations) > 0) {
365
    $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid);
366

    
367
    if( isset($occurrenceQuery->String) ) {
368
      $occurrenceQuery = $occurrenceQuery->String;
369

    
370
      $legendFormatQueryStr = null;
371
      if (variable_get('cdm_dataportal_map_openlayers', 1)) {
372
        $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', 680), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
373
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
374
      }
375
      else {
376
        // get_image_map($width, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE )
377
        $out .= get_image_map(variable_get('cdm_dataportal_geoservice_display_width', 680), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
378
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
379
      }
380
    }
381
  }
382
  $out_specimenList = '';
383
  if ($specimensOrObservations) {
384
    $out_specimenList = '<table class="specimens">';
385
    $i = 1;
386
    foreach ($specimensOrObservations as $specimensOrObservation) {
387
      $i++;
388

    
389
      $mediaList = array();
390
      if (is_array($specimensOrObservation->_fieldObjectMedia)) {
391
        $mediaList = array_merge($mediaList, $specimensOrObservation->_fieldObjectMedia);
392
      }
393
      if (is_array($specimensOrObservation->_derivedUnitMedia)) {
394
        $mediaList = array_merge($mediaList, $specimensOrObservation->_derivedUnitMedia);
395
      }
396

    
397
      // --- Render the title cache.
398
      $out_row = '<tr class="descriptionElement descriptionElement_IndividualsAssociation ' . ($i % 2 ? 'odd' : 'even') . '">';
399

    
400
      if ($specimensOrObservation->class != 'FieldObservation') {
401
        // details are loaded on request via the cdm_dynabox by AJAX
402
        $derived_unit_ws_request = cdm_compose_url('portal/' . CDM_WS_DERIVEDUNIT_FACADE, array( $specimensOrObservation->uuid));
403
        $label_html = cdm_dynabox(
404
            $specimensOrObservation->titleCache,
405
            $derived_unit_ws_request,
406
            'cdm_derivedUnitFacade',
407
            'Click for details',
408
            array('div','div')
409
        );
410
      }
411
      else {
412
        $label_html = $specimensOrObservation->titleCache;
413
      }
414
      $out_row .= '<td>' . $label_html . '</td>';
415

    
416
      // --- Render associated media.
417
      $gallery_html = '';
418
      if (count($mediaList) > 0) {
419
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
420
        $gallery_name = $specimensOrObservation->uuid;
421
        $captionElements = array(
422
          '#uri' => t('open media'),
423
        );
424

    
425
        $gallery_html = theme('cdm_media_gallerie', array(
426
          'mediaList' => $mediaList,
427
          'galleryName' => $gallery_name,
428
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
429
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
430
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
431
          'captionElements' => $captionElements,
432
          'mediaLinkType' => 'LIGHTBOX',
433
          'alternativeMediaUri' => NULL,
434
          'galleryLinkUri' => NULL,
435
          ));
436
      }
437
      $out_row .= '<td>' . $gallery_html . '</td></tr>';
438
      $out_specimenList .= $out_row;
439
    }
440
    $out_specimenList .= '</table>';
441
  }
442

    
443
  $out .= $out_specimenList;
444

    
445
  RenderHints::popFromRenderStack();
446
  return $out;
447
}
448

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

    
473
  // Render accepted taxon.
474
  $referenceUri = '';
475
  if ($addAcceptedTaxon) {
476
    if (isset($taxon->name->nomenclaturalReference)) {
477
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
478
    }
479

    
480
    $accepted_name = '<span class="accepted-name">';
481
    $accepted_name .= theme('cdm_taxonName', array(
482
      'taxonName' => $taxon->name,
483
      'nameLink' => NULL,
484
      'refenceLink' => $referenceUri,
485
      ));
486
    $accepted_name .= '</span>';
487

    
488
    $special_annotations_array = array();
489
    $special_annotations_array[] = $taxon->name;
490
    $special_annotations_array[] = $taxon;
491
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $special_annotations_array, 'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
492
    RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
493
  }
494

    
495
  // Render homotypic synonymy group.
496
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
497

    
498
  if (!empty($accepted_name)) {
499
    $out .= $accepted_name;
500
  }
501

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

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

    
544
  // Render the annontations text for the accepted taxa.
545
  if ($addAcceptedTaxon) {
546
    $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
547
  }
548
  RenderHints::popFromRenderStack();
549

    
550
  return $out;
551
}
552

    
553
/**
554
 * TODO Implementation of Hook taxon_image_gallery()
555
 *
556
 * @param unknown_type $taxon
557
 * @param unknown_type $media
558
 *
559
 * @return unknown_type
560
 */
561
function taxon_image_gallery_default($taxon, $media) {
562
  $hasImages = isset($media[0]);
563

    
564
  if ($hasImages) {
565

    
566
    $maxExtend = 150;
567
    $cols = 3;
568
    $maxRows = FALSE;
569
    $alternativeMediaUri = NULL;
570
    /* Comment @WA: was in D5:
571
    $captionElements = array(
572
      'title',
573
      'rights',
574
      '#uri' => t('open Image'),
575
    );
576
    */
577
    $captionElements = array(
578
      'title',
579
      'description',
580
      'artist',
581
      'location',
582
      'rights',
583
      '#uri' => t('open Image'),
584
    );
585
    $gallery_name = $taxon->uuid;
586
    $mediaLinkType = 'LIGHTBOX';
587

    
588
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
589

    
590
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
591

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

    
613
/**
614
 * TODO Implementation of Hook taxon_image_gallery()
615
 *
616
 * @param unknown_type $taxon
617
 * @param unknown_type $media
618
 *
619
 * @return unknown_type
620
 */
621
function taxon_image_gallery_fsi($taxon, $media) {
622
  $flashLink = isset($media[0]);
623

    
624
  if ($flashLink) {
625

    
626
    if (module_exists("fsi_gallery")) {
627
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
628
    }
629
    else {
630
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
631
      drupal_set_message($message, "error");
632
      $out = '<h3>' . $message . '</h3>';
633
    }
634
  }
635
  else {
636
    $out = 'No images available.';
637
  }
638
  return $out;
639
}
640

    
641
/**
642
 * Returns HTML for a single reference page.
643
 *
644
 * Renders a page with all data on a single reference.
645
 *
646
 * @param array $variables
647
 *   An associative array containing:
648
 *   - reference: Object.
649
 *
650
 * @ingroup themeable
651
 */
652
function theme_cdm_reference_page($variables) {
653
  $reference = $variables['reference'];
654

    
655
  $out = '';
656

    
657
  if (isset($reference->titleCache)) {
658
    drupal_set_title($reference->titleCache, PASS_THROUGH);
659
  }
660

    
661
  $field_order = array(
662
    "title",
663
    // "titleCache",
664
    // "citation",
665
    "authorTeam",
666
    "editor",
667
    "publisher",
668
    "placePublished",
669
    "datePublished",
670
    "year",
671
    "edition",// Class Book.
672
    "volume",// Class Article.
673
    "seriesPart",
674
    "inReference",
675
    "nomRefBase", // Class BookSection, Book, Article.
676
    "pages",// Class Article.
677
    "series",// Class Article, PrintSeries.
678
    "school",// Class Thesis.
679
    "institution",// Class Report.
680
    "organization",// Class Proceedings.
681
    "nextVersion",
682
    "previousVersion",
683
    "isbn",// Class Book.
684
    "issn",// Class Journal.
685
    "uri",
686
  );
687

    
688
  $header = array(
689
    t('Field'),
690
    t('Value'),
691
  );
692
  $table_rows = array();
693

    
694
  if (!isset($reference->authorTeam)) {
695
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
696
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
697
  }
698

    
699
  if (!isset($reference->inReference)) {
700
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
701
      $reference->uuid,
702
      "inReference",
703
    ));
704
  }
705

    
706
  foreach ($field_order as $fieldname) {
707

    
708
    if (isset($reference->$fieldname)) {
709

    
710
      if ($fieldname == "datePublished") {
711
        $period = $reference->$fieldname;
712
        $datePublished = timePeriodToString($period);
713
        if (isset($datePublished) && $datePublished != '') {
714
          $table_rows[] = array(
715
            t(ucfirst(strtolower($fieldname))),
716
            $datePublished,
717
          );
718
        }
719
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
720
        // $datePublished);
721
      }
722
      elseif (is_object($reference->$fieldname)) {
723
        if ($fieldname == "authorTeam") {
724
          $dump = $reference->$fieldname;
725
          $teammembers = "teamMembers";
726
          $team = $dump->$teammembers;
727
          $nameArray = array();
728

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

    
783
  $out = theme_table(array(
784
      'header' => array(),
785
      'rows' => $table_rows,
786
      'attributes' => array(),
787
      'caption' => NULL,
788
      'colgroups' => NULL,
789
      'sticky' => NULL,
790
     'empty' => NULL,
791
  ));
792

    
793
  // Annotations below the table.
794
  $annotations = cdm_ws_getAnnotationsFor($reference);
795
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
796

    
797
  return $out;
798
}
799

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

    
824
  $partIdx = 0;
825
  if (!is_numeric($partId)) {
826
    // Assuming it is an uuid.
827
    $i = 0;
828
    foreach ($media->representations[$representationIdx]->parts as $part) {
829
      if ($part->uuid == $partId) {
830
        $partIdx = $i;
831
      }
832
      $i++;
833
    }
834
  }
835
  else {
836
    // Assuming it is an index.
837
    $partIdx = $partId;
838
  }
839

    
840
  $media_metadata = cdm_read_media_metadata($media);
841
  // $title = $media->titleCache;
842
  $title = $media_metadata['title'];
843

    
844
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
845

    
846
  if (!$title) {
847
    $title = 'Media ' . $media->uuid . '';
848
  }
849

    
850
  drupal_set_title($title, PASS_THROUGH);
851

    
852
  $out .= '<div class="media cdm_media_viewer_image">';
853

    
854
  $out .= theme('cdm_back_to_image_gallery_button', array());
855
  $out .= '<div class="viewer">';
856
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
857
  $out .= '</div>';
858

    
859
  // General media metadata.
860
  /*
861
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
862
  vardump("PRINTING MEDIA METADATA");
863
  vardump($media_metadata);
864
  vardump("PRINTING MEDIA");
865
  vardump($media);
866
  */
867
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
868
  $out .= $metadataToPrint;
869

    
870
  // Tabs for the different representations.
871
  // ul.secondary
872
  $out .= '<ul class="primary">';
873
  foreach ($media->representations as $representation) {
874
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
875
  }
876
  $out .= '</ul>';
877

    
878
  // Representation(-part) specific metadata.
879
  $thumbnailMaxExtend = 100;
880
  $out .= '<table>';
881
  $i = 0;
882
  foreach ($media->representations[$representationIdx]->parts as $part) {
883
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
884
    switch ($part->class) {
885
      case 'ImageFile':
886
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
887
        break;
888
      case 'AudioFile':
889
      case 'MovieFile':
890
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
891
        break;
892
      default:
893
        $out .= $part->size . 'k';
894
    }
895

    
896
    $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));
897
    $i++;
898
  }
899
  $out .= '</table>';
900
  $out .= '</div>';
901

    
902
  return $out;
903
}
904

    
905
/**
906
 * @todo Please document this function.
907
 * @see http://drupal.org/node/1354
908
 */
909
function theme_cdm_polytomousKey_page($variables) {
910
  $polytomousKey = $variables['polytomousKey'];
911
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
912

    
913
  $out = theme("cdm_IdentificationKey", array(
914
    'identificationKey' => $polytomousKey,
915
    'doLinkToKeyPage' => FALSE,
916
    'showIdentificationKeyTitle' => FALSE,
917
    ));
918

    
919
  // Key nodes in linked style.
920
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
921
  /*
922
  FIXME implement node type for keys !!! (wrapping the content in the
923
  cdm_dataportal.node becomes obsolete then).
924
  */
925
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
926
}
927

    
928
/**
929
 * Returns HTML for taxon page tabs.
930
 *
931
 * Allows theming of the taxon page tabs.
932
 *
933
 * @param array $variables
934
 *   An associative array containing:
935
 *   - tabname
936
 *
937
 * @ingroup themeable
938
 */
939
function theme_cdm_taxonpage_tab($variables) {
940
  $tabname = $variables['tabname'];
941
  // TODO replace by using translations or theme the menue tabs itself instead?
942
  switch ($tabname) {
943
    default:
944
      return t($tabname);
945
  }
946
}
(7-7/9)