BibliographicExtension/bibliographystyle-csu.php

From PeacockWiki

(Difference between revisions)
Jump to: navigation, search

Revision as of 10:54, 25 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, $citation)
  {
    $maxNames=3;
    $names1=$citation->names();
    $count=count($names1);
    if($count>$maxNames)
      $names=$names1[0][1].' et al.';
    else
    {
      $names=array();
      foreach($names1 as $name)
      {
        $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']);
      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'];
    formatNames();
    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);
    return BibliographyFormat::renderWikiText('[['.$citation->referencename().'|'.CSUHarvard_Style::formatNames(array('type'=>'normal'), $citation).' '.$citation->year().']], '.$citation->title());
  }
  
  static function notfoundText($citation)
  {
    return BibliographyFormat::renderWikiText("[[".$citation->mFields['reference']."|Article not found: ".$citation->referencename()."]]");
  }

}

?>
Personal tools