Project

General

Profile

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

    
3
/**
4
 * The description page is supposed to be the front page for a taxon.
5
 *
6
 * @param TaxonTO $taxonTO
7
 * @return
8
 */
9
function palmweb_2_cdm_taxon_page_profile($taxon, $mergedTrees, $media, $hideImages = false){
10

    
11

    
12
  if(!$hideImages){
13
    // preferred image
14
    // hardcoded for testing;
15
    $defaultRepresentationPart = false;
16
    $defaultRepresentationPart->width = 184;
17
    $defaultRepresentationPart->height = 144;
18
    $defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2').'/images/no_picture.png';
19

    
20
    // preferred image size 184px × 144
21
    $imageMaxExtend = 184;
22
    $out .= '<div id="taxonProfileImage">'.theme('cdm_preferredImage', $media, $defaultRepresentationPart, $imageMaxExtend).'</div>';
23
  }
24

    
25
  // description TOC
26
  $out .= theme('cdm_featureTreeTOCs', $mergedTrees);
27
  // description
28
  $out .= theme('cdm_featureTrees', $mergedTrees, $taxon);
29

    
30
  return $out;
31
}
32

    
33

    
34
function palmweb_2_cdm_descriptionElementDistribution($descriptionElements, $enclosingTag = "span") {
35

    
36
  $out = '';
37
  $separator = ', ';
38

    
39
  RenderHints::pushToRenderStack('descriptionElementDistribution');
40
  RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
41

    
42
  $itemCnt = 0;
43
  foreach($descriptionElements as $descriptionElement){
44
        // annotations as footnotes
45
//        $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
46
//        // source references as footnotes
47
//        $sourcesFootnoteKeyList = '';
48
//        foreach($descriptionElement->sources as $source){
49
//            $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
50
//            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
51
//        }
52
//        if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
53
//            $annotationFootnoteKeys .= $separator;
54
//        }
55
        $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class .'">';
56
        $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList;
57
        if(++$itemCnt < count($descriptionElements)){
58
          $out .=  $separator;
59
        }
60
        $out .= "</" . $enclosingTag . ">";
61
  }
62
  $taxonTrees =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
63
  foreach($taxonTrees as $taxonTree){
64
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
65
      $reference = $taxonTree->reference;
66
      break;
67
    }
68
  }
69

    
70
  $referenceCitation = '('.l('<span class="reference">World Checklist of Monocotyledons</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE).')';
71

    
72
  if($out && strlen($out) > 0 ){
73
    $sourceRefs .= ' '.$referenceCitation;
74
  }
75

    
76
  if(strlen($sourceRefs) > 0){
77
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
78
  }
79

    
80
  RenderHints::popFromRenderStack();
81
  return $out. $sourceRefs ;
82

    
83
}
84

    
85
function palmweb_2_cdm_feature_nodesTOC($featureNodes){
86

    
87
  $out .= '<ul>';
88
  $countFeatures = 0;
89
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), substr(strrchr($_GET["q"], '/'), 1))));
90
  if ($numberOfChildren != 0) {
91
 	 $out .= '<li>'.l(t(theme('cdm_feature_name', 'Number of Species')), $_GET['q'], array("class"=>"toc"), NULL, generalizeString('Number Of Species')).'</li>';
92
  }
93
  foreach($featureNodes as $node){
94

    
95
    if(hasFeatureNodeDescriptionElements($node)){
96

    
97
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
98
      // HACK to implement images for taxa, should be removed
99
      if($node->feature->uuid != UUID_IMAGE){
100
      	$countFeatures++;
101
        $out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
102
      }
103
    }
104
  }
105
  //Setting the Anchor to the Bibliography section if the option is enabled
106
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
107
  
108
  if ($show_bibliography && $countFeatures != 0) {
109
  	$out .= '<li>'.l(t(theme('cdm_feature_name', 'Bibliography')), $_GET['q'], array("class"=>"toc"), NULL, generalizeString('Bibliography')).'</li>';
110
  }
111
  $out .= '</ul>';
112
  return $out;
