Project

General

Profile

Download (17.5 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 _add_js_thickbox(){
14
   // ---- jQuery ThickBox:
15
  /*
16
   * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
17
   * -> event is not triggered because of problems with compat-1.0.js'
18
   * see INSTALL.txt
19
   * 
20
   */
21
  
22
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox.js');
23
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_thickbox.css');
24
    
25
}
26

    
27
function tagNameParts($name, $numOfNameTokens){
28
    
29
    $out = '<span class="name">';
30
    
31
    $token = strtok($name, " \n\t");
32
    $i = 0;
33
    $noSpace = true;
34
    while($token != false){
35
        if($i == $numOfNameTokens){
36
            $out .= '</span> <span class="authors">';
37
            $noSpace = true;
38
        }
39
        $out .= ($noSpace?'':' ').$token;
40
        $noSpace = false;
41
        $token = strtok(" \n\t");
42
        $i++;
43
    }
44
    return $out.'</span>';
45
}
46

    
47
/**
48
 * Renders the full name string (complete scientific name including the author team)
49
 *  
50
 * @param NameTO $nameTO the taxon name
51
 */
52
function theme_cdm_name($nameTO, $displayNomRef = true){
53
  
54
    //TODO: - take the different subtypes of eu.etaxonomy.cdm.model.name.TaxonNameBase into account?
55
    $class = 'name'; //($nameTO->secUuid ? 'taxon' : 'taxonname');  
56
  
57
    if($nameTO){
58
      if(!$nameTO->taggedName || !count($nameTO->taggedName)){
59
        $out .= '<span class="'.$class.'">'.$nameTO->fullname.'</span>';
60
      } else {
61
        $out .= '<span class="'.$class.'">'.cdm_taggedtext2html($nameTO->taggedName).'</span>';
62
      }
63
    } else {
64
      $out .= '<span class="error">Invalid NameTO</span>';
65
    }
66
    
67
        
68
    if($displayNomRef && $nameTO->nomenclaturalReference->citation){
69
      $out .= (str_beginsWith($nameTO->nomenclaturalReference->citation, 'in') ? '&nbsp;':',&nbsp;');
70
      $out .= theme('cdm_nomenclaturalReferenceSTO', $nameTO->nomenclaturalReference);
71
    }
72
    
73
    if($nameTO->status){
74
      $out .= ', '.cdm_dataportal_t($nameTO->status);
75
    }
76
    
77
    return $out;
78
}
79

    
80
/**
81
 * Renders the given TaxonTO. The $enclosingTag (if not set false)
82
 * will get the following class attributes:
83
 * - name
84
 * - accepted (only if $ptaxon is an accepted name)
85
 * 
86
 * @param TaxonTO $taxon
87
 * @param boolean $displayNomRef whether to display the nomenclatural reference
88
 * @param boolean $noSecundum defaults to false. If set to true the secundum part is omitted.
89
 * @param string $enclosingTag defaults to span.
90
 * @return string of XHTML
91
 * 
92
 * usage: taxon_detail, theme_ptname_link
93
 */
94
function theme_cdm_taxon($taxonTO, $displayNomRef = true, $noSecundum = true, $enclosingTag = 'span'){
95

    
96
    
97
    $refSecundum = false;
98
    if(!$noSecundum){  
99
      $ref_sec = cdm_ws_get(CDM_WS_REFERENCE ,$taxonTO->secUuid);
100
      if($ref_sec){
101
        $refSecundum = str_trunk($ref_sec->fullcitation, 40, '...');
102
      }
103
    }
104
    
105
    $out  = theme('cdm_name', $taxonTO->name, $displayNomRef);
106
    
107
	  $out .=($refSecundum ? '&nbsp;<span class="secundum">sec. '.$refSecundum.'</span>': '');
108

    
109
	  //TODO:   .$ptaxon->namePhrase; 
110
	  
111
    if($enclosingTag){
112
        $out = '<'.$enclosingTag.' class="taxon'.($taxonTO->isAccepted === true ? ' accepted':'').'">'.$out.'</'.$enclosingTag.'>';
113
    }
114

    
115
    return $out;    
116
}
117

    
118
/**
119
 * Renders a link to the taxon detail page for the given $taxon 
120
 *
121
 * @param TaxonTO $taxon
122
 */
123
function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = false){
124
    
125
    if($fragment){
126
        $fragment = '#'.$fragment;
127
    }
128

    
129
    if(!$taxon->isAccepted) { 
130
        $out = 'ERROR: theme_cdm_taxon_link() - taxon is not accepted';
131
    }
132
    
133
    $name_html = theme('cdm_taxon', $taxonTO, false, true, '');
134
    $out = l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), '', $fragment, FALSE, TRUE);
