You are here

class csl_text in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_text
  2. 7.2 modules/CiteProc/CSL.inc \csl_text

Hierarchy

Expanded class hierarchy of csl_text

File

modules/CiteProc/CSL.inc, line 1432
CiteProc-PHP.

View source
class csl_text extends csl_format {
  public $source;
  protected $var;

  /**
   *
   */
  public function init($dom_node, $citeproc) {
    foreach (array(
      'variable',
      'macro',
      'term',
      'value',
    ) as $attr) {
      if ($dom_node
        ->hasAttribute($attr)) {
        $this->source = $attr;
        if ($this->source == 'macro') {
          $this->var = str_replace(' ', '_', $dom_node
            ->getAttribute($attr));
        }
        else {
          $this->var = $dom_node
            ->getAttribute($attr);
        }
      }
    }
  }

  /**
   *
   */
  public function init_formatting() {
    if ($this->variable == 'title') {
      $this->span_class = 'biblio-title';
    }
    parent::init_formatting();
  }

  /**
   *
   */
  public function render($data = NULL, $mode = NULL) {
    $text = '';
    if (in_array($this->var, $this->citeproc->quash)) {
      return;
    }
    switch ($this->source) {
      case 'variable':
        if (!isset($data->{$this->variable}) || empty($data->{$this->variable}) || trim($data->{$this->variable}) == FALSE) {
          return;
        }
        if ($this->variable == 'biblio_url') {
          $text = l($data->{$this->variable}, $data->{$this->variable});
        }
        else {
          $text = $data->{$this->variable};

          //$this->data[$this->var];  // include the contents of a variable
        }
        break;
      case 'macro':
        $macro = $this->var;

        // Trigger the macro process.
        $text = $this->citeproc
          ->render_macro($macro, $data, $mode);
        break;
      case 'term':
        $form = ($form = $this->form) ? $form : '';
        $text = $this->citeproc
          ->get_locale('term', $this->var, $form);
        break;
      case 'value':

        // $this->var;  // dump the text verbatim.
        $text = $this->var;
        break;
    }
    if (empty($text)) {
      return;
    }
    $text = $this
      ->format($text);
    if ($this->variable == 'title') {
      $url = biblio_get_title_url_info($data);
      $text = l($text, $url['link'], $url['options']);
    }
    return $text;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
csl_collection::$elements protected property
csl_collection::add_element public function
csl_element::$attributes protected property
csl_element::$citeproc protected property
csl_element::get_attributes public function
csl_element::get_hier_attributes public function
csl_element::name public function
csl_element::set_attributes public function
csl_element::__get public function
csl_element::__isset public function
csl_element::__set public function
csl_element::__unset public function
csl_format::$format protected property 1
csl_format::$no_op protected property
csl_format::format public function Overrides csl_collection::format 1
csl_format::__construct public function Overrides csl_element::__construct 2
csl_text::$source public property
csl_text::$var protected property
csl_text::init public function Overrides csl_element::init
csl_text::init_formatting public function Overrides csl_format::init_formatting
csl_text::render public function Overrides csl_rendering_element::render