File: smil.php

package info (click to toggle)
imp4 4.2-4lenny3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,252 kB
  • ctags: 5,316
  • sloc: php: 21,340; xml: 19,302; makefile: 68; sql: 14
file content (112 lines) | stat: -rw-r--r-- 3,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php

require_once 'Horde/MIME/Viewer/smil.php';

/**
 * The MIME_Viewer_smil renders SMIL documents to very basic HTML.
 *
 * $Horde: imp/lib/MIME/Viewer/smil.php,v 1.4.2.2 2008/01/02 11:31:51 jan Exp $
 *
 * Copyright 2006-2008 The Horde Project (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
 *
 * @author  Jan Schneider <jan@horde.org>
 * @author  Michael Slusarz <slusarz@horde.org>
 * @since   IMP 4.2
 * @package Horde_MIME_Viewer
 */
class IMP_MIME_Viewer_smil extends MIME_Viewer_smil {

    /**
     * The MIME_Contents object, needed for the _callback() function.
     *
     * @var MIME_Contents
     */
    var $_contents;

    /**
     * The list of related parts to the current part.
     *
     * @var array
     */
    var $_related = null;

    /**
     * Renders out the contents.
     *
     * @param array $params  Any parameters the Viewer may need.
     *
     * @return string  The rendered contents.
     */
    function render($params)
    {
        $this->_contents = &$params[0];
        return parent::render($params);
    }

    /**
     * User-defined function callback for start elements.
     *
     * @access private
     *
     * @param object $parser  Handle to the parser instance.
     * @param string $name    The name of this XML element.
     * @param array $attrs    List of this element's attributes.
     */
    function _startElement($parser, $name, $attrs)
    {
        switch ($name) {
        case 'IMG':
            if (isset($attrs['SRC'])) {
                $rp = $this->_getRelatedLink($attrs['SRC']);
                if ($rp !== false) {
                    $this->_content .= '<img src="' . $this->_contents->urlView($rp, 'view_attach') . '" alt="" /><br />';
                }
            }
            break;

        case 'TEXT':
            if (isset($attrs['SRC'])) {
                $rp = $this->_getRelatedLink($attrs['SRC']);
                if ($rp !== false) {
                    $this->_content .= htmlspecialchars($rp->getContents()) . '<br />';
                }
            }
            break;
        }
    }

    /**
     * Get related parts.
     *
     * @access private
     *
     * @param string $cid  The CID to search for.
     *
     * @return mixed  Either the related MIME_Part or false.
     */
    function _getRelatedLink($cid)
    {
        if ($this->_related === null) {
            $this->_related = false;
            $related = $this->mime_part->getInformation('related_part');
            if ($related !== false) {
                $relatedPart = $this->_contents->getMIMEPart($related);
                $this->_related = $relatedPart->getCIDList();
            }
        }

        if ($this->_related) {
            $key = array_search('<' . $cid . '>', $this->_related);
            if ($key !== false) {
                $cid_part = $this->_contents->getDecodedMIMEPart($key);
                return $cid_part;
            }
        }

        return false;
    }

}