1<?php
2
3namespace dokuwiki\Ui\Media;
4
5use dokuwiki\Utf8\PhpString;
6
7/**
8 * Display a MediaFile in the Media Popup
9 */
10class DisplayRow extends DisplayTile
11{
12    /** @inheritDoc */
13    public function show()
14    {
15        global $lang;
16        // FIXME Zebra classes have been dropped and need to be readded via CSS
17
18        $id = $this->mediaFile->getId();
19        $class = 'select mediafile mf_' . $this->mediaFile->getIcoClass();
20        $info = trim($this->formatDimensions('') . ' ' . $this->formatDate() . ' ' . $this->formatFileSize());
21        $jump = $this->scrollIntoView ? 'id="scroll__here"' : '';
22
23        echo '<div title="' . $id . '" ' . $jump . '>';
24        echo '<a id="h_:' . $id . '" class="' . $class . '">' .
25            $this->formatDisplayName() .
26            '</a> ';
27        echo '<span class="info">(' . $info . ')</span>' . NL;
28
29        // view button
30        $link = ml($id, '', true);
31        echo ' <a href="' . $link . '" target="_blank"><img src="' . DOKU_BASE . 'lib/images/magnifier.png" ' .
32            'alt="' . $lang['mediaview'] . '" title="' . $lang['mediaview'] . '" class="btn" /></a>';
33
34        // mediamanager button
35        $link = wl('', array('do' => 'media', 'image' => $id, 'ns' => getNS($id)));
36        echo ' <a href="' . $link . '" target="_blank"><img src="' . DOKU_BASE . 'lib/images/mediamanager.png" ' .
37            'alt="' . $lang['btn_media'] . '" title="' . $lang['btn_media'] . '" class="btn" /></a>';
38
39        // delete button
40        if ($this->mediaFile->isWritable() && $this->mediaFile->userPermission() >= AUTH_DELETE) {
41            $link = DOKU_BASE . 'lib/exe/mediamanager.php?delete=' . rawurlencode($id) .
42                '&amp;sectok=' . getSecurityToken();
43            echo ' <a href="' . $link . '" class="btn_media_delete" title="' . $id . '">' .
44                '<img src="' . DOKU_BASE . 'lib/images/trash.png" alt="' . $lang['btn_delete'] . '" ' .
45                'title="' . $lang['btn_delete'] . '" class="btn" /></a>';
46        }
47
48        echo '<div class="example" id="ex_' . str_replace(':', '_', $id) . '">';
49        echo $lang['mediausage'] . ' <code>{{:' . $id . '}}</code>';
50        echo '</div>';
51        if ($this->mediaFile->getWidth()) $this->showDetails();
52        echo '<div class="clearer"></div>' . NL;
53        echo '</div>' . NL;
54
55    }
56
57    /**
58     * Show Thumbnail and EXIF data
59     */
60    protected function showDetails()
61    {
62        $id = $this->mediaFile->getId();
63
64        echo '<div class="detail">';
65        echo '<div class="thumb">';
66        echo '<a id="d_:' . $id . '" class="select">';
67        echo $this->getPreviewHtml(120, 120);
68        echo '</a>';
69        echo '</div>';
70
71        // read EXIF/IPTC data
72        $t = $this->mediaFile->getMeta()->getField(array('IPTC.Headline', 'xmp.dc:title'));
73        $d = $this->mediaFile->getMeta()->getField(array(
74            'IPTC.Caption',
75            'EXIF.UserComment',
76            'EXIF.TIFFImageDescription',
77            'EXIF.TIFFUserComment',
78        ));
79        if (PhpString::strlen($d) > 250) $d = PhpString::substr($d, 0, 250) . '...';
80        $k = $this->mediaFile->getMeta()->getField(array('IPTC.Keywords', 'IPTC.Category', 'xmp.dc:subject'));
81
82        // print EXIF/IPTC data
83        if ($t || $d || $k) {
84            echo '<p>';
85            if ($t) echo '<strong>' . hsc($t) . '</strong><br />';
86            if ($d) echo hsc($d) . '<br />';
87            if ($t) echo '<em>' . hsc($k) . '</em>';
88            echo '</p>';
89        }
90        echo '</div>';
91    }
92
93}
94