Project

General

Profile

Download (27.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * Copyright (C) 2007 EDIT
6
 * European Distributed Institute of Taxonomy
7
 * http://www.e-taxonomy.eu
8
 *
9
 * The contents of this file are subject to the Mozilla Public License Version 1.1
10
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
 */
12

    
13
/**
14
 * default title for a taxon page
15
 *
16
 * @param NameTO $nameTO
17
 * @return the formatted taxon name
18
 */
19
function theme_cdm_taxon_page_title($taxon){
20

    
21
	RenderHints::pushToRenderStack('taxon_page_title');
22
	if(isset($taxon->name->nomenclaturalReference)){
23
		$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
24
	}
25
	$out = theme('cdm_taxonName', $taxon->name, null, $referenceUri, false);
26
	RenderHints::popFromRenderStack();
27

    
28
	return '<span class="'.$taxon->class.'">'.$out.'</span>';
29
}
30

    
31
/**
32
 * Default title for a name page
33
 * @param $taxon_name The taxon name object
34
 * @return the formatted name title
35
 */
36
function theme_cdm_name_page_title($taxon_name){
37
	RenderHints::pushToRenderStack('taxon_page_title');
38
	if(isset($taxon_name->nomenclaturalReference)){
39
		$referenceUri = url(path_to_reference($taxon_name->nomenclaturalReference->uuid));
40
	}
41

    
42
	$out = '<span class="'.$taxon_name->class.'">'.theme('cdm_taxonName', $taxon_name, null, $referenceUri, false).'</span>';
43
	RenderHints::popFromRenderStack();
44
	return $out;
45
}
46

    
47
/**
48
 * A wrapper function that groups available information to show by default, when
49
 * a taxon page is requested by the browser.
50
 * Individual themeing has to decide what this page should include (see methods beneath)
51
 * and what information should go into tabs or should not be shown at all.
52
 *
53
 * It is headed by the name of the accepted taxon without author and reference.
54
 * @param $taxonTO the taxon object
55
 * @param $page_part name of the part to display,
56
 *         valid values are: 'description', 'images', 'synonymy', 'all'
57
 */
58
function theme_cdm_taxon_page_general($taxon, $page_part = 'description') {
59

    
60
	global $theme;
61

    
62
	$page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
63
	$hideTabs = array();
64

    
65

    
66
	// get images
67
	$prefMimeTypeRegex = 'image:.*';
68
	$prefMediaQuality = '*';
69
	//$media =  cdm_ws_get(CDM_WS_PORTAL_TAXONOMY_MEDIA, array(variable_get('cdm_taxonomictree_uuid', false),$taxon->uuid));
70

    
71

    
72
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
73
	if ($selectShowMedia == 0){
74
		$media = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
75
	}else{
76
		$media = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid, $prefMimeTypeRegex, $prefMediaQuality));
77
	}
78
	/*
79
	 if(!isset($mediaList[0])) {
80
	 $hideTabs[] = theme('cdm_taxonpage_tab', 'Images');
81
	 }
82
	 */
83

    
84
	if(!isset($media[0])) {
85
		$hideTabs[] = theme('cdm_taxonpage_tab', 'Images');
86
	}
87

    
88
	$descriptionElementCount = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS_ELEMENTSBYTYPE, array($taxon->uuid, 'IndividualsAssociation'), "count=true");
89
  if($descriptionElementCount->Integer < 1) {
90
    $hideTabs[] = theme('cdm_taxonpage_tab', 'Specimens');
91
  }
92

    
93
	// hideImage flag depending on administative preset
94
	$hideImages = false;
95
	if(variable_get('image_hide_rank', '0') != '0'){
96
		$rankCompare = rank_compare($taxon->name->rank->uuid, variable_get('image_hide_rank', '-99'));
97
		$hideImages =  ($rankCompare > -1);
98
	}
99
	// $hideTabs[] = theme('cdm_taxonpage_tab', 'General');
100
	// $hideTabs[] = theme('cdm_taxonpage_tab', 'Synonymy')
101

    
102
	// hide tabs
103
	$tabhide_js = '';
104
	foreach($hideTabs as $tabText) {
105
		$tabhide_js .= "$('.tabs.primary').children('li').children('a:contains(\"$tabText\")').hide();\n";
106
	}
107
	drupal_add_js("
108
  $(document).ready(function(){
109
  $tabhide_js
110
    });", 'inline');
111

    
112
  $out = '';
113
  $out .= theme('cdm_back_to_search_result_button');
114
  if(variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR)){
115
  	$out .= theme('cdm_acceptedFor', 'page_general');
116
  }
117

    
118
  // --- DESCRIPTION --- //
119
  if($page_part == 'description' || $page_part == 'all'){
120

    
121
  	$featureTree = cdm_ws_get(CDM_WS_FEATURETREE, variable_get(CDM_DATAPORTAL_DEFAULT_FEATURETREE_UUID, UUID_DEFAULT_FEATURETREE));
122
  	$taxonDescriptions = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS, $taxon->uuid); //retrieve all description for the taxon
123

    
124
  	$nonStructuredDescriptions = array();
125
  	if($taxonDescriptions != null){
126
  		foreach ($taxonDescriptions as $taxonDescription) {
127
  			// check if structured description
128
  			$hasStructuredData = cdm_ws_get(CDM_WS_DESCRIPTION_HAS_STRUCTRURED_DATA, $taxonDescription->uuid);
129
  			$hasStructuredData = $hasStructuredData->Boolean == 'true';
130
  			if($hasStructuredData){
131
  				$naturallanguage_textData = cdm_ws_get(CDM_WS_DESCRIPTION_NATURALLANGUAGE_DESCRIPTION, array($taxonDescription->uuid, variable_get(CDM_DATAPORTAL_STRUCTURED_DESCRIPTION_FEATURETREE_UUID, false)));
132
  				$taxonDescription->elements = null;
133
  				$taxonDescription->elements = array($naturallanguage_textData);
134
  			}
135
  			$nonStructuredDescriptions[] = $taxonDescription;
136
  		}
137
  		$taxonDescriptions = null; // release memory
138
  	}
139

    
140
  	$mergedTrees = cdm_ws_descriptions_by_featuretree($featureTree, $nonStructuredDescriptions, variable_get('cdm_dataportal_descriptions_separated', FALSE));
141

    
142
  	$out .= '<div id="general">';
143
  	$out .= theme('cdm_taxon_page_description', $taxon, $mergedTrees, $media, $hideImages);
144
  	$out .= '</div>';
145
  }
146

    
147
  // --- IMAGES --- //
148
  if(!$hideImages && $page_part == 'images' || $page_part == 'all'){
149
  	$out .= '<div id="images">';
150
  	if($page_part == 'all'){
151
  		$out .= '<h2>'.t('Images').'</h2>';
152
  	}
153

    
154
  	// get the image gallery as configured by the admin
155
  	$taxon_image_gallery = call_user_func_array(
156
	    'taxon_image_gallery_' . variable_get('image_gallery_viewer', 'default'),
157
	    array($taxon, $media));
158
  	$out .= $taxon_image_gallery;
159

    
160
  	$out .= '</div>';
161

    
162
  	if($theme == 'garland_cichorieae'){
163
  		$out .= theme('cdm_taxon_page_images_cichorieae_copyright');
164
  	}
165
  }
166

    
167
  // --- SYNONYMY --- //
168
  if($page_part == 'synonymy' || $page_part == 'all'){
169
  	$out .= '<div id="synonymy">';
170
  	if($page_part == 'all'){
171
  		$out .= '<h2>'.t('Synonymy').'</h2>';
172
  	}
173
  	$addAcceptedTaxon = variable_get('cdm_dataportal_nomref_in_title', CDM_DATAPORTAL_NOMREF_IN_TITLE);
174
  	$out .= theme('cdm_taxon_page_synonymy', $taxon, $addAcceptedTaxon);
175

    
176
  	$out .= '</div>';
177
  }
178

    
179
  // --- SPECIMENS --- //
180
  if($descriptionElementCount > 0 && ($page_part == 'specimens' || $page_part == 'all') ){
181
  	$out .= '<div id="specimens">';
182
  	if($page_part == 'all'){
183
  		$out .= '<h2>'.t('Specimens').'</h2>';
184
  	}
185
  	$out .= theme('cdm_taxon_page_specimens', $taxon);
186
  	$out .= '</div>';
187
  }
188
  return $out;
189
}
190

    
191

    
192
/**
193
 * Outputs all descriptive data and shows the preferred picture of the
194
 * accepted taxon.
195
 *
196
 */
197
function theme_cdm_taxon_page_description($taxon, $mergedTrees, $media = null, $hideImages = false){
198

    
199
	if( variable_get('cdm_dataportal_show_default_image', false) && !$hideImages){
200
		// preferred image
201
		// hardcoded for testing;
202
		$defaultRepresentationPart = false;
203
		$defaultRepresentationPart->width = 184;
204
		$defaultRepresentationPart->height = 144;
205
		$defaultRepresentationPart->uri = drupal_get_path('theme', 'palmweb_2').'/images/no_picture.png';
206

    
207
		// preferred image size 184px × 144
208
		$imageMaxExtend = 184;
209
		$out .= '<div class="preferredImage">'.$defaultRepresentationPart->uri.theme('cdm_preferredImage', $media, $defaultRepresentationPart, $imageMaxExtend).'</div>';
210
	}
211
	// description TOC
212
	$out .= theme('cdm_featureTreeTOCs', $mergedTrees);
213
	// description
214
	$out .= theme('cdm_featureTrees', $mergedTrees, $taxon);
215
	return $out;
216
}
217

    
218

    
219
function theme_cdm_taxon_page_specimens($taxon){
220

    
221
	RenderHints::pushToRenderStack('taxon_page_specimens');
222

    
223
  $descriptionElements = cdm_ws_get(CDM_WS_PORTAL_TAXON_DESCRIPTIONS_ELEMENTSBYTYPE, array($taxon->uuid, 'IndividualsAssociation') );
224

    
225
  if(variable_get('cdm_dataportal_map_openlayers', 1)){
226

    
227
  	  $occurrenceQuery = cdm_ws_get(CDM_WS_GEOSERVICE_OCCURRENCEMAP, $taxon->uuid);
228
  	  $occurrenceQuery = $occurrenceQuery->String;
229
  	  //$query_string = 'l=v%3Aatbi%2Ce_w_0&legend=0&ms=400%2C350&od=1%3A44.29481%2C6.82161|44.29252%2C6.822873|44.29247%2C6.82346|44.29279%2C6.823678|44.29269%2C6.82394|44.28482%2C6.887252|44.11469%2C7.287144|44.11468%2C7.289168&os=1%3Ac%2F8B0000%2F10%2FAporrectodea caliginosa&recalculate=false&image=false';
230

    
231
  	  $out .= get_openlayers_map(variable_get('cdm_dataportal_geoservice_display_width', false), $occurrenceQuery);
232

    
233
  	}
234

    
235
  if($descriptionElements){
236
  	$out_specimenList = '<ul class="specimens">';
237
  	foreach($descriptionElements as $descriptionElement) {
238
  		if($descriptionElement->associatedSpecimenOrObservation){
239

    
240
  			$out_specimenList .= '<li class="descriptionElement descriptionElement_IndividualsAssociation">' . $descriptionElement->associatedSpecimenOrObservation->titleCache . '</li>';
241
  		}
242
  	}
243
  	$out_specimenList .= '</ul>';
244
  }
245

    
246
  $out .= $out_specimenList;
247

    
248

    
249
	RenderHints::popFromRenderStack();
250
	return $out;
251
}
252
/**
253
 * Show whole synonymy for the accepted taxon. Synonymy list is headed by the complete scientific name
254
 * of the accepted taxon with nomenclatural reference.
255
 *
256
 */
257
function theme_cdm_taxon_page_synonymy($taxon, $addAcceptedTaxon){
258

    
259
	RenderHints::pushToRenderStack('taxon_page_synonymy');
260
	$synomymie = cdm_ws_get(CDM_WS_PORTAL_TAXON_SYNONYMY, $taxon->uuid);
261
	$skip = array(UUID_BASIONYM);
262

    
263
	//render full accepted taxon
264
	if($addAcceptedTaxon){
265
		if(isset($taxon->name->nomenclaturalReference)){
266
			$referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
267
		}
268
		$out .= theme('cdm_taxonName', $taxon->name, null, $referenceUri);
269

    
270
		$special_annotations_array = array();
271
		$special_annotations_array[] = $taxon->name;
272
		$special_annotations_array[] = $taxon;
273
		$out .= theme('cdm_annotations_as_footnotekeys',
274
		$special_annotations_array,
275
		RenderHints::getRenderPath() . '-annotations');
276
		RenderHints::setFootnoteListKey(RenderHints::getRenderPath() . '-annotations');
277
	}
278
	//render accepted taxon homotypic synonymy groups or type desygnations
279
	if(!isset($synomymie->homotypicSynonymsByHomotypicGroup[0])){
280
		//if($addAcceptedTaxon && !isset($synomymie->homotypicSynonymsByHomotypicGroup[0])){
281
		// display the type information for the added taxon
282
		$typeDesignations = cdm_ws_get(CDM_WS_PORTAL_TAXON_NAMETYPEDESIGNATIONS, $taxon->uuid);
283
		if($typeDesignations){
284
			$out .= theme('cdm_typedesignations', $typeDesignations);
285
		}
286
	} else {
287
		// render the homotypicSynonymyGroup including the type information
288
		$out .= theme('cdm_homotypicSynonymyGroup', $synomymie->homotypicSynonymsByHomotypicGroup);
289
	}
290
	//render accepted taxon heterotypic synonymy groups
291
	if($synomymie->heterotypicSynonymyGroups) {
292
		foreach($synomymie->heterotypicSynonymyGroups as $homotypicalGroup){
293
			$out .= theme('cdm_heterotypicSynonymyGroup', $homotypicalGroup);
294
		}
295
	}
296
	//render taxon relationships
297
	if(variable_get(CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_TAXON_RELATIONSHIPS_DEFAULT)){
298
		$taxonRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, $taxon->uuid);
299
		$out .= theme('cdm_taxonRelationships', $taxonRelationships);
300
	}
301
  //render name relationships
302
  $name_rels_to_show = variable_get('name_relationships_to_show', 0);
303
  $skip = array();
304
  foreach ($name_rels_to_show as $key => $value){
305
    if ($value === 0){
306
      $skip[] = $key;
307
    }
308
  }
309
  if (sizeof($name_rels_to_show) != sizeof($skip)){
310
   $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
311
   $out .= theme('cdm_nameRelationships', $nameRelationships, $skip);
312
  }
313
  /*
314
  if(variable_get(CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS, CDM_DATAPORTAL_DISPLAY_NAME_RELATIONSHIPS_DEFAULT)){
315
    $nameRelationships = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
316
    // TODO is it correct to skip relationsFromThisName since all relationships are to be understood as 'is .... of'
317
    if(variable_get('cdm_dataportal_name_relations_skiptype_basionym', 1)){
318
      $skip = array(UUID_BASIONYM);
319
    }
320
    $out .= theme('cdm_nameRelationships', $nameRelationships, $skip);
321
  }
322
  */
323
	RenderHints::popFromRenderStack();
324

    
325
	return $out;
326
}
327

    
328

    
329
/**
330
 * TODO Implementation of Hook taxon_image_gallery()
331
 *
332
 * @param unknown_type $taxon
333
 * @param unknown_type $media
334
 * @return unknown_type
335
 */
336
function taxon_image_gallery_default($taxon, $media){
337

    
338
	 $hasImages = isset($media[0]);
339

    
340
  if($hasImages){
341
    //
342
    $maxExtend = 150;
343
    $cols = 3;
344
    $maxRows = false;
345
    $alternativeMediaUri = null;
346
    $captionElements = array('title', 'rights', '#uri'=>t('open Image'));
347
    $gallery_name = $taxon->uuid;
348
    $mediaLinkType = 'LIGHTBOX';
349

    
350
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_MEDIA_GALLERY_NAME);
351

    
352
    $out = '<div class="image-gallerie">';
353
    $out .= theme('cdm_media_gallerie', $media,
354
        $gallery_name,
355
        $gallery_settings['cdm_dataportal_media_maxextend'],
356
        $gallery_settings['cdm_dataportal_media_cols'],
357
        0, // ignore maxrows settings
358
        $captionElements,
359
        $mediaLinkType,
360
        null);
361
    $out .= '</div>';
362
  }else{
363
    $out = 'No images available.';
364

    
365
  }
