Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.descriptions.theme @ b5e773ef

History | View | Annotate | Download (18.5 KB)

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
function theme_cdm_feature_nodesTOC($featureNodes){
14

    
15
	$out .= '<ul>';
16

    
17
	foreach($featureNodes as $node){
18
		// process $descriptionElements with content only
19
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0){
20

    
21
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
22
			// HACK to implement images for taxa, should be removed
23
			if($node->feature->uuid != UUID_IMAGE){
24
				$out .= '<li>'.l(t(theme('cdm_feature_name', $featureRepresentation)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($featureRepresentation)).'</li>';
25
			}
26
		}
27
	}
28

    
29
	$out .= '</ul>';
30
	return $out;
31
}
32

    
33
function theme_cdm_feature_name($feature_name){
34
	//TODO replace by using translations ?
35
	switch($feature_name){
36
		default: return t(ucfirst($feature_name));
37
	}
38
}
39

    
40
function theme_cdm_featureTrees($mergedTrees, $taxon){
41

    
42
	if(!$mergedTrees){
43
		return;
44
	}
45
	foreach($mergedTrees as &$mTree){
46
		//TODO diplay title and reference in case of multiple $mergedTrees -> theme
47
		$out .= theme('cdm_feature_nodes', $mTree->root->children, $taxon);
48
	}
49
	return $out;
50
}
51

    
52

    
53

    
54
function theme_cdm_featureTreeTOCs($mergedTrees){
55

    
56
	if(!$mergedTrees){
57
		return;
58
	}
59
	//FIXME
60
	$out = '<div class="featureTOC">';
61
	$out .= '<h2>' . t('Content') .'</h2>';
62

    
63
	//TODO diplay title and reference in case of multiple $mergedTrees -> theme
64

    
65
	foreach($mergedTrees as &$mTree){
66
		$out .= theme('cdm_feature_nodesTOC', $mTree->root->children);
67
	}
68

    
69
	$out .= '</div>';
70
	return $out;
71
}
72

    
73

    
74

    
75
function theme_cdm_feature_nodes($featureNodes, $taxon){
76

    
77
	RenderHints::pushToRenderStack('feature_nodes');
78
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
79
	
80
	foreach($featureNodes as $node){
81
		// process $descriptionElements with content only
82
		if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0){
83

    
84
			$featureRepresentation = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
85

    
86
			$block->module = 'cdm_dataportal';
87

    
88
			if($node->feature->uuid != UUID_IMAGE){
89
				$block->delta = generalizeString($featureRepresentation);
90
				$block->subject = theme('cdm_feature_name', $featureRepresentation);
91
				$block->module = "cdm_dataportal-feature";
92

    
93
				//get the text for the feature block
94
				$block->content = theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid);
95
				// get media for the feature block
96
				$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
97
				$captionElements = array('title', 'rights');
98
				//$block->content .= theme('cdm_media_gallerie', $media_list, "test", 150, 4, false, $captionElements);
99
				$block->content .= theme('cdm_media_gallery', $media_list, 
100
					CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
101
					$gallery_settings['cdm_dataportal_media_maxextend'], 
102
	             	$gallery_settings['cdm_dataportal_media_cols'], 
103
	             	$gallery_settings['cdm_dataportal_media_maxRows'],
104
	             	$captionElements);
105
				
106
				// set anchor; FIXME put anchor in $block->subject
107
				$out .= '<a name="'.$block->delta.'"></a>';
108
				$out .= theme('block', $block);
109

    
110
				// TODO HACK
111
				if($node->feature->uuid == UUID_DISTRIBUTION){
112
					$out .= theme('cdm_descriptionElements_distribution', $taxon);
113
				}
114
				
115
			    $out .= theme('cdm_footnotes', $node->feature->uuid);
116
			    $out .= theme('cdm_annotation_footnotes', $node->feature->uuid);
117
			}
118
		}
119
		// theme
120
		if(count($node->children) > 0){
121
			$out .= '<div class="nested_description_elements">';
122
			$out .= theme('cdm_feature_nodes', $node->children, $taxon);
123
			$out .= '</div>';
124
		}
125
	}
126
	RenderHints::popFromRenderStack();
127
	return $out;
128
}
129

    
130

    
131

    
132

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

    
136
	if($sortArray) sort($elementArray);
137

    
138
	$out .= join($elementArray, $glue);
139

    
140
	$out .= '</'.$enclosingHtml.'>';
141
	return $out;
142
}
143

    
144
/**
145
 * TODO: assign a new name to the function? because it is used for the citations 
146
 *       textdata elements and not for all text data description elements
147
 * @param $element The description element which contains the text information
148
 * @param $asListElement A boolean which determines whether the citations should 
149
 *                       be renderer as a list or not  
150
 * @return unknown_type Html to be renderized in drupal
151
 */