135
    
136
    if($showNomRef){
137
       $out .=' '.theme('cdm_nomRef', $taxonTO);
138
    }
139
	
140
	return $out;
141
}
142

    
143
function theme_cdm_related_taxon($taxonSTO, $reltype_uuid = '', $displayNomRef = true){
144
  
145
  $relsign = '';
146
  $name_prefix = '';
147
  $name_postfix = '';
148
  switch ($reltype_uuid){
149
    case UUID_HOMOTYPIC_SYNONYM_OF: 
150
      $relsign = '≡';
151
      break;
152
    case UUID_MISAPPLIED_NAME_FOR: 
153
    case UUID_INVALID_DESIGNATION_FOR:
154
      $relsign = '&ndash;'; // &ndash; &mdash; &minus;
155
      $name_prefix = '"';
156
      $name_postfix = '"';
157
      break;
158
    default : 
159
      $relsign = '=';
160
  }
161
  
162
  $out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix.theme('cdm_taxon',$taxonSTO, $displayNomRef).$name_postfix;
163
  return $out;
164
  
165
}
166

    
167
function theme_cdm_dynabox($label, $content_url, $theme, $enclosingtag = 'li'){
168
  $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
169
  $out .= '<li class="dynabox"><span class="label">'.$label.'</span>';
170
  $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>';
171
  return $out;
172
}
173

    
174
function theme_cdm_listof_taxa($taxonSTOs){
175
  
176
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
177
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
178
  
179
  $out = '<ul class="cdm_names" style="background-image: none;">';
180
  $currentSecRef = _cdm_dataportal_currentSecRef_array();
181
  foreach($taxonSTOs as $taxon){
182
    if($taxon->isAccepted && $taxon->secUuid == $currentSecRef['uuid']){
183
      $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
184
    } else {
185
      $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_taxon_link');
186
    }
187
  }
188
  $out .= '</ul>';
189
  return $out;
190
}
191

    
192
function theme_cdm_alternative_taxa($taxonSTOs){
193
  $out = '<ul class="cdm_names" style="background-image: none;">';
194
  foreach($taxonSTOs as $taxon){
195
    $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
196
  }
197
  $out .= '</ul>';
198
  return $out;
199
}
200

    
201

    
202
function theme_cdm_credits(){
203
  $secRef_array = _cdm_dataportal_currentSecRef_array();
204
  return '<span class="sec_reference_citation">'.$secRef_array['citation'].'</span>'
205
  .( $secRef_array['year'] ? ' <span class="year">'.$secRef_array['year'].'</span>' : '')
206
  .( $secRef_array['authorship'] ? '<div class="author">'.$secRef_array['authorship'].'</div>' : '');
207
}
208

    
209

    
210
function theme_cdm_fullreference($referenceTO){
211
  $out = $referenceTO->authorship;
212
  
213
  if($referenceTO->citation){
214
    $out .= ' '.$referenceTO->citation;
215
  }
216
  if($referenceTO->microReference){
217
    $out .= ' : '.$referenceTO->microReference;
218
  }
219
  if($referenceTO->year){
220
    $out .= '. '.$referenceTO->year;
221
  }
222
  
223
  return $out;
224
}
225

    
226
/**
227
 * Enter description here...
228
 *
229
 * @param unknown_type $referenceSTO a referenceSTO or referenceTO instance
230
 * @param unknown_type $cssClass
231
 * @param unknown_type $separator
232
 * @param unknown_type $enclosingTag
233
 * @return unknown
234
 */
235
function theme_cdm_nomenclaturalReferenceSTO($referenceSTO, $cssClass = '', $separator = '<br />' , $enclosingTag = 'li'){
236
  
237
  if(isset($referenceSTO->microReference)){
238
    // well it is a ReferenceTO
239
    $nomref_citation = theme('cdm_fullreference', $referenceSTO);
240
  } else {
241
    // it is ReferenceSTO
242
    $nomref_citation = $referenceSTO->citation; 
243
  }
244

    
245
  _add_js_thickbox();
246
    
247
  if( count($referenceSTO->mediaURI) > 0 ){
248
    $attributes = array('class'=>'thickbox', 'rel'=>'protologues-'.$referenceSTO->uuid);
249
    $out = l($nomref_citation, $referenceSTO->mediaURI[0]->value, $attributes, NULL, NULL, TRUE);
250
    for($i = 1;  $i < count($referenceSTO->mediaURI); $i++) {
251
      $out .= l('', $referenceSTO->mediaURI[$i]->value, $attributes, NULL, NULL, TRUE);
252
    }
253
  } else {
254
    $out =  $nomref_citation;
255
  }
256
  return $out;  
257
}
258

    
259
function theme_cdm_taxon_page($taxonTO){
260
  $out = '';
261
  
262
  
263
  $out .= theme('cdm_homotypicSynonyms', $taxonTO->homotypicSynonyms, $taxonTO->typeDesignations, $taxonTO->nameTypeDesignations);
264
  
265
  foreach($taxonTO->heterotypicSynonymyGroups as $hs_group){
266
    $out .= theme('cdm_heterotypicSynonymyGroup', $hs_group);
267
  }
268
  
269
  $out .= theme('cdm_taxonRelations', $taxonTO->taxonRelations);
270
  
271
  return $out;
272
}
273

    
274
function theme_cdm_homotypicSynonyms($synonymRelationshipTOs, $specimenTypeDesignations = false, $nameTypeDesignations = false){
275
  
276
  $out = '';
277
  $out = '<ul class="homotypicSynonyms">';
278
  
279
  foreach($synonymRelationshipTOs as $synonym){
280
    $out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym->synoynm, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
281
  }
282
  if($specimenTypeDesignations){
283
    $out .= theme('cdm_typedesignations', $specimenTypeDesignations, $nameTypeDesignations);
284
  }
285
  
286
  $out .= '</ul>';
287
  return $out;
288
}
289

    
290
function theme_cdm_heterotypicSynonymyGroup($homotypicGroupTO){
291
  $out = '';  
292
  $out = '<ul class="heterotypicSynonymyGroup">';
293
  
294
  $is_first_entry = true;
295
  foreach($homotypicGroupTO->taxa as $taxonSTO){
296
    if($is_first_entry){
297
      $is_first_entry = false;
298
      // is first list entry
299
      $out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$taxonSTO, UUID_HETEROTYPIC_SYNONYM_OF).'</li>';
300
    } else {
301
      $out .= '<li class="synonym">'.theme('cdm_related_taxon',$taxonSTO, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
302
    }
303
  }
304
  
305
  if(isset($homotypicGroupTO->typeDesignations)){
306
    $out .= theme('cdm_typedesignations', $homotypicGroupTO->typeDesignations);
307
  }
308
  
309
  $out .= '</ul>';
310
  
311
  return $out;
312
}
313

    
314
/**
315
 * renders misapplied names and invalid designations. 
316
 * Both relation types are currently treated the same!
317
 *
318
 * @param unknown_type $TaxonRelationshipTOs
319
 * @return unknown
320
 */
