1: <?php
2: /**
3: * The Horde_Mime_Viewer_Msexcel class renders out Microsoft Excel
4: * documents in HTML format by using the Gnumeric 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_Msexcel 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 gnumeric 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 . ' -E Gnumeric_Excel:excel_dsf -T Gnumeric_html:html40 ' . $tmp_in . ' ' . $tmp_out);
71:
72: return $this->_renderReturn(
73: file_get_contents($tmp_out),
74: 'text/html; charset=UTF-8'
75: );
76: }
77:
78: }
79: