1: <?php
2:
3: 4: 5: 6: 7:
8:
9: namespace academicpuma\citeproc;
10:
11: 12: 13: 14: 15:
16:
17: class Text extends Format {
18:
19: public $source;
20: protected $var;
21:
22: function init($dom_node, $citeproc) {
23: foreach (array('variable', 'macro', 'term', 'value') as $attr) {
24: if ($dom_node->hasAttribute($attr)) {
25: $this->source = $attr;
26: if ($this->source == 'macro') {
27: $this->var = str_replace(' ', '_', $dom_node->getAttribute($attr));
28: } else {
29: $this->var = $dom_node->getAttribute($attr);
30: }
31: }
32: }
33: }
34:
35: function init_formatting() {
36:
37:
38:
39: parent::init_formatting();
40: }
41:
42: function render($data = NULL, $mode = NULL) {
43: $text = '';
44: if (in_array($this->var, $this->citeproc->quash))
45: return;
46:
47: switch ($this->source) {
48: case 'variable':
49: if (!isset($data->{$this->variable}) || empty($data->{$this->variable}))
50: return;
51: $text = $data->{$this->variable};
52: break;
53: case 'macro':
54: $macro = $this->var;
55: $text = $this->citeproc->render_macro($macro, $data, $mode);
56: break;
57: case 'term':
58: $form = (($form = $this->form)) ? $form : '';
59: $text = $this->citeproc->get_locale('term', $this->var, $form);
60: break;
61: case 'value':
62: $text = $this->var;
63: break;
64: }
65:
66: if (empty($text))
67: return;
68: return $this->format($text);
69: }
70:
71: public function getVar() {
72: return $this->var;
73: }
74:
75: }
76: