Project

General

Profile

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

    
16
/**
17
 * Returns HTML for the default title of a taxon page.
18
 *  * The returned title is a formatted taxon name.
19
 *
20
 * @param array $variables
21
 *   An associative array containing:
22
 *   - taxon: The taxon name being formatted for the title.
23
 *   - uuid: UUID for the taxon.
24
 *
25
 * @ingroup themeable
26
 */
27
function theme_cdm_taxon_page_title($variables) {
28
  $taxon = $variables['taxon'];
29
  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

    
96
  // add all mandatory js sources
97
  _add_js_footnotes();
98

    
99
  $taxon = $variables['taxon'];
100
  $page_part = $variables['page_part'];
101
  global $theme;
102

    
103
  $render_array = array();
104
  $weight = 0; // the weight for the render array elements
105

    
106
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
107

    
108
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
109

    
110
  $media = _load_media_for_taxon($taxon);
111

    
112

    
113
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
114
    taxon_page_tabs_hidden('images');
115
  }
116

    
117
  // HideImage flag depending on administative preset.
118
  $hideImages = FALSE;
119
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
120
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
121
    $hideImages = ($rankCompare > -1);
122
  }
123

    
124
  // --- GET specimensOrObservations --- //
125
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
126

    
127
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
128
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
129
    taxon_page_tabs_hidden('specimens');
130
  }
131

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

    
142
  if ($tabsToDisplay["Synonymy"] == '0') {
143
    taxon_page_tabs_hidden('synonymy');
144
  }
145

    
146
  // -------------------------------------------- //
147

    
148
  $render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), $weight++);
149

    
150
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
151
      $render_array['accepted_for'] = markup_to_render_array(theme('cdm_acceptedFor', array('acceptedFor' => $_REQUEST['acceptedFor'])), $weight++);
152
  }
153

    
154
  // --- PAGE PART: DESCRIPTION --- //
155
  if ($page_part == 'description' || $page_part == 'all') {
156

    
157
    $markerTypesEmpty = array();
158
    $markerTypesEmpty['markerTypes'] = '';
159
    $queryString = $markerTypesEmpty['markerTypes'] ? queryString($markerTypesEmpty) : '';
160
    // Retrieve all descriptions for the taxon.
161
    $taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid, $queryString);
162

    
163
    $nonStructuredDescriptions = array();
164
    if ($taxonDescriptions != NULL) {
165
      foreach ($taxonDescriptions as $taxonDescription) {
166
        // Check if structured description.
167
        $hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
168
        if (isset($hasStructuredData->Boolean)) {
169
          $hasStructuredData = $hasStructuredData->Boolean == 'TRUE';
170
        }
171
        if ($hasStructuredData) {
172
          $structured_description_featuretree_uuid = variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, FALSE);
173
          if($structured_description_featuretree_uuid) {
174
            // if a feature tree for natural language generation has been defined use it,
175
            // otherwise natural language generation is skipped
176
            $naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array(
177
              $taxonDescription->uuid,
178
              $structured_description_featuretree_uuid,
179
            ));
180

    
181
            if (!isset($naturallanguage_textData)) {
182
              drupal_set_message(
183
                t(
184
                "The 'FeatureTree' for the generation of natural language representations is not configured correctly,"
185
                ." please select a 'FeatureTree' in the !settings",
186
                array(
187
                  '!settings' => l(t('CDM Dataportal Settings'), 'admin/config/cdm_dataportal/layout/taxon'))
188
                  ),
189
                'warning');
190
            } else {
191
              $taxonDescription->elements = NULL;
192
              $taxonDescription->elements = array(
193
                $naturallanguage_textData,
194
              );
195
            }
196
          }
197
        }
198
        $nonStructuredDescriptions[] = $taxonDescription;
199
      }
200
      // Release memory.
201
      $taxonDescriptions = NULL;
202
    }
203

    
204
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
205

    
206
    $profile_html = '<div id="general">';
207
    $profile_html .= theme('cdm_taxon_page_profile', array(
208
      'taxon' => $taxon,
209
      'mergedTrees' => $mergedTrees,
210
      'media' => $media,
211
      'hideImages' => $hideImages,
212
      ));
