Project

General

Profile

Download (35.6 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)) {
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)) {
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)) {
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)) {
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)) {
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)) {
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 {
602
					$referenceString .= $reference->citation->authorTeam->titleCache;
603
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
604
				}
605
				/*else {
606
					$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname . " ";
607
				}*/
608
				if (!empty($reference->citation->datePublished->start)) {
609
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
610
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
611
				}
612
				$referenceString .= $reference->citation->title . ". " . $reference->citation->publisher;
613
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
614
				$referenceString .= "</li>";
615
				break;
616
			default:
617
				
618
				//$author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->citation->uuid);
619
				
620
				/*if(!empty($author_team->titleCache)) {
621
					$referenceString.= print_r($reference->citation);
622
					$referenceString .= '<li class="descriptionText DescriptionElement">' . "<b>" . $reference->citation->title . ":" . "</b>" . $author_team->titleCache .   '</li>';
623
				}
624
				else {
625
					$referenceString .= '<li class="descriptionText DescriptionElement">' ."<b>" . $reference->citation->titleCache . "</b>" . '</li>';
626
				}
627
				if ($referenceCitation){
628
					$sourceRefs = $referenceCitation;
629
					//$referenceString .= "[titleccache] " . $descriptionElementBiblio->feature->titleCache . "[/titlecache]";
630
					//$referenceString .= "[Class] " . $descriptionElementBiblio->class . "[/class]";
631
					//$referenceString .= "[sourceref]" . $sourceRefs . "[/sourceRef]";
632
				}*/
633
				break;
634
		}
635
		$outTemp[] = $referenceString;
636
	}
637
	sort($outTemp);
638
  	
639
	foreach ($outTemp as $refString) {
640
		$out .= $refString;
641
	}
642
	
643
	$out .= "</ul></div>";
644
	return $out;
645
}
646

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

    
649
	$media_metadata = cdm_read_media_metadata($media);
650

    
651
	$doTitle= !$elements || array_search('title', $elements)!== false;
652
	$doDescription = !$elements || array_search('description', $elements)!== false;
653
	$doArtist = !$elements || array_search('artist', $elements)!== false;
654
	$doLocation = !$elements || array_search('location', $elements)!== false;
655
	$doRights = !$elements || array_search('rights', $elements)!== false;
656

    
657
	$descriptionPrefix = "";
658

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

    
737

    
738

    
739

    
740

    
741

    
742
/**
743
 *
744
 * Enter description here ...
745
 * @param unknown_type $reference
746
 * @param unknown_type $microReference
747
 * @param unknown_type $doLink
748
 * @param unknown_type $referenceStyle
749
 */
750
function palmweb_2_cdm_reference($reference, $microReference = null, $doLink = FALSE, $referenceStyle = NULL ){
751

    
752
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
753

    
754
  $year = partialToYear($reference->datePublished->start);
755
  $citation = _short_form_of_author_team ($author_team->titleCache) . ($year ? '. '.$year : '');
756
  $citation = str_replace('..', '.', $citation);
757

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

    
773
  return $out;
774
}
775

    
776

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

    
786

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

    
805
  if (isset($class)) {
806
    print ' class="'. $class .'"';
807
  }
808
}
809

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

    
823
/**
824
 * Allow themable wrapping of all comments.
825
 */
826
function phptemplate_comment_wrapper($content, $type = null) {
827
  static $node_type;
828
  if (isset($type)) $node_type = $type;
829

    
830
  if (!$content || $node_type == 'forum') {
831
    return '<div id="comments">'. $content . '</div>';
832
  }
833
  else {
834
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
835
  }
836
}
837

    
838
/**
839
 * Override or insert PHPTemplate variables into the templates.
840
 */
841
function _phptemplate_variables($hook, $vars) {
842
  if ($hook == 'page') {
843

    
844
    if ($secondary = menu_secondary_local_tasks()) {
845
      $output = '<span class="clear"></span>';
846
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
847
      $vars['tabs2'] = $output;
848
    }
849

    
850
    // Hook into color.module
851
    if (module_exists('color')) {
852
      _color_page_alter($vars);
853
    }
854
    return $vars;
855
  }
856
  return array();
857
}
858

    
859
/**
860
 * Returns the rendered local tasks. The default implementation renders
861
 * them as tabs.
862
 *
863
 * @ingroup themeable
864
 */
865
function phptemplate_menu_local_tasks() {
866
  $output = '';
867

    
868
  if ($primary = menu_primary_local_tasks()) {
869
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
870
  }
871

    
872
  return $output;
873
}
874

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

    
899
function palmweb_2_get_nameRenderTemplate($renderPath){
900

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

    
928
function palmweb_2_cdm_feature_name($feature_name){
929
  switch($feature_name){
930
    case "Protologue": return t("Original Publication");
931
    default: return t(ucfirst($feature_name));
932
  }
933
}
934

    
935
function palmweb_2_cdm_taxon_page_title($taxon, $uuid, $synonym_uuid){
936
	RenderHints::pushToRenderStack('taxon_page_title');
937
	$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $synonym_uuid);
938
	if(isset($taxon->name->nomenclaturalReference)){
939
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
940
	}
941
	$out = theme('cdm_taxonName', $taxon->name, null, $referenceUri, false);
942

    
943
	RenderHints::popFromRenderStack();
944
	if ($synonym->name->titleCache){
945
	$result = '<span class = "synonym_title">' .$synonym->name->titleCache . ' is synonym of ' .'</span>'.
946
		   '<span class="'.$taxon->class.'">'.$out.'</span>';
947
	}else{
948
		$result = '<span class="'.$taxon->class.'">'.$out.'</span>';
949
	}
950
	return $result;
951

    
952
}
953

    
954
function palmweb_2_cdm_uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null) {
955
	$acceptedPath = path_to_taxon($acceptedUuid, true);
956
	return url($acceptedPath . ($pagePart ? '/'.$pagePart : '') . '/'.$synonymUuid, 'highlite='.$synonymUuid);
957
	//return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid, $synonymUuid."/$synonymUuid");
958
	//return url("$acceptedPath/$synonymUuid".($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid);
959
}
(12-12/12)