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_format
 13:  *
 14:  * @author sebastian
 15:  */
 16: 
 17: class Format extends RenderingElement {
 18: 
 19:     protected $no_op;
 20:     protected $format;
 21: 
 22:     function __construct($dom_node = NULL, $citeproc = NULL) {
 23:         parent::__construct($dom_node, $citeproc);
 24:         $this->init_formatting();
 25:     }
 26: 
 27:     function init_formatting() {
 28:         $this->no_op = TRUE;
 29:         $this->format = '';
 30:         if (isset($this->quotes) && strtolower($this->quotes) == "true") {
 31:             $this->quotes = array();
 32:             $this->quotes['punctuation-in-quote'] = $this->citeproc->get_locale('style_option', 'punctuation-in-quote');
 33:             $this->quotes['open-quote'] = $this->citeproc->get_locale('term', 'open-quote');
 34:             $this->quotes['close-quote'] = $this->citeproc->get_locale('term', 'close-quote');
 35:             $this->quotes['open-inner-quote'] = $this->citeproc->get_locale('term', 'open-inner-quote');
 36:             $this->quotes['close-inner-quote'] = $this->citeproc->get_locale('term', 'close-inner-quote');
 37:             $this->no_op = FALSE;
 38:         }
 39:         if (isset($this->{'prefix'}))
 40:             $this->no_op = FALSE;
 41:         if (isset($this->{'suffix'}))
 42:             $this->no_op = FALSE;
 43:         if (isset($this->{'display'}))
 44:             $this->no_op = FALSE;
 45: 
 46:         $this->format .= (isset($this->{'font-style'})) ? 'font-style: ' . $this->{'font-style'} . ';' : '';
 47:         $this->format .= (isset($this->{'font-family'})) ? 'font-family: ' . $this->{'font-family'} . ';' : '';
 48:         $this->format .= (isset($this->{'font-weight'})) ? 'font-weight: ' . $this->{'font-weight'} . ';' : '';
 49:         $this->format .= (isset($this->{'font-variant'})) ? 'font-variant: ' . $this->{'font-variant'} . ';' : '';
 50:         $this->format .= (isset($this->{'text-decoration'})) ? 'text-decoration: ' . $this->{'text-decoration'} . ';' : '';
 51:         $this->format .= (isset($this->{'vertical-align'})) ? 'vertical-align: ' . $this->{'vertical-align'} . ';' : '';
 52:         // $this->format .= (isset($this->{'display'})  && $this->{'display'}  == 'indent')  ? 'padding-left: 25px;' : '';
 53: 
 54:         if (isset($this->{'text-case'}) ||
 55:                 !empty($this->format) ||
 56:                 !empty($this->span_class) ||
 57:                 !empty($this->div_class)) {
 58:             $this->no_op = FALSE;
 59:         }
 60:     }
 61: 
 62:     function format($text) {
 63: 
 64:         if (empty($text) || $this->no_op)
 65:             return $text;
 66:         $quotes = $this->quotes;
 67:         $quotes = is_array($quotes) ? $quotes : array();
 68: 
 69:         if (isset($this->{'text-case'})) {
 70:             switch ($this->{'text-case'}) {
 71:                 case 'uppercase':
 72:                     $text = mb_strtoupper($text);
 73:                     break;
 74:                 case 'lowercase':
 75:                     $text = mb_strtolower($text);
 76:                     break;
 77:                 case 'capitalize-all':
 78:                 case 'title':
 79:                     $text = mb_convert_case($text, MB_CASE_TITLE);
 80:                     break;
 81:                 case 'capitalize-first':
 82:                     $chr1 = mb_strtoupper(mb_substr($text, 0, 1));
 83:                     $text = $chr1 . mb_substr($text, 1);
 84:                     break;
 85:             }
 86:         }
 87: 
 88:         $prefix = $this->prefix;
 89:         $prefix .= isset($quotes['open-quote']) ? $quotes['open-quote'] : '';
 90:         $suffix = $this->suffix;
 91:         if (isset($quotes['close-quote']) && !empty($suffix) && isset($quotes['punctuation-in-quote'])) {
 92:             if (strpos($suffix, '.') !== FALSE || strpos($suffix, ',') !== FALSE) {
 93:                 $suffix = $suffix . $quotes['close-quote'];
 94:             }
 95:         } elseif (isset($quotes['close-quote'])) {
 96:             $suffix = $quotes['close-quote'] . $suffix;
 97:         }
 98:         if (!empty($suffix)) { // gaurd against repeaded suffixes...
 99:             $no_tags = strip_tags($text);
100:             if (strlen($no_tags) && ($no_tags[(strlen($no_tags) - 1)] == $suffix[0])) {
101:                 $suffix = substr($suffix, 1);
102:             }
103:         }
104: 
105:         if (!empty($this->format) || !empty($this->span_class)) {
106:             $style = (!empty($this->format)) ? 'style="' . $this->format . '" ' : '';
107:             $class = (!empty($this->span_class)) ? 'class="' . $this->span_class . '"' : '';
108:             $text = '<span ' . $class . $style . '>' . $text . '</span>';
109:         }
110:         $div_class = $div_style = '';
111:         if (!empty($this->div_class)) {
112:             $div_class = (!empty($this->div_class)) ? 'class="' . $this->div_class . '"' : '';
113:         }
114:         if ($this->display == 'indent') {
115:             $div_style = 'style="text-indent: 0px; padding-left: 45px;"';
116:         }
117:         if ($div_class || $div_style) {
118:             return '<div ' . $div_class . $div_style . '>' . $prefix . $text . $suffix . '</div>';
119:         }
120: 
121:         return $prefix . $text . $suffix;
122:     }
123: 
124: }
125: 
126: 
API documentation generated by ApiGen