Project

General

Profile

Download (15.3 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
 * @todo Please document this function.
355
 * @see http://drupal.org/node/1354
356
 */
357
function theme_cdm_media_page($variables) {
358

    
359
  $media = $variables['media'];
360
  $mediarepresentation_uuid = $variables['mediarepresentation_uuid'];
361
  $partId = $variables['partId'];
362
  $out = '';
363

    
364
  // Determine which representation and which part to show
365
  $active_representation_index = 0;
366

    
367
  if (!$mediarepresentation_uuid) {
368
    // no representation requested by the method parameters, find the best one
369
    $representations = cdm_preferred_media_representations($media, array('image/png', 'image/jpeg', 'image/gif'), null, null);
370
    if($representations  && count($representations) > 0){
371
      $preferred_representation = array_shift($representations);
372
      $mediarepresentation_uuid = $preferred_representation->uuid;
373
    }
374
  }
375

    
376
  if($mediarepresentation_uuid){
377
    foreach ($media->representations as $representation) {
378
      if ($representation->uuid == $mediarepresentation_uuid) {
379
        break;
380
      }
381
      $active_representation_index++;
382
    }
383
  }
384

    
385

    
386
  $active_part_index = 0;
387
  if (is_uuid($partId)) {
388
    foreach ($media->representations[$active_representation_index]->parts as $part) {
389
      if ($part->uuid == $partId) {
390
        break;
391
      }
392
      $active_part_index++;
393
    }
394
  }
395
  else if(is_numeric($partId)){
396
    $active_part_index = $partId;
397
  }
398

    
399
  $media_metadata = read_media_metadata($media);
400
  $title = 'Media';
401
  if($media_metadata['title']){
402
    $title .= ' ' .$media_metadata['title'];
403
  } else if(isset($media_metadata['filename'])){
404
    $title .= ' (' .$media_metadata['filename'] .')';
405
  }
406

    
407
  $imageMaxExtend = variable_get('image-page-maxextend', 400);
408

    
409
  drupal_set_title($title, PASS_THROUGH);
410

    
411
  $out .= '<div class="media cdm_media_viewer_image">';
412

    
413
  if(preg_match('/cdm_dataportal\/taxon\//', $_SERVER['HTTP_REFERER']) ){
414
    if(variable_get('cdm_dataportal_taxonpage_tabs', 1)){
415
      // taxon page with tabs
416
      $out .= '<div id="backToGalleryButton">' . l(t('Back to images'), $_SESSION['cdm']['last_gallery']) . '</div>';
417
    } else {
418
      // tabless mode
419
      $out .= '<div id="backToGalleryButton">' . l(t('Back to taxon page'), $_SESSION['cdm']['last_gallery']) . '</div>';
420
    }
421
  }
422
  $out .= '<div class="viewer">';
423
  $out .= cdm_openlayers_image($media->representations[$active_representation_index]->parts[$active_part_index], $imageMaxExtend);
424
  $out .= '</div>';
425

    
426
  // General media metadata.
427
  $metadataToPrint = theme('cdm_media_caption', array('media' => $media, 'sources_as_content' => true));
428
  $out .= $metadataToPrint;
429

    
430
  $cdm_standard_image_viewer_settings = get_array_variable_merged(CDM_STANDARD_IMAGE_VIEWER, CDM_STANDARD_IMAGE_VIEWER_DEFAULT);
431
  if ($cdm_standard_image_viewer_settings['media_representation_details_enabled'] == 1){
432
    // Tabs for the different representations.
433
    // Representation(-part) specific metadata.
434
    $thumbnailMaxExtend = 100;
435
    $out .= '<h3>' .t('Media representations') .'</h3><ul id="media-representations">';
436
    $r_i = 0;
437
    foreach ($media->representations as $representation) {
438
      $out .= '<li><strong>'. t('Representation') . ' ' . $r_i . "</strong> ($representation->mimeType)" ;
439
      // parts
440
      $active_part_index = 0;
441
      $table_class_attribute = '';
442
      if($partIdx == $active_part_index && $active_representation_index == $r_i ){
443
        $table_class_attribute = 'class="active"';
444
      }
445
      $out .= "<table $table_class_attribute>";
446
      foreach ($representation->parts as $part) {
447
        $out .= '<tr><th>' . t('Part') . ' ' . ($active_part_index + 1) . '</th></tr><tr><td>';
448
        switch ($part->class) {
449
          case 'ImageFile':
450
            $out .= $part->width . 'x' . $part->height . ' px - ' . $part->size . ' kB';
451
            break;
452
          case 'AudioFile':
453
          case 'MovieFile':
454
            $out .= t('Duration') . ': ' . $part->duration . 's - ' . $part->size . ' kB';
455
            break;
456
          default:
457
            $out .= $part->size . 'k';
458
        }
459

    
460
        $out .= '</td><td><a href="' . url(path_to_media($media->uuid, $representation->uuid, $active_part_index)) . '">'
461
          . cdm_media_gallerie_image($part, $thumbnailMaxExtend, TRUE);
462
        $active_part_index++;
463
      }
464
      $out .= '</table>';
465
      $out .=  '</li>';
466
      $r_i++;
467
    }
468
    $out .= '</ul>';
469
  }
470

    
471
  $out .= '</div>';
472
  return $out;
473
}
474

    
475
/**
476
 * @todo Please document this function.
477
 * @see http://drupal.org/node/1354
478
 */
479
function theme_cdm_polytomousKey_page($variables) {
480
  $polytomousKey = $variables['polytomousKey'];
481
  drupal_set_title($polytomousKey->titleCache, PASS_THROUGH);
482

    
483
  $out = theme("cdm_IdentificationKey", array(
484
    'identificationKey' => $polytomousKey,
485
    'doLinkToKeyPage' => FALSE,
486
    'showIdentificationKeyTitle' => FALSE,
487
    ));
488

    
489
  // Key nodes in linked style.
490
  $out .= theme('cdm_polytomousKey', array('polytomousKey' => $polytomousKey));
491
  /*
492
   * FIXME implement node type for keys !!!
493
   * (wrapping the content in the cdm_dataportal.node becomes obsolete then).
494
   */
495
  return '<div id="identificationKey">' . $out . '</div>';
496
}
(6-6/9)