Project

General

Profile

Download (30.2 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 7a2a14b3 Andreas Kohlbecker
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
135 6657531f Andreas Kohlbecker
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 5003e934 Andreas Kohlbecker
    $defaultRepresentationPart = new stdClass();
311 6657531f Andreas Kohlbecker
    $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 347d2c07 Andreas Kohlbecker
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
318 6657531f Andreas Kohlbecker
      '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 7a2a14b3 Andreas Kohlbecker
    'specimensOrObservations',
345 6657531f Andreas Kohlbecker
  ));
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
      // os=&od=&legend=0&recalculate=false&image=false
369
      $occurrenceQuery = $occurrenceQuery->String;
370
371 7a2a14b3 Andreas Kohlbecker
      $legendFormatQueryStr = null;
372 6657531f Andreas Kohlbecker
      if (variable_get('cdm_dataportal_map_openlayers', 1)) {
373
        $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', FALSE), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
374 7a2a14b3 Andreas Kohlbecker
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
375 6657531f Andreas Kohlbecker
      }
376
      else {
377
        // get_image_map($width, $occurrenceQuery = FALSE, $distributionQuery = FALSE, $legendFormatQuery = FALSE, $map_caption = FALSE )
378
        $out .= get_image_map(variable_get('cdm_dataportal_geoservice_display_width', FALSE), variable_get('cdm_dataportal_geoservice_bounding_box', FALSE), $occurrenceQuery, NULL,
379 7a2a14b3 Andreas Kohlbecker
            $legendFormatQueryStr, variable_get('cdm_dataportal_geoservice_map_caption', ''));
380 6657531f Andreas Kohlbecker
      }
381
    }
382
  }
383
  $out_specimenList = '';
384
  if ($specimensOrObservations) {
385
    $out_specimenList = '<table class="specimens">';
386
    $i = 1;
387
    foreach ($specimensOrObservations as $specimensOrObservation) {
388
      $i++;
389
390
      $mediaList = array();
391
      if (is_array($specimensOrObservation->_fieldObjectMedia)) {
392
        $mediaList = array_merge($mediaList, $specimensOrObservation->_fieldObjectMedia);
393
      }
394
      if (is_array($specimensOrObservation->_derivedUnitMedia)) {
395
        $mediaList = array_merge($mediaList, $specimensOrObservation->_derivedUnitMedia);
396
      }
397
398
      // --- Render the title cache.
399
      $out_row = '<tr class="descriptionElement descriptionElement_IndividualsAssociation ' . ($i % 2 ? 'odd' : 'even') . '">';
400 7a2a14b3 Andreas Kohlbecker
401 6657531f Andreas Kohlbecker
      if ($specimensOrObservation->class != 'FieldObservation') {
402 7a2a14b3 Andreas Kohlbecker
        // details are loaded on request via the cdm_dynabox by AJAX
403
        $derived_unit_ws_request = cdm_compose_url('portal/' . CDM_WS_DERIVEDUNIT_FACADE, array( $specimensOrObservation->uuid));
404
        $label_html = cdm_dynabox(
405
            $specimensOrObservation->titleCache,
406
            $derived_unit_ws_request,
407
            'cdm_derivedUnitFacade',
408
            'Click for details',
409
            array('div','div')
410
        );
411 6657531f Andreas Kohlbecker
      }
412
      else {
413
        $label_html = $specimensOrObservation->titleCache;
414
      }
415
      $out_row .= '<td>' . $label_html . '</td>';
416
417
      // --- Render associated media.
418 7a2a14b3 Andreas Kohlbecker
      $gallery_html = '';
419 6657531f Andreas Kohlbecker
      if (count($mediaList) > 0) {
420
        $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
421
        $gallery_name = $specimensOrObservation->uuid;
422
        $captionElements = array(
423
          '#uri' => t('open media'),
424
        );
425
426
        $gallery_html = theme('cdm_media_gallerie', array(
427
          'mediaList' => $mediaList,
428
          'galleryName' => $gallery_name,
429
          'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
430
          'cols' => $gallery_settings['cdm_dataportal_media_cols'],
431 7a2a14b3 Andreas Kohlbecker
          'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
432 6657531f Andreas Kohlbecker
          'captionElements' => $captionElements,
433
          'mediaLinkType' => 'LIGHTBOX',
434
          'alternativeMediaUri' => NULL,
435
          'galleryLinkUri' => NULL,
436
          ));
437
      }
438
      $out_row .= '<td>' . $gallery_html . '</td></tr>';
439
      $out_specimenList .= $out_row;
440
    }
441
    $out_specimenList .= '</table>';
442
  }
443
444
  $out .= $out_specimenList;
