Project

General

Profile

Download (52.9 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

    
10
function _add_js_thickbox(){
11
  // ---- jQuery thickbox:
12
  /*
13
  * bug: compat-1.0.js && thickbox.js line 237 .trigger("unload")
14
  * -> event is not triggered because of problems with compat-1.0.js'
15
  * see INSTALL.txt
16
  *
17
  */
18
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.imagetool.min.js');
19
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/thickbox.js');
20
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_thickbox.css');
21
}
22

    
23
/**
24
 * TODO if getting fragment from request is possible remove $_REQUEST['highlite'] HACK
25
 * NOT WORKING since fragments are not available to the server
26
 function fragment(){
27
 global $fragment;
28
 if(!$fragment){
29
 $fragment = substr($_SERVER['REQUEST_URI'], strrpos($_SERVER['REQUEST_URI'], '#'));
30
 }
31
 return $fragment;
32
 }
33
 */
34

    
35
function uuid_anchor($uuid, $innerHTML){
36
  $highlite = $_REQUEST['highlite'] == $uuid;
37
  return '<a name="'.$uuid.'" ></a><span class="'.($highlite ? 'highlite' : '').'">'.$innerHTML.'</span>';
38
}
39

    
40
/**
41
 * Enter description here...
42
 *
43
 * @param unknown_type $name
44
 * @param unknown_type $numOfNameTokens
45
 * @return unknown
46
 * @deprecated looks like this is not used anymore
47
 */
48
function tagNameParts($name, $numOfNameTokens){
49

    
50

    
51
  $out = '<span class="name">';
52

    
53
  $token = strtok($name, " \n\t");
54
  $i = 0;
55
  $noSpace = true;
56
  while($token != false){
57
    if($i == $numOfNameTokens){
58
      $out .= '</span> <span class="authors">';
59
      $noSpace = true;
60
    }
61
    $out .= ($noSpace?'':' ').$token;
62
    $noSpace = false;
63
    $token = strtok(" \n\t");
64
    $i++;
65
  }
66
  return $out.'</span>';
67
}
68

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

    
90
/**
91
 * Almost any cdmObject may be annotated. Therefore we provide a generic way to display
92
 * as well as create or update annotations.
93
 *
94
 * TODO it should be configurable which objects can be annotated as this might differ in dataportals
95
 *
96
 */
97
function theme_cdm_annotation($baseTO){
98
  if(!$baseTO->uuid){
99
    return;
100
  }else{
101

    
102

    
103
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
104
    drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
105

    
106
    $annotatableUuid = $baseTO->uuid;
107
    $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($annotatableUuid));
108

    
109
    $annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_content');
110

    
111
    $out = ' <span class="annotation">';
112
    $out .= '<span class="annotation_toggle" rel="'.$annotationProxyUrl.'">+</span>';
113
     
114

    
115
    $out .= '<div class="annotation_box"></div>';
116
    $out .= '</span>';
117

    
118
    return $out;
119

    
120
  }
121
}
122

    
123
function theme_cdm_annotation_content($AnnotationTO){
124

    
125

    
126
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_annotations.js');
127
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.form.js');
128

    
129

    
130
  $out .= theme('cdm_list_of_annotations', $AnnotationTO->annotationElements);
131

    
132
  $annotationUrl = cdm_compose_url(CDM_WS_ANNOTATIONS, array($AnnotationTO->uuid));
133
  $annotationProxyUrl = url('cdm_api/proxy/'. urlencode($annotationUrl).'/cdm_annotation_post');
134

    
135
  // TODO users have to be authenticated to the dataportal to be able to write annotations
136
  $out .= '
137
  			<div class="annotation_create">
138
  				<form action="'.$annotationProxyUrl.'" method="POST">
139
  					<textarea name="annotation"></textarea>
140
  					<input type="hidden" name="commentator" value="">
141
  					<input type="submit" value="'.t('Save annotation').'" />
142
  				</form>
143
 			</div>
144
	';
145

    
146
  return $out;
147
}
148

    
149
function theme_cdm_list_of_annotations($annotationElements){
150

    
151
  $out = '<ul class="annotation_list">';
152

    
153
  foreach ($annotationElements as $key => $row){
154
    $created[$key] = $row;
155
  }
156
  array_multisort($created, SORT_ASC, $annotationElements);
157

    
158
  foreach ($annotationElements as $annotation){
159
    $out .= '<li>' . $annotation->text . '</li>';
160
  }
161

    
162
  $out .= '</ul>';
163

    
164
  return $out;
165

    
166
}
167

    
168
/**
169
 * Renders the full name string (complete scientific name including the author team)
170
 *
171
 * @param NameTO $nameTO the taxon name
172
 * @param $displayNomRef values are 'LINK', 'PLAIN', 'HIDE' = FALSE
173
 */
174
function theme_cdm_name($nameTO, $displayAuthor = true, $displayNomRef = true, $displayStatus = true, $displayDescription = true, $nomRefLink = true){
175

    
176
  if(!$nameTO){
177
    return '<span class="error">Invalid $nameTO in theme_cdm_name()</span>';
178
  }
179

    
180
  /* TODO: - take the different sub types of eu.etaxonomy.cdm.model.name.TaxonNameBase into account?
181
   *
182
   * Use class names from objects?, additional field in DTO?
183
   * Preliminary using default value, which can be set in module settings:
184
   * values correspond with eu.etaxonomy.cdm.model.name.*: 'ZoologicalName', 'ViralName', 'BotanicalName'
185
   */
186
  $taxonname_type = (variable_get('cdm_taxonname_type', 'BotanicalName'));
187
  $class = 'taxonname taxonname_'.strtolower($taxonname_type);
188
  
189
  $hasNomRef = $nameTO->nomenclaturalReference->fullCitation;
190
   
191
  if(!$nameTO->taggedName || !count($nameTO->taggedName)){
192
    $out .= '<span class="'.$class.'">'.$nameTO->fullname.'</span>';
193
  } else {
194
    $skip = $hasNomRef ? array('reference') : array();
195
    if(!$displayAuthor || $taxonname_type == 'ZoologicalName') {
196
      $skip[] = 'authors';
197
    }
198
    $out .= '<span class="'.$class.'">'.theme('cdm_taggedtext2html', $nameTO->taggedName, 'span', ' ', $skip).'</span>';
199
  }
200
  
201
  if($displayNomRef && $hasNomRef){
202
    $out .= '<span class="reference">';
203
    $out .= theme('cdm_nomenclaturalReferenceSTO', $nameTO->nomenclaturalReference, $nomRefLink);
204
    $out .= '</span>';
205
  }
206

    
207
  if($displayStatus){
208
    if(isset($nameTO->status[0])){
209
      foreach($nameTO->status as $key => $status){
210
        $out .= ', '.$status->term;
211
      }
212
    }
213
  }
214

    
215
  // render protologues etc...
216
  if($displayDescription && !empty($nameTO->descriptions)){
217
    foreach($nameTO->descriptions as $DescriptionTO){
218
    		if(!empty($DescriptionTO)){
219
    		  foreach($DescriptionTO->elements as $DescriptionElementSTO){
220
    		    $out .= theme("cdm_media", $DescriptionElementSTO, array('application/pdf', 'image/png', 'image/jpeg', 'image/gif', 'text/html'));
221
    		  }
222
    		}
223
    }
224
  }
225

    
226
  // testing annotations for taxon names
227
  //$out .= theme('cdm_annotation', $nameTO);
228

    
229
  return $out;
230
}
231

    
232
function theme_cdm_media($DescriptionElementSTO, $mimeTypePreference){
233
  $out = "";
234

    
235
  _add_js_thickbox();
236

    
237
  $uuid = $DescriptionElementSTO->uuid;
238
  $type = $DescriptionElementSTO->mediaType;
239
  $medias = $DescriptionElementSTO->media;
240

    
241
  foreach($medias as $media){
242
     
243
    $prefRepresentations = cdm_preferred_media_representations($media, $mimeTypePreference, 300, 400);
244
    $representation_inline = array_shift($prefRepresentations);
245
    if($representation_inline) {
246

    
247
      $contentTypeDirectory = substr($representation_inline->mimeType, 0, stripos($representation_inline->mimeType, '/'));
248

    
249
      $out = theme('cdm_media_mime_' . $contentTypeDirectory,  $representation_inline, $type);
250

    
251
      //			$attributes = array('class'=>'thickbox', 'rel'=>'descriptionElement-'.$uuid, 'title'=>$type->term);
252
      //		    for($i = 0; $part = $representation_inline->representationParts[$i]; $i++){
253
      //		    	if($i == 0){
254
      //		    	    $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$type->term.'-media.png';
255
      //		    	    $media = '<img src="'.$image_url.'" height="14px" alt="'.$type->term.'" />';
256
      //		    	    $out .= l($media, $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
257
      //		    	} else {
258
      //		    		$out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
259
      //		    	}
260
      //		  	}
261
    } else {
262
      // no media available, so display just the type term
263
      $out .=  $type->term;
264
    }
265
  }
266
  return $out;
267

    
268
}
269

    
270
function theme_cdm_mediaTypeTerm($type){
271
  $icon_url = drupal_get_path('module', 'cdm_dataportal').'/images/'.$type->term.'-media.png';
272
  return '<img src="'.$icon_url.'" height="14px" alt="'.$type->term.'" />';
273
}
274

    
275
function theme_cdm_media_mime_application($representation, $type){
276

    
277
  foreach($representation->representationParts as $part){
278
    $attributes = array('title'=>$type->term, 'target'=>'_blank');
279
    $out .= l(theme('cdm_mediaTypeTerm', $type), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
280
  }
281
  return $out;
282
}
283

    
284
function theme_cdm_media_mime_image($representation, $type){
285
  $out = '';
286
  $attributes = array('class'=>'thickbox', 'rel'=>'representation-'.$representation->uuid, 'title'=>$type->term);
287
  for($i = 0; $part = $representation->representationParts[$i]; $i++){
288
    if($i == 0){
289
       
290
      $out .= l(theme('cdm_mediaTypeTerm', $type), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
291
    } else {
292
    		$out .= l('', $part->uri, $attributes, NULL, NULL, TRUE);
293
    }
294
  }
295
  return $out;
296
}
297

    
298
function theme_cdm_media_mime_text($representation, $type){
299

    
300
  foreach($representation->representationParts as $part){
301
    $attributes = array('title'=>$type->term . t(' link will open in a new window'), 'target'=>'_blank');
302
    $out .= l(theme('cdm_mediaTypeTerm', $type), $part->uri, $attributes, NULL, NULL, TRUE, TRUE);
303
  }
304
  return $out;
305
}
306

    
307
/**
308
 * TODO
309
 * Quick-and-dirty solution to show distribution service to exemplar groups
310
 *
311
 * @param unknown_type $featureTo
312
 * @return unknown
313
 */
314
function theme_cdm_descriptionElement_distribution($featureTo){
315

    
316
  $server = variable_get('cdm_dataportal_geoservice_access_point', false);
317

    
318
  if(!server){
319
    return "<p>No geoservice specified</p>";
320
  }else{
321
    $map_data_parameters = '?' . $featureTo->externalResources->geoServiceParameters;
322

    
323
    $display_width = variable_get('cdm_dataportal_geoservice_display_width', false);
324
    $bounding_box = variable_get('cdm_dataportal_geoservice_bounding_box', false);
325
    $labels_on = variable_get('cdm_dataportal_geoservice_labels_on', 0);
326

    
327
    $query_string = ($display_width ? '&ms=' . $display_width: '')
328
      . ($bounding_box ? '&bbox=' .  $bounding_box : '')
329
      . ($labels_on ? '&labels=' .  $labels_on : '');
330

    
331
    $out .= '<img style="border: 1px solid #ddd" src="'.url($server.$map_data_parameters, $query_string).'" alt="Distribution Map" />';
332

    
333
    return $out;
334
  }
335
}
336

    
337
/**
338
 * Renders the given TaxonTO. The $enclosingTag (if not set false)
339
 * will get the following class attributes:
340
 * - name
341
 * - accepted (only if $ptaxon is an accepted name)
342
 *
343
 * @param TaxonTO $taxon
344
 * @param boolean $displayNomRef whether to display the nomenclatural reference
345
 * @param boolean $noSecundum defaults to false. If set to true the secundum part is omitted.
346
 * @param string $enclosingTag defaults to span.
347
 * @return string of XHTML
348
 *
349
 * usage: taxon_detail, theme_ptname_link
350
 */
351
function theme_cdm_taxon($taxonTO, $displayNomRef = true, $displayStatus = true, $displayDescription = true, $noSecundum = true, $enclosingTag = 'span', $uuidAnchor = TRUE, $nomRefLink = true){
352

    
353
  $refSecundum = false;
354
  if(!$noSecundum){
355
    $ref_sec = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE ,$taxonTO->secUuid);
356
    if($ref_sec){
357
      $refSecundum = str_trunk($ref_sec->fullCitation, 40, '...');
358
    }
359
  }
360
  $out  = theme('cdm_name', $taxonTO->name, true, $displayNomRef, $displayStatus, $displayDescription, $nomRefLink);
361
  // append secundum information
362
  $out .=($refSecundum ? '&nbsp;<span class="secundum">sec. '.$refSecundum.'</span>' : '');
363
  // add uuid anchor
364
  if($uuidAnchor === TRUE){
365
    $out = uuid_anchor($taxonTO->uuid, $out);
366
  }
367
  //TODO:   .$ptaxon->namePhrase;
368
  if($enclosingTag){
369
    $out = '<'.$enclosingTag.' class="taxon'.($taxonTO->accepted === true ? ' accepted':'').'">'.$out.'</'.$enclosingTag.'>';
370
  }
371

    
372
  return $out;
373
}
374

    
375
/**
376
 * Renders a link to the taxon detail page for the given $taxon
377
 *
378
 * @param TaxonTO $taxon
379
 */
380
function theme_cdm_taxon_link($taxonTO, $fragment = NULL, $showNomRef = true, $nomRefLink = true){
381

    
382
  if($fragment){
383
    $fragment = '#'.$fragment;
384
  }
385

    
386
  if(!$taxon->accepted) {
387
    $out = 'ERROR: theme_cdm_taxon_link() - taxon is not accepted';
388
  }
389

    
390
   if($showNomRef && $nomRefLink){
391
     // name part as link and reference part as link
392
     $name_html = theme('cdm_taxon', $taxonTO, FALSE /*$showNomRef*/, true, false, true, '', FALSE);
393
     $out = l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), null, $fragment, FALSE, TRUE);
394
     $out .= theme('cdm_nomenclaturalReferenceSTO', $taxonTO->name->nomenclaturalReference);
395
   } else {
396
     // fullname as link
397
     $name_html = theme('cdm_taxon', $taxonTO, $showNomRef, true, false, true, '', FALSE, $nomRefLink);
398
     $out = l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), null, $fragment, FALSE, TRUE);
399
   }
400
  
401
  return $out;
402
}
403

    
404
/**
405
 * Renders a link to the misapplied taxon detail page for the given $taxon
406
 *
407
 * @param TaxonTO $taxon
408
 */
409
function theme_cdm_taxon_misapplied_link($taxonTO, $fragment = NULL, $showNomRef = true){
410

    
411
  if($fragment){
412
    $fragment = '#'.$fragment;
413
  }
414

    
415
  if(!$taxon->accepted) {
416
    $out = 'ERROR: theme_cdm_taxon_link() - taxon is not accepted';
417
  }
418

    
419
  $name_html = theme('cdm_taxon', $taxonTO, $showNomRef, true, false, true, '', FALSE);
420
  $out = '"';
421
  $out .= l($name_html, cdm_dataportal_taxon_path($taxonTO->uuid), array('class'=>'accepted'), null, $fragment, FALSE, TRUE);
422
  $out .= '"';
423

    
424
  /*
425
   if($showNomRef){
426
   $out .= theme('cdm_nomenclaturalReferenceSTO', $taxonTO->name->nomenclaturalReference);
427
   }
428
   */
429
  return $out;
430
}
431

    
432

    
433
/**
434
 * Renders a link to the taxon detail page for the given $taxon
435
 *
436
 * @param TaxonTO $taxon
437
 */
438
function theme_cdm_synonym_link($taxonTO, $accepted_uuid, $showNomRef = true, $showStatus = true){
439

    
440
  $name_html = theme('cdm_taxon', $taxonTO, $showNomRef, $showStatus, false, true, '', FALSE);
441
  $out = l($name_html, cdm_dataportal_taxon_path($accepted_uuid), array('class'=>'synonym'), 'highlite='.$taxonTO->uuid.'&acceptedFor='.$taxonTO->uuid, NULL, FALSE, TRUE);
442

    
443
  /*
444
   if($showNomRef){
445
   $out .= theme('cdm_nomenclaturalReferenceSTO', $taxonTO->name->nomenclaturalReference);
446
   }
447

    
448
   if($showStatus){
449
   $out .= theme('cdm_nomenclaturalStatusSTO', $taxonTO->name->status, "nomStatus");
450
   }*/
451

    
452
  return $out;
453
}
454

    
455

    
456
function theme_cdm_related_taxon($taxonSTO, $reltype_uuid = '', $displayNomRef = true){
457

    
458
  $relsign = '';
459
  $name_prefix = '';
460
  $name_postfix = '';
461
  switch ($reltype_uuid){
462
    case UUID_HETEROTYPIC_SYNONYM_OF:
463
    case UUID_SYNONYM_OF:
464
      $relsign = '=';
465
      break;
466
    case UUID_HOMOTYPIC_SYNONYM_OF:
467
      $relsign = '≡';
468
      break;
469
    case UUID_MISAPPLIED_NAME_FOR:
470
    case UUID_INVALID_DESIGNATION_FOR:
471
      $relsign = '&ndash;'; // &ndash; &mdash; &minus;
472
      $name_prefix = '"';
473
      $name_postfix = '"';
474
      break;
475
    default :
476
      $relsign = '&ndash;';
477
  }
478

    
479
  $out = '<span class="relation_sign">'.$relsign.'</span>'.$name_prefix.theme('cdm_taxon',$taxonSTO, $displayNomRef).$name_postfix;
480
  return $out;
481

    
482
}
483

    
484

    
485
function theme_select_secuuid($element) {
486

    
487
  $default_uuid = variable_get($element['#varname'], false);
488

    
489
  $tree = cdm_taxontree_build_tree(null, false); // get root nodes
490
  $secUuids = array();
491
  foreach($tree as $node){
492
    $secUuids[] = $node->secUuid;
493
  }
494
  cdm_api_secref_cache_prefetch($secUuids);
495

    
496
  theme('cdm_taxontree_add_scripts');
497
  drupal_add_js('$(document).ready(function() {$(\'ul.cdm_taxontree\').cdm_taxontree(
498
  {
499
    widget:                 true,
500
    element_name:           \''.$element['#varname'].'\',  //
501
    multiselect:            '.($element['#multiple']?'true':'false').',         //
502
  }
503
  );});', 'inline');
504

    
505
  $out  = '<div class="cdm_taxontree_widget">';
506
  $out .= '<div class="taxontree">'.theme('cdm_taxontree', $tree, NULL, FALSE, 'cdm_taxontree_node_reference').'</div>';
507
  $out .= $element['#children'].'<div style="clear: both;" /></div>';
508

    
509
  return theme(
510
    'form_element',
511
  array(
512
      '#title' => $element['#title'],
513
      '#description' => $element['#description'],
514
      '#id' => $element['#id'],
515
      '#required' => $element['#required'],
516
      '#error' => $element['#error'],
517
  ),
518
  $out
519
  );
520
}
521

    
522
function theme_cdm_dynabox($label, $content_url, $theme, $enclosingtag = 'li'){
523
  $cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
524
  $out .= '<li class="dynabox"><span class="label" alt="'.t('Click for accepted taxon').'">'.$label.'</span>';
525
  $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>';
526
  return $out;
527
}
528

    
529
function theme_cdm_list_of_taxa($taxonSTOs){
530

    
531
  $out = '<ul class="cdm_names" style="background-image: none;">';
532

    
533
  $synonym_uuids = array();
534
  foreach($taxonSTOs as $taxon){
535
    if(!_cdm_dataportal_acceptedByCurrentView($taxon)){
536
      if(!array_key_exists($taxon->uuid, $synonym_uuids)){
537
        $synonym_uuids[$taxon->uuid] = $taxon->uuid;
538
      }
539
    }
540
  }
541
  $table_of_accepted = cdm_ws_get(CDM_WS_ACCEPTED_TAXON, join(',', $synonym_uuids));
542

    
543
  foreach($taxonSTOs as $taxon){
544
    if(_cdm_dataportal_acceptedByCurrentView($taxon)){
545
      $out .= '<li>'.theme('cdm_taxon_link', $taxon, /*$fragment*/ NULL, /*$showNomRef*/ true, /*$nomRefLink*/ false ).'</li>';
546
    } else {
547
      $uuid = $taxon->uuid;
548
      $acceptedTaxa = $table_of_accepted->$uuid;
549
      if(count($acceptedTaxa) == 1){
550
        $out .= '<li>'.theme('cdm_synonym_link', $taxon, $acceptedTaxa[0]->uuid ).'</li>';
551
      } else {
552
        //TODO avoid using AHAH ion the cdm_dynabox
553
        $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_list_of_taxa');
554
      }
555
    }
556
  }
557
  $out .= '</ul>';
558
  return $out;
559

    
560

    
561

    
562
  /*
563
   //  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cdm_dynabox.js');
564
   //  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/cdm_dataportal.css');
565
   //
566
   $out = '<ul class="cdm_names" style="background-image: none;">';
567

    
568
   //get all accepted for synonyms in one blow to reduce overhead
569
   /* disabled! Not implemented in cdmlib-remote. Did someone forget
570
   * to commit???
571
   $synonym_uuids = array();
572
   foreach($taxonSTOs as $taxon){
573
   if(!_cdm_dataportal_acceptedByCurrentView($taxon)){
574
   if(!array_key_exists($taxon->uuid, $synonym_uuids)){
575
   $synonym_uuids[$taxon->uuid] = $taxon->uuid;
576
   }
577
   }
578
   }
579
   $table_of_accepted = cdm_ws_get(CDM_WS_ACCEPTED_TAXON, join(',', $synonym_uuids));
580
   */
581
  /*
582
   // get the secUuid of the actual taxonomy.
583
   // TODO: this is not generic and can be applied if there is one taxonomy only
584
   $root = cdm_ws_get(CDM_WS_TREENODE_ROOT);
585
   $rootSecUuid = $root[0]->secUuid;
586

    
587
   // RUDE HACK: group misappliedNames by filtering identical names but differing secUuids.
588
   $misapplied = array();
589
   foreach($taxonSTOs as $taxon){
590
   if($taxon->secUuid != $rootSecUuid){
591
   // is misapplied name
592
   if(! in_array($taxon->name->uuid, $misapplied)){
593
   $misapplied[$taxon->name->uuid]['printed'] = 0;
594
   }
595
   }
596
   }
597

    
598
   foreach($taxonSTOs as $taxon){
599
   if(_cdm_dataportal_acceptedByCurrentView($taxon)){
600

    
601
   if($taxon->secUuid == $rootSecUuid){
602
   $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
603
   }
604
   else if(! $misapplied[$taxon->name->uuid]['printed']){
605
   // RUDE HACK for misapplied names, paging not correct with this
606
   $out .= '<li>'.theme('cdm_taxon_misapplied_link', $taxon).'</li>';
607
   $misapplied[$taxon->name->uuid]['printed'] = 1;
608

    
609
   }
610
   }
611
   else {
612
   // get accepted taxa for this taxon
613
   $table_of_accepted = cdm_ws_get(CDM_WS_ACCEPTED_TAXON, $taxon->uuid);
614
   if(count($table_of_accepted) == 1){
615
   $out .= '<li>'.theme('cdm_synonym_link', $taxon, $table_of_accepted[0]->uuid ).'<li>';
616
   }
617
   else {
618
   //TODO avoid using AHAH ion the cdm_dynabox
619
   $out .= theme('cdm_dynabox', theme('cdm_name', $taxon->name), cdm_compose_url(CDM_WS_ACCEPTED_TAXON, array($taxon->uuid)), 'cdm_list_of_taxa');
620
   }
621
   }
622
   }
623
   $out .= '</ul>';
624
   return $out;*/
625
}
626

    
627
function theme_cdm_alternative_taxa($taxonSTOs){
628
  $out = '<ul class="cdm_names" style="background-image: none;">';
629
  foreach($taxonSTOs as $taxon){
630
    $out .= '<li>'.theme('cdm_taxon_link', $taxon).'</li>';
631
  }
632
  $out .= '</ul>';
633
  return $out;
634
}
635

    
636

    
637
function theme_cdm_credits(){
638
  $secRef_array = _cdm_dataportal_currentSecRef_array();
639
  return '<span class="sec_reference_citation">'.$secRef_array['citation'].'</span>'
640
  .( $secRef_array['year'] ? ' <span class="year">'.$secRef_array['year'].'</span>' : '')
641
  .( $secRef_array['authorship'] ? '<div class="author">'.$secRef_array['authorship'].'</div>' : '');
642
}
643

    
644

    
645
function theme_cdm_fullreference($referenceTO, $link = FALSE){
646

    
647
  if($referenceTO->fullCitation){
648
    $out = $referenceTO->fullCitation;
649
  }else{
650
    $out = $referenceTO->authorship;
651
  }
652
  if($referenceTO->microReference){
653
    $out .= ' : '.$referenceTO->microReference;
654
  }
655
  /*
656
   if($referenceTO->year){
657
   $out .= '. '.$referenceTO->year;
658
   }
659
   */
660
  
661
  if($link){
662
   $out = l($out, "/cdm_dataportal/reference/".$referenceTO->uuid, array("class"=>"reference"));
663
  }
664
  return $out;
665
}
666

    
667
/**
668
 * Enter description here...
669
 *
670
 * @param unknown_type $referenceSTO a referenceSTO or referenceTO instance
671
 * @param unknown_type $cssClass
672
 * @param unknown_type $separator
673
 * @param unknown_type $enclosingTag
674
 * @return unknown
675
 */
676
function theme_cdm_nomenclaturalReferenceSTO($referenceSTO, $doLink = FALSE, $cssClass = '', $separator = '<br />' , $enclosingTag = 'li'){
677

    
678
  if(isset($referenceSTO->microReference)){
679
    // it is a ReferenceTO
680
    $nomref_citation = theme('cdm_fullreference', $referenceSTO);
681
  } else {
682
    // it is ReferenceSTO
683
    $nomref_citation = $referenceSTO->fullCitation;
684
  }
685
  
686
  $is_IN_reference = str_beginsWith($nomref_citation, 'in');
687

    
688
  if($doLink){
689
    $nomref_citation = l($nomref_citation, "/cdm_dataportal/reference/".$referenceSTO->uuid, array(), NULL, NULL, FALSE, TRUE);
690
  }
691
  
692
  if(!empty($nomref_citation)){
693
    $nomref_citation = ($is_IN_reference ? '&nbsp;':',&nbsp;') . $nomref_citation;
694
  }
695
  
696
  return $nomref_citation;
697
}
698

    
699
/**
700
 * Enter description here...
701
 *
702
 * @param unknown_type $statusSTO
703
 * @param unknown_type $cssClass
704
 * @param unknown_type $enclosingTag
705
 * @return unknown
706
 */
707
function theme_cdm_nomenclaturalStatusSTO($statusSTO, $cssClass = '', $enclosingTag = 'span'){
708

    
709
  $out = "<$enclosingTag" . ($cssClass == '' ? '' : ' class="' . $cssClass . '"') . ">";
710
  foreach ($statusSTO as $status){
711
    $out .= ", " . $status->term;
712
  }
713
  $out .= "</$enclosingTag>";
714

    
715
  return $out;
716
}
717

    
718
/**
719
 * default title for a taxon page
720
 *
721
 * @param NameTO $nameTO
722
 * @return the formatted taxon name
723
 */
724
function theme_cdm_taxon_page_title($nameTO){
725
  
726
  if(variable_get('cdm_dataportal_nomref_in_title', 1)){
727
    // taxon name only with author and year
728
    return theme('cdm_name', $nameTO, TRUE, false, false, false);
729
  } else {
730
    return theme('cdm_name', $nameTO);
731
  }
732
}
733

    
734
/**
735
 * Allows theaming of the taxon page tabs
736
 * 
737
 * @param $tabname
738
 * @return unknown_type
739
 */
740
function theme_cdm_taxonpage_tab($tabname){
741
  switch($tabname){
742
    default: return t($tabname); 
743
  }
744
}
745

    
746
function theme_cdm_acceptedFor(){
747
  $out = '';
748
  
749
  if(isset($_REQUEST['acceptedFor'])){
750
     
751
     $synonym = cdm_ws_get(CDM_WS_TAXON, $_REQUEST['acceptedFor']);
752
     
753
     if($synonym){
754
       $out .= '<span class="acceptedFor">';
755
       $out .= t('is accepted for ');
756
       $out .= theme('cdm_name', $synonym->name, TRUE, FALSE, FALSE, FALSE);
757
       $out .= '</span>';
758
     }
759
  }
760
  
761
  return $out;
762
}
763

    
764
function theme_cdm_back_to_search_result_button(){
765
  $out = '';
766
  
767
  //$out = '<div style="display:none">'.print_r($_SESSION).'</div>';
768
  if($_SESSION['cdm']['search']){
769
    $out .= '<div id="backButton">'.l(t('Back to search result'), "http://" . $_SERVER['SERVER_NAME'] . $_SESSION['cdm']['last_search'] ).'</div>';
770
  }
771
  return $out;
772
}
773

    
774
/**
775
 * A wrapper function that groups available information to show by default, when
776
 * a taxon page is requested by the browser.
777
 * Individual themeing has to decide what this page should include (see methods beneath)
778
 * and what information should go into tabs or should not be shown at all.
779
 *
780
 * It is headed by the name of the accepted taxon without author and reference.
781
 * @param $taxonTO the taxon object
782
 * @param $page_part name of the part to display,
783
 *         valid values are: 'description', 'images', 'synonymy', 'all'
784
 */
785
function theme_cdm_taxon_page_general($taxonTO, $page_part) {
786
  
787
  if(!$page_part){
788
    $page_part = 'description';
789
  }
790
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
791

    
792
  $out = '';
793
  $out .= theme('cdm_back_to_search_result_button');
794
  $out .= theme('cdm_acceptedFor');
795
  
796
  if($page_part == 'description' || $page_part == 'all'){
797
    $out .= '<div id="general">';
798
    $out .= theme('cdm_taxon_page_description', $taxonTO);
799
    $out .= '</div>';
800
  }
801
  
802
  if($page_part == 'images' || $page_part == 'all'){
803
    $out .= '<div id="images">';
804
    if($page_part == 'all'){
805
      $out .= '<h2>'.t('Images').'</h2>';
806
    }
807
    $out .= theme('cdm_taxon_page_images', $taxonTO);
808
    $out .= '</div>';
809
  }
810

    
811
  if($page_part == 'synonymy' || $page_part == 'all'){
812
    $out .= '<div id="synonymy">';
813
    if($page_part == 'all'){
814
      $out .= '<h2>'.t('Synonymy').'</h2>';
815
    }
816
    if(!variable_get('cdm_dataportal_nomref_in_title', 1)){
817
      $out .= theme('cdm_name', $taxonTO->name);
818
    }
819
    $out .= theme('cdm_taxon_page_synonymy', $taxonTO);
820

    
821
    if(variable_get('cdm_dataportal_display_name_relations', 1)){
822
      $out .= theme('cdm_nameRelations', $taxonTO->name->nameRelations);
823
     }
824
    $out .= '</div>';
825
  }
826

    
827
  return $out;
828
}
829

    
830
/**
831
 * Outputs all descriptive data and shows the preferred picture of the
832
 * accepted taxon.
833
 *
834
 */
835
function theme_cdm_taxon_page_description($taxonTO){
836
  
837
  // description TOC
838
  $out .= theme('cdm_featureTreeToc', $taxonTO->featureTree);
839
  // description
840
  $out .= theme('cdm_featureTree', $taxonTO->featureTree);
841
  return $out;
842
}
843

    
844
/**
845
 * Show whole synonymy for the accepted taxon. Synonymy list is headed by the complete scientific name
846
 * of the accepted taxon with nomenclatural reference.
847
 *
848
 */
849
function theme_cdm_taxon_page_synonymy($taxonTO){
850
  
851
  $out .= theme('cdm_homotypicSynonyms', $taxonTO->homotypicSynonyms, $taxonTO->typeDesignations);
852

    
853
  foreach($taxonTO->heterotypicSynonymyGroups as $HomotypicTaxonGroupSTO){
854
    $out .= theme('cdm_heterotypicSynonymyGroup', $HomotypicTaxonGroupSTO);
855
  }
856
  $out .= theme('cdm_taxonRelations', $taxonTO->taxonRelations);
857

    
858
  return $out;
859
}
860

    
861
/**
862
 * Show the collection of images stored with the accepted taxon
863
 *
864
 * TODO this is just a copy of the special image display in the cichorieae
865
 *  and will not work with other portals thus a more general solution is needed
866
 */
867
function theme_cdm_taxon_page_images($taxonTO){
868

    
869
  $descriptions = $taxonTO->featureTree->descriptions;
870
  foreach($descriptions as $descriptionTo){
871
    $features = $descriptionTo->features;
872
    foreach($features as $featureTo){
873
      if($featureTo->feature->term == 'Image'){
874
        $flashLink = count($featureTo->descriptionElements) > 0;
875
        break;
876
      }
877
    }
878
  }
879
  
880
  if($flashLink){
881
    
882
    $taggedName = $taxonTO->name->taggedName;
883
    
884
    $nameArray = array();
885
    foreach($taggedName as $taggedText){
886
      if($taggedText->type == 'name'){
887
        $nameArray[] = $taggedText->text;
888
      }
889
    }
890
    
891
    $query = join("%5F", $nameArray) . '%20AND%20jpg';
892
    
893
  $out = '
894
  
895
  <script type="text/javascript" src="http://media.bgbm.org/erez/js/fsiwriter.js"></script>
896

    
897
<script type="text/javascript">
898
<!--
899
	writeFlashCode( "http://media.bgbm.org/erez/fsi/fsi.swf?&cfg=showcase_presets/showcase_info.fsi&effects=%26quality%3D95&showcase_query='.$query.'&skin=silver&showcase_labeltextheight=50&textbox_textfrom=IPTC_WP6&textbox_height=50&param_backgroundcolor=454343&publishwmode=opaque&showcase_hscroll=true&showcase_basecolor=454343&plugins=PrintSave,textbox",
900
		"http://media.bgbm.org/erez/erez?src=erez-private/flashrequired.svg&tmp=Large&quality=97&width=470&height=400",
901
		"width=470;height=400;bgcolor=454343;wmode=opaque");
902
// -->
903
</script>
904
<noscript>
905
	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,65,0" width="470" height="400">
906
		<param name="movie" value="http://media.bgbm.org/erez/fsi/fsi.swf?&cfg=showcase_presets/showcase_info.fsi&effects=%26quality%3D95&showcase_query='.$query.'&skin=silver&showcase_labeltextheight=50&textbox_textfrom=IPTC_WP6&textbox_height=50&param_backgroundcolor=454343&publishwmode=opaque&showcase_hscroll=true&showcase_basecolor=454343plugins=PrintSave,textbox"/>
907
		<param name="bgcolor" value="454343" />
908
		<param name="wmode" value="opaque" />
909
		<param name="allowscriptaccess" value="always" />
910
		<param name="allowfullscreen" value="true" />
911
		<param name="quality" value="high" />
912
		<embed src="http://media.bgbm.org/erez/fsi/fsi.swf?&cfg=showcase_presets/showcase_info.fsi&effects=%26quality%3D95&showcase_query='.$query.'&skin=silver&showcase_labeltextheight=50&textbox_textfrom=IPTC_WP6&textbox_height=50&param_backgroundcolor=454343&publishwmode=opaque&showcase_hscroll=true&showcase_basecolor=454343plugins=PrintSave,textbox"
913
			width="470"
914
			height="400"
915
			bgcolor="454343"
916
			wmode="opaque"
917
			allowscriptaccess="always"
918
			allowfullscreen="true"
919
			quality="high"
920
			type="application/x-shockwave-flash"
921
			pluginspage="http://www.adobe.com/go/getflashplayer">
922
		</embed>
923
	</object>
924

    
925
</noscript>';
926
  
927
  }else{
928
    $out = 'No images available.';
929
  
930
  }
931
  return $out;
932

    
933
}
934

    
935
function theme_cdm_reference_pager($referencePager, $path, $parameters = array()){
936
  drupal_set_title(t('Bibliographic Index'));
937
  $out = '';
938
  if(count($referencePager->records) > 0){
939
    $out .= '<ul>';
940
    foreach($referencePager->records as $reference){
941
      $reference->fullCitation = $reference->titleCache; //FIXME remove hack for matching cdm entity to STO
942
      $out .= '<li>'.theme('cdm_fullreference', $reference, TRUE).'</li>';
943
    }
944
    $out .= '</ul>';
945
    $out .= theme('cdm_pager_new', $referencePager,  $path, $parameters);
946
  } else {
947
    $out = '<h4 class="error">Sorry, this page contains not entries.</h4>';
948
  }
949
  return $out;
950
}
951

    
952
/**
953
 * Show a reference in it's atomized form
954
 */
955
function theme_cdm_reference_page($referenceTO){
956
  if($referenceTO->titleCache) {
957
    drupal_set_title($referenceTO->titleCache);
958
  } else {
959
    drupal_set_title($referenceTO->fullCitation);
960
  }
961
  $field_order = array(
962
    "title",
963
    //"titleCache",
964
    //"citation",
965
    "authorTeam",
966
    "editor",
967
    "publisher",
968
    "placePublished",
969
    "datePublished",
970
    "year",
971
    "edition",      // class Book
972
    "volume",       // class Article
973
    "seriesPart",
974
    "inSeries",
975
    "inJournal",     // class Article
976
    "inBook",        // class BookSection
977
    "nomRefBase",    // class BookSection, Book, Article
978
    "inProceedings", // class InProceedings
979
    "pages",         // class Article
980
    "series",        // class Article, PrintSeries
981
    "school",        // class Thesis
982
    "institution",   // class Report
983
    "organization",  // class Proceedings
984
    "nextVersion",
985
    "previousVersion",
986
    "isbn",         // class Book
987
    "issn",         // class Journal
988
    "uri",
989
  );
990
  
991
  $table_rows = array();
992
  foreach($field_order as $fieldname){
993
      if(isset($referenceTO->$fieldname)){
994
        if($fieldname == "datePublished") {
995
          $partial = $referenceTO->$fieldname;
996
          $datePublished = '';
997
          if($partial->start){
998
            $datePublished = substr($partial->start, 0, 4).'-'.substr($partial->start, 4, 2).'-'.substr($partial->start, 6, 2);
999
          }
1000
          if($partial->end){
1001
            $datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
1002
          }
1003
          $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $datePublished);
1004
        } else if(is_object($referenceTO->$fieldname)){
1005
          $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname->titleCache);
1006
        } else {
1007
          $table_rows[] = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
1008
        }
1009
      }
1010
  }
1011
  return theme("table", array("","") , $table_rows);
1012
}
1013

    
1014
/**
1015
 * Show a synonym page
1016
 *
1017
 * TODO what should show on this page exactly?
1018
 *
1019
 */
1020
function theme_cdm_synonym_page(){
1021

    
1022
}
1023

    
1024
function theme_cdm_preferredImage($taxonTo, $defaultImage, $parameters = ''){
1025

    
1026
  $descriptions = $taxonTo->featureTree->descriptions;
1027

    
1028
  foreach($descriptions as $descriptionTo){
1029
    $features = $descriptionTo->features;
1030
    foreach($features as $featureTo){
1031
      if($featureTo->feature->term == 'Image'){
1032

    
1033
        $preferredImage = $featureTo->descriptionElements[0]->media[0]->representations[0]->representationParts[0]->uri;
1034
      }
1035
    }
1036
  }
1037

    
1038
  $image = $preferredImage ? $preferredImage . $parameters : $defaultImage;
1039
  $out = '<img class="left" src="'.$image.'" alt="no image available" />';
1040
  return $out;
1041
}
1042

    
1043

    
1044

    
1045

    
1046
function theme_cdm_homotypicSynonyms($synonymRelationshipTOs, $typeDesignations = false, $prependedSynonyms = array()){
1047

    
1048
  $out = '';
1049
  $out = '<ul class="homotypicSynonyms">';
1050

    
1051
  if(!empty($prependedSynonyms)){
1052
    foreach($prependedSynonyms as $taxon){
1053
      $out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxon, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
1054
    }
1055
  }
1056

    
1057
  foreach($synonymRelationshipTOs as $synonym){
1058
    $out .= '<li class="synonym">'.theme('cdm_related_taxon', $synonym->synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
1059
  }
1060
  if($typeDesignations){
1061
    $out .= theme('cdm_typedesignations', $typeDesignations);
1062
  }
1063

    
1064
  $out .= '</ul>';
1065
  return $out;
1066
}
1067

    
1068
function theme_cdm_homotypicSynonymLine($taxonSTO){
1069
  $out = '';
1070
  $out .= '<li class="synonym">'.theme('cdm_related_taxon', $taxonSTO, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
1071
  return $out;
1072
}
1073

    
1074
function theme_cdm_heterotypicSynonymyGroup($HomotypicTaxonGroupSTO){
1075
  $out = '';
1076
  $out = '<ul class="heterotypicSynonymyGroup">';
1077

    
1078
  $is_first_entry = true;
1079
  foreach($HomotypicTaxonGroupSTO->synonyms as $SynonymRelationshipTO){
1080
    if($is_first_entry){
1081
      $is_first_entry = false;
1082
      // is first list entry
1083
      $out .= '<li class="firstentry synonym">'.theme('cdm_related_taxon',$SynonymRelationshipTO->synonym, $SynonymRelationshipTO->typeUuid).'</li>';
1084
    } else {
1085
      $out .= '<li class="synonym">'.theme('cdm_related_taxon',$SynonymRelationshipTO->synonym, UUID_HOMOTYPIC_SYNONYM_OF).'</li>';
1086
    }
1087
  }
1088

    
1089
  if(isset($HomotypicTaxonGroupSTO->typeDesignations)){
1090
    $out .= theme('cdm_typedesignations', $HomotypicTaxonGroupSTO->typeDesignations);
1091
  }
1092

    
1093
  $out .= '</ul>';
1094

    
1095
  return $out;
1096
}
1097

    
1098
/**
1099
 * renders misapplied names and invalid designations.
1100
 * Both relation types are currently treated the same!
1101
 *
1102
 * @param unknown_type $TaxonRelationshipTOs
1103
 * @return unknown
1104
 */
1105
function theme_cdm_taxonRelations($TaxonRelationshipTOs){
1106

    
1107
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.js');
1108
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/jquery.dimensions.js');
1109
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.hoverIntent.js');
1110
  drupal_add_css(drupal_get_path('module', 'cdm_dataportal').'/js/cluetip/jquery.cluetip.css');
1111

    
1112
  drupal_add_js ("$(document).ready(function(){
1113
      $('.cluetip').css({color: '#0062C2'}).cluetip({
1114
        splitTitle: '|',
1115
        showTitle: true,
1116
        activation: 'hover',
1117
        arrows: true,
1118
        dropShadow: false,
1119
        cluetipClass: 'rounded'
1120
      });
1121
    });", 'inline');
1122

    
1123
  // aggregate misapplied names having the same fullname:
1124
  $misapplied = array();
1125
  foreach($TaxonRelationshipTOs as $taxonRelation){
1126
    if(true || $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
1127

    
1128
      $sensu_reference_list = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE ,$taxonRelation->taxon->secUuid);
1129
      $sensu_reference = $sensu_reference_list[0];
1130
      $name = $taxonRelation->taxon->name->fullname;
1131
      if(!isset($misapplied[$name])){
1132
        $misapplied[$name]['out'] = '<span class="misapplied">'.theme('cdm_related_taxon',$taxonRelation->taxon, UUID_MISAPPLIED_NAME_FOR, false).'</span>';
1133
      }
1134

    
1135
      // collect all authors for this fullname
1136
      $misapplied[$name]['authorship'][$sensu_reference->authorship] = '&nbsp;<span class="sensu cluetip no-print" title="|sensu '.htmlspecialchars(theme('cdm_fullreference',$sensu_reference )).'|">sensu '
1137
      .$sensu_reference->authorship.'</span>'
1138
      .'<span class="reference only-print">sensu '.theme('cdm_fullreference',$sensu_reference ).'</span>'
1139
      ;
1140

    
1141
      /*
1142
       $misapplied[$name]['out'] .= '&nbsp;<span class="sensu cluetip no-print" title="|sensu '.htmlspecialchars(theme('cdm_fullreference',$sensu_reference )).'|">sensu '
1143
       .$sensu_reference->authorship.'</span>'
1144
       .'<span class="reference only-print">sensu '.theme('cdm_fullreference',$sensu_reference ).'</span>'
1145
       ;*/
1146

    
1147
    }
1148
  }
1149
   
1150
  // generate output
1151
  $out = '<ul class="misapplied">';
1152
  foreach($misapplied as $misapplied_name){
1153
    $out .= '<li class="synonym">'.$misapplied_name['out'] . " ";
1154
    // sorting authors
1155
    ksort($misapplied_name['authorship']);
1156
    $out .= join('; ', $misapplied_name['authorship']);
1157
    $out .= '</li>';
1158
  }
1159
  $out .= '</ul>';
1160
  return $out;
1161
}
1162

    
1163
function theme_cdm_nameRelations($NameRelationshipTOs){
1164

    
1165
  $out = '';
1166

    
1167
  foreach($NameRelationshipTOs as $NameRelationshipTO){
1168

    
1169
    $block->module = 'cdm_dataportal';
1170

    
1171
    $type = isset($NameRelationshipTO->type->term) ? $NameRelationshipTO->type->term : 'Name relation';
1172

    
1173
    $block->delta  = $type;
1174
    $block->subject = t(ucfirst($block->delta));
1175
    $block->delta = str_replace(' ', '_', strtolower($block->delta));
1176

    
1177
    $block->content = '<ul class="nameRelationships '.$block->delta.'">';
1178
    $relatedNames = array();
1179
    foreach($NameRelationshipTO->relatedNames as $name){
1180
      $relatedNames[] = theme('cdm_name', $name);
1181
    }
1182

    
1183
    $block->content .= implode(', ', $relatedNames);
1184

    
1185
    $out .= theme('block', $block);
1186

    
1187
  }
1188
  return $out;
1189
}
1190

    
1191
/**
1192
 * FIXME this definitively has to be in another spot. just didn't know where to put it right now.
1193
 *
1194
 * @param String $a 	a typeDesignation status
1195
 * @param String $b		another typeDesignation status
1196
 */
1197
function compare_specimenTypeDesignationStatus($a, $b){
1198
  /* this is the desired sort oder as of now:
1199
   * 	Holotype
1200
   * 	Isotype
1201
   * 	Lectotype
1202
   * 	Isolectotype
1203
   * 	Syntype
1204
   *
1205
   * TODO
1206
   * Basically, what we are trying to do is, we define an ordered array of TypeDesignation-states
1207
   * and use the index of this array for comparison. This array has to be filled with the cdm-
1208
   * TypeDesignation states and the order should be parameterisable inside the dataportal.
1209
   */
1210
  // make that static for now
1211
  $typeOrder = array('Holotype', 'Isotype', 'Lectotype', 'Isolectotype', 'Syntype');
1212

    
1213
  $aQuantifier = array_search($a->status->text, $typeOrder);
1214
  $bQuantifier = array_search($b->status->text, $typeOrder);
1215

    
1216
  if ($aQuantifier == $bQuantifier) {
1217
    // sort alphabetically
1218
    return ($a->status->text < $b->status->text) ? -1 : 1;
1219
  }
1220
  return ($aQuantifier < $bQuantifier) ? -1 : 1;
1221

    
1222
}
1223

    
1224
function theme_cdm_typedesignations($typeDesignations = array()){
1225

    
1226
  $out = '<ul class="typeDesignations">';
1227

    
1228
  $specimenTypeDesignations = array();
1229
  foreach($typeDesignations as $variant => $typeDesignation){
1230
    if($typeDesignation->typeSpecimen){
1231
      // specimenTypeDesignations should be ordered. collect theme here only
1232
      $specimenTypeDesignations[] = $typeDesignation;
1233
    }else {
1234
      if($typeDesignation->notDesignated){
1235
        $out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: '.t('not designated'). '</li>';
1236
      }else if($typeDesignation->typeSpeciesName){
1237
        $out .= '<li class="nameTypeDesignation"><span class="status">Type</span>: '.theme('cdm_name', $typeDesignation->typeSpeciesName, false);
1238
        $out .= '</li>';
1239
      }
1240
    }
1241
  }
1242

    
1243
  if(!empty($specimenTypeDesignations)){
1244
    // sorting might be different for dataportals so this has to be parameterized
1245
    usort($specimenTypeDesignations, "compare_specimenTypeDesignationStatus");
1246
    foreach($specimenTypeDesignations as $std){
1247

    
1248
      $typeReference = '';
1249
      if($std->reference){
1250
        $typeReference .= '&nbsp;(' . t('designated by');
1251
        $typeReference .= '&nbsp;<span class="typeReference cluetip no-print" title="|'. htmlspecialchars(theme('cdm_fullreference',$std->reference )) .'|">';
1252
        $typeReference .= $std->reference->authorship . ' ' . $std->reference->year;
1253
        $typeReference .= '</span>';
1254
        $typeReference .= ')';
1255
        $typeReference .= '<span class="reference only-print">(designated by '.theme('cdm_fullreference',$std->reference ).')</span>';
1256
      }
1257

    
1258
      $out .= '<li class="specimenTypeDesignation">';
1259
      $out .= '<span class="status">'.(($std->status->text) ? $std->status->text : t('Type')) .$typeReference.'</span>: '.$std->typeSpecimen->specimenLabel;
1260
      $out .= theme('cdm_specimen', $std->typeSpecimen);
1261
      $out .= '</li>';
1262
    }
1263
  }
1264

    
1265
  $out .= '</ul>';
1266

    
1267
  return $out;
1268
}
1269

    
1270
function theme_cdm_specimen($specimen){
1271

    
1272
  _add_js_thickbox();
1273

    
1274
  $out = '';
1275
  if(isset($specimen->media[0])){
1276

    
1277
    $image_url = drupal_get_path('module', 'cdm_dataportal').'/images/external_link.gif';
1278
    // thickbox has problems reading the first url parameter, so a litte hack is needed here:
1279
    // adding a meaningless patameter &tb_hack=1& ....
1280
    $out .= '&nbsp;<a href="#TB_inline?tb_hack=1&width=300&amp;height=330&amp;inlineId=specimen_media_'.$specimen->uuid.'" class="thickbox">'
1281
    .'<img src="'.$image_url.'" title="'.t('Show media').'" /></a>';
1282

    
1283
    $out .= '<div id="specimen_media_'.$specimen->uuid.'" class="tickbox_content"><table>';
1284

    
1285
    $media_row = '<tr class="media_data">';
1286
    $meta_row = '<tr class="meta_data">';
1287

    
1288
    foreach($specimen->media as $media){
1289
      foreach($media->representations as $representation){
1290

    
1291
        //TODO this this is PART 2/2 of a HACK - select preferred representation by mimetype and size
1292
        //
1293
        if(true || $representation->mimeType == 'image/jpeg'){
1294
          foreach($representation->representationParts as $part){
1295
            // get media uri conversion rules if the module is installed and activated
1296
            if(module_exists('cdm_mediauri')){
1297
              $muris = cdm_mediauri_conversion($part->uri);
1298
            }
1299
            // --- handle media preview rules
1300
            if(isset($muris['preview'])){
1301

    
1302
              $a_child = '<img src="'.$muris['preview']['uri'].'" class="preview" '
1303
              .($muris['preview']['size_x'] ? 'width="'.$muris['preview']['size_x'].'"' : '')
1304
              .($muris['preview']['size_y'] ? 'width="'.$muris['preview']['size_y'].'"' : '')
1305
              .'/>';
1306
            } else {
1307
              $a_child = '<img src="'.$part->uri.'" />';
1308
            }
1309

    
1310
            // --- handle web application rules
1311
            $webapp = '';
1312
            if(isset($muris['webapp'])){
1313
              if($muris['webapp']['embed_html']){
1314
                // embed in same page
1315
                $webapp = $muris['webapp']['embed_html'];
1316
              } else {
1317
                $webapp = l(t('web application'), $muris['webapp']['uri']);
1318
              }
1319
            }
1320
            $media_row .= '<td><a href="'.$part->uri.'" target="'.$part->uuid.'">'.$a_child.'</a></td>';
1321
            $meta_row .= '<td><span class="label">'.check_plain($specimen->specimenLabel).'</span><div class="webapp">'.$webapp.'</div></td>';
1322
          } // END parts
1323
          //TODO this is PART 2/2 of a hack
1324
          break;
1325
        } // END representations
1326
      } // END media
1327
    }
1328
    $out .= $media_row.'</tr>';
1329
    $out .= $meta_row.'</tr>';
1330

    
1331
    $out .= '</div></table>';
1332
  }
1333
  return $out;
1334
}
1335

    
1336

    
1337

    
1338

    
1339
function theme_cdm_featureTree($featureTree){
1340
  /*
1341
   *	->featureTree{
1342
   *		->descriptions{
1343
   *			->DescriptionTo{
1344
   *				->label
1345
   *			    ->sources{}
1346
   *			    ->elements{}
1347
   *				->features{
1348
   *					->FeatureTo{
1349
   *						->descriptionElements{
1350
   *							->DescriptionElementSTO{}
1351
   *						->uuid
1352
   * 						->type
1353
   */
1354

    
1355
  $descriptions = $featureTree->descriptions;
1356
  foreach($descriptions as $descriptionTO){
1357
    $features = $descriptionTO->features;
1358
    foreach($features as $featureTo){
1359
      $descriptionElements = $featureTo->descriptionElements;
1360
      // process $descriptionElements with content only
1361
      if(is_array($descriptionElements) && count($descriptionElements) > 0){
1362
        $block->module = 'cdm_dataportal';
1363

    
1364
        $feature = isset($featureTo->feature->term) ? $featureTo->feature->term : 'Feature';
1365

    
1366
        if($feature != "Image"){
1367
          $block->delta = $feature;
1368
          $block->subject = t(ucfirst($block->delta));
1369
          $block->delta = generalizeString($block->delta);
1370

    
1371
          //
1372
          $block->content = theme('cdm_descriptionElements', $descriptionElements, $block->delta);
1373
          //
1374
          // set anchor
1375
          $out .= '<a name="'.$block->delta.'"></a>';
1376
          $out .= theme('block', $block);
1377

    
1378

    
1379

    
1380
          // TODO HACK
1381
          if($feature == 'Distribution'){
1382
            //                  ob_start();
1383
            //  				  echo "<pre>";
1384
            //  				  print_r($featureTo->url);
1385
            //  				  echo "</pre>";
1386
            //  				  ob_flush();
1387
            $out .= theme('cdm_descriptionElement_distribution', $featureTo);
1388
          }
1389
        }
1390
      }
1391
    }
1392
  }
1393
  return $out;
1394
}
1395

    
1396
function theme_cdm_featureTreeToc($featureTree){
1397
  
1398
  $out = '<div class="featureTOC">';
1399
  $out .= '<h2>' . t('Content') .'</h2>';
1400
  $out .= '<ul>';
1401

    
1402
  $descriptions = $featureTree->descriptions;
1403
  foreach($descriptions as $descriptionTO){
1404
    $features = $descriptionTO->features;
1405
    foreach($features as $featureTo){
1406
      $descriptionElements = $featureTo->descriptionElements;
1407
      // process $descriptionElements with content only
1408
      if(is_array($descriptionElements) && count($descriptionElements) > 0){
1409

    
1410
        $feature = isset($featureTo->feature->term) ? $featureTo->feature->term : 'Feature';
1411
        // HACK to implement images for taxa, should be removed
1412
        if($feature != 'Image'){
1413
          $out .= '<li>'.l(t(ucfirst($feature)), $_GET['q'], array("class"=>"toc"), NULL, generalizeString($feature)).'</li>';
1414
        }
1415
      }
1416
    }
1417
  }
1418
  $out .= '</ul></div>';
1419

    
1420
  return $out;
1421
}
1422

    
1423
/**
1424
 * Replaces all occurrences of space characters with an underscore and tronsforms the given
1425
 * string to lowercase.
1426
 *
1427
 * @param String $string
1428
 * @return the transformed string
1429
 */
