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
/**
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 cdm_exist_footnote($footnote_list, $footnote){
256
	$result = false;
257
	if (is_array($footnote_list)){
258
		foreach ($footnote_list as $element){
259
			if ($element == $footnote){
260
				$result = true;
261
			}
262
		}
263
	}
264
	return $result;
265
}
266

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

    
273
/* ============================ pager ============================= */
274

    
275

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

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

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

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

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

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

    
305
		return $out;
306
	}
307
}
308

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

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

    
322
/* ============================ special buttons ============================= */
323

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

    
332
	}
333
	return $out;
334
}
335

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

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

    
343
	return $out;
344
}
345

    
346
function theme_cdm_print_button(){
347

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

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

    
361
	return $output;
362
}
363

    
364

    
365

    
366

    
367
/* ============================ java script functions ============================= */
368

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

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

    
404
function _add_js_footnotes(){
405
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
406
}
407

    
408

    
409
function _add_js_cluetip(){
410

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

    
429
function _add_js_ahah(){
430
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
431
}
(1-1/8)