1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Ingo_Script_Sieve_Test_Body extends Ingo_Script_Sieve_Test
13: {
14: 15: 16: 17: 18:
19: public function __construct($vars = array())
20: {
21: $this->_vars['comparator'] = isset($vars['comparator'])
22: ? $vars['comparator']
23: : 'i;ascii-casemap';
24: $this->_vars['match-type'] = isset($vars['match-type'])
25: ? $vars['match-type']
26: : ':is';
27: $this->_vars['strings'] = isset($vars['strings'])
28: ? $vars['strings']
29: : '';
30: }
31:
32: 33: 34: 35: 36: 37:
38: public function check()
39: {
40: return preg_split('((?<!\\\)\,|\r\n|\n|\r)', $this->_vars['strings']);
41: }
42:
43: 44: 45: 46: 47:
48: public function toCode()
49: {
50: $code = 'body ' .
51: ':comparator "' . $this->_vars['comparator'] . '" ' .
52: $this->_vars['match-type'] . ' ';
53:
54: $strings = preg_split('(\r\n|\n|\r)', $this->_vars['strings']);
55: $strings = array_filter($strings);
56: if (count($strings) > 1) {
57: $code .= "[";
58: $stringlist = '';
59: foreach ($strings as $str) {
60: $stringlist .= empty($stringlist) ? '"' : ', "';
61: $stringlist .= Ingo_Script_Sieve::escapeString($str, $this->_vars['match-type'] == ':regex') . '"';
62: }
63: $code .= $stringlist . "] ";
64: } elseif (count($strings) == 1) {
65: $code .= '"' . Ingo_Script_Sieve::escapeString($strings[0], $this->_vars['match-type'] == ':regex') . '" ';
66: } else {
67: return _("No strings specified");
68: }
69:
70: return $code;
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function requires()
80: {
81: return ($this->_vars['match-type'] == ':regex')
82: ? array('regex', 'body')
83: : array('body');
84: }
85:
86: }
87: