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

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

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

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

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

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

    
97
  $taxon = $variables['taxon'];
98
  $page_part = $variables['page_part'];
99
  global $theme;
100

    
101
  $render_array = array();
102
  $weight = 0; // the weight for the render array elements
103

    
104
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
105

    
106
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
107

    
108
  $media = _load_media_for_taxon($taxon);
109

    
110

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

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

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

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

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

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

    
144
  // -------------------------------------------- //
145

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

    
148
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
149
    $render_array['accepted_for'] = theme('cdm_acceptedFor', 'page_general');
150
  }
151

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

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

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

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

    
202
    $mergedTrees = cdm_ws_descriptions_by_featuretree(get_profile_featureTree(), $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
203

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

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

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

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

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

    
253
  // --- PAGE PART: KEYS --- //
254
  if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
255
    $keys_html = '<div id="keys">';
256
    if ($page_part == 'all') {
257
      $keys_html .= '<h2>' . t('Keys') . '</h2>';
258
    }
259
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
260
    $keys_html .= '</div>';
261
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
262
  }
263

    
264
  return $render_array;
265
}
266

    
267
/**
268
 * Returns HTML containing descriptive data and preferred picture.
269
 *
270
 * Outputs all descriptive data and shows the preferred picture of the
271
 * accepted taxon.
272
 *
273
 * @param array $variables
274
 *   An associative array containing:
275
 *   - taxon
276
 *   - mergedTrees
277
 *   - media:
278
 *   - hideImages
279
 *
280
 * @ingroup themeable
281
 */
282
function theme_cdm_taxon_page_profile($variables) {
283
  $taxon = $variables['taxon'];
284
  $mergedTrees = $variables['mergedTrees'];
285
  $media = $variables['media'];
286
  $hideImages = $variables['hideImages'];
287
  $out = '';
288
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
289

    
290
    // Preferred image hardcoded for testing.
291
    $defaultRepresentationPart = new stdClass();
292
    $defaultRepresentationPart->width = 184;
293
    $defaultRepresentationPart->height = 144;
294
    $defaultRepresentationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
295

    
296
    // Preferred image size 184px × 144.
297
    $imageMaxExtend = 184;
298
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
299
      'media' => $media,
300
      'defaultRepresentationPart' => $defaultRepresentationPart,
301
      'imageMaxExtend' => $imageMaxExtend,
302
      )) . '</div>';
303
  }
304

    
305
  // Description TOC.
306
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
307

    
308
  // Description.
309
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
310

    
311
  return $out;
312
}
313

    
314

    
315

    
316
/**
317
 * Returns HTML containing the synonymy for the accepted taxon.
318
 *
319
 * Shows the whole synonymy for the accepted taxon.
320
 * The synonymy list is headed by the complete scientific name
321
 * of the accepted taxon with nomenclatural reference.
322
 *
323
 * @param array $variables
324
 *   An associative array containing:
325
 *   - taxon
326
 *   - addAcceptedTaxon
327
 *
328
 * @ingroup themeable
329
 */
330
function theme_cdm_taxon_page_synonymy($variables) {
331
  $taxon = $variables['taxon'];
332
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
333

    
334
  RenderHints::pushToRenderStack('taxon_page_synonymy');
335

    
336
  // footnote key for the homotypic group and accepted taxon,
337
  // both should have the same footnote key
338
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
339

    
340
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
341
  $skip = array(
342
    UUID_BASIONYM,
343
  );
344
  $out = '';
345

    
346
  // Render accepted taxon.
347
  //
348
  // foonotes of the accepted taxon will be rendered in the homotypic group section
349
  // even if there are not synonyms in the homotypic group
350
  // homotypic group and accepted taxon should have the same footnote key
351
  $referenceUri = '';
352
  if ($addAcceptedTaxon) {
353
    if (isset($taxon->name->nomenclaturalReference)) {
354
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
355
    }
356

    
357
    $accepted_name = '<span class="accepted-name">';
358
    $accepted_name .= theme('cdm_taxonName', array(
359
      'taxonName' => $taxon->name,
360
      'nameLink' => NULL,
361
      'refenceLink' => $referenceUri,
362
      ));
363
    $accepted_name .= '</span>';
364

    
365
    $special_annotations_array = array();
366
    $special_annotations_array[] = $taxon->name;
367
    $special_annotations_array[] = $taxon;
368
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
369
    		'cdmBase_list' => $special_annotations_array,
370
    		'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
371
  }
372

    
373
  // Render homotypic synonymy group.
374
  $hasHomotypicSynonyms = TRUE; //isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
375

    
376
  if (!empty($accepted_name)) {
377
    $out .= $accepted_name;
378
  }
379

    
380
  if (!$hasHomotypicSynonyms) {
381
    // Show typeDesignations even if the homotypic synonymy group is empty.
382
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
383
    if ($typeDesignations) {
384
      $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
385
    }
386
    if (!empty($typeDesignations) || !empty($accepted_name)) {
387
      // Add empty list for coherent layout.
388
      $out .= '<ul class="homotypicSynonyms"></ul>';
389
    }
390
  }
391
  else {
392
    // Render the homotypicSynonymyGroup including the type information.
393
    $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
394
  }
395
  // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
396
// no longer needed here, all foonotes of the accepted taxon will be rendered int the homotypic group section
397
//   $out .= '<ul class="footnotes">';
398
//   $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath(), 'enclosingTag' => 'li'));
399
//   $out .= '</ul>';
400

    
401

    
402
  // Render accepted taxon heterotypic synonymy groups.
403
  if ($synomymie->heterotypicSynonymyGroups) {
404
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
405
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
406
    }
407
  }
408
  // Render taxon relationships.
409
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
410
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
411
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
412
  }
413
  // Render name relationships.
414
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
415
  $skip = array();
416
  if ($name_rels_to_show) {
417
    foreach ($name_rels_to_show as $key => $value) {
418
      if ($value === 0) {
419
        $skip[] = $key;
420
      }
421
    }
422
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
423
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
424
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
425
    }
426
  }
427

    
428
  // Render all footnotes and annontations text for the accepted taxa.
429
 // no longer needed here, all foonotes of the accepted taxon will be rendered int the homotypic group section
430
//   if ($addAcceptedTaxon) {
431
//     $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
432
//   }
433
  RenderHints::popFromRenderStack();
434

    
435
  return $out;
436
}
437

    
438

    
439
/**
440
 * Returns HTML for the given result page including a pager.
441
 *
442
 * @param array $variables
443
 *   An associative array containing:
444
 *   - pager: The cdmlib pager object containing the result set of cdm base
445
 *     objects (currently this function can only handle taxon instances =>
446
 *     TODO)
447
 *   - path: The target path for the pager links, this will usually point to
448
 *     'cdm_dataportal/search/results/taxon'.
449
 *   - query_parameters: The query parameters to be used in the pager links.
450
 *
451
 * @ingroup themeable
452
 */
453
function theme_cdm_search_results($variables) {
454
  $pager = $variables['pager'];
455
  $path = $variables['path'];
456
  $query_parameters = $variables['query_parameters'];
457
  $freetextSearchResults = array();
458
  // The $query_parameters must not contain the 'q' parameter
459
  // since this would conflict with the desired target $path.
460
  // unset($search_params['q']);
461
  // If the pager contains records of SearchResults, extract the taxa and use
462
  // them as records instead.
463
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
464
    $freetextSearchResults = $pager->records;
465
    $taxa = array();
466
    // $highlightedFragments = array();
467
    foreach ($pager->records as $searchResult) {
468
      $taxa[] = &$searchResult->entity;
469
      /*
470
       if(!isset($searchResult->fieldHighlightMap)){
471
      $searchResult->fieldHighlightMap = NULL;
472
      }
473
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
474
      */
475
    }
476
    $pager->records = $taxa;
477
  }
478

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

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

    
521

    
522
/**
523
 * TODO Implementation of Hook taxon_image_gallery()
524
 *
525
 * @param unknown_type $taxon
526
 * @param unknown_type $media
527
 *
528
 * @return unknown_type
529
 */
