Project

General

Profile

Download (14.1 KB) Statistics
| Branch: | Tag: | Revision:
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
* Get the true path to the root of the Drupal site.
17
* Better than using DOCUMENT_ROOT and base_path().
18
*/
19
function absolute_path_to_drupal() {
20
    static $absolute_path_to_drupal = NULL;
21
    
22
    if ($absolute_path_to_drupal === NULL) {
23
        // Get the absolute path to this file:
24
        $dir = rtrim(str_replace('\\', '/', dirname(__FILE__)), '/');
25
        $parts = explode('/', $dir);
26
        // Iterate up the directory hierarchy until we find the website root:
27
        $done = FALSE;
28
        do{
29
            // Check a couple of obvious things:
30
            $done = is_dir("$dir/sites") && is_dir("$dir/includes") && is_file("$dir/index.php");
31
            if (!$done) {
32
                // If there's no more path to examine, we didn't find the site root:
33
                if (empty($parts)) {
34
                    $absolute_path_to_drupal = FALSE;
35
                    break;
36
                }
37
            // Go up one level and look again:
38
            array_pop($parts);
39
            $dir = implode('/', $parts);
40
            }
41
        }while (!$done);
42

    
43
        $absolute_path_to_drupal = $dir;
44
    }
45
    return $absolute_path_to_drupal;
46
}
47

    
48
function taxon_in_current_tree ($taxon_uuid) {
49
	$taxon_nodes = cdm_ws_get(CDM_WS_PORTAL_TAXON_TAXONNODES, $taxon_uuid);
50
	$taxon_in_current_tree = false;
51
	foreach($taxon_nodes as $node){
52
		if(get_taxonomictree_uuid_selected() == $node->classification->uuid){
53
			$taxon_in_current_tree = true;
54
			break;
55
		}
56
	}
57
	return $taxon_in_current_tree;
58
}
59
/**
60
 * TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
61
 * NOT WORKING since fragments are not available to the server
62
 function fragment(){
63
 global $fragment;
64
 if(!$fragment){
65
 $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
66
 }
67
 return $fragment;
68
 }
69
 */
70

    
71
function uuid_anchor($uuid, $innerHTML){
72
	$highlite = $_REQUEST['highlite'] == $uuid;
73
	return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
74
}
75

    
76
/**
77
 * Enter description here...
78
 *
79
 * @param unknown_type $name
80
 * @param unknown_type $numOfNameTokens
81
 * @return unknown
82
 * @deprecated looks like this is not used anymore
83
 */
84
function tagNameParts($name, $numOfNameTokens){
85

    
86
	$out = '<span class="name">';
87

    
88
	$token = strtok($name, " \n\t");
89
	$i = 0;
90
	$noSpace = true;
91
	while($token != false){
92
		if($i == $numOfNameTokens){
93
			$out .= '</span> <span class="authors">';
94
			$noSpace = true;
95
		}
96
		$out .= ($noSpace?'':' ').$token;
97
		$noSpace = false;
98
		$token = strtok(" \n\t");
99
		$i++;
100
	}
101
	return $out.'</span>';
102
}
103

    
104
/**
105
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas
106
 * each item will provided with a class attribute which set to the key of the TaggedText item.
107
 *
108
 * @param array $taggedtxt
109
 * @param String $tag
110
 * @param String $glue the string by which the chained text tokens are concatenated together.
111
 *       Default is a blank character
112
 * @return String of HTML
113
 */
114
function theme_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
115
	$out = '';
116
	$i = 0;
117
	foreach($taggedtxt as $tt){
118
		if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
119
			$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
120
		}
121
	}
122
	return $out;
123
}
124

    
125
/* ============================ annotations ============================= */
126

    
127
/**
128
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to display
129
 * as well as create or update annotations.
130
 * The following cdm classes are annotatable:
131
 *
132
 *  DescriptionElementBase
133
 *	EventBase
134
 *	HomotypicalGroup
135
 *	IdentifiableEntity
136
 *	  DescriptionBase
137
 *	  IdentifiableMediaEntity
138
 *	  Media
139
 *	  Sequence
140
 *	  TaxonBase
141
 *	  TaxonNameBase
142
 *	  TaxonomicTree
143
 *	  TermBase
144
 *	LanguageStringBase
145
 *	ReferencedEntityBase
146
 *	  NomenclaturalStatus
147
 *	  OriginalSourceBase
148
 *	  RelationshipBase
149
 *	  TypeDesignationBase
150
 *	TaxonNode
151
 *  WorkingSet
152
 *
153
 * TODO it should be configurable which objects can be annotated as this might differ in dataportals
154
 *
155
 */
156
function theme_cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = array()){
157
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
158
    return '';
159
  }
160
	$footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key);
161
	foreach($footNoteKeys as $a){
162
		//$out .=  theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)? ',' : ''));
163
		$out .=  theme('cdm_footnote_key', $a, (isset($out)? ',' : ''));
164
	}
165
	return $out;
166
}
167

    
168

    
169
function theme_cdm_annotation_footnotes($footnoteListKey, $enclosingTag = 'span'){
170
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
171
    return '';
172
  }
173
	return theme('cdm_footnotes', $footnoteListKey . '-annotations', $enclosingTag);
174
}
175

    
176
function theme_cdm_annotation_content($AnnotationTO){
177

    
178
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
179
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
180

    
181
	$out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
182

    
183
	$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
184
	$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
185

    
186
	// TODO users have to be authenticated to the dataportal to be able to write annotations
187
	$out .= '
188
  			<div class="annotation_create">
189
  				<form action="'.$annotationProxyUrl.'" method="POST">
190
  					<textarea name="annotation"></textarea>
191
  					<input type="hidden" name="commentator" value="">
192
  					<input type="submit" value="'.t('Save annotation').'" />
193
  				</form>
194
 			</div>
195
	';
196

    
197
	return $out;
198
}
199

    
200
function theme_cdm_list_of_annotations($annotationElements){
201

    
202
	$out = '<ul class="annotation_list">';
203

    
204
	foreach ($annotationElements as $key => $row){
205
		$created[$key] = $row;
206
	}
207
	array_multisort($created, SORT_ASC, $annotationElements);
208

    
209
	foreach ($annotationElements as $annotation){
210
		$out .= '<li>' . $annotation->text . '</li>';
211
	}
212

    
213
	$out .= '</ul>';
214

    
215
	return $out;
216

    
217
}
218

    
219
/* ============================ footnotes ============================= */
220

    
221
function theme_cdm_footnote_key($footnoteKey, $separator = '', $highlightable=true, $separator_off = false){
222
	if (!$footnoteKey->footnoteListKey){
223
		return '';
224
	}
225
	if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
226
		return '';
227
	}
228
	
229
	if ($separator_off){
230
		$separator = '';
231
	}
232
	$out = '<span class="footnote-key footnote-key-'.$footnoteKey->keyStr.' member-of-footnotes-'.$footnoteKey->footnoteListKey.'">'.$separator
233
	.'<a href="#footnote-'.$footnoteKey->keyStr.'">'.$footnoteKey->keyStr.'</a>'
234
	.'</span>';
235
	return $out;
236
}
237

    
238
function theme_cdm_footnote($footnoteKey, $footnoteText){
239
	_add_js_footnotes();
240
	$out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span>&nbsp;'.$footnoteText.'</span>';
241
	return $out;
242
}
243

    
244

    
245
function theme_cdm_footnotes($footnoteListKey, $enclosingTag = 'span'){
246
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
247
    return '';
248
  }
249
	$out = '<'.$enclosingTag.' class="footnotes footnotes-'.$footnoteListKey.' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</'.$enclosingTag.'>';
250
	FootnoteManager::removeFootnoteList($footnoteListKey);
251
	return $out;
252
}
253

    
254
function cdm_exist_footnote($footnote_list, $footnote){
255
	$result = false;
256
	if (is_array($footnote_list)){
257
		foreach ($footnote_list as $element){
258
			if ($element == $footnote){
259
				$result = true;
260
			}
261
		}
262
	}
263
	return $result;
264
}
265

    
266
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
267
	if(!cdm_exist_footnote($footnote_list, $footnote)){
268
		$footnote_list[] = $footnote;
269
	}