213
    $profile_html .= '</div>';
214
    $render_array['profile'] = markup_to_render_array($profile_html, $weight++);
215
  }
216

    
217
  // --- PAGE PART: IMAGES --- //
218
  if ((!$hideImages && $page_part == 'images' || $page_part == 'all')) {
219
    $images_html = '<div id="images">';
220
    if ($page_part == 'all') {
221
      $images_html .= '<h2>' . t('Images') . '</h2>';
222
    }
223
    // Get the image gallery as configured by the admin.
224
    $taxon_image_gallery = call_user_func_array('taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'), array(
225
      $taxon,
226
      $media,
227
    ));
228
    $images_html .= $taxon_image_gallery;
229
    $images_html .= '</div>';
230
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
231
  }
232

    
233
  // --- PAGE PART: SYNONYMY --- //
234
  if (($page_part == 'synonymy' || $page_part == 'all')) {
235
    $synonymy_html = '<div id="synonymy">';
236
    if ($page_part == 'all') {
237
      $synonymy_html .= '<h2>' . t('Synonymy') . '</h2>';
238
    }
239
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
240
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
241

    
242
    $synonymy_html .= '</div>';
243
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
244
  }
245

    
246
  // --- PAGE PART: SPECIMENS --- //
247
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
248
    $render_array['specimens'] = array(
249
        '#prefix' => '<div id="specimens">' . ($page_part == 'all' ? '<h2>' . t('Specimens') . '</h2>' : ''),
250
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
251
        '#suffix' => '</div>',
252
    );
253
  }
254

    
255
  // --- PAGE PART: KEYS --- //
256
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
257
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
258
  }
259
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
260
    $keys_html = '<div id="keys">';
261
    if ($page_part == 'all') {
262
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
263
    }
264
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
265
    $keys_html .= '</div>';
266
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
267
  }
268

    
269
  return $render_array;
270
}
271

    
272
/**
273
 * Returns HTML containing descriptive data and preferred picture.
274
 *
275
 * Outputs all descriptive data and shows the preferred picture of the
276
 * accepted taxon.
277
 *
278
 * @param array $variables
279
 *   An associative array containing:
280
 *   - taxon
281
 *   - mergedTrees
282
 *   - media:
283
 *   - hideImages
284
 *
285
 * @ingroup themeable
286
 */
287
function theme_cdm_taxon_page_profile($variables) {
288
  $taxon = $variables['taxon'];
289
  $mergedTrees = $variables['mergedTrees'];
290
  $media = $variables['media'];
291
  $hideImages = $variables['hideImages'];
292
  $out = '';
293

    
294
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
295
  if ($taxon_profile_image_settings['show'] && !$hideImages) {
296

    
297
    $representationPart = new stdClass();
298
    $attributes = array();
299
    if (isset($media[0]->representations[0]->parts[0])) {
300
      $representationPart = $media[0]->representations[0]->parts[0];
301
      $attributes['alt'] = $representationPart->uri;
302

    
303
      if(!empty($taxon_profile_image_settings['media_uri_query'])){
304
        $representationPart->uri = $representationPart->uri
305
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
306
            . $taxon_profile_image_settings['media_uri_query'];
307
      }
308
    }
309
    else {
310
      // show placeholder image instead
311
      if(!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])){
312
        // use the user provided image
313
        $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
314
        $url = file_create_url($profile_image_file->uri);
315
        $image_info = image_get_info($profile_image_file->uri);
316
        $representationPart->width = $image_info['width'];
317
        $representationPart->height = $image_info['height'];
318
        $representationPart->uri = $url;
319
      } else {
320
        // use the hard coded default
321
        $representationPart->width = 184;
322
        $representationPart->height = 144;
323
        $representationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
324
      }
325
      $attributes['alt'] = "no image available";
326
    }
327

    
328
    $profile_image = theme('cdm_media_gallerie_image', array(
329
        'mediaRepresentationPart' => $representationPart,
330
        'maxExtend' => $taxon_profile_image_settings['maxextend'],
331
        'addPassePartout' => FALSE,
332
        'attributes' => $attributes,
333
    ));
334
    // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
335
    $out .= '<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image. '</div>';
336
  }
337

    
338
  // Description TOC.
339
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
340

    
341
  // Description.
342
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
343

    
344
  return $out;
345
}
346

    
347

    
348

    
349
/**
350
 * Returns HTML containing the synonymy for the accepted taxon.
351
 *
352
 * Shows the whole synonymy for the accepted taxon.
353
 * The synonymy list is headed by the complete scientific name
354
 * of the accepted taxon with nomenclatural reference.
355
 *
356
 * @param array $variables
357
 *   An associative array containing:
358
 *   - taxon
359
 *   - addAcceptedTaxon
360
 *
361
 * @ingroup themeable
362
 */
363
function theme_cdm_taxon_page_synonymy($variables) {
364
  $taxon = $variables['taxon'];
365
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
366

    
367
  RenderHints::pushToRenderStack('taxon_page_synonymy');
368

    
369
  // footnote key for the homotypic group and accepted taxon,
370
  // both should have the same footnote key
371
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
372

    
373
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
374
  $skip = array(
375
    UUID_BASIONYM,
376
  );
377
  $out = '';
378

    
379
  // Render accepted taxon.
380
  //
381
  // foonotes of the accepted taxon will be rendered in the homotypic group section
382
  // even if there are not synonyms in the homotypic group
383
  // homotypic group and accepted taxon should have the same footnote key
384
  $referenceUri = '';
385
  if ($addAcceptedTaxon) {
386
    if (isset($taxon->name->nomenclaturalReference)) {
387
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
388
    }
389

    
390
    $accepted_name = '<span class="accepted-name">';
391
    $accepted_name .= theme('cdm_taxonName', array(
392
      'taxonName' => $taxon->name,
393
      'nameLink' => NULL,
394
      'refenceLink' => $referenceUri,
395
      ));
396
    $accepted_name .= '</span>';
397

    
398
    // handle annotations of the name and taxon
399
    $special_annotations_array = array();
400
    $special_annotations_array[] = $taxon->name;
401
    $special_annotations_array[] = $taxon;
402
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
403
        'cdmBase_list' => $special_annotations_array,
404
        'footnote_list_key' => RenderHints::getRenderPath() . '-annotations')
405
      );
406
  }
407

    
408
  // --- Render homotypic synonymy group
409
  if (!empty($accepted_name)) {
410
    $out .= $accepted_name;
411
  }
412

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

    
416

    
417
  // Render accepted taxon heterotypic synonymy groups.
418
  if ($synomymie->heterotypicSynonymyGroups) {
419
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
420
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
421
    }
422
  }
423
  // Render taxon relationships.
424
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
425
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
426
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
427
  }
428
  // Render name relationships.
429
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
430
  $skip = array();
431
  if ($name_rels_to_show) {
432
    foreach ($name_rels_to_show as $key => $value) {
433
      if ($value === 0) {
434
        $skip[] = $key;
435
      }
436
    }
437
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
438
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
439
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
440
    }
441
  }
442

    
443
  RenderHints::popFromRenderStack();
444

    
445
  return $out;
446
}
447

    
448

    
449
/**
450
 * Returns HTML for the given result page including a pager.
451
 *
452
 * @param array $variables
453
 *   An associative array containing:
454
 *   - pager: The cdmlib pager object containing the result set of cdm base
455
 *     objects (currently this function can only handle taxon instances =>
456
 *     TODO)
457
 *   - path: The target path for the pager links, this will usually point to
458
 *     'cdm_dataportal/search/results/taxon'
459
 *
460
 * @ingroup themeable
461
 */
462
function theme_cdm_search_results($variables) {
463
  $pager = $variables['pager'];
464
  $path = $variables['path'];
465

    
466
  $freetextSearchResults = array();
467

    
468
  // If the pager contains records of SearchResults, extract the taxa and use
469
  // them as records instead.
470
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
471
    $freetextSearchResults = $pager->records;
472
    $taxa = array();
473
    // $highlightedFragments = array();
474
    foreach ($pager->records as $searchResult) {
475
      $taxa[] = &$searchResult->entity;
476
      /*
477
       if(!isset($searchResult->fieldHighlightMap)){
478
      $searchResult->fieldHighlightMap = NULL;
479
      }
480
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
481
      */
482
    }
483
    $pager->records = $taxa;
484
  }
