Project

General

Profile

Revision 806baeb2

ID806baeb29d488f433eb5d63b61fbe82c816f8650
Parent 23f32680
Child 57e2ea1f

Added by Andreas Kohlbecker almost 11 years ago

refactoring i.e. splitting the themes file

View differences:

.gitattributes
18 18
modules/cdm_dataportal/cdm_dataportal.css -text
19 19
modules/cdm_dataportal/cdm_dataportal.info -text
20 20
modules/cdm_dataportal/cdm_dataportal.module -text
21
modules/cdm_dataportal/cdm_dataportal.theme.php -text
22 21
modules/cdm_dataportal/cdm_dataportal_print.css -text
23 22
modules/cdm_dataportal/cdm_dataportal_screen.css -text
24 23
modules/cdm_dataportal/cdm_mediauri/LICENSE.txt -text
......
207 206
modules/cdm_dataportal/js/thickbox/cdm_thickbox.css -text
208 207
modules/cdm_dataportal/js/thickbox/thickbox.js -text
209 208
modules/cdm_dataportal/node_types.php -text
209
modules/cdm_dataportal/theme/cdm_dataportal.common.theme -text
210
modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme -text
211
modules/cdm_dataportal/theme/cdm_dataportal.media.theme -text
212
modules/cdm_dataportal/theme/cdm_dataportal.name.theme -text
213
modules/cdm_dataportal/theme/cdm_dataportal.occurrence.theme -text
214
modules/cdm_dataportal/theme/cdm_dataportal.page.theme -text
215
modules/cdm_dataportal/theme/cdm_dataportal.references.theme -text
216
modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme -text
210 217
modules/cdm_dataportal/translations/cdm_dataportal.pot.template -text
211 218
modules/expertsdb/LICENSE.txt -text
212 219
modules/expertsdb/README.txt -text
modules/cdm_dataportal/cdm_dataportal.module
6 6
 * cdm_dataportal
7 7
 *
8 8
 * Copyright (C) 2007 EDIT
9
 * European Distributed Institute of Taxonomy
9
 * European Distributed Institute of Taxonomy 
10 10
 * http://www.e-taxonomy.eu
11
 *
11
 * 
12
 * The contents of this file are subject to the Mozilla Public License Version 1.1
13
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
12 14
 */
13 15

  
14 16
require_once('node_types.php');
15
require_once('cdm_dataportal.theme.php');
17

  
18
require_once('theme/cdm_dataportal.common.theme');
19
require_once('theme/cdm_dataportal.descriptions.theme');
20
require_once('theme/cdm_dataportal.media.theme');
21
require_once('theme/cdm_dataportal.occurrence.theme');
22
require_once('theme/cdm_dataportal.page.theme');
23
require_once('theme/cdm_dataportal.taxon.theme');
24
require_once('theme/cdm_dataportal.name.theme');
25
require_once('theme/cdm_dataportal.references.theme');
26

  
16 27
require_once('classes/footnotemanager.php');
17 28
require_once('classes/footnote.php');
18 29

  
......
27 38
    "cdm_dataportal_show_thumbnail_captions" => 1,
28 39
    "cdm_dataportal_media_maxextend" => 120,
29 40
    "cdm_dataportal_media_cols" => 3,
30
    "cdm_dataportal_media_maxRows" => 1);
41
    "cdm_dataportal_media_maxRows" => 0);
31 42
define('CDM_DATAPORTAL_GALLERY_SETTINGS', serialize($gallery_settings));
32
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_FORM_NAME', "description_gallery");
33
define('CDM_DATAPORTAL_MEDIA_GALLERY_FORM_NAME', "media_gallery");
34
define('CDM_DATAPORTAL_SEARCH_GALLERY_FORM_NAME', "search_gallery");
43
define('CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME', "description_gallery");
44
define('CDM_DATAPORTAL_MEDIA_GALLERY_NAME', "media_gallery");
45
define('CDM_DATAPORTAL_SEARCH_GALLERY_NAME', "search_gallery");
46

  
47

  
48

  
49

  
50
function getGallerySettings($gallery_config_form_name){
51
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
52
  	return variable_get($gallery_config_form_name, $default_values);
53
}
35 54

  
36 55

  
37 56

  
......
761 780
    '#options' => $selectShowMedia,
762 781
    '#description'   => t('Select if a taxon should show only his media or also child media.')
763 782
    );
764
/*
765
    // --- SEARCH TAXA GALLERY ---- //
766
    $form['findtaxa'] = array(
767
    '#type' => 'fieldset',
768
    '#title' => t('Search Taxa'),
769
    '#collapsible' => TRUE,
770
    '#collapsed' => FALSE,
771
    );
772 783

  
773
    //variable_get('', 1);
774
    $form['findtaxa']['cdm_dataportal_findtaxa_show_taxon_thumbnails'] = array(
775
    '#type' => 'checkbox',
776
    '#title' => t('Show media thumbnails for accepted taxa'),
777
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1),
778
    '#description' => t('')
779
    );
780

  
781
    $form['findtaxa']['cdm_dataportal_findtaxa_show_synonym_thumbnails'] = array(
782
    '#type' => 'checkbox',
783
    '#title' => t('Show media thumbnails for synonyms'),
784
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0),
785
    '#description' => t('')
786
    );
787

  
788
    //   $showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
789
    $form['findtaxa']['cdm_dataportal_findtaxa_show_thumbnail_captions'] = array(
790
    '#type' => 'checkbox',
791
    '#title' => t('Show captions under thumbnails'),
792
    '#default_value' => variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1),
793
    '#description' => t('')
794
    );
795

  
796
    $form['findtaxa']['cdm_dataportal_findtaxa_media_maxextend'] = array(
797
    '#type' => 'textfield',
798
    '#title' => t('Maximum extend of Images'),
799
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxextend', 120),
800
    '#description' => t('')
801
    );
802

  
803
    $form['findtaxa']['cdm_dataportal_findtaxa_media_cols'] = array(
804
    '#type' => 'textfield',
805
    '#title' => t('Number of columns'),
806
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_cols', 3),
807
    '#description' => t('')
808
    );
809

  
810
    $form['findtaxa']['cdm_dataportal_findtaxa_media_maxRows'] = array(
811
    '#type' => 'textfield',
812
    '#title' => t('Maximum number of rows'),
813
    '#default_value' => variable_get('cdm_dataportal_findtaxa_media_maxRows', 1),
814
    '#description' => t('')
815
    );
816
*/
817 784
    // --- SEARCH TAXA GALLERY ---- //
818 785
    $collapsed = TRUE;
819
    $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_FORM_NAME;
786
    $form_name = CDM_DATAPORTAL_SEARCH_GALLERY_NAME;
820 787
    $form_tittle = 'Search Taxa';
821 788
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
822 789

  
823 790
    // --- FEATURE DESCRIPTION GALLERY ---- //
824
    $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_FORM_NAME;
791
    $form_name = CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME;
825 792
    $form_tittle = 'Description elements gallery';
826 793
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
827 794

  
828 795
    // --- MEDIA GALLERY ---- //
829
    $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_FORM_NAME;
796
    $form_name = CDM_DATAPORTAL_MEDIA_GALLERY_NAME;
830 797
    $form_tittle = 'Media gallery';
831 798
    $form[] = cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed);
832 799

  
......
845 812

  
846 813
	$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
847 814
	$gallery_settings = variable_get($form_name, $default_values);
848
	//variable_get('', 1);
815

  
849 816
	$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
