Project

General

Profile

Download (28.2 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
  // add all mandatory js sources
98
  _add_js_footnotes();
99

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

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

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

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

    
111
  $media = _load_media_for_taxon($taxon);
112

    
113

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

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

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

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

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

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

    
147
  // -------------------------------------------- //
148

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

    
151
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)) {
152
    $render_array['accepted_for'] = theme('cdm_acceptedFor', 'page_general');
153
  }
154

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

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

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

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

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

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

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

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

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

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

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

    
270
  return $render_array;
271
}
272

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

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

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

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

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

    
317
  return $out;
318
}
319

    
320

    
321

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

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

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

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

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

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

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

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

    
386
  // Render the homotypicSynonymyGroup including the type information.
387
  $out .= theme('cdm_homotypicSynonymyGroup', array('synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup, 'accepted_taxon_uuid' => $taxon->uuid));
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
  RenderHints::popFromRenderStack();
417

    
418
  return $out;
419
}
420

    
421

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

    
439
  $freetextSearchResults = array();
440

    
441
  // The $query_parameters must not contain the 'q' parameter
442
  // since this would conflict with the desired target $path.
443
  // unset($search_params['q']);
444
  // If the pager contains records of SearchResults, extract the taxa and use
445
  // them as records instead.
446
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
447
    $freetextSearchResults = $pager->records;
448
    $taxa = array();
449
    // $highlightedFragments = array();
450
    foreach ($pager->records as $searchResult) {
451
      $taxa[] = &$searchResult->entity;
452
      /*
453
       if(!isset($searchResult->fieldHighlightMap)){
454
      $searchResult->fieldHighlightMap = NULL;
455
      }
456
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
457
      */
458
    }
459
    $pager->records = $taxa;
460
  }
461

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

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

    
504

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

    
516
  if ($hasImages) {
517

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

    
540
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
541

    
542
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
543

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

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

    
576
  if ($flashLink) {
577

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

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

    
607
  $out = '';
608

    
609
  if (isset($reference->titleCache)) {
610
    drupal_set_title($reference->titleCache, PASS_THROUGH);
611
  }
612

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

    
640
  $header = array(
641
    t('Field'),
642
    t('Value'),
643
  );
644
  $table_rows = array();
645

    
646
  if (!isset($reference->authorTeam)) {
647
    $authorTeam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
648
    $reference->authorTeam = isset($authorTeam->titleCache) ? $authorTeam->titleCache : '';
649
  }
650

    
651
  if (!isset($reference->inReference)) {
652
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
653
      $reference->uuid,
654
      "inReference",
655
    ));
656
  }
657

    
658
  foreach ($field_order as $fieldname) {
659

    
660
    if (isset($reference->$fieldname)) {
661

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

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

    
735
  $out = theme_table(array(
736
      'header' => array(),
737
      'rows' => $table_rows,
738
      'attributes' => array(),
739
      'caption' => NULL,
740
      'colgroups' => NULL,
741
      'sticky' => NULL,
742
     'empty' => NULL,
743
  ));
744

    
745
  // Annotations below the table.
746
  $annotations = cdm_ws_getAnnotationsFor($reference);
747
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
748

    
749
  return $out;
750
}
751

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

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

    
792
  $media_metadata = cdm_read_media_metadata($media);
793
  // $title = $media->titleCache;
794
  $title = $media_metadata['title'];
795

    
796
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
797

    
798
  if (!$title) {
799
    $title = 'Media ' . $media->uuid . '';
800
  }
801

    
802
  drupal_set_title($title, PASS_THROUGH);
803

    
804
  $out .= '<div class="media cdm_media_viewer_image">';
805

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

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

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

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

    
848
    $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));
849
    $i++;
850
  }
851
  $out .= '</table>';
852
  $out .= '</div>';
853

    
854
  return $out;
855
}
856

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

    
865
  $out = theme("cdm_IdentificationKey", array(
866
    'identificationKey' => $polytomousKey,
867
    'doLinkToKeyPage' => FALSE,
868
    'showIdentificationKeyTitle' => FALSE,
869
    ));
870

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

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