Project

General

Profile

Download (28.7 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
  RenderHints::pushToRenderStack('taxon_page_synonymy');
334
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
335
  $skip = array(
336
    UUID_BASIONYM,
337
  );
338
  $out = '';
339

    
340
  // Render accepted taxon.
341
  $referenceUri = '';
342
  if ($addAcceptedTaxon) {
343
    if (isset($taxon->name->nomenclaturalReference)) {
344
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
345
    }
346

    
347
    $accepted_name = '<span class="accepted-name">';
348
    $accepted_name .= theme('cdm_taxonName', array(
349
      'taxonName' => $taxon->name,
350
      'nameLink' => NULL,
351
      'refenceLink' => $referenceUri,
352
      ));
353
    $accepted_name .= '</span>';
354

    
355
    $special_annotations_array = array();
356
    $special_annotations_array[] = $taxon->name;
357
    $special_annotations_array[] = $taxon;
358
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array('cdmBase_list' => $special_annotations_array, 'footnote_list_key' => RenderHints::getRenderPath() . '-annotations'));
359
    RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
360
  }
361

    
362
  // Render homotypic synonymy group.
363
  $hasHomotypicSynonyms = isset($synomymie->homotypicSynonymsByHomotypicGroup[0]->name->uuid);
364

    
365
  if (!empty($accepted_name)) {
366
    $out .= $accepted_name;
367
  }
368

    
369
  if (!$hasHomotypicSynonyms) {
370
    // Show typeDesignations even if the homotypic synonymy group is empty.
371
    $typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
372
    if ($typeDesignations) {
373
      $out .= theme('cdm_typedesignations', array('typeDesignations' => $typeDesignations));
374
    }
375
    if (!empty($typeDesignations) || !empty($accepted_name)) {
376
      // Add empty list for coherent layout.
377
      $out .= '<ul class="homotypicSynonyms"></ul>';
378
    }
379
  }
380
  else {
381
    // Render the homotypicSynonymyGroup including the type information.
382
    $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
383
  }
384
  // all footnotes which has been assembled so far (e.g. from typeDesignations) to here
385
  $out .= '<ul class="footnotes">';
386
  $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath(), 'enclosingTag' => 'li'));
387
  $out .= '</ul>';
388

    
389

    
390
  // Render accepted taxon heterotypic synonymy groups.
391
  if ($synomymie->heterotypicSynonymyGroups) {
392
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
393
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
394
    }
395
  }
396
  // Render taxon relationships.
397
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
398
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
399
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
400
  }
401
  // Render name relationships.
402
  $name_rels_to_show = variable_get('name_relationships_to_show', NULL);
403
  $skip = array();
404
  if ($name_rels_to_show) {
405
    foreach ($name_rels_to_show as $key => $value) {
406
      if ($value === 0) {
407
        $skip[] = $key;
408
      }
409
    }
410
    if (sizeof($name_rels_to_show) != sizeof($skip)) {
411
      $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
412
      $out .= theme('cdm_nameRelationships', array('nameRelationships' => $nameRelationships, 'skipTypes' => $skip));
413
    }
414
  }
415

    
416
  // Render the annontations text for the accepted taxa.
417
  if ($addAcceptedTaxon) {
418
    $out .= theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getRenderPath() . '-annotations', 'enclosingTag' => 'li'));
419
  }
420
  RenderHints::popFromRenderStack();
421

    
422
  return $out;
423
}
424

    
425

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

    
466
  $out = '';
467
  // Add thumbnails checkbox and refine search link.
468
  $out = '<div class="page_options">';
469
  if (isset($_REQUEST['ws'])) {
470
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
471
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
472
    }
473
  }
474
  $out .= '<form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Show Thumbnails') . '</form>';
475
  $out .= '</div>';
476
  $out .= '<div id="search-summary">' . t('results for') . ' ';
477
  $classification = cdm_dataportal_searched_in_classification();
478
  if ($classification != NULL) {
479
    $out .=  $classification->titleCache ;
480
  } else {
481
   $out .= t('any classification');
482
  }
