Failed Conditions
Push — mediaitems ( 8f7d0e )
by Andreas
03:02
created

DisplayRow   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 45 4
B showDetails() 0 32 8
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 ($item['writable'] && $auth >= AUTH_DELETE) {
0 ignored issues
show
Bug introduced by
The variable $item does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $auth does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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 ($item['isimg']) media_printimgdetail($item);
54
        echo '<div class="clearer"></div>' . NL;
55
        echo '</div>' . NL;
56
57
    }
58
59
    public function showDetails()
60
    {
61
        $id = $this->mediaFile->getId();
62
63
        echo '<div class="detail">';
64
        echo '<div class="thumb">';
65
        echo '<a id="d_:' . $id . '" class="select">';
66
        echo $this->getPreviewHtml(120, 120);
67
        echo '</a>';
68
        echo '</div>';
69
70
        // read EXIF/IPTC data
71
        $t = $this->mediaFile->getMeta()->getField(array('IPTC.Headline', 'xmp.dc:title'));
72
        $d = $this->mediaFile->getMeta()->getField(array(
73
            'IPTC.Caption',
74
            'EXIF.UserComment',
75
            'EXIF.TIFFImageDescription',
76
            'EXIF.TIFFUserComment',
77
        ));
78
        if (PhpString::strlen($d) > 250) $d = PhpString::substr($d, 0, 250) . '...';
79
        $k = $this->mediaFile->getMeta()->getField(array('IPTC.Keywords', 'IPTC.Category', 'xmp.dc:subject'));
80
81
        // print EXIF/IPTC data
82
        if ($t || $d || $k) {
83
            echo '<p>';
84
            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 71 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...
85
            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 72 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...
86
            if ($t) echo '<em>' . hsc($k) . '</em>';
87
            echo '</p>';
88
        }
89
        echo '</div>';
90
    }
91
92
}
93