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">' . $name_used_in_source_link_to_show;
189
    //adding ":" if necesary 
190
    if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
191
    	$res_text .= ': ';
192
    }
193
     $res_text .= $description . $sourceRefs . '</li>';
194
  }else{
195
    $res_text = $description . $sourceRefs . ' (name in source: '. $name_used_in_source_link_to_show . ')';
196
  }
197
  return $res_text;
198
}
199

    
200

    
201
/**
202
 * Theme a list of description elements, usually of a specific feature type
203
 * @param $descriptionElements
204
 * @return unknown_type
205
 */
206
function theme_cdm_descriptionElements($descriptionElements, $featureUuid){
207
	$outArray = array();
208
	$glue = '';
209
	$sortOutArray = false;
210
	$enclosingHtml = 'ul';
211
	$distributionElements = array();
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
	
241
	// take the feature of the last $descriptionElement
242
	$feature = $descriptionElement->feature;
243
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
244
	$out .= '<div class="footnote_list">'. FootnoteManager::renderFootnoteList($featureUuid) . '</div>';
245
	return $out;
246
}
247

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

    
255
	$out = '';
256
	$separator = ', ';
257

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

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

    
283
	return $out;
284

    
285
}
286

    
287

    
288
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
289

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

    
320

    
321

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

    
331
	$fontStyles = array(0 => "plane", 1 => "italic");
332
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
333

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

    
339
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
340
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
341
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
342

    
343
		$query_string = ($display_width ? '&ms=' . $display_width: '')
344
		. ($bounding_box ? '&bbox=' .  $bounding_box : '')
345
		. ($labels_on ? '&labels=' .  $labels_on : '');
346

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

    
357
			//#print($map_tdwg_Uri.'<br>');
358

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

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

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

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

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

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

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

    
526
			}
527
			*/
528
		return $out;
529
	}
530
}
(2-2/8)