Completed
Push — master ( d1dabc...72613d )
by Michael
25s
created

public-download.php (3 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 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 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...
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
$permHandler = ExtgalleryPublicPermHandler::getInstance();
31
if (!$permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download', $photo->getVar('cat_id'))) {
32
    redirect_header('index.php');
33
}
34
35 View Code Duplication
switch (strtolower(strrchr($photo->getVar('photo_name'), '.'))) {
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...
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
    case '.jpeg':
46
        $type = 'image/jpeg';
47
        break;
48
    default:
49
        $type = 'application/octet-stream';
50
        break;
51
}
52
53
header('Content-Type: ' . $type . '');
54
header('Content-Disposition: attachment; filename="' . $photo->getVar('photo_name') . '"');
55
56
//if ($photo->getVar('photo_havelarge')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
//    if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download_original', $photo->getVar('cat_id')) && $photo->getVar('photo_orig_name') != "") {
58
//        $photoName = "original/".$photo->getVar('photo_orig_name');
59
//    } else {
60
//        $photoName = "large/large_".$photo->getVar('photo_name');
61
//    }
62
//} else {
63
//    $photoName = "medium/".$photo->getVar('photo_name');
64
//}
65
66
if ($permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_download_original', $photo->getVar('cat_id'))
67
    && $photo->getVar('photo_orig_name') != '') {
68
    $photoName = 'original/' . $photo->getVar('photo_orig_name');
69
} else {
70
    if ($photo->getVar('photo_havelarge')) {
71
        $photoName = 'large/large_' . $photo->getVar('photo_name');
72
    } else {
73
        $photoName = 'medium/' . $photo->getVar('photo_name');
74
    }
75
}
76
77
$photoHandler->updateDownload($photoId);
78
79
if ($photo->getVar('photo_serveur') == '') {
80
    readfile(XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/' . $photoName);
81
} else {
82
    readfile($photo->getVar('photo_serveur') . $photoName);
83
}
84