1430
function generalizeString($string){
1431
  return str_replace(' ', '_', strtolower($string));
1432
}
1433

    
1434
function theme_cdm_descriptionElements($descriptionElements, $feature){
1435

    
1436
  $outArray = array();
1437
  $glue = '';
1438
  $sortOutArray = false;
1439
  $enclosingHtml = 'ul';
1440
  
1441
  foreach($descriptionElements as $descriptionElementSTO){
1442

    
1443
    if($descriptionElementSTO->classType == 'TextData'){
1444
      $outArray[] = theme('cdm_descriptionElementTextData', $descriptionElementSTO);
1445
    }else if($descriptionElementSTO->classType == 'Distribution'){
1446
      $outArray[] = $descriptionElementSTO->area->term;
1447
      $glue = ', ';
1448
      $sortOutArray = true;
1449
      $enclosingHtml = 'p';
1450
    }else{
1451
      $outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElementSTO->classType.'</li>';
1452
    }
1453
  }
1454

    
1455
  return theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
1456
}
1457

    
1458
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
1459
  $out = '<'.$enclosingHtml.' class="description" id="'.$feature.'">';
1460
  
1461
  if($sortArray) sort($elementArray);
1462
  
1463
  $out .= join($elementArray, $glue);
1464
  
1465
  $out .= '</'.$enclosingHtml.'>';
1466
  return $out;
1467
}
1468

    
1469
function theme_cdm_descriptionElementTextData($element){
1470

    
1471
  $description = str_replace("\n", "<br/>", $element->description);
1472
  $referenceCitation = '';
1473
  if($element->reference){
1474
    $referenceCitation = '; '.theme('cdm_fullreference', $element->reference, TRUE);
1475
  }
1476
  return '<li class="descriptionText">' . $description . $referenceCitation.'</li>';
1477
}
1478

    
1479
function theme_cdm_search_results($resultPage, $path, $parameters){
1480

    
1481
  drupal_set_title(t('Search Results'));
1482

    
1483
  $out = '';
1484
  if(count($resultPage->results) > 0){
1485
    $out .= theme('cdm_list_of_taxa', $resultPage->results);
1486
    $out .= theme('cdm_pager', $resultPage,  $path, $parameters);
1487
  } else {
1488
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
1489
  }
1490
  return $out;
1491
}
1492

    
1493
function theme_cdm_pager(&$resultPageSTO, $path, $parameters, $neighbors = 2){
1494
  $out = '';
1495

    
1496
  if ($resultPageSTO->totalPageCount > 1) {
1497

    
1498
    $viewportsize = $neighbors * 2 + 1;
1499
    if($resultPageSTO->totalPageCount <= $viewportsize){
1500
      $viewportsize = $resultPageSTO->totalPageCount;
1501
    }
1502

    
1503
    $out .= '<div class="pager">';
1504
    if($resultPageSTO->pageNumber > 1){
1505
      $out .= theme('cdm_pager_link', t('« first'), 1,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
1506
      $out .= theme('cdm_pager_link', t('‹ previous'), $resultPageSTO->pageNumber - 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-previous'));
1507
    }
1508

    
1509
    if($resultPageSTO->totalPageCount <= $viewportsize || $resultPageSTO->pageNumber <= $neighbors){
1510
      $first_number = 1;
1511
    } else if($resultPageSTO->pageNumber >= $resultPageSTO->totalPageCount - $neighbors){
1512
      $first_number = $resultPageSTO->totalPageCount - $viewportsize;
1513
    } else {
1514
      $first_number = $resultPageSTO->pageNumber - $neighbors;
1515
    }
1516

    
1517
    if($first_number > 1){
1518
      $out .= '<div class="pager-list-dots-left">...</div>';
1519
    }
1520

    
1521

    
1522
    for($i = $first_number; ($i == $resultPageSTO->totalPageCount) || ($i < $first_number + $viewportsize); $i++){
1523
      $out .= theme('cdm_pager_link', $i, $i,  $resultPageSTO, $path, $parameters, array('class' => 'pager-first'));
1524
    }
1525
    if($i < $resultPageSTO->totalPageCount){
1526
      $out .= '<div class="pager-list-dots-right">...</div>';
1527
    }
1528

    
1529
    if($resultPageSTO->pageNumber < $resultPageSTO->totalPageCount){
1530
      $out .= theme('cdm_pager_link', t('next ›'), $resultPageSTO->pageNumber + 1, $resultPageSTO, $path, $parameters, array('class' => 'pager-next'));
1531
      $out .= theme('cdm_pager_link', t('last »'), $resultPageSTO->totalPageCount, $resultPageSTO, $path, $parameters, array('class' => 'pager-last'));
1532
    }
1533
    $out .= '</div>';
1534

    
1535
    return $out;
1536
  }
1537
}
1538

    
1539
function theme_cdm_pager_new(&$pager, $path, $parameters, $neighbors = 2){
1540
  $out = '';
1541

    
1542
  if ($pager->pagesAvailable > 1) {
1543

    
1544
    $viewportsize = $neighbors * 2 + 1;
1545
    if($pager->pagesAvailable <= $viewportsize){
1546
      $viewportsize = $pager->pagesAvailable;
1547
    }
1548

    
1549
    $out .= '<div class="pager">';
1550
    if($pager->currentIndex > 1){
1551
      $out .= theme('cdm_pager_link_new', t('« first'), 1,  $pager, $path, $parameters, array('class' => 'pager-first'));
1552
      $out .= theme('cdm_pager_link_new', t('‹ previous'), $pager->currentIndex - 1, $pager, $path, $parameters, array('class' => 'pager-previous'));
1553
    }
1554

    
1555
    if($pager->pagesAvailable <= $viewportsize || $pager->currentIndex <= $neighbors){
1556
      $first_number = 1;
1557
    } else if($pager->currentIndex >= $pager->pagesAvailable - $neighbors){
1558
      $first_number = $pager->pagesAvailable - $viewportsize;
1559
    } else {
1560
      $first_number = $pager->currentIndex - $neighbors;
1561
    }
1562

    
1563
    if($first_number > 1){
1564
      $out .= '<div class="pager-list-dots-left">...</div>';
1565
    }
1566

    
1567

    
1568
    for($i = $first_number; ($i == $pager->pagesAvailable) || ($i < $first_number + $viewportsize); $i++){
1569
      $out .= theme('cdm_pager_link_new', $i, $i,  $pager, $path, $parameters, array('class' => 'pager-first'));
1570
    }
1571
    if($i < $pager->pagesAvailable){
1572
      $out .= '<div class="pager-list-dots-right">...</div>';
1573
    }
1574

    
1575
    if($pager->currentIndex < $pager->pagesAvailable){
1576
      $out .= theme('cdm_pager_link_new', t('next ›'), $pager->currentIndex + 1, $pager, $path, $parameters, array('class' => 'pager-next'));
1577
      $out .= theme('cdm_pager_link_new', t('last »'), $pager->pagesAvailable, $pager, $path, $parameters, array('class' => 'pager-last'));
1578
    }
1579
    $out .= '</div>';
1580

    
1581
    return $out;
1582
  }
1583
}
1584

    
1585
function theme_cdm_pager_link_new($text, $linkPageNumber, &$pager, $path, $parameters = array(), $attributes) {
1586

    
1587
  $out = '';
1588

    
1589
  if ($linkPageNumber == $pager->currentIndex) {
1590
    $out = '<strong>'.$text.'</strong>';
1591
  } else {
1592
    $out = l($text, $path.$linkPageNumber, $attributes /*, compose_url_prameterstr($parameters)*/);
1593
  }
1594
  return $out;
1595
}
1596

    
1597
function theme_cdm_pager_link($text, $linkPageNumber, &$resultPageSTO, $path, $parameters = array(), $attributes) {
1598

    
1599
  $out = '';
1600

    
1601
  if ($linkPageNumber == $resultPageSTO->pageNumber) {
1602
    $out = '<strong>'.$text.'</strong>';
1603
  } else {
1604
    // <a class="pager-next active" title="Go to page 3" href="/node?page=2">3</a>
1605
    $parameters['page'] = $linkPageNumber;
1606
    $out = l($text, $path, $attributes, compose_url_prameterstr($parameters));
1607
  }
1608

    
1609

    
1610
  return $out;
1611
}
1612

    
1613

    
(6-6/9)