366
  return $out;
367

    
368
}
369

    
370
/**
371
 * TODO Implementation of Hook taxon_image_gallery()
372
 *
373
 * @param unknown_type $taxon
374
 * @param unknown_type $media
375
 * @return unknown_type
376
 */
377
function taxon_image_gallery_fsi($taxon, $media){
378

    
379
  $flashLink = isset($media[0]);
380

    
381
  if($flashLink){
382

    
383
    $taggedName = $taxon->name->taggedName;
384

    
385
    $nameArray = array();
386
    foreach($taggedName as $taggedText){
387
      if($taggedText->type == 'name'){
388
        $nameArray[] = $taggedText->text;
389
      }
390
    }
391

    
392
    $query = join("%5F", $nameArray) . '%20AND%20EditWP6%20AND%20jpg';
393

    
394
    $out = '
395

    
396
<script type="text/javascript" src="http://media.bgbm.org/erez/js/fsiwriter.js"></script>
397

    
398
<script type="text/javascript">
399
<!--
400
  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=textbox,fullscreen",
401
    "http://media.bgbm.org/erez/erez?src=erez-private/flashrequired.svg&tmp=Large&quality=97&width=620&height=400",
402
    "width=620;height=400;bgcolor=454343;wmode=opaque");
403
// -->
404
</script>
405
<noscript>
406
  <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">
407
    <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=textbox,fullscreen"/>
408
    <param name="bgcolor" value="454343" />
409
    <param name="wmode" value="opaque" />
410
    <param name="allowscriptaccess" value="always" />
411
    <param name="allowfullscreen" value="true" />
412
    <param name="quality" value="high" />
413
    <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,fullscreen"
414
      width="620"
415
      height="400"
416
      bgcolor="454343"
417
      wmode="opaque"
418
      allowscriptaccess="always"
419
      allowfullscreen="true"
420
      quality="high"
421
      type="application/x-shockwave-flash"
422
      pluginspage="http://www.adobe.com/go/getflashplayer">
423
    </embed>
424
  </object>
425

    
426
</noscript>';
427

    
428
  }else{
429
    $out = 'No images available.';
430

    
431
  }
432
  return $out;
433

    
434
}
435
/**
436
 * Show a reference in it's atomized form
437
 */
438
function theme_cdm_reference_page($referenceTO){
439

    
440
	/*
441
	 if($referenceTO->titleCache) {
442
		drupal_set_title($referenceTO->titleCache);
443
		} else {
444
		drupal_set_title($referenceTO->fullCitation);
445
		}
446
		*/
447

    
448
	$field_order = array(
449
    "title",
450
	//"titleCache",
451
	//"citation",
452
    "authorTeam",
453
    "editor",
454
    "publisher",
455
    "placePublished",
456
    "datePublished",
457
    "year",
458
    "edition",      // class Book
459
    "volume",       // class Article
460
    "seriesPart",
461
    "inReference",
462
	//"inJournal",     // class Article
463
	//"inBook",        // class BookSection
464
    "nomRefBase",    // class BookSection, Book, Article
465
	//"inProceedings", // class InProceedings
466
    "pages",         // class Article
467
    "series",        // class Article, PrintSeries
468
    "school",        // class Thesis
469
    "institution",   // class Report
470
    "organization",  // class Proceedings
471
    "nextVersion",
472
    "previousVersion",
473
    "isbn",         // class Book
474
    "issn",         // class Journal
475
    "uri",
476
	);
477
	/*
478
	 $table_rows = array();
479
	 foreach($field_order as $fieldname){
480

    
481
		if(isset($referenceTO->$fieldname)){
482

    
483
		if($fieldname == "datePublished") {
484
		$partial = $referenceTO->$fieldname;
485
		$datePublished = '';
486
		if($partial->start){
487
		//var_dump ($partial->start);
488
		$datePublishedYear = substr($partial->start, 0, 4);
489
		$datePublishedMonth = substr($partial->start, 5, 2);
490

    
491
		if (!(preg_match('#[0-9]#',$datePublishedMonth))){
492
		$datePublishedMonth = '00';
493
		}
494

    
495
		$datePublishedDay = substr($partial->start, 7, 2);
496
		if (!(preg_match('#[0-9]#',$datePublishedDay))){
497
		$datePublishedDay = '00';
498
		}
499
		$datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
500
		}
501
		if($partial->end){
502
		$datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
503
		}
504
		$table_rows[] = array(t(ucfirst(strtolower($fieldname))), $datePublished);
505
		//$datePublished = array(t(ucfirst(strtolower($fieldname))), $datePublished);
506
		} else if(is_object($referenceTO->$fieldname)){
507
		if ($fieldname == "authorTeam"){
508
		$dump = $referenceTO->$fieldname;
509
		$teammembers = "teamMembers";
510
		$team = $dump->$teammembers;
511
		$nameArray = array();
512

    
513
		foreach($team as $member){
514
		if (strlen($member->lastname)> 0){
515
		$nname = $member->lastname;
516
		$name = $nname;
517
		if (strlen($member->firstname)> 0){
518
		$vname = $member->firstname;
519
		$name =$vname." ". $nname;
520
		}
521
		$nameArray[] =$name;
522
		}else{
523
		if (strlen($member->titleCache)> 0){
524
		$nameArray[] = $member->titleCache;
525
		}
526
		}
527
		}
528
		$names = join($nameArray, ", ");
529
		}else if ($fieldname == "inReference"){
530
		$type = $referenceTO ->$fieldname-> type;
531
		$names = $referenceTO-> $fieldname-> titleCache;
532
		switch ($type) {
533
		case "Book":
534
		$fieldname = "in book";
535
		break;
536
		case "Journal":
537
		$fieldname = "in journal";
538
		break;
539
		case "Proceedings":
540
		$fieldname = "in proceedings";
541
		break;
542
		}
543

    
544
		}else{
545
		$names = $referenceTO->$fieldname-> titleCache;
546
		}
547
		$table_rows[] = array(t(ucfirst(strtolower($fieldname))), $names);
548
		//$name = array(t(ucfirst(strtolower($fieldname))), $names);
549

    
550
		} else {
551
		$table_rows[] = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
552
		//$name = array(t(ucfirst(strtolower($fieldname))), $referenceTO->$fieldname);
553
		}
554
		}
555
		}
556
		*/
557

    
558
	//select the type of the reference and find the in Reference attribute
559

    
560
	$referenceData = array(
561
    "title" => NULL,
562
	//"titleCache",
563
	//"citation",
564
    "authorTeam" => NULL,
565
    "editor" => NULL,
566
    "publisher" => NULL,
567
    "placePublished" => NULL,
568
    "datePublished" => NULL,
569
    "year" => NULL,
570
    "edition" => NULL,      // class Book
571
    "volume" => NULL,       // class Article
572
    "seriesPart" => NULL,
573
    "inReference" => NULL,
574
	//"inJournal",     // class Article
575
	//"inBook",        // class BookSection
576
    "nomRefBase" => NULL,    // class BookSection, Book, Article
577
	//"inProceedings", // class InProceedings
578
    "pages" => NULL,         // class Article
579
    "series" => NULL,        // class Article, PrintSeries
580
    "school" => NULL,        // class Thesis
581
    "institution" => NULL,   // class Report
582
    "organization" => NULL,  // class Proceedings
583
    "nextVersion" => NULL,
584
    "previousVersion" => NULL,
585
    "isbn" => NULL,         // class Book
586
    "issn" => NULL,         // class Journal
587
    "uri" => NULL,
588
	);
589

    
590
	foreach($field_order as $fieldname){
591

    
592
		if(isset($referenceTO->$fieldname)){
593
			switch($fieldname){
594
				case "datePublished":
595
					$partial = $referenceTO->$fieldname;
596
					$datePublished = '';
597
					if($partial->start){
598
						$datePublishedYear = substr($partial->start, 0, 4);
599
						$datePublishedMonth = substr($partial->start, 5, 2);
600
						if (!(preg_match('#[0-9]#',$datePublishedMonth))){
601
							$datePublishedMonth = '00';
602
						}
603
						$datePublishedDay = substr($partial->start, 7, 2);
604
						if (!(preg_match('#[0-9]#',$datePublishedDay))){
605
							$datePublishedDay = '00';
606
						}
607
						$datePublished = $datePublishedYear.'-'.$datePublishedMonth.'-'.$datePublishedDay;
608
					}
609
					if($partial->end){
610
						$datePublished = (strlen($datePublished) > 0 ? ' '.t('to').' ' : '').substr($partial->end, 0, 4).'-'.substr($partial->end, 4, 2).'-'.substr($partial->end, 6, 2);
611
					}
612

    
613
					$referenceData[$fieldname] = $datePublishedYear;
614
					break;
615

    
616
				default:
617
					if(is_object($referenceTO->$fieldname)){
618
						if ($fieldname == "authorTeam"){
619
							$dump = $referenceTO->$fieldname;
620
							$teammembers = "teamMembers";
621
							$team = $dump->$teammembers;
622
							$nameArray = array();
623

    
624
							foreach($team as $member){
625
								if (strlen($member->lastname)> 0){
626
									$nname = $member->lastname;
627
									$name = $nname;
628
									if (strlen($member->firstname)> 0){
629
										$vname = $member->firstname;
630
										$name =$vname." ". $nname;
631
									}
632
									$nameArray[] =$name;
633
								}else{
634
									if (strlen($member->titleCache)> 0){
635
										$nameArray[] = $member->titleCache;
636
									}
637
								}
638
							}
639
							$names = join($nameArray, ", ");
640
							$referenceData[$fieldname] = $names;
641
						}else if ($fieldname == "inReference"){
642
							$names = $referenceTO->$fieldname->titleCache;
643
							$referenceData[$fieldname] = $names;
644
						}else{
645
							$names = $referenceTO->$fieldname->titleCache;
646
							$referenceData[$fieldname] = $names;
647
						}
648
					}else{
649
						$referenceData[$fieldname] = $referenceTO->$fieldname;
650
					}
651

    
652
			}
653
		}
654
	}
655
	$author_team =  cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $referenceTO->uuid);
