Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.page.theme @ 72d57201

History | View | Annotate | Download (17.6 KB)

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 of a specimen page.
114
 *  * The returned title is a the identifier of the specimen.
115
 *
116
 * @param array $variables
117
 *   An associative array containing:
118
 *   - specimen: The specimen being formatted for the title.
119
 *
120
 * @return string
121
 *  Markup for the title of a specimen page
122
 *
123
 * @ingroup themeable
124
 */
125
function theme_cdm_specimen_dto_page_title($variables)
126
{
127

    
128
    $specimen = $variables['specimen'];
129
    RenderHints::pushToRenderStack('specimen_page_title');
130
    $referenceUri = '';
131
    $out = '';
132

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

    
163
    if ($specimen ->class == 'FieldUnit'){
164
        $out .= "FieldUnit ";
165
    }else{
166
        $out .= "Specimen ";
167
    }
168

    
169
    if($collection){
170
        $out .= $collection." ";
171
    }
172
    $out .= $specimenID;
173

    
174
    RenderHints::popFromRenderStack();
175

    
176
    return '<span class="' . $specimen->class . '">' . $out . '</span>';
177
}
178

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

    
197
  $referenceUri = NULL;
198
  if (isset($taxon_name->nomenclaturalReference)) {
199
    $referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
200
  }
201

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

    
209

    
210

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

    
234
  $freetextSearchResults = array();
235

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

    
254

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

    
267
  $classification = cdm_dataportal_searched_in_classification();
268

    
269

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

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

    
297

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

    
319

    
320

    
321
    // Add thumbnails checkbox and refine search link.
322
    $out = '<div class="page_options">';
323
    //if (isset($_REQUEST['ws'])) {
324
     //   if (cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) {
325
     //       $out .= '<div id="backButton">' . l(t('Modify search'), cdm_dataportal_search_form_path_for_ws($_REQUEST['ws'])) . '</div>';
326
     //   }
327
    //}
328
    if (variable_get(SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX, SEARCH_RESULTS_SHOW_THUMBNAIL_CHECKBOX_DEFAULT)) {
329
        $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>';
330
    }
331
    $out .= '</div>';
332

    
333

    
334

    
335

    
336

    
337

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

    
356

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

    
369
  if ($hasImages) {
370

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

    
393
    // $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
394

    
395
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_TAXON_MEDIA_GALLERY_NAME_TAB);
396

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

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

    
432
  if ($flashLink) {
433

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

    
449

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

    
456
  $media = $variables['media'];
457
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
458
  $partId = $variables['partId'];
459
  $out = '';
460

    
461
  // Determine which representation and which part to show
462
  $active_representation_index = 0;
463

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

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

    
482

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

    
496
  $media_metadata = read_media_metadata($media);
497
  // $title = $media->titleCache;
498
  $title = $media_metadata['title'];
499

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

    
502
  if (!$title) {
503
    $title = 'Media ' . $media->uuid . '';
504
  }
505

    
506
  drupal_set_title($title, PASS_THROUGH);
507

    
508
  $out .= '<div class="media cdm_media_viewer_image">';
509

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

    
523
  // General media metadata.
524
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media, 'sources_as_content' => true));
525
  $out .= $metadataToPrint;
526

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

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

    
568
  $out .= '</div>';
569
  return $out;
570
}
571

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

    
580
  $out = theme("cdm_IdentificationKey", array(
581
    'identificationKey' => $polytomousKey,
582
    'doLinkToKeyPage' => FALSE,
583
    'showIdentificationKeyTitle' => FALSE,
584
    ));
585

    
586
  // Key nodes in linked style.
587
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
588
  /*
589
   * FIXME implement node type for keys !!!
590
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
591
   */
592
  return '<div id="identificationKey">' . $out . '</div>';
593
}
Add picture from clipboard (Maximum size: 40 MB)