Project

General

Profile

Download (13.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
 * 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){
113
	
114
    $annotationUrl = cdm_compose_annotations_url($cdmBase);
115
    if($annotationUrl){
116
        $annotationPager = cdm_ws_get($annotationUrl, null, null, null, true);
117
        if($annotationPager->count > 0){
118
	        foreach($annotationPager->records as $annotation){
119
		        $footnoteKey = FootnoteManager::addNewFootnote(RenderHints::getFootnoteListKey() . '-annotations', $annotation->text);
120
		        $out .=  theme('cdm_footnote_key', $footnoteKey, RenderHints::getFootnoteListKey() . '-annotations', (isset($out)? ',' : ''));
121
		        
122
//		        var_dump(RenderHints::getFootnoteListKey());
123
//		        var_dump(RenderHints::getRenderPath());
124
//	        	$footnoteKey = FootnoteManager::addNewFootnote(RenderHints::getRenderPath() . '-annotations', $annotation->text);
125
//            $out .=  theme('cdm_footnote_key', $footnoteKey, RenderHints::getRenderPath() . '-annotations', (isset($out)? ',' : ''));
126
	        }   
127
        }
128
    }
129
	return $out;
130
}
131

    
132

    
133
function theme_cdm_annotation_footnotes($footnoteListKey, $enclosingTag = 'span'){
134
    return theme('cdm_footnotes', $footnoteListKey . '-annotations', $enclosingTag);
135
}
136

    
137
function theme_cdm_annotation_content($AnnotationTO){
138

    
139
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
140
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
141

    
142
	$out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
143

    
144
	$annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
145
	$annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
146

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

    
158
	return $out;
159
}
160

    
161
function theme_cdm_list_of_annotations($annotationElements){
162

    
163
	$out = '<ul class="annotation_list">';
164

    
165
	foreach ($annotationElements as $key => $row){
166
		$created[$key] = $row;
167
	}
168
	array_multisort($created, SORT_ASC, $annotationElements);
169

    
170
	foreach ($annotationElements as $annotation){
171
		$out .= '<li>' . $annotation->text . '</li>';
172
	}
173

    
174
	$out .= '</ul>';
175

    
176
	return $out;
177

    
178
}
179

    
180
/* ============================ footnotes ============================= */
181

    
182
function theme_cdm_footnote_key($footnoteKey, $footnoteListKey, $separator = '', $highlightable=true){
183
  $out = '<span class="footnote-key footnote-key-'.$footnoteKey.' member-of-footnotes-'.$footnoteListKey.'">'.$separator
184
        .'<a href="#footnote-'.$footnoteKey.'">'.$footnoteKey.'</a>'
185
        .'</span>';
186
  return $out;
187
}
188

    
189
function theme_cdm_footnote($footnoteKey, $footnoteText){
190
  _add_js_footnotes();
191
  $out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span>&nbsp;'.$footnoteText.'</span>';
192
  return $out;
193
}
194

    
195

    
196
function theme_cdm_footnotes($footnoteListKey, $enclosingTag = 'span'){
197
	
198
	$out = '<'.$enclosingTag.' class="footnotes footnotes-'.$footnoteListKey.' ">' . FootnoteManager::renderFootnoteList($footnoteListKey) . '</'.$enclosingTag.'>';
199
	return $out;
200
}
201

    
202

    
203
/* ============================ pager ============================= */
204

    
205

    
206
function theme_cdm_pager(&$pager, $path, $parameters){
207
	$out = '';
208

    
209
	if ($pager->pagesAvailable > 1) {
210

    
211
		$out .= '<div class="pager">';
212
		if($pager->currentIndex > 0){
213
			$out .= theme('cdm_pager_link', t('« first'), 0,  $pager, $path, $parameters, array('class' => 'pager-first'));
214
			$out .= theme('cdm_pager_link', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
215
		}
216

    
217
		if($pager->indices[0] > 0){
218
			$out .= '<div class="pager-list-dots-left">...</div>';
219
		}
220

    
221
		foreach($pager->indices as $index){
222
			$label = $index + 1;
223
			$out .= theme('cdm_pager_link', $label, $index,  $pager, $path, $parameters, array('class' => 'pager-first'));
224
		}
225
		if($pager->indices[count($pager->indices) - 1] < $pager->pagesAvailable - 1){
226
			$out .= '<div class="pager-list-dots-right">...</div>';
227
		}
228

    
229
		if($pager->nextIndex){
230
			$out .= theme('cdm_pager_link', t('next ›'), $pager->nextIndex, $pager, $path, $parameters, array('class' => 'pager-next'));
231
			$out .= theme('cdm_pager_link', t('last »'), $pager->pagesAvailable - 1, $pager, $path, $parameters, array('class' => 'pager-last'));
232
		}
233
		$out .= '</div>';
234

    
235
		return $out;
236
	}
237
}
238

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

    
241
	$out = '';
242
	$parameters['search']['page'] = $linkIndex;
243
	if ($linkIndex == $pager->currentIndex) {
244
		$out = '<strong>'.$text.'</strong>';
245
	} else {
246
		$queryString = drupal_query_string_encode($parameters);
247
		$out = l($text, $path, $attributes, $queryString);
248
	}
249
	return $out;
250
}
251

    
252
/* ============================ special buttons ============================= */
253

    
254
function theme_cdm_back_to_search_result_button(){
255
	$out = '';
256
	if($_SESSION['cdm']['search']){
257
		/*['cdm']['last_search']*/
258
		//$out .= '<div id="backButton">'.l(t('Back to search result'), $_SESSION ).'</div>';
259
		$out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
260

    
261
	}
262
	return $out;
263
}
264

    
265
function theme_cdm_back_to_image_gallery_button(){
266
	//$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
267
	//$gallery_name = $taxon->uuid;
268
	//$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
269

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

    
272
	return $out;
273
}
274

    
275
function theme_cdm_print_button(){
276

    
277
	drupal_add_js ('$(document).ready(function() {
278
         $(\'#print_button\').click(function () { 
279
         window.print();
280
     });
281
  });', 'inline');
