Project

General

Profile

Download (17.3 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 LICENSE.TXT at the top of this package for the full license terms.
11
 */
12

    
13
function tagNameParts($name, $numOfNameTokens){
14
    
15
    $out = '<span class="name">';
16
    
17
    $token = strtok($name, " \n\t");
18
    $i = 0;
19
    $noSpace = true;
20
    while($token != false){
21
        if($i == $numOfNameTokens){
22
            $out .= '</span> <span class="authors">';
23
            $noSpace = true;
24
        }
25
        $out .= ($noSpace?'':' ').$token;
26
        $noSpace = false;
27
        $token = strtok(" \n\t");
28
        $i++;
29
    }
30
    return $out.'</span>';
31
}
32

    
33
/**
34
 * Renders the full name string (complete scientific name including the author team)
35
 *  
36
 * @param NameTO $nameTO the taxon name
37
 */
38
function theme_cdm_name($nameTO, $displayNomRef = true){
39
  
40
    //TODO: - take the different subtypes of eu.etaxonomy.cdm.model.name.TaxonNameBase into account?
41
    $class = 'name'; //($nameTO->secUuid ? 'taxon' : 'taxonname');  
42
  
43
    if($nameTO){
44
      if(!$nameTO->taggedName || !count($nameTO->taggedName)){
45
        $out .= '<span class="'.$class.'">'.$nameTO->fullname.'</span>';
46
      } else {
47
        $out .= '<span class="'.$class.'">'.cdm_taggedtext2html($nameTO->taggedName).'</span>';
48
      }
49
    } else {
50
      $out .= '<span class="error">Invalid NameTO</span>';
51
    }
52
    
53
        
54
    if($displayNomRef && $nameTO->nomenclaturalReference->citation){
55
      $out .= (str_beginsWith($nameTO->nomenclaturalReference->citation, 'in') ? '&nbsp;':',&nbsp;');
56
      $out .= theme('cdm_nomenclaturalReferenceSTO', $nameTO->nomenclaturalReference);
57
    }
58
    
59
    if($nameTO->status){
60
      $out .= ', '.cdm_dataportal_t($nameTO->status);
61
    }
62
    
63
    return $out;
64
}
65

    
66
/**
67
 * Renders the given TaxonTO. The $enclosingTag (if not set false)
68
 * will get the following class attributes:
69
 * - name
70
 * - accepted (only if $ptaxon is an accepted name)
71
 * 
72
 * @param TaxonTO $taxon
73
 * @param boolean $displayNomRef whether to display the nomenclatural reference
74
 * @param boolean $noSecundum defaults to false. If set to true the secundum part is omitted.
75
 * @param string $enclosingTag defaults to span.
76
 * @return string of XHTML
77
 * 
78
 * usage: taxon_detail, theme_ptname_link
79
 */
80
function theme_cdm_taxon($taxonTO, $displayNomRef = true, $noSecundum = true, $enclosingTag = 'span'){
81

    
82
    
83
    $refSecundum = false;
84
    if(!$noSecundum){  
85
      $ref_sec = cdm_ws_get(CDM_WS_REFERENCE ,$taxonTO->secUuid);
86
      if($ref_sec){
87
        $refSecundum = str_trunk($ref_sec->fullcitation, 40, '...');
88
      }
89
    }
90
    
91
    $out  = theme('cdm_name', $taxonTO->name, $displayNomRef);
92
    
93
	  $out .=($refSecundum ? '&nbsp;<span class="secundum">sec. '.$refSecundum.'</span>': '');
94

    
95
	  //TODO:   .$ptaxon->namePhrase; 
96
	  
97
    if($enclosingTag){
98
        $out = '<'.$enclosingTag.' class="taxon'.($taxonTO->isAccepted === true ? ' accepted':'').'">'.$out.'</'.$enclosingTag.'>';
99
    }
100

    
101
    return $out;    
102
}
103

    
104
/**
105
 * Renders a link to the taxon detail page for the given $taxon 
106
 *
107
 * @param TaxonTO $taxon
108
 */
109
function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = false){
110
    
111
    if($fragment){
112
        $fragment = '#'.$fragment;
113
    }
114

    
115
    if(!$taxon->isAccepted) { 
116
        $out = 'ERROR: theme_cdm_taxon_link() - taxon is not accepted';
117
    }
118
    
119
    $name_html = theme('cdm_taxon', $taxonTO, false, true, '');
120
    $out = l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), '', $fragment, FALSE, TRUE);
