Issues (411)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

submit.php (6 issues)

1
<?php
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
 * Wfdownloads module
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package         wfdownload
18
 * @since           3.23
19
 * @author          Xoops Development Team
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Wfdownloads\{
24
    Common,
25
    Helper,
26
    Utility,
27
    MediaImgUploader
28
};
29
/** @var Helper $helper */
30
/** @var Utility $utility */
31
32
$currentFile = basename(__FILE__);
33
require_once __DIR__ . '/header.php';
34
35
// Check if submissions are allowed
36
$isSubmissionAllowed = false;
37
if (is_object($GLOBALS['xoopsUser'])
38
    && (_WFDOWNLOADS_SUBMISSIONS_DOWNLOAD == $helper->getConfig('submissions')
39
        || _WFDOWNLOADS_SUBMISSIONS_BOTH == $helper->getConfig('submissions'))) {
40
    // if user is a registered user
41
    $groups = $GLOBALS['xoopsUser']->getGroups();
42
    if (count(array_intersect($helper->getConfig('submitarts'), $groups)) > 0) {
43
        $isSubmissionAllowed = true;
44
    }
45
} else {
46
    // if user is ANONYMOUS
47
    if (!is_object($GLOBALS['xoopsUser'])
48
        && (_WFDOWNLOADS_ANONPOST_DOWNLOAD == $helper->getConfig('anonpost')
49
            || _WFDOWNLOADS_ANONPOST_BOTH == $helper->getConfig('anonpost'))) {
50
        $isSubmissionAllowed = true;
51
    } else {
52
        redirect_header(XOOPS_URL . '/user.php', 5, _MD_WFDOWNLOADS_MUSTREGFIRST);
53
    }
54
}
55
// Get categories where user can submit
56
$categoryObjs = $helper->getHandler('Category')->getUserUpCategories();
57
if (0 == count($categoryObjs)) {
58
    $isSubmissionAllowed = false;
59
}
60
if (false === $isSubmissionAllowed) {
61
    redirect_header('index.php', 5, _MD_WFDOWNLOADS_NOTALLOWESTOSUBMIT);
62
}
63
// Check posts if user is not an ADMIN
64
if (is_object($GLOBALS['xoopsUser']) && !$GLOBALS['xoopsUser']->isAdmin()) {
65
    if ($GLOBALS['xoopsUser']->getVar('posts') < $helper->getConfig('upload_minposts')) {
66
        redirect_header('index.php', 5, _MD_WFDOWNLOADS_UPLOADMINPOSTS);
67
    }
68
}
69
70
$lid    = Request::getInt('lid', 0);
71
$cid    = Request::getInt('cid', 0);
72
$agreed = Request::getBool('agreed', false, 'POST');
73
$op     = Request::getString('op', 'download.form');
74
$notify = Request::getBool('notify', false);
75
76
if ($helper->getConfig('showdisclaimer') && ('download.form' === $op) && false === $agreed) {
77
    $op = 'download.disclaimer';
78
}
79
80
switch ($op) {
81
    case 'download.disclaimer':
82
        // Show disclaimers
83
        $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_disclaimer.tpl";
84
        require_once XOOPS_ROOT_PATH . '/header.php';
85
86
        $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
87
        $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js');
0 ignored issues
show
The constant WFDOWNLOADS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
88
        $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css');
89
        $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css');
90
91
        $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/');
92
93
        $catarray['imageheader'] = Utility::headerImage();
94
        $xoopsTpl->assign('catarray', $catarray);
95
96
        // Breadcrumb
97
        $breadcrumb = new Common\Breadcrumb();
98
        $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL);
99
        $breadcrumb->addLink(_MD_WFDOWNLOADS_SUBMITDOWNLOAD, '');
100
        $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render());
101
102
        $xoopsTpl->assign('lid', $lid);
103
        $xoopsTpl->assign('cid', $cid);
104
105
        $xoopsTpl->assign('image_header', Utility::headerImage());
