1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* NewBB, XOOPS forum module |
7
|
|
|
* |
8
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
9
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
10
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
11
|
|
|
* @since 4.00 |
12
|
|
|
* @package module::newbb |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
|
17
|
|
|
require_once $GLOBALS['xoops']->path('class/uploader.php'); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Uploader |
21
|
|
|
*/ |
22
|
|
|
class Uploader extends \XoopsMediaUploader |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* No admin check for uploads |
26
|
|
|
* @param mixed $uploadDir |
27
|
|
|
* @param mixed $allowedMimeTypes |
28
|
|
|
* @param mixed $maxFileSize |
29
|
|
|
* @param mixed $maxWidth |
30
|
|
|
* @param mixed $maxHeight |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor |
35
|
|
|
* |
36
|
|
|
* @param string $uploadDir |
37
|
|
|
* @param array|int|string $allowedMimeTypes |
38
|
|
|
* @param int $maxFileSize |
39
|
|
|
* @param int $maxWidth |
40
|
|
|
* @param int $maxHeight |
41
|
|
|
*/ |
42
|
|
|
public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0) |
43
|
|
|
{ |
44
|
|
|
// $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
45
|
|
|
|
46
|
|
|
if (!\is_array($allowedMimeTypes)) { |
47
|
|
|
if (empty($allowedMimeTypes) || '*' === $allowedMimeTypes) { |
48
|
|
|
$allowedMimeTypes = []; |
49
|
|
|
} else { |
50
|
|
|
$allowedMimeTypes = \array_filter(\array_map('\trim', \explode('|', mb_strtolower($allowedMimeTypes)))); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
$_allowedMimeTypes = []; |
54
|
|
|
$extensionToMime = require $GLOBALS['xoops']->path('include/mimetypes.inc.php'); |
55
|
|
|
foreach ($allowedMimeTypes as $type) { |
56
|
|
|
if (isset($extensionToMime[$type])) { |
57
|
|
|
$_allowedMimeTypes[] = $extensionToMime[$type]; |
58
|
|
|
} else { |
59
|
|
|
$_allowedMimeTypes[] = $type; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set the CheckMediaTypeByExt |
67
|
|
|
* Deprecated |
68
|
|
|
* |
69
|
|
|
* @param bool|string $value |
70
|
|
|
*/ |
71
|
|
|
public function setCheckMediaTypeByExt($value = true) |
72
|
|
|
{ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set the imageSizeCheck |
77
|
|
|
* Deprecated |
78
|
|
|
* |
79
|
|
|
* @param string $value |
80
|
|
|
*/ |
81
|
|
|
public function setImageSizeCheck($value) |
82
|
|
|
{ |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Set the fileSizeCheck |
87
|
|
|
* Deprecated |
88
|
|
|
* |
89
|
|
|
* @param string $value |
90
|
|
|
*/ |
91
|
|
|
public function setFileSizeCheck($value) |
92
|
|
|
{ |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the file extension |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getExt() |
101
|
|
|
{ |
102
|
|
|
$this->ext = mb_strtolower(\ltrim(mb_strrchr($this->getMediaName(), '.'), '.')); |
|
|
|
|
103
|
|
|
|
104
|
|
|
return $this->ext; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|