Project

General

Profile

Download (13.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
 * TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
17
 * NOT WORKING since fragments are not available to the server
18
 function fragment(){
19
 global $fragment;
20
 if(!$fragment){
21
 $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
22
 }
23
 return $fragment;
24
 }
25
 */
26

    
27
function uuid_anchor($uuid, $innerHTML){
28
	$highlite = $_REQUEST['highlite'] == $uuid;
29
	return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
30
}
31

    
32
/**
33
 * Enter description here...
34
 *
35
 * @param unknown_type $name
36
 * @param unknown_type $numOfNameTokens
37
 * @return unknown
38
 * @deprecated looks like this is not used anymore
39
 */
40
function tagNameParts($name, $numOfNameTokens){
41

    
42
	$out = '<span class="name">';
43

    
44
	$token = strtok($name, " \n\t");
45
	$i = 0;
46
	$noSpace = true;
47
	while($token != false){
48
		if($i == $numOfNameTokens){
49
			$out .= '</span> <span class="authors">';
50
			$noSpace = true;
51
		}
52
		$out .= ($noSpace?'':' ').$token;
53
		$noSpace = false;
54
		$token = strtok(" \n\t");
55
		$i++;
56
	}
57
	return $out.'</span>';
58
}
59

    
60
/**
61
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas
62
 * each item will provided with a class attribute which set to the key of the TaggedText item.
63
 *
64
 * @param array $taggedtxt
65
 * @param String $tag
66
 * @param String $glue the string by which the chained text tokens are concatenated together.
67
 *       Default is a blank character
68
 * @return String of HTML
69
 */
70
function theme_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
71
	$out = '';
72
	$i = 0;
73
	foreach($taggedtxt as $tt){
74
		if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
75
			$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
76
		}
77
	}
78
	return $out;
79
}
80

    
81
/* ============================ annotations ============================= */
82

    
83
/**
84
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to display
85
 * as well as create or update annotations.
86
 * The following cdm classes are annotatable:
87
 *
88
 *  DescriptionElementBase
89
 *	EventBase
90
 *	HomotypicalGroup
91
 *	IdentifiableEntity
92
 *	  DescriptionBase
93
 *	  IdentifiableMediaEntity
94
 *	  Media
95
 *	  Sequence
96
 *	  TaxonBase
97
 *	  TaxonNameBase
98
 *	  TaxonomicTree
99
 *	  TermBase
100
 *	LanguageStringBase
101
 *	ReferencedEntityBase
102
 *	  NomenclaturalStatus
103
 *	  OriginalSourceBase
104
 *	  RelationshipBase
105
 *	  TypeDesignationBase
106
 *	TaxonNode
107
 *  WorkingSet
108
 *
109
 * TODO it should be configurable which objects can be annotated as this might differ in dataportals
110
 *
111
 */
112
function theme_cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key = array()){
113
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
114
    return '';
115
  }
116
	$footNoteKeys = cdm_annotations_as_footnotekeys($cdmBase, $footnote_list_key);
117
	foreach($footNoteKeys as $a){
118
		//$out .=  theme('cdm_footnote_key', $a, $a->footnoteListKey, (isset($out)? ',' : ''));
119
		$out .=  theme('cdm_footnote_key', $a, (isset($out)? ',' : ''));
120
	}
121
	return $out;
