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.

admin/downloads.php (10 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\IPAddress;
23
use Xmf\Module\Admin;
24
use Xmf\Request;
25
use XoopsModules\Wfdownloads\{
26
    Common\Configurator,
27
    Download,
28
    Helper,
29
    Utility
30
};
31
/** @var Helper $helper */
32
/** @var Utility $utility */
33
/** @var Download $downloadObj */
34
/** @var Configurator $configurator */
35
36
$currentFile = basename(__FILE__);
37
require_once __DIR__ . '/admin_header.php';
38
xoops_load('XoopsLocal');
39
40
/** @var \XoopsNotificationHandler $notificationHandler */
41
$notificationHandler = xoops_getHandler('notification');
42
43
$helper = Helper::getInstance();
44
$configurator = new Configurator();
45
$icons = $configurator->icons;
46
47
/** @var \XoopsMemberHandler $memberHandler */
48
$memberHandler = xoops_getHandler('member');
49
50
// Check directories
51
if (!is_dir($helper->getConfig('uploaddir'))) {
52
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_UPLOADDIRNOTEXISTS);
53
}
54
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('mainimagedir'))) {
55
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_MAINIMAGEDIRNOTEXISTS);
56
}
57
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('screenshots'))) {
58
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_SCREENSHOTSDIRNOTEXISTS);
59
}
60
if (!is_dir(XOOPS_ROOT_PATH . '/' . $helper->getConfig('catimage'))) {
61
    redirect_header('index.php', 4, _AM_WFDOWNLOADS_ERROR_CATIMAGEDIRNOTEXISTS);
62
}
63
64
$op = Request::getString('op', 'downloads.list');
65
switch ($op) {
66
    case 'download.edit':
67
    case 'download.add':
68
    case 'Download':
69
        Utility::getCpHeader();
70
        $adminObject = Admin::getInstance();
71
        $adminObject->displayNavigation($currentFile);
72
73
        //$adminObject = \Xmf\Module\Admin::getInstance();
74
        $adminObject->addItemButton(_MI_WFDOWNLOADS_MENU_DOWNLOADS, "{$currentFile}?op=downloads.list", 'list');
75
        $adminObject->displayButton('left');
76
77
        $lid = Request::getInt('lid', 0);
78
79
        $categoriesCount = $helper->getHandler('Category')->getCount();
80
        if ($categoriesCount) {
81
            // Allowed mimetypes list
82
            echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFDOWNLOADS_FILE_ALLOWEDAMIME . "</legend>\n";
83
            echo "<div style='padding: 8px;'>\n";
84
            $criteria       = new Criteria('mime_admin', 'true');
85
            $mimetypes      = $helper->getHandler('Mimetype')->getList($criteria);
86
            $allowMimetypes = implode(' | ', $mimetypes);
87
            echo $allowMimetypes;
88
            echo "</div>\n";
89
            echo "</fieldset><br>\n";
90
91
            if ($lid) {
92
                // edit download
93
                if (!$downloadObj = $helper->getHandler('Download')->get($lid)) {
94
                    redirect_header($currentFile, 4, _AM_WFDOWNLOADS_DOWN_ERROR_FILENOTFOUND);
95
                }
96
                $cid = $downloadObj->getVar('cid');
97
                if (!$categoryObj = $helper->getHandler('Category')->get($cid)) {
98
                    redirect_header($currentFile, 4, _AM_WFDOWNLOADS_DOWN_ERROR_CATEGORYNOTFOUND);
99
                }
100
                $title   = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FILE_EDIT);
101
                $title12 = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FFS_1STEP);
102
                $title22 = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FFS_EDITDOWNLOADTITLE);
103
            } else {
104
                // create download
105
                $downloadObj = $helper->getHandler('Download')->create();
106
                $cid         = Request::getInt('cid', 0, 'POST');
107
                $categoryObj = $helper->getHandler('Category')->get($cid);
108
                $downloadObj->setVar('cid', $cid);
109
                $title   = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FILE_CREATE);
110
                $title12 = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FFS_1STEP);
111
                $title22 = preg_replace('/{category}/', $categoryObj->getVar('title'), _AM_WFDOWNLOADS_FFS_DOWNLOADTITLE);
112
            }
113
114
            // Formulize module support (2006/05/04) jpc - start
115
            if (!Utility::checkModule('formulize')) {
116
                // one step form: 1st step
117
                $sform = $downloadObj->getAdminForm($title);
0 ignored issues
show
The method getAdminForm() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModules\Wfdownloads\Download or XoopsModules\Wfdownloads\Category. ( Ignorable by Annotation )

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

117
                /** @scrutinizer ignore-call */ 
118
                $sform = $downloadObj->getAdminForm($title);
Loading history...
118
            } elseif (Request::hasVar('submit_category', 'POST') && !empty($_POST['submit_category'])) {
119
                // two steps form: 2nd step
120
                $fid         = $categoryObj->getVar('formulize_fid');
121
                $customArray = [];
122
                if ($fid) {
123
                    require_once XOOPS_ROOT_PATH . '/modules/formulize/include/formdisplay.php';
124
                    require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php';
125
                    $customArray['fid']           = $fid;
126
                    $customArray['formulize_mgr'] = $helper->getHandler('Elements', 'formulize');
0 ignored issues
show
The call to XoopsModules\Wfdownloads\Helper::getHandler() has too many arguments starting with 'formulize'. ( Ignorable by Annotation )

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

126
                    /** @scrutinizer ignore-call */ 
127
                    $customArray['formulize_mgr'] = $helper->getHandler('Elements', 'formulize');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
127
                    $customArray['groups']        = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
128
                    $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

128
                    $customArray['prevEntry']     = /** @scrutinizer ignore-call */ getEntryValues(// is a Formulize function
Loading history...
129
                        $downloadObj->getVar('formulize_idreq'),
130
                        $customArray['formulize_mgr'],
131
                        $customArray['groups'],
132
                        $fid,
133
                        null,
134
                        null,
135
                        null,
136
                        null,
137
                        null
138
                    );
139
                    $customArray['entry']         = $downloadObj->getVar('formulize_idreq');
140
                    $customArray['go_back']       = '';
141
                    $customArray['parentLinks']   = '';
142
                    if (Utility::checkModule('formulize') < 300) {
143
                        $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

143
                        $owner = /** @scrutinizer ignore-call */ getEntryOwner($customArray['entry']); // is a Formulize function
Loading history...
144
                    } else {
145
                        $owner = getEntryOwner($customArray['entry'], $fid); // is a Formulize function
146
                    }
147
                    $ownerGroups                 = $memberHandler->getGroupsByUser($owner, false);
148
                    $customArray['owner_groups'] = $ownerGroups;
149
                }
150
                $sform = $downloadObj->getAdminForm($title22, $customArray);
151
            } else {
152
                // two steps form: 1st step
153
                $sform = $downloadObj->getCategoryForm($title12);
0 ignored issues
show
The method getCategoryForm() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModules\Wfdownloads\Download or XoopsModules\Wfdownloads\Category. ( Ignorable by Annotation )

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

153
                /** @scrutinizer ignore-call */ 
154
                $sform = $downloadObj->getCategoryForm($title12);
Loading history...
154
            }
155
            // Formulize module support (2006/05/04) jpc - end
156
            $sform->display();
157
        } else {
158
            redirect_header('categories.php', 1, _AM_WFDOWNLOADS_CCATEGORY_NOEXISTS);
159
        }
160
161
        // Vote data list/manager
162
        if ($lid) {
163
            $ratingCount = $helper->getHandler('Rating')->getCount();
164
165
            $regUserCriteria = new CriteriaCompo(new Criteria('lid', $lid));
166
            $regUserCriteria->add(new Criteria('ratinguser', 0, '>'));
167
            $regUserRatingCount = $helper->getHandler('Rating')->getCount($regUserCriteria);
168
            $regUserCriteria->setSort('ratingtimestamp');
169
            $regUserCriteria->setOrder('DESC');
170
            $regUserRatingObjs = $helper->getHandler('Rating')->getObjects($regUserCriteria);
171
172
            $anonUserCriteria = new CriteriaCompo(new Criteria('lid', $lid));
173
            $anonUserCriteria->add(new Criteria('ratinguser', 0, '='));
174
            $anonUserRatingCount = $helper->getHandler('Rating')->getCount($anonUserCriteria);
175
            $anonUserCriteria->setSort('ratingtimestamp');
176
            $anonUserCriteria->setOrder('DESC');
177
178
            echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFDOWNLOADS_VOTE_RATINGINFOMATION . "</legend>\n";
179
            echo "<div style='padding: 8px;'><b>" . _AM_WFDOWNLOADS_VOTE_TOTALVOTES . "</b>{$ratingCount}<br><br>\n";
180
181
            printf(_AM_WFDOWNLOADS_VOTE_REGUSERVOTES, $regUserRatingCount);
182
183
            echo '<br>';
184
185
            printf(_AM_WFDOWNLOADS_VOTE_ANONUSERVOTES, $anonUserRatingCount);
186
187
            echo "
188
                </div>\n
189
                <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
190
                <tr>\n
191
                <th>" . _AM_WFDOWNLOADS_VOTE_USER . "</td>\n
192
                <th>" . _AM_WFDOWNLOADS_VOTE_IP . "</td>\n
193
                <th>" . _AM_WFDOWNLOADS_VOTE_RATING . "</td>\n
194
                <th>" . _AM_WFDOWNLOADS_VOTE_USERAVG . "</td>\n
195
                <th>" . _AM_WFDOWNLOADS_VOTE_TOTALRATE . "</td>\n
196
                <th>" . _AM_WFDOWNLOADS_VOTE_DATE . "</td>\n
197
                <th>" . _AM_WFDOWNLOADS_MINDEX_ACTION . "</td>\n
198
                </tr>\n
199
                ";
200
201
            if (0 == $regUserRatingCount) {
202
                echo "<tr><td colspan='7' class='even'><b>" . _AM_WFDOWNLOADS_VOTE_NOREGVOTES . '</b></td></tr>';
203
            } else {
204
                $uids = [];
205
                foreach ($regUserRatingObjs as $regUserRatingObj) {
206
                    $uids[] = $regUserRatingObj->getVar('ratinguser');
207
                }
208
209
                $criteria = new Criteria('ratinguser', '(' . implode(',', $uids) . ')', 'IN');
210
                $criteria->setGroupBy('ratinguser');
211
                $userRatings = $helper->getHandler('Rating')->getUserAverage($criteria);
212
213
                foreach ($regUserRatingObjs as $regUserRatingObj) {
214
                    $formatted_date = formatTimestamp($regUserRatingObj->getVar('ratingtimestamp'), 'l');
215
                    $userAvgRating  = isset($userRatings[$regUserRatingObj->getVar('ratinguser')]) ? $userRatings[$regUserRatingObj->getVar('ratinguser')]['avg'] : 0;
216
                    $userVotes      = isset($userRatings[$regUserRatingObj->getVar('ratinguser')]) ? $userRatings[$regUserRatingObj->getVar('ratinguser')]['count'] : 0;
217
                    $ratingUserName = XoopsUser::getUnameFromId($regUserRatingObj->getVar('ratinguser'));
218
219
                    echo "
220
                        <tr><td class='head'>$ratingUserName</td>\n
221
                        <td class='even'>" . $regUserRatingObj->getVar('ratinghostname') . "</th>\n
222
                        <td class='even'>" . $regUserRatingObj->getVar('rating') . "</th>\n
223
                        <td class='even'>$userAvgRating</th>\n
224
                        <td class='even'>$userVotes</th>\n
225
                        <td class='even'>$formatted_date</th>\n
226
                        <td class='even'>\n
227
                        <a href='{$currentFile}?op=vote.delete&amp;lid={$lid}&amp;rid=" . $regUserRatingObj->getVar('ratingid') . "'>" . $icons['delete'] . "</a>\n
228
                        </th></tr>\n
229
                        ";
230
                }
231
            }
232
            echo "
233
                </table>\n
234
                <br>\n
235
                <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
236
                <tr>\n
237
                <th>" . _AM_WFDOWNLOADS_VOTE_USER . "</td>\n
238
                <th>" . _AM_WFDOWNLOADS_VOTE_IP . "</td>\n
239
                <th>" . _AM_WFDOWNLOADS_VOTE_RATING . "</td>\n
240
                <th>" . _AM_WFDOWNLOADS_VOTE_USERAVG . "</td>\n
241
                <th>" . _AM_WFDOWNLOADS_VOTE_TOTALRATE . "</td>\n
242
                <th>" . _AM_WFDOWNLOADS_VOTE_DATE . "</td>\n
243
                <th>" . _AM_WFDOWNLOADS_MINDEX_ACTION . "</td>\n
244
                </tr>\n
245
                ";
246
            if (0 == $anonUserRatingCount) {
247
                echo "<tr><td colspan='7' class='even'><b>" . _AM_WFDOWNLOADS_VOTE_NOUNREGVOTES . '</b></td></tr>';
248
            } else {
249
                $criteria           = new Criteria('ratinguser', 0);
250
                $userRatings        = $helper->getHandler('Rating')->getUserAverage($criteria);
251
                $anonUserRatingObjs = $helper->getHandler('Rating')->getObjects($anonUserCriteria);
252
253
                foreach (array_keys($anonUserRatingObjs) as $i) {
254
                    $formatted_date = formatTimestamp($anonUserRatingObjs[$i]->getVar('ratingtimestamp'), 'l');
255
                    $userAvgRating  = $userRatings['avg'] ?? 0;
256
                    $userVotes      = $userRatings['count'] ?? 0;
257
258
                    $ratingUserName = $GLOBALS['xoopsConfig']['anonymous'];
259
260
                    echo "
261
                        <tr><td class='head'>$ratingUserName</td>\n
262
                        <td class='even'>" . $anonUserRatingObjs[$i]->getVar('ratinghostname') . "</th>\n
263
                        <td class='even'>" . $anonUserRatingObjs[$i]->getVar('rating') . "</th>\n
264
                        <td class='even'>$userAvgRating</th>\n
265
                        <td class='even'>$userVotes</th>\n
266
                        <td class='even'>$formatted_date</th>\n
267
                        <td class='even'>\n
268
                        <a href='{$currentFile}?op=vote.delete&amp;lid={$lid}&amp;rid=" . $anonUserRatingObjs[$i]->getVar('ratingid') . "'>" . $icons['delete'] . "</a>\n
269
                        </th></tr>\n
270
                        ";
271
                }
272
            }
273
            echo "</table>\n";
274
            echo "</fieldset>\n";
275
        }
276
        require_once __DIR__ . '/admin_footer.php';
277
        break;
278
    case 'download.save':
279
    case 'addDownload':
280
        $lid    = Request::getInt('lid', 0, 'POST');
281
        $cid    = Request::getInt('cid', 0, 'POST');
282
        $status = Request::getInt('status', _WFDOWNLOADS_STATUS_UPDATED, 'POST');
283
284
        if ($lid > 0) {
285
            $thisIsANewRecord = false; /* Added by Lankford on 2007/3/21 */
286
            $downloadObj      = $helper->getHandler('Download')->get($lid);
287
        } else {
288
            $thisIsANewRecord = true; /* Added by Lankford on 2007/3/21 */
289
            $downloadObj      = $helper->getHandler('Download')->create();
290
        }
291
        // Define URL
292
        if (empty($_FILES['userfile']['name'])) {
293
            if ($_POST['url'] && '' != $_POST['url'] && 'http://' !== $_POST['url']) {
294
                $url      = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
295
                $filename = '';
296
                $filetype = '';
297
                // Get size from form
298
                $size = (empty($_POST['size']) || !is_numeric($_POST['size'])) ? 0 : Request::getInt('size', 0, 'POST');
299
            } else {
300
                $url      = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
301
                $filename = $_POST['filename'];
302
                $filetype = $_POST['filetype'];
303
                $filePath = $helper->getConfig('uploaddir') . '/' . $filename;
304
                // Get size from filesystem
305
                $size = @filesize($filePath);
306
            }
307
            $title = trim($_POST['title']);
308
            $downloadObj->setVar('filename', $filename);
309
            $downloadObj->setVar('filetype', $filetype);
310
        } else {
311
            $down  = Utility::uploading($_FILES, $helper->getConfig('uploaddir'), [], $currentFile, 0, false, true);
312
            $url   = ('http://' !== $_POST['url']) ? $_POST['url'] : '';
313
            $size  = $down['size'];
314
            $title = $_FILES['userfile']['name'];
315
316
            $ext   = rtrim(mb_strrchr($title, '.'), '.');
317
            $title = str_replace($ext, '', $title);
318
            $title = (isset($_POST['title_checkbox']) && 1 == $_POST['title_checkbox']) ? $title : trim($_POST['title']);
319
320
            $filename = $down['filename'];
321
            $filetype = $_FILES['userfile']['type'];
322
            $downloadObj->setVar('filename', $filename);
323
            $downloadObj->setVar('filetype', $filetype);
324
        }
325
        // Get data from form
326
        $screenshots   = [];
327
        $screenshots[] = ('blank.png' !== Request::getString('screenshot', '', 'POST')) ? Request::getString('screenshot', '', 'POST') : '';  //$_POST['screenshot']) ? $_POST['screenshot'] : '';
328
        $screenshots[] = ('blank.png' !== Request::getString('screenshot2', '', 'POST')) ? Request::getString('screenshot2', '', 'POST') : '';  //('blank.png' !== $_POST['screenshot2']) ? $_POST['screenshot2'] : '';
329
        $screenshots[] = ('blank.png' !== Request::getString('screenshot3', '', 'POST')) ? Request::getString('screenshot3', '', 'POST') : '';  //('blank.png' !== $_POST['screenshot3']) ? $_POST['screenshot3'] : '';
330
        $screenshots[] = ('blank.png' !== Request::getString('screenshot4', '', 'POST')) ? Request::getString('screenshot4', '', 'POST') : '';  //('blank.png' !== $_POST['screenshot4']) ? $_POST['screenshot4'] : '';
331
332
        if (Request::hasVar('homepage') || 'http://' !== Request::getString('homepage', '', 'POST')) {
333
            $downloadObj->setVar('homepage', Request::getString('homepage', '', 'POST')); //trim($_POST['homepage']));
334
            $downloadObj->setVar('homepagetitle', Request::getString('homepagetitle', '', 'POST')); //trim($_POST['homepagetitle']));
335
        }
336
337
        $version = Request::getInt('version', 0, 'POST');
338
339
        /* Added by Lankford on 2007/3/21 */
340
        // Here, I want to know if:
341
        //    a) Are they actually changing the value of version, or is it the same?
342
        //    b) Are they actually modifying the record, or is this a new one?
343
        //  If both conditions are true, then trigger all three notifications related to modified records.
344
        if (!$thisIsANewRecord && ($downloadObj->getVar('version') != $version)) {
345
            // Trigger the three events related to modified files (one for the file, category, and global event categories respectively)
346
            $tags                  = [];
347
            $tags['FILE_NAME']     = $title;
348
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$lid}";
0 ignored issues
show
The constant WFDOWNLOADS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
349
            $categoryObj           = $helper->getHandler('Category')->get($cid);
350
            $tags['FILE_VERSION']  = $version;
351
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
352
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid='{$cid}";
353
354
            if (_WFDOWNLOADS_AUTOAPPROVE_DOWNLOAD == $helper->getConfig('autoapprove') || _WFDOWNLOADS_AUTOAPPROVE_BOTH == $helper->getConfig('autoapprove')) {
355
                // Then this change will be automatically approved, so the notification needs to go out.
356
                $notificationHandler->triggerEvent('global', 0, 'filemodified', $tags);
357
                $notificationHandler->triggerEvent('category', $cid, 'filemodified', $tags);
358
                $notificationHandler->triggerEvent('file', $lid, 'filemodified', $tags);
359
            }
360
        }
361
        /* End add block */
362
        $downloadObj->setVar('version', $version);
363
        $downloadObj->setVar('url', $url);
364
        $downloadObj->setVar('cid', $cid);
365
        $downloadObj->setVar('title', $title);
366
        $downloadObj->setVar('status', $status);
367
        $downloadObj->setVar('size', $size);
368
        $downloadObj->setVar('screenshot', $screenshots[0]); // old style
369
        $downloadObj->setVar('screenshot2', $screenshots[1]); // old style
370
        $downloadObj->setVar('screenshot3', $screenshots[2]); // old style
371
        $downloadObj->setVar('screenshot4', $screenshots[3]); // old style
372
        $downloadObj->setVar('screenshots', $screenshots); // new style
373
        $downloadObj->setVar('platform', Request::getString('platform', '', 'POST'));
374
        $downloadObj->setVar('summary', Request::getText('summary', '', 'POST'));
375
        $downloadObj->setVar('description', Request::getText('description', '', 'POST'));
376
        $downloadObj->setVar('dohtml', Request::getInt('dohtml', 0, 'POST'));
377
        $downloadObj->setVar('dosmiley', Request::getInt('dosmiley', 0, 'POST'));
378
        $downloadObj->setVar('doxcode', Request::getInt('doxcode', 0, 'POST'));
379
        $downloadObj->setVar('doimage', Request::getInt('doimage', 0, 'POST'));
380
        $downloadObj->setVar('dobr', Request::getInt('dobr', 0, 'POST'));
381
        $downloadObj->setVar('submitter', Request::getInt('submitter', 0, 'POST'));
382
        $downloadObj->setVar('publisher', Request::getString('publisher', '', 'POST'));
383
        $downloadObj->setVar('price', Request::getString('price', '', 'POST'));
384
        $downloadObj->setVar('paypalemail', Request::getString('paypalemail', '', 'POST'));
385
        if (!$helper->getConfig('enable_mirrors')) {
386
            $downloadObj->setVar('mirror', formatURL(Request::getString('mirror', '', 'POST')));
387
        }
388
        $downloadObj->setVar('license', Request::getString('license', '', 'POST'));
389
        $downloadObj->setVar('features', Request::getText('features', '', 'POST'));
390
        $downloadObj->setVar('requirements', Request::getText('requirements', '', 'POST'));
391
        $downloadObj->setVar('limitations', Request::getString('limitations', '', 'POST'));
392
        $downloadObj->setVar('versiontypes', Request::getString('versiontypes', '', 'POST'));
393
394
        $dhistory        = Request::getText('dhistory', '', 'POST');
395
        $dhistoryhistory = Request::getString('dhistoryaddedd', '', 'POST');
396
397
        if ($lid > 0 && !empty($dhistoryhistory)) {
398
            $dhistory .= "\n\n";
399
            $time     = time();
400
            $dhistory .= _AM_WFDOWNLOADS_FILE_HISTORYVERS . $version . _AM_WFDOWNLOADS_FILE_HISTORDATE . XoopsLocal::formatTimestamp($time, 'l') . "\n\n";
401
            $dhistory .= $dhistoryhistory;
402
        }
403
        $downloadObj->setVar('dhistory', $dhistory);
404
        $downloadObj->setVar('dhistoryhistory', $dhistoryhistory);
405
406
        $updated = (Request::hasVar('was_published', 'POST') && 0 == Request::getInt('was_published', 0, 'POST')) ? 0 : time();
407
408
        if (0 == Request::getInt('up_dated', 0, 'POST')) {
409
            $updated = 0;
410
        }
411
        $downloadObj->setVar('updated', Request::getInt('up_dated', 0, 'POST'));
412
        $downloadObj->setVar('offline', Request::getInt('offline', 0, 'POST'));
413
        $approved  = Request::getInt('approved', 0, 'POST');
414
        $notifypub = Request::getInt('notifypub', 0, 'POST');
415
416
        $expiredate = 0;
417
        if (!$lid) {
418
            $publishdate = time();
419
        } else {
420
            $publishdate = Request::getInt('was_published', 0, 'POST');
421
            $expiredate  = Request::getInt('was_expired', 0, 'POST');
422
        }
423
        if (1 == $approved && empty($publishdate)) {
424
            $publishdate = time();
425
        }
426
        if (Request::hasVar('publishdateactivate')) {
427
            $publishdate = strtotime(Request::getArray('published')['date']) + Request::getArray('published')['time'];
428
        }
429
        if ($_POST['clearpublish']) {
430
            $publishdate = $downloadObj->getVar('published');
431
        }
432
        if (Request::hasVar('expiredateactivate')) {
433
            $expiredate = strtotime($_POST['expired']['date']) + $_POST['expired']['time'];
434
        }
435
        if ($_POST['clearexpire']) {
436
            $expiredate = '0';
437
        }
438
439
        $downloadObj->setVar('expired', $expiredate);
440
        $downloadObj->setVar('published', $publishdate);
441
        $downloadObj->setVar('date', time());
442
        // Update or insert download data into database
443
        if (!$lid) {
444
            $downloadObj->setVar('ipaddress', IPAddress::fromRequest()->asReadable()); //$_SERVER['REMOTE_ADDR']);
445
        }
446
447
        $categoryObj = $helper->getHandler('Category')->get($cid);
448
449
        // Formulize module support (2006/05/04) jpc - start
450
        if (Utility::checkModule('formulize')) {
451
            $fid = $categoryObj->getVar('formulize_fid');
452
            if ($fid) {
453
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/formread.php';
454
                require_once XOOPS_ROOT_PATH . '/modules/formulize/include/functions.php';
455
                $formulizeElementsHandler = $helper->getHandler('Elements', 'formulize');
456
                if ($lid) {
457
                    $entries[$fid][0] = $downloadObj->getVar('formulize_idreq');
458
                    if ($entries[$fid][0]) {
459
                        if (Utility::checkModule('formulize') < 300) {
460
                            $owner = getEntryOwner($entries[$fid][0]); // is a Formulize function
461
                        } else {
462
                            $owner = getEntryOwner($entries[$fid][0], $fid); // is a Formulize function
463
                        }
464
                    } else {
465
                        print 'no idreq';
466
                        $entries[$fid][0] = '';
467
                        $owner            = '';
468
                    }
469
                    $cid = $downloadObj->getVar('cid');
470
                } else {
471
                    $entries[$fid][0] = '';
472
                    $owner            = '';
473
                }
474
                $ownerGroups = $memberHandler->getGroupsByUser($owner, false);
475
                $uid         = !empty($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0;
476
                $groups      = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS];
477
                $entries     = handleSubmission($formulizeElementsHandler, $entries, $uid, $owner, $fid, $ownerGroups, $groups, 'new'); // "new" causes xoops token check to be skipped, since Wfdownloads should be doing that
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

477
                $entries     = /** @scrutinizer ignore-call */ handleSubmission($formulizeElementsHandler, $entries, $uid, $owner, $fid, $ownerGroups, $groups, 'new'); // "new" causes xoops token check to be skipped, since Wfdownloads should be doing that
Loading history...
478
                if (!$owner) {
479
                    $id_req = $entries[$fid][0];
480
                    $downloadObj->setVar('formulize_idreq', $id_req);
481
                }
482
            }
483
        }
484
        // Formulize module support (2006/05/04) jpc - end
485
        $helper->getHandler('Download')->insert($downloadObj);
486
        $newid = (int)$downloadObj->getVar('lid');
487
        // Send notifications
488
        if (!$lid) {
489
            $tags                  = [];
490
            $tags['FILE_NAME']     = $title;
491
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$newid}";
492
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
493
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
494
            $notificationHandler->triggerEvent('global', 0, 'new_file', $tags);
495
            $notificationHandler->triggerEvent('category', $cid, 'new_file', $tags);
496
        }
497
        if ($lid && $approved && $notifypub) {
498
            $tags                  = [];
499
            $tags['FILE_NAME']     = $title;
500
            $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$lid}";
501
            $categoryObj           = $helper->getHandler('Category')->get($cid);
502
            $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
503
            $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . '/viewcat.php?cid=' . $cid;
504
            $notificationHandler->triggerEvent('global', 0, 'new_file', $tags);
505
            $notificationHandler->triggerEvent('category', $cid, 'new_file', $tags);
506
            $notificationHandler->triggerEvent('file', $lid, 'approve', $tags);
507
        }
508
        $message = (!$lid) ? _AM_WFDOWNLOADS_FILE_NEWFILEUPLOAD : _AM_WFDOWNLOADS_FILE_FILEMODIFIEDUPDATE;
