BibliographicExtension/bibliographystyle-csu.php
From PeacockWiki
(Difference between revisions)
Revision as of 23:44, 26 August 2006 (edit) Trevorp (Talk | contribs) (BibliographicExtension/bibliographicstyle-csu.php moved to BibliographicExtension/bibliographystyle-csu.php) ← Previous diff |
Revision as of 04:33, 27 August 2006 (edit) Trevorp (Talk | contribs) Next diff → |
||
Line 13: | Line 13: | ||
class CSUHarvard_Style { | class CSUHarvard_Style { | ||
- | static function formatNames($argv, $names1) | + | static function formatNames($argv, $names1, $full=false) |
{ | { | ||
$maxNames=3; | $maxNames=3; | ||
$count=count($names1); | $count=count($names1); | ||
- | if($count>$maxNames) | + | if(!$full & $count>$maxNames) |
$names=$names1[0][1].' et al.'; | $names=$names1[0][1].' et al.'; | ||
else | else | ||
Line 24: | Line 24: | ||
foreach($names1 as $name) | foreach($names1 as $name) | ||
{ | { | ||
- | $names[]=$name[1]; | + | if($full) |
+ | { | ||
+ | $n=$name[1]; | ||
+ | if(count($name[2])>0) | ||
+ | $n.=", ".BibliographyFormat::makeList($name[2], '', ''); | ||
+ | $names[]=$n; | ||
+ | } | ||
+ | else | ||
+ | $names[]=$name[1]; | ||
} | } | ||
#var_dump($names); | #var_dump($names); | ||
Line 109: | Line 117: | ||
case 'Article': | case 'Article': | ||
$text=CSUHarvard_Style::referenceArticle($citation); | $text=CSUHarvard_Style::referenceArticle($citation); | ||
+ | break; | ||
+ | case 'Online Article': | ||
+ | $text=CSUHarvard_Style::referenceOnlineArticle($citation); | ||
break; | break; | ||
default: | default: | ||
- | $text='[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names()).' '.$citation->year().']], '.$citation->title().'?'; | + | $text=referenceUnknownType($citation); |
} | } | ||
return BibliographyFormat::renderWikiText($text); | return BibliographyFormat::renderWikiText($text); | ||
+ | } | ||
+ | |||
+ | static function notfoundText($citation) | ||
+ | { | ||
+ | return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]"); | ||
+ | } | ||
+ | |||
+ | static function referenceUnknownType($citation) | ||
+ | { | ||
+ | return '[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true).' '.$citation->year().']], '.$citation->title().'?'; | ||
} | } | ||
Line 119: | Line 140: | ||
{ | { | ||
$text='[['.$citation->referencename().'|'; | $text='[['.$citation->referencename().'|'; | ||
- | $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names()); | + | $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); |
$text.=' '.$citation->year(); | $text.=' '.$citation->year(); | ||
$text.=']]'; | $text.=']]'; | ||
Line 144: | Line 165: | ||
$text.=CSUHarvard_Style::electronicTranscription($citation); | $text.=CSUHarvard_Style::electronicTranscription($citation); | ||
//page | //page | ||
+ | return $text.'.'; | ||
+ | } | ||
+ | |||
+ | static function referenceArticle($citation) | ||
+ | { | ||
+ | $text='[['.$citation->referencename().'|'; | ||
+ | $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); | ||
+ | $text.=' '.$citation->year(); | ||
+ | $text.=']]'; | ||
+ | $text.=", '".$citation->title()."'"; | ||
+ | $text.=CSUHarvard_Style::electronicVer($citation); | ||
+ | if($citation->field('periodical')) | ||
+ | $text.=', '.CSUHarvard_Style::formatPeriodical($citation->field('periodical')); | ||
+ | if($citation->field('issue')) | ||
+ | $text.=', '.$citation->field('issue'); | ||
+ | if($citation->field('pages')) | ||
+ | $text.=', pp.'.$citation->field('pages'); | ||
+ | $text.=CSUHarvard_Style::electronicTranscription($citation); | ||
+ | return $text.'.'; | ||
+ | } | ||
+ | |||
+ | static function referenceOnlineArticle($citation) | ||
+ | { | ||
+ | $text='[['.$citation->referencename().'|'; | ||
+ | $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); | ||
+ | $text.=' '.$citation->year(); | ||
+ | $text.=']]'; | ||
+ | $text.=", '".$citation->title()."'"; | ||
+ | //version number | ||
+ | if($citation->field('date')) | ||
+ | $text.=', last edited '.CSUHarvard_Style::formatDate($citation->field('date')); | ||
+ | if($citation->field('description')) | ||
+ | $text.=', '.$citation->field('description'); | ||
+ | //name of publisher, sponsor or source | ||
+ | //place or location of publication | ||
+ | if($citation->field('viewed')) | ||
+ | $text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed')); | ||
+ | if($citation->field('url')) | ||
+ | $text.=', <'.$citation->field('url').'>'; | ||
return $text.'.'; | return $text.'.'; | ||
} | } | ||
Line 150: | Line 210: | ||
{ | { | ||
$text=''; | $text=''; | ||
+ | if(!$citation->field('url')) | ||
+ | return $text; | ||
if($citation->field('electronicdesc')) | if($citation->field('electronicdesc')) | ||
$text.=', '.$citation->field('electronicdesc'); | $text.=', '.$citation->field('electronicdesc'); | ||
Line 170: | Line 232: | ||
{ | { | ||
$date2=split('/', $date); | $date2=split('/', $date); | ||
- | if(count($date2)!=3) | + | if(count($date2)==3) |
- | return $date; | + | return date('j F Y', strtotime($date2[1].'/'.$date2[2].'/'.$date2[0])); |
- | return date('j F Y', strtotime($date2[1].'/'.$date2[2].'/'.$date2[0])); | + | if(count($date2)==2) |
- | } | + | return date('F Y', strtotime($date2[1].'/1/'.$date2[0])); |
- | + | return $date; | |
- | static function referenceArticle($citation) | + | |
- | { | + | |
- | $text='[['.$citation->referencename().'|'; | + | |
- | $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names()); | + | |
- | $text.=' '.$citation->year(); | + | |
- | $text.=']]'; | + | |
- | $text.=", '".$citation->title()."'"; | + | |
- | $text.=CSUHarvard_Style::electronicVer($citation); | + | |
- | if($citation->field('periodical')) | + | |
- | $text.=', '.CSUHarvard_Style::formatPeriodical($citation->field('periodical')); | + | |
- | if($citation->field('issue')) | + | |
- | $text.=', '.$citation->field('issue'); | + | |
- | if($citation->field('pages')) | + | |
- | $text.=', pp.'.$citation->field('pages'); | + | |
- | $text.=CSUHarvard_Style::electronicTranscription($citation); | + | |
- | return $text.'.'; | + | |
} | } | ||
Line 201: | Line 247: | ||
} | } | ||
- | static function notfoundText($citation) | ||
- | { | ||
- | return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]"); | ||
- | } | ||
- | |||
} | } | ||
?></pre> | ?></pre> |
Revision as of 04:33, 27 August 2006
<?php /* TODO: 2.4 Companies or organisations as authors ...this is not easily proven (CSIRO 1986) This publicatino of the Centre for Rurali Social Research (1988) shows ... 2.5 Anonymous Works 2.6 Authrs with the same surname distinguished by including initials in in-text citation. */ class CSUHarvard_Style { static function formatNames($argv, $names1, $full=false) { $maxNames=3; $count=count($names1); if(!$full & $count>$maxNames) $names=$names1[0][1].' et al.'; else { $names=array(); foreach($names1 as $name) { if($full) { $n=$name[1]; if(count($name[2])>0) $n.=", ".BibliographyFormat::makeList($name[2], '', ''); $names[]=$n; } else $names[]=$name[1]; } #var_dump($names); if($argv!=null && key_exists('type', $argv) && $argv['type']=='name') $names=BibliographyFormat::makeList($names, ', ', ' and '); else $names=BibliographyFormat::makeList($names, ', ', ' & '); } return $names; } //Types: // normal - (Hayes 2000) // name - Hayes (2000) // text - Hayes 2000 static function intextcite($articles) { //TODO: Sort articles # var_dump($articles); $text=array(); $lastarticle=null; foreach($articles['articles'] as $name=>$article) { if($article['article']->type()==NULL) { $text[]=CSUHarvard_Style::notfoundText($article['article']); continue; } $entry=CSUHarvard_Style::formatNames(array('type'=>$articles['type']), $article['article']->names()); if($articles['type']=='name') $entry.=' ('.$article['article']->year().')'; else $entry.=' '.$article['article']->year(); if($article['note']!='') $entry.=', '.$article['note']; $entry=BibliographyFormat::renderWikiText("[[".$article['article']->referencename().'|'.$entry.']]'); $text[]=$entry; } # var_dump($text); # exit(); switch($articles['type']) { case 'normal': $text=BibliographyFormat::makeList($text, ', ', ', '); break; case 'name': $text=BibliographyFormat::makeList($text, ' ', ' and '); break; case 'text': $text=BibliographyFormat::makeList($text, ', ', ' and '); break; } # var_dump($text); if($articles['type']=='normal') $text='('.$text.')'; return $text; } static function intext($argv, $citation) { if(!isset($citation->mFields['type'])) return "Article not found: ".$citation->mFields['reference']; if($argv!=null && key_exists('type', $argv) && $argv['type']=='name') return $names.' ('.$citation->mFields['year'].')'; else return '('.$names.' '.$citation->mFields['year'].')'; } static function referenceList($articles) { //TODO: sort $refrences=''; foreach($articles as $article) { $refrences.=CSUHarvard_Style::reference($article).'<br/>'; } return $refrences; return "refernce list"; } static function reference($citation) { if($citation->type()==NULL) return CSUHarvard_Style::notfoundText($citation); switch($citation->type()) { case 'Book': $text=CSUHarvard_Style::referenceBook($citation); break; case 'Article': $text=CSUHarvard_Style::referenceArticle($citation); break; case 'Online Article': $text=CSUHarvard_Style::referenceOnlineArticle($citation); break; default: $text=referenceUnknownType($citation); } return BibliographyFormat::renderWikiText($text); } static function notfoundText($citation) { return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]"); } static function referenceUnknownType($citation) { return '[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true).' '.$citation->year().']], '.$citation->title().'?'; } static function referenceBook($citation) { $text='[['.$citation->referencename().'|'; $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); $text.=' '.$citation->year(); $text.=']]'; $text.=", ''".$citation->title()."''"; //series if($citation->field('title')) $text.=', '.$citation->field('title'); $text.=CSUHarvard_Style::electronicVer($citation); //description if($citation->field('book')) $text.=", in ''".$citation->field('book')."''"; if($citation->field('edition')) $text.=', '.BibliographyFormat::formatCount($citation->field('edition')).' edn'; //editor //compiler //revisor //translator //illustrator //volume if($citation->field('publisher')) $text.=', '.$citation->field('publisher'); if($citation->field('location')) $text.=', '.$citation->field('location'); $text.=CSUHarvard_Style::electronicTranscription($citation); //page return $text.'.'; } static function referenceArticle($citation) { $text='[['.$citation->referencename().'|'; $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); $text.=' '.$citation->year(); $text.=']]'; $text.=", '".$citation->title()."'"; $text.=CSUHarvard_Style::electronicVer($citation); if($citation->field('periodical')) $text.=', '.CSUHarvard_Style::formatPeriodical($citation->field('periodical')); if($citation->field('issue')) $text.=', '.$citation->field('issue'); if($citation->field('pages')) $text.=', pp.'.$citation->field('pages'); $text.=CSUHarvard_Style::electronicTranscription($citation); return $text.'.'; } static function referenceOnlineArticle($citation) { $text='[['.$citation->referencename().'|'; $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->names(), true); $text.=' '.$citation->year(); $text.=']]'; $text.=", '".$citation->title()."'"; //version number if($citation->field('date')) $text.=', last edited '.CSUHarvard_Style::formatDate($citation->field('date')); if($citation->field('description')) $text.=', '.$citation->field('description'); //name of publisher, sponsor or source //place or location of publication if($citation->field('viewed')) $text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed')); if($citation->field('url')) $text.=', <'.$citation->field('url').'>'; return $text.'.'; } static function electronicTranscription($citation) { $text=''; if(!$citation->field('url')) return $text; if($citation->field('electronicdesc')) $text.=', '.$citation->field('electronicdesc'); if($citation->field('viewed')) $text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed')); if($citation->field('url')) $text.=', <'.$citation->field('url').'>'; return $text; } static function electronicVer($citation) { $text=''; if($citation->field('electronicversion')) $text.=' electronic version'; return $text; } static function formatDate($date) { $date2=split('/', $date); if(count($date2)==3) return date('j F Y', strtotime($date2[1].'/'.$date2[2].'/'.$date2[0])); if(count($date2)==2) return date('F Y', strtotime($date2[1].'/1/'.$date2[0])); return $date; } static function formatPeriodical($periodical) { preg_match('/(.*)(\(.*\))/', $periodical, $match); if(count($match)==0) return "''".$periodical."''"; return "''".trim($match[1])."'' ".$match[2]; } } ?>