Project

General

Profile

Download (24.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Functions for dealing with CDM entities from the package model.name
5
 *
6
 * @copyright
7
 *   (C) 2007-2015 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
 * @defgroup compose Compose functions
21
 * @{
22
 * Functions which are composing Drupal render arays
23
 *
24
 * The cdm_dataportal module needs to compose rather complex render arrays from
25
 * the data returned by the CDM REST service. The compose functions are
26
 * responsible for creating the render arrays.
27
 *
28
 * All these functions are also implementations of the compose_hook()
29
 * which is used in the proxy_content() function.
30
 * @}
31
 */
32

    
33

    
34
/**
35
 * Provides the name render template to be used within the page elements identified the the $renderPath.
36
 *
37
 * The render templates arrays contains one or more name render templates to be used within the page elements identified the the
38
 * renderPath. The renderPath is the key of the subelements whereas the value is the name render template.
39
 *
40
 * The render paths used for a cdm_dataportal page can be visualized by supplying the HTTP query parameter RENDER_PATH=1.
41
 *
42
 * It will be tried to find  the best matching default RenderTemplate by stripping the dot separated render path
43
 * element by element. If no matching template is found the DEFAULT will be used:
44
 *
45
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
46
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
47
 * - related_taxon.heterotypicSynonymyGroup.taxon_page_synonymy
48
 *
49
 * A single render template can be used for multiple render paths. In this case the according key of the render templates
50
 * array element should be the list of these render paths concatenated by ONLY a comma character without any whitespace.
51
 *
52
 * A render template is an associative array. The keys of this array are referring to the keys as defined in the part
53
 * definitions array.
54
 * @see get_partDefinition($taxonNameType) for more information
55
 *
56
 * The value of the render template element must be set to TRUE in order to let this part being rendered.
57
 * The namePart, nameAuthorPart and referencePart can also hold an associative array with a single
58
 * element: array('#uri' => TRUE). The value of the #uri element will be replaced by the according
59
 * links if the parameters $nameLink or $refenceLink are set.
60
 *
61
 * @param string $render_path
62
 *   The render path can consist of multiple dot separated elements
63
 *   @see RenderHints::getRenderPath()
64
 * @param string $nameLink
65
 *   The link path ot URL to be used for name parts if a link is forseen in the template
66
 *   matching the given $renderPath.
67
 * @param string $referenceLink
68
 *   The link path ot URL to be used for nomenclatural reference parts if a link is forseen
69
 *   in the template matching the given $renderPath.
70
 * @return array
71
 *   An associative array, the render template
72
 */
73
function get_nameRenderTemplate($render_path, $nameLink = NULL, $referenceLink = NULL) {
74

    
75
  static $default_render_templates = NULL;
76
  static $split_render_templates = NULL;
77

    
78

    
79
  if (!isset($default_render_templates)) {
80
    $default_render_templates = unserialize(CDM_NAME_RENDER_TEMPLATES_DEFAULT);
81
  }
82
  if($split_render_templates == NULL) {
83
    $render_templates = variable_get(CDM_NAME_RENDER_TEMPLATES, $default_render_templates);
84
    // needs to be converted to an array
85
    $render_templates = (convert_to_array($render_templates));
86

    
87
    // separate render templates which are combined with a comma
88
    $split_render_templates = array();
89
    foreach($render_templates as $key => $template){
90
      if(strpos($key, ',')){
91
        foreach(explode(',', $key) as $path){
92
          $split_render_templates[$path] = $template;
93
        }
94
      } else {
95
        $split_render_templates[$key] = $template;
96
      }
97
    }
98
  }
99

    
100
  // get the base element of the renderPath
101
  if (($separatorPos = strpos($render_path, '.')) > 0) {
102
    $renderPath_base = substr($render_path, 0, $separatorPos);
103
  } else {
104
    $renderPath_base = $render_path;
105
  }
106

    
107
  $template = NULL;
108
  // 1. try to find a template using the render path base element
109
  if(array_key_exists($renderPath_base, $split_render_templates)){
110
    $template = (array)$split_render_templates[$renderPath_base];
111
  }
112

    
113
  // 2. Find best matching default RenderTemplate
114
  // by stripping the dot separated render path element by element
115
  // if no matching template is found the DEFAULT will be used.
116
  while (!is_array($template) && strlen($render_path) > 0) {
117
    foreach ($split_render_templates as $path => $t) {
118
      if ($path == $render_path) {
119
        $template = $t;
120
        break;
121
      }
122
    }
123
    // shorten by one element
124
    $render_path = substr($render_path, strrpos($render_path, '.') + 1, strlen($render_path));
125
  }
126

    
127

    
128
  // 3. Otherwise get default RenderTemplate from theme.
129
  if (!is_array($template)) {
130
    $template = $split_render_templates['#DEFAULT'];
131
  }
132

    
133
  // --- set the link uris to the according template fields if they exist
134
  if(isset($template['nameAuthorPart']) && isset($template['nameAuthorPart']['#uri'])) {
135
    if ($nameLink) {
136
      $template['nameAuthorPart']['#uri'] = $nameLink;
137
    }
138
    else {
139
      unset($template['nameAuthorPart']['#uri']);
140
    }
141
  }
142

    
143
  if ($nameLink && isset($template['namePart']['#uri'])) {
144
    $template['namePart']['#uri'] = $nameLink;
145
  }
146
  else {
147
    unset($template['namePart']['#uri']);
148
  }
149

    
150
  if ($referenceLink && isset($template['referencePart']['#uri'])) {
151
    $template['referencePart']['#uri'] = $referenceLink;
152
  }
153
  else {
154
    unset($template['referencePart']['#uri']);
155
  }
156

    
157
  return $template;
158
}
159

    
160
/**
161
 * The part definitions define the specific parts of which a rendered taxon name plus additional information will consist.
162
 *
163
 * A full taxon name plus additional information can consist of the following elements:
164
 *
165
 *   - name: the taxon name inclugin rank nbut without author
166
 *   - authorTeam:  The authors of a reference, also used in taxon names
167
 *   - authors:  The authors of a reference, also used in taxon names
168
 *   - reference: the nomenclatural reference,
169
 *   - microreference:  Volume, page number etc.
170
 *   - status:  The nomenclatural status of a name
171
 *   - description: name descriptions like protologues etc ...
172
 *
173
 * These elements are combined in the part definitions array to from the specific parts to be rendered.
174
 * Usually the following parts are formed:
175
 *
176
 * The name "Lapsana communis L., Sp. Pl.: 811. 1753" shall be an example here:
177
 *  - namePart: the name and rank (in example: "Lapsana communis")
178
 *  - authorshipPart: the author (in example: "L.")
179
 *  - nameAuthorPart: the combination of name and author part (in example: "Lapsana communis L.").
180
 *     This is useful for zoological names where the authorshipPart belongs to the name and both should
181
 *     be combined when a link to the taxon is rendered.
182
 *  - referencePart: the nomencaltural reference (in example: "Sp. Pl. 1753")
183
 *  - microreferencePart: usually the page number (in example ": 811.")
184
 *  - statusPart: the nomenclatorical status
185
 *  - descriptionPart:
186
 *
187
 * Each set of parts is dedicated to render a specific TaxonName type, the type names are used as keys for the
188
 * specific parts part definitions:
189
 *
190
 *  - BotanicalName
191
 *  - ZoologicalName
192
 *  - #DEFAULT:  covers ViralNames and general NonViralNames
193
 *
194
 * An example:
195
 * @code
196
 * array(
197
 *    'ZoologicalName' => array(
198
 *        'namePart' => array('name' => TRUE),
199
 *        'referencePart' => array('authorTeam' => TRUE),
200
 *        'microreferencePart' => array('microreference' => TRUE),
201
 *        'statusPart' => array('status' => TRUE),
202
 *        'descriptionPart' => array('description' => TRUE),
203
 *    ),
204
 *    'BotanicalName' => array(
205
 *        'namePart' => array(
206
 *            'name' => TRUE,
207
 *            'authors' => TRUE,
208
 *        ),
209
 *        'referencePart' => array(
210
 *            'reference' => TRUE,
211
 *            'microreference' => TRUE,
212
 *        ),
213
 *        'statusPart' => array('status' => TRUE),
214
 *        'descriptionPart' => array('description' => TRUE),
215
 *    ),
216
 *  );
217
 * @endcode
218
 *
219
 */
220
function get_partDefinition($taxonNameType) {
221

    
222
  static $default_part_definitions = null;
223
  if (!isset($default_part_definitions)) {
224
    $default_part_definitions= unserialize(CDM_PART_DEFINITIONS_DEFAULT);
225
  }
226

    
227
  static $part_definitions = null;
228
  if (!isset($part_definitions)) {
229
    $part_definitions = convert_to_array(variable_get(CDM_PART_DEFINITIONS, $default_part_definitions));
230
  }
231

    
232
  if (array_key_exists($taxonNameType, $part_definitions)) {
233
    return $part_definitions[$taxonNameType];
234
  } else {
235
    return $part_definitions['#DEFAULT']; // covers ViralNames and general NonViralNames
236
  }
237

    
238
}
239

    
240

    
241
/**
242
 * Renders the markup for a CDM TaxonName instance.
243
 *
244
 * The layout of the name representation is configured by the
245
 * part_definitions and render_templates (see get_partDefinition() and
246
 * get_nameRenderTemplate())
247
 *
248
 * @param $taxonName
249
 *    cdm TaxonNameBase instance
250
 * @param $sec
251
 *    the sec reference of a taxon having this name (optional)
252
 * @param $nameLink
253
 *    URI to the taxon, @see path_to_taxon(), must be processed by url() before passing to this method
254
 * @param $refenceLink
255
 *    URI to the reference, @see path_to_reference(), must be processed by url() before passing to this method
256
 * @param $show_annotations
257
 *    turns the display of annotations on
258
 * @param $is_type_designation
259
 *    To indicate that the supplied taxon name is a name type designation.
260
 * @param $skiptags
261
 *    an array of name elements tags like 'name', 'rank' to skip. The name part
262
 *          'authors' will not ber affected by this filter. This part is managed though the render template
263
 *          mechanism.
264
 * @param $is_invalid
265
 *   Indicates that this taxon is invalid. In this case the name part will be shown in double quotes.
266
 *   This is useful when rendering taxon relation ships.
267
 *
268
 * @return string
269
 *  The markup for a taxon name.
270
 *
271
 */
272
function render_taxon_or_name($taxon_name_or_taxon_base, $nameLink = NULL, $refenceLink = NULL,
273
  $show_annotations = true, $is_type_designation = false, $skiptags = array(), $is_invalid = false) {
274

    
275
  $is_doubtful = false;
276

    
277
  if($taxon_name_or_taxon_base->class == 'Taxon' || $taxon_name_or_taxon_base->class == 'Synonym'){
278
    $taxonName = $taxon_name_or_taxon_base->name;
279
    $is_doubtful = $taxon_name_or_taxon_base->doubtful;
280
    // use the TaxonBase.taggedTitle so we have the secRef
281
    $taggedTitle = $taxon_name_or_taxon_base->taggedTitle;
282
  } else {
283
    // assuming this is a TaxonNameBase
284
    $taxonName = $taxon_name_or_taxon_base;
285
    $taggedTitle = $taxon_name_or_taxon_base->taggedName;
286
  }
287

    
288

    
289
  $renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
290
  $partDefinition = get_partDefinition($taxonName->class);
291

    
292
  // Apply definitions to template.
293
  foreach ($renderTemplate as $part => $uri) {
294

    
295
    if (isset($partDefinition[$part])) {
296
      $renderTemplate[$part] = $partDefinition[$part];
297
    }
298
    if (is_array($uri) && isset($uri['#uri'])) {
299
      $renderTemplate[$part]['#uri'] = $uri['#uri'];
300
    }
301
  }
302

    
303
  $secref_tagged_text = split_secref_from_tagged_text($taggedTitle);
304
  $nom_status_tagged_text = split_nomstatus_from_tagged_text($taggedTitle);
305
  $appended_phrase_tagged_text = array(); // this is filled later
306

    
307
  normalize_tagged_text($taggedTitle);
308

    
309
  $firstEntryIsValidNamePart =
310
    isset($taggedTitle)
311
    && is_array($taggedTitle)
312
    && isset($taggedTitle[0]->text)
313
    && is_string($taggedTitle[0]->text)
314
    && $taggedTitle[0]->text != ''
315
    && isset($taggedTitle[0]->type)
316
    && $taggedTitle[0]->type == 'name';
317
  $lastAuthorElementString = FALSE;
318

    
319
  $name_encasement = $is_invalid ? '"' : '';
320
  $doubtful_marker = $is_doubtful ? '? ' : '';
321

    
322
  // split off all appendedPhrase item  from the end of the array (usually there only should  be one)
323
  while($taggedTitle[count($taggedTitle)-1]->type == "appendedPhrase"){
324
    $appended_phrase_tagged_text[] = array_pop($taggedTitle);
325
  }
326

    
327
  // Got to use second entry as first one, see ToDo comment below ...
328
  if ($firstEntryIsValidNamePart) {
329

    
330
    $taggedName = $taggedTitle;
331
    $hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
332
    $hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
333

    
334

    
335
    if (!(($hasNamePart_with_Authors) || ($hasNameAuthorPart_with_Authors))) {
336
      // Find author and split off from name.
337
      // TODO expecting to find the author as the last element.
338
      /*
339
      if($taggedName[count($taggedName)- 1]->type == 'authors'){
340
        $authorTeam = $taggedName[count($taggedName)- 1]->text;
341
        unset($taggedName[count($taggedName)- 1]);
342
      }
343
      */
344

    
345
      // Remove all authors.
346
      $taggedNameNew = array();
347
      foreach ($taggedName as $element) {
348
        if ($element->type != 'authors') {
349
          $taggedNameNew[] = $element;
350
        }
351
        else {
352
          $lastAuthorElementString = $element->text;
353
        }
354
      }
355
      $taggedName = $taggedNameNew;
356
      unset($taggedNameNew);
357
    }
358
    $name = '<span class="' . $taxonName->class . '">' . $doubtful_marker . $name_encasement . cdm_tagged_text_to_markup($taggedName, 'span', ' ', $skiptags) . $name_encasement . '</span>';
359
  }
360
  else {
361
    $name = '<span class="' . $taxonName->class . '_titleCache">' . $doubtful_marker . $name_encasement . $taxonName->titleCache . $name_encasement . '</span>';
362
  }
363

    
364

    
365
  if(isset($appended_phrase_tagged_text[0])){
366
    $name .= ' '. cdm_tagged_text_to_markup($appended_phrase_tagged_text);
367
  }
368

    
369
  // Fill name into $renderTemplate.
370
  array_setr('name', $name , $renderTemplate);
371

    
372
  // Fill with authorTeam.
373
  /*
374
  if($authorTeam){
375
    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
376
    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
377
  }
378
  */
379

    
380
  // Fill with reference.
381
  if (isset($renderTemplate['referencePart']) && !$is_type_designation) {
382

    
383
    // default separator
384
    $separator = '';
385

    
386
    // [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
387
    // Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
388
    if (isset($renderTemplate['referencePart']['reference']) && isset($taxonName->nomenclaturalReference)) {
389
      $microreference = NULL;
390
      if (isset($renderTemplate['referencePart']['microreference'])&& isset($taxonName->nomenclaturalMicroReference)) {
391
        $microreference = $taxonName->nomenclaturalMicroReference;
392
      }
393
      $citation = cdm_ws_getNomenclaturalReference($taxonName->nomenclaturalReference->uuid, $microreference);
394

    
395
      // Find preceding element of the reference.
396
      $precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
397
      if (str_beginsWith($citation, ", in")) {
398
        $citation = substr($citation, 2);
399
        $separator = ' ';
400
      }
401
      elseif (!str_beginsWith($citation, "in") && $precedingKey == 'authors') {
402
        $separator = ', ';
403
      } else {
404
        $separator = ' ';
405
      }
406

    
407

    
408
      $referenceArray['#separator'] = $separator;
409
      $referenceArray['#html'] = '<span class="reference">' . $citation . '</span>';
410
      array_setr('reference', $referenceArray, $renderTemplate);
411
    }
412

    
413
    // If authors have been removed from the name part the last named authorteam
414
    // should be added to the reference citation, otherwise, keep the separator
415
    // out of the reference.
416
    if (isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString) {
417
      // If the nomenclaturalReference citation is not included in the
418
      // reference part but diplay of the microreference
419
      // is wanted, append the microreference to the authorTeam.
420
      $citation = '';
421
      if (!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])) {
422
        $separator = ": ";
423
        $citation = $taxonName->nomenclaturalMicroReference;
424
      }
425
      $referenceArray['#html'] = ' <span class="reference">' . $lastAuthorElementString . $separator . $citation . '</span>';
426
      array_setr('authors', $referenceArray, $renderTemplate);
427
    }
428
  }
429

    
430
  $is_reference_year = false;
431
  if (isset($renderTemplate['referenceYearPart']['reference.year'])) {
432
    if(isset($taxonName->nomenclaturalReference->datePublished)){
433
      $referenceArray['#html'] = ' <span class="reference">' . timePeriodToString($taxonName->nomenclaturalReference->datePublished) . '</span>';
434
      array_setr('reference.year', $referenceArray, $renderTemplate);
435
      $is_reference_year = true;
436
    }
437
  }
438

    
439
  // Fill with status.
440
  if(isset($renderTemplate['statusPart'])){
441
    if (isset($nom_status_tagged_text[0])) {
442
      if (array_setr('status', TRUE, $renderTemplate)) {
443
        array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, 'span', '', array('postSeparator')) . '</span>', $renderTemplate);
444
      }
445
    }
446
  }
447

    
448
  if (isset($renderTemplate['secReferencePart'])){
449
    if(isset($secref_tagged_text[1])){
450
      $post_separator_markup = $is_reference_year ? '.': '';
451
      if(isset($nom_status_tagged_text[count($nom_status_tagged_text) - 1]) && ($nom_status_tagged_text[count($nom_status_tagged_text) - 1]->type ==  'postSeparator')){
452
        $post_separator_markup = cdm_tagged_text_to_markup(array($nom_status_tagged_text[count($nom_status_tagged_text) - 1 ]));
453
      };
454
      array_setr('secReference',
455
        $post_separator_markup
456
          . ' <span class="sec_reference">'
457
          . join(' ', cdm_tagged_text_values($secref_tagged_text))
458
          . '</span>', $renderTemplate);
459
    }
460
  }