509
        $message = ($lid && !$_POST['was_published'] && $approved) ? _AM_WFDOWNLOADS_FILE_FILEAPPROVED : $message;
510
511
        redirect_header($currentFile, 1, $message);
512
        break;
513
    case 'download.delete':
514
        $lid = Request::getInt('lid', 0);
515
        $ok  = Request::getBool('ok', false, 'POST');
516
        if (!$downloadObj = $helper->getHandler('Download')->get($lid)) {
517
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_DOWNLOADNOTFOUND);
518
        }
519
        $title = (string)$downloadObj->getVar('title');
520
        if (true === $ok) {
521
            if (!$GLOBALS['xoopsSecurity']->check()) {
522
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
523
            }
524
            $file = $helper->getConfig('uploaddir') . '/' . $downloadObj->getVar('filename');
525
            if (is_file($file)) {
526
                if (false === @chmod($file, 0777)) {
527
                    throw new RuntimeException('The file mode for ' . $file . ' could not be changed.');
528
                }
529
                if (false === @unlink($file)) {
530
                    throw new RuntimeException('The file ' . $file . ' could not be deleted.');
531
                }
532
            }
533
            if ($helper->getHandler('Download')->delete($downloadObj)) {
534
                redirect_header($currentFile, 1, sprintf(_AM_WFDOWNLOADS_FILE_FILEWASDELETED, $title));
535
            } else {
536
                echo $downloadObj->getHtmlErrors();
537
            }
538
        } else {
539
            Utility::getCpHeader();
540
            xoops_confirm(['op' => 'download.delete', 'lid' => $lid, 'ok' => true, 'title' => $title], $currentFile, _AM_WFDOWNLOADS_FILE_REALLYDELETEDTHIS . '<br><br>' . $title, _DELETE);
541
            xoops_cp_footer();
542
        }
543
        break;
544
    case 'vote.delete':
545
    case 'delVote':
546
        $ratingObj = $helper->getHandler('Rating')->get($_GET['rid']);
547
        if ($helper->getHandler('Rating')->delete($ratingObj, true)) {
548
            Utility::updateRating((int)$ratingObj->getVar('lid'));
549
        }
550
        redirect_header($currentFile, 1, _AM_WFDOWNLOADS_VOTE_VOTEDELETED);
551
        break;
552
    // Formulize module support (2006/05/04) jpc - start
553
    case 'patch_formulize':
554
        if (Utility::checkModule('formulize')) {
555
            if (!isset($_POST['patch_formulize'])) {
556
                print "<form action=\"{$currentFile}?op=patch_formulize\" method=post>";
557
                print '<input type = submit name=patch_formulize value="Apply Patch for Formulize">';
558
                print '</form>';
559
            } else {
560
                $sqls[] = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_cat') . " ADD formulize_fid INT(5) NOT NULL DEFAULT '0';";
561
                $sqls[] = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_downloads') . " ADD formulize_idreq INT(5) NOT NULL DEFAULT '0';";
562
                foreach ($sqls as $sql) {
563
                    if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
564
                        exit('Error patching for Formulize.<br>SQL dump:<br>' . $sql . '<br>Please contact <a [email protected]>Freeform Solutions</a> for assistance.');
565
                    }
566
                }
567
                print 'Patching for Formulize completed.';
568
            }
569
        }
570
        break;
571
    // Formulize module support (2006/05/04) jpc - end
572
573
    case 'newdownload.approve':
574
    case 'approve':
575
        $lid = Request::getInt('lid', 0);
576
        if (!$downloadObj = $helper->getHandler('Download')->get($lid)) {
577
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_DOWNLOADNOTFOUND);
578
        }
579
        // Update the database
580
        $downloadObj->setVar('published', time());
581
        $downloadObj->setVar('status', _WFDOWNLOADS_STATUS_APPROVED);
582
        if (!$helper->getHandler('Download')->insert($downloadObj, true)) {
583
            echo $downloadObj->getHtmlErrors();
584
            exit();
585
        }
586
        // Trigger notify
587
        $title                 = $downloadObj->getVar('title');
588
        $cid                   = $downloadObj->getVar('cid');
589
        $categoryObj           = $helper->getHandler('Category')->get($cid);
590
        $tags                  = [];
591
        $tags['FILE_NAME']     = $title;
592
        $tags['FILE_URL']      = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&amp;lid={$lid}";
593
        $tags['CATEGORY_NAME'] = $categoryObj->getVar('title');
594
        $tags['CATEGORY_URL']  = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
595
        $notificationHandler->triggerEvent('global', 0, 'new_file', $tags);
596
        $notificationHandler->triggerEvent('category', $cid, 'new_file', $tags);
597
        if ($downloadObj->getVar('notifypub')) {
598
            $notificationHandler->triggerEvent('file', $lid, 'approve', $tags);
599
        }
600
        redirect_header($currentFile, 1, _AM_WFDOWNLOADS_SUB_NEWFILECREATED);
601
        break;
602
    case 'download.clone':
603
        $id_field = Request::getString('lid', '');
604
605
        if ($utility::cloneRecord('wfdownloads_downloads', 'lid', $id_field )) {
606
            redirect_header('downloads.php', 3, AM_WFDOWNLOADS_CLONED_OK);
607
        } else {
608
            redirect_header('downloads.php', 3, AM_WFDOWNLOADS_CLONED_FAILED);
609
        }
610
611
        break;
612
    case 'downloads.list':
613
    case 'downloads.filter':
614
    default:
615
        // get filter conditions
616
        $filter_title_condition          = Request::getString('filter_title_condition', '=');
617
        $filter_title                    = Request::getString('filter_title', '');
618
        $filter_category_title_condition = Request::getString('filter_category_title_condition', '=');
619
        $filter_category_title           = Request::getString('filter_category_title', '');
620
        $filter_submitter                = Request::getArray('filter_submitter', null);
621
        $filter_date                     = Request::getArray('filter_date', null);
622
        $filter_date_condition           = Request::getString('filter_date_condition', '<');
623
        // check filter conditions
624
        if ('downloads.filter' === $op) {
625
            if ('' == $filter_title && '' == $filter_category_title && null === $filter_submitter) {
0 ignored issues
show
The condition null === $filter_submitter is always false.
Loading history...
626
                $op = 'downloads.list';
627
            }
628
        }
629
630
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
631
632
        $categoryObjs = $helper->getHandler('Category')->getObjects();
633
634
        $start_published     = Request::getInt('start_published', 0);
635
        $start_new           = Request::getInt('start_new', 0);
636
        $start_autopublished = Request::getInt('start_autopublished', 0);
637
        $start_expired       = Request::getInt('start_expired', 0);
638
        $start_offline       = Request::getInt('start_offline', 0);
639
640
        $totalCategoriesCount = Utility::categoriesCount();
641
        $categoryObjs         = $helper->getHandler('Category')->getObjects(null, true, false);
642
643
        $totalDownloadsCount = $helper->getHandler('Download')->getCount();
644
        //    $totalDownloadsCount = $downloadHandler->getCount();
645
646
        Utility::getCpHeader();
647
        $adminObject = Admin::getInstance();
648
        $adminObject->displayNavigation($currentFile);
649
650
        //$adminObject = \Xmf\Module\Admin::getInstance();