113
}
114

    
115
function palmweb_2_cdm_feature_nodes($mergedFeatureNodes, $taxon){
116
RenderHints::pushToRenderStack('feature_nodes');
117
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
118
  //Creating an array to place the description elements in 
119
  $bibliographyOut = array();
120
  $countFeatures = 0;
121
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
122
  if ($numberOfChildren != 0) {
123
  	$out .= '<a name="number_of_species"> </a><H2>Number of Species</H2><div class="content"> <ul class="description">';
124
	$out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " Species." . '</li></ul>';
125
  }
126

    
127
  foreach($mergedFeatureNodes as $node){
128

    
129
    if(hasFeatureNodeDescriptionElements($node)) {
130
      $featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
131
      $block->module = 'cdm_dataportal';
132
      //if the option is enabled the description elements will be added to the array
133
      $show_bibliography = variable_get('cdm_show_bibliography', 1);
134
  	  if ($show_bibliography) {
135
      	$bibliographyOut[] =  $node->descriptionElements;
136
  	  }
137
      $media_list = array();
138
      if($node->feature->uuid != UUID_IMAGE) {
139
      	$countFeatures++;
140
        $block->delta = generalizeString($featureRepresentation);
141
        $block->subject = '<span class="'. html_class_atttibute_ref($node->feature) . '">' . theme('cdm_feature_name', $featureRepresentation) . '</span>';
142
        $block->module = "cdm_dataportal-feature";
143
        $block->content = '';
144
        /*
145
         * Content/DISTRIBUTION
146
         */
147
        if($node->feature->uuid == UUID_DISTRIBUTION){
148

    
149
          if(variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)){
150
            $distributionTextDataList = array();
151
            $distributionElementsList = array();
152
            foreach($node->descriptionElements as $descriptionElement){
153
              if($descriptionElement->class == "TextData"){
154
                $distributionTextDataList[] = $descriptionElement;
155
              } else {
156
                $distributionElementsList[] = $descriptionElement;
157
              }
158
            }
159
            if(count($distributionTextDataList) > 0){
160
              $node->descriptionElements = $distributionElementsList;
161
              $block->content .= theme('cdm_descriptionElements', $distributionTextDataList, $node->feature->uuid, $taxon->uuid);
162
            }
163
          }
164

    
165
          // Display cdm distribution map TODO this is a HACK to a proper generic implementation?
166
          $block->content .= theme('cdm_distribution_map', $taxon);
167
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
168
        }
169

    
170
        /*
171
         * Content/COMMON_NAME
172
         */
173
        else if ($node->feature->uuid == UUID_COMMON_NAME){
174
          //TODO why is theme_cdm_descriptionElement_CommonTaxonName not beeing used???
175
          $block->content .= theme('cdm_common_names', $node->descriptionElements);
176
        /*
177
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
178
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
179
        */
180
        }
181

    
182
        /*
183
         * Content/ALL OTHER FEATURES
184
         */
185
        else {
186
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
187

    
188
          /*
189
           *  Content/ALL OTHER FEATURES/Subordinate Features
190
           *
191
           *  subordinate features are printed inline in one floating text,
192
           *  it is expected that supordinate features only "contain" TextData elements
193
           */
194
          // TODO move into own theme
195
          if(count($node->children) > 0){
196

    
197
            //TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
198
            $text = '';
199
            foreach ($node->children as $child){
200

    
201
             if (is_array($child->descriptionElements)){
202
               foreach ($child->descriptionElements as $element) {
203

    
204
                 if(is_array($element->media)){
205
                   // append media of supordinate emelents to list of main feature
206
                   $media_list = array_merge($media_list, $element->media);
207
                 }
208

    
209
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
210
                //TODO use localized version of feature name, the locale must match the locale of the multilanguage text (http://dev.e-taxonomy.eu/trac/ticket/2394)
211
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
212
               }
213
               $text .= " " . $description;
214
               $description = '';
215
             }
216

    
217
            }
218
            $block->content .= $text;
219
          }
220

    
221
        }
222

    
223
        /*
224
         * Media/ALL FEATURES
225
         */
226
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
227
        $captionElements = array('title', 'rights');
228

    
229
        $gallery = theme('cdm_media_gallerie', $media_list, CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
230
              $gallery_settings['cdm_dataportal_media_maxextend'],
231
              $gallery_settings['cdm_dataportal_media_cols'],
232
              $gallery_settings['cdm_dataportal_media_maxRows'],
233
              $captionElements
234
        );
235

    
236
        $block->content .= $gallery;
237
        $block->content .= theme('cdm_footnotes', $node->feature->uuid);
238
        $block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
239
        // add anchor to subject
240
        $block->subject = '<a name="'.$block->delta.'"></a>'.  $block->subject;
241
       $out .= theme('block', $block);
242
        
243
      }
244
    
245
      
246
      
247
      
248
    }
249
    
250
  }
251
  //calling the theme function for Bibliography to add it to the output
252
  
253
  //Add the display of the number of taxa in the selected genus
254
 
255
	
256
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
257
  if ($show_bibliography && $countFeatures !=0) {
258
  	$out .= theme('cdm_descriptionElementBibliography', $bibliographyOut);
259
  }
260

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

    
265
function palmweb_2_cdm_search_results($pager, $path, $parameters){
266

    
267

    
268
	$showThumbnails = $_SESSION['pageoptions']['searchtaxa']['showThumbnails'];
269
	if( !is_numeric($showThumbnails)){
270
		//AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default 
271
		$showThumbnails = 0;
272
	}
273
	$setSessionUri = url('cdm_api/setvalue/session', "var=[pageoption][searchtaxa][showThumbnails]&val=");
274
	drupal_add_js('$(document).ready(function() {
275

    
276
        // init
277
        if('.$showThumbnails.' == 1){
278
              $(\'.media_gallery\').show(20);
279
        } else {
280
          $(\'.media_gallery\').hide(20);
281
        }
282
        // add change hander
283
        $(\'#showThumbnails\').change(
284
          function(event){
285
            var state = 0;
286
            if($(this).is(\':checked\')){
287
              $(\'.media_gallery\').show(20);
288
              state = 1;
289
            } else {
290
              $(\'.media_gallery\').hide(20);
291
            }
292
            // store state in session variable
293
            var uri = \''.$setSessionUri.'\' + state;
294
            jQuery.get(uri);
295
          });
296
        });', "inline");
297

    
298
	drupal_set_title(t('Search results'));
299

    
300
	$out = ''; //l('Advanced Search', '/cdm_dataportal/search');
301
	//AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails tick box text 
302
	$out = '<div class="page_options"><form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" '.($showThumbnails == 1? 'checked="checked"': '').'> '.t('Show Image Thumbnails').'</form></div>';
303
	if(count($pager->records) > 0){
304
	    $out .= '<div id="search_results">';
305
		$out .= theme('cdm_list_of_taxa', $pager->records);
306
		$out .= '</div>';
307
		$out .= theme('cdm_pager', $pager, $path, $parameters);
308
	} else {
309
		$out = '<h4 class="error">Sorry, no matching entries found.</h4>';
310
	}
311
	return $out;
312
}
313

    
314
//Bibluiography theming function
315
function theme_cdm_descriptionElementBibliography($descriptionElementsBibliogragphy) {
316
	$listOfReferences = array();
317
	foreach ($descriptionElementsBibliogragphy as $descriptionElementsBiblio) {
318
		foreach ($descriptionElementsBiblio as $descriptionElementBiblio) {
319
			if(is_array($descriptionElementBiblio->sources)){
320
				foreach($descriptionElementBiblio->sources as $source){
321
					$isAlreadySelected = false;
322
					if(empty($listOfReferences)) {
323
						$listOfReferences[] = $source;
324
					}
325
					else {
326
						foreach ($listOfReferences as $selectedReference) {
327
							if ($selectedReference->citation->uuid == $source->citation->uuid) {
328
								$isAlreadySelected = true;
329
							}
330
						}
331
						//add the source in the list of reference/ This is to remove duplicates from the Bibliography section.
332
						if (!$isAlreadySelected) {
333
							$listOfReferences[] = $source;
334
						}
335
					}
336
					
337
				}
338
			}
339
		}
340
		
341
	}
342
	//Call the reference formatting function, it will do the heavy lifting
343
	$out = formatReference_for_Bibliogrpahy($listOfReferences);
344
	return $out;
345
}
346

    
347
function formatReference_for_Bibliogrpahy($references) {
348
	    $out = '<a name="bibliography"> </a><H2>Bibliography</H2><div class="content"> <ul class="description">';
349
    $outTemp= array();
350
  foreach ($references as $reference) {
351
    $referenceString = '';
352
		//print_r($reference);
353
		switch ($reference->citation->type) {
354
			case "Journal":
355
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
356
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
357
				$currentRecord = 1;
358
				if (!empty($reference->citation->authorTeam->teamMembers)) {
359
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
360
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
361
							if ($currentRecord == 1) {
362
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
363
							}
364
							else if ($numberOfTeamMembers != $currentRecord) {
365
								$referenceString .= " , " . $teamMember->lastname . ", " . $teamMember->firstname;	
366
							}
367
							else {
368
								$referenceString .= " & " . $teamMember->lastname . ", " . $teamMember->firstname;
369
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
370
							}
371
							$currentRecord += 1;
372
						}
373
						else {
374
							if ($numberOfTeamMembers != $currentRecord) {
375
								$referenceString .= $teamMember->titleCache. " & ";	
376
							}
377
							else {
378
								$referenceString .= $teamMember->titleCache;
379
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
380
							}
381
							$currentRecord += 1;
382
						}
383
					}
384
				}
385
				else {
386
					$referenceString .= $reference->citation->authorTeam->titleCache;
387
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
388
				}
389
				/*else {
390
					$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname . " ";
391
				}*/
392
				if (!empty($reference->citation->datePublished->start)) {
393
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
394
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
395
				}
396
				$referenceString .= $reference->citation->title . ". " . $reference->citation->publisher;
397
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
398
				$referenceString .= "</li>";
399
				break;
400
				
401

    
402
			case "Article":
403
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
404
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
405
				$currentRecord = 1;
406
				if (!empty($reference->citation->authorTeam->teamMembers)) {
407
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
408
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
409
							if ($currentRecord == 1) {
410
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
411
							}
412
							else if ($numberOfTeamMembers != $currentRecord) {
413
								$referenceString .= " , " . $teamMember->lastname . ", " . $teamMember->firstname;	
414
							}
415
							else {
416
								$referenceString .= " & " . $teamMember->lastname . ", " . $teamMember->firstname;
417
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
418
							}
419
							$currentRecord += 1;
420
						}
421
						else {
422
							if ($numberOfTeamMembers != $currentRecord) {
423
								$referenceString .= $teamMember->titleCache. " & ";	
424
							}
425
							else {
426
								$referenceString .= $teamMember->titleCache;
427
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
428
							}
429
							$currentRecord += 1;
430
						}
431
					}
432
				}
433
				else {
434
					$referenceString .= $reference->citation->authorTeam->titleCache;
435
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
436
				}
437
				/*else {
438
					$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname . " ";
439
				}*/
440
				if (!empty($reference->citation->datePublished->start)) {
441
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
442
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
443
				}
444
				$referenceString .= $reference->citation->title . ". " . $reference->citation->publisher;
445
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
446
				$referenceString .= "</li>";
447
				break;
448
				
449
				
450
			case "Book":
451
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
452
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
453
				$currentRecord = 1;
454
				if (!empty($reference->citation->authorTeam->teamMembers) && $reference->citation->authorTeam->titleCache != "-empty team-") {
455
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
456
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
457
							if ($numberOfTeamMembers != $currentRecord) {
458
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname. " & ";	
459
							}
460
							else {
461
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
462
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
463
							}
464
							$currentRecord += 1;
465
						}
466
						else {
467
							if ($numberOfTeamMembers != $currentRecord) {
468
								$referenceString .= $teamMember->titleCache. " & ";	
469
							}
470
							else {
471
								$referenceString .= $teamMember->titleCache;
472
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
473
							}
474
							$currentRecord += 1;
475
						}
476
					}
477
					
478
					
479
				}
480
				else if ($reference->citation->authorTeam->titleCache != "-empty team-"){
481
					$referenceString .= $reference->citation->authorTeam->titleCache;
482
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
483
				}
484
				 else {
485
				 	$isCitationTitleCache  = true;
486
				 	$referenceString .=  $reference->citation->titleCache;
487
				 }
488
				if (!empty($reference->citation->datePublished->start)) {
489
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
490
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
491
				}
492
				if ($isCitationTitleCache == false && !empty($reference->citation->title)) {
493
					$referenceString .= $reference->citation->title; 
494
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
495
				}
496
				if (!empty($reference->citation->publisher)) {
497
					$referenceString .= $reference->citation->publisher;
498
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
499
				}
500
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
501
				$referenceString .= "</li>";
502
				break;
503
			case "BookSection":
504
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
505
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
506
				$currentRecord = 1;
507
				if (!empty($reference->citation->authorTeam->teamMembers)) {
508
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
509
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
510
							if ($numberOfTeamMembers != $currentRecord) {
511
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname. " & ";	
512
							}
513
							else {
514
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
515
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
516
							}
517
							$currentRecord += 1;
518
						}
519
						else {
520
							if ($numberOfTeamMembers != $currentRecord) {
521
								$referenceString .= $teamMember->titleCache. " & ";	
522
							}
523
							else {
524
								$referenceString .= $teamMember->titleCache;
525
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
526
							}
527
							$currentRecord += 1;
528
						}
529
					}
530
				}
531
				$referenceString .= substr($reference->citation->inReference->datePublished->start,0,4) . ". " . $reference->citation->title . ". " . "Pages ". $reference->citation->pages . ". In ";
532
				$numberOfTeamMembersInReference = count($reference->citation->inReference->authorTeam->teamMembers);
533
				$currentRecordinReference = 1;
534
				if (!empty($reference->citation->inReference->authorTeam->teamMembers)) {
535
					foreach ($reference->citation->inReference->authorTeam->teamMembers as $teamMember) {
536
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
537
							if ($numberOfTeamMembers != $currentRecord) {
538
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname. " & ";	
539
							}
540
							else {
541
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
542
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
543
							}
544
							$currentRecord += 1;
545
						}
546
						else {
547
							if ($numberOfTeamMembers != $currentRecord) {
548
								$referenceString .= $teamMember->titleCache. " & ";	
549
							}
550
							else {
551
								$referenceString .= $teamMember->titleCache;
552
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
553
							}
554
							$currentRecord += 1;
555
						}
556
					}
557
				}
558
				
559
				$referenceString .= $reference->citation->inReference->title . ". " . $reference->citation->inReference->publisher . ". " . $reference->citation->inReference->placePublished;
560
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
561
					
562
				
563
				$referenceString .= "</li>";
564
				break;
565
				
566
				
567
			case "WebPage" :
568
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">" . $reference->citation->titleCache . "</li>";
569
				break;
570
			case "Generic" :
571
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
572
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
573
				$currentRecord = 1;
574
				if (!empty($reference->citation->authorTeam->teamMembers)) {
575
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
576
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
577
							if ($currentRecord == 1) {
578
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
579
							}
580
							else if ($numberOfTeamMembers != $currentRecord) {
581
								$referenceString .= " , " . $teamMember->lastname . ", " . $teamMember->firstname;	
582
							}
583
							else {
584
								$referenceString .= " & " . $teamMember->lastname . ", " . $teamMember->firstname;
585
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
586
							}
587
							$currentRecord += 1;
588
						}
589
						else {
590
							if ($numberOfTeamMembers != $currentRecord) {
591
								$referenceString .= $teamMember->titleCache. " & ";	
592
							}
593
							else {
594
								$referenceString .= $teamMember->titleCache;
595
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
596
							}
597
							$currentRecord += 1;
598
						}
599
					}
600
				}
601
				else if(!empty($reference->citation->authorTeam->titleCache)) {
602
					$referenceString .= $reference->citation->authorTeam->titleCache;
603
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
604
				}
605
				else {
606
					$referenceString .= $reference->citation->titleCache;
607
					$referenceString .= ((str_endsWith($out, ".") || str_endsWith($out, ". ")) ? " " : ". ");
608
				}
