1: <?php
2: /**
3: * The Horde_Mime_Viewer_Smil renders SMIL documents to very basic HTML.
4: *
5: * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (LGPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9: *
10: * @author Jan Schneider <jan@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
13: * @package Mime_Viewer
14: */
15: class Horde_Mime_Viewer_Smil extends Horde_Mime_Viewer_Base
16: {
17: /**
18: * Handle for the XML parser object.
19: *
20: * @var resource
21: */
22: protected $_parser;
23:
24: /**
25: * String buffer to hold the generated content
26: *
27: * @var string
28: */
29: protected $_content;
30:
31: /**
32: * This driver's display capabilities.
33: *
34: * @var array
35: */
36: protected $_capability = array(
37: 'full' => true,
38: 'info' => false,
39: 'inline' => true,
40: 'raw' => false
41: );
42:
43: /**
44: * Return the full rendered version of the Horde_Mime_Part object.
45: *
46: * @return array See parent::render().
47: */
48: protected function _render()
49: {
50: return $this->_renderFullReturn($this->_renderInline());
51: }
52:
53: /**
54: * Return the rendered inline version of the Horde_Mime_Part object.
55: *
56: * @return array See parent::render().
57: */
58: protected function _renderInline()
59: {
60: $this->_content = '';
61:
62: /* Create a new parser and set its default properties. */
63: $this->_parser = xml_parser_create();
64: xml_set_object($this->_parser, $this);
65: xml_set_element_handler($this->_parser, '_startElement', '_endElement');
66: xml_set_character_data_handler($this->_parser, '_defaultHandler');
67: xml_parse($this->_parser, $this->_mimepart->getContents(), true);
68: xml_parser_free($this->_parser);
69:
70: return $this->_renderReturn(
71: $this->_content,
72: 'text/html; charset=UTF-8'
73: );
74: }
75:
76: /**
77: * User-defined function callback for start elements.
78: *
79: * @param object $parser Handle to the parser instance.
80: * @param string $name The name of this XML element.
81: * @param array $attrs List of this element's attributes.
82: */
83: protected function _startElement($parser, $name, $attrs)
84: {
85: switch ($name) {
86: case 'IMG':
87: if (isset($attrs['SRC'])) {
88: $this->_content .= '<img src="' . htmlspecialchars($attrs['SRC']) . '" />';
89: }
90: break;
91: }
92: }
93:
94: /**
95: * User-defined function callback for end elements.
96: *
97: * @param object $parser Handle to the parser instance.
98: * @param string $name The name of this XML element.
99: */
100: protected function _endElement($parser, $name)
101: {
102: }
103:
104: /**
105: * User-defined function callback for character data.
106: *
107: * @param object $parser Handle to the parser instance.
108: * @param string $data String of character data.
109: */
110: protected function _defaultHandler($parser, $data)
111: {
112: $data = trim($data);
113: if (!empty($data)) {
114: $this->_content .= ' ' . htmlspecialchars($data);
115: }
116: }
117:
118: }
119: