Project

General

Profile

Download (41.9 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
        $map_render_array = compose_map('specimens', $occurrence_query, $distribution_query, $legend_format_query, array());
103
      }
104
    }
105

    
106
    // -------------------------------------------------------
107
    $render_array['map'] = $map_render_array;
108

    
109
    if(variable_get('cdm_dataportal_compressed_specimen_derivate_table')){
110

    
111
        //COMPRESSED SPECIMEN DERIVATE TABLE
112
        $associatedFieldUnitsQuery_parameters = array();
113
        if (isset($_REQUEST['pager']) && is_array($_REQUEST['pager'])) {
114
            $associatedFieldUnitsQuery_parameters = array_merge($associatedFieldUnitsQuery_parameters, $_REQUEST['pager']);
115
        }
116

    
117
        $by_associatedtaxon_query = http_build_query($associatedFieldUnitsQuery_parameters);
118
        $pager_field_units = cdm_ws_get(CDM_WS_PORTAL_TAXON,
119
            array($taxon->uuid, 'associatedFieldUnits'),
120
            $by_associatedtaxon_query . '&pageSize=' . variable_get('cdm_dataportal_compressed_specimen_derivate_table_page_size')
121
        );
122

    
123
        if (isset($pager_field_units->records[0])) {
124
          $field_unit_uuids = array();
125
          foreach ($pager_field_units->records as $field_unit) {
126
            $field_unit_uuids[] = $field_unit->uuid;
127
          }
128
        }
129

    
130
        $render_array['derivate_hierarchy_table'] = compose_specimen_table($field_unit_uuids);
131

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

    
153
        if ($specimensOrObservations) {
154

    
155
            foreach ($specimensOrObservations as $specimenOrObservation) {
156

    
157
                $mediaList = array();
158
                if (is_array($specimenOrObservation->_fieldObjectMedia)) {
159
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_fieldObjectMedia);
160
                }
161
                if (is_array($specimenOrObservation->_derivedUnitMedia)) {
162
                    $mediaList = array_merge($mediaList, $specimenOrObservation->_derivedUnitMedia);
163
                }
164

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

    
181
                // --- Specimen entry as dynamic label:
182
                //     -> Dynabox for the specimenOrObservation
183
                $gallery_name = $specimenOrObservation->uuid;
184

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

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

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

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

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

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

    
282
  $rowcount = 0;
283
  $rows = array();
284

    
285
  foreach ($field_unit_uuids as $field_unit_uuid) {
286

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

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

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

    
382
  //add toggle functionality to derivate hierarchy table
383
  drupal_add_js_rowToggle("#" . $tableId);
384

    
385
  return $derivateHierarchyTable;
386
}
387

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

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

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

    
444
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
445
  $http_request_params = drupal_get_query_parameters();
446

    
447
  // add all mandatory js sources
448
  _add_js_footnotes();
449

    
450

    
451
  $render_array = array();
452
  $weight = 0; // the weight for the render array elements
453

    
454
  $tabsToDisplay = variable_get('cdm_taxonpage_tabs_visibility', unserialize(TAXONPAGE_VISIBILITY_OPTIONS_DEFAULT));
455

    
456
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
457

    
458
  $synonymy_as_tab = variable_get(CDM_SYNONYMY_AS_TAB, CDM_SYNONYMY_AS_TAB_DEFAULT) === 1;
459
  if(!$synonymy_as_tab){
460
    unset($tabsToDisplay["Synonymy"]);
461
    // the synonymy is located in the general part in this case
462
    if($page_part == 'synonymy'){
463
      $page_part = 'description';
464
    }
465
  }
466

    
467
  $media = _load_media_for_taxon($taxon);
468

    
469

    
470
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
471
    taxon_page_tabs_hidden('images');
472
  }
473

    
474
  // --- GET specimensOrObservations --- //
475
  $specimensOrObservations = cdm_ws_get(CDM_WS_TAXON, array( $taxon->uuid, 'specimensOrObservations'));
476

    
477
  $specimensOrObservationsCount = is_array($specimensOrObservations) ? count($specimensOrObservations) : 0;
478
  if ($specimensOrObservationsCount == 0 || ($tabsToDisplay["Specimens"] == '0')) {
479
    taxon_page_tabs_hidden('specimens');
480
  }
481

    
482
  // --- GET polytomousKeys --- //
483
  $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, NULL, "findByTaxonomicScope=$taxon->uuid");
484
  $identificationKeyCount = 0;
485
  if ($polytomousKeysPager) {
486
    $identificationKeyCount += $polytomousKeysPager->count;
487
  }
488
  if ($identificationKeyCount == 0 || ($tabsToDisplay["Keys"] == '0')) {
489
    taxon_page_tabs_hidden('keys');
490
  }
491

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

    
505
  if (!isset($tabsToDisplay["Synonymy"]) || $tabsToDisplay["Synonymy"] == '0') {
506
    taxon_page_tabs_hidden('synonymy');
507
  }
508

    
509
  // -------------------------------------------- //
510

    
511
  if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
512
    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
513
  }
514

    
515
  // --- PAGE PART: DESCRIPTION --- //
516
  if ($page_part == 'description' || $page_part == 'all') {
517

    
518
    $merged_tree = merged_taxon_feature_tree($taxon);
519

    
520

    
521
    $render_array['general'] = compose_cdm_taxon_page_profile($taxon, $merged_tree, $media, !$synonymy_as_tab);
522
    $render_array['general']['#weight'] = $weight++;
523
    $render_array['general']['#prefix'] = '<div id="general" class="page-part">';
524
    $render_array['general']['#suffix'] = '</div>';
525
  }
526

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

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

    
568
    $synonymy_html .= theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => $addAcceptedTaxon));
569

    
570
    $synonymy_html .= '</div>';
571
    $render_array['synonymy'] = markup_to_render_array($synonymy_html, $weight++);
572

    
573
  }
574

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

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

    
598
  // --- PAGE PART: EXPERTS --- //
599

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

    
608
  // ------------------ END OF PARTS -------------- //
609

    
610
  // adjust weights of page and toc elements according to the settings
611
  $taxontabs_weights = get_array_variable_merged(CDM_TAXONPAGE_TAB_WEIGHT, CDM_TAXONPAGE_TAB_WEIGHT_DEFAULT);
612
  foreach($taxontabs_weights as $tab_key => $weight){
613
    if(isset($render_array[$tab_key])){
614
      $render_array[$tab_key]['#weight'] = $weight;
615
    }
616
  }
617

    
618

    
619
  // set up the TOC for the pages which contain all pageparts
620
  if($page_part == 'all') {
621

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

    
648
    // move profile image in page structure
649
    if(isset($render_array['general']['taxon_profile_image'])){
650
      $render_array['profile_image'] = $render_array['general']['taxon_profile_image'];
651
      $render_array['profile_image']['#weight'] = -100;
652
      unset($render_array['general']['taxon_profile_image']);
653
    }
654

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

    
666

    
667
  return $render_array;
668
}
669

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

    
694
  $render_array = array();
695

    
696
  $taxon_profile_image_settings = variable_get(CDM_TAXON_PROFILE_IMAGE, unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT));
697

    
698
  $hide_taxon_profile_image = FALSE;
699
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
700
    $rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
701
    $hide_taxon_profile_image = ($rankCompare > -1);
702
  }
703

    
704
  if ($taxon_profile_image_settings['show'] && !$hide_taxon_profile_image) {
705

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

    
724
        $representation = array_shift($preferred_representations);
725
        $representationPart = $representation->parts[0];
726
        $attributes['alt'] = $representationPart->uri;
727

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

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

    
766
  if($add_synonymy){
767
    $render_array['synonymy'] = markup_to_render_array(
768
      theme('cdm_taxon_page_synonymy', array('taxon' => $taxon, 'addAcceptedTaxon' => true)),
769
      -102
770
    );
771
  }
772

    
773
  $pseudo_feature_blocks = array();
774
  $pseudo_feature_block_toc_items = array();
775

    
776

    
777
  // Render the sections for each real feature
778
  $feature_block_list = make_feature_block_list($merged_tree->root->childNodes, $taxon);
779

    
780
  // Bibliography
781
  $bibliography_settings = get_bibliography_settings();
782
  if($bibliography_settings['enabled'] == 1){
783
    $feature_bibliography = make_pseudo_feature('Bibliography', 'BIBLIOGRAPHY');
784
    $bibliography_block = feature_block(t('Bibliography'), $feature_bibliography);
785
    $bibliography_item = markup_to_render_array(FootnoteManager::renderFootnoteList('BIBLIOGRAPHY', ''));
786
    $bibliography_block->content[] = compose_feature_block_wrap_elements(array($bibliography_item), $feature_bibliography);
787

    
788
    if(!empty($bibliography_block->content)){
789
      $pseudo_feature_block_toc_items['Bibliography']= 'bibliography';
790
      $pseudo_feature_blocks[] = $bibliography_block;
791
    }
792
  }
793

    
794
  $render_array['taxon_description_features'] = _block_get_renderable_array(
795
    array_merge($feature_block_list, $pseudo_feature_blocks)
796
  );
797

    
798
  if($pseudo_feature_block_toc_items){
799
    foreach ($pseudo_feature_block_toc_items as $label=>$fragment){
800
      cdm_toc_list_add_item($label, $fragment);
801
    }
802
  }
803

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

    
815
  return $render_array;
816
}
817

    
818
/**
819
 * composes and returns an render array for the experts associated with the given taxon
820
 *
821
 * @param taxon
822
 *
823
 * @return array
824
 *   A Drupal render array for a table with the experts
825
 *
826
 * @ingroup compose
827
 */
828
function compose_cdm_taxon_page_experts($taxon){
829

    
830
  $render_array = array();
831
  if(!isset($taxon->uuid)){
832
    return $render_array;
833
  }
834

    
835
  $current_classification_uuid = get_current_classification_uuid();
836
  // TODO use cdm_ws_fetchall below but this failes! needs fix!
837
  $taxon_node_agent_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODEAGENTRELATIONS,
838
    array(
839
      $taxon->uuid,
840
      $current_classification_uuid
841
    )
842
  );
843

    
844
  $header = array(
845
    array('data' => t('Expert')),
846
    array('data' => t('Role'))
847
  );
848
  $rows = array();
849

    
850

    
851
  foreach($taxon_node_agent_relations->records as $taxon_node_agent_relation){
852

    
853

    
854
    $expert_role_id = $taxon_node_agent_relation->agent->uuid . '-' . $taxon_node_agent_relation->type->uuid;
855
    $expert_details_container_id = 'expert_details_' . $expert_role_id;
856

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

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

    
895
  }
896

    
897

    
898
  $render_array['experts_table'] = array(
899
    '#theme' => 'table',
900
    '#header' => $header,
901
    '#rows' => $rows,
902
  );
903

    
904

    
905
  return $render_array;
906
}
907

    
908

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

    
931
  if(!isset($tabs)){
932
    $tabs = array();
933
  }
934

    
935
  if (isset($add_tab) && !array_key_exists($add_tab, $tabs)) {
936
    $tabs[] = $add_tab;
937
  }
938

    
939
  return $tabs;
940
}
941

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

    
953
  $hidden_tabs = taxon_page_tabs_hidden();
954

    
955
  if (is_array($variables['primary'])) {
956
    foreach ($variables['primary'] as $key => &$element) {
957

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

    
969

    
970

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

    
984
  $link = $variables['element']['#link'];
985
  if (preg_match('/cdm_dataportal\/.*\/refresh$/', $link['href'])) {
986
    $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']) . '"/>';
987
    $link['localized_options']['html'] = TRUE;
988

    
989
    $variables['element']['#link'] = $link;
990
  }
991
}
992

    
993
/* =================== block composition ===================== */
994

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

    
1007
  _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
1008

    
1009
  $render_array = array();
1010

    
1011
  $render_array['#theme'] = 'item_list';
1012
  $render_array['#type'] = 'ul';
1013
  $render_array['#attributes'] = array(
1014
    'id' => 'classification-breadcrumbs',
1015
    'class' => 'breadcrumbs inline',
1016
  );
1017

    
1018
  $items = array();
1019

    
1020
  $parent_taxon_nodes = null;
1021
  if($taxon_uuid){
1022
    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
1023
  }
1024

    
1025
  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
1026
  // find current classification in list
1027
  $classification = null;
1028
  $current_classification_uuid = get_current_classification_uuid();
1029
  foreach ($classifications as $classification){
1030
    if($classification->uuid == $current_classification_uuid){
1031
      break;
1032
    }
1033
  }
1034

    
1035
  $node_name = '';
1036
  if(count($classifications) > 1 ){
1037
    // need to add the current classification as first label
1038

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

    
1053
  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
1054

    
1055
  $rank_separator = '<span> '
1056
    . font_awesome_icon_markup('fa-chevron-right')
1057
    . ' </span>';
1058
  $more_children_icon = font_awesome_icon_markup('fa-sitemap fa-rotate-270');
1059
  $more_children_label = '...';
1060

    
1061
  $items[] = $node_name;
1062

    
1063
  $more_children_for = null;
1064
  if($parent_taxon_nodes){
1065
    foreach ($parent_taxon_nodes as $node) {
1066

    
1067
      $is_first_item = count($items) == 0;
1068
      $is_last_item = count($items) == count($parent_taxon_nodes);
1069
      $node_name = cdm_dataportal_shortname_of($node);
1070
      $path = path_to_taxon($node->taxonUuid);
1071

    
1072
      if($node->taxonomicChildrenCount > 0) {
1073
        $more_children_for = $node->taxonUuid;
1074
      } else {
1075
        $more_children_for = null;
1076
      }
1077

    
1078
      // 'fa-sitemap'
1079

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

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

    
1115
  }
1116

    
1117
  $render_array['#items'] = $items;
1118

    
1119
  return $render_array;
1120
}
1121

    
1122

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

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

    
1138
  $detail_html = render_cdm_specimen_page($specimen, true);
1139
  $render_array['specimen_html'] = array(
1140
    '#markup' => $detail_html
1141
  );
1142

    
1143
  RenderHints::popFromRenderStack();
1144
  return $render_array;
1145
}
1146

    
1147
/**
1148
 * @param $named_area_uuid
1149
 * @return array
1150
 *    The drupal render array for the page
1151
 *
1152
 * @ingroup compose
1153
 */
1154
function compose_cdm_named_area_page($named_area_uuid)
1155
{
1156

    
1157
  $named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, array($named_area_uuid));
1158

    
1159
  $render_array = array();
1160
  RenderHints::pushToRenderStack('named_area_page');
1161

    
1162
  $groups = array();
1163
  @_description_list_group_add($groups, t('Name') . ':', $named_area->representation_L10n);
1164
  @_description_list_group_add($groups, t('IdInVocabulary') . ':', $named_area->idInVocabulary);
1165
  if(isset($named_area->level)) {
1166
    @_description_list_group_add($groups, t('Level') . ':', $named_area->level->representation_L10n);
1167
  }
1168

    
1169
  $name_area_details_elements = array(
1170
   // '#title' => $title,
1171
    '#theme' => 'description_list',
1172
    '#groups' => $groups,
1173
    '#attributes' => array('class' => html_class_attribute_ref($named_area)),
1174
  );
1175

    
1176
  $render_array[] = $name_area_details_elements;
1177

    
1178
  RenderHints::popFromRenderStack();
1179
  return $render_array;
1180
}
1181

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