656
	//return "" . ((strlen($referenceData["authorTeam"])>0) ? ($referenceData["authorTeam"] . '. ') : '')
657
	return "" . ((strlen($author_team->titleCache)>0) ? ($author_team->titleCache . '. ') : '')
658
	. ((strlen($referenceData["datePublished"])>0) ? ($referenceData["datePublished"] . '. ') : '')
659
	. ((strlen($referenceData["title"])>0) ? ($referenceData["title"] . '. ') : "")
660
	. ((strlen($referenceData["placePublished"])>0) ? ($referenceData["placePublished"] . '. ') : '')
661
	. ((strlen($referenceData["editor"])>0) ? ($referenceData["editor"] . '. ') : '')
662
	. ((strlen($referenceData["publisher"])>0) ? ($referenceData["publisher"] . '. ') : '')
663
	. ((strlen($referenceData["inReference"])>0) ? ($referenceData["inReference"] . '. ') : '')
664
	. ((strlen($referenceData["series"])>0) ? ($referenceData["series"] . '. ') : '')
665
	. ((strlen($referenceData["volume"])>0) ? ($referenceData["volume"] . '. ') : '')
666
	. ((strlen($referenceData["pages"])>0) ? ($referenceData["pages"] . '. ') : '')
667
	. ((strlen($referenceData["isbn"])>0) ? ($referenceData["isbn"] . '. ') : '')
668
	. ((strlen($referenceData["issn"])>0) ? ($referenceData["issn"] . '. ') : '')
669
	. ((strlen($referenceData["uri"])>0) ? ($referenceData["uri"] . '. ') : '');
670

    
671
}
672

    
673

    
674
function theme_cdm_media_page($media, $mediarepresentation_uuid = false, $partId = false){
675
	$out = '';
676
	// determine which reprresentation and which part to show
677
	$representationIdx = 0;
678
	if($mediarepresentation_uuid){
679
		$i = 0;
680
		foreach($media->representations as $representation) {
681
			if($representation->uuid == $mediarepresentation_uuid){
682
				$representationIdx = $i;
683
			}
684
			$i++;
685
		}
686
	} else {
687
		$mediarepresentation_uuid = $media->representations[0]->uuid;
688
	}
689

    
690
	$partIdx  = 0;
691
	if(!is_numeric($partId)){
692
		// assuming it is an uuid
693
		$i = 0;
694
		foreach($media->representations[$representationIdx]->parts as $part) {
695
			if($part->uuid == $partId){
696
				$partIdx = $i;
697
			}
698
			$i++;
699
		}
700
	} else {
701
		// assuming it is an index
702
		$partIdx = $partId;
703
	}
704

    
705
	$media_metadata = cdm_read_media_metadata($media);
706
	//$title = $media->titleCache;
707
	$title = $media_metadata['title'];
708

    
709
	$imageMaxExtend = variable_get('image-page-maxextend', 400);
710

    
711
	if(!$title){
712
		$title = 'Media '.$media->uuid.'';
713
	}
714

    
715
	drupal_set_title($title);
716

    
717

    
718
	$out .= '<div class="media">';
719

    
720
	//$out .= '<div class="viewer">';
721
	$out .= theme(cdm_back_to_image_gallery_button);
722
	$out .= '<div class="viewer">';
723
	//$out .= theme('cdm_media_gallerie_image', $representation->parts[$partIdx], $imageMaxExtend);
724
	$out .= theme('cdm_openlayers_image', $media->representations[$representationIdx]->parts[$partIdx], $imageMaxExtend);
725
	$out .= '</div>';
726

    
727
	// general media metadata
728
	//$media_metadata = cdm_ws_get(CDM_WS_MEDIA_METADATA, array($media->uuid));
729
	//vardump("PRINTING MEDIA METADATA");
730
	//vardump($media_metadata);
731
	//vardump("PRINTING MEDIA");
732
	//vardump($media);
733
	$metadataToPrint = theme('cdm_media_caption', $media);
734
	$out .= $metadataToPrint;
735

    
736

    
737
	//tabs for the different representations
738
	//ul.secondary
739
	$out .= '<ul class="primary">';
740
	foreach($media->representations as $representation){
741
		$out .= '<li>'.l($media->representations[$representationIdx]->mimeType, path_to_media($media->uuid, $mediarepresentation_uuid, $partIdx)).'</li>';
742
	}
743
	$out .= '</ul>';
744

    
745
	// representation(-part) specific metadata
746
	$thumbnailMaxExtend = 100;
747
	$out .= '<table>';
748
	//$out .= '<tr><th colspan="3">'.t('MimeType').': '.$media->representations[$representationIdx]->mimeType.'</th></tr>';
749
	$i = 0;
750
	foreach($media->representations[$representationIdx]->parts as $part){
751
		$out .= '<tr><th>'.t('Part').' '.($i + 1).'</th><td>';
752
		switch($part->class){
753
			case 'ImageFile': $out .= $part->width.' x '.$part->height.' - '.$part->size.'k'; break;
754
			case 'AudioFile':
755
			case 'MovieFile': $out .= t('Duration').': '.$part->duration.'s - '.$part->size.'k'; break;
756
			default: $out .= $part->size.'k';
757
		}
758
		$out .= '</td><td><a href="'.url(path_to_media($media->uuid, $mediarepresentation_uuid, $i)).'">'.theme('cdm_media_gallerie_image', $part, $thumbnailMaxExtend, true);'</a></td><tr>';
759
		$i++;
760
	}
761
	$out .= '</table>';
762
	$out .= '</div>';
763

    
764
	return $out;
765
}
766

    
767
/**
768
 * Allows theming of the taxon page tabs
769
 *
770
 * @param $tabname
771
 * @return unknown_type
772
 */
773
function theme_cdm_taxonpage_tab($tabname){
774
	//TODO replace by using translations or theme the menue tabs itself instead?
775
	switch($tabname){
776
		default: return t($tabname);
777
	}
778
}
779

    
(6-6/8)