Project

General

Profile

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

    
4
require_once('cdm/cdm_api.php');
5

    
6
function tagNameParts($name, $numOfNameTokens){
7
    
8
    $out = '<span class="name">';
9
    
10
    $token = strtok($name, " \n\t");
11
    $i = 0;
12
    $noSpace = true;
13
    while($token != false){
14
        if($i == $numOfNameTokens){
15
            $out .= '</span> <span class="authors">';
16
            $noSpace = true;
17
        }
18
        $out .= ($noSpace?'':' ').$token;
19
        $noSpace = false;
20
        $token = strtok(" \n\t");
21
        $i++;
22
    }
23
    return $out.'</span>';
24
}
25

    
26
/**
27
 * Renders the full name string (complete scientific name including the author team)
28
 *  
29
 * @param NameTO $nameTO the taxon name
30
 */
31
function theme_cdm_name($nameTO){
32
    //TODO: how to respect the different subtypes of eu.etaxonomy.cdm.model.name.TaxonNameBase ?
33
    $out = '<h2>Dummy content</h2>';
34
    
35
    $testo->fld = array('a'=>'A', 'b'=>'B');
36
    $tfld = $testo->fld; 
37
    
38
    if($nameTO){
39
      foreach($nameTO->taggedName as $ti){
40
        $out .= $ti->tag.'=&gt;'.$ti->text.'<br />';
41
      }
42
      $tn = $nameTO->taggedName;
43
      $out .= '<pre>'.print_r($nameTO, true).'</pre>';
44
      $out .= '<div>'.$nameTO->ws_url.'</div>';
45
      $out .= '<div>'.cdm_taggedtext2html($tn).'</div>';
46
    } else {
47
      $out .= '<div>Item not found</div>';
48
    }
49
    return $out;
50
}
51

    
52
/**
53
 * Renders the given TaxonTO. The $enclosingTag (if not set false)
54
 * will get the following class attributes:
55
 * - name
56
 * - acceptet (only if $ptaxon is an accepted name)
57
 * 
58
 * @param TaxonTO $taxon
59
 * @param boolean $noSecundum defaults to false. If set to true the secundum part is omitted.
60
 * @param string $enclosingTag defaults to span.
61
 * @param boolean $showNomRef whether to dispülay the nomenclatural reference
62
 * @return string of XHTML
63
 * 
64
 * usage: taxon_detail, theme_ptname_link
65
 */
66
function theme_cdm_taxon(TaxonTO $taxon, $noSecundum = true ,$enclosingTag = 'span', $showNomRef = false){
67

    
68
    /* TODO: port me
69
    $refSecundum = false;
70
    if(!$noSecundum && $taxon->ref){
71
        $refSecundum = str_trunk($ptaxon->ref, 40, '...');
72
    }
73
	*/
74
    $out = theme('cdm_name', $taxon)
75
	    .($refSecundum ? '&nbsp;<span class="secundum">sec. '.$refSecundum.'</span>': '')
76
	    .$ptaxon->namePhrase;
77
    /* TODO: port me
78
    if($showNomRef){
79
        $out .= (str_beginsWith($ptaxon->nomRef, 'in') || trim($ptaxon->nomRef) == '' ? '&nbsp;':',&nbsp;').theme('cdm_nomRef',$taxon);
80
    }
81
    if($enclosingTag){
82
        $out = '<'.$enclosingTag.' class="name'.($ptaxon->isAccepted()?' accepted':'').'"><!-- ['.$ptaxon->nameId.'|'.$ptaxon->refId.'] -->'.$out.'</'.$enclosingTag.'>';
83
    }
84
    */
85
    
86
    return $out;
87
    
88
}
89

    
90
/**
91
 * Renders a link to the taxon detail page for the given $taxon 
92
 *
93
 * @param TaxonTO $taxon
94
 */
95
function theme_cdm_taxon_link(TaxonTO $taxon, $fragment = '', $showNomRef = false){
96
    
97
    if($fragment){
98
        $fragment = '#'.$fragment;
99
    }
100

    
101
    if(!$taxon->isAccepted) { 
102
        $out = 'ERROR: theme_cdm_taxon_link() not accepted ptname; status:'.$taxon->status.$out;
103
    }
104
    
105
    $out = l(theme('cdm_taxon', $taxon, true, false), 'taxon', array('class'=>'accepted'), "uuid=$taxon->uuid", $fragment);
106
    
107
    if($showNomRef){
108
       $out .=' '.theme('cdm_nomRef', $ptaxon);
109
    }
110
	
111
	return $out;
112
}
113

    
114
//TODO: port everything below
115

    
116
/**
117
 * Renders a list of synonyms including misapplied names which are related to the 
118
 * given TAXIC_PTaxon.
119
 *
120
 * @param TAXIC_PTaxon $ptaxon
121
 * @param boolean $recursive default is false. Whether to crawl recursively into the
122
 * three of relations
123
 * 
124
 * usage taxon_detail.php.inc
125
 */
126
function render_synonyms(TAXIC_PTaxon $ptaxon, $recursive = false, $showNotes = false){
127

    
128
    $_debug = false;
129
    
130
    $is_higher_rank = $ptaxon->rankId < 60;
131
  
132
    
133
    $out = false;
134
    $last_relQualifierId = false;
135
    $last_was_heterotypic = false;
136
    $last_basionym_nameId = false;
137
    $is_other_basionym = false;
138
    
139
    $synonyms = findSynonyms($ptaxon->nameId, $ptaxon->refId, false, $recursive);
140

    
141
    foreach($synonyms AS $relpt){ // -- relations loop
142
             
143
      // whether this is the first entry in the lsit
144
      $is_first_entry = $out === false;
145
      
146
      // whether the current taxon has another basionym than the last one
147
      $is_other_basionym = $last_basionym_nameId !== false  
148
        && ($last_basionym_nameId !== $relpt->basionymNameId)
149
        && $relpt->relQualifierId != 3;
150
      
151
      // whether the current taxon has another name ralation than the last one
152
      $is_other_relQualifierId = $last_relQualifierId !== false && ($last_relQualifierId !== $relpt->relQualifierId);
153

    
154
      //is here the end of list of homotypic end of heterotypic subsection?  
155
      //$end_of_section = ($last_relQualifierId !== false && $is_other_basionym);
156
      $end_of_section = !$is_first_entry && $is_other_basionym || $is_other_relQualifierId && $relpt->relQualifierId == 3 /* misaplied */;
157

    
158
      // name relations declared as synomyn (id=2) are assumed to be heterotypic
159
      $is_heterotypic = $relpt->relQualifierId == 6 || ($relpt->relQualifierId == 2 && !$is_other_basionym && $last_was_heterotypic);
160
      // DELETE ME? $is_heterotypic = $relpt->relQualifierId == 6 || ($relpt->relQualifierId == 2 && !$is_other_basionym);
161
      
162
      $is_homotypic = $relpt->relQualifierId == 7 || $relpt->relQualifierId == 101 || $relpt->relQualifierId == 103;
163
      
164
      // is this taxon homotypic to a previously printed heterotypic taxon, so is should be
165
      // an intented subelement and re-taged as homotypic 
166
      $is_subelement = $is_heterotypic && !$is_other_basionym && !$is_first_entry;
167
      
168
      $is_the_basionym = $is_homotypic && !$last_basionym_nameId;
169
      
170
     
171
      if($is_first_entry){ 
172
        $out = '<ul>'.chr(10).'<li class="blank_line"></li>'.chr(10); 
173
           if($is_heterotypic){
174
             if($_debug) $out .= '<li><span style="color:blue; font-size: 80%;">renderTypeDesignations before first entry which is heterotypic]</span></li>';
175
             $out .= renderTypeDesignations($ptaxon->nameId, '', $is_higher_rank ); 
176
             $out .= '<li class="blank_line"></li>'.chr(10);
177
           }
178
      }
179
      /*$out .= '<li><span style="color:blue; font-size: 80%;">last: '
180
				.$last_basionym_nameId.' !== '.$relpt->basionymNameId.' '.$relpt->fullName
181
                .'</span></li>';
182
		*/      
183
      //DEBUG $out .= '<pre>'.print_r($relpt, true).'</pre>';
184
      
185
      if($is_other_basionym){
186
        if($_debug) $out .= '<li><span style="color:blue; font-size: 80%;">renderTypeDesignations 1 (relID: '.$last_relQualifierId.' for '.$last_basionym_nameId.')</span></li>';
187
        $out .= renderTypeDesignations($last_basionym_nameId, ($last_was_heterotypic ? 'subelement' : ''), $is_higher_rank ); 
188
        //$out .= renderTypeDesignations($last_basionym_nameId, '', $is_higher_rank ); 
189
      }
190
      
191
      if($end_of_section){
192
          // find type information          
193
          $out .= '<li class="blank_line"></li>'.chr(10);
194
      }
195
      
196
      if($is_subelement){
197
          // all those taxa which are homotypic to the preceeding basionym are to be
198
          // displayed as homotypic
199
          $relpt->relQualifierId = 7;
200
          $cssClass = 'subelement';
201
      } else {
202
          $cssClass = '';
203
      }
204
      
205
      $out .= render_related_ptname($relpt, 'li', $cssClass, $showNotes).chr(10);
206
      
207
       // remember last synonyms properties for next round
208
      $last_relQualifierId = $relpt->relQualifierId;
209
      $last_basionym_name = $relpt->basionymFullName;
210
      $last_basionym_nameId = $relpt->basionymNameId;
211
      $last_was_heterotypic = $is_heterotypic;
212
      
213
    } // END relations loop
214
    
215
    
216
    if($is_the_basionym){
217
       if($_debug) $out .= '<li><span style="color:blue; font-size: 80%;">renderTypeDesignations 0 for '.$relpt->nameId.'</span></li>';
218
        $out .= renderTypeDesignations($relpt->nameId, '', $is_higher_rank);
219
    } else 
220
    // TypeDesignations for the last item
221
    if($is_other_basionym || !$last_was_heterotypic){
222
        if($_debug) $out .= '<li><span style="color:blue; font-size: 80%;">renderTypeDesignations 2 for '.$last_basionym_nameId.'</span></li>';
223
        $out .= renderTypeDesignations($last_basionym_nameId, '', $is_higher_rank);
224
    } else
225
    
226
    // In case the given PTaxon had no synonyms ...
227
     if($last_basionym_nameId === false || $last_relQualifierId == 7){
228
        if($_debug) $out .= '<li><span style="color:blue; font-size: 80%;">renderTypeDesignations 3 for'.$ptaxon->nameId.'; last_basionym_nameId = '.$last_basionym_nameId.'</span></li>';
229
        $out .= renderTypeDesignations($ptaxon->nameId, '', $is_higher_rank);
230
    } else {
231
      $out .= '<li class="blank_line"></li>'.chr(10).'</ul>';
232
    }
233
    
234
    return $out;
235
}
236
// -------------------- END function render_synonyms()
237

    
238
function render_homonyms(TAXIC_TaxonName $taxon){
239
  $homonyms = getLaterHomonyms($taxon);
240
  $out = '';
241

    
242
  foreach($homonyms as $homnym){
243
    $out .= '<li class="homonym">[non '.$homnym->authors.', '.$homnym->nomRef.']'.render_notes($homnym).'</li>';
244
  }
245
  
246
  if($out){
247
    $out = '<ul>'.$out.'</ul>';
248
  }
249
  return $out;
250
}
251

    
252
/**
253
 * render_related_ptname() is used by render_synonyms()
254
 * @param TAXIC_PTaxon $relPTaxon
255
 * @param String $enclosingTag 
256
 */
