Project

General

Profile

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

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

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

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

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

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

    
126
/* ============================ annotations ============================= */
127

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

    
169

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

    
177
function theme_cdm_annotation_content($AnnotationTO){
178

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

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

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

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

    
198
	return $out;
199
}
200

    
201
function theme_cdm_list_of_annotations($annotationElements){
202

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

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

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

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

    
216
	return $out;
217

    
218
}
219

    
220
/* ============================ footnotes ============================= */
221

    
222
function theme_cdm_footnote_key($footnoteKey, $separator = '', $highlightable=true, $separator_off = false){
223
	if (!$footnoteKey->footnoteListKey){
224
		return '';
225
	}
226
	if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
227
		return '';
228
	}
229

    
230
	if ($separator_off){
231
		$separator = '';
232
	}
233
	$out = '<span class="footnote-key footnote-key-'.$footnoteKey->keyStr.' member-of-footnotes-'.$footnoteKey->footnoteListKey.'">'.$separator
234
	.'<a href="#footnote-'.$footnoteKey->keyStr.'">'.$footnoteKey->keyStr.'</a>'
235
	.'</span>';
236
	return $out;
237
}
238

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

    
245

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

    
255
function theme_cdm_annotations($annotations, $enclosingTag = 'span'){
256
  if(!is_array($annotations)){
257
  	return;
258
  }
259
  $out = '<'.$enclosingTag.' class="annotations">';
260
  $i = 0;
261
  foreach($annotations as $annotation){
262
    $out .= ($i++ > 0 ? ', ' : '') . $annotation->text;
263
  }
264
  $out .= '</'.$enclosingTag.'>';
265
  return $out;
266
}
267

    
268
function cdm_exist_footnote($footnote_list, $footnote){
269
	$result = false;
270
	if (is_array($footnote_list)){
271
		foreach ($footnote_list as $element){
272
			if ($element == $footnote){
273
				$result = true;
274
			}
275
		}
276
	}
277
	return $result;
278
}
279

    
280
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
281
	if(!cdm_exist_footnote($footnote_list, $footnote)){
282
		$footnote_list[] = $footnote;
283
	}
284
}
285

    
286
/* ============================ pager ============================= */
287

    
288

    
289
function theme_cdm_pager(&$pager, $path, $parameters){
290
	$out = '';
291

    
292
	if ($pager->pagesAvailable > 1) {
293

    
294
		$out .= '<div class="pager">';
295
		if($pager->currentIndex > 0){
296
			$out .= theme('cdm_pager_link', t('« first'), 0,  $pager, $path, $parameters, array('class' => 'pager-first'));
297
			$out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
298
		}
299

    
300
		if($pager->indices[0] > 0){
301
			$out .= '<div class="pager-list-dots-left">...</div>';
302
		}
303

    
304
		foreach($pager->indices as $index){
305
			$label = $index + 1;
306
			$out .= theme('cdm_pager_link', $label, $index,  $pager, $path, $parameters, array('class' => 'pager-first'));
307
		}
308
		if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
309
			$out .= '<div class="pager-list-dots-right">...</div>';
310
		}
311

    
312
		if($pager->nextIndex){
313
			$out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
314
			$out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
315
		}
316
		$out .= '</div>';
317

    
318
		return $out;
319
	}
320
}
321

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

    
324
	$out = '';
325
	$parameters['search']['pageNumber'] = $linkIndex;
326
	if ($linkIndex == $pager->currentIndex) {
327
		$out = '<strong>'.$text.'</strong>';
328
	} else {
329
		$queryString = drupal_query_string_encode($parameters);
330
		$out = l($text, $path, $attributes, $queryString);
331
	}
332
	return $out;
333
}
334

    
335
/* ============================ special buttons ============================= */
336

    
337
function theme_cdm_back_to_search_result_button(){
338
	$out = '';
339
	$show_button = variable_get('cdm_dataportal_show_back_to_search_results', 1);
340
	if($_SESSION['cdm']['search'] && $show_button){
341
		/*['cdm']['last_search']*/
342
		//$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
343
		$out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
344

    
345
	}
346
	return $out;
347
}
348

    
349
function theme_cdm_back_to_image_gallery_button(){
350

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

    
353
	return $out;
354
}
355

    
356
function theme_cdm_print_button(){
357

    
358
	drupal_add_js ('$(document).ready(function() {
359
         $(\'#print_button\').click(function () {
360
         window.print();
361
     });
362
  });', 'inline');
363

    
364
	$output = '<div id="print_button"><img src="'
365
	.drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
366
	. ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
367
	//$output .= l(' Print this page', '');
368
	$output .= '<span>Print this page</span>';
369
	$output .= '</div>';
370

    
371
	return $output;
372
}
373

    
374

    
375

    
376

    
377
/* ============================ java script functions ============================= */
378

    
379
function _add_js_thickbox(){
380
	// ---- jQuery thickbox:
381
	/*
382
	 * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
383
	 * -> event is not triggered because of problems with compat-1.0.js'
384
	 * see INSTALL.txt
385
	 *
386
	 */
387
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
388
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
389
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
390
}
391

    
392
function _add_js_lightbox($galleryID){
393
	/*
394
	 * Important Notice:
395
	 * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
396
	 * for captions instead of the "title" attribute
397
	 */
398
	$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
399
	drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
400
	drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
401
	drupal_add_js ('$(document).ready(function() {
402
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
403
        fixedNavigation:  true,
404
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\',
405
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',
406
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',
407
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',
408
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
409
      });
410
    });
411
    ', 'inline');
412
}
413

    
414
function _add_js_footnotes(){
415
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
416
}
417

    
418

    
419
function _add_js_cluetip(){
420

    
421
	//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
422
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
423
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
424
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
425
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
426
	drupal_add_js ("$(document).ready(function(){
427
      $('.cluetip').css({color: '#0062C2'}).cluetip({
428
        splitTitle: '|',
429
        showTitle: true,
430
        activation: 'hover',
431
        sicky: true,
432
        arrows: true,
433
        dropShadow: false,
434
        cluetipClass: 'rounded'
435
      });
436
    });", 'inline');
437
}
438

    
439
function _add_js_ahah(){
440
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
441
}
(1-1/8)