Project

General

Profile

Download (17.6 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
 * @return string
26
 *  Markup for a taxon page title
27
 *
28
 * @ingroup themeable
29
 */
30
function theme_cdm_taxon_page_title($variables) {
31
  $taxon = $variables['taxon'];
32
  RenderHints::pushToRenderStack('taxon_page_title');
33
  $referenceUri = '';
34
  $out = '';
35
  if (isset($taxon->name->nomenclaturalReference)) {
36
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
37
  }
38

    
39
  $out .= render_taxon_or_name($taxon, NULL, $referenceUri, FALSE);
40
  RenderHints::popFromRenderStack();
41

    
42
  return '<span class="' . $taxon->class . '">' . $out . '</span>';
43
}
44

    
45
/**
46
 * Returns HTML for the default title of a specimen page.
47
 *  * The returned title is a the identifier of the specimen.
48
 *
49
 * @param object $pecimen: The CDM SpecimenOrObeservation instnce
50
 *     being formatted for the title.
51
 *
52
 * @return string
53
 *  Markup for the title of a specimen page
54
 *
55
 */
56
function specimen_page_title($specimen)
57
{
58

    
59
    RenderHints::pushToRenderStack('specimen_page_title');
60
    $referenceUri = '';
61
    $out = '';
62

    
63
    $collection = null;
64
    if (!($specimen->class == 'FieldUnit')) {
65
        if ($specimen->collection) {
66
            if ($specimen->collection->code) {
67
                $collection = $specimen->collection->code;
68
            } elseif ($specimen->collection->name) {
69
                $collection = $specimen->collection->name;
70
            }
71
        }
72
        if ($specimen->accessionNumber) {
73
            $specimenID = $specimen->accessionNumber;
74
        } elseif ($specimen->barcode) {
75
            $specimenID = $specimen->barcode;
76
        } elseif ($specimen->catalogNumber) {
77
            $specimenID = $specimen->catalogNumber;
78
        } elseif ($specimen->titleCache) {
79
            $specimenID = $specimen->titleCache;
80
        }
81
        if (!isset($specimenID) and !isset($collection)) {
82
            $specimenID = $specimen->uuid;
83
        }
84
    }else{
85
        if ($specimen->titleCache) {
86
            $specimenID = $specimen->titleCache;
87
        }
88
        if (!isset($specimenID) and !isset($collection)) {
89
            $specimenID = $specimen->uuid;
90
        }
91
    }
92

    
93
    if ($specimen ->class == 'FieldUnit'){
94
        $out .= '<span class="type-label">Field unit: </span>';
95
    }else{
96
        $out .= '<span class="type-label">Specimen:  </span>';
97
    }
98

    
99
    if($collection){
100
        $out .= $collection." ";
101
    }
102
    $out .= $specimenID;
103

    
104
    RenderHints::popFromRenderStack();
105

    
106
    return '<span class="' . $specimen->class . '">' . $out . '</span>';
107
}
108

    
109
/**
110
 * Returns HTML for the default title of a specimen page.
111
 *  * The returned title is a the identifier of the specimen.
112
 *
113
 * @param array $variables
114
 *   An associative array containing:
115
 *   - specimen: The specimen being formatted for the title.
116
 *
117
 * @return string
118
 *  Markup for the title of a specimen page
119
 *
120
 * @ingroup themeable
121
 */
122
function theme_cdm_specimen_dto_page_title($variables)
123
{
124

    
125
    $specimen = $variables['specimen'];
126
    RenderHints::pushToRenderStack('specimen_page_title');
127
    $referenceUri = '';
128
    $out = '';
129

    
130
    $collection = null;
131
    if (!($specimen->class == 'FieldUnit')) {
132
        if ($specimen->collection) {
133
            if ($specimen->collection->code) {
134
                $collection = $specimen->collection->code;
135
            } elseif ($specimen->collection->name) {
136
                $collection = $specimen->collection->name;
137
            }
138
        }
139
        if ($specimen->accessionNumber) {
140
            $specimenID = $specimen->accessionNumber;
141
        } elseif ($specimen->barcode) {
142
            $specimenID = $specimen->barcode;
143
        } elseif ($specimen->catalogNumber) {
144
            $specimenID = $specimen->catalogNumber;
145
        } elseif ($specimen->titleCache) {
146
            $specimenID = $specimen->titleCache;
147
        }
148
        if (!isset($specimenID) and !isset($collection)) {
149
            $specimenID = $specimen->uuid;
150
        }
151
    }else{
152
        if ($specimen->titleCache) {
153
            $specimenID = $specimen->titleCache;
154
        }
155
        if (!isset($specimenID) and !isset($collection)) {
156
            $specimenID = $specimen->uuid;
157
        }
158
    }
159

    
160
    if ($specimen ->class == 'FieldUnit'){
161
        $out .= "FieldUnit ";
162
    }else{
163
        $out .= "Specimen ";
164
    }
165

    
166
    if($collection){
167
        $out .= $collection." ";
168
    }
169
    $out .= $specimenID;
170

    
171
    RenderHints::popFromRenderStack();
172

    
173
    return '<span class="' . $specimen->class . '">' . $out . '</span>';
174
}
175

    
176
/**
177
 * Returns HTML for the default title for a name page.
178
 *
179
 * The returned title is a formatted name.
180
 *
181
 * @param array $variables
182
 *   An associative array containing:
183
 *   - taxon_name: The taxon name object.
184
 *
185
 * @return string
186
 *  Markup for the title of a name page
187
 *
188
 * @ingroup themeable
189
 */
190
function theme_cdm_name_page_title($variables) {
191
  $taxon_name = $variables['taxon_name'];
192
  RenderHints::pushToRenderStack('name_page_title');
193

    
194
  $referenceUri = NULL;
195
  if (isset($taxon_name->nomenclaturalReference)) {
196
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
197
  }
198

    
199
  $out = '<span class="' . html_class_attribute_ref($taxon_name) . '">'
200
    . render_taxon_or_name($taxon_name, NULL, $referenceUri, FALSE)
201
    . '</span>';
202
  RenderHints::popFromRenderStack();
203
  return $out;
204
}
205

    
206

    
207

    
208
/**
209
 * Returns HTML for the given result page including a pager.
210
 *
211
 * @param array $variables
212
 *   An associative array containing:
213
 *   - pager: The cdmlib pager object containing the result set of cdm base
214
 *     objects (currently this function can only handle taxon instances =>
215
 *     TODO)
216
 *   - path: The target path for the pager links, this will usually point to
217
 *     'cdm_dataportal/search/results/taxon'
218
 *
219
 * @return string
220
 *  Markup for the result page
221
 *
222
 * @throws Exception
223
 *
224
 * @ingroup themeable
225
 */
226
function theme_cdm_search_taxa_results($variables)
227
{
228
  $pager = $variables['pager'];
229
  $path = $variables['path'];
230

    
231
  $freetextSearchResults = array();
232

    
233
  // If the pager contains records of SearchResults, extract the taxa and use
234
  // them as records instead.
235
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
236
    $freetextSearchResults = $pager->records;
237
    $taxa = array();
238
    // $highlightedFragments = array();
239
    foreach ($pager->records as $searchResult) {
240
      $taxa[] = &$searchResult->entity;
241
      /*
242
       if(!isset($searchResult->fieldHighlightMap)){
243
      $searchResult->fieldHighlightMap = NULL;
244
      }
245
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
246
      */
247
    }
248
    $pager->records = $taxa;
249
  }
250

    
251

    
252
  // Add thumbnails checkbox and refine search link.
253
  $out = '<div class="page_options">';
254
  if (isset($_REQUEST['ws'])) {
255
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
256
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
257
    }
258
  }
259
  if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
260
    $out .= '<form name="pageoptions"><div id="showThumbnails"><input class="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Display image thumbnails') . '</div></form>';
261
  }
262
  $out .= '</div>';
263

    
264
  $classification = cdm_dataportal_searched_in_classification();
265

    
266

    
267
  if (  count(cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY)) > 1 ) { // FIXME use a count REST method for this!!!
268
    $out .= '<div id="search-summary">' . t('results for') . ' ';
269
    if ($classification != NULL) {
270
      $out .=  $classification->titleCache ;
271
    } else {
272
     $out .= t('any classification');
273
    }
274
    $out .= ':</div>';
275
  }
276

    
277
  // List results.
278
  if (isset($pager->records) && count($pager->records) > 0) {
279
    $out .= '<div id="search_results">';
280
    $list_of_taxa = compose_list_of_taxa($pager->records, $freetextSearchResults, $classification === NULL);
281
    $out .= drupal_render($list_of_taxa);
282
    $out .= '</div>';
283
    $out .= theme('cdm_pager', array(
284
        'pager' => $pager,
285
        'path' => $path,
286
        'parameters' => $_REQUEST,
287
    ));
288
  } else {
289
    $out .= '<h4 class="error">' . t('Sorry, no matching entries found.') . '</h4>';
290
  }
291
  return $out;
292
}
293

    
294

    
295
/**
296
 * Returns HTML for the given result page including a pager.
297
 *
298
 * @param array $variables
299
 *   An associative array containing:
300
 *   - pager: TODO
301
 *   - path: The target path for the pager links, this will usually point to
302
 *     'cdm_dataportal/search/results/taxon'
303
 *
304
 * @return string
305
 *  Markup for the result page
306
 *
307
 * @throws Exception
308
 *
309
 * @ingroup themeable
310
 */
311
function theme_cdm_search_specimen_results($variables)
312
{
313
    $pager = $variables['pager'];
314
    $path = $variables['path'];
315

    
316

    
317

    
318
    // Add thumbnails checkbox and refine search link.
319
    $out = '<div class="page_options">';
320
    //if (isset($_REQUEST['ws'])) {
321
     //   if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
322
     //       $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
323
     //   }
324
    //}
325
    if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
326
        $out .= '<form name="pageoptions"><div id="showThumbnails"><input class="showThumbnails" type="checkbox" name="showThumbnails" ' . (do_showThumbnails() == 1 ? 'checked="checked"' : '') . '> ' . t('Display image thumbnails') . '</div></form>';
327
    }
328
    $out .= '</div>';
329

    
330

    
331

    
332

    
333

    
334

    
335
    // List results.
336
    if (isset($pager->data) ) {
337
        $data = json_decode($pager->data, true);
338
        $out .= '<div id="search_results">';
339
        $list_of_result = compose_table_of_blast_result($data);
340
        $out .= $list_of_result;
341
        $out .= '</div>';
342
       // $out .= theme('cdm_pager', array(
343
       //     'pager' => $pager,
344
       //     'path' => $path,
345
       //     'parameters' => $_REQUEST,
346
        //));
347
    } else {
348
        $out .= '<h4 class="error">' . t('Sorry, no matching entries found.') . '</h4>';
349
    }
350
    return $out;
351
}
352

    
353

    
354
/**
355
 * TODO Implementation of Hook taxon_image_gallery()
356
 *
357
 * @param object $taxon
358
 * @param object $media
359
 *
360
 * @return string
361
 *  Markup for the default media gallery
362
 */
363
function taxon_image_gallery_default($taxon, $media) {
364
  $hasImages = isset($media[0]);
365

    
366
  if ($hasImages) {
367

    
368
    $maxExtend = 150;
369
    $cols = 3;
370
    $maxRows = FALSE;
371
    $alternativeMediaUri = NULL;
372
    /* Comment @WA: was in D5:
373
    $captionElements = array(
374
      'title',
375
      'rights',
376
      '#uri' => t('Open Image'),
377
    );
378
    */
379
    $captionElements = array(
380
      'title',
381
      'description',
382
      'artist',
383
      'location',
384
      'rights',
385
      '#uri' => t('Open image'),
386
    );
387
    $gallery_name = $taxon->uuid;
388
    $mediaLinkType = 'LIGHTBOX';
389

    
390
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
391

    
392
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
393

    
394
    $out = '<div class="image-gallerie">';
395
    $out .= compose_cdm_media_gallerie(array(
396
      'mediaList' => $media,
397
      'galleryName' => $gallery_name,
398
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
399
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
400
      'maxRows' => 0, // Ignore maxrows settings.
401
      'captionElements' => $captionElements,
402
      'mediaLinkType' => $mediaLinkType,
403
      'alternativeMediaUri' => NULL,
404
      'galleryLinkUri' => NULL,
405
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
406
    ));
407
    $out .= '</div>';
408
  }
409
  else {
410
    $out = 'No images available.';
411
  }
412
  return $out;
413
}
414

    
415
/**
416
 * TODO Implementation of Hook taxon_image_gallery()
417
 *
418
 * @param object $taxon
419
 * @param object $media
420
 *
421
 * @return string
422
 *  Markup for the fsi media gallery
423
 *
424
 * @throws Exception
425
 */
426
function taxon_image_gallery_fsi($taxon, $media) {
427
  $flashLink = isset($media[0]);
428

    
429
  if ($flashLink) {
430

    
431
    if (module_exists("fsi_gallery")) {
432
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
433
    }
434
    else {
435
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
436
      drupal_set_message($message, "error");
437
      $out = '<h3>' . $message . '</h3>';
438
    }
439
  }
440
  else {
441
    $out = 'No images available.';
442
  }
443
  return $out;
444
}
445

    
446

    
447
/**
448
 * @todo Please document this function.
449
 * @see http://drupal.org/node/1354
450
 */
451
function theme_cdm_media_page($variables) {
452

    
453
  $media = $variables['media'];
454
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
455
  $partId = $variables['partId'];
456
  $out = '';
457

    
458
  // Determine which representation and which part to show
459
  $active_representation_index = 0;
460

    
461
  if (!$mediarepresentation_uuid) {
462
    // no representation requested by the method parameters, find the best one
463
    $representations = cdm_preferred_media_representations($media, array('image/png', 'image/jpeg', 'image/gif'), null, null);
464
    if($representations  && count($representations) > 0){
465
      $preferred_representation = array_shift($representations);
466
      $mediarepresentation_uuid = $preferred_representation->uuid;
467
    }
468
  }
469

    
470
  if($mediarepresentation_uuid){
471
    foreach ($media->representations as $representation) {
472
      if ($representation->uuid == $mediarepresentation_uuid) {
473
        break;
474
      }
475
      $active_representation_index++;
476
    }
477
  }
478

    
479

    
480
  $active_part_index = 0;
481
  if (is_uuid($partId)) {
482
    foreach ($media->representations[$active_representation_index]->parts as $part) {
483
      if ($part->uuid == $partId) {
484
        break;
485
      }
486
      $active_part_index++;
487
    }
488
  }
489
  else if(is_numeric($partId)){
490
    $active_part_index = $partId;
491
  }
492

    
493
  $media_metadata = read_media_metadata($media);
494
  $title = 'Media';
495
  if($media_metadata['title']){
496
    $title .= ' ' .$media_metadata['title'];
497
  } else if(isset($media_metadata['filename'])){
498
    $title .= ' (' .$media_metadata['filename'] .')';
499
  }
500

    
501
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
502

    
503
  drupal_set_title($title, PASS_THROUGH);
504

    
505
  $out .= '<div class="media cdm_media_viewer_image">';
506

    
507
  if(preg_match('/cdm_dataportal\/taxon\//', $_SERVER['HTTP_REFERER']) ){
508
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)){
509
      // taxon page with tabs
510
      $out .= '<div id="backToGalleryButton">' . l(t('Back to images'), $_SESSION['cdm']['last_gallery']) . '</div>';
511
    } else {
512
      // tabless mode
513
      $out .= '<div id="backToGalleryButton">' . l(t('Back to taxon page'), $_SESSION['cdm']['last_gallery']) . '</div>';
514
    }
515
  }
516
  $out .= '<div class="viewer">';
517
  $out .= cdm_openlayers_image($media->representations[$active_representation_index]->parts[$active_part_index], $imageMaxExtend);
518
  $out .= '</div>';
519

    
520
  // General media metadata.
521
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media, 'sources_as_content' => true));
522
  $out .= $metadataToPrint;
523

    
524
  $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
525
  if ($cdm_standard_image_viewer_settings['media_representation_details_enabled'] == 1){
526
    // Tabs for the different representations.
527
    // Representation(-part) specific metadata.
528
    $thumbnailMaxExtend = 100;
529
    $out .= '<h3>' .t('Media representations') .'</h3><ul id="media-representations">';
530
    $r_i = 0;
531
    foreach ($media->representations as $representation) {
532
      $out .= '<li><strong>'. t('Representation') . ' ' . $r_i . "</strong> ($representation->mimeType)" ;
533
      // parts
534
      $active_part_index = 0;
535
      $table_class_attribute = '';
536
      if($partIdx == $active_part_index && $active_representation_index == $r_i ){
537
        $table_class_attribute = 'class="active"';
538
      }
539
      $out .= "<table $table_class_attribute>";
540
      foreach ($representation->parts as $part) {
541
        $out .= '<tr><th>' . t('Part') . ' ' . ($active_part_index + 1) . '</th></tr><tr><td>';
542
        switch ($part->class) {
543
          case 'ImageFile':
544
            $out .= $part->width . 'x' . $part->height . ' px - ' . $part->size . ' kB';
545
            break;
546
          case 'AudioFile':
547
          case 'MovieFile':
548
            $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . ' kB';
549
            break;
550
          default:
551
            $out .= $part->size . 'k';
552
        }
553

    
554
        $out .= '</td><td><a href="' . url(path_to_media($media->uuid, $representation->uuid, $active_part_index)) . '">'
555
          . cdm_media_gallerie_image($part, $thumbnailMaxExtend, TRUE);
556
        $active_part_index++;
557
      }
558
      $out .= '</table>';
559
      $out .=  '</li>';
560
      $r_i++;
561
    }
562
    $out .= '</ul>';
563
  }
564

    
565
  $out .= '</div>';
566
  return $out;
567
}
568

    
569
/**
570
 * @todo Please document this function.
571
 * @see http://drupal.org/node/1354
572
 */
573
function theme_cdm_polytomousKey_page($variables) {
574
  $polytomousKey = $variables['polytomousKey'];
575
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
576

    
577
  $out = theme("cdm_IdentificationKey", array(
578
    'identificationKey' => $polytomousKey,
579
    'doLinkToKeyPage' => FALSE,
580
    'showIdentificationKeyTitle' => FALSE,
581
    ));
582

    
583
  // Key nodes in linked style.
584
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
585
  /*
586
   * FIXME implement node type for keys !!!
587
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
588
   */
589
  return '<div id="identificationKey">' . $out . '</div>';
590
}
(6-6/9)