651
        $adminObject->addItemButton(_AM_WFDOWNLOADS_FILE_CREATE, $currentFile . '?op=download.add', 'add');
652
        $adminObject->displayButton('left');
653
654
        if ($totalDownloadsCount > 0) {
655
            // Published Downloads
656
            $criteria = new CriteriaCompo();
657
            if ('downloads.filter' === $op) {
658
                // Evaluate title criteria
659
                if ('' != $filter_title) {
660
                    if ('LIKE' === $filter_title_condition) {
661
                        $criteria->add(new Criteria('title', "%{$filter_title}%", 'LIKE'));
662
                    } else {
663
                        $criteria->add(new Criteria('title', $filter_title, '='));
664
                    }
665
                }
666
                // Evaluate cid criteria
667
                if ('' != $filter_category_title) {
668
                    if ('LIKE' === $filter_category_title_condition) {
669
                        $cids = $helper->getHandler('Category')->getIds(new Criteria('title', "%{$filter_category_title}%", 'LIKE'));
670
                        $criteria->add(new Criteria('cid', '(' . implode(',', $cids) . ')', 'IN'));
671
                    } else {
672
                        $cids = $helper->getHandler('Category')->getIds(new Criteria('title', $filter_category_title, '='));
673
                        $criteria->add(new Criteria('cid', '(' . implode(',', $cids) . ')', 'IN'));
674
                    }
675
                }
676
                // Evaluate submitter criteria
677
                if (!null === $filter_submitter) {
0 ignored issues
show
The condition ! null === $filter_submitter is always false.
Loading history...
678
                    $criteria->add(new Criteria('submitter', '(' . implode(',', $filter_submitter) . ')', 'IN'));
679
                }
680
                // Evaluate date criteria
681
                if (!empty($filter_date)) {
682
                    // TODO: IN PROGRESS
683
                }
684
            }
685
686
            $criteria->setSort('published');
687
            $criteria->setOrder('DESC');
688
            $criteria->setStart($start_published);
689
            $criteria->setLimit($helper->getConfig('admin_perpage'));
690
            $publishedDownloadObjs  = $helper->getHandler('Download')->getActiveDownloads($criteria);
691
            $publishedDownloadCount = $helper->getHandler('Download')->getActiveCount();
692
            $GLOBALS['xoopsTpl']->assign('published_downloads_count', $publishedDownloadCount);
693
694
            if ($publishedDownloadCount > 0) {
695
                foreach ($publishedDownloadObjs as $publishedDownloadObj) {
696
                    $publishedDownload_array                        = $publishedDownloadObj->toArray();
697
                    $publishedDownload_array['title_html']          = htmlspecialchars(trim($publishedDownload_array['title']), ENT_QUOTES | ENT_HTML5);
698
                    $publishedDownload_array['category_title']      = $categoryObjs[$publishedDownload_array['cid']]['title'];
699
                    $publishedDownload_array['submitter_uname']     = XoopsUserUtility::getUnameFromId($publishedDownload_array['submitter']);
700
                    $publishedDownload_array['published_formatted'] = formatTimestamp($publishedDownload_array['published'], 'l');
701
                    $GLOBALS['xoopsTpl']->append('published_downloads', $publishedDownload_array);
702
                }
703
            }
704
705
            $pagenav = new XoopsPageNav($publishedDownloadCount, $helper->getConfig('admin_perpage'), $start_published, 'start_published');
706
            $GLOBALS['xoopsTpl']->assign('filter_title', $filter_title);
707
            $GLOBALS['xoopsTpl']->assign('filter_title_condition', $filter_title_condition);
708
            $GLOBALS['xoopsTpl']->assign('filter_category_title', $filter_category_title);
709
            $GLOBALS['xoopsTpl']->assign('filter_category_title_condition', $filter_category_title_condition);
710
            $submitters                = [];
711
            $downloadsSubmitters_array = $helper->getHandler('Download')->getAll(null, ['submitter'], false, false);
712
            foreach ($downloadsSubmitters_array as $downloadSubmitters_array) {
713
                $submitters[$downloadSubmitters_array['submitter']] = XoopsUserUtility::getUnameFromId($downloadSubmitters_array['submitter']);
714
            }
715
            asort($submitters);
716
            $submitter_select = new XoopsFormSelect('', 'filter_submitter', $filter_submitter, (count($submitters) > 5) ? 5 : count($submitters), true);
717
            foreach ($submitters as $submitter_uid => $submitter_uname) {
718
                $submitter_select->addOption($submitter_uid, $submitter_uname);
719
            }
720
            $GLOBALS['xoopsTpl']->assign('filter_submitter_select', $submitter_select->render());
721
            $date_select = new XoopsFormDateTime(null, 'filter_date', 15, time(), false);
722
            $GLOBALS['xoopsTpl']->assign('filter_date_select', $date_select->render());
723
            $GLOBALS['xoopsTpl']->assign('filter_date_condition', $filter_date_condition);
724
            //mb
725
            $GLOBALS['xoopsTpl']->assign('published_downloads_pagenav', $pagenav->renderNav());
726
727
            // New Downloads
728
            $criteria = new CriteriaCompo();
729
            $criteria->add(new Criteria('published', 0));
730
            $criteria->setStart($start_new);
731
            $criteria->setLimit($helper->getConfig('admin_perpage'));
732
            $newDownloadObjs  = $helper->getHandler('Download')->getObjects($criteria);
733
            $newDownloadCount = $helper->getHandler('Download')->getCount($criteria);
734
            $GLOBALS['xoopsTpl']->assign('new_downloads_count', $newDownloadCount);
735
            if ($newDownloadCount > 0) {
736
                foreach ($newDownloadObjs as $newDownloadObj) {
737
                    $newDownload_array                   = $newDownloadObj->toArray();
738
                    $newDownload_array['rating']         = number_format($newDownload_array['rating'], 2);
739
                    $newDownload_array['title_html']     = htmlspecialchars($newDownload_array['title'], ENT_QUOTES | ENT_HTML5);
740
                    $newDownload_array['category_title'] = $categoryObjs[$newDownload_array['cid']]['title'];
741
                    /*
742
                                        $url                                  = urldecode(htmlspecialchars($newDownload_array['url']));
743
                                        $homepage                             = htmlspecialchars($newDownload_array['homepage']);
744
                                        $version                              = htmlspecialchars($newDownload_array['version']);
745
                                        $size                                 = htmlspecialchars($newDownload_array['size']);
746
                                        $platform                             = htmlspecialchars($newDownload_array['platform']);
747
                                        $logourl                              = htmlspecialchars($newDownload_array['screenshot']); // IN PROGRESS
748
                    */
749
                    $newDownload_array['submitter_uname'] = XoopsUserUtility::getUnameFromId($newDownload_array['submitter']);
750
                    $newDownload_array['date_formatted']  = formatTimestamp($newDownload_array['date'], 'l');
751
                    $GLOBALS['xoopsTpl']->append('new_downloads', $newDownload_array);
752
                }
753
            }
754
            $pagenav = new XoopsPageNav($newDownloadCount, $helper->getConfig('admin_perpage'), $start_new, 'start_new');
755
            $GLOBALS['xoopsTpl']->assign('new_downloads_pagenav', $pagenav->renderNav());
756
757
            // Autopublished Downloads
758
            $criteria = new CriteriaCompo();
759
            $criteria->add(new Criteria('published', time(), '>'));
760
            $criteria->setSort('published');
761
            $criteria->setOrder('ASC');
762
            $criteria->setStart($start_autopublished);
763
            $criteria->setLimit($helper->getConfig('admin_perpage'));
764
            $autopublishedDownloadObjs  = $helper->getHandler('Download')->getObjects($criteria);
765
            $autopublishedDownloadCount = $helper->getHandler('Download')->getCount($criteria);
766
            $GLOBALS['xoopsTpl']->assign('autopublished_downloads_count', $autopublishedDownloadCount);
767
            if ($autopublishedDownloadCount > 0) {
768
                foreach ($autopublishedDownloadObjs as $autopublishedDownloadObj) {
769
                    $autopublishedDownload_array                        = $autopublishedDownloadObj->toArray();
770
                    $autopublishedDownload_array['title_html']          = htmlspecialchars(trim($autopublishedDownload_array['title']), ENT_QUOTES | ENT_HTML5);
771
                    $autopublishedDownload_array['category_title']      = $categories[$autopublishedDownload_array['cid']]['title'];
772
                    $autopublishedDownload_array['submitter_uname']     = XoopsUserUtility::getUnameFromId($autopublishedDownload_array['submitter']);
773
                    $autopublishedDownload_array['published_formatted'] = formatTimestamp($autopublishedDownload_array['published'], 'l');
774
                    $GLOBALS['xoopsTpl']->append('autopublished_downloads', $autopublishedDownload_array);
775
                }
776
            }
777
            $pagenav = new XoopsPageNav($autopublishedDownloadCount, $helper->getConfig('admin_perpage'), $start_autopublished, 'start_autopublished');
778
            $GLOBALS['xoopsTpl']->assign('autopublished_downloads_pagenav', $pagenav->renderNav());
779
780
            // Expired downloads
781
            $criteria = new CriteriaCompo();
782
            $criteria->add(new Criteria('expired', time(), '<'), 'AND');
783
            $criteria->add(new Criteria('expired', 0, '<>'), 'AND');
784
            $criteria->setSort('expired');
785
            $criteria->setOrder('ASC');
786
            $criteria->setStart($start_expired);
787
            $criteria->setLimit($helper->getConfig('admin_perpage'));
788
            $expiredDownloadObjs  = $helper->getHandler('Download')->getObjects($criteria);
789
            $expiredDownloadCount = $helper->getHandler('Download')->getCount($criteria);
790
            $GLOBALS['xoopsTpl']->assign('expired_downloads_count', $expiredDownloadCount);
791
            if ($expiredDownloadCount > 0) {
792
                foreach ($expiredDownloadObjs as $expiredDownloadObj) {
793
                    $expiredDownload_array                        = $expiredDownloadObj->toArray();
794
                    $expiredDownload_array['title_html']          = htmlspecialchars(trim($expiredDownload_array['title']), ENT_QUOTES | ENT_HTML5);
795
                    $expiredDownload_array['category_title']      = $categories[$expiredDownload_array['cid']]['title'];
796
                    $expiredDownload_array['submitter_uname']     = XoopsUserUtility::getUnameFromId($expiredDownload_array['submitter']);
797
                    $expiredDownload_array['published_formatted'] = formatTimestamp($expiredDownload_array['published'], 'l');
798
                    $GLOBALS['xoopsTpl']->append('expired_downloads', $expiredDownload_array);
799
                }
800
            }
801
            $pagenav = new XoopsPageNav($expiredDownloadCount, $helper->getConfig('admin_perpage'), $start_expired, 'start_expired');
802
            $GLOBALS['xoopsTpl']->assign('expired_downloads_pagenav', $pagenav->renderNav());
803
804
            // Offline downloads
805
            $criteria = new Criteria('offline', true);
0 ignored issues
show
true of type true is incompatible with the type string expected by parameter $value of Criteria::__construct(). ( Ignorable by Annotation )

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

805
            $criteria = new Criteria('offline', /** @scrutinizer ignore-type */ true);
Loading history...
806
            $criteria->setSort('published');
807
            $criteria->setOrder('ASC');
808
            $criteria->setStart($start_offline);
809
            $criteria->setLimit($helper->getConfig('admin_perpage'));
810
            $offlineDownloadObjs  = $helper->getHandler('Download')->getObjects($criteria);
811
            $offlineDownloadCount = $helper->getHandler('Download')->getCount($criteria);
812
            $GLOBALS['xoopsTpl']->assign('offline_downloads_count', $offlineDownloadCount);
813
            if ($offlineDownloadCount > 0) {
814
                foreach ($offlineDownloadObjs as $offlineDownloadObj) {
815
                    $offlineDownload_array                        = $offlineDownloadObj->toArray();
816
                    $offlineDownload_array['title_html']          = htmlspecialchars(trim($offlineDownload_array['title']), ENT_QUOTES | ENT_HTML5);
817
                    $offlineDownload_array['category_title']      = $categories[$offlineDownload_array['cid']]['title'];
818
                    $offlineDownload_array['submitter_uname']     = XoopsUserUtility::getUnameFromId($offlineDownload_array['submitter']);
819
                    $offlineDownload_array['published_formatted'] = formatTimestamp($offlineDownload_array['published'], 'l');
820
                    $GLOBALS['xoopsTpl']->append('offline_downloads', $offlineDownload_array);
821
                }
822
            }
823
            $pagenav = new XoopsPageNav($offlineDownloadCount, $helper->getConfig('admin_perpage'), $start_offline, 'start_offline');
824
            $GLOBALS['xoopsTpl']->assign('offline_downloads_pagenav', $pagenav->renderNav());
825
        }
