|
1
|
|
|
<?php namespace XoopsModules\Extgallery; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* ExtGallery Class Manager |
|
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
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
14
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
15
|
|
|
* @author Zoullou (http://www.zoullou.net) |
|
16
|
|
|
* @package ExtGallery |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
use XoopsModules\Extgallery; |
|
20
|
|
|
|
|
21
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class PhotoHandler |
|
26
|
|
|
*/ |
|
27
|
|
|
class PhotoHandler extends Extgallery\PersistableObjectHandler |
|
28
|
|
|
{ |
|
29
|
|
|
public $photoUploader = null; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param $db |
|
33
|
|
|
* @param $type |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(\XoopsDatabase $db, $type) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
parent::__construct($db, 'extgallery_' . $type . 'photo', ucfirst($type) . 'Photo', 'photo_id'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param $data |
|
42
|
|
|
* |
|
43
|
|
|
* @return bool |
|
44
|
|
|
*/ |
|
45
|
|
|
public function createPhoto($data) |
|
46
|
|
|
{ |
|
47
|
|
|
$photo = $this->create(); |
|
48
|
|
|
$photo->setVars($data); |
|
49
|
|
|
|
|
50
|
|
|
return $this->insert($photo, true); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $photoId |
|
55
|
|
|
* @param $data |
|
56
|
|
|
* |
|
57
|
|
|
* @return bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function modifyPhoto($photoId, $data) |
|
60
|
|
|
{ |
|
61
|
|
|
$photo = $this->get($photoId); |
|
62
|
|
|
$photo->setVars($data); |
|
63
|
|
|
|
|
64
|
|
|
return $this->insert($photo, true); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param $photo |
|
69
|
|
|
*/ |
|
70
|
|
|
public function deletePhoto(&$photo) |
|
71
|
|
|
{ |
|
72
|
|
|
if ('' == $photo->getVar('photo_serveur')) { |
|
73
|
|
|
$this->deleteFile($photo); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
$this->deleteById($photo->getVar('photo_id'), true); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param $catId |
|
80
|
|
|
*/ |
|
81
|
|
|
public function deletePhotoByCat($catId) |
|
82
|
|
|
{ |
|
83
|
|
|
$criteria = new \Criteria('cat_id', $catId); |
|
|
|
|
|
|
84
|
|
|
$photos =& $this->getObjects($criteria); |
|
85
|
|
|
foreach ($photos as $photo) { |
|
86
|
|
|
$this->deletePhoto($photo); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function deleteFile() |
|
91
|
|
|
{ |
|
92
|
|
|
exit('deleteFile() method must be defined on sub classes'); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param $photoId |
|
97
|
|
|
* |
|
98
|
|
|
* @return bool |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getPhoto($photoId) |
|
101
|
|
|
{ |
|
102
|
|
|
$criteria = new \CriteriaCompo(); |
|
|
|
|
|
|
103
|
|
|
$criteria->add(new \Criteria('photo_id', $photoId)); |
|
104
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
105
|
|
|
|
|
106
|
|
|
$photo =& $this->getObjects($criteria); |
|
107
|
|
|
if (1 != count($photo)) { |
|
108
|
|
|
return false; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return $photo[0]; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param $cat |
|
116
|
|
|
* |
|
117
|
|
|
* @return int |
|
118
|
|
|
*/ |
|
119
|
|
|
public function nbPhoto(&$cat) |
|
120
|
|
|
{ |
|
121
|
|
|
$criteria = new \Criteria('cat_id', $cat->getVar('cat_id')); |
|
122
|
|
|
|
|
123
|
|
|
return $this->getCount($criteria); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @param $catId |
|
128
|
|
|
* @param $start |
|
129
|
|
|
* @param $sortby |
|
130
|
|
|
* @param $orderby |
|
131
|
|
|
* |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getAlbumPhotoPage($catId, $start, $sortby, $orderby) |
|
135
|
|
|
{ |
|
136
|
|
|
$criteria = new \CriteriaCompo(); |
|
137
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
138
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
139
|
|
|
$criteria->setStart($start); |
|
140
|
|
|
$criteria->setLimit($GLOBALS['xoopsModuleConfig']['nb_column'] * $GLOBALS['xoopsModuleConfig']['nb_line']); |
|
141
|
|
|
if ('' == $criteria->getSort()) { |
|
142
|
|
|
$criteria->setSort($sortby); |
|
143
|
|
|
$criteria->setOrder($orderby); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $this->getObjects($criteria); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param $catId |
|
151
|
|
|
* @param $start |
|
152
|
|
|
* |
|
153
|
|
|
* @return array |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getAlbumPhotoAdminPage($catId, $start) |
|
156
|
|
|
{ |
|
157
|
|
|
$criteria = new \CriteriaCompo(); |
|
158
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
159
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
160
|
|
|
$criteria->setStart($start); |
|
161
|
|
|
$criteria->setLimit($GLOBALS['xoopsModuleConfig']['admin_nb_photo']); |
|
162
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
163
|
|
|
$criteria->setOrder($GLOBALS['xoopsModuleConfig']['display_set_order']); |
|
164
|
|
|
|
|
165
|
|
|
return $this->getObjects($criteria); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param $catId |
|
170
|
|
|
* |
|
171
|
|
|
* @return array |
|
172
|
|
|
*/ |
|
173
|
|
|
public function getSlideshowAlbumPhoto($catId) |
|
174
|
|
|
{ |
|
175
|
|
|
$criteria = new \CriteriaCompo(); |
|
176
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
177
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
178
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
179
|
|
|
$criteria->setOrder($GLOBALS['xoopsModuleConfig']['display_set_order']); |
|
180
|
|
|
|
|
181
|
|
|
return $this->getObjects($criteria, false, false); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param $catId |
|
186
|
|
|
* |
|
187
|
|
|
* @return array |
|
188
|
|
|
*/ |
|
189
|
|
|
public function getPhotoAlbumId($catId) |
|
190
|
|
|
{ |
|
191
|
|
|
$criteria = new \CriteriaCompo(); |
|
192
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
193
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
194
|
|
|
|
|
195
|
|
|
$sql = 'SELECT photo_id FROM ' . $this->db->prefix('extgallery_publicphoto') . ' ' . $criteria->renderWhere() . ' ORDER BY photo_weight, photo_id ASC;'; |
|
196
|
|
|
|
|
197
|
|
|
$result = $this->db->query($sql); |
|
198
|
|
|
$ret = []; |
|
199
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
200
|
|
|
$ret[] = $myrow['photo_id']; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
return $ret; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @param $catId |
|
208
|
|
|
* @param $photoId |
|
209
|
|
|
* |
|
210
|
|
|
* @return array |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getAlbumPrevPhoto($catId, $photoId) |
|
213
|
|
|
{ |
|
214
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
215
|
|
|
|
|
216
|
|
|
$criteria = new \CriteriaCompo(); |
|
217
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
218
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
219
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
220
|
|
|
$criteria->add(new \Criteria('photo_id', $photoId, '<')); |
|
221
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
222
|
|
|
$criteria->setOrder('DESC'); |
|
223
|
|
|
$criteria->setLimit(1); |
|
224
|
|
|
|
|
225
|
|
|
return $this->getObjects($criteria); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @param $catId |
|
230
|
|
|
* @param $photoId |
|
231
|
|
|
* |
|
232
|
|
|
* @return array |
|
233
|
|
|
*/ |
|
234
|
|
|
public function getAlbumNextPhoto($catId, $photoId) |
|
235
|
|
|
{ |
|
236
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
237
|
|
|
|
|
238
|
|
|
$criteria = new \CriteriaCompo(); |
|
239
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
240
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
241
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
242
|
|
|
$criteria->add(new \Criteria('photo_id', $photoId, '>')); |
|
243
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
244
|
|
|
$criteria->setOrder('ASC'); |
|
245
|
|
|
$criteria->setLimit(1); |
|
246
|
|
|
|
|
247
|
|
|
return $this->getObjects($criteria); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @param $catId |
|
252
|
|
|
* @param $photoId |
|
253
|
|
|
* |
|
254
|
|
|
* @return int |
|
255
|
|
|
*/ |
|
256
|
|
|
public function getAlbumCurrentPhotoPlace($catId, $photoId) |
|
257
|
|
|
{ |
|
258
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
259
|
|
|
|
|
260
|
|
|
$criteria = new \CriteriaCompo(); |
|
261
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
262
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
263
|
|
|
$criteria->add(new \Criteria('cat_id', $catId)); |
|
264
|
|
|
$criteria->add(new \Criteria('photo_id', $photoId, '<=')); |
|
265
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
266
|
|
|
$criteria->setOrder('DESC'); |
|
267
|
|
|
|
|
268
|
|
|
return $this->getCount($criteria); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @param $catId |
|
273
|
|
|
* |
|
274
|
|
|
* @return array |
|
275
|
|
|
*/ |
|
276
|
|
|
public function getAlbumPhoto($catId) |
|
277
|
|
|
{ |
|
278
|
|
|
$criteria = new \Criteria('cat_id', $catId); |
|
279
|
|
|
$criteria->setSort('photo_weight, photo_id'); |
|
280
|
|
|
$criteria->setOrder('ASC'); |
|
281
|
|
|
|
|
282
|
|
|
return $this->getObjects($criteria); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* @param $category |
|
287
|
|
|
* |
|
288
|
|
|
* @return array |
|
289
|
|
|
*/ |
|
290
|
|
|
public function getCatPhoto(&$category) |
|
291
|
|
|
{ |
|
292
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
293
|
|
|
|
|
294
|
|
|
$criteria = new \CriteriaCompo(); |
|
295
|
|
|
$criteria->add(new \Criteria('nleft', $category->getVar('nleft'), '>=')); |
|
296
|
|
|
$criteria->add(new \Criteria('nright', $category->getVar('nright'), '<=')); |
|
297
|
|
|
|
|
298
|
|
|
$cats = $catHandler->getObjects($criteria); |
|
299
|
|
|
|
|
300
|
|
|
$count = count($cats); |
|
301
|
|
|
if ($count > 0) { |
|
302
|
|
|
$in = '(' . $cats[0]->getVar('cat_id'); |
|
303
|
|
|
array_shift($cats); |
|
304
|
|
|
/** @var Extgallery\Category $cat */ |
|
305
|
|
|
foreach ($cats as $cat) { |
|
306
|
|
|
$in .= ',' . $cat->getVar('cat_id'); |
|
307
|
|
|
} |
|
308
|
|
|
$in .= ')'; |
|
309
|
|
|
$criteria = new \Criteria('cat_id', $in, 'IN'); |
|
310
|
|
|
} else { |
|
311
|
|
|
$criteria = new \Criteria('cat_id', '(0)', 'IN'); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
return $this->getObjects($criteria); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @param $catId |
|
319
|
|
|
* |
|
320
|
|
|
* @return int |
|
321
|
|
|
*/ |
|
322
|
|
|
public function getAlbumCount($catId) |
|
323
|
|
|
{ |
|
324
|
|
|
$criteria = new \Criteria('cat_id', $catId); |
|
325
|
|
|
|
|
326
|
|
|
return $this->getCount($criteria); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @param $photoId |
|
331
|
|
|
* |
|
332
|
|
|
* @return bool |
|
333
|
|
|
*/ |
|
334
|
|
|
public function updateHits($photoId) |
|
335
|
|
|
{ |
|
336
|
|
|
$criteria = new \Criteria('photo_id', $photoId); |
|
337
|
|
|
|
|
338
|
|
|
return $this->updateCounter('photo_hits', $criteria); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* @param $photoId |
|
343
|
|
|
* |
|
344
|
|
|
* @return bool |
|
345
|
|
|
*/ |
|
346
|
|
|
public function updateNbRating($photoId) |
|
347
|
|
|
{ |
|
348
|
|
|
$criteria = new \Criteria('photo_id', $photoId); |
|
349
|
|
|
|
|
350
|
|
|
return $this->updateCounter('photo_nbrating', $criteria); |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* @param $photoId |
|
355
|
|
|
* |
|
356
|
|
|
* @return bool |
|
357
|
|
|
*/ |
|
358
|
|
|
public function updateDownload($photoId) |
|
359
|
|
|
{ |
|
360
|
|
|
$criteria = new \Criteria('photo_id', $photoId); |
|
361
|
|
|
|
|
362
|
|
|
return $this->updateCounter('photo_download', $criteria); |
|
363
|
|
|
} |
|
364
|
|
|
|
|
365
|
|
|
/** |
|
366
|
|
|
* @param $photoId |
|
367
|
|
|
* |
|
368
|
|
|
* @return bool |
|
369
|
|
|
*/ |
|
370
|
|
|
public function updateEcard($photoId) |
|
371
|
|
|
{ |
|
372
|
|
|
$criteria = new \Criteria('photo_id', $photoId); |
|
373
|
|
|
|
|
374
|
|
|
return $this->updateCounter('photo_ecard', $criteria); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
public function getAllSize() |
|
378
|
|
|
{ |
|
379
|
|
|
exit('getAllSize() method must be defined on sub classes'); |
|
|
|
|
|
|
380
|
|
|
} |
|
381
|
|
|
|
|
382
|
|
|
/** |
|
383
|
|
|
* @param $imageTransform |
|
384
|
|
|
*/ |
|
385
|
|
|
public function _makeWatermark(&$imageTransform) |
|
386
|
|
|
{ |
|
387
|
|
|
if (!function_exists('imagettfbbox')) { |
|
388
|
|
|
return; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
392
|
|
|
|
|
393
|
|
|
/* Text position param |
|
394
|
|
|
/ |
|
395
|
|
|
/ 0 : orig |
|
396
|
|
|
/ -1 : opposit |
|
397
|
|
|
/ 1 : center |
|
398
|
|
|
/ |
|
399
|
|
|
*/ |
|
400
|
|
|
if ('tl' === $xoopsModuleConfig['watermark_position']) { |
|
401
|
|
|
$x = 0; |
|
402
|
|
|
$y = 0; |
|
403
|
|
|
} elseif ('tr' === $xoopsModuleConfig['watermark_position']) { |
|
404
|
|
|
$x = -1; |
|
405
|
|
|
$y = 0; |
|
406
|
|
|
} elseif ('bl' === $xoopsModuleConfig['watermark_position']) { |
|
407
|
|
|
$x = 0; |
|
408
|
|
|
$y = -1; |
|
409
|
|
|
} elseif ('br' === $xoopsModuleConfig['watermark_position']) { |
|
410
|
|
|
$x = -1; |
|
411
|
|
|
$y = -1; |
|
412
|
|
|
} elseif ('tc' === $xoopsModuleConfig['watermark_position']) { |
|
413
|
|
|
$x = 1; |
|
414
|
|
|
$y = 0; |
|
415
|
|
|
} elseif ('bc' === $xoopsModuleConfig['watermark_position']) { |
|
416
|
|
|
$x = 1; |
|
417
|
|
|
$y = -1; |
|
418
|
|
|
} elseif ('lc' === $xoopsModuleConfig['watermark_position']) { |
|
419
|
|
|
$x = 0; |
|
420
|
|
|
$y = 1; |
|
421
|
|
|
} elseif ('rc' === $xoopsModuleConfig['watermark_position']) { |
|
422
|
|
|
$x = -1; |
|
423
|
|
|
$y = 1; |
|
424
|
|
|
} elseif ('cc' === $xoopsModuleConfig['watermark_position']) { |
|
425
|
|
|
$x = 1; |
|
426
|
|
|
$y = 1; |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
$text = (0 == $xoopsModuleConfig['watermark_type']) ? $GLOBALS['xoopsUser']->getVar('uname') : $xoopsModuleConfig['watermark_text']; |
|
430
|
|
|
|
|
431
|
|
|
$watermarkParams = [ |
|
432
|
|
|
'text' => $text, |
|
433
|
|
|
'x' => $x, |
|
|
|
|
|
|
434
|
|
|
'y' => $y, |
|
|
|
|
|
|
435
|
|
|
'color' => $xoopsModuleConfig['watermark_color'], |
|
436
|
|
|
'font' => XOOPS_ROOT_PATH . '/modules/extgallery/fonts/' . $xoopsModuleConfig['watermark_font'], |
|
|
|
|
|
|
437
|
|
|
'size' => $xoopsModuleConfig['watermark_fontsize'], |
|
438
|
|
|
'resize_first' => false, |
|
439
|
|
|
'padding' => $xoopsModuleConfig['watermark_padding'] |
|
440
|
|
|
]; |
|
441
|
|
|
$imageTransform->addText($watermarkParams); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
/** |
|
445
|
|
|
* @param $imageTransform |
|
446
|
|
|
*/ |
|
447
|
|
|
public function _makeBorder(&$imageTransform) |
|
448
|
|
|
{ |
|
449
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
450
|
|
|
|
|
451
|
|
|
$borders = []; |
|
452
|
|
|
$borders[] = [ |
|
453
|
|
|
'borderWidth' => $xoopsModuleConfig['inner_border_size'], |
|
454
|
|
|
'borderColor' => $xoopsModuleConfig['inner_border_color'] |
|
455
|
|
|
]; |
|
456
|
|
|
$borders[] = [ |
|
457
|
|
|
'borderWidth' => $xoopsModuleConfig['outer_border_size'], |
|
458
|
|
|
'borderColor' => $xoopsModuleConfig['outer_border_color'] |
|
459
|
|
|
]; |
|
460
|
|
|
// $imageTransform->addBorders($borders); |
|
|
|
|
|
|
461
|
|
|
foreach ($borders as $border) { |
|
462
|
|
|
$imageTransform->addBorder($border['borderWidth'], $border['borderColor']); |
|
463
|
|
|
} |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
public function _getUploadPhotoPath() |
|
467
|
|
|
{ |
|
468
|
|
|
exit('_getUploadPhotoPath() method must be defined on sub classes'); |
|
|
|
|
|
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
/** |
|
472
|
|
|
* @param $photoName |
|
473
|
|
|
*/ |
|
474
|
|
|
public function _largePhotoTreatment($photoName) |
|
475
|
|
|
{ |
|
476
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
477
|
|
|
|
|
478
|
|
|
// Check if must save large photo |
|
479
|
|
|
if ($xoopsModuleConfig['save_large']) { |
|
480
|
|
|
|
|
481
|
|
|
// Define Graphical library path |
|
482
|
|
|
if (!defined('IMAGE_TRANSFORM_IM_PATH') && 'imagick' === $xoopsModuleConfig['graphic_lib']) { |
|
483
|
|
|
define('IMAGE_TRANSFORM_IM_PATH', $xoopsModuleConfig['graphic_lib_path']); |
|
484
|
|
|
} |
|
485
|
|
|
$imageFactory = new \Image_Transform; |
|
486
|
|
|
$imageTransform = $imageFactory->factory($xoopsModuleConfig['graphic_lib']); |
|
487
|
|
|
|
|
488
|
|
|
$filePath = $this->_getUploadPhotoPath(); |
|
|
|
|
|
|
489
|
|
|
$imageTransform->load($filePath . $photoName); |
|
490
|
|
|
|
|
491
|
|
|
// Save large photo only if it's bigger than medium size |
|
492
|
|
|
if ($imageTransform->getImageWidth() > $xoopsModuleConfig['medium_width'] |
|
493
|
|
|
|| $imageTransform->getImageHeight() > $xoopsModuleConfig['medium_heigth']) { |
|
494
|
|
|
|
|
495
|
|
|
// Make watermark |
|
496
|
|
|
if ($xoopsModuleConfig['enable_large_watermark']) { |
|
497
|
|
|
$this->_makeWatermark($imageTransform); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
// Make border |
|
501
|
|
|
if ($xoopsModuleConfig['enable_large_border']) { |
|
502
|
|
|
$this->_makeBorder($imageTransform); |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
$largeFilePath = $filePath . 'large/large_' . $photoName; |
|
506
|
|
|
$imageTransform->save($largeFilePath, '', 100); |
|
507
|
|
|
$imageTransform->free(); |
|
508
|
|
|
} |
|
509
|
|
|
} |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* @param $photoName |
|
514
|
|
|
* @param null|string $filePath |
|
|
|
|
|
|
515
|
|
|
* @param null $mediumFilePath |
|
516
|
|
|
*/ |
|
517
|
|
|
public function _mediumPhotoTreatment($photoName, $filePath = null, $mediumFilePath = null) |
|
518
|
|
|
{ |
|
519
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
520
|
|
|
|
|
521
|
|
|
// Define Graphical library path |
|
522
|
|
|
if (!defined('IMAGE_TRANSFORM_IM_PATH') && 'imagick' === $xoopsModuleConfig['graphic_lib']) { |
|
523
|
|
|
define('IMAGE_TRANSFORM_IM_PATH', $xoopsModuleConfig['graphic_lib_path']); |
|
524
|
|
|
} |
|
525
|
|
|
$imageFactory = new \Image_Transform; |
|
526
|
|
|
$imageTransform = $imageFactory->factory($xoopsModuleConfig['graphic_lib']); |
|
527
|
|
|
|
|
528
|
|
|
if (null === $filePath) { |
|
529
|
|
|
$filePath = $this->_getUploadPhotoPath(); |
|
|
|
|
|
|
530
|
|
|
} |
|
531
|
|
|
if (null === $mediumFilePath) { |
|
532
|
|
|
$mediumFilePath = $filePath . 'medium/' . $photoName; |
|
533
|
|
|
} |
|
534
|
|
|
$imageTransform->load($filePath . $photoName); |
|
535
|
|
|
|
|
536
|
|
|
// Fitting image to desired size |
|
537
|
|
|
if ($xoopsModuleConfig['enable_medium_border']) { |
|
538
|
|
|
$borderSize = ($xoopsModuleConfig['inner_border_size'] * 2) + ($xoopsModuleConfig['outer_border_size'] * 2); |
|
539
|
|
|
} else { |
|
540
|
|
|
$borderSize = 0; |
|
541
|
|
|
} |
|
542
|
|
|
$imageTransform->fit($xoopsModuleConfig['medium_width'] - $borderSize, $xoopsModuleConfig['medium_heigth'] - $borderSize); |
|
543
|
|
|
$imageTransform->save($mediumFilePath, '', $xoopsModuleConfig['medium_quality']); |
|
544
|
|
|
$imageTransform->free(); |
|
545
|
|
|
|
|
546
|
|
|
if ($xoopsModuleConfig['enable_medium_watermark'] || $xoopsModuleConfig['enable_medium_border']) { |
|
547
|
|
|
$imageTransform->load($mediumFilePath); |
|
548
|
|
|
|
|
549
|
|
|
// Make watermark |
|
550
|
|
|
if ($xoopsModuleConfig['enable_medium_watermark']) { |
|
551
|
|
|
$this->_makeWatermark($imageTransform); |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
// Make border |
|
555
|
|
|
if ($xoopsModuleConfig['enable_medium_border']) { |
|
556
|
|
|
$this->_makeBorder($imageTransform); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
$imageTransform->save($mediumFilePath, '', $xoopsModuleConfig['medium_quality']); |
|
560
|
|
|
$imageTransform->free(); |
|
561
|
|
|
} |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
/** |
|
565
|
|
|
* @param $photoName |
|
566
|
|
|
*/ |
|
567
|
|
|
public function _makeThumb($photoName) |
|
568
|
|
|
{ |
|
569
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
570
|
|
|
|
|
571
|
|
|
// Define Graphical library path |
|
572
|
|
|
if (!defined('IMAGE_TRANSFORM_IM_PATH') && 'imagick' === $xoopsModuleConfig['graphic_lib']) { |
|
573
|
|
|
define('IMAGE_TRANSFORM_IM_PATH', $xoopsModuleConfig['graphic_lib_path']); |
|
574
|
|
|
} |
|
575
|
|
|
$imageFactory = new \Image_Transform; |
|
576
|
|
|
$imageTransform = $imageFactory->factory($xoopsModuleConfig['graphic_lib']); |
|
577
|
|
|
|
|
578
|
|
|
$filePath = $this->_getUploadPhotoPath() . 'medium/' . $photoName; |
|
|
|
|
|
|
579
|
|
|
$thumbPath = $this->_getUploadPhotoPath() . 'thumb/thumb_' . $photoName; |
|
580
|
|
|
|
|
581
|
|
|
$imageTransform->load($filePath); |
|
582
|
|
|
$imageTransform->fit($xoopsModuleConfig['thumb_width'], $xoopsModuleConfig['thumb_heigth']); |
|
583
|
|
|
$imageTransform->save($thumbPath, '', $xoopsModuleConfig['thumb_quality']); |
|
584
|
|
|
$imageTransform->free(); |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
/** |
|
588
|
|
|
* @param $photoName |
|
589
|
|
|
* |
|
590
|
|
|
* @return bool |
|
591
|
|
|
*/ |
|
592
|
|
|
public function _haveLargePhoto($photoName) |
|
593
|
|
|
{ |
|
594
|
|
|
return file_exists($this->_getUploadPhotoPath() . 'large/large_' . $photoName); |
|
|
|
|
|
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
/** |
|
598
|
|
|
* @param $photoName |
|
599
|
|
|
* |
|
600
|
|
|
* @return array |
|
601
|
|
|
*/ |
|
602
|
|
|
public function _getImageDimension($photoName) |
|
603
|
|
|
{ |
|
604
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
605
|
|
|
|
|
606
|
|
|
// Define Graphical library path |
|
607
|
|
|
if (!defined('IMAGE_TRANSFORM_IM_PATH') && 'imagick' === $xoopsModuleConfig['graphic_lib']) { |
|
608
|
|
|
define('IMAGE_TRANSFORM_IM_PATH', $xoopsModuleConfig['graphic_lib_path']); |
|
609
|
|
|
} |
|
610
|
|
|
$imageFactory = new \Image_Transform; |
|
611
|
|
|
$imageTransform = $imageFactory->factory($xoopsModuleConfig['graphic_lib']); |
|
612
|
|
|
|
|
613
|
|
|
$ret = []; |
|
614
|
|
|
if ($this->_haveLargePhoto($photoName)) { |
|
615
|
|
|
$imageTransform->load($this->_getUploadPhotoPath() . 'large/large_' . $photoName); |
|
616
|
|
|
$ret['width'] = $imageTransform->getImageWidth(); |
|
617
|
|
|
$ret['height'] = $imageTransform->getImageHeight(); |
|
618
|
|
|
} else { |
|
619
|
|
|
$imageTransform->load($this->_getUploadPhotoPath() . 'medium/' . $photoName); |
|
620
|
|
|
$ret['width'] = $imageTransform->getImageWidth(); |
|
621
|
|
|
$ret['height'] = $imageTransform->getImageHeight(); |
|
622
|
|
|
} |
|
623
|
|
|
$imageTransform->free(); |
|
624
|
|
|
|
|
625
|
|
|
return $ret; |
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
/** |
|
629
|
|
|
* @param $photoName |
|
630
|
|
|
* |
|
631
|
|
|
* @return string |
|
632
|
|
|
*/ |
|
633
|
|
|
public function _getAutoDescription($photoName) |
|
634
|
|
|
{ |
|
635
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
636
|
|
|
|
|
637
|
|
|
//DNPROSSI |
|
638
|
|
|
/*if ($xoopsModuleConfig['enable_longdesc']) { |
|
|
|
|
|
|
639
|
|
|
$newphotoname = ''; |
|
640
|
|
|
$newnewphotoname = ''; |
|
641
|
|
|
$patterns = array(); |
|
642
|
|
|
$patterns[0] = "/-/"; |
|
643
|
|
|
$patterns[1] = "/_/"; |
|
644
|
|
|
$replacements = array(); |
|
645
|
|
|
$replacements[0] = " "; |
|
646
|
|
|
$replacements[1] = "'"; |
|
647
|
|
|
$newphotoName = substr($photoName, strpos($photoName, "-") + 1); |
|
648
|
|
|
$newphotoName = substr($newphotoName, strpos($newphotoName, "-") + 1); |
|
649
|
|
|
|
|
650
|
|
|
return preg_replace($patterns, $replacements, substr($newphotoName,0,-12)); |
|
651
|
|
|
} else { */ |
|
652
|
|
|
$matches = []; |
|
653
|
|
|
preg_match_all($xoopsModuleConfig['photoname_pattern'], substr($photoName, 0, -12), $matches); |
|
654
|
|
|
preg_match_all($xoopsModuleConfig['photoname_pattern'], $photoName, $matches); |
|
655
|
|
|
|
|
656
|
|
|
return implode(' ', $matches[1]); |
|
657
|
|
|
//} |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* @param $fileName |
|
662
|
|
|
* |
|
663
|
|
|
* @return string |
|
664
|
|
|
*/ |
|
665
|
|
|
public function _makeFileName($fileName) |
|
666
|
|
|
{ |
|
667
|
|
|
//DNPROSSI |
|
668
|
|
|
//$fileName = preg_replace("/[^a-zA-Z0-9()_\.-]/", "-", $fileName); |
|
|
|
|
|
|
669
|
|
|
$fileName = preg_replace("/[^a-zA-Z0-9_\.-]/", '-', $fileName); |
|
670
|
|
|
|
|
671
|
|
|
$fileName = explode('.', $fileName); |
|
672
|
|
|
$userId = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
673
|
|
|
|
|
674
|
|
|
return $fileName[0] . '_' . $userId . '_' . substr(md5(uniqid(mt_rand(), true)), 27) . '.' . $fileName[1]; |
|
675
|
|
|
} |
|
676
|
|
|
|
|
677
|
|
|
/** |
|
678
|
|
|
* @param $photoName |
|
679
|
|
|
* |
|
680
|
|
|
* @return float |
|
681
|
|
|
*/ |
|
682
|
|
|
public function _getPhotoSize($photoName) |
|
683
|
|
|
{ |
|
684
|
|
|
if ($this->_haveLargePhoto($photoName)) { |
|
685
|
|
|
return $this->_getFileSize('large/large_' . $photoName); |
|
686
|
|
|
} else { |
|
687
|
|
|
return $this->_getFileSize($photoName); |
|
688
|
|
|
} |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
/** |
|
692
|
|
|
* @param $fileName |
|
693
|
|
|
* |
|
694
|
|
|
* @return float |
|
695
|
|
|
*/ |
|
696
|
|
|
public function _getFileSize($fileName) |
|
697
|
|
|
{ |
|
698
|
|
|
return round(filesize($this->_getUploadPhotoPath() . $fileName) / 1024, 2); |
|
|
|
|
|
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
/** |
|
702
|
|
|
* @param $catId |
|
703
|
|
|
*/ |
|
704
|
|
|
public function rebuildThumbnail($catId) |
|
705
|
|
|
{ |
|
706
|
|
|
$photos = $this->getAlbumPhoto($catId); |
|
707
|
|
|
foreach ($photos as $photo) { |
|
708
|
|
|
$this->_makeThumb($photo->getVar('photo_name')); |
|
709
|
|
|
} |
|
710
|
|
|
} |
|
711
|
|
|
|
|
712
|
|
|
/* Return Code : |
|
713
|
|
|
0 : Photo added |
|
714
|
|
|
1 : Photo pending |
|
715
|
|
|
2 : This is not an album |
|
716
|
|
|
3 : HTTP Upload error |
|
717
|
|
|
4 : File rejected |
|
718
|
|
|
5 : File chunk receive |
|
719
|
|
|
*/ |
|
720
|
|
|
/** |
|
721
|
|
|
* @param $file |
|
722
|
|
|
* @param bool $checkMd5 |
|
723
|
|
|
* |
|
724
|
|
|
* @return int |
|
725
|
|
|
*/ |
|
726
|
|
|
public function postPhotoTraitement($file, $checkMd5 = false) |
|
727
|
|
|
{ |
|
728
|
|
|
// require_once XOOPS_ROOT_PATH.'/modules/extgallery/class/photoUploader.php'; |
|
|
|
|
|
|
729
|
|
|
|
|
730
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
731
|
|
|
|
|
732
|
|
|
$catId = (int)$_POST['cat_id']; |
|
733
|
|
|
|
|
734
|
|
|
// If isn't an album when stop the traitment |
|
735
|
|
|
$cat = $catHandler->getCat($catId); |
|
736
|
|
|
if (null !== $cat && (1 != $cat->getVar('nright') - $cat->getVar('nleft'))) { |
|
737
|
|
|
return 2; |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
$allowedMimeTypes = ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']; |
|
741
|
|
|
// $allowedMimeTypes = array('jpg/jpeg', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/x-png', 'image/png'); |
|
|
|
|
|
|
742
|
|
|
|
|
743
|
|
|
$uploadDir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/'; |
|
|
|
|
|
|
744
|
|
|
|
|
745
|
|
|
// $this->photoUploader = new Extgallery\PhotoUploader($uploadDir, 50000000, 5000, 5000); |
|
|
|
|
|
|
746
|
|
|
// $this->photoUploader->checkMd5 = $checkMd5; |
|
|
|
|
|
|
747
|
|
|
// $this->photoUploader->fetchPhoto($_FILES[$file]); |
|
|
|
|
|
|
748
|
|
|
|
|
749
|
|
|
//------------------------ |
|
750
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
751
|
|
|
$this->photoUploader = new \XoopsMediaUploader($uploadDir, $allowedMimeTypes, 50000000, 5000, 5000); |
|
|
|
|
|
|
752
|
|
|
|
|
753
|
|
|
$jupart = isset($_POST['jupart']) ? (int)$_POST['jupart'] : 0; |
|
754
|
|
|
$jufinal = isset($_POST['jufinal']) ? (int)$_POST['jufinal'] : 1; |
|
755
|
|
|
|
|
756
|
|
|
if ($this->photoUploader->fetchMedia($file) && $this->photoUploader->upload()) { |
|
|
|
|
|
|
757
|
|
|
} else { |
|
758
|
|
|
// We got a chunk, so we don't add photo to database |
|
759
|
|
|
if ($jupart && !$jufinal) { |
|
760
|
|
|
return 5; |
|
761
|
|
|
} else { |
|
762
|
|
|
return 4; |
|
763
|
|
|
} |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
//--------------------------- |
|
767
|
|
|
|
|
768
|
|
|
/* |
|
769
|
|
|
|
|
770
|
|
|
$jupart = (isset($_POST['jupart'])) ? (int) $_POST['jupart'] : 0; |
|
771
|
|
|
$jufinal = (isset($_POST['jufinal'])) ? (int) $_POST['jufinal'] : 1; |
|
772
|
|
|
|
|
773
|
|
|
if ($this->photoUploader->isError()) { |
|
774
|
|
|
return 4; |
|
775
|
|
|
// We got a chunk, so we don't add photo to database |
|
776
|
|
|
} elseif ($jupart && !$jufinal) { |
|
777
|
|
|
return 5; |
|
778
|
|
|
} |
|
779
|
|
|
*/ |
|
780
|
|
|
|
|
781
|
|
|
//DNPROSSI - add missing title and description on upload |
|
782
|
|
|
$photoTitle = ''; |
|
783
|
|
|
$photoDesc = ''; |
|
784
|
|
|
$photoExtra = ''; |
|
785
|
|
|
$photoTag = ''; |
|
786
|
|
|
|
|
787
|
|
|
if (isset($_POST['photo_title'])) { |
|
788
|
|
|
$photoTitle = $_POST['photo_title']; |
|
789
|
|
|
} |
|
790
|
|
|
if (isset($_POST['photo_desc'])) { |
|
791
|
|
|
$photoDesc = $_POST['photo_desc']; |
|
792
|
|
|
} |
|
793
|
|
|
if (isset($_POST['photo_extra'])) { |
|
794
|
|
|
$photoExtra = $_POST['photo_extra']; |
|
795
|
|
|
} |
|
796
|
|
|
if (isset($_POST['tag'])) { |
|
797
|
|
|
$photoTag = $_POST['tag']; |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
|
|
$photoStatus = $this->addLocalPhoto($catId, $this->photoUploader->getSavedFileName(), $photoTitle, $photoDesc, $photoExtra, $photoTag); |
|
801
|
|
|
/** @var Extgallery\Category $cat */ |
|
802
|
|
|
$cat = $catHandler->getCat($catId); |
|
803
|
|
|
$cat->setVar('cat_isalbum', 1); |
|
804
|
|
|
$catHandler->insert($cat); |
|
805
|
|
|
|
|
806
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
|
807
|
|
|
$notificationHandler = xoops_getHandler('notification'); |
|
|
|
|
|
|
808
|
|
|
$extraTags = [ |
|
809
|
|
|
'X_ITEM_CAT' => $cat->getVar('cat_name'), |
|
810
|
|
|
'X_ITEM_NBPHOTO' => 1 |
|
811
|
|
|
]; |
|
812
|
|
|
|
|
813
|
|
|
if (1 == $photoStatus) { |
|
814
|
|
|
$extraTags['X_ITEM_URL'] = XOOPS_URL . '/modules/extgallery/public-album.php?id=' . $cat->getVar('cat_id'); |
|
|
|
|
|
|
815
|
|
|
$notificationHandler->triggerEvent('global', 0, 'new_photo', $extraTags); |
|
816
|
|
|
$notificationHandler->triggerEvent('album', $cat->getVar('cat_id'), 'new_photo_album', $extraTags); |
|
817
|
|
|
|
|
818
|
|
|
// Update album count |
|
819
|
|
|
if (0 == $cat->getVar('cat_nb_photo')) { |
|
820
|
|
|
$criteria = new \CriteriaCompo(); |
|
821
|
|
|
$criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<')); |
|
822
|
|
|
$criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>')); |
|
823
|
|
|
$catHandler->updateFieldValue('cat_nb_album', 'cat_nb_album + 1', $criteria); |
|
824
|
|
|
} |
|
825
|
|
|
|
|
826
|
|
|
// Update photo count |
|
827
|
|
|
$criteria = new \CriteriaCompo(); |
|
828
|
|
|
$criteria->add(new \Criteria('nleft', $cat->getVar('nleft'), '<=')); |
|
829
|
|
|
$criteria->add(new \Criteria('nright', $cat->getVar('nright'), '>=')); |
|
830
|
|
|
$catHandler->updateFieldValue('cat_nb_photo', 'cat_nb_photo + 1', $criteria); |
|
831
|
|
|
|
|
832
|
|
|
return 0; |
|
833
|
|
|
} else { |
|
834
|
|
|
$extraTags['X_ITEM_URL'] = XOOPS_URL . '/modules/extgallery/admin/photo.php'; |
|
835
|
|
|
$notificationHandler->triggerEvent('global', 0, 'new_photo_pending', $extraTags); |
|
836
|
|
|
|
|
837
|
|
|
return 1; |
|
838
|
|
|
} |
|
839
|
|
|
} |
|
840
|
|
|
|
|
841
|
|
|
/** |
|
842
|
|
|
* @param $catId |
|
843
|
|
|
* @param $dirtyPhotoName |
|
844
|
|
|
* @param string $photoTitle |
|
845
|
|
|
* @param string $photoDesc |
|
846
|
|
|
* @param string $photoExtra |
|
847
|
|
|
* @param string $photoTag |
|
848
|
|
|
* |
|
849
|
|
|
* @return mixed |
|
850
|
|
|
*/ |
|
851
|
|
|
public function addLocalPhoto( |
|
852
|
|
|
$catId, |
|
853
|
|
|
$dirtyPhotoName, |
|
854
|
|
|
$photoTitle = '', |
|
855
|
|
|
$photoDesc = '', |
|
856
|
|
|
$photoExtra = '', |
|
857
|
|
|
$photoTag = '' |
|
858
|
|
|
) { |
|
859
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/pear/Image/Transform.php'; |
|
|
|
|
|
|
860
|
|
|
|
|
861
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
862
|
|
|
$permHandler = Extgallery\PublicPermHandler::getInstance(); |
|
863
|
|
|
|
|
864
|
|
|
// Replace all bad file name character |
|
865
|
|
|
$photoName = $this->_makeFileName($dirtyPhotoName); |
|
866
|
|
|
rename($this->_getUploadPhotoPath() . $dirtyPhotoName, $this->_getUploadPhotoPath() . $photoName); |
|
|
|
|
|
|
867
|
|
|
|
|
868
|
|
|
//DNPROSSI - changed photo_desc to photo_title |
|
869
|
|
|
// Making auto description |
|
870
|
|
|
if ('' === $photoTitle) { |
|
871
|
|
|
$photoTitle = $this->_getAutoDescription($photoName); |
|
872
|
|
|
} |
|
873
|
|
|
|
|
874
|
|
|
$originalName = ''; |
|
875
|
|
|
// Save original photo |
|
876
|
|
|
if ($xoopsModuleConfig['save_large'] && $xoopsModuleConfig['save_original']) { |
|
877
|
|
|
$fileName = explode('.', $photoName); |
|
878
|
|
|
$originalName = md5(uniqid(mt_rand(), true)) . '.' . $fileName[1]; |
|
879
|
|
|
copy($this->_getUploadPhotoPath() . $photoName, $this->_getUploadPhotoPath() . 'original/' . $originalName); |
|
880
|
|
|
} |
|
881
|
|
|
|
|
882
|
|
|
$this->_largePhotoTreatment($photoName); |
|
883
|
|
|
|
|
884
|
|
|
$this->_mediumPhotoTreatment($photoName); |
|
885
|
|
|
|
|
886
|
|
|
$this->_makeThumb($photoName); |
|
887
|
|
|
|
|
888
|
|
|
$imageDimension = $this->_getImageDimension($photoName); |
|
889
|
|
|
|
|
890
|
|
|
$userId = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
891
|
|
|
$data = [ |
|
892
|
|
|
'cat_id' => $catId, |
|
893
|
|
|
'photo_title' => $photoTitle, |
|
894
|
|
|
'photo_desc' => $photoDesc, |
|
895
|
|
|
'photo_name' => $photoName, |
|
896
|
|
|
'photo_orig_name' => $originalName, |
|
897
|
|
|
'uid' => $userId, |
|
898
|
|
|
'photo_size' => $this->_getPhotoSize($photoName), |
|
899
|
|
|
'photo_res_x' => $imageDimension['width'], |
|
900
|
|
|
'photo_res_y' => $imageDimension['height'], |
|
901
|
|
|
'photo_date' => time(), |
|
902
|
|
|
'photo_havelarge' => $this->_haveLargePhoto($photoName), |
|
903
|
|
|
'photo_approved' => $permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_autoapprove', $catId), |
|
904
|
|
|
'photo_extra' => $photoExtra, |
|
905
|
|
|
'dohtml' => $xoopsModuleConfig['allow_html'] |
|
906
|
|
|
]; |
|
907
|
|
|
|
|
908
|
|
|
// Deleting working photo |
|
909
|
|
|
unlink($this->_getUploadPhotoPath() . $photoName); |
|
910
|
|
|
|
|
911
|
|
|
$this->createPhoto($data); |
|
912
|
|
|
|
|
913
|
|
|
if (1 == $xoopsModuleConfig['usetag'] || (is_dir('../tag') || is_dir('../../tag'))) { |
|
914
|
|
|
$newid = $this->db->getInsertId(); |
|
915
|
|
|
$tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag'); |
|
|
|
|
|
|
916
|
|
|
$tagHandler->updateByItem($photoTag, $newid, 'extgallery', 0); |
|
917
|
|
|
} |
|
918
|
|
|
|
|
919
|
|
|
return $data['photo_approved']; |
|
920
|
|
|
} |
|
921
|
|
|
|
|
922
|
|
|
/** |
|
923
|
|
|
* @param $queryArray |
|
924
|
|
|
* @param $condition |
|
925
|
|
|
* @param $limit |
|
926
|
|
|
* @param $start |
|
927
|
|
|
* @param $userId |
|
928
|
|
|
* |
|
929
|
|
|
* @return array |
|
930
|
|
|
*/ |
|
931
|
|
|
public function getSearchedPhoto($queryArray, $condition, $limit, $start, $userId) |
|
932
|
|
|
{ |
|
933
|
|
|
$criteria = new \CriteriaCompo(); |
|
934
|
|
|
if ($userId > 0) { |
|
935
|
|
|
$criteria->add(new \Criteria('uid', $userId)); |
|
936
|
|
|
} |
|
937
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
938
|
|
|
if (is_array($queryArray) && count($queryArray) > 0) { |
|
939
|
|
|
$subCriteria = new \CriteriaCompo(); |
|
940
|
|
|
foreach ($queryArray as $keyWord) { |
|
941
|
|
|
$keyWordCriteria = new \CriteriaCompo(); |
|
942
|
|
|
$keyWordCriteria->add(new \Criteria('photo_title', '%' . $keyWord . '%', 'LIKE')); |
|
943
|
|
|
$keyWordCriteria->add(new \Criteria('photo_desc', '%' . $keyWord . '%', 'LIKE'), 'OR'); |
|
944
|
|
|
$keyWordCriteria->add(new \Criteria('photo_name', '%' . $keyWord . '%', 'LIKE'), 'OR'); |
|
945
|
|
|
$subCriteria->add($keyWordCriteria, $condition); |
|
946
|
|
|
unset($keyWordCriteria); |
|
947
|
|
|
} |
|
948
|
|
|
$criteria->add($subCriteria); |
|
949
|
|
|
} |
|
950
|
|
|
$criteria->setStart($start); |
|
951
|
|
|
$criteria->setLimit($limit); |
|
952
|
|
|
$criteria->setSort('photo_date'); |
|
953
|
|
|
|
|
954
|
|
|
$photos =& $this->getObjects($criteria); |
|
955
|
|
|
|
|
956
|
|
|
$ret = []; |
|
957
|
|
|
foreach ($photos as $photo) { |
|
958
|
|
|
if ($photo->getVar('photo_title')) { |
|
959
|
|
|
$title = $photo->getVar('photo_title'); |
|
960
|
|
|
} else { |
|
961
|
|
|
$title = $photo->getVar('photo_desc'); |
|
962
|
|
|
} |
|
963
|
|
|
$data = [ |
|
964
|
|
|
'image' => 'assets/images/extgallery-posticon.gif', |
|
965
|
|
|
'link' => 'public-photo.php?photoId=' . $photo->getVar('photo_id'), |
|
966
|
|
|
'title' => $title, |
|
967
|
|
|
'time' => $photo->getVar('photo_date'), |
|
968
|
|
|
'uid' => $photo->getVar('uid') |
|
969
|
|
|
]; |
|
970
|
|
|
$ret[] = $data; |
|
971
|
|
|
} |
|
972
|
|
|
|
|
973
|
|
|
return $ret; |
|
974
|
|
|
} |
|
975
|
|
|
|
|
976
|
|
|
/** |
|
977
|
|
|
* @return array |
|
978
|
|
|
*/ |
|
979
|
|
|
public function getPendingPhoto() |
|
980
|
|
|
{ |
|
981
|
|
|
$criteria = new \Criteria('photo_approved', 0); |
|
982
|
|
|
|
|
983
|
|
|
return $this->getObjects($criteria); |
|
984
|
|
|
} |
|
985
|
|
|
|
|
986
|
|
|
/** |
|
987
|
|
|
* @param $criteria |
|
988
|
|
|
* @param $data |
|
989
|
|
|
*/ |
|
990
|
|
|
public function _addInCriteria(&$criteria, $data) |
|
991
|
|
|
{ |
|
992
|
|
|
$count = count($data); |
|
993
|
|
|
if ($count > 0) { |
|
994
|
|
|
$in = '(' . $data[0]; |
|
995
|
|
|
array_shift($data); |
|
996
|
|
|
foreach ($data as $elmt) { |
|
997
|
|
|
$in .= ',' . $elmt; |
|
998
|
|
|
} |
|
999
|
|
|
$in .= ')'; |
|
1000
|
|
|
$criteria->add(new \Criteria('cat_id', $in, 'IN')); |
|
1001
|
|
|
} |
|
1002
|
|
|
} |
|
1003
|
|
|
|
|
1004
|
|
|
/** |
|
1005
|
|
|
* @param $param |
|
1006
|
|
|
* |
|
1007
|
|
|
* @return array |
|
1008
|
|
|
*/ |
|
1009
|
|
|
public function getRandomPhoto($param) |
|
1010
|
|
|
{ |
|
1011
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
1012
|
|
|
$criteria = new \CriteriaCompo(); |
|
1013
|
|
|
if (null !== $catHandler->getCatRestrictCriteria()) { |
|
1014
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
1015
|
|
|
} |
|
1016
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
1017
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1018
|
|
|
$criteria->setSort('RAND()'); |
|
1019
|
|
|
$criteria->setLimit($param['limit']); |
|
1020
|
|
|
|
|
1021
|
|
|
return $this->getObjects($criteria); |
|
1022
|
|
|
} |
|
1023
|
|
|
|
|
1024
|
|
|
/** |
|
1025
|
|
|
* @param $param |
|
1026
|
|
|
* |
|
1027
|
|
|
* @return array |
|
1028
|
|
|
*/ |
|
1029
|
|
|
public function getLastPhoto($param) |
|
1030
|
|
|
{ |
|
1031
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
1032
|
|
|
|
|
1033
|
|
|
$criteria = new \CriteriaCompo(); |
|
1034
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
1035
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
1036
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1037
|
|
|
$criteria->setSort('photo_date'); |
|
1038
|
|
|
$criteria->setOrder('DESC'); |
|
1039
|
|
|
$criteria->setLimit($param['limit']); |
|
1040
|
|
|
|
|
1041
|
|
|
return $this->getObjects($criteria); |
|
1042
|
|
|
} |
|
1043
|
|
|
|
|
1044
|
|
|
/** |
|
1045
|
|
|
* @param $param |
|
1046
|
|
|
* |
|
1047
|
|
|
* @return array |
|
1048
|
|
|
*/ |
|
1049
|
|
|
public function getTopViewPhoto($param) |
|
1050
|
|
|
{ |
|
1051
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
1052
|
|
|
|
|
1053
|
|
|
$criteria = new \CriteriaCompo(); |
|
1054
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
1055
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
1056
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1057
|
|
|
$criteria->setSort('photo_hits'); |
|
1058
|
|
|
$criteria->setOrder('DESC'); |
|
1059
|
|
|
$criteria->setLimit($param['limit']); |
|
1060
|
|
|
|
|
1061
|
|
|
return $this->getObjects($criteria); |
|
1062
|
|
|
} |
|
1063
|
|
|
|
|
1064
|
|
|
/** |
|
1065
|
|
|
* @param $param |
|
1066
|
|
|
* |
|
1067
|
|
|
* @return array |
|
1068
|
|
|
*/ |
|
1069
|
|
|
public function getTopRatedPhoto($param) |
|
1070
|
|
|
{ |
|
1071
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
1072
|
|
|
|
|
1073
|
|
|
$criteria = new \CriteriaCompo(); |
|
1074
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
1075
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
1076
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1077
|
|
|
$criteria->setSort('photo_rating'); |
|
1078
|
|
|
$criteria->setOrder('DESC'); |
|
1079
|
|
|
$criteria->setLimit($param['limit']); |
|
1080
|
|
|
|
|
1081
|
|
|
return $this->getObjects($criteria); |
|
1082
|
|
|
} |
|
1083
|
|
|
|
|
1084
|
|
|
/** |
|
1085
|
|
|
* @param $param |
|
1086
|
|
|
* |
|
1087
|
|
|
* @return array |
|
1088
|
|
|
*/ |
|
1089
|
|
|
public function getTopEcardPhoto($param) |
|
1090
|
|
|
{ |
|
1091
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
1092
|
|
|
|
|
1093
|
|
|
$criteria = new \CriteriaCompo(); |
|
1094
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
|
1095
|
|
|
$criteria->add(new \Criteria('photo_approved', 1)); |
|
1096
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1097
|
|
|
$criteria->setSort('photo_ecard'); |
|
1098
|
|
|
$criteria->setOrder('DESC'); |
|
1099
|
|
|
$criteria->setLimit($param['limit']); |
|
1100
|
|
|
|
|
1101
|
|
|
return $this->getObjects($criteria); |
|
1102
|
|
|
} |
|
1103
|
|
|
|
|
1104
|
|
|
/** |
|
1105
|
|
|
* @param $param |
|
1106
|
|
|
*/ |
|
1107
|
|
|
public function getTopSubmitter($param) |
|
1108
|
|
|
{ |
|
1109
|
|
|
$catHandler = Extgallery\Helper::getInstance()->getHandler('PublicCategory'); |
|
|
|
|
|
|
1110
|
|
|
|
|
1111
|
|
|
$criteria = new \Criteria(); |
|
1112
|
|
|
$this->_addInCriteria($criteria, $param['cat']); |
|
1113
|
|
|
|
|
1114
|
|
|
echo $criteria->renderWhere(); |
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
/** |
|
1118
|
|
|
* @return mixed |
|
1119
|
|
|
*/ |
|
1120
|
|
|
public function getInsertId() |
|
1121
|
|
|
{ |
|
1122
|
|
|
return $this->db->getInsertId(); |
|
1123
|
|
|
} |
|
1124
|
|
|
} |
|
1125
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.