Issues (3210)

plugins/xoopsimagemanager/xoopsimagebrowser.php (2 issues)

1
<?php
2
/**
3
 *  Xoopsemotions plugin for tinymce
4
 *
5
 * @copyright       (c) 2000-2025 XOOPS Project (https://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() : [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         = [];
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, [
142
            'image/gif',
143
            'image/jpeg',
144
            'image/pjpeg',
145
            'image/x-png',
146
            'image/png',
147
            'image/bmp',
148
        ], $imgcat->getVar('imgcat_maxsize'), $imgcat->getVar('imgcat_maxwidth'), $imgcat->getVar('imgcat_maxheight'));
149
        $uploader->setPrefix('img');
150
        $err    = [];
151
        $ucount = count($_POST['xoops_upload_file']);
152
        for ($i = 0; $i < $ucount; ++$i) {
153
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
154
                if (!$uploader->upload()) {
155
                    $err[] = $uploader->getErrors();
156
                } else {
157
                    $image_handler = xoops_getHandler('image');
158
                    $image         = $image_handler->create();
159
                    $image->setVar('image_name', $uploader->getSavedFileName());
160
                    $image->setVar('image_nicename', $image_nicename);
161
                    $image->setVar('image_mimetype', $uploader->getMediaType());
162
                    $image->setVar('image_created', time());
163
                    $image_display = empty($image_display) ? 0 : 1;
164
                    $image->setVar('image_display', $image_display);
165
                    $image->setVar('image_weight', $image_weight);
166
                    $image->setVar('imgcat_id', $imgcat_id);
167
                    if ($imgcat->getVar('imgcat_storetype') === 'db') {
168
                        $fp      = @fopen($uploader->getSavedDestination(), 'rb');
169
                        $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
170
                        @fclose($fp);
171
                        $image->setVar('image_body', $fbinary, true);
172
                        @unlink($uploader->getSavedDestination());
173
                    }
174
                    if (!$image_handler->insert($image)) {
175
                        $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
176
                    }
177
                }
178
            } else {
179
                $err[] = sprintf(_FAILFETCHIMG, $i);
180
                $err   = array_merge($err, $uploader->getErrors(false));
181
            }
182
        }
183
        if (count($err) > 0) {
184
            redirect_header($current_file . '?target=' . $target, 3, xoops_error(implode('<br>', $err)));
185
        }
186
        redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED);
187
    }
188
    // Add new image - end
189
190
    // Add new category - start
191
    if (!empty($_POST['op']) && $op === 'addcat') {
192
        if (!$GLOBALS['xoopsSecurity']->check()) {
193
            redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
194
        }
195
        $imgcat_handler = xoops_getHandler('imagecategory');
196
        $imagecategory  = $imgcat_handler->create();
197
        $imagecategory->setVar('imgcat_name', $imgcat_name);
198
        $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
199
        $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
200
        $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
201
        $imgcat_display = empty($imgcat_display) ? 0 : 1;
202
        $imagecategory->setVar('imgcat_display', $imgcat_display);
203
        $imagecategory->setVar('imgcat_weight', $imgcat_weight);
204
        $imagecategory->setVar('imgcat_storetype', $imgcat_storetype);
205
        $imagecategory->setVar('imgcat_type', 'C');
206
        if (!$imgcat_handler->insert($imagecategory)) {
207
            redirect_header($current_file . '?target=' . $target, 3);
208
        }
209
        $newid                     = $imagecategory->getVar('imgcat_id');
210
        $imagecategoryperm_handler = xoops_getHandler('groupperm');
211
        if (!isset($readgroup)) {
212
            $readgroup = [];
213
        }
214
        if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
215
            array_push($readgroup, XOOPS_GROUP_ADMIN);
216
        }
217
        foreach ($readgroup as $rgroup) {
218
            $imagecategoryperm = $imagecategoryperm_handler->create();
219
            $imagecategoryperm->setVar('gperm_groupid', $rgroup);
220
            $imagecategoryperm->setVar('gperm_itemid', $newid);
221
            $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
222
            $imagecategoryperm->setVar('gperm_modid', 1);
223
            $imagecategoryperm_handler->insert($imagecategoryperm);
224
            unset($imagecategoryperm);
225
        }
226
        if (!isset($writegroup)) {
227
            $writegroup = [];
228
        }
229
        if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
230
            array_push($writegroup, XOOPS_GROUP_ADMIN);
231
        }
232
        foreach ($writegroup as $wgroup) {
233
            $imagecategoryperm = $imagecategoryperm_handler->create();
234
            $imagecategoryperm->setVar('gperm_groupid', $wgroup);
235
            $imagecategoryperm->setVar('gperm_itemid', $newid);
236
            $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
237
            $imagecategoryperm->setVar('gperm_modid', 1);
238
            $imagecategoryperm_handler->insert($imagecategoryperm);
239
            unset($imagecategoryperm);
240
        }
241
        redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED);
242
    }
243
    // Add new category - end
244
245
    // Update category - start
246
    if (!empty($_POST['op']) && $op === 'updatecat') {
247
        if (!$GLOBALS['xoopsSecurity']->check() || $imgcat_id <= 0) {
248
            redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
249
        }
250
        $imgcat_handler = xoops_getHandler('imagecategory');
251
        $imagecategory  = $imgcat_handler->get($imgcat_id);
252
        if (!is_object($imagecategory)) {
253
            redirect_header($current_file . '?target=' . $target, 3);
254
        }
255
        $imagecategory->setVar('imgcat_name', $imgcat_name);
256
        $imgcat_display = empty($imgcat_display) ? 0 : 1;
257
        $imagecategory->setVar('imgcat_display', $imgcat_display);
258
        $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
259
        $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
260
        $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
261
        $imagecategory->setVar('imgcat_weight', $imgcat_weight);
262
        if (!$imgcat_handler->insert($imagecategory)) {
263
            redirect_header($current_file . '?target=' . $target, 3);
264
        }
265
        /** @var \XoopsGroupPermHandler $imagecategoryperm_handler */
266
        $imagecategoryperm_handler = xoops_getHandler('groupperm');
267
        $criteria                  = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
268
        $criteria->add(new Criteria('gperm_modid', 1));
269
        $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
270
        $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
271
        $criteria->add($criteria2);
272
        $imagecategoryperm_handler->deleteAll($criteria);
273
        if (!isset($readgroup)) {
274
            $readgroup = [];
275
        }
276
        if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
277
            array_push($readgroup, XOOPS_GROUP_ADMIN);
278
        }
279
        foreach ($readgroup as $rgroup) {
280
            /** @var XoopsGroupPerm $imagecategoryperm */
281
            $imagecategoryperm = $imagecategoryperm_handler->create();
282
            $imagecategoryperm->setVar('gperm_groupid', $rgroup);
283
            $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
284
            $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
285
            $imagecategoryperm->setVar('gperm_modid', 1);
286
            $imagecategoryperm_handler->insert($imagecategoryperm);
287
            unset($imagecategoryperm);
288
        }
289
        if (!isset($writegroup)) {
290
            $writegroup = [];
291
        }
292
        if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
293
            array_push($writegroup, XOOPS_GROUP_ADMIN);
294
        }
295
        foreach ($writegroup as $wgroup) {
296
            $imagecategoryperm = $imagecategoryperm_handler->create();
297
            $imagecategoryperm->setVar('gperm_groupid', $wgroup);
298
            $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
299
            $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
300
            $imagecategoryperm->setVar('gperm_modid', 1);
301
            $imagecategoryperm_handler->insert($imagecategoryperm);
302
            unset($imagecategoryperm);
303
        }
304
        redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED);
305
    }
306
    // Update category - end
307
308
    // Confirm delete category - start
309
    if (!empty($_GET['op']) && $op === 'delcat') {
310
        xoops_header();
311
        echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />";
312
        xoops_confirm(['op' => 'delcatok', 'imgcat_id' => $imgcat_id, 'target' => $target], 'xoopsimagebrowser.php', _AM_SYSTEM_IMAGES_RUDELIMGCAT);
313
        xoops_footer();
314
        exit();
315
    }
316
    // Confirm delete category - end
317
318
    // Delete category - start
319
    if (!empty($_POST['op']) && $op === 'delcatok') {
320
        if (!$GLOBALS['xoopsSecurity']->check()) {
321
            redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
322
        }
323
        $imgcat_id = (int) $imgcat_id;
324
        if ($imgcat_id <= 0) {
325
            redirect_header($current_file . '?target=' . $target, 3);
326
        }
327
        $imgcat_handler = xoops_getHandler('imagecategory');
328
        $imagecategory  = $imgcat_handler->get($imgcat_id);
329
        if (!is_object($imagecategory)) {
330
            redirect_header($current_file . '?target=' . $target, 3);
331
        }
332
        if ($imagecategory->getVar('imgcat_type') !== 'C') {
333
            redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_IMAGES_SCATDELNG);
334
        }
335
        /** @var \XoopsImageHandler $image_handler */
336
        $image_handler = xoops_getHandler('image');
337
        $images        = $image_handler->getObjects(new Criteria('imgcat_id', $imgcat_id), true, false);
338
        $errors        = [];
339
        foreach (array_keys($images) as $i) {
340
            if (!$image_handler->delete($images[$i])) {
341
                $errors[] = sprintf(_MD_FAILDEL, $i);
342
            } else {
343
                if (file_exists(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name')) && !unlink(XOOPS_UPLOAD_PATH . '/' . $images[$i]->getVar('image_name'))) {
344
                    $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILUNLINK, $i);
345
                }
346
            }
347
        }
348
        if (!$imgcat_handler->delete($imagecategory)) {
349
            $errors[] = sprintf(_AM_SYSTEM_IMAGES_FAILDEL, $imagecategory->getVar('imgcat_name'));
350
        }
351
        if (count($errors) > 0) {
352
            redirect_header($current_file . '?target=' . $target, 3, xoops_error(implode('<br>', $error)));
353
        }
354
        redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED);
355
    }
356
    // Delete category - end
357
358
    // ************************* NOT USED ************************************
359
    // Confirm delete file - start
360
    if (!empty($_GET['op']) && $op === 'delfile') {
361
        xoops_header();
362
        echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />";
363
        xoops_confirm(['op' => 'delfileok', 'image_id' => $image_id, 'target' => $target], 'xoopsimagebrowser.php', _AM_SYSTEM_IMAGES_RUDELIMG);
364
        xoops_footer();
365
        exit();
366
    }
367
    // Confirm delete file - end
368
369
    // Delete file - start
370
    if ($op === 'delfileok') {
371
        if (!$GLOBALS['xoopsSecurity']->check()) {
372
            redirect_header($current_file . '?target=' . $target, 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
373
        }
374
        $image_id = (int) $image_id;
375
        if ($image_id <= 0) {
376
            redirect_header($current_file . '?target=' . $target, 3);
377
        }
378
        $image_handler = xoops_getHandler('image');
379
        $image         = $image_handler->get($image_id);
380
        if (!is_object($image)) {
381
            redirect_header($current_file . '?target=' . $target, 3);
382
        }
383
        if (!$image_handler->delete($image)) {
384
            redirect_header($current_file . '?target=' . $target, 3, xoops_error(sprintf(_MD_FAILDEL, $image->getVar('image_id'))));
385
        }
386
        @unlink(XOOPS_UPLOAD_PATH . '/' . $image->getVar('image_name'));
387
        redirect_header($current_file . '?target=' . $target, 3, _AM_SYSTEM_DBUPDATED);
388
    }
389
    // Delete file - end
390
    // ************************* NOT USED ************************************
391
}
392
393
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
394
echo '<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '">';
395
echo '<head>';
396
echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />';
397
echo '<meta http-equiv="content-language" content="' . _LANGCODE . '" />';
398
echo '<title>{#xoopsimagebrowser_dlg.dialog_title}</title>';
399
echo '<script type="text/javascript" src="../../tiny_mce_popup.js"></script>';
400
echo '<script type="text/javascript" src="../../utils/mctabs.js"></script>';
401
echo '<script type="text/javascript" src="../../utils/form_utils.js"></script>';
402
echo '<script type="text/javascript" src="../../utils/validate.js"></script>';
403
echo '<script type="text/javascript" src="js/xoopsimagebrowser.js"></script>';
404
echo '<link href="' . xoops_getcss($xoopsConfig['theme_set']) . '" rel="stylesheet" type="text/css" />';
405
echo '<link href="css/xoopsimagebrowser.css" rel="stylesheet" type="text/css" />';
406
echo '<base target="_self" />';
407
echo '</head>';
408
echo '<body>';
409
410
echo '<div class="tabs">';
411
echo '<ul>';
412
echo '<li id="imagebrowser_tab" class="current"><span><a href="javascript:mcTabs.displayTab(\'imagebrowser_tab\',\'imagebrowser_panel\');" onmousedown="return false;">';
413
if ($op === 'listimg') {
414
    echo '{#xoopsimagebrowser_dlg.tab_listimages}';
415
} else {
416
    echo '{#xoopsimagebrowser_dlg.tab_listcategories}';
417
}
418
echo '</a></span></li>';
419
if (!empty($catwritelist)) {
420
    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>';
421
}
422
if ($isadmin) {
423
    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>';
424
}
425
echo '</ul>';
426
echo '</div>';
427
428
echo '<div class="panel_wrapper">';
429
echo '<div id="imagebrowser_panel" class="panel current" style="overflow:auto;">';
430
431
//list Categories - start
432
if ($op === 'list') {
433
    if (!empty($catreadlist)) {
434
        echo '<table width="100%" class="outer" cellspacing="1">';
435
        // get all categories
436
        $imagecategories = $imgcat_handler->getObjects();
437
        $catcount        = count($imagecategories);
438
        /** @var \XoopsImageHandler $image_handler */
439
        $image_handler = xoops_getHandler('image');
440
        for ($i = 0; $i < $catcount; ++$i) {
441
            echo '<tr valign="top" align="left"><td class="head">';
442
            if (in_array($imagecategories[$i]->getVar('imgcat_id'), array_keys($catreadlist))) {
443
                // count images stored in this category
444
                $this_imgcat_id   = $imagecategories[$i]->getVar('imgcat_id');
445
                $countimagesincat = $image_handler->getCount(new Criteria('imgcat_id', $this_imgcat_id));
446
                echo $this_imgcat_id . ' - ' . $imagecategories[$i]->getVar('imgcat_name') . ' (' . sprintf(_NUMIMAGES, '<strong>' . $countimagesincat . '</strong>') . ')';
447
                echo '</td><td class="even">';
448
                echo '&nbsp;[<a href="' . $current_file . '?target=' . $target . '&amp;op=listimg&amp;imgcat_id=' . $this_imgcat_id . '">' . _LIST . '</a>]';
449
                if ($isadmin) {
450
                    echo '&nbsp;[<a href="' . $current_file . '?target=' . $target . '&amp;op=editcat&amp;imgcat_id=' . $this_imgcat_id . '">' . _EDIT . '</a>]';
451
                }
452
                if ($isadmin && $imagecategories[$i]->getVar('imgcat_type') === 'C') {
453
                    echo '&nbsp;[<a href="' . $current_file . '?target=' . $target . '&amp;op=delcat&amp;imgcat_id=' . $this_imgcat_id . '">' . _DELETE . '</a>]';
454
                }
455
            }
456
            echo '</td></tr>';
457
        }
458
        echo '</table>';
459
    }
460
}
461
//list Categories - end
462
463
//list images - start
464
if ($op === 'listimg') {
465
    $imgcat_id = (int) $imgcat_id;
466
    if ($imgcat_id <= 0) {
467
        redirect_header($current_file . '?target=' . $target, 1);
468
    }
469
    $imgcat_handler = xoops_getHandler('imagecategory');
470
    $imagecategory  = $imgcat_handler->get($imgcat_id);
471
    if (!is_object($imagecategory)) {
472
        redirect_header($current_file . '?target=' . $target, 1);
473
    }
474
    $image_handler = xoops_getHandler('image');
475
476
    $criteria = new Criteria('imgcat_id', $imgcat_id);
477
    $imgcount = $image_handler->getCount($criteria);
478
    $start    = Request::getInt('start', 0, 'GET');
479
    $criteria->setStart($start);
480
    $criteria->setSort('image_id');
481
    $criteria->setOrder('DESC');
482
    $criteria->setLimit(20);
483
    $images = $image_handler->getObjects($criteria, true, false);
484
485
    echo '<a href="' . $current_file . '?target=' . $target . '">' . _MD_IMGMAIN . '</a>&nbsp;<span style="font-weight:bold;">&gt;</span>&nbsp;' . $imagecategory->getVar('imgcat_name');
486
    echo '<br><br><strong>{#xoopsimagebrowser_dlg.select_image}</strong>';
487
    echo '<form action="' . $current_file . '?target=' . $target . '" method="post">';
488
    $rowspan = $catwritelist ? 5 : 2;
489
    foreach (array_keys($images) as $i) {
490
        $image_src = '';
491
        // check if image stored in db/as file - start
492
        if ($imagecategory->getVar('imgcat_storetype') === 'db') {
493
            $image_src = '' . XOOPS_URL . '/image.php?id=' . $i . '';
494
            if (ini_get('allow_url_fopen') == true) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing ini_get('allow_url_fopen') of type string to the boolean true. If you are specifically checking for a non-empty string, consider using the more explicit !== '' instead.
Loading history...
495
                $image_info = true;
496
                $image_size = getimagesize($image_src);
497
            } else {
498
                $image_info = false;
499
            }
500
        } else {
501
            $image_src = '' . XOOPS_UPLOAD_URL . '/' . $images[$i]->getVar('image_name') . '';
502
            $image_size = getimagesize(XOOPS_ROOT_PATH . '/uploads/' . $images[$i]->getVar('image_name'));
503
            $image_info = true;
504
        }
505
506
        // check if image stored in db/as file - end
507
        echo '<table width="100%" class="outer">';
508
        echo '<tr>';
509
        echo '<td rowspan="' . $rowspan . '" class="xoopsimage">';
510
511
        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;"/>';
512
        echo '<br>';
513
        if ($image_info == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
514
            echo '' . $image_size[0] . 'x' . $image_size[1] . '';
515
        }
516
        echo '</td>';
517
        echo '<td class="head">' . _IMAGENAME, '</td>';
518
        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>';
519
        echo '</tr>';
520
521
        echo '<tr>';
522
        echo '<td class="head">' . _IMAGEMIME . '</td>';
523
        echo '<td class="odd">' . $images[$i]->getVar('image_mimetype') . '</td>';
524
        echo '</tr>';
525
526
        if ($catwritelist) {
527
            echo '<tr>';
528
            echo '<td class="head">' . _IMAGECAT . '</td>';
529
            echo '<td class="even">';
530
            echo '<select name="imgcat_id[]" size="1">';
531
            $list = $imgcat_handler->getList($groups, null, null, $imagecategory->getVar('imgcat_storetype'));
532
            foreach ($list as $value => $name) {
533
                echo '<option value="' . $value . '"' . (($value == $images[$i]->getVar('imgcat_id')) ? ' selected="selected"' : '') . '>' . $name . '</option>';
534
            }
535
            echo '</select>';
536
            echo '</td>';
537
            echo '</tr>';
538
539
            echo '<tr>';
540
            echo '<td class="head">' . _IMGWEIGHT . '</td>';
541
            echo '<td class="odd"><input type="text" name="image_weight[]" value="' . $images[$i]->getVar('image_weight') . '" size="3" maxlength="4" /></td>';
542
            echo '</tr>';
543
544
            echo '<tr>';
545
            echo '<td class="head">' . _IMGDISPLAY . '</td>';
546
            echo '<td class="even">';
547
            echo '<input type="checkbox" name="image_display[]" value="1"' . (($images[$i]->getVar('image_display') == 1) ? ' checked="checked"' : '') . ' />';
548
            echo '</td>';
549
            echo '</tr>';
550
        }
551
        echo '</table>';
552
        echo '<br>';
553
    }
554
555
    if ($imgcount > 0) {
556
        if ($imgcount > 20) {
557
            include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
558
            $nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'op=listimg&amp;target=' . $target . '&amp;imgcat_id=' . $imgcat_id);
559
            echo '<div text-align="right">' . $nav->renderNav() . '</div>';
560
        }
561
        if ($catwritelist) {
562
            echo '<input type="hidden" name="op" value="save" />' . $GLOBALS['xoopsSecurity']->getTokenHTML() . '<input type="submit" name="submit" value="' . _SUBMIT . '" />';
563
            echo '</form>';
564
        }
565
    }
566
}
567
//list images - end
568
569
//edit category - start
570
if ($op === 'editcat') {
571
    if ($imgcat_id <= 0) {
572
        redirect_header($current_file . '?target=' . $target, 1);
573
    }
574
    $imgcat_handler = xoops_getHandler('imagecategory');
575
    $imagecategory  = $imgcat_handler->get($imgcat_id);
576
    if (!is_object($imagecategory)) {
577
        redirect_header($current_file . '?target=' . $target, 1);
578
    }
579
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
580
    $imagecategoryperm_handler = xoops_getHandler('groupperm');
581
    $form                      = new XoopsThemeForm(_MD_EDITIMGCAT, 'imagecat_form', '' . $current_file . '?target=' . $target . '', 'post', true);
582
    $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true);
583
    $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true));
584
    $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true));
585
    $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize')));
586
    $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth')));
587
    $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight')));
588
    $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight')));
589
    $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO));
590
    $storetype = ['db' => _MD_INDB, 'file' => _MD_ASFILE];
591
    $form->addElement(new XoopsFormLabel(_MD_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')]));
592
    $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
593
    $form->addElement(new XoopsFormHidden('op', 'updatecat'));
594
    $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
595
    echo '<a href="' . $current_file . '?target=' . $target . '">' . _MD_IMGMAIN . '</a>&nbsp;<span style="font-weight:bold;">&gt;</span>&nbsp;' . $imagecategory->getVar('imgcat_name') . '<br><br>';
596
    $form->display();
597
}
598
echo '<div class="mceActionPanel floatright" >';
599
echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
600
echo '</div>';
601
echo '</div>';
602
//edit category - end
603
604
//create Image - start
605
if ($isadmin || !empty($catwritelist)) {
606
    echo '<div id="loadimage_panel" class="panel" style="overflow:auto;">';
607
    $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', '' . $current_file . '?target=' . $target . '', 'post', true);
608
    $form->setExtra('enctype="multipart/form-data"');
609
    $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
610
    $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id');
611
    if ($isadmin) {
612
        $select->addOptionArray($imgcat_handler->getList());
613
    } else {
614
        $select->addOptionArray($catwritelist);
615
    }
616
    $form->addElement($select, true);
617
    $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
618
    $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
619
    $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
620
    $form->addElement(new XoopsFormHidden('op', 'addfile'));
621
    $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
622
    $form->display();
623
    echo '<div class="mceActionPanel floatright" >';
624
    echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
625
    echo '</div>';
626
    echo '</div>';
627
}
628
//create Image - end
629
630
//create Category - start
631
if ($isadmin) {
632
    echo '<div id="createcategory_panel" class="panel" style="overflow:auto;">';
633
    $form = new XoopsThemeForm(_MD_ADDIMGCAT, 'imagecat_form', '' . $current_file . '?target=' . $target . '', 'post', true);
634
    $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255), true);
635
    $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true));
636
    $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true));
637
    $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000));
638
    $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120));
639
    $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120));
640
    $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0));
641
    $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO));
642
    $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE . '<br><span style="color:#ff0000;">' . _MD_STRTYOPENG . '</span>', 'imgcat_storetype', 'file');
643
    $storetype->addOptionArray(['file' => _MD_ASFILE, 'db' => _MD_INDB]);
644
    $form->addElement($storetype);
645
    $form->addElement(new XoopsFormHidden('op', 'addcat'));
646
    $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
647
    $form->display();
648
    echo '<div class="mceActionPanel floatright" >';
649
    echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
650
    echo '</div>';
651
    echo '</div>';
652
}
653
//create Category - end
654
655
echo '</div>';
656
xoops_footer();
657