Project

General

Profile

Download (18.9 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
  $res_text;
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
    }
162
  }
163
  if(strlen($sourceRefs) > 0){
164
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
165
  }
166
/*  
167
          $out = l('<span class="reference">'.$reference.'</span>'
168
          , path_to_reference($descriptionElementSource->citation->uuid)
169
          , array("class"=>"reference")
170
          , NULL, NULL, FALSE ,TRUE);
171
*/  
172
  if ($source->nameUsedInSource->uuid){ //do a link to name page
173
    $name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
174
                                           path_to_name($source->nameUsedInSource->uuid), 
175
                                           array(),
176
                                           NULL, NULL, FALSE ,TRUE);
177
   
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 (strlen($name_used_in_source) > 0){
183
    $name_used_in_source_text_to_show = "  (name used in source: " . $name_used_in_source . ")";
184
  }
185
  */
186
  
187
  if ($asListElement){
188
    $res_text = '<li class="descriptionText">' 
189
      . $name_used_in_source_link_to_show . ': ' . $description . $sourceRefs . '</li>';
190
  }else{
191
    $res_text = $description . $sourceRefs . ' (name in source: '. $name_used_in_source_link_to_show . ')';
192
  }
193
  return $res_text;
194
}
195

    
196

    
197
/**
198
 * Theme a list of description elements, usually of a specific feature type
199
 * @param $descriptionElements
200
 * @return unknown_type
201
 */
202
function theme_cdm_descriptionElements($descriptionElements, $featureUuid){
203
	$outArray = array();
204
	$glue = '';
205
	$sortOutArray = false;
206
	$enclosingHtml = 'ul';
207
	$distributionElements = array();
208

    
209
	foreach($descriptionElements as $descriptionElement){
210
		
211
		if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
212
			if($descriptionElement->class == 'Distribution'){
213
				$distributionElements[]= $descriptionElement;
214
			} else if($descriptionElement->class == 'TextData'){
215
				$asListElement = false;
216
				$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
217
					
218
				if( !array_search($repr, $outArray)){
219
					$outArray[] = $repr;
220
					$glue = '<br/> ';
221
					$sortOutArray = true;
222
					$enclosingHtml = 'p';
223
				}
224
			}
225
		} else if($descriptionElement->class == 'TextData'){
226
			$asListElement = true;
227
			$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
228
		} else {
229
			$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
230
		}
231

    
232
	}
233

    
234
	$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
235
	
236
	
237
	// take the feature of the last $descriptionElement
238
	$feature = $descriptionElement->feature;
239
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
240
	$out .= '<div class="footnote_list">'. FootnoteManager::renderFootnoteList($featureUuid) . '</div>';
241
	return $out;
242
}
243

    
244
/**
245
 * 
246
 * @param unknown_type $descriptionElements
247
 * @return unknown_type
248
 */
249
function theme_cdm_descriptionElementDistribution($descriptionElements){
250

    
251
	$out = '';
252
	$separator = ', ';
253

    
254
	foreach($descriptionElements as $descriptionElement){
255
		//$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $descriptionElement->area->representation_L10n);
256
	$footnoteKeyList = '';
257
	foreach($descriptionElement->sources as $source){
258
		break;
259
		$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $source, 'cdm_DescriptionElementSource');
260
		$footnoteKeyList .= theme('cdm_footnode_key', $footnoteKey) . ' ';
261
	}
262
    $out .= $descriptionElement->area->representation_L10n . $footnoteKeyList . $separator;
263
	}
264
	$out = substr($out, 0, strlen($out)-strlen($separator) );
265
	
266
	$taxonTrees =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY);
267
	foreach($taxonTrees as $taxonTree){
268
		if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
269
			$reference = $taxonTree-> reference;
270
			break;
271
		}
272
	}
273

    
274
//  $referenceCitation = l('<span class="reference">('.$reference->title.')</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
275
//	if($descriptions && strlen($descriptions) > 0 ){
276
//		$sourceRefs .= ' '.$referenceCitation;
277
//	}
278

    
279
	return $out;
280

    
281
}
282

    
283

    
284
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
285

    
286
    //ev. delegate to theme_cdm_ReferencedEntityBase
287
    $out = '';
288
    if($descriptionElementSource->citation){
289
    	//var_dump($descriptionElementSource->citation->authorTeam->teamMembers[0]->lastname);
290
      $datePublished = $descriptionElementSource->citation->datePublished;
291
      if (strlen($datePublished->start) >0){
292
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
293
      }
294
      //$author_team_titlecache = $descriptionElementSource->citation->authorTeam->titleCache;
295
      $author_team_titlecache = $descriptionElementSource->citation->authorTeam->teamMembers[0]->lastname;
296
      if (strlen($year)>0){
297
        $reference = $author_team_titlecache.' '. $year;
298
      }else {
299
        $reference = $author_team_titlecache ;
300
      }
301
      
302
      if($doLink){
303
        $out = l('<span class="reference">'.$reference.'</span>'
304
          , path_to_reference($descriptionElementSource->citation->uuid)
305
          , array("class"=>"reference")
306
          , NULL, NULL, FALSE ,TRUE);
307
      } else {
308
       $out = $reference;
309
      }
310
      if($descriptionElementSource->citationMicroReference){
311
        $out .= ': '. $descriptionElementSource->citationMicroReference;
312
      }
313
    }
314
    return $out;
315
}
316

    
317

    
318

    
319
/**
320
 * TODO
321
 * Quick-and-dirty solution to show distribution service to exemplar groups
322
 *
323
 * @param unknown_type $featureTo
324
 * @return unknown
325
 */
326
function theme_cdm_descriptionElements_distribution($taxon){
327

    
328
	$fontStyles = array(0 => "plane", 1 => "italic");
329
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
330

    
331
	if(!server){
332
		return "<p>No geoservice specified</p>";
333
	}else{
334
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
335

    
336
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
337
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
338
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
339

    
340
		$query_string = ($display_width ? '&ms=' . $display_width: '')
341
		. ($bounding_box ? '&bbox=' .  $bounding_box : '')
342
		. ($labels_on ? '&labels=' .  $labels_on : '');
343

    
344
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
345
			// embed into openlayers viewer
346
			$query_string .= '&img=false&legend=1&mlp=3';
347
			$map_tdwg_Uri = url($server. '/areas.php?' .$map_data_parameters->String, $query_string);
348
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
349
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
350
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
351
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
352
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
353

    
354
			//#print($map_tdwg_Uri.'<br>');
355

    
356
			// get the respone from the map service
357
			$responseObj = cdm_ws_get($map_tdwg_Uri, null, null, "GET", TRUE);
358
			$responseObj = $responseObj[0];
359

    
360
			$geoserver_uri = $responseObj->geoserver;
361
			// get the sld files from the response object
362
			if(isset($responseObj->layers)){
363
				if(isset($responseObj->legend)){
364

    
365
					$sldLegend=$responseObj->legend;
366
					$legend_url  = $geoserver_uri . "/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
367
					$legend_url .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
368
					$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);
369
				}
370
				$layerSlds = $responseObj->layers;
371
				foreach($layerSlds as $layer){
372
					$tdwg_sldUris[$layer->tdwg] = $layer->sld;
373
					//#print($tdwg_sldUris[$layer->tdwg].'<br>');
374
				}
375
			}
376
			// get the bbox from the response object
377
			$zoomto_bbox = ($bounding_box ? $bounding_box : ($responseObj->bbox ? $responseObj->bbox :'-180, -90, 180, 90') );
378

    
379
			$add_tdwg1 = (isset($tdwg_sldUris['tdwg1']) ? "
380
          tdwg_1.params.SLD = '".$tdwg_sldUris['tdwg1']."';
381
          map.addLayers([tdwg_1]);" : '');
382
			$add_tdwg2 = (isset($tdwg_sldUris['tdwg2']) ? "
383
          tdwg_2.params.SLD = '".$tdwg_sldUris['tdwg2']."';
384
          map.addLayers([tdwg_2]);" : '');
385
			$add_tdwg3 = (isset($tdwg_sldUris['tdwg3']) ? "
386
          tdwg_3.params.SLD = '".$tdwg_sldUris['tdwg3']."';
387
          map.addLayers([tdwg_3]);" : '');
388
			$add_tdwg4 = (isset($tdwg_sldUris['tdwg4']) ? "
389
          tdwg_4.params.SLD = '".$tdwg_sldUris['tdwg4']."';
390
          map.addLayers([tdwg_4]);" : '');
391

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

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

    
516
			$out .= '<div class="distribution_map_legend">';
517
			foreach($legenddata as $term => $color){
518
			$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
519
			drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
520
			}
521
			$out .= '</div>';
522

    
523
			}
524
			*/
525
		return $out;
526
	}
527
}
(2-2/8)