461

    
462
  // Fill with protologues etc...
463
  $descriptionHtml = '';
464
  if (array_setr('description', TRUE, $renderTemplate)) {
465
    $descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
466
    foreach ($descriptions as $description) {
467
      if (!empty($description)) {
468
        foreach ($description->elements as $description_element) {
469
          $second_citation = '';
470
          if (isset($description_element->multilanguageText_L10n) && $description_element->multilanguageText_L10n->text) {
471
            $second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
472
          }
473
          $descriptionHtml .= $second_citation;
474
          $descriptionHtml .= theme("cdm_media", array(
475
              'descriptionElement' => $description_element,
476
              'mimeTypePreference' => array(
477
                'application/pdf',
478
                'image/png',
479
                'image/jpeg',
480
                'image/gif',
481
                'text/html',
482
              )
483
            )
484
          );
485

    
486
        }
487
      }
488
    }
489
    array_setr('description', $descriptionHtml, $renderTemplate);
490
  }
491

    
492
  // Render.
493
  $out = '';
494
  if(isset($_REQUEST['RENDER_PATH'])){
495
    // developer option to show the render path with each taxon name
496
    $out .= '<span class="render-path">' . RenderHints::getRenderPath() . '</span>';
497
  }
498
  $out .= '<span class="' . html_class_attribute_ref($taxon_name_or_taxon_base)
