TranscoderVariable::getGifUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Transcoder plugin for Craft CMS
4
 *
5
 * Transcode videos to various formats, and provide thumbnails of the video
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\transcoder\variables;
12
13
use craft\helpers\UrlHelper;
14
use nystudio107\pluginvite\variables\ViteVariableInterface;
15
use nystudio107\pluginvite\variables\ViteVariableTrait;
16
use nystudio107\transcoder\Transcoder;
17
use yii\base\InvalidConfigException;
18
19
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
21
 * @package   Transcode
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
22
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
23
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
24
class TranscoderVariable implements ViteVariableInterface
25
{
26
    use ViteVariableTrait;
27
28
    // Public Methods
29
    // =========================================================================
30
31
    /**
32
     * Returns a URL to the transcoded video or "" if it doesn't exist (at which
33
     * time it will create it).
34
     *
35
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
36
     * @param $videoOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
37
     * @param bool $generate
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
38
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
39
     * @throws InvalidConfigException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
40
     * @bool $generate
0 ignored issues
show
Coding Style introduced by
Tag @bool cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Tag value for @bool tag indented incorrectly; expected 3 spaces but found 1
Loading history...
41
     *
42
     */
0 ignored issues
show
Coding Style introduced by
Additional blank lines found at end of doc comment
Loading history...
43
    public function getVideoUrl($filePath, $videoOptions, bool $generate = true): string
44
    {
45
        return Transcoder::$plugin->transcode->getVideoUrl($filePath, $videoOptions, $generate);
46
    }
47
48
    /**
49
     * Returns a URL to a video thumbnail
50
     *
51
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param $thumbnailOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
53
     *
54
     * @return string|false|null URL or path of the video thumbnail
55
     * @throws InvalidConfigException
56
     */
57
    public function getVideoThumbnailUrl($filePath, $thumbnailOptions): string|false|null
58
    {
59
        return Transcoder::$plugin->transcode->getVideoThumbnailUrl($filePath, $thumbnailOptions);
60
    }
61
62
    /**
63
     * Returns a URL to the transcoded audio file or "" if it doesn't exist
64
     * (at which time it will create it).
65
     *
66
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
67
     * @param $audioOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
68
     *
69
     * @return string
70
     * @throws InvalidConfigException
71
     */
72
    public function getAudioUrl($filePath, $audioOptions): string
73
    {
74
        return Transcoder::$plugin->transcode->getAudioUrl($filePath, $audioOptions);
75
    }
76
77
    /**
78
     * Extract information from a video/audio file
79
     *
80
     * @param      $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 1 spaces but found 6
Loading history...
81
     * @param bool $summary
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
82
     *
83
     * @return ?array
84
     * @throws InvalidConfigException
85
     */
86
    public function getFileInfo($filePath, bool $summary = false): ?array
87
    {
88
        return Transcoder::$plugin->transcode->getFileInfo($filePath, $summary);
89
    }
90
91
    /**
92
     * Get a video progress URL
93
     *
94
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
95
     * @param $videoOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
96
     *
97
     * @return string
98
     * @throws InvalidConfigException
99
     */
100
    public function getVideoProgressUrl($filePath, $videoOptions): string
101
    {
102
        $result = '';
103
        $filename = Transcoder::$plugin->transcode->getVideoFilename($filePath, $videoOptions);
104
        if (!empty($filename)) {
105
            $urlParams = [
106
                'filename' => $filename,
107
            ];
108
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
109
        }
110
111
        return $result;
112
    }
113
114
    /**
115
     * Get an audio progress URL
116
     *
117
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
118
     * @param $audioOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
119
     *
120
     * @return string
121
     * @throws InvalidConfigException
122
     */
123
    public function getAudioProgressUrl($filePath, $audioOptions): string
124
    {
125
        $result = '';
126
        $filename = Transcoder::$plugin->transcode->getAudioFilename($filePath, $audioOptions);
127
        if (!empty($filename)) {
128
            $urlParams = [
129
                'filename' => $filename,
130
            ];
131
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
132
        }
133
134
        return $result;
135
    }
136
137
    /**
138
     * Get a GIF progress URL
139
     *
140
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
141
     * @param $gifOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
142
     *
143
     * @return string
144
     * @throws InvalidConfigException
145
     */
146
    public function getGifProgressUrl($filePath, $gifOptions): string
147
    {
148
        $result = '';
149
        $filename = Transcoder::$plugin->transcode->getGifFilename($filePath, $gifOptions);
150
        if (!empty($filename)) {
151
            $urlParams = [
152
                'filename' => $filename,
153
            ];
154
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
155
        }
156
157
        return $result;
158
    }
159
160
    /**
161
     * Get a download URL
162
     *
163
     * @param $url
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
164
     *
165
     * @return string
166
     */
167
    public function getDownloadUrl($url): string
168
    {
169
        $result = '';
170
        $filePath = parse_url($url, PHP_URL_PATH);
171
        $filePath = $_SERVER['DOCUMENT_ROOT'] . $filePath;
172
        if (file_exists($filePath)) {
173
            $urlParams = [
174
                'url' => $url,
175
            ];
176
            $result = UrlHelper::actionUrl('transcoder/default/download-file', $urlParams);
177
        }
178
179
        return $result;
180
    }
181
182
    /**
183
     * Returns a URL to a GIF file
184
     *
185
     * @param $filePath
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
186
     * @param $gifOptions
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
187
     *
188
     * @return string|false|null
189
     * @throws InvalidConfigException
190
     */
191
    public function getGifUrl($filePath, $gifOptions): string|false|null
192
    {
193
        return Transcoder::$plugin->transcode->getGifUrl($filePath, $gifOptions);
194
    }
195
}
196