1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
37: class Horde_Mime_Viewer_Richtext extends Horde_Mime_Viewer_Base
38: {
39: 40: 41: 42: 43:
44: protected $_capability = array(
45: 'full' => true,
46: 'info' => false,
47: 'inline' => true,
48: 'raw' => false
49: );
50:
51: 52: 53: 54: 55:
56: protected function _render()
57: {
58: return $this->_renderFullReturn($this->_renderReturn(
59: $this->_toHTML(),
60: 'text/html; charset=' . $this->_mimepart->getCharset()
61:
62: ));
63: }
64:
65: 66: 67: 68: 69:
70: protected function _renderInline()
71: {
72: return $this->_renderReturn(
73: Horde_String::convertCharset($this->_toHTML(), $this->_mimepart->getCharset(), 'UTF-8'),
74: 'text/html; charset=UTF-8'
75: );
76: }
77:
78: 79: 80: 81: 82:
83: protected function _toHTML()
84: {
85: $text = trim($this->_mimepart->getContents());
86: if ($text == '') {
87: return array();
88: }
89:
90: 91: 92:
93: $text = ' ' . $text . ' ';
94:
95:
96: $text = preg_replace('/<comment.*>.*<\/comment>/Uis', '', $text);
97:
98: 99: 100:
101: $tags = '<bold><italic><fixed><smaller><bigger><underline><center><flushleft><flushright><indent><subscript><excerpt><paragraph><signature><lt><nl>';
102: $text = strip_tags($text, $tags);
103:
104:
105: $text = str_ireplace(array('<lt>', "\r\n"), array('<', ' '), $text);
106:
107:
108: $text = @htmlspecialchars($text, ENT_QUOTES, $this->_mimepart->getCharset());
109:
110: 111:
112: $text = str_ireplace(array('<nl>', '<np>'), array('<br />', '<p />'), $text);
113:
114: 115:
116: $replace = array(
117: '/(?<!<)<bold.*>(.*)<\/bold>/Uis' => '<span style="font-weight: bold">\1</span>',
118: '/(?<!<)<italic.*>(.*)<\/italic>/Uis' => '<span style="font-style: italic">\1</span>',
119: '/(?<!<)<fixed.*>(.*)<\/fixed>/Uis' => '<font face="fixed">\1</font>',
120: '/(?<!<)<smaller.*>(.*)<\/smaller>/Uis' => '<span style="font-size: smaller">\1</span>',
121: '/(?<!<)<bigger.*>(.*)<\/bigger>/Uis' => '<span style="font-size: larger">\1</span>',
122: '/(?<!<)<underline.*>(.*)<\/underline>/Uis' => '<span style="text-decoration: underline">\1</span>',
123: '/(?<!<)<center.*>(.*)<\/center>/Uis' => '<div align="center">\1</div>',
124: '/(?<!<)<flushleft.*>(.*)<\/flushleft>/Uis' => '<div align="left">\1</div>',
125: '/(?<!<)<flushright.*>(.*)<\/flushright>/Uis' => '<div align="right">\1</div>',
126: '/(?<!<)<indent.*>(.*)<\/indent>/Uis' => '<blockquote>\1</blockquote>',
127: '/(?<!<)<excerpt.*>(.*)<\/excerpt>/Uis' => '<cite>\1</cite>',
128: '/(?<!<)<subscript.*>(.*)<\/subscript>/Uis' => '<sub>\1</sub>',
129: '/(?<!<)<superscript.*>(.*)<\/superscript>/Uis' => '<sup>\1</sup>',
130: '/(?<!<)<heading.*>(.*)<\/heading>/Uis' => '<br /><div align="center" style="font-weight: bold">\1</div><br />',
131: '/(?<!<)<footing.*>(.*)<\/footing>/Uis' => '<br /><div align="center" style="font-weight: bold">\1</div><br />',
132: '/(?<!<)<paragraph.*>(.*)<\/paragraph>/Uis' => '<p>\1</p>',
133: '/(?<!<)<signature.*>(.*)<\/signature>/Uis' => '<address>\1</address>'
134: );
135: $text = preg_replace(array_keys($replace), array_values($replace), $text);
136:
137:
138: $text = substr($text, 1, -1);
139:
140:
141: $text = str_replace(array("\t", ' ', "\n "), array(' ', ' ', "\n "), $text);
142: if ($text[0] == ' ') {
143: $text = ' ' . substr($text, 1);
144: }
145:
146: return '<p style="font-size:100%;font-family:Lucida Console,Courier,Courier New;">' . nl2br($text) . '</p>';
147: }
148:
149: }
150: