Project

General

Profile

Download (18.4 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

    
77

    
78

    
79
/**
80
 * Returns HTML containing the synonymy for the accepted taxon.
81
 *
82
 * Shows the whole synonymy for the accepted taxon.
83
 * The synonymy list is headed by the complete scientific name
84
 * of the accepted taxon with nomenclatural reference.
85
 *
86
 * @param array $variables
87
 *   An associative array containing:
88
 *   - taxon
89
 *   - addAcceptedTaxon
90
 *
91
 * @ingroup themeable
92
 */
93
function theme_cdm_taxon_page_synonymy($variables) {
94
  $taxon = $variables['taxon'];
95
  $addAcceptedTaxon = $variables['addAcceptedTaxon'];
96

    
97
  RenderHints::pushToRenderStack('taxon_page_synonymy');
98

    
99
  // footnote key for the homotypic group and accepted taxon,
100
  // both should have the same footnote key
101
  RenderHints::setFootnoteListKey(RenderHints::getRenderPath());
102

    
103
  $synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
104
  $skip = array(
105
    UUID_BASIONYM,
106
  );
107
  $out = '';
108

    
109
  // Render accepted taxon.
110
  //
111
  // foonotes of the accepted taxon will be rendered in the homotypic group section
112
  // even if there are not synonyms in the homotypic group
113
  // homotypic group and accepted taxon should have the same footnote key
114
  $referenceUri = '';
115
  if ($addAcceptedTaxon) {
116
    if (isset($taxon->name->nomenclaturalReference)) {
117
      $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
118
    }
119

    
120
    $accepted_name = '<div class="accepted-name">';
121
    $accepted_name .= theme('cdm_taxonName', array(
122
      'taxonName' => $taxon->name,
123
      'nameLink' => NULL,
124
      'refenceLink' => $referenceUri,
125
      ));
126

    
127
    // handle annotations of the name and taxon
128
    $special_annotations_array = array();
129
    $special_annotations_array[] = $taxon->name;
130
    $special_annotations_array[] = $taxon;
131
    $accepted_name .= theme('cdm_annotations_as_footnotekeys', array(
132
        'cdmBase_list' => $special_annotations_array,
133
        'footnote_list_key' => RenderHints::getRenderPath() . '-annotations')
134
      );
135
    $accepted_name .= '</div>';
136
  }
137

    
138
  // --- Render homotypic synonymy group
139
  if (!empty($accepted_name)) {
140
    $out .= $accepted_name;
141
  }
142

    
143
  // Render the homotypicSynonymyGroup including the type information.
144
  $out .= theme(
145
      'cdm_homotypicSynonymyGroup',
146
      array(
147
          'synonymList' => $synomymie->homotypicSynonymsByHomotypicGroup,
148
          'accepted_taxon_name_uuid' => $taxon->name->uuid
149
      )
150
    );
151

    
152

    
153
  // Render accepted taxon heterotypic synonymy groups.
154
  if ($synomymie->heterotypicSynonymyGroups) {
155
    foreach ($synomymie->heterotypicSynonymyGroups as $homotypicalGroup) {
156
      $out .= theme('cdm_heterotypicSynonymyGroup', array('homotypicalGroup' => $homotypicalGroup));
157
    }
158
  }
159
  // Render taxon relationships.
160
  if (variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)) {
161
    $taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
162
    $out .= theme('cdm_taxonRelationships', array('taxonRelationships' => $taxonRelationships, 'focusedTaxon' => $taxon));
163
  }
164

    
165
  RenderHints::popFromRenderStack();
166

    
167
  return $out;
168
}
169

    
170

    
171
/**
172
 * Returns HTML for the given result page including a pager.
173
 *
174
 * @param array $variables
175
 *   An associative array containing:
176
 *   - pager: The cdmlib pager object containing the result set of cdm base
177
 *     objects (currently this function can only handle taxon instances =>
178
 *     TODO)
179
 *   - path: The target path for the pager links, this will usually point to
180
 *     'cdm_dataportal/search/results/taxon'
181
 *
182
 * @ingroup themeable
183
 */
184
function theme_cdm_search_results($variables) {
185
  $pager = $variables['pager'];
186
  $path = $variables['path'];
187

    
188
  $freetextSearchResults = array();
189

    
190
  // If the pager contains records of SearchResults, extract the taxa and use
191
  // them as records instead.
192
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
193
    $freetextSearchResults = $pager->records;
194
    $taxa = array();
195
    // $highlightedFragments = array();
196
    foreach ($pager->records as $searchResult) {
197
      $taxa[] = &$searchResult->entity;
198
      /*
199
       if(!isset($searchResult->fieldHighlightMap)){
200
      $searchResult->fieldHighlightMap = NULL;
201
      }
202
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
203
      */
204
    }
205
    $pager->records = $taxa;
206
  }
207

    
208
  $out = '';
209
  // Add thumbnails checkbox and refine search link.
210
  $out = '<div class="page_options">';
211
  if (isset($_REQUEST['ws'])) {
212
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
213
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
214
    }
215
  }
216
  $out .= '<form name="pageoptions"><div id="showThumbnails"><input type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Show Thumbnails') . '</div></form>';
217
  $out .= '</div>';
218

    
219
  $classification = cdm_dataportal_searched_in_classification();
220

    
221

    
222
  if (  count(cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY)) > 1 ) { // FIXME use a count REST method for this!!!
223
    $out .= '<div id="search-summary">' . t('results for') . ' ';
224
    if ($classification != NULL) {
225
      $out .=  $classification->titleCache ;
226
    } else {
227
     $out .= t('any classification');
228
    }
229
    $out .= ':</div>';
230
  }
231

    
232
  // List results.
233
  if (isset($pager->records) && count($pager->records) > 0) {
234
    $out .= '<div id="search_results">';
235
    $out .= theme('cdm_list_of_taxa',
236
        array(
237
          'records' => $pager->records,
238
          'freetextSearchResults' => $freetextSearchResults,
239
          'show_classification' => $classification === NULL
240
        )
241
      );
242
    $out .= '</div>';
243
    $out .= theme('cdm_pager', array(
244
        'pager' => $pager,
245
        'path' => $path,
246
        'parameters' => $_REQUEST,
247
    ));
248
  } else {
249
    $out .= '<h4 class="error">Sorry, no matching entries found.</h4>';
250
  }
251
  return $out;
252
}
253

    
254

    
255
/**
256
 * TODO Implementation of Hook taxon_image_gallery()
257
 *
258
 * @param unknown_type $taxon
259
 * @param unknown_type $media
260
 *
261
 * @return unknown_type
262
 */
263
function taxon_image_gallery_default($taxon, $media) {
264
  $hasImages = isset($media[0]);
265

    
266
  if ($hasImages) {
267

    
268
    $maxExtend = 150;
269
    $cols = 3;
270
    $maxRows = FALSE;
271
    $alternativeMediaUri = NULL;
272
    /* Comment @WA: was in D5:
273
    $captionElements = array(
274
      'title',
275
      'rights',
276
      '#uri' => t('open Image'),
277
    );
278
    */
279
    $captionElements = array(
280
      'title',
281
      'description',
282
      'artist',
283
      'location',
284
      'rights',
285
      '#uri' => t('open Image'),
286
    );
287
    $gallery_name = $taxon->uuid;
288
    $mediaLinkType = 'LIGHTBOX';
289

    
290
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
291

    
292
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
293

    
294
    $out = '<div class="image-gallerie">';
295
    $out .= theme('cdm_media_gallerie', array(
296
      'mediaList' => $media,
297
      'galleryName' => $gallery_name,
298
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
299
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
300
      'maxRows' => 0, // Ignore maxrows settings.
301
      'captionElements' => $captionElements,
302
      'mediaLinkType' => $mediaLinkType,
303
      'alternativeMediaUri' => NULL,
304
      'galleryLinkUri' => NULL,
305
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
306
    ));
307
    $out .= '</div>';
308
  }
309
  else {
310
    $out = 'No images available.';
311
  }
312
  return $out;
313
}
314

    
315
/**
316
 * TODO Implementation of Hook taxon_image_gallery()
317
 *
318
 * @param unknown_type $taxon
319
 * @param unknown_type $media
320
 *
321
 * @return unknown_type
322
 */
323
function taxon_image_gallery_fsi($taxon, $media) {
324
  $flashLink = isset($media[0]);
325

    
326
  if ($flashLink) {
327

    
328
    if (module_exists("fsi_gallery")) {
329
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
330
    }
331
    else {
332
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
333
      drupal_set_message($message, "error");
334
      $out = '<h3>' . $message . '</h3>';
335
    }
336
  }
337
  else {
338
    $out = 'No images available.';
339
  }
340
  return $out;
341
}
342

    
343
/**
344
 * Returns HTML for a single reference page.
345
 *
346
 * Renders a page with all data on a single reference.
347
 *
348
 * @param array $variables
349
 *   An associative array containing:
350
 *   - reference: Object.
351
 *
352
 * @ingroup themeable
353
 */
354
function theme_cdm_reference_page($variables) {
355
  $reference = $variables['reference'];
356

    
357
  $out = '';
358

    
359
  if (isset($reference->titleCache)) {
360
    drupal_set_title($reference->titleCache, PASS_THROUGH);
361
  }
362

    
363
  $field_order = array(
364
    "title",
365
    // "titleCache",
366
    // "citation",
367
    "authorship",
368
    "editor",
369
    "publisher",
370
    "placePublished",
371
    "datePublished",
372
    "year",
373
    "edition",// Class Book.
374
    "volume",// Class Article.
375
    "seriesPart",
376
    "inReference",
377
    "nomRefBase", // Class BookSection, Book, Article.
378
    "pages",// Class Article.
379
    "series",// Class Article, PrintSeries.
380
    "school",// Class Thesis.
381
    "institution",// Class Report.
382
    "organization",// Class Proceedings.
383
    "nextVersion",
384
    "previousVersion",
385
    "isbn",// Class Book.
386
    "issn",// Class Journal.
387
    "uri",
388
  );
389

    
390
  $header = array(
391
    t('Field'),
392
    t('Value'),
393
  );
394
  $table_rows = array();
395

    
396
  if (!isset($reference->authorship)) {
397
    $authorship = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
398
    $reference->authorship = isset($authorship->titleCache) ? $authorship->titleCache : '';
399
  }
400

    
401
  if (!isset($reference->inReference)) {
402
    $reference->inReference = cdm_ws_get(CDM_WS_REFERENCE, array(
403
      $reference->uuid,
404
      "inReference",
405
    ));
406
  }
407

    
408
  foreach ($field_order as $fieldname) {
409

    
410
    if (isset($reference->$fieldname)) {
411

    
412
      if ($fieldname == "datePublished") {
413
        $period = $reference->$fieldname;
414
        $datePublished = timePeriodToString($period);
415
        if (isset($datePublished) && $datePublished != '') {
416
          $table_rows[] = array(
417
            t(ucfirst(strtolower($fieldname))),
418
            $datePublished,
419
          );
420
        }
421
        // $datePublished = array(t(ucfirst(strtolower($fieldname))),
422
        // $datePublished);
423
      }
424
      elseif (is_object($reference->$fieldname)) {
425
        if ($fieldname == "authorship") {
426
          $dump = $reference->$fieldname;
427
          $teammembers = "teamMembers";
428
          $team = $dump->$teammembers;
429
          $nameArray = array();
430

    
431
          foreach ($team as $member) {
432
            if (strlen($member->lastname) > 0) {
433
              $nname = $member->lastname;
434
              $name = $nname;
435
              if (strlen($member->firstname) > 0) {
436
                $vname = $member->firstname;
437
                $name = $vname . " " . $nname;
438
              }
439
              $nameArray[] = $name;
440
            }
441
            else {
442
              if (strlen($member->titleCache) > 0) {
443
                $nameArray[] = $member->titleCache;
444
              }
445
            }
446
          }
447
          $value = join($nameArray, ", ");
448
        }
449
        elseif ($fieldname == "inReference") {
450
          $type = $reference->$fieldname->type;
451
          $value = l($reference->$fieldname->titleCache, path_to_reference($reference->$fieldname->uuid));
452
          switch ($type) {
453
            case "Book":
454
              $fieldname = "in book";
455
              break;
456
            case "Journal":
457
              $fieldname = "in journal";
458
              break;
459
            case "Proceedings":
460
              $fieldname = "in proceedings";
461
              break;
462
          }
463
        }
464
        else {
465
          $value = $reference->$fieldname->titleCache;
466
        }
467
        if (isset($value) && $value != '') {
468
          $table_rows[] = array(
469
            t(ucfirst(strtolower($fieldname))),
470
            $value,
471
          );
472
        }
473
      }
474
      else {
475
        if (isset($reference->$fieldname) && $reference->$fieldname != '') {
476
          $table_rows[] = array(
477
            t(ucfirst(strtolower($fieldname))),
478
            $reference->$fieldname,
479
          );
480
        }
481
      }
482
    }
483
  }
484

    
485
  $out = theme_table(array(
486
      'header' => array(),
487
      'rows' => $table_rows,
488
      'attributes' => array(),
489
      'caption' => NULL,
490
      'colgroups' => NULL,
491
      'sticky' => NULL,
492
     'empty' => NULL,
493
  ));
494

    
495
  // Annotations below the table.
496
  $annotations = cdm_ws_getAnnotationsFor($reference);
497
  $out .= theme("cdm_annotations", array('annotations' => $annotations));
498

    
499
  return $out;
500
}
501

    
502
/**
503
 * @todo Please document this function.
504
 * @see http://drupal.org/node/1354
505
 */
506
function theme_cdm_media_page($variables) {
507
  $media = $variables['media'];
508
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
509
  $partId = $variables['partId'];
510
  $out = '';
511
  // Determine which reprresentation and which part to show.
512
  $representationIdx = 0;
513
  if ($mediarepresentation_uuid) {
514
    $i = 0;
515
    foreach ($media->representations as $representation) {
516
      if ($representation->uuid == $mediarepresentation_uuid) {
517
        $representationIdx = $i;
518
      }
519
      $i++;
520
    }
521
  }
522
  else {
523
    $mediarepresentation_uuid = $media->representations[0]->uuid;
524
  }
525

    
526
  $partIdx = 0;
527
  if (!is_numeric($partId)) {
528
    // Assuming it is an uuid.
529
    $i = 0;
530
    foreach ($media->representations[$representationIdx]->parts as $part) {
531
      if ($part->uuid == $partId) {
532
        $partIdx = $i;
533
      }
534
      $i++;
535
    }
536
  }
537
  else {
538
    // Assuming it is an index.
539
    $partIdx = $partId;
540
  }
541

    
542
  $media_metadata = cdm_read_media_metadata($media);
543
  // $title = $media->titleCache;
544
  $title = $media_metadata['title'];
545

    
546
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
547

    
548
  if (!$title) {
549
    $title = 'Media ' . $media->uuid . '';
550
  }
551

    
552
  drupal_set_title($title, PASS_THROUGH);
553

    
554
  $out .= '<div class="media cdm_media_viewer_image">';
555

    
556
  $out .= theme('cdm_back_to_image_gallery_button', array());
557
  $out .= '<div class="viewer">';
558
  $out .= theme('cdm_openlayers_image', array('mediaRepresentationPart' => $media->representations[$representationIdx]->parts[$partIdx], 'maxExtend' => $imageMaxExtend));
559
  $out .= '</div>';
560

    
561
  // General media metadata.
562
  /*
563
  $media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
564
  vardump("PRINTING MEDIA METADATA");
565
  vardump($media_metadata);
566
  vardump("PRINTING MEDIA");
567
  vardump($media);
568
  */
569
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media));
570
  $out .= $metadataToPrint;
571

    
572
  // Tabs for the different representations.
573
  // ul.secondary
574
  $out .= '<ul class="primary">';
575
  foreach ($media->representations as $representation) {
576
    $out .= '<li>' . l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)) . '</li>';
577
  }
578
  $out .= '</ul>';
579

    
580
  // Representation(-part) specific metadata.
581
  $thumbnailMaxExtend = 100;
582
  $out .= '<table>';
583
  $i = 0;
584
  foreach ($media->representations[$representationIdx]->parts as $part) {
585
    $out .= '<tr><th>' . t('Part') . ' ' . ($i + 1) . '</th><td>';
586
    switch ($part->class) {
587
      case 'ImageFile':
588
        $out .= $part->width . ' x ' . $part->height . ' - ' . $part->size . 'k';
589
        break;
590
      case 'AudioFile':
591
      case 'MovieFile':
592
        $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . 'k';
593
        break;
594
      default:
595
        $out .= $part->size . 'k';
596
    }
597

    
598
    $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));
599
    $i++;
600
  }
601
  $out .= '</table>';
602
  $out .= '</div>';
603

    
604
  return $out;
605
}
606

    
607
/**
608
 * @todo Please document this function.
609
 * @see http://drupal.org/node/1354
610
 */
611
function theme_cdm_polytomousKey_page($variables) {
612
  $polytomousKey = $variables['polytomousKey'];
613
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
614

    
615
  $out = theme("cdm_IdentificationKey", array(
616
    'identificationKey' => $polytomousKey,
617
    'doLinkToKeyPage' => FALSE,
618
    'showIdentificationKeyTitle' => FALSE,
619
    ));
620

    
621
  // Key nodes in linked style.
622
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
623
  /*
624
   * FIXME implement node type for keys !!!
625
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
626
   */
627
  return '<div id="identificationKey">' . $out . '</div>';
628
}
629

    
630
/**
631
 * Returns HTML for taxon page tabs.
632
 *
633
 * Allows theming of the taxon page tabs.
634
 *
635
 * @param array $variables
636
 *   An associative array containing:
637
 *   - tabname
638
 *
639
 * @ingroup themeable
640
 */
641
function theme_cdm_taxonpage_tab($variables) {
642
  $tabname = $variables['tabname'];
643
  // TODO replace by using translations or theme the menue tabs itself instead?
644
  switch ($tabname) {
645
    default:
646
      return t($tabname);
647
  }
648
}
(6-6/9)