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