1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Compose_Stationery implements ArrayAccess, Countable, Iterator
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28: protected $_stationery;
29:
30: 31: 32:
33: public function __construct()
34: {
35: $slist = @unserialize($GLOBALS['prefs']->getValue('stationery'));
36: $this->_stationery = is_array($slist)
37: ? $slist
38: : array();
39: }
40:
41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
51: public function getContent($id, IMP_Prefs_Identity $identity, $msg,
52: $html = false)
53: {
54: $s_content = $this[$id]['c'];
55:
56: if (strpos($s_content, '%s') !== false) {
57: $sig = $identity->getSignature($html ? 'html' : 'text');
58:
59: switch ($this[$id]['t']) {
60: case 'html':
61: if (!$html) {
62: $s_content = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($s_content, 'Html2text', array('charset' => 'UTF-8'));
63: }
64: break;
65:
66: case 'text':
67: if ($html) {
68: $s_content = IMP_Compose::text2html($s_content);
69: }
70: break;
71: }
72:
73: $msg = str_replace(array("\r\n", $sig), array("\n", ''), $msg);
74: $s_content = str_replace('%s', $sig, $s_content);
75: }
76:
77: return (strpos($s_content, '%c') === false)
78: ? $s_content
79: : str_replace('%c', $msg, $s_content);
80: }
81:
82: 83: 84:
85: protected function _save()
86: {
87: $GLOBALS['prefs']->setValue('stationery', serialize($this->_stationery));
88: }
89:
90:
91:
92: public function offsetExists($offset)
93: {
94: return isset($this->_stationery[$offset]);
95: }
96:
97: public function offsetGet($offset)
98: {
99: return isset($this->_stationery[$offset])
100: ? $this->_stationery[$offset]
101: : null;
102: }
103:
104: public function offsetSet($offset, $value)
105: {
106: if (is_null($offset)) {
107: $this->_stationery[] = $value;
108: } else {
109: $this->_stationery[$offset] = $value;
110: }
111:
112: $this->_save();
113: }
114:
115:
116: public function offsetUnset($offset)
117: {
118: if (isset($this->_stationery[$offset])) {
119: unset($this->_stationery[$offset]);
120: $this->_stationery = array_values($this->_stationery);
121: $this->_save();
122: }
123: }
124:
125:
126:
127: public function count()
128: {
129: return count($this->_stationery);
130: }
131:
132:
133:
134: public function current()
135: {
136: return current($this->_stationery);
137: }
138:
139: public function key()
140: {
141: return key($this->_stationery);
142: }
143:
144: public function next()
145: {
146: next($this->_stationery);
147: }
148:
149: public function rewind()
150: {
151: reset($this->_stationery);
152: }
153:
154: public function valid()
155: {
156: return (key($this->_stationery) !== null);
157: }
158:
159: }
160: