Project

General

Profile

Download (65.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Returns the localized representations of the modifiers hold by the
5
 * supplied cdm instance concatenated into one string.
6
 *
7
 * @param object $iModifieable
8
 *   cdm instance of an class implementing the interface IModifieable:
9
 *   DescriptionElementBase, StateDate, State
10
 *
11
 * @return String
12
 *   localized representations of the modifiers hold by the
13
 *   supplied cdm instance concatenated into one string
14
 */
15
function cdm_modifers_representations($iModifieable, $glue = ', ') {
16
  $modifiers_strings = array();
17
  if (isset($iModifieable->modifiers)) {
18
    foreach ($iModifieable->modifiers as $modifier) {
19
      $modifiers_strings[] = cdm_term_representation($modifier);
20
    }
21
  }
22
  return implode(', ', $modifiers_strings);
23
}
24

    
25
/**
26
 * Filters the given set of description elements and prefers computed elements over others.
27
 *
28
 * Computed description elements
29
 * are identified by the MarkerType.COMPUTED()
30
 *
31
 * If the given set contains at least one computed element only
32
 * the computed elements are returned.
33
 *
34
 * @param array $description_elements
35
 *   An array of CDM DescriptionElementBase instances
36
 *
37
 * @return array
38
 *   only the computed description elements otherwise all others.
39
 *
40
 * @deprecated this is replaced by the cdmlib DistributionUtil class!!!
41
 */
42
function cdm_description_elements_prefer_computed($description_elements){
43

    
44
  $computed_elements = array();
45
  $other_elements = array();
46

    
47
  if (!empty($description_elements)) {
48
    foreach ($description_elements as $element) {
49
      if (cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)) {
50
        $computed_elements[] = $element;
51
      }
52
      else {
53
        $other_elements[] = $element;
54
      }
55
    }
56
  }
57

    
58
  if (count($computed_elements) > 0) {
59
    return $computed_elements;
60
  }
61
  else {
62
    return $other_elements;
63
  }
64
}
65

    
66
/**
67
 * Creates a query parameter array based on the setting stored in the drupal variable CDM_DISTRIBUTION_FILTER.
68
 *
69
 * @return array
70
 *   An array with distribution filter query parameters
71
 */
72
function cdm_distribution_filter_query() {
73
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
74
  $query = array();
75

    
76
  // new default, TODO put into settings #5677
77
  $query['distributionOrder'] = 'AREA_ORDER';
78

    
79
  if ($cdm_distribution_filter['filter_rules']['statusOrderPreference']) {
80
    $query['statusOrderPreference'] = 1;
81
  }
82
  if ($cdm_distribution_filter['filter_rules']['subAreaPreference']) {
83
    $query['subAreaPreference'] = 1;
84
  }
85
  if (is_array($cdm_distribution_filter['hiddenAreaMarkerType']) && count($cdm_distribution_filter['hiddenAreaMarkerType']) > 0) {
86
    $query['hiddenAreaMarkerType'] = '';
87
    foreach ($cdm_distribution_filter['hiddenAreaMarkerType'] as $marker_type => $enabled) {
88
      if ($enabled) {
89
        $query['hiddenAreaMarkerType'] .= ($query['hiddenAreaMarkerType'] ? ',' : '') . $marker_type;
90
      }
91
    }
92
  }
93

    
94
  return $query;
95
}
96

    
97
/**
98
 * Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into  the target.
99
 *
100
 * @param object $target
101
 *   The source CDM DescriptionElement
102
 * @param object $source
103
 *   The target CDM DescriptionElement
104
 */
105
function cdm_merge_description_elements(&$target, &$source) {
106
  static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
107

    
108
  foreach ($fields_to_merge as $field) {
109
    if (is_array($source->$field)) {
110
      if (!is_array($target->$field)) {
111
        $target->$field = $source->$field;
112
      }
113
      else {
114
        $target->$field = array_merge($target->$field, $source->$field);
115
      }
116
    }
117
  }
118
}
119

    
120
/**
121
 * Adds an entry to the end of the table of content items list
122
 *
123
 * The  table of content items are crated internally by calling
124
 * toc_list_item() the resulting item is added to the statically cached
125
 * list of toc elements
126
 *
127
 * @param string $label
128
 *   The label of toc entry
129
 * @param $class_attribute_suffix
130
 *   The suffix to be appended to the class attribute prefix: "feature-toc-item-"
131
 * @param string $fragment
132
 *   Optional parameter to define a url fragment different from the $label,
133
 *   if the $fragment is not defined the $label will be used
134
 */
135
function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL, $as_first_element = FALSE) {
136
  $toc_list_items = &cdm_toc_list();
137

    
138
  if (!$fragment) {
139
    $fragment = $label;
140
  }
141
  $fragment = generalizeString($fragment);
142

    
143
  $class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
144

    
145
  $new_item = toc_list_item(
146
    theme(
147
      'cdm_feature_name',
148
      array('feature_name' => $label)),
149
      array('class' => $class_attributes),
150
      $fragment
151
    );
152

    
153
  if ($as_first_element) {
154
    array_unshift($toc_list_items, $new_item);
155
  }
156
  else {
157
    $toc_list_items[] = $new_item;
158
  }
159

    
160
}
161

    
162
/**
163
 * Returns the statically cached table of content items as render array.
164
 *
165
 * @see cdm_toc_list_add_item()
166
 *
167
 * @return array
168
 *   a render array of table of content items suitable for theme_item_list()
169
 */
170
function &cdm_toc_list(){
171
  $toc_list_items = &drupal_static('toc_list_items', array());
172

    
173
  return $toc_list_items;
174
}
175

    
176
/**
177
 * Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
178
 *
179
 * The block can also be used for pseudo Features like a bibliography. Pseudo features are
180
 * derived from other data on the fly and so not exist as such in the cdm data. In case
181
 * of pseudo features the $feature is left empty
182
 *
183
 * @param $feature_name
184
 *   A label describing the feature, usually the localized feature representation.
185
 * @param object $feature
186
 *   The CDM Feature for which the block is created. (optional)
187
 * @return object
188
 *   A Drupal block object
189
 */
190
function feature_block($feature_name, $feature = NULL) {
191
  $block = new stdclass(); // Empty object.
192
  $block->module = 'cdm_dataportal';
193
  $block->delta = generalizeString($feature_name);
194
  $block->region = NULL;
195
  $block->subject = '<a name="' . $block->delta . '"></a><span class="' . html_class_attribute_ref($feature) . '">'
196
    . theme('cdm_feature_name', array('feature_name' => $feature_name))
197
    . '</span>';
198
  $block->module = "cdm_dataportal-feature";
199
  $block->content = '';
200
  return $block;
201
}
202

    
203

    
204
/**
205
 * Returns a list of a specific type of IdentificationKeys.
206
 *
207
 * The list can be restricted by a taxon.
208
 *
209
 * @param string $type
210
 *   The simple name of the cdm class implementing the interface
211
 *   IdentificationKey, valid values are:
212
 *   PolytomousKey, MediaKey, MultiAccessKey.
213
 * @param string $taxonUuid
214
 *   If given this parameter restrict the listed keys to those which have
215
 *   the taxon identified be this uuid in scope.
216
 *
217
 * @return array
218
 *   List with identification keys.
219
 */
220
function _list_IdentificationKeys($type, $taxonUuid = NULL, $pageSize = NULL, $pageNumber = NULL) {
221
  if (!$type) {
222
    drupal_set_message(t('Type parameter is missing'), 'error');
223
    return;
224
  }
225
  $cdm_ws_pasepath = NULL;
226
  switch ($type) {
227
    case "PolytomousKey":
228
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
229
      break;
230

    
231
    case "MediaKey":
232
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
233
      break;
234

    
235
    case "MultiAccessKey":
236
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
237
      break;
238

    
239
  }
240

    
241
  if (!$cdm_ws_pasepath) {
242
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
243
  }
244

    
245
  $queryParameters = '';
246
  if (is_numeric($pageSize)) {
247
    $queryParameters = "pageSize=" . $pageSize;
248
  }
249
  else {
250
    $queryParameters = "pageSize=0";
251
  }
252

    
253
  if (is_numeric($pageNumber)) {
254
    $queryParameters = "pageNumber=" . $pageNumber;
255
  }
256
  else {
257
    $queryParameters = "pageNumber=0";
258
  }
259
  $queryParameters = NULL;
260
  if ($taxonUuid) {
261
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
262
  }
263
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
264

    
265
  if (!$pager || $pager->count == 0) {
266
    return array();
267
  }
268
  return $pager->records;
269
}
270

    
271

    
272
/**
273
 * Creates a list item for a table of content, suitable as data element for a themed list
274
 *
275
 * @see theme_list()
276
 *
277
 * @param $label
278
 * @param $http_request_params
279
 * @param $attributes
280
 * @return array
281
 */
282
function toc_list_item($label, $attributes = array(), $fragment = null) {
283

    
284
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
285
  $http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
286

    
287
  $item =  array(
288
    'data' => l(
289
      $label,
290
      $_GET['q'],
291
      array(
292
        'attributes' => array('class' => array('toc')),
293
        'fragment' => generalizeString($label),
294
        'query' => $http_request_params,
295
      )
296
    ),
297
  );
298
  $item['attributes'] = $attributes;
299
  return $item;
300
}
301

    
302
/**
303
 * Creates the footnotes for the given CDM DescriptionElement instance.
304
 *
305
 * Footnotes are created for annotations and original sources,
306
 * optionally the sources are put into a separate bibliography.
307
 *
308
 * @param $descriptionElement
309
 *   A CDM DescriptionElement instance
310
 * @param $separator
311
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
312
 * @param $footnote_list_key_suggestion
313
 *   will be overridden for original sources if the bibliography block is enabled
314
 *
315
 * @return String
316
 *   The foot note keys
317
 */
318
function cdm_create_description_element_footnotes($description_element, $separator = ',',
319
          $footnote_list_key_suggestion = null, $do_link_to_reference = FALSE,
320
          $do_link_to_name_used_in_source = FALSE
321
    ){
322

    
323

    
324
  // Annotations as footnotes.
325
  $footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
326

    
327
  // Source references as footnotes.
328
  $bibliography_settings = get_bibliography_settings();
329
  $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // null will cause original_source_footnote_list_key to use the default
330

    
331
  usort($description_element->sources, 'compare_original_sources');
332
  foreach ($description_element->sources as $source) {
333
    if (_is_original_source_type($source)) {
334
      $fn_key = FootnoteManager::addNewFootnote(
335
        original_source_footnote_list_key($footnote_list_key_suggestion),
336
        theme('cdm_OriginalSource', array(
337
          'source' => $source,
338
          'doLink' => $do_link_to_reference,
339
          'do_link_to_name_used_in_source' => $do_link_to_name_used_in_source
340

    
341
        )),
342
        $original_source_footnote_tag
343
      );
344
      // Ensure uniqueness of the footnote keys.
345
      cdm_add_footnote_to_array($footNoteKeys, $fn_key);
346
    }
347
  }
348
  // Sort and render footnote keys.
349
  $footnoteKeyListStr = '';
350
  asort($footNoteKeys);
351
  foreach ($footNoteKeys as $footNoteKey) {
352
    $footnoteKeyListStr .= theme('cdm_footnote_key',
353
      array(
354
        'footnoteKey' => $footNoteKey,
355
        'separator' => ($footnoteKeyListStr ? $separator : '')));
356
  }
357
  return $footnoteKeyListStr;
358
}
359

    
360

    
361
/**
362
 * Compare callback to be used in usort() to sort render arrays produced by compose_description_element().
363
 *
364
 * @param $a
365
 * @param $b
366
 */
367
function compare_description_element_render_arrays($a, $b){
368
  if ($a['#value'].$a['#value-suffix'] == $b['#value'].$b['#value-suffix']) {
369
    return 0;
370
  }
371
  return ($a['#value'].$a['#value-suffix'] < $b['#value'].$b['#value-suffix']) ? -1 : 1;
372

    
373
}
374

    
375

    
376
/**
377
 * @param $render_array
378
 * @param $element
379
 * @param $feature_block_settings
380
 * @param $element_markup
381
 * @param $footnote_list_key_suggestion
382
 */
383
function compose_description_element($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion, $prepend_feature_label = FALSE)
384
{
385

    
386
  $render_array = array(
387
    '#type' => 'html_tag',
388
    '#tag' => cdm_feature_block_element_tag_name($feature_block_settings),
389

    
390
    '#attributes' => array(
391
      'class' => array(
392
        'DescriptionElement',
393
        'DescriptionElement-' . $element->class,
394
        html_class_attribute_ref($element)
395
      )
396
    ),
397

    
398
    '#value' => '',
399
    '#value_suffix' => NULL
400

    
401
  );
402

    
403
  $annotations_and_sources = handle_annotations_and_sources($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion);
404

    
405
  // handle the special case were the TextData is used as container for original source with name
406
  // used in source information without any text stored in it.
407
  $names_used_in_source_markup = '';
408
  if (!empty($annotations_and_sources['names_used_in_source']) && empty($element_markup)) {
409
    $names_used_in_source_markup = join(', ', $annotations_and_sources['names_used_in_source']) . ': ';
410
    // remove all <span class="nameUsedInSource">...</span> from all source_references
411
    // these are expected to be at the end of the strings
412
    $pattern = '/ <span class="nameUsedInSource">.*$/';
413
    foreach( $annotations_and_sources['source_references'] as &$source_reference){
414
      $source_reference = preg_replace($pattern , '', $source_reference);
415
    }
416
  }
417

    
418

    
419
  $source_references_markup = '';
420
  if (!empty($annotations_and_sources['source_references'])) {
421
    $source_references_markup = '<span class="sources">' . join(' ', $annotations_and_sources['source_references']) . '<span>';
422
  }
423

    
424
  $feature_label = '';
425
  if ($prepend_feature_label) {
426
    $feature_label = '<span class="nested-feature-tree-feature-label">' . $element->feature->representation_L10n . ':</span> ';
427
  }
428
  $render_array['#value'] = $feature_label . $names_used_in_source_markup . $element_markup . $source_references_markup;
429
  $render_array['#value_suffix'] = $annotations_and_sources['foot_note_keys'];
430

    
431
  return $render_array;
432
}
433

    
434

    
435
  /**
436
   * @param $element
437
   * @param $feature_block_settings
438
   * @param $element_text
439
   *   used to decide if the source references should be enclosed in brackets or not
440
   * @param $footnote_list_key_suggestion
441
   * @return array
442
   *   an associative array with the following elements:
443
   *   - foot_note_keys: all footnote keys as markup
444
   *   - source_references: an array of the source references citations
445
   *   - names used in source: an associative array of the names in source,
446
   *        the name in source strings are de-duplicated
447
   *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
448
   *
449
   *
450
   */
451
  function handle_annotations_and_sources($element, $feature_block_settings, $element_text, $footnote_list_key_suggestion) {
452
    $annotations_and_sources = array(
453
      'foot_note_keys' => NULL,
454
      'source_references' => array(),
455
      'names_used_in_source' => array()
456
    );
457

    
458
    usort($element->sources, 'compare_original_sources');
459

    
460
    if ($feature_block_settings['sources_as_content'] == 1) {
461
      foreach ($element->sources as $source) {
462

    
463
        $referenceCitation = theme('cdm_OriginalSource',
464
          array(
465
            'source' => $source,
466
            'doLink' => $feature_block_settings['link_to_reference'] == 1,
467
            'do_link_to_name_used_in_source' => $feature_block_settings['link_to_name_used_in_source'] == 1,
468
          )
469
        );
470

    
471
        if ($referenceCitation) {
472
          if (empty($element_text)) {
473
            $annotations_and_sources['source_references'][] = $referenceCitation;
474
          }
475
          else {
476
            $annotations_and_sources['source_references'][] = ' (' . $referenceCitation . ')';
477
          }
478
        }
479

    
480
        $name_in_source_render_array = compose_name_in_source(
481
          $source,
482
          $feature_block_settings['link_to_name_used_in_source'] == 1
483
        );
484

    
485
        if(!empty($name_in_source_render_array)){
486
          $annotations_and_sources['names_used_in_source'][$name_in_source_render_array['#_plaintext']] = drupal_render($name_in_source_render_array);
487
        }
488
      } // END of loop over sources
489

    
490
      // annotations footnotes separate.
491
      $annotations_and_sources['foot_note_keys'] = theme('cdm_annotations_as_footnotekeys',
492
        array(
493
          'cdmBase_list' => $element,
494
          'footnote_list_key' => $footnote_list_key_suggestion,
495
        )
496
      );
497

    
498
    } // END of references inline
499

    
500
    // put sources into bibliography if requested ...
501
    if ($feature_block_settings['sources_as_content'] !== 1 || $feature_block_settings['sources_as_content_to_bibliography'] == 1) {
502
      $annotations_and_sources['foot_note_keys'] = cdm_create_description_element_footnotes(
503
        $element, ',',
504
        $footnote_list_key_suggestion,
505
        $feature_block_settings['link_to_reference'] == 1,
506
        $feature_block_settings['link_to_name_used_in_source'] == 1
507
      );
508
    }
509

    
510
    return $annotations_and_sources;
511
  }
512

    
513

    
514
  /**
515
   *
516
   *
517
   * @return string
518
   *  the footnote_list_key
519
   */
520
  function original_source_footnote_list_key($key_suggestion = null) {
521
    if(!$key_suggestion){
522
      $key_suggestion = RenderHints::getFootnoteListKey();
523
    }
524
    $bibliography_settings = get_bibliography_settings();
525
    $footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : 'BIBLIOGRAPHY-' . $key_suggestion;
526
    return $footnote_list_key;
527
  }
528

    
529
  /**
530
   * Provides the according tag name for the description element markup which fits the  $feature_block_settings['as_list'] value
531
   *
532
   * @param $feature_block_settings
533
   *   A feature_block_settings array, for details, please see get_feature_block_settings($feature_uuid = 'DEFAULT')
534
   */
535
  function cdm_feature_block_element_tag_name($feature_block_settings){
536
    switch ($feature_block_settings['as_list']){
537
      case 'ul':
538
      case 'ol':
539
        return 'li';
540
      case 'div':
541
        if(isset($feature_block_settings['element_tag'])){
542
          return $feature_block_settings['element_tag'];
543
        }
544
        return 'span';
545
      case 'dl':
546
        return 'dd';
547
      default:
548
        return 'div'; // should never happen, throw error instead?
549
    }
550
  }
551

    
552

    
553
/* ==================== COMPOSE FUNCTIONS =============== */
554

    
555
  /**
556
   * Returns a set of feature blocks for a taxon profile from the $mergedFeatureNodes of a given $taxon.
557
   *
558
   * The taxon profile consists of drupal block elements, one for the description elements
559
   * of a specific feature. The structure is defined by specific FeatureTree.
560
   * The chosen FeatureTree is merged with the list of description elements prior to using this method.
561
   *
562
   * The merged nodes can be obtained by making use of the
563
   * function cdm_ws_descriptions_by_featuretree().
564
   *
565
   * @see cdm_ws_descriptions_by_featuretree()
566
   *
567
   * @param $mergedFeatureNodes
568
   *
569
   * @param $taxon
570
   *
571
   * @return array
572
   *  A Drupal render array containing feature blocks and the table of content
573
   *
574
   * @ingroup compose
575
   */
576
  function compose_feature_blocks($mergedFeatureNodes, $taxon) {
577

    
578
    $block_list = array();
579

    
580
    RenderHints::pushToRenderStack('feature_nodes');
581

    
582
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
583

    
584
    // Create a drupal block for each feature
585
    foreach ($mergedFeatureNodes as $node) {
586

    
587
      if ((isset($node->descriptionElements['#type']) ||
588
          has_feature_node_description_elements($node)) && $node->feature->uuid != UUID_IMAGE) { // skip empty or suppressed features
589

    
590
        $feature_name = cdm_term_representation($node->feature, 'Unnamed Feature');
591
        $feature_block_settings = get_feature_block_settings($node->feature->uuid);
592

    
593
        $block = feature_block($feature_name, $node->feature);
594
        $block->content = array();
595
        $block_content_is_empty = TRUE;
596

    
597
        /*
598
         * Content/DISTRIBUTION.
599
         */
600

    
601
        if ($node->feature->uuid == UUID_DISTRIBUTION) {
602
          $block = compose_feature_block_distribution($taxon, $node->descriptionElements, $node->feature);
603
          $block_content_is_empty = FALSE;
604
        }
605
        /*
606
         * Content/COMMON_NAME.
607
         */
608
        else if ($node->feature->uuid == UUID_COMMON_NAME) {
609
          $common_names_render_array = compose_feature_block_items_feature_common_name($node->descriptionElements, $node->feature);
610
          $block->content[] = $common_names_render_array;
611
          $block_content_is_empty = FALSE;
612
        }
613

    
614
        else if ($node->feature->uuid == UUID_USE_RECORD) {
615
          $block_uses_content_html = theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
616
          $block->content[] = markup_to_render_array($block_uses_content_html);
617
          $block_content_is_empty = FALSE;
618
        }
619

    
620
        /*
621
         * Content/ALL OTHER FEATURES.
622
         */
623
        else {
624

    
625
          $media_list = array();
626
          $elements_render_array = array();
627
          $child_elements_render_array = null;
628

    
629
          if (isset($node->descriptionElements[0])) {
630
            $elements_render_array = compose_feature_block_items_generic($node->descriptionElements, $node->feature);
631
          }
632

    
633
          // Content/ALL OTHER FEATURES/Subordinate Features
634
          // subordinate features are printed inline in one floating text,
635
          // it is expected hat subordinate features can "contain" TextData,
636
          // Qualitative- and Qualitative- DescriptionElements
637
          if (isset($node->childNodes[0])) {
638
            $child_elements_render_array = compose_feature_block_items_nested($node, $media_list, $feature_block_settings);
639
            $elements_render_array = array_merge($elements_render_array, $child_elements_render_array);
640
          }
641
          $block_content_is_empty = $block_content_is_empty && empty($media_list) && empty($elements_render_array);
642
          if(!$block_content_is_empty){
643
            $block->content[] = compose_feature_block_wrap_elements($elements_render_array, $node->feature);
644
            $block->content[] = compose_feature_media_gallery($node, $media_list, $gallery_settings);
645
            /*
646
             * Footnotes for the feature block
647
             */
648
            $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $node->feature->uuid)));
649
            $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => $node->feature->uuid)));
650
            $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => $node->feature->uuid)));
651
          }
652
        } // END all other features
653

    
654
        // allows modifying the block contents via a the hook_cdm_feature_node_block_content_alter
655
        drupal_alter('cdm_feature_node_block_content', $block->content, $node->feature, $node->descriptionElements);
656

    
657
        if(!$block_content_is_empty){ // skip empty block content
658
          $block_list[] = $block;
659
          cdm_toc_list_add_item(cdm_term_representation($node->feature), $node->feature->uuid);
660
        } // END: skip empty block content
661
      } // END: skip empty or suppressed features
662
    } // END: creating a block per feature
663

    
664
    drupal_alter('cdm_feature_node_blocks', $block_list, $taxon);
665

    
666
    RenderHints::popFromRenderStack();
667

    
668
    return _block_get_renderable_array($block_list);
669
  }
670

    
671
/**
672
 * Creates a render array of description elements  held by child nodes of the given feature node.
673
 *
674
 * This function is called recursively!
675
 *
676
 * @param $node
677
 *   The feature node.
678
 * @param array $media_list
679
 *   List of CDM Media entities. All media of subordinate elements should be passed to the main feature.ä
680
 * @param $feature_block_settings
681
 *   The feature block settings.
682
 * @param $main_feature
683
 *  Only used internally in recursive calls.
684
 *
685
 * @return array
686
 *  A Drupal render array
687
 *
688
 * @ingroup compose
689
 */
690
function compose_feature_block_items_nested($node, &$media_list, $feature_block_settings, $main_feature = NULL)
691
{
692

    
693
  if(!$main_feature){
694
    $main_feature = $node->feature;
695
  }
696
  /*
697
   * TODO should be configurable, options; YES, NO, AUTOMATIC
698
   * (automatic will only place the label if the first word of the description element text is not the same)
699
   */
700
  $prepend_feature_label = false;
701

    
702
  $render_arrays = array();
703
  foreach ($node->childNodes as $child_node) {
704
    if (isset($child_node->descriptionElements[0])) {
705
      foreach ($child_node->descriptionElements as $element) {
706

    
707
        if (isset($element->media[0])) {
708
          // Append media of subordinate elements to list of main
709
          // feature.
710
          $media_list = array_merge($media_list, $element->media);
711
        }
712

    
713
        $child_node_element = null;
714
        switch ($element->class) {
715
          case 'TextData':
716
            $child_node_element = compose_description_element_text_data($element, $element->feature->uuid, $feature_block_settings, $prepend_feature_label);
717
            break;
718
          case 'CategoricalData':
719
            $child_node_element = compose_description_element_categorical_data($element, $feature_block_settings, $prepend_feature_label);
720
            break;
721
          case 'QuantitativeData':
722
            $child_node_element = compose_description_element_quantitative_data($element, $feature_block_settings, $prepend_feature_label);
723

    
724
        }
725
        if (is_array($child_node_element)) {
726
          $render_arrays[] = $child_node_element;
727
        }
728
      }
729
    }
730

    
731
    if(isset($child_node->childNodes[0])){
732
      $render_arrays = array_merge($render_arrays, compose_feature_block_items_nested($child_node, $media_list, $feature_block_settings, $main_feature ));
733
    }
734
  }
735

    
736
  return $render_arrays;
737
}
738

    
739
  /**
740
   *
741
   * @param $node
742
   *  The merged feature three node which potentially contains media in its description elements.
743
   * @param $media_list
744
   *    Additional media to be merged witht the media contained in the nodes description elements
745
   * @param $gallery_settings
746
   * @return array
747
   *
748
   * @ingroup compose
749
   */
750
  function compose_feature_media_gallery($node, $media_list, $gallery_settings) {
751

    
752
    if (isset($node->descriptionElements)) {
753
      $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
754
    }
755

    
756
    $captionElements = array('title', 'rights');
757

    
758
    if (isset($media_list[0]) && isset($gallery_settings['cdm_dataportal_media_maxextend']) && isset($gallery_settings['cdm_dataportal_media_cols'])) {
759
      $gallery = theme('cdm_media_gallerie', array(
760
        'mediaList' => $media_list,
761
        'galleryName' => CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME . '_' . $node->feature->uuid,
762
        'maxExtend' => $gallery_settings['cdm_dataportal_media_maxextend'],
763
        'cols' => $gallery_settings['cdm_dataportal_media_cols'],
764
        'captionElements' => $captionElements,
765
      ));
766
      return markup_to_render_array($gallery);
767
    }
768

    
769
    return markup_to_render_array('');
770
  }