826
        // NOP
827
828
        // Batch files
829
        $extensionToMime = require_once $GLOBALS['xoops']->path('include/mimetypes.inc.php');
830
        $batchPath       = $helper->getConfig('batchdir');
831
        $GLOBALS['xoopsTpl']->assign('batch_path', $batchPath);
832
        $batchFiles      = Utility::getFiles($batchPath . '/');
833
        $batchFilesCount = count($batchFiles);
834
        $GLOBALS['xoopsTpl']->assign('batch_files_count', $batchFilesCount);
835
        if ($batchFilesCount > 0) {
836
            foreach ($batchFiles as $key => $batchFile) {
837
                $batchFile_array              = [];
838
                $batchFile_array['id']        = $key;
839
                $batchFile_array['filename']  = $batchFile;
840
                $batchFile_array['size']      = Utility::bytesToSize1024(filesize($batchPath . '/' . $batchFile));
841
                $batchFile_array['extension'] = pathinfo($batchFile, PATHINFO_EXTENSION);
842
                $batchFile_array['mimetype']  = $extensionToMime[pathinfo($batchFile, PATHINFO_EXTENSION)];
843
                $GLOBALS['xoopsTpl']->append('batch_files', $batchFile_array);
844
                unset($batchFile_array);
845
            }
846
        }
847
848
        $GLOBALS['xoopsTpl']->display("db:{$helper->getModule()->dirname()}_am_downloadslist.tpl");
849
850
        require_once __DIR__ . '/admin_footer.php';