321
function theme_cdm_taxonRelations($TaxonRelationshipTOs){
322
  
323
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
324
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
325
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
326
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
327

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

    
366

    
367
function theme_cdm_typedesignations($specimenTypeDesignations, $nameTypeDesignations = array()){
368
  
369
  $out = '<ul class="typeDesignations">';
370

    
371
  foreach($nameTypeDesignations as $ntd){
372
    $out .= '<li class="nameTypeDesignation"><span class="status">'.$ntd->status->value.'</span> - '.theme('cdm_name', $ntd->typeSpecies, false);
373
    $out .= theme('cdm_typedesignations', $ntd->typeSpecimens);
374
    $out .= '</li>';
375
  }    
376
  
377
  foreach($specimenTypeDesignations as $std){
378
    $out .= '<li class="specimenTypeDesignation">';
379
    $out .= '<span class="status">'.$std->status->value.'</span> - '.$std->typeSpecimen->specimenLabel;
380
    $out .= theme('cdm_specimen', $std->typeSpecimen);
381
    $out .= '</li>';
382
  }
383
  
384
  $out .= '</ul>';
385
  
386
  return $out;
387
}
388

    
389
function theme_cdm_specimen($specimen){
390
  
391
  // rights, 
392
  //$specimen->specimenLabel
393
  //$specimen->uuid
394
  
395
  _add_js_thickbox();
396
  
397
  $out = '';
398
  if(is_array($specimen->mediaURI)){
399
    
400
    $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/external_link.gif';
401
    // thickbox has problems reading the first url parameter, so a litte hack is needed here:
402
    // adding a meningless patameter &tb_hack=1& ....
403
    $out .= '&nbsp;<a href="#TB_inline?tb_hack=1&width=300&amp;height=330&amp;inlineId=specimen_media_'.$specimen->uuid.'" class="thickbox">'
404
    .'<img src="'.$image_url.'" title="'.t('Show media').'" /></a>';
405
    
406
    $out .= '<div id="specimen_media_'.$specimen->uuid.'" class="tickbox_content"><table>';
407
    
408
    $media_row = '<tr class="media_data">';
409
    $meta_row = '<tr class="meta_data">';
410
    
411
    foreach($specimen->mediaURI as $uri){
412
      
413
      // get media uri conversion rules if the module is installed and activated
414
      if(module_exists('cdm_mediauri')){
415
        $muris = cdm_mediauri_conversion($uri->value);
416
      }
417
      // --- handle media preview rules
418
      if(isset($muris['preview'])){    
419
        
420
        $a_child = '<img src="'.$muris['preview']['uri'].'" class="preview"'
421
          .($muris['preview']['size_x'] ? 'width="'.$muris['preview']['size_x'].'"' : '')
422
          .($muris['preview']['size_y'] ? 'width="'.$muris['preview']['size_y'].'"' : '')
423
          .'/>';
424
      } else {
425
        $a_child = '<img src="'.$image_url.'" />';
426
      }
427
      
428
      // --- handle web application rules
429
      $webapp = '';
430
      if(isset($muris['webapp'])){
431
        if($muris['webapp']['embed_html']){
432
          // embed in same page
433
          $webapp = $muris['webapp']['embed_html'];  
434
        } else {
435
          $webapp = l(t('web application'), $muris['webapp']['uri']);            
436
        }
437
      }
438
      $media_row .= '<td><a href="'.$uri->value.'" target="'.$uri->uuid.'">'.$a_child.'</a></td>';
439
      $meta_row .= '<td><span class="label">'.check_plain($specimen->specimenLabel).'</span><div class="webapp">'.$webapp.'</div></td>';
440
    }
441
    $out .= $media_row.'</tr>';
442
    $out .= $meta_row.'</tr>';
443
    
444
    $out .= '</div></table>';
445
  }
446
  return $out;
447
}
448

    
449

    
450
function theme_cdm_search_results($resultPageSTO, $path, $parameters){
451
  
452
  drupal_set_title(t('Search Results'));
453
  
454
  $out = '';
455
  if(count($resultPageSTO->results) > 0){
456
    $out = theme('cdm_listof_taxa', $resultPageSTO->results);
457
    $out .= theme('cdm_pager', $resultPageSTO,  $path, $parameters);
458
  } else {
459
    $out = '<h4 calss="error">Sorry, no matching entries found.</h4>';
460
  }
461
  return $out;
462
}
463

    
464
function theme_cdm_pager(&$resultPageSTO, $path, $parameters, $neighbors = 2){
465
  $out = '';
466

    
467
  if ($resultPageSTO->totalPageCount > 1) {
468
    
469
    $viewportsize = $neighbors * 2 + 1; 
470
    
471

    
472
    $out .= '<div class="pager">';
473
    if($resultPageSTO->pageNumber > 1){
474
      $out .= theme('cdm_pager_link', t('« first'), 1,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
475
      $out .= theme('cdm_pager_link', t('‹ previous'), $resultPageSTO->pageNumber - 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-previous'));
476
    }
477
    
478
    if($resultPageSTO->totalPageCount <= $viewportsize || $resultPageSTO->pageNumber <= $neighbors){
479
      $first_number = 1;
480
    } else if($resultPageSTO->pageNumber >= $resultPageSTO->totalPageCount - $neighbors){
481
      $first_number = $resultPageSTO->totalPageCount - $viewportsize;
482
    } else {
483
      $first_number = $resultPageSTO->pageNumber - $neighbors;
484
    }
485
    
486
    if($first_number > 1){
487
      $out .= '<div class="pager-list-dots-left">...</div>';
488
    }
489
    for($i = $first_number; $i < $first_number + $viewportsize; $i++){
490
      $out .= theme('cdm_pager_link', $i, $i,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
491
    }
492
    if($i < $resultPageSTO->totalPageCount){
493
      $out .= '<div class="pager-list-dots-right">...</div>';
494
    }
495
    
496
    if($resultPageSTO->pageNumber < $resultPageSTO->totalPageCount){
497
      $out .= theme('cdm_pager_link', t('next ›'), $resultPageSTO->pageNumber + 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-next'));
498
      $out .= theme('cdm_pager_link', t('last »'), $resultPageSTO->totalPageCount, $resultPageSTO, $path, $parameters, array('class' => 'pager-last'));
499
    }
500
    $out .= '</div>';
501
  
502
    return $out;
503
  }
504
}
505

    
506
function theme_cdm_pager_link($text, $linkPageNumber, &$resultPageSTO, $path, $parameters = array(), $attributes) {
507
  
508
  $out = '';
509
  
510
  if ($linkPageNumber == $resultPageSTO->pageNumber) {
511
    $out = '<strong>'.$text.'</strong>';
512
  } else {
513
    // <a class="pager-next active" title="Go to page 3" href="/node?page=2">3</a>
514
    $parameters['page'] = $linkPageNumber;
515
    $out = l($text, $path, $attributes, compose_url_prameterstr($parameters));
516
  }
517
  
518

    
519
  return $out;
520
}
(6-6/9)