771

    
772
  /**
773
   * Composes the distribution feature block for a taxon
774
   *
775
   * @param $taxon
776
   * @param $descriptionElements
777
   *   an associative array with two elements:
778
   *   - '#type': must be 'DTO'
779
   *   - 'DistributionInfoDTO': a CDM DistributionInfoDTO object as returned by the DistributionInfo web service
780
   * @param $feature
781
   *
782
   * @return array
783
   *  A drupal render array
784
   *
785
   * @ingroup compose
786
   */
787
  function compose_feature_block_distribution($taxon, $descriptionElements, $feature) {
788
    $text_data_glue = '';
789
    $text_data_sortOutArray = FALSE;
790
    $text_data_enclosingTag = 'ul';
791
    $text_data_out_array = array();
792

    
793
    $distributionElements = NULL;
794
    $distribution_info_dto = NULL;
795
    $distribution_sortOutArray = FALSE;
796

    
797
    $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
798

    
799
    // TODO use feature_block_settings instead of DISTRIBUTION_ORDER_MODE
800
    if (variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT) != 'TREE') {
801
      $distribution_glue = '';
802
      $distribution_enclosingTag = 'dl';
803
    } else {
804
      $distribution_glue = '';
805
      $distribution_enclosingTag = 'ul';
806
    }
807

    
808
    if (!isset($descriptionElements['#type']) || !$descriptionElements['#type'] == 'DTO') {
809
      // skip the DISTRIBUTION section if there is no DTO type element
810
      return array(); // FIXME is it ok to return an empty array?
811
    }
812

    
813
    $block = feature_block(
814
      cdm_term_representation($feature, 'Unnamed Feature'),
815
      $feature
816
    );
817

    
818
    // $$descriptionElements['TextData'] is added to to the feature node in merged_taxon_feature_tree()
819
    if (isset($descriptionElements['TextData'])) {
820
      // --- TextData
821
      foreach ($descriptionElements['TextData'] as $text_data_element) {
822
        $text_data_render_array = compose_description_element_text_data($text_data_element, $text_data_element->feature->uuid, $feature_block_settings);
823
        $repr = drupal_render($text_data_render_array);
824

    
825
        if (!array_search($repr, $text_data_out_array)) { // de-duplication !!
826
          $text_data_out_array[] = $repr;
827
          // TODO HINT: sorting in compose_feature_block_wrap_elements will
828
          // not work since this array contains html attributes with uuids
829
          // and what is about cases like the bibliography where
830
          // any content can be prefixed with some foot-note anchors?
831
          $text_data_sortOutArray = TRUE;
832
          $text_data_glue = '<br/> ';
833
          $text_data_enclosingTag = 'p';
834
        }
835
      }
836
    }
837

    
838

    
839
    if ($text_data_out_array && variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
840
      $block->content[] = compose_feature_block_wrap_elements(
841
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
842
      );
843
    }
844

    
845
    // --- Distribution map
846
    $distribution_map_query_parameters = NULL;
847
    if (isset($descriptionElements['DistributionInfoDTO'])) {
848
      $distribution_map_query_parameters = $descriptionElements['DistributionInfoDTO']->mapUriParams;
849
    }
850
    $map_render_element = compose_distribution_map($taxon, $distribution_map_query_parameters);
851
    $block->content[] = $map_render_element;
852

    
853
    $dto_out_array = array();
854

    
855
    // --- Condensed Distribution
856
    if(variable_get(DISTRIBUTION_CONDENSED) && isset($descriptionElements['DistributionInfoDTO']->condensedDistribution)){
857
      $condensed_distribution_markup = '<p class="condensed_distribution">';
858

    
859
      $isFirst = true;
860
      if(isset($descriptionElements['DistributionInfoDTO']->condensedDistribution->indigenous[0])){
861
        foreach($descriptionElements['DistributionInfoDTO']->condensedDistribution->indigenous as $cdItem){
862
          if(!$isFirst){
863
            $condensed_distribution_markup .= ' ';
864
          }
865
          $condensed_distribution_markup .= '<span class="status_' . $cdItem->status->idInVocabulary . '">'
866
          . $cdItem->areaStatusLabel . '</span>';
867
          $isFirst = false;
868
        }
869
      }
870

    
871
      if(isset($descriptionElements['DistributionInfoDTO']->condensedDistribution->foreign[0])) {
872
        if(!$isFirst){
873
          $condensed_distribution_markup .= ' ';
874
        }
875
        $isFirst = TRUE;
876
        $condensed_distribution_markup .= '[';
877
        foreach ($descriptionElements['DistributionInfoDTO']->condensedDistribution->foreign as $cdItem) {
878
          if (!$isFirst) {
879
            $condensed_distribution_markup .= ' ';
880
          }
881
          $condensed_distribution_markup .= '<span class="status_' . $cdItem->status->titleCache . '">'
882
            . $cdItem->areaStatusLabel . '</span>';
883
          $isFirst = false;
884
        }
885
        $condensed_distribution_markup .= ']';
886
      }
887

    
888
      $condensed_distribution_markup .= '&nbsp;' . l(
889
          font_awesome_icon_markup(
890
            'fa-info-circle',
891
            array(
892
              'alt'=>'help',
893
              'class' => array('superscript')
894
            )
895
          ),
896
          variable_get(DISTRIBUTION_CONDENSED_INFO_PATH, DISTRIBUTION_CONDENSED_INFO_PATH_DEFAULT) ,
897
          array('html' => TRUE));
898
      $condensed_distribution_markup .= '</p>';
899
      $dto_out_array[] = $condensed_distribution_markup;
900
    }
901

    
902
    // --- tree or list
903
    if (isset($descriptionElements['DistributionInfoDTO'])) {
904
      $distribution_info_dto = $descriptionElements['DistributionInfoDTO'];
905

    
906
      // --- tree
907
      if (is_object($distribution_info_dto->tree)) {
908
        $distribution_tree_render_array = compose_distribution_hierarchy($distribution_info_dto->tree, $feature_block_settings);
909
        $dto_out_array[] = $distribution_tree_render_array;
910
      }
911

    
912
      // --- sorted element list
913
      if (is_array($distribution_info_dto->elements) && count($distribution_info_dto->elements) > 0) {
914
        foreach ($distribution_info_dto->elements as $descriptionElement) {
915
          if (is_object($descriptionElement->area)) {
916
            $sortKey = $descriptionElement->area->representation_L10n;
917
            $distributionElements[$sortKey] = $descriptionElement;
918
          }
919
        }
920
        ksort($distributionElements);
921
        $distribution_element_render_array = compose_description_elements_distribution($distributionElements);
922
        $dto_out_array[] = $distribution_element_render_array;
923

    
924
      }
925
      //
926
      $block->content[] = compose_feature_block_wrap_elements(
927
        $dto_out_array, $feature, $distribution_glue, $distribution_sortOutArray
928
      );
929
    }
930

    
931
    // --- TextData at the bottom
932
    if ($text_data_out_array && !variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)) {
933
      $block->content[] = compose_feature_block_wrap_elements(
934
        $text_data_out_array, $feature, $text_data_glue, $text_data_sortOutArray
935
      );
936
    }
937

    
938
    $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . UUID_DISTRIBUTION)));
939
    $block->content[] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
940
    $block->content[] = markup_to_render_array(theme('cdm_annotation_footnotes', array('footnoteListKey' => UUID_DISTRIBUTION)));
941

    
942
    return $block;
943
  }
944

    
945

    
946
  /**
947
   * Composes a drupal render array for single CDM TextData description element.
948
   *
949
   * @param $element
950
   *    The CDM TextData description element.
951
   *  @param $feature_uuid
952
   * @param bool $prepend_feature_label
953
   *   Used in nested feature trees to put the feature as label in front of the description element text representation.
954
   *
955
   * @return array
956
   *   A drupal render array with the following elements being used:
957
   *    - #tag: either 'div', 'li', ...
958
   *    ⁻ #attributes: class attributes
959
   *    - #value_prefix: (optionally) contains footnote anchors
960
   *    - #value: contains the textual content
961
   *    - #value_suffix: (optionally) contains footnote keys
962
   *
963
   * @ingroup compose
964
   */
965
  function compose_description_element_text_data($element, $feature_uuid, $feature_block_settings, $prepend_feature_label = FALSE) {
966

    
967
    $footnote_list_key_suggestion = $feature_uuid;
968

    
969
    $element_markup = '';
970
    if (isset($element->multilanguageText_L10n->text)) {
971
      // TODO replacement of \n by <br> should be configurable
972
      $element_markup = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
973
    }
974

    
975
    $render_array = compose_description_element($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion, $prepend_feature_label);
976

    
977
    return $render_array;
978
  }
