1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/**
|
5
|
* Copyright (C) 2007 EDIT
|
6
|
* European Distributed Institute of Taxonomy
|
7
|
* http://www.e-taxonomy.eu
|
8
|
*
|
9
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
10
|
* See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
|
11
|
*/
|
12
|
|
13
|
define(FOOTNOTE_ANNOTATIONS, 'annotations');
|
14
|
|
15
|
|
16
|
/**
|
17
|
* Get the true path to the root of the Drupal site.
|
18
|
* Better than using DOCUMENT_ROOT and base_path().
|
19
|
*/
|
20
|
function absolute_path_to_drupal() {
|
21
|
static $absolute_path_to_drupal = NULL;
|
22
|
|
23
|
if ($absolute_path_to_drupal === NULL) {
|
24
|
// Get the absolute path to this file:
|
25
|
$dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
|
26
|
$parts = explode('/', $dir);
|
27
|
// Iterate up the directory hierarchy until we find the website root:
|
28
|
$done = FALSE;
|
29
|
do{
|
30
|
// Check a couple of obvious things:
|
31
|
$done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
|
32
|
if (!$done) {
|
33
|
// If there's no more path to examine, we didn't find the site root:
|
34
|
if (empty($parts)) {
|
35
|
$absolute_path_to_drupal = FALSE;
|
36
|
break;
|
37
|
}
|
38
|
// Go up one level and look again:
|
39
|
array_pop($parts);
|
40
|
$dir = implode('/', $parts);
|
41
|
}
|
42
|
}while (!$done);
|
43
|
|
44
|
$absolute_path_to_drupal = $dir;
|
45
|
}
|
46
|
return $absolute_path_to_drupal;
|
47
|
}
|
48
|
|
49
|
function taxon_in_current_tree ($taxon_uuid) {
|
50
|
$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
|
51
|
$taxon_in_current_tree = false;
|
52
|
if(is_array($taxon_nodes)){
|
53
|
foreach($taxon_nodes as $node){
|
54
|
if(get_taxonomictree_uuid_selected() == $node->classification->uuid){
|
55
|
$taxon_in_current_tree = true;
|
56
|
break;
|
57
|
}
|
58
|
}
|
59
|
}
|
60
|
return $taxon_in_current_tree;
|
61
|
}
|
62
|
|
63
|
/**
|
64
|
* TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
|
65
|
* NOT WORKING since fragments are not available to the server
|
66
|
function fragment(){
|
67
|
global $fragment;
|
68
|
if(!$fragment){
|
69
|
$fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
|
70
|
}
|
71
|
return $fragment;
|
72
|
}
|
73
|
*/
|
74
|
|
75
|
function uuid_anchor($uuid, $innerHTML){
|
76
|
$highlite = $_REQUEST['highlite'] == $uuid;
|
77
|
return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
|
78
|
}
|
79
|
|
80
|
/**
|
81
|
* Enter description here...
|
82
|
*
|
83
|
* @param unknown_type $name
|
84
|
* @param unknown_type $numOfNameTokens
|
85
|
* @return unknown
|
86
|
* @deprecated looks like this is not used anymore
|
87
|
*/
|
88
|
function tagNameParts($name, $numOfNameTokens){
|
89
|
|
90
|
$out = '<span class="name">';
|
91
|
|
92
|
$token = strtok($name, " \n\t");
|
93
|
$i = 0;
|
94
|
$noSpace = true;
|
95
|
while($token != false){
|
96
|
if($i == $numOfNameTokens){
|
97
|
$out .= '</span> <span class="authors">';
|
98
|
$noSpace = true;
|
99
|
}
|
100
|
$out .= ($noSpace?'':' ').$token;
|
101
|
$noSpace = false;
|
102
|
$token = strtok(" \n\t");
|
103
|
$i++;
|
104
|
}
|
105
|
return $out.'</span>';
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Converts an array of TagedText items into a sequence of corresponding html tags whereas
|
110
|
* each item will provided with a class attribute which set to the key of the TaggedText item.
|
111
|
*
|
112
|
* @param array $taggedtxt
|
113
|
* @param String $tag
|
114
|
* @param String $glue the string by which the chained text tokens are concatenated together.
|
115
|
* Default is a blank character
|
116
|
* @return String of HTML
|
117
|
*/
|
118
|
function theme_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
|
119
|
$out = '';
|
120
|
$i = 0;
|
121
|
foreach($taggedtxt as $tt){
|
122
|
if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
|
123
|
$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
|
124
|
}
|
125
|
}
|
126
|
return $out;
|
127
|
}
|
128
|
|
129
|
/* ============================ annotations ============================= */
|
130
|
|
131
|
/**
|
132
|
* Almost any cdmObject may be annotated. Therefore we provide a generic way to display
|
133
|
* as well as create or update annotations.
|
134
|
* The following cdm classes are annotatable:
|
135
|
*
|
136
|
* DescriptionElementBase
|
137
|
* EventBase
|
138
|
* HomotypicalGroup
|
139
|
* IdentifiableEntity
|
140
|
* DescriptionBase
|
141
|
* IdentifiableMediaEntity
|
142
|
* Media
|
143
|
* Sequence
|
144
|
* TaxonBase
|
145
|
* TaxonNameBase
|
146
|
* TaxonomicTree
|
147
|
* TermBase
|
148
|
* LanguageStringBase
|
149
|
* ReferencedEntityBase
|
150
|
* NomenclaturalStatus
|
151
|
* OriginalSourceBase
|
152
|
* RelationshipBase
|
153
|
* TypeDesignationBase
|
154
|
* TaxonNode
|
155
|
* WorkingSet
|
156
|
*
|
157
|
* @param $cdmBase_list an array of CdmBase instances or a single instance
|
158
|
* @param $footnote_list_key
|
159
|
*/
|
160
|
function theme_cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key = null){
|
161
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
|
162
|
return '';
|
163
|
}
|
164
|
$footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase_list, $footnote_list_key);
|
165
|
foreach($footNoteKeys as $a){
|
166
|
//$out .= theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)? ',' : ''));
|
167
|
$out .= theme('cdm_footnote_key', $a, (isset($out)? ',' : ''));
|
168
|
}
|
169
|
return $out;
|
170
|
}
|
171
|
|
172
|
|
173
|
function theme_cdm_annotation_footnotes($footnoteListKey, $enclosingTag = 'span'){
|
174
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
|
175
|
return '';
|
176
|
}
|
177
|
return theme('cdm_footnotes', $footnoteListKey . '-annotations', $enclosingTag);
|
178
|
}
|
179
|
|
180
|
function theme_cdm_annotation_content($AnnotationTO){
|
181
|
|
182
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
|
183
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
|
184
|
|
185
|
$out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
|
186
|
|
187
|
$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
|
188
|
$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
|
189
|
|
190
|
// TODO users have to be authenticated to the dataportal to be able to write annotations
|
191
|
$out .= '
|
192
|
<div class="annotation_create">
|
193
|
<form action="'.$annotationProxyUrl.'" method="POST">
|
194
|
<textarea name="annotation"></textarea>
|
195
|
<input type="hidden" name="commentator" value="">
|
196
|
<input type="submit" value="'.t('Save annotation').'" />
|
197
|
</form>
|
198
|
</div>
|
199
|
';
|
200
|
|
201
|
return $out;
|
202
|
}
|
203
|
|
204
|
function theme_cdm_list_of_annotations($annotationElements){
|
205
|
|
206
|
$out = '<ul class="annotation_list">';
|
207
|
|
208
|
foreach ($annotationElements as $key => $row){
|
209
|
$created[$key] = $row;
|
210
|
}
|
211
|
array_multisort($created, SORT_ASC, $annotationElements);
|
212
|
|
213
|
foreach ($annotationElements as $annotation){
|
214
|
$out .= '<li>' . $annotation->text . '</li>';
|
215
|
}
|
216
|
|
217
|
$out .= '</ul>';
|
218
|
|
219
|
return $out;
|
220
|
|
221
|
}
|
222
|
|
223
|
/* ============================ footnotes ============================= */
|
224
|
|
225
|
function theme_cdm_footnote_key($footnoteKey, $separator = '', $highlightable=true, $separator_off = false){
|
226
|
if (!$footnoteKey->footnoteListKey){
|
227
|
return '';
|
228
|
}
|
229
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
|
230
|
return '';
|
231
|
}
|
232
|
|
233
|
if ($separator_off){
|
234
|
$separator = '';
|
235
|
}
|
236
|
$out = '<span class="footnote-key footnote-key-'.$footnoteKey->keyStr.' member-of-footnotes-'.$footnoteKey->footnoteListKey.'">'.$separator
|
237
|
.'<a href="#footnote-'.$footnoteKey->keyStr.'">'.$footnoteKey->keyStr.'</a>'
|
238
|
.'</span>';
|
239
|
return $out;
|
240
|
}
|
241
|
|
242
|
function theme_cdm_footnote($footnoteKey, $footnoteText){
|
243
|
_add_js_footnotes();
|
244
|
$out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span> '.$footnoteText.'</span>';
|
245
|
return $out;
|
246
|
}
|
247
|
|
248
|
|
249
|
function theme_cdm_footnotes($footnoteListKey, $enclosingTag = 'span'){
|
250
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
|
251
|
return '';
|
252
|
}
|
253
|
$out = '<'.$enclosingTag.' class="footnotes footnotes-'.$footnoteListKey.' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</'.$enclosingTag.'>';
|
254
|
FootnoteManager::removeFootnoteList($footnoteListKey);
|
255
|
return $out;
|
256
|
}
|
257
|
|
258
|
function theme_cdm_annotations($annotations, $enclosingTag = 'span'){
|
259
|
if(!is_array($annotations)){
|
260
|
return;
|
261
|
}
|
262
|
$out = '<'.$enclosingTag.' class="annotations">';
|
263
|
$i = 0;
|
264
|
foreach($annotations as $annotation){
|
265
|
$out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
|
266
|
}
|
267
|
$out .= '</'.$enclosingTag.'>';
|
268
|
return $out;
|
269
|
}
|
270
|
|
271
|
function cdm_exist_footnote($footnote_list, $footnote){
|
272
|
$result = false;
|
273
|
if (is_array($footnote_list)){
|
274
|
foreach ($footnote_list as $element){
|
275
|
if ($element == $footnote){
|
276
|
$result = true;
|
277
|
}
|
278
|
}
|
279
|
}
|
280
|
return $result;
|
281
|
}
|
282
|
|
283
|
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
|
284
|
if(!cdm_exist_footnote($footnote_list, $footnote)){
|
285
|
$footnote_list[] = $footnote;
|
286
|
}
|
287
|
}
|
288
|
|
289
|
/* ============================ pager ============================= */
|
290
|
|
291
|
|
292
|
function theme_cdm_pager(&$pager, $path, $parameters){
|
293
|
$out = '';
|
294
|
|
295
|
if ($pager->pagesAvailable > 1) {
|
296
|
|
297
|
$out .= '<div class="pager">';
|
298
|
if($pager->currentIndex > 0){
|
299
|
$out .= theme('cdm_pager_link', t('« first'), 0, $pager, $path, $parameters, array('class' => 'pager-first'));
|
300
|
$out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
|
301
|
}
|
302
|
|
303
|
if($pager->indices[0] > 0){
|
304
|
$out .= '<div class="pager-list-dots-left">...</div>';
|
305
|
}
|
306
|
|
307
|
foreach($pager->indices as $index){
|
308
|
$label = $index + 1;
|
309
|
$out .= theme('cdm_pager_link', $label, $index, $pager, $path, $parameters, array('class' => 'pager-first'));
|
310
|
}
|
311
|
if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
|
312
|
$out .= '<div class="pager-list-dots-right">...</div>';
|
313
|
}
|
314
|
|
315
|
if($pager->nextIndex){
|
316
|
$out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
|
317
|
$out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
|
318
|
}
|
319
|
$out .= '</div>';
|
320
|
|
321
|
return $out;
|
322
|
}
|
323
|
}
|
324
|
|
325
|
function theme_cdm_pager_link($text, $linkIndex, &$pager, $path, $parameters = array(), $attributes) {
|
326
|
|
327
|
$out = '';
|
328
|
$parameters['search']['pageNumber'] = $linkIndex;
|
329
|
if ($linkIndex == $pager->currentIndex) {
|
330
|
$out = '<strong>'.$text.'</strong>';
|
331
|
} else {
|
332
|
$queryString = drupal_query_string_encode($parameters);
|
333
|
$out = l($text, $path, $attributes, $queryString);
|
334
|
}
|
335
|
return $out;
|
336
|
}
|
337
|
|
338
|
/* ============================ special buttons ============================= */
|
339
|
|
340
|
function theme_cdm_back_to_search_result_button(){
|
341
|
$out = '';
|
342
|
$show_button = variable_get('cdm_dataportal_show_back_to_search_results', 1);
|
343
|
if($_SESSION['cdm']['search'] && $show_button){
|
344
|
/*['cdm']['last_search']*/
|
345
|
//$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
|
346
|
$out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
|
347
|
|
348
|
}
|
349
|
return $out;
|
350
|
}
|
351
|
|
352
|
function theme_cdm_back_to_image_gallery_button(){
|
353
|
|
354
|
$out = '<div id="backToGalleryButton">'.l(t('Back to Images'), $_SESSION['cdm']['last_gallery'] ).'</div>';
|
355
|
|
356
|
return $out;
|
357
|
}
|
358
|
|
359
|
function theme_cdm_print_button(){
|
360
|
|
361
|
drupal_add_js ('$(document).ready(function() {
|
362
|
$(\'#print_button\').click(function () {
|
363
|
window.print();
|
364
|
});
|
365
|
});', 'inline');
|
366
|
|
367
|
$output = '<div id="print_button"><img src="'
|
368
|
.drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
|
369
|
. ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
|
370
|
//$output .= l(' Print this page', '');
|
371
|
$output .= '<span>Print this page</span>';
|
372
|
$output .= '</div>';
|
373
|
|
374
|
return $output;
|
375
|
}
|
376
|
|
377
|
|
378
|
|
379
|
|
380
|
/* ============================ java script functions ============================= */
|
381
|
|
382
|
function _add_js_thickbox(){
|
383
|
// ---- jQuery thickbox:
|
384
|
/*
|
385
|
* bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
|
386
|
* -> event is not triggered because of problems with compat-1.0.js'
|
387
|
* see INSTALL.txt
|
388
|
*
|
389
|
*/
|
390
|
//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
|
391
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
|
392
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
|
393
|
}
|
394
|
|
395
|
function _add_js_lightbox($galleryID){
|
396
|
/*
|
397
|
* Important Notice:
|
398
|
* The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
|
399
|
* for captions instead of the "title" attribute
|
400
|
*/
|
401
|
$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
|
402
|
drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
|
403
|
drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
|
404
|
drupal_add_js ('$(document).ready(function() {
|
405
|
$(\'#'.$galleryID.' a.lightbox\').lightBox({
|
406
|
fixedNavigation: true,
|
407
|
imageLoading: \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\',
|
408
|
imageBtnPrev: \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',
|
409
|
imageBtnNext: \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',
|
410
|
imageBtnClose: \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',
|
411
|
imageBlank: \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
|
412
|
});
|
413
|
});
|
414
|
', 'inline');
|
415
|
}
|
416
|
|
417
|
function _add_js_footnotes(){
|
418
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
|
419
|
}
|
420
|
|
421
|
|
422
|
function _add_js_cluetip(){
|
423
|
|
424
|
//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
|
425
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
|
426
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
|
427
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
|
428
|
drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
|
429
|
drupal_add_js ("$(document).ready(function(){
|
430
|
$('.cluetip').css({color: '#0062C2'}).cluetip({
|
431
|
splitTitle: '|',
|
432
|
showTitle: true,
|
433
|
activation: 'hover',
|
434
|
sicky: true,
|
435
|
arrows: true,
|
436
|
dropShadow: false,
|
437
|
cluetipClass: 'rounded'
|
438
|
});
|
439
|
});", 'inline');
|
440
|
}
|
441
|
|
442
|
function _add_js_ahah(){
|
443
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
|
444
|
}
|