122
}
123

    
124

    
125
function theme_cdm_annotation_footnotes($footnoteListKey, $enclosingTag = 'span'){
126
  if (variable_get('cdm_dataportal_annotations_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
127
    return '';
128
  }
129
	return theme('cdm_footnotes', $footnoteListKey . '-annotations', $enclosingTag);
130
}
131

    
132
function theme_cdm_annotation_content($AnnotationTO){
133

    
134
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
135
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
136

    
137
	$out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
138

    
139
	$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
140
	$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
141

    
142
	// TODO users have to be authenticated to the dataportal to be able to write annotations
143
	$out .= '
144
  			<div class="annotation_create">
145
  				<form action="'.$annotationProxyUrl.'" method="POST">
146
  					<textarea name="annotation"></textarea>
147
  					<input type="hidden" name="commentator" value="">
148
  					<input type="submit" value="'.t('Save annotation').'" />
149
  				</form>
150
 			</div>
151
	';
152

    
153
	return $out;
154
}
155

    
156
function theme_cdm_list_of_annotations($annotationElements){
157

    
158
	$out = '<ul class="annotation_list">';
159

    
160
	foreach ($annotationElements as $key => $row){
161
		$created[$key] = $row;
162
	}
163
	array_multisort($created, SORT_ASC, $annotationElements);
164

    
165
	foreach ($annotationElements as $annotation){
166
		$out .= '<li>' . $annotation->text . '</li>';
167
	}
168

    
169
	$out .= '</ul>';
170

    
171
	return $out;
172

    
173
}
174

    
175
/* ============================ footnotes ============================= */
176

    
177
function theme_cdm_footnote_key($footnoteKey, $separator = '', $highlightable=true, $separator_off = false){
178
	if (!$footnoteKey->footnoteListKey){
179
		return '';
180
	}
181
	if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
182
		return '';
183
	}
184
	
185
	if ($separator_off){
186
		$separator = '';
187
	}
188
	$out = '<span class="footnote-key footnote-key-'.$footnoteKey->keyStr.' member-of-footnotes-'.$footnoteKey->footnoteListKey.'">'.$separator
189
	.'<a href="#footnote-'.$footnoteKey->keyStr.'">'.$footnoteKey->keyStr.'</a>'
190
	.'</span>';
191
	return $out;
192
}
193

    
194
function theme_cdm_footnote($footnoteKey, $footnoteText){
195
	_add_js_footnotes();
196
	$out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span>&nbsp;'.$footnoteText.'</span>';
197
	return $out;
198
}
199

    
200

    
201
function theme_cdm_footnotes($footnoteListKey, $enclosingTag = 'span'){
202
  if (variable_get('cdm_dataportal_all_footnotes', CDM_DATAPORTAL_ALL_FOOTNOTES)){
203
    return '';
204
  }
205
	$out = '<'.$enclosingTag.' class="footnotes footnotes-'.$footnoteListKey.' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</'.$enclosingTag.'>';
206
	FootnoteManager::removeFootnoteList($footnoteListKey);
207
	return $out;
208
}
209

    
210
function cdm_exist_footnote($footnote_list, $footnote){
211
	$result = false;
212
	if (is_array($footnote_list)){
213
		foreach ($footnote_list as $element){
214
			if ($element == $footnote){
215
				$result = true;
216
			}
217
		}
218
	}
219
	return $result;
220
}
221

    
222
function cdm_add_footnote_to_array(&$footnote_list, $footnote){
223
	if(!cdm_exist_footnote($footnote_list, $footnote)){
224
		$footnote_list[] = $footnote;
225
	}
226
}
227

    
228
/* ============================ pager ============================= */
229

    
230

    
231
function theme_cdm_pager(&$pager, $path, $parameters){
232
	$out = '';
233

    
234
	if ($pager->pagesAvailable > 1) {
235

    
236
		$out .= '<div class="pager">';
237
		if($pager->currentIndex > 0){
238
			$out .= theme('cdm_pager_link', t('« first'), 0,  $pager, $path, $parameters, array('class' => 'pager-first'));
239
			$out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
240
		}
241

    
242
		if($pager->indices[0] > 0){
243
			$out .= '<div class="pager-list-dots-left">...</div>';
244
		}
245

    
246
		foreach($pager->indices as $index){
247
			$label = $index + 1;
248
			$out .= theme('cdm_pager_link', $label, $index,  $pager, $path, $parameters, array('class' => 'pager-first'));
249
		}
250
		if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
251
			$out .= '<div class="pager-list-dots-right">...</div>';
252
		}
253

    
254
		if($pager->nextIndex){
255
			$out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
256
			$out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
257
		}
258
		$out .= '</div>';
259

    
260
		return $out;
261
	}
262
}
263

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

    
266
	$out = '';
267
	$parameters['search']['page'] = $linkIndex;
268
	if ($linkIndex == $pager->currentIndex) {
269
		$out = '<strong>'.$text.'</strong>';
270
	} else {
271
		$queryString = drupal_query_string_encode($parameters);
272
		$out = l($text, $path, $attributes, $queryString);
273
	}
274
	return $out;
275
}
276

    
277
/* ============================ special buttons ============================= */
278

    
279
function theme_cdm_back_to_search_result_button(){
280
	$out = '';
281
	if($_SESSION['cdm']['search']){
282
		/*['cdm']['last_search']*/
283
		//$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
284
		$out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
285

    
286
	}
287
	return $out;
288
}
289

    
290
function theme_cdm_back_to_image_gallery_button(){
291
	//$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
292
	//$gallery_name = $taxon->uuid;
293
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
294

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

    
297
	return $out;
298
}
299

    
300
function theme_cdm_print_button(){
301

    
302
	drupal_add_js ('$(document).ready(function() {
303
         $(\'#print_button\').click(function () {
304
         window.print();
305
     });
306
  });', 'inline');
307

    
308
	$output = '<div id="print_button"><img src="'
309
	.drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
310
	. ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
311
	//$output .= l(' Print this page', '');
312
	$output .= '<span>Print this page</span>';
313
	$output .= '</div>';
314

    
315
	return $output;
316
}
317

    
318
/* ============================ other ============================= */
319

    
320

    
321

    
322

    
323
function theme_cdm_dynabox($label, $content_url, $theme, $enclosingtag = 'li'){
324
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
325

    
326
	$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
327
	$out .= '<li class="dynabox"><span class="label" alt="'.t('Click for accepted taxon').'">'.$label.'</span>';
328
	$out .= '<ul class="dynabox_content" title="'.$cdm_proxy_url.'"><li><img class="loading" src="'.drupal_get_path('module', 'cdm_dataportal').'/images/loading_circle_grey_16.gif" style="display:none;"></li></ul>';
329
	return $out;
330
}
331

    
332

    
333
/* ============================ java script functions ============================= */
334

    
335
function _add_js_thickbox(){
336
	// ---- jQuery thickbox:
337
	/*
338
	 * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
339
	 * -> event is not triggered because of problems with compat-1.0.js'
340
	 * see INSTALL.txt
341
	 *
342
	 */
343
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
344
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
345
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
346
}
347

    
348
function _add_js_lightbox($galleryID){
349
	/*
350
	 * Important Notice:
351
	 * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
352
	 * for captions instead of the "title" attribute
353
	 */
354
	$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
355
	drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
356
	drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
357
	drupal_add_js ('$(document).ready(function() {
358
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
359
        fixedNavigation:  true,
360
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\',
361
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',
362
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',
363
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',
364
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
365
      });
366
    });
367
    ', 'inline');
368
}
369

    
370
function _add_js_footnotes(){
371
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
372
}
373

    
374

    
375
function _add_js_cluetip(){
376

    
377
	//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
378
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
379
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
380
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
381
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
382
	drupal_add_js ("$(document).ready(function(){
383
      $('.cluetip').css({color: '#0062C2'}).cluetip({
384
        splitTitle: '|',
385
        showTitle: true,
386
        activation: 'hover',
387
        sicky: true,
388
        arrows: true,
389
        dropShadow: false,
390
        cluetipClass: 'rounded'
391
      });
392
    });", 'inline');
393
}
394

    
395
function _add_js_ahah(){
396
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
397
}
(1-1/8)