483
  $out .= ':</div>';
484

    
485
  // List results.
486
  if (isset($pager->records) && count($pager->records) > 0) {
487
    $out .= '<div id="search_results">';
488
    $out .= theme('cdm_list_of_taxa',
489
        array(
490
          'records' => $pager->records,
491
          'freetextSearchResults' => $freetextSearchResults,
492
          'show_classification' => $classification === NULL
493
        )
494
      );
495
    $out .= '</div>';
496
    $out .= theme('cdm_pager', array(
497
        'pager' => $pager,
498
        'path' => $path,
499
        'parameters' => $query_parameters,
500
    ));
501
  }
502
  else {
503
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
504
  }
505
  return $out;
506
}
507

    
508

    
509
/**
510
 * TODO Implementation of Hook taxon_image_gallery()
511
 *
512
 * @param unknown_type $taxon
513
 * @param unknown_type $media
514
 *
515
 * @return unknown_type
516
 */
517
function taxon_image_gallery_default($taxon, $media) {
518
  $hasImages = isset($media[0]);
519

    
520
  if ($hasImages) {
521

    
522
    $maxExtend = 150;
523
    $cols = 3;
524
    $maxRows = FALSE;
525
    $alternativeMediaUri = NULL;
526
    /* Comment @WA: was in D5:
527
    $captionElements = array(
528
      'title',
529
      'rights',
530
      '#uri' => t('open Image'),
531
    );
532
    */
533
    $captionElements = array(
534
      'title',
535
      'description',
536
      'artist',
537
      'location',
538
      'rights',
539
      '#uri' => t('open Image'),
540
    );
541
    $gallery_name = $taxon->uuid;
542
    $mediaLinkType = 'LIGHTBOX';
543

    
544
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
545

    
546
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
547

    
548
    $out = '<div class="image-gallerie">';
549
    $out .= theme('cdm_media_gallerie', array(
550
      'mediaList' => $media,
551
      'galleryName' => $gallery_name,
552
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
553
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
554
      'maxRows' => 0, // Ignore maxrows settings.
555
      'captionElements' => $captionElements,
556
      'mediaLinkType' => $mediaLinkType,
557
      'alternativeMediaUri' => NULL,
558
      'galleryLinkUri' => NULL,
559
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
560
    ));
561
    $out .= '</div>';
562
  }
563
  else {
564
    $out = 'No images available.';
565
  }
566
  return $out;
567
}
568

    
569
/**
570
 * TODO Implementation of Hook taxon_image_gallery()
571
 *
572
 * @param unknown_type $taxon
573
 * @param unknown_type $media
574
 *
575
 * @return unknown_type
576
 */
577
function taxon_image_gallery_fsi($taxon, $media) {
578
  $flashLink = isset($media[0]);
579

    
580
  if ($flashLink) {
581

    
582
    if (module_exists("fsi_gallery")) {
583
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
584
    }
585
    else {
586
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
587
      drupal_set_message($message, "error");
588
      $out = '<h3>' . $message . '</h3>';
589
    }
590
  }
591
  else {
592
    $out = 'No images available.';
593
  }
594
  return $out;
595
}
596

    
597
/**
598
 * Returns HTML for a single reference page.
599
 *
600
 * Renders a page with all data on a single reference.
601
 *
602
 * @param array $variables
603
 *   An associative array containing:
604
 *   - reference: Object.
605
 *
606
 * @ingroup themeable
607
 */
608
function theme_cdm_reference_page($variables) {
609
  $reference = $variables['reference'];
610

    
611
  $out = '';
612

    
613
  if (isset($reference->titleCache)) {
614
    drupal_set_title($reference->titleCache, PASS_THROUGH);
615
  }
616

    
617
  $field_order = array(
618
    "title",
619
    // "titleCache",
620
    // "citation",
621
    "authorTeam",
622
    "editor",
623
    "publisher",
624
    "placePublished",
625
    "datePublished",
626
    "year",
627
    "edition",// Class Book.
628
    "volume",// Class Article.
629
    "seriesPart",
630
    "inReference",
631
    "nomRefBase", // Class BookSection, Book, Article.
632
    "pages",// Class Article.
633
    "series",// Class Article, PrintSeries.
634
    "school",// Class Thesis.
635
    "institution",// Class Report.
636
    "organization",// Class Proceedings.
637
    "nextVersion",
638
    "previousVersion",
639
    "isbn",// Class Book.
640
    "issn",// Class Journal.
641
    "uri",
642
  );
643

    
644
  $header = array(
645
    t('Field'),
646
    t('Value'),
647
  );
648
  $table_rows = array();
649

    
650
  if (!isset($reference->authorTeam)) {
651
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
652
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
653
  }
654

    
655
  if (!isset($reference->inReference)) {
656
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
657
      $reference->uuid,
658
      "inReference",
659
    ));
660
  }
661

    
662
  foreach ($field_order as $fieldname) {
663

    
664
    if (isset($reference->$fieldname)) {
665

    
666
      if ($fieldname == "datePublished") {
667
        $period = $reference->$fieldname;
668
        $datePublished = timePeriodToString($period);
669
        if (isset($datePublished) && $datePublished != '') {
670
          $table_rows[] = array(
671
            t(ucfirst(strtolower($fieldname))),
672
            $datePublished,
673
          );
674
        }
675
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
676
        // $datePublished);
677
      }
678
      elseif (is_object($reference->$fieldname)) {
679
        if ($fieldname == "authorTeam") {
680
          $dump = $reference->$fieldname;
681
          $teammembers = "teamMembers";
682
          $team = $dump->$teammembers;
683
          $nameArray = array();
684

    
685
          foreach ($team as $member) {
686
            if (strlen($member->lastname) > 0) {
687
              $nname = $member->lastname;
688
              $name = $nname;
689
              if (strlen($member->firstname) > 0) {
690
                $vname = $member->firstname;
691
                $name = $vname . " " . $nname;
692
              }
693
              $nameArray[] = $name;
694
            }
695
            else {
696
              if (strlen($member->titleCache) > 0) {
697
                $nameArray[] = $member->titleCache;
698
              }
699
            }
700
          }
701
          $value = join($nameArray, ", ");
702
        }
703
        elseif ($fieldname == "inReference") {
704
          $type = $reference->$fieldname->type;
705
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
706
          switch ($type) {
707
            case "Book":
708
              $fieldname = "in book";
709
              break;
710
            case "Journal":
711
              $fieldname = "in journal";
712
              break;
713
            case "Proceedings":
714
              $fieldname = "in proceedings";
715
              break;
716
          }
717
        }
718
        else {
719
          $value = $reference->$fieldname->titleCache;
720
        }
721
        if (isset($value) && $value != '') {
722
          $table_rows[] = array(
723
            t(ucfirst(strtolower($fieldname))),
724
            $value,
725
          );
726
        }
727
      }
728
      else {
729
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
730
          $table_rows[] = array(
731
            t(ucfirst(strtolower($fieldname))),
732
            $reference->$fieldname,
733
          );
734
        }
735
      }
736
    }
737
  }
738

    
739
  $out = theme_table(array(
740
      'header' => array(),
741
      'rows' => $table_rows,
742
      'attributes' => array(),
743
      'caption' => NULL,
744
      'colgroups' => NULL,
745
      'sticky' => NULL,
746
     'empty' => NULL,
747
  ));
748

    
749
  // Annotations below the table.
750
  $annotations = cdm_ws_getAnnotationsFor($reference);
751
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
752

    
753
  return $out;
754
}
755

    
756
/**
757
 * @todo Please document this function.
758
 * @see http://drupal.org/node/1354
759
 */