257
function render_related_ptname($relPTaxon, $enclosingTag = 'li', $cssClass = '', $showNotes = false){
258
    
259
    $cssClass .= ' '.str_replace(' ', '_', $relPTaxon->relQualifier);
260
  
261
    switch($relPTaxon->relQualifierId){
262
        case 7  :
263
        case 101  :
264
        case 103  : // homotypic-synonym
265
            $relSign = '≡';
266
            break;
267
        case 3  :   // misapplied_name
268
            $relSign = '-';
269
            break;
270
        case 8  :   // invalid_designation
271
            $relSign = '-';
272
            break;
273
        default : 
274
            $relSign = '=';
275
            break;
276
    }
277
    
278
    //$relSign .= $relPTaxon->relQualifierId;
279

    
280
    $out = '';
281
    
282
    if($relPTaxon->relQualifierId == 3){
283
        // special look for misapplied_names
284
        $relatedToName = ''; // only used in HTML comment
285
        $sensuPart = ' sensu '.$relPTaxon->ref;
286
        if($relPTaxon->relInversion){
287
            $namePart = ($relPTaxon->isAccepted()? render_ptname_link($relPTaxon) : render_ptname($relPTaxon));
288
            $out = $relPTaxon->relQualifier.' '.$namePart.' '.$sensuPart;
289
        } else {
290
            $namePart = '„'.trim($relPTaxon->name).'“';
291
            if($relPTaxon->relPTaxon->name){
292
                // only used in HTML comment!!
293
                $relatedToName = trim($relPTaxon->relPTaxon->name); 
294
            }
295
            $out .= $namePart.'</span>'.$sensuPart;
296
        }
297
        
298
    } else {
299
        $relatedToName = ($relPTaxon->relPTaxon ? $relPTaxon->relPTaxon->name : false);
300
        if($relPTaxon->isAccepted()) {
301
            $out .= render_ptname_link($relPTaxon, null, true);
302
        } else {
303
            $out .= render_ptname($relPTaxon, true ,'span', true);
304
        }
305
            
306
    } // END else special look for misapplied_names
307

    
308
    $notes = ($showNotes && showNotes() ? render_notes($relPTaxon) : '');
309
    
310
    $out =  '<'.$enclosingTag.' class="'.$cssClass.'"><!-- '.$relPTaxon->relQualifier.' '.$relatedToName.'-->'
311
			.'<a name="'.$relPTaxon->nameId.'_'.$relPTaxon->refId.'" ></a><span class="relation_sign">'.$relSign.'</span> '
312
            .$out . $notes
313
            .'</'.$enclosingTag.'>';
314
    return $out;
315
}
316

    
317
/**
318
 * @param TAXIC_PTaxon $ptname
319
 */
320
$NOMREFSET_COUNTER = 0;
321

    
322
function render_nomRef($ptname){
323
  global $conf;
324
  global $NOMREFSET_COUNTER;
325
  $NOMREFSET_COUNTER += 1;
326
    if(count($protoploges = $ptname->getProtologues()) > 0){
327
		$prot = $protoploges[0];
328
		// FIXME: protologues are really a list of links. treat only the first
329
		if(is_file($conf['abs_media_path'].$conf['protologue_path'].$prot.".png")){
330
    	  $nomrefLink = '<span class="nomref"><a href="'.$conf['protologue_path'].$prot.'.png" rel="lightbox[nomrefset'.$NOMREFSET_COUNTER.']" title="&lt;a href=&quot;'.$conf['protologue_quality_path'].$prot.'.tif&quot;&gt;High Quality Scan&lt;/a&gt;">'.trim($ptname->nomRef).'</a></span>';
331
		} else {
332
		  $nomrefLink = '<span class="nomref"><a href="'.$conf['protologue_path'].$prot.'001.png" rel="lightbox[nomrefset'.$NOMREFSET_COUNTER.']" title="&lt;a href=&quot;'.$conf['protologue_quality_path'].$prot.'.tif&quot;&gt;High Quality Scan&lt;/a&gt;">'.trim($ptname->nomRef).'</a></span>';	  
333
          // check in filesystem if there are more pages as JPGs. TIFFs can cope with 8 pages per file, so no need for that
334
          $i=2;
335
          while (is_file($conf['abs_media_path'].$conf['protologue_path'].$prot.str_pad($i, 3, '0', STR_PAD_LEFT).".png")){
336
          	$nomrefLink = $nomrefLink."   <a href='".$conf['protologue_path'].$prot.str_pad($i, 3, '0', STR_PAD_LEFT).".png' rel='lightbox[nomrefset".$NOMREFSET_COUNTER."]'></a>";
337
          	$i++;
338
          }
339
		}
340
        return $nomrefLink;
341
    } else {
342
        return '<span class="nomref">'.trim($ptname->nomRef).'</span>';
343
    }
344
    
345
}
346

    
347
function renderTypeDesignations($nameId, $cssClass = '', $togglebox = false, $separator = '<br />' , $enclosingTag = 'li'){
348
  
349
  $typeDesignations = getTypeDesignations($nameId);
350

    
351
  if(count($typeDesignations) > 0){
352
    $out = ''; 
353
    foreach($typeDesignations as $td){
354
      
355
      if(strlen($out) > 0){
356
        $out .= $separator.chr(10);
357
      }
358
      $out .= $td['TypeStatus'].' - '.html_entity_decode($td['TypePhrase']);
359
    }
360
    
361
    if($togglebox){
362
       $out = '<div class="tbox_toggler">&nbsp;</div><div class="tbox_content">'.$out.'</div>';
363
    } 
364
    return '<'.$enclosingTag.' class="type_designation'.($cssClass ? ' '.$cssClass : '' ).'">'
365
  		.$out.'</'.$enclosingTag.'>'.chr(10);
366
    
367
  }
368
}
369

    
370
/**
371
 * render a numeric pager
372
 */
