Project

General

Profile

Download (43.4 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
        $pagerFieldUnits = 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
        // get icon images
119
        $expand_icon = font_awesome_icon_markup(
120
            'fa-plus-square-o',
121
            array(
122
                'alt'=>'Show details',
123
                'class' => array('expand_icon')
124
            )
125
        );
126
        $collapse_icon = font_awesome_icon_markup(
127
            'fa-minus-square-o',
128
            array(
129
                'alt'=>'Show details',
130
                'class' => array('collapse_icon')
131
            )
132
        );
133
        $detail_image_icon = '<img title="Detail Image" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/detail_image_derivate-16x16-32.png' . '"/>';
134
        $checked_box_icon = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/step_done.gif' . '"/>';
135
        $sequence_icon = '<img title="Molecular Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/sequence_derivate-16x16-32.png' . '"/>';
136
        $character_data_icon = '<img title="Character Data" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/character_data_derivate-16x16-32.png' . '"/>';
137
        if (isset($pagerFieldUnits->records[0])) {
138
            $rowcount = 0;
139
            foreach ($pagerFieldUnits->records as $fieldUnit) {
140
                //get derivate hierarchy for the FieldUnit
141
                $derivateHierarchy = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($fieldUnit->uuid, 'derivateHierarchy'), 'taxonUuid=' . $taxon->uuid);
142
                if($derivateHierarchy){
143
                    //summary row
144
                    $rows[] = array(
145
                        'data' => array(
146
                            array(
147
                                'data' => $expand_icon . $collapse_icon,
148
                                'class' => array('summary_row_cell', 'summary_row_icon', 'expand_column')
149
                            ),
150
                            array(
151
                                'data' => $derivateHierarchy->country,
152
                                'class' => array('summary_row_cell')
153
                            ),
154
                            array(
155
                                'data' => $derivateHierarchy->date,
156
                                'class' => array('summary_row_cell')
157
                            ),
158
                            array(
159
                                'data' => $derivateHierarchy->collection,
160
                                'class' => array('summary_row_cell')
161
                            ),
162
                            array(
163
                                'data' => $derivateHierarchy->herbarium,
164
                                'class' => array('summary_row_cell')
165
                            ),
166
                            array(
167
                                'data' => $derivateHierarchy->hasType? $checked_box_icon:"",
168
                                'class' => array('summary_row_cell', 'summary_row_icon')
169
                            ),
170
                            array(
171
                                'data' => $derivateHierarchy->hasSpecimenScan? $checked_box_icon:"",
172
                                'class' => array('summary_row_cell', 'summary_row_icon')
173
                            ),
174
                            array(
175
                                'data' => ($derivateHierarchy->hasDna? $sequence_icon :"")." "
176
                                    .($derivateHierarchy->hasDetailImage?$detail_image_icon:"")." "
177
                                    .($derivateHierarchy->hasCharacterData?$character_data_icon:""),
178
                                'class' => array('summary_row_cell', 'summary_row_icon')
179
                            )
180
                        ),
181
                        'id' => ('derivate_summary' . $rowcount), // summary row id
182
                        'class' => array('summary_row'),
183
                    );
184

    
185
                    //assemble field unit details
186
                    $detail_html = "";
187
                    // - taxon name
188
                    if (variable_get('cdm_dataportal_compressed_specimen_derivate_table_show_determined_as') && $derivateHierarchy->taxonName) {
189
                        $detail_html .= create_label("Associated with") . $derivateHierarchy->taxonName . "<br>";
190
                    }
191
                    // - protologue
192
                    if ($derivateHierarchy->protologue) {
193
                        //$detail_html .= "<strong>Protologue:</strong> " . $derivateHierarchy->protologue . "<br>"
194
                    }
195
                    // - citation
196
                    if ($derivateHierarchy->citation) {
197
                        $detail_html .= create_label("Citation") . $derivateHierarchy->citation . "<br>";
198
                    }
199
                    //assemble specimen details
200
                    if($derivateHierarchy->preservedSpecimenDTOs){
201
                        foreach($derivateHierarchy->preservedSpecimenDTOs as $preservedSpecimenDTO) {
202
                            $detail_html .= "<br>";
203
                            $detail_html .= render_cdm_specimen_page($preservedSpecimenDTO);
204
                        }
205
                    }
206
                    $detail_html .= "<br>";
207
                    //detail row resp. one BIG detail cell
208
                    $rows[] = array(
209
                        'data' => array(
210
                            array(
211
                                'data' => "", //empty first column
212
                                'class' => array('expand_column')
213
                            ),
214
                            array(
215
                                'data' => $detail_html,
216
                                'colspan' => 7,
217
                            ),
218
                        ),
219
                        'id' => ('derivate_details' . $rowcount),//details row ID
220
                        'class' => array('detail_row'),
221
                    );
222
                    $rowcount++;
223
                }
224
            }
225

    
226
            $tableId = "derivate_hierarchy_table";
227
            $derivateHierarchyTable = array(
228
                "#theme" => "table",
229
                "#weight" => 2,
230
                "#header" => array(
231
                    array(
232
                        'data' => "",
233
                        'class' => array('expand_column')
234
                    ),
235
                    "Country", "Date", "Collector + collecting number", "Herbaria", "Type", "Scan", "Derivatives"),
236
                "#rows" => $rows,
237
                "#attributes" => array(
238
                    "id" => $tableId,
239
                    "border" => 2
240
                )
241
            );
242

    
243
            //add toggle functionality to derivate hierarchy table
244
            drupal_add_js_rowToggle("#".$tableId);
245

    
246
            $render_array['derivate_hierarchy_table'] = $derivateHierarchyTable;
247
            $render_array['pager'] = markup_to_render_array(
248
                theme('cdm_pager', array(
249
                    'pager' => $pagerFieldUnits,
250
                    'path' => $_REQUEST['q'],
251
                    'parameters' => $_REQUEST
252
                )),
253
                10 // weight
254
            );
255
        }
256
    }
257
    else{
258
        //BOTTOM-UP-SPECIMEN-TABLE
259
        // --- generate the specimen list as table
260
        $specimen_table = array(
261
            '#theme' => 'table',
262
            '#weight' => 2,
263
            // prefix attributes and rows with '#' to let it pass to the theme function,
264
            // otherwise it is handled as child render array
265
            '#attributes' => array('class' => 'specimens'),
266
            '#rows' => array(),
267
        );
268

    
269
        if ($specimensOrObservations) {
270

    
271
            foreach ($specimensOrObservations as $specimenOrObservation) {
272

    
273
                $mediaList = array();
274
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
275
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
276
                }
277
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
278
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
279
                }
280

    
281
                // typelabel will contain the typeStatus
282
                $type_label = '';
283
                $typeDesignationPager = cdm_ws_get(CDM_WS_OCCURRENCE . '/$0/specimenTypeDesignations', $specimenOrObservation->uuid);
284
                if (isset($typeDesignationPager) and isset($typeDesignationPager->records)) {
285
                    $type_status = array();
286
                    foreach ($typeDesignationPager->records as $typeDesignation) {
287
                        if (isset($typeDesignation->typeStatus->representation_L10n)){
288
                            $type_status[] = $typeDesignation->typeStatus->representation_L10n;
289
                        }
290
                    }
291
                    $type_label = implode(', ', $type_status);
292
                    if($type_label){
293
                        $type_label .= ': ' ;
294
                    }
295
                }
296

    
297
                // --- Specimen entry as dynamic label:
298
                //     -> Dynabox for the specimenOrObservation
299
                $gallery_name = $specimenOrObservation->uuid;
300

    
301
                $derived_unit_ws_request = cdm_compose_url(CDM_WS_OCCURRENCE, array( $specimenOrObservation->uuid));
302
                $label_html = cdm_dynabox(
303
                  $specimenOrObservation->uuid,
304
                  $type_label . $specimenOrObservation->titleCache,
305
                  $derived_unit_ws_request,
306
                  'cdm_specimenOrObservation',
307
                  'Click for details',
308
                  array('div', 'div'),
309
                  array(),
310
                  null, // $content_element_selector
311
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').hide(); }', // open_callback
312
                  'function(){ jQuery(\'#media_gallery_' . $gallery_name . '\').show(); }' // close_callback
313
                );
314

    
315
                // --- Render associated media.
316
                $gallery_html = '';
317
                if (count($mediaList) > 0) {
318
                    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SPECIMEN_GALLERY_NAME);
319
                    $captionElements = array(
320
                        '#uri' => t('open media'),
321
                    );
322

    
323
                    $gallery_html = compose_cdm_media_gallerie(array(
324
                        'mediaList' => $mediaList,
325
                        'galleryName' => $gallery_name,
326
                        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
327
                        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
328
                        'maxRows' => isset($gallery_settings['cdm_dataportal_media_maxRows']) ? isset($gallery_settings['cdm_dataportal_media_maxRows']) : null,
329
                        'captionElements' => $captionElements,
330
                        'mediaLinkType' => 'LIGHTBOX',
331
                        'alternativeMediaUri' => NULL,
332
                        'galleryLinkUri' => NULL,
333
                    ));
334
                }
335

    
336
                $specimen_table['#rows'][] = array(
337
                    // An array of table rows. Every row is an array of cells, or an associative array
338
                    'data' => array(
339
                        // Each cell can be either a string or an associative array
340
                        $label_html . $gallery_html
341
                    ),
342
                    'class' =>  array(
343
                        'descriptionElement',
344
                        'descriptionElement_IndividualsAssociation'
345
                    ),
346
                );
347
            }
348
        }
349

    
350
        $render_array['specimen_list'] = $specimen_table;
351
        $render_array['pager'] = markup_to_render_array(
352
            theme('cdm_pager', array(
353
                'pager' => $pager,
354
                'path' => $_REQUEST['q'],
355
                'parameters' => $_REQUEST,
356
            )),
357
            10 // weight
358
        );
359
    }
360
    RenderHints::popFromRenderStack();
361
    return $render_array;
362
}
363
 
364
function create_html_link($link, $openInExternalWindow=false){
365
    $html = "";
366
    if($link->uri && $link->uri!=""){
367
        $html .= '<a  href="' . $link->uri . '"';
368
        if($openInExternalWindow){
369
            $html .= ' target="_blank"';
370
        }
371
        $html .= '>' . $link->linkText . '</a>';
372
    }
373
    else{
374
        $html .= $link->linkText;
375
    }
376
    return $html;
377
}
378

    
379
/**
380
 * Creates HTML links from the given link list concatenated by default by a comma.
381
 * @param $linkList the list with Link objects having "uri" and "linkText" as members
382
 * @return string the assembled HTML string containing the links
383
 */
384
function create_html_links($linkList, $openInExternalWindow=false, $separator=", ")
385
{
386
    $html = "";
387
    if ($linkList) {
388
        foreach ($linkList as $link) {
389
            $html .= create_html_link($link, $openInExternalWindow).$separator;
390
        }
391
        $html = rtrim($html, $separator);
392
    }
393
    return $html;
394
}
395

    
396
/**
397
 * Composes a taxon page which can consist of multiple parts like
398
 * 'General', 'Synonymy', 'Images', 'Keys'. These parts can be displayed
399
 * as tabs or as sections of a single page.
400
 *
401
 * It is headed by the name of the accepted taxon without author and reference.
402
 *
403
 * @param $taxon
404
 *   The CDM Taxon Instance to compose the page for.
405
 * @param $page_part
406
 *   Name of the part to display, valid values are:
407
 *    - 'description' -  for the general part
408
 *    - 'images'
409
 *    - 'synonymy'
410
 *    - 'keys'
411
 *    - 'all'
412
 *
413
 * @return array
414
 *   A drupal render array
415
 *
416
 * @ingroup compose
417
 */
418
function compose_cdm_taxon_page($taxon, $page_part = 'description') {
419

    
420
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
421
  $http_request_params = drupal_get_query_parameters();
422

    
423
  // add all mandatory js sources
424
  _add_js_footnotes();
425

    
426

    
427
  $render_array = array();
428
  $weight = 0; // the weight for the render array elements
429

    
430
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
431

    
432
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
433

    
434
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
435
  if(!$synonymy_as_tab){
436
    unset($tabsToDisplay["Synonymy"]);
437
    // the synonymy is located in the general part in this case
438
    if($page_part == 'synonymy'){
439
      $page_part = 'description';
440
    }
441
  }
442

    
443
  $media = _load_media_for_taxon($taxon);
444

    
445

    
446
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
447
    taxon_page_tabs_hidden('images');
448
  }
449

    
450
  // --- GET specimensOrObservations --- //
451
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
452

    
453
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
454
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
455
    taxon_page_tabs_hidden('specimens');
456
  }
457

    
458
  // --- GET polytomousKeys --- //
459
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
460
  $identificationKeyCount = 0;
461
  if ($polytomousKeysPager) {
462
    $identificationKeyCount += $polytomousKeysPager->count;
463
  }
464
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
465
    taxon_page_tabs_hidden('keys');
466
  }
467

    
468
  // --- GET TaxonNodeAgentRelations --- //
469
  $current_classification_uuid = get_current_classification_uuid();
470
  $taxon_node_agent_relations_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
471
      array(
472
          $taxon->uuid,
473
          $current_classification_uuid,
474
      ),
475
      "pageSize=1&pageIndex=0"// we are only interested into the count so we are fetching only one item, o is not possible!
476
  );
477
  if (!$taxon_node_agent_relations_pager || $taxon_node_agent_relations_pager->count == 0){
478
      taxon_page_tabs_hidden('experts');
479
  }
480

    
481
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
482
    taxon_page_tabs_hidden('synonymy');
483
  }
484

    
485
  // -------------------------------------------- //
486

    
487
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
488
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
489
  }
490

    
491
  // --- PAGE PART: DESCRIPTION --- //
492
  if ($page_part == 'description' || $page_part == 'all') {
493

    
494
    $merged_tree = merged_taxon_feature_tree($taxon);
495

    
496

    
497
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
498
    $render_array['general']['#weight'] = $weight++;
499
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
500
    $render_array['general']['#suffix'] = '</div>';
501
  }
502

    
503
  // --- PAGE PART: IMAGES --- //
504
  if (array_search('images', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'images' || $page_part == 'all')) {
505
    $images_html = '<div id="images" class="page-part">';
506
    if ($page_part == 'all') {
507
      $images_html .= '<h2>' . t(cdm_taxonpage_tab_label('Images')) . '</h2>';
508
    }
509
    // Get the image gallery as configured by the admin.
510
    $default_image_gallery = 'default';
511
    $configured_image_gallery_viewer = variable_get('image_gallery_viewer', 'default');
512
    $taxon_image_gallery = '<div class="error">No image gallery viewer configured</div>';
513
    if($configured_image_gallery_viewer == $default_image_gallery || $configured_image_gallery_viewer == 'fsi'){
514
      // the fsi_gallery requires a flash plugin, in case the client browser is not supporting
515
      // flash we also need to provide an the default gallery as alternative
516
      $taxon_image_gallery = '<div id="default-gallery-viewer">' .
517
        call_user_func_array('taxon_image_gallery_' . $default_image_gallery, array(
518
          $taxon,
519
          $media,
520
        ))
521
        . '</div>';
522
    }
523
    if($configured_image_gallery_viewer == 'fsi'){
524
      $taxon_image_gallery .= '<div id="'. $configured_image_gallery_viewer .'-gallery-viewer">' .
525
        call_user_func_array('taxon_image_gallery_' . $configured_image_gallery_viewer, array(
526
          $taxon,
527
          $media,
528
        ))
529
       . '</div>';
530
    }
531
    $images_html .= $taxon_image_gallery;
532
    $images_html .= '</div>';
533
    $render_array['images'] = markup_to_render_array($images_html, $weight++);
534
  }
535

    
536
  // --- PAGE PART: SYNONYMY --- //
537
  if ((($page_part == 'synonymy' || $page_part == 'all') && $synonymy_as_tab)) {
538
    $synonymy_html = '<div id="synonymy" class="page-part">';
539
    if ($page_part == 'all') {
540
      $synonymy_html .= '<h2>' . t(cdm_taxonpage_tab_label('Synonymy')) . '</h2>';
541
    }
542
    $addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
543

    
544
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
545

    
546
    $synonymy_html .= '</div>';
547
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
548

    
549
  }
550

    
551
  // --- PAGE PART: SPECIMENS --- //
552
  if ($specimensOrObservationsCount > 0 && ($page_part == 'specimens' || $page_part == 'all')) {
553
    $render_array['specimens'] = array(
554
        '#prefix' => '<div id="specimens" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Specimens')) . '</h2>' : ''),
555
        'content' => cdm_dataportal_taxon_page_specimens($taxon), // returns render array
556
        '#suffix' => '</div>',
557
    );
558
  }
559

    
560
  // --- PAGE PART: KEYS --- //
561
  if ($identificationKeyCount == 1 && $page_part == 'keys'){
562
    drupal_goto(path_to_key($polytomousKeysPager->records[0]->class, $polytomousKeysPager->records[0]->uuid));
563
  }
564
  else if ($identificationKeyCount > 0 && ($page_part == 'keys' || $page_part == 'all')) {
565
    $keys_html = '<div id="keys" class="page-part">';
566
    if ($page_part == 'all') {
567
      $keys_html .= '<h2>' . t(cdm_taxonpage_tab_label('Keys')) . '</h2>';
568
    }
569
    $keys_html .= theme('cdm_block_IdentificationKeys', array('taxonUuid' => $taxon->uuid));
570
    $keys_html .= '</div>';
571
    $render_array['keys'] = markup_to_render_array($keys_html, $weight++);
572
  }
573

    
574
  // --- PAGE PART: EXPERTS --- //
575

    
576
  if (array_search('experts', taxon_page_tabs_hidden()) === FALSE && ($page_part == 'experts' || $page_part == 'all')) {
577
    $render_array['experts'] = array(
578
        '#prefix' => '<div id="experts" class="page-part">' . ($page_part == 'all' ? '<h2>' . t(cdm_taxonpage_tab_label('Experts')) . '</h2>' : ''),
579
        'content' => compose_cdm_taxon_page_experts($taxon), // returns render array
580
        '#suffix' => '</div>',
581
    );
582
  }
583

    
584
  // ------------------ END OF PARTS -------------- //
585

    
586
  // adjust weights of page and toc elements according to the settings
587
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
588
  foreach($taxontabs_weights as $tab_key => $weight){
589
    if(isset($render_array[$tab_key])){
590
      $render_array[$tab_key]['#weight'] = $weight;
591
    }
592
  }
593

    
594

    
595
  // set up the TOC for the pages which contain all pageparts
596
  if($page_part == 'all') {
597

    
598
    asort($taxontabs_weights);
599
    foreach(array_keys($taxontabs_weights) as $tab_key){
600
      if(isset($render_array[$tab_key])){
601
        if($tab_key != 'general'){
602
          // add entry for page part
603
          $toc_elements[] = array(
604
              'data' => l(t(cdm_taxonpage_tab_label(ucfirst($tab_key))), $_GET['q'], array('fragment' => $tab_key, 'query' => $http_request_params)),
605
              'class' => array('page-part-toc-item-' . $tab_key)
606
          );
607
        } else {
608
          // add content of profile part instead
609
          if(isset($render_array['general'])) {
610
            // in case all tabs are shown at once the feature tocs
611
            // should be integrated into the tabs toc as sub list
612
            // and the profile image should be on top of the page
613
            if(isset($render_array['general']['taxon_description_feature_toc'])){;
614
            foreach ($render_array['general']['taxon_description_feature_toc']['#items'] as $profile_toc_item){
615
              $toc_elements[] = $profile_toc_item;
616
            }
617
            unset($render_array['general']['taxon_description_feature_toc']);
618
            }
619
          }
620
        }
621
      }
622
    }
623

    
624
    // move profile image in page structure
625
    if(isset($render_array['general']['taxon_profile_image'])){
626
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
627
      $render_array['profile_image']['#weight'] = -100;
628
      unset($render_array['general']['taxon_profile_image']);
629
    }
630

    
631
    // finally add the table of contents to the render array
632
    $render_array['toc'] = array(
633
        '#theme' => 'item_list',
634
        '#items' => $toc_elements,
635
        '#title' => t('Content'),
636
        '#weight' => -101,
637
        '#suffix' => '</div>',
638
        '#prefix'=> '<div id="page-toc">'
639
    );
640
  }
641

    
642

    
643
  return $render_array;
644
}
645

    
646
/**
647
 * TODO should this function really be a compose function?
648
 *     For a compose function must there always be a theme function with the same name? (ak 8.8.2013)
649
 *
650
 * composes and returns an render array containing the components of the taxon profile tab:
651
 *  - 'taxon_profile_image'
652
 *  - 'taxon_description_feature_toc'
653
 *  - 'taxon_description_features'
654
 *
655
 *
656
 * @param taxon
657
 * @param mergedTrees
658
 * @param media
659
 *
660
 * @return array
661
 *   A Drupal render array with the following elements:
662
 *     - 'taxon_profile_image'
663
 *     - 'taxon_description_feature_toc'
664
 *     - 'taxon_description_features'
665
 *
666
 * @ingroup compose
667
 */
668
function compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, $add_synonymy) {
669

    
670
  $render_array = array();
671

    
672
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
673

    
674
  $hide_taxon_profile_image = FALSE;
675
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
676
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
677
    $hide_taxon_profile_image = ($rankCompare > -1);
678
  }
679

    
680
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
681

    
682
    $representationPart = new stdClass();
683
    $attributes = array();
684
    if (isset($media[0])) {
685
      // due to a bug the portal/taxon/{uuid}/media service only delivers a filtered media object
686
      // which only contains the thumbnail representation even if the height and width filters are not set.
687
      // -->
688
      $preferred_media = cdm_ws_get(CDM_WS_MEDIA, $media[0]->uuid);
689
      $preferred_representations = cdm_preferred_media_representations($preferred_media, array(
690
        'image/jpg',
691
        'image/jpeg',
692
        'image/png',
693
        'image/gif',
694
      ),
695
        $taxon_profile_image_settings['maxextend'],
696
        $taxon_profile_image_settings['maxextend']
697
      );
698
      if(count($preferred_representations) > 0){
699

    
700
        $representation = array_shift($preferred_representations);
701
        $representationPart = $representation->parts[0];
702
        $attributes['alt'] = $representationPart->uri;
703

    
704
        if (!empty($taxon_profile_image_settings['media_uri_query'])) {
705
          $representationPart->uri = $representationPart->uri
706
            . (strpos($representationPart->uri, '?') !== FALSE ? '&' : '?')
707
            . $taxon_profile_image_settings['media_uri_query'];
708
        }
709
      }
710
    }
711
    else {
712
      if ($taxon_profile_image_settings['custom_placeholder_enabled']) {
713
        // show placeholder image instead
714
        if (!empty($taxon_profile_image_settings['custom_placeholder_image_on']) && !empty($taxon_profile_image_settings['custom_placeholder_image_fid'])) {
715
          // use the user provided image
716
          $profile_image_file = file_load($taxon_profile_image_settings['custom_placeholder_image_fid']);
717
          $url = file_create_url($profile_image_file->uri);
718
          $image_info = image_get_info($profile_image_file->uri);
719
          $representationPart->width = $image_info['width'];
720
          $representationPart->height = $image_info['height'];
721
          $representationPart->uri = $url;
722
        }
723
        else {
724
          // use the hard coded default
725
          $representationPart->width = 184;
726
          $representationPart->height = 144;
727
          $representationPart->uri = base_path() . drupal_get_path('module',
728
              'cdm_dataportal') . '/images/no_picture.png';
729
        }
730
        $attributes['alt'] = "no image available";
731
      }
732
    }
