Overview

Namespaces

  • academicpuma
    • citeproc

Classes

  • Bibliography
  • Choose
  • Citation
  • CiteProc
  • Collection
  • CSLUtils
  • Date
  • DatePart
  • Element
  • EtAl
  • Factory
  • Format
  • Group
  • Info
  • Label
  • Layout
  • Locale
  • Macro
  • Macros
  • Mapper
  • Name
  • Names
  • Number
  • Option
  • Options
  • PElse
  • PElseIf
  • PIf
  • RenderingElement
  • Sort
  • Style
  • Substitute
  • Terms
  • Text
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  *   CiteProc-PHP
  5:  *
  6:  *   Copyright (C) 2010 - 2011  Ron Jerome, all rights reserved
  7:  *
  8:  *   This program is free software: you can redistribute it and/or modify
  9:  *   it under the terms of the GNU General Public License as published by
 10:  *   the Free Software Foundation, either version 3 of the License, or
 11:  *   (at your option) any later version.
 12:  *
 13:  *   This program is distributed in the hope that it will be useful,
 14:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 15:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16:  *   GNU General Public License for more details.
 17:  *
 18:  *   You should have received a copy of the GNU General Public License
 19:  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 20:  *
 21:  */
 22: 
 23: namespace academicpuma\citeproc;
 24: use \DOMDocument;
 25: 
 26: class CiteProc {
 27: 
 28:     private static $instance;
 29:     public $bibliography = null;
 30:     public $citation = null;
 31:     public $style = null;
 32:     protected $macros = null;
 33:     private $info = null;
 34:     protected $locale = null;
 35:     protected $style_locale = null;
 36:     private $mapper = null;
 37:     public $quash = null;
 38:     /**
 39:      * 
 40:      * @return citeproc 
 41:      */
 42:     public static function getInstance($xml) {
 43: 
 44:         if (self::$instance == null) {
 45: 
 46:             self::$instance = new CiteProc($xml);
 47:         }
 48: 
 49:         return self::$instance;
 50:     }
 51: 
 52:     function __construct($csl = NULL, $lang = 'en') {
 53:         if ($csl) {
 54:             $this->init($csl, $lang);
 55:         }
 56:     }
 57:     
 58:     function init($csl, $lang) {
 59:         // define field values appropriate to your data in the csl_mapper class and un-comment the next line.        
 60:         $this->mapper = new Mapper();
 61:         $this->quash = array();
 62: 
 63:         $csl_doc = new DOMDocument();
 64: 
 65:         if ($csl_doc->loadXML($csl)) {
 66: 
 67:             $style_nodes = $csl_doc->getElementsByTagName('style');
 68:             if ($style_nodes) {
 69:                 foreach ($style_nodes as $style) {
 70:                     $this->style = new Style($style);
 71:                 }
 72:             }
 73: 
 74:             $info_nodes = $csl_doc->getElementsByTagName('info');
 75:             if ($info_nodes) {
 76:                 foreach ($info_nodes as $info) {
 77:                     $this->info = new Info($info);
 78:                 }
 79:             }
 80: 
 81:             $this->locale = new Locale($lang);
 82:             $this->locale->set_style_locale($csl_doc);
 83: 
 84: 
 85:             $macro_nodes = $csl_doc->getElementsByTagName('macro');
 86:             if ($macro_nodes) {
 87:                 $this->macros = new Macros($macro_nodes, $this);
 88:             }
 89: 
 90:             $citation_nodes = $csl_doc->getElementsByTagName('citation');
 91:             foreach ($citation_nodes as $citation) {
 92:                 $this->citation = new Citation($citation, $this);
 93:             }
 94: 
 95:             $bibliography_nodes = $csl_doc->getElementsByTagName('bibliography');
 96:             foreach ($bibliography_nodes as $bibliography) {
 97:                 $this->bibliography = new Bibliography($bibliography, $this);
 98:             }
 99:         }
100:     }
101: 
102:     function render($data, $mode = NULL) {
103:         $text = '';
104:         switch ($mode) {
105:             case 'citation':
106:                 $text .= (isset($this->citation)) ? $this->citation->render($data) : '';
107:                 break;
108:             case 'bibliography':
109:             default:
110:                 $text .= (isset($this->bibliography)) ? $this->bibliography->render($data) : '';
111:                 break;
112:         }
113:         return $text;
114:     }
115: 
116:     function render_macro($name, $data, $mode) {
117:         return $this->macros->render_macro($name, $data, $mode);
118:     }
119: 
120:     function get_locale($type, $arg1, $arg2 = NULL, $arg3 = NULL) {
121:         return $this->locale->get_locale($type, $arg1, $arg2, $arg3);
122:     }
123: 
124:     function map_field($field) {
125:         if ($this->mapper) {
126:             return $this->mapper->map_field($field);
127:         }
128:         return ($field);
129:     }
130: 
131:     function map_type($field) {
132:         if ($this->mapper) {
133:             return $this->mapper->map_type($field);
134:         }
135:         return ($field);
136:     }
137: 
138: }
139: 
API documentation generated by ApiGen