1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/*
|
5
|
* @file
|
6
|
* cdm_dataportal
|
7
|
*
|
8
|
* Copyright (C) 2007 EDIT
|
9
|
* European Distributed Institute of Taxonomy
|
10
|
* http://www.e-taxonomy.eu
|
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.
|
14
|
*/
|
15
|
|
16
|
require_once('node_types.php');
|
17
|
require_once('settings.php');
|
18
|
require_once('help.php');
|
19
|
|
20
|
require_once('theme/cdm_dataportal.common.theme');
|
21
|
require_once('theme/cdm_dataportal.descriptions.theme');
|
22
|
require_once('theme/cdm_dataportal.media.theme');
|
23
|
require_once('theme/cdm_dataportal.occurrence.theme');
|
24
|
require_once('theme/cdm_dataportal.page.theme');
|
25
|
require_once('theme/cdm_dataportal.taxon.theme');
|
26
|
require_once('theme/cdm_dataportal.name.theme');
|
27
|
require_once('theme/cdm_dataportal.references.theme');
|
28
|
|
29
|
require_once('classes/footnotemanager.php');
|
30
|
require_once('classes/footnote.php');
|
31
|
require_once('classes/footnotekey.php');
|
32
|
require_once('classes/renderhints.php');
|
33
|
|
34
|
function _add_js_progressbar(){
|
35
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
|
36
|
}
|
37
|
|
38
|
function _add_js_treeselector(){
|
39
|
//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
|
40
|
drupal_add_js("
|
41
|
if (Drupal.jsEnabled) {
|
42
|
$(document).ready(function() {
|
43
|
$('#cdm-taxonomictree-selector-form #edit-val').change(function () {
|
44
|
$('#cdm-taxonomictree-selector-form').submit();
|
45
|
});
|
46
|
|
47
|
});
|
48
|
}", 'inline');
|
49
|
}
|
50
|
|
51
|
function _add_js_openlayers_map(){
|
52
|
|
53
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
|
54
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
|
55
|
|
56
|
$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
|
57
|
|
58
|
$baseLayers = variable_get('baselayers', array());
|
59
|
if(!is_array($baseLayers) || count($baseLayers) == 0){
|
60
|
$baseLayers = array('metacarta_vmap0' => 'Metacarta Vmap0', 'PREFERRED' => 'metacarta_vmap0');
|
61
|
}
|
62
|
$layerNames = '';
|
63
|
foreach($baseLayers as $layerName => $layerLabel){
|
64
|
if($layerName == 'PREFERRED'){
|
65
|
$preferredLayer = $baseLayers['PREFERRED'];
|
66
|
} else {
|
67
|
$layerNames .= ($layerNames ? ', ': '') . "'$layerName'";
|
68
|
}
|
69
|
}
|
70
|
|
71
|
if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){
|
72
|
drupal_set_html_head('<script src=http://maps.google.com/maps?file=api&v=2&sensor=false&key='.$gmap_api_key.'" type="text/javascript"></script>');
|
73
|
drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
|
74
|
}
|
75
|
|
76
|
drupal_add_js("
|
77
|
if (Drupal.jsEnabled) {
|
78
|
$(document).ready(function() {
|
79
|
$('#openlayers_map').cdm_openlayers_map('"
|
80
|
.getEDITMapServiceURI()."', {
|
81
|
legendPosition: 3,
|
82
|
displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "',
|
83
|
boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "',
|
84
|
distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
|
85
|
legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
|
86
|
showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true':'false') . ",
|
87
|
baseLayerNames: [".$layerNames."],
|
88
|
defaultBaseLayerName: '".$preferredLayer."',
|
89
|
});
|
90
|
});
|
91
|
}", 'inline');
|
92
|
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
*
|
97
|
* Enter description here ...
|
98
|
* @param unknown_type $width
|
99
|
* @param unknown_type $occurrenceQuery
|
100
|
* @param unknown_type $distributionQuery
|
101
|
* @param unknown_type $legendFormatQuery
|
102
|
* @param unknown_type $map_caption
|
103
|
*/
|
104
|
function get_image_map($width, $bounding_box=false, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
|
105
|
|
106
|
$server = getEDITMapServiceURI();
|
107
|
|
108
|
if(!$server){
|
109
|
//warning message
|
110
|
drupal_set_message('No \'Geoservice Access Point\' has been set so far. '
|
111
|
. 'Please configure the variable \'Geoservice Access Point\' here '
|
112
|
. l('CDM Dataportal Settings', 'admin/settings/cdm_dataportal/geo'), 'warning');
|
113
|
//message to render
|
114
|
return "<p>No geoservice specified</p>";
|
115
|
}
|
116
|
|
117
|
// additional query parameters as set in the data portal admin section
|
118
|
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
|
119
|
|
120
|
$query_string .= '&image=true&recalculate=false&legend=1&ms=' . $width
|
121
|
. ($bounding_box ? '&bbox=' . $bounding_box : '')
|
122
|
. ($labels_on ? '&label=' . $labels_on : '');
|
123
|
|
124
|
if($map_caption){
|
125
|
$query_string .= '&mlp=3&mc_s=Georgia,15,blue&mc=' . $map_caption;
|
126
|
}
|
127
|
|
128
|
if (getEDITMapServiceVersionNumber() >= 1.1) {
|
129
|
|
130
|
// either occurrence or distribution - combined maps will be possible in future
|
131
|
if ($occurrenceQuery){
|
132
|
|
133
|
//fix $occurrenceQuery
|
134
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
135
|
//$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
136
|
$occurrenceQuery .= '&l=tdwg4&as='; // will be replaced below // HACK!!!
|
137
|
$query_string .= "&" .$occurrenceQuery;
|
138
|
|
139
|
} else if($distributionQuery){
|
140
|
|
141
|
$query_string .= "&" .$distributionQuery;
|
142
|
|
143
|
}
|
144
|
|
145
|
// apply Plain Image map settings special for version >= 1.1
|
146
|
/*
|
147
|
* example : title=a:Naturalized++non-invasive
|
148
|
* &ad=cyprusdivs:bdcode:a:5&as=a:ff9900,,0.1,&l=tdwg4
|
149
|
* &ms=500&bbox=32,34,35,36&img=true&legend=1&mlp=3
|
150
|
* &mc_s=Georgia,15,blue&mc=&recalculate=false
|
151
|
*
|
152
|
* http://edit.br.fgov.be/edit_wp5/v1/rest_gen.php?
|
153
|
* l=background_gis:b,cyprusdivs&ad=cyprusdivs%3Abdcode%3Aa%3A8%2C4
|
154
|
* &as=a%3A339966%2C%2C0.1%2C|b:0000ff,,
|
155
|
* &bbox=32%2C34%2C35%2C36&img=true&legend=1&mc=&mc_s=Georgia%2C15%2Cblue
|
156
|
* &mlp=3&ms=500&recalculate=false&title=a%3Aindigenous
|
157
|
*/
|
158
|
|
159
|
$map_service_script_name = "rest_gen.php";
|
160
|
|
161
|
$bgcolor_areaStyleId= "y";
|
162
|
$baselayer_areaStyleId= "z";
|
163
|
$bgcolor_layer='';
|
164
|
$additional_area_styles = array();
|
165
|
|
166
|
// background color:
|
167
|
if(variable_get('map_bg_color', '')){
|
168
|
$bgcolor_layer = "background_gis:".$bgcolor_areaStyleId;
|
169
|
$additional_area_styles[] = $bgcolor_areaStyleId . ":" . variable_get('map_bg_color', '') . ",,";
|
170
|
}
|
171
|
|
172
|
//TODO HACK to replace the default base layer which currently is tdwg4 !!! only needed for distribution maps
|
173
|
if(strpos($query_string, "?l=") !== FALSE){
|
174
|
$layer_param_token = "?l=";
|
175
|
} else {
|
176
|
$layer_param_token = "&l=";
|
177
|
}
|
178
|
if(strpos($query_string, "?as=") !== FALSE){
|
179
|
$areystyle_param_token = "?as=";
|
180
|
} else {
|
181
|
$areystyle_param_token = "&as=";
|
182
|
}
|
183
|
if(variable_get('map_base_layer', '')){
|
184
|
$query_string = str_replace($layer_param_token."tdwg4", "$layer_param_token".variable_get('map_base_layer', ''). ":" . $baselayer_areaStyleId, $query_string);
|
185
|
} else {
|
186
|
$query_string = str_replace($layer_param_token."tdwg4", $layer_param_token."tdwg4:".$baselayer_areaStyleId . ",", $query_string);
|
187
|
}
|
188
|
|
189
|
if($bgcolor_layer){
|
190
|
$query_string = str_replace($layer_param_token, $layer_param_token . $bgcolor_layer . ",", $query_string);
|
191
|
}
|
192
|
|
193
|
if(variable_get('map_base_layer_style', '')){
|
194
|
$additional_area_styles[] = $baselayer_areaStyleId . ":" . variable_get('map_base_layer_style', '');
|
195
|
}
|
196
|
|
197
|
foreach ($additional_area_styles as $as) {
|
198
|
$query_string = str_replace($areystyle_param_token, $areystyle_param_token . $as . "|", $query_string);
|
199
|
}
|
200
|
|
201
|
} else {
|
202
|
// pre 1.1. version of map service
|
203
|
if ($occurrenceQuery){
|
204
|
|
205
|
$map_service_script_name = "point.php";
|
206
|
|
207
|
//fix $occurrenceQuery
|
208
|
$occurrenceQuery = str_replace("&image=false", "", $occurrenceQuery);
|
209
|
//$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
210
|
$occurrenceQuery .= '&l=v:e_w_0';
|
211
|
$query_string .= "&" .$occurrenceQuery;
|
212
|
|
213
|
} else if($distributionQuery){
|
214
|
|
215
|
$query_string .= "&" .$distributionQuery;
|
216
|
$map_service_script_name = "areas.php";
|
217
|
|
218
|
}
|
219
|
|
220
|
}
|
221
|
|
222
|
$mapUri = url("$server/$map_service_script_name?$query_string");
|
223
|
$out = '<img class="distribution_map" src="' . $mapUri . '" alt="Map" />';
|
224
|
// showing map caption
|
225
|
if($map_caption){
|
226
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
|
227
|
$out .= '</div>';
|
228
|
}
|
229
|
|
230
|
return $out;
|
231
|
|
232
|
|
233
|
}
|
234
|
|
235
|
/**
|
236
|
*
|
237
|
* Enter description here ...
|
238
|
* @param unknown_type $width
|
239
|
* @param unknown_type $occurrenceQuery
|
240
|
* @param unknown_type $distributionQuery
|
241
|
* @param unknown_type $legendFormatQuery
|
242
|
* @param unknown_type $map_caption
|
243
|
*/
|
244
|
function get_openlayers_map($width, $bounding_box=false, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
|
245
|
|
246
|
_add_js_openlayers_map();
|
247
|
|
248
|
$out = '<div id="openlayers">';
|
249
|
$out .= '<div id="openlayers_map" class="smallmap"';
|
250
|
$out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
|
251
|
|
252
|
// additional query parameters as set in the data portal admin section
|
253
|
$labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
|
254
|
|
255
|
$openlayers_map_query_string .= '&img=false&ms=' . $width
|
256
|
. ($bounding_box ? '&bbox=' . $bounding_box : '')
|
257
|
. ($labels_on ? '&label=' . $labels_on : '');
|
258
|
|
259
|
if($occurrenceQuery){
|
260
|
//fix $occurrenceQuery
|
261
|
$occurrenceQuery .= '&bbox=-180,-90,180,90';
|
262
|
$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
263
|
//$occurrenceQuery .= '&l=v:e_w_0';
|
264
|
$occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
|
265
|
|
266
|
$out .= ' occurrenceQuery="' . $occurrenceQuery . '&' . $openlayers_map_query_string . '"';
|
267
|
}
|
268
|
|
269
|
if($distributionQuery){
|
270
|
$out .= ' distributionQuery="' . $distributionQuery . '&' . $openlayers_map_query_string . '"';
|
271
|
}
|
272
|
|
273
|
if($legendFormatQuery){
|
274
|
$out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
|
275
|
}
|
276
|
|
277
|
$out .= '></div></div>';
|
278
|
|
279
|
// showing map caption
|
280
|
if($map_caption){
|
281
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
|
282
|
$out .= '</div>';
|
283
|
}
|
284
|
return $out;
|
285
|
}
|
286
|
|
287
|
/* ====================== hook implementations ====================== */
|
288
|
|
289
|
|
290
|
/**
|
291
|
* Implementation of hook_perm()
|
292
|
*
|
293
|
* Valid permissions for this module
|
294
|
* @return array An array of valid permissions for the portfolio module
|
295
|
*/
|
296
|
function cdm_dataportal_perm() {
|
297
|
return array(
|
298
|
'administer cdm_dataportal',
|
299
|
'cdm_dataportal view notes',
|
300
|
//TODO which else permission are required? -> check the WP6 requirements document
|
301
|
);
|
302
|
}
|
303
|
|
304
|
|
305
|
/**
|
306
|
* Implementation of hook_menu()
|
307
|
*/
|
308
|
function cdm_dataportal_menu($may_cache) {
|
309
|
$items = array();
|
310
|
|
311
|
cdm_dataportal_menu_admin($may_cache, $items);
|
312
|
cdm_dataportal_menu_help($may_cache, $items);
|
313
|
|
314
|
if ($may_cache) {
|
315
|
|
316
|
$items[] = array(
|
317
|
'path' => 'cdm_dataportal/names',
|
318
|
'callback' => 'cdm_dataportal_view_names',
|
319
|
'access' => true,
|
320
|
'type' => MENU_CALLBACK,
|
321
|
);
|
322
|
// optional callback arguments: page
|
323
|
|
324
|
$items[] = array(
|
325
|
'path' => 'cdm_dataportal/taxon',
|
326
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
327
|
'access' => true,
|
328
|
'type' => MENU_CALLBACK,
|
329
|
// expected callback arguments: uuid
|
330
|
);
|
331
|
|
332
|
$items[] = array(
|
333
|
'path' => 'cdm_dataportal/name',
|
334
|
'callback' => 'cdm_dataportal_name_page_view',
|
335
|
'access' => true,
|
336
|
'type' => MENU_CALLBACK,
|
337
|
// expected callback arguments: uuid
|
338
|
);
|
339
|
|
340
|
$items[] = array(
|
341
|
'path' => 'cdm_dataportal/reference',
|
342
|
'callback' => 'cdm_dataportal_view_reference',
|
343
|
'access' => true,
|
344
|
'type' => MENU_CALLBACK,
|
345
|
// expected callback arguments: uuid
|
346
|
);
|
347
|
|
348
|
$items[] = array(
|
349
|
'path' => 'cdm_dataportal/reference/list',
|
350
|
'callback' => 'cdm_dataportal_view_reference_list',
|
351
|
'access' => true,
|
352
|
'type' => MENU_CALLBACK,
|
353
|
// expected callback arguments: uuid
|
354
|
);
|
355
|
|
356
|
$items[] = array(
|
357
|
'path' => 'cdm_dataportal/media',
|
358
|
'callback' => 'cdm_dataportal_view_media',
|
359
|
'access' => true,
|
360
|
'type' => MENU_CALLBACK,
|
361
|
// expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
|
362
|
);
|
363
|
|
364
|
$items[] = array(
|
365
|
'path' => 'cdm_dataportal/polytomousKey',
|
366
|
'callback' => 'cdm_dataportal_view_polytomousKey',
|
367
|
'access' => true,
|
368
|
'type' => MENU_CALLBACK,
|
369
|
// expected callback arguments: polytomousKey->uuid
|
370
|
);
|
371
|
|
372
|
$items[] = array(
|
373
|
'path' => 'cdm_dataportal/search',
|
374
|
'callback' => 'cdm_dataportal_view_search_advanced',
|
375
|
'access' => true,
|
376
|
'type' => MENU_CALLBACK,
|
377
|
);
|
378
|
|
379
|
$items[] = array(
|
380
|
'path' => 'cdm_dataportal/search/taxon',
|
381
|
'callback' => 'cdm_dataportal_view_search_taxon',
|
382
|
'access' => true,
|
383
|
'type' => MENU_CALLBACK,
|
384
|
);
|
385
|
|
386
|
$items[] = array(
|
387
|
'path' => 'cdm/xml2json',
|
388
|
'callback' => 'cdm_view_xml2json',
|
389
|
'access' => true,
|
390
|
'type' => MENU_CALLBACK,
|
391
|
);
|
392
|
|
393
|
}elseif (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid)) {
|
394
|
//user configuration of cdm_dataportal
|
395
|
$items[] = array('path' => 'user/'.$uid.'/cdm_dataportal',
|
396
|
'title' => t('cdm_dataportal'),
|
397
|
'access' => TRUE,
|
398
|
'callback' => 'drupal_get_form',
|
399
|
'callback arguments' => array('cdm_dataportal_user_form'),
|
400
|
'type' => MENU_LOCAL_TASK,
|
401
|
'weight' => 10,
|
402
|
);
|
403
|
} else {
|
404
|
// may not cache
|
405
|
// --- local tasks for Taxon
|
406
|
$items[] = array(
|
407
|
'path' => 'cdm_dataportal/name/'.arg(2),
|
408
|
//'callback' => 'cdm_dataportal_view_name',
|
409
|
'callback' => 'cdm_dataportal_name_page_view',
|
410
|
'callback arguments' => array(arg(2), arg(3), arg(4)),
|
411
|
'access' => true,
|
412
|
'type' => MENU_CALLBACK,
|
413
|
);
|
414
|
|
415
|
if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
|
416
|
|
417
|
$items[] = array(
|
418
|
'path' => 'cdm_dataportal/taxon/'.arg(2),
|
419
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
420
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
421
|
'access' => true,
|
422
|
'type' => MENU_CALLBACK,
|
423
|
'weight' => 1,
|
424
|
'callback arguments' => array(arg(2), "description")
|
425
|
// expected callback arguments: name_uuid
|
426
|
);
|
427
|
|
428
|
$items[] = array(
|
429
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
|
430
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
431
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
432
|
'access' => true,
|
433
|
'type' => MENU_CALLBACK,
|
434
|
'weight' => 2,
|
435
|
'callback arguments' => array(arg(2), "all")
|
436
|
// expected callback arguments: name_uuid
|
437
|
);
|
438
|
|
439
|
$items[] = array(
|
440
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
|
441
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
442
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
443
|
'access' => true,
|
444
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
445
|
'weight' => 2,
|
446
|
'callback arguments' => array(arg(2), "description")
|
447
|
// expected callback arguments: name_uuid
|
448
|
);
|
449
|
|
450
|
$items[] = array(
|
451
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
|
452
|
'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
|
453
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
454
|
'access' => true,
|
455
|
'type' => MENU_LOCAL_TASK,
|
456
|
'weight' => 4,
|
457
|
'callback arguments' => array(arg(2), "synonymy", arg(4))
|
458
|
// expected callback arguments: name_uuid
|
459
|
);
|
460
|
$items[] = array(
|
461
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
|
462
|
'title' => theme('cdm_taxonpage_tab', 'Images'),
|
463
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
464
|
'access' => true,
|
465
|
'type' => MENU_LOCAL_TASK,
|
466
|
'weight' => 5,
|
467
|
'callback arguments' => array(arg(2), "images")
|
468
|
// expected callback arguments: name_uuid
|
469
|
);
|
470
|
|
471
|
$items[] = array(
|
472
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
|
473
|
'title' => theme('cdm_taxonpage_tab', 'Specimens'),
|
474
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
475
|
'access' => true,
|
476
|
'type' => MENU_LOCAL_TASK,
|
477
|
'weight' => 6,
|
478
|
'callback arguments' => array(arg(2), "specimens")
|
479
|
// expected callback arguments: name_uuid
|
480
|
);
|
481
|
|
482
|
$items[] = array(
|
483
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/keys',
|
484
|
'title' => theme('cdm_taxonpage_tab', 'Keys'),
|
485
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
486
|
'access' => true,
|
487
|
'type' => MENU_LOCAL_TASK,
|
488
|
'weight' => 6,
|
489
|
'callback arguments' => array(arg(2), "keys")
|
490
|
// expected callback arguments: name_uuid
|
491
|
);
|
492
|
}
|
493
|
}
|
494
|
|
495
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
|
496
|
//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
|
497
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
|
498
|
|
499
|
return $items;
|
500
|
|
501
|
}
|
502
|
/**
|
503
|
* The function generate form for own user cdm dataportal configurations
|
504
|
*/
|
505
|
function cdm_dataportal_user_form() {
|
506
|
|
507
|
global $user;
|
508
|
$checkbox_value = 'cdm_dataportal_' .$user->uid . '_default_tab_active';
|
509
|
|
510
|
$form['check'] = array
|
511
|
(
|
512
|
'#type' => 'checkbox',
|
513
|
'#title' => t('Activate user default configuration'),
|
514
|
'#default_value' => variable_get($checkbox_value, 0),
|
515
|
'#description' => t('Check this if you want configure your own default tab from the below menu.')
|
516
|
);
|
517
|
|
518
|
$form['cdm_dataportal_user_form'] = array(
|
519
|
'#type' => 'select',
|
520
|
'#title' => t('Default tab to display'),
|
521
|
'#default_value' => get_default_taxon_tab(true),
|
522
|
'#options' => unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB),
|
523
|
'#description' => t('<p>Select the default tab to display when visiting a taxon page. Only available if Tabbed Taxon Page is enable.</p>
|
524
|
<strong>Note:</strong> After performing a search and clicking in any synonym, the taxon tab
|
525
|
to be renderized will be the synonymy of the accepted taxon and not the above selected tab.'),
|
526
|
);
|
527
|
|
528
|
$form['submit'] = array(
|
529
|
'#type' => 'submit',
|
530
|
'#value' => t('Submit')
|
531
|
);
|
532
|
|
533
|
return $form;
|
534
|
}
|
535
|
|
536
|
/**
|
537
|
* The function submit the user cdm dataportal configurations
|
538
|
* @param unknown_type $form
|
539
|
* @param unknown_type $form_values
|
540
|
*/
|
541
|
function cdm_dataportal_user_form_submit($form, $form_values) {
|
542
|
global $user;
|
543
|
$msg_type = 'status';
|
544
|
$username = $user->name;
|
545
|
$variable_to_use = 'cdm_dataportal_' .$user->uid . '_default_tab';
|
546
|
|
547
|
//if is the right user the variables are setted
|
548
|
if (arg(0)=='user' && ($uid=arg(1)) && is_numeric($uid) && $user->uid==$uid){
|
549
|
$variable = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
|
550
|
variable_set($variable_to_use . '_active', $form_values['check']);
|
551
|
variable_set($variable_to_use, $form_values['cdm_dataportal_user_form']);
|
552
|
if ($form_values['check']){
|
553
|
drupal_set_message('The user default tab will be used for the next taxon site visit.');
|
554
|
drupal_set_message('The user default tab have been changed to: '
|
555
|
. $variable[variable_get($variable_to_use, 0)]
|
556
|
. ' for the user ' . $username, $msg_type);
|
557
|
}else{
|
558
|
drupal_set_message('The user default tab wont be used for the next taxon site, check the box if you want to use the user default configuration.');
|
559
|
}
|
560
|
//problem with the user id => variables wont be saved
|
561
|
}else{
|
562
|
$msg_type = 'warning';
|
563
|
drupal_set_message('Default tab have not been saved due to user id problems', $msg_type);
|
564
|
}
|
565
|
}
|
566
|
|
567
|
/**
|
568
|
* Implementation of hook_block()
|
569
|
*
|
570
|
* Provides the following blocks:
|
571
|
* 0: list of links useful during development
|
572
|
*
|
573
|
* @param String $op
|
574
|
* @param int $delta
|
575
|
*/
|
576
|
function cdm_dataportal_block($op='list', $delta=0) {
|
577
|
// listing of blocks, such as on the admin/block page
|
578
|
if ($op == "list") {
|
579
|
//$block[0]["info"] = t("CDM DataPortal DevLinks");
|
580
|
//$block[1]["info"] = t("CDM DataPortal Credits");
|
581
|
$block[2]["info"] = t("CDM Search Taxa");
|
582
|
//$block[3]["info"] = t("CDM Filters");
|
583
|
$block[4]["info"] = t("CDM Dataportal Print");
|
584
|
$block["keys"]["info"] = t("CDM identification keys");
|
585
|
$block["uses"]["info"] = t("CDM Uses");
|
586
|
$block["fundedByEDIT"]["info"] = t('Funded by EDIT');
|
587
|
|
588
|
return $block;
|
589
|
}
|
590
|
else if ($op == 'view') {
|
591
|
switch($delta){
|
592
|
// case 1:
|
593
|
// $block['subject'] = t('Credits');
|
594
|
// $block['content'] = theme('cdm_credits');
|
595
|
// return $block;
|
596
|
case 2:
|
597
|
$block['subject'] = t('Search taxa');
|
598
|
$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
|
599
|
if (variable_get('cdm_dataportal_show_advanced_search', 1)){
|
600
|
$block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
|
601
|
}
|
602
|
return $block;
|
603
|
case 4:
|
604
|
$block['subject'] = t('<none>');
|
605
|
$block['content'] = theme('cdm_print_button');;
|
606
|
return $block;
|
607
|
case "keys":
|
608
|
$block['subject'] = t('Identification Keys');
|
609
|
$block['content'] = theme('cdm_block_IdentificationKeys');
|
610
|
return $block;
|
611
|
//Creating a block specific for the Use Interface.
|
612
|
case "uses":
|
613
|
$block['subject'] = t('Uses');
|
614
|
$block['content'] = theme('cdm_block_uses');
|
615
|
return $block;
|
616
|
case "fundedByEDIT":
|
617
|
$text = '<none>'; //t('Funded by EDIT');
|
618
|
$block['subject'] = $text;
|
619
|
$img_tag = '<img src="' . drupal_get_path('module', 'cdm_dataportal').'/images/funded_by_EDIT.png' . '" alt="'.$text.'"/>';
|
620
|
$block['content'] = l($img_tag, "http://www.e-taxonomy.eu/", array("target"=>"EDIT"), NULL, NULL, TRUE, TRUE);
|
621
|
return $block;
|
622
|
}
|
623
|
}
|
624
|
}
|
625
|
|
626
|
|
627
|
|
628
|
/*
|
629
|
function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
|
630
|
$_SESSION['cdm'] = null;
|
631
|
if(is_string($cdm_ws_uri_update)){
|
632
|
$_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
|
633
|
}
|
634
|
}
|
635
|
|
636
|
function cdm_dataportal_session_validate(){
|
637
|
|
638
|
if(!isset($_SESSION['cdm']['ws_uri'])){
|
639
|
$_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
|
640
|
} else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
|
641
|
cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
|
642
|
}
|
643
|
}
|
644
|
*/
|
645
|
|
646
|
function cdm_dataportal_search_taxon_form($advancedForm = false){
|
647
|
global $theme_key;
|
648
|
|
649
|
$tdwg_level_select = (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
|
650
|
$selected_areas = (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
|
651
|
|
652
|
if(isset($_SESSION['cdm']['search']) && !$preset_UseDefaults) {
|
653
|
$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
654
|
}
|
655
|
|
656
|
$url = 'cdm_dataportal/search/taxon';
|
657
|
$form['#method'] = 'get';
|
658
|
$form['#process'] = array('cdm_dataportal_search_process' => array());
|
659
|
$form['#action'] = url($url, NULL, NULL, true);
|
660
|
|
661
|
if(!$advancedForm) {
|
662
|
$form['query'] = array(
|
663
|
'#delta' => 0,
|
664
|
'#type' => 'textfield',
|
665
|
'#size' => 20,
|
666
|
'#attributes' => array('title' => t('Enter the name or part of a name you wish to search for. The asterisk character * can always be used as wildcard')),
|
667
|
'#value' => $preset_query,
|
668
|
);
|
669
|
}
|
670
|
//AT RBG KEW - 14/11/2011 Added to extend the text box in the Advanced form only
|
671
|
else {
|
672
|
$form['query'] = array(
|
673
|
'#delta' => 0,
|
674
|
'#type' => 'textfield',
|
675
|
'#size' => 68,
|
676
|
'#attributes' => array('title' => t('Enter the name or part of a name you wish to search for. The asterisk character * can always be used as wildcard')),
|
677
|
'#value' => $preset_query,
|
678
|
);
|
679
|
}
|
680
|
|
681
|
$form['search'] = array(
|
682
|
'#delta' => 1,
|
683
|
'#tree' => true,
|
684
|
//'#type' => $advancedForm ? 'fieldset': 'hidden',
|
685
|
'#title' => t('Options')
|
686
|
);
|
687
|
|
688
|
$form['search']['tree'] = array(
|
689
|
'#delta' => -1,
|
690
|
'#type' => 'hidden',
|
691
|
'#value' => get_taxonomictree_uuid_selected()
|
692
|
);
|
693
|
|
694
|
|
695
|
// clean URL get forms breaks if we don't give it a 'q'.
|
696
|
if (!(bool)variable_get('clean_url', '0')) {
|
697
|
$form['search']['q'] = array(
|
698
|
'#delta' => -1,
|
699
|
'#type' => 'hidden',
|
700
|
'#value' => $url,
|
701
|
'#name' => 'q',
|
702
|
);
|
703
|
}
|
704
|
|
705
|
$form['search']['pageSize'] = array(
|
706
|
'#delta' => -1,
|
707
|
'#type' => 'hidden',
|
708
|
'#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
|
709
|
);
|
710
|
|
711
|
$form['search']['pageNumber'] = array(
|
712
|
'#delta' => -1,
|
713
|
'#type' => 'hidden',
|
714
|
'#value' => 0
|
715
|
);
|
716
|
|
717
|
if($advancedForm){
|
718
|
|
719
|
// get presets from settings
|
720
|
$preset_doTaxa = variable_get('cdm_search_doTaxa', 1);
|
721
|
$preset_doSynonyms = variable_get('cdm_search_doSynonyms', 1);
|
722
|
$preset_doTaxaByCommonNames = variable_get('cdm_search_doTaxaByCommonNames', 0);
|
723
|
$preset_doMisappliedNames = variable_get('cdm_search_doMisappliedNames', 1);
|
724
|
$preset_UseDefaults = variable_get('cdm_search_use_default_values', 1);
|
725
|
|
726
|
// overwrite presets by user choice stored in session
|
727
|
if(isset($_SESSION['cdm']['search']) && !$preset_UseDefaults) {
|
728
|
$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
|
729
|
$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
|
730
|
$preset_doMisappliedNames = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
|
731
|
$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
|
732
|
}
|
733
|
// general search parameters
|
734
|
|
735
|
$form['search']['doTaxa'] = array(
|
736
|
'#delta' => 2,
|
737
|
'#type' => 'checkbox',
|
738
|
'#title' => t('Search for accepted taxa'),
|
739
|
'#value' => $preset_doTaxa
|
740
|
);
|
741
|
$form['search']['doSynonyms'] = array(
|
742
|
'#delta' => 3,
|
743
|
'#type' => 'checkbox',
|
744
|
'#title' => t('Search for synonyms'),
|
745
|
'#value' => $preset_doSynonyms
|
746
|
);
|
747
|
$form['search']['doMisappliedNames'] = array(
|
748
|
'#delta' => 4,
|
749
|
'#type' => 'checkbox',
|
750
|
'#title' => t('Search for misapplied names'),
|
751
|
'#value' => $preset_doMisappliedNames
|
752
|
);
|
753
|
$form['search']['doTaxaByCommonNames'] = array(
|
754
|
'#delta' => 5,
|
755
|
'#type' => 'checkbox',
|
756
|
'#title' => t('Search for common names'),
|
757
|
'#value' => $preset_doTaxaByCommonNames
|
758
|
);
|
759
|
|
760
|
// Geographic Range
|
761
|
$form['search']['geographic_range'] = array(
|
762
|
'#type' => 'fieldset',
|
763
|
'#delta' => 5,
|
764
|
'#tree' => true,
|
765
|
'#title' => t('Geographic range'),
|
766
|
);
|
767
|
|
768
|
$form['search']['geographic_range']['tdwg_level_select'] = array(
|
769
|
'#type' => 'radios',
|
770
|
'#title' => t('Select a TDWG distribution level and code'),
|
771
|
'#default_value' => $tdwg_level_select,
|
772
|
'#options' => array(
|
773
|
t('TDWG level-1, i.e. a continent'),
|
774
|
t('TDWG level-2'),
|
775
|
t('TDWG level-3, i.e. a country'),
|
776
|
t('TDWG level-4')
|
777
|
)
|
778
|
);
|
779
|
$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
|
780
|
$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
|
781
|
$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
|
782
|
$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
|
783
|
|
784
|
$tdwg_js = '';
|
785
|
foreach($tdwg as $key=>$tdwg_level){
|
786
|
$tdwgOptions = array();
|
787
|
$tdwgOptionsSelected = array();
|
788
|
foreach($tdwg_level as $area){
|
789
|
$representation = $area->representations[0];
|
790
|
$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
|
791
|
if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
|
792
|
$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
|
793
|
}
|
794
|
}
|
795
|
asort($tdwgOptions);
|
796
|
$form['search']['geographic_range']['tdwg_level_'.$key] = array(
|
797
|
'#type' => 'select',
|
798
|
'#title' => t('TDWG level').' '.$key,
|
799
|
'#default_value' => $tdwgOptionsSelected,
|
800
|
'#multiple' => TRUE,
|
801
|
'#options' => $tdwgOptions
|
802
|
);
|
803
|
$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ? '.show()' : '.hide()'). ";\n";
|
804
|
}
|
805
|
|
806
|
drupal_add_js(
|
807
|
"$(document).ready(function(){
|
808
|
|
809
|
$(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
|
810
|
function(event){
|
811
|
var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
|
812
|
var i;
|
813
|
for(i = 0; i < 4; i++){
|
814
|
if(selectId == i){
|
815
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
|
816
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
817
|
} else {
|
818
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
|
819
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
820
|
}
|
821
|
}
|
822
|
}
|
823
|
);
|
824
|
|
825
|
$tdwg_js
|
826
|
});",
|
827
|
'inline');
|
828
|
|
829
|
} else {
|
830
|
$preset_doTaxa = variable_get('cdm_search_doTaxa', 1);
|
831
|
$preset_doSynonyms = variable_get('cdm_search_doSynonyms', 1);
|
832
|
$preset_doTaxaByCommonNames = variable_get('cdm_search_doTaxaByCommonNames', 0);
|
833
|
$preset_doMisappliedNames = variable_get('cdm_search_doMisappliedNames', 1);
|
834
|
$preset_UseDefaults = variable_get('cdm_search_use_default_values', 1);
|
835
|
|
836
|
// overwrite presets by user choice stored in session
|
837
|
if(isset($_SESSION['cdm']['search']) && !$preset_UseDefaults) {
|
838
|
$preset_doMisappliedNames = (isset($_SESSION['cdm']['search']['doMisappliedNames']) ? 1 : 0);
|
839
|
}
|
840
|
|
841
|
$form['search']['doTaxa'] = array(
|
842
|
'#delta' => -2,
|
843
|
'#type' => 'hidden',
|
844
|
'#value' => $preset_doTaxa
|
845
|
);
|
846
|
$form['search']['doSynonyms'] = array(
|
847
|
'#delta' => -3,
|
848
|
'#type' => 'hidden',
|
849
|
'#value' => $preset_doSynonyms
|
850
|
);
|
851
|
$form['search']['doMisappliedNames'] = array(
|
852
|
'#delta' => -4,
|
853
|
'#type' => 'checkbox',
|
854
|
'#title' => t('Misapplied names'),
|
855
|
'#value' => $preset_doMisappliedNames
|
856
|
);
|
857
|
$form['search']['doTaxaByCommonNames'] = array(
|
858
|
'#delta' => -5,
|
859
|
'#type' => 'hidden',
|
860
|
'#value' => $preset_doTaxaByCommonNames
|
861
|
);
|
862
|
}
|
863
|
|
864
|
$form['submit'] = array(
|
865
|
'#delta' => 9,
|
866
|
'#type' => 'submit',
|
867
|
'#name' => '',
|
868
|
'#value' => t('Search')
|
869
|
);
|
870
|
|
871
|
return $form;
|
872
|
}
|
873
|
|
874
|
function cdm_dataportal_search_taxon_form_advanced(){
|
875
|
return cdm_dataportal_search_taxon_form(true);
|
876
|
}
|
877
|
|
878
|
function cdm_taxonomictree_selector(){
|
879
|
_add_js_treeselector();
|
880
|
|
881
|
$out = drupal_get_form('cdm_taxonomictree_selector_form');
|
882
|
|
883
|
return $out;
|
884
|
}
|
885
|
|
886
|
|
887
|
function cdm_taxonomictree_selector_form(){
|
888
|
|
889
|
$url = url('cdm_api/setvalue/session', null);
|
890
|
$form['#action'] = $url;
|
891
|
|
892
|
$form['var'] = array(
|
893
|
'#delta' => -3,
|
894
|
'#type' => 'hidden',
|
895
|
'#value' => '[cdm][taxonomictree_uuid]'
|
896
|
);
|
897
|
|
898
|
$form['destination'] = array(
|
899
|
'#delta' => -3,
|
900
|
'#type' => 'hidden',
|
901
|
'#value' => substr(drupal_get_destination(), strlen('destination='))
|
902
|
);
|
903
|
|
904
|
$form['val'] = array(
|
905
|
'#type' => 'select',
|
906
|
'#title' => t('Available classifications'),
|
907
|
'#default_value' => get_taxonomictree_uuid_selected(),
|
908
|
'#options' => cdm_get_taxontrees_as_options()
|
909
|
);
|
910
|
|
911
|
return $form;
|
912
|
|
913
|
}
|
914
|
|
915
|
/**
|
916
|
* Implementation #process method call, see form_builder()
|
917
|
* <p>
|
918
|
* Removes Drupal internal form elements from query
|
919
|
* @param $form
|
920
|
* @return unknown_type
|
921
|
*/
|
922
|
function cdm_dataportal_search_process($form) {
|
923
|
unset($form['form_id']);
|
924
|
unset($form['form_token']);
|
925
|
return $form;
|
926
|
}
|
927
|
|
928
|
/**
|
929
|
* Filters $_REQUEST by a list of valid request parameters and also sets defaults if required.
|
930
|
* returns the processed request parameters submitted by the search form.
|
931
|
*/
|
932
|
function cdm_dataportal_search_form_request(){
|
933
|
|
934
|
|
935
|
$form_params = array();
|
936
|
array_deep_copy($_REQUEST['search'], $form_params);
|
937
|
$form_params['query'] = trim($_REQUEST['query']);
|
938
|
|
939
|
// split of geographic range
|
940
|
if(isset($_REQUEST['search']['geographic_range'])){
|
941
|
$geographicRange = $_REQUEST['search']['geographic_range'];
|
942
|
// remove
|
943
|
unset($form_params['geographic_range']);
|
944
|
}
|
945
|
|
946
|
// add geographic range
|
947
|
if($geographicRange){
|
948
|
$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
|
949
|
for($i = 1; $i < 5; $i++){
|
950
|
if(isset($geographicRange['tdwg_level_'.$i])){
|
951
|
$form_params['area'] = $geographicRange['tdwg_level_'.$i];
|
952
|
}
|
953
|
}
|
954
|
}
|
955
|
|
956
|
// store in session
|
957
|
$_SESSION['cdm']['search'] = $form_params;
|
958
|
|
959
|
return $form_params;
|
960
|
}
|
961
|
|
962
|
|
963
|
/* UNREACHABLE since action of form directly links to view
|
964
|
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
|
965
|
|
966
|
$_SESSION['cdm']['search'] = $form_values;
|
967
|
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
|
968
|
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
|
969
|
//$paramstr = compose_url_prameterstr($form_values);
|
970
|
//return url('/cdm_dataportal/search/taxon/', $paramstr);
|
971
|
}
|
972
|
*/
|
973
|
/* ====================== menu callback functions ====================== */
|
974
|
|
975
|
|
976
|
|
977
|
function cdm_dataportal_form_alter($form_id, &$form) {
|
978
|
|
979
|
static $comment_node_disabled = 0;
|
980
|
static $comment_node_read_only = 1;
|
981
|
static $comment_node_read_write = 2;
|
982
|
|
983
|
|
984
|
if ($form_id == 'node_type_form'
|
985
|
&& isset($form['identity']['type'])
|
986
|
&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
|
987
|
) {
|
988
|
$form['workflow']['comment'] = array(
|
989
|
'#type' => 'radios',
|
990
|
'#title' => t('Default comment setting'),
|
991
|
'#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
|
992
|
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
|
993
|
'#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
|
994
|
);
|
995
|
}
|
996
|
}
|
997
|
|
998
|
|
999
|
|
1000
|
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed, $form_description = ''){
|
1001
|
//TODO move into settings.php
|
1002
|
$form[$form_name] = array(
|
1003
|
'#type' => 'fieldset',
|
1004
|
'#title' => t($form_tittle),
|
1005
|
'#collapsible' => TRUE,
|
1006
|
'#collapsed' => $collapsed,
|
1007
|
'#tree' => true,
|
1008
|
'#description' => t($form_description),
|
1009
|
);
|
1010
|
|
1011
|
$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
|
1012
|
$gallery_settings = variable_get($form_name, $default_values);
|
1013
|
//$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
|
1014
|
|
1015
|
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
|
1016
|
/* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
|
1017
|
$form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
|
1018
|
'#type' => 'textfield',
|
1019
|
'#title' => t('Search Page Size'),
|
1020
|
'#default_value' => $test,
|
1021
|
'#description' => t('Number of Names to display per page in search results.')
|
1022
|
);
|
1023
|
*/
|
1024
|
$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
|
1025
|
'#type' => 'checkbox',
|
1026
|
'#title' => t('Show media thumbnails for accepted taxa'),
|
1027
|
'#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
|
1028
|
);
|
1029
|
|
1030
|
$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
|
1031
|
'#type' => 'checkbox',
|
1032
|
'#title' => t('Show media thumbnails for synonyms'),
|
1033
|
'#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
|
1034
|
'#description' => t('')
|
1035
|
);
|
1036
|
}
|
1037
|
|
1038
|
//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
|
1039
|
$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
|
1040
|
'#type' => 'checkbox',
|
1041
|
'#title' => t('Show captions under thumbnails'),
|
1042
|
'#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
|
1043
|
'#description' => t('')
|
1044
|
);
|
1045
|
|
1046
|
$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
|
1047
|
'#type' => 'textfield',
|
1048
|
'#title' => t('Thumbnail size'),
|
1049
|
'#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
|
1050
|
'#description' => t('Select the size of each individual thumbnail.')
|
1051
|
);
|
1052
|
|
1053
|
if($form_name != CDM_DATAPORTAL_MEDIA_GALLERY_NAME){
|
1054
|
$form[$form_name]['cdm_dataportal_media_cols'] = array(
|
1055
|
'#type' => 'textfield',
|
1056
|
'#title' => t('Number of columns'),
|
1057
|
'#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
|
1058
|
'#description' => t('Group the thumbnails in columns: select how many columns should the gallery display.')
|
1059
|
);
|
1060
|
}
|
1061
|
|
1062
|
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
|
1063
|
$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
|
1064
|
'#type' => 'textfield',
|
1065
|
'#title' => t('Maximum number of rows'),
|
1066
|
'#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
|
1067
|
'#description' => t('You can group the thumbnails in rows, select in how many rows should be the thumbnails grouped.<br>
|
1068
|
<b>Note:</b> If you want an unlimited number of rows please set to 0')
|
1069
|
);
|
1070
|
}
|
1071
|
|
1072
|
return $form;
|
1073
|
}
|
1074
|
|
1075
|
|
1076
|
/**
|
1077
|
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
|
1078
|
*
|
1079
|
* TODO: parameters are still preliminar
|
1080
|
* @param String $page page number to diplay defaults to page 1
|
1081
|
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
|
1082
|
*/
|
1083
|
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
|
1084
|
|
1085
|
$request_params = array(
|
1086
|
'q' => $beginsWith,
|
1087
|
//'sec' = '',
|
1088
|
//'higherTaxa' => getFiters(),
|
1089
|
// 'matchAnywhere' => false, // default is false
|
1090
|
'page' => $page,
|
1091
|
'onlyAccepted' => $onlyAccepted,
|
1092
|
'pagesize' => 20 /*$_SESSION['cdm']['namelist_pagesize'] */);
|
1093
|
|
1094
|
$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
|
1095
|
/*
|
1096
|
* FIXME the filter for accepted names will be a form element, thus this widget
|
1097
|
* should be generated via form api preferably as block
|
1098
|
*/
|
1099
|
//$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
|
1100
|
//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
|
1101
|
$out .= theme('cdm_listof_taxa', $taxonPager);
|
1102
|
return $out;
|
1103
|
}
|
1104
|
|
1105
|
function cdm_dataportal_view_reference($uuid, $arg2 = null){
|
1106
|
$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
|
1107
|
return theme('cdm_reference_page', $reference);
|
1108
|
}
|
1109
|
|
1110
|
function cdm_dataportal_view_reference_list($pageNumber){
|
1111
|
$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
|
1112
|
return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
|
1113
|
}
|
1114
|
|
1115
|
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
|
1116
|
$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
|
1117
|
return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
|
1118
|
}
|
1119
|
|
1120
|
function _load_taxonBase(&$taxonBase){
|
1121
|
if(isset($taxonBase->uuid)){
|
1122
|
$taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name"));
|
1123
|
$taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName"));
|
1124
|
$taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference"));
|
1125
|
}
|
1126
|
}
|
1127
|
|
1128
|
/**
|
1129
|
* similar to the variable_get() function of Drupal, except of thst this function
|
1130
|
* is able to handle arrays correctly. This function is especially useful
|
1131
|
* when dealing with collections of setting form elemens (#tree = true)
|
1132
|
*
|
1133
|
* @param String $variableKey
|
1134
|
* @param String $defaultValueString a sting as for example derived from a CONSTANT
|
1135
|
* @return mixed, usually an array
|
1136
|
*/
|
1137
|
function mixed_variable_get($variableKey, $defaultValueString){
|
1138
|
$systemDefaults = unserialize($defaultValueString);
|
1139
|
$storedSettings = variable_get($variableKey, array());
|
1140
|
if(is_array($storedSettings)){
|
1141
|
$settings = array_merge($systemDefaults, $storedSettings);
|
1142
|
} else {
|
1143
|
$settings = $systemDefaults;
|
1144
|
}
|
1145
|
return $settings;
|
1146
|
}
|
1147
|
|
1148
|
/**
|
1149
|
* Loads the subgraph of the given PolytomousKeyNode recursively from the cdm REST service.
|
1150
|
* @param PolytomousKeyNode $polytomousKeyNode passed by reference
|
1151
|
* @return nothing
|
1152
|
*/
|
1153
|
function _load_polytomousKeySubGraph(&$polytomousKeyNode){
|
1154
|
|
1155
|
if(!$polytomousKeyNode){
|
1156
|
return;
|
1157
|
}
|
1158
|
if($polytomousKeyNode->class != "PolytomousKeyNode"){
|
1159
|
drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
|
1160
|
return;
|
1161
|
}
|
1162
|
if(!is_uuid($polytomousKeyNode->uuid)){
|
1163
|
drupal_set_message("_load_polytomousKeySubGraph() invalid type given.", "error");
|
1164
|
return;
|
1165
|
}
|
1166
|
|
1167
|
$polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid);
|
1168
|
|
1169
|
if(!$polytomousKeyNode){
|
1170
|
//drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error");
|
1171
|
return;
|
1172
|
}
|
1173
|
|
1174
|
// load children
|
1175
|
foreach($polytomousKeyNode->children as &$childNode){
|
1176
|
_load_polytomousKeySubGraph($childNode);
|
1177
|
}
|
1178
|
|
1179
|
// load subkey
|
1180
|
$polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey"));
|
1181
|
|
1182
|
// load taxon
|
1183
|
$polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon"));
|
1184
|
_load_taxonBase($polytomousKeyNode->taxon);
|
1185
|
return;
|
1186
|
}
|
1187
|
|
1188
|
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid){
|
1189
|
$polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
|
1190
|
|
1191
|
$sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
|
1192
|
if(is_array($sourcePager->records)){
|
1193
|
$polytomousKey->sources = $sourcePager->records;
|
1194
|
//$polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "sources"));
|
1195
|
}
|
1196
|
|
1197
|
$annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, "annotations"));
|
1198
|
if(is_array($annotationPager->records)){
|
1199
|
$polytomousKey->annotations = $annotationPager->records;
|
1200
|
}
|
1201
|
|
1202
|
_load_polytomousKeySubGraph($polytomousKey->root);
|
1203
|
return theme('cdm_polytomousKey_page', $polytomousKey);
|
1204
|
}
|
1205
|
|
1206
|
/**
|
1207
|
* The taxon page gives detailed information on a taxon, it shows:
|
1208
|
* - Taxon name
|
1209
|
* - Full list of synonyms homotypic synonyms on top, followed by the
|
1210
|
* heterotypic and finally followed by misapplied names.
|
1211
|
* The list is ordered historically.
|
1212
|
* - All description associated with the taxon.
|
1213
|
*
|
1214
|
* @param $uuid
|
1215
|
* @param $chapter name of the part to display,
|
1216
|
* valid values are: 'description', 'images', 'synonymy', 'specimens', 'all'
|
1217
|
* @return unknown_type
|
1218
|
*/
|
1219
|
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all', $synonym_uuid = null){
|
1220
|
// display the page for the taxon defined by $uuid
|
1221
|
set_last_taxon_page_tab(arg(3));
|
1222
|
$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter, $synonym_uuid);
|
1223
|
return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
|
1224
|
}
|
1225
|
|
1226
|
/**
|
1227
|
* @param $uuid
|
1228
|
* @param $chapter name of the part to display,
|
1229
|
* valid values are: 'description', 'images', 'synonymy', 'all'
|
1230
|
* @return unknown_type
|
1231
|
*/
|
1232
|
function cdm_dataportal_taxon_view($uuid, $chapter = 'all', $synonym_uuid = null){
|
1233
|
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
|
1234
|
if(!$taxon){
|
1235
|
drupal_set_title(t('Taxon does not exist'));
|
1236
|
return false;
|
1237
|
}
|
1238
|
|
1239
|
$taxonpage->title = theme('cdm_taxon_page_title', $taxon, $uuid, $synonym_uuid);
|
1240
|
|
1241
|
// check if the taxon id contained in the currently selected tree
|
1242
|
$taxon_in_current_tree = taxon_in_current_tree($uuid);
|
1243
|
$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
|
1244
|
if(!$taxon_in_current_tree){
|
1245
|
if(count($taxon_nodes) == 0){
|
1246
|
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
|
1247
|
,'warning');
|
1248
|
} else {
|
1249
|
$trees = '';
|
1250
|
foreach($taxon_nodes as $node){
|
1251
|
$trees .= ($trees?', ':'').'<strong>'.$node->classification->titleCache.'</strong>';
|
1252
|
|
1253
|
}
|
1254
|
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
|
1255
|
.(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
|
1256
|
, 'warning');
|
1257
|
}
|
1258
|
}
|
1259
|
|
1260
|
// render the taxon page
|
1261
|
$taxonpage->content = theme('cdm_taxon_page', $taxon, $chapter);
|
1262
|
|
1263
|
return $taxonpage;
|
1264
|
}
|
1265
|
|
1266
|
/**
|
1267
|
* The function returns a name page as a drupal node ready to be renderized by drupal.
|
1268
|
* The node page show the taxon name title and the list of taxon related with such taxon
|
1269
|
* name on the tree already in used.
|
1270
|
* @param $taxon_name_uuid A taxon name uuid
|
1271
|
* @return The formatted name page as node
|
1272
|
*/
|
1273
|
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
|
1274
|
$taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
|
1275
|
return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
|
1276
|
}
|
1277
|
|
1278
|
/**
|
1279
|
* The function genates a object ready to be transformated to a node
|
1280
|
* in order to show as a drupal node
|
1281
|
* @param $taxon_name_uuid
|
1282
|
* @return the object with the page content and title
|
1283
|
*/
|
1284
|
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
|
1285
|
//getting the full taxonname object from the server
|
1286
|
$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
|
1287
|
if(!$taxon_name){
|
1288
|
drupal_set_title(t('Taxon name does not exist'));
|
1289
|
return false;
|
1290
|
}
|
1291
|
//searching for all the taxa connected with the taxon name on the tree in used
|
1292
|
$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
|
1293
|
$request_params = array();
|
1294
|
$request_params['query'] = $name_cache;
|
1295
|
$request_params['tree'] = get_taxonomictree_uuid_selected();
|
1296
|
$request_params['doTaxa'] = 1;
|
1297
|
$request_params['doSynonyms'] = 1;
|
1298
|
$request_params['doTaxaByCommonNames'] = 0;
|
1299
|
$request_params['matchMode'] = "EXACT";
|
1300
|
$taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
|
1301
|
|
1302
|
//removing the name where we come from and
|
1303
|
foreach($taxon_pager->records as $k=>&$taxon){
|
1304
|
if($taxon->uuid == $taxon_to_hide_uuid){
|
1305
|
unset($taxon_pager->records[$k]);
|
1306
|
}
|
1307
|
}
|
1308
|
//show the taxa list or go to the singular taxon
|
1309
|
if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
|
1310
|
reset($taxon_pager->records);
|
1311
|
$singleTaxon = $taxon_pager->records[0];
|
1312
|
if($singleTaxon->class != "Taxon"){
|
1313
|
// it is a Synonym -> look for the accepted
|
1314
|
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid, get_taxonomictree_uuid_selected()));
|
1315
|
if($synonym_uuid){
|
1316
|
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
|
1317
|
}else {
|
1318
|
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $singleTaxon->uuid);
|
1319
|
}
|
1320
|
}else{
|
1321
|
// it is an accepted taxon
|
1322
|
if($synonym_uuid){
|
1323
|
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
|
1324
|
}else{
|
1325
|
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid);
|
1326
|
}
|
1327
|
}
|
1328
|
}else{ //more than one taxa case
|
1329
|
$taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
|
1330
|
if($taxon_pager->records){
|
1331
|
$taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
|
1332
|
}else{
|
1333
|
$taxon_name_page->content = 'This name has no taxa';
|
1334
|
}
|
1335
|
return $taxon_name_page;
|
1336
|
}
|
1337
|
}
|
1338
|
|
1339
|
function cdm_dataportal_view_search_advanced(){
|
1340
|
|
1341
|
drupal_set_title(t('Advanced search'));
|
1342
|
|
1343
|
$searchForm = cdm_dataportal_search_taxon_form(true);
|
1344
|
|
1345
|
return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
|
1346
|
|
1347
|
}
|
1348
|
|
1349
|
/**
|
1350
|
*
|
1351
|
* future extensions to meet palmweb mockup requirements:
|
1352
|
* - habitat
|
1353
|
* - uses
|
1354
|
* - conservation status
|
1355
|
* - locality / tdwg region
|
1356
|
*/
|
1357
|
function cdm_dataportal_view_search_taxon(){
|
1358
|
|
1359
|
$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
|
1360
|
|
1361
|
$request_params = cdm_dataportal_search_form_request();
|
1362
|
$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
|
1363
|
|
1364
|
$search_params = $_REQUEST;
|
1365
|
unset($search_params['q']);
|
1366
|
return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
|
1367
|
}
|
1368
|
|
1369
|
|
1370
|
function cdm_view_xml2json(){
|
1371
|
$file = arg(2);
|
1372
|
$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
|
1373
|
return xml2json::transformXmlStringToJson($datastr);
|
1374
|
}
|
1375
|
|
1376
|
/* ====================== other functions ====================== */
|
1377
|
|
1378
|
|
1379
|
/**
|
1380
|
* Creates a URL to the taxon page specified by the $uuid parameter.
|
1381
|
* The URL will be prepended with a path element to a specific taxon page tab.
|
1382
|
*
|
1383
|
* This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can
|
1384
|
* be set globally in the administrative settings or individually in the user
|
1385
|
* profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB
|
1386
|
* the last portal will stay on this last tab.
|
1387
|
*
|
1388
|
* A third option is offerered by the $page_tab parameter which allows overwriting this
|
1389
|
* internal mechanism by a specific value.
|
1390
|
*
|
1391
|
* @param String $uuid the UUID of the taxon
|
1392
|
* @param String $page_tab overwriting the preset mechanism by defining specific valuefor the taxon page tab.
|
1393
|
*
|
1394
|
* @return the URL
|
1395
|
*/
|
1396
|
function path_to_taxon($uuid, $page_tab = false){
|
1397
|
|
1398
|
$tab = get_default_taxon_tab();
|
1399
|
$values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB);
|
1400
|
|
1401
|
if(!$uuid) return false;
|
1402
|
|
1403
|
if($page_tab){
|
1404
|
return 'cdm_dataportal/taxon/'.$uuid . '/' . $page_tab;
|
1405
|
} else if (!$tab){
|
1406
|
return 'cdm_dataportal/taxon/'.$uuid;
|
1407
|
}else if(get_last_taxon_page_tab() && $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]){
|
1408
|
return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
|
1409
|
} else {
|
1410
|
return 'cdm_dataportal/taxon/'.$uuid . '/' . strtolower($tab);
|
1411
|
}
|
1412
|
}
|
1413
|
|
1414
|
function uri_to_synonym($synonymUuid, $acceptedUuid){
|
1415
|
$acceptedPath = path_to_taxon($acceptedUuid, "synonymy");
|
1416
|
return url($acceptedPath, 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid, $synonymUuid);
|
1417
|
}
|
1418
|
|
1419
|
function path_to_key($keyType, $keyUuid){
|
1420
|
if(!$keyUuid || !$keyType) return false;
|
1421
|
$keyType{0} = strtolower($keyType{0});
|
1422
|
return "cdm_dataportal/".$keyType."/$keyUuid";
|
1423
|
}
|
1424
|
|
1425
|
function path_to_reference($uuid){
|
1426
|
if(!$uuid) return false;
|
1427
|
return 'cdm_dataportal/reference/'.$uuid;
|
1428
|
}
|
1429
|
|
1430
|
function path_to_name($name_uuid){
|
1431
|
$res = false;
|
1432
|
if($name_uuid){
|
1433
|
$res = 'cdm_dataportal/name/'.$name_uuid;
|
1434
|
}
|
1435
|
return $res;
|
1436
|
}
|
1437
|
|
1438
|
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
|
1439
|
if(!$uuid) return false;
|
1440
|
$out = 'cdm_dataportal/media/'.$uuid;
|
1441
|
if($representaion_uuid){
|
1442
|
$out .= '/'.$representaion_uuid;
|
1443
|
if($partId !== false){
|
1444
|
$out .= '/'.$partId;
|
1445
|
}
|
1446
|
}
|
1447
|
return $out;
|
1448
|
}
|
1449
|
|
1450
|
/**
|
1451
|
* Compares thisRank with thatRank.
|
1452
|
* Returns a negative integer, zero, or a positive integer
|
1453
|
* as the of thisRank is higher than, equal to, or lower than thatRank.
|
1454
|
* e.g:
|
1455
|
* <ul>
|
1456
|
* <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
|
1457
|
* <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
|
1458
|
* <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
|
1459
|
* </ul>
|
1460
|
* <p>
|
1461
|
* This compare logic of the underlying webservice is the
|
1462
|
* <b>inverse logic</b> of the the one implemented in
|
1463
|
* java.lang.Comparable#compareTo(java.lang.Object)
|
1464
|
* @param $thisRankUuid
|
1465
|
* @param $thatRankUuid
|
1466
|
* @return a negative integer, zero, or a positive integer
|
1467
|
* as the thisRank is lower than, equal to, or higher than thatRank
|
1468
|
*/
|
1469
|
function rank_compare($thisRankUuid, $thatRankUuid){
|
1470
|
$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
|
1471
|
return $result->Integer;
|
1472
|
}
|
1473
|
|
1474
|
/**
|
1475
|
* Composes an HTML element class attribute value composed of
|
1476
|
* the shortname of the cdm class and the uuid of the entity.
|
1477
|
* This class attribute should be used whereever an cdm-entity is rendered.
|
1478
|
*
|
1479
|
* These according class selectors in css must be escaped, eg:
|
1480
|
* .cdm\:TextData
|
1481
|
*
|
1482
|
* @param $cdmEntity
|
1483
|
*/
|
1484
|
function html_class_atttibute_ref($cdmEntity){
|
1485
|
|
1486
|
if(is_cdm_entity($cdmEntity)) {
|
1487
|
return "cdm:".$cdmEntity->class." uuid:".$cdmEntity->uuid;
|
1488
|
}
|
1489
|
}
|
1490
|
|
1491
|
|
1492
|
/**
|
1493
|
* Preprocess the taggedName to normalize newly introduced tagtypes like hybridSign, separator, .. more?
|
1494
|
*
|
1495
|
* @param unknown_type $taggedTextList
|
1496
|
*/
|
1497
|
function normalize_TaggedName(&$taggedTextList){
|
1498
|
|
1499
|
if(is_array($taggedTextList)) {
|
1500
|
|
1501
|
// first pass: rename
|
1502
|
for($i = 0; $i < count($taggedTextList); $i++){
|
1503
|
|
1504
|
if($taggedTextList[$i]->type == "hybridSign"){
|
1505
|
$taggedTextList[$i]->type = "name";
|
1506
|
}
|
1507
|
|
1508
|
}
|
1509
|
|
1510
|
// second pass: resolve separators
|
1511
|
$taggedNameListNew = array();
|
1512
|
for($i = 0; $i < count($taggedTextList); $i++){
|
1513
|
|
1514
|
if($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator" ) {
|
1515
|
|
1516
|
if($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type){
|
1517
|
$taggedName = $taggedTextList[$i];
|
1518
|
$taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text;
|
1519
|
$taggedNameListNew[] = $taggedName;
|
1520
|
++$i;
|
1521
|
++$i;
|
1522
|
}
|
1523
|
} else {
|
1524
|
$taggedNameListNew[] = $taggedTextList[$i];
|
1525
|
}
|
1526
|
}
|
1527
|
$taggedTextList = $taggedNameListNew;
|
1528
|
}
|
1529
|
}
|
1530
|
|
1531
|
/**
|
1532
|
* Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
|
1533
|
* If the taggename if empty the fullname will be returned.
|
1534
|
*
|
1535
|
* @param unknown_type $Name or TreeNode
|
1536
|
* @return string
|
1537
|
*/
|
1538
|
function cdm_dataportal_shortname_of($name){
|
1539
|
$nameStr = '';
|
1540
|
|
1541
|
normalize_TaggedName($name->taggedTitle);
|
1542
|
|
1543
|
// get all tagged text tokens of the scientific name
|
1544
|
foreach($name->taggedTitle as $tagtxt){
|
1545
|
if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
|
1546
|
$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
|
1547
|
}
|
1548
|
}
|
1549
|
$nameStr = trim($nameStr);
|
1550
|
|
1551
|
if($nameStr){
|
1552
|
// do not return short names for these
|
1553
|
if ($name->unplaced || $name->excluded){
|
1554
|
return $nameStr;
|
1555
|
}
|
1556
|
/*
|
1557
|
* - 1st capture group (^[a-zA-Z]): Fist letter of uninomial
|
1558
|
* - second capture group ([a-zA-Z]+): remaining letters of uninomial
|
1559
|
* - third capture group (\s+[^(\x2E]+\s+.+$): letters of name,
|
1560
|
* but only matching if no '(' or '.' in second word of name, ( \x2E = '.' )
|
1561
|
* OR only one specific epithet \s+[a-zA-Z]+$
|
1562
|
*/
|
1563
|
$pattern = '/(^[a-zA-Z])([a-zA-Z]+)(\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$)/';
|
1564
|
if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)){
|
1565
|
return $matches[1][0] . "." . $matches[3][0];
|
1566
|
} else {
|
1567
|
return $nameStr;
|
1568
|
}
|
1569
|
} else {
|
1570
|
return $name->titleCache;
|
1571
|
}
|
1572
|
}
|
1573
|
|
1574
|
|
1575
|
/**
|
1576
|
* Check if a taxon is accepted by the current taxonomic tree
|
1577
|
*
|
1578
|
* @param Taxon $taxon
|
1579
|
* @return true if $taxon is accepted, false otherwise
|
1580
|
*/
|
1581
|
|
1582
|
function _cdm_dataportal_acceptedByCurrentView($taxon){
|
1583
|
|
1584
|
$defaultTreeUuid = get_taxonomictree_uuid_selected();
|
1585
|
|
1586
|
if(isset($taxon->taxonNodes)) {
|
1587
|
$taxonNodes = $taxon->taxonNodes;
|
1588
|
} else {
|
1589
|
$taxonNodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid);
|
1590
|
}
|
1591
|
|
1592
|
if($taxon->class == "Taxon" && isset($taxonNodes)){
|
1593
|
foreach($taxonNodes as $node){
|
1594
|
if(is_object($node->classification)){
|
1595
|
if($node->classification->uuid == $defaultTreeUuid) {
|
1596
|
return true;
|
1597
|
}
|
1598
|
} else {
|
1599
|
if($node->classification == $defaultTreeUuid) {
|
1600
|
return true;
|
1601
|
}
|
1602
|
}
|
1603
|
}
|
1604
|
}
|
1605
|
|
1606
|
return false;
|
1607
|
}
|
1608
|
|
1609
|
/**@Deprecated
|
1610
|
*
|
1611
|
*/
|
1612
|
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
|
1613
|
$pstr = '';
|
1614
|
foreach($parameters as $key=>$value){
|
1615
|
if(is_array($value)){
|
1616
|
|
1617
|
} else {
|
1618
|
$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
|
1619
|
}
|
1620
|
}
|
1621
|
return $pstr;
|
1622
|
}
|
1623
|
|
1624
|
/**
|
1625
|
* workaround for missing original source type, idNamespace is always set in these cases
|
1626
|
* @param unknown_type $source
|
1627
|
* @return unknown_type
|
1628
|
*/
|
1629
|
function _is_original_source_type($source){
|
1630
|
return !$source->idNamespace && strlen($source->idNamespace) == 0;
|
1631
|
}
|
1632
|
|
1633
|
function _is_invers_taxonRelationship($taxonRelationship, $focusedTaxon){
|
1634
|
return $taxonRelationship->toTaxon->uuid == $focusedTaxon->uuid;
|
1635
|
}
|
1636
|
|
1637
|
|
1638
|
|
1639
|
/**
|
1640
|
* The function read the metadata info such title or artist of a media file. The
|
1641
|
* function tries at first to get all the info from the file metadata and if it is
|
1642
|
* not avaible look at the media file info stored at the database.
|
1643
|
* @param $media The media file
|
1644
|
* @return array The array with the avilable specified metadata info.
|
1645
|
* TODO rename to read_media_metadata() and move to *.module
|
1646
|
*/
|
1647
|
function cdm_read_media_metadata($media){
|
1648
|
|
1649
|
$metadata_caption = array('title' => '', //media_metadata and media
|
1650
|
'artist' => '', //media_metadata and media
|
1651
|
'rights', //media_metadata and media
|
1652
|
'location', //media_metadata
|
1653
|
'filename' => '', //media
|
1654
|
'mediacreated' => '', //media
|
1655
|
'description' => ''); //media
|
1656
|
|
1657
|
//getting the media metadata
|
1658
|
$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
|
1659
|
$media_metadata_aux = (array) $media_metadata;
|
1660
|
|
1661
|
//filename
|
1662
|
if(isset($media->representations[0]->parts[0]->uri)){
|
1663
|
$fileUri = $media->representations[0]->parts[0]->uri;
|
1664
|
$filename = substr($fileUri, strrpos($fileUri, "/")+1);
|
1665
|
$metadata_caption['filename'] = $filename;
|
1666
|
}
|
1667
|
else{
|
1668
|
$metadata_caption['filename'] = '';
|
1669
|
}
|
1670
|
|
1671
|
//title
|
1672
|
if ($media_metadata->ObjectName) {
|
1673
|
$metadata_caption['title'] = $media_metadata->ObjectName;
|
1674
|
} else if ($media_metadata_aux['Object Name']){
|
1675
|
$metadata_caption['title'] = $media_metadata_aux['Object Name'];
|
1676
|
} else if ($media->title_L10n){
|
1677
|
$metadata_caption['title'] = $media->title_L10n;
|
1678
|
} else if ($media->titleCache){
|
1679
|
$metadata_caption['title'] = $media->titleCache;
|
1680
|
}
|
1681
|
|
1682
|
// append description to title
|
1683
|
if ($media->description_L10n) {
|
1684
|
$metadata_caption['title'] .= '<span class="media-description">' . $media->description_L10n . '<span>';
|
1685
|
}
|
1686
|
|
1687
|
//artist
|
1688
|
if ($media_metadata->Artist){
|
1689
|
$metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
|
1690
|
}
|
1691
|
elseif ($media->artist->titleCache){
|
1692
|
$metadata_caption['artist'] = $media->artist->titleCache;
|
1693
|
}
|
1694
|
|
1695
|
//copyright
|
1696
|
$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
|
1697
|
'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
|
1698
|
if ($media_metadata->Copyright)
|
1699
|
$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
|
1700
|
elseif ($media->rights){
|
1701
|
foreach($media->rights as $right){
|
1702
|
switch($right->term->uuid){
|
1703
|
case UUID_RIGHTS_LICENCE:
|
1704
|
$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
|
1705
|
$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
|
1706
|
$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
|
1707
|
$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
|
1708
|
break;
|
1709
|
case UUID_RIGHTS_COPYRIGHT:
|
1710
|
$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
|
1711
|
break;
|
1712
|
}
|
1713
|
}
|
1714
|
} else {
|
1715
|
$metadata_caption['rights']['agentNames'][] = '';
|
1716
|
}
|
1717
|
|
1718
|
//filling the description (though there is no description in the db???)
|
1719
|
//$metadata_caption['description'] = $media->description_L10n;
|
1720
|
|
1721
|
//location
|
1722
|
$metadata_caption['location'] = array();
|
1723
|
$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
|
1724
|
$metadata_caption['location']['city'] = $media_metadata->City;
|
1725
|
$metadata_caption['location']['province'] = $media_metadata->Province;
|
1726
|
$metadata_caption['location']['country'] = $media_metadata->Country;
|
1727
|
|
1728
|
/*
|
1729
|
//creation date
|
1730
|
if($media_metadata["Modify Date"])
|
1731
|
$metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
|
1732
|
else
|
1733
|
$metadata_caption['mediacreated'] = $media->created;
|
1734
|
*/
|
1735
|
//returned value
|
1736
|
return $metadata_caption;
|
1737
|
}
|
1738
|
|
1739
|
/**
|
1740
|
* This function collects all the media from a list of description elements
|
1741
|
* and return them as an Array.
|
1742
|
*
|
1743
|
* @param $descriptionElementes The description elements
|
1744
|
* @return Array The output with all the media
|
1745
|
*/
|
1746
|
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
|
1747
|
//variables
|
1748
|
$outArrayOfMedia = array(); //return value
|
1749
|
//implementation
|
1750
|
if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
|
1751
|
foreach($descriptionElements as $descriptionElement){
|
1752
|
if(is_array($descriptionElement->media)){
|
1753
|
foreach($descriptionElement->media as $media){
|
1754
|
if(is_object($media)){
|
1755
|
$outArrayOfMedia[] = $media;
|
1756
|
}
|
1757
|
}
|
1758
|
}
|
1759
|
}
|
1760
|
}
|
1761
|
return $outArrayOfMedia;
|
1762
|
}
|
1763
|
|
1764
|
/**
|
1765
|
*
|
1766
|
* @param - $cdmBase_list @param $cdmBase_list an array of CdmBase instances or a single instance
|
1767
|
* @param - $footnote_list_key
|
1768
|
*/
|
1769
|
function cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key = null){
|
1770
|
static $annotations_types_filter;
|
1771
|
|
1772
|
if(!$annotations_types_filter) {
|
1773
|
unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
|
1774
|
}
|
1775
|
|
1776
|
$footNoteKeys = array();
|
1777
|
|
1778
|
//is argument cdmBase an array?
|
1779
|
if (!is_array($cdmBase_list)){
|
1780
|
$cdmBase_array = array();
|
1781
|
$cdmBase_array[] = $cdmBase_list;
|
1782
|
}else{
|
1783
|
$cdmBase_array = $cdmBase_list;
|
1784
|
}
|
1785
|
|
1786
|
//getting the key for the footnotemanager
|
1787
|
if( $footnote_list_key ){
|
1788
|
$footnoteListKey = $footnote_list_key;
|
1789
|
}else{
|
1790
|
$footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
|
1791
|
}
|
1792
|
|
1793
|
//adding the footnotes keys
|
1794
|
$annotations_types_filter = unserialize(ANNOTATIONS_TYPES_AS_FOOTNOTES_DEFAULT);
|
1795
|
foreach($cdmBase_array as $cdmBase_element){
|
1796
|
$annotations = cdm_ws_getAnnotationsFor($cdmBase_element, variable_get('annotations_types_as_footnotes', $annotations_types_filter));
|
1797
|
if(is_array($annotations)){
|
1798
|
foreach($annotations as $annotation){
|
1799
|
$footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
|
1800
|
}
|
1801
|
}
|
1802
|
}
|
1803
|
|
1804
|
return $footNoteKeys;
|
1805
|
}
|
1806
|
|
1807
|
function cdm_dynabox($label, $content_url, $theme, $link_alt_text, $enclosingtags = array('li', 'ul')){
|
1808
|
|
1809
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
|
1810
|
|
1811
|
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
|
1812
|
$out .= '<'. $enclosingtags[0]. ' class="dynabox"><a href="'.$content_url.'" class="label" alt="'.t($link_alt_text).'">'.$label.'</a>';
|
1813
|
$out .= '<'. $enclosingtags[1]. ' class="dynabox_content" title="'.$cdm_proxy_url.'"><'. $enclosingtags[0]. '><img class="loading" src="'.drupal_get_path('module', 'cdm_dataportal').'/images/loading_circle_grey_16.gif" style="display:none;"></'. $enclosingtags[0]. '></'. $enclosingtags[1]. '>';
|
1814
|
$out .= '</'. $enclosingtags[0]. '>';
|
1815
|
return $out;
|
1816
|
}
|
1817
|
|
1818
|
/**
|
1819
|
* returns true if the given $featureNode or any of its subordinate nodes contains
|
1820
|
* at least one non empty TextData or at least one DescriptionElement of an other type.
|
1821
|
* A TextData element holding a multilanguageText or a source reference is considered to be not empty.
|
1822
|
*
|
1823
|
* @param unknown_type $featureNode A heature node as produced by the function _mergeFeatureTreeDescriptions()
|
1824
|
*/
|
1825
|
function hasFeatureNodeDescriptionElements($featureNode) {
|
1826
|
|
1827
|
if(is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) {
|
1828
|
foreach ($featureNode->descriptionElements as $descriptionElement) {
|
1829
|
if($descriptionElement->class != "TextData" || $descriptionElement->multilanguageText_L10n->text || isset($descriptionElement->sources[0]) ){
|
1830
|
return true;
|
1831
|
}
|
1832
|
}
|
1833
|
} else if(is_array($featureNode->children)) {
|
1834
|
foreach ($featureNode->children as $child) {
|
1835
|
if(hasFeatureNodeDescriptionElements($child)){
|
1836
|
return true;
|
1837
|
}
|
1838
|
}
|
1839
|
}
|
1840
|
return false;
|
1841
|
}
|
1842
|
|