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

hook-photo.php (2 issues)

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 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
 * @version     $Id: hook-photo.php 8088 2011-11-06 09:38:12Z beckmi $
17
 */
18
19
include __DIR__ . '/header.php';
20
include_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php';
21
22 View Code Duplication
if (!isset($_GET['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...
23
    $photoId = 0;
24
} else {
25
    $photoId = (int)$_GET['id'];
26
}
27
28
$photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
29
$photoHandler->updateHits($photoId);
30
$photo = $photoHandler->get($photoId);
31
32 View Code Duplication
switch (strtolower(strrchr($photo->getVar('photo_name'), '.'))) {
33
    case '.png':
34
        $type = 'image/png';
35
        break;
36
    case '.gif':
37
        $type = 'image/gif';
38
        break;
39
    case '.jpg':
40
        $type = 'image/jpeg';
41
        break;
42
    default:
43
        $type = 'application/octet-stream';
44
        break;
45
}
46
47
$permHandler = ExtgalleryPublicPermHandler::getInstance();
48
49
// If require image don't exist
50 View Code Duplication
if ($photo->getVar('cat_id') == 0) {
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...
51
    header('Content-type: image/jpeg');
52
    readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/dont-exist.jpg');
53
54
    // If user is allowed to view this picture
55
} elseif ($permHandler->isAllowed($xoopsUser, 'public_access', $photo->getVar('cat_id'))) {
56
    $photo = $photoHandler->objectToArray($photo);
57
    header('Content-type: ' . $type . '');
58
    readfile(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $photo['photo_name']);
59
60
    // If user isn't allowed to view this picture
61
} else {
62
    header('Content-type: image/jpeg');
63
    readfile(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/not-allowed.jpg');
64
}
65