1: <?php
2: /**
3: * The Horde_Mime_Viewer_Wordperfect class renders out WordPerfect documents
4: * in HTML format by using the libwpd package.
5: *
6: * libpwd website: http://libwpd.sourceforge.net/
7: *
8: * Copyright 2007-2012 Horde LLC (http://www.horde.org/)
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 Matt Selsky <selsky@columbia.edu>
14: * @category Horde
15: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
16: * @package Mime_Viewer
17: */
18: class Horde_Mime_Viewer_Wordperfect 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 wpd2html 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_wpd = $this->_getTempFile();
67: $tmp_output = $this->_getTempFile();
68:
69: file_put_contents($tmp_wpd, $this->_mimepart->getContents());
70:
71: exec($location . ' ' . $tmp_wpd . ' > ' . $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 WordPerfect document");
76:
77: return $this->_renderReturn(
78: $data,
79: 'text/html; charset=UTF-8'
80: );
81: }
82:
83: }
84: