Project

General

Profile

Download (29.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

    
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
    $out .= '<div id="taxonProfileImage">' . $profile_image. '</div>';
335
  }
336

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

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

    
343
  return $out;
344
}
345

    
346

    
347

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

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

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

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

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

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

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

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

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

    
415

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

    
442
  RenderHints::popFromRenderStack();
443

    
444
  return $out;
445
}
446

    
447

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

    
465
  $freetextSearchResults = array();
466

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

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

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

    
527

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

    
539
  if ($hasImages) {
540

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

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

    
565
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
566

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

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

    
599
  if ($flashLink) {
600

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

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

    
630
  $out = '';
631

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

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

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

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

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

    
681
  foreach ($field_order as $fieldname) {
682

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

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

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

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

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

    
772
  return $out;
773
}
774

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

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

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

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

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

    
825
  drupal_set_title($title, PASS_THROUGH);
826

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

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

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

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

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

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

    
877
  return $out;
878
}
879

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

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

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

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