Passed
Push — master ( 8d8e58...047d50 )
by Michael
02:21
created

hook-photo.php (1 issue)

Labels
Severity
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
 * @version     $Id: hook-photo.php 8088 2011-11-06 09:38:12Z beckmi $
17
 */
18
19
20
use XoopsModules\Extgallery;
21
22
include __DIR__ . '/header.php';
23
include_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php';
0 ignored issues
show
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
24
25
if (!isset($_GET['id'])) {
26
    $photoId = 0;
27
} else {
28
    $photoId = (int)$_GET['id'];
29
}
30
31
$photoHandler = Extgallery\Helper::getInstance()->getHandler('PublicPhoto');
32
$photoHandler->updateHits($photoId);
33
$photo = $photoHandler->get($photoId);
34
35
switch (strtolower(strrchr($photo->getVar('photo_name'), '.'))) {
36
    case '.png':
37
        $type = 'image/png';
38
        break;
39
    case '.gif':
40
        $type = 'image/gif';
41
        break;
42
    case '.jpg':
43
        $type = 'image/jpeg';
44
        break;
45
    default:
46
        $type = 'application/octet-stream';
47
        break;
48
}
49
50
$permHandler = Extgallery\PublicPermHandler::getInstance();
51
52
// If require image don't exist
53
if (0 == $photo->getVar('cat_id')) {
54
    header('Content-type: image/jpeg');
55
    readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/dont-exist.jpg');
56
57
    // If user is allowed to view this picture
58
} elseif ($permHandler->isAllowed($xoopsUser, 'public_access', $photo->getVar('cat_id'))) {
59
    $photo = $photoHandler->objectToArray($photo);
60
    header('Content-type: ' . $type . '');
61
    readfile(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo['photo_name']);
62
63
    // If user isn't allowed to view this picture
64
} else {
65
    header('Content-type: image/jpeg');
66
    readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/not-allowed.jpg');
67
}
68