1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Common Theming functions.
|
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
|
|
16
|
define('FOOTNOTE_ANNOTATIONS', 'annotations');
|
17
|
|
18
|
/**
|
19
|
* Get the true path to the root of the Drupal site.
|
20
|
*
|
21
|
* Better than using DOCUMENT_ROOT and base_path().
|
22
|
*/
|
23
|
function absolute_path_to_drupal() {
|
24
|
static $absolute_path_to_drupal = NULL;
|
25
|
|
26
|
if ($absolute_path_to_drupal === NULL) {
|
27
|
// Get the absolute path to this file:
|
28
|
$dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
|
29
|
$parts = explode('/', $dir);
|
30
|
// Iterate up the directory hierarchy until we find the website root:
|
31
|
$done = FALSE;
|
32
|
do {
|
33
|
// Check a couple of obvious things:
|
34
|
$done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
|
35
|
if (!$done) {
|
36
|
// If there's no more path to examine, we didn't find the site root:
|
37
|
if (empty($parts)) {
|
38
|
$absolute_path_to_drupal = FALSE;
|
39
|
break;
|
40
|
}
|
41
|
// Go up one level and look again:
|
42
|
array_pop($parts);
|
43
|
$dir = implode('/', $parts);
|
44
|
}
|
45
|
} while (!$done);
|
46
|
|
47
|
$absolute_path_to_drupal = $dir;
|
48
|
}
|
49
|
return $absolute_path_to_drupal;
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* @todo Please document this function.
|
54
|
* @see http://drupal.org/node/1354
|
55
|
*/
|
56
|
function taxon_in_current_classification($taxon_uuid) {
|
57
|
$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
|
58
|
$taxon_in_current_tree = FALSE;
|
59
|
if (is_array($taxon_nodes)) {
|
60
|
foreach ($taxon_nodes as $node) {
|
61
|
if (get_current_classification_uuid() == $node->classification->uuid) {
|
62
|
$taxon_in_current_tree = TRUE;
|
63
|
break;
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
return $taxon_in_current_tree;
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* TODO if getting fragment from request is possible remove
|
72
|
* $_REQUEST['highlite'] HACK
|
73
|
* NOT WORKING since fragments are not available to the server
|
74
|
*
|
75
|
* function fragment(){
|
76
|
* global $fragment;
|
77
|
* if(!$fragment){
|
78
|
* $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
|
79
|
* }
|
80
|
* return $fragment;
|
81
|
* }
|
82
|
*/
|
83
|
function uuid_anchor($uuid, $innerHTML) {
|
84
|
$highlite = FALSE;
|
85
|
$params = drupal_get_query_parameters();
|
86
|
if (isset($params['highlite']) && $params['highlite'] == $uuid) {
|
87
|
$highlite = TRUE;
|
88
|
}
|
89
|
|
90
|
return '<a name="' . $uuid . '" ></a><span class="' . ($highlite ? 'highlite' : '') . '">' . $innerHTML . '</span>';
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* @todo Enter description here...
|
95
|
* @deprecated looks like this is not used anymore
|
96
|
*/
|
97
|
/*
|
98
|
function tagNameParts($name, $numOfNameTokens) {
|
99
|
$out = '<span class="name">';
|
100
|
|
101
|
$token = strtok($name, " \n\t");
|
102
|
$i = 0;
|
103
|
$noSpace = TRUE;
|
104
|
while ($token != FALSE) {
|
105
|
if ($i == $numOfNameTokens) {
|
106
|
$out .= '</span> <span class="authors">';
|
107
|
$noSpace = TRUE;
|
108
|
}
|
109
|
$out .= ($noSpace ? '' : ' ') . $token;
|
110
|
$noSpace = FALSE;
|
111
|
$token = strtok(" \n\t");
|
112
|
$i++;
|
113
|
}
|
114
|
return $out . '</span>';
|
115
|
}
|
116
|
*/
|
117
|
|
118
|
/* ============================ annotations ============================= */
|
119
|
|
120
|
/**
|
121
|
* Returns HTML for annotations to cdm objects.
|
122
|
*
|
123
|
* Almost any cdmObject may be annotated. Therefore we provide a generic way to
|
124
|
* display as well as create or update annotations. The following cdm classes
|
125
|
* are annotatable:
|
126
|
*
|
127
|
* - DescriptionElementBase
|
128
|
* - EventBase
|
129
|
* - HomotypicalGroup
|
130
|
* - IdentifiableEntity
|
131
|
* - DescriptionBase
|
132
|
* - IdentifiableMediaEntity
|
133
|
* - Media
|
134
|
* - Sequence
|
135
|
* - TaxonBase
|
136
|
* - TaxonNameBase
|
137
|
* - TaxonomicTree
|
138
|
* - TermBase
|
139
|
* - LanguageStringBase
|
140
|
* - ReferencedEntityBase
|
141
|
* - NomenclaturalStatus
|
142
|
* - OriginalSourceBase
|
143
|
* - RelationshipBase
|
144
|
* - TypeDesignationBase
|
145
|
* - TaxonNode
|
146
|
* - WorkingSet
|
147
|
*
|
148
|
* @param array $variables
|
149
|
* An associative array containing:
|
150
|
* - cdmBase_list: An array of CdmBase instances or a single instance.
|
151
|
* - footnote_list_key
|
152
|
*
|
153
|
* @ingroup themeable
|
154
|
*/
|
155
|
function theme_cdm_annotations_as_footnotekeys($variables) {
|
156
|
$cdm_entities = $variables['cdmBase_list'];
|
157
|
$footnote_list_key = $variables['footnote_list_key'];
|
158
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
159
|
return '';
|
160
|
}
|
161
|
$out = '';
|
162
|
$footNoteKeys = cdm_annotations_as_footnotekeys($cdm_entities, $footnote_list_key);
|
163
|
foreach ($footNoteKeys as $a) {
|
164
|
// $out .= theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)?
|
165
|
// ',' : ''));
|
166
|
$out .= theme('cdm_footnote_key', array('footnoteKey' => $a, 'separator' => ($out ? ',' : '')));
|
167
|
}
|
168
|
return $out;
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* @todo Please document this function.
|
173
|
* @see http://drupal.org/node/1354
|
174
|
*/
|
175
|
function theme_cdm_annotation_footnotes($variables) {
|
176
|
$footnoteListKey = $variables['footnoteListKey'];
|
177
|
$enclosingTag = $variables['enclosingTag'];
|
178
|
if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
179
|
return '';
|
180
|
}
|
181
|
return theme('cdm_footnotes', array('footnoteListKey' => $footnoteListKey . '-annotations', 'enclosingTag' => $enclosingTag));
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
* @todo Please document this function.
|
186
|
* @see http://drupal.org/node/1354
|
187
|
*/
|
188
|
function theme_cdm_annotation_content($variables) {
|
189
|
$AnnotationTO = $variables['AnnotationTO'];
|
190
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/cdm_annotations.js');
|
191
|
drupal_add_js(drupal_get_path('module', 'cdm_dataportal') . '/js/jquery.form.js');
|
192
|
|
193
|
$out = theme('cdm_list_of_annotations', array('annotationElements' => $AnnotationTO->annotationElements));
|
194
|
|
195
|
$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array(
|
196
|
$AnnotationTO->uuid,
|
197
|
));
|
198
|
$annotationProxyUrl = url('cdm_api/proxy/' . urlencode($annotationUrl) . '/cdm_annotation_post');
|
199
|
|
200
|
// TODO users have to be authenticated to the dataportal to be able to write
|
201
|
// annotations.
|
202
|
$out .= '
|
203
|
<div class="annotation_create">
|
204
|
<form action="' . $annotationProxyUrl . '" method="POST">
|
205
|
<textarea name="annotation"></textarea>
|
206
|
<input type="hidden" name="commentator" value="">
|
207
|
<input type="submit" value="' . t('Save annotation') . '" />
|
208
|
</form>
|
209
|
</div>
|
210
|
';
|
211
|
|
212
|
return $out;
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* @todo Please document this function.
|
217
|
* @see http://drupal.org/node/1354
|
218
|
*/
|
219
|
function theme_cdm_list_of_annotations($variables) {
|
220
|
$annotationElements = $variables['annotationElements'];
|
221
|
$out = '<ul class="annotation_list">';
|
222
|
|
223
|
foreach ($annotationElements as $key => $row) {
|
224
|
$created[$key] = $row;
|
225
|
}
|
226
|
array_multisort($created, SORT_ASC, $annotationElements);
|
227
|
|
228
|
foreach ($annotationElements as $annotation) {
|
229
|
$out .= '<li>' . $annotation->text . '</li>';
|
230
|
}
|
231
|
|
232
|
$out .= '</ul>';
|
233
|
|
234
|
return $out;
|
235
|
}
|
236
|
|
237
|
/* ============================ footnotes ============================= */
|
238
|
/**
|
239
|
* @todo Please document this function.
|
240
|
* @see http://drupal.org/node/1354
|
241
|
*/
|
242
|
function theme_cdm_footnote_key($variables) {
|
243
|
|
244
|
$footnoteKey = $variables['footnoteKey'];
|
245
|
$separator = $variables['separator'];
|
246
|
$highlightable = $variables['highlightable'];
|
247
|
$separator_off = $variables['separator_off'];
|
248
|
if (!is_object($footnoteKey) or !isset($footnoteKey->footnoteListKey)) {
|
249
|
return '';
|
250
|
}
|
251
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
252
|
return '';
|
253
|
}
|
254
|
|
255
|
if ($separator_off) {
|
256
|
$separator = '';
|
257
|
}
|
258
|
$out = '<span class="footnote-key footnote-key-' . $footnoteKey->keyStr . ' member-of-footnotes-' . $footnoteKey->footnoteListKey . '">' . $separator . '<a href="#footnote-' . $footnoteKey->keyStr . '">' . $footnoteKey->keyStr . '</a>' . '</span>';
|
259
|
return $out;
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* @todo Please document this function.
|
264
|
* @see http://drupal.org/node/1354
|
265
|
*/
|
266
|
function theme_cdm_footnote($variables) {
|
267
|
$footnoteKey = $variables['footnoteKey'];
|
268
|
$footnoteText = $variables['footnoteText'];
|
269
|
$enclosing_tag = $variables['enclosing_tag'];
|
270
|
_add_js_footnotes();
|
271
|
$out = '<' . $enclosing_tag . ' class="footnote footnote-' . $footnoteKey . '">'
|
272
|
. '<a name="footnote-' . $footnoteKey . '"></a>'
|
273
|
. '<span class="footnote-anchor">' . $footnoteKey . '.</span> ' . $footnoteText
|
274
|
. '</' . $enclosing_tag . '>';
|
275
|
return $out;
|
276
|
}
|
277
|
|
278
|
/**
|
279
|
* @todo Please document this function.
|
280
|
* @see http://drupal.org/node/1354
|
281
|
*/
|
282
|
function theme_cdm_footnotes($variables) {
|
283
|
$footnoteListKey = $variables['footnoteListKey'];
|
284
|
$enclosingTag = $variables['enclosingTag'];
|
285
|
if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)) {
|
286
|
return '';
|
287
|
}
|
288
|
|
289
|
$out = '<' . $enclosingTag . ' class="footnotes footnotes-' . $footnoteListKey . ' ">'
|
290
|
. FootnoteManager::renderFootnoteList($footnoteListKey)
|
291
|
. '</' . $enclosingTag . '>';
|
292
|
|
293
|
FootnoteManager::removeFootnoteList($footnoteListKey);
|
294
|
return $out;
|
295
|
}
|
296
|
|
297
|
/**
|
298
|
* @todo Please document this function.
|
299
|
* @see http://drupal.org/node/1354
|
300
|
*/
|
301
|
function theme_cdm_annotations($variables) {
|
302
|
$annotations = $variables['annotations'];
|
303
|
$enclosingTag = $variables['enclosingTag'];
|
304
|
if (!is_array($annotations)) {
|
305
|
return;
|
306
|
}
|
307
|
$out = '<' . $enclosingTag . ' class="annotations">';
|
308
|
$i = 0;
|
309
|
foreach ($annotations as $annotation) {
|
310
|
$out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
|
311
|
}
|
312
|
$out .= '</' . $enclosingTag . '>';
|
313
|
return $out;
|
314
|
}
|
315
|
|
316
|
/**
|
317
|
* @todo Please document this function.
|
318
|
* @see http://drupal.org/node/1354
|
319
|
*/
|
320
|
function cdm_exist_footnote($footnote_list, $footnote) {
|
321
|
$result = FALSE;
|
322
|
if (is_array($footnote_list)) {
|
323
|
foreach ($footnote_list as $element) {
|
324
|
if ($element == $footnote) {
|
325
|
$result = TRUE;
|
326
|
}
|
327
|
}
|
328
|
}
|
329
|
return $result;
|
330
|
}
|
331
|
|
332
|
/**
|
333
|
* @todo Please document this function.
|
334
|
* @see http://drupal.org/node/1354
|
335
|
*/
|
336
|
function cdm_add_footnote_to_array(&$footnote_list, $footnote) {
|
337
|
if (!cdm_exist_footnote($footnote_list, $footnote)) {
|
338
|
$footnote_list[] = $footnote;
|
339
|
}
|
340
|
}
|
341
|
|
342
|
/**
|
343
|
* Theme function for CDM marker instances
|
344
|
*
|
345
|
* @see compose_cdm_marker();
|
346
|
* @param array $variables
|
347
|
* - markerType_representation_l10n: the localized representation of the marker.markerType field
|
348
|
*/
|
349
|
function theme_cdm_marker($variables) {
|
350
|
$class_attribute = null;
|
351
|
//TODO class attribute hacked?, use generic drupal way?
|
352
|
if(isset($variables['attributes']['class'])){
|
353
|
$class_attribute = $variables['attributes']['class'];
|
354
|
}
|
355
|
return '<span class="' . $class_attribute . '">' . $variables['label'] . '</span>';
|
356
|
}
|
357
|
|
358
|
/* ============================ pager ============================= */
|
359
|
/**
|
360
|
* @todo Please document this function.
|
361
|
* @see http://drupal.org/node/1354
|
362
|
*/
|
363
|
function theme_cdm_pager($variables) {
|
364
|
$pager = $variables['pager'];
|
365
|
$path = $variables['path'];
|
366
|
$parameters = $variables['parameters'];
|
367
|
$out = '';
|
368
|
|
369
|
if ($pager->pagesAvailable > 1) {
|
370
|
|
371
|
$out .= '<div class="pager">';
|
372
|
if ($pager->currentIndex > 0) {
|
373
|
$out .= theme('cdm_pager_link', array(
|
374
|
'text' => t('« first'),
|
375
|
'linkIndex' => 0,
|
376
|
'pager' => $pager,
|
377
|
'path' => $path,
|
378
|
'parameters' => $parameters,
|
379
|
'attributes' => array('class' => array('pager-first')),
|
380
|
));
|
381
|
$out .= theme('cdm_pager_link', array(
|
382
|
'text' => t('‹ previous'),
|
383
|
'linkIndex' => $pager->currentIndex - 1,
|
384
|
'pager' => $pager,
|
385
|
'path' => $path,
|
386
|
'parameters' => $parameters,
|
387
|
'attributes' => array('class' => array('pager-previous')),
|
388
|
));
|
389
|
}
|
390
|
|
391
|
if ($pager->indices[0] > 0) {
|
392
|
$out .= '<div class="pager-list-dots-left">...</div>';
|
393
|
}
|
394
|
|
395
|
foreach ($pager->indices as $index) {
|
396
|
$label = $index + 1;
|
397
|
$out .= theme('cdm_pager_link', array('text' => $label, 'linkIndex' => $index, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
|
398
|
'class' => array('pager-first'),
|
399
|
)));
|
400
|
}
|
401
|
if ($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1) {
|
402
|
$out .= '<div class="pager-list-dots-right">...</div>';
|
403
|
}
|
404
|
|
405
|
if ($pager->nextIndex) {
|
406
|
$out .= theme('cdm_pager_link', array('text' => t('next ›'), 'linkIndex' => $pager->nextIndex, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
|
407
|
'class' => array('pager-next'),
|
408
|
)));
|
409
|
$out .= theme('cdm_pager_link', array('text' => t('last »'), 'linkIndex' => $pager->pagesAvailable - 1, 'pager' => $pager, 'path' => $path, 'parameters' => $parameters, 'attributes' => array(
|
410
|
'class' => array('pager-last'),
|
411
|
)));
|
412
|
}
|
413
|
$out .= '</div>';
|
414
|
|
415
|
return $out;
|
416
|
}
|
417
|
}
|
418
|
|
419
|
/**
|
420
|
* @todo Please document this function.
|
421
|
* @see http://drupal.org/node/1354
|
422
|
*/
|
423
|
function theme_cdm_pager_link($variables) {
|
424
|
$text = $variables['text'];
|
425
|
$linkIndex = $variables['linkIndex'];
|
426
|
$pager = $variables['pager'];
|
427
|
$path = $variables['path'];
|
428
|
$parameters = $variables['parameters'];
|
429
|
$attributes = $variables['attributes'];
|
430
|
|
431
|
// the parameters may still contain the q param,
|
432
|
// but this is already in the path variable
|
433
|
unset($parameters['q']);
|
434
|
|
435
|
$parameters['pager']['pageNumber'] = $linkIndex;
|
436
|
if ($linkIndex == $pager->currentIndex) {
|
437
|
$out = '<strong>' . $text . '</strong>';
|
438
|
}
|
439
|
else {
|
440
|
// $queryString = drupal_query_string_encode($parameters);
|
441
|
$queryString = $parameters;
|
442
|
$out = l($text, $path, array(
|
443
|
'attributes' => $attributes,
|
444
|
'query' => $queryString,
|
445
|
));
|
446
|
}
|
447
|
return $out;
|
448
|
}
|
449
|
|
450
|
/* ============================ special buttons ============================= */
|
451
|
|
452
|
/**
|
453
|
* @todo Please document this function.
|
454
|
* @see http://drupal.org/node/1354
|
455
|
*/
|
456
|
function theme_cdm_back_to_image_gallery_button() {
|
457
|
$out = '<div id="backToGalleryButton">' . l(t('Back to Images'), $_SESSION['cdm']['last_gallery']) . '</div>';
|
458
|
return $out;
|
459
|
}
|
460
|
|
461
|
/**
|
462
|
* @todo Please document this function.
|
463
|
* @see http://drupal.org/node/1354
|
464
|
*/
|
465
|
function theme_cdm_print_button() {
|
466
|
|
467
|
drupal_add_js('jQuery(document).ready(function() {
|
468
|
jQuery(\'#print_button\').click(function () {
|
469
|
window.print();
|
470
|
});
|
471
|
});', array('type' => 'inline'));
|
472
|
|
473
|
$output = '<div id="print_button"><img src="' . base_path() . drupal_get_path('module', 'cdm_dataportal') . '/images/print_icon.gif"' . ' alt="' . t('Print this page') . '" title="' . t('Print this page') . '" />';
|
474
|
// .t('Print this page');
|
475
|
// $output .= l('Print this page', '');
|
476
|
$output .= '<span>Print this page</span>';
|
477
|
$output .= '</div>';
|
478
|
|
479
|
return $output;
|
480
|
}
|
481
|
|