106
107
        $xoopsTpl->assign('submission_disclaimer', true);
108
        $xoopsTpl->assign('download_disclaimer', false);
109
        $xoopsTpl->assign('submission_disclaimer_content', $myts->displayTarea($helper->getConfig('disclaimer'), true, true, true, true, true));
110
111
        $xoopsTpl->assign('down_disclaimer', false); // this definition is not removed for backward compatibility issues
112
        $xoopsTpl->assign('disclaimer', $myts->displayTarea($helper->getConfig('disclaimer'), true, true, true, true, true)); // this definition is not removed for backward compatibility issues
113
        $xoopsTpl->assign('cancel_location', WFDOWNLOADS_URL . '/index.php'); // this definition is not removed for backward compatibility issues
114
        if (!isset($_REQUEST['lid'])) {
115
            $xoopsTpl->assign('agree_location', WFDOWNLOADS_URL . "/{$currentFile}?agreed=1");
116
        } else {
117
            $lid = Request::getInt('lid');
118
            $xoopsTpl->assign('agree_location', WFDOWNLOADS_URL . "/{$currentFile}?agreed=1&amp;lid={$lid}");
119
        }
120
121
        $xoopsTpl->assign('categoryPath', _MD_WFDOWNLOADS_DISCLAIMERAGREEMENT);
122
        $xoopsTpl->assign('module_home', Utility::moduleHome(true));
123
124
        require_once __DIR__ . '/footer.php';
125
        exit();
126
        break;
127
    case 'download.form':
128
    case 'download.edit':
129
    case 'download.add':
130
        // Show submit form
131
        if ((0 != $lid) && is_object($GLOBALS['xoopsUser'])) {
132
            $downloadObj = $helper->getHandler('Download')->get($lid);
133
            if ($GLOBALS['xoopsUser']->uid() != $downloadObj->getVar('submitter')) {
134
                redirect_header('index.php', 5, _MD_WFDOWNLOADS_NOTALLOWEDTOMOD);
135
            }
136
            $cid = $downloadObj->getVar('cid');
137
        } else {
138
            $downloadObj = $helper->getHandler('Download')->create();
139
            $downloadObj->setVar('cid', $cid);
140
        }
141
        // Formulize module support - jpc - start
142
        if (Request::hasVar('submit_category', 'POST') && !empty($_POST['submit_category'])) {
143
            // two steps form: 2nd step
144
            $categoryObj = $helper->getHandler('Category')->get($cid);
145
            $fid         = $categoryObj->getVar('formulize_fid');
146
            $customArray = [];
147
            if (Utility::checkModule('formulize') && $fid) {
148
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/formdisplay.php';
149
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php';
150
                $customArray['fid']           = $fid;
151
                $customArray['formulize_mgr'] = $helper->getHandler('Elements', 'formulize');
152
                $customArray['groups']        = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
153
                $customArray['prevEntry']     = getEntryValues(// is a Formulize function
0 ignored issues
show
The function getEntryValues was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

153
                $customArray['prevEntry']     = /** @scrutinizer ignore-call */ getEntryValues(// is a Formulize function
Loading history...
154
                    $downloadObj->getVar('formulize_idreq'),
155
                    $customArray['formulize_mgr'],
156
                    $customArray['groups'],
157
                    $fid,
158
                    null,
159
                    null,
160
                    null,
161
                    null,
162
                    null
163
                );
164
                $customArray['entry']         = $downloadObj->getVar('formulize_idreq');
165
                $customArray['go_back']       = '';
166
                $customArray['parentLinks']   = '';
167
                if (Utility::checkModule('formulize') < 300) {
168
                    $owner = getEntryOwner($customArray['entry']); // is a Formulize function
0 ignored issues
show
The function getEntryOwner was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

168
                    $owner = /** @scrutinizer ignore-call */ getEntryOwner($customArray['entry']); // is a Formulize function
Loading history...
169
                } else {
170
                    $owner = getEntryOwner($customArray['entry'], $fid); // is a Formulize function
171
                }
172
                $owner_groups                = $memberHandler->getGroupsByUser($owner, false);
173
                $customArray['owner_groups'] = $owner_groups;
174
            }
175
            $sform = $downloadObj->getForm($customArray);
176
        } elseif (Utility::checkModule('formulize')) {
177
            // two steps form: 1st step
178
            $sform = $downloadObj->getCategoryForm(_MD_WFDOWNLOADS_FFS_SUBMIT1ST_STEP);
179
        } else {
180
            // one step form: 1st step
181
            $sform = $downloadObj->getForm();
182
        }
183
        // Formulize module support - jpc - end
184
        $GLOBALS['xoopsOption']['template_main'] = "{$helper->getModule()->dirname()}_submit.tpl";
185
        require_once XOOPS_ROOT_PATH . '/header.php';
186
187
        $xoTheme->addScript(XOOPS_URL . '/browse.php?Frameworks/jquery/jquery.js');
188
        $xoTheme->addScript(WFDOWNLOADS_URL . '/assets/js/magnific/jquery.magnific-popup.min.js');
189
        $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/js/magnific/magnific-popup.css');
190
        $xoTheme->addStylesheet(WFDOWNLOADS_URL . '/assets/css/module.css');
191
192
        $xoopsTpl->assign('wfdownloads_url', WFDOWNLOADS_URL . '/');
193
194
        $catarray['imageheader'] = Utility::headerImage();
195
196
        // Breadcrumb
197
        $breadcrumb = new Common\Breadcrumb();
198
        $breadcrumb->addLink($helper->getModule()->getVar('name'), WFDOWNLOADS_URL);
199
        $breadcrumb->addLink(_MD_WFDOWNLOADS_SUBMITDOWNLOAD, '');
200
        $xoopsTpl->assign('wfdownloads_breadcrumb', $breadcrumb->render());
201
202
        $xoopsTpl->assign('catarray', $catarray);
203
        $xoopsTpl->assign('categoryPath', _MD_WFDOWNLOADS_SUBMITDOWNLOAD);
204
        $xoopsTpl->assign('module_home', Utility::moduleHome(true));
205
        $xoopsTpl->assign('submit_form', $sform->render());
206
207
        require_once __DIR__ . '/footer.php';
208
        exit();
209
        break;
210
    case 'download.save':
211
        // Save submitted download
212
        if (empty($_FILES['userfile']['name'])) {
213
            if ($_POST['url'] && '' != $_POST['url'] && 'http://' !== $_POST['url']) {
214
                $url      = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
215
                $filename = '';
216
                $filetype = '';
217
            } else {
218
                $url      = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
219
                $filename = $_POST['filename'];
220
                $filetype = $_POST['filetype'];
221
            }
222
            $size  = empty($_POST['size']) || !is_numeric($_POST['size']) ? 0 : Request::getInt('size', 0, 'POST');
223
            $title = trim($_POST['title']);
224
        } else {
225
            $isAdmin  = Utility::userIsAdmin();
226
            $down     = Utility::uploading($_FILES, $helper->getConfig('uploaddir'), '', $currentFile, 0, false, $isAdmin);
0 ignored issues
show
'' of type string is incompatible with the type array expected by parameter $allowedMimetypes of XoopsModules\Wfdownloads\Utility::uploading(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

226
            $down     = Utility::uploading($_FILES, $helper->getConfig('uploaddir'), /** @scrutinizer ignore-type */ '', $currentFile, 0, false, $isAdmin);
Loading history...
227
            $url      = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
228
            $size     = $down['size'];
229
            $filename = $down['filename'];
230
            $filetype = $_FILES['userfile']['type'];
231
            $title    = $_FILES['userfile']['name'];
232
            $title    = rtrim(Utility::strrrchr($title, '.'), '.');
233
            $title    = (isset($_POST['title_checkbox']) && 1 == $_POST['title_checkbox']) ? $title : trim($_POST['title']);
234
        }
235
236
        // Load screenshot
237
        $allowedMimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
238
        $uploadDirectory  = XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots') . '/';
239
240
        $screenshots = [];
241
242
        // Load screenshot #1
243
        $screenshot1 = '';
244
        if (isset($_FILES['screenshot']['name']) && !empty($_FILES['screenshot']['name'])) {
245
            $screenshot1 = mb_strtolower($_FILES['screenshot']['name']);
246
            $uploader    = new MediaImgUploader($uploadDirectory, $allowedMimetypes, $helper->getConfig('maxfilesize'), $helper->getConfig('maximgwidth'), $helper->getConfig('maximgheight'));
247
            if (!$uploader->fetchMedia($_POST['xoops_upload_file'][1]) && !$uploader->upload()) {
248
                if (false === @unlink($uploadDirectory . $screenshot1)) {
249
                    throw new RuntimeException('The file ' . $uploadDirectory . $screenshot1 . ' could not be uploaded.');
250
                }
251
                redirect_header($currentFile, 1, $uploader->getErrors());
252
            }
253
        }
254
        $screenshots[] = $screenshot1;
255
        // Load screenshot #2
256
        $screenshot2 = '';
257
        if ($helper->getConfig('max_screenshot') >= 2) {
258
            if (isset($_FILES['screenshot2']['name']) && !empty($_FILES['screenshot2']['name'])) {
259
                $screenshot2 = mb_strtolower($_FILES['screenshot2']['name']);
260
                $uploader    = new MediaImgUploader($uploadDirectory, $allowedMimetypes, $helper->getConfig('maxfilesize'), $helper->getConfig('maximgwidth'), $helper->getConfig('maximgheight'));
261
                if (!$uploader->fetchMedia($_POST['xoops_upload_file'][2]) && !$uploader->upload()) {
262
                    @unlink($uploadDirectory . $screenshot2);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

262
                    /** @scrutinizer ignore-unhandled */ @unlink($uploadDirectory . $screenshot2);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
263
                    redirect_header($currentFile, 1, $uploader->getErrors());
264
                }
265
            }
266
        }
267
        $screenshots[] = $screenshot2;
268
        // Load screenshot #3
269
        $screenshot3 = '';
270
        if ($helper->getConfig('max_screenshot') >= 3) {
271
            if (isset($_FILES['screenshot3']['name']) && !empty($_FILES['screenshot3']['name'])) {
272
                $screenshot3 = mb_strtolower($_FILES['screenshot3']['name']);
273
                $uploader    = new MediaImgUploader($uploadDirectory, $allowedMimetypes, $helper->getConfig('maxfilesize'), $helper->getConfig('maximgwidth'), $helper->getConfig('maximgheight'));
274
                if (!$uploader->fetchMedia($_POST['xoops_upload_file'][3]) && !$uploader->upload()) {
275
                    @unlink($uploadDirectory . $screenshot3);
276
                    redirect_header($currentFile, 1, $uploader->getErrors());
277
                }
278
            }
279
        }
280
        $screenshots[] = $screenshot3;
281
        // Load screenshot #4
282
        $screenshot4 = '';
283
        if ($helper->getConfig('max_screenshot') >= 4) {
284
            if (isset($_FILES['screenshot4']['name']) && !empty($_FILES['screenshot4']['name'])) {
285
                $screenshot4 = mb_strtolower($_FILES['screenshot4']['name']);
286
                $uploader    = new MediaImgUploader($uploadDirectory, $allowedMimetypes, $helper->getConfig('maxfilesize'), $helper->getConfig('maximgwidth'), $helper->getConfig('maximgheight'));
287
                if (!$uploader->fetchMedia($_POST['xoops_upload_file'][4]) && !$uploader->upload()) {
288
                    @unlink($uploadDirectory . $screenshot4);
289
                    redirect_header($currentFile, 1, $uploader->getErrors());
290
                }
291
            }
292
        }
293
        $screenshots[] = $screenshot4;
294
295
        if ($lid > 0) {
296
            $isANewRecord = false;
297
            if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove')
298
                || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
299
                $downloadObj = $helper->getHandler('Download')->get($lid);
300
            } else {
301
                $downloadObj = $helper->getHandler('Modification')->create();
302
                $downloadObj->setVar('lid', $lid);
303
            }
304
        } else {
305
            $isANewRecord = true;
306
            $downloadObj  = $helper->getHandler('Download')->create();
307
            if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove')
308
                || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
309
                $downloadObj->setVar('published', time());
310
                $downloadObj->setVar('status', _WFDOWNLOADS_STATUS_APPROVED);
311
            } else {
312
                $downloadObj->setVar('published', false);
313
                $downloadObj->setVar('status', _WFDOWNLOADS_STATUS_WAITING);
314
            }
315
        }