282

    
283
	$output = '<div id="print_button"><img src="'
284
	.drupal_get_path('module', 'cdm_dataportal').'/images/print_icon.gif'
285
	. ' "alt="' . t('Print this page') . ' "title="'.t('Print this page').'" />'; //.t(' Print this page');
286
	//$output .= l(' Print this page', '');
287
	$output .= '<span>Print this page</span>';
288
	$output .= '</div>';
289

    
290
	return $output;
291
}
292

    
293
/* ============================ other ============================= */
294

    
295
//function theme_cdm_credits(){
296
//	return "";
297
//	$secRef_array = _cdm_dataportal_currentSecRef_array();
298
//	return '<span class="sec_reference_citation">'.$secRef_array['citation'].'</span>'
299
//	.( $secRef_array['period'] ? ' <span class="year">'.partialToYear($secRef_array['period']).'</span>' : '')
300
//	.( $secRef_array['authorTeam'] ? '<div class="author">'.$secRef_array['authorTeam']['titleCache'].'</div>' : '');
301
//}
302

    
303

    
304
function theme_cdm_dynabox($label, $content_url, $theme, $enclosingtag = 'li'){
305
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
306

    
307
	$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
308
	$out .= '<li class="dynabox"><span class="label" alt="'.t('Click for accepted taxon').'">'.$label.'</span>';
309
	$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>';
310
	return $out;
311
}
312

    
313
/* ============================ java script functions ============================= */
314

    
315
function _add_js_thickbox(){
316
	// ---- jQuery thickbox:
317
	/*
318
	* bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
319
	* -> event is not triggered because of problems with compat-1.0.js'
320
	* see INSTALL.txt
321
	*
322
	*/
323
	//drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
324
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/thickbox.js');
325
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox/cdm_thickbox.css');
326
}
327

    
328
function _add_js_lightbox($galleryID){
329
	/*
330
	 * Important Notice:
331
	 * The jquery.lightbox-0.5.js has been modified in order to allow using the "alt" attribute
332
	 * for captions instead of the "title" attribute
333
	 */
334
	$lightBoxBasePath = drupal_get_path('module', 'cdm_dataportal') .'/js/jquery-lightbox-0.5';
335
	drupal_add_js($lightBoxBasePath.'/js/jquery.lightbox-0.5.js');
336
	drupal_add_css($lightBoxBasePath.'/css/jquery.lightbox-0.5.css');
337
	drupal_add_js ('$(document).ready(function() {
338
      $(\'#'.$galleryID.' a.lightbox\').lightBox({
339
        fixedNavigation:  true,
340
        imageLoading:     \''.$lightBoxBasePath.'/images/lightbox-ico-loading.gif\', 
341
        imageBtnPrev:     \''.$lightBoxBasePath.'/images/lightbox-btn-prev.gif\',    
342
        imageBtnNext:     \''.$lightBoxBasePath.'/images/lightbox-btn-next.gif\',   
343
        imageBtnClose:    \''.$lightBoxBasePath.'/images/lightbox-btn-close.gif\',  
344
        imageBlank:       \''.$lightBoxBasePath.'/images/lightbox-blank.gif\'
345
      });
346
    });
347
    ', 'inline');
348
}
349

    
350
function _add_js_footnotes(){
351
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
352
}
353

    
354

    
355
function _add_js_cluetip(){
356

    
357
	//TODO replace by http://www.socialembedded.com/labs/jQuery-Tooltip-Plugin/jQuery-Tooltip-Plugin.html
358
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
359
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
360
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
361
	drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
362
	drupal_add_js ("$(document).ready(function(){
363
      $('.cluetip').css({color: '#0062C2'}).cluetip({
364
        splitTitle: '|',
365
        showTitle: true,
366
        activation: 'hover',
367
        sicky: true,
368
        arrows: true,
369
        dropShadow: false,
370
        cluetipClass: 'rounded'
371
      });
372
    });", 'inline');
373
}
374

    
375
function _add_js_ahah(){
376
	drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/ahah-content.js');
377
}
(1-1/8)