Completed
Push — master ( a25b3b...67bb37 )
by Michael
02:44
created

editdesc.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
-------------------------------------------------------------------------
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
$moduleDirName = basename(dirname(__DIR__));
24
$main_lang     = '_' . strtoupper($moduleDirName);
25
26
/**
27
 * Xoops Header
28
 */
29
include dirname(dirname(__DIR__)) . '/mainfile.php';
30
include_once XOOPS_ROOT_PATH . '/header.php';
31
include_once XOOPS_ROOT_PATH . '/class/criteria.php';
32
33
/**
34
 * Include modules classes
35
 */
36
include_once __DIR__ . '/class/pictures.php';
37
38
/**
39
 * Check if using XoopsCube (by jlm69)
40
 * Needed because of a difference in the way Xoops and XoopsCube handle tokens
41
 */
42
43
$xCube = false;
44
if (preg_match('/^XOOPS Cube/', XOOPS_VERSION)) { // XOOPS Cube 2.1x
45
    $xCube = true;
46
}
47
48
/**
49
 * Verify Ticket for Xoops Cube (by jlm69)
50
 * If your site is XoopsCube it uses $xoopsGTicket for the token.
51
 */
52
53 View Code Duplication
if ($xCube) {
1 ignored issue
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...
54
    if (!$xoopsGTicket->check(true, 'token')) {
55
        redirect_header($_SERVER['HTTP_REFERER'], 3, $xoopsGTicket->getErrors());
56
    }
57
} else {
58
    /**
59
     * Verify TOKEN for Xoops
60
     * If your site is Xoops it uses xoopsSecurity for the token.
61
     */
62
    if (!$GLOBALS['xoopsSecurity']->check()) {
63
        redirect_header($_SERVER['HTTP_REFERER'], 3, constant('_ADSLIGHT_TOKENEXPIRED'));
64
    }
65
}
66
67
/**
68
 * Receiving info from get parameters
69
 */
70
$cod_img = XoopsRequest::getString('cod_img', '', 'POST');
71
//$lid = $_POST['lid'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
72
//$marker = $_POST['marker'];
73
$marker = XoopsRequest::getInt('marker', '', 'POST');
74
75
if ($marker == 1) {
76
    /**
77
     * Creating the factory  loading the picture changing its caption
78
     */
79
    $picture_factory = new Xoopsjlm_picturesHandler($xoopsDB);
80
    $picture         = $picture_factory->create(false);
81
    $picture->load(XoopsRequest::getString('cod_img', '', 'POST'));
82
    $picture->setVar('title', XoopsRequest::getString('caption', '', 'POST'));
83
84
    /**
85
     * Verifying who's the owner to allow changes
86
     */
87
    $uid = $GLOBALS['xoopsUser']->getVar('uid');
88
    $lid = $picture->getVar('lid');
89
    if ($uid == $picture->getVar('uid_owner')) {
90
        if ($picture_factory->insert($picture)) {
91
            redirect_header('view_photos.php?lid=' . $lid . '&uid=' . $uid . '', 2, constant('_ADSLIGHT_DESC_EDITED'));
92 View Code Duplication
        } else {
1 ignored issue
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...
93
            redirect_header('view_photos.php?lid=' . $lid . '&uid=' . $uid . '', 2, constant('_ADSLIGHT_NOCACHACA'));
94
        }
95
    }
96
}
97
98
/**
99
 * Creating the factory  and the criteria to edit the desc of the picture
100
 * The user must be the owner
101
 */
102
$album_factory = new Xoopsjlm_picturesHandler($xoopsDB);
103
$criteria_img  = new Criteria('cod_img', $cod_img);
104
$uid           = $GLOBALS['xoopsUser']->getVar('uid');
105
$criteria_uid  = new Criteria('uid_owner', $uid);
106
$criteria      = new CriteriaCompo($criteria_img);
107
$criteria->add($criteria_uid);
108
109
/**
110
 * Lets fetch the info of the pictures to be able to render the form
111
 * The user must be the owner
112
 */
113
if ($array_pict =& $album_factory->getObjects($criteria)) {
114
    $caption = $array_pict[0]->getVar('title');
115
    $url     = $array_pict[0]->getVar('url');
116
}
117
$url = $GLOBALS['xoopsModuleConfig']['adslight_link_upload'] . '/thumbs/thumb_' . $url;
118
$album_factory->renderFormEdit($caption, $cod_img, $url);
119
120
/**
121
 * Close page
122
 */
123
include XOOPS_ROOT_PATH . '/footer.php';
124