Project

General

Profile

Download (15.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Page theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16
/**
17
 * Returns HTML for the default title of a taxon page.
18
 *  * The returned title is a formatted taxon name.
19
 *
20
 * @param array $variables
21
 *   An associative array containing:
22
 *   - taxon: The taxon name being formatted for the title.
23
 *   - uuid: UUID for the taxon.
24
 *
25
 * @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 array $variables
50
 *   An associative array containing:
51
 *   - specimen: The specimen being formatted for the title.
52
 *
53
 * @return string
54
 *  Markup for the title of a specimen page
55
 *
56
 * @ingroup themeable
57
 */
58
function theme_cdm_specimen_page_title($variables)
59
{
60

    
61
    $specimen = $variables['specimen'];
62
    RenderHints::pushToRenderStack('specimen_page_title');
63
    $referenceUri = '';
64
    $out = '';
65

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

    
96
    if ($specimen ->class == 'FieldUnit'){
97
        $out .= "FieldUnit ";
98
    }else{
99
        $out .= "Specimen ";
100
    }
101

    
102
  if($collection){
103
    $out .= $collection." ";
104
  }
105
  $out .= $specimenID;
106

    
107
  RenderHints::popFromRenderStack();
108

    
109
  return '<span class="' . $specimen->class . '">' . $out . '</span>';
110
}
111

    
112
/**
113
 * Returns HTML for the default title for a name page.
114
 *
115
 * The returned title is a formatted name.
116
 *
117
 * @param array $variables
118
 *   An associative array containing:
119
 *   - taxon_name: The taxon name object.
120
 *
121
 * @return string
122
 *  Markup for the title of a name page
123
 *
124
 * @ingroup themeable
125
 */
126
function theme_cdm_name_page_title($variables) {
127
  $taxon_name = $variables['taxon_name'];
128
  RenderHints::pushToRenderStack('taxon_page_title');
129

    
130
  $referenceUri = NULL;
131
  if (isset($taxon_name->nomenclaturalReference)) {
132
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
133
  }
134

    
135
  $out = '<span class="' . html_class_attribute_ref($taxon_name) . '">'
136
    . render_taxon_or_name($taxon_name, NULL, $referenceUri, FALSE)
137
    . '</span>';
138
  RenderHints::popFromRenderStack();
139
  return $out;
140
}
141

    
142

    
143

    
144
/**
145
 * Returns HTML for the given result page including a pager.
146
 *
147
 * @param array $variables
148
 *   An associative array containing:
149
 *   - pager: The cdmlib pager object containing the result set of cdm base
150
 *     objects (currently this function can only handle taxon instances =>
151
 *     TODO)
152
 *   - path: The target path for the pager links, this will usually point to
153
 *     'cdm_dataportal/search/results/taxon'
154
 *
155
 * @return string
156
 *  Markup for the result page
157
 *
158
 * @throws Exception
159
 *
160
 * @ingroup themeable
161
 */
162
function theme_cdm_search_taxa_results($variables)
163
{
164
  $pager = $variables['pager'];
165
  $path = $variables['path'];
166

    
167
  $freetextSearchResults = array();
168

    
169
  // If the pager contains records of SearchResults, extract the taxa and use
170
  // them as records instead.
171
  if (isset($pager->records[0]) && $pager->records[0]->class == "SearchResult") {
172
    $freetextSearchResults = $pager->records;
173
    $taxa = array();
174
    // $highlightedFragments = array();
175
    foreach ($pager->records as $searchResult) {
176
      $taxa[] = &$searchResult->entity;
177
      /*
178
       if(!isset($searchResult->fieldHighlightMap)){
179
      $searchResult->fieldHighlightMap = NULL;
180
      }
181
      $fragmentHighlighting[] = $searchResult->fieldHighlightMap;
182
      */
183
    }
184
    $pager->records = $taxa;
185
  }
186

    
187

    
188
  // Add thumbnails checkbox and refine search link.
189
  $out = '<div class="page_options">';
190
  if (isset($_REQUEST['ws'])) {
191
    if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
192
      $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
193
    }
194
  }
195
  if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
196
    $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>';
197
  }
198
  $out .= '</div>';
199

    
200
  $classification = cdm_dataportal_searched_in_classification();
201

    
202

    
203
  if (  count(cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY)) > 1 ) { // FIXME use a count REST method for this!!!
204
    $out .= '<div id="search-summary">' . t('results for') . ' ';
205
    if ($classification != NULL) {
206
      $out .=  $classification->titleCache ;
207
    } else {
208
     $out .= t('any classification');
209
    }
210
    $out .= ':</div>';
211
  }
212

    
213
  // List results.
214
  if (isset($pager->records) && count($pager->records) > 0) {
215
    $out .= '<div id="search_results">';
216
    $list_of_taxa = compose_list_of_taxa($pager->records, $freetextSearchResults, $classification === NULL);
217
    $out .= drupal_render($list_of_taxa);
218
    $out .= '</div>';
219
    $out .= theme('cdm_pager', array(
220
        'pager' => $pager,
221
        'path' => $path,
222
        'parameters' => $_REQUEST,
223
    ));
224
  } else {
225
    $out .= '<h4 class="error">' . t('Sorry, no matching entries found.') . '</h4>';
226
  }
227
  return $out;
228
}
229

    
230

    
231
/**
232
 * Returns HTML for the given result page including a pager.
233
 *
234
 * @param array $variables
235
 *   An associative array containing:
236
 *   - pager: TODO
237
 *   - path: The target path for the pager links, this will usually point to
238
 *     'cdm_dataportal/search/results/taxon'
239
 *
240
 * @return string
241
 *  Markup for the result page
242
 *
243
 * @throws Exception
244
 *
245
 * @ingroup themeable
246
 */
247
function theme_cdm_search_specimen_results($variables)
248
{
249
    $pager = $variables['pager'];
250
    $path = $variables['path'];
251

    
252

    
253

    
254
    // Add thumbnails checkbox and refine search link.
255
    $out = '<div class="page_options">';
256
    //if (isset($_REQUEST['ws'])) {
257
     //   if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
258
     //       $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
259
     //   }
260
    //}
261
    if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
262
        $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>';
263
    }
264
    $out .= '</div>';
265

    
266

    
267

    
268

    
269

    
270

    
271
    // List results.
272
    if (isset($pager->data) ) {
273
        $data = json_decode($pager->data, true);
274
        $out .= '<div id="search_results">';
275
        $list_of_result = compose_table_of_blast_result($data);
276
        $out .= $list_of_result;
277
        $out .= '</div>';
278
       // $out .= theme('cdm_pager', array(
279
       //     'pager' => $pager,
280
       //     'path' => $path,
281
       //     'parameters' => $_REQUEST,
282
        //));
283
    } else {
284
        $out .= '<h4 class="error">' . t('Sorry, no matching entries found.') . '</h4>';
285
    }
286
    return $out;
287
}
288

    
289

    
290
/**
291
 * TODO Implementation of Hook taxon_image_gallery()
292
 *
293
 * @param object $taxon
294
 * @param object $media
295
 *
296
 * @return string
297
 *  Markup for the default media gallery
298
 */
299
function taxon_image_gallery_default($taxon, $media) {
300
  $hasImages = isset($media[0]);
301

    
302
  if ($hasImages) {
303

    
304
    $maxExtend = 150;
305
    $cols = 3;
306
    $maxRows = FALSE;
307
    $alternativeMediaUri = NULL;
308
    /* Comment @WA: was in D5:
309
    $captionElements = array(
310
      'title',
311
      'rights',
312
      '#uri' => t('Open Image'),
313
    );
314
    */
315
    $captionElements = array(
316
      'title',
317
      'description',
318
      'artist',
319
      'location',
320
      'rights',
321
      '#uri' => t('Open image'),
322
    );
323
    $gallery_name = $taxon->uuid;
324
    $mediaLinkType = 'LIGHTBOX';
325

    
326
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
327

    
328
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
329

    
330
    $out = '<div class="image-gallerie">';
331
    $out .= compose_cdm_media_gallerie(array(
332
      'mediaList' => $media,
333
      'galleryName' => $gallery_name,
334
      'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
335
      'cols' => $gallery_settings['cdm_dataportal_media_cols'],
336
      'maxRows' => 0, // Ignore maxrows settings.
337
      'captionElements' => $captionElements,
338
      'mediaLinkType' => $mediaLinkType,
339
      'alternativeMediaUri' => NULL,
340
      'galleryLinkUri' => NULL,
341
      'showCaption' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
342
    ));
343
    $out .= '</div>';
344
  }
345
  else {
346
    $out = 'No images available.';
347
  }
348
  return $out;
349
}
350

    
351
/**
352
 * TODO Implementation of Hook taxon_image_gallery()
353
 *
354
 * @param object $taxon
355
 * @param object $media
356
 *
357
 * @return string
358
 *  Markup for the fsi media gallery
359
 *
360
 * @throws Exception
361
 */
362
function taxon_image_gallery_fsi($taxon, $media) {
363
  $flashLink = isset($media[0]);
364

    
365
  if ($flashLink) {
366

    
367
    if (module_exists("fsi_gallery")) {
368
      $out = theme("fsi_gallery", array('taxon' => $taxon, 'media' => $media));
369
    }
370
    else {
371
      $message = t('In order to use the FSI gallery you must enable the according ') . l(t("module"), "admin/modules");
372
      drupal_set_message($message, "error");
373
      $out = '<h3>' . $message . '</h3>';
374
    }
375
  }
376
  else {
377
    $out = 'No images available.';
378
  }
379
  return $out;
380
}
381

    
382

    
383
/**
384
 * @todo Please document this function.
385
 * @see http://drupal.org/node/1354
386
 */
387
function theme_cdm_media_page($variables) {
388

    
389
  $media = $variables['media'];
390
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
391
  $partId = $variables['partId'];
392
  $out = '';
393

    
394
  // Determine which representation and which part to show
395
  $active_representation_index = 0;
396

    
397
  if (!$mediarepresentation_uuid) {
398
    // no representation requested by the method parameters, find the best one
399
    $representations = cdm_preferred_media_representations($media, array('image/png', 'image/jpeg', 'image/gif'), null, null);
400
    if($representations  && count($representations) > 0){
401
      $preferred_representation = array_shift($representations);
402
      $mediarepresentation_uuid = $preferred_representation->uuid;
403
    }
404
  }
405

    
406
  if($mediarepresentation_uuid){
407
    foreach ($media->representations as $representation) {
408
      if ($representation->uuid == $mediarepresentation_uuid) {
409
        break;
410
      }
411
      $active_representation_index++;
412
    }
413
  }
414

    
415

    
416
  $active_part_index = 0;
417
  if (is_uuid($partId)) {
418
    foreach ($media->representations[$active_representation_index]->parts as $part) {
419
      if ($part->uuid == $partId) {
420
        break;
421
      }
422
      $active_part_index++;
423
    }
424
  }
425
  else if(is_numeric($partId)){
426
    $active_part_index = $partId;
427
  }
428

    
429
  $media_metadata = read_media_metadata($media);
430
  // $title = $media->titleCache;
431
  $title = $media_metadata['title'];
432

    
433
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
434

    
435
  if (!$title) {
436
    $title = 'Media ' . $media->uuid . '';
437
  }
438

    
439
  drupal_set_title($title, PASS_THROUGH);
440

    
441
  $out .= '<div class="media cdm_media_viewer_image">';
442

    
443
  if(preg_match('/cdm_dataportal\/taxon\//', $_SERVER['HTTP_REFERER']) ){
444
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)){
445
      // taxon page with tabs
446
      $out .= '<div id="backToGalleryButton">' . l(t('Back to images'), $_SESSION['cdm']['last_gallery']) . '</div>';
447
    } else {
448
      // tabless mode
449
      $out .= '<div id="backToGalleryButton">' . l(t('Back to taxon page'), $_SESSION['cdm']['last_gallery']) . '</div>';
450
    }
451
  }
452
  $out .= '<div class="viewer">';
453
  $out .= cdm_openlayers_image($media->representations[$active_representation_index]->parts[$active_part_index], $imageMaxExtend);
454
  $out .= '</div>';
455

    
456
  // General media metadata.
457
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media, 'sources_as_content' => true));
458
  $out .= $metadataToPrint;
459

    
460
  $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
461
  if ($cdm_standard_image_viewer_settings['media_representation_details_enabled'] == 1){
462
    // Tabs for the different representations.
463
    // Representation(-part) specific metadata.
464
    $thumbnailMaxExtend = 100;
465
    $out .= '<h3>' .t('Media representations') .'</h3><ul id="media-representations">';
466
    $r_i = 0;
467
    foreach ($media->representations as $representation) {
468
      $out .= '<li><strong>'. t('Representation') . ' ' . $r_i . "</strong> ($representation->mimeType)" ;
469
      // parts
470
      $active_part_index = 0;
471
      $table_class_attribute = '';
472
      if($partIdx == $active_part_index && $active_representation_index == $r_i ){
473
        $table_class_attribute = 'class="active"';
474
      }
475
      $out .= "<table $table_class_attribute>";
476
      foreach ($representation->parts as $part) {
477
        $out .= '<tr><th>' . t('Part') . ' ' . ($active_part_index + 1) . '</th></tr><tr><td>';
478
        switch ($part->class) {
479
          case 'ImageFile':
480
            $out .= $part->width . 'x' . $part->height . ' px - ' . $part->size . ' kB';
481
            break;
482
          case 'AudioFile':
483
          case 'MovieFile':
484
            $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . ' kB';
485
            break;
486
          default:
487
            $out .= $part->size . 'k';
488
        }
489

    
490
        $out .= '</td><td><a href="' . url(path_to_media($media->uuid, $representation->uuid, $active_part_index)) . '">'
491
          . cdm_media_gallerie_image($part, $thumbnailMaxExtend, TRUE);
492
        $active_part_index++;
493
      }
494
      $out .= '</table>';
495
      $out .=  '</li>';
496
      $r_i++;
497
    }
498
    $out .= '</ul>';
499
  }
500

    
501
  $out .= '</div>';
502
  return $out;
503
}
504

    
505
/**
506
 * @todo Please document this function.
507
 * @see http://drupal.org/node/1354
508
 */
509
function theme_cdm_polytomousKey_page($variables) {
510
  $polytomousKey = $variables['polytomousKey'];
511
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
512

    
513
  $out = theme("cdm_IdentificationKey", array(
514
    'identificationKey' => $polytomousKey,
515
    'doLinkToKeyPage' => FALSE,
516
    'showIdentificationKeyTitle' => FALSE,
517
    ));
518

    
519
  // Key nodes in linked style.
520
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
521
  /*
522
   * FIXME implement node type for keys !!!
523
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
524
   */
525
  return '<div id="identificationKey">' . $out . '</div>';
526
}
(6-6/9)