Project

General

Profile

Download (25.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * Copyright (C) 2007 EDIT
6
 * European Distributed Institute of Taxonomy
7
 * http://www.e-taxonomy.eu
8
 *
9
 * The contents of this file are subject to the Mozilla Public License Version 1.1
10
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
 */
12

    
13
/**
14
 * This function prints the lectotype citation with the correct layout
15
 * Lectotypes are renderized in the synonymy tab of a taxon if they exist
16
 * @param $typeDesignation_citation The lectotype citation to print
17
 * @return html valid string
18
 */
19
function type_designation_citation_layout($typeDesignation, $footnote_separator = ','){
20
	$res = '';
21
	$citation = $typeDesignation->citation;
22
	$pages = $typeDesignation->citationMicroReference;
23

    
24
	if ($typeDesignation->typeStatus->uuid == UUID_ORIGINAL_DESIGNATION ||
25
	$typeDesignation->typeStatus->uuid == UUID_MONOTYPE){
26
		$res = ' ('. $typeDesignation->typeStatus->representation_L10n . ')';
27
		return $res;
28
	}
29

    
30
	if ($citation){
31
		//$type = $typeDesignation_citation->type;
32
	$year = substr($citation->datePublished->start, 0, 4);
33
	$author = $citation->authorTeam->titleCache;
34
	$res .= ' (designated by ';
35
	$res .= $author;
36
	$res .= ($year ? ' '.$year : '');
37
	$res .= ($pages ? ': '. $pages : '');
38
	//$res .= ')';
39

    
40
	$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations', $typeDesignation->citation->titleCache);
41
	$res .= theme('cdm_footnote_key', $fkey_typeDesignation, $footnote_separator, true, true) . ')';
42

    
43
}
44
return $res;
45
}
46

    
47
function contains_type_designation ($element, $collection){
48
    $result = false;
49
    foreach ($collection as $a){
50
    	if($a->uuid == $element->uuid){
51
    		$result = true;
52
    	}
53
    }
54
    return $result;
55
}
56

    
57
function cdm_add_type_designations ($source, $extra) {
58
	if (is_array($source)){
59
	   $result = $source;
60
        if ($extra){
61
            foreach ($extra as $element) {
62
                if (!contains_type_designation($element, $source)){
63
                $result[] = $element;
64
            }
65
        }
66
    }
67
	}else {
68
		$result = $extra;
69
	}
70

    
71
    return $result;
72
}
73

    
74
function theme_cdm_typedesignations($typeDesignations = array()){
75
	/*
76
	 if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
77
	 $microreference = null;
78
	 if(isset($renderTemplate['referencePart']['microreference'])){
79
	 $microreference = $taxonName->nomenclaturalMicroReference;
80
	 }
81
	 $citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($typeDesignation->uuid), "microReference=".urlencode($microreference));
82
	 $citation = $citation->String;
83
	 */
84

    
85
	RenderHints::pushToRenderStack('typedesignations');
86
	$out = '<ul class="typeDesignations">';
87
	$typeDesignation_footnotes = false;
88
	$is_lectotype = false;
89
	$specimenTypeDesignations = array();
90
	$separator = ',';
91
	foreach($typeDesignations as $typeDesignation){
92
		if($typeDesignation->class == 'SpecimenTypeDesignation'){
93
			// SpecimenTypeDesignations should be ordered. collect theme here only
94
			$specimenTypeDesignations[] = $typeDesignation;
95
		}else{ //it is a lectotype?
96
			if(strcmp($typeDesignation->typeStatus->titleCache, 'lectotype') == 0){
97
				$is_lectotype = true;
98
			}
99
			// it's a NameTypeDesignation
100
			if($typeDesignation->notDesignated){
101
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>: ' . t('not designated'). '</li>';
102
				//$out .= '<li class="nameTypeDesignation"><span class="status">Lectotype</span>: '.t('not designated'). '</li>';
103
			}else if($typeDesignation->typeName){
104
				$link_to_name_page = '?q=' . path_to_name($typeDesignation->typeName->uuid);
105
				$out .= '<li class="nameTypeDesignation"><span class="status">' . ($is_lectotype ? 'Lectotype' : 'Type') . '</span>';
106

    
107
				if($typeDesignation->citation){
108
					$out .= type_designation_citation_layout($typeDesignation, $separator);
109
					//footnotes
110
					//$fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, $typeDesignation->citation->titleCache);
111
					/*
112
				  $fkey_typeDesignation = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-typeDesignations', $typeDesignation->citation->titleCache);
113
				  $out .= theme('cdm_footnote_key', $fkey_typeDesignation, $separator, true, true) . ')';
114
				  */
115
				}
116
				if($typeDesignation->typeName->nomenclaturalReference){
117
					$referenceUri = url(path_to_reference($typeDesignation->typeName->nomenclaturalReference->uuid));
118
				}
119
				$out .= ': ' . theme('cdm_taxonName', $typeDesignation->typeName, $link_to_name_page, $referenceUri, true, true);
120
			}
121
		}
122
	}
123

    
124
	if(!empty($specimenTypeDesignations)){
125
		// sorting might be different for dataportals so this has to be parameterized
126
		usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
127
		foreach($specimenTypeDesignations as $std){
128
			$typeReference = '';
129
			//show citation only for Lectotype or Neotype
130
			$showCitation = isset($std->typeStatus) && ($std->typeStatus->uuid == UUID_NEOTYPE || $std->typeStatus->uuid == UUID_LECTOTYPE);
131
			if($showCitation && !empty($std->citation)){
132
				//$shortCitation = $std->citation->authorTeam->titleCache;
133

    
134
				$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $std->citation->uuid);
135
				$shortCitation = $author_team->titleCache;
136

    
137
				$shortCitation .= (strlen($shortCitation) > 0 ? ' ' : '' ). partialToYear($std->citation->datePublished->start);
138
				if(strlen($shortCitation) == 0){
139
					$shortCitation = theme('cdm_reference', $std->citation);
140
					$missingShortCitation = true;
141
				}
142

    
143
				$typeReference .= '&nbsp;(' . t('designated by');
144
				$typeReference .= '&nbsp;<span class="typeReference '.($missingShortCitation ? '' : 'cluetip').' no-print" title="'. htmlspecialchars('|'.theme('cdm_reference',$std->citation ).'|') .'">';
145
				$typeReference .= $shortCitation.'</span>';
146
				$typeReference .= ':'. $std->citationMicroReference .')';
147

    
148
				$_fkey2 = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-lectotypes', $std->citation->titleCache);
149
				$typeReference .= theme('cdm_footnote_key', $_fkey2, $separator, true, true);
150
			}
151

    
152
			$derivedUnitFacadeInstance = cdm_ws_get(CDM_WS_DERIVEDUNIT_FACADE, $std->typeSpecimen->uuid);
153

    
154
			$out .= '<li class="specimenTypeDesignation">';
155
			$out .= '<span class="status">'
156
			.(($std->typeStatus->representation_L10n) ? $std->typeStatus->representation_L10n : t('Type'))
157
			.$typeReference.'</span>: '.$derivedUnitFacadeInstance->titleCache;
158
			$out .= theme('cdm_specimen', $derivedUnitFacadeInstance);
159

    
160
			//footnotes for synonymy acronyms
161
			$_fkey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-acronyms', $derivedUnitFacadeInstance->collection->titleCache);
162
			$out .= theme('cdm_footnote_key', $_fkey, $separator);
163
			$out .= '</li>';
164

    
165
			if (!empty($std->citation)){
166
				$render_footnote_lectotypes = true;
167
			 //$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
168
			}
169
		}
170
	}
171

    
172
	$out .= '</ul>';
173

    
174
	//render the footnotes at the end of the page
175
	if ($render_footnote_lectotypes){
176
		$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-lectotypes');
177
	}
178
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-acronyms', 'li');
179
	$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations', 'li');
180
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-typeDesignations-' . $typeDesignation->uuid, 'li');
181

    
182
	RenderHints::popFromRenderStack();
183

    
184
	return $out;
185
}
186

    
187

    
188
/**
189
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
190
 * Compares the status of two SpecimenTypeDesignations
191
 * @param String $a 	a SpecimenTypeDesignations
192
 * @param String $b		another SpecimenTypeDesignations
193
 */
194
function compare_specimenTypeDesignationStatus($a, $b){
195
	/* this is the desired sort oder as of now:
196
	 * 	Holotype
197
	 * 	Isotype
198
	 * 	Lectotype
199
	 * 	Isolectotype
200
	 * 	Syntype
201
	 *
202
	 * TODO
203
	 * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
204
	 * and use the index of this array for comparison. This array has to be filled with the cdm-
205
	 * TypeDesignation states and the order should be parameterisable inside the dataportal.
206
	 */
207
	// make that static for now
208
	$typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
209

    
210
	$aQuantifier = array_search($a->typeStatus->label, $typeOrder);
211
	$bQuantifier = array_search($b->typeStatus->label, $typeOrder);
212

    
213
	if ($aQuantifier == $bQuantifier) {
214
		// sort alphabetically
215
		return ($a->typeStatus->label < $b->typeStatus->label) ? -1 : 1;
216
	}
217
	return ($aQuantifier < $bQuantifier) ? -1 : 1;
218

    
219
}
220

    
221
function theme_cdm_nameRelationships($nameRelationships, $skipTypes = false){
222

    
223
	if(!$nameRelationships){
224
		return;
225
	}
226

    
227
	RenderHints::pushToRenderStack('nameRelationships');
228
	$footnoteListKey = 'nameRelationships';
229
	RenderHints::setFootnoteListKey($footnoteListKey);
230

    
231
	// group by relationship type
232
	$relationshipGroups = array();
233
	foreach($nameRelationships as $nameRelationship){
234
		if(!array_key_exists($nameRelationship->type->uuid, $relationshipGroups)){
235
			$relationshipGroups[$nameRelationship->type->uuid] = array();
236
		}
237
		$relationshipGroups[$nameRelationship->type->uuid][] = $nameRelationship;
238
	}
239

    
240
	// generate output
241
	$out = '';
242
	foreach($relationshipGroups as $group){
243
		$type = $group[0]->type;
244

    
245
		if(is_array($skipTypes) && in_array($type->uuid, $skipTypes)){
246
			continue;
247
		}
248

    
249
		$block->module = 'cdm_dataportal';
250
		$block->subject = t(ucfirst($type->inverseRepresentation_L10n));
251
		$block->delta = generalizeString(strtolower($type->inverseRepresentation_L10n));
252

    
253
		foreach($group as $relationship){
254
			$relatedNames[] = cdm_taggedtext2html($relationship->fromName->taggedName);
255
		}
256

    
257
		$block->content .= implode('; ', $relatedNames);
258
		$out .= theme('block', $block);
259
	}
260
	$out .= theme('cdm_footnotes', $footnoteListKey, 'li');
261

    
262
	RenderHints::popFromRenderStack();
263
	return $out;
264
}
265

    
266

    
267

    
268
function theme_cdm_homotypicSynonymLine($taxon){
269
	$out = '';
270
	$out .= '<li class="synonym">'.cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
271

    
272
	return $out;
273
}
274

    
275
function theme_cdm_heterotypicSynonymyGroup($homotypicalGroup){
276

    
277
	RenderHints::pushToRenderStack('heterotypicSynonymyGroup');
278

    
279
	$out = '';
280
	$out = '<ul class="heterotypicSynonymyGroup">';
281
	$footnoteListKey = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
282
	RenderHints::setFootnoteListKey($footnoteListKey);
283

    
284
	$is_first_entry = true;
285
	$typeDesignations = null;
286
	foreach($homotypicalGroup as $synonym){
287
		if($is_first_entry){
288
			$is_first_entry = false;
289
			$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonym->name->uuid);
290
			// is first list entry
291
			$out .= '<li class="firstentry synonym">'.cdm_related_taxon($synonym, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
292
		} else {
293
			$out .= '<li class="synonym">'.cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
294
		}
295
	}
296
	//$test =  theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
297
	//tuypedesignations footnotes
298

    
299
	if($typeDesignations){
300
		$out .= theme('cdm_typedesignations', $typeDesignations);
301

    
302
	}
303

    
304
	//annotation footnotes
305
	//$annotation_key = ( isset($homotypicalGroup[0]) ? $homotypicalGroup[0]->uuid : 'NULL');
306
	//$fkey_annotations = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-annotations-' . $annotation_key, $annotation_key);
307
	//$out .= theme('cdm_footnotes', RenderHints::getRenderPath() . '-annotations-' . $annotation_key);
308
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
309
	//$out .= theme('cdm_annotation_footnotes', $footnoteListKey);
310
	$out .= '</ul>';
311

    
312

    
313
	RenderHints::popFromRenderStack();
314
	return $out;
315
}
316

    
317

    
318

    
319
function theme_cdm_homotypicSynonymyGroup($synonymList, $accepted_taxon_uuid, $prependedSynonyms = array()){
320

    
321
	RenderHints::pushToRenderStack('homotypicSynonymyGroup');
322

    
323
	$footnoteListKey = isset($prependedSynonyms[0]) ? $prependedSynonyms[0]->uuid : (isset($synonymList[0]) ? $synonymList[0]->uuid : 'NULL');
324
	$accepted_taxon_footnoteListKey = RenderHints::getFootnoteListKey();
325
	RenderHints::setFootnoteListKey($footnoteListKey);
326

    
327
	if(! is_array($synonymList) || count($synonymList) == 0){
328
		return;
329
	}
330

    
331
	$out = '<ul class="homotypicSynonyms">';
332

    
333
	if(!empty($prependedSynonyms)){
334
		foreach($prependedSynonyms as $taxon){
335
			$out .= '<li class="synonym">'.cdm_related_taxon($taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
336
		}
337
	}
338

    
339
	foreach($synonymList as $synonym){
340
		$out .= '<li class="synonym">'.cdm_related_taxon($synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
341
	}
342

    
343
	$homonym_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_NAME_TYPEDESIGNATIONS, $synonymList[0]->name->uuid);
344
    $accepted_typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $accepted_taxon_uuid);
345
    if($accepted_typeDesignations){
346
        $typeDesignations = cdm_add_type_designations($homonym_typeDesignations, $accepted_typeDesignations);
347
    }else {
348
    	$typeDesignations = $homonym_typeDesignations;
349
    }
350
	if($typeDesignations){
351
		$out .= theme('cdm_typedesignations', $typeDesignations);
352
	}
353
	if($accepted_taxon_footnoteListKey){// to avoiding drupal warnings (#1830) why false???
354
		$out .= theme('cdm_footnotes', $accepted_taxon_footnoteListKey, 'li');
355
	}
356

    
357
	$out .= theme('cdm_annotation_footnotes', $footnoteListKey, 'li');
358
	$out .= '</ul>';
359

    
360
	RenderHints::popFromRenderStack();
361
	return $out;
362
}
363

    
364
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
365
  //TODO implement admin user interface to replace switch statement
366
  //     preliminar solution: using themes
367

    
368
  $template = null;
369
  // find best matching default RenderTemplate in theme
370
  //echo "<br/><br/>RENDER PATH:  ".$renderPath;
371
  //var_dump('RENDER PATH: ' . $renderPath);
372

    
373
  // preserve renderPath_base
374
  if( ($separatorPos =  strpos($renderPath, '.')) >= 0 ){
375
  } else {
376
  	$separatorPos = strlen($renderPath);
377
  }
378
  $renderPath_base = substr($renderPath, 0, $separatorPos);
379

    
380
  // find in theme function if it exists
381
  if(theme_get_function('get_nameRenderTemplate')){
382
	  while(!is_array($template) && strlen($renderPath) > 0){
383
	    $template = theme('get_nameRenderTemplate', $renderPath);
384
	    $renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
385
	    //     if(!is_array($template)){
386
	    //         echo "<br/>->".$renderPath;
387
	    //     }
388
	  }
389
  }
390

    
391
  // otherwise get default RenderTemplate from theme
392
  if(!is_array($template)){
393
    $template = theme('get_nameRenderTemplate', '#DEFAULT');
394
  }
395
  // otherwise get system default RenderTemplate
396
  if(!is_array($template)){
397
    switch($renderPath_base){
398
      case 'list_of_taxa':
399
      case 'acceptedFor':
400
      case 'taxon_page_synonymy':
401
      case 'typedesignations':
402
      case 'taxon_page_title':
403
      case 'polytomousKey':
404
      case 'na': $template = array(
405
              'namePart' => array('#uri'=>true),
406
      //'authorshipPart' => true,
407
      );
408
      break;
409
      case 'nar': $template = array(
410
                'namePart' => array('#uri'=>true),
411
      //'authorshipPart' => true,
412
                'referencePart' => array('#uri'=>true),
413
                'microreferencePart' => true,
414
      );
415
      break;
416
      default: $template = array(
417
          'namePart' => array('#uri'=>true),
418
          'authorshipPart' => true,
419
          'referencePart' => array('#uri'=>true),
420
          'microreferencePart' => true,
421
          'statusPart' => true,
422
          'descriptionPart' => true
423
      );
424
    }
425
  }
