BibliographicExtension/bibliographystyle-csu.php

From PeacockWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 15:17, 16 October 2006 (edit)
137.166.127.86 (Talk)

← Previous diff
Current revision (23:48, 16 October 2006) (edit)
137.166.127.86 (Talk)

 
Line 1: Line 1:
<pre><?php <pre><?php
- 
- 
/* /*
- 
TODO: TODO:
- 
2.4 Companies or organisations as authors 2.4 Companies or organisations as authors
- 
...this is not easily proven (CSIRO 1986) ...this is not easily proven (CSIRO 1986)
- 
This publicatino of the Centre for Rurali Social Research (1988) shows ... This publicatino of the Centre for Rurali Social Research (1988) shows ...
- 
2.5 Anonymous Works 2.5 Anonymous Works
- 
2.6 Authrs with the same surname 2.6 Authrs with the same surname
- 
distinguished by including initials in in-text citation. distinguished by including initials in in-text citation.
- 
*/ */
- 
- 
class CSUHarvard_Style { class CSUHarvard_Style {
- 
- 
static function formatNames($argv, $names1, $full=false) static function formatNames($argv, $names1, $full=false)
- 
{ {
- 
$maxNames=3; $maxNames=3;
- 
$count=count($names1); $count=count($names1);
- 
if(!$full & $count>$maxNames) if(!$full & $count>$maxNames)
- 
$names=$names1[0][1].' et al.'; $names=$names1[0][1].' et al.';
- 
else else
- 
{ {
- 
$names=array(); $names=array();
- 
foreach($names1 as $name) foreach($names1 as $name)
- 
{ {
- 
if($full) if($full)
- 
{ {
- 
$n=$name[1]; $n=$name[1];
- 
if(count($name[2])>0) if(count($name[2])>0)
- 
$n.=", ".BibliographyFormat::makeList($name[2], '', ''); $n.=", ".BibliographyFormat::makeList($name[2], '', '');
- 
$names[]=$n; $names[]=$n;
- 
} }
- 
else else
- 
$names[]=$name[1]; $names[]=$name[1];
- 
} }
- 
#var_dump($names); #var_dump($names);
- 
if($argv!=null && key_exists('type', $argv) && $argv['type']=='name') if($argv!=null && key_exists('type', $argv) && $argv['type']=='name')
- 
$names=BibliographyFormat::makeList($names, ', ', ' and '); $names=BibliographyFormat::makeList($names, ', ', ' and ');
- 
else else
- 
$names=BibliographyFormat::makeList($names, ', ', ' & '); $names=BibliographyFormat::makeList($names, ', ', ' & ');
- 
} }
- 
return $names; return $names;
- 
} }
- 
- 
//Types: //Types:
- 
// normal - (Hayes 2000) // normal - (Hayes 2000)
- 
// name - Hayes (2000) // name - Hayes (2000)
- 
// text - Hayes 2000 // text - Hayes 2000
- 
static function intextcite($articles) static function intextcite($articles)
- 
{ {
# TODO: McHenry (2004) and McHenry (2006) => McHenry (2004, 2006) # TODO: McHenry (2004) and McHenry (2006) => McHenry (2004, 2006)
uasort($articles['articles'], array("CSUHarvard_Style", "intextListCmp")); uasort($articles['articles'], array("CSUHarvard_Style", "intextListCmp"));
$text=array(); $text=array();
- 
$lastarticle=null; $lastarticle=null;
- + $articlelist=array();
foreach($articles['articles'] as $name=>$article) foreach($articles['articles'] as $name=>$article)
- 
{ {
- + $author=CSUHarvard_Style::formatNames(array('type'=>$articles['type']), $article['article']->authors());
- if($article['article']->type()==NULL)+ if(!array_key_exists($author, $articlelist))
- + $articlelist[$author]=array();
 + $articlelist[$author][$name]=$article;
 + }
 + foreach($articlelist as $author=>$authorsarticles)
 + {
 + //TODO: articlenotfound
 + if(count($authorsarticles)==1)
{ {
- + $article=array_keys($authorsarticles);
- $text[]=CSUHarvard_Style::notfoundText($article['article']);+ $article=$authorsarticles[$article[0]];
- + $entry=$author;
- continue;+ if($articles['type']=='name')
- + $entry.=' ('.$article['article']->year().')';
 + else
 + $entry.=' '.$article['article']->year();
 + if($article['note']!='')
 + $entry.=', '.$article['note'];
 + $entry="[[".$article['article']->referencename().'|'.$entry.']]';
} }
- 
- $entry=CSUHarvard_Style::formatNames(array('type'=>$articles['type']), $article['article']->authors()); 
- 
- if($articles['type']=='name') 
- 
- $entry.=' ('.$article['article']->year().')'; 
- 
else else
- + {
- $entry.=' '.$article['article']->year();+ $years=array();
- + foreach($authorsarticles as $name=>$article)
- if($article['note']!='')+ {
- + $year=$article['article']->year();
- $entry.=', '.$article['note'];+ if($article['note']!='')
- + $year.=', '.$article['note'];
- $entry=BibliographyFormat::renderWikiText("[[".$article['article']->referencename().'|'.$entry.']]');+ $years[]="[[".$article['article']->referencename().'|'.$year.']]';
- + }
- $text[]=$entry;+ $years=BibliographyFormat::makeList($years, ', ', ', ');
- + $entry=$author;
 + if($articles['type']=='name')
 + $entry.=' ('.$years.')';
 + else
 + $entry.=' '.$years;
 + }
 + $text[]=BibliographyFormat::renderWikiText($entry);
} }
- 
-# var_dump($text); 
- 
-# exit(); 
- 
switch($articles['type']) switch($articles['type'])
- 
{ {
- 
case 'normal': $text=BibliographyFormat::makeList($text, ', ', ', '); break; case 'normal': $text=BibliographyFormat::makeList($text, ', ', ', '); break;
- 
case 'name': $text=BibliographyFormat::makeList($text, ' ', ' and '); break; case 'name': $text=BibliographyFormat::makeList($text, ' ', ' and '); break;
- 
case 'text': $text=BibliographyFormat::makeList($text, ', ', ' and '); break; case 'text': $text=BibliographyFormat::makeList($text, ', ', ' and '); break;
- 
} }
- 
-# var_dump($text); 
- 
if($articles['type']=='normal') if($articles['type']=='normal')
- 
$text='('.$text.')'; $text='('.$text.')';
- 
return $text; return $text;
- 
} }
- 
- 
static function intext($argv, $citation) static function intext($argv, $citation)
- 
{ {
- 
if(!isset($citation->mFields['type'])) if(!isset($citation->mFields['type']))
- 
return "Article not found: ".$citation->mFields['reference']; return "Article not found: ".$citation->mFields['reference'];
- 
if($argv!=null && key_exists('type', $argv) && $argv['type']=='name') if($argv!=null && key_exists('type', $argv) && $argv['type']=='name')
- 
return $names.' ('.$citation->mFields['year'].')'; return $names.' ('.$citation->mFields['year'].')';
- 
else else
- 
return '('.$names.' '.$citation->mFields['year'].')'; return '('.$names.' '.$citation->mFields['year'].')';
- 
} }
- 
- 
static function intextListCmp($a, $b) static function intextListCmp($a, $b)
Line 226: Line 157:
static function referenceList($articles) static function referenceList($articles)
- 
{ {
$refrences=''; $refrences='';
- 
foreach($articles as $article) foreach($articles as $article)
- 
{ {
- 
$refrences.='<p class="bibliographicReference">'.CSUHarvard_Style::reference($article)."</p>\n"; $refrences.='<p class="bibliographicReference">'.CSUHarvard_Style::reference($article)."</p>\n";
- 
} }
- 
return '<div class="bibliographicReferences">'.$refrences.'</div>'; return '<div class="bibliographicReferences">'.$refrences.'</div>';
- 
return "refernce list"; return "refernce list";
- 
} }
- 
- 
static function reference($citation) static function reference($citation)
- 
{ {
- 
if($citation->type()==NULL) if($citation->type()==NULL)
- 
return CSUHarvard_Style::notfoundText($citation); return CSUHarvard_Style::notfoundText($citation);
- 
switch($citation->type()) switch($citation->type())
- 
{ {
- 
case 'Book': case 'Book':
- 
$text=CSUHarvard_Style::referenceBook($citation); $text=CSUHarvard_Style::referenceBook($citation);
- 
break; break;
- 
case 'Article': case 'Article':
- 
$text=CSUHarvard_Style::referenceArticle($citation); $text=CSUHarvard_Style::referenceArticle($citation);
- 
break; break;
- 
case 'Online Article': case 'Online Article':
- 
$text=CSUHarvard_Style::referenceOnlineArticle($citation); $text=CSUHarvard_Style::referenceOnlineArticle($citation);
- 
break; break;
- 
default: default:
- 
$text=referenceUnknownType($citation); $text=referenceUnknownType($citation);
- 
} }
- 
return BibliographyFormat::renderWikiText($text); return BibliographyFormat::renderWikiText($text);
- 
} }
- 
- 
static function notfoundText($citation) static function notfoundText($citation)
- 
{ {
- 
return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]"); return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]");
- 
} }
- 
- 
static function referenceUnknownType($citation) static function referenceUnknownType($citation)
- 
{ {
- 
return '[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true).' '.$citation->year().']], '.$citation->title().'?'; return '[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true).' '.$citation->year().']], '.$citation->title().'?';
- 
} }
- 
- 
static function referenceBook($citation) static function referenceBook($citation)
- 
{ {
- 
$text='[['.$citation->referencename().'|'; $text='[['.$citation->referencename().'|';
- 
$text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true); $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true);
- 
$text.=' '.$citation->year(); $text.=' '.$citation->year();
- 
$text.=']]'; $text.=']]';
- 
$text.=", ''".$citation->title()."''"; $text.=", ''".$citation->title()."''";
- 
//series //series
- 
if($citation->field('title')) if($citation->field('title'))
- 
$text.=', '.$citation->field('title'); $text.=', '.$citation->field('title');
- 
$text.=CSUHarvard_Style::electronicVer($citation); $text.=CSUHarvard_Style::electronicVer($citation);
- 
//description //description
- 
if($citation->field('book')) if($citation->field('book'))
- 
$text.=", in ''".$citation->field('book')."''"; $text.=", in ''".$citation->field('book')."''";
- 
if($citation->field('edition')) if($citation->field('edition'))
- 
$text.=', '.BibliographyFormat::formatCount($citation->field('edition')).' edn'; $text.=', '.BibliographyFormat::formatCount($citation->field('edition')).' edn';
- 
//editor //editor
- 
//compiler //compiler
- 
//revisor //revisor
- 
//translator //translator
- 
//illustrator //illustrator
- 
//volume //volume
- 
if($citation->field('publisher')) if($citation->field('publisher'))
- 
$text.=', '.$citation->field('publisher'); $text.=', '.$citation->field('publisher');
- 
if($citation->field('location')) if($citation->field('location'))
- 
$text.=', '.$citation->field('location'); $text.=', '.$citation->field('location');
- 
$text.=CSUHarvard_Style::electronicTranscription($citation); $text.=CSUHarvard_Style::electronicTranscription($citation);
- 
//page //page
- 
return $text.'.'; return $text.'.';
- 
} }
- 
- 
static function referenceArticle($citation) static function referenceArticle($citation)
- 
{ {
- 
$text='[['.$citation->referencename().'|'; $text='[['.$citation->referencename().'|';
- 
$text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true); $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true);
- 
$text.=' '.$citation->year(); $text.=' '.$citation->year();
- 
$text.=']]'; $text.=']]';
- 
$text.=", '".$citation->title()."'"; $text.=", '".$citation->title()."'";
- 
$text.=CSUHarvard_Style::electronicVer($citation); $text.=CSUHarvard_Style::electronicVer($citation);
- 
if($citation->field('periodical')) if($citation->field('periodical'))
- 
$text.=', '.CSUHarvard_Style::formatPeriodical($citation->field('periodical')); $text.=', '.CSUHarvard_Style::formatPeriodical($citation->field('periodical'));
- 
if($citation->field('issue')) if($citation->field('issue'))
- 
$text.=', '.$citation->field('issue'); $text.=', '.$citation->field('issue');
- 
if($citation->field('pages')) if($citation->field('pages'))
- 
$text.=', pp.'.$citation->field('pages'); $text.=', pp.'.$citation->field('pages');
- 
$text.=CSUHarvard_Style::electronicTranscription($citation); $text.=CSUHarvard_Style::electronicTranscription($citation);
- 
return $text.'.'; return $text.'.';
- 
} }
- 
- 
static function referenceOnlineArticle($citation) static function referenceOnlineArticle($citation)
- 
{ {
- 
if(!$citation->field('viewed') && !$citation->field('url')) if(!$citation->field('viewed') && !$citation->field('url'))
- 
return CSUHarvard_Style::referenceUnknownType($citation); return CSUHarvard_Style::referenceUnknownType($citation);
- 
$text='[['.$citation->referencename().'|'; $text='[['.$citation->referencename().'|';
if($citation->field('author')) if($citation->field('author'))
- 
$text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true); $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true);
else else
Line 425: Line 261:
$text.="?"; $text.="?";
} }
- 
$text.=' '.$citation->year(); $text.=' '.$citation->year();
- 
$text.=']]'; $text.=']]';
- 
$text.=", '".$citation->title()."'"; $text.=", '".$citation->title()."'";
- 
//version number //version number
- 
if($citation->field('date')) if($citation->field('date'))
- 
$text.=', last edited '.CSUHarvard_Style::formatDate($citation->field('date')); $text.=', last edited '.CSUHarvard_Style::formatDate($citation->field('date'));
- 
if($citation->field('description')) if($citation->field('description'))
- 
$text.=', '.$citation->field('description'); $text.=', '.$citation->field('description');
- 
//name of publisher, sponsor or source //name of publisher, sponsor or source
- 
//place or location of publication //place or location of publication
- 
if($citation->field('viewed')) if($citation->field('viewed'))
- 
$text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed')); $text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed'));
- 
if($citation->field('url')) if($citation->field('url'))
- 
$text.=', <'.$citation->field('url').'>'; $text.=', <'.$citation->field('url').'>';
- 
return $text.'.'; return $text.'.';
- 
} }
- 
- 
static function electronicTranscription($citation) static function electronicTranscription($citation)
- 
{ {
- 
$text=''; $text='';
- 
if(!$citation->field('url')) if(!$citation->field('url'))
- 
return $text; return $text;
- 
if($citation->field('electronicdesc')) if($citation->field('electronicdesc'))
- 
$text.=', '.$citation->field('electronicdesc'); $text.=', '.$citation->field('electronicdesc');
- 
if($citation->field('viewed')) if($citation->field('viewed'))
- 
$text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed')); $text.=', viewed '.CSUHarvard_Style::formatDate($citation->field('viewed'));
- 
if($citation->field('url')) if($citation->field('url'))
- 
$text.=', <'.$citation->field('url').'>'; $text.=', <'.$citation->field('url').'>';
- 
return $text; return $text;
- 
} }
- 
- 
static function electronicVer($citation) static function electronicVer($citation)
- 
{ {
- 
$text=''; $text='';
- 
if($citation->field('electronicversion')) if($citation->field('electronicversion'))
- 
$text.=' electronic version'; $text.=' electronic version';
- 
return $text; return $text;
- 
} }
- 
- 
static function formatDate($date) static function formatDate($date)
- 
{ {
- 
$date2=split('/', $date); $date2=split('/', $date);
- 
if(count($date2)==3) if(count($date2)==3)
- 
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) if(count($date2)==2)
- 
return date('F Y', strtotime($date2[1].'/1/'.$date2[0])); return date('F Y', strtotime($date2[1].'/1/'.$date2[0]));
- 
if(count($date2)==1) if(count($date2)==1)
- 
return date('Y', strtotime('1/1/'.$date2[0])); return date('Y', strtotime('1/1/'.$date2[0]));
- 
return $date; return $date;
- 
} }
- 
- 
static function formatPeriodical($periodical) static function formatPeriodical($periodical)
- 
{ {
- 
preg_match('/(.*)(\(.*\))/', $periodical, $match); preg_match('/(.*)(\(.*\))/', $periodical, $match);
- 
if(count($match)==0) if(count($match)==0)
- 
return "''".$periodical."''"; return "''".$periodical."''";
- 
return "''".trim($match[1])."'' ".$match[2]; return "''".trim($match[1])."'' ".$match[2];
- 
} }
- 
- 
} }
- 
- 
?></pre> ?></pre>

