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 http://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
|
|
|
include_once __DIR__ . '/photoHandler.php'; |
21
|
|
|
include_once __DIR__ . '/publicPerm.php'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ExtgalleryPublicPhoto |
25
|
|
|
*/ |
26
|
|
|
class ExtgalleryPublicPhoto extends ExtgalleryPhoto |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* ExtgalleryPublicPhoto constructor. |
30
|
|
|
*/ |
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
parent::__construct(); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class ExtgalleryPublicPhotoHandler |
39
|
|
|
*/ |
40
|
|
|
class ExtgalleryPublicPhotoHandler extends ExtgalleryPhotoHandler |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* ExtgalleryPublicPhotoHandler constructor. |
44
|
|
|
* @param XoopsDatabase $db |
45
|
|
|
*/ |
46
|
|
|
public function __construct(XoopsDatabase $db) |
47
|
|
|
{ |
48
|
|
|
parent::__construct($db, 'public'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $photo |
53
|
|
|
*/ |
54
|
|
|
public function deleteFile(XoopsObject $photo = null) |
55
|
|
|
{ |
56
|
|
View Code Duplication |
if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name'))) { |
|
|
|
|
57
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name'))) { |
|
|
|
|
61
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo->getVar('photo_name')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
if (file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name'))) { |
|
|
|
|
65
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/large_' . $photo->getVar('photo_name')); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
if ($photo->getVar('photo_orig_name') != '' |
|
|
|
|
69
|
|
|
&& file_exists(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name')) |
70
|
|
|
) { |
71
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/' . $photo->getVar('photo_orig_name')); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return array|int|string |
77
|
|
|
*/ |
78
|
|
|
public function getAllSize() |
79
|
|
|
{ |
80
|
|
|
return $this->getSum(null, 'photo_size'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function _getUploadPhotoPath() |
87
|
|
|
{ |
88
|
|
|
return XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/'; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $userId |
93
|
|
|
* @param $start |
94
|
|
|
* @param $sortby |
95
|
|
|
* @param $orderby |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getUserAlbumPhotoPage($userId, $start, $sortby, $orderby) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
102
|
|
|
|
103
|
|
|
$criteria = new CriteriaCompo(); |
104
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
105
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
106
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
107
|
|
|
$criteria->setSort($sortby); |
108
|
|
|
$criteria->setOrder($orderby); |
109
|
|
|
$criteria->setStart($start); |
110
|
|
|
$criteria->setLimit($GLOBALS['xoopsModuleConfig']['nb_column'] * $GLOBALS['xoopsModuleConfig']['nb_line']); |
111
|
|
|
|
112
|
|
|
return $this->getObjects($criteria); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param $userId |
117
|
|
|
* @param $photoDate |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
View Code Duplication |
public function getUserAlbumPrevPhoto($userId, $photoDate) |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
124
|
|
|
|
125
|
|
|
$criteria = new CriteriaCompo(); |
126
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
127
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
128
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
129
|
|
|
$criteria->add(new Criteria('photo_date', $photoDate, '>')); |
130
|
|
|
$criteria->setSort('photo_date'); |
131
|
|
|
$criteria->setOrder('ASC'); |
132
|
|
|
$criteria->setLimit(1); |
133
|
|
|
|
134
|
|
|
return $this->getObjects($criteria); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param $userId |
139
|
|
|
* @param $photoDate |
140
|
|
|
* |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public function getUserAlbumNextPhoto($userId, $photoDate) |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
146
|
|
|
|
147
|
|
|
$criteria = new CriteriaCompo(); |
148
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
149
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
150
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
151
|
|
|
$criteria->add(new Criteria('photo_date', $photoDate, '<')); |
152
|
|
|
$criteria->setSort('photo_date'); |
153
|
|
|
$criteria->setOrder('DESC'); |
154
|
|
|
$criteria->setLimit(1); |
155
|
|
|
|
156
|
|
|
return $this->getObjects($criteria); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param $userId |
161
|
|
|
* @param $photoDate |
162
|
|
|
* |
163
|
|
|
* @return int |
164
|
|
|
*/ |
165
|
|
View Code Duplication |
public function getUserAlbumCurrentPhotoPlace($userId, $photoDate) |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
168
|
|
|
|
169
|
|
|
$criteria = new CriteriaCompo(); |
170
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
171
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
172
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
173
|
|
|
$criteria->add(new Criteria('photo_date', $photoDate, '>=')); |
174
|
|
|
$criteria->setSort('photo_date'); |
175
|
|
|
$criteria->setOrder('ASC'); |
176
|
|
|
|
177
|
|
|
return $this->getCount($criteria); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param $userId |
182
|
|
|
* |
183
|
|
|
* @return int |
184
|
|
|
*/ |
185
|
|
|
public function getUserAlbumCount($userId) |
186
|
|
|
{ |
187
|
|
|
$catHandler = xoops_getModuleHandler('publiccat', 'extgallery'); |
188
|
|
|
|
189
|
|
|
$criteria = new CriteriaCompo(); |
190
|
|
|
$criteria->add($catHandler->getCatRestrictCriteria()); |
191
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
192
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
193
|
|
|
|
194
|
|
|
return $this->getCount($criteria); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param $userId |
199
|
|
|
* |
200
|
|
|
* @return array |
201
|
|
|
*/ |
202
|
|
View Code Duplication |
public function getUserPhotoAlbumId($userId) |
|
|
|
|
203
|
|
|
{ |
204
|
|
|
$criteria = new CriteriaCompo(); |
205
|
|
|
$criteria->add(new Criteria('uid', $userId)); |
206
|
|
|
$criteria->add(new Criteria('photo_approved', 1)); |
207
|
|
|
|
208
|
|
|
$sql = 'SELECT photo_id FROM ' . $this->db->prefix('extgallery_publicphoto') . ' ' . $criteria->renderWhere() . ' ORDER BY photo_date, photo_id DESC;'; |
209
|
|
|
|
210
|
|
|
$result = $this->db->query($sql); |
211
|
|
|
$ret = array(); |
212
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
213
|
|
|
$ret[] = $myrow['photo_id']; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $ret; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
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.