426

    
427
  if($nameLink && isset($template['nameAuthorPart']['#uri'])){
428
    $template['nameAuthorPart']['#uri'] = $nameLink;
429
  } else{
430
    unset($template['nameAuthorPart']['#uri']);
431
  }
432

    
433
  if($nameLink && isset($template['namePart']['#uri'])){
434
    $template['namePart']['#uri'] = $nameLink;
435
  } else{
436
    unset($template['namePart']['#uri']);
437
  }
438

    
439
  if($refenceLink && isset($template['referencePart']['#uri'])){
440
    $template['referencePart']['#uri'] = $refenceLink;
441
  }else{
442
    unset($template['referencePart']['#uri']);
443
  }
444

    
445
  return $template;
446
}
447

    
448
function get_partDefinition($taxonNameType){
449

    
450
  //TODO implement admin user interface to allow specify the partdefinitions for any type
451
  //     preliminar solution: using themes
452

    
453
  $partdef = theme('get_partDefinition', $taxonNameType);
454

    
455
  if(!is_array($partdef)){
456
    switch($taxonNameType){
457
      case 'ZoologicalName': $partdef = array(
458
        'namePart' => array(
459
          'name' => true,
460
      ),
461
        'referencePart' => array(
462
          'authorTeam' => true
463
      ),
464
        'microreferencePart' => array(
465
          'microreference' => true,
466
      ),
467
        'statusPart' => array(
468
          'status' => true,
469
      ),
470
        'descriptionPart' => array(
471
          'description' => true,
472
      ),
473
      );
474
      break;
475
      case 'BotanicalName':
476
      default: $partdef = array(
477
        'namePart' => array(
478
          'name' => true,
479
          'authors' => true
480
      ),
481
        'referencePart' => array(
482
          'reference' => true,
483
          'microreference' => true
484
      ),
485
        'statusPart' => array(
486
          'status' => true,
487
      ),
488
        'descriptionPart' => array(
489
          'description' => true,
490
      ),
491
      );
492
      break;
493
//      default: $partdef = array(
494
//        'namePart' => array(
495
//          'name' => true,
496
//          'authorTeam' => true
497
//      ),
498
//      'referencePart' => array(
499
//          'reference' => true
500
//      ),
501
//        'microreferencePart' => array(
502
//          'microreference' => true,
503
//      ),
504
//        'statusPart' => array(
505
//          'status' => true,
506
//      ),
507
//        'descriptionPart' => array(
508
//          'description' => true,
509
//      ),
510
//      );
511
    }
512
  }
513
  return $partdef;
514
}
515

    
516

    
517

    
518
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL,
519
	$show_annotations = true, $is_type_designation = false, $skiptags = array()){
520

    
521
	$renderTemplate = get_nameRenderTemplate(RenderHints::getRenderPath(), $nameLink, $refenceLink);
522
	$partDefinition = get_partDefinition($taxonName->class);
523

    
524
	// apply defintions to template
525
	foreach($renderTemplate as $part=>$uri){
526
		if(isset($partDefinition[$part])){
527
			$renderTemplate[$part] = $partDefinition[$part];
528
		}
529
		if(is_array($uri)){
530
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
531
		}
532
	}
533

    
534
   normalize_TaggedName($taxonName->taggedName);
535

    
536
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
537
			&& is_string($taxonName->taggedName[0]->text)
538
			&& $taxonName->taggedName[0]->text != ''
539
			&& $taxonName->taggedName[0]->type == 'name';
540

    
541
	// got to use second entry as first one, see ToDo comment below ...
542
	if($firstEntryIsValidNamePart){
543

    
544
		$taggedName = $taxonName->taggedName;
545

    
546
		$lastAuthorElementString = false;
547
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
548
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
549

    
550
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
551
			//      // find author and split off from name
552
			//      // TODO expecting to find the author as the last element
553
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
554
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
555
			//        unset($taggedName[count($taggedName)- 1]);
556
			//      }
557

    
558
			// remove all authors
559
			$taggedNameNew = array();
560
			foreach($taggedName as $element){
561
				if($element->type != 'authors'){
562
					$taggedNameNew[] = $element;
563
				} else {
564
					$lastAuthorElementString = $element->text;
565
				}
566
			}
567
			$taggedName = $taggedNameNew;
568

    
569
		}
570
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName, 'span', ' ', $skiptags).'</span>';
571
	} else {
572
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
573
	}
