Passed
Pull Request — master (#193)
by Lio
05:07
created

delpicture.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * @category        Module
14
 * @copyright       {@link https://xoops.org/ XOOPS Project}
15
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
17
 */
18
19
use Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
20
use XoopsModules\Suico\{
21
    ImageHandler
22
};
23
24
require __DIR__ . '/header.php';
25
if (!$GLOBALS['xoopsSecurity']->check()) {
26
    redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED);
27
}
28
$image_id = Request::getInt('image_id', 0, 'POST');
29
if (!isset($_POST['confirm']) || 1 !== Request::getInt('confirm', 0, 'POST')) {
30
    xoops_confirm(
31
        [
32
            'image_id' => $image_id,
33
            'confirm'  => 1,
34
        ],
35
        'delpicture.php',
36
        _MD_SUICO_ASK_CONFIRM_DELETION,
37
        _MD_SUICO_CONFIRM_DELETION
38
    );
39
} else {
40
    /**
41
     * Creating the factory  and the criteria to delete the picture
42
     * The user must be the owner
43
     */
44
    $imageFactory = new ImageHandler(
45
        $xoopsDB
46
    );
47
    $criteria_img = new Criteria('image_id', $image_id);
48
    $uid          = (int)$xoopsUser->getVar('uid');
49
    $criteriaUid  = new Criteria('uid_owner', $uid);
50
    $criteria     = new CriteriaCompo($criteria_img);
51
    $criteria->add($criteriaUid);
52
    $objects_array = $imageFactory->getObjects($criteria);
53
    $image_name    = $objects_array[0]->getVar('filename');
54
    $avatar_image  = $xoopsUser->getVar('user_avatar');
55
    /**
56
     * Try to delete
57
     */
58
    if ($imageFactory->deleteAll($criteria)) {
59
        if (1 === $helper->getConfig('physical_delete')) {
60
            //unlink($xoopsModuleConfig['path_upload']."\/".$image_name);
61
//            unlink(XOOPS_ROOT_PATH . '/uploads' . '/images/suico/' . $image_name);
62
            $file = XOOPS_ROOT_PATH . '/uploads' . '/images/suico/' . $image_name;
63
            if (@\unlink($file) === false) {
64
                throw new \RuntimeException('The file ' . $file . ' could not be deleted.');
65
            }
66
67
//            unlink(XOOPS_ROOT_PATH . '/uploads' . '/images/suico/resized_' . $image_name);
68
            $file = XOOPS_ROOT_PATH . '/uploads' . '/images/suico/resized_' . $image_name;
69
            if (@\unlink($file) === false) {
70
                throw new \RuntimeException('The file ' . $file . ' could not be deleted.');
71
            }
72
73
            /**
74
             * Delete the thumb (avatar now has another name)
75
             */
76
            //if ($avatar_image!=$image_name){
77
//            unlink(XOOPS_ROOT_PATH . '/uploads' . '/images/thumb_' . $image_name);
78
            $file = XOOPS_ROOT_PATH . '/uploads' . '/images/thumb_' . $image_name;
79
            if (@\unlink($file) === false) {
80
                throw new \RuntimeException('The file ' . $file . ' could not be deleted.');
81
            }
82
            //}
83
        }
84
        redirect_header('album.php', 2, _MD_SUICO_DELETED);
85
    } else {
86
        redirect_header('album.php', 2, _MD_SUICO_ERROR);
87
    }
88
}
89
require \dirname(__DIR__, 2) . '/footer.php';
90