152
function theme_cdm_descriptionElementTextData($element, $asListElement){
153

    
154
  $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
155
  $sourceRefs = '';
156
  $result = array();
157
  $out;
158
  $res_author;
159
  $res_date;
160
   
161
  foreach($element->sources as $source){
162
    $referenceCitation = theme('cdm_DescriptionElementSource', $source);
163
    if($description && strlen($description) > 0 && $referenceCitation ){
164
        $sourceRefs .= ' ('.$referenceCitation.')' ;
165
    }else if ($referenceCitation){
166
    	  $sourceRefs = $referenceCitation;
167
    }
168
  }
169
  if(strlen($sourceRefs) > 0){
170
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
171
  }
172
 
173
  if ($source->nameUsedInSource->uuid){ //do a link to name page
174
    $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
175
                                           path_to_name($source->nameUsedInSource->uuid), 
176
                                           array(),
177
                                           NULL, NULL, FALSE ,TRUE);
178
  }else if (strlen($source->nameUsedInSource->originalNameString) > 0){ //show a text without link
179
  	$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
180
  }
181
  
182
  if ($asListElement){
183
    $out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
184
    //adding ":" if necesary 
185
    if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
186
    	$out .= ': ';
187
    }
188
     $out .= $description . $sourceRefs . '</li>';
189
  }else{
190
    $out = $description . $sourceRefs . ' (name in source: '. $name_used_in_source_link_to_show . ')';
191
  }
192
  
193
  // add annotations as footnote key
194
  $out .= theme('cdm_annotations_as_footnotekeys', $element);
195
  return $out;
196
}
197

    
198

    
199
/**
200
 * Theme a list of description elements, usually of a specific feature type
201
 * @param $descriptionElements
202
 * @return unknown_type
203
 */
204
function theme_cdm_descriptionElements($descriptionElements, $featureUuid){
205
	$outArray = array();
206
	$glue = '';
207
	$sortOutArray = false;
208
	$enclosingHtml = 'ul';
209
	$distributionElements = array();
210
	
211
	RenderHints::pushToRenderStack('cdm_descriptionElements');
212
	
213
	foreach($descriptionElements as $descriptionElement){
214
		
215
		if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
216
			if($descriptionElement->class == 'Distribution'){
217
				$distributionElements[]= $descriptionElement;
218
			} else if($descriptionElement->class == 'TextData'){
219
				$asListElement = false;
220
				$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
221
					
222
				if( !array_search($repr, $outArray)){
223
					$outArray[] = $repr;
224
					$glue = '<br/> ';
225
					$sortOutArray = true;
226
					$enclosingHtml = 'p';
227
				}
228
			}
229
		} else if($descriptionElement->class == 'TextData'){
230
			$asListElement = true;
231
			$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
232
		} else {
233
			$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
234
		}
235

    
236
	}
237

    
238
	$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
239
	
240
	// take the feature of the last $descriptionElement
241
	$feature = $descriptionElement->feature;
242
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
243
	
244
    RenderHints::popFromRenderStack();
245
    
246
	return $out;
247
}
248

    
249
/**
250
 * 
251
 * @param unknown_type $descriptionElements
252
 * @return unknown_type
253
 */
254
function theme_cdm_descriptionElementDistribution($descriptionElements){
255

    
256
	$out = '';
257
	$separator = ',';
258
    RenderHints::pushToRenderStack('descriptionElementDistribution');
259
	RenderHints::setFootnoteListKey(UUID_DISTRIBUTION);
260
	foreach($descriptionElements as $descriptionElement){
261
		// annotations as footnotes
262
		$annotationFootnoteKeys = theme('cdm_annotations_as_footnotekeys', $descriptionElement);
263
		// source references as footnotes
264
		$sourcesFootnoteKeyList = '';
265
		foreach($descriptionElement->sources as $source){
266
			$_fkey = FootnoteManager::addNewFootnote(UUID_DISTRIBUTION, theme('cdm_DescriptionElementSource', $source, false));
267
			$sourcesFootnoteKeyList .= theme('cdm_footnote_key', $_fkey, UUID_DISTRIBUTION, ($sourcesFootnoteKeyList ? $separator : ''));
268
		}
269
		if($annotationFootnoteKeys && $sourcesFootnoteKeyList){
270
			$annotationFootnoteKeys .= $separator;
271
		}
272
	    $out .= $descriptionElement->area->representation_L10n . $annotationFootnoteKeys . $sourcesFootnoteKeyList . ' ';
273
	}
274
	
275
	
276
	$out = substr($out, 0, strlen($out)-strlen($separator) );
277
	
278
	$taxonTrees =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
279
	foreach($taxonTrees as $taxonTree){
280
		if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
281
			$reference = $taxonTree-> reference;
282
			break;
283
		}
284
	}
285

    
286
    RenderHints::popFromRenderStack();
287
	return $out;
288

    
289
}
290

    
291

    
292
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
293

    
294
    $out = theme('cdm_reference', $descriptionElementSource->citation, $descriptionElementSource->citationMicroReference, $doLink);
295
    
296
	// add annotations as footnote key
297
    $out .= theme('cdm_annotations_as_footnotekeys', $descriptionElementSource->citation);
298
    return $out;
299
}
300

    
301
/**
302
 * TODO
303
 * Quick-and-dirty solution to show distribution service to exemplar groups
304
 *
305
 * @param unknown_type $featureTo
306
 * @return unknown
307
 */
308
function theme_cdm_descriptionElements_distribution($taxon){
309

    
310
	$fontStyles = array(0 => "plane", 1 => "italic");
311
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
312

    
313
	if(!server){
314
		return "<p>No geoservice specified</p>";
315
	}else{
316
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
317

    
318
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
319
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
320
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
321

    
322
		$query_string = ($display_width ? '&ms=' . $display_width: '')
323
		. ($bounding_box ? '&bbox=' .  $bounding_box : '')
324
		. ($labels_on ? '&labels=' .  $labels_on : '');
325

    
326
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
327
			// embed into openlayers viewer
328
			if (variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
329
			  $query_string .= '&img=false&legend=1&mlp=3';
330
			}
331
			$map_data_parameters->String = str_replace(': ', "%20", $map_data_parameters->String);
332
			$map_data_parameters->String = str_replace('(', "", $map_data_parameters->String);
333
			$map_data_parameters->String = str_replace(')', "", $map_data_parameters->String);
334
			$map_tdwg_Uri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
335
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
336
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
337
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
338
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
339
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
340

    
341
			//print($map_tdwg_Uri.'<br>');
342

    
343
			// get the respone from the map service
344
			$responseObj = cdm_ws_get($map_tdwg_Uri, null, null, "GET", TRUE);
345
			$responseObj = $responseObj[0];
346

    
347
			$geoserver_uri = $responseObj->geoserver;
348
			// get the sld files from the response object
349
			if(isset($responseObj->layers)){
350
				if(isset($responseObj->legend)){
351

    
352
					$sldLegend=$responseObj->legend;
353
					$legend_url  = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
354
					$legend_url .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
355
					$legend_url .="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);
356
				}
357
				$layerSlds = $responseObj->layers;
358
				foreach($layerSlds as $layer){
359
					$tdwg_sldUris[$layer->tdwg] = $layer->sld;
360
					//#print($tdwg_sldUris[$layer->tdwg].'<br>');
361
				}
362
			}
363
			// get the bbox from the response object
364
			$zoomto_bbox = ($bounding_box ? $bounding_box : ($responseObj->bbox ? $responseObj->bbox :'-180, -90, 180, 90') );
365

    
366
			$add_tdwg1 = (isset($tdwg_sldUris['tdwg1']) ? "
367
          tdwg_1.params.SLD = '".$tdwg_sldUris['tdwg1']."';
368
          map.addLayers([tdwg_1]);" : '');
369
			$add_tdwg2 = (isset($tdwg_sldUris['tdwg2']) ? "
370
          tdwg_2.params.SLD = '".$tdwg_sldUris['tdwg2']."';
371
          map.addLayers([tdwg_2]);" : '');
372
			$add_tdwg3 = (isset($tdwg_sldUris['tdwg3']) ? "
373
          tdwg_3.params.SLD = '".$tdwg_sldUris['tdwg3']."';
374
          map.addLayers([tdwg_3]);" : '');
375
			$add_tdwg4 = (isset($tdwg_sldUris['tdwg4']) ? "
376
          tdwg_4.params.SLD = '".$tdwg_sldUris['tdwg4']."';
377
          map.addLayers([tdwg_4]);" : '');
378

    
379
			//      $googleMapsApiKey_localhost = 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ';
380
			//      drupal_set_html_head(' <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$googleMapsApiKey_localhost.'"></script>');
381

    
382
			/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
383
			 * OpenLayers.js must be loaded BEFORE jQuery.
384
			 * If jQuery loaded before $.something will fail in IE8.
385
			 * Therefore we add OpenLayers.js it in the page.tpl.php
386
			 * -----------------------------------------------------
387
			 * Andreas Kohlbecker [Feb 25th 2010]:
388
			 * This problems seems to be solved somehow (a bugfix in IE8?)
389
			 * so I am removing this "hack" by uncommenting the line below
390
			 */
391
			drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
392
			drupal_add_js('
393
 var map;
394
 
395
 var layerOptions = {
396
     maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
397
     isBaseLayer: false,
398
     displayInLayerSwitcher: false
399
  };
400
 
401
 var tdwg_1 = new OpenLayers.Layer.WMS.Untiled( 
402
    "tdwg level 1", 
403
    "'.$geoserver_uri.'/wms",
404
    {layers:"topp:tdwg_level_1",transparent:"true", format:"image/png"},
405
    layerOptions
406
  );
407
  
408
 var tdwg_2 = new OpenLayers.Layer.WMS.Untiled( 
409
    "tdwg level 2", 
410
    "'.$geoserver_uri.'/wms",
411
    {layers:"topp:tdwg_level_2",transparent:"true", format:"image/png"},
412
    layerOptions
413
  );
414
  
415
 var tdwg_3 = new OpenLayers.Layer.WMS.Untiled( 
416
    "tdwg level 3", 
417
    "'.$geoserver_uri.'/wms",
418
    {layers:"topp:tdwg_level_3", transparent:"true", format:"image/png"},
419
    layerOptions
420
  );
421
  
422
  var tdwg_4 = new OpenLayers.Layer.WMS.Untiled( 
423
    "tdwg level 4", 
424
    "'.$geoserver_uri.'/wms",
425
    {layers:"topp:tdwg_level_4",transparent:"true", format:"image/png"},
426
    layerOptions
427
  );
428
  
429
 // make baselayer
430
 layerOptions[\'isBaseLayer\'] = true; 
431
 
432
 var ol_wms = new OpenLayers.Layer.WMS( 
433
    "OpenLayers WMS",
434
    "http://labs.metacarta.com/wms/vmap0",
435
    {layers: \'basic\'}, 
436
    layerOptions
437
  );
438
  
439
  
440
  // ------------------------------
441
  
442
  
443
 function init() {
444
 
445
   var mapOptions={
446
     controls: 
447
       [ 
448
         new OpenLayers.Control.PanZoom(),
449
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
450
       ],
451
       maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
452
       maxResolution: '.(360 / $display_width).',
453
       restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
454
       projection: new OpenLayers.Projection("EPSG:4326")
455
    };
456
   
457
   map = new OpenLayers.Map(\'openlayers_map\', mapOptions);
458
   map.addLayers([ol_wms]);
459
   '.$add_tdwg1.'
460
   '.$add_tdwg2.'
461
   '.$add_tdwg3.'
462
   '.$add_tdwg4.'
463
   map.zoomToExtent(new OpenLayers.Bounds('.$zoomto_bbox.'), false);
464
 }
465
 
466
$(document).ready(function(){
467
  init();
468
  $(\'#openlayers_legend\').css(\'top\', -$(\'#openlayers_map\').height());
469
  $(\'#openlayers_legend\').css(\'left\', $(\'#openlayers_map\').width()-100);
470
});'
471
, 'inline');
472
// showing openlayers
473
$out = '<div id="openlayers">';
474
$out .= '<div id="openlayers_map" class="smallmap" style="width: '.$display_width.'px; height:'.($display_width / 2).'px"></div>';
475
// showing lengeds
476
if (variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
477
	$out .= '<div id="openlayers_legend"><img id="legend" src="'.$legend_url.'"></div>';
478
}
479
// showing map caption
480
$out .= '<div class="distribution_map_caption">' . variable_get('cdm_dataportal_geoservice_map_caption', '') . '</div>' . '<br>';
481
$out .= '</div>';
482
 
483
		} else {
484
			// simple image
485
			$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
486
			$query_string .= '&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
487
			$mapUri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
488
			$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
489
		}
490
		/*
491
		 // add a simple legend
492
		 if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
493
			$legenddata = array(
494
			'native' => "4daf4a",
495
			'native_doubtfully_native' => "377eb8",
496
			'cultivated' => "984ea3",
497
			'introduced' => "ff7f00",
498
			'introduced adventitious' => "ffff33",
499
			'introduced cultivated' => "a65628",
500
			'introduced naturalized' => "f781bf"
501
			);
502

    
503
			$out .= '<div class="distribution_map_legend">';
504
			foreach($legenddata as $term => $color){
505
			$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
506
			drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
507
			}
508
			$out .= '</div>';
509

    
510
			}
511
			*/
512
		return $out;
513
	}
514
}
Add picture from clipboard (Maximum size: 40 MB)