cdm-dataportal / modules / cdm_dataportal / cdm_dataportal.module @ 64cfdac1
History | View | Annotate | Download (99.7 KB)
1 |
<?php |
---|---|
2 |
/** |
3 |
* @file |
4 |
* Module to provide a CDM Dataportal. |
5 |
* |
6 |
* @copyright |
7 |
* (C) 2007-2012 EDIT |
8 |
* European Distributed Institute of Taxonomy |
9 |
* http://www.e-taxonomy.eu |
10 |
* |
11 |
* The contents of this module are subject to the Mozilla |
12 |
* Public License Version 1.1. |
13 |
* @see http://www.mozilla.org/MPL/MPL-1.1.html |
14 |
* |
15 |
* @author |
16 |
* - Andreas Kohlbecker <a.kohlbecker@BGBM.org> |
17 |
* - Wouter Addink <w.addink@eti.uva.nl> (migration from Drupal 5 to Drupal7) |
18 |
*/ |
19 |
|
20 |
module_load_include('php', 'cdm_dataportal', 'node_types'); |
21 |
module_load_include('php', 'cdm_dataportal', 'settings'); |
22 |
module_load_include('php', 'cdm_dataportal', 'help'); |
23 |
module_load_include('php', 'cdm_dataportal', 'cdm_dataportal.search'); |
24 |
|
25 |
module_load_include('inc', 'cdm_dataportal', 'includes/common'); |
26 |
module_load_include('inc', 'cdm_dataportal', 'includes/agent'); |
27 |
module_load_include('inc', 'cdm_dataportal', 'includes/name'); |
28 |
module_load_include('inc', 'cdm_dataportal', 'includes/taxon'); |
29 |
module_load_include('inc', 'cdm_dataportal', 'includes/taxon-node'); |
30 |
module_load_include('inc', 'cdm_dataportal', 'includes/references'); |
31 |
module_load_include('inc', 'cdm_dataportal', 'includes/pages'); |
32 |
module_load_include('inc', 'cdm_dataportal', 'includes/media'); |
33 |
module_load_include('inc', 'cdm_dataportal', 'includes/maps'); |
34 |
module_load_include('inc', 'cdm_dataportal', 'includes/occurrences'); |
35 |
module_load_include('inc', 'cdm_dataportal', 'includes/descriptions'); |
36 |
module_load_include('inc', 'cdm_dataportal', 'includes/pre-drupal8'); |
37 |
|
38 |
module_load_include('inc', 'cdm_dataportal', 'theme/theme_registry'); |
39 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.common'); |
40 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.descriptions'); |
41 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.media'); |
42 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.occurrence'); |
43 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.page'); |
44 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.taxon'); |
45 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.name'); |
46 |
module_load_include('theme', 'cdm_dataportal', 'theme/cdm_dataportal.references'); |
47 |
|
48 |
module_load_include('php', 'cdm_dataportal', 'classes/footnotemanager'); |
49 |
module_load_include('php', 'cdm_dataportal', 'classes/footnote'); |
50 |
module_load_include('php', 'cdm_dataportal', 'classes/footnotekey'); |
51 |
module_load_include('php', 'cdm_dataportal', 'classes/renderhints'); |
52 |
|
53 |
|
54 |
/* ============================ java script functions ============================= */ |
55 |
|
56 |
|
57 |
/** |
58 |
* loads external java script files asynchronously. |
59 |
* |
60 |
* @param unknown_type $script_url |
61 |
*/ |
62 |
function drupal_add_js_async($script_url, $callback){ |
63 |
|
64 |
drupal_add_js(" |
65 |
jQuery(document).ready(function() { |
66 |
jQuery.ajax({ |
67 |
url: '" . $script_url . "', |
68 |
dataType: 'script', |
69 |
cache: true, // otherwise will get fresh copy every page load |
70 |
success: function() { |
71 |
" . $callback . " |
72 |
} |
73 |
}); |
74 |
});" |
75 |
, 'inline'); |
76 |
} |
77 |
|
78 |
/** |
79 |
*/ |
80 |
function drupal_add_js_rowToggle($tableId){ |
81 |
|
82 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/table_modification.js'); |
83 |
drupal_add_js('jQuery(document).ready(function(){ |
84 |
addRowToggle("' . $tableId . '"); |
85 |
}); |
86 |
', array('type' => 'inline')); |
87 |
} |
88 |
|
89 |
/** |
90 |
* @param unknown_type $link_element_selector |
91 |
* @param unknown_type $progress_element_selector |
92 |
*/ |
93 |
function _add_js_cdm_ws_progressbar($link_element_selector, $progress_element_selector){ |
94 |
|
95 |
$callback = "jQuery('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "');"; |
96 |
|
97 |
drupal_add_js_async(variable_get('cdm_webservice_url', '').'js/cdm_ws_progress.js', $callback); |
98 |
|
99 |
// drupal_add_js(" |
100 |
// if (Drupal.jsEnabled) { |
101 |
// $(document).ready(function() { |
102 |
// $('" . $link_element_selector . "').cdm_ws_progress('" . $progress_element_selector . "'); |
103 |
// }); |
104 |
// }", 'inline'); |
105 |
} |
106 |
|
107 |
/** |
108 |
* @todo Please document this function. |
109 |
* @see http://drupal.org/node/1354 |
110 |
*/ |
111 |
function _add_js_treeselector() { |
112 |
// drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/treeselector.js'); |
113 |
drupal_add_js(" |
114 |
jQuery(document).ready(function() { |
115 |
jQuery('#cdm-taxonomictree-selector-form #edit-val').change(function () { |
116 |
jQuery('#cdm-taxonomictree-selector-form').submit(); |
117 |
}); |
118 |
|
119 |
}); |
120 |
", |
121 |
array( |
122 |
'type' => 'inline', |
123 |
'scope' => 'footer' |
124 |
) |
125 |
); |
126 |
} |
127 |
|
128 |
function _add_js_resizable_element($selector, $y_axis_only) { |
129 |
|
130 |
_add_jquery_ui(); |
131 |
$options = ""; |
132 |
if($y_axis_only) { |
133 |
$options = "resize: function(event, ui) { |
134 |
ui.size.width = ui.originalSize.width; |
135 |
}, |
136 |
handles: \"s\""; |
137 |
|
138 |
} |
139 |
drupal_add_js(" |
140 |
jQuery(document).ready(function() { |
141 |
jQuery('" . $selector . "').resizable({". $options ."}); |
142 |
}); |
143 |
", |
144 |
array( |
145 |
'type' => 'inline', |
146 |
'scope' => 'footer' |
147 |
) |
148 |
); |
149 |
} |
150 |
|
151 |
function _add_js_openlayers() { |
152 |
|
153 |
$openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.js'; |
154 |
$proj4js = '/js/map/proj4js-1.1.0/proj4js-compressed.js'; |
155 |
|
156 |
if(variable_get('cdm_js_devel_mode', FALSE)){ |
157 |
// develooper mode libs |
158 |
// $openlayers = '/js/map/OpenLayers-2.13.1/lib/OpenLayers.js'; |
159 |
$openlayers = '/js/map/OpenLayers-2.13.1/OpenLayers.debug.js'; |
160 |
$proj4js = '/js/map/proj4js-1.1.0/proj4js-combined.js'; |
161 |
} |
162 |
|
163 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $openlayers, |
164 |
array( |
165 |
'type' => 'file', |
166 |
'group' => JS_LIBRARY, |
167 |
'weight' => 0, |
168 |
'cache' => TRUE, |
169 |
'preprocess' => FALSE |
170 |
) |
171 |
); |
172 |
|
173 |
|
174 |
// see https://github.com/proj4js/proj4js |
175 |
// http://openlayers.org/dev/examples/using-proj4js.html |
176 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . $proj4js, |
177 |
array( |
178 |
'type' => 'file', |
179 |
'group' => JS_LIBRARY, |
180 |
'weight' => -1, // before open layers |
181 |
'cache' => TRUE, |
182 |
) |
183 |
); |
184 |
|
185 |
// configure the theme |
186 |
$openlayers_theme_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/OpenLayers-2.13.1/theme/default/'; |
187 |
$openlayers_imp_path = drupal_get_path('module', 'cdm_dataportal') . '/js/map/img/dark/'; |
188 |
drupal_add_js('OpenLayers.ImgPath="' . base_path() . $openlayers_imp_path . '";', array( |
189 |
'type' => 'inline', |
190 |
'group' => JS_LIBRARY, |
191 |
'weight' => 1, // after openlayers |
192 |
'cache' => TRUE, |
193 |
'preprocess' => FALSE |
194 |
)); |
195 |
|
196 |
drupal_add_css($openlayers_theme_path . 'style.tidy.css', |
197 |
array( |
198 |
'type' => 'file', |
199 |
'cache' => TRUE, |
200 |
'preprocess' => FALSE |
201 |
) |
202 |
); |
203 |
|
204 |
} |
205 |
|
206 |
/** |
207 |
* @todo Please document this function. |
208 |
* @see http://drupal.org/node/1354 |
209 |
*/ |
210 |
function _add_js_thickbox() { |
211 |
// ---- jQuery thickbox: |
212 |
/* |
213 |
* bug: compat-1.0.js && thickbox.js line 237 .trigger("unload") -> event is |
214 |
* not triggered because of problems with compat-1.0.js' see INSTALL.txt |
215 |
*/ |
216 |
// drupal_add_js(drupal_get_path('module', |
217 |
// 'cdm_dataportal').'/js/jquery.imagetool.min.js'); |
218 |
// |
219 |
// Add a setting for the path to cdm_dataportal module, used to find the path |
220 |
// for the loading animation image in thickbox. |
221 |
drupal_add_js(array( |
222 |
'cdm_dataportal' => array( |
223 |
'cdm_dataportal_path' => base_path() . drupal_get_path('module', 'cdm_dataportal'), |
224 |
) |
225 |
), |
226 |
'setting' |
227 |
); |
228 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/thickbox.js'); |
229 |
drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/js/thickbox/cdm_thickbox.css'); |
230 |
} |
231 |
|
232 |
/** |
233 |
* @todo Please document this function. |
234 |
* @see http://drupal.org/node/1354 |
235 |
*/ |
236 |
function _add_js_lightbox($galleryID) { |
237 |
/* |
238 |
* Important Notice: The jquery.lightbox-0.5.js has been modified in order to |
239 |
* allow using the "alt" attribute for captions instead of the "title" |
240 |
* attribute |
241 |
*/ |
242 |
$lightbox_base_path = drupal_get_path('module', 'cdm_dataportal') . '/js/jquery-lightbox-0.5'; |
243 |
$lightbox_image_path = base_path() . $lightbox_base_path . '/images/'; |
244 |
drupal_add_js($lightbox_base_path . '/js/jquery.lightbox-0.5.js'); |
245 |
drupal_add_css($lightbox_base_path . '/css/jquery.lightbox-0.5.css'); |
246 |
drupal_add_js('jQuery(document).ready(function() { |
247 |
jQuery(\'#' . $galleryID . ' a.lightbox\').lightBox({ |
248 |
fixedNavigation: true, |
249 |
imageLoading: \'' . $lightbox_image_path . 'lightbox-ico-loading.gif\', |
250 |
imageBtnPrev: \'' . $lightbox_image_path . 'lightbox-btn-prev.gif\', |
251 |
imageBtnNext: \'' . $lightbox_image_path . 'lightbox-btn-next.gif\', |
252 |
imageBtnClose: \'' . $lightbox_image_path . 'lightbox-btn-close.gif\', |
253 |
imageBlank: \'' . $lightbox_image_path . 'lightbox-blank.gif\', |
254 |
adjustToWindow: true |
255 |
}); |
256 |
}); |
257 |
', array('type' => 'inline')); |
258 |
} |
259 |
|
260 |
/** |
261 |
* @todo Please document this function. |
262 |
* @see http://drupal.org/node/1354 |
263 |
*/ |
264 |
function _add_js_footnotes() { |
265 |
_add_js_domEvent(); |
266 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/footnotes.js'); |
267 |
} |
268 |
|
269 |
/** |
270 |
* @todo Please document this function. |
271 |
* @see http://drupal.org/node/1354 |
272 |
*/ |
273 |
function _add_js_ahah() { |
274 |
|
275 |
_add_js_domEvent(); // requires domEvent.js |
276 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/ahah-content.js'); |
277 |
} |
278 |
|
279 |
/** |
280 |
* @todo Please document this function. |
281 |
* @see http://drupal.org/node/1354 |
282 |
*/ |
283 |
function _add_js_taxonomic_children($jquery_selector) { |
284 |
|
285 |
global $base_url; |
286 |
|
287 |
|
288 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.cdm.taxonomic_children.js'); |
289 |
|
290 |
drupal_add_js('jQuery(document).ready(function() { |
291 |
jQuery(\'' . $jquery_selector . '\').taxonomic_children({ |
292 |
// hoverClass: "fa-rotate-90", |
293 |
// activeClass: "fa-rotate-90", |
294 |
classificationUuid: "' . get_current_classification_uuid() . '", |
295 |
taxonUuid: "' . get_current_taxon_uuid() . '", |
296 |
cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '", |
297 |
proxyBaseUri: "' . $base_url . '", |
298 |
|
299 |
}); |
300 |
}); |
301 |
', array('type' => 'inline')); |
302 |
} |
303 |
|
304 |
/** |
305 |
* Adds the external javascript file for domEvent.js. |
306 |
* |
307 |
* @see drupal_add_js() |
308 |
*/ |
309 |
function _add_js_domEvent() { |
310 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/domEvent.js'); |
311 |
} |
312 |
|
313 |
function _add_jquery_ui() |
314 |
{ |
315 |
drupal_add_css(drupal_get_path('module', |
316 |
'cdm_dataportal') . '/js/jquery-ui-1.8.24/themes/base/jquery.ui.all.css'); |
317 |
drupal_add_js(drupal_get_path('module', |
318 |
'cdm_dataportal') . '/js/jquery-ui-1.8.24/ui/jquery-ui.js', |
319 |
array( |
320 |
'type' => 'file', |
321 |
'weight' => JS_LIBRARY, |
322 |
'cache' => TRUE, |
323 |
'preprocess' => FALSE |
324 |
) |
325 |
); |
326 |
} |
327 |
|
328 |
function _add_js_ui_accordion(){ |
329 |
_add_jquery_ui(); |
330 |
drupal_add_js('jQuery(document).ready(function() { |
331 |
jQuery( "#accordion" ).accordion(); |
332 |
});', |
333 |
array('type' => 'inline') |
334 |
); |
335 |
} |
336 |
|
337 |
|
338 |
function _add_js_utis_client($jquery_selector){ |
339 |
|
340 |
drupal_add_js(drupal_get_path('module', |
341 |
'cdm_dataportal') . '/js/utis-client/utis-client.js', |
342 |
array( |
343 |
'type' => 'file', |
344 |
'weight' => JS_LIBRARY, |
345 |
'cache' => TRUE, |
346 |
'preprocess' => FALSE |
347 |
) |
348 |
); |
349 |
|
350 |
drupal_add_js('jQuery(document).ready(function() { |
351 |
jQuery( "' . $jquery_selector . '" ).utis_client( |
352 |
{ |
353 |
spinnerIcon: \'' . font_awesome_icon_markup('fa-sync', array('class' => array('fa-3x', 'fa-spin'), 'style' => array('opacity: 0.3;'))) . '\', |
354 |
externalLinkIcon: \'' . font_awesome_icon_markup('fa-external-link-alt') . '\' |
355 |
}); |
356 |
});', |
357 |
array('type' => 'inline') |
358 |
); |
359 |
} |
360 |
|
361 |
function _add_js_universalviewer($jquery_selector, $manifest_uri){ |
362 |
|
363 |
$universalviewer_path = drupal_get_path('module', 'cdm_dataportal') . '/js/universalviewer'; |
364 |
|
365 |
drupal_add_css($universalviewer_path . '/uv/uv.css'); |
366 |
drupal_add_css($universalviewer_path . '/uv-fix.css'); |
367 |
|
368 |
// offline.js is all of these dependencies concatenated (jQuery, CoreJS, and JSViews) |
369 |
drupal_add_js($universalviewer_path . '/uv/lib/offline.js', |
370 |
array( |
371 |
'type' => 'file', |
372 |
'group' => JS_LIBRARY, |
373 |
'cache' => TRUE, |
374 |
'preprocess' => FALSE |
375 |
) |
376 |
); |
377 |
drupal_add_js($universalviewer_path . '/uv/helpers.js', |
378 |
array( |
379 |
'type' => 'file', |
380 |
'group' => JS_LIBRARY, |
381 |
'cache' => TRUE, |
382 |
'preprocess' => FALSE |
383 |
) |
384 |
); |
385 |
// from UV 3.x documentation: |
386 |
// "root: |
387 |
// The path to the uv directory. Use a relative path e.g. root: '../../uv' |
388 |
// Don't start your path with a / otherwise requirejs will not append .js to |
389 |
// dependencies and they won't load." |
390 |
// |
391 |
// universalviewerPath will be used to build the root config variable. |
392 |
$iCleanUrlRequest = strpos($_SERVER['REQUEST_URI'], 'q=cdm_dataportal/') === false; |
393 |
if($iCleanUrlRequest){ |
394 |
$folders_up = preg_replace('/[^\/]+/', '..', $_GET['q']); |
395 |
$folders_up = preg_replace('/\.\.$/', '', $folders_up); |
396 |
} else { |
397 |
$folders_up = ''; |
398 |
} |
399 |
$basePath = base_path(); |
400 |
$config_file = 'uv-config.json'; |
401 |
drupal_add_js(' |
402 |
console.log(\'jQuery inline: \' + jQuery.fn.jquery); |
403 |
jQuery(window).on(\'uvLoaded\', function() { |
404 |
jQuery( "' . $jquery_selector . '" ).jqUniversalviewer( |
405 |
{ |
406 |
root: \'' . $folders_up . $universalviewer_path . '/uv\', |
407 |
configUri: \'' . $basePath . $universalviewer_path . '/'. $config_file . '\', |
408 |
manifestUri: \'' . $manifest_uri . '\' |
409 |
} |
410 |
); |
411 |
});', |
412 |
array( |
413 |
'type' => 'inline', |
414 |
'scope' => 'footer', |
415 |
'group' => JS_DEFAULT, |
416 |
'weight' => 0, |
417 |
) |
418 |
); |
419 |
drupal_add_js($universalviewer_path . '/jq-universalviewer.js', |
420 |
array( |
421 |
'type' => 'file', |
422 |
'scope' => 'footer', |
423 |
'group' => JS_DEFAULT, |
424 |
'weight' => 10, |
425 |
'cache' => TRUE, |
426 |
'preprocess' => FALSE |
427 |
) |
428 |
); |
429 |
// ui.js must be last |
430 |
drupal_add_js($universalviewer_path . '/uv/uv.js', |
431 |
array( |
432 |
'type' => 'file', |
433 |
'scope' => 'footer', |
434 |
'group' => 300, // IMPORTANT! |
435 |
'cache' => TRUE, |
436 |
'preprocess' => FALSE |
437 |
) |
438 |
); |
439 |
} |
440 |
|
441 |
/** |
442 |
* Provides the markup for an font awesome icon. |
443 |
* |
444 |
* The icons is created in default size without any extra features. |
445 |
* |
446 |
* The available icons are listed here http://fontawesome.io/cheatsheet/ |
447 |
* fontawesome icons have much more features than implemented here in this function, |
448 |
* for spinning icons, fixed width icons, rotation, etc please checkout the |
449 |
* examples at http://fontawesome.io/examples/ |
450 |
* |
451 |
* @parameter $icon_name |
452 |
* The name of the icon which starts with 'fa-' |
453 |
* |
454 |
* @return String |
455 |
* the markup for the icon in an <i> tag |
456 |
* |
457 |
*/ |
458 |
function font_awesome_icon_markup($icon_name = NULL, $attributes = array()){ |
459 |
_add_font_awesome_font(); |
460 |
|
461 |
|
462 |
if($icon_name){ |
463 |
if(!isset($attributes['class'])){ |
464 |
$attributes['class'] = array(); |
465 |
} |
466 |
$attributes['class'][] = 'fa'; |
467 |
$attributes['class'][] = $icon_name; |
468 |
|
469 |
return '<i ' . drupal_attributes($attributes) . '></i>'; |
470 |
} |
471 |
|
472 |
return ''; |
473 |
} |
474 |
|
475 |
/** |
476 |
* @param string $glyph_name |
477 |
* The name of the gloyph (e.g. 'icon-interal-link-alt-solid') for the foll list please |
478 |
* refer to modules/cdm_dataportal/fonts/custom-icon-font |
479 |
* @param array $attributes |
480 |
* @return string |
481 |
*/ |
482 |
function custom_icon_font_markup($glyph_name = NULL, $attributes = array()){ |
483 |
_add_font_custom_icon_font(); |
484 |
|
485 |
|
486 |
if($glyph_name){ |
487 |
if(!isset($attributes['class'])){ |
488 |
$attributes['class'] = array(); |
489 |
} |
490 |
$attributes['class'][] = $glyph_name; |
491 |
|
492 |
return '<i ' . drupal_attributes($attributes) . '></i>'; |
493 |
} |
494 |
|
495 |
return ''; |
496 |
} |
497 |
|
498 |
/** |
499 |
* Adds the css containing the font awesome icons to the html header. |
500 |
*/ |
501 |
function _add_font_awesome_font() |
502 |
{ |
503 |
// $fa_font_version = 'font-awesome-4.6.3/css/font-awesome.min.css'; |
504 |
$fa_font_version = 'fontawesome-free-5.9.0-web/css/all.css'; |
505 |
$font_awesome_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/' . $fa_font_version; |
506 |
|
507 |
drupal_add_html_head_link( |
508 |
array( |
509 |
'href' => $font_awesome_css_uri, |
510 |
'rel' => 'stylesheet' |
511 |
) |
512 |
); |
513 |
} |
514 |
|
515 |
/** |
516 |
* Adds the css containing the font awesome icons to the html header. |
517 |
*/ |
518 |
function _add_font_custom_icon_font() |
519 |
{ |
520 |
|
521 |
$custom_icon_font_css_uri = base_path() . drupal_get_path('module', 'cdm_dataportal') . '/fonts/custom-icon-font/style.css'; |
522 |
|
523 |
drupal_add_html_head_link( |
524 |
array( |
525 |
'href' => $custom_icon_font_css_uri, |
526 |
'rel' => 'stylesheet' |
527 |
) |
528 |
); |
529 |
} |
530 |
|
531 |
/* ====================== hook implementations ====================== */ |
532 |
/** |
533 |
* Implements hook_permission(). |
534 |
* |
535 |
* Valid permissions for this module. |
536 |
* |
537 |
* @return array |
538 |
* An array of valid permissions for the cdm_dataportal module. |
539 |
*/ |
540 |
function cdm_dataportal_permission() { |
541 |
return array( |
542 |
'administer cdm_dataportal' => array( |
543 |
'title' => t('Administer CDM DataPortal settings'), |
544 |
'description' => t("Access the settings pages specific for the cdm_dataportal module"), |
545 |
), |
546 |
'access cdm content' => array( |
547 |
'title' => t('Access CDM content'), |
548 |
'description' => t("Access content (taxa, names, specimens, etc.) served by the CDM web service."), |
549 |
), |
550 |
); |
551 |
} |
552 |
|
553 |
/** |
554 |
* Implements hook_menu(). |
555 |
*/ |
556 |
function cdm_dataportal_menu() { |
557 |
$items = array(); |
558 |
|
559 |
// @see settings.php. |
560 |
cdm_dataportal_menu_admin($items); |
561 |
cdm_dataportal_menu_help($items); |
562 |
|
563 |
$items['cdm_dataportal/names'] = array( |
564 |
'page callback' => 'cdm_dataportal_view_names', |
565 |
'access arguments' => array('access cdm content'), |
566 |
'type' => MENU_CALLBACK, |
567 |
); |
568 |
|
569 |
// Optional callback arguments: page. |
570 |
$items['cdm_dataportal/taxon'] = array( |
571 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
572 |
'access arguments' => array('access cdm content'), |
573 |
'type' => MENU_CALLBACK, |
574 |
// Expected callback arguments: uuid. |
575 |
); |
576 |
|
577 |
$items['cdm_dataportal/occurrence'] = array( |
578 |
'page callback' => 'cdm_dataportal_specimen_page_view', |
579 |
'access arguments' => array('access cdm content'), |
580 |
'type' => MENU_CALLBACK, |
581 |
// Expected callback arguments: uuid. |
582 |
); |
583 |
|
584 |
$items['cdm_dataportal/description'] = array( |
585 |
'page callback' => 'cdm_dataportal_description_page_view', |
586 |
'access arguments' => array('access cdm content'), |
587 |
'type' => MENU_CALLBACK, |
588 |
// Expected callback arguments: uuid. |
589 |
); |
590 |
|
591 |
$items['cdm_dataportal/specimen/accession_number'] = array( |
592 |
'page callback' => 'cdm_dataportal_specimen_by_accession_number_page_view', |
593 |
'access arguments' => array('access cdm content'), |
594 |
'type' => MENU_CALLBACK, |
595 |
// Expected callback arguments: accession number. |
596 |
); |
597 |
$items['cdm_dataportal/named_area'] = array( |
598 |
'page callback' => 'cdm_dataportal_named_area_page_view', |
599 |
'access arguments' => array('access cdm content'), |
600 |
'type' => MENU_CALLBACK, |
601 |
// Expected callback arguments: uuid. |
602 |
); |
603 |
|
604 |
$items['cdm_dataportal/name'] = array( |
605 |
'page callback' => 'cdm_dataportal_name_page_view', |
606 |
/* |
607 |
'page arguments' => array( |
608 |
'taxon_name_uuid', |
609 |
'taxon_to_hide_uuid', |
610 |
'synonym_uuid' => NULL |
611 |
), |
612 |
*/ |
613 |
'access arguments' => array('access cdm content'), |
614 |
'type' => MENU_CALLBACK, |
615 |
// Expected callback arguments: uuid. |
616 |
); |
617 |
|
618 |
$items['cdm_dataportal/reference'] = array( |
619 |
'page callback' => 'cdm_dataportal_view_reference', |
620 |
'access arguments' => array('access cdm content'), |
621 |
'type' => MENU_CALLBACK, |
622 |
// Expected callback arguments: uuid. |
623 |
); |
624 |
|
625 |
$items['cdm_dataportal/reference/list'] = array( |
626 |
'page callback' => 'cdm_dataportal_view_reference_list', |
627 |
'access arguments' => array('access cdm content'), |
628 |
'type' => MENU_CALLBACK, |
629 |
// Expected callback arguments: uuid. |
630 |
); |
631 |
|
632 |
$items['cdm_dataportal/media'] = array( |
633 |
'page callback' => 'cdm_dataportal_view_media', |
634 |
'access arguments' => array('access cdm content'), |
635 |
'type' => MENU_CALLBACK, |
636 |
// Expected callback arguments: |
637 |
// uuid, mediarepresentation_uuid, part_uuid or part#. |
638 |
); |
639 |
|
640 |
$items['cdm_dataportal/polytomousKey'] = array( |
641 |
'page callback' => 'cdm_dataportal_view_polytomousKey', |
642 |
'access arguments' => array('access cdm content'), |
643 |
'type' => MENU_CALLBACK, |
644 |
// Expected callback arguments: polytomousKey->uuid. |
645 |
); |
646 |
|
647 |
$items['cdm_dataportal/search'] = array( |
648 |
'page callback' => 'cdm_dataportal_view_search_advanced', |
649 |
'access arguments' => array('access cdm content'), |
650 |
'type' => MENU_CALLBACK, |
651 |
); |
652 |
|
653 |
// Optional callback arguments: page. |
654 |
$items['cdm_dataportal/registration'] = array( |
655 |
'page callback' => 'cdm_dataportal_registration_page_view', |
656 |
'access arguments' => array('access cdm content'), |
657 |
'type' => MENU_CALLBACK, |
658 |
// Expected callback arguments: uuid. |
659 |
); |
660 |
|
661 |
// ------------ SEARCH ----------- |
662 |
$items['cdm_dataportal/search/advanced'] = array( |
663 |
'title' => 'Advanced', // will be passed through t() |
664 |
'page callback' => 'cdm_dataportal_view_search_advanced', |
665 |
'access arguments' => array('access cdm content'), |
666 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
667 |
); |
668 |
$items['cdm_dataportal/search/blast'] = array( |
669 |
'title' => 'Blast', // will be passed through t() |
670 |
'page callback' => 'cdm_dataportal_view_search_blast', |
671 |
'access arguments' => array('access cdm content'), |
672 |
'type' => MENU_LOCAL_TASK, |
673 |
); |
674 |
|
675 |
$items['cdm_dataportal/search/taxon_by_description'] = array( |
676 |
'title' => 'By content category', // will be passed through t() |
677 |
'page callback' => 'cdm_dataportal_view_search_taxon_by_description', |
678 |
'access arguments' => array('access cdm content'), |
679 |
'type' => MENU_LOCAL_TASK, |
680 |
); |
681 |
$items['cdm_dataportal/search/results/taxon'] = array( |
682 |
'page callback' => 'cdm_dataportal_view_search_results_taxon', |
683 |
'access arguments' => array('access cdm content'), |
684 |
'type' => MENU_CALLBACK, |
685 |
); |
686 |
|
687 |
$items['cdm_dataportal/search/results/specimen'] = array( |
688 |
'page callback' => 'cdm_dataportal_view_search_results_specimen', |
689 |
'access arguments' => array('access cdm content'), |
690 |
'type' => MENU_CALLBACK, |
691 |
); |
692 |
|
693 |
/* |
694 |
* MENU_CALLBACK at cdm_dataportal/registration-search is needed to make the |
695 |
* tabs in the subordinate paths work, accessing this 'page' will cause the |
696 |
* MENU_DEFAULT_LOCAL_TASK being displayed |
697 |
*/ |
698 |
$items['cdm_dataportal/registration-search'] = array( |
699 |
'title' => 'Search', // will be passed through t() |
700 |
'page callback' => 'cdm_dataportal_view_search_registrations_results', |
701 |
'page arguments' => array("filter"), |
702 |
'access arguments' => array('access cdm content'), |
703 |
'type' => MENU_CALLBACK, |
704 |
); |
705 |
/* |
706 |
* the MENU_DEFAULT_LOCAL_TASK creates a tab for the MENU_CALLBACK |
707 |
* defined at a higher level of the path (cdm_dataportal/registration-search) |
708 |
*/ |
709 |
$items['cdm_dataportal/registration-search/filter'] = array( |
710 |
'title' => 'Search', // will be passed through t() |
711 |
'page callback' => 'cdm_dataportal_view_search_registrations_results', |
712 |
'page arguments' => array("filter"), |
713 |
'access arguments' => array('access cdm content'), |
714 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
715 |
); |
716 |
/* |
717 |
* the MENU_LOCAL_TASK creates another tab |
718 |
*/ |
719 |
$items['cdm_dataportal/registration-search/taxongraph'] = array( |
720 |
'title' => 'Taxon graph search', // will be passed through t() |
721 |
'page callback' => 'cdm_dataportal_view_search_registrations_results', |
722 |
'page arguments' => array("taxongraph"), |
723 |
'access arguments' => array('access cdm content'), |
724 |
'type' => MENU_LOCAL_TASK, |
725 |
); |
726 |
|
727 |
// Optional callback arguments: page. |
728 |
$items['cdm_dataportal/search/agent'] = array( |
729 |
'page callback' => 'cdm_dataportal_view_search_agent', |
730 |
'access arguments' => array('access cdm content'), |
731 |
'type' => MENU_CALLBACK, |
732 |
// Expected callback arguments: uuid. |
733 |
); |
734 |
|
735 |
// ------------ menu items with variable path elements ----------- |
736 |
|
737 |
// 'May not cache' in D5. |
738 |
$items['cdm_dataportal/name/%'] = array( |
739 |
// 'page callback' => 'cdm_dataportal_view_name', |
740 |
'page callback' => 'cdm_dataportal_name_page_view', |
741 |
'page arguments' => array(2, 3, 4, 5), |
742 |
'access arguments' => array('access cdm content'), |
743 |
'type' => MENU_CALLBACK, |
744 |
); |
745 |
|
746 |
// --- Local tasks for Taxon. |
747 |
// --- tabbed taxon page |
748 |
if (variable_get('cdm_dataportal_taxonpage_tabs', 1)) { |
749 |
$items['cdm_dataportal/taxon/%'] = array( |
750 |
'title' => cdm_taxonpage_tab_label('General'), |
751 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
752 |
'access arguments' => array('access cdm content'), |
753 |
'type' => MENU_CALLBACK, |
754 |
'weight' => 1, |
755 |
'page arguments' => array(2, "description") |
756 |
, // Expected callback arguments: taxon_uuid. |
757 |
); |
758 |
|
759 |
$items['cdm_dataportal/taxon/%/all'] = array( |
760 |
'title' => cdm_taxonpage_tab_label('General'), |
761 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
762 |
'access arguments' => array('access cdm content'), |
763 |
'type' => MENU_CALLBACK, |
764 |
'weight' => 2, |
765 |
'page arguments' => array(2, "all") |
766 |
, // Expected callback arguments: taxon_uuid. |
767 |
); |
768 |
|
769 |
$items['cdm_dataportal/taxon/%/description'] = array( |
770 |
'title' => cdm_taxonpage_tab_label('General'), |
771 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
772 |
'access arguments' => array('access cdm content'), |
773 |
'type' => MENU_DEFAULT_LOCAL_TASK, |
774 |
'weight' => 2, |
775 |
'page arguments' => array(2, "description") |
776 |
, // Expected callback arguments: taxon_uuid. |
777 |
); |
778 |
|
779 |
$items['cdm_dataportal/taxon/%/synonymy'] = array( |
780 |
'title' => cdm_taxonpage_tab_label('Synonymy'), |
781 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
782 |
'access arguments' => array('access cdm content'), |
783 |
'type' => MENU_LOCAL_TASK, |
784 |
'weight' => 4, |
785 |
'page arguments' => array(2, "synonymy", 4) |
786 |
, // Expected callback arguments: taxon_uuid and ... |
787 |
); |
788 |
$items['cdm_dataportal/taxon/%/images'] = array( // Images |
789 |
'title' => cdm_taxonpage_tab_label('Images'), |
790 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
791 |
'access arguments' => array('access cdm content'), |
792 |
'type' => MENU_LOCAL_TASK, |
793 |
'weight' => 5, |
794 |
'page arguments' => array(2, "images") |
795 |
, // Expected callback arguments: taxon_uuid. |
796 |
); |
797 |
|
798 |
$items['cdm_dataportal/taxon/%/specimens'] = array( // Specimens |
799 |
'title' => cdm_taxonpage_tab_label('Specimens'), |
800 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
801 |
'access arguments' => array('access cdm content'), |
802 |
'type' => MENU_LOCAL_TASK, |
803 |
'weight' => 6, |
804 |
'page arguments' => array(2, "specimens") |
805 |
, // Expected callback arguments: taxon_uuid. |
806 |
); |
807 |
|
808 |
$items['cdm_dataportal/taxon/%/keys'] = array( // Keys |
809 |
'title' => cdm_taxonpage_tab_label('Keys'), |
810 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
811 |
'access arguments' => array('access cdm content'), |
812 |
'type' => MENU_LOCAL_TASK, |
813 |
'weight' => 6, |
814 |
'page arguments' => array(2, "keys") |
815 |
, // Expected callback arguments: taxon_uuid. |
816 |
); |
817 |
|
818 |
$items['cdm_dataportal/taxon/%/experts'] = array( // Experts |
819 |
'title' => cdm_taxonpage_tab_label('Experts'), |
820 |
'page callback' => 'cdm_dataportal_taxon_page_view', |
821 |
'access arguments' => array('access cdm content'), |
822 |
'type' => MENU_LOCAL_TASK, |
823 |
'weight' => 6, |
824 |
'page arguments' => array(2, "experts") |
825 |
, // Expected callback arguments: taxon_uuid. |
826 |
); |
827 |
|
828 |
$items['cdm_dataportal/taxon/autosuggest/%/%/%/'] = array( |
829 |
'page callback' => 'cdm_dataportal_taxon_autosuggest', |
830 |
'access arguments' => array('access cdm content'), |
831 |
'page arguments' => array(3,4,5), |
832 |
'type' => MENU_CALLBACK |
833 |
); |
834 |
} |
835 |
|
836 |
// --- refresh link for all cdmnode types |
837 |
foreach (cdm_get_nodetypes() as $type=>$name) { |
838 |
$items['cdm_dataportal/' . $name . '/%/refresh'] = array( |
839 |
'title' => 'Refresh', |
840 |
'page callback' => 'cdm_dataportal_refresh_node', |
841 |
'access arguments' => array('administer cdm_dataportal'), |
842 |
'type' => MENU_LOCAL_TASK, |
843 |
'weight' => 100, |
844 |
'page arguments' => array($name, 2) |
845 |
); |
846 |
} |
847 |
|
848 |
return $items; |
849 |
} |
850 |
|
851 |
/** |
852 |
* Implements hook_init(). |
853 |
* |
854 |
*/ |
855 |
function cdm_dataportal_init() { |
856 |
if (!path_is_admin(current_path())) { |
857 |
//FIXME To add CSS or JS that should be present on all pages, modules |
858 |
// should not implement this hook, but declare these files in their .info file. |
859 |
drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal.css'); |
860 |
// drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal_print.css', 'print'); |
861 |
drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_screen.css', array('type' => 'screen')); |
862 |
} else { |
863 |
drupal_add_css(drupal_get_path('module', 'cdm_dataportal') . '/cdm_dataportal_settings.css'); |
864 |
} |
865 |
|
866 |
if(variable_get('cdm_debug_mode', FALSE)){ |
867 |
$file = 'temporary://drupal_debug.txt'; |
868 |
file_put_contents($file, 'CDM DEBUG LOG for ' . $_GET['q']. "\n"); // will overwrite the file |
869 |
} |
870 |
|
871 |
$bibliography_settings = get_bibliography_settings(); |
872 |
$enclosing_tag = $bibliography_settings['enabled'] == 1 ? 'div' : 'span'; |
873 |
FootnoteManager::registerFootnoteSet('BIBLIOGRAPHY', $enclosing_tag, $bibliography_settings['key_format']); |
874 |
} |
875 |
|
876 |
function cdm_dataportal_refresh_node($cdm_node_name, $uuid, $parameters = array()){ |
877 |
|
878 |
$base_path = 'cdm_dataportal/' . $cdm_node_name . '/' . $uuid; |
879 |
|
880 |
if($cdm_node_name == 'taxon' && variable_get('cdm_dataportal_taxonpage_tabs', 1)){ |
881 |
// force reloading of all and notify user about this special loading |
882 |
drupal_set_message(t('The level 2 cache has been cleared for all tabs of this taxon page at once, please click here to return to the tabbed page: ') |
883 |
. l('Back to tabbed taxon page', $base_path)); |
884 |
$base_path .= '/all'; |
885 |
} else { |
886 |
drupal_set_message(t('The level 2 cache has been cleared for this page')); |
887 |
} |
888 |
|
889 |
$parameters['cacheL2_refresh'] ='1'; |
890 |
|
891 |
|
892 |
drupal_goto($base_path, array('query' => $parameters)); |
893 |
} |
894 |
|
895 |
/** |
896 |
* Implements hook_requirements($phase) |
897 |
*/ |
898 |
function cdm_dataportal_requirements($phase) { |
899 |
$requirements = array(); |
900 |
if($phase == 'runtime'){ |
901 |
|
902 |
} |
903 |
return $requirements; |
904 |
} |
905 |
|
906 |
/** |
907 |
* Implements hook_block_info(). |
908 |
*/ |
909 |
function cdm_dataportal_block_info() { |
910 |
|
911 |
// $block[0]["info"] = t("CDM DataPortal DevLinks"); |
912 |
// $block[1]["info"] = t("CDM DataPortal Credits"); |
913 |
$block["2"] = array( |
914 |
"info" => t("CDM - Search Taxa"), |
915 |
"cache" => DRUPAL_NO_CACHE |
916 |
); |
917 |
// $block[3]["info"] = t("CDM Filters"); |
918 |
$block["4"]["info"] = t("CDM - Dataportal Print"); |
919 |
$block["keys"]["info"] = t("CDM - Identification keys"); |
920 |
$block["fundedByEDIT"]["info"] = t('CDM - Powered by EDIT'); |
921 |
$block["classification_breadcrumbs"] = array( |
922 |
'info' => t('CDM - Classification breadcrumbs'), |
923 |
'cache' => DRUPAL_CACHE_PER_PAGE |
924 |
); |
925 |
$block["taxonomic_children"] = array( |
926 |
'info' => t('CDM - Taxonomic children'), |
927 |
'cache' => DRUPAL_CACHE_PER_PAGE |
928 |
); |
929 |
$block["back_to_search_results"] = array( |
930 |
'title' => '<none>', |
931 |
'info' => t('CDM - Back to search Results'), |
932 |
'cache' => DRUPAL_CACHE_PER_PAGE, |
933 |
'visibility' => BLOCK_VISIBILITY_LISTED, |
934 |
'pages' => "cdm_dataportal/taxon/*", // multiple page paths separated by "\n"!!! |
935 |
); |
936 |
$block['registrations_search_filter'] = array( |
937 |
'title' => 'Filter registrations', |
938 |
'info' => t('CDM - Registrations search filter'), |
939 |
'cache' => DRUPAL_CACHE_PER_PAGE, |
940 |
'visibility' => BLOCK_VISIBILITY_NOTLISTED, |
941 |
'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!! |
942 |
); |
943 |
$block['registrations_search_taxongraph'] = array( |
944 |
'title' => 'Taxonomic registration search', |
945 |
'info' => t('CDM - Registrations search by taxon graph'), |
946 |
'cache' => DRUPAL_CACHE_PER_PAGE, |
947 |
'visibility' => BLOCK_VISIBILITY_NOTLISTED, |
948 |
'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!! |
949 |
); |
950 |
$block['registrations_search'] = array( |
951 |
'title' => 'Search', |
952 |
'info' => t('CDM - Registrations search combining filter and taxon graph search' ), |
953 |
'cache' => DRUPAL_CACHE_PER_PAGE, |
954 |
'visibility' => BLOCK_VISIBILITY_NOTLISTED, |
955 |
'pages' => "cdm_dataportal/registration-search\ncdm_dataportal/registration-search/*", // multiple page paths separated by "\n"!!! |
956 |
); |
957 |
$block['utis_search'] = array( |
958 |
'title' => 'UTIS Search', |
959 |
'info' => t('Query the Unified Taxonomic Information Service (UTIS)' ), |
960 |
'cache' => DRUPAL_CACHE_PER_PAGE, |
961 |
'visibility' => BLOCK_VISIBILITY_NOTLISTED |
962 |
); |
963 |
return $block; |
964 |
} |
965 |
|
966 |
/** |
967 |
* Implements hook_block_view(). |
968 |
*/ |
969 |
function cdm_dataportal_block_view($delta) { |
970 |
// TODO Rename block deltas (e.g. '2') to readable strings. |
971 |
switch ($delta) { |
972 |
// case 'delta-1': |
973 |
// $block['subject'] = t('Credits'); |
974 |
// $block['content'] = theme('cdm_credits'); |
975 |
// return $block; |
976 |
case '2': |
977 |
$block['subject'] = t('Search taxa'); |
978 |
$form = drupal_get_form('cdm_dataportal_search_taxon_form'); |
979 |
$block['content'] = drupal_render($form); |
980 |
|
981 |
if (variable_get('cdm_dataportal_show_advanced_search', 1)) { |
982 |
$block['content'] .= '<div>' . l(t('Advanced Search'), 'cdm_dataportal/search') . '</div>'; |
983 |
} |
984 |
if (variable_get(CDM_SEARCH_BLAST_ENABLED)){ |
985 |
$block['content'] .= '<div>' . l(t('Blast Search'), 'cdm_dataportal/search/blast') . '</div>'; |
986 |
} |
987 |
return $block; |
988 |
case '4': |
989 |
$block['subject'] = ''; |
990 |
$block['content'] = theme('cdm_print_button'); |
991 |
return $block; |
992 |
case "keys": |
993 |
$block['subject'] = t('Identification Keys'); |
994 |
$block['content'] = theme('cdm_block_IdentificationKeys', array('taxonUuid' => NULL)); |
995 |
return $block; |
996 |
case "fundedByEDIT": |
997 |
// t('Funded by EDIT'); |
998 |
$text = '<none>'; |
999 |
$block['subject'] = $text; |
1000 |
$img_tag = '<img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/powered_by_edit.png' . '" alt="' . $text . '"/>'; |
1001 |
$block['content'] = l($img_tag, "http://cybertaxonomy.org/", array( |
1002 |
'attributes' => array("target" => "EDIT"), |
1003 |
'absolute' => TRUE, |
1004 |
'html' => TRUE, |
1005 |
)); |
1006 |
return $block; |
1007 |
case 'classification_breadcrumbs': |
1008 |
$taxon_uuid = get_current_taxon_uuid(); |
1009 |
$block['subject'] = '<none>'; |
1010 |
$block['content'] = compose_classification_breadcrumbs($taxon_uuid); |
1011 |
return $block; |
1012 |
case 'taxonomic_children': |
1013 |
$taxon_uuid = get_current_taxon_uuid(); |
1014 |
$block['subject'] = '<none>'; |
1015 |
$block['content'] = compose_taxonomic_children($taxon_uuid); |
1016 |
return $block; |
1017 |
case 'back_to_search_results': |
1018 |
$block['subject'] = '<none>'; |
1019 |
if (isset($_SESSION['cdm']['search'])) { |
1020 |
$block['content'] = l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search']); |
1021 |
} |
1022 |
return $block; |
1023 |
case 'registrations_search_filter': |
1024 |
$block['subject'] = '<none>'; |
1025 |
$block['content'] = drupal_get_form('cdm_dataportal_search_registration_filter_form'); // see cdm_dataportal_search_registration_filter_form($form, &$form_state) |
1026 |
return $block; |
1027 |
case 'registrations_search_taxongraph': |
1028 |
$block['subject'] = '<none>'; |
1029 |
$block['content'] = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); // see cdm_dataportal_search_registration_taxongraph_form($form, &$form_state) |
1030 |
return $block; |
1031 |
case 'registrations_search': |
1032 |
_add_js_ui_accordion(); |
1033 |
_add_font_awesome_font(); |
1034 |
$block['subject'] = '<none>'; |
1035 |
$filter_form = drupal_get_form('cdm_dataportal_search_registration_filter_form'); |
1036 |
$filter_form['#prefix'] = '<div>'; |
1037 |
$filter_form['#suffix'] = '</div>'; |
1038 |
$taxongraph_form = drupal_get_form('cdm_dataportal_search_registration_taxongraph_form'); |
1039 |
$taxongraph_form['#prefix'] = '<div>'; |
1040 |
$taxongraph_form['#suffix'] = '</div>'; |
1041 |
$block['content'] = array( |
1042 |
'accordion' => array( |
1043 |
'#markup' => '', |
1044 |
'#prefix' => '<div id="accordion">', |
1045 |
'#suffix' => '</div>', |
1046 |
'content' => array( |
1047 |
array('#markup' => '<h3>Filter</h3>'), |
1048 |
$filter_form, |
1049 |
array('#markup' => '<h3>Taxon graph</h3>'), |
1050 |
$taxongraph_form, |
1051 |
) |
1052 |
) |
1053 |
); |
1054 |
return $block; |
1055 |
case 'utis_search': |
1056 |
_add_js_utis_client('.utis_client'); |
1057 |
$block['subject'] = '<none>'; |
1058 |
$block['content'] = '<div class="utis_client"></div>'; |
1059 |
return $block; |
1060 |
default: |
1061 |
return null; |
1062 |
} |
1063 |
} |
1064 |
|
1065 |
|
1066 |
/** |
1067 |
* Provides the uuid of the taxon for pages with the path ./taxon/{taxon_uuid} |
1068 |
* |
1069 |
* @return string |
1070 |
* the taxon uuid or NULL |
1071 |
*/ |
1072 |
function get_current_taxon_uuid() |
1073 |
{ |
1074 |
static $taxon_uuid; |
1075 |
|
1076 |
if(!isset($taxon_uuid)){ |
1077 |
if(isset($_REQUEST['currentTaxon']) && is_uuid($_REQUEST['currentTaxon'])) { |
1078 |
$taxon_uuid = $_REQUEST['currentTaxon']; |
1079 |
} else if (arg(1) == 'taxon' && is_uuid(arg(2))) { |
1080 |
$taxon_uuid = arg(2); |
1081 |
} else { |
1082 |
$taxon_uuid = null; |
1083 |
} |
1084 |
} |
1085 |
|
1086 |
return $taxon_uuid; |
1087 |
} |
1088 |
|
1089 |
/** |
1090 |
* Returns the currently classification tree in use. |
1091 |
* |
1092 |
* @return string |
1093 |
* The uuid of the currently focused classification |
1094 |
*/ |
1095 |
function get_current_classification_uuid() { |
1096 |
if (isset($_SESSION['cdm']['taxonomictree_uuid']) && is_uuid($_SESSION['cdm']['taxonomictree_uuid'])) { |
1097 |
return $_SESSION['cdm']['taxonomictree_uuid']; |
1098 |
} |
1099 |
else { |
1100 |
return variable_get(CDM_TAXONOMICTREE_UUID, FALSE); |
1101 |
} |
1102 |
} |
1103 |
|
1104 |
/* |
1105 |
function cdm_dataportal_session_clear($cdm_ws_uri_update = FALSE){ |
1106 |
$_SESSION['cdm'] = NULL; |
1107 |
if(is_string($cdm_ws_uri_update)){ |
1108 |
$_SESSION['cdm'] = array('ws_uri'=>$cdm_ws_uri_update); |
1109 |
} |
1110 |
} |
1111 |
|
1112 |
function cdm_dataportal_session_validate(){ |
1113 |
if(!isset($_SESSION['cdm']['ws_uri'])){ |
1114 |
$_SESSION['cdm'] = array('ws_uri'=>variable_get('cdm_webservice_url', FALSE)); |
1115 |
} else if($_SESSION['cdm']['ws_uri'] != variable_get('cdm_webservice_url', FALSE)){ |
1116 |
cdm_dataportal_session_clear(variable_get('cdm_webservice_url', FALSE)); |
1117 |
} |
1118 |
} |
1119 |
*/ |
1120 |
|
1121 |
/** |
1122 |
* creates a selector form for taxonomic trees. |
1123 |
* |
1124 |
* @return array |
1125 |
* a drupal form array |
1126 |
*/ |
1127 |
function cdm_taxonomictree_selector() { |
1128 |
_add_js_treeselector(); |
1129 |
|
1130 |
$form = drupal_get_form('cdm_taxonomictree_selector_form'); |
1131 |
return $form; |
1132 |
} |
1133 |
|
1134 |
/** |
1135 |
* @todo Please document this function. |
1136 |
* @see http://drupal.org/node/1354 |
1137 |
* |
1138 |
* @deprecated use compose_classification_selector instead |
1139 |
*/ |
1140 |
function cdm_taxonomictree_selector_form($form, &$form_state) { |
1141 |
|
1142 |
$url = url('cdm_api/setvalue/session', array('query' => NULL)); |
1143 |
$form['#action'] = $url; |
1144 |
|
1145 |
$form['var'] = array( |
1146 |
'#weight' => -3, |
1147 |
'#type' => 'hidden', |
1148 |
'#value' => '[cdm][taxonomictree_uuid]', |
1149 |
); |
1150 |
|
1151 |
$destination_array = drupal_get_destination(); |
1152 |
$destination = $destination_array['destination']; |
1153 |
|
1154 |
$form['destination'] = array( |
1155 |
'#weight' => -3, |
1156 |
'#type' => 'hidden', |
1157 |
'#value' => $destination, |
1158 |
); |
1159 |
|
1160 |
$options = cdm_get_taxontrees_as_options(); |
1161 |
$taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null); |
1162 |
if($taxontree_includes){ |
1163 |
$filtered_options = array(); |
1164 |
foreach($options as $uuid=>$label){ |
1165 |
if(!empty($taxontree_includes[$uuid])){ |
1166 |
$filtered_options[$uuid] = $label; |
1167 |
} |
1168 |
} |
1169 |
$options = $filtered_options; |
1170 |
} |
1171 |
|
1172 |
$form['val'] = array( |
1173 |
'#type' => 'select', |
1174 |
'#title' => t('Available classifications'), |
1175 |
'#default_value' => get_current_classification_uuid(), |
1176 |
'#options' => $options, |
1177 |
'#attributes' => array('class' => array('highlite-first-child')), |
1178 |
); |
1179 |
|
1180 |
return $form; |
1181 |
|
1182 |
} |
1183 |
|
1184 |
/** |
1185 |
* |
1186 |
* @ingroup compose |
1187 |
*/ |
1188 |
function compose_classification_selector() { |
1189 |
|
1190 |
$destination_array = drupal_get_destination(); |
1191 |
$destination = $destination_array['destination']; |
1192 |
|
1193 |
$options = cdm_get_taxontrees_as_options(); |
1194 |
$items = array(); |
1195 |
$taxontree_includes = variable_get(CDM_TAXONTREE_INCLUDES, null); |
1196 |
|
1197 |
$current_classification_uuid = get_current_classification_uuid(); |
1198 |
|
1199 |
|
1200 |
foreach($options as $uuid=>$label){ |
1201 |
if(!$taxontree_includes || !empty($taxontree_includes[$uuid])){ |
1202 |
|
1203 |
$class_attributes = ''; |
1204 |
if($current_classification_uuid == $uuid){ |
1205 |
$class_attributes = array('focused'); |
1206 |
} |
1207 |
$items[] = array( |
1208 |
'data' => l($label, |
1209 |
'cdm_api/setvalue/session', |
1210 |
array( |
1211 |
'query' => array( |
1212 |
'destination' => $destination, |
1213 |
'val' => $uuid, |
1214 |
'var' => '[cdm][taxonomictree_uuid]' |
1215 |
), |
1216 |
) |
1217 |
), |
1218 |
'class' => $class_attributes |
1219 |
); |
1220 |
} |
1221 |
} |
1222 |
|
1223 |
$render_array = array( |
1224 |
'#theme' => 'item_list', |
1225 |
'#type' => 'ul', |
1226 |
'#items' => $items |
1227 |
); |
1228 |
|
1229 |
return $render_array; |
1230 |
} |
1231 |
|
1232 |
|
1233 |
/* UNREACHABLE since action of form directly links to view. |
1234 |
function cdm_dataportal_search_taxon_form_submit($form_id, $form_values) { |
1235 |
|
1236 |
$_SESSION['cdm']['search'] = $form_values; |
1237 |
//return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['vernacular']?'1':'0').'/'.$form_values['language']; |
1238 |
return '/cdm_dataportal/search/taxon/'.$form_values['queryString'].'/'.($form_values['onlyAccepted']?'1':'0'); |
1239 |
//$paramstr = compose_url_prameterstr($form_values); |
1240 |
//return url('/cdm_dataportal/search/taxon/', array('query' => $paramstr)); |
1241 |
} |
1242 |
*/ |
1243 |
/* ====================== menu callback functions ====================== */ |
1244 |
/** |
1245 |
* @todo Please document this function. |
1246 |
* @see http://drupal.org/node/1354 |
1247 |
*/ |
1248 |
/* |
1249 |
function cdm_dataportal_form_alter(&$form, &$form_state, $form_id) { |
1250 |
static $comment_node_disabled = 0; |
1251 |
static $comment_node_read_only = 1; |
1252 |
static $comment_node_read_write = 2; |
1253 |
|
1254 |
if ($form_id == 'node_type_form' |
1255 |
&& isset($form['identity']['type']) |
1256 |
&& array_key_exists($form['#node_type']->type, cdm_get_nodetypes()) |
1257 |
) { |
1258 |
$form['workflow']['comment'] = array( |
1259 |
'#type' => 'radios', |
1260 |
'#title' => t('Default comment setting'), |
1261 |
'#default_value' => variable_get('comment__' . $node->type . $form['#node_type']->type, $comment_node_disabled), |
1262 |
'#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), |
1263 |
'#description' => t('Users with the <em>administer comments</em> permission will be able to override this setting.'), |
1264 |
); |
1265 |
} |
1266 |
} |
1267 |
*/ |
1268 |
|
1269 |
/** |
1270 |
* Displays a list of the known taxonomic names. |
1271 |
* |
1272 |
* When the list of taxonomic names is displayed, long lists are split up into |
1273 |
* multiple pages. |
1274 |
* |
1275 |
* TODO: Parameters are still preliminary. |
1276 |
* |
1277 |
* @param string $beginsWith |
1278 |
* @param string $page |
1279 |
* Page number to diplay defaults to page 1. |
1280 |
* @param bool $onlyAccepted |
1281 |
*/ |
1282 |
function cdm_dataportal_view_names($beginsWith = 'A', $page = 1, $onlyAccepted = FALSE) { |
1283 |
|
1284 |
$out = t('<h3>Sorry, the name list feature is not yet available in this version of the DataPortal software<h3>'); |
1285 |
|
1286 |
/* |
1287 |
// FIXME the filter for accepted names will be a form element, thus this |
1288 |
// widget should be generated via form api preferably as block. |
1289 |
$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted); |
1290 |
$out .= theme('cdm_dataportal_widget_names_list', $names, $page); |
1291 |
$out .= theme('cdm_listof_taxa', $taxonPager); |
1292 |
return $out; |
1293 |
*/ |
1294 |
} |
1295 |
|
1296 |
/** |
1297 |
* @todo Please document this function. |
1298 |
* @see http://drupal.org/node/1354 |
1299 |
* @throws Exception |
1300 |
*/ |
1301 |
function cdm_dataportal_view_reference($uuid, $arg2 = NULL) { |
1302 |
|
1303 |
cdm_check_valid_portal_page(); |
1304 |
|
1305 |
return compose_cdm_reference_page($uuid); |
1306 |
} |
1307 |
|
1308 |
/** |
1309 |
* Creates a view on a all references contained in the portal. |
1310 |
* |
1311 |
* This function is used at the path cdm_dataportal/reference/list |
1312 |
*/ |
1313 |
function cdm_dataportal_view_reference_list($pageNumber) { |
1314 |
$referencePager = cdm_ws_page(CDM_WS_REFERENCE, variable_get('cdm_dataportal_search_items_on_page', CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE), $pageNumber); |
1315 |
cdm_reference_pager($referencePager, 'cdm_dataportal/reference/list/'); |
1316 |
} |
1317 |
|
1318 |
/** |
1319 |
* @todo Please document this function. |
1320 |
* @see http://drupal.org/node/1354 |
1321 |
*/ |
1322 |
function cdm_dataportal_view_media($mediaUuid, $mediarepresentation_uuid = FALSE, $part = 0) { |
1323 |
|
1324 |
cdm_check_valid_portal_page(); |
1325 |
|
1326 |
$media = cdm_ws_get(CDM_WS_PORTAL_MEDIA, $mediaUuid); |
1327 |
if (!$media) { |
1328 |
drupal_set_title(t('Media does not exist'), PASS_THROUGH); |
1329 |
return ""; |
1330 |
} |
1331 |
return theme('cdm_media_page', array( |
1332 |
'media' => $media, |
1333 |
'mediarepresentation_uuid' => $mediarepresentation_uuid, |
1334 |
'partId' => $part, |
1335 |
)); |
1336 |
} |
1337 |
|
1338 |
/** |
1339 |
* @todo Please document this function. |
1340 |
* @see http://drupal.org/node/1354 |
1341 |
*/ |
1342 |
function _load_taxonBase(&$taxonBase) { |
1343 |
if (isset($taxonBase->uuid)) { |
1344 |
$taxonBase->name = cdm_ws_get(CDM_WS_TAXON, array($taxonBase->uuid, "name")); |
1345 |
$taxonBase->name->taggedName = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "taggedName")); |
1346 |
$taxonBase->name->nomenclaturalReference = cdm_ws_get(CDM_WS_NAME, array($taxonBase->name->uuid, "nomenclaturalReference")); |
1347 |
} |
1348 |
} |
1349 |
|
1350 |
/** |
1351 |
* Loads the media associated to the given taxon from the cdm server. |
1352 |
* The aggregation settings regarding taxon relathionships and |
1353 |
* taxonnomic childen are taken into account. |
1354 |
* |
1355 |
* The media lists are cached in a static variable. |
1356 |
* |
1357 |
* @param Taxon $taxon |
1358 |
* A CDM Taxon entity |
1359 |
* |
1360 |
* @return array |
1361 |
* An array of CDM Media entities |
1362 |
* |
1363 |
*/ |
1364 |
function _load_media_for_taxon($taxon) { |
1365 |
|
1366 |
static $media = NULL; |
1367 |
|
1368 |
if(!isset($media)) { |
1369 |
$media = array(); |
1370 |
} |
1371 |
if (!isset($media[$taxon->uuid])) { |
1372 |
|
1373 |
|
1374 |
$mediaQueryParameters = taxon_media_query_parameters(); |
1375 |
|
1376 |
$ws_endpoint = NULL; |
1377 |
if ( $mediaQueryParameters['includeTaxonomicChildren']) { |
1378 |
$ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA; |
1379 |
} else { |
1380 |
$ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA; |
1381 |
} |
1382 |
// this parameter is not yet used by the CDM_WS_PORTAL_TAXON_*MEDIA |
1383 |
// services |
1384 |
unset($mediaQueryParameters['includeTaxonomicChildren']); |
1385 |
|
1386 |
$media[$taxon->uuid] = cdm_ws_get($ws_endpoint, |
1387 |
array( |
1388 |
$taxon->uuid, |
1389 |
), |
1390 |
queryString($mediaQueryParameters) |
1391 |
); |
1392 |
} |
1393 |
|
1394 |
return $media[$taxon->uuid]; |
1395 |
} |
1396 |
|
1397 |
/** |
1398 |
* |
1399 |
* @param Taxon $taxon |
1400 |
* A CDM Taxon entitiy |
1401 |
* |
1402 |
* @return array |
1403 |
* An array of CDM SpecimenOrObservation entities |
1404 |
* |
1405 |
function _load_occurences_for_taxon($taxon){ |
1406 |
|
1407 |
static $occurences = NULL; |
1408 |
|
1409 |
if(!isset($occurences)) { |
1410 |
$occurences = array(); |
1411 |
} |
1412 |
|
1413 |
if (!isset($occurences[$taxon->uuid])){ |
1414 |
|
1415 |
$relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT)); |
1416 |
$relationship_choice['direct'] = get_selection($relationship_choice['direct']); |
1417 |
$relationship_choice['invers'] = get_selection($relationship_choice['invers']); |
1418 |
|
1419 |
$by_associatedtaxon_query = http_build_query(array( |
1420 |
'relationshipsInvers' => implode(',', $relationship_choice['invers']), |
1421 |
'relationships' => implode(',', $relationship_choice['direct']), |
1422 |
'pageSize' => null // all hits in one page |
1423 |
) |
1424 |
); |
1425 |
|
1426 |
$pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON, |
1427 |
null, |
1428 |
$by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid |
1429 |
); |
1430 |
|
1431 |
|
1432 |
if(isset($pager->records[0])){ |
1433 |
$occurences[$taxon->uuid] = $pager->records; |
1434 |
} |
1435 |
} |
1436 |
return $occurences[$taxon->uuid]; |
1437 |
} |
1438 |
*/ |
1439 |
|
1440 |
/** |
1441 |
* Gets a Drupal variable, string or array and returns it. |
1442 |
* |
1443 |
* Similar to the variable_get() function of Drupal, except that this function |
1444 |
* is able to handle arrays correctly. This function is especially useful |
1445 |
* when dealing with collections of settings form elements (#tree = TRUE). |
1446 |
* |
1447 |
* @param string $variableKey |
1448 |
* The Unique key of the Drupal variable in the Drupal variables table. |
1449 |
* @param string $defaultValueString |
1450 |
* A string as for example derived from a CONSTANT. |
1451 |
* |
1452 |
* @return mixed |
1453 |
* usually an array, depending on the nature of the variable. |
1454 |
* |
1455 |
* TODO compare with get_array_variable_merged() duplicate functions? |
1456 |
* @deprecated rather use get_array_variable_merged() since this function |
1457 |
* used an array as second parameter |
1458 |
*/ |
1459 |
function mixed_variable_get($variableKey, $defaultValueString) { |
1460 |
$systemDefaults = unserialize($defaultValueString); |
1461 |
$storedSettings = variable_get($variableKey, array()); |
1462 |
if (is_array($storedSettings)) { |
1463 |
// TODO better use drupal_array_merge_deep() ? |
1464 |
$settings = array_merge($systemDefaults, $storedSettings); |
1465 |
} |
1466 |
else { |
1467 |
$settings = $systemDefaults; |
1468 |
} |
1469 |
return $settings; |
1470 |
} |
1471 |
|
1472 |
/** |
1473 |
* Recursive function to convert an object into an array. |
1474 |
* also subordinate objects will be converted. |
1475 |
* |
1476 |
* @param object $object |
1477 |
* the object to be converted |
1478 |
* @return array |
1479 |
* The array |
1480 |
*/ |
1481 |
function object_to_array($object) { |
1482 |
if(is_object($object) || is_array($object)) { |
1483 |
$array = (array)$object; |
1484 |
foreach ($array as $key=>$value){ |
1485 |
$array[$key] = object_to_array($value); |
1486 |
} |
1487 |
return $array; |
1488 |
} else { |
1489 |
return $object; |
1490 |
} |
1491 |
} |
1492 |
|
1493 |
/** |
1494 |
* Searches the $collection for the cdm entitiy given as $element. |
1495 |
* |
1496 |
* The elements are compared by their UUID. |
1497 |
* |
1498 |
* @param $element |
1499 |
* the CDM entitiy to search for |
1500 |
* @param $collection |
1501 |
* the list of CDM entities to search in |
1502 |
* |
1503 |
* @return boolean TRUE if the $collection contains the $element, otheriwse FALSE |
1504 |
* |
1505 |
*/ |
1506 |
function contains_cdm_entitiy($element, $collection) { |
1507 |
$result = FALSE; |
1508 |
foreach ($collection as $a) { |
1509 |
if ($a->uuid == $element->uuid) { |
1510 |
$result = TRUE; |
1511 |
} |
1512 |
} |
1513 |
return $result; |
1514 |
} |
1515 |
|
1516 |
/** |
1517 |
* Filters the array $entity_list of CDM entities by the list |
1518 |
* of $excludes. Any element contained in the $excludes will be removed |
1519 |
* from included int the returned list. |
1520 |
* |
1521 |
* If the $entity_list is not an array the $excludes will be returned. |
1522 |
*/ |
1523 |
function filter_cdm_entity_list($entity_list, $excludes) { |
1524 |
if (is_array($entity_list)) { |
1525 |
$result = $entity_list; |
1526 |
if ($excludes) { |
1527 |
foreach ($excludes as $exclude) { |
1528 |
if (!contains_cdm_entitiy($exclude, $entity_list)) { |
1529 |
$result[] = $exclude; |
1530 |
} |
1531 |
} |
1532 |
} |
1533 |
} |
1534 |
else { |
1535 |
$result = $excludes; |
1536 |
} |
1537 |
return $result; |
1538 |
} |
1539 |
|
1540 |
/** |
1541 |
* Wraps the given $html string into a render array suitable for drupal_render() |
1542 |
* |
1543 |
* @param $html |
1544 |
* the html string, see |
1545 |
* http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#markup |
1546 |
* @param $weight |
1547 |
* A positive or negative number (integer or decimal). |
1548 |
* see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#weightval |
1549 |
* @param $prefix |
1550 |
* Optional markup for the '#prefix' element of the render array |
1551 |
* @param $suffix |
1552 |
* Optional markup for the '#suffix' element of the render array |
1553 |
* |
1554 |
* @return array |
1555 |
* A render array |
1556 |
* |
1557 |
*/ |
1558 |
function markup_to_render_array($html, $weight = FALSE, $prefix = NULL, $suffix = NULL) { |
1559 |
$render_array = array( |
1560 |
'#markup' => $html |
1561 |
); |
1562 |
if (is_numeric($weight)) { |
1563 |
$render_array['#weight'] = $weight; |
1564 |
} |
1565 |
if($prefix){ |
1566 |
$render_array['#prefix'] = $prefix; |
1567 |
} |
1568 |
if($suffix) { |
1569 |
$render_array['#suffix'] = $suffix; |
1570 |
} |
1571 |
return $render_array; |
1572 |
} |
1573 |
|
1574 |
/** |
1575 |
* Loads the subgraph of a given PolytomousKeyNode. |
1576 |
* |
1577 |
* Loads the subgraph of the given PolytomousKeyNode recursively from |
1578 |
* the CDM REST service. |
1579 |
* |
1580 |
* @param mixed $polytomousKeyNode |
1581 |
* PolytomousKeyNode passed by reference. |
1582 |
* |
1583 |
* @return void |
1584 |
*/ |
1585 |
function _load_polytomousKeySubGraph(&$polytomousKeyNode) { |
1586 |
|
1587 |
if (!$polytomousKeyNode) { |
1588 |
return; |
1589 |
} |
1590 |
if ($polytomousKeyNode->class != "PolytomousKeyNode") { |
1591 |
drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error'); |
1592 |
return; |
1593 |
} |
1594 |
if (!is_uuid($polytomousKeyNode->uuid)) { |
1595 |
drupal_set_message('_load_polytomousKeySubGraph(): ' . t('invalid type given.'), 'error'); |
1596 |
return; |
1597 |
} |
1598 |
|
1599 |
$polytomousKeyNode = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, $polytomousKeyNode->uuid); |
1600 |
|
1601 |
if (!$polytomousKeyNode) { |
1602 |
// drupal_set_message("_load_polytomousKeyChildNodes() : could not load polytomousKeyNode", "error"); |
1603 |
return; |
1604 |
} |
1605 |
|
1606 |
// Load children. |
1607 |
foreach ($polytomousKeyNode->children as &$childNode) { |
1608 |
_load_polytomousKeySubGraph($childNode); |
1609 |
} |
1610 |
|
1611 |
// Load subkey. |
1612 |
$polytomousKeyNode->subkey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "subkey")); |
1613 |
|
1614 |
// Load taxon. |
1615 |
$polytomousKeyNode->taxon = cdm_ws_get(CDM_WS_POLYTOMOUSKEY_NODE, array($polytomousKeyNode->uuid, "taxon")); |
1616 |
_load_taxonBase($polytomousKeyNode->taxon); |
1617 |
return; |
1618 |
} |
1619 |
|
1620 |
/** |
1621 |
* @todo Please document this function. |
1622 |
* @see http://drupal.org/node/1354 |
1623 |
*/ |
1624 |
function cdm_dataportal_view_polytomousKey($polytomousKeyUuid) { |
1625 |
|
1626 |
cdm_check_valid_portal_page(); |
1627 |
|
1628 |
$polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid); |
1629 |
if (!$polytomousKey) { |
1630 |
drupal_set_title(t('Polytomous key does not exist'), PASS_THROUGH); |
1631 |
return ""; |
1632 |
} |
1633 |
|
1634 |
$sourcePager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources')); |
1635 |
if (is_array($sourcePager->records)) { |
1636 |
$polytomousKey->sources = $sourcePager->records; |
1637 |
// $polytomousKey->sources->citation = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'sources')); |
1638 |
} |
1639 |
|
1640 |
$annotationPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, array($polytomousKeyUuid, 'annotations')); |
1641 |
if (is_array($annotationPager->records)) { |
1642 |
$polytomousKey->annotations = $annotationPager->records; |
1643 |
} |
1644 |
|
1645 |
_load_polytomousKeySubGraph($polytomousKey->root); |
1646 |
return theme('cdm_polytomousKey_page', array('polytomousKey' => $polytomousKey)); |
1647 |
} |
1648 |
|
1649 |
/** |
1650 |
* Creates a taxon page view or a chapter of it. |
1651 |
* |
1652 |
* The taxon page gives detailed information on a taxon, it shows: |
1653 |
* - Taxon name. |
1654 |
* - Full list of synonyms homotypic synonyms on top, followed by the |
1655 |
* heterotypic and finally followed by misapplied names. |
1656 |
* The list is ordered historically. |
1657 |
* - All description associated with the taxon. |
1658 |
* |
1659 |
* @param string $uuid |
1660 |
* @param string $chapter |
1661 |
* Name of the part to display, valid values are: |
1662 |
* 'description', 'images', 'synonymy', 'specimens', 'all'. |
1663 |
* |
1664 |
* @return string |
1665 |
*/ |
1666 |
function cdm_dataportal_taxon_page_view($uuid, $chapter = 'all') { |
1667 |
|
1668 |
cdm_check_valid_taxon_page($chapter); |
1669 |
cdm_dd("START OF TAXON PAGE [" . $chapter . "] " . $uuid . ' for ' . $_GET['q']); |
1670 |
|
1671 |
|
1672 |
// Display the page for the taxon defined by $uuid. |
1673 |
// set_last_taxon_page_tab(arg(3)); |
1674 |
$taxonpage = cdm_dataportal_taxon_view($uuid, $chapter); |
1675 |
if (!empty($taxonpage)) { |
1676 |
cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid); |
1677 |
return cdm_node_show(NODETYPE_TAXON, $uuid, $taxonpage->title, $taxonpage->content); |
1678 |
} |
1679 |
else { |
1680 |
cdm_dd("END OF TAXON PAGE [" . $chapter . "] " . $uuid . ' !!! PAGE IS EMPTY !!!'); |
1681 |
return ''; |
1682 |
} |
1683 |
} |
1684 |
|
1685 |
/** |
1686 |
* This function will generate the taxon page part ($chapter) and returns a taxonpage object |
1687 |
* which has two fields, one for the page title and one for the content. Later on in the |
1688 |
* process chain the value contained in these fields will be passed to the cdm_node_show() |
1689 |
* function as the function parameters $title and $content. |
1690 |
* |
1691 |
* @param string $uuid |
1692 |
* the uuid of the taxon to show |
1693 |
* @param string $chapter |
1694 |
* Name of the part to display, valid values are: |
1695 |
* 'description', 'images', 'synonymy', 'all'. |
1696 |
* |
1697 |
* @return object with the following fields: |
1698 |
* - title : the title of the page |
1699 |
* - content: the content of the page |
1700 |
* |
1701 |
* @throws Exception |
1702 |
* |
1703 |
*/ |
1704 |
function cdm_dataportal_taxon_view($uuid, $chapter = 'all') { |
1705 |
// Taxon object. |
1706 |
$taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $uuid); |
1707 |
if (empty($taxon)) { |
1708 |
drupal_set_title(t('Taxon does not exist'), PASS_THROUGH); |
1709 |
return null; |
1710 |
} |
1711 |
$taxonpage = new stdClass(); |
1712 |
|
1713 |
$taxonpage->title = theme('cdm_taxon_page_title', array( |
1714 |
'taxon' => $taxon |
1715 |
)); |
1716 |
|
1717 |
// Check if the taxon id contained in the currently selected tree. |
1718 |
$taxon_in_current_classification = taxon_in_current_classification($uuid); |
1719 |
|
1720 |
if (!$taxon_in_current_classification) { |
1721 |
$classifications = get_classifications_for_taxon($taxon); |
1722 |
RenderHints::pushToRenderStack('not_in_current_classification'); |
1723 |
$taxon_name_markup = render_taxon_or_name($taxon); |
1724 |
|
1725 |
if (count($classifications) == 0) { |
1726 |
drupal_set_message(t('This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification.', |
1727 |
array( |
1728 |
'!taxonname' => $taxon_name_markup, |
1729 |
) |
1730 |
), 'warning'); |
1731 |
} |
1732 |
else { |
1733 |
$trees = ''; |
1734 |
foreach ($classifications as $classification) { |
1735 |
if (isset($classification->titleCache)) { |
1736 |
$trees .= ($trees ? ', ' : '') . '<strong>' . $classification->titleCache . '</strong>'; |
1737 |
} |
1738 |
} |
1739 |
|
1740 |
drupal_set_message(format_plural(count($trees), |
1741 |
'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in this one: !trees', |
1742 |
'This concept of the taxon !taxonname is not contained as an accepted taxon in the currently chosen classification, but in one of these: !trees', |
1743 |
array('!taxonname' => $taxon_name_markup, '!trees' => $trees) |
1744 |
) , |
1745 |
'warning'); |
1746 |
} |
1747 |
RenderHints::popFromRenderStack(); |
1748 |
} |
1749 |
|
1750 |
// Render the taxon page. |
1751 |
$render_array = compose_cdm_taxon_page($taxon, $chapter); |
1752 |
$taxonpage->content = drupal_render($render_array); |
1753 |
|
1754 |
return $taxonpage; |
1755 |
} |
1756 |
|
1757 |
|
1758 |
function cdm_dataportal_specimen_by_accession_number_page_view($accession_number) |
1759 |
{ |
1760 |
cdm_check_valid_portal_page(); |
1761 |
|
1762 |
$specimenpage = specimen_by_accession_number_view($accession_number); |
1763 |
|
1764 |
if (!empty($specimenpage)) { |
1765 |
return cdm_node_show_simulate($specimenpage->content); |
1766 |
} |
1767 |
else { |
1768 |
return ''; |
1769 |
} |
1770 |
|
1771 |
|
1772 |
} |
1773 |
|
1774 |
/** |
1775 |
* Creates a specimen page view. |
1776 |
* @param string $uuid the UUID of the specimen |
1777 |
* @return array|string |
1778 |
*/ |
1779 |
function cdm_dataportal_specimen_page_view($uuid) { |
1780 |
|
1781 |
cdm_check_valid_portal_page(); |
1782 |
$specimenpage = cdm_dataportal_specimen_view($uuid); |
1783 |
if (!empty($specimenpage)) { |
1784 |
return cdm_node_show_simulate($specimenpage->content); |
1785 |
} |
1786 |
else { |
1787 |
return ''; |
1788 |
} |
1789 |
} |
1790 |
|
1791 |
|
1792 |
/** |
1793 |
* Creates a specimen page view. |
1794 |
* @param string $uuid the UUID of the specimen |
1795 |
* @return object |
1796 |
* The page object with the following fields: |
1797 |
* - 'title': the page title |
1798 |
* - 'content' : the page content rendered as markup |
1799 |
*/ |
1800 |
function specimen_by_accession_number_view($accession_number = null) { |
1801 |
|
1802 |
$field_unit_dto = cdm_ws_get(CDM_WS_OCCURRENCE_ACCESSION_NUMBER, null, 'accessionNumber=' . $accession_number); |
1803 |
|
1804 |
// Display the page for the specimen defined by $uuid. |
1805 |
if (isset($field_unit_dto)){ |
1806 |
$dto_array = array($field_unit_dto); |
1807 |
$specimen_array = specimen_render_array_items($dto_array); |
1808 |
$specimen_table = array( |
1809 |
'#theme' => 'table', |
1810 |
'#weight' => 2, |
1811 |
// prefix attributes and rows with '#' to let it pass toF the theme function, |
1812 |
// otherwise it is handled as child render array |
1813 |
'#attributes' => array('class' => 'specimens'), |
1814 |
'#rows' => array(), |
1815 |
'#prefix' => '<div id="specimens">', |
1816 |
'#suffix' => '</div>', |
1817 |
); |
1818 |
foreach($specimen_array as $value){ |
1819 |
$renderArray = array( |
1820 |
'#theme' => 'item_list', |
1821 |
'#items' => array($value), |
1822 |
'#type' => 'ul'); |
1823 |
$output = drupal_render($renderArray); |
1824 |
$specimen_table['#rows'][] = array( |
1825 |
// An array of table rows. Every row is an array of cells, or an associative array |
1826 |
'data' => array($output), |
1827 |
'class' => array( |
1828 |
'descriptionElement', |
1829 |
'descriptionElement_IndividualsAssociation' |
1830 |
), |
1831 |
); |
1832 |
|
1833 |
|
1834 |
} |
1835 |
$specimenpage = new stdClass(); |
1836 |
|
1837 |
$specimenpage->title = theme('theme_cdm_specimen_dto_page_title', array( |
1838 |
'specimen' => $field_unit_dto |
1839 |
)); |
1840 |
|
1841 |
$render_array['markup'] = $specimen_table; |
1842 |
$specimenpage->content = drupal_render($render_array); |
1843 |
} |
1844 |
|
1845 |
return $specimenpage; |
1846 |
} |
1847 |
|
1848 |
|
1849 |
/** |
1850 |
* |
1851 |
* Creates a specimen view. |
1852 |
* @param string $uuid the UUID of the specimen |
1853 |
* @return object |
1854 |
* Page object with the fields |
1855 |
* - title |
1856 |
* - content |
1857 |
*/ |
1858 |
function cdm_dataportal_specimen_view($uuid) { |
1859 |
//TODO: get the derivateDTO and don't call the webservice a second time in compose_cdm_specimen_page |
1860 |
$specimen = cdm_ws_get(CDM_WS_PORTAL_OCCURRENCE, $uuid); |
1861 |
if (empty($specimen)) { |
1862 |
drupal_set_title(t('Specimen does not exist'), PASS_THROUGH); |
1863 |
return FALSE; |
1864 |
} |
1865 |
$specimenpage = new stdClass(); |
1866 |
|
1867 |
$specimenpage->title = specimen_page_title($specimen); |
1868 |
|
1869 |
// Render the specimen page. |
1870 |
$render_array = compose_cdm_specimen_page($specimen); |
1871 |
$specimenpage->content = drupal_render($render_array); |
1872 |
|
1873 |
return $specimenpage; |
1874 |
} |
1875 |
|
1876 |
/** |
1877 |
* |
1878 |
* Creates a description view. |
1879 |
* |
1880 |
* @param string $uuid the UUID of the description |
1881 |
* @param null $descriptive_dataset_uuid the uuid of the data set which defines |
1882 |
* the display of the description detail page |
1883 |
* |
1884 |
* @return object Page object with the fields |
1885 |
* Page object with the fields |
1886 |
* - title |
1887 |
* - content |
1888 |
*/ |
1889 |
function cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid = NULL) { |
1890 |
$description = cdm_ws_get(CDM_WS_PORTAL_DESCRIPTION, $uuid); |
1891 |
$description_page = new stdClass(); |
1892 |
if (empty($description)) { |
1893 |
$description_page->title = t('Description does not exist'); |
1894 |
drupal_set_title($description_page->title, PASS_THROUGH); // not necessary if correctly implemented as drupal node |
1895 |
$description_page->content = ""; |
1896 |
|
1897 |
} else { |
1898 |
$description_page->title = $description->titleCache; |
1899 |
drupal_set_title($description_page->title); // not necessary if correctly implemented as drupal node |
1900 |
|
1901 |
// Render the description page. |
1902 |
$render_array = compose_description_table($description->uuid, $descriptive_dataset_uuid); |
1903 |
if($render_array['title']){ |
1904 |
$page_title = strip_tags($render_array['title']['#markup']); |
1905 |
drupal_set_title($page_title); |
1906 |
unset($render_array['title']); |
1907 |
} |
1908 |
$description_page->content = drupal_render($render_array); |
1909 |
} |
1910 |
|
1911 |
return $description_page; |
1912 |
} |
1913 |
|
1914 |
function cdm_dataportal_description_page_view($uuid, $descriptive_dataset_uuid = NULL) { |
1915 |
|
1916 |
cdm_check_valid_portal_page(); |
1917 |
$descriptionpage = cdm_dataportal_description_view($uuid, $descriptive_dataset_uuid); |
1918 |
if (!empty($descriptionpage)) { |
1919 |
return cdm_node_show_simulate($descriptionpage->content); |
1920 |
} |
1921 |
else { |
1922 |
return NULL; |
1923 |
} |
1924 |
} |
1925 |
|
1926 |
/** |
1927 |
* |
1928 |
* Creates a named area view. |
1929 |
* @param string $uuid the UUID of the specimen |
1930 |
* * @return object |
1931 |
* An object with two fields: |
1932 |
* - title: the page title |
1933 |
* - content: the page content |
1934 |
*/ |
1935 |
|
1936 |
function cdm_dataportal_named_area_view($uuid) { |
1937 |
$named_area = cdm_ws_get(CDM_WS_PORTAL_TERM, $uuid); |
1938 |
if (empty($named_area) || $named_area->class !== 'NamedArea') { |
1939 |
drupal_set_title(t('Named area does not exist'), PASS_THROUGH); |
1940 |
return null; |
1941 |
} |
1942 |
$named_area_page = new stdClass(); |
1943 |
|
1944 |
$named_area_page->title = $named_area->representation_L10n; |
1945 |
|
1946 |
// Render the specimen page. |
1947 |
$render_array = compose_cdm_named_area_page($uuid); |
1948 |
$named_area_page->content = drupal_render($render_array); |
1949 |
|
1950 |
return $named_area_page; |
1951 |
} |
1952 |
|
1953 |
function cdm_dataportal_named_area_page_view($uuid) { |
1954 |
|
1955 |
cdm_check_valid_portal_page(); |
1956 |
|
1957 |
$named_area_page = cdm_dataportal_named_area_view($uuid); |
1958 |
if (!empty($named_area_page)) { |
1959 |
return cdm_node_show(NODETYPE_NAME, $uuid, $named_area_page->title, $named_area_page->content); |
1960 |
} |
1961 |
else { |
1962 |
return ''; |
1963 |
} |
1964 |
|
1965 |
|
1966 |
} |
1967 |
|
1968 |
/** |
1969 |
* Returns a name page as a Drupal node ready to be renderized by Drupal. |
1970 |
* |
1971 |
* The node page shows the taxon name title and the list of taxon related |
1972 |
* with such taxon. Name on the tree already in use. |
1973 |
* |
1974 |
* @param string $taxon_name_uuid |
1975 |
* The uuid of the CDM TaxonName to show a name page for |
1976 |
* @param string $taxon_to_hide_uuid |
1977 |
* A taxon which should not be displayed in the taxon list |
1978 |
* @param $redirect_to_taxon |
1979 |
* Automatically redirect to the related taxon if there is only one |
1980 |
* accepted taxon for this name. |
1981 |
* @param string $highlite_synonym_uuid |
1982 |
* Optinal parameter wich takes another taxon uuid, if given the |
1983 |
* target taxon pages will show the syonymy tab where the taxon |
1984 |
* refenrenced by the $highlite_synonym_uuid will be highlighted |
1985 |
* in case it is found on this page. |
1986 |
* |
1987 |
* @return mixed |
1988 |
* The formatted name page as node. |
1989 |
*/ |
1990 |
function cdm_dataportal_name_page_view($taxon_name_uuid, $taxon_to_hide_uuid, $synonym_uuid = NULL, $redirect_to_taxon = false) { |
1991 |
|
1992 |
cdm_check_valid_portal_page(); |
1993 |
|
1994 |
$taxonname_page = cdm_dataportal_name_view( |
1995 |
is_uuid($taxon_name_uuid) ? $taxon_name_uuid : null, |
1996 |
is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : null, |
1997 |
$redirect_to_taxon == 'redirect_to_taxon', |
1998 |
is_uuid($synonym_uuid) ? $synonym_uuid : null); |
1999 |
if (!empty($taxonname_page)) { |
2000 |
return cdm_node_show(NODETYPE_NAME, $taxon_name_uuid, $taxonname_page->title, $taxonname_page->content); |
2001 |
} |
2002 |
else { |
2003 |
return ''; |
2004 |
} |
2005 |
} |
2006 |
|
2007 |
/** |
2008 |
* View function for a TaxonName page. |
2009 |
* |
2010 |
* The name page lists all taxa for which the name specified by the |
2011 |
* $taxon_name_uuid is being used. I case there is only one name the |
2012 |
* page automatically redirects ti the according taxon page. Otherwise |
2013 |
* the list of names is displayed. |
2014 |
* |
2015 |
* The parameter $taxon_to_hide_uuid allows to exclude a taxon from the |
2016 |
* list of taxa. This is useful for example when referencing from a taxon |
2017 |
* to the name page and the referring taxon should not be repeaded in the |
2018 |
* name page. |
2019 |
* |
2020 |
* |
2021 |
* @param string $taxon_name_uuid |
2022 |
* The uuid of the CDM TaxonName to show a name page for |
2023 |
* @param string $taxon_to_hide_uuid |
2024 |
* A taxon which should not be displayed in the taxon list |
2025 |
* @param $redirect_to_taxon |
2026 |
* Automatically redirect to the related taxon if there is only one |
2027 |
* accepted taxon for this name. |
2028 |
* @param string $highlite_synonym_uuid |
2029 |
* Optional parameter which takes another taxon uuid, if given the |
2030 |
* target taxon pages will show the synonymy tab where the taxon |
2031 |
* referenced by the $highlite_synonym_uuid will be highlighted |
2032 |
* in case it is found on this page. |
2033 |
* |
2034 |
* @return object|boolean |
2035 |
* An object with two fields: |
2036 |
* - title: the page title |
2037 |
* - content: the page content |
2038 |
* or FALSE |
2039 |
* |
2040 |
*/ |
2041 |
function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $redirect_to_taxon, $highlite_synonym_uuid = NULL) { |
2042 |
// Getting the full taxonname object from the server. |
2043 |
$taxon_name = cdm_ws_get(CDM_WS_PORTAL_NAME, array($taxon_name_uuid)); |
2044 |
if (!$taxon_name) { |
2045 |
drupal_set_title(t('Taxon name does not exist'), PASS_THROUGH); |
2046 |
return FALSE; |
2047 |
} |
2048 |
cdm_load_tagged_full_title($taxon_name); |
2049 |
// Searching for all the taxa connected with the taxon name on the tree |
2050 |
// in use. |
2051 |
$name = cdm_ws_get(CDM_WS_NAME, array($taxon_name_uuid)); |
2052 |
$restrictions = array(new Restriction("name.titleCache","EXACT", array($name->titleCache), 'AND')); |
2053 |
$init_strategy = array( |
2054 |
"name.titleCache", |
2055 |
"name.nomenclaturalReference.authorship", |
2056 |
"name.nomenclaturalReference.inReference.authorship", |
2057 |
"name.nomenclaturalReference.inReference.inReference.authorship", |
2058 |
"name.nomenclaturalReference.inReference.inReference.inReference.authorship" |
2059 |
); |
2060 |
$taxa = cdm_ws_fetch_all_by_restriction("Taxon", NULL, $restrictions, $init_strategy); |
2061 |
|
2062 |
// Removing the name where we came from. |
2063 |
foreach ($taxa as $k => &$taxon) { |
2064 |
if ($taxon->uuid == $taxon_to_hide_uuid) { |
2065 |
unset($taxa[$k]); |
2066 |
} |
2067 |
} |
2068 |
// Show the taxa list or go to the singular taxon. |
2069 |
if (sizeof($taxa) == 1 && $redirect_to_taxon) { |
2070 |
// redirect to the taxon if there is only one. |
2071 |
$singleTaxon = array_pop($taxa); |
2072 |
if ($singleTaxon->class != "Taxon") { |
2073 |
// It is a Synonym -> look for the accepted. |
2074 |
$accepted_taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($singleTaxon->uuid), 'classificationFilter=' . get_current_classification_uuid()); |
2075 |
if (!empty($highlite_synonym_uuid)) { |
2076 |
drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid))); |
2077 |
} |
2078 |
else { |
2079 |
drupal_goto('cdm_dataportal/taxon/' . $accepted_taxon->uuid . '/synonymy', array('query' => array('highlite' => $singleTaxon->uuid))); |
2080 |
} |
2081 |
} |
2082 |
else { |
2083 |
// It is an accepted taxon. |
2084 |
if (!empty($highlite_synonym_uuid)) { |
2085 |
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid . '/synonymy', array('query' => array('highlite' => $highlite_synonym_uuid))); |
2086 |
} |
2087 |
else { |
2088 |
drupal_goto('cdm_dataportal/taxon/' . $singleTaxon->uuid); |
2089 |
} |
2090 |
} |
2091 |
} |
2092 |
else { |
2093 |
// display the name page content |
2094 |
$taxon_name_page = new stdClass(); |
2095 |
$taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name)); |
2096 |
$content = array(); |
2097 |
|
2098 |
RenderHints::pushToRenderStack('name_page'); |
2099 |
RenderHints::setFootnoteListKey('name_page'); |
2100 |
$content['taxon_name'] = markup_to_render_array(render_taxon_or_name($taxon_name), null, '<div class="name-page-name">', '</div>'); |
2101 |
|
2102 |
|
2103 |
// name relationships |
2104 |
$name_relations = cdm_ws_fetch_all(str_replace("$0", $taxon_name->uuid, CDM_WS_PORTAL_NAME_NAME_RELATIONS)); |
2105 |
if(count($name_relations) > 0){ |
2106 |
$content['name_relationships'] = compose_name_relationships_list($name_relations, $taxon_name->uuid, null); |
2107 |
} |
2108 |
|
2109 |
// type designations |
2110 |
$type_designations_render_array = compose_type_designations($taxon_name->uuid); |
2111 |
$content = array_merge($content, $type_designations_render_array); |
2112 |
// registrations |
2113 |
$registrationDTOs= cdm_ws_fetch_all(CDM_WS_REGISTRATION_DTO, array('nameUuid' => $taxon_name_uuid)); |
2114 |
if(isset($registrationDTOs) && count($registrationDTOs ) > 0 ){ |
2115 |
$content['registrations'][] = markup_to_render_array('<h2>' . t("Registrations") . '</h2>') ; |
2116 |
foreach ($registrationDTOs as $regDTO){ |
2117 |
$content['registrations'][] = compose_registration_dto_compact($regDTO); |
2118 |
} |
2119 |
} |
2120 |
|
2121 |
|
2122 |
// related taxa |
2123 |
$show_taxa_section = variable_get(CDM_NAME_PAGE_SECTION_TAXA, CDM_NAME_PAGE_SECTION_TAXA_DEFAULT); |
2124 |
if($show_taxa_section){ |
2125 |
if ($taxa) { |
2126 |
$content['related_taxa_header'] = markup_to_render_array("<h2>Taxa for this name</h2>"); |
2127 |
$content['related_taxa'] = compose_list_of_taxa($taxa); |
2128 |
} |
2129 |
else { |
2130 |
$content['related_taxa'] = markup_to_render_array('This name is not assigned to a taxon.', null, '<div class="no-taxon-message">', '</div>'); |
2131 |
} |
2132 |
} |
2133 |
|
2134 |
$content['footnotes'] = markup_to_render_array(theme('cdm_footnotes', array('footnoteListKey' => RenderHints::getFootnoteListKey()))); |
2135 |
|
2136 |
$taxon_name_page->content = $content; |
2137 |
RenderHints::popFromRenderStack(); |
2138 |
RenderHints::clearFootnoteListKey(); |
2139 |
return $taxon_name_page; |
2140 |
} |
2141 |
} |
2142 |
|
2143 |
|
2144 |
/** |
2145 |
* Returns a registration page as a Drupal node to be rendered by Drupal. |
2146 |
* |
2147 |
* @param string $registration_identifier_encoded |
2148 |
* The persistent identifier of the registration urlencoded. |
2149 |
* @return mixed |
2150 |
* The formatted registration page as node. |
2151 |
*/ |
2152 |
function cdm_dataportal_registration_page_view($registration_identifier_encoded) { |
2153 |
|
2154 |
cdm_check_valid_portal_page("/\/cdm_dataportal\/registration\/.*$/"); |
2155 |
$registration_page = cdm_dataportal_registration_view($registration_identifier_encoded); |
2156 |
return cdm_node_show_simulate($registration_page); |
2157 |
} |
2158 |
|
2159 |
/** |
2160 |
* @param $registration_identifier_encoded |
2161 |
* @return array |
2162 |
* The drupal render array for the registration view. |
2163 |
*/ |
2164 |
function cdm_dataportal_registration_view($registration_identifier_encoded) { |
2165 |
|
2166 |
$registration_identifier = urldecode($registration_identifier_encoded); |
2167 |
|
2168 |
RenderHints::pushToRenderStack('registration_page'); |
2169 |
RenderHints::setFootnoteListKey('registration_page'); |
2170 |
|
2171 |
$render_array = array(); |
2172 |
$registration_dto = cdm_ws_get(CDM_WS_REGISTRATION_DTO_BY_IDENTIFIER . $registration_identifier_encoded); |
2173 |
if($registration_dto){ |
2174 |
|
2175 |
drupal_set_title(t('Registration Id:') . ' ' . $registration_identifier, PASS_THROUGH); |
2176 |
$render_array = compose_registration_dto_full($registration_dto, true); |
2177 |
|
2178 |
} else { |
2179 |
$status_text = cdm_ws_get(CDM_WS_REGISTRATION_STATUS_BY_IDENTIFIER, array($registration_identifier)); |
2180 |
if(isset($status_text->String)) { |
2181 |
$status_text = strtolower($status_text->String); |
2182 |
if($status_text == 'preparation' || $status_text == 'curation'){ |
2183 |
$status_text = 'in ' . $status_text; |
2184 |
} |
2185 |
drupal_set_title(t('Registration ' . $status_text), PASS_THROUGH); |
2186 |
//$status_message; |
2187 |
drupal_set_message("A registration with the identifier " . $registration_identifier . " is " . $status_text, "status"); |
2188 |
} else { |
2189 |
drupal_set_title(t('Registration not found'), PASS_THROUGH); |
2190 |
drupal_set_message("A registration with the identifier " . $registration_identifier . " does not exist", "warning"); |
2191 |
} |
2192 |
} |
2193 |
|
2194 |
$render_array = array( |
2195 |
'#prefix' => '<div id="registration">', |
2196 |
'registration' => $render_array, |
2197 |
'#suffix' => '</div>', |
2198 |
); |
2199 |
|
2200 |
RenderHints::popFromRenderStack(); |
2201 |
RenderHints::clearFootnoteListKey(); |
2202 |
|
2203 |
return $render_array ; |
2204 |
} |
2205 |
|
2206 |
|
2207 |
/** |
2208 |
* Creates a page with the advance search form. |
2209 |
* |
2210 |
* NOTE: The advance search form allows searching for taxa. |
2211 |
*/ |
2212 |
function cdm_dataportal_view_search_advanced() { |
2213 |
drupal_set_title(t('Advanced search'), PASS_THROUGH); |
2214 |
return drupal_get_form('cdm_dataportal_search_taxon_form_advanced'); |
2215 |
} |
2216 |
|
2217 |
/** |
2218 |
* Creates a page with the blast search form. |
2219 |
* |
2220 |
* NOTE: The advance search form allows searching for specimen in blast DB. |
2221 |
*/ |
2222 |
function cdm_dataportal_view_search_blast() { |
2223 |
drupal_set_title(t('Blast search'), PASS_THROUGH); |
2224 |
return drupal_get_form('cdm_dataportal_search_blast_form'); |
2225 |
} |
2226 |
|
2227 |
/** |
2228 |
* Creates a page with the search form for searching by taxon descriptions. |
2229 |
*/ |
2230 |
function cdm_dataportal_view_search_taxon_by_description() { |
2231 |
drupal_set_title(t('Search by factual data'), PASS_THROUGH); |
2232 |
return drupal_get_form('cdm_dataportal_search_taxon_by_description_form'); |
2233 |
} |
2234 |
|
2235 |
/** |
2236 |
* Executes the search and generates the result list of taxa. |
2237 |
*/ |
2238 |
function cdm_dataportal_view_search_results_taxon() { |
2239 |
|
2240 |
$taxonPager = cdm_dataportal_search_taxon_execute(); |
2241 |
|
2242 |
$showThumbnails = do_showThumbnails(); |
2243 |
|
2244 |
$setSessionUri = url('cdm_api/setvalue/session', array( |
2245 |
'query' => array('var' => '[pageoption][searchtaxa][showThumbnails]', 'val' => ''), |
2246 |
)); |
2247 |
|
2248 |
drupal_add_js('jQuery(document).ready(function() { |
2249 |
|
2250 |
// init |
2251 |
if(' . $showThumbnails . ' == 1){ |
2252 |
jQuery(\'.media_gallery\').show(20); |
2253 |
} else { |
2254 |
jQuery(\'.media_gallery\').hide(20); |
2255 |
} |
2256 |
|
2257 |
// add change handler |
2258 |
jQuery(\'#showThumbnails input.showThumbnails\').change( |
2259 |
function(event){ |
2260 |
var state = 0; |
2261 |
if(jQuery(this).is(\':checked\')){ |
2262 |
jQuery(\'.media_gallery\').show(20); |
2263 |
state = 1; |
2264 |
} else { |
2265 |
jQuery(\'.media_gallery\').hide(20); |
2266 |
} |
2267 |
// store state in session variable |
2268 |
var uri = \'' . $setSessionUri . '\' + state; |
2269 |
jQuery.get(uri); |
2270 |
}); |
2271 |
});', |
2272 |
array('type' => "inline", 'scope' => JS_DEFAULT)); |
2273 |
|
2274 |
drupal_set_title(t('Search results'), PASS_THROUGH); |
2275 |
|
2276 |
return theme('cdm_search_taxa_results', array( |
2277 |
'pager' => $taxonPager, |
2278 |
'path' => 'cdm_dataportal/search/results/taxon', |
2279 |
)); |
2280 |
} |
2281 |
|
2282 |
/** |
2283 |
* Executes the blast search and generates the result list of specimen. |
2284 |
*/ |
2285 |
function cdm_dataportal_view_search_results_specimen() { |
2286 |
|
2287 |
$specimenPager = cdm_dataportal_search_blast_execute(); |
2288 |
|
2289 |
return theme('cdm_search_specimen_results', array( |
2290 |
'pager' => $specimenPager, |
2291 |
'path' => 'cdm_dataportal/search/results/specimen', |
2292 |
)); |
2293 |
} |
2294 |
|
2295 |
|
2296 |
/** |
2297 |
* Executes the search for registrations and generates the result list.. |
2298 |
*/ |
2299 |
function cdm_dataportal_view_search_registrations_results($mode = 'filter') { |
2300 |
|
2301 |
switch($mode ){ |
2302 |
case 'taxongraph': |
2303 |
$block = block_load('cdm_dataportal', 'registrations_search_taxongraph'); |
2304 |
$registration_pager = cdm_dataportal_search_registrations_taxongraph_execute(); |
2305 |
break; |
2306 |
case 'filter': |
2307 |
default: |
2308 |
$block = block_load('cdm_dataportal', 'registrations_search_filter'); |
2309 |
$registration_pager = cdm_dataportal_search_registrations_filter_execute(); |
2310 |
} |
2311 |
$block->title = null; |
2312 |
|
2313 |
drupal_set_title(t('Search registrations'), PASS_THROUGH); |
2314 |
|
2315 |
$render_array = _block_get_renderable_array(_block_render_blocks(array($block))); |
2316 |
$registrations_pager_array = compose_search_results($registration_pager, new RegistrationDTOComposeHandler()); |
2317 |
$render_array = array_merge($render_array, $registrations_pager_array); |
2318 |
|
2319 |
return $render_array; |
2320 |
} |
2321 |
|
2322 |
/** |
2323 |
* Executes the search for registrations and generates the result list.. |
2324 |
*/ |
2325 |
function cdm_dataportal_view_search_agent() { |
2326 |
|
2327 |
$render_array = []; |
2328 |
$title = isset($_REQUEST['class']) && $_REQUEST['class'] ? $_REQUEST['class'] : 'Persons & Teams'; |
2329 |
drupal_set_title(t($title), PASS_THROUGH); |
2330 |
// TODO $block = block_load('cdm_dataportal', 'search_agent_filter'); |
2331 |
// $block->title = null; |
2332 |
// $render_array = _block_get_renderable_array(_block_render_blocks(array($block))); |
2333 |
$pager = cdm_dataportal_search_agent_execute(); |
2334 |
$pager_render_array = compose_search_results($pager, new AgentComposeHandler()); |
2335 |
$render_array = array_merge($render_array, $pager_render_array); |
2336 |
return $render_array; |
2337 |
} |
2338 |
|
2339 |
|
2340 |
/** |
2341 |
* Provides the standard image which indicated a loading process |
2342 |
* |
2343 |
* @return string |
2344 |
* The img html tag |
2345 |
*/ |
2346 |
function loading_image_html() { |
2347 |
return '<img class="loading" src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') |
2348 |
. '/images/loading_circle_grey_16.gif" style="display:none;">'; |
2349 |
} |
2350 |
|
2351 |
/** |
2352 |
* Returns the state of the the showThumbnails flag set in the |
2353 |
* users session ($_SESSION['pageoption']['searchtaxa']['showThumbnails']). |
2354 |
* |
2355 |
* @return boolean |
2356 |
* returns 1 if the flag is set |
2357 |
*/ |
2358 |
function do_showThumbnails() { |
2359 |
static $showThumbnails = null; |
2360 |
|
2361 |
if($showThumbnails == null) { |
2362 |
$showThumbnails = 0; |
2363 |
if (!isset($_SESSION['pageoption']['searchtaxa']['showThumbnails'])) { |
2364 |
$showThumbnails = 0; |
2365 |
$search_gallery_settings = variable_get(CDM_DATAPORTAL_SEARCH_GALLERY_NAME, null); |
2366 |
$showThumbnails = is_array($search_gallery_settings) |
2367 |
&& isset($search_gallery_settings['cdm_dataportal_show_taxon_thumbnails']) |
2368 |
&& ( |
2369 |
$search_gallery_settings['cdm_dataportal_show_taxon_thumbnails'] + |
2370 |
$search_gallery_settings['cdm_dataportal_show_synonym_thumbnails'] + |
2371 |
$search_gallery_settings['cdm_dataportal_show_thumbnail_captions'] > 0 |
2372 |
) |
2373 |
? 1 : 0; |
2374 |
|
2375 |
drupal_array_set_nested_value($_SESSION, array('pageoption', 'searchtaxa', 'showThumbnails'), $showThumbnails); |
2376 |
} |
2377 |
$showThumbnails = $_SESSION['pageoption']['searchtaxa']['showThumbnails']; |
2378 |
if (!is_numeric($showThumbnails)) { |
2379 |
$showThumbnails = 1; |
2380 |
} |
2381 |
} |
2382 |
|
2383 |
return $showThumbnails; |
2384 |
} |
2385 |
|
2386 |
|
2387 |
|
2388 |
/* ====================== other functions ====================== */ |
2389 |
/** |
2390 |
* Creates a URL to the taxon page specified by the $uuid parameter. |
2391 |
* |
2392 |
* The URL will be prepended with a path element to a specific taxon page tab. |
2393 |
* |
2394 |
* This tab is either taken from the CDM_DATAPORTAL_DEFAULT_TAXON_TAB which can |
2395 |
* be set globally in the administrative settings or individually in the user |
2396 |
* profile. If the CDM_DATAPORTAL_DEFAULT_TAXON_TAB value is set to LAST_VISITED_TAB |
2397 |
* the last portal will stay on this last tab. |
2398 |
* |
2399 |
* A third option is offerered by the $page_tab parameter which allows overwriting this |
2400 |
* internal mechanism by a specific value. |
2401 |
* |
2402 |
* @param string $uuid |
2403 |
* The UUID of the taxon. |
2404 |
* @param string $page_tab |
2405 |
* Overwriting the preset mechanism by defining specific value for the |
2406 |
* taxon page tab. |
2407 |
* @return string |
2408 |
* The created URL. |
2409 |
*/ |
2410 |
function path_to_taxon($uuid, $page_tab = FALSE) { |
2411 |
|
2412 |
$tab = get_default_taxon_tab(); |
2413 |
$values = unserialize(CDM_DATAPORTAL_DEFAULT_TAXON_TAB); |
2414 |
|
2415 |
if (!$uuid) { |
2416 |
return FALSE; |
2417 |
} |
2418 |
|
2419 |
if ($page_tab) { |
2420 |
$url = 'cdm_dataportal/taxon/' . $uuid . '/' . $page_tab; |
2421 |
} |
2422 |
elseif (!$tab || strtolower($tab) == 'general') { |
2423 |
$url = 'cdm_dataportal/taxon/' . $uuid; |
2424 |
} |
2425 |
elseif (get_last_taxon_page_tab() && $tab == $values[CDM_DATAPORTAL_LAST_VISITED_TAB_ARRAY_INDEX]) { |
2426 |
$url = 'cdm_dataportal/taxon/' . $uuid . '/' . get_last_taxon_page_tab(); |
2427 |
} |
2428 |
else { |
2429 |
$url = 'cdm_dataportal/taxon/' . $uuid . '/' . strtolower($tab); |
2430 |
} |
2431 |
return $url; |
2432 |
} |
2433 |
|
2434 |
function path_to_description($uuid, $descriptive_dataset_uuid = NULL) { |
2435 |
|
2436 |
if (!$uuid) { |
2437 |
return FALSE; |
2438 |
} |
2439 |
else { |
2440 |
return 'cdm_dataportal/description/' . $uuid |
2441 |
. (is_uuid($descriptive_dataset_uuid) ? '/' . $descriptive_dataset_uuid : ''); |
2442 |
} |
2443 |
} |
2444 |
|
2445 |
function path_to_specimen($uuid) { |
2446 |
|
2447 |
if (!$uuid) { |
2448 |
return FALSE; |
2449 |
} |
2450 |
else { |
2451 |
return 'cdm_dataportal/occurrence/' . $uuid; |
2452 |
} |
2453 |
} |
2454 |
|
2455 |
function path_to_specimen_by_accession_number($accession_number) { |
2456 |
|
2457 |
if (!$accession_number) { |
2458 |
return FALSE; |
2459 |
} |
2460 |
else { |
2461 |
return 'cdm_dataportal/specimen/accession_number/' . $accession_number; |
2462 |
} |
2463 |
} |
2464 |
|
2465 |
function path_to_named_area($uuid) { |
2466 |
|
2467 |
if (!$uuid) { |
2468 |
return FALSE; |
2469 |
} |
2470 |
else { |
2471 |
return 'cdm_dataportal/named_area/' . $uuid; |
2472 |
} |
2473 |
} |
2474 |
|
2475 |
/** |
2476 |
* Creates a URL to show a synonmy in the according taxon page. |
2477 |
* |
2478 |
* The URL will point to the synonymy tab of the taxon page of the accepted taxon given as parameter $acceptedUuid. |
2479 |
* The resulting URI will include query parameters to highlight the synonym, and to optionally display |
2480 |
* the accepted taxons name in aform like "Foo bar is accepted taxon for Ree doo". The URI will also |
2481 |
* include the sysnonym uuid as fragment in order to let the browser scroll to the according location |
2482 |
* in the page |
2483 |
* |
2484 |
* @param string $synonymUuid |
2485 |
* The uuid of the synonym |
2486 |
* @param string $acceptedUuid |
2487 |
* The uuid of the according accepted taxon |
2488 |
* @return string |
2489 |
* The URL to show a synonmy in the according taxon page |
2490 |
*/ |
2491 |
function uri_to_synonym($synonymUuid, $acceptedUuid) { |
2492 |
$acceptedPath = path_to_taxon($acceptedUuid, "synonymy"); |
2493 |
return url($acceptedPath, array( |
2494 |
'query' => array( |
2495 |
// highlite the synony in the synonymy |
2496 |
'highlite' => $synonymUuid, |
2497 |
// the taxon page is refered from a synonym and the synonym can optionally be named in the page title |
2498 |
// see theme_taxon_page_title() |
2499 |
'acceptedFor' => $synonymUuid |
2500 |
), |
2501 |
'fragment' => $synonymUuid |
2502 |
)); |
2503 |
|
2504 |
} |
2505 |
|
2506 |
/** |
2507 |
* Composes the drupal path to the key identified by the uuid. |
2508 |
* |
2509 |
* @param string $keyType |
2510 |
* the key typer corresponds to the specific class of the CDM |
2511 |
* IdentificationKey. Possible values are |
2512 |
* -PolytomousKey |
2513 |
* -MultimediaKey |
2514 |
* - ... |
2515 |
* @param string $keyUuid |
2516 |
* The UUID of the key |
2517 |
*/ |
2518 |
function path_to_key($keyType, $keyUuid) { |
2519 |
if (!$keyUuid || !$keyType) { |
2520 |
return FALSE; |
2521 |
} |
2522 |
$keyType{0} = strtolower($keyType{0}); |
2523 |
return "cdm_dataportal/" . $keyType . "/$keyUuid"; |
2524 |
} |
2525 |
|
2526 |
/** |
2527 |
* Composes the drupal path to the reference identified by the uuid. |
2528 |
* |
2529 |
* @param $uuid string String representation of the registration entity uuid. |
2530 |
* |
2531 |
* @return string |
2532 |
* The drupal path |
2533 |
* |
2534 |
*/ |
2535 |
function path_to_reference($uuid) { |
2536 |
if (!$uuid) { |
2537 |
return FALSE; |
2538 |
} |
2539 |
return 'cdm_dataportal/reference/' . $uuid; |
2540 |
} |
2541 |
|
2542 |
/** |
2543 |
* Composes the drupal path to the reference identified by the uuid. |
2544 |
* |
2545 |
* @param string $identifier |
2546 |
* The persistent identifier of the registration entity (Registration.identifier). |
2547 |
* @return string |
2548 |
* The drupal path |
2549 |
*/ |
2550 |
function path_to_registration($identifier) { |
2551 |
|
2552 |
if(variable_get(CDM_REGISTRATION_PRESISTENT_IDENTIFIER_AS_LINK)){ |
2553 |
return $identifier; |
2554 |
} else { |
2555 |
return 'cdm_dataportal/registration/' . urlencode($identifier); |
2556 |
} |
2557 |
} |
2558 |
|
2559 |
/** |
2560 |
* Creates the path to a cdm_dataportal taxon name page. |
2561 |
* |
2562 |
* @param string $taxon_name_uuid |
2563 |
* The uuid as string of the CDM TaxonName to show a name page for |
2564 |
* @param string $taxon_to_hide_uuid |
2565 |
* The uuid as string of a taxon which should not be displayed in the taxon list |
2566 |
* @param string $highlited_synonym_uuid |
2567 |
* Optional parameter which takes another taxon uuid, if given the |
2568 |
* target taxon pages will show the synonymy tab where the taxon |
2569 |
* referenced by the $highlite_synonym_uuid will be highlighted |
2570 |
* in case it is found on this page. |
2571 |
* @param $redirect_to_taxon |
2572 |
* If true, the name page will redirect to the related taxon if there is a single one |
2573 |
* for this name only. |
2574 |
* |
2575 |
* @return string |
2576 |
* URI path element as string |
2577 |
*/ |
2578 |
function path_to_name($name_uuid, $taxon_to_hide_uuid = NULL, $highlited_synonym_uuid = NULL, $redirect_to_taxon = false) { |
2579 |
$res = FALSE; |
2580 |
if ($name_uuid) { |
2581 |
$res = 'cdm_dataportal/name/' . $name_uuid . |
2582 |
'/' . (is_uuid($taxon_to_hide_uuid) ? $taxon_to_hide_uuid : "null") . |
2583 |
'/' . (is_uuid($highlited_synonym_uuid) ? $highlited_synonym_uuid : "null") . |
2584 |
'/' . ($redirect_to_taxon || variable_get(CDM_NAME_PAGE_AUTOREDIRECT, 0) ? "redirect_to_taxon" : ""); |
2585 |
} |
2586 |
|
2587 |
return $res; |
2588 |
} |
2589 |
|
2590 |
/** |
2591 |
* Composes the drupal path to the media entity identified by the uuid. |
2592 |
* |
2593 |
* @param string $uuid |
2594 |
* The persistent identifier of the entity entity |
2595 |
* @return string |
2596 |
* The drupal path |
2597 |
*/ |
2598 |
function path_to_media($uuid, $representaion_uuid = FALSE, $partId = FALSE) { |
2599 |
if (!$uuid) { |
2600 |
return FALSE; |
2601 |
} |
2602 |
$out = 'cdm_dataportal/media/' . $uuid; |
2603 |
if ($representaion_uuid) { |
2604 |
$out .= '/' . $representaion_uuid; |
2605 |
if (is_numeric($partId)) { |
2606 |
$out .= '/' . $partId; |
2607 |
} |
2608 |
} |
2609 |
return $out; |
2610 |
} |
2611 |
|
2612 |
/** |
2613 |
* Compares thisRank with thatRank. |
2614 |
* |
2615 |
* Returns a negative integer, zero, or a positive integer |
2616 |
* as the of thisRank is higher than, equal to, or lower than thatRank. |
2617 |
* e.g: |
2618 |
* <ul> |
2619 |
* <li>rank_compare({species_uuid}, {genus_uuid}) = -1</li> |
2620 |
* <li>rank_compare({genus_uuid}, {genus_uuid}) = 0</li> |
2621 |
* <li>rank_compare({genus_uuid}, {tribus_uuid}) = 1</li> |
2622 |
* </ul> |
2623 |
* <p> |
2624 |
* This compare logic of the underlying webservice is the |
2625 |
* <b>inverse logic</b> of the the one implemented in |
2626 |
* java.lang.Comparable#compareTo(java.lang.Object) |
2627 |
* |
2628 |
* @param $thisRankUuid |
2629 |
* @param $thatRankUuid |
2630 |
* |
2631 |
* @return int |
2632 |
* A negative integer, zero, or a positive integer |
2633 |
* as the thisRank is lower than, equal to, or higher than thatRank. |
2634 |
*/ |
2635 |
function rank_compare($thisRankUuid, $thatRankUuid) { |
2636 |
$result = cdm_ws_get(CDM_WS_TERM_COMPARE, array($thisRankUuid, $thatRankUuid)); |
2637 |
return $result->Integer; |
2638 |
} |
2639 |
|
2640 |
/** |
2641 |
* Creates a short version of a taxonname. |
2642 |
* |
2643 |
* The short name is created by using the taggedTitle field of |
2644 |
* TaxonNodeDTO instances. |
2645 |
* If the taggedTitle if empty the fullname will be returned. |
2646 |
* |
2647 |
* @param object $taxonNodeDTO |
2648 |
* A TaxonNodeDTO object |
2649 |
* |
2650 |
* @return string |
2651 |
*/ |
2652 |
function cdm_dataportal_shortname_of($taxonNodeDTO) { |
2653 |
|
2654 |
$nameStr = ''; |
2655 |
|
2656 |
normalize_tagged_text($taxonNodeDTO->taggedTitle); |
2657 |
|
2658 |
// Get all tagged text tokens of the scientific name. |
2659 |
foreach ($taxonNodeDTO->taggedTitle as $tagtxt) { |
2660 |
if ($tagtxt->type == 'name' || $tagtxt->type == 'rank') { |
2661 |
$nameStr .= ($nameStr ? ' ' : '') . $tagtxt->text; |
2662 |
} |
2663 |
} |
2664 |
$nameStr = trim($nameStr); |
2665 |
|
2666 |
if ($nameStr) { |
2667 |
if(isset($taxonNodeDTO->nodeStatus->symbol)){ |
2668 |
$nameStr = $taxonNodeDTO->nodeStatus->symbol . ' ' . $nameStr; |
2669 |
} |
2670 |
// Do not return short names for these. |
2671 |
if ($taxonNodeDTO->unplaced || $taxonNodeDTO->excluded) { |
2672 |
return $nameStr; |
2673 |
} |
2674 |
|
2675 |
/* |
2676 |
1st capture group (^[a-zA-Z]): First letter of uninomial. |
2677 |
Second capture group ([\p{L}]+): remaining letters of uninomial ([\p{L} = an UTF-8 letter). |
2678 |
Third capture group (\s+[^(\x2E]+\s+.+$|\s+[a-zA-Z]+$): letters of name, |
2679 |
but only matching if no '(' or '.' in second word of name, ( \x2E = '.') |
2680 |
OR only one specific epithet \s+[\p{L}\x22\x2D\xD7]+$ (\x22= '"', \x2D='-', \xD7='×' ) |
2681 |
*/ |
2682 |
$pattern = '/(^[a-zA-Z])([\p{L}]+)(\s+[^(\x2E]+\s+.+$|\s+[\p{L}\x22\x2D\xD7]+$)/u'; |
2683 |
if (preg_match($pattern, $nameStr, $matches, PREG_OFFSET_CAPTURE)) { |
2684 |
return $matches[1][0] . "." . $matches[3][0]; |
2685 |
} |
2686 |
else { |
2687 |
return $nameStr; |
2688 |
} |
2689 |
} |
2690 |
else { |
2691 |
return $taxonNodeDTO->titleCache; |
2692 |
} |
2693 |
} |
2694 |
|
2695 |
/** |
2696 |
* Check if a taxon is accepted by the current taxonomic tree. |
2697 |
* |
2698 |
* @param mixed $taxon |
2699 |
* The Taxon obkect to check. |
2700 |
* |
2701 |
* @return bool |
2702 |
* Returns TRUE if $taxon is accepted, FALSE otherwise. |
2703 |
*/ |
2704 |
function _cdm_dataportal_acceptedByCurrentView($taxon) { |
2705 |
|
2706 |
$defaultTreeUuid = get_current_classification_uuid(); |
2707 |
|
2708 |
if (isset($taxon->taxonNodes)) { |
2709 |
$taxonNodes = $taxon->taxonNodes; |
2710 |
} |
2711 |
else { |
2712 |
$taxonNodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon->uuid); |
2713 |
} |
2714 |
|
2715 |
if ($taxon->class == "Taxon" && isset($taxonNodes)) { |
2716 |
foreach ($taxonNodes as $node) { |
2717 |
if (isset($node->classificationUUID)){ |
2718 |
if ($node->classificationUUID == $defaultTreeUuid) { |
2719 |
return TRUE; |
2720 |
} |
2721 |
} |
2722 |
else { |
2723 |
if ($node->classification == $defaultTreeUuid) { |
2724 |
return TRUE; |
2725 |
} |
2726 |
} |
2727 |
} |
2728 |
} |
2729 |
|
2730 |
return FALSE; |
2731 |
} |
2732 |
|
2733 |
/** |
2734 |
* Checks is the source has one of the given types. |
2735 |
* |
2736 |
* @param object $source |
2737 |
* The original source entity |
2738 |
* @param array $types |
2739 |
* An array of element of the OriginalSourceType enumeration |
2740 |
* If not set the default will be used which is: |
2741 |
* - Lineage |
2742 |
* - PrimaryMediaSource |
2743 |
* - PrimaryTaxonomicSource |
2744 |
* - Unknown |
2745 |
* - Other |
2746 |
* @return boolean |
2747 |
*/ |
2748 |
function _is_original_source_type($source, $types = null) { |
2749 |
// this is the default |
2750 |
// maybe this should also be put into the settings |
2751 |
static $default = array( |
2752 |
OriginalSourceType::Lineage, |
2753 |
OriginalSourceType::PrimaryMediaSource, |
2754 |
OriginalSourceType::PrimaryTaxonomicSource, |
2755 |
OriginalSourceType::Unknown, |
2756 |
OriginalSourceType::Other, |
2757 |
OriginalSourceType::Aggregation |
2758 |
); |
2759 |
|
2760 |
if(!$types){ |
2761 |
$types = $default; |
2762 |
} |
2763 |
return isset($source->type) && in_array($source->type, $types); |
2764 |
} |
2765 |
|
2766 |
/** |
2767 |
* Collects all the media from a list of description elements. |
2768 |
* |
2769 |
* @param array $descriptionElements |
2770 |
* The description elements from which to collect the media. |
2771 |
* |
2772 |
* @return array |
2773 |
* The output with all the collected media. |
2774 |
*/ |
2775 |
function cdm_dataportal_media_from_descriptionElements($descriptionElements) { |
2776 |
|
2777 |
$outArrayOfMedia = array(); |
2778 |
|
2779 |
// Avoiding a warning box in Drupal for Flora Malesiana. |
2780 |
if (isset($descriptionElements) && is_array($descriptionElements)) { |
2781 |
foreach ($descriptionElements as $descriptionElement) { |
2782 |
if (isset($descriptionElement->media) && is_array($descriptionElement->media)) { |
2783 |
foreach ($descriptionElement->media as $media) { |
2784 |
if (is_object($media)) { |
2785 |
$outArrayOfMedia[] = $media; |
2786 |
} |
2787 |
} |
2788 |
} |
2789 |
} |
2790 |
} |
2791 |
return $outArrayOfMedia; |
2792 |
} |
2793 |
|
2794 |
/** |
2795 |
* Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them. |
2796 |
* |
2797 |
* The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys. |
2798 |
* |
2799 |
* @see cdm_fetch_visible_annotations() |
2800 |
* |
2801 |
* @param array $cdm_entities |
2802 |
* An array of CdmBase instances or a single instance. |
2803 |
* @param $footnote_list_key_suggestion string |
2804 |
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to |
2805 |
* RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used. |
2806 |
* |
2807 |
* @return array of footnote keys |
2808 |
*/ |
2809 |
function cdm_annotations_as_footnotekeys(array $cdm_entities, $footnote_list_key_suggestion = NULL) { |
2810 |
|
2811 |
$foot_note_keys = array(); |
2812 |
|
2813 |
// Is argument cdmBase an array? |
2814 |
if (!is_array($cdm_entities)) { |
2815 |
$enties = array(); |
2816 |
$enties[] = $cdm_entities; |
2817 |
} |
2818 |
else { |
2819 |
$enties = $cdm_entities; |
2820 |
} |
2821 |
|
2822 |
// Getting the key for the footnotemanager. |
2823 |
if (isset($footnote_list_key_suggestion)) { |
2824 |
$footnote_list_key = $footnote_list_key_suggestion; |
2825 |
} |
2826 |
else { |
2827 |
$footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations'; |
2828 |
} |
2829 |
|
2830 |
// Adding the footnotes keys. |
2831 |
foreach ($enties as $cdm_entity) { |
2832 |
$annotations = cdm_fetch_visible_annotations($cdm_entity); |
2833 |
if (is_array($annotations)) { |
2834 |
foreach ($annotations as $annotation) { |
2835 |
$foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text); |
2836 |
} |
2837 |
} |
2838 |
} |
2839 |
|
2840 |
return $foot_note_keys; |
2841 |
} |
2842 |
|
2843 |
/** |
2844 |
* Fetches the list of visible annotations for each of the cdm entities and returns the footnote keys for them. |
2845 |
* |
2846 |
* The footnotes are passed to the FootnoteManager in order to store the annotations and to create the footnote keys. |
2847 |
* |
2848 |
* @see cdm_fetch_visible_annotations() |
2849 |
* |
2850 |
* @param array $cdm_entities |
2851 |
* An array of CdmBase instances or a single instance. |
2852 |
* @param $footnote_list_key_suggestion string |
2853 |
* optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined be set to |
2854 |
* RenderHints::getFootnoteListKey().'-annotations' otherwise the supplied key will be used. |
2855 |
* |
2856 |
* @return array of footnote keys |
2857 |
*/ |
2858 |
function cdm_entity_annotations_as_footnotekeys($cdm_entity, $footnote_list_key_suggestion = NULL) { |
2859 |
|
2860 |
$foot_note_keys = array(); |
2861 |
|
2862 |
// Getting the key for the footnotemanager. |
2863 |
if (isset($footnote_list_key_suggestion)) { |
2864 |
$footnote_list_key = $footnote_list_key_suggestion; |
2865 |
} else { |
2866 |
$footnote_list_key = RenderHints::getFootnoteListKey() . '-annotations'; |
2867 |
} |
2868 |
|
2869 |
// Adding the footnotes keys. |
2870 |
$annotations = cdm_fetch_visible_annotations($cdm_entity); |
2871 |
if (is_array($annotations)) { |
2872 |
foreach ($annotations as $annotation) { |
2873 |
$foot_note_keys[] = FootnoteManager::addNewFootnote($footnote_list_key, $annotation->text); |
2874 |
} |
2875 |
} |
2876 |
|
2877 |
return $foot_note_keys; |
2878 |
} |
2879 |
|
2880 |
|
2881 |
/** |
2882 |
* Creates a CDM Dynabox. |
2883 |
* |
2884 |
* @param string $dynabox_id |
2885 |
* a uninque name for tha dynabox, using a cdm entity uuid as id is good practice. |
2886 |
* @param string $label |
2887 |
* The clickable text to show. |
2888 |
* @param string $content_url |
2889 |
* The cdm REST service request url wich will deliver the content to be shown |
2890 |
* once the dynabox toggles open. |
2891 |
* @param string $theme |
2892 |
* The theme to be used for rendering the cdm REST service response with is |
2893 |
* returned from the $content_url. |
2894 |
* @param string $link_alt_text |
2895 |
* The value for the alt attribute of the dynabox link. |
2896 |
* @param array $enclosingtags |
2897 |
* An array with two elements: $enclosingtags[0] will be used for the dynabox |
2898 |
* element itself, $enclosingtags[1] is the tag to be used for the |
2899 |
* dynabox_content (optional) |
2900 |
* @param array $attributes |
2901 |
* @param $content_element_selector |
2902 |
* Optional jQuery selector which can be used to reference a dom element which should |
2903 |
* be used as container for the content to be shown. The dynabox-<dynabox id>-content |
2904 |
* element will be placed in this container. |
2905 |
* |
2906 |
* @param string $open_callback |
2907 |
* optional javascript call back function to be triggered after toggling the box to |
2908 |
* the open state. |
2909 |
* @param string $close_callback |
2910 |
* optional javascript call back function to be triggered after toggling the box to |
2911 |
* the closed state. |
2912 |
* @return string Returns HTML for a dynabox. |
2913 |
* Returns HTML for a dynabox. |
2914 |
*/ |
2915 |
function cdm_dynabox($dynabox_id, $label, $content_url, $theme, $link_alt_text, |
2916 |
$enclosingtags = array('li', 'ul'), $attributes = array(), |
2917 |
$content_element_selector = null, |
2918 |
$open_callback = 'function(){}', $close_callback = 'function(){}' ) { |
2919 |
$out = ''; |
2920 |
|
2921 |
// check for plain class attribute string |
2922 |
$dynabox_id = preg_replace('/[^a-zA-Z0-9\-]/', '', $dynabox_id); |
2923 |
|
2924 |
if(!array_key_exists('class', $attributes)) { |
2925 |
$attributes['class'] = array(); |
2926 |
} |
2927 |
$attributes['id'][] = 'dynabox-' . $dynabox_id; |
2928 |
$dynabox_attributes = drupal_attributes($attributes); |
2929 |
|
2930 |
|
2931 |
_add_js_domEvent(); // requires domEvent.js |
2932 |
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_dynabox.js'); |
2933 |
drupal_add_js(" |
2934 |
jQuery(document).ready( |
2935 |
function() { |
2936 |
dynabox('". $dynabox_id ."', |
2937 |
{ |
2938 |
open_callback: " . $open_callback .", |
2939 |
close_callback: " . $close_callback . |
2940 |
($content_element_selector ? ",\n content_container_selector: '" . $content_element_selector . "'" : "") . " |
2941 |
} |
2942 |
); |
2943 |
} |
2944 |
);", |
2945 |
array( |
2946 |
'type'=>'inline', |
2947 |
'scope'=>'footer' |
2948 |
) |
2949 |
); |
2950 |
|
2951 |
|
2952 |
$cdm_proxy_url = url('cdm_api/proxy/' . urlencode($content_url) . "/$theme"); |
2953 |
$out .= '<!-- dynabox for ' . $content_url . ' -->'; |
2954 |
$out .= '<' . $enclosingtags[0] . ' ' . $dynabox_attributes. '><a href="' . $cdm_proxy_url . '" class="label" alt="' . t('@link-alt-text', array('@link-alt-text' => $link_alt_text)) . '">' . $label . '</a>'; |
2955 |
$out .= ' <' . $enclosingtags[1] . ' id="dynabox-' . $dynabox_id . '-content">'; |
2956 |
$out .= ' <' . $enclosingtags[0] . ' class="dynabox-content-inner">' . loading_image_html() . '</' . $enclosingtags[0] . '>'; |
2957 |
$out .= ' </' . $enclosingtags[1] . '>'; |
2958 |
$out .= ' </' . $enclosingtags[0] . '>'; |
2959 |
$out .= '<!-- dynabox end -->'; |
2960 |
return $out; |
2961 |
} |
2962 |
|
2963 |
/** |
2964 |
* Checks whether a feature has any description elements. |
2965 |
* |
2966 |
* @param mixed $featureNode |
2967 |
* A feature node as produced by the function _mergeFeatureTreeDescriptions(). |
2968 |
* |
2969 |
* @see _mergeFeatureTreeDescriptions() |
2970 |
* |
2971 |
* @return bool |
2972 |
* Returns TRUE if the given $featureNode or any of its subordinate nodes |
2973 |
* contains at least one non empty TextData or at least one DescriptionElement |
2974 |
* of an other type. A TextData element holding a multilanguageText or a |
2975 |
* source reference is considered to be not empty. |
2976 |
* |
2977 |
* @TODO this function may have become obsolete by the new method of detecting empty blocks, |
2978 |
* see $block_content_is_not_empty in make_feature_block_list() and |
2979 |
* $feature_block_has_content in compose_feature_block_items_generic |
2980 |
*/ |
2981 |
function has_feature_node_description_elements($featureNode) { |
2982 |
|
2983 |
if (isset($featureNode->descriptionElements) && is_array($featureNode->descriptionElements) && count($featureNode->descriptionElements) > 0) { |
2984 |
if(!isset($featureNode->descriptionElements['#type'])){ // #type is used to identify e.g. DTO elements: '#type' => 'DTO' |
2985 |
foreach ($featureNode->descriptionElements as $descriptionElement) { |
2986 |
if ($descriptionElement->class != "TextData" || isset($descriptionElement->multilanguageText_L10n->text) |
2987 |
&& $descriptionElement->multilanguageText_L10n->text != '' |
2988 |
|| isset($descriptionElement->sources[0]) |
2989 |
|| isset($descriptionElement->media[0]) ) { |
2990 |
return TRUE; |
2991 |
} |
2992 |
} |
2993 |
} |
2994 |
} |
2995 |
else if (isset($featureNode->childNodes) && is_array($featureNode->childNodes)) { |
2996 |
foreach ($featureNode->childNodes as $child) { |
2997 |
if (has_feature_node_description_elements($child)) { |
2998 |
return TRUE; |
2999 |
} |
3000 |
} |
3001 |
} |
3002 |
return FALSE; |
3003 |
} |
3004 |
|
3005 |
/** |
3006 |
* Checks if the current page is a valid taxon portal page and responds with HTTP status 404 (not found) otherwise |
3007 |
* |
3008 |
* @param $chapter |
3009 |
* The taxon page chapter or part |
3010 |
*/ |
3011 |
function cdm_check_valid_taxon_page($chapter){ |
3012 |
static $taxon_tabs = null; |
3013 |
|
3014 |
cdm_check_valid_portal_page(); |
3015 |
|
3016 |
if($taxon_tabs == null){ |
3017 |
$taxon_tabs = array('all', 'description'); |
3018 |
foreach(get_taxon_tabs_list() as $tab){ |
3019 |
$taxon_tabs[] = strtolower($tab); |
3020 |
} |
3021 |
} |
3022 |
|
3023 |
if(!in_array($chapter, $taxon_tabs)){ |
3024 |
// oops this is not a valid chapter name |
3025 |
http_response_code(404); // 404 = Not Found |
3026 |
} |
3027 |
|
3028 |
} |
3029 |
|
3030 |
function check_js_devel_mode_disabled() { |
3031 |
if(variable_get('cdm_js_devel_mode', FALSE)) { |
3032 |
drupal_set_message(t('The !url1 is enabled. |
3033 |
WARNING: this is a performance penalty and must be turned off on production websites.', array( |
3034 |
'!url1' => l('java-script development mode', 'admin/config/cdm_dataportal/settings', array('fragment' => 'edit-cdm-js-devel-mode')) |
3035 |
)), |
3036 |
'warning' |
3037 |
); |
3038 |
} |
3039 |
} |
3040 |
|
3041 |
/** |
3042 |
* Checks if the current page is a valid portal page and responds with HTTP status 404 (not found) otherwise. |
3043 |
* The test applied by default it a check for the query parameter 'q' ending with a file suffix like '*.*' |
3044 |
* |
3045 |
* @param $preg_pattern |
3046 |
* Optional regular expression pattern to be used in preg_match(). |
3047 |
*/ |
3048 |
function cdm_check_valid_portal_page($preg_pattern = null){ |
3049 |
$ends_with_file_suffix_pattern = '/\/[^\.\/]*[\.][^\.\/]*$/'; |
3050 |
if($preg_pattern === null){ |
3051 |
$preg_pattern = $ends_with_file_suffix_pattern; |
3052 |
} |
3053 |
if(preg_match($preg_pattern, $_GET['q'])){ |
3054 |
// oops this urls ends with a file_suffix and thus does not refer to a portal page |
3055 |
http_response_code(404); // 404 = Not Found |
3056 |
exit('HTTP 404'); |
3057 |
} |
3058 |
check_js_devel_mode_disabled(); |
3059 |
} |
3060 |
|
3061 |
/** |
3062 |
* Generates the diff of the texts and presents it in a HTML diff viewer. |
3063 |
* |
3064 |
* @param $text_a |
3065 |
* @param $text_b |
3066 |
* @return string |
3067 |
*/ |
3068 |
function diff_viewer($text_a, $text_b) { |
3069 |
|
3070 |
static $diff_viewer_count = 0; |
3071 |
|
3072 |
$element_id = 'part_definitions_diff_' . $diff_viewer_count++; |
3073 |
|
3074 |
// http://code.stephenmorley.org/php/diff-implementation/ |
3075 |
module_load_include('php', 'cdm_dataportal', 'lib/class.Diff'); |
3076 |
drupal_add_css(drupal_get_path('module', |
3077 |
'cdm_dataportal') . '/css/diff.css'); |
3078 |
_add_jquery_ui(); |
3079 |
drupal_add_js( |
3080 |
'jQuery(document).ready( function(){ |
3081 |
jQuery(\'#' . $element_id . '\').accordion({ |
3082 |
collapsible: true, |
3083 |
active: false, |
3084 |
fillSpace: true, |
3085 |
}).children(\'div\').css({ \'height\': \'auto\' }); |
3086 |
jQuery(\'#' . $element_id . ' table.diff\').prepend(\'<thead><tr><th>Default</th><th>User defined<th></th><tr></thead>\'); |
3087 |
});' |
3088 |
, array( |
3089 |
'type' => 'inline', |
3090 |
'scope' => 'footer' |
3091 |
)); |
3092 |
|
3093 |
$diff = Diff::compare($text_a, |
3094 |
$text_b); |
3095 |
$diff_viewer_markup = '<div id="' . $element_id . '"><h3>View Diff</h3><div>' |
3096 |
. Diff::toTable($diff, '', '') |
3097 |
. '</div></div>'; |
3098 |
return $diff_viewer_markup; |
3099 |
} |
3100 |
|
3101 |
|