270
}
271

    
272
/* ============================ pager ============================= */
273

    
274

    
275
function theme_cdm_pager(&$pager, $path, $parameters){
276
	$out = '';
277

    
278
	if ($pager->pagesAvailable > 1) {
279

    
280
		$out .= '<div class="pager">';
281
		if($pager->currentIndex > 0){
282
			$out .= theme('cdm_pager_link', t('« first'), 0,  $pager, $path, $parameters, array('class' => 'pager-first'));
283
			$out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
284
		}
285

    
286
		if($pager->indices[0] > 0){
287
			$out .= '<div class="pager-list-dots-left">...</div>';
288
		}
289

    
290
		foreach($pager->indices as $index){
291
			$label = $index + 1;
292
			$out .= theme('cdm_pager_link', $label, $index,  $pager, $path, $parameters, array('class' => 'pager-first'));
293
		}
294
		if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
295
			$out .= '<div class="pager-list-dots-right">...</div>';
296
		}
297

    
298
		if($pager->nextIndex){
299
			$out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
300
			$out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
301
		}
302
		$out .= '</div>';
303

    
304
		return $out;
305
	}
306
}
307

    
308
function theme_cdm_pager_link($text, $linkIndex, &$pager, $path, $parameters = array(), $attributes) {
309

    
310
	$out = '';
311
	$parameters['search']['page'] = $linkIndex;
312
	if ($linkIndex == $pager->currentIndex) {
313
		$out = '<strong>'.$text.'</strong>';
314
	} else {
315
		$queryString = drupal_query_string_encode($parameters);
316
		$out = l($text, $path, $attributes, $queryString);
317
	}
318
	return $out;
319
}
320

    
321
/* ============================ special buttons ============================= */
322

    
323
function theme_cdm_back_to_search_result_button(){
324
	$out = '';
325
	$show_button = variable_get('cdm_dataportal_show_back_to_search_results', 1);
326
	if($_SESSION['cdm']['search'] && $show_button){
327
		/*['cdm']['last_search']*/
328
		//$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
329
		$out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
330

    
331
	}
332
	return $out;
333
}
334

    
335
function theme_cdm_back_to_image_gallery_button(){
336
	//$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
337
	//$gallery_name = $taxon->uuid;
338
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
339

    
340
	$out = '<div id="backToGalleryButton">'.l(t('Back to Images'), $_SESSION['cdm']['last_gallery'] ).'</div>';
341

    
342
	return $out;
343
}
344

    
345
function theme_cdm_print_button(){
346

    
347
	drupal_add_js ('$(document).ready(function() {
348
         $(\'#print_button\').click(function () {
349
         window.print();
350
     });
351
  });', 'inline');
352

    
353
	$output = '<div id="print_button"><img src="'
354
	.drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
355
	. ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
356
	//$output .= l(' Print this page', '');
357
	$output .= '<span>Print this page</span>';
358
	$output .= '</div>';
359

    
360
	return $output;
361
}
362

    
363

    
364
/* ============================ java script functions ============================= */
365

    
366
function _add_js_thickbox(){
367
	// ---- jQuery thickbox:
368
	/*
369
	 * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
370
	 * -> event is not triggered because of problems with compat-1.0.js'
371
	 * see INSTALL.txt
372
	 *
373
	 */
374
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
375
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
376
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
377
}
378

    
379
function _add_js_lightbox($galleryID){
380
	/*
381
	 * Important Notice:
382
	 * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
383
	 * for captions instead of the "title" attribute
384
	 */
385
	$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
386
	drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
387
	drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
388
	drupal_add_js ('$(document).ready(function() {
389
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
390
        fixedNavigation:  true,
391
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\',
392
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',
393
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',
394
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',
395
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
396
      });
397
    });
398
    ', 'inline');
399
}
400

    
401
function _add_js_footnotes(){
402
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
403
}
404

    
405

    
406
function _add_js_cluetip(){
407

    
408
	//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
409
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
410
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
411
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
412
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
413
	drupal_add_js ("$(document).ready(function(){
414
      $('.cluetip').css({color: '#0062C2'}).cluetip({
415
        splitTitle: '|',
416
        showTitle: true,
417
        activation: 'hover',
418
        sicky: true,
419
        arrows: true,
420
        dropShadow: false,
421
        cluetipClass: 'rounded'
422
      });
423
    });", 'inline');
424
}
425

    
426
function _add_js_ahah(){
427
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
428
}
(1-1/8)