574

    
575
	// fill name into $renderTemplate
576
	array_setr('name', $name, $renderTemplate);
577

    
578
	//  // fill with authorTeam
579
	//  if($authorTeam){
580
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
581
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
582
	//  }
583

    
584
	// fill with reference
585
	if(isset($renderTemplate['referencePart']) && !$is_type_designation){
586

    
587
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
588
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
589
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
590
			$microreference = null;
591
			if(isset($renderTemplate['referencePart']['microreference'])){
592
				$microreference = $taxonName->nomenclaturalMicroReference;
593
			}
594
			$citation = cdm_ws_getNomenclaturalReference($taxonName->nomenclaturalReference->uuid, $microreference);
595
			// find preceding element of the refrence
596
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
597
			if(str_beginsWith($citation, ", in")){
598
				$citation = substr($citation, 2);
599
				$separator = ' ';
600
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
601
				$separator = ', ';
602
			} else {
603
				$separator = ' ';
604
			}
605

    
606
			$referenceArray['#separator'] = $separator;
607
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
608
			array_setr('reference', $referenceArray, $renderTemplate);
609
		}
610

    
611
		// if authors have been removed from the name part the last named authorteam
612
		// should be added to the reference citation, otherwise, keep the separator
613
		// out of the reference
614
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
615
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
616
			// is whanted append the microreference to the authorTeam
617
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
618
				$separator = ": ";
619
				$citation = $taxonName->nomenclaturalMicroReference;
620
			}
621
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
622
			array_setr('authors', $referenceArray, $renderTemplate);
623
		}
624

    
625
	}
626

    
627
	// fill with status
628
	if(is_array($taxonName->status)){
629
		if(array_setr('status', true, $renderTemplate)){
630
			if(isset($taxonName->status[0])){
631
				foreach($taxonName->status as $status){
632
					$statusHtml .= ', '.$status->type->representation_L10n_abbreviatedLabel;
633
				}
634
			}
635
			array_setr('status', '<span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
636
		}
637
	}
638

    
639
	// fill with protologues etc...
640
	if(array_setr('description', true, $renderTemplate)){
641
		$descriptions = cdm_ws_get(CDM_WS_PORTAL_NAME_DESCRIPTIONS, $taxonName->uuid);
642
		foreach($descriptions as $description){
643
			if(!empty($description)){
644
				foreach($description->elements as $description_element){
645
					$second_citation = '';
646
					if ($description_element->multilanguageText_L10n->text){
647
						$second_citation = '[& ' . $description_element->multilanguageText_L10n->text . '].';
648
					}
649
					$descriptionHtml .= $second_citation;
650
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
651
				}
652
			}
653
		}
654
		array_setr('description', $descriptionHtml, $renderTemplate);
655
	}
656

    
657
	// render
658
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
659

    
660
	foreach($renderTemplate as $partName=>$part){
661
		$separator = '';
662
		$partHtml = '';
663
		$uri = false;
664
		if(!is_array($part)){
665
			continue;
666
		}
667
		if(isset($part['#uri']) && is_string($part['#uri'])){
668
			$uri = $part['#uri'];
669
			unset($part['#uri']);
670
		}
671
		foreach($part as $key=>$content){
672
			$html = '';
673
			if(is_array($content)){
674
				$html = $content['#html'];
675
				$separator = $content['#separator'];
676
			} else if(is_string($content)){
677
				$html = $content;
678
			}
679
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
680
		}
681
		if($uri){
682
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
683
		} else {
684
			$out .= $separator.$partHtml;
685

    
686
		}
687
	}
688
	$out .= '</span>';
689
	if ($show_annotations){
690
		//$out .= theme('cdm_annotations_as_footnotekeys', $taxonName);
691
	}
692
	return $out;
693
}
694

    
695
/**
696
 * Recursively searches the array for the $key and sets the given value
697
 * @param $key
698
 * @param $value
699
 * @param $array
700
 * @return true if the key has been found
701
 */
702
function &array_setr($key, $value, array &$array){
703
	foreach($array as $k=>&$v){
704
		if($key == $k){
705
			$v = $value;
706
			return $array;
707
		} else if(is_array($v)){
708
			$innerArray = array_setr($key, $value, $v);
709
			if($innerArray){
710
				return $array;
711
			}
712
		}
713
	}
714
	return null;
715
}
716

    
717
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
718
	$precedingElement = null;
719
	foreach($renderTemplate as &$part){
720
		foreach($part as $key=>&$element){
721
			if($key == $contentElementKey){
722
				return $precedingElement;
723
			}
724
			$precedingElement = $element;
725
		}
726
	}
727
	return null;
728
}
729

    
730
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
731
	$precedingKey = null;
732
	foreach($renderTemplate as &$part){
733
		if(is_array($part)){
734
			foreach($part as $key=>&$element){
735
				if($key == $contentElementKey){
736
					return $precedingKey;
737
				}
738
				if(!str_beginsWith($key, '#')){
739
					$precedingKey = $key;
740
				}
741
			}
742
		}
743
	}
744
	return null;
745
}
746

    
747

    
748

    
749

    
750

    
751

    
752

    
(4-4/8)