Project

General

Profile

Download (8.81 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id: template.php,v 1.4.2.1 2007/04/18 03:38:59 drumm Exp $
3

    
4
/**
5
 * Sets the body-tag class attribute.
6
 *
7
 * Adds 'sidebar-left', 'sidebar-right' or 'sidebars' classes as needed.
8
 */
9
function phptemplate_body_class($sidebar_left, $sidebar_right) {
10
  if ($sidebar_left != '' && $sidebar_right != '') {
11
    $class = 'sidebars';
12
  }
13
  else {
14
    if ($sidebar_left != '') {
15
      $class = 'sidebar-left';
16
    }
17
    if ($sidebar_right != '') {
18
      $class = 'sidebar-right';
19
    }
20
  }
21

    
22
  if (isset($class)) {
23
    print ' class="'. $class .'"';
24
  }
25
}
26

    
27
/**
28
 * Return a themed breadcrumb trail.
29
 *
30
 * @param $breadcrumb
31
 *   An array containing the breadcrumb links.
32
 * @return a string containing the breadcrumb output.
33
 */
34
function phptemplate_breadcrumb($breadcrumb) {
35
  if (!empty($breadcrumb)) {
36
    return '<div class="breadcrumb">'. implode(' › ', $breadcrumb) .'</div>';
37
  }
38
}
39

    
40
/**
41
 * Allow themable wrapping of all comments.
42
 */
43
function phptemplate_comment_wrapper($content, $type = null) {
44
  static $node_type;
45
  if (isset($type)) $node_type = $type;
46

    
47
  if (!$content || $node_type == 'forum') {
48
    return '<div id="comments">'. $content . '</div>';
49
  }
50
  else {
51
    return '<div id="comments"><h2 class="comments">'. t('Comments') .'</h2>'. $content .'</div>';
52
  }
53
}
54

    
55
/**
56
 * Override or insert PHPTemplate variables into the templates.
57
 */
58
function _phptemplate_variables($hook, $vars) {
59
  if ($hook == 'page') {
60

    
61
    if ($secondary = menu_secondary_local_tasks()) {
62
      $output = '<span class="clear"></span>';
63
      $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
64
      $vars['tabs2'] = $output;
65
    }
66

    
67
    // Hook into color.module
68
    if (module_exists('color')) {
69
      _color_page_alter($vars);
70
    }
71
    return $vars;
72
  }
73
  return array();
74
}
75

    
76
/**
77
 * Returns the rendered local tasks. The default implementation renders
78
 * them as tabs.
79
 *
80
 * @ingroup themeable
81
 */
82
function phptemplate_menu_local_tasks() {
83
  $output = '';
84

    
85
  if ($primary = menu_primary_local_tasks()) {
86
    $output .= "<ul class=\"tabs primary\">\n". $primary ."</ul>\n";
87
  }
88

    
89
  return $output;
90
}
91

    
92
/**
93
 * This function sort an array of description elements where all the elements
94
 * are of type UUID_CITATION. The sorting is done based at first on the title
95
 * cache of the author and second of the date of the publication.
96
 * @param $x An element of the array
97
 * @param $y An element of the array
98
 * @return array The sortered description elements array
99
 */
100
function compare_citations($x, $y)
101
{
102
	
103
	if( !$x->sources[0]->citation->uuid){// && !$y->sources[0]->citation->uuid){
104
		$res = -1;
105
		//var_dump($y->sources[0]->citation->uuid);
106
	}elseif(!$y->sources[0]->citation->uuid){
107
		$res = 1;
108
		//var_dump($x->sources[0]->citation->uuid);
109
	}
110
	else{
111
		
112
	
113
  $author_team_x = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $x->sources[0]->citation->uuid);
114
  $author_team_y = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $y->sources[0]->citation->uuid);
115

    
116
	 //same author, and different year
117
	if($author_team_x->titleCache == $author_team_y->titleCache){   	
118
		$x_year = substr(
119
		        $x->sources[0]->citation->datePublished->start,
120
		        0,
121
		        strpos($x->sources[0]->citation->datePublished->start,'-'));
122
		$y_year = substr(
123
		          $y->sources[0]->citation->datePublished->start,
124
		          0,
125
		          strpos($y->sources[0]->citation->datePublished->start,'-'));
126
		if ($x_year < $y_year){//the year of the first publication is smaller
127
			$res = -1;
128
		}
129
		else if($x_year == $y_year){ //if same year check the page
130
			$x_page = $x->sources[0]->citationMicroReference;
131
			$y_page = $y->sources[0]->citationMicroReference;
132
			if($x_page < $y_page){
133
				$res = -1;
134
			}
135
			else{
136
				$res = 1;
137
			}
138
		}else
139
		$res = 1;
140
	}
141
	//different author and the first one is alphabetically smaller
142
	//else if($x->sources[0]->citation->authorTeam->teamMembers[0]->lastname <
143
	//$y->sources[0]->citation->authorTeam->teamMembers[0]->lastname){
144
	else if ($author_team_x->titleCache < $author_team_y->titleCache)	{
145
		$res = -1;
146
	}
147
	//different author and the second one is alphabetically smaller
148
	else{
149
		$res = 1;
150
	}
151
	
152
  }
153
	//var_dump($res);
154
	//var_dump(' ============ ');
155
	return $res;