760
function theme_cdm_media_page($variables) {
761
  $media = $variables['media'];
762
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
763
  $partId = $variables['partId'];
764
  $out = '';
765
  // Determine which reprresentation and which part to show.
766
  $representationIdx = 0;
767
  if ($mediarepresentation_uuid) {
768
    $i = 0;
769
    foreach ($media->representations as $representation) {
770
      if ($representation->uuid == $mediarepresentation_uuid) {
771
        $representationIdx = $i;
772
      }
773
      $i++;
774
    }
775
  }
776
  else {
777
    $mediarepresentation_uuid = $media->representations[0]->uuid;
778
  }
779

    
780
  $partIdx = 0;
781
  if (!is_numeric($partId)) {
782
    // Assuming it is an uuid.
783
    $i = 0;
784
    foreach ($media->representations[$representationIdx]->parts as $part) {
785
      if ($part->uuid == $partId) {
786
        $partIdx = $i;
787
      }
788
      $i++;
789
    }
790
  }
791
  else {
792
    // Assuming it is an index.
793
    $partIdx = $partId;
794
  }
795

    
796
  $media_metadata = cdm_read_media_metadata($media);
797
  // $title = $media->titleCache;
798
  $title = $media_metadata['title'];
799

    
800
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
801

    
802
  if (!$title) {
803
    $title = 'Media ' . $media->uuid . '';
804
  }
805

    
806
  drupal_set_title($title, PASS_THROUGH);
807

    
808
  $out .= '<div class="media cdm_media_viewer_image">';
809

    
810
  $out .= theme('cdm_back_to_image_gallery_button', array());
811
  $out .= '<div class="viewer">';
812
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
813
  $out .= '</div>';
814

    
815
  // General media metadata.
816
  /*
817
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
818
  vardump("PRINTING MEDIA METADATA");
819
  vardump($media_metadata);
820
  vardump("PRINTING MEDIA");
821
  vardump($media);
822
  */
823
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
824
  $out .= $metadataToPrint;
825

    
826
  // Tabs for the different representations.
827
  // ul.secondary
828
  $out .= '<ul class="primary">';
829
  foreach ($media->representations as $representation) {
830
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
831
  }
832
  $out .= '</ul>';
833

    
834
  // Representation(-part) specific metadata.
835
  $thumbnailMaxExtend = 100;
836
  $out .= '<table>';
837
  $i = 0;
838
  foreach ($media->representations[$representationIdx]->parts as $part) {
839
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
840
    switch ($part->class) {
841
      case 'ImageFile':
842
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
843
        break;
844
      case 'AudioFile':
845
      case 'MovieFile':
846
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
847
        break;
848
      default:
849
        $out .= $part->size . 'k';
850
    }
851

    
852
    $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));
853
    $i++;
854
  }
855
  $out .= '</table>';
856
  $out .= '</div>';
857

    
858
  return $out;
859
}
860

    
861
/**
862
 * @todo Please document this function.
863
 * @see http://drupal.org/node/1354
864
 */
865
function theme_cdm_polytomousKey_page($variables) {
866
  $polytomousKey = $variables['polytomousKey'];
867
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
868

    
869
  $out = theme("cdm_IdentificationKey", array(
870
    'identificationKey' => $polytomousKey,
871
    'doLinkToKeyPage' => FALSE,
872
    'showIdentificationKeyTitle' => FALSE,
873
    ));
874

    
875
  // Key nodes in linked style.
876
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
877
  /*
878
  FIXME implement node type for keys !!! (wrapping the content in the
879
  cdm_dataportal.node becomes obsolete then).
880
  */
881
  return '<div id="cdm_dataportal.node">' . $out . '</div>';
882
}
883

    
884
/**
885
 * Returns HTML for taxon page tabs.
886
 *
887
 * Allows theming of the taxon page tabs.
888
 *
889
 * @param array $variables
890
 *   An associative array containing:
891
 *   - tabname
892
 *
893
 * @ingroup themeable
894
 */
895
function theme_cdm_taxonpage_tab($variables) {
896
  $tabname = $variables['tabname'];
897
  // TODO replace by using translations or theme the menue tabs itself instead?
898
  switch ($tabname) {
899
    default:
900
      return t($tabname);
901
  }
902
}
(7-7/10)