445
446
  RenderHints::popFromRenderStack();
447
  return $out;
448
}
449
450
/**
451
 * Returns HTML containing the synonymy for the accepted taxon.
452
 *
453
 * Shows the whole synonymy for the accepted taxon.
454
 * The synonymy list is headed by the complete scientific name
455
 * of the accepted taxon with nomenclatural reference.
456
 *
457
 * @param array $variables
458
 *   An associative array containing:
459
 *   - taxon
460
 *   - addAcceptedTaxon
461
 *
462
 * @ingroup themeable
463
 */
464
function theme_cdm_taxon_page_synonymy($variables) {
465
  $taxon = $variables['taxon'];
466
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
467
  RenderHints::pushToRenderStack('taxon_page_synonymy');
468
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
469
  $skip = array(
470
    UUID_BASIONYM,
471
  );
472
  $out = '';
473
474
  // Render accepted taxon.
475
  $referenceUri = '';
476
  if ($addAcceptedTaxon) {
477
    if (isset($taxon->name->nomenclaturalReference)) {
478
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
479
    }
480
481
    $accepted_name = '<span class="accepted-name">';
482
    $accepted_name .= theme('cdm_taxonName', array(
483
      'taxonName' => $taxon->name,
484
      'nameLink' => NULL,
485
      'refenceLink' => $referenceUri,
486
      ));
487
    $accepted_name .= '</span>';
488
489
    $special_annotations_array = array();
490
    $special_annotations_array[] = $taxon->name;
491
    $special_annotations_array[] = $taxon;
492
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $special_annotations_array, 'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
493
    RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
494
  }
495
496
  // Render homotypic synonymy group.
497
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
498
499
  if (!empty($accepted_name)) {
500
    $out .= $accepted_name;
501
  }
502
503
  if (!$hasHomotypicSynonyms) {
504
    // Show typeDesignations even if the homotypic synonymy group is empty.
505
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
506
    if ($typeDesignations) {
507
      $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
508
    }
509
    if (!empty($typeDesignations) || !empty($accepted_name)) {
510
      // Add empty list for coherent layout.
511
      $out .= '<ul class="homotypicSynonyms"></ul>';
512
    }
513
  }
514
  else {
515
    // Render the homotypicSynonymyGroup including the type information.
516
    $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
517
  }
518
519
  // Render accepted taxon heterotypic synonymy groups.
520
  if ($synomymie->heterotypicSynonymyGroups) {
521
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
522
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
523
    }
524
  }
525
  // Render taxon relationships.
526
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
527
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
528
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
529
  }
530
  // Render name relationships.
531
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
532
  $skip = array();
533
  if ($name_rels_to_show) {
534
    foreach ($name_rels_to_show as $key => $value) {
535
      if ($value === 0) {
536
        $skip[] = $key;
537
      }
538
    }
539
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
540
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
541
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
542
    }
543
  }
544
545
  // Render the annontations text for the accepted taxa.
546
  if ($addAcceptedTaxon) {
547
    $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
548
  }
549
  RenderHints::popFromRenderStack();
550
551
  return $out;
552
}
553
554
/**
555
 * TODO Implementation of Hook taxon_image_gallery()
556
 *
557
 * @param unknown_type $taxon
558
 * @param unknown_type $media
559
 *
560
 * @return unknown_type
561
 */
562
function taxon_image_gallery_default($taxon, $media) {
563
  $hasImages = isset($media[0]);
564
565
  if ($hasImages) {
566
567
    $maxExtend = 150;
568
    $cols = 3;
569
    $maxRows = FALSE;
570
    $alternativeMediaUri = NULL;
571
    /* Comment @WA: was in D5:
572
    $captionElements = array(
573
      'title',
574
      'rights',
575
      '#uri' => t('open Image'),
576
    );
577
    */
578
    $captionElements = array(
579
      'title',
580
      'description',
581
      'artist',
582
      'location',
583
      'rights',
584
      '#uri' => t('open Image'),
585
    );
586
    $gallery_name = $taxon->uuid;
587
    $mediaLinkType = 'LIGHTBOX';
588
589
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
590
591
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
592
593
    $out = '<div class="image-gallerie">';
594
    $out .= theme('cdm_media_gallerie', array(
595
      'mediaList' => $media,
596
      'galleryName' => $gallery_name,
597
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
598
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
599
      'maxRows' => 0, // Ignore maxrows settings.
600
      'captionElements' => $captionElements,
601
      'mediaLinkType' => $mediaLinkType,
602
      'alternativeMediaUri' => NULL,
603
      'galleryLinkUri' => NULL,
604
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
605
    ));
606
    $out .= '</div>';
607
  }
608
  else {
609
    $out = 'No images available.';
610
  }
611
  return $out;
612
}
613
614
/**
615
 * TODO Implementation of Hook taxon_image_gallery()
616
 *
617
 * @param unknown_type $taxon
618
 * @param unknown_type $media
619
 *
620
 * @return unknown_type
621
 */