979

    
980

    
981
/**
982
 * Theme function to render CDM DescriptionElements of the type TaxonInteraction.
983
 *
984
 * @param $element
985
 *  The CDM TaxonInteraction entity
986
 *
987
 * @return
988
 *  A drupal render array
989
 *
990
 * @ingroup compose
991
 */
992
function compose_description_element_taxon_interaction($element, $feature_block_settings) {
993

    
994
  $out = '';
995

    
996

    
997
  if (isset($element->description_L10n)) {
998
    $out .=  ' ' . $element->description_L10n;
999
  }
1000

    
1001
  if(isset($element->taxon2)){
1002
    $out = render_taxon_or_name($element->taxon2, url(path_to_taxon($element->taxon2->uuid)));
1003
  }
1004

    
1005
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid);
1006

    
1007
  return $render_array;
1008
}
1009

    
1010

    
1011
/**
1012
 * Renders a single instance of the type IndividualsAssociations.
1013
 *
1014
 * @param $element
1015
 *   The CDM IndividualsAssociations entity.
1016
 * @param $feature_block_settings
1017
 *
1018
 * @return array
1019
 *   Drupal render array
1020
 *
1021
 * @ingroup compose
1022
 */
1023
function compose_description_element_individuals_association($element, $feature_block_settings) {
1024

    
1025
  $out = '';
1026

    
1027
  $render_array = compose_cdm_specimenOrObservation($element->associatedSpecimenOrObservation);
1028

    
1029
  if (isset($element->description_L10n)) {
1030
    $out .=  ' ' . $element->description_L10n;
1031
  }
1032

    
1033
  $out .= drupal_render($render_array);
1034

    
1035
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid);
1036

    
1037
  return $render_array;
1038
}
1039

    
1040
/**
1041
 * Renders a single instance of the type CategoricalData.
1042
 *
1043
 * @param $element
1044
 *  The CDM CategoricalData entity
1045
 *
1046
 * @param $feature_block_settings
1047
 *
1048
 * @param bool $prepend_feature_label
1049
 *   Used in nested feature trees to put the feature as label in front of the description element text representation.
1050
 *
1051
 * @return string
1052
 *   a html representation of the given CategoricalData element
1053
 *
1054
 * @ingroup compose
1055
 */
1056
function compose_description_element_categorical_data($element, $feature_block_settings, $prepend_feature_label = FALSE) {
1057

    
1058
  $enclosing_tag = cdm_feature_block_element_tag_name($feature_block_settings);
1059

    
1060
  $state_data_strings = array();
1061
  if (isset($element->stateData)) {
1062
    foreach ($element->stateData as $state_data) {
1063

    
1064
      $state  = NULL;
1065

    
1066
      if (isset($state_data->state)) {
1067
        $state = cdm_term_representation($state_data->state);
1068
      }
1069

    
1070
      if (isset($state_data->modifyingText_L10n)) {
1071
        $state = ' ' . $state_data->modifyingText_L10n;
1072
      }
1073

    
1074
      $modifiers_strings = cdm_modifers_representations($state_data);
1075

    
1076
      $state_data_strings[] = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
1077

    
1078
    }
1079
  }
1080

    
1081
  $out = '<span class="' . html_class_attribute_ref($element) . '">' . implode(', ', $state_data_strings) . '</span>';
1082

    
1083
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid, $prepend_feature_label);
1084

    
1085
  return $render_array;
1086
}
1087

    
1088

    
1089
/**
1090
 * Theme function to render CDM DescriptionElements of the type QuantitativeData.
1091
 *
1092
 * The function renders the statisticalValues contained in the QuantitativeData
1093
 * entity according to the following scheme:
1094
 *
1095
 * (ExtremeMin)-Min-Average-Max-(ExtremeMax)
1096
 *
1097
 * All modifiers of these values are appended.
1098
 *
1099
 * If the QuantitativeData is containing more statisticalValues with further
1100
 * statisticalValue types, these additional measures will be appended to the
1101
 * above string separated by whitespace.
1102
 *
1103
 * Special cases;
1104
 * 1. Min==Max: this will be interpreted as Average
1105
 *
1106
 * @param $element
1107
 *  The CDM QuantitativeData entity
1108
 *
1109
 * @param $feature_block_settings
1110
 *
1111
 * @param bool $prepend_feature_label
1112
 *   Used in nested feature trees to put the feature as label in front of the description element text representation.
1113
 *
1114
 *
1115
 * @return string
1116
 *   a html representation of the given QuantitativeData element
1117
 *
1118
 * @ingroup themeable
1119
 */
1120
function compose_description_element_quantitative_data($element, $feature_block_settings, $prepend_feature_label = FALSE) {
1121
  /*
1122
   * - statisticalValues
1123
   *   - value
1124
   *   - modifiers
1125
   *   - type
1126
   * - unit->representation_L10n
1127
   * - modifyingText
1128
   * - modifiers
1129
   * - sources
1130
   */
1131

    
1132
  $out = '';
1133
  $type_representation = NULL;
1134
  $min_max = min_max_array();
1135

    
1136

    
1137
  $other_values = array();
1138

    
1139
  if (isset($element->statisticalValues)) {
1140
    $other_values_markup = array();
1141
    foreach ($element->statisticalValues as $statistical_val) {
1142

    
1143
      // compile the full value string which also may contain modifiers
1144
      if (isset($statistical_val->value)) {
1145
        $statistical_val->_value = $statistical_val->value;
1146
      }
1147
      $val_modifiers_strings = cdm_modifers_representations($statistical_val);
1148
      if ($val_modifiers_strings) {
1149
        $statistical_val->_value = ' ' . $val_modifiers_strings . ' ' . $statistical_val->_value;
1150
      }
1151

    
1152
      // either put into min max array or into $other_values
1153
      // for generic output to be appended to 'min-max' string
1154
      if (array_key_exists($statistical_val->type->titleCache, $min_max)) {
1155
        $min_max[$statistical_val->type->titleCache] = $statistical_val;
1156
      }
1157
      else {
1158
        $other_values[] = $statistical_val;
1159
      }
1160
    } // end of loop over statisticalValues
1161

    
1162
    // create markup
1163

    
1164
    $min_max_markup = min_max_markup($min_max);
1165

    
1166

    
1167
    foreach ($other_values as $statistical_val) {
1168
      $statistical_val_type_representation = NULL;
1169
      if (isset($statistical_val->type)) {
1170
        $statistical_val_type_representation = cdm_term_representation($statistical_val->type);
1171
        // $statistical_val->type->termType;
1172
        // $statistical_val->type->userFriendlyTypeName;
1173
      }
1174
      $value_markup = '<span class="' . html_class_attribute_ref($statistical_val) . ' ' . $statistical_val->type->termType . ' ">'
1175
        . $statistical_val->_value . '</span>';
1176
      $value_markup = $value_markup .
1177
        ($statistical_val_type_representation ? ' <span class="type">' . $statistical_val_type_representation . '</span>' : '');
1178
      $other_values_markup[] = $value_markup;
1179
    }
1180

    
1181

    
1182
    $out .= $min_max_markup . ' ' . implode($other_values_markup, ', ');
1183
  }
1184

    
1185
  if (isset($element->unit)) {
1186
    $out .= ' <span class="unit" title="'
1187
      . cdm_term_representation($element->unit) . '">'
1188
      . cdm_term_representation_abbreviated($element->unit)
1189
      . '</span>';
1190
  }
1191

    
1192
  // modifiers of the description element itself
1193
  $modifier_string = cdm_modifers_representations($element);
1194
  $out .= ($modifier_string ? ' ' . $modifier_string : '');
1195
  if (isset($element->modifyingText_L10n)) {
1196
    $out = $element->modifyingText_L10n . ' ' . $out;
1197
  }
1198

    
1199
  $render_array = compose_description_element($element, $feature_block_settings, $out, $element->feature->uuid, $prepend_feature_label);
1200

    
1201
  return $render_array;
1202
}
1203

    
1204

    
1205
/**
1206
 * Wraps the render array for the given feature into an enclosing html tag.
1207
 *
1208
 * Optionally the elements can be sorted and glued together by a separator string.
1209
 *
1210
 * @param array $description_element_render_arrays
1211
 *   An list of render arrays. Which are usually are produced by the compose_description_element()
1212
 *   function. The render arrays should be of #type=html_tag, so that they can understand the #attribute property.
1213
 * @param  $feature :
1214
 *  The feature to which the elements given in $elements are belonging to.
1215
 * @param string $glue :
1216
 *  Defaults to empty string.
1217
 * @param bool $sort
1218
 *   Boolean Whether to sort the $elements alphabetically, default is FALSE
1219
 *
1220
 * @return array
1221
 *    A Drupal render array
1222
 *
1223
 * @ingroup compose
1224
 */
1225
  function compose_feature_block_wrap_elements(array $description_element_render_arrays, $feature, $glue = '', $sort = FALSE)