850 817
    '#type' => 'checkbox',
851 818
    '#title' => t('Show media thumbnails for accepted taxa'),
......
872 839
    '#type' => 'textfield',
873 840
    '#title' => t('Maximum extend of Images'),
874 841
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
875
    '#description' => t('')
842
    '#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
876 843
	);
877 844

  
878 845
	$form[$form_name]['cdm_dataportal_media_cols'] = array(
......
886 853
    '#type' => 'textfield',
887 854
    '#title' => t('Maximum number of rows'),
888 855
    '#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
889
    '#description' => t('')
856
    '#description' => t('If you want an unlimited number of rows please set to 0')
890 857
	);
891 858

  
892 859
	return $form;
......
1669 1636
	//returned value
1670 1637
	return $metadata_caption;
1671 1638
}
1639

  
1640
/**
1641
 * This function collects all the media from a list of description elements
1642
 * and return them as an Array.
1643
 *
1644
 * @param $descriptionElementes The description elements
1645
 * @return Array The output with all the media
1646
 */
1647
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
1648
	//variables
1649
	$outArrayOfMedia = array(); //return value
1650
	//implementation
1651
	foreach($descriptionElements as $descriptionElement){
1652
		foreach($descriptionElement->media as $media){
1653
			if(isset($media)){
1654
			 $outArrayOfMedia[] = $media;
1655
			}
1656
	 }
1657
	}
1658
	return $outArrayOfMedia;
1659
}
1660

  
1661

  
modules/cdm_dataportal/cdm_dataportal.theme.php
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

  
10
function _add_js_thickbox(){
11
	// ---- jQuery thickbox:
12
	/*
13
	* bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
14
	* -> event is not triggered because of problems with compat-1.0.js'
15
	* see INSTALL.txt
16
	*
17
	*/
18
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
19
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
20
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
21
}
22

  
23
function _add_js_lightbox($galleryID){
24
	/*
25
	 * Important Notice:
26
	 * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
27
	 * for captions instead of the "title" attribute
28
	 */
29
	$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
30
	drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
31
	drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
32
	drupal_add_js ('$(document).ready(function() {
33
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
34
        fixedNavigation:  true,
35
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\', 
36
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',    
37
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',   
38
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',  
39
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
40
      });
41
    });
42
    ', 'inline');
43
}
44

  
45
function _add_js_footnotes(){
46
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
47
}
48

  
49

  
50
function _add_js_cluetip(){
51

  
52
	//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
53
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
54
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
55
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
56
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
57
	drupal_add_js ("$(document).ready(function(){
58
      $('.cluetip').css({color: '#0062C2'}).cluetip({
59
        splitTitle: '|',
60
        showTitle: true,
61
        activation: 'hover',
62
        sicky: true,
63
        arrows: true,
64
        dropShadow: false,
65
        cluetipClass: 'rounded'
66
      });
67
    });", 'inline');
68
}
69

  
70
function _add_js_ahah(){
71
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
72
}
73

  
74

  
75
/**
76
 * TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
77
 * NOT WORKING since fragments are not available to the server
78
 function fragment(){
79
 global $fragment;
80
 if(!$fragment){
81
 $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
82
 }
83
 return $fragment;
84
 }
85
 */
86

  
87
function uuid_anchor($uuid, $innerHTML){
88
	$highlite = $_REQUEST['highlite'] == $uuid;
89
	return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
90
}
91

  
92
/**
93
 * Enter description here...
94
 *
95
 * @param unknown_type $name
96
 * @param unknown_type $numOfNameTokens
97
 * @return unknown
98
 * @deprecated looks like this is not used anymore
99
 */
100
function tagNameParts($name, $numOfNameTokens){
101

  
102
	$out = '<span class="name">';
103

  
104
	$token = strtok($name, " \n\t");
105
	$i = 0;
106
	$noSpace = true;
107
	while($token != false){
108
		if($i == $numOfNameTokens){
109
			$out .= '</span> <span class="authors">';
110
			$noSpace = true;
111
		}
112
		$out .= ($noSpace?'':' ').$token;
113
		$noSpace = false;
114
		$token = strtok(" \n\t");
115
		$i++;
116
	}
117
	return $out.'</span>';
118
}
119

  
120
/**
121
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas
122
 * each item will provided with a class attribute which set to the key of the TaggedText item.
123
 *
124
 * @param array $taggedtxt
125
 * @param String $tag
126
 * @param String $glue the string by which the chained text tokens are concatenated together.
127
 *       Default is a blank character
128
 * @return String of HTML
129
 */
130
function theme_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
131
	$out = '';
132
	$i = 0;
133
	foreach($taggedtxt as $tt){
134
		if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
135
			$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
136
		}
137
	}
138
	return $out;
139
}
140

  
141
/**
142
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to display
143
 * as well as create or update annotations.
144
 *
145
 * TODO it should be configurable which objects can be annotated as this might differ in dataportals
146
 *
147
 */
148
function theme_cdm_annotation($cdmBase){
149
	if(!$cdmBase->uuid){
150
		return;
151
	}else{
152

  
153
		drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
154
		drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
155

  
156
		$annotatableUuid = $cdmBase->uuid;
157
		//FIXME annotations only available as property of e.g. taxon, name, ...
158
		$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($annotatableUuid));
159

  
160
		$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_content');
161

  
162
		$out = ' <span class="annotation">';
163
		$out .= '<span class="annotation_toggle" rel="'.$annotationProxyUrl.'">+</span>';
164
			
165

  
166
		$out .= '<div class="annotation_box"></div>';
167
		$out .= '</span>';
168

  
169
		return $out;
170

  
171
	}
