1: <?php
2: /**
3: * The Horde_Mime_Viewer_Rtf class renders out Rich Text Format documents in
4: * HTML format by using the UnRTF package.
5: *
6: * UnRTF package: http://www.gnu.org/software/unrtf/unrtf.html
7: *
8: * Copyright 2007 Duck <duck@obala.net>
9: *
10: * See the enclosed file COPYING for license information (LGPL). If you
11: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
12: *
13: * @author Duck <duck@obala.net>
14: * @category Horde
15: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
16: * @package Mime_Viewer
17: */
18: class Horde_Mime_Viewer_Rtf extends Horde_Mime_Viewer_Base
19: {
20: /**
21: * This driver's display capabilities.
22: *
23: * @var array
24: */
25: protected $_capability = array(
26: 'full' => true,
27: 'info' => false,
28: 'inline' => false,
29: 'raw' => false
30: );
31:
32: /**
33: * Constructor.
34: *
35: * @param Horde_Mime_Part $mime_part The object with the data to be
36: * rendered.
37: * @param array $conf Configuration:
38: * <pre>
39: * 'location' - (string) Location of the unrtf binary.
40: * </pre>
41: *
42: * @throws InvalidArgumentException
43: */
44: public function __construct(Horde_Mime_Part $part, array $conf = array())
45: {
46: $this->_required = array_merge($this->_required, array(
47: 'location'
48: ));
49:
50: parent::__construct($part, $conf);
51: }
52:
53: /**
54: * Return the full rendered version of the Horde_Mime_Part object.
55: *
56: * @return array See parent::render().
57: */
58: protected function _render()
59: {
60: /* Check to make sure the viewer program exists. */
61: if (!($location = $this->getConfigParam('location')) ||
62: !file_exists($location)) {
63: return array();
64: }
65:
66: $tmp_rtf = $this->_getTempFile();
67: $tmp_output = $this->_getTempFile();
68:
69: file_put_contents($tmp_rtf, $this->_mimepart->getContents());
70:
71: exec($location . ' ' . $tmp_rtf . ' > ' . $tmp_output);
72:
73: $data = file_exists($tmp_output)
74: ? file_get_contents($tmp_output)
75: : Horde_Mime_Viewer_Translation::t("Unable to translate this RTF document");
76:
77: return $this->_renderReturn(
78: $data,
79: 'text/html; charset=UTF-8'
80: );
81: }
82:
83: }
84: