Project

General

Profile

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

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

    
13

    
14
function _add_js_openlayers_map(){
15

    
16
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
17
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
18
	drupal_add_js("
19
        if (Drupal.jsEnabled) {
20
          $(document).ready(function() {
21
              $('#openlayers_map').cdm_openlayers_map('"
22
              .variable_get('cdm_dataportal_geoservice_access_point', false)."', {
23
                legendPosition: 3,
24
                displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "',
25
                boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "',
26
                distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
27
                legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "'
28
            });
29
          });
30
        }", 'inline');
31

    
32
}
33

    
34
function theme_cdm_feature_nodesTOC($featureNodes){
35

    
36
	$out .= '<ul>';
37

    
38
	foreach($featureNodes as $node){
39
		// process $descriptionElements with content only
40
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
41

    
42
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
43
			// HACK to implement images for taxa, should be removed
44
			if($node->feature->uuid != UUID_IMAGE){
45
				$out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
46
			}
47
		}
48
	}
49

    
50
	$out .= '</ul>';
51
	return $out;
52
}
53

    
54
function theme_cdm_feature_name($feature_name){
55
	//TODO replace by using translations ?
56
	switch($feature_name){
57
		default: return t(ucfirst($feature_name));
58
	}
59
}
60

    
61
function theme_cdm_featureTrees($mergedTrees, $taxon){
62
	if(!$mergedTrees){
63
		return;
64
	}
65
	foreach($mergedTrees as &$mTree){
66
		//TODO diplay title and reference in case of multiple $mergedTrees -> theme
67
		$out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
68
	}
69
	return $out;
70
}
71

    
72

    
73

    
74
function theme_cdm_featureTreeTOCs($mergedTrees){
75

    
76
	if(!$mergedTrees){
77
		return;
78
	}
79
	//FIXME
80
	$out = '<div class="featureTOC">';
81
	$out .= '<h2>' . t('Content') .'</h2>';
82

    
83
	//TODO diplay title and reference in case of multiple $mergedTrees -> theme
84

    
85
	foreach($mergedTrees as &$mTree){
86
		$out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
87
	}
88

    
89
	$out .= '</div>';
90
	return $out;
91
}
92

    
93

    
94

    
95
function theme_cdm_feature_nodes($featureNodes, $taxon){
96

    
97
	RenderHints::pushToRenderStack('feature_nodes');
98
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
99

    
100
	foreach($featureNodes as $node){
101
		// process $descriptionElements with content only
102
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
103
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
104
			$block->module = 'cdm_dataportal';
105

    
106
			if($node->feature->uuid != UUID_IMAGE){
107
				$block->delta = generalizeString($featureRepresentation);
108
				$block->subject = theme('cdm_feature_name', $featureRepresentation);
109
				$block->module = "cdm_dataportal-feature";
110
				$block->content = '';
111

    
112
				// Display cdm distribution map TODO this is a HACK to a proper generic implementation?
113
				if($node->feature->uuid == UUID_DISTRIBUTION){
114
					$block->content .= theme('cdm_distribution_map', $taxon);
115
				}
116

    
117
				//get the text for the feature block
118
				//if ($node->feature->titleCache == 'Common Name'){
119
				if ($node->feature->uuid == UUID_COMMON_NAME){
120
					$block->content .= theme('cdm_common_names', $node->descriptionElements);
121
				} else {
122
					$block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
123
				}
124

    
125
				// get media for the feature block
126
				$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
127
				$captionElements = array('title', 'rights');
128
				//$block->content .= theme('cdm_media_gallerie', $media_list, "test", 150, 4, false, $captionElements);
129
				$block->content .= theme('cdm_media_gallery', $media_list,
130
				          CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
131
				$gallery_settings['cdm_dataportal_media_maxextend'],
132
				$gallery_settings['cdm_dataportal_media_cols'],
133
				$gallery_settings['cdm_dataportal_media_maxRows'],
134
				$captionElements
135
				);
136

    
137
				$block->content .= theme('cdm_footnotes', $node->feature->uuid);
138
				$block->content .= theme('cdm_annotation_footnotes', $node->feature->uuid);
139

    
140
				// set anchor; FIXME put anchor in $block->subject
141
				$out .= '<a name="'.$block->delta.'"></a>';
142
				$out .= theme('block', $block);
143

    
144
			}
145
		}
146
		// theme
147
		if(count($node->children) > 0){
148
			/*
149
			 $out .= '<div class="nested_description_elements">';
150
			 $out .= theme('cdm_feature_nodes', $node->children, $taxon);
151
			 $out .= '</div>';
152
			 */
153
			$text = '';
154
			foreach ($node->children as $child){
155
			 //$out .= theme('cdm_descriptionElementTextData', $child->descriptionElements[0], false);
156
			 if (is_array($child->descriptionElements)){//if condition added to avoid warnings
157
			 	foreach ($child->descriptionElements as $element) {
158
			 		$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
159
			 		$description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
160
			 	}
161
			 	$text .= $description;
162
			 	$description = '';
163
			 }
164
			}
165
			$out .= $text;
166
		}
167

    
168
	}
169
	RenderHints::popFromRenderStack();
170
	return $out;
171
}
172

    
173

    
174

    
175

    
176
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
177
	$out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
178

    
179
	if($sortArray) sort($elementArray);
180

    
181
	$out .= join($elementArray, $glue);
182

    
183
	$out .= '</'.$enclosingHtml.'>';
184
	return $out;
185
}
186

    
187

    
188
function theme_cdm_descriptionElement_CommonTaxonName($element){
189
	$out = $element->language->representation_L10n . ' (' . $element->area->titleCache . '): ' . $element->name;
190
	return $out;
191
}
192
/**
193
 * TODO: assign a new name to the function? because it is used for the citations
194
 *       textdata elements and not for all text data description elements
195
 * @param $element The description element which contains the text information
196
 * @param $asListElement A boolean which determines whether the citations should
197
 *                       be renderer as a list or not
198
 * @return unknown_type Html to be renderized in drupal
199
 */
200
function theme_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid){
201
	$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
202
	$sourceRefs = '';
203
	$result = array();
204
	$out;
205
	$res_author;
206
	$res_date;
207

    
208
	if(is_array($element->sources)){
209
		foreach($element->sources as $source){
210
			$referenceCitation = theme('cdm_DescriptionElementSource', $source);
211
			if($description && strlen($description) > 0 && $referenceCitation ){
212
				$sourceRefs .= ' ('.$referenceCitation.')' ;
213
			}else if ($referenceCitation){
214
				$sourceRefs = $referenceCitation;
215
			}
216

    
217
			if(strlen($sourceRefs) > 0){
218
				$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
219
			}
220

    
221
			if ($source->nameUsedInSource->uuid){ //do a link to name page
222
				$name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
223
				             path_to_name($source->nameUsedInSource->uuid),
224
				             array(), NULL, NULL, FALSE ,TRUE);
225
			}else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
226
				$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
227
			}
228

    
229
			if ($asListElement){
230
				$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
231
				//adding ":" if necesary
232
				if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
233
					$out .= ': ';
234
				}
235
				$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
236
			}else{
237
				if ($name_used_in_source_link_to_show){
238
					$name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
239
				}
240
				$out = $description . $sourceRefs . $name_used_in_source_link_to_show;
241
			}
242
		}
243
	}
244
	//if no sources, print the description
245
  if(!isset($out)) {
246
    $out = $description;
247
  }
248
  //printing annotations footnotes
249
	//$out .= theme('cdm_annotations_as_footnotekeys', $element);
250
	// add annotations as footnote key
251
	//$out .= theme('cdm_annotations_as_footnotekeys', $element); move above
252
	return $out;
253
}
254

    
255
function theme_cdm_common_names($elements){
256
  $text_data_out = '';
257
  $common_name_out = '';
258
  $separator = ',';
259
  $textData_commonNames = array();
260

    
261
  if (is_array($elements)){
262
   foreach ($elements as $element){
263
    if ($element->class == 'CommonTaxonName'){
264
      //$key = '<b>' . $element->language->representation_L10n . '</b> (' . $element->area->titleCache . ')';
265
      $key = '<b>' . $element->language->representation_L10n . '</b>';
266
      $key .= (strlen($element->area->titleCache)>0) ? ' (' . $element->area->titleCache . ')' : '';
267
      $common_names[$key][] = $element;
268
    }else if ($element->class == 'TextData' && $element->feature->uuid == UUID_COMMON_NAME){
269
      $textData_commonNames[] = $element;
270
    }
271
   }
272
  }
273
  //handling common names
274
  if (count($common_names) > 0){
275
    //sorting the a-array based on the area (key)
276
    ksort($common_names);
277
    //creating the output to be render by drupal
278
    foreach ($common_names as $key => $elements){
279

    
280
      $rendered_element_list = '';
281
      foreach($elements as $element){
282
        $sourcesFootnoteKeyList = '';
283
        // addinf footnotes sources
284
        foreach($element->sources as $source){
285
          if(_is_original_source_type($source)){
286
            $_fkey = FootnoteManager::addNewFootnote(UUID_COMMON_NAME, theme('cdm_DescriptionElementSource', $source, false));
287
            $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, ($sourcesFootnoteKeyList ? $separator : ''));
288
          }
289
        }
290
        $rendered_element_list .= (strlen($rendered_element_list) > 0 ? ', ': '') . $element->name . $sourcesFootnoteKeyList;
291
      }
292
      $common_name_out .= (strlen($common_name_out) > 0 ? '; ': '') . $key . ': ' . $rendered_element_list;
293

    
294
    }
295
  }
296
  //handling commons names as text data
297
  foreach($textData_commonNames as $text_data_element){
298
    $text_data_out .= theme('cdm_descriptionElementTextData', $text_data_element, true, $text_data_element->feature->uuid);
299
  }
300
  $out_array[] = $text_data_out;
301
  return $common_name_out . theme('cdm_descriptionElementArray', $out_array, $element->feature);
302
}
303

    
304
/**
305
 * Theme a list of description elements, usually of a specific feature type
306
 * @param $descriptionElements
307
 * @return unknown_type
308
 */
309
function theme_cdm_descriptionElements($descriptionElements, $featureUuid, $taxon_uuid){
310
	$outArray = array();
311
	if(variable_get('distribution_sort', false)){
312
		$glue = '';
313
		$enclosingHtml = 'dl';
314
	} else {
315
		$glue = '';
316
		$enclosingHtml = 'ul';
317
	}
318
	$sortOutArray = false;
319
	$distributionElements = array();
320

    
321
	RenderHints::pushToRenderStack('cdm_descriptionElements');
322
	$common_names = theme('cdm_common_names', $descriptionElements);
323
	if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
324
	foreach($descriptionElements as $descriptionElement){
325
		if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
326
			if($descriptionElement->class == 'Distribution'){
327
				$distributionElements[]= $descriptionElement;
328
			} else if($descriptionElement->class == 'TextData'){
329
				$asListElement = false;
330
				$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
331

    
332
				if( !array_search($repr, $outArray)){
333
					$outArray[] = $repr;
334
					$glue = '<br/> ';
335
					$sortOutArray = true;
336
					$enclosingHtml = 'p';
337
				}
338
			}
339
		}else if($descriptionElement->class == 'TextData'){
340
			$asListElement = true;
341
			$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement, $descriptionElement->feature->uuid);
342
		}else if ($descriptionElement->class == 'CommonTaxonName') {
343
			$outArray[] = theme('cdm_descriptionElement_CommonTaxonName', $descriptionElement);
344
		}else {
345
			$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
346
		}
347
	}
348
	}
349
	//if feature = NAME USAGE sort the list of sources
350
	//this is ONLY for FLORA MALESIANA and FLORE d'AFRIQUE CENTRALE
351
	if($descriptionElement->feature->uuid == UUID_NAME_USAGE){
352
		sort($outArray);
353
	}
354

    
355
	if(variable_get('distribution_sort', false)){
356
		$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
357
	}else{
358
		$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
359
	}
