Completed
Push — master ( ce95ba...616741 )
by Michael
02:29
created

delpicture.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
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
use Xmf\Request;
24
25
$moduleDirName = basename(dirname(__DIR__));
26
$main_lang     = '_' . strtoupper($moduleDirName);
27
28
/**
29
 * Xoops Header
30
 */
31
include dirname(dirname(__DIR__)) . '/mainfile.php';
32
include_once XOOPS_ROOT_PATH . '/header.php';
33
include_once XOOPS_ROOT_PATH . '/class/criteria.php';
34
35
/**
36
 * Module classes
37
 */
38
39
include __DIR__ . '/class/pictures.php';
40
41
/**
42
 * Check if using XoopsCube (by jlm69)
43
 * Needed because of a difference in the way Xoops and XoopsCube handle tokens
44
 */
45
46
$xCube = false;
47
if (preg_match('/^XOOPS Cube/', XOOPS_VERSION)) { // XOOPS Cube 2.1x
48
    $xCube = true;
49
}
50
/**
51
 * Verify Ticket for Xoops Cube (by jlm69)
52
 * If your site is XoopsCube it uses $xoopsGTicket for the token.
53
 */
54
55 View Code Duplication
if ($xCube) {
56
    if (!$xoopsGTicket->check(true, 'token')) {
57
        redirect_header($_SERVER['HTTP_REFERER'], 3, $xoopsGTicket->getErrors());
58
    }
59
} else {
60
    /**
61
     * Verify TOKEN for Xoops
62
     * If your site is Xoops it uses xoopsSecurity for the token.
63
     */
64
    if (!$GLOBALS['xoopsSecurity']->check()) {
65
        redirect_header($_SERVER['HTTP_REFERER'], 3, constant('_ADSLIGHT_TOKENEXPIRED'));
66
    }
67
}
68
69
/**
70
 * Receiving info from get parameters
71
 */
72
$cod_img = Request::getString('cod_img', '', 'POST');
73
74
/**
75
 * Creating the factory  and the criteria to delete the picture
76
 * The user must be the owner
77
 */
78
$album_factory = new JlmPicturesHandler($xoopsDB);
79
$criteria_img  = new Criteria('cod_img', $cod_img);
80
$uid           = $GLOBALS['xoopsUser']->getVar('uid');
81
$criteria_uid  = new Criteria('uid_owner', $uid);
82
//$criteria_lid = new Criteria ('lid',$lid);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
83
$criteria = new CriteriaCompo($criteria_img);
84
$criteria->add($criteria_uid);
85
86
$objects_array =& $album_factory->getObjects($criteria);
87
$image_name    = $objects_array[0]->getVar('url');
88
/**
89
 * Try to delete
90
 */
91
if ($album_factory->deleteAll($criteria)) {
92
    $path_upload = $GLOBALS['xoopsModuleConfig']['adslight_path_upload'];
93
94
    unlink("$path_upload/$image_name");
95
96
    unlink("$path_upload/thumbs/thumb_$image_name");
97
98
    unlink("$path_upload/midsize/resized_$image_name");
99
100
    $lid =  Request::getInt('lid', 0, 'POST');
101
102
    $xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('adslight_listing') . " SET photo=photo-1 WHERE lid='$lid'");
103
104
    redirect_header('view_photos.php?lid=' . $lid . '&uid=' . $uid . '', 13, constant('_ADSLIGHT_DELETED'));
105 View Code Duplication
} else {
106
    redirect_header('view_photos.php?lid=' . $lid . '&uid=' . $uid . '', 13, constant('_ADSLIGHT_NOCACHACA'));
107
}
108
109
/**
110
 * Close page
111
 */
112
include_once XOOPS_ROOT_PATH . '/footer.php';
113