530
function taxon_image_gallery_default($taxon, $media) {
531
  $hasImages = isset($media[0]);
532

    
533
  if ($hasImages) {
534

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

    
557
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
558

    
559
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
560

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

    
582
/**
583
 * TODO Implementation of Hook taxon_image_gallery()
584
 *
585
 * @param unknown_type $taxon
586
 * @param unknown_type $media
587
 *
588
 * @return unknown_type
589
 */
590
function taxon_image_gallery_fsi($taxon, $media) {
591
  $flashLink = isset($media[0]);
592

    
593
  if ($flashLink) {
594

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

    
610
/**
611
 * Returns HTML for a single reference page.
612
 *
613
 * Renders a page with all data on a single reference.
614
 *
615
 * @param array $variables
616
 *   An associative array containing:
617
 *   - reference: Object.
618
 *
619
 * @ingroup themeable
620
 */
621
function theme_cdm_reference_page($variables) {
622
  $reference = $variables['reference'];
623

    
624
  $out = '';
625

    
626
  if (isset($reference->titleCache)) {
627
    drupal_set_title($reference->titleCache, PASS_THROUGH);
628
  }
629

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

    
657
  $header = array(
658
    t('Field'),
659
    t('Value'),
660
  );
661
  $table_rows = array();
662

    
663
  if (!isset($reference->authorTeam)) {
664
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
665
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
666
  }
667

    
668
  if (!isset($reference->inReference)) {
669
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
670
      $reference->uuid,
671
      "inReference",
672
    ));
673
  }
674

    
675
  foreach ($field_order as $fieldname) {
676

    
677
    if (isset($reference->$fieldname)) {
678

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

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

    
752
  $out = theme_table(array(
753
      'header' => array(),
754
      'rows' => $table_rows,
755
      'attributes' => array(),
756
      'caption' => NULL,
757
      'colgroups' => NULL,
758
      'sticky' => NULL,
759
     'empty' => NULL,
760
  ));
761

    
762
  // Annotations below the table.
763
  $annotations = cdm_ws_getAnnotationsFor($reference);
764
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
765

    
766
  return $out;
767
}
768

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

    
793
  $partIdx = 0;
794
  if (!is_numeric($partId)) {
795
    // Assuming it is an uuid.
796
    $i = 0;
797
    foreach ($media->representations[$representationIdx]->parts as $part) {
798
      if ($part->uuid == $partId) {
799
        $partIdx = $i;
800
      }
801
      $i++;
802
    }
803
  }
804
  else {
805
    // Assuming it is an index.
806
    $partIdx = $partId;
807
  }
808

    
809
  $media_metadata = cdm_read_media_metadata($media);
810
  // $title = $media->titleCache;
811
  $title = $media_metadata['title'];
812

    
813
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
814

    
815
  if (!$title) {
816
    $title = 'Media ' . $media->uuid . '';
817
  }
818

    
819
  drupal_set_title($title, PASS_THROUGH);
820

    
821
  $out .= '<div class="media cdm_media_viewer_image">';
822

    
823
  $out .= theme('cdm_back_to_image_gallery_button', array());
824
  $out .= '<div class="viewer">';
825
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
826
  $out .= '</div>';
827

    
828
  // General media metadata.
829
  /*
830
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
831
  vardump("PRINTING MEDIA METADATA");
832
  vardump($media_metadata);
833
  vardump("PRINTING MEDIA");
834
  vardump($media);
835
  */
836
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
837
  $out .= $metadataToPrint;
838

    
839
  // Tabs for the different representations.
840
  // ul.secondary
841
  $out .= '<ul class="primary">';
842
  foreach ($media->representations as $representation) {
843
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
844
  }
845
  $out .= '</ul>';
846

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

    
865
    $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));
866
    $i++;
867
  }
868
  $out .= '</table>';
869
  $out .= '</div>';
870

    
871
  return $out;
872
}
873

    
874
/**
875
 * @todo Please document this function.
876
 * @see http://drupal.org/node/1354
877
 */
878
function theme_cdm_polytomousKey_page($variables) {
879
  $polytomousKey = $variables['polytomousKey'];
880
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
881

    
882
  $out = theme("cdm_IdentificationKey", array(
883
    'identificationKey' => $polytomousKey,
884
    'doLinkToKeyPage' => FALSE,
885
    'showIdentificationKeyTitle' => FALSE,
886
    ));
887

    
888
  // Key nodes in linked style.
889
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
890
  /*
891
  FIXME implement node type for keys !!! (wrapping the content in the
892
  cdm_dataportal.node becomes obsolete then).
893
  */
894
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
895
}
896

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