1226
  {
1227

    
1228
    $feature_block_settings = get_feature_block_settings($feature->uuid);
1229
    $enclosing_tag = $feature_block_settings['as_list'];
1230

    
1231
    if ($sort) { // TODO remove parameter and replace by $feature_block_settings['sort_elements']
1232
      usort($description_element_render_arrays, 'compare_description_element_render_arrays');
1233
    }
1234

    
1235
    $is_first = true;
1236
    foreach($description_element_render_arrays as &$element_render_array){
1237
      if(!is_array($element_render_array)){
1238
        $element_render_array = markup_to_render_array($element_render_array);
1239
      }
1240
      $element_render_array['#attributes']['class'][] = "feature-block-element";
1241

    
1242
      // add the glue!
1243
      if(!$is_first) {
1244
        if (isset($element_render_array['#value'])) {
1245
          $element_render_array['#value'] = $glue . $element_render_array['#value'];
1246
        } elseif (isset($element_render_array['#markup'])) {
1247
          $element_render_array['#markup'] = $glue . $element_render_array['#markup'];
1248
        }
1249
      }
1250
      $is_first = false;
1251
    }
1252

    
1253
    $render_array['elements']['children'] = $description_element_render_arrays;
1254

    
1255
    $render_array['elements']['#prefix'] = '<' . $enclosing_tag . ' class="feature-block-elements" id="' . $feature->representation_L10n . '">';
1256
    $render_array['elements']['#suffix'] = '</' . $enclosing_tag . '>';
1257

    
1258
    return $render_array;
1259
  }
1260

    
1261

    
1262
  /* compose nameInSource or originalNameString as markup
1263
   *
1264
   * @param $source
1265
   * @param $do_link_to_name_used_in_source
1266
   * @param $suppress_for_shown_taxon
1267
   *    the nameInSource will be suppressed when it has the same name as the accepted taxon
1268
   *    for which the taxon page is being created, Defaults to TRUE
1269
   *
1270
   * @return array
1271
   *    A Drupal render array with an additional element, the render array is empty
1272
   *    if the source had no name in source information
1273
   *    - #_plaintext: contains the plaintext version of the name (custom element)
1274
   *
1275
   * @ingroup compose
1276
   */
1277
  function compose_name_in_source($source, $do_link_to_name_used_in_source, $suppress_for_shown_taxon = TRUE) {
1278

    
1279
    $plaintext = NULL;
1280
    $markup = NULL;
1281
    $name_in_source_render_array = array();
1282

    
1283
    static $taxon_page_accepted_name = '';
1284
    if($suppress_for_shown_taxon && arg(1) == 'taxon' && empty($taxon_page_accepted_name)){
1285

    
1286
      $current_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, arg(2));
1287
      $taxon_page_accepted_name = $current_taxon->name->titleCache;
1288
    }
1289

    
1290
    if (isset($source->nameUsedInSource->uuid) && isset($source->nameUsedInSource->titleCache)) {
1291
      // it is a DescriptionElementSource !
1292
      $plaintext = $source->nameUsedInSource->titleCache;
1293
      if($suppress_for_shown_taxon && $taxon_page_accepted_name == $plaintext){
1294
        return $name_in_source_render_array; // SKIP this name
1295
      }
1296
      $markup = render_taxon_or_name($source->nameUsedInSource);
1297
      if ($do_link_to_name_used_in_source) {
1298
        $markup = l(
1299
          $markup,
1300
          path_to_name($source->nameUsedInSource->uuid),
1301
          array(
1302
            'attributes' => array(),
1303
            'absolute' => TRUE,
1304
            'html' => TRUE,
1305
          ));
1306
      }
1307
    }
1308
    else if (isset($source->originalNameString) && !empty($source->originalNameString)) {
1309
      // the name used in source can not be expressed as valid taxon name,
1310
      // so the editor has chosen to put the freetext name into ReferencedEntityBase.originalNameString
1311
      // field
1312
      // using the originalNameString as key to avoid duplicate entries
1313
      $plaintext = $source->originalNameString;
1314
      if($suppress_for_shown_taxon && $taxon_page_accepted_name == $plaintext){
1315
        return $name_in_source_render_array; // SKIP this name
1316
      }
1317
      $markup = $source->originalNameString;
1318
    }
1319

    
1320
    if ($plaintext) { // checks if we have any content
1321
      $name_in_source_render_array = markup_to_render_array($markup);
1322
      $name_in_source_render_array['#_plaintext'] = $plaintext;
1323
    }
1324

    
1325
    return $name_in_source_render_array;
1326
  }
1327

    
1328

    
1329

    
1330
  /**
1331
   * Return HTML for a list of description elements.
1332
   *
1333
   * Usually these are of a specific feature type.
1334
   *
1335
   * @param $description_elements
1336
   *   array of descriptionElements which belong to the same feature.
1337
   *   These descriptions elements of a Description must be ordered by the chosen feature tree by
1338
   *   calling the function _mergeFeatureTreeDescriptions().
1339
   *   @see _mergeFeatureTreeDescriptions()
1340
   *
1341
   * @param  $feature_uuid
1342
   *
1343
   * @return
1344
   *    A drupal render array for the $descriptionElements, may be an empty array if the textual content was empty.
1345
   *    Footnote key or anchors are not considered to be textual content.
1346
   *
1347
   * @ingroup compose
1348
   */
1349
  function compose_feature_block_items_generic($description_elements, $feature) {
1350

    
1351
    $elements_out_array = array();
1352
    $distribution_tree = null;
1353

    
1354
    /*
1355
     * $feature_block_has_content will be set true if at least one of the
1356
     * $descriptionElements contains some text which makes up some content
1357
     * for the feature block. Footnote keys are not considered
1358
     * to be content in this sense.
1359
     */
1360
    $feature_block_has_content = false;
1361

    
1362
    if (is_array($description_elements)) {
1363
      foreach ($description_elements as $description_element) {
1364
          /* decide based on the description element class
1365
           *
1366
           * Features handled here:
1367
           * all except DISTRIBUTION, COMMON_NAME, USES, IMAGES,
1368
           *
1369
           * TODO provide api_hook as extension point for this?
1370
           */
1371
        $feature_block_settings = get_feature_block_settings($description_element->feature->uuid);
1372
        switch ($description_element->class) {
1373
          case 'TextData':
1374
            $elements_out_array[] = compose_description_element_text_data($description_element, $description_element->feature->uuid, $feature_block_settings);
1375
            break;
1376
          case 'CategoricalData':
1377
            $elements_out_array[] = compose_description_element_categorical_data($description_element, $feature_block_settings);
1378
            break;
1379
          case 'QuantitativeData':
1380
            $elements_out_array[] = compose_description_element_quantitative_data($description_element, $feature_block_settings);
1381
            break;
1382
          case 'IndividualsAssociation':
1383
            $elements_out_array[] = compose_description_element_individuals_association($description_element, $feature_block_settings);
1384
            break;
1385
          case 'TaxonInteraction':
1386
            $elements_out_array[] = compose_description_element_taxon_interaction($description_element, $feature_block_settings);
1387
            break;
1388
          case 'CommonTaxonName':
1389
            $elements_out_array[] = compose_description_element_common_taxon_name($description_element, $feature_block_settings);
1390
            break;
1391
          case 'Uses':
1392
            /* IGNORE Uses classes, these are handled completely in theme_cdm_UseDescription */
1393
            break;
1394
          default:
1395
            $feature_block_has_content = true;
1396
            $elements_out_array[] = markup_to_render_array('<li>No method for rendering unknown description class: ' . $description_element->class . '</li>');
1397
        }
1398
        $elements_out_array_last_item = $elements_out_array[count($elements_out_array) - 1];
1399
        // considering not empty as long as the last item added is a render array
1400
        $feature_block_has_content = $feature_block_has_content || !empty($elements_out_array_last_item['#type']);
1401
      }
1402

    
1403
      // If feature = CITATION sort the list of sources.
1404
      // This is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE.
1405
      if (isset($description_element) && $description_element->feature->uuid == UUID_CITATION) {
1406
        sort($elements_out_array);
1407
      }
1408
    }
1409

    
1410
    return $elements_out_array;
1411
  }
1412

    
1413
/**
1414
 * Composes block of common names for the given DescriptionElements $elements which must be of the feature CommonName
1415
 *
1416
 * @parameter $elements
1417
 *  an array of CDM DescriptionElements either of type CommonName or TextData
1418
 * @parameter $feature
1419
 *  the common feature of all $elements, must be CommonName
1420
 *
1421
 * @return
1422
 *   A drupal render array
1423
 *
1424
 * @ingroup compose
1425
 */
