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:  * To change this license header, choose License Headers in Project Properties.
  5:  * To change this template file, choose Tools | Templates
  6:  * and open the template in the editor.
  7:  */
  8: 
  9: namespace academicpuma\citeproc;
 10: 
 11: /**
 12:  * Description of csl_date
 13:  *
 14:  * @author sebastian
 15:  */
 16: 
 17: 
 18: class Date extends Format {
 19: 
 20:     function init($dom_node, $citeproc) {
 21:         $locale_elements = array();
 22: 
 23:         if ($form = $this->form) {
 24:             $local_date = $this->citeproc->get_locale('date_options', $form);
 25:             $dom_elem = dom_import_simplexml($local_date[0]);
 26:             if ($dom_elem) {
 27:                 foreach ($dom_elem->childNodes as $node) {
 28:                     if ($node->nodeType == 1) {
 29:                         $locale_elements[] = Factory::create($node, $citeproc);
 30:                     }
 31:                 }
 32:             }
 33: 
 34:             //debug($dom_node->childNodes);
 35: 
 36:             foreach ($dom_node->childNodes as $node) {
 37:                 if ($node->nodeType == 1) {
 38:                     $element = Factory::create($node, $citeproc);
 39: 
 40:                     foreach ($locale_elements as $key => $locale_element) {
 41:                         if ($locale_element->name == $element->name) {
 42:                             $locale_elements[$key]->attributes = array_merge($locale_element->attributes, $element->attributes);
 43:                             $locale_elements[$key]->format = $element->format;
 44:                             break;
 45:                         } else {
 46:                             $locale_elements[] = $element;
 47:                         }
 48:                     }
 49:                 }
 50:             }
 51:             if ($date_parts = $this->{'date-parts'}) {
 52:                 $parts = explode('-', $date_parts);
 53:                 foreach ($locale_elements as $key => $element) {
 54:                     if (array_search($element->name, $parts) === FALSE) {
 55:                         unset($locale_elements[$key]);
 56:                     }
 57:                 }
 58:                 if (count($locale_elements) != count($parts)) {
 59:                     foreach ($parts as $part) {
 60:                         $element = new DatePart();
 61:                         $element->name = $part;
 62:                         $locale_elements[] = $element;
 63:                     }
 64:                 }
 65:                 // now re-order the elements
 66:                 foreach ($parts as $part) {
 67:                     foreach ($locale_elements as $key => $element)
 68:                         if ($element->name == $part) {
 69:                             $this->elements[] = $element;
 70:                             unset($locale_elements[$key]);
 71:                         }
 72:                 }
 73:             }
 74:             //Changes @ 2012-06-23 from Sebastian Böttger
 75:             /*
 76:             else if (isset($this->{'literal'})) {
 77:                 $element = new DatePart();
 78:                 $element->name = $this->{'literal'};
 79:                 $this->elements[] = $element;
 80:             }
 81:              * 
 82:              */
 83:             //END Changes      
 84:             else {
 85:                 $this->elements = $locale_elements;
 86:             }
 87:         } else {
 88:             parent::init($dom_node, $citeproc);
 89:         }
 90:     }
 91: 
 92:     function render($data, $mode = NULL) {
 93:         $date_parts = array();
 94:         $date = '';
 95:         $text = '';
 96: 
 97:         if (($var = $this->variable) && isset($data->{$var})) {
 98:             $date = $data->{$var}->{'date-parts'}[0];
 99:             foreach ($this->elements as $element) {
100:                 $date_parts[] = $element->render($date, $mode);
101:             }
102:             $text = implode('', $date_parts);
103:         }
104: 
105:         return $this->format($text);
106:     }
107: 
108: }
109: 
API documentation generated by ApiGen