|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Tdmdownloads\Common; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits |
|
7
|
|
|
of supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
|
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright 2020 XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
18
|
|
|
* @link https://xoops.org |
|
19
|
|
|
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com> |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Object Handler Images |
|
24
|
|
|
*/ |
|
25
|
|
|
class ImagesHandler extends \XoopsPersistableObjectHandler |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Constructor |
|
29
|
|
|
* @param \XoopsDatabase|null $db |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(?\XoopsDatabase $db = null) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct($db, 'tdmdownloads_images', Images::class, 'img_id', 'img_name'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* retrieve a field |
|
38
|
|
|
* |
|
39
|
|
|
* @param int $i field id |
|
40
|
|
|
* @param null|mixed $fields |
|
41
|
|
|
* @return mixed reference to the {@link Get} object |
|
42
|
|
|
*/ |
|
43
|
|
|
public function get($i = null, $fields = null) |
|
44
|
|
|
{ |
|
45
|
|
|
return parent::get($i, $fields); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* get inserted id |
|
50
|
|
|
* |
|
51
|
|
|
* @param null |
|
52
|
|
|
* @return int reference to the {@link Get} object |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getInsertId() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->db->getInsertId(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get Count Images in the database |
|
61
|
|
|
* @param int $albId |
|
62
|
|
|
* @param int $start |
|
63
|
|
|
* @param int $limit |
|
64
|
|
|
* @param string $sort |
|
65
|
|
|
* @param string $order |
|
66
|
|
|
* @return int |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getCountImages($albId = 0, $start = 0, $limit = 0, $sort = 'img_id ASC, img_name', $order = 'ASC') |
|
69
|
|
|
{ |
|
70
|
|
|
$crCountImages = new \CriteriaCompo(); |
|
71
|
|
|
|
|
72
|
|
|
$crCountImages = $this->getImagesCriteria($crCountImages, $albId, $start, $limit, $sort, $order); |
|
73
|
|
|
|
|
74
|
|
|
return parent::getCount($crCountImages); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get All Images in the database |
|
79
|
|
|
* @param int $start |
|
80
|
|
|
* @param int $limit |
|
81
|
|
|
* @param string $sort |
|
82
|
|
|
* @param string $order |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getAllImages($start = 0, $limit = 0, $sort = 'img_id ASC, img_name', $order = 'ASC') |
|
86
|
|
|
{ |
|
87
|
|
|
$crAllImages = new \CriteriaCompo(); |
|
88
|
|
|
|
|
89
|
|
|
$crAllImages = $this->getImagesCriteria($crAllImages, 0, $start, $limit, $sort, $order); |
|
90
|
|
|
|
|
91
|
|
|
return parent::getAll($crAllImages); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get Criteria Images |
|
96
|
|
|
* @param $crImages |
|
97
|
|
|
* @param $albId |
|
98
|
|
|
* @param int $start |
|
99
|
|
|
* @param int $limit |
|
100
|
|
|
* @param string $sort |
|
101
|
|
|
* @param string $order |
|
102
|
|
|
* @return int |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getImagesCriteria($crImages, $albId, $start, $limit, $sort, $order) |
|
105
|
|
|
{ |
|
106
|
|
|
if ($albId > 0) { |
|
107
|
|
|
$crImages->add(new \Criteria('img_albid', $albId)); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$crImages->setStart($start); |
|
111
|
|
|
|
|
112
|
|
|
$crImages->setLimit($limit); |
|
113
|
|
|
|
|
114
|
|
|
$crImages->setSort($sort); |
|
115
|
|
|
|
|
116
|
|
|
$crImages->setOrder($order); |
|
117
|
|
|
|
|
118
|
|
|
return $crImages; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* delete all copies of a specific image |
|
123
|
|
|
* @param $imageName |
|
124
|
|
|
* @return bool |
|
125
|
|
|
*/ |
|
126
|
|
|
public function unlinkImages($imageName) |
|
127
|
|
|
{ |
|
128
|
|
|
\unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/large/' . $imageName); |
|
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/large/' . $imageName)) { |
|
131
|
|
|
return false; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
\unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/medium/' . $imageName); |
|
135
|
|
|
|
|
136
|
|
|
if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/medium/' . $imageName)) { |
|
137
|
|
|
return false; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
\unlink(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/thumbs/' . $imageName); |
|
141
|
|
|
|
|
142
|
|
|
if (\file_exists(\constant($moduleDirNameUpper . '_' . 'UPLOAD_IMAGE_PATH') . '/thumbs/' . $imageName)) { |
|
143
|
|
|
return false; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return true; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|