156
}
157

    
158

    
159
function garland_diptera_cdm_descriptionElements($descriptionElements){
160

    
161
  $outArray = array();
162
  $glue = '';
163
  $sortOutArray = false;
164
  $enclosingHtml = 'ul';
165
  
166
	$citations = array();
167

    
168
  // only for diptera
169
  if(isset($descriptionElements[0]) && $descriptionElements[0]->feature->uuid == UUID_CITATION ) {
170
    foreach($descriptionElements as $element){
171
      $tokens = split(":", $element->multilanguageText_L10n->text);
172
      if(count($tokens) == 2){
173
        // token[0]: taxon name; token[1]: note; 
174
        $element->multilanguageText_L10n->text = $tokens[1] . ' [<span class="name">' . $tokens[0] . '</span>]';
175
      }
176
      if(isset($element->citation->datePublished->start)){
177
        $elementMap[partialToYear($element->citation->datePublished->start)] = $element;
178
      } else {
179
        $elementMap[] = $element;
180
      }
181
    }
182
    $success = ksort($elementMap);
183
    $descriptionElements = $elementMap;
184
  }
185
  // ---
186
	usort($descriptionElements, 'compare_citations');
187
  foreach($descriptionElements as $element){
188
    if($element->class == 'TextData'){
189
      $asListElement = true;
190
      $outArray[] = theme('cdm_descriptionElementTextData', $element, $asListElement);
191
    }else if($element->class == 'Distribution'){
192
      if( !array_search($element->area->representation_L10n, $outArray)){
193
        $outArray[] = $element->area->representation_L10n;
194
        $glue = ', ';
195
        $sortOutArray = true;
196
        $enclosingHtml = 'p';
197
      }
198
    }else{
199
      $outArray[] = '<li>No method for rendering unknown description class: '.$element->classType.'</li>';
200
    }
201
  }
202

    
203
  return theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
204
}
205

    
206
/**
207
 * Allows theaming of the taxon page tabs
208
 * 
209
 * @param $tabname
210
 * @return unknown_type
211
 */
212
function garland_diptera_cdm_taxonpage_tab($tabname){
213
  switch($tabname){
214
    case 'Synonymy' : return t('Nomenclature'); break;
215
    default : return t($tabname); 
216
  }
217
}
218

    
219
function garland_diptera_cdm_feature_name($feature_name){
220
  switch($feature_name){
221
    case "Citation": return t("Citations");
222
		case 'Has orthographic variant': return t("Misspellings");
223
    default: return t(ucfirst($feature_name));
224
  }
225
}
226

    
227

    
228
function garland_diptera_get_partDefinition($nameType){
229
  
230
  if($nameType == 'ZoologicalName'){
231
    return array(
232
        'namePart' => array(
233
          'name' => true
234
        ),
235
        'nameAuthorPart' => array(
236
          'name' => true,
237
          'authors' => true
238
        ),
239
        'referencePart' => array(
240
         'authors' => true,
241
         'microreference' => true
242
        ),
243
        'statusPart' => array(
244
          'status' => true,
245
        ),
246
        'descriptionPart' => array(
247
          'description' => true,
248
        ),
249
      );
250
  }
251
  return false;
252
}
253

    
254
function garland_diptera_get_nameRenderTemplate($renderPath){
255
  
256
  switch ($renderPath){
257
    case 'taxon_page_title': 
258
      $template = array(
259
          'namePart' => array('#uri'=>true),
260
        );
261
      break;
262
    case  'acceptedFor':
263
    case 'list_of_taxa': 
264
      $template = array(
265
        'namePart' => array('#uri'=>true),
266
        'referencePart' => array('#uri'=>true),
267
      );
268
      break;
269
    case 'typedesignations': 
270
      $template = array(
271
        'namePart' => array('#uri'=>true),
272
        'referencePart' => array('#uri'=>true)
273
      );
274
      break;
275
    case 'taxon_page_synonymy':
276
    case 'related_taxon':
277
    case '#DEFAULT':
278
      $template = array(
279
        'namePart' => array('#uri'=>true),
280
        'referencePart' => array('#uri'=>true),
281
        'statusPart' => true,
282
        'descriptionPart' => true
283
      );
284
  }
285
  return $template;
286
}
287

    
288
function garland_diptera_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
289

    
290
    //ev. delegate to theme_cdm_ReferencedEntityBase
291
    $out = '';
292
    if($descriptionElementSource->citation){
293
      $datePublished = $descriptionElementSource->citation->datePublished;
294
      if (strlen($datePublished->start) >0){
295
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
296
      }
297

    
298
        $author_team = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $descriptionElementSource->citation->uuid);
299
        $author_team_titlecache = $author_team->titleCache;
300
        if (strlen($year)>0){
301
          $reference = $author_team_titlecache.' '. $year;
302
        }else {
303
          $reference = $author_team_titlecache ;
304
        }
305

    
306
      if($doLink){
307
        $out = l('<span class="reference">'.$reference.'</span>'
308
          , path_to_reference($descriptionElementSource->citation->uuid)
309
          , array("class"=>"reference")
310
          , NULL, NULL, FALSE ,TRUE);
311
      } else {
312
       $out = $reference;
313
      }
314
      if($descriptionElementSource->citationMicroReference){
315
        $out .= ': '. $descriptionElementSource->citationMicroReference;
316
      }
317
    }
318
    return $out;
319
}
(18-18/18)