622
function taxon_image_gallery_fsi($taxon, $media) {
623
  $flashLink = isset($media[0]);
624
625
  if ($flashLink) {
626
627
    if (module_exists("fsi_gallery")) {
628
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
629
    }
630
    else {
631
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
632
      drupal_set_message($message, "error");
633
      $out = '<h3>' . $message . '</h3>';
634
    }
635
  }
636
  else {
637
    $out = 'No images available.';
638
  }
639
  return $out;
640
}
641
642
/**
643
 * Returns HTML for a single reference page.
644
 *
645
 * Renders a page with all data on a single reference.
646
 *
647
 * @param array $variables
648
 *   An associative array containing:
649
 *   - reference: Object.
650
 *
651
 * @ingroup themeable
652
 */
653
function theme_cdm_reference_page($variables) {
654
  $reference = $variables['reference'];
655
656
  $out = '';
657
658
  if (isset($reference->titleCache)) {
659
    drupal_set_title($reference->titleCache, PASS_THROUGH);
660
  }
661
662
  $field_order = array(
663
    "title",
664
    // "titleCache",
665
    // "citation",
666
    "authorTeam",
667
    "editor",
668
    "publisher",
669
    "placePublished",
670
    "datePublished",
671
    "year",
672
    "edition",// Class Book.
673
    "volume",// Class Article.
674
    "seriesPart",
675
    "inReference",
676
    "nomRefBase", // Class BookSection, Book, Article.
677
    "pages",// Class Article.
678
    "series",// Class Article, PrintSeries.
679
    "school",// Class Thesis.
680
    "institution",// Class Report.
681
    "organization",// Class Proceedings.
682
    "nextVersion",
683
    "previousVersion",
684
    "isbn",// Class Book.
685
    "issn",// Class Journal.
686
    "uri",
687
  );
688
689
  $header = array(
690
    t('Field'),
691
    t('Value'),
692
  );
693
  $table_rows = array();
694
695
  if (!isset($reference->authorTeam)) {
696
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
697
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
698
  }
699
700
  if (!isset($reference->inReference)) {
701
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
702
      $reference->uuid,
703
      "inReference",
704
    ));
705
  }
706
707
  foreach ($field_order as $fieldname) {
708
709
    if (isset($reference->$fieldname)) {
710
711
      if ($fieldname == "datePublished") {
712
        $period = $reference->$fieldname;
713
        $datePublished = timePeriodToString($period);
714
        if (isset($datePublished) && $datePublished != '') {
715
          $table_rows[] = array(
716
            t(ucfirst(strtolower($fieldname))),
717
            $datePublished,
718
          );
719
        }
720
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
721
        // $datePublished);
722
      }
723
      elseif (is_object($reference->$fieldname)) {
724
        if ($fieldname == "authorTeam") {
725
          $dump = $reference->$fieldname;
726
          $teammembers = "teamMembers";
727
          $team = $dump->$teammembers;
728
          $nameArray = array();
729
730
          foreach ($team as $member) {
731
            if (strlen($member->lastname) > 0) {
732
              $nname = $member->lastname;
733
              $name = $nname;
734
              if (strlen($member->firstname) > 0) {
735
                $vname = $member->firstname;
736
                $name = $vname . " " . $nname;
737
              }
738
              $nameArray[] = $name;
739
            }
740
            else {
741
              if (strlen($member->titleCache) > 0) {
742
                $nameArray[] = $member->titleCache;
743
              }
744
            }
745
          }
746
          $value = join($nameArray, ", ");
747
        }
748
        elseif ($fieldname == "inReference") {
749
          $type = $reference->$fieldname->type;
750
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
751
          switch ($type) {
752
            case "Book":
753
              $fieldname = "in book";
754
              break;
755
            case "Journal":
756
              $fieldname = "in journal";
757
              break;
758
            case "Proceedings":
759
              $fieldname = "in proceedings";
760
              break;
761
          }
762
        }
763
        else {
764
          $value = $reference->$fieldname->titleCache;
765
        }
766
        if (isset($value) && $value != '') {
767
          $table_rows[] = array(
768
            t(ucfirst(strtolower($fieldname))),
769
            $value,
770
          );
771
        }
772
      }
773
      else {
774
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
775
          $table_rows[] = array(
776
            t(ucfirst(strtolower($fieldname))),
777
            $reference->$fieldname,
778
          );
779
        }
780
      }
781
    }
782
  }
783
784
  $out = theme_table(array(
785
      'header' => array(),
786
      'rows' => $table_rows,
787
      'attributes' => array(),
788
      'caption' => NULL,
789
      'colgroups' => NULL,
790
      'sticky' => NULL,
791
     'empty' => NULL,
792
  ));
793
794
  // Annotations below the table.
795
  $annotations = cdm_ws_getAnnotationsFor($reference);
796
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
797
798
  return $out;
799
}
800
801
/**
802
 * @todo Please document this function.
803
 * @see http://drupal.org/node/1354
804
 */
805
function theme_cdm_media_page($variables) {
806
  $media = $variables['media'];
807
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
808
  $partId = $variables['partId'];
809
  $out = '';
810
  // Determine which reprresentation and which part to show.
811
  $representationIdx = 0;
812
  if ($mediarepresentation_uuid) {
813
    $i = 0;
814
    foreach ($media->representations as $representation) {
815
      if ($representation->uuid == $mediarepresentation_uuid) {
816
        $representationIdx = $i;
817
      }
818
      $i++;
819
    }
820
  }
821
  else {
822
    $mediarepresentation_uuid = $media->representations[0]->uuid;
823
  }
824
825
  $partIdx = 0;
826
  if (!is_numeric($partId)) {
827
    // Assuming it is an uuid.
828
    $i = 0;
829
    foreach ($media->representations[$representationIdx]->parts as $part) {
830
      if ($part->uuid == $partId) {
831
        $partIdx = $i;
832
      }
833
      $i++;
834
    }
835
  }
836
  else {
837
    // Assuming it is an index.
838
    $partIdx = $partId;
839
  }
840
841
  $media_metadata = cdm_read_media_metadata($media);
842
  // $title = $media->titleCache;
843
  $title = $media_metadata['title'];
844
845
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
846
847
  if (!$title) {
848
    $title = 'Media ' . $media->uuid . '';
849
  }
850
851
  drupal_set_title($title, PASS_THROUGH);
852
853
  $out .= '<div class="media cdm_media_viewer_image">';
854
855
  $out .= theme('cdm_back_to_image_gallery_button', array());
856
  $out .= '<div class="viewer">';
857
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
858
  $out .= '</div>';
859
860
  // General media metadata.
861
  /*
862
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
863
  vardump("PRINTING MEDIA METADATA");
864
  vardump($media_metadata);
865
  vardump("PRINTING MEDIA");
866
  vardump($media);
867
  */
868
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
869
  $out .= $metadataToPrint;
870
871
  // Tabs for the different representations.
872
  // ul.secondary
873
  $out .= '<ul class="primary">';
874
  foreach ($media->representations as $representation) {
875
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
876
  }
877
  $out .= '</ul>';
878
879
  // Representation(-part) specific metadata.
880
  $thumbnailMaxExtend = 100;
881
  $out .= '<table>';
882
  $i = 0;
883
  foreach ($media->representations[$representationIdx]->parts as $part) {
884
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
885
    switch ($part->class) {
886
      case 'ImageFile':
887
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
888
        break;
889
      case 'AudioFile':
890
      case 'MovieFile':
891
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
892
        break;
893
      default:
894
        $out .= $part->size . 'k';
895
    }
896
897
    $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));
898
    $i++;
899
  }
900
  $out .= '</table>';
901
  $out .= '</div>';
902
903
  return $out;
904
}
905
906
/**
907
 * @todo Please document this function.
908
 * @see http://drupal.org/node/1354
909
 */
910
function theme_cdm_polytomousKey_page($variables) {
911
  $polytomousKey = $variables['polytomousKey'];
912
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
913
914
  $out = theme("cdm_IdentificationKey", array(
915
    'identificationKey' => $polytomousKey,
916
    'doLinkToKeyPage' => FALSE,
917
    'showIdentificationKeyTitle' => FALSE,
918
    ));
919
920
  // Key nodes in linked style.
921
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
922
  /*
923
  FIXME implement node type for keys !!! (wrapping the content in the
924
  cdm_dataportal.node becomes obsolete then).
925
  */
926
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
927
}
928
929
/**
930
 * Returns HTML for taxon page tabs.
931
 *
932
 * Allows theming of the taxon page tabs.
933
 *
934
 * @param array $variables
935
 *   An associative array containing:
936
 *   - tabname
937
 *
938
 * @ingroup themeable
939
 */
940
function theme_cdm_taxonpage_tab($variables) {
941
  $tabname = $variables['tabname'];
942
  // TODO replace by using translations or theme the menue tabs itself instead?
943
  switch ($tabname) {
944
    default:
945
      return t($tabname);
946
  }
947
}