851
        break;
852
    case 'batchfile.add':
853
        $batchid = Request::getInt('batchid', 0);
854
855
        $extensionToMime = require_once $GLOBALS['xoops']->path('include/mimetypes.inc.php');
856
        $batchPath       = $helper->getConfig('batchdir');
857
        $batchFiles      = Utility::getFiles($batchPath . '/');
858
859
        if (!isset($batchFiles[$batchid]) || !is_file($batchPath . '/' . $batchFiles[$batchid])) {
860
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_BATCHFILENOTFOUND);
861
        }
862
        $batchFile = $batchFiles[$batchid];
863
864
        $savedFileName = iconv('UTF-8', 'ASCII//TRANSLIT', $batchFile);
865
        $savedFileName = preg_replace('!\s+!', '_', $savedFileName);
866
        $savedFileName = preg_replace('/[^a-zA-Z0-9\._-]/', '', $savedFileName);
867
        $savedFileName = uniqid(time(), true) . '--' . $savedFileName;
868
869
        if (!Utility::copyFile($batchPath . '/' . $batchFile, $helper->getConfig('uploaddir') . '/' . $savedFileName)) {
870
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_BATCHFILENOTCOPIED);
871
        }
872
873
        $downloadObj = $helper->getHandler('Download')->create();
874
        $downloadObj->setVar('title', $batchFile);
875
        $downloadObj->setVar('filename', $savedFileName);
876
        $downloadObj->setVar('size', filesize($helper->getConfig('uploaddir') . '/' . $savedFileName));
877
        $downloadObj->setVar('filetype', $extensionToMime[pathinfo($batchFile, PATHINFO_EXTENSION)]);
878
        $downloadObj->setVar('version', 0);
879
        $downloadObj->setVar('status', _WFDOWNLOADS_STATUS_APPROVED); // IN PROGRESS
880
        $downloadObj->setVar('published', time());
881
        $downloadObj->setVar('date', time());
882
        $downloadObj->setVar('ipaddress', IPAddress::fromRequest()->asReadable()); //$_SERVER['REMOTE_ADDR']);
883
        $downloadObj->setVar('submitter', $GLOBALS['xoopsUser']->getVar('uid', 'e'));
884
        $downloadObj->setVar('publisher', $GLOBALS['xoopsUser']->getVar('uid', 'e'));
885
886
        if (!$helper->getHandler('Download')->insert($downloadObj)) {
887
            Utility::delFile($helper->getConfig('uploaddir') . '/' . $savedFileName);
888
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_BATCHFILENOTADDED);
889
        }
890
        $newid = (int)$downloadObj->getVar('lid');
891
        // Delete batch file
892
        Utility::delFile($batchPath . '/' . $batchFile);
893
        redirect_header("{$currentFile}?op=download.edit&lid={$newid}", 3, _AM_WFDOWNLOADS_BATCHFILE_MOVEDEDITNOW);
894
        break;
895
    case 'batchfile.delete':
896
        $batchid = Request::getInt('batchid', 0);
897
        $ok      = Request::getBool('ok', false, 'POST');
898
899
        $batchPath  = $helper->getConfig('batchdir');
900
        $batchFiles = Utility::getFiles($batchPath);
901
902
        if (!isset($batchFiles[$batchid]) || !is_file($batchPath . '/' . $batchFiles[$batchid])) {
903
            redirect_header($currentFile, 4, _AM_WFDOWNLOADS_ERROR_BATCHFILENOTFOUND);
904
        }
905
        $title = $batchFiles[$batchid];
906
        if (true === $ok) {
907
            if (!$GLOBALS['xoopsSecurity']->check()) {
908
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
909
            }
910
            $file = $batchPath . '/' . $batchFiles[$batchid];
911
            Utility::delFile($file);
912
        } else {
913
            Utility::getCpHeader();
914
            xoops_confirm(['op' => 'batchfile.delete', 'batchid' => $batchid, 'ok' => true, 'title' => $title], $currentFile, _AM_WFDOWNLOADS_FILE_REALLYDELETEDTHIS . '<br><br>' . $title, _DELETE);
915
            xoops_cp_footer();
916
        }
917
        break;
918
    case 'ip_logs.list':
919
        $lid = Request::getInt('lid', 0);
920
        if (!$lid) {
921
            header('Location index.php');
922
        }
923
924
        Utility::getCpHeader();
925
        $adminObject = Admin::getInstance();
926
        $adminObject->displayNavigation($currentFile);
927
928
        //$adminObject = \Xmf\Module\Admin::getInstance();
929
        $adminObject->addItemButton(_AM_WFDOWNLOADS_FILE_CREATE, $currentFile . '?op=download.add', 'add');
930
        $adminObject->displayButton('left');
931
932
        // Get ip logs
933
        $criteria = new CriteriaCompo();
934
        if (0 != $lid) {
935
            $criteria->add(new Criteria('lid', $lid));
936
        }
937
        $criteria->setSort('date');
938
        $criteria->setOrder('DESC');
939
        $ip_logObjs  = $helper->getHandler('Iplog')->getObjects($criteria);
940
        $ip_logCount = $helper->getHandler('Iplog')->getCount($criteria);
941
        $GLOBALS['xoopsTpl']->assign('ip_logs_count', $ip_logCount);
942
        unset($criteria);
943
944
        // Get download info
945
        if (0 != $lid) {
946
            $downloadObj                 = $helper->getHandler('Download')->get($lid);
947
            $download_array              = $downloadObj->toArray();
948
            $download_array['log_title'] = sprintf(_AM_WFDOWNLOADS_LOG_FOR_LID, $download_array['title']);
949
            $GLOBALS['xoopsTpl']->assign('download', $download_array);
950
        }
951
952
        // Get all logged users
953
        $uidArray = [];
954
        foreach ($ip_logObjs as $ip_logObj) {
955
            if (0 != $ip_logObj->getVar('uid') && '' != $ip_logObj->getVar('uid')) {
956
                $uidArray[] = $ip_logObj->getVar('uid');
957
            }
958
        }
959
        $criteria = new CriteriaCompo();
960
        if (!empty($uidArray)) {
961
            $criteria->add(new Criteria('uid', '(' . implode(', ', $uidArray) . ')', 'IN'));
962
        }
963
        $userList = $memberHandler->getUserList($criteria);
964
        if (empty($ip_logObjs)) {
965
            // NOP
966
        } else {
967
            foreach ($ip_logObjs as $ip_logObj) {
968
                $ip_log_array          = $ip_logObj->toArray();
969
                $ip_log_array['uname'] = XoopsUserUtility::getUnameFromId($ip_log_array['uid']);
970
                //($ip_log_array['uid'] != 0) ? $userList[$ip_log_array['uid']] : _AM_WFDOWNLOADS_ANONYMOUS;
971
                $ip_log_array['date_formatted'] = formatTimestamp($ip_log_array['date']);
972
                $GLOBALS['xoopsTpl']->append('ip_logs', $ip_log_array);
973
            }
974
        }
975
976
        $GLOBALS['xoopsTpl']->display("db:{$helper->getModule()->dirname()}_am_ip_logslist.tpl");
977
978
        require_once __DIR__ . '/admin_footer.php';
979
        break;
980
}
981