485

    
486
  $out = '';
487
  // Add thumbnails checkbox and refine search link.
488
  $out = '<div class="page_options">';
489
  if (isset($_REQUEST['ws'])) {
490
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
491
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
492
    }
493
  }
494
  $out .= '<form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Show Thumbnails') . '</form>';
495
  $out .= '</div>';
496
  $out .= '<div id="search-summary">' . t('results for') . ' ';
497
  $classification = cdm_dataportal_searched_in_classification();
498
  if ($classification != NULL) {
499
    $out .=  $classification->titleCache ;
500
  } else {
501
   $out .= t('any classification');
502
  }
503
  $out .= ':</div>';
504

    
505
  // List results.
506
  if (isset($pager->records) && count($pager->records) > 0) {
507
    $out .= '<div id="search_results">';
508
    $out .= theme('cdm_list_of_taxa',
509
        array(
510
          'records' => $pager->records,
511
          'freetextSearchResults' => $freetextSearchResults,
512
          'show_classification' => $classification === NULL
513
        )
514
      );
515
    $out .= '</div>';
516
    $out .= theme('cdm_pager', array(
517
        'pager' => $pager,
518
        'path' => $path,
519
        'parameters' => $_REQUEST,
520
    ));
521
  }
522
  else {
523
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
524
  }
525
  return $out;
526
}
527

    
528

    
529
/**
530
 * TODO Implementation of Hook taxon_image_gallery()
531
 *
532
 * @param unknown_type $taxon
533
 * @param unknown_type $media
534
 *
535
 * @return unknown_type
536
 */
537
function taxon_image_gallery_default($taxon, $media) {
538
  $hasImages = isset($media[0]);
539

    
540
  if ($hasImages) {
541

    
542
    $maxExtend = 150;
543
    $cols = 3;
544
    $maxRows = FALSE;
545
    $alternativeMediaUri = NULL;
546
    /* Comment @WA: was in D5:
547
    $captionElements = array(
548
      'title',
549
      'rights',
550
      '#uri' => t('open Image'),
551
    );
552
    */
553
    $captionElements = array(
554
      'title',
555
      'description',
556
      'artist',
557
      'location',
558
      'rights',
559
      '#uri' => t('open Image'),
560
    );
561
    $gallery_name = $taxon->uuid;
562
    $mediaLinkType = 'LIGHTBOX';
563

    
564
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
565

    
566
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
567

    
568
    $out = '<div class="image-gallerie">';
569
    $out .= theme('cdm_media_gallerie', array(
570
      'mediaList' => $media,
571
      'galleryName' => $gallery_name,
572
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
573
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
574
      'maxRows' => 0, // Ignore maxrows settings.
575
      'captionElements' => $captionElements,
576
      'mediaLinkType' => $mediaLinkType,
577
      'alternativeMediaUri' => NULL,
578
      'galleryLinkUri' => NULL,
579
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
580
    ));
581
    $out .= '</div>';
582
  }
583
  else {
584
    $out = 'No images available.';
585
  }
586
  return $out;
587
}
588

    
589
/**
590
 * TODO Implementation of Hook taxon_image_gallery()
591
 *
592
 * @param unknown_type $taxon
593
 * @param unknown_type $media
594
 *
595
 * @return unknown_type
596
 */
597
function taxon_image_gallery_fsi($taxon, $media) {
598
  $flashLink = isset($media[0]);
599

    
600
  if ($flashLink) {
601

    
602
    if (module_exists("fsi_gallery")) {
603
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
604
    }
605
    else {
606
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
607
      drupal_set_message($message, "error");
608
      $out = '<h3>' . $message . '</h3>';
609
    }
610
  }
611
  else {
612
    $out = 'No images available.';
613
  }
614
  return $out;
615
}
616

    
617
/**
618
 * Returns HTML for a single reference page.
619
 *
620
 * Renders a page with all data on a single reference.
621
 *
622
 * @param array $variables
623
 *   An associative array containing:
624
 *   - reference: Object.
625
 *
626
 * @ingroup themeable
627
 */
