Project

General

Profile

Download (26.3 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
  RenderHints::pushToRenderStack('taxon_page_title');
30
  $referenceUri = '';
31
  $out = '';
32
  if (isset($taxon->name->nomenclaturalReference)) {
33
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
34
  }
35

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

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

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

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

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

    
99
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
100
  $http_request_params = drupal_get_query_parameters();
101

    
102
  // add all mandatory js sources
103
  _add_js_footnotes();
104

    
105

    
106
  $render_array = array();
107
  $weight = 0; // the weight for the render array elements
108

    
109
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
110

    
111
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
112

    
113
  $media = _load_media_for_taxon($taxon);
114

    
115

    
116
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
117
    taxon_page_tabs_hidden('images');
118
  }
119

    
120
  // --- GET specimensOrObservations --- //
121
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
122

    
123
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
124
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
125
    taxon_page_tabs_hidden('specimens');
126
  }
127

    
128
  // --- GET polytomousKeys --- //
129
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
130
  $identificationKeyCount = 0;
131
  if ($polytomousKeysPager) {
132
    $identificationKeyCount += $polytomousKeysPager->count;
133
  }
134
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
135
    taxon_page_tabs_hidden('keys');
136
  }
137

    
138
  if ($tabsToDisplay["Synonymy"] == '0') {
139
    taxon_page_tabs_hidden('synonymy');
140
  }
141

    
142
  // -------------------------------------------- //
143

    
144
  $render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), -103);
145

    
146
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
147
      $render_array['accepted_for'] = markup_to_render_array(theme('cdm_acceptedFor', array('acceptedFor' => $_REQUEST['acceptedFor'])), $weight++);
148
  }
149

    
150
  // --- PAGE PART: DESCRIPTION --- //
151
  if ($page_part == 'description' || $page_part == 'all') {
152

    
153
    $merged_tree = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $taxon->uuid);
154

    
155
    $render_array['profile'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media);
156
    $render_array['profile']['#weight'] = $weight++;
157
    $render_array['profile']['#prefix'] = '<div id="general">';
158
    $render_array['profile']['#suffix'] = '</div>';
159
    $toc_elements['profile'] = l(t('General'), $_GET['q'], array('fragment' => 'general', 'query' => $http_request_params));
160
  }
161

    
162
  // --- PAGE PART: IMAGES --- //
163
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
164
    $images_html = '<div id="images">';
165
    if ($page_part == 'all') {
166
      $images_html .= '<h2>' . t('Images') . '</h2>';
167
    }
168
    // Get the image gallery as configured by the admin.
169
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
170
      $taxon,
171
      $media,
172
    ));
173
    $images_html .= $taxon_image_gallery;
174
    $images_html .= '</div>';
175
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
176
    $toc_elements['images'] = l(t('Images'), $_GET['q'], array('fragment' => 'images', 'query' => $http_request_params));
177
  }
178

    
179
  // --- PAGE PART: SYNONYMY --- //
180
  if (($page_part == 'synonymy' || $page_part == 'all')) {
181
    $synonymy_html = '<div id="synonymy">';
182
    if ($page_part == 'all') {
183
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
184
    }
185
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
186
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
187

    
188
    $synonymy_html .= '</div>';
189
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
190
    $toc_elements['synonymy'] = l(t('Synonymy'), $_GET['q'], array('fragment' => 'synonymy', 'query' => $http_request_params));
191
  }
192

    
193
  // --- PAGE PART: SPECIMENS --- //
194
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
195
    $render_array['specimens'] = array(
196
        '#prefix' => '<div id="specimens">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
197
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
198
        '#suffix' => '</div>',
199
    );
200
    $toc_elements['specimens'] = l(t('Specimens'), $_GET['q'], array('fragment' => 'specimens', 'query' => $http_request_params));
201
  }
202

    
203
  // --- PAGE PART: KEYS --- //
204
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
205
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
206
  }
207
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
208
    $keys_html = '<div id="keys">';
209
    if ($page_part == 'all') {
210
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
211
    }
212
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
213
    $keys_html .= '</div>';
214
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
215
    $toc_elements['keys'] = l(t('Keys'), $_GET['q'], array('fragment' => 'keys', 'query' => $http_request_params));
216
  }
217

    
218

    
219
  if($page_part == 'all') {
220
    if(isset($render_array['profile'])) {
221
      // in case all tabs are shown at once the feature tocs
222
      // should be integrated into the tabs toc as sub list
223
      // and the profile image should be on top of the page
224
      if(isset($render_array['profile']['taxon_description_feature_toc'])){
225
//         $toc_elements['profile'] = array(
226
//             'data' => $toc_elements['profile'],
227
//             'children' => $render_array['profile']['taxon_description_feature_toc']['items']
228
//         );
229
        $toc_elements = array_merge($render_array['profile']['taxon_description_feature_toc']['#items'], $toc_elements);
230
        unset($toc_elements['profile']);
231
        unset($render_array['profile']['taxon_description_feature_toc']);
232
      }
233
      if($render_array['profile']['taxon_profile_image']){
234
        $render_array['profile_image'] = $render_array['profile']['taxon_profile_image'];
235
        $render_array['profile_image']['#weight'] = -100;
236
        unset($render_array['profile']['taxon_profile_image']);
237
      }
238
    }
239

    
240
    // finally add the table of contents to the render array
241
    $render_array['toc'] = array(
242
        '#theme' => 'item_list',
243
        '#items' => $toc_elements,
244
        '#title' => t('Content'),
245
        '#weight' => -101,
246
        '#suffix' => '</div>',
247
        '#prefix'=> '<div id="featureTOC">' // reusing id featureTOC even if this is semantically not correct
248
    );
249
  }
250
  return $render_array;
251
}
252

    
253

    
254

    
255

    
256
/**
257
 * Returns HTML containing the synonymy for the accepted taxon.
258
 *
259
 * Shows the whole synonymy for the accepted taxon.
260
 * The synonymy list is headed by the complete scientific name
261
 * of the accepted taxon with nomenclatural reference.
262
 *
263
 * @param array $variables
264
 *   An associative array containing:
265
 *   - taxon
266
 *   - addAcceptedTaxon
267
 *
268
 * @ingroup themeable
269
 */
270
function theme_cdm_taxon_page_synonymy($variables) {
271
  $taxon = $variables['taxon'];
272
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
273

    
274
  RenderHints::pushToRenderStack('taxon_page_synonymy');
275

    
276
  // footnote key for the homotypic group and accepted taxon,
277
  // both should have the same footnote key
278
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
279

    
280
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
281
  $skip = array(
282
    UUID_BASIONYM,
283
  );
284
  $out = '';
285

    
286
  // Render accepted taxon.
287
  //
288
  // foonotes of the accepted taxon will be rendered in the homotypic group section
289
  // even if there are not synonyms in the homotypic group
290
  // homotypic group and accepted taxon should have the same footnote key
291
  $referenceUri = '';
292
  if ($addAcceptedTaxon) {
293
    if (isset($taxon->name->nomenclaturalReference)) {
294
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
295
    }
296

    
297
    $accepted_name = '<span class="accepted-name">';
298
    $accepted_name .= theme('cdm_taxonName', array(
299
      'taxonName' => $taxon->name,
300
      'nameLink' => NULL,
301
      'refenceLink' => $referenceUri,
302
      ));
303
    $accepted_name .= '</span>';
304

    
305
    // handle annotations of the name and taxon
306
    $special_annotations_array = array();
307
    $special_annotations_array[] = $taxon->name;
308
    $special_annotations_array[] = $taxon;
309
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
310
        'cdmBase_list' => $special_annotations_array,
311
        'footnote_list_key' => RenderHints::getRenderPath() . '-annotations')
312
      );
313
  }
314

    
315
  // --- Render homotypic synonymy group
316
  if (!empty($accepted_name)) {
317
    $out .= $accepted_name;
318
  }
319

    
320
  // Render the homotypicSynonymyGroup including the type information.
321
  $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
322

    
323

    
324
  // Render accepted taxon heterotypic synonymy groups.
325
  if ($synomymie->heterotypicSynonymyGroups) {
326
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
327
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
328
    }
329
  }
330
  // Render taxon relationships.
331
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
332
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
333
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
334
  }
335
  // Render name relationships.
336
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
337
  $skip = array();
338
  if ($name_rels_to_show) {
339
    foreach ($name_rels_to_show as $key => $value) {
340
      if ($value === 0) {
341
        $skip[] = $key;
342
      }
343
    }
344
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
345
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
346
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
347
    }
348
  }
349

    
350
  RenderHints::popFromRenderStack();
351

    
352
  return $out;
353
}
354

    
355

    
356
/**
357
 * Returns HTML for the given result page including a pager.
358
 *
359
 * @param array $variables
360
 *   An associative array containing:
361
 *   - pager: The cdmlib pager object containing the result set of cdm base
362
 *     objects (currently this function can only handle taxon instances =>
363
 *     TODO)
364
 *   - path: The target path for the pager links, this will usually point to
365
 *     'cdm_dataportal/search/results/taxon'
366
 *
367
 * @ingroup themeable
368
 */
369
function theme_cdm_search_results($variables) {
370
  $pager = $variables['pager'];
371
  $path = $variables['path'];
372

    
373
  $freetextSearchResults = array();
374

    
375
  // If the pager contains records of SearchResults, extract the taxa and use
376
  // them as records instead.
377
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
378
    $freetextSearchResults = $pager->records;
379
    $taxa = array();
380
    // $highlightedFragments = array();
381
    foreach ($pager->records as $searchResult) {
382
      $taxa[] = &$searchResult->entity;
383
      /*
384
       if(!isset($searchResult->fieldHighlightMap)){
385
      $searchResult->fieldHighlightMap = NULL;
386
      }
387
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
388
      */
389
    }
390
    $pager->records = $taxa;
391
  }
392

    
393
  $out = '';
394
  // Add thumbnails checkbox and refine search link.
395
  $out = '<div class="page_options">';
396
  if (isset($_REQUEST['ws'])) {
397
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
398
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
399
    }
400
  }
401
  $out .= '<form name="pageoptions"><div id="showThumbnails"><input type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Show Thumbnails') . '</div></form>';
402
  $out .= '</div>';
403
  $out .= '<div id="search-summary">' . t('results for') . ' ';
404
  $classification = cdm_dataportal_searched_in_classification();
405
  if ($classification != NULL) {
406
    $out .=  $classification->titleCache ;
407
  } else {
408
   $out .= t('any classification');
409
  }
410
  $out .= ':</div>';
411

    
412
  // List results.
413
  if (isset($pager->records) && count($pager->records) > 0) {
414
    $out .= '<div id="search_results">';
415
    $out .= theme('cdm_list_of_taxa',
416
        array(
417
          'records' => $pager->records,
418
          'freetextSearchResults' => $freetextSearchResults,
419
          'show_classification' => $classification === NULL
420
        )
421
      );
422
    $out .= '</div>';
423
    $out .= theme('cdm_pager', array(
424
        'pager' => $pager,
425
        'path' => $path,
426
        'parameters' => $_REQUEST,
427
    ));
428
  }
429
  else {
430
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
431
  }
432
  return $out;
433
}
434

    
435

    
436
/**
437
 * TODO Implementation of Hook taxon_image_gallery()
438
 *
439
 * @param unknown_type $taxon
440
 * @param unknown_type $media
441
 *
442
 * @return unknown_type
443
 */
444
function taxon_image_gallery_default($taxon, $media) {
445
  $hasImages = isset($media[0]);
446

    
447
  if ($hasImages) {
448

    
449
    $maxExtend = 150;
450
    $cols = 3;
451
    $maxRows = FALSE;
452
    $alternativeMediaUri = NULL;
453
    /* Comment @WA: was in D5:
454
    $captionElements = array(
455
      'title',
456
      'rights',
457
      '#uri' => t('open Image'),
458
    );
459
    */
460
    $captionElements = array(
461
      'title',
462
      'description',
463
      'artist',
464
      'location',
465
      'rights',
466
      '#uri' => t('open Image'),
467
    );
468
    $gallery_name = $taxon->uuid;
469
    $mediaLinkType = 'LIGHTBOX';
470

    
471
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
472

    
473
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
474

    
475
    $out = '<div class="image-gallerie">';
476
    $out .= theme('cdm_media_gallerie', array(
477
      'mediaList' => $media,
478
      'galleryName' => $gallery_name,
479
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
480
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
481
      'maxRows' => 0, // Ignore maxrows settings.
482
      'captionElements' => $captionElements,
483
      'mediaLinkType' => $mediaLinkType,
484
      'alternativeMediaUri' => NULL,
485
      'galleryLinkUri' => NULL,
486
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
487
    ));
488
    $out .= '</div>';
489
  }
490
  else {
491
    $out = 'No images available.';
492
  }
493
  return $out;
494
}
495

    
496
/**
497
 * TODO Implementation of Hook taxon_image_gallery()
498
 *
499
 * @param unknown_type $taxon
500
 * @param unknown_type $media
501
 *
502
 * @return unknown_type
503
 */
