Project

General

Profile

Download (28.1 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
  if (variable_get('cdm_dataportal_show_default_image', FALSE) && !$hideImages) {
294

    
295
    // Preferred image hardcoded for testing.
296
    $defaultRepresentationPart = new stdClass();
297
    $defaultRepresentationPart->width = 184;
298
    $defaultRepresentationPart->height = 144;
299
    $defaultRepresentationPart->uri = base_path() .  drupal_get_path('module', 'cdm_dataportal') . '/images/no_picture.png';
300

    
301
    // Preferred image size 184px × 144.
302
    $imageMaxExtend = variable_get(CDM_DEFAULT_IMAGE_MAXEXTEND, CDM_DEFAULT_IMAGE_MAXEXTEND_DEFAULT);
303
    $out .= '<div id="taxonProfileImage">' . theme('cdm_preferredImage', array(
304
      'media' => $media,
305
      'defaultRepresentationPart' => $defaultRepresentationPart,
306
      'imageMaxExtend' => $imageMaxExtend,
307
      )) . '</div>';
308
  }
309

    
310
  // Description TOC.
311
  $out .= theme('cdm_featureTreeTOCs', array('mergedTrees' => $mergedTrees));
312

    
313
  // Description.
314
  $out .= theme('cdm_featureTrees', array('mergedTrees' => $mergedTrees, 'taxon' => $taxon));
315

    
316
  return $out;
317
}
318

    
319

    
320

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

    
339
  RenderHints::pushToRenderStack('taxon_page_synonymy');
340

    
341
  // footnote key for the homotypic group and accepted taxon,
342
  // both should have the same footnote key
343
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
344

    
345
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
346
  $skip = array(
347
    UUID_BASIONYM,
348
  );
349
  $out = '';
350

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

    
362
    $accepted_name = '<span class="accepted-name">';
363
    $accepted_name .= theme('cdm_taxonName', array(
364
      'taxonName' => $taxon->name,
365
      'nameLink' => NULL,
366
      'refenceLink' => $referenceUri,
367
      ));
368
    $accepted_name .= '</span>';
369

    
370
    // handle annotations of the name and taxon
371
    $special_annotations_array = array();
372
    $special_annotations_array[] = $taxon->name;
373
    $special_annotations_array[] = $taxon;
374
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
375
        'cdmBase_list' => $special_annotations_array,
376
        'footnote_list_key' => RenderHints::getRenderPath() . '-annotations')
377
      );
378
  }
379

    
380
  // --- Render homotypic synonymy group
381
  if (!empty($accepted_name)) {
382
    $out .= $accepted_name;
383
  }
384

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

    
388

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

    
415
  RenderHints::popFromRenderStack();
416

    
417
  return $out;
418
}
419

    
420

    
421
/**
422
 * Returns HTML for the given result page including a pager.
423
 *
424
 * @param array $variables
425
 *   An associative array containing:
426
 *   - pager: The cdmlib pager object containing the result set of cdm base
427
 *     objects (currently this function can only handle taxon instances =>
428
 *     TODO)
429
 *   - path: The target path for the pager links, this will usually point to
430
 *     'cdm_dataportal/search/results/taxon'
431
 *
432
 * @ingroup themeable
433
 */
434
function theme_cdm_search_results($variables) {
435
  $pager = $variables['pager'];
436
  $path = $variables['path'];
437

    
438
  $freetextSearchResults = array();
439

    
440
  // If the pager contains records of SearchResults, extract the taxa and use
441
  // them as records instead.
442
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
443
    $freetextSearchResults = $pager->records;
444
    $taxa = array();
445
    // $highlightedFragments = array();
446
    foreach ($pager->records as $searchResult) {
447
      $taxa[] = &$searchResult->entity;
448
      /*
449
       if(!isset($searchResult->fieldHighlightMap)){
450
      $searchResult->fieldHighlightMap = NULL;
451
      }
452
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
453
      */
454
    }
455
    $pager->records = $taxa;
456
  }
457

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

    
477
  // List results.
478
  if (isset($pager->records) && count($pager->records) > 0) {
479
    $out .= '<div id="search_results">';
480
    $out .= theme('cdm_list_of_taxa',
481
        array(
482
          'records' => $pager->records,
483
          'freetextSearchResults' => $freetextSearchResults,
484
          'show_classification' => $classification === NULL
485
        )
486
      );
487
    $out .= '</div>';
488
    $out .= theme('cdm_pager', array(
489
        'pager' => $pager,
490
        'path' => $path,
491
        'parameters' => $_REQUEST,
492
    ));
493
  }
494
  else {
495
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
496
  }
497
  return $out;
498
}
499

    
500

    
501
/**
502
 * TODO Implementation of Hook taxon_image_gallery()
503
 *
504
 * @param unknown_type $taxon
505
 * @param unknown_type $media
506
 *
507
 * @return unknown_type
508
 */
509
function taxon_image_gallery_default($taxon, $media) {
510
  $hasImages = isset($media[0]);
511

    
512
  if ($hasImages) {
513

    
514
    $maxExtend = 150;
515
    $cols = 3;
516
    $maxRows = FALSE;
517
    $alternativeMediaUri = NULL;
518
    /* Comment @WA: was in D5:
519
    $captionElements = array(
520
      'title',
521
      'rights',
522
      '#uri' => t('open Image'),
523
    );
524
    */
525
    $captionElements = array(
526
      'title',
527
      'description',
528
      'artist',
529
      'location',
530
      'rights',
531
      '#uri' => t('open Image'),
532
    );
533
    $gallery_name = $taxon->uuid;
534
    $mediaLinkType = 'LIGHTBOX';
535

    
536
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
537

    
538
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
539

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

    
561
/**
562
 * TODO Implementation of Hook taxon_image_gallery()
563
 *
564
 * @param unknown_type $taxon
565
 * @param unknown_type $media
566
 *
567
 * @return unknown_type
568
 */
569
function taxon_image_gallery_fsi($taxon, $media) {
570
  $flashLink = isset($media[0]);
571

    
572
  if ($flashLink) {
573

    
574
    if (module_exists("fsi_gallery")) {
575
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
576
    }
577
    else {
578
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
579
      drupal_set_message($message, "error");
580
      $out = '<h3>' . $message . '</h3>';
581
    }
582
  }
583
  else {
584
    $out = 'No images available.';
585
  }
586
  return $out;
587
}
588

    
589
/**
590
 * Returns HTML for a single reference page.
591
 *
592
 * Renders a page with all data on a single reference.
593
 *
594
 * @param array $variables
595
 *   An associative array containing:
596
 *   - reference: Object.
597
 *
598
 * @ingroup themeable
599
 */
600
function theme_cdm_reference_page($variables) {
601
  $reference = $variables['reference'];
602

    
603
  $out = '';
604

    
605
  if (isset($reference->titleCache)) {
606
    drupal_set_title($reference->titleCache, PASS_THROUGH);
607
  }
608

    
609
  $field_order = array(
610
    "title",
611
    // "titleCache",
612
    // "citation",
613
    "authorTeam",
614
    "editor",
615
    "publisher",
616
    "placePublished",
617
    "datePublished",
618
    "year",
619
    "edition",// Class Book.
620
    "volume",// Class Article.
621
    "seriesPart",
622
    "inReference",
623
    "nomRefBase", // Class BookSection, Book, Article.
624
    "pages",// Class Article.
625
    "series",// Class Article, PrintSeries.
626
    "school",// Class Thesis.
627
    "institution",// Class Report.
628
    "organization",// Class Proceedings.
629
    "nextVersion",
630
    "previousVersion",
631
    "isbn",// Class Book.
632
    "issn",// Class Journal.
633
    "uri",
634
  );
635

    
636
  $header = array(
637
    t('Field'),
638
    t('Value'),
639
  );
640
  $table_rows = array();
641

    
642
  if (!isset($reference->authorTeam)) {
643
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
644
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
645
  }
646

    
647
  if (!isset($reference->inReference)) {
648
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
649
      $reference->uuid,
650
      "inReference",
651
    ));
652
  }
653

    
654
  foreach ($field_order as $fieldname) {
655

    
656
    if (isset($reference->$fieldname)) {
657

    
658
      if ($fieldname == "datePublished") {
659
        $period = $reference->$fieldname;
660
        $datePublished = timePeriodToString($period);
661
        if (isset($datePublished) && $datePublished != '') {
662
          $table_rows[] = array(
663
            t(ucfirst(strtolower($fieldname))),
664
            $datePublished,
665
          );
666
        }
667
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
668
        // $datePublished);
669
      }
670
      elseif (is_object($reference->$fieldname)) {
671
        if ($fieldname == "authorTeam") {
672
          $dump = $reference->$fieldname;
673
          $teammembers = "teamMembers";
674
          $team = $dump->$teammembers;
675
          $nameArray = array();
676

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

    
731
  $out = theme_table(array(
732
      'header' => array(),
733
      'rows' => $table_rows,
734
      'attributes' => array(),
735
      'caption' => NULL,
736
      'colgroups' => NULL,
737
      'sticky' => NULL,
738
     'empty' => NULL,
739
  ));
740

    
741
  // Annotations below the table.
742
  $annotations = cdm_ws_getAnnotationsFor($reference);
743
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
744

    
745
  return $out;
746
}
747

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

    
772
  $partIdx = 0;
773
  if (!is_numeric($partId)) {
774
    // Assuming it is an uuid.
775
    $i = 0;
776
    foreach ($media->representations[$representationIdx]->parts as $part) {
777
      if ($part->uuid == $partId) {
778
        $partIdx = $i;
779
      }
780
      $i++;
781
    }
782
  }
783
  else {
784
    // Assuming it is an index.
785
    $partIdx = $partId;
786
  }
787

    
788
  $media_metadata = cdm_read_media_metadata($media);
789
  // $title = $media->titleCache;
790
  $title = $media_metadata['title'];
791

    
792
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
793

    
794
  if (!$title) {
795
    $title = 'Media ' . $media->uuid . '';
796
  }
797

    
798
  drupal_set_title($title, PASS_THROUGH);
799

    
800
  $out .= '<div class="media cdm_media_viewer_image">';
801

    
802
  $out .= theme('cdm_back_to_image_gallery_button', array());
803
  $out .= '<div class="viewer">';
804
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
805
  $out .= '</div>';
806

    
807
  // General media metadata.
808
  /*
809
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
810
  vardump("PRINTING MEDIA METADATA");
811
  vardump($media_metadata);
812
  vardump("PRINTING MEDIA");
813
  vardump($media);
814
  */
815
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
816
  $out .= $metadataToPrint;
817

    
818
  // Tabs for the different representations.
819
  // ul.secondary
820
  $out .= '<ul class="primary">';
821
  foreach ($media->representations as $representation) {
822
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
823
  }
824
  $out .= '</ul>';
825

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

    
844
    $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));
845
    $i++;
846
  }
847
  $out .= '</table>';
848
  $out .= '</div>';
849

    
850
  return $out;
851
}
852

    
853
/**
854
 * @todo Please document this function.
855
 * @see http://drupal.org/node/1354
856
 */
857
function theme_cdm_polytomousKey_page($variables) {
858
  $polytomousKey = $variables['polytomousKey'];
859
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
860

    
861
  $out = theme("cdm_IdentificationKey", array(
862
    'identificationKey' => $polytomousKey,
863
    'doLinkToKeyPage' => FALSE,
864
    'showIdentificationKeyTitle' => FALSE,
865
    ));
866

    
867
  // Key nodes in linked style.
868
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
869
  /*
870
   * FIXME implement node type for keys !!!
871
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
872
   */
873
  return '<div id="identificationKey">' . $out . '</div>';
874
}
875

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