172
}
173

  
174
function theme_cdm_annotation_content($AnnotationTO){
175

  
176
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
177
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
178

  
179
	$out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
180

  
181
	$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
182
	$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
183

  
184
	// TODO users have to be authenticated to the dataportal to be able to write annotations
185
	$out .= '
186
  			<div class="annotation_create">
187
  				<form action="'.$annotationProxyUrl.'" method="POST">
188
  					<textarea name="annotation"></textarea>
189
  					<input type="hidden" name="commentator" value="">
190
  					<input type="submit" value="'.t('Save annotation').'" />
191
  				</form>
192
 			</div>
193
	';
194

  
195
	return $out;
196
}
197

  
198
function theme_cdm_list_of_annotations($annotationElements){
199

  
200
	$out = '<ul class="annotation_list">';
201

  
202
	foreach ($annotationElements as $key => $row){
203
		$created[$key] = $row;
204
	}
205
	array_multisort($created, SORT_ASC, $annotationElements);
206

  
207
	foreach ($annotationElements as $annotation){
208
		$out .= '<li>' . $annotation->text . '</li>';
209
	}
210

  
211
	$out .= '</ul>';
212

  
213
	return $out;
214

  
215
}
216

  
217
function theme_cdm_media($descriptionElement, $mimeTypePreference){
218
	$out = "";
219

  
220
	_add_js_thickbox();
221

  
222
	$uuid = $descriptionElement->uuid;
223
	$feature = $descriptionElement->feature;
224
	$medias = $descriptionElement->media;
225

  
226
	foreach($medias as $media){
227
		$prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
228
		$mediaRepresentation = array_shift($prefRepresentations);
229
		if($mediaRepresentation) {
230

  
231
			$contentTypeDirectory = media_content_type_dir($mediaRepresentation);
232

  
233
			$out .= theme('cdm_media_mime_' . $contentTypeDirectory,  $mediaRepresentation, $feature);
234

  
235
			//			$attributes = array('class'=>'thickbox', 'rel'=>'descriptionElement-'.$uuid, 'title'=>$feature->term);
236
			//		    for($i = 0; $part = $mediaRepresentation->representationParts[$i]; $i++){
237
			//		    	if($i == 0){
238
			//		    	    $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$feature->term.'-media.png';
239
			//		    	    $media = '<img src="'.$image_url.'" height="14px" alt="'.$feature->term.'" />';
240
			//		    	    $out .= l($media, $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
241
			//		    	} else {
242
			//		    		$out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
243
			//		    	}
244
			//		  	}
245
		} else {
246
			// no media available, so display just the type term
247
			$out .=  $feature->representation_L10n;
248
		}
249
	}
250
	return $out;
251

  
252
}
253

  
254
function theme_cdm_mediaTypeTerm($feature){
255
	$icon_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$feature->representation_L10n.'-media.png';
256
	return '<img src="'.$icon_url.'" height="14px" alt="'.$feature->representation_L10n.'" />';
257
}
258

  
259
function theme_cdm_media_mime_application($mediaRepresentation, $feature){
260

  
261
	foreach($mediaRepresentation->parts as $part){
262
		$attributes = array('title'=> theme('cdm_feature_name', $feature->representation_L10n), 'target'=>'_blank');
263
		//$attributes = array('title'=>$feature->representation_L10n, 'target'=>'_blank');
264
		//$attributes = array('title'=>'original publication', 'target'=>'_blank');
265
		$out .= l(theme('cdm_mediaTypeTerm', $feature), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
266
	}
267
	return $out;
268
}
269

  
270
function theme_cdm_media_mime_image($mediaRepresentation, $feature){
271
	$out = '';
272
	//TODO thickbox is not used anymore -> delete ?
273
	$attributes = array('class'=>'thickbox', 'rel'=>'representation-'.$representation->uuid, 'title'=>$feature->representation_L10n);
274
	for($i = 0; $part = $representation->representationParts[$i]; $i++){
275
		if($i == 0){
276

  
277
			$out .= l(theme('cdm_mediaTypeTerm', $feature), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
278
		} else {
279
			$out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
280
		}
281
	}
282
	return $out;
283
}
284

  
285
function theme_cdm_media_mime_text($representation, $feature){
286

  
287
	foreach($representation->parts as $part){
288
		$attributes = array('title'=> theme('cdm_feature_name', $feature->representation_L10n), 'target'=>'_blank');
289
		//$attributes = array('title'=>t('original publication'), 'target'=>'_blank');
290
		$out .= l(theme('cdm_mediaTypeTerm', $feature), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
291
	}
292
	return $out;
293
}
294

  
295

  
296
function theme_cdm_media_caption($media, $elements = array('title', 'description', 'artist', 'location', 'rights'), $fileUri = null){
297

  
298
	$media_metadata = cdm_read_media_metadata($media);
299

  
300
	$out = '<dl class="media-caption">';
301
	//title
302
	if($media_metadata['title'] && (!$elements || array_search('title', $elements)!== false)){
303
		$out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
304
		//unset($media_metadata['title']);
305
	}
306
	//description
307
	if($media_metadata['description'] && (!$elements || array_search('description', $elements)!== false)){
308
		$out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $media_metadata['description'] . '</dd>';
309
		//unset($media_metadata['description']);
310
	}
311
	//artist
312
	if($media_metadata['artist'] && (!$elements || array_search('artist', $elements)!== false)){
313
		//$out .= '<span class = "artist">' . ($media_metadata['artist'] ? 'Artist: ' . $media_metadata['artist'] . '</span>' . '<br>' : '');
314
		$out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
315
	}
316
	//location
317
	if(!$elements || array_search('location', $elements)!== false){
318
		$location = '';
319
		$location .= $media_metadata['location']['sublocation'];
320
		if ($location && $media_metadata['location']['city']){
321
			$location .= ', ';
322
		}
323
		$location .= $media_metadata['location']['city'];
324
		if ($location && $media_metadata['location']['province']){
325
			$location .= ', ';
326
		}
327
		$location .= $media_metadata['location']['province'];
328
		if ($location && $media_metadata['location']['country']){
329
			$location .= ' (' . $media_metadata['location']['country'] . ')';
330
		} else {
331
			$location .= $media_metadata['location']['country'];
332
		}
333
		if ($location){
334
			$out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location  . '</dd>';
335
		}
336
	}
337
	//rights
338
	if(!$elements || array_search('rights', $elements)!== false){
339
		$rights = '';
340
		//copyrights
341
		$cnt = count($media_metadata['rights']['copyright']['agentNames']);
342
		if($cnt > 0){
343
			$rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
344
			for($i = 0; $i < $cnt; $i++){
345
				$rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
346
				if($i+1 < $cnt){
347
					$rights .= ' / ';
348
				}
349
			}
350
			$rights .= '</dd>';
351
		}
352
		//license
353
		$cnt = count($media_metadata['rights']['license']['agentNames']);
354
		if($cnt > 0){
355
			$rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
356
			for($i = 0; $i < $cnt; $i++){
357
				$rights .= $media_metadata['rights']['license']['agentNames'][$i];
358
				if ($i+1 < $cnt){
359
					$rights .= ' / ';
360
				}
361
			}
362
			$rights .= '</dd>';
363
		}
364
		if($rights){
365
			$out .=  $rights . '</dt>';
366
		}
367
	}
368
	//TODO add all other metadata elemenst generically
369
	$out .= '</dl>';
370
	//return value
371
	return $out;
372
}
373

  
374
/**
375
 */
376
function theme_cdm_taxon_list_thumbnails($taxon){
377

  
378
	$gallery_name = $taxon->uuid;
379

  
380
	$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 1);
381
	$prefMimeTypeRegex = 'image:.*';
382
	$prefMediaQuality = '*';
383
	//$cols = variable_get('cdm_dataportal_findtaxa_media_cols', 3);
384
	//$maxRows = variable_get('cdm_dataportal_findtaxa_media_maxRows', 1);
385
	//$maxExtend = variable_get('cdm_dataportal_findtaxa_media_maxextend', 120);
386

  
387
	if($showCaption){
388
		//$captionElements = array('title', '#uri'=>t('open Image'));
389
		$captionElements = array('title', 'rights');
390
	}
391

  
392
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
393
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
394
	if ($selectShowMedia == 0){
395
		$mediaList = cdm_ws_get(CDM_WS_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
396
	}else{
397
		$mediaList = cdm_ws_get(CDM_WS_TAXON_SUBTREE_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
398
	}
399
	//$mediaList = cdm_ws_get(CDM_WS_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false), $taxon ->rank, $taxon->uuid ));
400
	//$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,$maxExtend, $cols, $maxRows, $captionElements, 'LIGHTBOX', null, $galleryLinkUri);
401
	
402
	
403
	$out .= theme('cdm_media_gallery_wrapper', $mediaList, $gallery_name, CDM_DATAPORTAL_SEARCH_GALLERY_FORM_NAME);
404

  
405
	return $out;
406
}
407

  
408

  
409
function theme_cdm_media_gallery_wrapper($media_list, $gallery_name, $gallery_config_form_name){
410
  $caption_elements = array('title', 'rights');
411
  $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
412
  $gallery_settings = variable_get('description_gallery', $gallery_settings);
413
  
414
	return theme('cdm_media_gallerie', 
415
	             $media_list, 
416
	             $gallery_name, 
417
	             $gallery_settings['cdm_dataportal_media_maxextend'], 
418
	             $gallery_settings['cdm_dataportal_media_cols'], 
419
	             $gallery_settings['cdm_dataportal_media_maxRows'], 
420
	             $caption_elements);
421
}
422

  
423
/**
424
 * @param $mediaList an array of Media entities
425
 * @param $maxExtend
426
 * @param $cols
427
 * @param $maxRows
428
 * @param $captionElements an array possible values are like in the following example: array('title', 'description', 'file', 'filename'),
429
 *         to add a link to the caption: array('titlecache', '#uri'=>t('open Image'));
430
 * @param $mediaLinkType valid values:
431
 *      "NONE": do not link the images,
432
 *      "LIGHTBOX": open the link in a light box,
433
 *      "NORMAL": link to the image page or to the $alternativeMediaUri if it is defined
434
 * @param $alternativeMediaUri an array of alternative URIs to link the images wich will overwrite the URIs of the media parts.
435
 *     The order of URI in this array must correspond with the order of images in $mediaList
436
 * @param $galleryLinkUri an URI to link the the hint on more images to; if null no link is created
437
 * @return unknown_type
438
 */
439
function theme_cdm_media_gallerie($mediaList, $galleryName, $maxExtend = 150, $cols = 4, $maxRows = false, $captionElements = array('title'),
440
$mediaLinkType = 'LIGHTBOX', $alternativeMediaUri = null, $galleryLinkUri = null ){
441

  
442
	if(!is_array($captionElements)){
443
		$captionElements = array();
444
	}
445
	//TODO correctly handle multiple media representation parts
446
	$_SESSION['cdm']['last_gallery']= substr($_SERVER['REQUEST_URI'],strpos($_SERVER['REQUEST_URI'], "?q=")+3);
447
	// prevent from errors
448
	if(!isset($mediaList[0])){
449
		return;
450
	}
451

  
452
	$galleryID = "media_gallery_".$galleryName;
453

  
454
	// prepare media links
455
	$doLink = false;
456
	$linkAttributes = null;
457
	if($mediaLinkType != 'NONE'){
458
		$doLink = true;
459
	}
460
	if($mediaLinkType == 'LIGHTBOX'){
461
		$doLink = true;
462
		//_add_js_thickbox();
463
		//$linkAttributes = array("class"=>"thickbox", "rel"=>"media_gallerie".$galleryName);
464
		_add_js_lightbox($galleryID);
465
		$linkAttributes = array("class"=>"lightbox");
466
	}
467

  
468
	// render the media gallery grid
469
	$out = '<table id="'.$galleryID.'" class="media_gallery">';
470
	$out .= '<colgroup>';
471
	for($c = 0; $c < $cols; $c++){
472
		$out .= '<col width="'.(100 / $cols).'%">';
473
	}
474
	$out .= '</colgroup>';
475

  
476
	for($r = 0; ($r < $maxRows || !$maxRows) && count($mediaList) > 0; $r++){
477
		$captionParts = array();
478
		$out .= '<tr>';
479
		for($c = 0; $c < $cols; $c++){
480
			$media = array_shift($mediaList);
481
			if(isset($media->representations[0]->parts[0])){
482
				$contentTypeDirectory = media_content_type_dir($media->representations[0], 'image');
483
				$mediaIndex++;
484
				$mediaPartHtml = theme('cdm_media_gallerie_'.$contentTypeDirectory, $media->representations[0]->parts[0], $maxExtend, TRUE);
485

  
486
				// --- compose Media Link
487
				$mediaLinkUri = false;
488
				if($alternativeMediaUri){
489
					if(isset($alternativeMediaUri[$mediaIndex])){
490
						$mediaLinkUri = $alternativeMediaUri[$mediaIndex];
491
					}
492
					if(is_string($alternativeMediaUri)){
493
						$mediaLinkUri = $alternativeMediaUri;
494
					}
495
				} else {
496
					$mediaLinkUri = $media->representations[0]->parts[0]->uri;
497
				}
498

  
499
				// generate gallery caption
500
				_add_js_ahah();
501
				$content_url = cdm_compose_url(CDM_WS_MEDIA, $media->uuid);
502
				$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/cdm_media_caption/".join(',',$captionElements));
503
				$captionPartHtml = '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading" style="display: none;">Loading ....</span></div>';
504

  
505
				// generate & add caption to lightbox
506
				$lightBoxCaptionElements = null;
507
				$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/cdm_media_caption"); //.($lightBoxCaptionElements?'/'.join	(',',$lightBoxCaptionElements):''));
508
				$linkAttributes['alt'] = '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading" style="display: none;">Loading ....</span></div>';
509

  
510
				if(isset($captionElements['#uri'])){
511
					$captionPartHtml .= '<div>'.l($captionElements['#uri'], path_to_media($media->uuid), null, null, null, FALSE, TRUE).'</div>';
512
				}
513
				$captionParts[] = $captionPartHtml;
514

  
515
				// --- surround imagePart with link
516
				if($doLink){
517
					$mediaPartHtml = l($mediaPartHtml, $mediaLinkUri, $linkAttributes, null, null, FALSE, TRUE);
518
				}
519

  
520
			} else {
521
				$mediaPartHtml = '';
522
				$captionParts[] = '';
523
			}
524
			$out .= '<td>'.$mediaPartHtml.'</td>';
525
		}
526
		$out .= '</tr>'; // end of media parts
527
		if(isset($captionElements[0])){
528
			$out .= '<tr>';
529
			// add caption row
530
			foreach($captionParts as $captionPartHtml){
531
				$out .= '<td>'.$captionPartHtml.'</td>';
532
			}
533
			$out .= '</tr>';
534
		}
535
	}
536
	if($galleryLinkUri){
537
		if(count($mediaList) > 0){
538
			$moreHtml = count($mediaList).' '.t('more in gallery');
539
		} else {
540
			$moreHtml = t('open gallery');
541
		}
542
		$moreHtml = l($moreHtml, $galleryLinkUri);
543
		$out .= '<tr><td colspan="'.$cols.'">'.$moreHtml.'</td></tr>';
544
	}
545
	$out .= '</table>';
546
	return $out;
547
}
548

  
549
function theme_cdm_media_gallerie_image($mediaRepresentationPart, $maxExtend, $addPassePartout = FALSE, $attributes = null){
550
	//TODO merge with theme_cdm_media_mime_image?
551

  
552
	if(isset($mediaRepresentationPart)){
553
			
554
		$h = $mediaRepresentationPart->height;
555
		$w = $mediaRepresentationPart->width;
556
		if($w == 0 || $h == 0){
557
			$image_uri = str_replace(' ','%20',$mediaRepresentationPart->uri); //take url and replace spaces
558
			$imageDimensions = getimagesize_remote($image_uri);
559
			if(!$imageDimensions){
560
				return '<div>'.t('Image unavailable, uri:').$mediaRepresentationPart->uri.'</div>';
561
			}
562
			$w = $imageDimensions[0];
563
			$h = $imageDimensions[1];
564
		}
565
		$margins = '0 0 0 0';
566
		$ratio = $w / $h;
567
		if($ratio > 1){
568
			$displayHeight = round($maxExtend / $ratio);
569
			$displayWidth = $maxExtend;
570
			$m = round(($maxExtend - $displayHeight) / 2);
571
			$margins = 'margin:'.$m.'px 0 '.$m.'px 0;';
572
		} else {
573
			$displayHeight = $maxExtend;
574
			$displayWidth = round($maxExtend * $ratio);
575
			$m = round(($maxExtend - $displayWidth) / 2);
576
			$margins = 'margin:0 '.$m.'px 0 '.$m.'px;';
577
		}
578

  
579
		// turn attributes array into string
580
		$attrStr = ' ';
581
		//$attributes['title'] = 'h:'.$h.', w:'.$w.',ratio:'.$ratio;
582
		if(is_array($attributes)){
583
			foreach($attributes as $name=>$value){
584
				$attrStr .= $name.'="'.$value.'" ';
585
			}
586
		}
587

  
588
		//return  '<img src="'."http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/photos/Lapsana_communis_A_01.jpg".'" width="'.$maxExtend.'" height="'.$maxExtend.'" />';
589
		if($addPassePartout){
590
			$out .= '<div class="image-passe-partout" style="width:'.$maxExtend.'px; height:'.$maxExtend.'px;">';
591
		} else {
592
			// do not add margins if no pass partout is shown
593
			$margins = '';
594
		}
595
		$out .= '<img src="'.$mediaRepresentationPart->uri.'" width="'.$displayWidth.'" height="'.$displayHeight.'" style="'.$margins.'"'.$attrStr.' />';
596

  
597
		if($addPassePartout){
598
			$out .= '</div>';
599
		}
600
		return $out;
601
	}
602

  
603
}
604

  
605
function theme_cdm_openlayers_image($mediaRepresentationPart, $maxExtend){
606

  
607
	// see http://trac.openlayers.org/wiki/UsingCustomTiles#UsingTilesWithoutaProjection
608
	// and http://trac.openlayers.org/wiki/SettingZoomLevels
609
	
610
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
611
      
612
  //TODO megre code below with code from theme_cdm_media_gallerie_image
613
	//var_dump("MEDIA URI: " . $mediaRepresentationPart->uri);
614
	//TODO merge code below with code from theme_cdm_media_gallerie_image
615
	$w = $mediaRepresentationPart->width;
616
	$h = $mediaRepresentationPart->height;
617

  
618
	if($w == 0 || $h == 0){
619
		$image_uri = str_replace(' ','%20',$mediaRepresentationPart->uri); //take url and replace spaces
620
		$imageDimensions = getimagesize_remote($image_uri);
621
		if(!$imageDimensions){
622
			return '<div>'.t('Image unavailable, uri:').$mediaRepresentationPart->uri.'</div>';
623
		}
624
		$w = $imageDimensions[0];
625
		$h = $imageDimensions[1];
626
	}
627

  
628
	// calculate  maxResolution (default is 360 deg / 256 px) and the bounds
629
	if($w > $h){
630
		$lat = 90;
631
		$lon = 90 * ($h / $w);
632
		$maxRes = $w / $maxExtend;
633
	} else {
634
		$lat = 90 * ($w / $h);
635
		$lon = 90;
636
		$maxRes =  $h / $maxExtend ;
637
	}
638

  
639
	$maxRes *= 1;
640
	drupal_add_js('
641
 var map;
642

  
643
 var imageLayerOptions={
644
     maxResolution: '.$maxRes.',
645
     maxExtent: new OpenLayers.Bounds(0, 0, '.$w.', '.$h.')
646
  };
647
  var mapOptions={
648
      controls: 
649
       [ 
650
         new OpenLayers.Control.PanZoom(),
651
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
652
       ],
653
     restrictedExtent:  new OpenLayers.Bounds(0, 0, '.$w.', '.$h.')
654
  };
655
 
656
 var graphic = new OpenLayers.Layer.Image(
657
          \'Image Title\',
658
          \''.$mediaRepresentationPart->uri.'\',
659
          new OpenLayers.Bounds(0, 0, '.$w.', '.$h.'),
660
          new OpenLayers.Size('.$w.', '.$h.'),
661
          imageLayerOptions
662
          );
663
  
664
 function init() {
665
   map = new OpenLayers.Map(\'openlayers_image\', mapOptions);
666
   map.addLayers([graphic]);
667
   map.setCenter(new OpenLayers.LonLat(0, 0), 1);
668
   map.zoomToMaxExtent();
669
 }
670
 
671
$(document).ready(function(){
672
  init();
673

  
674
});'
675
, 'inline');
676
$out = '<div id="openlayers_image" class="image_viewer" style="width: '.$maxExtend.'px; height:'.($maxExtend).'px"></div>';
677
return $out;
678

  
679
}
680

  
681
function theme_cdm_media_page($media, $mediarepresentation_uuid = false, $partId = false){
682
	$out = '';
683
	// determine which reprresentation and which part to show
684
	$representationIdx = 0;
685
	if($mediarepresentation_uuid){
686
		$i = 0;
687
		foreach($media->representations as $representation) {
688
			if($representation->uuid == $mediarepresentation_uuid){
689
				$representationIdx = $i;
690
			}
691
			$i++;
692
		}
693
	} else {
694
		$mediarepresentation_uuid = $media->representations[0]->uuid;
695
	}
696

  
697
	$partIdx  = 0;
698
	if(!is_numeric($partId)){
699
		// assuming it is an uuid
700
		$i = 0;
701
		foreach($media->representations[$representationIdx]->parts as $part) {
702
			if($part->uuid == $partId){
703
				$partIdx = $i;
704
			}
705
			$i++;
706
		}
707
	} else {
708
		// assuming it is an index
709
		$partIdx = $partId;
710
	}
711

  
712
	$media_metadata = cdm_read_media_metadata($media);
713
	//$title = $media->titleCache;
714
	$title = $media_metadata['title'];
715

  
716
	$imageMaxExtend = variable_get('image-page-maxextend', 400);
717

  
718
	if(!$title){
719
		$title = 'Media### '.$media->uuid.'';
720
	}
721

  
722
	drupal_set_title($title);
723

  
724

  
725
	$out .= '<div class="media">';
726

  
727
	//$out .= '<div class="viewer">';
728
	$out .= theme(cdm_back_to_image_gallery_button);
729
	$out .= '<div class="viewer">';
730
	//$out .= theme('cdm_media_gallerie_image', $representation->parts[$partIdx], $imageMaxExtend);
731
	$out .= theme('cdm_openlayers_image', $media->representations[$representationIdx]->parts[$partIdx], $imageMaxExtend);
732
	$out .= '</div>';
733

  
734
	// general media metadata
735
	//$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
736
	//vardump("PRINTING MEDIA METADATA");
737
	//vardump($media_metadata);
738
	//vardump("PRINTING MEDIA");
739
	//vardump($media);
740
	$metadataToPrint = theme('cdm_media_caption', $media);
741
	$out .= $metadataToPrint;
742

  
743

  
744
	//tabs for the different representations
745
	//ul.secondary
746
	$out .= '<ul class="primary">';
747
	foreach($media->representations as $representation){
748
		$out .= '<li>'.l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)).'</li>';
749
	}
750
	$out .= '</ul>';
751

  
752
	// representation(-part) specific metadata
753
	$thumbnailMaxExtend = 100;
754
	$out .= '<table>';
755
	//$out .= '<tr><th colspan="3">'.t('MimeType').': '.$media->representations[$representationIdx]->mimeType.'</th></tr>';
756
	$i = 0;
757
	foreach($media->representations[$representationIdx]->parts as $part){
758
		$out .= '<tr><th>'.t('Part').' '.($i + 1).'</th><td>';
759
		switch($part->class){
760
			case 'ImageFile': $out .= $part->width.' x '.$part->height.' - '.$part->size.'k'; break;
761
			case 'AudioFile':
762
			case 'MovieFile': $out .= t('Duration').': '.$part->duration.'s - '.$part->size.'k'; break;
763
			default: $out .= $part->size.'k';
764
		}
765
		$out .= '</td><td><a href="'.url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)).'">'.theme('cdm_media_gallerie_image', $part, $thumbnailMaxExtend, true);'</a></td><tr>';
766
		$i++;
767
	}
768
	$out .= '</table>';
769
	$out .= '</div>';
770

  
771
	return $out;
772
}
773

  
774
/**
775
 * TODO
776
 * Quick-and-dirty solution to show distribution service to exemplar groups
777
 *
778
 * @param unknown_type $featureTo
779
 * @return unknown
780
 */
781
function theme_cdm_descriptionElements_distribution($taxon){
782

  
783
	$fontStyles = array(0 => "plane", 1 => "italic");
784
	$server = variable_get('cdm_dataportal_geoservice_access_point', false);
785

  
786
	if(!server){
787
		return "<p>No geoservice specified</p>";
788
	}else{
789
		$map_data_parameters = cdm_ws_get(CDM_WS_GEOSERVICE_DISTRIBUTIONMAP, $taxon->uuid);
790

  
791
		$display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
792
		$bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
793
		$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
794

  
795
		$query_string = ($display_width ? '&ms=' . $display_width: '')
796
		. ($bounding_box ? '&bbox=' .  $bounding_box : '')
797
		. ($labels_on ? '&labels=' .  $labels_on : '');
798

  
799
		if(variable_get('cdm_dataportal_map_openlayers', 1)){
800
			// embed into openlayers viewer
801
			$server = 'http://edit.csic.es/v1/areas.php';
802
			$query_string .= '&img=false&legend=1&mlp=3';
803
			$map_tdwg_Uri = url($server. '?' .$map_data_parameters->String, $query_string);
804
			$legend_url_font_size = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
805
			$legend_url_font_style = variable_get('cdm_dataportal_geoservice_legend_font_style', 1);
806
			$legend_url_font_style = $fontStyles[$legend_url_font_style];
807
			$legend_url_icon_width  = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
808
			$legend_url_icon_height = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
809

  
810
			//#print($map_tdwg_Uri.'<br>');
811

  
812
			//$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';
813
			//$tdwg_sldFile = cdm_http_request($map_tdwg_Uri);
814

  
815
			// get the respone from the map service
816
			$responseObj = cdm_ws_get($map_tdwg_Uri, null, null, "GET", TRUE);
817
			$responseObj = $responseObj[0];
818

  
819
			// get the sld files from the response object
820
			if(isset($responseObj->layers)){
821
				if(isset($responseObj->legend)){
822
					//$splittedLegendSldUrl = explode("http://edit.csic.es/v1/sld/", $responseObj->legend);
823
					//$tdwg_sldLegend = $splittedLegendSldUrl[1];
824
					$sldLegend=$responseObj->legend;
825
					$legend_url  ="http://edit.csic.es/geoserver/wms/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1&format=image".urlencode('/')."png&TRANSPARENT=TRUE";
826
					$legend_url .= "&WIDTH=".$legend_url_icon_width."&HEIGHT=".$legend_url_icon_height."&";
827
					$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);
828
				}
829
				$layerSlds = $responseObj->layers;
830
				foreach($layerSlds as $layer){
831
					$tdwg_sldUris[$layer->tdwg] = "http://edit.csic.es/v1/sld/".$layer->sld;
832
					//#print($tdwg_sldUris[$layer->tdwg].'<br>');
833
				}
834
			}
835
			// get the bbox from the response object
836
			$zoomto_bbox = ($bounding_box ? $bounding_box : ($responseObj->bbox ? $responseObj->bbox :'-180, -90, 180, 90') );
837

  
838
			$add_tdwg1 = (isset($tdwg_sldUris['tdwg1']) ? "
839
          tdwg_1.params.SLD = '".$tdwg_sldUris['tdwg1']."';
840
          map.addLayers([tdwg_1]);" : '');
841
			$add_tdwg2 = (isset($tdwg_sldUris['tdwg2']) ? "
842
          tdwg_2.params.SLD = '".$tdwg_sldUris['tdwg2']."';
843
          map.addLayers([tdwg_2]);" : '');
844
			$add_tdwg3 = (isset($tdwg_sldUris['tdwg3']) ? "
845
          tdwg_3.params.SLD = '".$tdwg_sldUris['tdwg3']."';
846
          map.addLayers([tdwg_3]);" : '');
847
			$add_tdwg4 = (isset($tdwg_sldUris['tdwg4']) ? "
848
          tdwg_4.params.SLD = '".$tdwg_sldUris['tdwg4']."';
849
          map.addLayers([tdwg_4]);" : '');
850

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

  
854
			/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
855
			 * OpenLayers.js must be loaded BEFORE jQuery.
856
			 * If jQuery loaded before $.something will fail in IE8.
857
			 * Therefore we add OpenLayers.js it in the page.tpl.php
858
			 * -----------------------------------------------------
859
			 * Andreas Kohlbecker [Feb 25th 2010]:
860
			 * This problems seems to be solved somehow (a bugfix in IE8?)
861
			 * so I am removing this "hack" by uncommenting the line below
862
			 */
863
			drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
864
			drupal_add_js('
865
 var map;
866
 
867
 var layerOptions = {
868
     maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
869
     isBaseLayer: false,
870
     displayInLayerSwitcher: false
871
  };
872
 
873
 var tdwg_1 = new OpenLayers.Layer.WMS.Untiled( 
874
    "tdwg level 1", 
875
    "http://edit.csic.es/geoserver/wms",
876
    {layers:"topp:tdwg_level_1",transparent:"true", format:"image/png"},
877
    layerOptions
878
  );
879
  
880
 var tdwg_2 = new OpenLayers.Layer.WMS.Untiled( 
881
    "tdwg level 2", 
882
    "http://edit.csic.es/geoserver/wms",
883
    {layers:"topp:tdwg_level_2",transparent:"true", format:"image/png"},
884
    layerOptions
885
  );
886
  
887
 var tdwg_3 = new OpenLayers.Layer.WMS.Untiled( 
888
    "tdwg level 3", 
889
    "http://edit.csic.es/geoserver/wms",
890
    {layers:"topp:tdwg_level_3", transparent:"true", format:"image/png"},
891
    layerOptions
892
  );
893
  
894
  var tdwg_4 = new OpenLayers.Layer.WMS.Untiled( 
895
    "tdwg level 4", 
896
    "http://edit.csic.es/geoserver/wms",
897
    {layers:"topp:tdwg_level_4",transparent:"true", format:"image/png"},
898
    layerOptions
899
  );
900
  
901
 // make baselayer
902
 layerOptions[\'isBaseLayer\'] = true; 
903
 
904
 var ol_wms = new OpenLayers.Layer.WMS( 
905
    "OpenLayers WMS",
906
    "http://labs.metacarta.com/wms/vmap0",
907
    {layers: \'basic\'}, 
908
    layerOptions
909
  );
910
  
911
  
912
  // ------------------------------
913
  
914
  
915
 function init() {
916
 
917
   var mapOptions={
918
     controls: 
919
       [ 
920
         new OpenLayers.Control.PanZoom(),
921
         new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL})
922
       ],
923
       maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
924
       maxResolution: '.(360 / $display_width).',
925
       restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
926
       projection: new OpenLayers.Projection("EPSG:4326")
927
    };
928
   
929
   map = new OpenLayers.Map(\'openlayers_map\', mapOptions);
930
   map.addLayers([ol_wms]);
931
   '.$add_tdwg1.'
932
   '.$add_tdwg2.'
933
   '.$add_tdwg3.'
934
   '.$add_tdwg4.'
935
   map.zoomToExtent(new OpenLayers.Bounds('.$zoomto_bbox.'), false);
936
 }
937
 
938
$(document).ready(function(){
939
  init();
940
  $(\'#openlayers_legend\').css(\'top\', -$(\'#openlayers_map\').height());
941
  $(\'#openlayers_legend\').css(\'left\', $(\'#openlayers_map\').width()-100);
942
});'
943
, 'inline');
944
// showing openlayers
945
$out = '<div id="openlayers">';
946
$out .= '<div id="openlayers_map" class="smallmap" style="width: '.$display_width.'px; height:'.($display_width / 2).'px"></div>';
947
// showing lengeds
948
if (variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
949
	$out .= '<div id="openlayers_legend"><img id="legend" src="'.$legend_url.'"></div>';
950
}
951
// showing map caption
952
$out .= '<div class="distribution_map_caption">' . variable_get('cdm_dataportal_geoservice_map_caption', '') . '</div>' . '<br>';
953
$out .= '</div>';
954
 
955
		} else {
956
			// simple image
957
			$mapStaticCaption = '&mc_s=Georgia,15,blue&mc=' . variable_get('cdm_dataportal_geoservice_map_caption', '');
958
			$query_string .= '&img=true&legend=1&mlp=3' . $mapStaticCaption . '&recalculate=false';
959
			$mapUri = url($server. '?' .$map_data_parameters->String, $query_string);
960
			$out .= '<img class="distribution_map" src="' . $mapUri . '" alt="Distribution Map" />';
961
		}
962
		/*
963
		 // add a simple legend
964
		 if(variable_get('cdm_dataportal_geoservice_legend_on', TRUE)){
965
			$legenddata = array(
966
			'native' => "4daf4a",
967
			'native_doubtfully_native' => "377eb8",
968
			'cultivated' => "984ea3",
969
			'introduced' => "ff7f00",
970
			'introduced adventitious' => "ffff33",
971
			'introduced cultivated' => "a65628",
972
			'introduced naturalized' => "f781bf"
973
			);
974

  
975
			$out .= '<div class="distribution_map_legend">';
976
			foreach($legenddata as $term => $color){
977
			$out .= '<img style="width: 3em; height: 1em; background-color: #'.$color.'" src="'.
978
			drupal_get_path('module', 'cdm_dataportal').'/images/clear.gif" />'.t($term).' ';
979
			}
980
			$out .= '</div>';
981

  
982
			}
983
			*/
984
		return $out;
985
	}
986
}
987

  
988
function theme_cdm_taxonName($taxonName, $nameLink = NULL, $refenceLink = NULL, $renderPath = null){
989

  
990

  
991

  
992
	$renderTemplate = get_nameRenderTemplate($renderPath, $nameLink, $refenceLink);
993

  
994
	$partDefinition = get_partDefinition($taxonName->class);
995

  
996
	// apply defintions to template
997
	foreach($renderTemplate as $part=>$uri){
998
		if(isset($partDefinition[$part])){
999
			$renderTemplate[$part] = $partDefinition[$part];
1000
		}
1001
		if(is_array($uri)){
1002
			$renderTemplate[$part]['#uri'] = $uri['#uri'];
1003
		}
1004
	}
1005

  
1006
	$firstEntryIsValidNamePart = is_array($taxonName->taggedName)
1007
	&& is_string($taxonName->taggedName[1]->text)
1008
	&& $taxonName->taggedName[1]->text != ''
1009
	&& $taxonName->taggedName[1]->type = 'name';
1010
	// got to use second entry as first one, see ToDo comment below ...
1011
	if($firstEntryIsValidNamePart){
1012

  
1013
		$taggedName = $taxonName->taggedName;
1014
		//TODO  due to a bug in the cdmlib the taggedName alway has a lst empty element, we will remove it:
1015
		array_pop($taggedName);
1016

  
1017
		$lastAuthorElementString = false;
1018
		$hasNamePart_with_Authors = isset($renderTemplate['namePart']) && isset($renderTemplate['namePart']['authors']);
1019
		$hasNameAuthorPart_with_Authors = isset($renderTemplate['nameAuthorPart']) && isset($renderTemplate['nameAuthorPart']['authors']);
1020

  
1021
		if(!($hasNamePart_with_Authors || $hasNameAuthorPart_with_Authors)){
1022
			//      // find author and split off from name
1023
			//      // TODO expecting to find the author as the last element
1024
			//      if($taggedName[count($taggedName)- 1]->type == 'authors'){
1025
			//        $authorTeam = $taggedName[count($taggedName)- 1]->text;
1026
			//        unset($taggedName[count($taggedName)- 1]);
1027
			//      }
1028

  
1029
			// remove all authors
1030
			$taggedNameNew = array();
1031
			foreach($taggedName as $element){
1032
				if($element->type != 'authors'){
1033
					$taggedNameNew[] = $element;
1034
				} else {
1035
					$lastAuthorElementString = $element->text;
1036
				}
1037
			}
1038
			$taggedName = $taggedNameNew;
1039

  
1040
		}
1041
		$name = '<span class="'.$taxonName->class.'">'.theme('cdm_taggedtext2html', $taggedName).'</span>';
1042
	} else {
1043
		$name = '<span class="'.$taxonName->class.'_titleCache">'.$taxonName->titleCache.'</span>';
1044
	}
1045

  
1046
	// fill name into $renderTemplate
1047
	array_setr('name', $name, $renderTemplate);
1048

  
1049
	//  // fill with authorTeam
1050
	//  if($authorTeam){
1051
	//    $authorTeamHtml = ' <span class="authorTeam">'.$authorTeam.'</span>';
1052
	//    array_setr('authorTeam', $authorTeamHtml, $renderTemplate);
1053
	//  }
1054

  
1055

  
1056
	// fill with reference
1057
	if(isset($renderTemplate['referencePart'])){
1058

  
1059
		// [Eckhard]:"Komma nach dem Taxonnamen ist grunsätzlich falsch,
1060
		// Komma nach dem Autornamen ist überall dort falsch, wo ein "in" folgt."
1061
		if(isset($renderTemplate['referencePart']['reference']) && $taxonName->nomenclaturalReference){
1062
			$microreference = null;
1063
			if(isset($renderTemplate['referencePart']['microreference'])){
1064
				$microreference = $taxonName->nomenclaturalMicroReference;
1065
			}
1066
			$citation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION, array($taxonName->nomenclaturalReference->uuid, $microreference));
1067
			$citation = $citation->String;
1068
			// find preceding element of the refrence
1069
			$precedingKey = get_preceding_contentElementKey('reference', $renderTemplate);
1070
			if(str_beginsWith($citation, ", in")){
1071
				$citation = substr($citation, 2);
1072
				$separator = ' ';
1073
			} else if(!str_beginsWith($citation, "in") && $precedingKey == 'authors'){
1074
				$separator = ', ';
1075
			} else {
1076
				$separator = ' ';
1077
			}
1078

  
1079
			$referenceArray['#separator'] = $separator;
1080
			$referenceArray['#html'] = '<span class="reference">'.$citation.'</span>';
1081
			array_setr('reference', $referenceArray, $renderTemplate);
1082
		}
1083

  
1084
		// if authors have been removed from the name part the last named authorteam
1085
		// should be added to the reference citation, otherwise, keep the separator
1086
		// out of the reference
1087
		if(isset($renderTemplate['referencePart']['authors']) && $lastAuthorElementString){
1088
			// if the nomenclaturalReference cintation is not included in the reference part but diplay of the microreference
1089
			// is whanted append the microreference to the authorTeam
1090
			if(!isset($renderTemplate['referencePart']['reference']) && isset($renderTemplate['referencePart']['microreference'])){
1091
				$separator = ": ";
1092
				$citation = $taxonName->nomenclaturalMicroReference;
1093
			}
1094
			$referenceArray['#html'] = ' <span class="reference">'.$lastAuthorElementString.$separator.$citation.'</span>';
1095
			array_setr('authors', $referenceArray, $renderTemplate);
1096
		}
1097

  
1098
	}
1099

  
1100
	// fill with status
1101
	if(array_setr('status', true, $renderTemplate)){
1102
		if(isset($taxon->name->status[0])){
1103
			foreach($taxon->name->status as $status){
1104
				$statusHtml .= ', '.$status->type->representation_L10n;
1105
			}
1106
		}
1107
		array_setr('status', ' <span class="nomenclatural_status">'.$statusHtml.'</span>', $renderTemplate);
1108
	}
1109

  
1110
	// fill with protologues etc...
1111
	if(array_setr('description', true, $renderTemplate)){
1112
		$descriptions = cdm_ws_get(CDM_WS_NAME_DESCRIPTIONS, $taxonName->uuid);
1113
		foreach($descriptions as $description){
1114
			if(!empty($description)){
1115
				foreach($description->elements as $description_element){
1116
					$descriptionHtml .= theme("cdm_media", $description_element, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
1117
				}
1118
			}
1119
		}
1120
		array_setr('description', $descriptionHtml, $renderTemplate);
1121
	}
1122

  
1123
	// render
1124
	$out = '<span ref="/name/'.$taxonName->uuid.'">';
1125
	foreach($renderTemplate as $partName=>$part){
1126
		$separator = '';
1127
		$partHtml = '';
1128
		$uri = false;
1129
		if(!is_array($part)){
1130
			continue;
1131
		}
1132
		if(isset($part['#uri']) && is_string($part['#uri'])){
1133
			$uri = $part['#uri'];
1134
			unset($part['#uri']);
1135
		}
1136
		foreach($part as $key=>$content){
1137
			$html = '';
1138
			if(is_array($content)){
1139
				$html = $content['#html'];
1140
				$separator = $content['#separator'];
1141
			} else if(is_string($content)){
1142
				$html = $content;
1143
			}
1144
			$partHtml .= '<span class="'.$key.'">'.$html.'</span>';
1145
		}
1146
		if($uri){
1147
			$out .= $separator.'<a href="'.$uri.'" class="'.$partName.'">'.$partHtml.'</a>';
1148
		} else {
1149
			$out .= $separator.$partHtml;
1150
		}
1151
	}
1152

  
1153
	return $out.'</span>';
1154
}
1155

  
1156
/**
1157
 * Recursively searches the array for the $key and sets the given value
1158
 * @param $key
1159
 * @param $value
1160
 * @param $array
1161
 * @return true if the key has been found
1162
 */
1163
function &array_setr($key, $value, array &$array){
1164
	foreach($array as $k=>&$v){
1165
		if($key == $k){
1166
			$v = $value;
1167
			return $array;
1168
		} else if(is_array($v)){
1169
			$innerArray = array_setr($key, $value, $v);
1170
			if($innerArray){
1171
				return $array;
1172
			}
1173
		}
1174
	}
1175
	return null;
1176
}
1177

  
1178
function &get_preceding_contentElement($contentElementKey, array &$renderTemplate){
1179
	$precedingElement = null;
1180
	foreach($renderTemplate as &$part){
1181
		foreach($part as $key=>&$element){
1182
			if($key == $contentElementKey){
1183
				return $precedingElement;
1184
			}
1185
			$precedingElement = $element;
1186
		}
1187
	}
1188
	return null;
1189
}
1190

  
1191
function &get_preceding_contentElementKey($contentElementKey, array &$renderTemplate){
1192
	$precedingKey = null;
1193
	foreach($renderTemplate as &$part){
1194
		foreach($part as $key=>&$element){
1195
			if($key == $contentElementKey){
1196
				return $precedingKey;
1197
			}
1198
			if(!str_beginsWith($key, '#')){
1199
				$precedingKey = $key;
1200
			}
1201
		}
1202
	}
1203
	return null;
1204
}
1205

  
1206

  
1207
function theme_cdm_related_taxon($taxon, $reltype_uuid = '', $displayNomRef = true){
1208

  
1209
	$relsign = '';
1210
	$name_prefix = '';
1211
	$name_postfix = '';
1212
	switch ($reltype_uuid){
1213
		case UUID_HETEROTYPIC_SYNONYM_OF:
1214
		case UUID_SYNONYM_OF:
1215
			$relsign = '=';
1216
			break;
1217
		case UUID_HOMOTYPIC_SYNONYM_OF:
1218
			$relsign = '≡';
1219
			break;
1220
		case UUID_MISAPPLIED_NAME_FOR:
1221
		case UUID_INVALID_DESIGNATION_FOR:
1222
			$relsign = '&ndash;'; // &ndash; &mdash; &minus;
1223
			$name_prefix = '"';
1224
			$name_postfix = '"';
1225
			break;
1226
		default :
1227
			$relsign = '&ndash;';
1228
	}
1229

  
1230
	$renderPath = 'related_taxon';
1231

  
1232
	//$taxonUri = url(path_to_taxon($taxon->uuid));
1233
	if($taxon->name->nomenclaturalReference){
1234
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
1235
	}
1236
	$nameHtml = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, $renderPath);
1237

  
1238
	$out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix . $nameHtml . $name_postfix;
1239
	
1240
	return uuid_anchor($taxon->uuid, $out);
1241

  
1242
}
1243

  
1244
/**
1245
 * will theme form elements of type 'select_secuuid'
1246
 * see $form['cdm_dataportal']['secuuid_widget']
1247
 * @param FormElement $element
1248
 */
1249
function theme_select_secuuid($element) {
1250

  
1251
	$default_uuid = variable_get($element['#varname'], false);
1252

  
1253
	$tree = cdm_taxontree_build_tree(null, false); // get root nodes
1254
	$secUuids = array();
1255
	foreach($tree as $node){
1256
		$secUuids[] = $node->secUuid;
1257
	}
1258
	cdm_api_secref_cache_prefetch($secUuids);
1259

  
1260
	theme('cdm_taxontree_add_scripts');
1261
	drupal_add_js('$(document).ready(function() {$(\'ul.cdm_taxontree\').cdm_taxontree(
1262
  {
1263
    widget:                 true,
1264
    element_name:           \''.$element['#varname'].'\',  //
1265
    multiselect:            '.($element['#multiple']?'true':'false').',         //
1266
  }
1267
  );});', 'inline');
1268

  
1269
	$out  = '<div class="cdm_taxontree_widget">';
1270
	$out .= '<div class="taxontree">'.theme('cdm_taxontree', $tree, NULL, FALSE, 'cdm_taxontree_node_reference').'</div>';
1271
	$out .= $element['#children'].'<div style="clear: both;" /></div>';
1272

  
1273
	return theme(
1274
    'form_element',
1275
	array(
1276
      '#title' => $element['#title'],
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)