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