121
    
122
    if($showNomRef){
123
       $out .=' '.theme('cdm_nomRef', $taxonTO);
124
    }
125
	
126
	return $out;
127
}
128

    
129
function theme_cdm_related_taxon($taxonSTO, $reltype_uuid = '', $displayNomRef = true){
130
  
131
  $relsign = '';
132
  $name_prefix = '';
133
  $name_postfix = '';
134
  switch ($reltype_uuid){
135
    case UUID_HOMOTYPIC_SYNONYM_OF: 
136
      $relsign = '≡';
137
      break;
138
    case UUID_MISAPPLIED_NAME_FOR: 
139
    case UUID_INVALID_DESIGNATION_FOR:
140
      $relsign = '&ndash;'; // &ndash; &mdash; &minus;
141
      $name_prefix = '"';
142
      $name_postfix = '"';
143
      break;
144
    default : 
145
      $relsign = '=';
146
  }
147
  
148
  $out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix.theme('cdm_taxon',$taxonSTO, $displayNomRef).$name_postfix;
149
  return $out;
150
  
151
}
152

    
153
function theme_cdm_dynabox($label, $content_url, $theme, $enclosingtag = 'li'){
154
  $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
155
  $out .= '<li class="dynabox"><span class="label">'.$label.'</span>';
156
  $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>';
157
  return $out;
158
}
159

    
160
function theme_cdm_listof_taxa($taxonSTOs){
161
  
162
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
163
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
164
  
165
  $out = '<ul class="cdm_names" style="background-image: none;">';
166
  $currentSecRef = _cdm_dataportal_currentSecRef_array();
167
  foreach($taxonSTOs as $taxon){
168
    if($taxon->isAccepted && $taxon->secUuid == $currentSecRef['uuid']){
169
      $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
170
    } else {
171
      $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_taxon_link');
172
    }
173
  }
174
  $out .= '</ul>';
175
  return $out;
176
}
177

    
178
function theme_cdm_alternative_taxa($taxonSTOs){
179
  $out = '<ul class="cdm_names" style="background-image: none;">';
180
  foreach($taxonSTOs as $taxon){
181
    $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
182
  }
183
  $out .= '</ul>';
184
  return $out;
185
}
186

    
187

    
188
function theme_cdm_credits(){
189
  $secRef_array = _cdm_dataportal_currentSecRef_array();
190
  return '<span class="sec_reference_citation">'.$secRef_array['citation'].'</span>'
191
  .( $secRef_array['year'] ? ' <span class="year">'.$secRef_array['year'].'</span>' : '')
192
  .( $secRef_array['authorship'] ? '<div class="author">'.$secRef_array['authorship'].'</div>' : '');
193
}
194

    
195

    
196
function theme_cdm_fullreference($referenceTO){
197
  $out = $referenceTO->authorship;
198
  
199
  if($referenceTO->citation){
200
    $out .= ' '.$referenceTO->citation;
201
  }
202
  if($referenceTO->microReference){
203
    $out .= ' : '.$referenceTO->microReference;
204
  }
205
  if($referenceTO->year){
206
    $out .= '. '.$referenceTO->year;
207
  }
208
  
209
  return $out;
210
}
211

    
212
/**
213
 * Enter description here...
214
 *
215
 * @param unknown_type $referenceSTO a referenceSTO or referenceTO instance
216
 * @param unknown_type $cssClass
217
 * @param unknown_type $separator
218
 * @param unknown_type $enclosingTag
219
 * @return unknown
220
 */
221
function theme_cdm_nomenclaturalReferenceSTO($referenceSTO, $cssClass = '', $separator = '<br />' , $enclosingTag = 'li'){
222
  
223
  if(isset($referenceSTO->microReference)){
224
    // well it is a ReferenceTO
225
    $nomref_citation = theme('cdm_fullreference', $referenceSTO);
226
  } else {
227
    // it is ReferenceSTO
228
    $nomref_citation = $referenceSTO->citation; 
229
  }
230

    
231
  $module_path = drupal_get_path('module', 'cdm_dataportal');
232
  drupal_add_js($module_path.'/js/jquery_lightbox/js/jlightbox.uncompressed.js');
233
  drupal_add_css($module_path.'/js/jquery_lightbox/css/jlightbox.css', 'module', 'screen');
234
  
235
  if( count($referenceSTO->mediaURI) > 0 ){
236
    $attributes = array('rel'=>'lightbox[protologues]');
237
    $out = l($nomref_citation, $referenceSTO->mediaURI[0]->value, $attributes, NULL, NULL, TRUE);
238
    for($i = 1;  $i < count($referenceSTO->mediaURI); $i++) {
239
      $out .= l('', $referenceSTO->mediaURI[$i]->value, $attributes, NULL, NULL, TRUE);
240
    }
241
  } else {
242
    $out =  $nomref_citation;
243
  }
244
  return $out;  
245
}
246

    
247
function theme_cdm_taxon_page($taxonTO){
248
  $out = '';
249
  
250
  
251
  $out .= theme('cdm_homotypicSynonyms', $taxonTO->homotypicSynonyms, $taxonTO->typeDesignations, $taxonTO->nameTypeDesignations);
252
  
253
  foreach($taxonTO->heterotypicSynonymyGroups as $hs_group){
254
    $out .= theme('cdm_heterotypicSynonymyGroup', $hs_group);
255
  }
256
  
257
  $out .= theme('cdm_taxonRelations', $taxonTO->taxonRelations);
258
  
259
  return $out;
260
}
261

    
262
function theme_cdm_homotypicSynonyms($synonymRelationshipTOs, $specimenTypeDesignations = false, $nameTypeDesignations = false){
263
  
264
  $out = '';
265
  $out = '<ul class="homotypicSynonyms">';
266
  
267
  foreach($synonymRelationshipTOs as $synonym){
268
    $out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym->synoynm, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
269
  }
270
  if($specimenTypeDesignations){
271
    $out .= theme('cdm_typedesignations', $specimenTypeDesignations, $nameTypeDesignations);
272
  }
273
  
274
  $out .= '</ul>';
275
  return $out;
276
}
277

    
278
function theme_cdm_heterotypicSynonymyGroup($homotypicGroupTO){
279
  $out = '';  
280
  $out = '<ul class="heterotypicSynonymyGroup">';
281
  
282
  $is_first_entry = true;
283
  foreach($homotypicGroupTO->taxa as $taxonSTO){
284
    if($is_first_entry){
285
      $is_first_entry = false;
286
      // is first list entry
287
      $out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$taxonSTO, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
288
    } else {
289
      $out .= '<li class="synonym">'.theme('cdm_related_taxon',$taxonSTO, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
290
    }
291
  }
292
  
293
  if(isset($homotypicGroupTO->typeDesignations)){
294
    $out .= theme('cdm_typedesignations', $homotypicGroupTO->typeDesignations);
295
  }
296
  
297
  $out .= '</ul>';
298
  
299
  return $out;
300
}
301

    
302
/**
303
 * renders misapplied names and invalid designations. 
304
 * Both relation types are currently treated the same!
305
 *
306
 * @param unknown_type $TaxonRelationshipTOs
307
 * @return unknown
308
 */
309
function theme_cdm_taxonRelations($TaxonRelationshipTOs){
310
  
311
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
312
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.dimensions.js');
313
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
314
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
315

    
316
  drupal_add_js ("$(document).ready(function(){ 
317
      $('.cluetip').css({color: '#0062C2'}).cluetip({
318
        splitTitle: '|',
319
        showTitle: true,
320
        activation: 'hover',
321
        arrows: true,
322
        dropShadow: false,
323
        cluetipClass: 'rounded'
324
      });
325
    });", 'inline');
326
  
327
  // aggregate misapplied named having the same fullname:
328
  $misapplied = array();
329
  foreach($TaxonRelationshipTOs as $taxonRelation){
330
    if(true || $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
331
      
332
      $sensu_reference = cdm_ws_get(CDM_WS_REFERENCE ,$taxonRelation->secUuid);
333
      $name = $taxonRelation->name->fullname;
334
      if(!isset($misapplied[$name])){
335
        $misapplied[$name] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
336
      } else {
337
        $misapplied[$name] .= ';';
338
      }
339
      $misapplied[$name] .= '&nbsp;<span class="sensu cluetip no-print" title="|sensu '.theme('cdm_fullreference',$sensu_reference ).'|">sensu '
340
      .$sensu_reference->authorship.'</span>'
341
      .'<span class="reference only-print">sensu '.theme('cdm_fullreference',$sensu_reference ).'</span>'
342
      ;
343
    }
344
  }
345
  // generate output
346
  $out = '<ul class="misapplied">';
347
  foreach($misapplied as $misapplied_name){
348
    $out .= '<li class="synonym">'.$misapplied_name.'</li>';
349
  }
350
  $out .= '</ul>';
351
  return $out;
352
}
353

    
354

    
355
function theme_cdm_typedesignations($specimenTypeDesignations, $nameTypeDesignations = array()){
356
  
357
  $out = '<ul class="typeDesignations">';
358

    
359
  foreach($nameTypeDesignations as $ntd){
360
    $out .= '<li class="nameTypeDesignation"><span class="status">'.$ntd->status->value.'</span> - '.theme('cdm_name', $ntd->typeSpecies, false);
361
    $out .= theme('cdm_typedesignations', $ntd->typeSpecimens);
362
    $out .= '</li>';
363
  }    
364
  
365
  foreach($specimenTypeDesignations as $std){
366
    $out .= '<li class="specimenTypeDesignation">';
367
    $out .= '<span class="status">'.$std->status->value.'</span> - '.$std->typeSpecimen->specimenLabel;
368
    $out .= theme('cdm_specimen', $std->typeSpecimen);
369
    $out .= '</li>';
370
  }
371
  
372
  $out .= '</ul>';
373
  
374
  return $out;
375
}
376

    
377
function theme_cdm_specimen($specimen){
378
  
379
  // rights, 
380
  //$specimen->specimenLabel
381
  //$specimen->uuid
382
  
383
  // ---- jQuery ThickBox:
384
  // bug: thickbox.js line 237 .trigger("unload") -> event is not triggered
385
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox.js');
386
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox.css');
387
  
388
  // ---- jQuery jqModal:
389
  // untested ...
390
  //drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jqModal.js');
391
  //drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/jqModal.css');
392
  
393
  
394
  
395
  $out = '';
396
  if(is_array($specimen->mediaURI)){
397
    
398
    $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/external_link.gif';
399
    // thickbox has problems reading the first url parameter, so a litte hack is needed here:
400
    // adding a meningless patameter &tb_hack=1& ....
401
    $out .= '&nbsp;<a href="#TB_inline?tb_hack=1&width=300&amp;height=330&amp;inlineId=specimen_media_'.$specimen->uuid.'" class="thickbox">'
402
    .'<img src="'.$image_url.'" title="'.t('Show media').'" /></a>';
403
    
404
    $out .= '<div id="specimen_media_'.$specimen->uuid.'" class="tickbox_content"><table>';
405
    
406
    $media_row = '<tr class="media_data">';
407
    $meta_row = '<tr class="meta_data">';
408
    
409
    foreach($specimen->mediaURI as $uri){
410
      // get media uri conversion rules if the module is installed and activated
411
      if(module_exists('cdm_mediauri')){
412
        $muris = cdm_mediauri_mediaUri_conversion($uri->value);
413
      }
414
      if(isset($muris['preview'])){    
415
        
416
        $a_child = '<img src="'.$muris['preview']['uri'].'" '
417
          .($muris['preview']['size_x'] ? 'width="'.$muris['preview']['size_x'].'"' : '')
418
          .($muris['preview']['size_y'] ? 'width="'.$muris['preview']['size_y'].'"' : '')
419
          .'/>';
420
      } else {
421
        $a_child = '<img src="'.$image_url.'" />';
422
      }
423
      $webapp_access = '';
424
      $media_row .= '<td><a href="'.$uri->value.'" target="'.$uri->uuid.'">'.$a_child.'</a></td>';
425
      $meta_row .= '<td><span class="label">'.check_plain($specimen->specimenLabel).'</span>'.$webapp_access.'</td>';
426
    }
427
    $out .= $media_row.'</tr>';
428
    $out .= $meta_row.'</tr>';
429
    
430
    $out .= '</div></table>';
431
  }
432
  return $out;
433
}
434

    
435

    
436
function theme_cdm_search_results($resultPageSTO, $path, $parameters){
437
  
438
  drupal_set_title(t('Search Results'));
439
  
440
  $out = '';
441
  if(count($resultPageSTO->results) > 0){
442
    $out = theme('cdm_listof_taxa', $resultPageSTO->results);
443
    $out .= theme('cdm_pager', $resultPageSTO,  $path, $parameters);
444
  } else {
445
    $out = '<h4 calss="error">Sorry, no matching entries found.</h4>';
446
  }
447
  return $out;
448
}
449

    
450
function theme_cdm_pager(&$resultPageSTO, $path, $parameters, $neighbors = 2){
451
  $out = '';
452

    
453
  if ($resultPageSTO->totalPageCount > 1) {
454
    
455
    $viewportsize = $neighbors * 2 + 1; 
456
    
457

    
458
    $out .= '<div class="pager">';
459
    if($resultPageSTO->pageNumber > 1){
460
      $out .= theme('cdm_pager_link', t('« first'), 1,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
461
      $out .= theme('cdm_pager_link', t('‹ previous'), $resultPageSTO->pageNumber - 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-previous'));
462
    }
463
    
464
    if($resultPageSTO->totalPageCount <= $viewportsize || $resultPageSTO->pageNumber <= $neighbors){
465
      $first_number = 1;
466
    } else if($resultPageSTO->pageNumber >= $resultPageSTO->totalPageCount - $neighbors){
467
      $first_number = $resultPageSTO->totalPageCount - $viewportsize;
468
    } else {
469
      $first_number = $resultPageSTO->pageNumber - $neighbors;
470
    }
471
    
472
    if($first_number > 1){
473
      $out .= '<div class="pager-list-dots-left">...</div>';
474
    }
475
    for($i = $first_number; $i < $first_number + $viewportsize; $i++){
476
      $out .= theme('cdm_pager_link', $i, $i,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
477
    }
478
    if($i < $resultPageSTO->totalPageCount){
479
      $out .= '<div class="pager-list-dots-right">...</div>';
480
    }
481
    
482
    if($resultPageSTO->pageNumber < $resultPageSTO->totalPageCount){
483
      $out .= theme('cdm_pager_link', t('next ›'), $resultPageSTO->pageNumber + 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-next'));
484
      $out .= theme('cdm_pager_link', t('last »'), $resultPageSTO->totalPageCount, $resultPageSTO, $path, $parameters, array('class' => 'pager-last'));
485
    }
486
    $out .= '</div>';
487
  
488
    return $out;
489
  }
490
}
491

    
492
function theme_cdm_pager_link($text, $linkPageNumber, &$resultPageSTO, $path, $parameters = array(), $attributes) {
493
  
494
  $out = '';
495
  
496
  if ($linkPageNumber == $resultPageSTO->pageNumber) {
497
    $out = '<strong>'.$text.'</strong>';
498
  } else {
499
    // <a class="pager-next active" title="Go to page 3" href="/node?page=2">3</a>
500
    $parameters['page'] = $linkPageNumber;
501
    $out = l($text, $path, $attributes, compose_url_prameterstr($parameters));
502
  }
503
  
504

    
505
  return $out;
506
}
(6-6/9)