733

    
734
    if (isset($representationPart->uri)) {
735
      $profile_image = cdm_media_gallerie_image($representationPart, $taxon_profile_image_settings['maxextend'], FALSE, $attributes);
736
      // NOTE: style="width:${maxextend}px' is needed for IE8 !!!
737
      $render_array['taxon_profile_image'] = markup_to_render_array('<div id="taxonProfileImage" style="width:' . $taxon_profile_image_settings['maxextend'] . 'px">' . $profile_image . '</div>',
738
        -101);
739
    }
740
  }
741

    
742
  if($add_synonymy){
743
    $render_array['synonymy'] = markup_to_render_array(
744
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
745
      -102
746
    );
747
  }
748

    
749
  $pseudo_feature_blocks = array();
750
  $pseudo_feature_block_toc_items = array();
751

    
752

    
753
  // Render the sections for each real feature
754
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
755

    
756
  // Bibliography
757
  $bibliography_settings = get_bibliography_settings();
758
  if($bibliography_settings['enabled'] == 1){
759
    $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
760
    $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
761
    $bibliography_item = markup_to_render_array(FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''));
762
    $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
763

    
764
    if(!empty($bibliography_block->content)){
765
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
766
      $pseudo_feature_blocks[] = $bibliography_block;
767
    }
768
  }
769

    
770
  $render_array['taxon_description_features'] = _block_get_renderable_array(
771
    array_merge($feature_block_list, $pseudo_feature_blocks)
772
  );
773

    
774
  if($pseudo_feature_block_toc_items){
775
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
776
      cdm_toc_list_add_item($label, $fragment);
777
    }
778
  }
779

    
780
  // create the table of content
781
  $toc = array(
782
      '#theme' => 'item_list',
783
    '#items' => cdm_toc_list(),
784
      '#title' => t('Content'),
785
    '#weight' => -100,                  // move to the top
786
      '#suffix' => '</div>',
787
      '#prefix'=> '<div id="page-toc">'
788
  );
789
  $render_array['taxon_description_feature_toc'] = $toc;
790

    
791
  return $render_array;
792
}
793

    
794
/**
795
 * composes and returns an render array for the experts associated with the given taxon
796
 *
797
 * @param taxon
798
 *
799
 * @return array
800
 *   A Drupal render array for a table with the experts
801
 *
802
 * @ingroup compose
803
 */
804
function compose_cdm_taxon_page_experts($taxon){
805

    
806
  $render_array = array();
807
  if(!isset($taxon->uuid)){
808
    return $render_array;
809
  }
810

    
811
  $current_classification_uuid = get_current_classification_uuid();
812
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
813
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
814
    array(
815
      $taxon->uuid,
816
      $current_classification_uuid
817
    )
818
  );
819

    
820
  $header = array(
821
    array('data' => t('Expert')),
822
    array('data' => t('Role'))
823
  );
824
  $rows = array();
825

    
826

    
827
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
828

    
829

    
830
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
831
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
832

    
833
    $agent_label_markup = cdm_dynabox(
834
      'expert_' . $expert_role_id,
835
      $taxon_node_agent_relation->agent->titleCache,
836
      // specifying both ends of the relationship will return only one record in the pager
837
      cdm_compose_url(CDM_WS_PORTAL_AGENT,
838
         array($taxon_node_agent_relation->agent->uuid, 'taxonNodeAgentRelations'),
839
        'taxon_uuid=' . $taxon->uuid . '&relType_uuid=' . $taxon_node_agent_relation->type->uuid),
840
      'cdm_taxon_expert',
841
      'Click for details',
842
      array('div', 'div'),
843
      array(), // attributes
844
      '#' . $expert_details_container_id // $content_element_selector
845
    );
846

    
847
    // Expert and Role
848
    $rows[] = array(
849
      'data' => array(
850
        array(
851
          'data' => $agent_label_markup,
852
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->agent))
853
        ),
854
        array(
855
          'data' => $taxon_node_agent_relation->type->representation_L10n,
856
          'class' => array(html_class_attribute_ref($taxon_node_agent_relation->type))
857
        )
858
      )
859
    );
860
    // Agent details
861
    $rows[] = array(
862
      'data' => array(
863
        array(
864
          'data' => '<!-- expert_details_container -->',
865
          'id' => $expert_details_container_id,
866
          'colspan' => 2
867
        )
868
      )
869
    );
870

    
871
  }
872

    
873

    
874
  $render_array['experts_table'] = array(
875
    '#theme' => 'table',
876
    '#header' => $header,
877
    '#rows' => $rows,
878
  );
879

    
880

    
881
  return $render_array;
882
}
883

    
884

    
885
/**
886
 * Manages the tabs to be hidden in the taxon page.
887
 *
888
 * The tabs are identified by their last menu link path element:
889
 *  - description
890
 *  - synonymy
891
 *  - images
892
 *  - specimens
893
 *  - key
894
 *
895
 * Internally the tabs are stored in a static variable which is
896
 * managed by drupal_static().
897
 *
898
 * @param string $add_tab
899
 *   Optional parameter. The given string will be added to the array of tabs
900
 *
901
 * @return
902
 *   The array of tabs
903
 */
904
function taxon_page_tabs_hidden($add_tab = NULL) {
905
  $tabs = &drupal_static(__FUNCTION__);
906

    
907
  if(!isset($tabs)){
908
    $tabs = array();
909
  }
910

    
911
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
912
    $tabs[] = $add_tab;
913
  }
914

    
915
  return $tabs;
916
}
917

    
918
/**
919
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
920
 *
921
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
922
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
923
 *
924
 * @param array $variables
925
 *   The variables array
926
 */
927
function cdm_dataportal_preprocess_menu_local_tasks(&$variables) {
928

    
929
  $hidden_tabs = taxon_page_tabs_hidden();
930

    
931
  if (is_array($variables['primary'])) {
932
    foreach ($variables['primary'] as $key => &$element) {
933

    
934
      // 1. Remove the tabs to be hidden
935
      foreach ($hidden_tabs as $tab) {
936
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
937
          // remove the tab
938
          unset($variables['primary'][$key]);
939
        }
940
      }
941
    }
942
  }
943
}
944

    
945

    
946

    
947
/**
948
 * Implements the hook_preprocess_HOOK() for theme_menu_local_task()
949
 *
950
 *
951
 * @param array $variables
952
 *   An associative array containing:
953
 *     - element: A render element containing:
954
 *          #link: A menu link array with 'title', 'href', and 'localized_options' keys.
955
 *          #active: A boolean indicating whether the local task is active.
956
 *
957
 */
958
function cdm_dataportal_preprocess_menu_local_task(&$variables) {
959

    
960
  $link = $variables['element']['#link'];
961
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
962
    $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']) . '"/>';
963
    $link['localized_options']['html'] = TRUE;
964

    
965
    $variables['element']['#link'] = $link;
966
  }
967
}
968

    
969
/* =================== block composition ===================== */
970

    
971
/**
972
 * Composes and returns an render array for the classification breadcrumbs of the given taxon.
973
 *
974
 * @param taxon
975
 *
976
 * @return array
977
 *   A Drupal render array for a table with the experts
978
 *
979
 * @ingroup compose
980
 */