316
317
        // Formulize module support (2006/05/04) jpc - start
318
        if (Utility::checkModule('formulize')) {
319
            // Now that the $downloadObj object has been instantiated, handle the Formulize part of the submission...
320
            $categoryObj = $helper->getHandler('Category')->get($cid);
321
            $fid         = $categoryObj->getVar('formulize_fid');
322
            if ($fid) {
323
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/formread.php';
324
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php';
325
                $formulizeElementsHandler = $helper->getHandler('Elements', 'formulize');
326
                if ($lid) {
327
                    $entries[$fid][0] = $downloadObj->getVar('formulize_idreq');
328
                    if ($entries[$fid][0]) {
329
                        if (Utility::checkModule('formulize') < 300) {
330
                            $owner = getEntryOwner($entries[$fid][0]); // is a Formulize function
331
                        } else {
332
                            $owner = getEntryOwner($entries[$fid][0], $fid); // is a Formulize function
333
                        }
334
                    } else {
335
                        $entries[$fid][0] = '';
336
                        $owner            = '';
337
                    }
338
                    $cid = $downloadObj->getVar('cid');
339
                } else {
340
                    $entries[$fid][0] = '';
341
                    $owner            = '';
342
                }
343
                $owner_groups = $memberHandler->getGroupsByUser($owner, false);
344
                $uid          = is_object($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0;
345
                $groups       = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
346
                $entries      = handleSubmission(// is a Formulize function
0 ignored issues
show
The function handleSubmission was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

346
                $entries      = /** @scrutinizer ignore-call */ handleSubmission(// is a Formulize function
Loading history...
347
                    $formulizeElementsHandler,
348
                    $entries,
349
                    $uid,
350
                    $owner,
351
                    $fid,
352
                    $owner_groups,
353
                    $groups,
354
                    'new'
355
                ); // 'new' causes xoops token check to be skipped, since Wfdownloads should be doing that
356
                if (!$owner) {
357
                    $id_req = $entries[$fid][0];
358
                    $downloadObj->setVar('formulize_idreq', $id_req);
359
                }
360
            }
361
        }
362
        // Formulize module support (2006/05/04) jpc - end
363
364
        if (!empty($_POST['homepage']) || 'http://' !== $_POST['homepage']) {
365
            $downloadObj->setVar('homepage', formatURL(trim($_POST['homepage'])));
366
            $downloadObj->setVar('homepagetitle', trim($_POST['homepagetitle']));
367
        }
368
        $downloadObj->setVar('title', $title);
369
        $downloadObj->setVar('url', $url);
370
        $downloadObj->setVar('cid', (int)$cid);
371
        $downloadObj->setVar('filename', $filename);
372
        $downloadObj->setVar('filetype', $filetype);
373
374
        /* Added by Lankford on 2007/3/21 */
375
        // Here, I want to know if:
376
        //    a) Are they actually changing the value of version, or is it the same?
377
        //    b) Are they actually modifying the record, or is this a new one?
378
        //  If both conditions are true, then trigger all three notifications related to modified records.
379
        $version = !empty($_POST['version']) ? trim($_POST['version']) : 0;
380
381
        if (!$isANewRecord && ($downloadObj->getVar('version') != $version)) {
382
            // Trigger the three events related to modified files (one for the file, category, and global event categories respectively)
383
            $tags                  = [];
384
            $tags['FILE_NAME']     = $title;
385
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$lid}";
386
            $categoryObj           = $helper->getHandler('Category')->get($cid);
387
            $tags['FILE_VERSION']  = $version;
388
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
389
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
390
391
            if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove') || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
392
                // Then this change will be automatically approved, so the notification needs to go out.
393
                $notificationHandler->triggerEvent('global', 0, 'filemodified', $tags);
394
                $notificationHandler->triggerEvent('category', $cid, 'filemodified', $tags);
395
                $notificationHandler->triggerEvent('file', $lid, 'filemodified', $tags);
396
            }
397
        }
398
        /* End add block */
399
400
        $downloadObj->setVar('version', $_POST['version']);
401
        $downloadObj->setVar('size', $size);
402
        $downloadObj->setVar('platform', $_POST['platform']);
403
        $downloadObj->setVar('screenshot', $screenshots[0]); // old style
404
        $downloadObj->setVar('screenshot2', $screenshots[1]); // old style
405
        $downloadObj->setVar('screenshot3', $screenshots[2]); // old style
406
        $downloadObj->setVar('screenshot4', $screenshots[3]); // old style
407
        $downloadObj->setVar('screenshots', $screenshots); // new style
408
        $downloadObj->setVar('summary', $_POST['summary']);
409
        $downloadObj->setVar('description', $_POST['description']);
410
        $downloadObj->setVar('dohtml', isset($_POST['dohtml']));
411
        $downloadObj->setVar('dosmiley', isset($_POST['dosmiley']));
412
        $downloadObj->setVar('doxcode', isset($_POST['doxcode']));
413
        $downloadObj->setVar('doimage', isset($_POST['doimage']));
414
        $downloadObj->setVar('dobr', isset($_POST['dobr']));
415
        $submitter = is_object($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->getVar('uid') : 0;
416
        $downloadObj->setVar('submitter', $submitter);
417
        $downloadObj->setVar('publisher', trim($_POST['publisher']));
418
        $downloadObj->setVar('price', trim($_POST['price']));
419
        $downloadObj->setVar('mirror', isset($_POST['mirror']) ? trim($_POST['mirror']) : '');
420
        $downloadObj->setVar('license', trim($_POST['license']));
421
        $paypalEmail = '';
422
        $downloadObj->setVar('features', trim($_POST['features']));
423
        $downloadObj->setVar('requirements', trim($_POST['requirements']));
424
        $forumid = (isset($_POST['forumid']) && $_POST['forumid'] > 0) ? Request::getInt('forumid', 0, 'POST') : 0;
425
        $downloadObj->setVar('forumid', $forumid);
426
        $limitations = isset($_POST['limitations']) ? $myts->addSlashes($_POST['limitations']) : '';
427
        $downloadObj->setVar('limitations', $limitations);
428
        $versiontypes = isset($_POST['versiontypes']) ? $myts->addSlashes($_POST['versiontypes']) : '';
429
        $downloadObj->setVar('versiontypes', $versiontypes);
430
        $dhistory        = isset($_POST['dhistory']) ? $myts->addSlashes($_POST['dhistory']) : '';
431
        $dhistoryhistory = isset($_POST['dhistoryaddedd']) ? $myts->addSlashes($_POST['dhistoryaddedd']) : '';
432
        if ($lid > 0 && !empty($dhistoryhistory)) {
433
            $dhistory .= "\n\n";
434
            $dhistory .= '<b>' . formatTimestamp(time(), $helper->getConfig('dateformat')) . "</b>\n\n";
435
            $dhistory .= $dhistoryhistory;
436
        }
437
        $downloadObj->setVar('dhistory', $dhistory);
438
        $offline = (isset($_POST['offline']) && 1 == $_POST['offline']);
439
        $downloadObj->setVar('offline', $offline);
440
        $downloadObj->setVar('date', time());
441
        /*
442
                $screenshot1 = '';
443
                $screenshot2 = '';
444
                $screenshot3 = '';
445
                $screenshot4 = '';
446
        */
447
        if (0 == $lid) {
448
            $notifypub = (isset($_POST['notifypub']) && true === $_POST['notifypub']);
449
            $downloadObj->setVar('notifypub', $notifypub);
450
            $downloadObj->setVar('ipaddress', $_SERVER['REMOTE_ADDR']);
451
452
            if (!$helper->getHandler('Download')->insert($downloadObj)) {
453
                $error = _MD_WFDOWNLOADS_INFONOSAVEDB;
454
                trigger_error($error, E_USER_ERROR);
455
            }
456
            $newid  = (int)$downloadObj->getVar('lid');
457
            $groups = [1, 2];
458
            //  Notify of new link (anywhere) and new link in category
459
            $tags                  = [];
460
            $tags['FILE_NAME']     = $title;
461
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$newid}";
462
            $categoryObj           = $helper->getHandler('Category')->get($cid);
463
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
464
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
465
466
            if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove') || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
467
                $notificationHandler->triggerEvent('global', 0, 'new_file', $tags);
468
                $notificationHandler->triggerEvent('category', $cid, 'new_file', $tags);
469
                redirect_header('index.php', 2, _MD_WFDOWNLOADS_ISAPPROVED);
470
            } else {
471
                $tags['WAITINGFILES_URL'] = WFDOWNLOADS_URL . '/admin/downloads.php';
472
                $notificationHandler->triggerEvent('global', 0, 'file_submit', $tags);
473
                $notificationHandler->triggerEvent('category', $cid, 'file_submit', $tags);
474
                if ($notify) {
475
                    require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
476
                    $notificationHandler->subscribe('file', $newid, 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
477
                }
478
                redirect_header('index.php', 2, _MD_WFDOWNLOADS_THANKSFORINFO);
479
            }
480
            exit();
481
        }
