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