Completed
Push — master ( a62cdb...8d8e58 )
by Michael
12s
created

hook-thumb.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ExtGallery User area
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
include __DIR__ . '/header.php';
19
require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php';
20
21
if (!isset($_GET['id'])) {
22
    $photoId = 0;
23
} else {
24
    $photoId = (int)$_GET['id'];
25
}
26
/** @var ExtgalleryPublicPhotoHandler $photoHandler */
27
$photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
28
$photo        = $photoHandler->get($photoId);
29
30
switch (strtolower(strrchr($photo->getVar('photo_name'), '.'))) {
31
    case '.png':
32
        $type = 'image/png';
33
        break;
34
    case '.gif':
35
        $type = 'image/gif';
36
        break;
37
    case '.jpg':
38
        $type = 'image/jpeg';
39
        break;
40
    default:
41
        $type = 'application/octet-stream';
42
        break;
43
}
44
45
$permHandler = ExtgalleryPublicPermHandler::getInstance();
46
47
// If require image don't exist
48 View Code Duplication
if (0 == $photo->getVar('cat_id')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    header('Content-type: image/jpeg');
50
    readfile(__DIR__ . '/assets/images/dont-exist.jpg');
51
52
    // If user is allowed to view this picture
53
} elseif ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_access', $photo->getVar('cat_id'))) {
54
    $photo = $photoHandler->objectToArray($photo);
55
56
    header('Content - type: ' . $type . '');
57
    readfile(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo['photo_name']);
58
59
    // If user isn't allowed to view this picture
60
} else {
61
    header('Content-type: image/jpeg');
62
    readfile(__DIR__ . '/assets/images/not-allowed.jpg');
63
}
64