Current revision

<?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: McHenry (2004) and McHenry (2006) => McHenry (2004, 2006)
    uasort($articles['articles'], array("CSUHarvard_Style", "intextListCmp"));
    $text=array();
    $lastarticle=null;
    $articlelist=array();
    foreach($articles['articles'] as $name=>$article)
    {
      $author=CSUHarvard_Style::formatNames(array('type'=>$articles['type']), $article['article']->authors());
      if(!array_key_exists($author, $articlelist))
        $articlelist[$author]=array();
      $articlelist[$author][$name]=$article;
    }
    foreach($articlelist as $author=>$authorsarticles)
    {
      //TODO: articlenotfound
      if(count($authorsarticles)==1)
      {
        $article=array_keys($authorsarticles);
        $article=$authorsarticles[$article[0]];
        $entry=$author;
        if($articles['type']=='name')
          $entry.=' ('.$article['article']->year().')';
        else
          $entry.=' '.$article['article']->year();
        if($article['note']!='')
          $entry.=', '.$article['note'];
        $entry="[[".$article['article']->referencename().'|'.$entry.']]';
      }
      else
      {
        $years=array();
        foreach($authorsarticles as $name=>$article)
        {
          $year=$article['article']->year();
          if($article['note']!='')
            $year.=', '.$article['note'];
          $years[]="[[".$article['article']->referencename().'|'.$year.']]';
        }
        $years=BibliographyFormat::makeList($years, ', ', ', ');
        $entry=$author;
        if($articles['type']=='name')
          $entry.=' ('.$years.')';
        else
          $entry.=' '.$years;
      }
      $text[]=BibliographyFormat::renderWikiText($entry);
    }
    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;
    }
    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 intextListCmp($a, $b)
  {
    return CSUHarvard_Style::referenceListCmp($a['article'], $b['article']);
  }

  static function referenceListCmp($a, $b)
  {
  #var_dump($a);
    $res=strcasecmp(CSUHarvard_Style::formatNames(array('type'=>'normal'), $a->authors(), true),
      CSUHarvard_Style::formatNames(array('type'=>'normal'), $b->authors(), true));
    if($res!=0) return $res;
    $res=$a->year()-$b->year();
    if($res!=0) return $res;
    return strcasecmp($a->title(), $b->title());
  }

  static function orderReferences($articles)
  {
    uasort($articles, array("CSUHarvard_Style", "referenceListCmp"));
    $lastname='';
    $count=0;
    #var_dump($articles);
    foreach($articles as $id=>$article)
    {
      $name=CSUHarvard_Style::formatNames(array('type'=>'normal'), $article->authors(), true);
      if($name==$lastname && $lastarticle && $lastarticle->rawYear()==$article->rawYear())
      {
        if($count==0)
          $lastarticle->displayYear=$lastarticle->rawYear().chr(97+$count++);
        $article->displayYear=$article->year().chr(97+$count++);
      }
      else
        $count=0;
      $lastname=$name;
      $lastarticle=$article;
    }
    return $articles;
  }  
  
  static function referenceList($articles)
  {
    $refrences='';
    foreach($articles as $article)
    {
      $refrences.='<p class="bibliographicReference">'.CSUHarvard_Style::reference($article)."</p>\n";
    }
    return '<div class="bibliographicReferences">'.$refrences.'</div>';
    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->authors(), true).' '.$citation->year().']], '.$citation->title().'?';
  }
  
  static function referenceBook($citation)
  {
    $text='[['.$citation->referencename().'|';
    $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), 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->authors(), 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)
  {
    if(!$citation->field('viewed') && !$citation->field('url'))
      return CSUHarvard_Style::referenceUnknownType($citation);
    $text='[['.$citation->referencename().'|';
    if($citation->field('author'))
      $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->authors(), true);
    else
    {
      if($citation->field('editor'))
        $text.=CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation->editors(), true).(count($citation->editors())==1?" (ed.)":" (eds.)");
      else
        $text.="?";
    }
    $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]));
    if(count($date2)==1)
      return date('Y', strtotime('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];
  }
  
}

?>
Personal tools