Project

General

Profile

Download (15.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_description($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 class="preferredImage">'.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
	if ($feature_uuid == UUID_NAME_USAGE || $feature_uuid == UUID_CHROMOSOMES){
91
		$no_links = true;
92
	}
93

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

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

    
153
    //if no sources, print the description
154
    if(!isset($out)) {
155
      $out = $description;
156
    }
157
    //printing annotations footnotes
158
    $out .= theme('cdm_annotations_as_footnotekeys', $element);
159
/*
160
	if ($feature_uuid == UUID_NAME_USAGE){
161
		foreach($element->sources as $source){
162
			$referenceCitation = cdm_ws_get(CDM_WS_NOMENCLATURAL_REFERENCE_CITATION,
163
			                                array($source->citation->uuid),
164
								            "microReference=".urlencode($source->citationMicroReference));
165
			$referenceCitation = $referenceCitation->String;
166
			if($description && strlen($description) > 0 && $referenceCitation ){
167
				$sourceRefs .= ' ('.$referenceCitation.')' ;
168
			}else if ($referenceCitation){
169
				$sourceRefs = $referenceCitation;
170
			}
171
		}
172
	}else{
173
		foreach($element->sources as $source){
174
			$referenceCitation = theme('cdm_DescriptionElementSource',
175
		                               $source,
176
								       ($feature_uuid == UUID_NAME_USAGE) ? false : true);
177
			if($description && strlen($description) > 0 && $referenceCitation ){
178
				$sourceRefs .= ' ('.$referenceCitation.')' ;
179
			}else if ($referenceCitation){
180
				$sourceRefs = $referenceCitation;
181
			}
182
		}
183
	}
184

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

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

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

    
228
	return $out;
229
}
230

    
231

    
232

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

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

    
257
	if($sortArray) sort($elementArray);
258

    
259
	$out .= join($elementArray, $glue);
260

    
261
	$out .= '</'.$enclosingHtml.'>';
262
	return $out;
263
}
264

    
265

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

    
271
	$doLink = FALSE;
272

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

    
281
	$is_IN_reference = str_beginsWith($nomref_citation, 'in');
282

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

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

    
291
	return $nomref_citation;
292
}
293

    
294

    
295
/***** GARLAND OVERRIDES ******/
296

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

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

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

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

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

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

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

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

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

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

    
382
	return $output;
383
}
384

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

    
410
function garland_cichorieae_get_nameRenderTemplate($renderPath){
411

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

    
445
/**
446
 */
447
function garland_cichorieae_cdm_taxon_list_thumbnails($taxon){
448

    
449
	$gallery_name = $taxon->uuid;
450

    
451
	$showCaption = variable_get('cdm_dataportal_findtaxa_show_thumbnail_captions', 0);
452
	$prefMimeTypeRegex = 'image:.*';
453
	$prefMediaQuality = '*';
454
	$cols = variable_get('cdm_dataportal_findtaxa_media_cols', 3);
455
	$maxRows = variable_get('cdm_dataportal_findtaxa_media_maxRows', 1);
456
	$maxExtend = variable_get('cdm_dataportal_findtaxa_media_maxextend', 120);
457

    
458
	if($showCaption){
459
		$captionElements = array('title', '#uri'=>t('open Image'));
460
	}
461

    
462
	$mediaQueryParameters = array("type"=>"ImageFile");
463
	$mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString($mediaQueryParameters));
464
	$out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,$maxExtend, $cols, $maxRows, $captionElements, 'NORMAL', $galleryLinkUri, null);
465

    
466
	return $out;
467
}
468

    
469
function garland_cichorieae_cdm_feature_name($feature_name){
470
  switch($feature_name){
471
    case "Protologue": return t("Original Publication");
472
    default: return t(ucfirst($feature_name));
473
  }
474
}
475

    
476
/* ======================== Special functions for subtheme handling ================  */
477

    
478
function sub_theme() {
479
	global $user, $custom_theme;
480

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

    
485
  // Allow modules to override the present theme... only select custom theme
486
  // if it is available in the list of installed themes.
487
  $theme = $custom_theme && $themes[$custom_theme] ? $custom_theme : $theme;
488

    
489
  return $theme;
490
}
491

    
492

    
493
/**
494
 * Return the path to the currently selected sub theme.
495
 */
496
function path_to_sub_theme() {
497
  $themes = list_themes();
498
  $theme = sub_theme();
499
  return dirname($themes[$theme]->filename);
500
}
(12-12/13)