360
	//$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
361
	//$outArray[] = theme('cdm_description_ordered_distributions', $taxon_uuid, $distributionElements);
362

    
363
	// take the feature of the last $descriptionElement
364
	$feature = $descriptionElement->feature;
365
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
366

    
367
	RenderHints::popFromRenderStack();
368
	return $out;
369
}
370

    
371
/**
372
 *
373
 * @param unknown_type $descriptionElements
374
 * @return unknown_type
375
 */
376
function theme_cdm_descriptionElementDistribution($descriptionElements){
377
	$out = '';
378
	$separator = ',';
379
	RenderHints::pushToRenderStack('descriptionElementDistribution');
380
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
381
	foreach($descriptionElements as $descriptionElement){
382
		// annotations as footnotes
383
		//$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
384
		$footNoteKeys = cdm_annotations_as_footnotekeys($descriptionElement);
385
		// source references as footnotes
386
		foreach($descriptionElement->sources as $source){
387
			if(_is_original_source_type($source)){
388
				$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
389
				cdm_add_footnote_to_array($footNoteKeys, $fn_key);// ensure uniqueness of the footnote keys
390
			}
391
		}
392
		// sort and render footnote keys
393
		$footnoteKeyListStr = '';
394
		asort($footNoteKeys);
395
		foreach($footNoteKeys as $footNoteKey){
396
			$footnoteKeyListStr .= theme('cdm_footnote_key', $footNoteKey, ($footnoteKeyListStr ? $separator : ''));
397
		}
398
		$out .= '<span class="descriptionElement descriptionElement-'.$descriptionElement->uuid.'">'.$descriptionElement->area->representation_L10n . $footnoteKeyListStr . ' </span>';
399
	}
400

    
401
	//$out = substr($out, 0, strlen($out)-strlen($separator) );
402

    
403
	RenderHints::popFromRenderStack();
404
	return $out;
405

    
406
}
407

    
408
function theme_cdm_description_ordered_distributions($taxon_uuid, $descriptionElements){
409

    
410
	if ($descriptionElements == null){
411
	 return '';
412
	}
413
	$out = '';
414
	$separator = ',';
415
	RenderHints::pushToRenderStack('descriptionElementDistribution');
416
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
417

    
418
	//getting all the taxon description for a given taxon
419
	$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon_uuid);
420
	foreach ($taxonDescriptions as $description){
421
		$descriptions_uuids[] = $description->uuid;
422
	}
423
	//getting the sortered distributions (omiting level ??)
424
	$request_params = array();
425
	$request_params['omitLevels'] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2;
426
	//$ordered_areas = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_AREAS_TREE, $descriptions_uuids, queryString($request_params));
427
	$ordered_areas2 = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION_DISTRIBUTION_TREE, $descriptions_uuids, queryString($request_params));
428
	$ordered_areas2 = $ordered_areas2->rootElement->children;
429

    
430
	//printing the distributions
431
	foreach ($ordered_areas2 as $element_l1){//level 1
432

    
433
		if ($element_l1->data){
434
			$out .= '<dt>' . $element_l1->data->area->representation_L10n . ':</dt> ';
435
		}
436
		$out .= '<dd>';
437
		foreach ($element_l1->children as $element_l3){//level 3
438
			$out_l4 = '';
439
			if ($element_l3->data){
440
				$l3 = $element_l3->data->area->representation_L10n;
441
			}
442
			if (sizeof($element_l3->children) == 0){
443
				$footnoteKeyListStr2 = '';
444
				$footNoteKeys2 = cdm_annotations_as_footnotekeys($element_l3->data);
445
				foreach($element_l3->data->sources as $source){
446
					if(_is_original_source_type($source)){
447
						//$footNoteKeys2[] = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
448
						$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
449
						cdm_add_footnote_to_array($footNoteKeys2, $fn_key);
450
					}
451
				}
452
				foreach($footNoteKeys2 as $key){
453
					$footnoteKeyListStr2 .= theme('cdm_footnote_key', $key, ($footnoteKeyListStr2 ? $separator : ''));
454
				}
455
				$out_l4 .= $l3 . $footnoteKeyListStr2 . ', ';
456
			}
457
			foreach ($element_l3->children as $element_l4){//level 4
458
				if ($element_l4->data){
459
					$l4 = $element_l4->data->area->representation_L10n;
460
					if (strlen($l4) > 0){
461
						//$out_l4 .= $l4;
462
						$footnoteKeyListStr = '';
463
						$footNoteKeys = cdm_annotations_as_footnotekeys($element_l4->data);
464
						if(isset($element_l4->data->sources)){
465
							foreach($element_l4->data->sources as $source){
466
								if(_is_original_source_type($source)){
467
									//$footNoteKeys[] = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
468
									$fn_key = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey(), theme('cdm_DescriptionElementSource', $source, false));
469
									cdm_add_footnote_to_array($footNoteKeys, $fn_key);
470
								}
471
							}
472
						}
473
						foreach($footNoteKeys as $key){
474
							$footnoteKeyListStr .= theme('cdm_footnote_key', $key, ($footnoteKeyListStr ? $separator : ''));
475
						}
476
						$out_l4 .= $l4 . $footnoteKeyListStr .', ';
477
					}
478
				}
479
			}
480
			$out_l4 = substr($out_l4, 0, -2);
481
			//$out_l4 = '<span class="descriptionElement descriptionElement-' . $element_l4->data->uuid.'">' . $out_l4 . '</span>';
482
			$pieces1 = explode(", ", $out_l4);
483
			$pieces2 =  explode('<span class="footnote-key', $pieces1[0]);
484
			if (((sizeof($pieces1) == 1) && substr_count($pieces2[0], $l3) > 0) || strlen($out_l4)<2){
485
				$out .= $out_l4 . '; ';
486
			}else{
487
				$out .= $l3 . ' (' . $out_l4 . '); ';
488
			}
489
		}
490
		$out = substr($out, 0, -2);
491
		$out .= '.</dd>';
492
	}
493
	RenderHints::popFromRenderStack();
494
	return $out;
495

    
496
	//ignoring the root element because is garbage
497
	/*
498
	 $ordered_areas = $ordered_areas->rootElement->children;
499
	 $out = '';
500

    
501
	 foreach ($ordered_areas as $element_l1){//level 1
502
	 if ($element_l1->data){
503
	 //$result[] = $element_l1->data->titleCache;
504
	 $out .= '<b>' . $element_l1->data->titleCache . ':</b> ';
505
	 }
506
	 foreach ($element_l1->children as $element_l2){//level 2
507
	 $out_l3 = '';
508
	 if ($element_l2->data){
509
	 //$result[][] = $element_l2->data->titleCache;
510
	 //$out .= $element_l2->data->titleCache . '[';
511
	 }
512
	 foreach ($element_l2->children as $element_l3){//level 3
513
	 $out_l4 = '';
514
	 if ($element_l3->data){
515
	 //$result[][][] = $element_l3->data->titleCache;
516
	 $out .= $element_l3->data->titleCache;
517

    
518
	 $l3 = $element_l3->data->titleCache;
519
	 }
520
	 foreach ($element_l3->children as $element_l4){//level 4
521
	 if ($element_l4->data){
522
	 //$result[][][][] = $element_14->data->titleCache;
523
	 $l4 = $element_l4->data->titleCache;
524
	 if (sizeof($l4) != 0 && $l4 != $l3){
525
	 $out_l4 .= $l4 . ', ';
526
	 }
527
	 }
528
	 }
529
	 $out_l4 = substr($out_l4, 0, -2);
530
	 if($out_l4){
531
	 $out .= ' (' . $out_l4 . '); ';
532
	 }else{
533
	 $out .= '; ';
534
	 }
535
	 }
536
	 }
537
	 $out = substr($out, 0, -2);
538
	 $out .= '<br>';
539
	 }
540
	 */
541
}
542

    
543

    
544
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
545

    
546
	if(isset($descriptionElementSource->citation)){
547
		$out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
548
	}