1426
function compose_feature_block_items_feature_common_name($elements, $feature, $weight = FALSE) {
1427

    
1428
  $common_name_out = '';
1429
  $common_name_feature_elements = array();
1430
  $textData_commonNames = array();
1431

    
1432
  $footnote_key_suggestion = 'common-names-feature-block';
1433

    
1434
  $feature_block_settings = get_feature_block_settings(UUID_COMMON_NAME);
1435

    
1436
  if (is_array($elements)) {
1437
    foreach ($elements as $element) {
1438

    
1439
      if ($element->class == 'CommonTaxonName') {
1440

    
1441
        // common name without a language or area, should not happen but is possible
1442
        $language_area_key = '';
1443
        if (isset($element->language->representation_L10n)) {
1444
          $language_area_key .= '<span class="language-label">' . $element->language->representation_L10n . '</span>';
1445
        }
1446
        if(isset($element->area->titleCache) && strlen($element->area->titleCache) > 0){
1447
          $language_area_key .= ($language_area_key ? ' '  : '') . '(' . $element->area->titleCache . ')';
1448
        }
1449

    
1450
        if(isset($common_names[$language_area_key][$element->name])) {
1451
          // same name already exists for language and area combination, se we merge the description elements
1452
          cdm_merge_description_elements($common_names[$language_area_key][$element->name], $element);
1453
        } else{
1454
          // otherwise add as new entry
1455
          $common_names[$language_area_key][$element->name] = $element;
1456
        }
1457

    
1458
      }
1459
      elseif ($element->class == 'TextData') {
1460
        $textData_commonNames[] = $element;
1461
      }
1462
    }
1463
  }
1464
  // Handling common names.
1465
  if (isset($common_names) && count($common_names) > 0) {
1466
    // Sorting the array based on the key (language, + area if set).
1467
    // Comment @WA there are common names without a language, so this sorting
1468
    // can give strange results.
1469
    ksort($common_names);
1470

    
1471
    // loop over set of elements per language area
1472
    foreach ($common_names as $language_area_key => $elements) {
1473
      ksort($elements); // sort names alphabetically
1474
      $per_language_area_out = array();
1475

    
1476
      foreach ($elements as $element) {
1477
        $common_name_render_array = compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key_suggestion);
1478
        $common_name_markup = drupal_render($common_name_render_array);
1479
        // IMPORTANT!
1480
        // during the above drupal_render the theme_html_tag function is executed, which adds a "\n" character to the end of the markup
1481
        // this is an error and the trailing whitespace needs to be removed
1482
        if(str_endsWith($common_name_markup, "\n")){
1483
          $common_name_markup = substr($common_name_markup, 0, strlen($common_name_markup) - 1);
1484
        }
1485
        $per_language_area_out[] = $common_name_markup;
1486
      }
1487

    
1488
      $common_name_feature_elements[] = ($language_area_key ? $language_area_key . ': ' : '' ) . join(', ', $per_language_area_out);
1489
    } // End of loop over set of elements per language area
1490

    
1491

    
1492
    $common_name_feature_elements_render_array = compose_feature_block_wrap_elements(
1493
      $common_name_feature_elements, $feature, '; ', FALSE
1494
    );
1495
    $common_name_out .= drupal_render($common_name_feature_elements_render_array); // FIXME should this be a render array instead?
1496

    
1497
  }
1498

    
1499
  // Handling commons names as text data.
1500
  $text_data_out = array();
1501

    
1502
  foreach ($textData_commonNames as $text_data_element) {
1503
    /* footnotes are not handled correctly in compose_description_element_text_data,
1504
       need to set 'common-names-feature-block' as $footnote_key_suggestion */
1505
    RenderHints::setFootnoteListKey($footnote_key_suggestion);
1506
    $text_data_render_array = compose_description_element_text_data($text_data_element, $text_data_element->feature->uuid, $feature_block_settings);
1507
    $text_data_out[] = drupal_render($text_data_render_array);
1508
  }
1509

    
1510
  $common_name_out_text_data = compose_feature_block_wrap_elements(
1511
    $text_data_out, $feature
1512
  );
1513

    
1514
  $footnotes = theme('cdm_footnotes', array('footnoteListKey' => 'BIBLIOGRAPHY-' . $footnote_key_suggestion));
1515
  $footnotes .= theme('cdm_footnotes', array('footnoteListKey' => $footnote_key_suggestion)); // FIXME is this needed at all?
1516
  $footnotes .= theme('cdm_annotation_footnotes', array('footnoteListKey' => $footnote_key_suggestion));
1517

    
1518
  return  markup_to_render_array(  // FIXME markup_to_render_array should no longer be needed
1519
    '<div class="common-taxon-name">' . $common_name_out . '</div>'
1520
    .'<div class="text-data">' . drupal_render($common_name_out_text_data) . '</div>'
1521
    .$footnotes,
1522
    $weight
1523
  );
1524
}
1525

    
1526
/**
1527
 * Renders a single instance of the type CommonTaxonName.
1528
 *
1529
 * @param $element
1530
 *   The CDM CommonTaxonName entity.
1531
 * @param $feature_block_settings
1532
 *
1533
 * @param $footnote_key_suggestion
1534
 *
1535
 * @param $element_tag_name
1536
 *
1537
 * @return array
1538
 *   Drupal render array
1539
 *
1540
 * @ingroup compose
1541
 */
1542
function compose_description_element_common_taxon_name($element, $feature_block_settings, $footnote_key_suggestion = NULL)
1543
{
1544

    
1545
  if(!$footnote_key_suggestion) {
1546
    $footnote_key_suggestion = $element->feature->uuid;
1547
  }
1548

    
1549
  $name = '';
1550
  if(isset($element->name)){
1551
    $name = $element->name;
1552
  }
1553

    
1554

    
1555
  return compose_description_element($element, $feature_block_settings, $name, $footnote_key_suggestion);
1556
}
1557

    
1558
/**
1559
 * Composes the render array for a CDM Distribution description element
1560
 *
1561
 * @param array $description_elements
1562
 *   Array of CDM Distribution instances
1563
 * @param $enclosingTag
1564
 *   The html tag to be use for the enclosing element
1565
 *
1566
 * @return array
1567
 *   A Drupal render array
1568
 *
1569
 * @ingroup compose
1570
 */
1571
function compose_description_elements_distribution($description_elements){
1572

    
1573
  $out = '';
1574
  RenderHints::pushToRenderStack('descriptionElementDistribution');
1575
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1576

    
1577
  $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
1578
  $enclosingTag = cdm_feature_block_element_tag_name($feature_block_settings);
1579

    
1580
  foreach ($description_elements as $description_element) {
1581
    $annotations_and_sources = handle_annotations_and_sources(
1582
      $description_element,
1583
      $feature_block_settings,
1584
      $description_element->area->representation_L10n,
1585
      UUID_DISTRIBUTION
1586
    );
1587

    
1588

    
1589
    list($status_label, $status_markup) = distribution_status_label_and_markup($description_element);
1590

    
1591
    $out .= '<' . $enclosingTag . ' class="descriptionElement descriptionElement-' . $description_element->uuid
1592
      . ' " title="' . $status_label. '">'
1593
      . $description_element->area->representation_L10n
1594
      . $status_markup;
1595
    if(!empty($annotations_and_sources['source_references'])){
1596
      $out .= ' ' . join(' ', $annotations_and_sources['source_references'] );
1597
    }
1598
    $out .= $annotations_and_sources['foot_note_keys']   . ' </' . $enclosingTag . '>';
1599
  }
1600

    
1601
  RenderHints::popFromRenderStack();
1602
  return markup_to_render_array($out);
1603
}
1604

    
1605
  /**
1606
   * @param $descriptionElement
1607
   * @return array
1608
   */
1609
  function distribution_status_label_and_markup($descriptionElement) {
1610
    $status_markup = '';
1611
    $status_label = '';
1612

    
1613
    if (isset($descriptionElement->status)) {
1614
      $status_label = $descriptionElement->status->representation_L10n;
1615
      $status_markup = '<span class="distributionStatus distributionStatus-' . $descriptionElement->status->idInVocabulary . '"> '
1616
        . $status_label . ' </span>';
1617

    
1618
    };
1619
    return array($status_label, $status_markup);
1620
  }
1621

    
1622

    
1623
  /**
1624
   * Provides the merged feature tree for a taxon profile page.
1625
   *
1626
   * The merging of the profile feature tree is actully done in
1627
   * _mergeFeatureTreeDescriptions(). See this method  for details
1628
   * on the structure of the merged tree.
1629
   *
1630
   * This method provides t hook which can be used to modify the
1631
   * merged feature tree after it has been created, see
1632
   * hook_merged_taxon_feature_tree_alter()
1633
   *
1634
   * @param $taxon
1635
   *   A CDM Taxon instance
1636
   *
1637
   * @return object
1638
   *  The merged feature tree
1639
   *
1640
   */
