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
|
|
19
|
require_once('theme/cdm_dataportal.common.theme');
|
20
|
require_once('theme/cdm_dataportal.descriptions.theme');
|
21
|
require_once('theme/cdm_dataportal.media.theme');
|
22
|
require_once('theme/cdm_dataportal.occurrence.theme');
|
23
|
require_once('theme/cdm_dataportal.page.theme');
|
24
|
require_once('theme/cdm_dataportal.taxon.theme');
|
25
|
require_once('theme/cdm_dataportal.name.theme');
|
26
|
require_once('theme/cdm_dataportal.references.theme');
|
27
|
|
28
|
require_once('classes/footnotemanager.php');
|
29
|
require_once('classes/footnote.php');
|
30
|
require_once('classes/footnotekey.php');
|
31
|
require_once('classes/renderhints.php');
|
32
|
|
33
|
|
34
|
|
35
|
function _add_js_progressbar(){
|
36
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.progressbar/js/jquery.progressbar.js');
|
37
|
}
|
38
|
|
39
|
function _add_js_treeselector(){
|
40
|
//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js');
|
41
|
drupal_add_js("
|
42
|
if (Drupal.jsEnabled) {
|
43
|
$(document).ready(function() {
|
44
|
$('#cdm-taxonomictree-selector-form #edit-val').change(function () {
|
45
|
$('#cdm-taxonomictree-selector-form').submit();
|
46
|
});
|
47
|
|
48
|
});
|
49
|
}", 'inline');
|
50
|
}
|
51
|
|
52
|
function _add_js_openlayers_map(){
|
53
|
|
54
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/OpenLayers/OpenLayers.js', 'core', 'header');
|
55
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/openlayers_map.js');
|
56
|
|
57
|
$gmap_api_key = variable_get('gmap_api_key', 'ABQIAAAAFho6eHAcUOTHLmH9IYHAeBRi_j0U6kJrkFvY4-OX2XYmEAa76BTsyMmEq-tn6nFNtD2UdEGvfhvoCQ');
|
58
|
|
59
|
$baseLayers = variable_get('baselayers', array('metacarta_vmap0', 'PREFERRED' => 'metacarta_vmap0'));
|
60
|
$layerNames = '';
|
61
|
foreach($baseLayers as $layerName => $layerLabel){
|
62
|
if($layerName == 'PREFERRED'){
|
63
|
$preferredLayer = $baseLayers['PREFERRED'];
|
64
|
} else {
|
65
|
$layerNames .= ($layerNames ? ', ': '') . "'$layerName'";
|
66
|
}
|
67
|
}
|
68
|
|
69
|
if( isset($baseLayers['gmap']) || isset($baseLayers['gsat']) || isset($baseLayers['ghyb']) ){
|
70
|
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>');
|
71
|
drupal_set_html_head('<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1" type="text/javascript"></script>');
|
72
|
}
|
73
|
|
74
|
drupal_add_js("
|
75
|
if (Drupal.jsEnabled) {
|
76
|
$(document).ready(function() {
|
77
|
$('#openlayers_map').cdm_openlayers_map('"
|
78
|
.getEDITMapServiceURI()."', {
|
79
|
legendPosition: 3,
|
80
|
displayWidth: '" . variable_get('cdm_dataportal_geoservice_display_width', false) . "',
|
81
|
boundingBox: '" . variable_get('cdm_dataportal_geoservice_bounding_box', false) . "',
|
82
|
distributionOpacity: '" . variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5') . "',
|
83
|
legendOpacity: '" . variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5') . "',
|
84
|
showLayerSwitcher: " . (variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE) ? 'true':'false') . ",
|
85
|
baseLayerNames: [".$layerNames."],
|
86
|
defaultBaseLayerName: '".$preferredLayer."',
|
87
|
});
|
88
|
});
|
89
|
}", 'inline');
|
90
|
|
91
|
}
|
92
|
|
93
|
|
94
|
function get_openlayers_map($width, $occurrenceQuery = false, $distributionQuery = false, $legendFormatQuery = false, $map_caption = false ){
|
95
|
|
96
|
_add_js_openlayers_map();
|
97
|
|
98
|
$out = '<div id="openlayers">';
|
99
|
$out .= '<div id="openlayers_map" class="smallmap"';
|
100
|
$out .= ' style="width: ' . $width . 'px; height:'.( $width / 2).'px"';
|
101
|
if($occurrenceQuery){
|
102
|
|
103
|
//fix $occurrenceQuery
|
104
|
$occurrenceQuery .= '&ms=400,350';
|
105
|
$occurrenceQuery .= '&l=v%3Aatbi%2Ce_w_0';
|
106
|
$occurrenceQuery .= '&legend=0'; //TODO add to cdm service?
|
107
|
|
108
|
$out .= ' occurrenceQuery="'.$occurrenceQuery.'"';
|
109
|
}
|
110
|
if($distributionQuery){
|
111
|
$out .= ' distributionQuery="'.$distributionQuery.'"';
|
112
|
}
|
113
|
if($legendFormatQuery){
|
114
|
$out .= ' legendFormatQuery="'.$legendFormatQuery.'"';
|
115
|
}
|
116
|
$out .= '></div></div>';
|
117
|
|
118
|
// showing map caption
|
119
|
if($map_caption){
|
120
|
$out .= '<div class="distribution_map_caption">' . $map_caption . '</div>' . '<br />'; //FIXME: replace <br> by according css style
|
121
|
$out .= '</div>';
|
122
|
}
|
123
|
return $out;
|
124
|
}
|
125
|
|
126
|
/* ====================== hook implementations ====================== */
|
127
|
|
128
|
/**
|
129
|
* Implementation of hook_help()
|
130
|
*
|
131
|
* Display help and module information
|
132
|
* @param section which section of the site we're displaying help
|
133
|
* @return help text for section
|
134
|
*/
|
135
|
function cdm_dataportal_help($section='') {
|
136
|
|
137
|
$out = '';
|
138
|
switch ($section) {
|
139
|
case "admin/modules#description":
|
140
|
$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
|
141
|
break;
|
142
|
}
|
143
|
return $out;
|
144
|
}
|
145
|
|
146
|
|
147
|
/**
|
148
|
* Implementation of hook_perm()
|
149
|
*
|
150
|
* Valid permissions for this module
|
151
|
* @return array An array of valid permissions for the portfolio module
|
152
|
*/
|
153
|
function cdm_dataportal_perm() {
|
154
|
return array(
|
155
|
'administer cdm_dataportal',
|
156
|
'cdm_dataportal view notes',
|
157
|
//TODO which else permission are required? -> check the WP6 requirements document
|
158
|
);
|
159
|
}
|
160
|
|
161
|
|
162
|
/**
|
163
|
* Implementation of hook_menu()
|
164
|
*/
|
165
|
function cdm_dataportal_menu($may_cache) {
|
166
|
$items = array();
|
167
|
|
168
|
cdm_dataportal_menu_admin($may_cache, $items);
|
169
|
|
170
|
if ($may_cache) {
|
171
|
|
172
|
$items[] = array(
|
173
|
'path' => 'cdm_dataportal/names',
|
174
|
'callback' => 'cdm_dataportal_view_names',
|
175
|
'access' => true,
|
176
|
'type' => MENU_CALLBACK,
|
177
|
);
|
178
|
// optional callback arguments: page
|
179
|
|
180
|
$items[] = array(
|
181
|
'path' => 'cdm_dataportal/taxon',
|
182
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
183
|
'access' => true,
|
184
|
'type' => MENU_CALLBACK,
|
185
|
// expected callback arguments: uuid
|
186
|
);
|
187
|
|
188
|
$items[] = array(
|
189
|
'path' => 'cdm_dataportal/name',
|
190
|
'callback' => 'cdm_dataportal_name_page_view',
|
191
|
'access' => true,
|
192
|
'type' => MENU_CALLBACK,
|
193
|
// expected callback arguments: uuid
|
194
|
);
|
195
|
|
196
|
$items[] = array(
|
197
|
'path' => 'cdm_dataportal/reference',
|
198
|
'callback' => 'cdm_dataportal_view_reference',
|
199
|
'access' => true,
|
200
|
'type' => MENU_CALLBACK,
|
201
|
// expected callback arguments: uuid
|
202
|
);
|
203
|
|
204
|
$items[] = array(
|
205
|
'path' => 'cdm_dataportal/reference/list',
|
206
|
'callback' => 'cdm_dataportal_view_reference_list',
|
207
|
'access' => true,
|
208
|
'type' => MENU_CALLBACK,
|
209
|
// expected callback arguments: uuid
|
210
|
);
|
211
|
|
212
|
$items[] = array(
|
213
|
'path' => 'cdm_dataportal/media',
|
214
|
'callback' => 'cdm_dataportal_view_media',
|
215
|
'access' => true,
|
216
|
'type' => MENU_CALLBACK,
|
217
|
// expected callback arguments: uuid, mediarepresentation_uuid, part_uuid or part#
|
218
|
);
|
219
|
|
220
|
$items[] = array(
|
221
|
'path' => 'cdm_dataportal/search',
|
222
|
'callback' => 'cdm_dataportal_view_search_advanced',
|
223
|
'access' => true,
|
224
|
'type' => MENU_CALLBACK,
|
225
|
);
|
226
|
|
227
|
$items[] = array(
|
228
|
'path' => 'cdm_dataportal/search/taxon',
|
229
|
'callback' => 'cdm_dataportal_view_search_taxon',
|
230
|
'access' => true,
|
231
|
'type' => MENU_CALLBACK,
|
232
|
);
|
233
|
|
234
|
$items[] = array(
|
235
|
'path' => 'cdm/xml2json',
|
236
|
'callback' => 'cdm_view_xml2json',
|
237
|
'access' => true,
|
238
|
'type' => MENU_CALLBACK,
|
239
|
);
|
240
|
|
241
|
} else {
|
242
|
// may not cache
|
243
|
// --- local tasks for Taxon
|
244
|
$items[] = array(
|
245
|
'path' => 'cdm_dataportal/name/'.arg(2),
|
246
|
//'callback' => 'cdm_dataportal_view_name',
|
247
|
'callback' => 'cdm_dataportal_name_page_view',
|
248
|
'callback arguments' => array(arg(2), arg(3), arg(4)),
|
249
|
'access' => true,
|
250
|
'type' => MENU_CALLBACK,
|
251
|
);
|
252
|
|
253
|
if(variable_get('cdm_dataportal_taxonpage_tabs', 1)) {
|
254
|
|
255
|
$items[] = array(
|
256
|
'path' => 'cdm_dataportal/taxon/'.arg(2),
|
257
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
258
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
259
|
'access' => true,
|
260
|
'type' => MENU_CALLBACK,
|
261
|
'weight' => 1,
|
262
|
'callback arguments' => array(arg(2), "description")
|
263
|
// expected callback arguments: name_uuid
|
264
|
);
|
265
|
|
266
|
$items[] = array(
|
267
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/all',
|
268
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
269
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
270
|
'access' => true,
|
271
|
'type' => MENU_CALLBACK,
|
272
|
'weight' => 2,
|
273
|
'callback arguments' => array(arg(2), "all")
|
274
|
// expected callback arguments: name_uuid
|
275
|
);
|
276
|
|
277
|
$items[] = array(
|
278
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/description',
|
279
|
'title' => theme('cdm_taxonpage_tab', 'General'),
|
280
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
281
|
'access' => true,
|
282
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
283
|
'weight' => 2,
|
284
|
'callback arguments' => array(arg(2), "description")
|
285
|
// expected callback arguments: name_uuid
|
286
|
);
|
287
|
|
288
|
$items[] = array(
|
289
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/synonymy',
|
290
|
'title' => theme('cdm_taxonpage_tab', 'Synonymy'),
|
291
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
292
|
'access' => true,
|
293
|
'type' => MENU_LOCAL_TASK,
|
294
|
'weight' => 3,
|
295
|
'callback arguments' => array(arg(2), "synonymy")
|
296
|
// expected callback arguments: name_uuid
|
297
|
);
|
298
|
|
299
|
$items[] = array(
|
300
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/images',
|
301
|
'title' => theme('cdm_taxonpage_tab', 'Images'),
|
302
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
303
|
'access' => true,
|
304
|
'type' => MENU_LOCAL_TASK,
|
305
|
'weight' => 4,
|
306
|
'callback arguments' => array(arg(2), "images")
|
307
|
// expected callback arguments: name_uuid
|
308
|
);
|
309
|
$items[] = array(
|
310
|
'path' => 'cdm_dataportal/taxon/'.arg(2).'/specimens',
|
311
|
'title' => theme('cdm_taxonpage_tab', 'Specimens'),
|
312
|
'callback' => 'cdm_dataportal_taxon_page_view',
|
313
|
'access' => true,
|
314
|
'type' => MENU_LOCAL_TASK,
|
315
|
'weight' => 5,
|
316
|
'callback arguments' => array(arg(2), "specimens")
|
317
|
// expected callback arguments: name_uuid
|
318
|
);
|
319
|
|
320
|
}
|
321
|
}
|
322
|
|
323
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
|
324
|
//drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print');
|
325
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_screen.css', 'screen');
|
326
|
|
327
|
return $items;
|
328
|
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* Implementation of hook_block()
|
333
|
*
|
334
|
* Provides the following blocks:
|
335
|
* 0: list of links useful during development
|
336
|
*
|
337
|
* @param String $op
|
338
|
* @param int $delta
|
339
|
*/
|
340
|
function cdm_dataportal_block($op='list', $delta=0) {
|
341
|
// listing of blocks, such as on the admin/block page
|
342
|
if ($op == "list") {
|
343
|
//$block[0]["info"] = t("CDM DataPortal DevLinks");
|
344
|
// $block[1]["info"] = t("CDM DataPortal Credits");
|
345
|
$block[2]["info"] = t("CDM Search Taxa");
|
346
|
//$block[3]["info"] = t("CDM Filters");
|
347
|
$block[4]["info"] = t("CDM Dataportal Print");
|
348
|
return $block;
|
349
|
}
|
350
|
else if ($op == 'view') {
|
351
|
switch($delta){
|
352
|
// case 1:
|
353
|
// $block['subject'] = t('Credits');
|
354
|
// $block['content'] = theme('cdm_credits');
|
355
|
// return $block;
|
356
|
case 2:
|
357
|
$block['subject'] = t('Search taxa');
|
358
|
$block['content'] = drupal_get_form('cdm_dataportal_search_taxon_form');
|
359
|
$block['content'] .= '<div>'.l('Advanced Search', '/cdm_dataportal/search').'</div>';
|
360
|
return $block;
|
361
|
case 4:
|
362
|
$block['subject'] = t('<none>');
|
363
|
$block['content'] = theme('cdm_print_button');;
|
364
|
return $block;
|
365
|
}
|
366
|
}
|
367
|
}
|
368
|
|
369
|
|
370
|
|
371
|
/*
|
372
|
function cdm_dataportal_session_clear($cdm_ws_uri_update = false){
|
373
|
$_SESSION['cdm'] = null;
|
374
|
if(is_string($cdm_ws_uri_update)){
|
375
|
$_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update);
|
376
|
}
|
377
|
}
|
378
|
|
379
|
function cdm_dataportal_session_validate(){
|
380
|
|
381
|
if(!isset($_SESSION['cdm']['ws_uri'])){
|
382
|
$_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', false));
|
383
|
} else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', false)){
|
384
|
cdm_dataportal_session_clear(variable_get('cdm_webservice_url', false));
|
385
|
}
|
386
|
}
|
387
|
*/
|
388
|
|
389
|
function cdm_dataportal_search_taxon_form($advancedForm = false){
|
390
|
|
391
|
$preset_query = (isset($_SESSION['cdm']['search']['query']) ? $_SESSION['cdm']['search']['query'] : '');
|
392
|
$preset_doTaxa = (isset($_SESSION['cdm']['search']['doTaxa']) ? 1 : 0);
|
393
|
$preset_doSynonyms = (isset($_SESSION['cdm']['search']['doSynonyms']) ? 1 : 0);
|
394
|
$preset_doTaxaByCommonNames = (isset($_SESSION['cdm']['search']['doTaxaByCommonNames']) ? 1 : 0);
|
395
|
$tdwg_level_select = (isset($_SESSION['cdm']['search']['tdwg_level_select']) ? $_SESSION['cdm']['search']['tdwg_level_select'] : 2);
|
396
|
$selected_areas = (isset($_SESSION['cdm']['search']['area']) ? $_SESSION['cdm']['search']['area'] : false);
|
397
|
|
398
|
$url = 'cdm_dataportal/search/taxon';
|
399
|
$form['#method'] = 'get';
|
400
|
$form['#process'] = array('cdm_dataportal_search_process' => array());
|
401
|
$form['#action'] = url($url, NULL, NULL, true);
|
402
|
|
403
|
$form['query'] = array(
|
404
|
'#delta' => 0,
|
405
|
'#type' => 'textfield',
|
406
|
'#size' => 20,
|
407
|
'#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')),
|
408
|
'#value' => $preset_query,
|
409
|
);
|
410
|
|
411
|
$form['search'] = array(
|
412
|
'#delta' => 1,
|
413
|
'#tree' => true,
|
414
|
//'#type' => $advancedForm ? 'fieldset': 'hidden',
|
415
|
'#title' => t('Options')
|
416
|
);
|
417
|
|
418
|
$form['search']['tree'] = array(
|
419
|
'#delta' => -1,
|
420
|
'#type' => 'hidden',
|
421
|
'#value' => get_taxonomictree_uuid_selected()
|
422
|
);
|
423
|
|
424
|
|
425
|
// clean URL get forms breaks if we don't give it a 'q'.
|
426
|
if (!(bool)variable_get('clean_url', '0')) {
|
427
|
$form['search']['q'] = array(
|
428
|
'#delta' => -1,
|
429
|
'#type' => 'hidden',
|
430
|
'#value' => $url,
|
431
|
'#name' => 'q',
|
432
|
);
|
433
|
}
|
434
|
|
435
|
$form['search']['pageSize'] = array(
|
436
|
'#delta' => -1,
|
437
|
'#type' => 'hidden',
|
438
|
'#value' => variable_get('cdm_dataportal_search_items_on_page', 25)
|
439
|
);
|
440
|
|
441
|
if($advancedForm){
|
442
|
// general search parameters
|
443
|
$form['search']['doTaxa'] = array(
|
444
|
'#delta' => 2,
|
445
|
'#type' => 'checkbox',
|
446
|
'#title' => t('Search for accepted taxa'),
|
447
|
'#value' => $preset_doTaxa
|
448
|
);
|
449
|
$form['search']['doSynonyms'] = array(
|
450
|
'#delta' => 3,
|
451
|
'#type' => 'checkbox',
|
452
|
'#title' => t('Search for synonyms'),
|
453
|
'#value' => $preset_doSynonyms
|
454
|
);
|
455
|
$form['search']['doTaxaByCommonNames'] = array(
|
456
|
'#delta' => 4,
|
457
|
'#type' => 'checkbox',
|
458
|
'#title' => t('Search for common names'),
|
459
|
'#value' => $preset_doTaxaByCommonNames
|
460
|
);
|
461
|
|
462
|
// Geographic Range
|
463
|
$form['search']['geographic_range'] = array(
|
464
|
'#type' => 'fieldset',
|
465
|
'#delta' => 5,
|
466
|
'#tree' => true,
|
467
|
'#title' => t('Geographic range'),
|
468
|
);
|
469
|
|
470
|
$form['search']['geographic_range']['tdwg_level_select'] = array(
|
471
|
'#type' => 'radios',
|
472
|
'#title' => t('Select a TDWG distribution level and code'),
|
473
|
'#default_value' => $tdwg_level_select,
|
474
|
'#options' => array(
|
475
|
t('TDWG level-1, i.e. a continent'),
|
476
|
t('TDWG level-2'),
|
477
|
t('TDWG level-3, i.e. a country'),
|
478
|
t('TDWG level-4')
|
479
|
)
|
480
|
);
|
481
|
$tdwg[1] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '1');
|
482
|
$tdwg[2] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '2');
|
483
|
$tdwg[3] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '3');
|
484
|
$tdwg[4] = cdm_ws_get(CDM_WS_TDWG_LEVEL, '4');
|
485
|
|
486
|
$tdwg_js = '';
|
487
|
foreach($tdwg as $key=>$tdwg_level){
|
488
|
$tdwgOptions = array();
|
489
|
$tdwgOptionsSelected = array();
|
490
|
foreach($tdwg_level as $area){
|
491
|
$representation = $area->representations[0];
|
492
|
$tdwgOptions[$representation->abbreviatedLabel] = $area->representation_L10n;
|
493
|
if(is_array($selected_areas) && in_array($representation->abbreviatedLabel, $selected_areas)){
|
494
|
$tdwgOptionsSelected[] = $representation->abbreviatedLabel; //$area->uuid;
|
495
|
}
|
496
|
}
|
497
|
asort($tdwgOptions);
|
498
|
$form['search']['geographic_range']['tdwg_level_'.$key] = array(
|
499
|
'#type' => 'select',
|
500
|
'#title' => t('TDWG level').' '.$key,
|
501
|
'#default_value' => $tdwgOptionsSelected,
|
502
|
'#multiple' => TRUE,
|
503
|
'#options' => $tdwgOptions
|
504
|
);
|
505
|
$tdwg_js .= "$('#edit-search-geographic-range-tdwg-level-$key').parent()".($tdwg_level_select + 1 == $key ? '.show()' : '.hide()'). ";\n";
|
506
|
}
|
507
|
|
508
|
drupal_add_js(
|
509
|
"$(document).ready(function(){
|
510
|
|
511
|
$(\"input[@name='search[geographic_range][tdwg_level_select]']\").change(
|
512
|
function(event){
|
513
|
var selectId = $(\"input[@name='search[geographic_range][tdwg_level_select]']:checked\").val();
|
514
|
var i;
|
515
|
for(i = 0; i < 4; i++){
|
516
|
if(selectId == i){
|
517
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1) ).parent().fadeIn('slow');
|
518
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
519
|
} else {
|
520
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).parent().fadeOut('slow');
|
521
|
$('#edit-search-geographic-range-tdwg-level-' + (i + 1)).children().removeAttr('selected');
|
522
|
}
|
523
|
}
|
524
|
}
|
525
|
);
|
526
|
|
527
|
$tdwg_js
|
528
|
});",
|
529
|
'inline');
|
530
|
|
531
|
} else {
|
532
|
$form['search']['doTaxa'] = array(
|
533
|
'#delta' => -2,
|
534
|
'#type' => 'hidden',
|
535
|
'#value' => 1
|
536
|
);
|
537
|
$form['search']['doSynonyms'] = array(
|
538
|
'#delta' => -3,
|
539
|
'#type' => 'hidden',
|
540
|
'#value' => 1
|
541
|
);
|
542
|
$form['search']['doTaxaByCommonNames'] = array(
|
543
|
'#delta' => -4,
|
544
|
'#type' => 'hidden',
|
545
|
'#value' => 0
|
546
|
);
|
547
|
}
|
548
|
|
549
|
$form['submit'] = array(
|
550
|
'#delta' => 9,
|
551
|
'#type' => 'submit',
|
552
|
'#name' => '',
|
553
|
'#value' => t('Search')
|
554
|
);
|
555
|
|
556
|
return $form;
|
557
|
}
|
558
|
|
559
|
function cdm_dataportal_search_taxon_form_advanced(){
|
560
|
return cdm_dataportal_search_taxon_form(true);
|
561
|
}
|
562
|
|
563
|
function cdm_taxonomictree_selector(){
|
564
|
_add_js_treeselector();
|
565
|
|
566
|
$out = drupal_get_form('cdm_taxonomictree_selector_form');
|
567
|
|
568
|
return $out;
|
569
|
}
|
570
|
|
571
|
|
572
|
function cdm_taxonomictree_selector_form(){
|
573
|
|
574
|
$url = url('cdm_api/setvalue/session', null);
|
575
|
$form['#action'] = $url;
|
576
|
|
577
|
$form['var'] = array(
|
578
|
'#delta' => -3,
|
579
|
'#type' => 'hidden',
|
580
|
'#value' => '[cdm][taxonomictree_uuid]'
|
581
|
);
|
582
|
|
583
|
$form['destination'] = array(
|
584
|
'#delta' => -3,
|
585
|
'#type' => 'hidden',
|
586
|
'#value' => substr(drupal_get_destination(), strlen('destination='))
|
587
|
);
|
588
|
|
589
|
$form['val'] = array(
|
590
|
'#type' => 'select',
|
591
|
'#title' => t('Available classifications'),
|
592
|
'#default_value' => get_taxonomictree_uuid_selected(),
|
593
|
'#options' => cdm_get_taxontrees_as_options()
|
594
|
);
|
595
|
|
596
|
return $form;
|
597
|
|
598
|
}
|
599
|
|
600
|
/**
|
601
|
* Implementation #process method call, see form_builder()
|
602
|
* <p>
|
603
|
* Removes Drupal internal form elements from query
|
604
|
* @param $form
|
605
|
* @return unknown_type
|
606
|
*/
|
607
|
function cdm_dataportal_search_process($form) {
|
608
|
unset($form['form_id']);
|
609
|
unset($form['form_token']);
|
610
|
return $form;
|
611
|
}
|
612
|
|
613
|
/**
|
614
|
* Filters $_REQUEST by a list of valid request parameters and also sets defaults if required.
|
615
|
* returns the processed request parameters submitted by the search form.
|
616
|
*/
|
617
|
function cdm_dataportal_search_form_request(){
|
618
|
|
619
|
|
620
|
$form_params = array();
|
621
|
array_deep_copy($_REQUEST['search'], $form_params);
|
622
|
$form_params['query'] = trim($_REQUEST['query']);
|
623
|
|
624
|
// split of geographic range
|
625
|
if(isset($_REQUEST['search']['geographic_range'])){
|
626
|
$geographicRange = $_REQUEST['search']['geographic_range'];
|
627
|
// remove
|
628
|
unset($form_params['geographic_range']);
|
629
|
}
|
630
|
|
631
|
// add geographic range
|
632
|
if($geographicRange){
|
633
|
$form_params['tdwg_level_select'] = $geographicRange['tdwg_level_select'];
|
634
|
for($i = 1; $i < 5; $i++){
|
635
|
if(isset($geographicRange['tdwg_level_'.$i])){
|
636
|
$form_params['area'] = $geographicRange['tdwg_level_'.$i];
|
637
|
}
|
638
|
}
|
639
|
}
|
640
|
|
641
|
// store in session
|
642
|
$_SESSION['cdm']['search'] = $form_params;
|
643
|
|
644
|
return $form_params;
|
645
|
}
|
646
|
|
647
|
|
648
|
/* UNREACHABLE since action of form directly links to view
|
649
|
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) {
|
650
|
|
651
|
$_SESSION['cdm']['search'] = $form_values;
|
652
|
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language'];
|
653
|
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0');
|
654
|
//$paramstr = compose_url_prameterstr($form_values);
|
655
|
//return url('/cdm_dataportal/search/taxon/', $paramstr);
|
656
|
}
|
657
|
*/
|
658
|
/* ====================== menu callback functions ====================== */
|
659
|
|
660
|
|
661
|
|
662
|
function cdm_dataportal_form_alter($form_id, &$form) {
|
663
|
|
664
|
static $comment_node_disabled = 0;
|
665
|
static $comment_node_read_only = 1;
|
666
|
static $comment_node_read_write = 2;
|
667
|
|
668
|
|
669
|
if ($form_id == 'node_type_form'
|
670
|
&& isset($form['identity']['type'])
|
671
|
&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes())
|
672
|
) {
|
673
|
$form['workflow']['comment'] = array(
|
674
|
'#type' => 'radios',
|
675
|
'#title' => t('Default comment setting'),
|
676
|
'#default_value' => variable_get('comment_'. $form['#node_type']->type, $comment_node_disabled),
|
677
|
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
|
678
|
'#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'),
|
679
|
);
|
680
|
}
|
681
|
}
|
682
|
|
683
|
|
684
|
|
685
|
function cdm_dataportal_create_gallery_settings_form($form_name, $form_tittle, $collapsed){
|
686
|
|
687
|
$form[$form_name] = array(
|
688
|
'#type' => 'fieldset',
|
689
|
'#title' => t($form_tittle),
|
690
|
'#collapsible' => TRUE,
|
691
|
'#collapsed' => $collapsed,
|
692
|
'#tree' => true,
|
693
|
);
|
694
|
|
695
|
$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
|
696
|
$gallery_settings = variable_get($form_name, $default_values);
|
697
|
//$test = variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE);
|
698
|
|
699
|
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
|
700
|
/* TODO: why cdm_dataportal_search_items_on_page does not save the value on $test???
|
701
|
$form[$form_name]['cdm_dataportal_search_items_on_page'] = array(
|
702
|
'#type' => 'textfield',
|
703
|
'#title' => t('Search Page Size'),
|
704
|
'#default_value' => $test,
|
705
|
'#description' => t('Number of Names to display per page in search results.')
|
706
|
);
|
707
|
*/
|
708
|
$form[$form_name]['cdm_dataportal_show_taxon_thumbnails'] = array(
|
709
|
'#type' => 'checkbox',
|
710
|
'#title' => t('Show media thumbnails for accepted taxa'),
|
711
|
'#default_value' => $gallery_settings['cdm_dataportal_show_taxon_thumbnails'],
|
712
|
'#description' => t('')
|
713
|
);
|
714
|
|
715
|
$form[$form_name]['cdm_dataportal_show_synonym_thumbnails'] = array(
|
716
|
'#type' => 'checkbox',
|
717
|
'#title' => t('Show media thumbnails for synonyms'),
|
718
|
'#default_value' => $gallery_settings['cdm_dataportal_show_synonym_thumbnails'],
|
719
|
'#description' => t('')
|
720
|
);
|
721
|
}
|
722
|
|
723
|
//$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
|
724
|
$form[$form_name]['cdm_dataportal_show_thumbnail_captions'] = array(
|
725
|
'#type' => 'checkbox',
|
726
|
'#title' => t('Show captions under thumbnails'),
|
727
|
'#default_value' => $gallery_settings['cdm_dataportal_show_thumbnail_captions'],
|
728
|
'#description' => t('')
|
729
|
);
|
730
|
|
731
|
$form[$form_name]['cdm_dataportal_media_maxextend'] = array(
|
732
|
'#type' => 'textfield',
|
733
|
'#title' => t('Maximum extend of Images'),
|
734
|
'#default_value' => $gallery_settings['cdm_dataportal_media_maxextend'],
|
735
|
'#description' => t('In the gallery neither width or height will exceed the maximum extend of images.')
|
736
|
);
|
737
|
|
738
|
$form[$form_name]['cdm_dataportal_media_cols'] = array(
|
739
|
'#type' => 'textfield',
|
740
|
'#title' => t('Number of columns'),
|
741
|
'#default_value' => $gallery_settings['cdm_dataportal_media_cols'],
|
742
|
'#description' => t('')
|
743
|
);
|
744
|
|
745
|
if($form_name == CDM_DATAPORTAL_SEARCH_GALLERY_NAME){
|
746
|
$form[$form_name]['cdm_dataportal_media_maxRows'] = array(
|
747
|
'#type' => 'textfield',
|
748
|
'#title' => t('Maximum number of rows'),
|
749
|
'#default_value' => $gallery_settings['cdm_dataportal_media_maxRows'],
|
750
|
'#description' => t('If you want an unlimited number of rows please set to 0')
|
751
|
);
|
752
|
}
|
753
|
|
754
|
return $form;
|
755
|
}
|
756
|
|
757
|
|
758
|
/**
|
759
|
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
|
760
|
*
|
761
|
* TODO: parameters are still preliminar
|
762
|
* @param String $page page number to diplay defaults to page 1
|
763
|
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
|
764
|
*/
|
765
|
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = false ){
|
766
|
|
767
|
$request_params = array(
|
768
|
'q' => $beginsWith,
|
769
|
//'sec' = '',
|
770
|
//'higherTaxa' => getFiters(),
|
771
|
// 'matchAnywhere' => false, // default is false
|
772
|
'page' => $page,
|
773
|
'onlyAccepted' => $onlyAccepted,
|
774
|
'pagesize' => 20 /*$_SESSION['cdm']['namelist_pagesize'] */);
|
775
|
|
776
|
$taxonPager = cdm_ws_find(CDM_WS_PORTAL_TAXON_FIND, $request_params);
|
777
|
/*
|
778
|
* FIXME the filter for accepted names will be a form element, thus this widget
|
779
|
* should be generated via form api preferably as block
|
780
|
*/
|
781
|
//$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
|
782
|
//$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
|
783
|
$out .= theme('cdm_listof_taxa', $taxonPager);
|
784
|
return $out;
|
785
|
}
|
786
|
|
787
|
function cdm_dataportal_view_reference($uuid, $arg2 = null){
|
788
|
$reference = cdm_ws_get(CDM_WS_REFERENCE, $uuid);
|
789
|
return theme('cdm_reference_page', $reference);
|
790
|
}
|
791
|
|
792
|
function cdm_dataportal_view_reference_list($pageNumber){
|
793
|
$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber);
|
794
|
return theme('cdm_reference_pager', $referencePager, 'cdm_dataportal/reference/list/');
|
795
|
}
|
796
|
|
797
|
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = false, $part = 0){
|
798
|
$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid);
|
799
|
return theme('cdm_media_page', $media, $mediarepresentation_uuid, $part);
|
800
|
}
|
801
|
|
802
|
/**
|
803
|
* The taxon page gives detailed information on a taxon, it shows:
|
804
|
* - Taxon name
|
805
|
* - Full list of synonyms homotypic synonyms on top, followed by the
|
806
|
* heterotypic and finally followed by misapplied names.
|
807
|
* The list is ordered historically.
|
808
|
* - All description associated with the taxon.
|
809
|
*
|
810
|
* @param $uuid
|
811
|
* @param $chapter name of the part to display,
|
812
|
* valid values are: 'description', 'images', 'synonymy', 'specimens', 'all'
|
813
|
* @return unknown_type
|
814
|
*/
|
815
|
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all'){
|
816
|
// display the page for the taxon defined by $uuid
|
817
|
set_last_taxon_page_tab(arg(3));
|
818
|
$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter);
|
819
|
return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title , $taxonpage->content);
|
820
|
}
|
821
|
|
822
|
/**
|
823
|
* @param $uuid
|
824
|
* @param $chapter name of the part to display,
|
825
|
* valid values are: 'description', 'images', 'synonymy', 'all'
|
826
|
* @return unknown_type
|
827
|
*/
|
828
|
function cdm_dataportal_taxon_view($uuid, $chapter = 'all'){
|
829
|
|
830
|
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid);
|
831
|
if(!$taxon){
|
832
|
drupal_set_title(t('Taxon does not exist'));
|
833
|
return false;
|
834
|
}
|
835
|
$taxonpage->title = theme('cdm_taxon_page_title', $taxon);
|
836
|
|
837
|
// check if the taxon id contained in the currently selected tree
|
838
|
$taxon_in_current_tree = taxon_in_current_tree($uuid);
|
839
|
$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $uuid);
|
840
|
if(!$taxon_in_current_tree){
|
841
|
if(count($taxon_nodes) == 0){
|
842
|
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained any classification.'
|
843
|
,'warning');
|
844
|
} else {
|
845
|
$trees = '';
|
846
|
foreach($taxon_nodes as $node){
|
847
|
$trees .= ($trees?', ':'').'<strong>'.$node->taxonomicTree->titleCache.'</strong>';
|
848
|
|
849
|
}
|
850
|
drupal_set_message('This concept of the taxon '.theme('cdm_taxonName', $taxon->name).' is not contained in the currently chosen classification, but in '
|
851
|
.(count($taxon_nodes) > 1? ' one of these: ' : ' this one: ') . $trees
|
852
|
, 'warning');
|
853
|
}
|
854
|
}
|
855
|
|
856
|
// render the taxon page
|
857
|
$taxonpage->content = theme('cdm_taxon_page_general', $taxon, $chapter);
|
858
|
|
859
|
return $taxonpage;
|
860
|
}
|
861
|
|
862
|
/**
|
863
|
* The function returns a name page as a drupal node ready to be renderized by drupal.
|
864
|
* The node page show the taxon name title and the list of taxon related with such taxon
|
865
|
* name on the tree already in used.
|
866
|
* @param $taxon_name_uuid A taxon name uuid
|
867
|
* @return The formatted name page as node
|
868
|
*/
|
869
|
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
|
870
|
$taxonname_page = cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid);
|
871
|
return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title , $taxonname_page->content);
|
872
|
}
|
873
|
|
874
|
/**
|
875
|
* The function genates a object ready to be transformated to a node
|
876
|
* in order to show as a drupal node
|
877
|
* @param $taxon_name_uuid
|
878
|
* @return the object with the page content and title
|
879
|
*/
|
880
|
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = null){
|
881
|
//getting the full taxonname object from the server
|
882
|
$taxon_name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid));
|
883
|
if(!$taxon_name){
|
884
|
drupal_set_title(t('Taxon name does not exist'));
|
885
|
return false;
|
886
|
}
|
887
|
//searching for all the taxa connected with the taxon name on the tree in used
|
888
|
$name_cache = cdm_ws_get(CDM_WS_NAME_NAMECAHE, array($taxon_name_uuid));
|
889
|
$request_params = array();
|
890
|
$request_params['query'] = $name_cache;
|
891
|
$request_params['tree'] = get_taxonomictree_uuid_selected();
|
892
|
$request_params['doTaxa'] = 1;
|
893
|
$request_params['doSynonyms'] = 1;
|
894
|
$request_params['doTaxaByCommonNames'] = 0;
|
895
|
$request_params['matchMode'] = "EXACT";
|
896
|
$taxon_pager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
|
897
|
|
898
|
//removing the name where we come from and
|
899
|
foreach($taxon_pager->records as $k=>&$taxon){
|
900
|
if($taxon->uuid == $taxon_to_hide_uuid){
|
901
|
unset($taxon_pager->records[$k]);
|
902
|
}
|
903
|
}
|
904
|
//show the taxa list or go to the singular taxon
|
905
|
if (sizeof($taxon_pager->records) == 1){ //sigle taxon case
|
906
|
reset($taxon_pager->records);
|
907
|
$first_key = key($taxon_pager->records);
|
908
|
if($taxon_pager->records[$first_key]->class != "Taxon"){
|
909
|
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, $taxon_pager->records[$first_key]->uuid);
|
910
|
if($synonym_uuid){
|
911
|
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid . '/synonymy', 'highlite=' . $synonym_uuid);
|
912
|
}else{
|
913
|
drupal_goto('cdm_dataportal/taxon/' . $taxon[0]->uuid);
|
914
|
}
|
915
|
}else{
|
916
|
if($synonym_uuid){
|
917
|
drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid . '/synonymy',
|
918
|
'highlite=' . $synonym_uuid);
|
919
|
}else{
|
920
|
drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
|
921
|
}
|
922
|
//drupal_goto('cdm_dataportal/taxon/' . $taxon_pager->records[$first_key]->uuid);
|
923
|
}
|
924
|
}else{ //more than one taxa case
|
925
|
$taxon_name_page->title = theme('cdm_name_page_title', $taxon_name);
|
926
|
if($taxon_pager->records){
|
927
|
$taxon_name_page->content = theme_cdm_list_of_taxa($taxon_pager->records, false);
|
928
|
}else{
|
929
|
$taxon_name_page->content = 'This name has no taxa';
|
930
|
}
|
931
|
return $taxon_name_page;
|
932
|
}
|
933
|
}
|
934
|
|
935
|
function cdm_dataportal_view_search_advanced(){
|
936
|
|
937
|
drupal_set_title(t('Advanced search'));
|
938
|
|
939
|
$searchForm = cdm_dataportal_search_taxon_form(true);
|
940
|
|
941
|
return drupal_get_form('cdm_dataportal_search_taxon_form_advanced');
|
942
|
|
943
|
}
|
944
|
|
945
|
/**
|
946
|
*
|
947
|
* future extensions to meet palmweb mockup requirements:
|
948
|
* - habitat
|
949
|
* - uses
|
950
|
* - conservation status
|
951
|
* - locality / tdwg region
|
952
|
*/
|
953
|
function cdm_dataportal_view_search_taxon(){
|
954
|
|
955
|
$_SESSION['cdm']['last_search'] = $_SERVER['REQUEST_URI'];
|
956
|
|
957
|
$request_params = cdm_dataportal_search_form_request();
|
958
|
$taxonPager = cdm_ws_get(CDM_WS_PORTAL_TAXON_FIND, null, queryString($request_params));
|
959
|
|
960
|
$search_params = $_REQUEST;
|
961
|
unset($search_params['q']);
|
962
|
return theme('cdm_search_results', $taxonPager, 'cdm_dataportal/search/taxon', $search_params);
|
963
|
}
|
964
|
|
965
|
|
966
|
function cdm_view_xml2json(){
|
967
|
$file = arg(2);
|
968
|
$datastr = get_content(variable_get('cdm_webservice_url', '').$file);
|
969
|
return xml2json::transformXmlStringToJson($datastr);
|
970
|
}
|
971
|
|
972
|
/* ====================== other functions ====================== */
|
973
|
|
974
|
/**
|
975
|
* Enter description here...
|
976
|
*
|
977
|
* @param String $uuid the UUID of the taxon
|
978
|
* @return the URL
|
979
|
*/
|
980
|
function path_to_taxon($uuid){
|
981
|
if(!$uuid) return false;
|
982
|
if(get_last_taxon_page_tab()){
|
983
|
return 'cdm_dataportal/taxon/'.$uuid . '/' . get_last_taxon_page_tab();
|
984
|
} else {
|
985
|
return 'cdm_dataportal/taxon/'.$uuid ;
|
986
|
}
|
987
|
}
|
988
|
|
989
|
function path_to_reference($uuid){
|
990
|
if(!$uuid) return false;
|
991
|
return 'cdm_dataportal/reference/'.$uuid;
|
992
|
}
|
993
|
|
994
|
function path_to_name($name_uuid){
|
995
|
$res = false;
|
996
|
if($name_uuid){
|
997
|
$res = 'cdm_dataportal/name/'.$name_uuid;
|
998
|
}
|
999
|
return $res;
|
1000
|
}
|
1001
|
|
1002
|
function path_to_media($uuid, $representaion_uuid = false, $partId = false){
|
1003
|
if(!$uuid) return false;
|
1004
|
$out = 'cdm_dataportal/media/'.$uuid;
|
1005
|
if($representaion_uuid){
|
1006
|
$out .= '/'.$representaion_uuid;
|
1007
|
if($partId !== false){
|
1008
|
$out .= '/'.$partId;
|
1009
|
}
|
1010
|
}
|
1011
|
return $out;
|
1012
|
}
|
1013
|
|
1014
|
/**
|
1015
|
* Compares thisRank with thatRank.
|
1016
|
* Returns a negative integer, zero, or a positive integer
|
1017
|
* as the of thisRank is higher than, equal to, or lower than thatRank.
|
1018
|
* e.g:
|
1019
|
* <ul>
|
1020
|
* <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li>
|
1021
|
* <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li>
|
1022
|
* <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li>
|
1023
|
* </ul>
|
1024
|
* <p>
|
1025
|
* This compare logic of the underlying webservice is the
|
1026
|
* <b>inverse logic</b> of the the one implemented in
|
1027
|
* java.lang.Comparable#compareTo(java.lang.Object)
|
1028
|
* @param $thisRankUuid
|
1029
|
* @param $thatRankUuid
|
1030
|
* @return a negative integer, zero, or a positive integer
|
1031
|
* as the thisRank is lower than, equal to, or higher than thatRank
|
1032
|
*/
|
1033
|
function rank_compare($thisRankUuid, $thatRankUuid){
|
1034
|
$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid));
|
1035
|
return $result->Integer;
|
1036
|
}
|
1037
|
|
1038
|
function uri_to_synonym($synonymUuid, $acceptedUuid, $pagePart = null){
|
1039
|
$acceptedPath = path_to_taxon($acceptedUuid);
|
1040
|
return url($acceptedPath.($pagePart ? '/'.$pagePart : ''), 'highlite='.$synonymUuid.'&acceptedFor='.$synonymUuid, $synonymUuid);
|
1041
|
}
|
1042
|
|
1043
|
/**
|
1044
|
* Creates a short taxonname by using the taggename field of NameSTO or NameTO instances.
|
1045
|
* If the taggename if empty the fullname will be returned.
|
1046
|
*
|
1047
|
* @param unknown_type $Name or TreeNode
|
1048
|
* @return string
|
1049
|
*/
|
1050
|
function cdm_dataportal_shortname_of($name){
|
1051
|
$nameStr = '';
|
1052
|
// get all tagged text tokens of the scientific name
|
1053
|
foreach($name->taggedTitle as $tagtxt){
|
1054
|
if($tagtxt->type == 'name' || $tagtxt->type == 'rank'){
|
1055
|
$nameStr .= ($nameStr ? ' ' : '').$tagtxt->text;
|
1056
|
}
|
1057
|
}
|
1058
|
$nameStr = trim($nameStr);
|
1059
|
if($nameStr){
|
1060
|
// do not return short names for these
|
1061
|
//if (stristr(strtolower($nameStr), 'incertae sedis') !== FALSE ||
|
1062
|
// stristr(strtolower($nameStr), 'nomina excludenda') !== FALSE) {
|
1063
|
if ($name->unplaced || $name->excluded){
|
1064
|
return $nameStr;
|
1065
|
}
|
1066
|
if($pos = stripos($nameStr, ' ')){
|
1067
|
return substr($nameStr, 0, 1).'. '.substr($nameStr, $pos);
|
1068
|
} else {
|
1069
|
return $nameStr;
|
1070
|
}
|
1071
|
} else {
|
1072
|
return $name->titleCache;
|
1073
|
}
|
1074
|
}
|
1075
|
|
1076
|
|
1077
|
/**
|
1078
|
* Check if a taxon is accepted by the current taxonomic tree
|
1079
|
*
|
1080
|
* @param Taxon $taxon
|
1081
|
* @return true if $taxon is accepted, false otherwise
|
1082
|
*/
|
1083
|
|
1084
|
function _cdm_dataportal_acceptedByCurrentView($taxon){
|
1085
|
|
1086
|
$defaultTreeUuid = get_taxonomictree_uuid_selected();
|
1087
|
if($taxon->class == "Taxon" && isset($taxon->taxonNodes)){
|
1088
|
foreach($taxon->taxonNodes as $node){
|
1089
|
if($node->taxonomicTree == $defaultTreeUuid) {
|
1090
|
return true;
|
1091
|
}
|
1092
|
}
|
1093
|
}
|
1094
|
return false;
|
1095
|
}
|
1096
|
|
1097
|
/**@Deprecated
|
1098
|
*
|
1099
|
*/
|
1100
|
function compose_url_prameterstr($parameters = array(), $parentPropertyName = false){
|
1101
|
$pstr = '';
|
1102
|
foreach($parameters as $key=>$value){
|
1103
|
if(is_array($value)){
|
1104
|
|
1105
|
} else {
|
1106
|
$pstr .= ($pstr ? '&' :'').$key.'='.urlencode($value);
|
1107
|
}
|
1108
|
}
|
1109
|
return $pstr;
|
1110
|
}
|
1111
|
|
1112
|
/**
|
1113
|
* workaround for missing original source type, idNamespace is always set in these cases
|
1114
|
* @param unknown_type $source
|
1115
|
* @return unknown_type
|
1116
|
*/
|
1117
|
function _is_original_source_type($source){
|
1118
|
return !$source->idNamespace && strlen($source->idNamespace) == 0;
|
1119
|
}
|
1120
|
|
1121
|
|
1122
|
function get_nameRenderTemplate($renderPath, $nameLink = NULL, $refenceLink = NULL){
|
1123
|
//TODO implement admin user interface to replace switch statement
|
1124
|
// preliminar solution: using themes
|
1125
|
|
1126
|
$template = null;
|
1127
|
// find best matching default RenderTemplate in theme
|
1128
|
//echo "<br/><br/>RENDER PATH: ".$renderPath;
|
1129
|
//var_dump('RENDER PATH: ' . $renderPath);
|
1130
|
while(!is_array($template) && strlen($renderPath) > 0){
|
1131
|
$template = theme('get_nameRenderTemplate', $renderPath);
|
1132
|
$renderPath = substr($renderPath, 0, strrpos($renderPath, '.'));
|
1133
|
// if(!is_array($template)){
|
1134
|
// echo "<br/>->".$renderPath;
|
1135
|
// }
|
1136
|
}
|
1137
|
|
1138
|
// otherwise get default RenderTemplate from theme
|
1139
|
if(!is_array($template)){
|
1140
|
$template = theme('get_nameRenderTemplate', '#DEFAULT');
|
1141
|
}
|
1142
|
// otherwise get system default RenderTemplate
|
1143
|
if(!is_array($template)){
|
1144
|
switch($renderPath){
|
1145
|
case 'list_of_taxa':
|
1146
|
case 'acceptedFor':
|
1147
|
case 'taxon_page_synonymy':
|
1148
|
case 'typedesignations':
|
1149
|
case 'taxon_page_title':
|
1150
|
case 'na': $template = array(
|
1151
|
'namePart' => array('#uri'=>true),
|
1152
|
//'authorshipPart' => true,
|
1153
|
);
|
1154
|
break;
|
1155
|
case 'nar': $template = array(
|
1156
|
'namePart' => array('#uri'=>true),
|
1157
|
//'authorshipPart' => true,
|
1158
|
'referencePart' => array('#uri'=>true),
|
1159
|
'microreferencePart' => true,
|
1160
|
);
|
1161
|
break;
|
1162
|
default: $template = array(
|
1163
|
'namePart' => array('#uri'=>true),
|
1164
|
'authorshipPart' => true,
|
1165
|
'referencePart' => array('#uri'=>true),
|
1166
|
'microreferencePart' => true,
|
1167
|
'statusPart' => true,
|
1168
|
'descriptionPart' => true
|
1169
|
);
|
1170
|
}
|
1171
|
}
|
1172
|
|
1173
|
if($nameLink && isset($template['nameAuthorPart']['#uri'])){
|
1174
|
$template['nameAuthorPart']['#uri'] = $nameLink;
|
1175
|
} else{
|
1176
|
unset($template['nameAuthorPart']['#uri']);
|
1177
|
}
|
1178
|
|
1179
|
if($nameLink && isset($template['namePart']['#uri'])){
|
1180
|
$template['namePart']['#uri'] = $nameLink;
|
1181
|
} else{
|
1182
|
unset($template['namePart']['#uri']);
|
1183
|
}
|
1184
|
|
1185
|
if($refenceLink && isset($template['referencePart']['#uri'])){
|
1186
|
$template['referencePart']['#uri'] = $refenceLink;
|
1187
|
}else{
|
1188
|
unset($template['referencePart']['#uri']);
|
1189
|
}
|
1190
|
|
1191
|
return $template;
|
1192
|
}
|
1193
|
|
1194
|
function get_partDefinition($taxonNameType){
|
1195
|
//TODO implement admin user interface to allow specify the partdefinitions for any type
|
1196
|
// preliminar solution: using themes
|
1197
|
|
1198
|
$partdef = theme('get_partDefinition', $taxonNameType);
|
1199
|
|
1200
|
if(!is_array($partdef)){
|
1201
|
switch($taxonNameType){
|
1202
|
case 'ZoologicalName': $partdef = array(
|
1203
|
'namePart' => array(
|
1204
|
'name' => true,
|
1205
|
),
|
1206
|
'referencePart' => array(
|
1207
|
'authorTeam' => true
|
1208
|
),
|
1209
|
'microreferencePart' => array(
|
1210
|
'microreference' => true,
|
1211
|
),
|
1212
|
'statusPart' => array(
|
1213
|
'status' => true,
|
1214
|
),
|
1215
|
'descriptionPart' => array(
|
1216
|
'description' => true,
|
1217
|
),
|
1218
|
);
|
1219
|
break;
|
1220
|
case 'BotanicalName': $partdef = array(
|
1221
|
'namePart' => array(
|
1222
|
'name' => true
|
1223
|
),
|
1224
|
'authorTeamPart' => array(
|
1225
|
'authorTeam' => true,
|
1226
|
),
|
1227
|
'referencePart' => array(
|
1228
|
'reference' => true
|
1229
|
),
|
1230
|
'microreferencePart' => array(
|
1231
|
'microreference' => true,
|
1232
|
),
|
1233
|
'statusPart' => array(
|
1234
|
'status' => true,
|
1235
|
),
|
1236
|
'descriptionPart' => array(
|
1237
|
'description' => true,
|
1238
|
),
|
1239
|
);
|
1240
|
break;
|
1241
|
default: $partdef = array(
|
1242
|
'namePart' => array(
|
1243
|
'name' => true,
|
1244
|
),
|
1245
|
'authorTeamPart' => array(
|
1246
|
'authorTeam' => true,
|
1247
|
),
|
1248
|
'referencePart' => array(
|
1249
|
'reference' => true
|
1250
|
),
|
1251
|
'microreferencePart' => array(
|
1252
|
'microreference' => true,
|
1253
|
),
|
1254
|
'statusPart' => array(
|
1255
|
'status' => true,
|
1256
|
),
|
1257
|
'descriptionPart' => array(
|
1258
|
'description' => true,
|
1259
|
),
|
1260
|
);
|
1261
|
}
|
1262
|
}
|
1263
|
return $partdef;
|
1264
|
}
|
1265
|
|
1266
|
/**
|
1267
|
* The function read the metadata info such title or artist of a media file. The
|
1268
|
* function tries at first to get all the info from the file metadata and if it is
|
1269
|
* not avaible look at the media file info stored at the database.
|
1270
|
* @param $media The media file
|
1271
|
* @return array The array with the avilable specified metadata info.
|
1272
|
* TODO rename to read_media_metadata() and move to *.module
|
1273
|
*/
|
1274
|
function cdm_read_media_metadata($media){
|
1275
|
|
1276
|
$metadata_caption = array('title' => '', //media_metadata and media
|
1277
|
'artist' => '', //media_metadata and media
|
1278
|
'rights', //media_metadata and media
|
1279
|
'location', //media_metadata
|
1280
|
'filename' => '', //media
|
1281
|
'mediacreated' => '', //media
|
1282
|
'description' => ''); //media
|
1283
|
|
1284
|
//getting the media metadata
|
1285
|
$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
|
1286
|
|
1287
|
//title
|
1288
|
//if ($media_metadata->Headline) {
|
1289
|
if ($media_metadata->ObjectName) {
|
1290
|
$metadata_caption['title'] = $media_metadata->ObjectName;
|
1291
|
// } else if ($media->titleCache){
|
1292
|
// $metadata_caption['title'] = $media_metadata->ObjectName;
|
1293
|
} else if ($media->titleCache){
|
1294
|
$metadata_caption['title'] = $media->titleCache;
|
1295
|
if ($media->description_L10n)
|
1296
|
$metadata_caption['title'] .= ' - ' . $media->description_L10n;
|
1297
|
}else{ //if there is no title on the db and metadata get file title
|
1298
|
$aux = $media->representations[0]->parts[0]->uri;
|
1299
|
$aux = explode("/", $aux);
|
1300
|
$aux = end($aux);
|
1301
|
$metadata_caption['title'] = $aux;
|
1302
|
}
|
1303
|
|
1304
|
//artist
|
1305
|
if ($media_metadata->Artist){
|
1306
|
$metadata_caption['artist'] = ($media_metadata->Artist ? ''.$media_metadata->Artist : '');
|
1307
|
}
|
1308
|
elseif ($media->artist->titleCache){
|
1309
|
$metadata_caption['artist'] = $media->artist->titleCache;
|
1310
|
}
|
1311
|
|
1312
|
//copyright
|
1313
|
$metadata_caption['rights'] = array('copyright' => array('agentNames' => array()),
|
1314
|
'license' => array('agentNames' => array(), 'types' => array(), 'abbreviatedTexts' => array(), 'uris' => array()));
|
1315
|
if ($media_metadata->Copyright)
|
1316
|
$metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
|
1317
|
elseif ($media->rights){
|
1318
|
foreach($media->rights as $right){
|
1319
|
switch($right->term->uuid){
|
1320
|
case UUID_RIGHTS_LICENCE:
|
1321
|
$metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? ''.$right->agent->firstname.' '.$right->agent->lastname : '');
|
1322
|
$metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? ''.$right->representation_L10n : '');
|
1323
|
$metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? ''.$right->abbreviatedText : '');
|
1324
|
$metadata_caption['rights']['license']['uris'][] = ($right->uri ? ''.$right->uri : '');
|
1325
|
break;
|
1326
|
case UUID_RIGHTS_COPYRIGHT:
|
1327
|
$metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
|
1328
|
break;
|
1329
|
}
|
1330
|
}
|
1331
|
}
|
1332
|
else
|
1333
|
$metadata_caption['rights']['agentNames'][] = '';
|
1334
|
|
1335
|
//filling the description (though there is no description in the db???)
|
1336
|
//$metadata_caption['description'] = $media->description_L10n;
|
1337
|
|
1338
|
//location
|
1339
|
$metadata_caption['location'] = array();
|
1340
|
$metadata_caption['location']['sublocation'] = $media_metadata->Sublocation;
|
1341
|
$metadata_caption['location']['city'] = $media_metadata->City;
|
1342
|
$metadata_caption['location']['province'] = $media_metadata->Province;
|
1343
|
$metadata_caption['location']['country'] = $media_metadata->Country;
|
1344
|
|
1345
|
//filename
|
1346
|
if(isset($media->representations[0]->parts[0]->uri)){
|
1347
|
$fileUri = $media->representations[0]->parts[0]->uri;
|
1348
|
$filename = substr($fileUri, strrpos($fileUri, "/")+1);
|
1349
|
$metadata_caption['filename'] = $filename;
|
1350
|
}
|
1351
|
else{
|
1352
|
$metadata_caption['filename'] = '';
|
1353
|
}
|
1354
|
/*
|
1355
|
//creation date
|
1356
|
if($media_metadata["Modify Date"])
|
1357
|
$metadata_caption['mediacreated'] = $media_metadata["Modify Date"];
|
1358
|
else
|
1359
|
$metadata_caption['mediacreated'] = $media->created;
|
1360
|
*/
|
1361
|
//returned value
|
1362
|
return $metadata_caption;
|
1363
|
}
|
1364
|
|
1365
|
/**
|
1366
|
* This function collects all the media from a list of description elements
|
1367
|
* and return them as an Array.
|
1368
|
*
|
1369
|
* @param $descriptionElementes The description elements
|
1370
|
* @return Array The output with all the media
|
1371
|
*/
|
1372
|
function cdm_dataportal_media_from_descriptionElements($descriptionElements){
|
1373
|
//variables
|
1374
|
$outArrayOfMedia = array(); //return value
|
1375
|
//implementation
|
1376
|
if(is_array($descriptionElements)){//avoiding warning box in drupal for flora malesiana
|
1377
|
foreach($descriptionElements as $descriptionElement){
|
1378
|
if(is_array($descriptionElement->media)){
|
1379
|
foreach($descriptionElement->media as $media){
|
1380
|
if(isset($media)){
|
1381
|
$outArrayOfMedia[] = $media;
|
1382
|
}
|
1383
|
}
|
1384
|
}
|
1385
|
}
|
1386
|
}
|
1387
|
return $outArrayOfMedia;
|
1388
|
}
|
1389
|
|
1390
|
function cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = array()){
|
1391
|
$footNoteKeys = array();
|
1392
|
//is argument cdmBase an array?
|
1393
|
if (!is_array($cdmBase)){
|
1394
|
$cdmBase_array = array();
|
1395
|
$cdmBase_array[] = $cdmBase;
|
1396
|
}else{
|
1397
|
$cdmBase_array = $cdmBase;
|
1398
|
}
|
1399
|
//getting the key for the footnotemanager
|
1400
|
if((bool) $footnote_list_key){
|
1401
|
$footnoteListKey = $footnote_list_key;
|
1402
|
}else{
|
1403
|
$footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
|
1404
|
}
|
1405
|
//adding the footnotes keys
|
1406
|
foreach($cdmBase_array as $cdmBase_element){
|
1407
|
$annotationUrl = cdm_compose_annotations_url($cdmBase_element);
|
1408
|
if($annotationUrl){
|
1409
|
$annotationPager = cdm_ws_get($annotationUrl, null, null, null, true);
|
1410
|
if($annotationPager->count > 0){
|
1411
|
foreach($annotationPager->records as $annotation){
|
1412
|
$footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
|
1413
|
}
|
1414
|
}
|
1415
|
}
|
1416
|
}
|
1417
|
return $footNoteKeys;
|
1418
|
/*
|
1419
|
$footNoteKeys = array();
|
1420
|
$footnoteListKey = RenderHints::getFootnoteListKey() . '-annotations';
|
1421
|
$annotationUrl = cdm_compose_annotations_url($cdmBase);
|
1422
|
if($annotationUrl){
|
1423
|
$annotationPager = cdm_ws_get($annotationUrl, null, null, null, true);
|
1424
|
if($annotationPager->count > 0){
|
1425
|
foreach($annotationPager->records as $annotation){
|
1426
|
$footNoteKeys[] = FootnoteManager::addNewFootnote($footnoteListKey, $annotation->text);
|
1427
|
}
|
1428
|
}
|
1429
|
}
|
1430
|
return $footNoteKeys;
|
1431
|
*/
|
1432
|
}
|
1433
|
|
1434
|
function cdm_dynabox($label, $content_url, $theme, $link_alt_text, $enclosingtags = array('li', 'ul')){
|
1435
|
|
1436
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
|
1437
|
|
1438
|
$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
|
1439
|
$out .= '<'. $enclosingtags[0]. ' class="dynabox"><a href="'.$content_url.'" class="label" alt="'.t($link_alt_text).'">'.$label.'</a>';
|
1440
|
$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]. '>';
|
1441
|
$out .= '</'. $enclosingtags[0]. '>';
|
1442
|
return $out;
|
1443
|
}
|
1444
|
|