Project

General

Profile

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

    
4
/**
5
 * Overrides of generic themeing functions in cdm_datportal.theme.php
6
 */
7

    
8

    
9
/**
10
 * The description page is supposed to be the front page for a taxon.
11
 *
12
 * @param TaxonTO $taxonTO
13
 * @return
14
 */
15
function garland_cichorieae_cdm_taxon_page_profile($taxon, $mergedTrees, $media, $hideImages = false){
16

    
17
	RenderHints::pushToRenderStack('taxon_page_description');
18
	// description TOC
19
	$out = theme('cdm_featureTreeTOCs', $mergedTrees);
20

    
21
	// preferred image
22
	// 2 lines hard coded for testing
23
	if( variable_get('cdm_dataportal_show_default_image', false) && !$hideImages){
24

    
25
		//$defaultPreferredImage = drupal_get_path('theme', 'garland_cichorieae').'/images/nopic_400x300.jpg';
26
		$defaultRepresentationPart = false;
27
		$defaultRepresentationPart->width = 400;
28
		$defaultRepresentationPart->height = 300;
29
		$defaultRepresentationPart->uri = drupal_get_path('theme', 'garland_cichorieae').'/images/nopic_400x300_4x3cm.jpg';
30

    
31
		$imageUriParams = '&width=400&height=300&quality=95&format=jpeg';
32

    
33
		$imageMaxExtend = 400;
34
		$out .= '<div id="taxonProfileImage">'.theme('cdm_preferredImage', $media, $defaultRepresentationPart, $imageMaxExtend, $imageUriParams).'</div>';
35
	}
36

    
37
	// description
38
	$out .= theme('cdm_featureTrees', $mergedTrees, $taxon);
39
	RenderHints::popFromRenderStack();
40

    
41
	return $out;
42
}
43

    
44
/*
45
 function garland_cichorieae_cdm_descriptionElementTextData($element){
46

    
47
 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
48
 $referenceCitation = '';
49
 $sourceRefs = '';
50

    
51
 if($element->reference){
52
 // disabling references for cichorieae description Elements because they all have faulty references
53
 $referenceCitation = '; '.theme('cdm_fullreference', $element->reference, TRUE);
54
 }
55
 //return '<p class="descriptionText">' . $description . $referenceCitation.'</p>';
56

    
57
 foreach($element->sources as $source){
58
 $referenceCitation = theme('cdm_DescriptionElementSource', $source);
59
 if($description && strlen($description) > 0 && $referenceCitation ){
60
 $sourceRefs .= ' ('.$referenceCitation.')' ;
61
 /*
62
 * TODO: why does not belongs this code to the cichorieae theme ??
63
 *
64
 }else if ($referenceCitation){
65
 $sourceRefs = $referenceCitation;
66
 }
67
 }
68
 return '<p class="descriptionText">' . $description . $sourceRefs . '</p>';
69
 }
70
 */
71
function garland_cichorieae_cdm_descriptionElementTextData($element, $asListElement, $feature_uuid){
72

    
73
	$description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
74
	$sourceRefs = '';
75
	$result = array();
76
	$res_author;
77
	$res_date;
78
	$no_links = false;
79
	$default_theme = variable_get('theme_default', 'garland_cichorieae');
80

    
81
	if (($default_theme == 'flora_malesiana' || $default_theme == 'flore_afrique_centrale')
82
	    && $element->feature->titleCache == 'Citation'){
83
		$asListElement = true;
84
	}elseif ($element->feature->uuid == UUID_CHROMOSOMES_NUMBERS){
85
	   	$asListElement = true;
86
	}else{
87
		$asListElement = false;
88
	}
89

    
90
	    //printing annotations footnotes
91
    $annotation_fkeys =  theme('cdm_annotations_as_footnotekeys', $element, $feature_uuid);
92

    
93
	if ($feature_uuid == UUID_NAME_USAGE || $feature_uuid == UUID_CHROMOSOMES){
94
		$no_links = true;
95
	}
96

    
97
	if(is_array($element->sources)){
98
		foreach($element->sources as $source){
99
			//initialize some variables
100
			if ($feature_uuid == UUID_NAME_USAGE){
101
				$referenceCitation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
102
				                                array($source->citation->uuid),
103
									            "microReference=".urlencode($source->citationMicroReference));
104
				$referenceCitation = $referenceCitation->String;
105
			}else{
106
				$referenceCitation = theme('cdm_DescriptionElementSource',
107
			                               $source,
108
									       ($no_links) ? false : true);
109
			}
110
			if($description && strlen($description) > 0 && $referenceCitation ){
111
				$sourceRefs .= ' ('.$referenceCitation.')' ;
112
			}else if ($referenceCitation){
113
				$sourceRefs = $referenceCitation;
114
			}
115
			//generate the output
116
			if(strlen($sourceRefs) > 0){
117
				$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
118
			}
119
			if ($source->nameUsedInSource->uuid && ($feature_uuid != UUID_NAME_USAGE)){
120
				//do a link to name page
121
				$name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
122
												  path_to_name($source->nameUsedInSource->uuid),
123
												  array(), NULL, NULL, FALSE ,TRUE);
124
			}else if ($source->nameUsedInSource->uuid && ($feature_uuid == UUID_NAME_USAGE)){
125
				//do not do link for NAME USAGE feature
126
				$name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
127
			}else if (strlen($source->nameUsedInSource->originalNameString) > 0){
128
				//show a text without link
129
				$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
130
			}
131

    
132
			if($asListElement && ($feature_uuid == UUID_NAME_USAGE)){
133
				$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
134
				//adding ":" if necesary
135
				if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
136
					$out .= ': ';
137
				}
138
				$out .= $description . $sourceRefs .theme('cdm_annotations_as_footnotekeys', $element, $feature_uuid) . $annotation_fkeys . '</li>';
139
			}else if ($asListElement){
140
				$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
141
				//adding ":" if necesary
142
				if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
143
					$out .= ': ';
144
				}
145
				$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element, $feature_uuid) . $annotation_fkeys . '</li>';
146
			//special handling for flora malesiana TODO: possible better way to implement this case?
147
			}else{
148
				if ($name_used_in_source_link_to_show){
149
					$name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
150
				}
151
				$out = '<span class="'. html_class_atttibute_ref($element) . '"> '. $description . $sourceRefs . $name_used_in_source_link_to_show . $annotation_fkeys. '</span>';
152
			}
153
		}
154
	}
155

    
156
    //if no sources, print the description
157
    if(!isset($out)) {
158
      $out = '<span class="'. html_class_atttibute_ref($element) . '"> ' . $description . $annotation_fkeys. '</span>';
159
    }
160

    
161
/*
162
	if ($feature_uuid == UUID_NAME_USAGE){
163
		foreach($element->sources as $source){
164
			$referenceCitation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
165
			                                array($source->citation->uuid),
166
								            "microReference=".urlencode($source->citationMicroReference));
167
			$referenceCitation = $referenceCitation->String;
168
			if($description && strlen($description) > 0 && $referenceCitation ){
169
				$sourceRefs .= ' ('.$referenceCitation.')' ;
170
			}else if ($referenceCitation){
171
				$sourceRefs = $referenceCitation;
172
			}
173
		}
174
	}else{
175
		foreach($element->sources as $source){
176
			$referenceCitation = theme('cdm_DescriptionElementSource',
177
		                               $source,
178
								       ($feature_uuid == UUID_NAME_USAGE) ? false : true);
179
			if($description && strlen($description) > 0 && $referenceCitation ){
180
				$sourceRefs .= ' ('.$referenceCitation.')' ;
181
			}else if ($referenceCitation){
182
				$sourceRefs = $referenceCitation;
183
			}
184
		}
185
	}
186

    
187
	if(strlen($sourceRefs) > 0){
188
		$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
189
	}
190

    
191
	if ($source->nameUsedInSource->uuid && ($feature_uuid != UUID_NAME_USAGE)){
192
	//do a link to name page
193
		$name_used_in_source_link_to_show = l($source->nameUsedInSource->titleCache,
194
											  path_to_name($source->nameUsedInSource->uuid),
195
											  array(), NULL, NULL, FALSE ,TRUE);
196
	}else if ($source->nameUsedInSource->uuid && ($feature_uuid == UUID_NAME_USAGE)){
197
	//do not do link for NAME USAGE feature
198
		$name_used_in_source_link_to_show = $source->nameUsedInSource->titleCache;
199
	}else if (strlen($source->nameUsedInSource->originalNameString) > 0){
200
	//show a text without link
201
		$name_used_in_source_link_to_show = $source->nameUsedInSource->originalNameString;
202
	}
203

    
204
	if($asListElement && ($feature_uuid == UUID_NAME_USAGE)){
205
		$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
206
		//adding ":" if necesary
207
		if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
208
			$out .= ': ';
209
		}
210
		$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
211
	}else if ($asListElement){
212
		$out = '<li class="descriptionText">' . $name_used_in_source_link_to_show;
213
		//adding ":" if necesary
214
		if ($name_used_in_source_link_to_show && ($description || $sourceRefs)){
215
			$out .= ': ';
216
		}
217
		$out .= $description . $sourceRefs . theme('cdm_annotations_as_footnotekeys', $element) . '</li>';
218
	//special handling for flora malesiana TODO: possible better way to implement this case?
219
	}else{
220
		if ($name_used_in_source_link_to_show){
221
			$name_used_in_source_link_to_show = ' (name in source: '. $name_used_in_source_link_to_show . ')';
222
		}
223
		$out = $description . $sourceRefs . $name_used_in_source_link_to_show;
224
		$out .= theme('cdm_annotations_as_footnotekeys', $element);
225
	}
226
*/
227
	// add annotations as footnote key
228
	//$out .= theme('cdm_annotations_as_footnotekeys', $element); move above
229

    
230
	return $out;
231
}
232

    
233

    
234

    
235
/**
236
 * @overrides theme_cdm_taggedtext2html in order to replace t.infr and t.infgen. with '[unranked]'
237
 */
238
function garland_cichorieae_cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
239
	$out = '';
240
	$i = 0;
241
	foreach($taggedtxt as $tt){
242
		if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
243
			$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">';
244
			if($tt->type == "rank" && ($tt->text == "t.infr." || $tt->text == "t.infgen.")){
245
				$out .= t('[unranked]');
246
			}else{
247
				$out .= t($tt->text);
248
			}
249
			$out .= '</'.$tag.'>';
250
		}
251
	}
252
	return $out;
253
}
254

    
255
function garland_cichorieae_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
256
	$enclosingHtml = 'div';
257
	$out = '<'.$enclosingHtml.' class="description" id="'.$feature->representation_L10n.'">';
258

    
259
	if($sortArray) sort($elementArray);
260

    
261
	$out .= join($elementArray, $glue);
262

    
263
	$out .= '</'.$enclosingHtml.'>';
264
	return $out;
265
}
266

    
267

    
268
/**
269
 * all reference links switched of
270
 */
271
function garland_cichorieae_cdm_nomenclaturalReferenceSTO($referenceSTO, $doLink = FALSE, $cssClass = '', $separator = '<br />' , $enclosingTag = 'li'){
272

    
273
	$doLink = FALSE;
274

    
275
	if(isset($referenceSTO->microReference)){
276
		// it is a ReferenceTO
277
		$nomref_citation = theme('cdm_fullreference', $referenceSTO);
278
	} else {
279
		// it is ReferenceSTO
280
		$nomref_citation = $referenceSTO->fullCitation;
281
	}
282

    
283
	$is_IN_reference = str_beginsWith($nomref_citation, 'in');
284

    
285
	if($doLink){
286
		$nomref_citation = l($nomref_citation, "/cdm_dataportal/reference/".$referenceSTO->uuid, array(), NULL, NULL, FALSE, TRUE);
287
	}
288

    
289
	if(!empty($nomref_citation)){
290
		$nomref_citation = ($is_IN_reference ? '&nbsp;':',&nbsp;') . $nomref_citation;
291
	}
292

    
293
	return $nomref_citation;
294
}
295

    
296

    
297
/***** GARLAND OVERRIDES ******/
298

    
299
/**
300
 * Sets the body-tag class attribute.
301
 *
302
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
303
 */
304
function phptemplate_body_class($sidebar_left, $sidebar_right) {
305
	if ($sidebar_left != '' && $sidebar_right != '') {
306
		$class = 'sidebars';
307
	}
308
	else {
309
		if ($sidebar_left != '') {
310
			$class = 'sidebar-left';
311
		}
312
		if ($sidebar_right != '') {
313
			$class = 'sidebar-right';
314
		}
315
	}
316

    
317
	if (isset($class)) {
318
		print ' class="'. $class .'"';
319
	}
320
}
321

    
322
/**
323
 * Return a themed breadcrumb trail.
324
 *
325
 * @param $breadcrumb
326
 *   An array containing the breadcrumb links.
327
 * @return a string containing the breadcrumb output.
328
 */
329
function phptemplate_breadcrumb($breadcrumb) {
330
	if (!empty($breadcrumb)) {
331
		return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
332
	}
333
}
334

    
335
/**
336
 * Allow themable wrapping of all comments.
337
 */
338
function phptemplate_comment_wrapper($content, $type = null) {
339
	static $node_type;
340
	if (isset($type)) $node_type = $type;
341

    
342
	if (!$content || $node_type == 'forum') {
343
		return '<div id="comments">'. $content . '</div>';
344
	}
345
	else {
346
		return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
347
	}
348
}
349

    
350
/**
351
 * Override or insert PHPTemplate variables into the templates.
352
 */
353
function _phptemplate_variables($hook, $vars) {
354
	if ($hook == 'page') {
355

    
356
		if ($secondary = menu_secondary_local_tasks()) {
357
			$output = '<span class="clear"></span>';
358
			$output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
359
			$vars['tabs2'] = $output;
360
		}
361

    
362
		// Hook into color.module
363
		if (module_exists('color')) {
364
			_color_page_alter($vars);
365
		}
366
		return $vars;
367
	}
368
	return array();
369
}
370

    
371
/**
372
 * Returns the rendered local tasks. The default implementation renders
373
 * them as tabs.
374
 *
375
 * @ingroup themeable
376
 */
377
function phptemplate_menu_local_tasks() {
378
	$output = '';
379

    
380
	if ($primary = menu_primary_local_tasks()) {
381
		$output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
382
	}
383

    
384
	return $output;
385
}
386

    
387
function garland_cichorieae_get_partDefinition($nameType){
388
	if($nameType == 'BotanicalName'){
389
		return array(
390
        'namePart' => array(
391
          'name' => true
392
		),
393
        'nameAuthorPart' => array(
394
          'name' => true,
395
          'authors' => true
396
		),
397
        'referencePart' => array(
398
          'reference' => true,
399
          'microreference' => true,
400
		),
401
        'statusPart' => array(
402
          'status' => true,
403
		),
404
        'descriptionPart' => array(
405
          'description' => true,
406
		),
407
		);
408
	}
409
	return false;
410
}
411

    
412
function garland_cichorieae_get_nameRenderTemplate($renderPath){
413

    
414
	switch($renderPath) {
415
		case 'taxon_page_title':
416
		case 'polytomousKey':
417
			$template = array(
418
            'namePart' => array('#uri'=>true)
419
			);
420
			break;
421
		case 'taxon_page_synonymy':
422
		case 'related_taxon':
423
			$template = array(
424
          'nameAuthorPart' => array('#uri'=>true),
425
          'referencePart' => true,
426
          'statusPart' => true,
427
          'descriptionPart' => true
428
			);
429
			break;
430
		case 'acceptedFor':
431
			$template = array(
432
            'nameAuthorPart' => array('#uri'=>true),
433
            'referencePart' => true
434
			);
435
			break;
436
		case 'typedesignations':
437
		case 'list_of_taxa':
438
		case '#DEFAULT':
439
			$template = array(
440
            'nameAuthorPart' => array('#uri'=>true),
441
            'referencePart' => true
442
			);
443
	}
444
	return $template;
445
}
446

    
447
/**
448
 * theme specific mods:
449
 * 	$captionElements = array('title', '#uri'=>t('open Image'));
450
 * 	$mediaLinkType:
451
 *      "NORMAL": link to the image page or to the $alternativeMediaUri if it is defined
452
 *      instead of
453
 *      "LIGHTBOX": open the link in a light box,
454
 * TODO expose those in admin section, by adding 'em to gallery_settings see http://dev.e-taxonomy.eu/trac/ticket/2494
455
 */
456
function garland_cichorieae_cdm_taxon_list_thumbnails($taxon){
457

    
458

    
459
	$gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
460

    
461
	$mediaLinkType = 'NORMAL';
462
	$showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
463
	if($showCaption){
464
		$captionElements = array('title', '#uri'=>t('open Image'));
465
	}
466

    
467
	$gallery_name = $taxon->uuid;
468

    
469
 	$mediaQueryParameters = array("type"=>"ImageFile");
470
	$galleryLinkUri = path_to_taxon($taxon->uuid).'/images';
471

    
472
    // cdm_dataportal_show_media = ???? TODO
473
	$selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
474
	if ($selectShowMedia == 0){
475
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
476
	}else{
477
		$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
478
	}
479

    
480
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name,
481
    	$gallery_settings['cdm_dataportal_media_maxextend'],
482
    	$gallery_settings['cdm_dataportal_media_cols'],
483
    	$gallery_settings['cdm_dataportal_media_maxRows'],
484
	    $captionElements, $mediaLinkType, $galleryLinkUri, null);
485

    
486
	return $out;
487
}
488

    
489
function garland_cichorieae_cdm_feature_name($feature_name){
490
  switch($feature_name){
491
    case "Protologue": return t("Original Publication");
492
    default: return t(ucfirst($feature_name));
493
  }
494
}
495

    
496
/* ======================== Special functions for subtheme handling ================  */
497

    
498
function sub_theme() {
499
	global $user, $custom_theme;
500

    
501
	// Only select the user selected theme if it is available in the
502
  // list of enabled themes.
503
  $theme = $user->theme && $themes[$user->theme]->status ? $user->theme : variable_get('theme_default', 'garland');
504

    
505
  // Allow modules to override the present theme... only select custom theme
506
  // if it is available in the list of installed themes.
507
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
508

    
509
  return $theme;
510
}
511

    
512

    
513
/**
514
 * Return the path to the currently selected sub theme.
515
 */
516
function path_to_sub_theme() {
517
  $themes = list_themes();
518
  $theme = sub_theme();
519
  return dirname($themes[$theme]->filename);
520
}
(12-12/13)