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

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

    
284
  foreach ($field_unit_uuids as $field_unit_uuid) {
285

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

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

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

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

    
384
  return $derivateHierarchyTable;
385
}
386

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

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

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

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

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

    
449

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

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

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

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

    
466
  $media = _load_media_for_taxon($taxon);
467

    
468

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

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

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

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

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

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

    
508
  // -------------------------------------------- //
509

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

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

    
517
    $merged_tree = merged_taxon_feature_tree($taxon);
518

    
519

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

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

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

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

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

    
572
  }
573

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

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

    
597
  // --- PAGE PART: EXPERTS --- //
598

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

    
607
  // ------------------ END OF PARTS -------------- //
608

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

    
617

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

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

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

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

    
665

    
666
  return $render_array;
667
}
668

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

    
693
  $render_array = array();
694

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

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

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

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

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

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

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

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

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

    
775

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

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

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

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

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

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

    
814
  return $render_array;
815
}
816

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

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

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

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

    
849

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

    
852

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

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

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

    
894
  }
895

    
896

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

    
903

    
904
  return $render_array;
905
}
906

    
907

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

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

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

    
938
  return $tabs;
939
}
940

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

    
952
  $hidden_tabs = taxon_page_tabs_hidden();
953

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

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

    
968

    
969

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

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

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

    
992
/* =================== block composition ===================== */
993

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

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

    
1008
  $render_array = array();
1009

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

    
1017
  $items = array();
1018

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

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

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

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

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

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

    
1060
  $items[] = $node_name;
1061

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

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

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

    
1077
      // 'fa-sitemap'
1078

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

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

    
1114
  }
1115

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

    
1118
  return $render_array;
1119
}
1120

    
1121

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

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

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

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

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

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

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

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

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

    
1175
  $render_array[] = $name_area_details_elements;
1176

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

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