504
function taxon_image_gallery_fsi($taxon, $media) {
505
  $flashLink = isset($media[0]);
506

    
507
  if ($flashLink) {
508

    
509
    if (module_exists("fsi_gallery")) {
510
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
511
    }
512
    else {
513
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
514
      drupal_set_message($message, "error");
515
      $out = '<h3>' . $message . '</h3>';
516
    }
517
  }
518
  else {
519
    $out = 'No images available.';
520
  }
521
  return $out;
522
}
523

    
524
/**
525
 * Returns HTML for a single reference page.
526
 *
527
 * Renders a page with all data on a single reference.
528
 *
529
 * @param array $variables
530
 *   An associative array containing:
531
 *   - reference: Object.
532
 *
533
 * @ingroup themeable
534
 */
535
function theme_cdm_reference_page($variables) {
536
  $reference = $variables['reference'];
537

    
538
  $out = '';
539

    
540
  if (isset($reference->titleCache)) {
541
    drupal_set_title($reference->titleCache, PASS_THROUGH);
542
  }
543

    
544
  $field_order = array(
545
    "title",
546
    // "titleCache",
547
    // "citation",
548
    "authorTeam",
549
    "editor",
550
    "publisher",
551
    "placePublished",
552
    "datePublished",
553
    "year",
554
    "edition",// Class Book.
555
    "volume",// Class Article.
556
    "seriesPart",
557
    "inReference",
558
    "nomRefBase", // Class BookSection, Book, Article.
559
    "pages",// Class Article.
560
    "series",// Class Article, PrintSeries.
561
    "school",// Class Thesis.
562
    "institution",// Class Report.
563
    "organization",// Class Proceedings.
564
    "nextVersion",
565
    "previousVersion",
566
    "isbn",// Class Book.
567
    "issn",// Class Journal.
568
    "uri",
569
  );
570

    
571
  $header = array(
572
    t('Field'),
573
    t('Value'),
574
  );
575
  $table_rows = array();
576

    
577
  if (!isset($reference->authorTeam)) {
578
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
579
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
580
  }
581

    
582
  if (!isset($reference->inReference)) {
583
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
584
      $reference->uuid,
585
      "inReference",
586
    ));
587
  }
588

    
589
  foreach ($field_order as $fieldname) {
590

    
591
    if (isset($reference->$fieldname)) {
592

    
593
      if ($fieldname == "datePublished") {
594
        $period = $reference->$fieldname;
595
        $datePublished = timePeriodToString($period);
596
        if (isset($datePublished) && $datePublished != '') {
597
          $table_rows[] = array(
598
            t(ucfirst(strtolower($fieldname))),
599
            $datePublished,
600
          );
601
        }
602
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
603
        // $datePublished);
604
      }
605
      elseif (is_object($reference->$fieldname)) {
606
        if ($fieldname == "authorTeam") {
607
          $dump = $reference->$fieldname;
608
          $teammembers = "teamMembers";
609
          $team = $dump->$teammembers;
610
          $nameArray = array();
611

    
612
          foreach ($team as $member) {
613
            if (strlen($member->lastname) > 0) {
614
              $nname = $member->lastname;
615
              $name = $nname;
616
              if (strlen($member->firstname) > 0) {
617
                $vname = $member->firstname;
618
                $name = $vname . " " . $nname;
619
              }
620
              $nameArray[] = $name;
621
            }
622
            else {
623
              if (strlen($member->titleCache) > 0) {
624
                $nameArray[] = $member->titleCache;
625
              }
626
            }
627
          }
628
          $value = join($nameArray, ", ");
629
        }
630
        elseif ($fieldname == "inReference") {
631
          $type = $reference->$fieldname->type;
632
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
633
          switch ($type) {
634
            case "Book":
635
              $fieldname = "in book";
636
              break;
637
            case "Journal":
638
              $fieldname = "in journal";
639
              break;
640
            case "Proceedings":
641
              $fieldname = "in proceedings";
642
              break;
643
          }
644
        }
645
        else {
646
          $value = $reference->$fieldname->titleCache;
647
        }
648
        if (isset($value) && $value != '') {
649
          $table_rows[] = array(
650
            t(ucfirst(strtolower($fieldname))),
651
            $value,
652
          );
653
        }
654
      }
655
      else {
656
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
657
          $table_rows[] = array(
658
            t(ucfirst(strtolower($fieldname))),
659
            $reference->$fieldname,
660
          );
661
        }
662
      }
663
    }
664
  }
665

    
666
  $out = theme_table(array(
667
      'header' => array(),
668
      'rows' => $table_rows,
669
      'attributes' => array(),
670
      'caption' => NULL,
671
      'colgroups' => NULL,
672
      'sticky' => NULL,
673
     'empty' => NULL,
674
  ));
675

    
676
  // Annotations below the table.
677
  $annotations = cdm_ws_getAnnotationsFor($reference);
678
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
679

    
680
  return $out;
681
}
682

    
683
/**
684
 * @todo Please document this function.
685
 * @see http://drupal.org/node/1354
686
 */
687
function theme_cdm_media_page($variables) {
688
  $media = $variables['media'];
689
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
690
  $partId = $variables['partId'];
691
  $out = '';
692
  // Determine which reprresentation and which part to show.
693
  $representationIdx = 0;
694
  if ($mediarepresentation_uuid) {
695
    $i = 0;
696
    foreach ($media->representations as $representation) {
697
      if ($representation->uuid == $mediarepresentation_uuid) {
698
        $representationIdx = $i;
699
      }
700
      $i++;
701
    }
702
  }
703
  else {
704
    $mediarepresentation_uuid = $media->representations[0]->uuid;
705
  }
706

    
707
  $partIdx = 0;
708
  if (!is_numeric($partId)) {
709
    // Assuming it is an uuid.
710
    $i = 0;
711
    foreach ($media->representations[$representationIdx]->parts as $part) {
712
      if ($part->uuid == $partId) {
713
        $partIdx = $i;
714
      }
715
      $i++;
716
    }
717
  }
718
  else {
719
    // Assuming it is an index.
720
    $partIdx = $partId;
721
  }
722

    
723
  $media_metadata = cdm_read_media_metadata($media);
724
  // $title = $media->titleCache;
725
  $title = $media_metadata['title'];
726

    
727
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
728

    
729
  if (!$title) {
730
    $title = 'Media ' . $media->uuid . '';
731
  }
732

    
733
  drupal_set_title($title, PASS_THROUGH);
734

    
735
  $out .= '<div class="media cdm_media_viewer_image">';
736

    
737
  $out .= theme('cdm_back_to_image_gallery_button', array());
738
  $out .= '<div class="viewer">';
739
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
740
  $out .= '</div>';
741

    
742
  // General media metadata.
743
  /*
744
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
745
  vardump("PRINTING MEDIA METADATA");
746
  vardump($media_metadata);
747
  vardump("PRINTING MEDIA");
748
  vardump($media);
749
  */
750
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
751
  $out .= $metadataToPrint;
752

    
753
  // Tabs for the different representations.
754
  // ul.secondary
755
  $out .= '<ul class="primary">';
756
  foreach ($media->representations as $representation) {
757
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
758
  }
759
  $out .= '</ul>';
760

    
761
  // Representation(-part) specific metadata.
762
  $thumbnailMaxExtend = 100;
763
  $out .= '<table>';
764
  $i = 0;
765
  foreach ($media->representations[$representationIdx]->parts as $part) {
766
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
767
    switch ($part->class) {
768
      case 'ImageFile':
769
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
770
        break;
771
      case 'AudioFile':
772
      case 'MovieFile':
773
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
774
        break;
775
      default:
776
        $out .= $part->size . 'k';
777
    }
778

    
779
    $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));
780
    $i++;
781
  }
782
  $out .= '</table>';
783
  $out .= '</div>';
784

    
785
  return $out;
786
}
787

    
788
/**
789
 * @todo Please document this function.
790
 * @see http://drupal.org/node/1354
791
 */
792
function theme_cdm_polytomousKey_page($variables) {
793
  $polytomousKey = $variables['polytomousKey'];
794
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
795

    
796
  $out = theme("cdm_IdentificationKey", array(
797
    'identificationKey' => $polytomousKey,
798
    'doLinkToKeyPage' => FALSE,
799
    'showIdentificationKeyTitle' => FALSE,
800
    ));
801

    
802
  // Key nodes in linked style.
803
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
804
  /*
805
   * FIXME implement node type for keys !!!
806
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
807
   */
808
  return '<div id="identificationKey">' . $out . '</div>';
809
}
810

    
811
/**
812
 * Returns HTML for taxon page tabs.
813
 *
814
 * Allows theming of the taxon page tabs.
815
 *
816
 * @param array $variables
817
 *   An associative array containing:
818
 *   - tabname
819
 *
820
 * @ingroup themeable
821
 */
822
function theme_cdm_taxonpage_tab($variables) {
823
  $tabname = $variables['tabname'];
824
  // TODO replace by using translations or theme the menue tabs itself instead?
825
  switch ($tabname) {
826
    default:
827
      return t($tabname);
828
  }
829
}
(7-7/10)