628
function theme_cdm_reference_page($variables) {
629
  $reference = $variables['reference'];
630

    
631
  $out = '';
632

    
633
  if (isset($reference->titleCache)) {
634
    drupal_set_title($reference->titleCache, PASS_THROUGH);
635
  }
636

    
637
  $field_order = array(
638
    "title",
639
    // "titleCache",
640
    // "citation",
641
    "authorTeam",
642
    "editor",
643
    "publisher",
644
    "placePublished",
645
    "datePublished",
646
    "year",
647
    "edition",// Class Book.
648
    "volume",// Class Article.
649
    "seriesPart",
650
    "inReference",
651
    "nomRefBase", // Class BookSection, Book, Article.
652
    "pages",// Class Article.
653
    "series",// Class Article, PrintSeries.
654
    "school",// Class Thesis.
655
    "institution",// Class Report.
656
    "organization",// Class Proceedings.
657
    "nextVersion",
658
    "previousVersion",
659
    "isbn",// Class Book.
660
    "issn",// Class Journal.
661
    "uri",
662
  );
663

    
664
  $header = array(
665
    t('Field'),
666
    t('Value'),
667
  );
668
  $table_rows = array();
669

    
670
  if (!isset($reference->authorTeam)) {
671
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
672
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
673
  }
674

    
675
  if (!isset($reference->inReference)) {
676
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
677
      $reference->uuid,
678
      "inReference",
679
    ));
680
  }
681

    
682
  foreach ($field_order as $fieldname) {
683

    
684
    if (isset($reference->$fieldname)) {
685

    
686
      if ($fieldname == "datePublished") {
687
        $period = $reference->$fieldname;
688
        $datePublished = timePeriodToString($period);
689
        if (isset($datePublished) && $datePublished != '') {
690
          $table_rows[] = array(
691
            t(ucfirst(strtolower($fieldname))),
692
            $datePublished,
693
          );
694
        }
695
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
696
        // $datePublished);
697
      }
698
      elseif (is_object($reference->$fieldname)) {
699
        if ($fieldname == "authorTeam") {
700
          $dump = $reference->$fieldname;
701
          $teammembers = "teamMembers";
702
          $team = $dump->$teammembers;
703
          $nameArray = array();
704

    
705
          foreach ($team as $member) {
706
            if (strlen($member->lastname) > 0) {
707
              $nname = $member->lastname;
708
              $name = $nname;
709
              if (strlen($member->firstname) > 0) {
710
                $vname = $member->firstname;
711
                $name = $vname . " " . $nname;
712
              }
713
              $nameArray[] = $name;
714
            }
715
            else {
716
              if (strlen($member->titleCache) > 0) {
717
                $nameArray[] = $member->titleCache;
718
              }
719
            }
720
          }
721
          $value = join($nameArray, ", ");
722
        }
723
        elseif ($fieldname == "inReference") {
724
          $type = $reference->$fieldname->type;
725
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
726
          switch ($type) {
727
            case "Book":
728
              $fieldname = "in book";
729
              break;
730
            case "Journal":
731
              $fieldname = "in journal";
732
              break;
733
            case "Proceedings":
734
              $fieldname = "in proceedings";
735
              break;
736
          }
737
        }
738
        else {
739
          $value = $reference->$fieldname->titleCache;
740
        }
741
        if (isset($value) && $value != '') {
742
          $table_rows[] = array(
743
            t(ucfirst(strtolower($fieldname))),
744
            $value,
745
          );
746
        }
747
      }
748
      else {
749
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
750
          $table_rows[] = array(
751
            t(ucfirst(strtolower($fieldname))),
752
            $reference->$fieldname,
753
          );
754
        }
755
      }
756
    }
757
  }
758

    
759
  $out = theme_table(array(
760
      'header' => array(),
761
      'rows' => $table_rows,
762
      'attributes' => array(),
763
      'caption' => NULL,
764
      'colgroups' => NULL,
765
      'sticky' => NULL,
766
     'empty' => NULL,
767
  ));
768

    
769
  // Annotations below the table.
770
  $annotations = cdm_ws_getAnnotationsFor($reference);
771
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
772

    
773
  return $out;
774
}
775

    
776
/**
777
 * @todo Please document this function.
778
 * @see http://drupal.org/node/1354
779
 */
