Project

General

Profile

Download (41.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Page 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
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Creates a render array representing the ocurrences associetad with the $taxon.
22
 *
23
 * The resulting render array contains two elements:
24
 *  - 'map': A map showing all point locations of the occurences is availabale
25
 *  - 'specimen_list': the list of occurences prepated as table for theme_table()
26
 *
27
 * @param object $taxon
28
 *   A cdm Taxon object
29
 * @return
30
 *   A render array suitable for drupal_render()
31
 *
32
 */
33
function cdm_dataportal_taxon_page_specimens($taxon) {
34

    
35
    $render_array = array();
36
    RenderHints::pushToRenderStack('taxon_page_specimens');
37

    
38
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
39
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
40
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
41

    
42
    $by_associatedtaxon_query_parameters = array(
43
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
44
        'relationships' => implode(',', $relationship_choice['direct']),
45
    );
46

    
47
    if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
48
        $by_associatedtaxon_query_parameters = array_merge($by_associatedtaxon_query_parameters, $_REQUEST['pager']);
49
    }
50

    
51
    $by_associatedtaxon_query = http_build_query($by_associatedtaxon_query_parameters);
52

    
53
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
54
        null,
55
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
56
    );
57

    
58
    $specimensOrObservations = array();
59
    if(isset($pager->records[0])){
60
        $specimensOrObservations =  $pager->records;
61
    }
62

    
63
    // order occurrences by date but types should be on top of the list
64
    $type_specimens = array();
65
    $other_occurrences = array();
66
    foreach ($specimensOrObservations as &$occurrence) {
67
        $typeDesignationsPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $occurrence->uuid);
68
        if (isset($typeDesignationsPager->count) && $typeDesignationsPager->count > 0) {
69
            $type_specimens[] = $occurrence;
70
        } else {
71
            $other_occurrences[] = $occurrence;
72
        }
73
    }
74
    $specimensOrObservations = array_merge($type_specimens, $other_occurrences);
75

    
76
    // Collect media (fieldObjectMedia, derivedUnitMedia) and add as a custom field
77
    // $occurrence->_fieldObjectMedia
78
    foreach ($specimensOrObservations as &$occurrence) {
79
        $occurrence->_fieldObjectMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
80
            $occurrence->uuid,
81
            'fieldObjectMedia',
82
        ));
83
        $occurrence->_derivedUnitMedia = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, array(
84
            $occurrence->uuid,
85
            'derivedUnitMedia',
86
        ));
87
    }
88

    
89
    // --- get map service HTTP query parameters
90
    if (count($specimensOrObservations) > 0) {
91
        $occurrence_queryDto = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid,  $by_associatedtaxon_query);
92

    
93
      $map_visibility = variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT);
94
      if($map_visibility == 'always' ||
95
        variable_get(SPECIMEN_MAP_VISIBILITY, SPECIMEN_MAP_VISIBILITY_DEFAULT) == 'automatic' &&
96
          (isset($occurrence_queryDto->fieldUnitPoints[0]) || isset($occurrence_queryDto->derivedUnitPoints[0]))
97
        )
98
      {
99
        $occurrence_query = $occurrence_queryDto->occurrenceQuery;
100
        $legend_format_query = null;
101
        $distribution_query = NULL;
102
        $render_array['map'] = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
103
      }
104
    }
105
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
106

    
107
        //COMPRESSED SPECIMEN DERIVATE TABLE
108
        $associatedFieldUnitsQuery_parameters = array();
109
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
110
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
111
        }
112

    
113
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
114
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
115
            array($taxon->uuid, 'associatedFieldUnits'),
116
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
117
        );
118

    
119
        if (isset($pager_field_units->records[0])) {
120
          $field_unit_uuids = array();
121
          foreach ($pager_field_units->records as $field_unit) {
122
            $field_unit_uuids[] = $field_unit->uuid;
123
          }
124
        }
125

    
126
        $render_array['derivate_hierarchy_table'] = render_derivate_hierarchy_table($field_unit_uuids);
127

    
128
        $render_array['pager'] = markup_to_render_array(
129
            theme('cdm_pager', array(
130
                'pager' => $pager_field_units,
131
                'path' => $_REQUEST['q'],
132
                'parameters' => $_REQUEST
133
            )),
134
            10 // weight
135
        );
136
    }
137
    else{
138
        //BOTTOM-UP-SPECIMEN-TABLE
139
        // --- generate the specimen list as table
140
        $specimen_table = array(
141
            '#theme' => 'table',
142
            '#weight' => 2,
143
            // prefix attributes and rows with '#' to let it pass toF the theme function,
144
            // otherwise it is handled as child render array
145
            '#attributes' => array('class' => 'specimens'),
146
            '#rows' => array(),
147
        );
148

    
149
        if ($specimensOrObservations) {
150

    
151
            foreach ($specimensOrObservations as $specimenOrObservation) {
152

    
153
                $mediaList = array();
154
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
155
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
156
                }
157
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
158
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
159
                }
160

    
161
                // typelabel will contain the typeStatus
162
                $type_label = '';
163
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
164
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
165
                    $type_status = array();
166
                    foreach ($typeDesignationPager->records as $typeDesignation) {
167
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
168
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
169
                        }
170
                    }
171
                    $type_label = implode(', ', $type_status);
172
                    if($type_label){
173
                        $type_label .= ': ' ;
174
                    }
175
                }
176

    
177
                // --- Specimen entry as dynamic label:
178
                //     -> Dynabox for the specimenOrObservation
179
                $gallery_name = $specimenOrObservation->uuid;
180

    
181
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
182
                $label_html = cdm_dynabox(
183
                  $specimenOrObservation->uuid,
184
                  $type_label . $specimenOrObservation->titleCache,
185
                  $derived_unit_ws_request,
186
                  'cdm_specimenOrObservation',
187
                  'Click for details',
188
                  array('div', 'div'),
189
                  array(),
190
                  null, // $content_element_selector
191
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
192
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
193
                );
194

    
195
                // --- Render associated media.
196
                $gallery_html = '';
197
                if (count($mediaList) > 0) {
198
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
199
                    $captionElements = array(
200
                        '#uri' => t('open media'),
201
                    );
202

    
203
                    $gallery_html = compose_cdm_media_gallerie(array(
204
                        'mediaList' => $mediaList,
205
                        'galleryName' => $gallery_name,
206
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
207
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
208
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
209
                        'captionElements' => $captionElements,
210
                        'mediaLinkType' => 'LIGHTBOX',
211
                        'alternativeMediaUri' => NULL,
212
                        'galleryLinkUri' => NULL,
213
                    ));
214
                }
215

    
216
                $specimen_table['#rows'][] = array(
217
                    // An array of table rows. Every row is an array of cells, or an associative array
218
                    'data' => array(
219
                        // Each cell can be either a string or an associative array
220
                        $label_html . $gallery_html
221
                    ),
222
                    'class' =>  array(
223
                        'descriptionElement',
224
                        'descriptionElement_IndividualsAssociation'
225
                    ),
226
                );
227
            }
228
        }
229

    
230
        $render_array['specimen_list'] = $specimen_table;
231
        $render_array['pager'] = markup_to_render_array(
232
            theme('cdm_pager', array(
233
                'pager' => $pager,
234
                'path' => $_REQUEST['q'],
235
                'parameters' => $_REQUEST,
236
            )),
237
            10 // weight
238
        );
239
    }
240
    RenderHints::popFromRenderStack();
241
    return $render_array;
242
}
243

    
244
/**
245
 * Creates the drupal render array for the derivate_hierarchy_table
246
 *
247
 * @param $field_unit_uuids array
248
 *  An array of uuids for cdm FieldUnit entities.
249
 *
250
 * @return array
251
 *  A drupal render array for a table
252
 *
253
 * @ingroup compose
254
 */
255
function compose_derivate_hierarchy_table($field_unit_uuids)
256
{
257
// get icon images
258
  $expand_icon = font_awesome_icon_markup(
259
    'fa-plus-square-o',
260
    array(
261
      'alt' => 'Show details',
262
      'class' => array('expand_icon')
263
    )
264
  );
265
  $collapse_icon = font_awesome_icon_markup(
266
    'fa-minus-square-o',
267
    array(
268
      'alt' => 'Show details',
269
      'class' => array('collapse_icon')
270
    )
271
  );
272
  $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
273
  $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
274
  $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
275
  $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
276

    
277
  $rowcount = 0;
278
  $rows = array();
279

    
280
  foreach ($field_unit_uuids as $field_unit_uuid) {
281

    
282
    //get derivate hierarchy for the FieldUnit
283
    $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($field_unit_uuid, 'derivateHierarchy'));
284
    if ($derivateHierarchy) {
285
      //summary row
286
      $rows[] = array(
287
        'data' => array(
288
          array(
289
            'data' => $expand_icon . $collapse_icon,
290
            'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
291
          ),
292
          array(
293
            'data' => $derivateHierarchy->country,
294
            'class' => array('summary_row_cell')
295
          ),
296
          array(
297
            'data' => $derivateHierarchy->date,
298
            'class' => array('summary_row_cell')
299
          ),
300
          array(
301
            'data' => $derivateHierarchy->collection,
302
            'class' => array('summary_row_cell')
303
          ),
304
          array(
305
            'data' => $derivateHierarchy->herbarium,
306
            'class' => array('summary_row_cell')
307
          ),
308
          array(
309
            'data' => $derivateHierarchy->hasType ? $checked_box_icon : "",
310
            'class' => array('summary_row_cell', 'summary_row_icon')
311
          ),
312
          array(
313
            'data' => $derivateHierarchy->hasSpecimenScan ? $checked_box_icon : "",
314
            'class' => array('summary_row_cell', 'summary_row_icon')
315
          ),
316
          array(
317
            'data' => ($derivateHierarchy->hasDna ? $sequence_icon : "") . " "
318
              . ($derivateHierarchy->hasDetailImage ? $detail_image_icon : "") . " "
319
              . ($derivateHierarchy->hasCharacterData ? $character_data_icon : ""),
320
            'class' => array('summary_row_cell', 'summary_row_icon')
321
          )
322
        ),
323
        'id' => ('derivate_summary' . $rowcount), // summary row id
324
        'class' => array('summary_row'),
325
      );
326

    
327
      //assemble field unit details
328
      $detail_html = "";
329
      // - citation
330
      if ($derivateHierarchy->citation) {
331
        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
332
      }
333
      //assemble specimen details
334
      if ($derivateHierarchy->preservedSpecimenDTOs) {
335
        foreach ($derivateHierarchy->preservedSpecimenDTOs as $preservedSpecimenDTO) {
336
          $detail_html .= "<br>";
337
          $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
338
        }
339
      }
340
      $detail_html .= "<br>";
341
      //detail row resp. one BIG detail cell
342
      $rows[] = array(
343
        'data' => array(
344
          array(
345
            'data' => "", //empty first column
346
            'class' => array('expand_column')
347
          ),
348
          array(
349
            'data' => $detail_html,
350
            'colspan' => 7,
351
          ),
352
        ),
353
        'id' => ('derivate_details' . $rowcount),//details row ID
354
        'class' => array('detail_row'),
355
      );
356
      $rowcount++;
357
    }
358
  }
359

    
360
  $tableId = "derivate_hierarchy_table";
361
  $derivateHierarchyTable = array(
362
    "#theme" => "table",
363
    "#weight" => 2,
364
    "#header" => array(
365
      array(
366
        'data' => "",
367
        'class' => array('expand_column')
368
      ),
369
      "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
370
    "#rows" => $rows,
371
    "#attributes" => array(
372
      "id" => $tableId,
373
      "border" => 2
374
    )
375
  );
376

    
377
  //add toggle functionality to derivate hierarchy table
378
  drupal_add_js_rowToggle("#" . $tableId);
379

    
380
  return $derivateHierarchyTable;
381
}
382

    
383
function create_html_link($link, $openInExternalWindow=false){
384
    $html = "";
385
    if($link->uri && $link->uri!=""){
386
        $html .= '<a  href="' . $link->uri . '"';
387
        if($openInExternalWindow){
388
            $html .= ' target="_blank"';
389
        }
390
        $html .= '>' . $link->linkText . '</a>';
391
    }
392
    else{
393
        $html .= $link->linkText;
394
    }
395
    return $html;
396
}
397

    
398
/**
399
 * Creates HTML links from the given link list concatenated by default by a comma.
400
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
401
 * @return string the assembled HTML string containing the links
402
 */
403
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
404
{
405
    $html = "";
406
    if ($linkList) {
407
        foreach ($linkList as $link) {
408
            $html .= create_html_link($link, $openInExternalWindow).$separator;
409
        }
410
        $html = rtrim($html, $separator);
411
    }
412
    return $html;
413
}
414

    
415
/**
416
 * Composes a taxon page which can consist of multiple parts like
417
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
418
 * as tabs or as sections of a single page.
419
 *
420
 * It is headed by the name of the accepted taxon without author and reference.
421
 *
422
 * @param $taxon
423
 *   The CDM Taxon Instance to compose the page for.
424
 * @param $page_part
425
 *   Name of the part to display, valid values are:
426
 *    - 'description' -  for the general part
427
 *    - 'images'
428
 *    - 'synonymy'
429
 *    - 'keys'
430
 *    - 'all'
431
 *
432
 * @return array
433
 *   A drupal render array
434
 *
435
 * @ingroup compose
436
 */
437
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
438

    
439
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
440
  $http_request_params = drupal_get_query_parameters();
441

    
442
  // add all mandatory js sources
443
  _add_js_footnotes();
444

    
445

    
446
  $render_array = array();
447
  $weight = 0; // the weight for the render array elements
448

    
449
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
450

    
451
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
452

    
453
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
454
  if(!$synonymy_as_tab){
455
    unset($tabsToDisplay["Synonymy"]);
456
    // the synonymy is located in the general part in this case
457
    if($page_part == 'synonymy'){
458
      $page_part = 'description';
459
    }
460
  }
461

    
462
  $media = _load_media_for_taxon($taxon);
463

    
464

    
465
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
466
    taxon_page_tabs_hidden('images');
467
  }
468

    
469
  // --- GET specimensOrObservations --- //
470
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
471

    
472
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
473
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
474
    taxon_page_tabs_hidden('specimens');
475
  }
476

    
477
  // --- GET polytomousKeys --- //
478
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
479
  $identificationKeyCount = 0;
480
  if ($polytomousKeysPager) {
481
    $identificationKeyCount += $polytomousKeysPager->count;
482
  }
483
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
484
    taxon_page_tabs_hidden('keys');
485
  }
486

    
487
  // --- GET TaxonNodeAgentRelations --- //
488
  $current_classification_uuid = get_current_classification_uuid();
489
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
490
      array(
491
          $taxon->uuid,
492
          $current_classification_uuid,
493
      ),
494
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
495
  );
496
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
497
      taxon_page_tabs_hidden('experts');
498
  }
499

    
500
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
501
    taxon_page_tabs_hidden('synonymy');
502
  }
503

    
504
  // -------------------------------------------- //
505

    
506
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
507
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
508
  }
509

    
510
  // --- PAGE PART: DESCRIPTION --- //
511
  if ($page_part == 'description' || $page_part == 'all') {
512

    
513
    $merged_tree = merged_taxon_feature_tree($taxon);
514

    
515

    
516
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
517
    $render_array['general']['#weight'] = $weight++;
518
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
519
    $render_array['general']['#suffix'] = '</div>';
520
  }
521

    
522
  // --- PAGE PART: IMAGES --- //
523
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
524
    $images_html = '<div id="images" class="page-part">';
525
    if ($page_part == 'all') {
526
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
527
    }
528
    // Get the image gallery as configured by the admin.
529
    $default_image_gallery = 'default';
530
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
531
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
532
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
533
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
534
      // flash we also need to provide an the default gallery as alternative
535
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
536
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
537
          $taxon,
538
          $media,
539
        ))
540
        . '</div>';
541
    }
542
    if($configured_image_gallery_viewer == 'fsi'){
543
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
544
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
545
          $taxon,
546
          $media,
547
        ))
548
       . '</div>';
549
    }
550
    $images_html .= $taxon_image_gallery;
551
    $images_html .= '</div>';
552
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
553
  }
554

    
555
  // --- PAGE PART: SYNONYMY --- //
556
  if ((($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
557
    $synonymy_html = '<div id="synonymy" class="page-part">';
558
    if ($page_part == 'all') {
559
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
560
    }
561
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
562

    
563
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
564

    
565
    $synonymy_html .= '</div>';
566
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
567

    
568
  }
569

    
570
  // --- PAGE PART: SPECIMENS --- //
571
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
572
    $render_array['specimens'] = array(
573
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
574
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
575
        '#suffix' => '</div>',
576
    );
577
  }
578

    
579
  // --- PAGE PART: KEYS --- //
580
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
581
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
582
  }
