1 | <?php |
||
2 | /** |
||
3 | * Xoopsemotions plugin for tinymce |
||
4 | * |
||
5 | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
||
6 | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
7 | * @package class / xoopseditor |
||
8 | * @subpackage tinymce / xoops plugins |
||
9 | * @since 2.3.0 |
||
10 | * @author ralf57 |
||
11 | * @author luciorota <[email protected]> |
||
12 | * @author Laurent JEN <[email protected]> |
||
13 | */ |
||
14 | |||
15 | use Xmf\Request; |
||
16 | |||
17 | // load mainfile.php |
||
18 | $current_path = __DIR__; |
||
19 | if (DIRECTORY_SEPARATOR !== '/') { |
||
20 | $current_path = str_replace(DIRECTORY_SEPARATOR, '/', $current_path); |
||
21 | } |
||
22 | $xoops_root_path = substr($current_path, 0, strpos(strtolower($current_path), '/class/xoopseditor/tinymce/')); |
||
23 | include_once $xoops_root_path . '/mainfile.php'; |
||
24 | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
25 | |||
26 | /** |
||
27 | * This code was moved to the top to avoid overriding variables that do not come from post |
||
28 | */ |
||
29 | $op = 'list'; // default |
||
30 | if (isset($_POST)) { |
||
31 | foreach ($_POST as $k => $v) { |
||
32 | ${$k} = $v; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | // get current filename |
||
37 | $current_file = basename(__FILE__); |
||
38 | |||
39 | // load language definitions |
||
40 | xoops_loadLanguage('admin', 'system'); |
||
41 | xoops_loadLanguage('/admin/images', 'system'); |
||
42 | |||
43 | // include |
||
44 | xoops_load('xoopsformloader'); |
||
45 | //xoops_load("xoopsmodule"); |
||
46 | include_once XOOPS_ROOT_PATH . '/include/cp_functions.php'; |
||
47 | include_once XOOPS_ROOT_PATH . '/modules/system/constants.php'; |
||
48 | |||
49 | global $xoopsConfig; |
||
50 | |||
51 | // check user/group - start |
||
52 | $isadmin = false; |
||
53 | |||
54 | /** @var XoopsGroupPermHandler $gperm_handler */ |
||
55 | $gperm_handler = xoops_getHandler('groupperm'); |
||
56 | $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
||
57 | $isadmin = $gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_IMAGE, $groups); |
||
58 | |||
59 | // check category readability/writability |
||
60 | /** @var \XoopsImagecategoryHandler $imgcat_handler */ |
||
61 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
62 | $catreadlist = $imgcat_handler->getList($groups, 'imgcat_read', 1); // get readable categories |
||
63 | $catwritelist = $imgcat_handler->getList($groups, 'imgcat_write', 1); // get writable categories |
||
64 | |||
65 | $catreadcount = count($catreadlist); // count readable categories |
||
66 | $catwritecount = count($catwritelist); // count writable categories |
||
67 | |||
68 | // check/set parameters - start |
||
69 | if (!isset($_REQUEST['target'])) { |
||
70 | exit(); |
||
71 | } else { |
||
72 | $target = $_REQUEST['target']; |
||
73 | } |
||
74 | |||
75 | if (isset($_GET['op'])) { |
||
76 | $op = Request::getString('op', '', 'GET'); |
||
77 | } |
||
78 | |||
79 | if (isset($_GET['target'])) { |
||
80 | $target = Request::getString('target', '', 'GET'); |
||
81 | } |
||
82 | |||
83 | if (isset($_GET['image_id'])) { |
||
84 | $image_id = Request::getInt('image_id', 0, 'GET'); |
||
85 | } |
||
86 | |||
87 | if (isset($_GET['imgcat_id'])) { |
||
88 | $imgcat_id = Request::getInt('imgcat_id', 0, 'GET'); |
||
89 | } |
||
90 | |||
91 | if (isset($imgcat_id)) { |
||
92 | $imgcat_id = (int)$imgcat_id; |
||
93 | } |
||
94 | $target = htmlspecialchars($target, ENT_QUOTES | ENT_HTML5); |
||
95 | |||
96 | if ($isadmin || ($catreadcount > 0) || ($catwritecount > 0)) { |
||
97 | |||
98 | // Save Image modification - start |
||
99 | if (!empty($_POST['op']) && $op === 'save') { |
||
100 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
101 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
102 | } |
||
103 | $count = count($image_id); |
||
104 | if ($count > 0) { |
||
105 | $image_handler = xoops_getHandler('image'); |
||
106 | $error = array(); |
||
107 | for ($i = 0; $i < $count; ++$i) { |
||
108 | $image = $image_handler->get($image_id[$i]); |
||
109 | if (!is_object($image)) { |
||
110 | $error[] = sprintf(_FAILGETIMG, $image_id[$i]); |
||
111 | continue; |
||
112 | } |
||
113 | $image_display[$i] = empty($image_display[$i]) ? 0 : 1; |
||
114 | $image->setVar('image_display', $image_display[$i]); |
||
115 | $image->setVar('image_weight', $image_weight[$i]); |
||
116 | $image->setVar('image_nicename', $image_nicename[$i]); |
||
117 | $image->setVar('imgcat_id', $imgcat_id[$i]); |
||
118 | if (!$image_handler->insert($image)) { |
||
119 | $error[] = sprintf(_FAILSAVEIMG, $image_id[$i]); |
||
120 | } |
||
121 | } |
||
122 | if (count($error) > 0) { |
||
123 | redirect_header($current_file . '?target=' . $target, 3, xoops_error(implode('<br>', $error))); |
||
124 | } |
||
125 | } |
||
126 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
127 | } |
||
128 | // Save Image modification - end |
||
129 | |||
130 | // Add new image - start |
||
131 | if (!empty($_POST['op']) && $op === 'addfile') { |
||
132 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
133 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
134 | } |
||
135 | $imgcat = $imgcat_handler->get((int)$imgcat_id); |
||
136 | if (!is_object($imgcat)) { |
||
137 | redirect_header($current_file . '?target=' . $target, 3); |
||
138 | } |
||
139 | include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
140 | |||
141 | $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array( |
||
142 | 'image/gif', |
||
143 | 'image/jpeg', |
||
144 | 'image/pjpeg', |
||
145 | 'image/x-png', |
||
146 | 'image/png', |
||
147 | 'image/bmp'), $imgcat->getVar('imgcat_maxsize'), $imgcat->getVar('imgcat_maxwidth'), $imgcat->getVar('imgcat_maxheight')); |
||
148 | $uploader->setPrefix('img'); |
||
149 | $err = array(); |
||
150 | $ucount = count($_POST['xoops_upload_file']); |
||
151 | for ($i = 0; $i < $ucount; ++$i) { |
||
152 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) { |
||
153 | if (!$uploader->upload()) { |
||
154 | $err[] = $uploader->getErrors(); |
||
155 | } else { |
||
156 | $image_handler = xoops_getHandler('image'); |
||
157 | $image = $image_handler->create(); |
||
158 | $image->setVar('image_name', $uploader->getSavedFileName()); |
||
159 | $image->setVar('image_nicename', $image_nicename); |
||
160 | $image->setVar('image_mimetype', $uploader->getMediaType()); |
||
161 | $image->setVar('image_created', time()); |
||
162 | $image_display = empty($image_display) ? 0 : 1; |
||
163 | $image->setVar('image_display', $image_display); |
||
164 | $image->setVar('image_weight', $image_weight); |
||
165 | $image->setVar('imgcat_id', $imgcat_id); |
||
166 | if ($imgcat->getVar('imgcat_storetype') === 'db') { |
||
167 | $fp = @fopen($uploader->getSavedDestination(), 'rb'); |
||
168 | $fbinary = @fread($fp, filesize($uploader->getSavedDestination())); |
||
169 | @fclose($fp); |
||
170 | $image->setVar('image_body', $fbinary, true); |
||
171 | @unlink($uploader->getSavedDestination()); |
||
172 | } |
||
173 | if (!$image_handler->insert($image)) { |
||
174 | $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename')); |
||
175 | } |
||
176 | } |
||
177 | } else { |
||
178 | $err[] = sprintf(_FAILFETCHIMG, $i); |
||
179 | $err = array_merge($err, $uploader->getErrors(false)); |
||
180 | } |
||
181 | } |
||
182 | if (count($err) > 0) { |
||
183 | redirect_header($current_file . '?target=' . $target, 3, xoops_error(implode('<br>', $err))); |
||
184 | } |
||
185 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
186 | } |
||
187 | // Add new image - end |
||
188 | |||
189 | // Add new category - start |
||
190 | if (!empty($_POST['op']) && $op === 'addcat') { |
||
191 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
192 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
193 | } |
||
194 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
195 | $imagecategory = $imgcat_handler->create(); |
||
196 | $imagecategory->setVar('imgcat_name', $imgcat_name); |
||
197 | $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize); |
||
198 | $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth); |
||
199 | $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight); |
||
200 | $imgcat_display = empty($imgcat_display) ? 0 : 1; |
||
201 | $imagecategory->setVar('imgcat_display', $imgcat_display); |
||
202 | $imagecategory->setVar('imgcat_weight', $imgcat_weight); |
||
203 | $imagecategory->setVar('imgcat_storetype', $imgcat_storetype); |
||
204 | $imagecategory->setVar('imgcat_type', 'C'); |
||
205 | if (!$imgcat_handler->insert($imagecategory)) { |
||
206 | redirect_header($current_file . '?target=' . $target, 3); |
||
207 | } |
||
208 | $newid = $imagecategory->getVar('imgcat_id'); |
||
209 | $imagecategoryperm_handler = xoops_getHandler('groupperm'); |
||
210 | if (!isset($readgroup)) { |
||
211 | $readgroup = array(); |
||
212 | } |
||
213 | if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) { |
||
214 | array_push($readgroup, XOOPS_GROUP_ADMIN); |
||
215 | } |
||
216 | foreach ($readgroup as $rgroup) { |
||
217 | $imagecategoryperm = $imagecategoryperm_handler->create(); |
||
218 | $imagecategoryperm->setVar('gperm_groupid', $rgroup); |
||
219 | $imagecategoryperm->setVar('gperm_itemid', $newid); |
||
220 | $imagecategoryperm->setVar('gperm_name', 'imgcat_read'); |
||
221 | $imagecategoryperm->setVar('gperm_modid', 1); |
||
222 | $imagecategoryperm_handler->insert($imagecategoryperm); |
||
223 | unset($imagecategoryperm); |
||
224 | } |
||
225 | if (!isset($writegroup)) { |
||
226 | $writegroup = array(); |
||
227 | } |
||
228 | if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) { |
||
229 | array_push($writegroup, XOOPS_GROUP_ADMIN); |
||
230 | } |
||
231 | foreach ($writegroup as $wgroup) { |
||
232 | $imagecategoryperm = $imagecategoryperm_handler->create(); |
||
233 | $imagecategoryperm->setVar('gperm_groupid', $wgroup); |
||
234 | $imagecategoryperm->setVar('gperm_itemid', $newid); |
||
235 | $imagecategoryperm->setVar('gperm_name', 'imgcat_write'); |
||
236 | $imagecategoryperm->setVar('gperm_modid', 1); |
||
237 | $imagecategoryperm_handler->insert($imagecategoryperm); |
||
238 | unset($imagecategoryperm); |
||
239 | } |
||
240 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
241 | } |
||
242 | // Add new category - end |
||
243 | |||
244 | // Update categorie - start |
||
245 | if (!empty($_POST['op']) && $op === 'updatecat') { |
||
246 | if (!$GLOBALS['xoopsSecurity']->check() || $imgcat_id <= 0) { |
||
247 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
248 | } |
||
249 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
250 | $imagecategory = $imgcat_handler->get($imgcat_id); |
||
251 | if (!is_object($imagecategory)) { |
||
252 | redirect_header($current_file . '?target=' . $target, 3); |
||
253 | } |
||
254 | $imagecategory->setVar('imgcat_name', $imgcat_name); |
||
255 | $imgcat_display = empty($imgcat_display) ? 0 : 1; |
||
256 | $imagecategory->setVar('imgcat_display', $imgcat_display); |
||
257 | $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize); |
||
258 | $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth); |
||
259 | $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight); |
||
260 | $imagecategory->setVar('imgcat_weight', $imgcat_weight); |
||
261 | if (!$imgcat_handler->insert($imagecategory)) { |
||
262 | redirect_header($current_file . '?target=' . $target, 3); |
||
263 | } |
||
264 | /** @var \XoopsGroupPermHandler $imagecategoryperm_handler */ |
||
265 | $imagecategoryperm_handler = xoops_getHandler('groupperm'); |
||
266 | $criteria = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id)); |
||
267 | $criteria->add(new Criteria('gperm_modid', 1)); |
||
268 | $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write')); |
||
269 | $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR'); |
||
270 | $criteria->add($criteria2); |
||
271 | $imagecategoryperm_handler->deleteAll($criteria); |
||
272 | if (!isset($readgroup)) { |
||
273 | $readgroup = array(); |
||
274 | } |
||
275 | if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) { |
||
276 | array_push($readgroup, XOOPS_GROUP_ADMIN); |
||
277 | } |
||
278 | foreach ($readgroup as $rgroup) { |
||
279 | /** @var XoopsGroupPerm $imagecategoryperm */ |
||
280 | $imagecategoryperm = $imagecategoryperm_handler->create(); |
||
281 | $imagecategoryperm->setVar('gperm_groupid', $rgroup); |
||
282 | $imagecategoryperm->setVar('gperm_itemid', $imgcat_id); |
||
283 | $imagecategoryperm->setVar('gperm_name', 'imgcat_read'); |
||
284 | $imagecategoryperm->setVar('gperm_modid', 1); |
||
285 | $imagecategoryperm_handler->insert($imagecategoryperm); |
||
286 | unset($imagecategoryperm); |
||
287 | } |
||
288 | if (!isset($writegroup)) { |
||
289 | $writegroup = array(); |
||
290 | } |
||
291 | if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) { |
||
292 | array_push($writegroup, XOOPS_GROUP_ADMIN); |
||
293 | } |
||
294 | foreach ($writegroup as $wgroup) { |
||
295 | $imagecategoryperm = $imagecategoryperm_handler->create(); |
||
296 | $imagecategoryperm->setVar('gperm_groupid', $wgroup); |
||
297 | $imagecategoryperm->setVar('gperm_itemid', $imgcat_id); |
||
298 | $imagecategoryperm->setVar('gperm_name', 'imgcat_write'); |
||
299 | $imagecategoryperm->setVar('gperm_modid', 1); |
||
300 | $imagecategoryperm_handler->insert($imagecategoryperm); |
||
301 | unset($imagecategoryperm); |
||
302 | } |
||
303 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
304 | } |
||
305 | // Update categorie - end |
||
306 | |||
307 | // Confirm delete categorie - start |
||
308 | if (!empty($_GET['op']) && $op === 'delcat') { |
||
309 | xoops_header(); |
||
310 | echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />"; |
||
311 | xoops_confirm(array('op' => 'delcatok', 'imgcat_id' => $imgcat_id, 'target' => $target), 'xoopsimagebrowser.php', _AM_SYSTEM_IMAGES_RUDELIMGCAT); |
||
312 | xoops_footer(); |
||
313 | exit(); |
||
314 | } |
||
315 | // Confirm delete categorie - end |
||
316 | |||
317 | // Delete categorie - start |
||
318 | if (!empty($_POST['op']) && $op === 'delcatok') { |
||
319 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
320 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
321 | } |
||
322 | $imgcat_id = (int)$imgcat_id; |
||
323 | if ($imgcat_id <= 0) { |
||
324 | redirect_header($current_file . '?target=' . $target, 3); |
||
325 | } |
||
326 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
327 | $imagecategory = $imgcat_handler->get($imgcat_id); |
||
328 | if (!is_object($imagecategory)) { |
||
329 | redirect_header($current_file . '?target=' . $target, 3); |
||
330 | } |
||
331 | if ($imagecategory->getVar('imgcat_type') !== 'C') { |
||
332 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_IMAGES_SCATDELNG); |
||
333 | } |
||
334 | /** @var \XoopsImageHandler $image_handler */ |
||
335 | $image_handler = xoops_getHandler('image'); |
||
336 | $images = $image_handler->getObjects(new Criteria('imgcat_id', $imgcat_id), true, false); |
||
337 | $errors = array(); |
||
338 | foreach (array_keys($images) as $i) { |
||
339 | if (!$image_handler->delete($images[$i])) { |
||
340 | $errors[] = sprintf(_MD_FAILDEL, $i); |
||
341 | } else { |
||
342 | if (file_exists(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name')) && !unlink(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name'))) { |
||
343 | $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILUNLINK, $i); |
||
344 | } |
||
345 | } |
||
346 | } |
||
347 | if (!$imgcat_handler->delete($imagecategory)) { |
||
348 | $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILDEL, $imagecategory->getVar('imgcat_name')); |
||
349 | } |
||
350 | if (count($errors) > 0) { |
||
351 | redirect_header($current_file . '?target=' . $target, 3, xoops_error(implode('<br>', $error))); |
||
352 | } |
||
353 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
354 | } |
||
355 | // Delete categorie - end |
||
356 | |||
357 | // ************************* NOT USED ************************************ |
||
358 | // Confirm delete file - start |
||
359 | if (!empty($_GET['op']) && $op === 'delfile') { |
||
360 | xoops_header(); |
||
361 | echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />"; |
||
362 | xoops_confirm(array('op' => 'delfileok', 'image_id' => $image_id, 'target' => $target), 'xoopsimagebrowser.php', _AM_SYSTEM_IMAGES_RUDELIMG); |
||
363 | xoops_footer(); |
||
364 | exit(); |
||
365 | } |
||
366 | // Confirm delete file - end |
||
367 | |||
368 | // Delete file - start |
||
369 | if ($op === 'delfileok') { |
||
370 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
371 | redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||
372 | } |
||
373 | $image_id = (int)$image_id; |
||
374 | if ($image_id <= 0) { |
||
375 | redirect_header($current_file . '?target=' . $target, 3); |
||
376 | } |
||
377 | $image_handler = xoops_getHandler('image'); |
||
378 | $image = $image_handler->get($image_id); |
||
379 | if (!is_object($image)) { |
||
380 | redirect_header($current_file . '?target=' . $target, 3); |
||
381 | } |
||
382 | if (!$image_handler->delete($image)) { |
||
383 | redirect_header($current_file . '?target=' . $target, 3, xoops_error(sprintf(_MD_FAILDEL, $image->getVar('image_id')))); |
||
384 | } |
||
385 | @unlink(XOOPS_UPLOAD_PATH . '/' . $image->getVar('image_name')); |
||
386 | redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED); |
||
387 | } |
||
388 | // Delete file - end |
||
389 | // ************************* NOT USED ************************************ |
||
390 | } |
||
391 | |||
392 | echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; |
||
393 | echo '<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '">'; |
||
394 | echo '<head>'; |
||
395 | echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />'; |
||
396 | echo '<meta http-equiv="content-language" content="' . _LANGCODE . '" />'; |
||
397 | echo '<title>{#xoopsimagebrowser_dlg.dialog_title}</title>'; |
||
398 | echo '<script type="text/javascript" src="../../tiny_mce_popup.js"></script>'; |
||
399 | echo '<script type="text/javascript" src="../../utils/mctabs.js"></script>'; |
||
400 | echo '<script type="text/javascript" src="../../utils/form_utils.js"></script>'; |
||
401 | echo '<script type="text/javascript" src="../../utils/validate.js"></script>'; |
||
402 | echo '<script type="text/javascript" src="js/xoopsimagebrowser.js"></script>'; |
||
403 | echo '<link href="' . xoops_getcss($xoopsConfig['theme_set']) . '" rel="stylesheet" type="text/css" />'; |
||
404 | echo '<link href="css/xoopsimagebrowser.css" rel="stylesheet" type="text/css" />'; |
||
405 | echo '<base target="_self" />'; |
||
406 | echo '</head>'; |
||
407 | echo '<body>'; |
||
408 | |||
409 | echo '<div class="tabs">'; |
||
410 | echo '<ul>'; |
||
411 | echo '<li id="imagebrowser_tab" class="current"><span><a href="javascript:mcTabs.displayTab(\'imagebrowser_tab\',\'imagebrowser_panel\');" onmousedown="return false;">'; |
||
412 | if ($op === 'listimg') { |
||
413 | echo '{#xoopsimagebrowser_dlg.tab_listimages}'; |
||
414 | } else { |
||
415 | echo '{#xoopsimagebrowser_dlg.tab_listcategories}'; |
||
416 | } |
||
417 | echo '</a></span></li>'; |
||
418 | if (!empty($catwritelist)) { |
||
419 | echo '<li id="loadimage_tab"><span><a href="javascript:mcTabs.displayTab(\'loadimage_tab\',\'loadimage_panel\');" onmousedown="return false;">{#xoopsimagebrowser_dlg.tab_loadimage}</a></span></li>'; |
||
420 | } |
||
421 | if ($isadmin) { |
||
422 | echo '<li id="createcategory_tab"><span><a href="javascript:mcTabs.displayTab(\'createcategory_tab\',\'createcategory_panel\');" onmousedown="return false;">{#xoopsimagebrowser_dlg.tab_createcategory}</a></span></li>'; |
||
423 | } |
||
424 | echo '</ul>'; |
||
425 | echo '</div>'; |
||
426 | |||
427 | echo '<div class="panel_wrapper">'; |
||
428 | echo '<div id="imagebrowser_panel" class="panel current" style="overflow:auto;">'; |
||
429 | |||
430 | //list Categories - start |
||
431 | if ($op === 'list') { |
||
432 | if (!empty($catreadlist)) { |
||
433 | echo '<table width="100%" class="outer" cellspacing="1">'; |
||
434 | // get all categories |
||
435 | $imagecategories = $imgcat_handler->getObjects(); |
||
436 | $catcount = count($imagecategories); |
||
437 | /** @var \XoopsImageHandler $image_handler */ |
||
438 | $image_handler = xoops_getHandler('image'); |
||
439 | for ($i = 0; $i < $catcount; ++$i) { |
||
440 | echo '<tr valign="top" align="left"><td class="head">'; |
||
441 | if (in_array($imagecategories[$i]->getVar('imgcat_id'), array_keys($catreadlist))) { |
||
442 | // count images stored in this category |
||
443 | $this_imgcat_id = $imagecategories[$i]->getVar('imgcat_id'); |
||
444 | $countimagesincat = $image_handler->getCount(new Criteria('imgcat_id', $this_imgcat_id)); |
||
445 | echo $this_imgcat_id . ' - ' . $imagecategories[$i]->getVar('imgcat_name') . ' (' . sprintf(_NUMIMAGES, '<strong>' . $countimagesincat . '</strong>') . ')'; |
||
446 | echo '</td><td class="even">'; |
||
447 | echo ' [<a href="' . $current_file . '?target=' . $target . '&op=listimg&imgcat_id=' . $this_imgcat_id . '">' . _LIST . '</a>]'; |
||
448 | if ($isadmin) { |
||
449 | echo ' [<a href="' . $current_file . '?target=' . $target . '&op=editcat&imgcat_id=' . $this_imgcat_id . '">' . _EDIT . '</a>]'; |
||
450 | } |
||
451 | if ($isadmin && $imagecategories[$i]->getVar('imgcat_type') === 'C') { |
||
452 | echo ' [<a href="' . $current_file . '?target=' . $target . '&op=delcat&imgcat_id=' . $this_imgcat_id . '">' . _DELETE . '</a>]'; |
||
453 | } |
||
454 | } |
||
455 | echo '</td></tr>'; |
||
456 | } |
||
457 | echo '</table>'; |
||
458 | } |
||
459 | } |
||
460 | //list Categories - end |
||
461 | |||
462 | //list images - start |
||
463 | if ($op === 'listimg') { |
||
464 | $imgcat_id = (int)$imgcat_id; |
||
465 | if ($imgcat_id <= 0) { |
||
466 | redirect_header($current_file . '?target=' . $target, 1); |
||
467 | } |
||
468 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
469 | $imagecategory = $imgcat_handler->get($imgcat_id); |
||
470 | if (!is_object($imagecategory)) { |
||
471 | redirect_header($current_file . '?target=' . $target, 1); |
||
472 | } |
||
473 | $image_handler = xoops_getHandler('image'); |
||
474 | |||
475 | $criteria = new Criteria('imgcat_id', $imgcat_id); |
||
476 | $imgcount = $image_handler->getCount($criteria); |
||
477 | $start = Request::getInt('start', 0, 'GET'); |
||
478 | $criteria->setStart($start); |
||
479 | $criteria->setSort('image_id'); |
||
480 | $criteria->setOrder('DESC'); |
||
481 | $criteria->setLimit(20); |
||
482 | $images = $image_handler->getObjects($criteria, true, false); |
||
483 | |||
484 | echo '<a href="' . $current_file . '?target=' . $target . '">' . _MD_IMGMAIN . '</a> <span style="font-weight:bold;">></span> ' . $imagecategory->getVar('imgcat_name'); |
||
485 | echo '<br><br><strong>{#xoopsimagebrowser_dlg.select_image}</strong>'; |
||
486 | echo '<form action="' . $current_file . '?target=' . $target . '" method="post">'; |
||
487 | $rowspan = $catwritelist ? 5 : 2; |
||
488 | foreach (array_keys($images) as $i) { |
||
489 | $image_src = ''; |
||
490 | // check if image stored in db/as file - start |
||
491 | if ($imagecategory->getVar('imgcat_storetype') === 'db') { |
||
492 | $image_src = '' . XOOPS_URL . '/image.php?id=' . $i . ''; |
||
493 | if (ini_get('allow_url_fopen') == true){ |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
494 | $image_info = true; |
||
495 | $image_size = getimagesize($image_src); |
||
496 | } else { |
||
497 | $image_info = false; |
||
498 | } |
||
499 | } else { |
||
500 | $image_src = '' . XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name') . ''; |
||
501 | $image_size = getimagesize(XOOPS_ROOT_PATH . '/uploads/' . $images[$i]->getVar('image_name')); |
||
502 | $image_info = true; |
||
503 | } |
||
504 | |||
505 | // check if image stored in db/as file - end |
||
506 | echo '<table width="100%" class="outer">'; |
||
507 | echo '<tr>'; |
||
508 | echo '<td rowspan="' . $rowspan . '" class="xoopsimage">'; |
||
509 | |||
510 | echo '<img id="imageid' . $images[$i]->getVar('image_id') . '" src="' . $image_src . '" alt="' . $images[$i]->getVar('image_nicename', 'E') . '" title="' . $images[$i]->getVar('image_nicename', 'E') . '" onclick="XoopsimagebrowserDialog.insertAndClose(\'imageid' . $images[$i]->getVar('image_id') . '\');return false;"/>'; |
||
511 | echo '<br>'; |
||
512 | if ($image_info == true){ |
||
0 ignored issues
–
show
|
|||
513 | echo '' . $image_size[0] . 'x' . $image_size[1] . ''; |
||
514 | } |
||
515 | echo '</td>'; |
||
516 | echo '<td class="head">' . _IMAGENAME, '</td>'; |
||
517 | echo '<td class="even"><input type="hidden" name="image_id[]" value="' . $i . '" /><input type="text" name="image_nicename[]" value="' . $images[$i]->getVar('image_nicename', 'E') . '" size="20" maxlength="255" /></td>'; |
||
518 | echo '</tr>'; |
||
519 | |||
520 | echo '<tr>'; |
||
521 | echo '<td class="head">' . _IMAGEMIME . '</td>'; |
||
522 | echo '<td class="odd">' . $images[$i]->getVar('image_mimetype') . '</td>'; |
||
523 | echo '</tr>'; |
||
524 | |||
525 | if ($catwritelist) { |
||
526 | echo '<tr>'; |
||
527 | echo '<td class="head">' . _IMAGECAT . '</td>'; |
||
528 | echo '<td class="even">'; |
||
529 | echo '<select name="imgcat_id[]" size="1">'; |
||
530 | $list = $imgcat_handler->getList($groups, null, null, $imagecategory->getVar('imgcat_storetype')); |
||
531 | foreach ($list as $value => $name) { |
||
532 | echo '<option value="' . $value . '"' . (($value == $images[$i]->getVar('imgcat_id')) ? ' selected="selected"' : '') . '>' . $name . '</option>'; |
||
533 | } |
||
534 | echo '</select>'; |
||
535 | echo '</td>'; |
||
536 | echo '</tr>'; |
||
537 | |||
538 | echo '<tr>'; |
||
539 | echo '<td class="head">' . _IMGWEIGHT . '</td>'; |
||
540 | echo '<td class="odd"><input type="text" name="image_weight[]" value="' . $images[$i]->getVar('image_weight') . '" size="3" maxlength="4" /></td>'; |
||
541 | echo '</tr>'; |
||
542 | |||
543 | echo '<tr>'; |
||
544 | echo '<td class="head">' . _IMGDISPLAY . '</td>'; |
||
545 | echo '<td class="even">'; |
||
546 | echo '<input type="checkbox" name="image_display[]" value="1"' . (($images[$i]->getVar('image_display') == 1) ? ' checked="checked"' : '') . ' />'; |
||
547 | echo '</td>'; |
||
548 | echo '</tr>'; |
||
549 | } |
||
550 | echo '</table>'; |
||
551 | echo '<br>'; |
||
552 | } |
||
553 | |||
554 | if ($imgcount > 0) { |
||
555 | if ($imgcount > 20) { |
||
556 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
557 | $nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'op=listimg&target=' . $target . '&imgcat_id=' . $imgcat_id); |
||
558 | echo '<div text-align="right">' . $nav->renderNav() . '</div>'; |
||
559 | } |
||
560 | if ($catwritelist) { |
||
561 | echo '<input type="hidden" name="op" value="save" />' . $GLOBALS['xoopsSecurity']->getTokenHTML() . '<input type="submit" name="submit" value="' . _SUBMIT . '" />'; |
||
562 | echo '</form>'; |
||
563 | } |
||
564 | } |
||
565 | } |
||
566 | //list images - end |
||
567 | |||
568 | //edit category - start |
||
569 | if ($op === 'editcat') { |
||
570 | if ($imgcat_id <= 0) { |
||
571 | redirect_header($current_file . '?target=' . $target, 1); |
||
572 | } |
||
573 | $imgcat_handler = xoops_getHandler('imagecategory'); |
||
574 | $imagecategory = $imgcat_handler->get($imgcat_id); |
||
575 | if (!is_object($imagecategory)) { |
||
576 | redirect_header($current_file . '?target=' . $target, 1); |
||
577 | } |
||
578 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
579 | $imagecategoryperm_handler = xoops_getHandler('groupperm'); |
||
580 | $form = new XoopsThemeForm(_MD_EDITIMGCAT, 'imagecat_form', '' . $current_file . '?target=' . $target . '', 'post', true); |
||
581 | $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true); |
||
582 | $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true)); |
||
583 | $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true)); |
||
584 | $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize'))); |
||
585 | $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth'))); |
||
586 | $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight'))); |
||
587 | $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight'))); |
||
588 | $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO)); |
||
589 | $storetype = array('db' => _MD_INDB, 'file' => _MD_ASFILE); |
||
590 | $form->addElement(new XoopsFormLabel(_MD_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')])); |
||
591 | $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id)); |
||
592 | $form->addElement(new XoopsFormHidden('op', 'updatecat')); |
||
593 | $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit')); |
||
594 | echo '<a href="' . $current_file . '?target=' . $target . '">' . _MD_IMGMAIN . '</a> <span style="font-weight:bold;">></span> ' . $imagecategory->getVar('imgcat_name') . '<br><br>'; |
||
595 | $form->display(); |
||
596 | } |
||
597 | echo '<div class="mceActionPanel floatright" >'; |
||
598 | echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />'; |
||
599 | echo '</div>'; |
||
600 | echo '</div>'; |
||
601 | //edit category - end |
||
602 | |||
603 | //create Image - start |
||
604 | if ($isadmin || !empty($catwritelist)) { |
||
605 | echo '<div id="loadimage_panel" class="panel" style="overflow:auto;">'; |
||
606 | $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', '' . $current_file . '?target=' . $target . '', 'post', true); |
||
607 | $form->setExtra('enctype="multipart/form-data"'); |
||
608 | $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true); |
||
609 | $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id'); |
||
610 | if ($isadmin) { |
||
611 | $select->addOptionArray($imgcat_handler->getList()); |
||
612 | } else { |
||
613 | $select->addOptionArray($catwritelist); |
||
614 | } |
||
615 | $form->addElement($select, true); |
||
616 | $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000)); |
||
617 | $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0)); |
||
618 | $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO)); |
||
619 | $form->addElement(new XoopsFormHidden('op', 'addfile')); |
||
620 | $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit')); |
||
621 | $form->display(); |
||
622 | echo '<div class="mceActionPanel floatright" >'; |
||
623 | echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />'; |
||
624 | echo '</div>'; |
||
625 | echo '</div>'; |
||
626 | } |
||
627 | //create Image - end |
||
628 | |||
629 | //create Category - start |
||
630 | if ($isadmin) { |
||
631 | echo '<div id="createcategory_panel" class="panel" style="overflow:auto;">'; |
||
632 | $form = new XoopsThemeForm(_MD_ADDIMGCAT, 'imagecat_form', '' . $current_file . '?target=' . $target . '', 'post', true); |
||
633 | $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255), true); |
||
634 | $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true)); |
||
635 | $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true)); |
||
636 | $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000)); |
||
637 | $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120)); |
||
638 | $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120)); |
||
639 | $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0)); |
||
640 | $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO)); |
||
641 | $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE . '<br><span style="color:#ff0000;">' . _MD_STRTYOPENG . '</span>', 'imgcat_storetype', 'file'); |
||
642 | $storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB)); |
||
643 | $form->addElement($storetype); |
||
644 | $form->addElement(new XoopsFormHidden('op', 'addcat')); |
||
645 | $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit')); |
||
646 | $form->display(); |
||
647 | echo '<div class="mceActionPanel floatright" >'; |
||
648 | echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />'; |
||
649 | echo '</div>'; |
||
650 | echo '</div>'; |
||
651 | } |
||
652 | //create Category - end |
||
653 | |||
654 | echo '</div>'; |
||
655 | xoops_footer(); |
||
656 |