1641
  function merged_taxon_feature_tree($taxon) {
1642

    
1643
    // 1. fetch descriptions_by_featuretree but exclude the distribution feature
1644
    $merged_tree = cdm_ws_descriptions_by_featuretree(get_profile_feature_tree(), $taxon->uuid, array(UUID_DISTRIBUTION));
1645

    
1646

    
1647
    // 2. find the distribution feature node
1648
    $distribution_node =& cdm_feature_tree_find_node($merged_tree->root->childNodes, UUID_DISTRIBUTION);
1649

    
1650
    if ($distribution_node) {
1651
      // 3. get the distributionInfoDTO
1652
      $query_parameters = cdm_distribution_filter_query();
1653
      $query_parameters['part'] = array('mapUriParams');
1654
      if(variable_get(DISTRIBUTION_CONDENSED)){
1655
        $query_parameters['part'][] = 'condensedDistribution';
1656
      }
1657
      if (variable_get(DISTRIBUTION_ORDER_MODE, DISTRIBUTION_ORDER_MODE_DEFAULT) == 'TREE') {
1658
        $query_parameters['part'][] = 'tree';
1659
      }
1660
      else {
1661
        $query_parameters['part'][] = 'elements';
1662
      }
1663
      $query_parameters['omitLevels'] = array();
1664
      foreach(variable_get(DISTRIBUTION_TREE_OMIT_LEVELS, array()) as $uuid){
1665
        if(is_uuid($uuid)){
1666
          $query_parameters['omitLevels'][] = $uuid;
1667
        }
1668
      }
1669
      $customStatusColorsJson = variable_get(DISTRIBUTION_STATUS_COLORS, NULL);
1670
      if ($customStatusColorsJson) {
1671
        $query_parameters['statusColors'] = $customStatusColorsJson;
1672
      }
1673

    
1674
      $distribution_info_dto = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_INFO_FOR, $taxon->uuid, queryString($query_parameters));
1675
      // 4. get distribution TextData is there are any
1676
      $distribution_text_data = cdm_ws_fetch_all(CDM_WS_DESCRIPTIONELEMENT_BY_TAXON,
1677
        array(
1678
          'taxon' => $taxon->uuid,
1679
          'type' => 'TextData',
1680
          'features' => UUID_DISTRIBUTION
1681
        )
1682
      );
1683

    
1684
      // 5. put all distribution data into the distribution feature node
1685
      if ($distribution_text_data //if text data exists
1686
        || ($distribution_info_dto && isset($distribution_info_dto->tree) && $distribution_info_dto->tree->rootElement->numberOfChildren > 0) // OR if tree element has distribution elements
1687
        || ($distribution_info_dto && !empty($distribution_info_dto->elements))
1688
      ) { // OR if DTO has distribution elements
1689
        $distribution_node->descriptionElements = array('#type' => 'DTO');
1690
        if ($distribution_text_data) {
1691
          $distribution_node->descriptionElements['TextData'] = $distribution_text_data;
1692
        }
1693
        if ($distribution_info_dto) {
1694
          $distribution_node->descriptionElements['DistributionInfoDTO'] = $distribution_info_dto;
1695
        }
1696
      }
1697
    }
1698

    
1699
    // allows modifying the merged tree via a the hook_cdm_feature_node_block_content_alter
1700
    drupal_alter('merged_taxon_feature_tree', $taxon, $merged_tree);
1701

    
1702
    return $merged_tree;
1703
  }
1704

    
1705

    
1706
  function compose_distribution_hierarchy($distribution_tree, $feature_block_settings){
1707

    
1708
    static $hierarchy_style;
1709
    // TODO expose $hierarchy_style to administration of provide a hook
1710
    if( !isset($hierarchy_style)){
1711
      $hierarchy_style = array(
1712
        // level 2
1713
        array(
1714
          'label_suffix' => '',
1715
          'element_glue' => ', ',
1716
          'element_set_pre' => '(',
1717
          'element_set_post' => ')'
1718
        ),
1719
        // level 1
1720
        array(
1721
          'label_suffix' => '',
1722
          'element_glue' => '; ',
1723
          'element_set_pre' => '',
1724
          'element_set_post' => ''
1725
        ),
1726
        // level 0
1727
        array(
1728
          'label_suffix' => ':',
1729
          'element_glue' => ' ',
1730
          'element_set_pre' => '',
1731
          'element_set_post' => ''
1732
        ),
1733
      );
1734
    }
1735

    
1736
    $render_array = array();
1737

    
1738
    RenderHints::pushToRenderStack('descriptionElementDistribution');
1739
    RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
1740

    
1741
    // Returning NULL if there are no description elements.
1742
    if ($distribution_tree == null) {
1743
      return $render_array;
1744
    }
1745
    // for now we are not using a render array internally to avoid performance problems
1746
    $markup = '';
1747
    if (isset($distribution_tree->rootElement->children)) {
1748
      $tree_nodes = $distribution_tree->rootElement->children;
1749
      _compose_distribution_hierarchy($tree_nodes, $feature_block_settings, $markup, $hierarchy_style);
1750
    }
1751

    
1752
    $render_array['distribution_hierarchy'] = markup_to_render_array(
1753
      $markup,
1754
      0,
1755
      '<div id="distribution_hierarchy" class="distribution_hierarchy">',
1756
      '</div>'
1757
    );
1758

    
1759
    return $render_array;
1760
  }
1761

    
1762
  /**
1763
   * this function should produce markup as the compose_description_elements_distribution()
1764
   * function.
1765
   *
1766
   * @see compose_description_elements_distribution()
1767
   *
1768
   * @param $distribution_tree
1769
   * @param $feature_block_settings
1770
   * @param $tree_nodes
1771
   * @param $markup
1772
   * @param $hierarchy_style
1773
   */
1774
  function _compose_distribution_hierarchy($tree_nodes, $feature_block_settings, &$markup, $hierarchy_style, $level_index = -1){
1775

    
1776
    $level_index++;
1777
    static $enclosingTag = "span";
1778

    
1779
    $level_style = array_pop($hierarchy_style);
1780
    if(count($hierarchy_style) == 0){
1781
      // lowest defined level style will be reused for all following levels
1782
      $hierarchy_style[] = $level_style;
1783
    }
1784

    
1785
    $node_index = -1;
1786
    $per_node_markup = array();
1787
    foreach ($tree_nodes as $node){
1788

    
1789
      $per_node_markup[++$node_index] = '';
1790

    
1791
      $label = $node->nodeId->representation_L10n;
1792

    
1793
      $distributions = $node->data;
1794
      $distribution_uuids = array();
1795
      $distribution_aggregate = NULL;
1796
        foreach($distributions as $distribution){
1797

    
1798
          $distribution_uuids[] = $distribution->uuid;
1799

    
1800
          // if there is more than one distribution we aggregate the sources and
1801
          // annotations into a synthetic distribution so that the footnote keys
1802
          // can be rendered consistently
1803
          if(!$distribution_aggregate) {
1804
            $distribution_aggregate = $distribution;
1805
            if(!isset($distribution_aggregate->sources[0])){
1806
              $distribution_aggregate->sources = array();
1807
            }
1808
            if(!isset($distribution_aggregate->annotations[0])){
1809
              $distribution_aggregate->annotations = array();
1810
            }
1811
          } else {
1812
            if(isset($distribution->sources[0])) {
1813
              $distribution_aggregate->sources = array_merge($distribution_aggregate->sources,
1814
                $distribution->sources);
1815
            }
1816
            if(isset($distribution->annotations[0])) {
1817
              $distribution_aggregate->annotations = array_merge($distribution_aggregate->annotations,
1818
                $distribution->annotations);
1819
            }
1820
          }
1821
        }
1822

    
1823
      $status_label= '';
1824
      $status_markup = '';
1825
      $annotations_and_sources =  null;
1826
      if($distribution_aggregate) {
1827
        $annotations_and_sources = handle_annotations_and_sources(
1828
          $distribution_aggregate,
1829
          $feature_block_settings,
1830
          $label,
1831
          UUID_DISTRIBUTION
1832
        );
1833

    
1834
        list($status_label, $status_markup) = distribution_status_label_and_markup($distribution);
1835
      }
1836

    
1837
      $per_node_markup[$node_index] .= '<' . $enclosingTag . ' class="descriptionElement'
1838
        . join(' descriptionElement-', $distribution_uuids)
1839
        . ' level_index_' . $level_index
1840
        . ' " title="' . $status_label . '">'
1841
        . '<span class="area_label">' . $label
1842
        . $level_style['label_suffix'] . ' </span>'
1843
        .  $status_markup
1844
      ;
1845

    
1846
      if(isset($annotations_and_sources)){
1847
        if(!empty($annotations_and_sources['source_references'])){
1848
          $per_node_markup[$node_index] .= ' ' . join(', ' , $annotations_and_sources['source_references']);
1849
        }
1850
        if($annotations_and_sources['foot_note_keys']) {
1851
          $per_node_markup[$node_index] .= $annotations_and_sources['foot_note_keys'];
1852
        }
1853
      }
1854

    
1855
      if(isset($node->children[0])){
1856
        _compose_distribution_hierarchy(
1857
          $node->children,
1858
          $feature_block_settings,
1859
          $per_node_markup[$node_index],
1860
          $hierarchy_style,
1861
          $level_index
1862
        );
1863
      }
1864

    
1865
      $per_node_markup[$node_index] .= '</' . $enclosingTag . '>';
1866
    }
1867
    $markup .= $level_style['element_set_pre']  . join( $level_style['element_glue'], $per_node_markup) . $level_style['element_set_post'];
1868
  }
1869

    
1870

    
(2-2/8)