499
    . '" data-cdm-ref="/name/' . $taxonName->uuid . '" data-cdm-render-path="' . RenderHints::getRenderPath() .'">';
500

    
501
  foreach ($renderTemplate as $partName => $part) {
502
    $separator = '';
503
    $partHtml = '';
504
    $uri = FALSE;
505
    if (!is_array($part)) {
506
      continue;
507
    }
508
    if (isset($part['#uri']) && is_string($part['#uri'])) {
509
      $uri = $part['#uri'];
510
      unset($part['#uri']);
511
    }
512
    foreach ($part as $key => $content) {
513
      $html = '';
514
      if (is_array($content)) {
515
        $html = $content['#html'];
516
        if(isset($content['#separator'])) {
517
          $separator = $content['#separator'];
518
        }
519
      }
520
      elseif (is_string($content)) {
521
        $html = $content;
522
      }
523
      $partHtml .= '<span class="' . $key . '">' . $html . '</span>';
524
    }
525
    if ($uri) {
526
      // cannot use l() here since the #uri aleady should have been processed through uri() at this point
527
      $out .= $separator . '<a href="' . $uri . '" class="' . $partName . '">' . $partHtml . '</a>';
528

    
529
    }
530
    else {
531
      $out .= $separator . $partHtml;
532
    }
533
  }
534
  $out .= '</span>';
535
  if ($show_annotations) {
536
    // $out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
537
  }
538
  return $out;
539
}
540

    
541
/**
542
 * Renders the string of Homonyms for a given taxon.
543
 *
544
 * @param $taxon
545
 *    A CDM Taxon instance
546
 * @return String
547
 *    The string of homomyns
548
 *
549
 * @throws \Exception
550
 */
551
function cdm_name_relationships_of($taxon) {
552

    
553
  static $inverse_name_rels_uuids = array(UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR);
554

    
555
  // =========== START OF HOMONYMS ========== //
556
  RenderHints::pushToRenderStack('homonym');
557
  // the render stack element homonyms is being used in the default render templates !!!, see CDM_NAME_RENDER_TEMPLATES_DEFAULT
558

    
559
  $selected_name_rel_uuids = variable_get(CDM_NAME_RELATIONSHIP_TYPES, unserialize(CDM_NAME_RELATIONSHIP_TYPES_DEFAULT));
560

    
561
  $from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS,
562
    $taxon->uuid);
563
  $to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS,
564
    $taxon->uuid);
565
  $name_relations = array_merge($from_name_relations, $to_name_relations);
566

    
567
  $homonyms_array = array();
568

    
569
  if ($name_relations) {
570
    foreach ($name_relations as $element) {
571
      if(!isset($selected_name_rel_uuids[$element->type->uuid])){
572
        // skip if not selected in the settings
573
        continue;
574
      }
575

    
576
      if(isset($inverse_name_rels_uuids[$element->type->uuid])) {
577
        // case of UUID_NAMERELATIONSHIPTYPE_BLOCKING_NAME_FOR
578
        //to relation ships -> only shown at toName-synonym
579
        $elementTaxonBasesUuid = isset ($element->fromName->taxonBases [0]->uuid) ? $element->fromName->taxonBases [0]->uuid : '';
580
        if ($taxon->name->uuid == $element->toName->uuid) {
581
          $taxon_html = render_taxon_or_name($element->fromName,
582
            url(path_to_name($element->fromName->uuid, $taxon->uuid, $elementTaxonBasesUuid))
583
          );
584
        }
585
      } else {
586
        $elementTaxonBasesUuid = isset ($element->toName->taxonBases [0]->uuid) ? $element->toName->taxonBases [0]->uuid : '';
587
        //from relation ships -> only shown at fromName-synonym
588
        if ($taxon->name->uuid == $element->fromName->uuid) {
589
          $taxon_html =render_taxon_or_name($element->toName,
590
            url(path_to_name($element->toName->uuid, $taxon->uuid, $elementTaxonBasesUuid))
591
          );
592
        }
593
      }
594

    
595
      if (count($homonyms_array)) {
596
        // lat: "non nec" == german: "weder noch"
597
        $homonyms_array [] = 'nec ' . $taxon_html;
598
      } else {
599
        $homonyms_array [] = 'non ' . $taxon_html;
600
      }
601

    
602
    }
603
  }
604

    
605
  RenderHints::popFromRenderStack();
606
  return (count($homonyms_array) ?'[' . trim(join(" ", $homonyms_array)) . ']' : '');
607
}
608

    
609

    
610
  /**
611
 * Recursively searches the array for the $key and sets the given value.
612
 *
613
 * @param mixed $key
614
 *   Key to search for.
615
 * @param mixed $value
616
 *   Value to set.'
617
 * @param array $array
618
 *   Array to search in.
619
 *
620
 * @return bool
621
 *   True if the key has been found.
622
 */
623
function &array_setr($key, $value, array &$array) {
624
  $res = NULL;
625
  foreach ($array as $k => &$v) {
626
    if ($key == $k) {
627
      $v = $value;
628
      return $array;
629
    }
630
    elseif (is_array($v)) {
631
      $innerArray = array_setr($key, $value, $v);
632
      if ($innerArray) {
633
        return $array;
634
      }
635
    }
636
  }
637
  return $res;
638
}
639

    
640
/**
641
 * @todo Please document this function.
642
 * @see http://drupal.org/node/1354
643
 */
644
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate) {
645
  $res = NULL;
646
  $precedingElement = NULL;
647
  foreach ($renderTemplate as &$part) {
648
    foreach ($part as $key => &$element) {
649
      if ($key == $contentElementKey) {
650
        return $precedingElement;
651
      }
652
      $precedingElement = $element;
653
    }
654
  }
655
  return $res;
656
}
657

    
658
/**
659
 * @todo Please document this function.
660
 * @see http://drupal.org/node/1354
661
 */
662
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate) {
663
  $res = NULL;
664
  $precedingKey = NULL;
665
  foreach ($renderTemplate as &$part) {
666
    if (is_array($part)) {
667
      foreach ($part as $key => &$element) {
668
        if ($key == $contentElementKey) {
669
          return $precedingKey;
670
        }
671
        if (!str_beginsWith($key, '#')) {
672
          $precedingKey = $key;
673
        }
674
      }
675
    }
676
  }
677
  return $res;
678
}
(5-5/8)