780
function theme_cdm_media_page($variables) {
781
  $media = $variables['media'];
782
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
783
  $partId = $variables['partId'];
784
  $out = '';
785
  // Determine which reprresentation and which part to show.
786
  $representationIdx = 0;
787
  if ($mediarepresentation_uuid) {
788
    $i = 0;
789
    foreach ($media->representations as $representation) {
790
      if ($representation->uuid == $mediarepresentation_uuid) {
791
        $representationIdx = $i;
792
      }
793
      $i++;
794
    }
795
  }
796
  else {
797
    $mediarepresentation_uuid = $media->representations[0]->uuid;
798
  }
799

    
800
  $partIdx = 0;
801
  if (!is_numeric($partId)) {
802
    // Assuming it is an uuid.
803
    $i = 0;
804
    foreach ($media->representations[$representationIdx]->parts as $part) {
805
      if ($part->uuid == $partId) {
806
        $partIdx = $i;
807
      }
808
      $i++;
809
    }
810
  }
811
  else {
812
    // Assuming it is an index.
813
    $partIdx = $partId;
814
  }
815

    
816
  $media_metadata = cdm_read_media_metadata($media);
817
  // $title = $media->titleCache;
818
  $title = $media_metadata['title'];
819

    
820
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
821

    
822
  if (!$title) {
823
    $title = 'Media ' . $media->uuid . '';
824
  }
825

    
826
  drupal_set_title($title, PASS_THROUGH);
827

    
828
  $out .= '<div class="media cdm_media_viewer_image">';
829

    
830
  $out .= theme('cdm_back_to_image_gallery_button', array());
831
  $out .= '<div class="viewer">';
832
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
833
  $out .= '</div>';
834

    
835
  // General media metadata.
836
  /*
837
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
838
  vardump("PRINTING MEDIA METADATA");
839
  vardump($media_metadata);
840
  vardump("PRINTING MEDIA");
841
  vardump($media);
842
  */
843
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
844
  $out .= $metadataToPrint;
845

    
846
  // Tabs for the different representations.
847
  // ul.secondary
848
  $out .= '<ul class="primary">';
849
  foreach ($media->representations as $representation) {
850
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
851
  }
852
  $out .= '</ul>';
853

    
854
  // Representation(-part) specific metadata.
855
  $thumbnailMaxExtend = 100;
856
  $out .= '<table>';
857
  $i = 0;
858
  foreach ($media->representations[$representationIdx]->parts as $part) {
859
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
860
    switch ($part->class) {
861
      case 'ImageFile':
862
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
863
        break;
864
      case 'AudioFile':
865
      case 'MovieFile':
866
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
867
        break;
868
      default:
869
        $out .= $part->size . 'k';
870
    }
871

    
872
    $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));
873
    $i++;
874
  }
875
  $out .= '</table>';
876
  $out .= '</div>';
877

    
878
  return $out;
879
}
880

    
881
/**
882
 * @todo Please document this function.
883
 * @see http://drupal.org/node/1354
884
 */
885
function theme_cdm_polytomousKey_page($variables) {
886
  $polytomousKey = $variables['polytomousKey'];
887
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
888

    
889
  $out = theme("cdm_IdentificationKey", array(
890
    'identificationKey' => $polytomousKey,
891
    'doLinkToKeyPage' => FALSE,
892
    'showIdentificationKeyTitle' => FALSE,
893
    ));
894

    
895
  // Key nodes in linked style.
896
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
897
  /*
898
   * FIXME implement node type for keys !!!
899
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
900
   */
901
  return '<div id="identificationKey">' . $out . '</div>';
902
}
903

    
904
/**
905
 * Returns HTML for taxon page tabs.
906
 *
907
 * Allows theming of the taxon page tabs.
908
 *
909
 * @param array $variables
910
 *   An associative array containing:
911
 *   - tabname
912
 *
913
 * @ingroup themeable
914
 */
915
function theme_cdm_taxonpage_tab($variables) {
916
  $tabname = $variables['tabname'];
917
  // TODO replace by using translations or theme the menue tabs itself instead?
918
  switch ($tabname) {
919
    default:
920
      return t($tabname);
921
  }
922
}
(7-7/10)