373
function renderNumPager($numOfPages, $activePage, $maxPagerItems, $linkUrlBase){
374
	
375
    if ($activePage > $maxPagerItems - 2){
376
        // shift visible pager items
377
        $begin = $activePage - floor($maxPagerItems / 2);
378
        $end   = min($activePage + ceil($maxPagerItems / 2), $numOfPages);
379
    } else {
380
        $begin = 1; 
381
        $end   = min($numOfPages, $maxPagerItems);
382
    }
383
    // hide the pager if there is only one page:
384
    if($begin == $end)
385
        return;
386
        
387
    echo '<ul class="paging numeric">';
388
    if ($activePage > 10){
389
	    echo '<li><a href="', $linkUrlBase, $activePage - 10, '" title="backward 10 pages">&laquo;</a></li>';
390
    }
391
    if ($activePage > 1){
392
	    echo '<li><a href="', $linkUrlBase, $activePage - 1, '" title="previuos">&lt;</a></li>';
393
    }
394
	for ($pn = $begin; $pn <= $end ; ++$pn) {
395
		if($pn != $activePage){
396
		     echo '<li><a href="'.$linkUrlBase.$pn.'">'. $pn. '</a></li>';
397
		} else {
398
			echo '<li class="active">'.$pn.'</li>';
399
		}
400
	} 
401
    if ($activePage < $numOfPages){
402
	    echo '<li><a href="', $linkUrlBase, $activePage + 1, '" title="next">&gt;</a></li>';
403
    }
404
    if ($activePage < $numOfPages - 9){
405
	    echo '<li><a href="', $linkUrlBase, $activePage + 10, '" title="forward 10 pages">&raquo;</a></li>';
406
    }
407
    if($numOfPages > 0){
408
        echo '<li> (of '.$numOfPages.' pages)</li>';
409
    }
410
    echo '</ul>';
411
}
412

    
413
/**
414
 * @param TAXIC_TaxonName $taxon
415
 */
416
function render_notes(TAXIC_TaxonName $taxon){
417
  
418
    if(!showNotes()){
419
      return;
420
    }
421
    
422
    $notes = array();
423
    if($taxon->nameNotes && trim($taxon->nameNotes)){
424
      $notes['Name Notes'] = $taxon->nameNotes;
425
    }
426
    if($taxon->nomRefNotes && trim($taxon->nomRefNotes)){
427
      $notes['Nomenclatural Ref. Notes'] = $taxon->nomRefNotes;
428
    }
429
    
430
    if($taxon instanceof TAXIC_PTaxon){
431
      if($taxon->nameNotes && trim($taxon->conceptNotes)){
432
        $notes['Taxon Concept Notes'] = $taxon->conceptNotes;
433
      }
434
      if($taxon->refNotes && trim($taxon->refNotes)){
435
        $notes['Concept Reference Notes'] = $taxon->refNotes;
436
      }
437
    }
438
    if(count($notes) > 0){
439
      $out = '<span class="note_toggler"><img src="themes/cichorieae/note_gray.gif" /><div class="note">';
440
      $out .= '<div class="title"><div class="close" title="close"><img src="themes/cichorieae/close.gif" /></div>Notes on '.render_name($taxon).'</div><div class="content">';
441
      foreach(array_keys($notes) as $title){
442
        $out .= render_notes_entry($title, $notes[$title]);
443
      }
444
      return $out.'</div></div></span>';
445
    } else {
446
      return;
447
    }
448
}
449

    
450
function render_notes_entry($title, $note){
451
    
452
    return '<h4>'.$title.'</h4><p>'.htmlspecialchars($note).'</p>'.chr(10);
453
}
454

    
(5-5/5)