1: <?php
2: /**
3: * The Horde_Mime_Viewer_Deb class renders out lists of files in Debian
4: * packages by using the dpkg tool to query the 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: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @package Mime_Viewer
15: */
16: class Horde_Mime_Viewer_Deb extends Horde_Mime_Viewer_Base
17: {
18: /**
19: * This driver's display capabilities.
20: *
21: * @var array
22: */
23: protected $_capability = array(
24: 'full' => false,
25: 'info' => true,
26: 'inline' => false,
27: 'raw' => false
28: );
29:
30: /**
31: * Metadata for the current viewer/data.
32: *
33: * @var array
34: */
35: protected $_metadata = array(
36: 'compressed' => true,
37: 'embedded' => false,
38: 'forceinline' => false
39: );
40:
41: /**
42: * Constructor.
43: *
44: * @param Horde_Mime_Part $mime_part The object with the data to be
45: * rendered.
46: * @param array $conf Configuration:
47: * <pre>
48: * 'location' - (string) Location of the dpkg binary [REQUIRED].
49: * 'monospace' - (string) A class to use to display monospace text inline.
50: * DEFAULT: Uses style="font-family:monospace"
51: * </pre>
52: *
53: * @throws InvalidArgumentException
54: */
55: public function __construct(Horde_Mime_Part $part, array $conf = array())
56: {
57: $this->_required = array_merge($this->_required, array(
58: 'location'
59: ));
60:
61: parent::__construct($part, $conf);
62: }
63:
64: /**
65: * Return the rendered information about the Horde_Mime_Part object.
66: *
67: * @return array See parent::render().
68: */
69: protected function _renderInfo()
70: {
71: /* Check to make sure the viewer program exists. */
72: if (!($location = $this->getConfigParam('location')) ||
73: !file_exists($location)) {
74: return array();
75: }
76:
77: $data = '';
78: $tmp_deb = $this->_getTempFile();
79:
80: file_put_contents($tmp_deb, $this->_mimepart->getContents());
81:
82: $fh = popen($location . ' -f ' . $tmp_deb . ' 2>&1', 'r');
83: while ($rc = fgets($fh, 8192)) {
84: $data .= $rc;
85: }
86: pclose($fh);
87:
88: $monospace = $this->getConfigParam('monospace');
89:
90: return $this->_renderReturn(
91: '<span ' .
92: ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') .
93: htmlspecialchars($data) . '</span>',
94: 'text/html; charset=UTF-8'
95: );
96: }
97:
98: }
99: