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