609
				/*else {
610
					$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname . " ";
611
				}*/
612
				if (!empty($reference->citation->datePublished->start)) {
613
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
614
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
615
				}
616
				$referenceString .= $reference->citation->title . ". " . $reference->citation->publisher;
617
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
618
				$referenceString .= ((str_endsWith($referenceString, ".") ) ? " " : "");
619
				$referenceString .= "</li>";
620
				break;
621
			default:
622
				
623
				//$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->citation->uuid);
624
				
625
				/*if(!empty($author_team->titleCache)) {
626
					$referenceString.= print_r($reference->citation);
627
					$referenceString .= '<li class="descriptionText DescriptionElement">' . "<b>" . $reference->citation->title . ":" . "</b>" . $author_team->titleCache .   '</li>';
628
				}
629
				else {
630
					$referenceString .= '<li class="descriptionText DescriptionElement">' ."<b>" . $reference->citation->titleCache . "</b>" . '</li>';
631
				}
632
				if ($referenceCitation){
633
					$sourceRefs = $referenceCitation;
634
					//$referenceString .= "[titleccache] " . $descriptionElementBiblio->feature->titleCache . "[/titlecache]";
635
					//$referenceString .= "[Class] " . $descriptionElementBiblio->class . "[/class]";
636
					//$referenceString .= "[sourceref]" . $sourceRefs . "[/sourceRef]";
637
				}*/
638
				break;
639
		}
640
		$outTemp[] = $referenceString;
641
	}
642
	sort($outTemp);
643
  	
644
	foreach ($outTemp as $refString) {
645
		$out .= $refString;
646
	}
647
	
648
	$out .= "</ul></div>";
649
	return $out;
650
}
651

    
652
function palmweb_2_cdm_media_caption($media, $elements = array('title', 'description', 'artist', 'location', 'rights'), $fileUri = null){
653

    
654
	$media_metadata = cdm_read_media_metadata($media);
655

    
656
	$doTitle= !$elements || array_search('title', $elements)!== false;
657
	$doDescription = !$elements || array_search('description', $elements)!== false;
658
	$doArtist = !$elements || array_search('artist', $elements)!== false;
659
	$doLocation = !$elements || array_search('location', $elements)!== false;
660
	$doRights = !$elements || array_search('rights', $elements)!== false;
661

    
662
	$descriptionPrefix = "";
663

    
664
	$out = '<dl class="media-caption">';
665
	//title
666
	if($doTitle) {
667
	    if($media_metadata['title']){
668
		  $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
669
		  $descriptionPrefix = "- ";
670
	    } else if(!($doDescription && $media_metadata['description'])) {
671
	      // use filename as fallbackoption if no description will be shown
672
          $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['filename'] . '</dd>';
673
          $descriptionPrefix = "- ";
674
	    }
675
	}
676
	//description
677
	if($media_metadata['description'] && $doDescription) {
678
		$out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
679
	}
680
	//artist
681
	if($media_metadata['artist'] && $doArtist) {
682
		$out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . str_replace("'","", $media_metadata['artist']) . '</dd>';
683
	}
684
	//location
685
	if($doLocation){
686
		$location = '';
687
		$location .= $media_metadata['location']['sublocation'];
688
		if ($location && $media_metadata['location']['city']){
689
			$location .= ', ';
690
		}
691
		$location .= $media_metadata['location']['city'];
692
		if ($location && $media_metadata['location']['province']){
693
			$location .= ', ';
694
		}
695
		$location .= $media_metadata['location']['province'];
696
		if ($location && $media_metadata['location']['country']){
697
			$location .= ' (' . $media_metadata['location']['country'] . ')';
698
		} else {
699
			$location .= $media_metadata['location']['country'];
700
		}
701
		if ($location){
702
			$out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
703
		}
704
	}
705
	//rights
706
	if($doRights){
707
		$rights = '';
708
		//copyrights
709
		$cnt = count($media_metadata['rights']['copyright']['agentNames']);
710
		if($cnt > 0){
711
			$rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
712
			for($i = 0; $i < $cnt; $i++){
713
				$rights .= str_replace("'","", $media_metadata['rights']['copyright']['agentNames'][$i]);
714
				if($i+1 < $cnt){
715
					$rights .= ' / ';
716
				}
717
			}
718
			$rights .= '</dd>';
719
		}
720
		//license
721
		$cnt = count($media_metadata['rights']['license']['agentNames']);
722
		if($cnt > 0){
723
			$rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
724
			for($i = 0; $i < $cnt; $i++){
725
				$rights .= $media_metadata['rights']['license']['agentNames'][$i];
726
				if ($i+1 < $cnt){
727
					$rights .= ' / ';
728
				}
729
			}
730
			$rights .= '</dd>';
731
		}
732
		if($rights){
733
			$out .=  $rights . '</dt>';
734
		}
735
	}
736
	//TODO add all other metadata elemenst generically
737
	$out .= '</dl>';
738
	//return value
739
	return $out;
740
}
741

    
742

    
743

    
744

    
745

    
746

    
747
/**
748
 *
749
 * Enter description here ...
750
 * @param unknown_type $reference
751
 * @param unknown_type $microReference
752
 * @param unknown_type $doLink
753
 * @param unknown_type $referenceStyle
754
 */
755
function palmweb_2_cdm_reference($reference, $microReference = null, $doLink = FALSE, $referenceStyle = NULL ){
756

    
757
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
758

    
759
  $year = partialToYear($reference->datePublished->start);
760
  $citation = _short_form_of_author_team ($author_team->titleCache) . ($year ? '. '.$year : '');
761
  $citation = str_replace('..', '.', $citation);
762

    
763
  if($doLink){
764
    $out = l('<span class="reference">'.$citation.'</span>'
765
   	, path_to_reference($reference->uuid) 
766
    //, $_GET['q']
767
    , array("class"=>"reference")
768
    //, NULL, generalizeString('Bibliography'), FALSE ,TRUE);
769
    , NULL, NULL, FALSE ,TRUE);
770
  } else {
771
    $out = '<span class="reference">'.$citation.'</span>';
772
  }
773
  //FIXME use microreference webservice instead
774
  if(!empty($descriptionElementSource->citationMicroReference)){
775
    $out .= ': '. $descriptionElementSource->citationMicroReference;
776
  }
777

    
778
  return $out;
779
}
780

    
781

    
782
/*function palmweb_2_cdm_reference_page($referenceTO){
783
	//print_r($referenceTO);
784
	$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $referenceTO->uuid);
785
	$nomenclatural = cdm_ws_get('portal/taxon/$0/descriptions', '1d91bd71-7109-4916-872f-a82b710a9cdf');
786
	
787
	print_r($nomenclatural);
788
	return "TOTO";
789
}*/
790

    
791

    
792
/**
793
 * Sets the body-tag class attribute.
794
 *
795
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
796
 */
797
function phptemplate_body_class($sidebar_left, $sidebar_right) {
798
  if ($sidebar_left != '' && $sidebar_right != '') {
799
    $class = 'sidebars';
800
  }
801
  else {
802
    if ($sidebar_left != '') {
803
      $class = 'sidebar-left';
804
    }
805
    if ($sidebar_right != '') {
806
      $class = 'sidebar-right';
807
    }
808
  }
809

    
810
  if (isset($class)) {
811
    print ' class="'. $class .'"';
812
  }
813
}
814

    
815
/**
816
 * Return a themed breadcrumb trail.
817
 *
818
 * @param $breadcrumb
819
 *   An array containing the breadcrumb links.
820
 * @return a string containing the breadcrumb output.
821
 */
822
function phptemplate_breadcrumb($breadcrumb) {
823
  if (!empty($breadcrumb)) {
824
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
825
  }
826
}
827

    
828
/**
829
 * Allow themable wrapping of all comments.
830
 */
