Project

General

Profile

Download (18.5 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
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

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

    
53

    
54

    
55
function theme_cdm_featureTreeTOCs($mergedTrees){
56

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

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

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

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

    
74

    
75

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

    
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
		}
116
		// theme
117
		if(count($node->children) > 0){
118
			$out .= '<div class="nested_description_elements">';
119
			$out .= theme('cdm_feature_nodes', $node->children, $taxon);
120
			$out .= '</div>';
121
		}
122
	}
123
	return $out;
124
}
125

    
126

    
127

    
128

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

    
132
	if($sortArray) sort($elementArray);
133

    
134
	$out .= join($elementArray, $glue);
135

    
136
	$out .= '</'.$enclosingHtml.'>';
137
	return $out;
138
}
139

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

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

    
199

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

    
237
	}
238

    
239
	$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
240
	
241
	// take the feature of the last $descriptionElement
242
	$feature = $descriptionElement->feature;
243
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
244
	
245
	$out .= '<div class="footnote_list">'. FootnoteManager::renderFootnoteList($featureUuid) . '</div>';
246
		
247
    RenderHints::popFromRenderStack();
248
    
249
	return $out;
250
}
251

    
252
/**
253
 * 
254
 * @param unknown_type $descriptionElements
255
 * @return unknown_type
256
 */
257
function theme_cdm_descriptionElementDistribution($descriptionElements){
258

    
259
	$out = '';
260
	$separator = ', ';
261

    
262
	foreach($descriptionElements as $descriptionElement){
263
		//$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $descriptionElement->area->representation_L10n);
264
//		$footnoteKeyList = '';
265
//		foreach($descriptionElement->sources as $source){
266
//			$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, theme('cdm_DescriptionElementSource', $source));
267
//			$footnoteKeyList .= theme('cdm_footnode_key', $footnoteKey) . ' ';
268
//		}
269
	    $out .= $descriptionElement->area->representation_L10n . $footnoteKeyList . $separator;
270
	}
271
	$out = substr($out, 0, strlen($out)-strlen($separator) );
272
	
273
	$taxonTrees =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
274
	foreach($taxonTrees as $taxonTree){
275
		if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
276
			$reference = $taxonTree-> reference;
277
			break;
278
		}
279
	}
280

    
281
//  $referenceCitation = l('<span class="reference">('.$reference->title.')</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
282
//	if($descriptions && strlen($descriptions) > 0 ){
283
//		$sourceRefs .= ' '.$referenceCitation;
284
//	}
285

    
286
	return $out;
287

    
288
}
289

    
290

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
509
			}
510
			*/
511
		return $out;
512
	}
513
}
(2-2/8)