1: <?php
2:
3: 4: 5: 6: 7:
8:
9: namespace academicpuma\citeproc;
10:
11: 12: 13: 14: 15:
16:
17: class PIf extends RenderingElement {
18:
19: function evaluate($data) {
20: $match = (($match = $this->match)) ? $match : 'all';
21: if (($types = $this->type)) {
22: $types = explode(' ', $types);
23: $matches = 0;
24: foreach ($types as $type) {
25: if (isset($data->type)) {
26: if ($data->type == $type && $match == 'any')
27: return TRUE;
28: if ($data->type != $type && $match == 'all')
29: return FALSE;
30: if ($data->type == $type)
31: $matches++;
32: }
33: }
34: if ($match == 'all' && $matches == count($types))
35: return TRUE;
36: if ($match == 'none' && $matches == 0)
37: return TRUE;
38: return FALSE;
39: }
40: if (($variables = $this->variable)) {
41: $variables = explode(' ', $variables);
42: $matches = 0;
43: foreach ($variables as $var) {
44: if (isset($data->$var) && !empty($data->$var) && $match == 'any')
45: return TRUE;
46: if ((!isset($data->$var) || empty($data->$var)) && $match == 'all')
47: return FALSE;
48: if (isset($data->$var) && !empty($data->$var))
49: $matches++;
50: }
51: if ($match == 'all' && $matches == count($variables))
52: return TRUE;
53: if ($match == 'none' && $matches == 0)
54: return TRUE;
55: return FALSE;
56: }
57: if (($is_numeric = $this->{'is-numeric'})) {
58: $variables = explode(' ', $is_numeric);
59: $matches = 0;
60: foreach ($variables as $var) {
61: if (isset($data->$var)) {
62: if (is_numeric($data->$var) && $match == 'any')
63: return TRUE;
64: if (!is_numeric($data->$var)) {
65: if (preg_match('/(?:^\d+|\d+$)/', $data->$var)) {
66: $matches++;
67: } elseif ($match == 'all') {
68: return FALSE;
69: }
70: }
71: if (is_numeric($data->$var))
72: $matches++;
73: }
74: }
75: if ($match == 'all' && $matches == count($variables))
76: return TRUE;
77: if ($match == 'none' && $matches == 0)
78: return TRUE;
79: return FALSE;
80: }
81: if (isset($this->locator))
82: $test = explode(' ', $this->type);
83:
84: return FALSE;
85: }
86:
87: }
88: