Passed
Push — master ( 6d3e95...4ad186 )
by Goffy
03:09
created

admin/readmes.php (7 issues)

Labels
Severity
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
 * wgGitHub module for xoops
14
 *
15
 * @copyright      2020 XOOPS Project (https://xooops.org)
16
 * @license        GPL 2.0 or later
17
 * @package        wggithub
18
 * @since          1.0
19
 * @min_xoops      2.5.10
20
 * @author         Goffy - XOOPS Development Team - Email:<[email protected]> - Website:<https://wedega.com>
21
 */
22
23
use Xmf\Request;
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use XoopsModules\Wggithub;
25
use XoopsModules\Wggithub\Constants;
26
use XoopsModules\Wggithub\Common;
27
28
require __DIR__ . '/header.php';
29
// It recovered the value of argument op in URL$
30
$op    = Request::getCmd('op', 'list');
31
$rmId  = Request::getInt('rm_id');
32
$start = Request::getInt('start', 0);
33
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
34
$GLOBALS['xoopsTpl']->assign('start', $start);
35
$GLOBALS['xoopsTpl']->assign('limit', $limit);
36
37
switch ($op) {
38
    case 'list':
39
    default:
40
        // Define Stylesheet
41
        $GLOBALS['xoTheme']->addStylesheet($style, null);
42
        $templateMain = 'wggithub_admin_readmes.tpl';
43
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('readmes.php'));
44
45
        $filterValue = '';
46
        $crReadmes = new \CriteriaCompo();
0 ignored issues
show
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
        if ('filter' == $op) {
48
            $crRepositories = new \CriteriaCompo();
49
            $operand = Request::getInt('filter_operand', 0);
50
            $filterField = Request::getString('filter_field', '');
51
            $filterValue = Request::getString('filter_value', 'none');
52
            if (Constants::FILTER_OPERAND_EQUAL == $operand) {
53
                $crRepositories->add(new Criteria($filterField, $filterValue));
0 ignored issues
show
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
            } elseif (Constants::FILTER_OPERAND_LIKE == $operand) {
55
                $crRepositories->add(new Criteria($filterField, "%$filterValue%", 'LIKE'));
56
            }
57
            $repositoriesCount = $repositoriesHandler->getCount($crRepositories);
58
            $in = [];
59
            $in[] = 0; //in order to get 'no result' if no repo is matching
60
            if ($repositoriesCount > 0) {
61
                $repositoriesAll = $repositoriesHandler->getAll($crRepositories);
62
                foreach (\array_keys($repositoriesAll) as $i) {
63
                    $in[] = $i;
64
                }
65
            }
66
            $crReadmes->add(new Criteria('rm_repoid', '(' . \implode(',', $in) . ')', 'IN'));
67
        }
68
        $crReadmes->setStart($start);
69
        $crReadmes->setLimit($limit);
70
        $readmesCount = $readmesHandler->getCount($crReadmes);
71
        $readmesAll = $readmesHandler->getAll($crReadmes);
72
        $GLOBALS['xoopsTpl']->assign('readmes_count', $readmesCount);
73
        $GLOBALS['xoopsTpl']->assign('wggithub_url', WGGITHUB_URL);
74
        $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', WGGITHUB_UPLOAD_URL);
75
        // Table view readmes
76
        if ($readmesCount > 0) {
77
            foreach (\array_keys($readmesAll) as $i) {
78
                $readme = $readmesAll[$i]->getValuesReadmes();
79
                $GLOBALS['xoopsTpl']->append('readmes_list', $readme);
80
                unset($readme);
81
            }
82
            // Display Navigation
83
            if ($readmesCount > $limit) {
84
                include_once \XOOPS_ROOT_PATH . '/class/pagenav.php';
0 ignored issues
show
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
85
                $pagenav = new \XoopsPageNav($readmesCount, $limit, $start, 'start', 'op=list&limit=' . $limit);
0 ignored issues
show
The type XoopsPageNav was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
                $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
87
            }
88
        } else {
89
            if ('filter' == $op) {
90
                $GLOBALS['xoopsTpl']->assign('noData', \_AM_WGGITHUB_THEREARENT_READMES_FILTER);
91
            } else {
92
                $GLOBALS['xoopsTpl']->assign('noData', \_AM_WGGITHUB_THEREARENT_READMES);
93
            }
94
        }
95
        $form = $readmesHandler->getFormFilterReadmes(false, $start, $limit, $filterValue);
96
        $GLOBALS['xoopsTpl']->assign('formFilter', $form->render());
97
        break;
98
    case 'save':
99
        // Security Check
100
        if (!$GLOBALS['xoopsSecurity']->check()) {
101
            \redirect_header('readmes.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
0 ignored issues
show
The function redirect_header 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

101
            /** @scrutinizer ignore-call */ 
102
            \redirect_header('readmes.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
Loading history...
102
        }
103
        if ($rmId > 0) {
104
            $readmesObj = $readmesHandler->get($rmId);
105
        } else {
106
            $readmesObj = $readmesHandler->create();
107
        }
108
        // Set Vars
109
        $readmesObj->setVar('rm_repoid', Request::getInt('rm_repoid', 0));
110
        $readmesObj->setVar('rm_name', Request::getString('rm_name', ''));
111
        $readmesObj->setVar('rm_type', Request::getString('rm_type', ''));
112
        $readmesObj->setVar('rm_content', Request::getString('rm_content', ''));
113
        $readmesObj->setVar('rm_encoding', Request::getString('rm_encoding', ''));
114
        $readmesObj->setVar('rm_downloadurl', Request::getString('rm_downloadurl', ''));
115
        $readmesObj->setVar('rm_baseurl', Request::getString('rm_baseurl', ''));
116
        $readmeDatecreatedObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('rm_datecreated'));
0 ignored issues
show
The constant _SHORTDATESTRING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
        $readmesObj->setVar('rm_datecreated', $readmeDatecreatedObj->getTimestamp());
118
        $readmesObj->setVar('rm_submitter', Request::getInt('rm_submitter', 0));
119
        // Insert Data
120
        if ($readmesHandler->insert($readmesObj)) {
121
            \redirect_header('readmes.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_AM_WGGITHUB_FORM_OK);
122
        }
123
        // Get Form
124
        $GLOBALS['xoopsTpl']->assign('error', $readmesObj->getHtmlErrors());
125
        $form = $readmesObj->getFormReadmes(false, $start, $limit);
126
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
127
        break;
128
    case 'edit':
129
        $templateMain = 'wggithub_admin_readmes.tpl';
130
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('readmes.php'));
131
        $adminObject->addItemButton(\_AM_WGGITHUB_READMES_LIST, 'readmes.php', 'list');
132
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
133
        // Get Form
134
        $readmesObj = $readmesHandler->get($rmId);
135
        $form = $readmesObj->getFormReadmes(false, $start, $limit);
136
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
137
        break;
138
    case 'delete':
139
        $templateMain = 'wggithub_admin_readmes.tpl';
140
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('readmes.php'));
141
        $readmesObj = $readmesHandler->get($rmId);
142
        $rmName = $readmesObj->getVar('rm_name');
143
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
144
            if (!$GLOBALS['xoopsSecurity']->check()) {
145
                \redirect_header('readmes.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
146
            }
147
            if ($readmesHandler->delete($readmesObj)) {
148
                \redirect_header('readmes.php', 3, \_AM_WGGITHUB_FORM_DELETE_OK);
149
            } else {
150
                $GLOBALS['xoopsTpl']->assign('error', $readmesObj->getHtmlErrors());
151
            }
152
        } else {
153
            $xoopsconfirm = new Common\XoopsConfirm(
154
                ['ok' => 1, 'rm_id' => $rmId, 'op' => 'delete'],
155
                $_SERVER['REQUEST_URI'],
156
                \sprintf(\_AM_WGGITHUB_FORM_SURE_DELETE, $readmesObj->getVar('rm_name')));
157
            $form = $xoopsconfirm->getFormXoopsConfirm();
158
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
159
        }
160
        break;
161
}
162
require __DIR__ . '/footer.php';
163