981
function compose_classification_breadcrumbs($taxon_uuid) {
982

    
983
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
984

    
985
  $render_array = array();
986

    
987
  $render_array['#theme'] = 'item_list';
988
  $render_array['#type'] = 'ul';
989
  $render_array['#attributes'] = array(
990
    'id' => 'classification-breadcrumbs',
991
    'class' => 'breadcrumbs inline',
992
  );
993

    
994
  $items = array();
995

    
996
  $parent_taxon_nodes = null;
997
  if($taxon_uuid){
998
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
999
  }
1000

    
1001
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1002
  // find current classification in list
1003
  $classification = null;
1004
  $current_classification_uuid = get_current_classification_uuid();
1005
  foreach ($classifications as $classification){
1006
    if($classification->uuid == $current_classification_uuid){
1007
      break;
1008
    }
1009
  }
1010

    
1011
  $node_name = '';
1012
  if(count($classifications) > 1 ){
1013
    // need to add the current classification as first label
1014

    
1015
    $label = $classification->titleCache;
1016
    if(strlen($label) > 20){
1017
      $label = substr($label, 0, strpos($label, ' ', 15)) . '...';
1018
    }
1019
    $node_name = font_awesome_icon_markup('fa-th-list')  . ' ' . l($label, '#', array(
1020
      'attributes' => array(
1021
        'class' => 'taxonomic-children-button classification-chooser',
1022
        'data-destination-uri' => drupal_get_destination(),
1023
        'data-cdm-align-with' => array('prev')
1024
      ),
1025
      'html' => true
1026
    ));
1027
  }
1028

    
1029
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1030

    
1031
  $rank_separator = '<span> '
1032
    . font_awesome_icon_markup('fa-chevron-right')
1033
    . ' </span>';
1034
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1035
  $more_children_label = '...';
1036

    
1037
  $items[] = $node_name;
1038

    
1039
  $more_children_for = null;
1040
  if($parent_taxon_nodes){
1041
    foreach ($parent_taxon_nodes as $node) {
1042

    
1043
      $is_first_item = count($items) == 0;
1044
      $is_last_item = count($items) == count($parent_taxon_nodes);
1045
      $node_name = cdm_dataportal_shortname_of($node);
1046
      $path = path_to_taxon($node->taxonUuid);
1047

    
1048
      if($node->taxonomicChildrenCount > 0) {
1049
        $more_children_for = $node->taxonUuid;
1050
      } else {
1051
        $more_children_for = null;
1052
      }
1053

    
1054
      // 'fa-sitemap'
1055

    
1056
      $items[] =
1057
        ($is_first_item ? '' : ' ')
1058
        . $rank_separator
1059
        . l(
1060
          '<span class="' . html_class_attribute_ref($node) . '">' . $node_name . '</span>',
1061
          $path,
1062
          array(
1063
            'attributes' => array(
1064
              'class' => array('taxonomic-children-button'),
1065
              'data-cdm-taxon-uuid' => array($node->taxonUuid),
1066
              'data-cdm-classification-mode' => array('siblings'),
1067
              'data-cdm-align-with' => array('prev')
1068
            ),
1069
            'html' => true
1070
          )
1071
        );
1072
      }
1073
    }
1074

    
1075
  // add more button to the end
1076
  if(!$parent_taxon_nodes) {
1077
    // not taxon focused yet, adding button to make  the root nodes available
1078
    $items[] = '<span>'
1079
      . $more_children_icon . '&nbsp;' .
1080
      '<span class="taxonomic-children-button" data-classification-uuid="' . $current_classification_uuid
1081
      . '" data-rank-limit-uuid="' . $rank_limit_uuid . '" data-cdm-align-with="prev"> ' . $more_children_label . '<span>'
1082
      . '</span>';
1083
  } else if($more_children_for){
1084
    // last parent item has child taxon nodes
1085
    $items[] = ' <span>'
1086
      . $more_children_icon . '&nbsp;' .
1087
      '<span class="taxonomic-children-button" data-cdm-taxon-uuid="' .$more_children_for
1088
      . '" data-cdm-classification-mode="children" data-cdm-align-with="prev"> ' . $more_children_label . '</span>'
1089
      . '</span>';
1090

    
1091
  }
1092

    
1093
  $render_array['#items'] = $items;
1094

    
1095
  return $render_array;
1096
}
1097

    
1098

    
1099
/**
1100
 * @param $specimen_uuid
1101
 * @return array
1102
 *    The drupal render array for the page
1103
 *
1104
 * @ingroup compose
1105
 */
1106
function compose_cdm_specimen_page($specimen_uuid)
1107
{
1108
  drupal_set_title("Specimen Details");
1109
  $specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, array($specimen_uuid, 'specimenDerivates'));
1110

    
1111
  $render_array = array();
1112
  RenderHints::pushToRenderStack('specimen_page');
1113

    
1114
  $detail_html = render_cdm_specimen_page($specimen, true);
1115
  $render_array['specimen_html'] = array(
1116
    '#markup' => $detail_html
1117
  );
1118

    
1119
  RenderHints::popFromRenderStack();
1120
  return $render_array;
1121
}
1122

    
1123
/**
1124
 * @param $named_area_uuid
1125
 * @return array
1126
 *    The drupal render array for the page
1127
 *
1128
 * @ingroup compose
1129
 */
1130
function compose_cdm_named_area_page($named_area_uuid)
1131
{
1132

    
1133
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1134

    
1135
  $render_array = array();
1136
  RenderHints::pushToRenderStack('named_area_page');
1137

    
1138
  $groups = array();
1139
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1140
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1141
  if(isset($named_area->level)) {
1142
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1143
  }
1144

    
1145
  $name_area_details_elements = array(
1146
   // '#title' => $title,
1147
    '#theme' => 'description_list',
1148
    '#groups' => $groups,
1149
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1150
  );
1151

    
1152
  $render_array[] = $name_area_details_elements;
1153

    
1154
  RenderHints::popFromRenderStack();
1155
  return $render_array;
1156
}
1157

    
1158
/**
1159
 * Provides the the label string for taxon page tabs.
1160
 *
1161
 * The $tabname as passed to the method will be returned if no override
1162
 * label is configured in the settings.
1163
 */
1164
function cdm_taxonpage_tab_label($tabname) {
1165
  static $taxon_tabs_labels = null;
1166
  if($taxon_tabs_labels == null){
1167
    $taxon_tabs_labels = get_array_variable_merged(CDM_TAXONPAGE_TAB_LABELS, CDM_TAXONPAGE_TAB_LABELS_DEFAULT);
1168
  }
1169
  $tabname_key = strtolower($tabname);
1170
  if(isset($taxon_tabs_labels[$tabname_key]) && $taxon_tabs_labels[$tabname_key]){
1171
    return $taxon_tabs_labels[$tabname_key];
1172
  }
1173
  return $tabname;
1174
}
(7-7/10)