Project

General

Profile

Download (36.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
  $out = '';
36
  $separator = ', ';
37

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

    
41
  $itemCnt = 0;
42
  foreach($descriptionElements as $descriptionElement){
43
  	//$out .= ($descriptionElement->class);
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
		
56
        $out .= '<' . $enclosingTag . ' class="DescriptionElement DescriptionElement-' . $descriptionElement->class .'">';
57
        $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList;
58
        if(++$itemCnt < count($descriptionElements)){
59
          $out .=  $separator;
60
        }
61
        $out .= "</" . $enclosingTag . ">";
62
  }
63
  $taxonTrees =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
64
  foreach($taxonTrees as $taxonTree){
65
    if ($taxonTree->uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
66
      $reference = $taxonTree->reference;
67
      break;
68
    }
69
  }
70

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

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

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

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

    
84
}
85

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

    
96
    if(hasFeatureNodeDescriptionElements($node)){
97

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

    
122
function palmweb_2_cdm_feature_nodes($mergedFeatureNodes, $taxon){
123
RenderHints::pushToRenderStack('feature_nodes');
124

    
125
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
126
  //Creating an array to place the description elements in 
127
  $bibliographyOut = array();
128
  $countFeatures = 0;
129
  $numberOfChildren = count(cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_CHILDNODES_OF_TAXON, array (get_taxonomictree_uuid_selected(), $taxon->uuid)));
130
  if ($numberOfChildren != 0) {
131
  	$out .= '<a name="number_of_species"> </a><H2>Number of Species</H2><div class="content"> <ul class="description">';
132
	$out .= '<li class=\"descriptionText DescriptionElement\">' . $numberOfChildren . " Species." . '</li></ul>';
133
  }
134

    
135
  foreach($mergedFeatureNodes as $node){
136

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

    
158
          if(variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)){
159
            $distributionTextDataList = array();
160
            $distributionElementsList = array();
161
            foreach($node->descriptionElements as $descriptionElement){
162
            	
163
              if($descriptionElement->class == "TextData"){
164
                $distributionTextDataList[] = $descriptionElement;
165
              } else {
166
                $distributionElementsList[] = $descriptionElement;
167
              }
168
            }
169
            if(count($distributionTextDataList) > 0){
170
              $node->descriptionElements = $distributionElementsList;
171
              $block->content .= theme('cdm_descriptionElements', $distributionTextDataList, $node->feature->uuid, $taxon->uuid);
172
            }
173
          }
174

    
175
          // Display cdm distribution map TODO this is a HACK to a proper generic implementation?
176
          $block->content .= theme('cdm_distribution_map', $taxon);
177
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
178
        }
179

    
180
        /*
181
         * Content/COMMON_NAME
182
         */
183
        else if ($node->feature->uuid == UUID_COMMON_NAME){
184
          //TODO why is theme_cdm_descriptionElement_CommonTaxonName not beeing used???
185
          $block->content .= theme('cdm_common_names', $node->descriptionElements);
186
        /*
187
        }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
188
          $block->content .= theme('cdm_image_sources', $node->descriptionElements);
189
        */
190
        }
191

    
192
        /*
193
         * Content/ALL OTHER FEATURES
194
         */
195
        else if($node->feature->uuid == UUID_USE_RECORD) { 
196
        	$block->content .= theme('cdm_block_Uses', $taxon->uuid);
197
          	//$block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid),
198
        }
199
        else {
200
          $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
201

    
202
          /*
203
           *  Content/ALL OTHER FEATURES/Subordinate Features
204
           *
205
           *  subordinate features are printed inline in one floating text,
206
           *  it is expected that supordinate features only "contain" TextData elements
207
           */
208
          // TODO move into own theme
209
          if(count($node->children) > 0){
210

    
211
            //TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
212
            $text = '';
213
            foreach ($node->children as $child){
214
            
215
             if (is_array($child->descriptionElements)){
216
               foreach ($child->descriptionElements as $element) {
217

    
218
                 if(is_array($element->media)){
219
                   // append media of supordinate emelents to list of main feature
220
                   $media_list = array_merge($media_list, $element->media);
221
                 }
222

    
223
                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
224
                //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)
225
                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
226
               }
227
               $text .= " " . $description;
228
               $description = '';
229
             }
230

    
231
            }
232
            $block->content .= $text;
233
          }
234

    
235
        }
236

    
237
        /*
238
         * Media/ALL FEATURES
239
         */
240
        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
241
        $captionElements = array('title', 'rights');
242

    
243
        $gallery = theme('cdm_media_gallerie', $media_list, CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
244
              $gallery_settings['cdm_dataportal_media_maxextend'],
245
              $gallery_settings['cdm_dataportal_media_cols'],
246
              $gallery_settings['cdm_dataportal_media_maxRows'],
247
              $captionElements
248
        );
249

    
250
        $block->content .= $gallery;
251
        $block->content .= theme('cdm_footnotes', $node->feature->uuid);
252
        $block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
253
        // add anchor to subject
254
        $block->subject = '<a name="'.$block->delta.'"></a>'.  $block->subject;
255
       $out .= theme('block', $block);
256

    
257
        
258
      }
259
    
260
      
261
      
262
      
263
    }
264
    
265
  }
266
  //calling the theme function for Bibliography to add it to the output
267
  
268
  //Add the display of the number of taxa in the selected genus
269
  $out .= theme('cdm_block_Uses', $taxon->uuid);
270

    
271
	
272
  $show_bibliography = variable_get('cdm_show_bibliography', 1);
273
  if ($show_bibliography && $countFeatures !=0) {
274
  	$out .= theme('cdm_descriptionElementBibliography', $bibliographyOut);
275
  }
276

    
277
  RenderHints::popFromRenderStack();
278
  return $out;
279
}
280

    
281

    
282
function palmweb_2_cdm_search_results($pager, $path, $parameters){
283

    
284

    
285
	$showThumbnails = $_SESSION['pageoptions']['searchtaxa']['showThumbnails'];
286
	if( !is_numeric($showThumbnails)){
287
		//AT RBG KEW - 14/11/2011 - Set the show thumbnails to 0 by default 
288
		$showThumbnails = 0;
289
	}
290
	$setSessionUri = url('cdm_api/setvalue/session', "var=[pageoption][searchtaxa][showThumbnails]&val=");
291
	drupal_add_js('$(document).ready(function() {
292

    
293
        // init
294
        if('.$showThumbnails.' == 1){
295
              $(\'.media_gallery\').show(20);
296
        } else {
297
          $(\'.media_gallery\').hide(20);
298
        }
299
        // add change hander
300
        $(\'#showThumbnails\').change(
301
          function(event){
302
            var state = 0;
303
            if($(this).is(\':checked\')){
304
              $(\'.media_gallery\').show(20);
305
              state = 1;
306
            } else {
307
              $(\'.media_gallery\').hide(20);
308
            }
309
            // store state in session variable
310
            var uri = \''.$setSessionUri.'\' + state;
311
            jQuery.get(uri);
312
          });
313
        });', "inline");
314

    
315
	drupal_set_title(t('Search results'));
316

    
317
	$out = ''; //l('Advanced Search', '/cdm_dataportal/search');
318
	//AT RBG KEW - 14/11/2011 - Changed the wording of the Show Thumbnails tick box text 
319
	$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>';
320
	if(count($pager->records) > 0){
321
	    $out .= '<div id="search_results">';
322
		$out .= theme('cdm_list_of_taxa', $pager->records);
323
		$out .= '</div>';
324
		$out .= theme('cdm_pager', $pager, $path, $parameters);
325
	} else {
326
		$out = '<h4 class="error">Sorry, no matching entries found.</h4>';
327
	}
328
	return $out;
329
}
330

    
331
//Bibluiography theming function
332
function theme_cdm_descriptionElementBibliography($descriptionElementsBibliogragphy) {
333
	$listOfReferences = array();
334
	foreach ($descriptionElementsBibliogragphy as $descriptionElementsBiblio) {
335
		foreach ($descriptionElementsBiblio as $descriptionElementBiblio) {
336
			if(is_array($descriptionElementBiblio->sources)){
337
				foreach($descriptionElementBiblio->sources as $source){
338
					$isAlreadySelected = false;
339
					if(empty($listOfReferences)) {
340
						$listOfReferences[] = $source;
341
					}
342
					else {
343
						foreach ($listOfReferences as $selectedReference) {
344
							if ($selectedReference->citation->uuid == $source->citation->uuid) {
345
								$isAlreadySelected = true;
346
							}
347
						}
348
						//add the source in the list of reference/ This is to remove duplicates from the Bibliography section.
349
						if (!$isAlreadySelected) {
350
							$listOfReferences[] = $source;
351
						}
352
					}
353
					
354
				}
355
			}
356
		}
357
		
358
	}
359
	//Call the reference formatting function, it will do the heavy lifting
360
	$out = formatReference_for_Bibliogrpahy($listOfReferences);
361
	return $out;
362
}
363

    
364
function formatReference_for_Bibliogrpahy($references) {
365
	$out = '<div id="block-cdm_dataportal-feature-discussion"><a name="bibliography"> </a><H2>Bibliography</H2><div class="content"> <ul class="description">';
366
    $outTemp= array();
367
  foreach ($references as $reference) {
368
    $referenceString = '';
369
		switch ($reference->citation->type) {
370
			case "Journal":
371
				$referenceString .= "<li class=\"descriptionText DescriptionElement\">";
372
				$numberOfTeamMembers = count($reference->citation->authorTeam->teamMembers);
373
				$currentRecord = 1;
374
				if (!empty($reference->citation->authorTeam->teamMembers)) {
375
					foreach ($reference->citation->authorTeam->teamMembers as $teamMember) {
376
						if(!empty($teamMember->lastname) && !empty($teamMember->firstname)) {
377
							if ($currentRecord == 1) {
378
								$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname;
379
							}
380
							else if ($numberOfTeamMembers != $currentRecord) {
381
								$referenceString .= " , " . $teamMember->lastname . ", " . $teamMember->firstname;	
382
							}
383
							else {
384
								$referenceString .= " & " . $teamMember->lastname . ", " . $teamMember->firstname;
385
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
386
							}
387
							$currentRecord += 1;
388
						}
389
						else {
390
							if ($numberOfTeamMembers != $currentRecord) {
391
								$referenceString .= $teamMember->titleCache. " & ";	
392
							}
393
							else {
394
								$referenceString .= $teamMember->titleCache;
395
								$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? ' ' : ". ");
396
							}
397
							$currentRecord += 1;
398
						}
399
					}
400
				}
401
				else {
402
					$referenceString .= $reference->citation->authorTeam->titleCache;
403
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? " " : ". ");
404
				}
405
				/*else {
406
					$referenceString .= $teamMember->lastname . ", " . $teamMember->firstname . " ";
407
				}*/
408
				if (!empty($reference->citation->datePublished->start)) {
409
					$referenceString .= substr($reference->citation->datePublished->start,0,4);
410
					$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
411
				}
412
				$referenceString .= $reference->citation->title . ". " . $reference->citation->publisher;
413
				$referenceString .= ((str_endsWith($referenceString, ".") || str_endsWith($referenceString, ". ")) ? "" : ". ");
414
				$referenceString .= "</li>";
415
				break;
416
				
417

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

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

    
670
	$media_metadata = cdm_read_media_metadata($media);
671

    
672
	$doTitle= !$elements || array_search('title', $elements)!== false;
673
	$doDescription = !$elements || array_search('description', $elements)!== false;
674
	$doArtist = !$elements || array_search('artist', $elements)!== false;
675
	$doLocation = !$elements || array_search('location', $elements)!== false;
676
	$doRights = !$elements || array_search('rights', $elements)!== false;
677

    
678
	$descriptionPrefix = "";
679

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

    
758

    
759

    
760

    
761

    
762

    
763
/**
764
 *
765
 * Enter description here ...
766
 * @param unknown_type $reference
767
 * @param unknown_type $microReference
768
 * @param unknown_type $doLink
769
 * @param unknown_type $referenceStyle
770
 */
771
function palmweb_2_cdm_reference($reference, $microReference = null, $doLink = FALSE, $referenceStyle = NULL ){
772

    
773
  $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $reference->uuid);
774

    
775
  $year = partialToYear($reference->datePublished->start);
776
  $citation = _short_form_of_author_team ($author_team->titleCache) . ($year ? '. '.$year : '');
777
  $citation = str_replace('..', '.', $citation);
778

    
779
  if($doLink){
780
    $out = l('<span class="reference">'.$citation.'</span>'
781
   	, path_to_reference($reference->uuid) 
782
    //, $_GET['q']
783
    , array("class"=>"reference")
784
    //, NULL, generalizeString('Bibliography'), FALSE ,TRUE);
785
    , NULL, NULL, FALSE ,TRUE);
786
  } else {
787
    $out = '<span class="reference">'.$citation.'</span>';
788
  }
789
  //FIXME use microreference webservice instead
790
  if(!empty($descriptionElementSource->citationMicroReference)){
791
    $out .= ': '. $descriptionElementSource->citationMicroReference;
792
  }
793

    
794
  return $out;
795
}
796

    
797

    
798

    
799
/**
800
 * Sets the body-tag class attribute.
801
 *
802
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
803
 */
804
function phptemplate_body_class($sidebar_left, $sidebar_right) {
805
  if ($sidebar_left != '' && $sidebar_right != '') {
806
    $class = 'sidebars';
807
  }
808
  else {
809
    if ($sidebar_left != '') {
810
      $class = 'sidebar-left';
811
    }
812
    if ($sidebar_right != '') {
813
      $class = 'sidebar-right';
814
    }
815
  }
816

    
817
  if (isset($class)) {
818
    print ' class="'. $class .'"';
819
  }
820
}
821

    
822
/**
823
 * Return a themed breadcrumb trail.
824
 *
825
 * @param $breadcrumb
826
 *   An array containing the breadcrumb links.
827
 * @return a string containing the breadcrumb output.
828
 */
829
function phptemplate_breadcrumb($breadcrumb) {
830
  if (!empty($breadcrumb)) {
831
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
832
  }
833
}
834

    
835
/**
836
 * Allow themable wrapping of all comments.
837
 */
838
function phptemplate_comment_wrapper($content, $type = null) {
839
  static $node_type;
840
  if (isset($type)) $node_type = $type;
841

    
842
  if (!$content || $node_type == 'forum') {
843
    return '<div id="comments">'. $content . '</div>';
844
  }
845
  else {
846
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
847
  }
848
}
849

    
850
/**
851
 * Override or insert PHPTemplate variables into the templates.
852
 */
853
function _phptemplate_variables($hook, $vars) {
854
  if ($hook == 'page') {
855

    
856
    if ($secondary = menu_secondary_local_tasks()) {
857
      $output = '<span class="clear"></span>';
858
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
859
      $vars['tabs2'] = $output;
860
    }
861

    
862
    // Hook into color.module
863
    if (module_exists('color')) {
864
      _color_page_alter($vars);
865
    }
866
    return $vars;
867
  }
868
  return array();
869
}
870

    
871
/**
872
 * Returns the rendered local tasks. The default implementation renders
873
 * them as tabs.
874
 *
875
 * @ingroup themeable
876
 */
877
function phptemplate_menu_local_tasks() {
878
  $output = '';
879

    
880
  if ($primary = menu_primary_local_tasks()) {
881
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
882
  }
883

    
884
  return $output;
885
}
886

    
887
function palmweb_2_get_partDefinition($nameType){
888
  if($nameType == 'BotanicalName'){
889
    return array(
890
        'namePart' => array(
891
          'name' => true,
892
          'authors' => true,
893
        ),
894
        'authorshipPart' => array(
895
        ),
896
        'referencePart' => array(
897
          'reference' => true,
898
          'microreference' => true
899
        ),
900
        'statusPart' => array(
901
          'status' => true,
902
        ),
903
        'descriptionPart' => array(
904
          'description' => true,
905
        ),
906
      );
907
  }
908
  return false;
909
}
910

    
911
function palmweb_2_get_nameRenderTemplate($renderPath){
912

    
913
  switch($renderPath) {
914
      case 'acceptedFor':
915
        $template = array(
916
          'namePart' => array('#uri'=>true),
917
        );
918
        break;
919
      case 'typedesignations':
920
        $template = array(
921
          'namePart' => array('#uri'=>true),
922
          'referencePart' => true
923
        );
924
      case 'taxon_page_title':
925
      case 'list_of_taxa':
926
      case 'taxon_page_synonymy':
927
      case 'related_taxon':
928
      case 'polytomousKey':
929
      case '#DEFAULT':
930
        $template = array(
931
          'namePart' => array('#uri'=>true),
932
          'referencePart' => true,
933
          'descriptionPart' => true,
934
          'statusPart' => true
935
        );
936
  }
937
  return $template;
938
}
939

    
940
function palmweb_2_cdm_feature_name($feature_name){
941
  switch($feature_name){
942
    case "Protologue": return t("Original Publication");
943
    default: return t(ucfirst($feature_name));
944
  }
945
}
946

    
947
function palmweb_2_cdm_taxon_page_title($taxon, $uuid, $synonym_uuid){
948
	RenderHints::pushToRenderStack('taxon_page_title');
949
	$synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $synonym_uuid);
950
	if(isset($taxon->name->nomenclaturalReference)){
951
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
952
	}
953
	$out = theme('cdm_taxonName', $taxon->name, null, $referenceUri, false);
954

    
955
	RenderHints::popFromRenderStack();
956
	if ($synonym->name->titleCache){
957
	$result = '<span class = "synonym_title">' .$synonym->name->titleCache . ' is synonym of ' .'</span>'.
958
		   '<span class="'.$taxon->class.'">'.$out.'</span>';
959
	}else{
960
		$result = '<span class="'.$taxon->class.'">'.$out.'</span>';
961
	}
962
	return $result;
963

    
964
}
965

    
966
function palmweb_2_cdm_uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null) {
967
	$acceptedPath = path_to_taxon($acceptedUuid, true);
968
	return url($acceptedPath . ($pagePart ? '/'.$pagePart : '') . '/'.$synonymUuid, 'highlite='.$synonymUuid);
969
	//return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid, $synonymUuid."/$synonymUuid");
970
	//return url("$acceptedPath/$synonymUuid".($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid);
971
}
(12-12/12)