Project

General

Profile

Download (16.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

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

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

    
25
/**
26
 * Renders the full name string (complete scientific name including the author team)
27
 *  
28
 * @param NameTO $nameTO the taxon name
29
 */
30
function theme_cdm_name(NameTO $nameTO){
31
    //TODO: how to respect the different subtypes of eu.etaxonomy.cdm.model.name.TaxonNameBase ?
32
    return cdm_taggedtext2html($nameTO->taggedName, 'span');
33
}
34

    
35
/**
36
 * Renders the given TaxonTO. The $enclosingTag (if not set false)
37
 * will get the following class attributes:
38
 * - name
39
 * - acceptet (only if $ptaxon is an accepted name)
40
 * 
41
 * @param TaxonTO $taxon
42
 * @param boolean $noSecundum defaults to false. If set to true the secundum part is omitted.
43
 * @param string $enclosingTag defaults to span.
44
 * @param boolean $showNomRef whether to dispülay the nomenclatural reference
45
 * @return string of XHTML
46
 * 
47
 * usage: taxon_detail, theme_ptname_link
48
 */
49
function theme_cdm_taxon(TaxonTO $taxon, $noSecundum = true ,$enclosingTag = 'span', $showNomRef = false){
50

    
51
    /* TODO: port me
52
    $refSecundum = false;
53
    if(!$noSecundum && $taxon->ref){
54
        $refSecundum = str_trunk($ptaxon->ref, 40, '...');
55
    }
56
	*/
57
    $out = theme('cdm_name', $taxon)
58
	    .($refSecundum ? '&nbsp;<span class="secundum">sec. '.$refSecundum.'</span>': '')
59
	    .$ptaxon->namePhrase;
60
    /* TODO: port me
61
    if($showNomRef){
62
        $out .= (str_beginsWith($ptaxon->nomRef, 'in') || trim($ptaxon->nomRef) == '' ? '&nbsp;':',&nbsp;').theme('cdm_nomRef',$taxon);
63
    }
64
    if($enclosingTag){
65
        $out = '<'.$enclosingTag.' class="name'.($ptaxon->isAccepted()?' accepted':'').'"><!-- ['.$ptaxon->nameId.'|'.$ptaxon->refId.'] -->'.$out.'</'.$enclosingTag.'>';
66
    }
67
    */
68
    
69
    return $out;
70
    
71
}
72

    
73
/**
74
 * Renders a link to the taxon detail page for the given $taxon 
75
 *
76
 * @param TaxonTO $taxon
77
 */
78
function theme_cdm_taxon_link(TaxonTO $taxon, $fragment = '', $showNomRef = false){
79
    
80
    if($fragment){
81
        $fragment = '#'.$fragment;
82
    }
83

    
84
    if(!$taxon->isAccepted) { 
85
        $out = 'ERROR: theme_cdm_taxon_link() not accepted ptname; status:'.$taxon->status.$out;
86
    }
87
    
88
    $out = l(theme('cdm_taxon', $taxon, true, false), 'taxon', array('class'=>'accepted'), "uuid=$taxon->uuid", $fragment);
89
    
90
    if($showNomRef){
91
       $out .=' '.theme('cdm_nomRef', $ptaxon);
92
    }
93
	
94
	return $out;
95
}
96

    
97
//TODO: port everything below
98

    
99
/**
100
 * Renders a list of synonyms including misapplied names which are related to the 
101
 * given TAXIC_PTaxon.
102
 *
103
 * @param TAXIC_PTaxon $ptaxon
104
 * @param boolean $recursive default is false. Whether to crawl recursively into the
105
 * three of relations
106
 * 
107
 * usage taxon_detail.php.inc
108
 */
109
function render_synonyms(TAXIC_PTaxon $ptaxon, $recursive = false, $showNotes = false){
110

    
111
    $_debug = false;
112
    
113
    $is_higher_rank = $ptaxon->rankId < 60;
114
  
115
    
116
    $out = false;
117
    $last_relQualifierId = false;
118
    $last_was_heterotypic = false;
119
    $last_basionym_nameId = false;
120
    $is_other_basionym = false;
121
    
122
    $synonyms = findSynonyms($ptaxon->nameId, $ptaxon->refId, false, $recursive);
123

    
124
    foreach($synonyms AS $relpt){ // -- relations loop
125
             
126
      // whether this is the first entry in the lsit
127
      $is_first_entry = $out === false;
128
      
129
      // whether the current taxon has another basionym than the last one
130
      $is_other_basionym = $last_basionym_nameId !== false  
131
        && ($last_basionym_nameId !== $relpt->basionymNameId)
132
        && $relpt->relQualifierId != 3;
133
      
134
      // whether the current taxon has another name ralation than the last one
135
      $is_other_relQualifierId = $last_relQualifierId !== false && ($last_relQualifierId !== $relpt->relQualifierId);
136

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

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

    
221
function render_homonyms(TAXIC_TaxonName $taxon){
222
  $homonyms = getLaterHomonyms($taxon);
223
  $out = '';
224

    
225
  foreach($homonyms as $homnym){
226
    $out .= '<li class="homonym">[non '.$homnym->authors.', '.$homnym->nomRef.']'.render_notes($homnym).'</li>';
227
  }
228
  
229
  if($out){
230
    $out = '<ul>'.$out.'</ul>';
231
  }
232
  return $out;
233
}
234

    
235
/**
236
 * render_related_ptname() is used by render_synonyms()
237
 * @param TAXIC_PTaxon $relPTaxon
238
 * @param String $enclosingTag 
239
 */
240
function render_related_ptname($relPTaxon, $enclosingTag = 'li', $cssClass = '', $showNotes = false){
241
    
242
    $cssClass .= ' '.str_replace(' ', '_', $relPTaxon->relQualifier);
243
  
244
    switch($relPTaxon->relQualifierId){
245
        case 7  :
246
        case 101  :
247
        case 103  : // homotypic-synonym
248
            $relSign = '≡';
249
            break;
250
        case 3  :   // misapplied_name
251
            $relSign = '-';
252
            break;
253
        case 8  :   // invalid_designation
254
            $relSign = '-';
255
            break;
256
        default : 
257
            $relSign = '=';
258
            break;
259
    }
260
    
261
    //$relSign .= $relPTaxon->relQualifierId;
262

    
263
    $out = '';
264
    
265
    if($relPTaxon->relQualifierId == 3){
266
        // special look for misapplied_names
267
        $relatedToName = ''; // only used in HTML comment
268
        $sensuPart = ' sensu '.$relPTaxon->ref;
269
        if($relPTaxon->relInversion){
270
            $namePart = ($relPTaxon->isAccepted()? render_ptname_link($relPTaxon) : render_ptname($relPTaxon));
271
            $out = $relPTaxon->relQualifier.' '.$namePart.' '.$sensuPart;
272
        } else {
273
            $namePart = '„'.trim($relPTaxon->name).'“';
274
            if($relPTaxon->relPTaxon->name){
275
                // only used in HTML comment!!
276
                $relatedToName = trim($relPTaxon->relPTaxon->name); 
277
            }
278
            $out .= $namePart.'</span>'.$sensuPart;
279
        }
280
        
281
    } else {
282
        $relatedToName = ($relPTaxon->relPTaxon ? $relPTaxon->relPTaxon->name : false);
283
        if($relPTaxon->isAccepted()) {
284
            $out .= render_ptname_link($relPTaxon, null, true);
285
        } else {
286
            $out .= render_ptname($relPTaxon, true ,'span', true);
287
        }
288
            
289
    } // END else special look for misapplied_names
290

    
291
    $notes = ($showNotes && showNotes() ? render_notes($relPTaxon) : '');
292
    
293
    $out =  '<'.$enclosingTag.' class="'.$cssClass.'"><!-- '.$relPTaxon->relQualifier.' '.$relatedToName.'-->'
294
			.'<a name="'.$relPTaxon->nameId.'_'.$relPTaxon->refId.'" ></a><span class="relation_sign">'.$relSign.'</span> '
295
            .$out . $notes
296
            .'</'.$enclosingTag.'>';
297
    return $out;
298
}
299

    
300
/**
301
 * @param TAXIC_PTaxon $ptname
302
 */
303
$NOMREFSET_COUNTER = 0;
304

    
305
function render_nomRef($ptname){
306
  global $conf;
307
  global $NOMREFSET_COUNTER;
308
  $NOMREFSET_COUNTER += 1;
309
    if(count($protoploges = $ptname->getProtologues()) > 0){
310
		$prot = $protoploges[0];
311
		// FIXME: protologues are really a list of links. treat only the first
312
		if(is_file($conf['abs_media_path'].$conf['protologue_path'].$prot.".png")){
313
    	  $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>';
314
		} else {
315
		  $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>';	  
316
          // check in filesystem if there are more pages as JPGs. TIFFs can cope with 8 pages per file, so no need for that
317
          $i=2;
318
          while (is_file($conf['abs_media_path'].$conf['protologue_path'].$prot.str_pad($i, 3, '0', STR_PAD_LEFT).".png")){
319
          	$nomrefLink = $nomrefLink."   <a href='".$conf['protologue_path'].$prot.str_pad($i, 3, '0', STR_PAD_LEFT).".png' rel='lightbox[nomrefset".$NOMREFSET_COUNTER."]'></a>";
320
          	$i++;
321
          }
322
		}
323
        return $nomrefLink;
324
    } else {
325
        return '<span class="nomref">'.trim($ptname->nomRef).'</span>';
326
    }
327
    
328
}
329

    
330
function renderTypeDesignations($nameId, $cssClass = '', $togglebox = false, $separator = '<br />' , $enclosingTag = 'li'){
331
  
332
  $typeDesignations = getTypeDesignations($nameId);
333

    
334
  if(count($typeDesignations) > 0){
335
    $out = ''; 
336
    foreach($typeDesignations as $td){
337
      
338
      if(strlen($out) > 0){
339
        $out .= $separator.chr(10);
340
      }
341
      $out .= $td['TypeStatus'].' - '.html_entity_decode($td['TypePhrase']);
342
    }
343
    
344
    if($togglebox){
345
       $out = '<div class="tbox_toggler">&nbsp;</div><div class="tbox_content">'.$out.'</div>';
346
    } 
347
    return '<'.$enclosingTag.' class="type_designation'.($cssClass ? ' '.$cssClass : '' ).'">'
348
  		.$out.'</'.$enclosingTag.'>'.chr(10);
349
    
350
  }
351
}
352

    
353
/**
354
 * render a numeric pager
355
 */
356
function renderNumPager($numOfPages, $activePage, $maxPagerItems, $linkUrlBase){
357
	
358
    if ($activePage > $maxPagerItems - 2){
359
        // shift visible pager items
360
        $begin = $activePage - floor($maxPagerItems / 2);
361
        $end   = min($activePage + ceil($maxPagerItems / 2), $numOfPages);
362
    } else {
363
        $begin = 1; 
364
        $end   = min($numOfPages, $maxPagerItems);
365
    }
366
    // hide the pager if there is only one page:
367
    if($begin == $end)
368
        return;
369
        
370
    echo '<ul class="paging numeric">';
371
    if ($activePage > 10){
372
	    echo '<li><a href="', $linkUrlBase, $activePage - 10, '" title="backward 10 pages">&laquo;</a></li>';
373
    }
374
    if ($activePage > 1){
375
	    echo '<li><a href="', $linkUrlBase, $activePage - 1, '" title="previuos">&lt;</a></li>';
376
    }
377
	for ($pn = $begin; $pn <= $end ; ++$pn) {
378
		if($pn != $activePage){
379
		     echo '<li><a href="'.$linkUrlBase.$pn.'">'. $pn. '</a></li>';
380
		} else {
381
			echo '<li class="active">'.$pn.'</li>';
382
		}
383
	} 
384
    if ($activePage < $numOfPages){
385
	    echo '<li><a href="', $linkUrlBase, $activePage + 1, '" title="next">&gt;</a></li>';
386
    }
387
    if ($activePage < $numOfPages - 9){
388
	    echo '<li><a href="', $linkUrlBase, $activePage + 10, '" title="forward 10 pages">&raquo;</a></li>';
389
    }
390
    if($numOfPages > 0){
391
        echo '<li> (of '.$numOfPages.' pages)</li>';
392
    }
393
    echo '</ul>';
394
}
395

    
396
/**
397
 * @param TAXIC_TaxonName $taxon
398
 */
399
function render_notes(TAXIC_TaxonName $taxon){
400
  
401
    if(!showNotes()){
402
      return;
403
    }
404
    
405
    $notes = array();
406
    if($taxon->nameNotes && trim($taxon->nameNotes)){
407
      $notes['Name Notes'] = $taxon->nameNotes;
408
    }
409
    if($taxon->nomRefNotes && trim($taxon->nomRefNotes)){
410
      $notes['Nomenclatural Ref. Notes'] = $taxon->nomRefNotes;
411
    }
412
    
413
    if($taxon instanceof TAXIC_PTaxon){
414
      if($taxon->nameNotes && trim($taxon->conceptNotes)){
415
        $notes['Taxon Concept Notes'] = $taxon->conceptNotes;
416
      }
417
      if($taxon->refNotes && trim($taxon->refNotes)){
418
        $notes['Concept Reference Notes'] = $taxon->refNotes;
419
      }
420
    }
421
    if(count($notes) > 0){
422
      $out = '<span class="note_toggler"><img src="themes/cichorieae/note_gray.gif" /><div class="note">';
423
      $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">';
424
      foreach(array_keys($notes) as $title){
425
        $out .= render_notes_entry($title, $notes[$title]);
426
      }
427
      return $out.'</div></div></span>';
428
    } else {
429
      return;
430
    }
431
}
432

    
433
function render_notes_entry($title, $note){
434
    
435
    return '<h4>'.$title.'</h4><p>'.htmlspecialchars($note).'</p>'.chr(10);
436
}
437

    
(3-3/3)