583
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
584
    $keys_html = '<div id="keys" class="page-part">';
585
    if ($page_part == 'all') {
586
      $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
587
    }
588
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
589
    $keys_html .= '</div>';
590
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
591
  }
592

    
593
  // --- PAGE PART: EXPERTS --- //
594

    
595
  if (array_search('experts', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'experts' || $page_part == 'all')) {
596
    $render_array['experts'] = array(
597
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
598
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
599
        '#suffix' => '</div>',
600
    );
601
  }
602

    
603
  // ------------------ END OF PARTS -------------- //
604

    
605
  // adjust weights of page and toc elements according to the settings
606
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
607
  foreach($taxontabs_weights as $tab_key => $weight){
608
    if(isset($render_array[$tab_key])){
609
      $render_array[$tab_key]['#weight'] = $weight;
610
    }
611
  }
612

    
613

    
614
  // set up the TOC for the pages which contain all pageparts
615
  if($page_part == 'all') {
616

    
617
    asort($taxontabs_weights);
618
    foreach(array_keys($taxontabs_weights) as $tab_key){
619
      if(isset($render_array[$tab_key])){
620
        if($tab_key != 'general'){
621
          // add entry for page part
622
          $toc_elements[] = array(
623
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
624
              'class' => array('page-part-toc-item-' . $tab_key)
625
          );
626
        } else {
627
          // add content of profile part instead
628
          if(isset($render_array['general'])) {
629
            // in case all tabs are shown at once the feature tocs
630
            // should be integrated into the tabs toc as sub list
631
            // and the profile image should be on top of the page
632
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
633
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
634
              $toc_elements[] = $profile_toc_item;
635
            }
636
            unset($render_array['general']['taxon_description_feature_toc']);
637
            }
638
          }
639
        }
640
      }
641
    }
642

    
643
    // move profile image in page structure
644
    if(isset($render_array['general']['taxon_profile_image'])){
645
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
646
      $render_array['profile_image']['#weight'] = -100;
647
      unset($render_array['general']['taxon_profile_image']);
648
    }
649

    
650
    // finally add the table of contents to the render array
651
    $render_array['toc'] = array(
652
        '#theme' => 'item_list',
653
        '#items' => $toc_elements,
654
        '#title' => t('Content'),
655
        '#weight' => -101,
656
        '#suffix' => '</div>',
657
        '#prefix'=> '<div id="page-toc">'
658
    );
659
  }
660

    
661

    
662
  return $render_array;
663
}
664

    
665
/**
666
 * TODO should this function really be a compose function?
667
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
668
 *
669
 * composes and returns an render array containing the components of the taxon profile tab:
670
 *  - 'taxon_profile_image'
671
 *  - 'taxon_description_feature_toc'
672
 *  - 'taxon_description_features'
673
 *
674
 *
675
 * @param taxon
676
 * @param mergedTrees
677
 * @param media
678
 *
679
 * @return array
680
 *   A Drupal render array with the following elements:
681
 *     - 'taxon_profile_image'
682
 *     - 'taxon_description_feature_toc'
683
 *     - 'taxon_description_features'
684
 *
685
 * @ingroup compose
686
 */
687
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
688

    
689
  $render_array = array();
690

    
691
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
692

    
693
  $hide_taxon_profile_image = FALSE;
694
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
695
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
696
    $hide_taxon_profile_image = ($rankCompare > -1);
697
  }
698

    
699
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
700

    
701
    $representationPart = new stdClass();
702
    $attributes = array();
703
    if (isset($media[0])) {
704
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
705
      // which only contains the thumbnail representation even if the height and width filters are not set.
706
      // -->
707
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
708
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
709
        'image/jpg',
710
        'image/jpeg',
711
        'image/png',
712
        'image/gif',
713
      ),
714
        $taxon_profile_image_settings['maxextend'],
715
        $taxon_profile_image_settings['maxextend']
716
      );
717
      if(count($preferred_representations) > 0){
718

    
719
        $representation = array_shift($preferred_representations);
720
        $representationPart = $representation->parts[0];
721
        $attributes['alt'] = $representationPart->uri;
722

    
723
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
724
          $representationPart->uri = $representationPart->uri
725
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
726
            . $taxon_profile_image_settings['media_uri_query'];
727
        }
728
      }
729
    }
730
    else {
731
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
732
        // show placeholder image instead
733
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
734
          // use the user provided image
735
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
736
          $url = file_create_url($profile_image_file->uri);
737
          $image_info = image_get_info($profile_image_file->uri);
738
          $representationPart->width = $image_info['width'];
739
          $representationPart->height = $image_info['height'];
740
          $representationPart->uri = $url;
741
        }
742
        else {
743
          // use the hard coded default
744
          $representationPart->width = 184;
745
          $representationPart->height = 144;
746
          $representationPart->uri = base_path() . drupal_get_path('module',
747
              'cdm_dataportal') . '/images/no_picture.png';
748
        }
749
        $attributes['alt'] = "no image available";
750
      }
751
    }
752

    
753
    if (isset($representationPart->uri)) {
754
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
755
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
756
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
757
        -101);
758
    }
759
  }
760

    
761
  if($add_synonymy){
762
    $render_array['synonymy'] = markup_to_render_array(
763
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
764
      -102
765
    );
766
  }
767

    
768
  $pseudo_feature_blocks = array();
769
  $pseudo_feature_block_toc_items = array();
770

    
771

    
772
  // Render the sections for each real feature
773
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
774

    
775
  // Bibliography
776
  $bibliography_settings = get_bibliography_settings();
777
  if($bibliography_settings['enabled'] == 1){
778
    $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
779
    $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
780
    $bibliography_item = markup_to_render_array(FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''));
781
    $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
782

    
783
    if(!empty($bibliography_block->content)){
784
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
785
      $pseudo_feature_blocks[] = $bibliography_block;
786
    }
787
  }
788

    
789
  $render_array['taxon_description_features'] = _block_get_renderable_array(
790
    array_merge($feature_block_list, $pseudo_feature_blocks)
791
  );
792

    
793
  if($pseudo_feature_block_toc_items){
794
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
795
      cdm_toc_list_add_item($label, $fragment);
796
    }
797
  }
798

    
799
  // create the table of content
800
  $toc = array(
801
      '#theme' => 'item_list',
802
    '#items' => cdm_toc_list(),
803
      '#title' => t('Content'),
804
    '#weight' => -100,                  // move to the top
805
      '#suffix' => '</div>',
806
      '#prefix'=> '<div id="page-toc">'
807
  );
808
  $render_array['taxon_description_feature_toc'] = $toc;
809

    
810
  return $render_array;
811
}
812

    
813
/**
814
 * composes and returns an render array for the experts associated with the given taxon
815
 *
816
 * @param taxon
817
 *
818
 * @return array
819
 *   A Drupal render array for a table with the experts
820
 *
821
 * @ingroup compose
822
 */
823
function compose_cdm_taxon_page_experts($taxon){
824

    
825
  $render_array = array();
826
  if(!isset($taxon->uuid)){
827
    return $render_array;
828
  }
829

    
830
  $current_classification_uuid = get_current_classification_uuid();
831
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
832
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
833
    array(
834
      $taxon->uuid,
835
      $current_classification_uuid
836
    )
837
  );
838

    
839
  $header = array(
840
    array('data' => t('Expert')),
841
    array('data' => t('Role'))
842
  );
843
  $rows = array();
844

    
845

    
846
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
847

    
848

    
849
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
850
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
851

    
852
    $agent_label_markup = cdm_dynabox(
853
      'expert_' . $expert_role_id,
854
      $taxon_node_agent_relation->agent->titleCache,
855
      // specifying both ends of the relationship will return only one record in the pager
856
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
857
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
858
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
859
      'cdm_taxon_expert',
860
      'Click for details',
861
      array('div', 'div'),
862
      array(), // attributes
863
      '#' . $expert_details_container_id // $content_element_selector
864
    );
865

    
866
    // Expert and Role
867
    $rows[] = array(
868
      'data' => array(
869
        array(
870
          'data' => $agent_label_markup,
871
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
872
        ),
873
        array(
874
          'data' => $taxon_node_agent_relation->type->representation_L10n,
875
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
876
        )
877
      )
878
    );
879
    // Agent details
880
    $rows[] = array(
881
      'data' => array(
882
        array(
883
          'data' => '<!-- expert_details_container -->',
884
          'id' => $expert_details_container_id,
885
          'colspan' => 2
886
        )
887
      )
888
    );
889

    
890
  }
891

    
892

    
893
  $render_array['experts_table'] = array(
894
    '#theme' => 'table',
895
    '#header' => $header,
896
    '#rows' => $rows,
897
  );
898

    
899

    
900
  return $render_array;
901
}
902

    
903

    
904
/**
905
 * Manages the tabs to be hidden in the taxon page.
906
 *
907
 * The tabs are identified by their last menu link path element:
908
 *  - description
909
 *  - synonymy
910
 *  - images
911
 *  - specimens
912
 *  - key
913
 *
914
 * Internally the tabs are stored in a static variable which is
915
 * managed by drupal_static().
916
 *
917
 * @param string $add_tab
918
 *   Optional parameter. The given string will be added to the array of tabs
919
 *
920
 * @return
921
 *   The array of tabs
922
 */
923
function taxon_page_tabs_hidden($add_tab = NULL) {
924
  $tabs = &drupal_static(__FUNCTION__);
925

    
926
  if(!isset($tabs)){
927
    $tabs = array();
928
  }
929

    
930
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
931
    $tabs[] = $add_tab;
932
  }
933

    
934
  return $tabs;
935
}
936

    
937
/**
938
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
939
 *
940
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
941
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
942
 *
943
 * @param array $variables
944
 *   The variables array
945
 */
946
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
947

    
948
  $hidden_tabs = taxon_page_tabs_hidden();
949

    
950
  if (is_array($variables['primary'])) {
951
    foreach ($variables['primary'] as $key => &$element) {
952

    
953
      // 1. Remove the tabs to be hidden
954
      foreach ($hidden_tabs as $tab) {
955
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
956
          // remove the tab
957
          unset($variables['primary'][$key]);
958
        }
959
      }
960
    }
961
  }
962
}
963

    
964

    
965

    
966
/**
967
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
968
 *
969
 *
970
 * @param array $variables
971
 *   An associative array containing:
972
 *     - element: A render element containing:
973
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
974
 *          #active: A boolean indicating whether the local task is active.
975
 *
976
 */
977
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
978

    
979
  $link = $variables['element']['#link'];
980
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
981
    $link['title'] = '<img class="refresh" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/view-refresh.png' . '" alt="' . check_plain($link['title']) . '" title="' . check_plain($link['title']) . '"/>';
982
    $link['localized_options']['html'] = TRUE;
983

    
984
    $variables['element']['#link'] = $link;
985
  }
986
}
987

    
988
/* =================== block composition ===================== */
989

    
990
/**
991
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
992
 *
993
 * @param taxon
994
 *
995
 * @return array
996
 *   A Drupal render array for a table with the experts
997
 *
998
 * @ingroup compose
999
 */
1000
function compose_classification_breadcrumbs($taxon_uuid) {
1001

    
1002
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1003

    
1004
  $render_array = array();
1005

    
1006
  $render_array['#theme'] = 'item_list';
1007
  $render_array['#type'] = 'ul';
1008
  $render_array['#attributes'] = array(
1009
    'id' => 'classification-breadcrumbs',
1010
    'class' => 'breadcrumbs inline',
1011
  );
1012

    
1013
  $items = array();
1014

    
1015
  $parent_taxon_nodes = null;
1016
  if($taxon_uuid){
1017
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1018
  }
1019

    
1020
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1021
  // find current classification in list
1022
  $classification = null;
1023
  $current_classification_uuid = get_current_classification_uuid();
1024
  foreach ($classifications as $classification){
1025
    if($classification->uuid == $current_classification_uuid){
1026
      break;
1027
    }
1028
  }
1029

    
1030
  $node_name = '';
1031
  if(count($classifications) > 1 ){
1032
    // need to add the current classification as first label
1033

    
1034
    $label = $classification->titleCache;
1035
    if(strlen($label) > 20){
1036
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1037
    }
1038
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1039
      'attributes' => array(
1040
        'class' => 'taxonomic-children-button classification-chooser',
1041
        'data-destination-uri' => drupal_get_destination(),
1042
        'data-cdm-align-with' => array('prev')
1043
      ),
1044
      'html' => true
1045
    ));
1046
  }
1047

    
1048
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1049

    
1050
  $rank_separator = '<span> '
1051
    . font_awesome_icon_markup('fa-chevron-right')
1052
    . ' </span>';
1053
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1054
  $more_children_label = '...';
1055

    
1056
  $items[] = $node_name;
1057

    
1058
  $more_children_for = null;
1059
  if($parent_taxon_nodes){
1060
    foreach ($parent_taxon_nodes as $node) {
1061

    
1062
      $is_first_item = count($items) == 0;
1063
      $is_last_item = count($items) == count($parent_taxon_nodes);
1064
      $node_name = cdm_dataportal_shortname_of($node);
1065
      $path = path_to_taxon($node->taxonUuid);
1066

    
1067
      if($node->taxonomicChildrenCount > 0) {
1068
        $more_children_for = $node->taxonUuid;
1069
      } else {
1070
        $more_children_for = null;
1071
      }
1072

    
1073
      // 'fa-sitemap'
1074

    
1075
      $items[] =
1076
        ($is_first_item ? '' : ' ')
1077
        . $rank_separator
1078
        . l(
1079
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1080
          $path,
1081
          array(
1082
            'attributes' => array(
1083
              'class' => array('taxonomic-children-button'),
1084
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1085
              'data-cdm-classification-mode' => array('siblings'),
1086
              'data-cdm-align-with' => array('prev')
1087
            ),
1088
            'html' => true
1089
          )
1090
        );
1091
      }
1092
    }
1093

    
1094
  // add more button to the end
1095
  if(!$parent_taxon_nodes) {
1096
    // not taxon focused yet, adding button to make  the root nodes available
1097
    $items[] = '<span>'
1098
      . $more_children_icon . '&nbsp;' .
1099
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1100
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1101
      . '</span>';
1102
  } else if($more_children_for){
1103
    // last parent item has child taxon nodes
1104
    $items[] = ' <span>'
1105
      . $more_children_icon . '&nbsp;' .
1106
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1107
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1108
      . '</span>';
1109

    
1110
  }
1111

    
1112
  $render_array['#items'] = $items;
1113

    
1114
  return $render_array;
1115
}
1116

    
1117

    
1118
/**
1119
 * @param $specimen_uuid
1120
 * @return array
1121
 *    The drupal render array for the page
1122
 *
1123
 * @ingroup compose
1124
 */
1125
function compose_cdm_specimen_page($specimen_uuid)
1126
{
1127
  drupal_set_title("Specimen Details");
1128
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1129

    
1130
  $render_array = array();
1131
  RenderHints::pushToRenderStack('specimen_page');
1132

    
1133
  $detail_html = render_cdm_specimen_page($specimen, true);
1134
  $render_array['specimen_html'] = array(
1135
    '#markup' => $detail_html
1136
  );
1137

    
1138
  RenderHints::popFromRenderStack();
1139
  return $render_array;
1140
}
1141

    
1142
/**
1143
 * @param $named_area_uuid
1144
 * @return array
1145
 *    The drupal render array for the page
1146
 *
1147
 * @ingroup compose
1148
 */
1149
function compose_cdm_named_area_page($named_area_uuid)
1150
{
1151

    
1152
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1153

    
1154
  $render_array = array();
1155
  RenderHints::pushToRenderStack('named_area_page');
1156

    
1157
  $groups = array();
1158
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1159
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1160
  if(isset($named_area->level)) {
1161
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1162
  }
1163

    
1164
  $name_area_details_elements = array(
1165
   // '#title' => $title,
1166
    '#theme' => 'description_list',
1167
    '#groups' => $groups,
1168
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1169
  );
1170

    
1171
  $render_array[] = $name_area_details_elements;
1172

    
1173
  RenderHints::popFromRenderStack();
1174
  return $render_array;
1175
}
1176

    
1177
/**
1178
 * Provides the the label string for taxon page tabs.
1179
 *
1180
 * The $tabname as passed to the method will be returned if no override
1181
 * label is configured in the settings.
1182
 */
1183
function cdm_taxonpage_tab_label($tabname) {
1184
  static $taxon_tabs_labels = null;
1185
  if($taxon_tabs_labels == null){
1186
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1187
  }
1188
  $tabname_key = strtolower($tabname);
1189
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1190
    return $taxon_tabs_labels[$tabname_key];
1191
  }
1192
  return $tabname;
1193
}
(7-7/10)