482
        if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove') || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
483
            $notifypub = (isset($_POST['notifypub']) && true === $_POST['notifypub']);
484
            $downloadObj->setVar('notifypub', $notifypub);
485
            $downloadObj->setVar('ipaddress', $_SERVER['REMOTE_ADDR']);
486
            $downloadObj->setVar('updated', time());
487
            $helper->getHandler('Download')->insert($downloadObj);
488
489
            $tags                  = [];
490
            $tags['FILE_NAME']     = $title;
491
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$lid}";
492
            $categoryObj           = $helper->getHandler('Category')->get($cid);
493
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
494
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
495
            $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags);
496
            redirect_header('index.php', 2, _MD_WFDOWNLOADS_ISAPPROVED);
497
        } else {
498
            $updated = (isset($_POST['up_dated']) && 0 == $_POST['up_dated']) ? 0 : time();
499
            $downloadObj->setVar('updated', $updated);
500
            $downloadObj->setVar('modifysubmitter', (int)$GLOBALS['xoopsUser']->uid());
501
            $downloadObj->setVar('requestdate', time());
502
            if (!$helper->getHandler('Modification')->insert($downloadObj)) {
503
                $error = _MD_WFDOWNLOADS_INFONOSAVEDB;
504
                trigger_error($error, E_USER_ERROR);
505
            }
506
            $tags                      = [];
507
            $tags['MODIFYREPORTS_URL'] = WFDOWNLOADS_URL . '/admin/reportsmodifications.php';
508
            $notificationHandler->triggerEvent('global', 0, 'file_modify', $tags);
509
            redirect_header('index.php', 2, _MD_WFDOWNLOADS_THANKSFORINFO);
510
        }
511
512
        break;
513
}
514