Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.descriptions.theme @ 806baeb2

History | View | Annotate | Download (18.4 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

    
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
  if ($asListElement){
167
    $res_text = '<li class="descriptionText">' . $description . $sourceRefs. '</li>';
168
  }else{
169
    $res_text = $description . $sourceRefs;
170
  }
171
  return $res_text;
172
}
173

    
174

    
175
/**
176
 * Theme a list of description elements, usually of a specific feature type
177
 * @param $descriptionElements
178
 * @return unknown_type
179
 */
180
function theme_cdm_descriptionElements($descriptionElements, $featureUuid){
181
	$outArray = array();
182
	$glue = '';
183
	$sortOutArray = false;
184
	$enclosingHtml = 'ul';
185
	$distributionElements = array();
186

    
187
	foreach($descriptionElements as $descriptionElement){
188
		
189
		if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
190
			if($descriptionElement->class == 'Distribution'){
191
				$distributionElements[]= $descriptionElement;
192
			} else if($descriptionElement->class == 'TextData'){
193
				$asListElement = false;
194
				$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
195
					
196
				if( !array_search($repr, $outArray)){
197
					$outArray[] = $repr;
198
					$glue = '<br/> ';
199
					$sortOutArray = true;
200
					$enclosingHtml = 'p';
201
				}
202
			}
203
		} else if($descriptionElement->class == 'TextData'){
204
			$asListElement = true;
205
			$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
206
		} else {
207
			$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
208
		}
209

    
210
	}
211

    
212
	$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
213
	
214
	
215
	// take the feature of the last $descriptionElement
216
	$feature = $descriptionElement->feature;
217
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
218
	$out .= '<div class="footnote_list">'. FootnoteManager::renderFootnoteList($featureUuid) . '</div>';
219
	return $out;
220
}
221

    
222
/**
223
 * 
224
 * @param unknown_type $descriptionElements
225
 * @return unknown_type
226
 */
227
function theme_cdm_descriptionElementDistribution($descriptionElements){
228

    
229
	$out = '';
230
	$separator = ', ';
231

    
232
	foreach($descriptionElements as $descriptionElement){
233
		//$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $descriptionElement->area->representation_L10n);
234
	  $footnoteKeyList = '';
235
		foreach($descriptionElement->sources as $source){
236
  		$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $source, 'cdm_DescriptionElementSource');
237
  		$footnoteKeyList .= theme('cdm_footnode_key', $footnoteKey) . ' ';
238
		}
239
    $out .= $descriptionElement->area->representation_L10n . $footnoteKeyList . $separator;
240
	}
241
	$out = substr($out, 0, strlen($out)-strlen($separator) );
242
	
243
	$taxonTrees =  cdm_ws_get(CDM_WS_TAXONOMY);
244
	foreach($taxonTrees as $taxonTree){
245
		if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
246
			$reference = $taxonTree-> reference;
247
			break;
248
		}
249
	}
250

    
251
//  $referenceCitation = l('<span class="reference">('.$reference->title.')</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
252
//	if($descriptions && strlen($descriptions) > 0 ){
253
//		$sourceRefs .= ' '.$referenceCitation;
254
//	}
255

    
256
	return $out;
257

    
258
}
259

    
260

    
261
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
262
  
263
    //ev. delegate to theme_cdm_ReferencedEntityBase
264
    $out = '';
265
    if($descriptionElementSource->citation){
266
      $datePublished = $descriptionElementSource->citation->datePublished;
267
      if (strlen($datePublished->start) >0){
268
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
269
      }
270
      $author_team_titlecache = $descriptionElementSource->citation->authorTeam->titleCache;
271
      if (strlen($year)>0){
272
        $reference = $author_team_titlecache.' '. $year;
273
      }else {
274
        $reference = $author_team_titlecache ;
275
      }
276
      
277
      if($doLink){
278
        $out = l('<span class="reference">'.$reference.'</span>'
279
          , path_to_reference($descriptionElementSource->citation->uuid)
280
          , array("class"=>"reference")
281
          , NULL, NULL, FALSE ,TRUE);
282
      } else {
283
       $out = $reference;
284
      }
285
      if($descriptionElementSource->citationMicroReference){
286
        $out .= ': '. $descriptionElementSource->citationMicroReference;
287
      }
288
    }
289
    return $out;
290
}
291

    
292

    
293

    
294
/**
295
 * TODO
296
 * Quick-and-dirty solution to show distribution service to exemplar groups
297
 *
298
 * @param unknown_type $featureTo
299
 * @return unknown
300
 */
301
function theme_cdm_descriptionElements_distribution($taxon){
302

    
303
	$fontStyles = array(0 => "plane", 1 => "italic");
304
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
305

    
306
	if(!server){
307
		return "<p>No geoservice specified</p>";
308
	}else{
309
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
310

    
311
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
312
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
313
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
314

    
315
		$query_string = ($display_width ? '&ms=' . $display_width: '')
316
		. ($bounding_box ? '&bbox=' .  $bounding_box : '')
317
		. ($labels_on ? '&labels=' .  $labels_on : '');
318

    
319
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
320
			// embed into openlayers viewer
321
			$server = 'http://edit.csic.es/v1/areas.php';
322
			$query_string .= '&img=false&legend=1&mlp=3';
323
			$map_tdwg_Uri = url($server. '?' .$map_data_parameters->String, $query_string);
324
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
325
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
326
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
327
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
328
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
329

    
330
			//#print($map_tdwg_Uri.'<br>');
331

    
332
			//$map_tdwg_Uri ='http://edit.csic.es/v1/areas3_ol.php?l=earth&ad=tdwg4:c:UGAOO,SAROO,NZSOO,SUDOO,SPAAN,BGMBE,SICSI,TANOO,GEROO,SPASP,KENOO,SICMA,CLCBI,YUGMA,GRCOO,ROMOO,NZNOO,CLCMA,YUGSL,CLCLA,ALGOO,SWIOO,CLCSA,MDROO,HUNOO,ETHOO,BGMLU,COROO,BALOO,POROO,BALOO|e:CZESK,GRBOO|g:AUTAU|b:LBSLB,TUEOO|d:IREIR,AUTLI,POLOO,IRENI|f:NETOO,YUGCR|a:TUEOO,BGMBE,LBSLB||tdwg3:c:BGM,MOR,SPA,SIC,ITA,MOR,SPA,FRA|a:YUG,AUT&as=a:8dd3c7,,1|b:fdb462,,1|c:4daf4a,,1|d:ffff33,,1|e:bebada,,1|f:ff7f00,,1|g:377eb8,,1&&ms=610&bbox=-180,-90,180,90';
333
			//$tdwg_sldFile = cdm_http_request($map_tdwg_Uri);
334

    
335
			// get the respone from the map service
336
			$responseObj = cdm_ws_get($map_tdwg_Uri, null, null, "GET", TRUE);
337
			$responseObj = $responseObj[0];
338

    
339
			// get the sld files from the response object
340
			if(isset($responseObj->layers)){
341
				if(isset($responseObj->legend)){
342
					//$splittedLegendSldUrl = explode("http://edit.csic.es/v1/sld/", $responseObj->legend);
343
					//$tdwg_sldLegend = $splittedLegendSldUrl[1];
344
					$sldLegend=$responseObj->legend;
345
					$legend_url  ="http://edit.csic.es/geoserver/wms/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
346
					$legend_url .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
347
					$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);
348
				}
349
				$layerSlds = $responseObj->layers;
350
				foreach($layerSlds as $layer){
351
					$tdwg_sldUris[$layer->tdwg] = "http://edit.csic.es/v1/sld/".$layer->sld;
352
					//#print($tdwg_sldUris[$layer->tdwg].'<br>');
353
				}
354
			}
355
			// get the bbox from the response object
356
			$zoomto_bbox = ($bounding_box ? $bounding_box : ($responseObj->bbox ? $responseObj->bbox :'-180, -90, 180, 90') );
357

    
358
			$add_tdwg1 = (isset($tdwg_sldUris['tdwg1']) ? "
359
          tdwg_1.params.SLD = '".$tdwg_sldUris['tdwg1']."';
360
          map.addLayers([tdwg_1]);" : '');
361
			$add_tdwg2 = (isset($tdwg_sldUris['tdwg2']) ? "
362
          tdwg_2.params.SLD = '".$tdwg_sldUris['tdwg2']."';
363
          map.addLayers([tdwg_2]);" : '');
364
			$add_tdwg3 = (isset($tdwg_sldUris['tdwg3']) ? "
365
          tdwg_3.params.SLD = '".$tdwg_sldUris['tdwg3']."';
366
          map.addLayers([tdwg_3]);" : '');
367
			$add_tdwg4 = (isset($tdwg_sldUris['tdwg4']) ? "
368
          tdwg_4.params.SLD = '".$tdwg_sldUris['tdwg4']."';
369
          map.addLayers([tdwg_4]);" : '');
370

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

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

    
495
			$out .= '<div class="distribution_map_legend">';
496
			foreach($legenddata as $term => $color){
497
			$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
498
			drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
499
			}
500
			$out .= '</div>';
501

    
502
			}
503
			*/
504
		return $out;
505
	}
506
}
Add picture from clipboard (Maximum size: 40 MB)