549
	return $out;
550
}
551

    
552

    
553
/*
554
 function theme_cdm_descriptionElementDistribution($descriptionElements){
555

    
556
 $out = '';
557
 $separator = ',';
558
 RenderHints::pushToRenderStack('descriptionElementDistribution');
559
 RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
560
 foreach($descriptionElements as $descriptionElement){
561
 // annotations as footnotes
562
 $annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
563
 // source references as footnotes
564
 $sourcesFootnoteKeyList = '';
565
 foreach($descriptionElement->sources as $source){
566
 if(_is_original_source_type($source)){
567
 $_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
568
 $sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
569
 }
570
 }
571
 if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
572
 $annotationFootnoteKeys .= $separator;
573
 }
574
 $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
575
 }
576

    
577
 $out = substr($out, 0, strlen($out)-strlen($separator) );
578

    
579
 RenderHints::popFromRenderStack();
580
 return $out;
581

    
582
 }
583
 */
584

    
585

    
586
/**
587
 * TODO
588
 * Quick-and-dirty solution to show distribution service to exemplar groups
589
 *
590
 * @param unknown_type $featureTo
591
 * @return unknown
592
 */
593
function theme_cdm_distribution_map($taxon){
594

    
595
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
596

    
597
	if(!$server){
598
		//warning message
599
		drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
600
		. 'Please configure the variable \'Geoservice Access Point\' here '
601
		. l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
602
		//message to render
603
		return "<p>No geoservice specified</p>";
604
	}else{
605
		$fontStyles = array(0 => "plane", 1 => "italic");
606

    
607
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
608
		$query_string = $map_data_parameters->String;
609
		if(!$query_string){
610
			// the $query_string is empty if there are no distribution areas defined
611
			return ;
612
		}
613

    
614
		$query_string = str_replace('%3A', ":", $query_string);
615

    
616
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
617
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
618
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
619

    
620
		$query_string .= ($display_width ? '&img=false&ms=' . $display_width: '').
621
		  ($bounding_box ? '&bbox=' .  $bounding_box : '')
622
		. ($labels_on ? '&labels=' .  $labels_on : '');
623

    
624
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
625

    
626
			/* =========== display distributions using the openlayers map viewer =========== */
627

    
628
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
629
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
630
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
631
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
632
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
633

    
634
			//$legendQueryStr  = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
635
			$legendFormatQueryStr  = "format=image".urlencode('/')."png&TRANSPARENT=TRUE";
636
			$legendFormatQueryStr .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
637
			$legendFormatQueryStr .="layer=topp".urlencode(':')."tdwg_level_4&LEGEND_OPTIONS=forceLabels".urlencode(':')."on;fontStyle".urlencode(':').$legend_url_font_style.";fontSize".urlencode(':').$legend_url_font_size."&SLD=".urlencode($sldLegend);
638

    
639
			$out = get_openlayers_map(
640
				$display_width,
641
				null,
642
				$query_string,
643
				$legendFormatQueryStr,
644
				variable_get('cdm_dataportal_geoservice_map_caption', '')
645
			);
646

    
647
		} else {
648
			// simple image
649
			$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
650

    
651
			$query_string .= ($display_width ? '&img=true&ms=' . $display_width: '')
652
			.'&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
653

    
654
			$mapUri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
655
			$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
656
		}
657
		/*
658
		 // add a simple legend
659
		 if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
660
			$legenddata = array(
661
			'native' => "4daf4a",
662
			'native_doubtfully_native' => "377eb8",
663
			'cultivated' => "984ea3",
664
			'introduced' => "ff7f00",
665
			'introduced adventitious' => "ffff33",
666
			'introduced cultivated' => "a65628",
667
			'introduced naturalized' => "f781bf"
668
			);
669

    
670
			$out .= '<div class="distribution_map_legend">';
671
			foreach($legenddata as $term => $color){
672
			$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
673
			drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
674
			}
675
			$out .= '</div>';
676

    
677
			}
678
			*/
679
		return $out;
680
	}
681
}
(2-2/8)