831
function phptemplate_comment_wrapper($content, $type = null) {
832
  static $node_type;
833
  if (isset($type)) $node_type = $type;
834

    
835
  if (!$content || $node_type == 'forum') {
836
    return '<div id="comments">'. $content . '</div>';
837
  }
838
  else {
839
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
840
  }
841
}
842

    
843
/**
844
 * Override or insert PHPTemplate variables into the templates.
845
 */
846
function _phptemplate_variables($hook, $vars) {
847
  if ($hook == 'page') {
848

    
849
    if ($secondary = menu_secondary_local_tasks()) {
850
      $output = '<span class="clear"></span>';
851
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
852
      $vars['tabs2'] = $output;
853
    }
854

    
855
    // Hook into color.module
856
    if (module_exists('color')) {
857
      _color_page_alter($vars);
858
    }
859
    return $vars;
860
  }
861
  return array();
862
}
863

    
864
/**
865
 * Returns the rendered local tasks. The default implementation renders
866
 * them as tabs.
867
 *
868
 * @ingroup themeable
869
 */
870
function phptemplate_menu_local_tasks() {
871
  $output = '';
872

    
873
  if ($primary = menu_primary_local_tasks()) {
874
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
875
  }
876

    
877
  return $output;
878
}
879

    
880
function palmweb_2_get_partDefinition($nameType){
881
  if($nameType == 'BotanicalName'){
882
    return array(
883
        'namePart' => array(
884
          'name' => true,
885
          'authors' => true,
886
        ),
887
        'authorshipPart' => array(
888
        ),
889
        'referencePart' => array(
890
          'reference' => true,
891
          'microreference' => true
892
        ),
893
        'statusPart' => array(
894
          'status' => true,
895
        ),
896
        'descriptionPart' => array(
897
          'description' => true,
898
        ),
899
      );
900
  }
901
  return false;
902
}
903

    
904
function palmweb_2_get_nameRenderTemplate($renderPath){
905

    
906
  switch($renderPath) {
907
      case 'acceptedFor':
908
        $template = array(
909
          'namePart' => array('#uri'=>true),
910
        );
911
        break;
912
      case 'typedesignations':
913
        $template = array(
914
          'namePart' => array('#uri'=>true),
915
          'referencePart' => true
916
        );
917
      case 'taxon_page_title':
918
      case 'list_of_taxa':
919
      case 'taxon_page_synonymy':
920
      case 'related_taxon':
921
      case 'polytomousKey':
922
      case '#DEFAULT':
923
        $template = array(
924
          'namePart' => array('#uri'=>true),
925
          'referencePart' => true,
926
          'descriptionPart' => true,
927
          'statusPart' => true
928
        );
929
  }
930
  return $template;
931
}
932

    
933
function palmweb_2_cdm_feature_name($feature_name){
934
  switch($feature_name){
935
    case "Protologue": return t("Original Publication");
936
    default: return t(ucfirst($feature_name));
937
  }
938
}
939

    
940
function palmweb_2_cdm_taxon_page_title($taxon, $uuid, $synonym_uuid){
941
	RenderHints::pushToRenderStack('taxon_page_title');
942
	$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $synonym_uuid);
943
	if(isset($taxon->name->nomenclaturalReference)){
944
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
945
	}
946
	$out = theme('cdm_taxonName', $taxon->name, null, $referenceUri, false);
947

    
948
	RenderHints::popFromRenderStack();
949
	if ($synonym->name->titleCache){
950
	$result = '<span class = "synonym_title">' .$synonym->name->titleCache . ' is synonym of ' .'</span>'.
951
		   '<span class="'.$taxon->class.'">'.$out.'</span>';
952
	}else{
953
		$result = '<span class="'.$taxon->class.'">'.$out.'</span>';
954
	}
955
	return $result;
956

    
957
}
958

    
959
function palmweb_2_cdm_uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null) {
960
	$acceptedPath = path_to_taxon($acceptedUuid, true);
961
	return url($acceptedPath . ($pagePart ? '/'.$pagePart : '') . '/'.$synonymUuid, 'highlite='.$synonymUuid);
962
	//return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid, $synonymUuid."/$synonymUuid");
963
	//return url("$acceptedPath/$synonymUuid".($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid);
964
}
(12-12/12)