Failed Conditions
Pull Request — master (#3372)
by Andreas
08:37 queued 05:41
created

DisplayRow::show()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

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

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
88
            if ($d) echo hsc($d) . '<br />';
0 ignored issues
show
Bug introduced by
It seems like $d defined by $this->mediaFile->getMet...EXIF.TIFFUserComment')) on line 75 can also be of type array<string,?>; however, hsc() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
89
            if ($t) echo '<em>' . hsc($k) . '</em>';
90
            echo '</p>';
91
        }
92
        echo '</div>';
93
    }
94
95
}
96