Passed
Push — master ( dbde9b...3f3727 )
by Goffy
03:56
created

admin/directories.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\ {
26
    Common,
27
    Github\GithubClient
28
};
29
30
require __DIR__ . '/header.php';
31
// It recovered the value of argument op in URL$
32
$op    = Request::getCmd('op', 'list');
33
$dirId = Request::getInt('dir_id');
34
$start = Request::getInt('start', 0);
35
$limit = Request::getInt('limit', $helper->getConfig('adminpager'));
36
$GLOBALS['xoopsTpl']->assign('start', $start);
37
$GLOBALS['xoopsTpl']->assign('limit', $limit);
38
39
switch ($op) {
40
    case 'list':
41
    default:
42
        // Define Stylesheet
43
        $GLOBALS['xoTheme']->addStylesheet($style, null);
44
        $GLOBALS['xoTheme']->addScript(\WGGITHUB_URL . '/assets/js/jquery-ui.js');
45
        $GLOBALS['xoTheme']->addScript(\WGGITHUB_URL . '/assets/js/sortable.js');
46
        $templateMain = 'wggithub_admin_directories.tpl';
47
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directories.php'));
48
        $adminObject->addItemButton(\_AM_WGGITHUB_ADD_DIRECTORY, 'directories.php?op=new', 'add');
49
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
50
        $directoriesCount = $directoriesHandler->getCountDirectories();
51
        $directoriesAll = $directoriesHandler->getAllDirectories($start, $limit);
52
        $GLOBALS['xoopsTpl']->assign('directories_count', $directoriesCount);
53
        $GLOBALS['xoopsTpl']->assign('wggithub_url', \WGGITHUB_URL);
54
        $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', \WGGITHUB_UPLOAD_URL);
55
        $GLOBALS['xoopsTpl']->assign('wggithub_icons_url_16', \WGGITHUB_ICONS_URL . '/16');
56
        // Table view directories
57
        if ($directoriesCount > 0) {
58
            foreach (\array_keys($directoriesAll) as $i) {
59
                $directory = $directoriesAll[$i]->getValuesDirectories();
60
                $GLOBALS['xoopsTpl']->append('directories_list', $directory);
61
                unset($directory);
62
            }
63
            // Display Navigation
64
            if ($directoriesCount > $limit) {
65
                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...
66
                $pagenav = new \XoopsPageNav($directoriesCount, $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...
67
                $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4));
68
            }
69
        } else {
70
            $GLOBALS['xoopsTpl']->assign('errors', [\_AM_WGGITHUB_THEREARENT_DIRECTORIES]);
71
        }
72
        break;
73
    case 'new':
74
        $templateMain = 'wggithub_admin_directories.tpl';
75
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directories.php'));
76
        $adminObject->addItemButton(\_AM_WGGITHUB_DIRECTORIES_LIST, 'directories.php', 'list');
77
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
78
        // Form Create
79
        $directoriesObj = $directoriesHandler->create();
80
        $form = $directoriesObj->getFormDirectories(false, $start, $limit);
81
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
82
        break;
83
    case 'save':
84
        // Security Check
85
        if (!$GLOBALS['xoopsSecurity']->check()) {
86
            \redirect_header('directories.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

86
            /** @scrutinizer ignore-call */ \redirect_header('directories.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
Loading history...
87
        }
88
        if ($dirId > 0) {
89
            $directoriesObj = $directoriesHandler->get($dirId);
90
        } else {
91
            $directoriesObj = $directoriesHandler->create();
92
        }
93
        // Set Vars
94
        $directoriesObj->setVar('dir_name', Request::getString('dir_name', ''));
95
        $directoriesObj->setVar('dir_descr', Request::getText('dir_descr', ''));
96
        $directoriesObj->setVar('dir_type', Request::getInt('dir_type', 0));
97
        $directoriesObj->setVar('dir_content', Request::getInt('dir_content', 0));
98
        $directoriesObj->setVar('dir_autoupdate', Request::getInt('dir_autoupdate', 0));
99
        $directoriesObj->setVar('dir_online', Request::getInt('dir_online', 0));
100
        $directoriesObj->setVar('dir_filterrelease', Request::getInt('dir_filterrelease', 0));
101
        $directoryDatecreatedObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('dir_datecreated'));
0 ignored issues
show
The constant _SHORTDATESTRING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
        $directoriesObj->setVar('dir_datecreated', $directoryDatecreatedObj->getTimestamp());
103
        $directoriesObj->setVar('dir_submitter', Request::getInt('dir_submitter', 0));
104
        // Insert Data
105
        if ($directoriesHandler->insert($directoriesObj)) {
106
            \redirect_header('directories.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_AM_WGGITHUB_FORM_OK);
107
        }
108
        // Get Form
109
        $GLOBALS['xoopsTpl']->assign('error', $directoriesObj->getHtmlErrors());
110
        $form = $directoriesObj->getFormDirectories(false, $start, $limit);
111
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
112
        break;
113
    case 'edit':
114
        $templateMain = 'wggithub_admin_directories.tpl';
115
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directories.php'));
116
        $adminObject->addItemButton(\_AM_WGGITHUB_ADD_DIRECTORY, 'directories.php?op=new', 'add');
117
        $adminObject->addItemButton(\_AM_WGGITHUB_DIRECTORIES_LIST, 'directories.php', 'list');
118
        $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left'));
119
        // Get Form
120
        $directoriesObj = $directoriesHandler->get($dirId);
121
        $form = $directoriesObj->getFormDirectories(false, $start, $limit);
122
        $GLOBALS['xoopsTpl']->assign('form', $form->render());
123
        break;
124
    case 'delete':
125
        $templateMain = 'wggithub_admin_directories.tpl';
126
        $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('directories.php'));
127
        $directoriesObj = $directoriesHandler->get($dirId);
128
        $dirName = $directoriesObj->getVar('dir_name');
129
        if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) {
130
            if (!$GLOBALS['xoopsSecurity']->check()) {
131
                \redirect_header('directories.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors()));
132
            }
133
            $errors = [];
134
            //delete all related data
135
            $crRepositories = 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...
136
            $crRepositories->add(new \Criteria('repo_user', $dirName));
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...
137
            $repositoriesAll = $repositoriesHandler->getAll($crRepositories);
138
            foreach (\array_keys($repositoriesAll) as $i) {
139
                $repoId = $repositoriesAll[$i]->getVar('repo_id');
140
                if ($repositoriesAll[$i]->getVar('repo_readme') > 0) {
141
                    //delete all readmes
142
                    $crReadmes = new \CriteriaCompo();
143
                    $crReadmes->add(new \Criteria('rm_repoid', $repoId));
144
                    if (!$readmesHandler->deleteAll($crReadmes)) {
145
                        $errors[] = \_AM_WGGITHUB_ERROR_DELETE_DATA . ' READMES';
146
                    }
147
                }
148
                if ($repositoriesAll[$i]->getVar('repo_release') > 0 || $repositoriesAll[$i]->getVar('repo_prerelease') > 0) {
149
                    //delete all releases
150
                    $crReleases = new \CriteriaCompo();
151
                    $crReleases->add(new \Criteria('rel_repoid', $repoId));
152
                    if (!$releasesHandler->deleteAll($crReleases)) {
153
                        $errors[] = \_AM_WGGITHUB_ERROR_DELETE_DATA . ' RELEASES';
154
                    }
155
                }
156
            }
157
            if (!$repositoriesHandler->deleteAll($crRepositories)) {
158
                $errors[] = \_AM_WGGITHUB_ERROR_DELETE_DATA . ' REPOSITORIES';
159
            }
160
            unset($crReadmes, $crReleases, $repositoriesAll);
161
            //delete directory
162
            if (!$directoriesHandler->delete($directoriesObj)) {
163
                $errors[] = \_AM_WGGITHUB_ERROR_DELETE_DATA . ' DIRECTORIES - ' . $directoriesObj->getHtmlErrors();
164
            }
165
            if (0 == \count($errors)) {
166
                \redirect_header('directories.php', 3, \_AM_WGGITHUB_FORM_DELETE_OK);
167
            } else {
168
                $GLOBALS['xoopsTpl']->assign('errors', $errors);
169
            }
170
        } else {
171
            $xoopsconfirm = new Common\XoopsConfirm(
172
                ['ok' => 1, 'dir_id' => $dirId, 'op' => 'delete'],
173
                $_SERVER['REQUEST_URI'],
174
                \sprintf(\_AM_WGGITHUB_FORM_SURE_DELETE, $dirName));
175
            $form = $xoopsconfirm->getFormXoopsConfirm();
176
            $GLOBALS['xoopsTpl']->assign('form', $form->render());
177
        }
178
        break;
179
    case 'readgh':
180
        $directoriesObj = $directoriesHandler->get($dirId);
181
        $dirName = $directoriesObj->getVar('dir_name');
182
        $githubClient = GithubClient::getInstance();
183
        $result = $githubClient->executeUpdate($dirName);
184
        $redir = 'directories.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit;
185
        if ($result) {
186
            \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_SUCCESS);
187
        } else {
188
            \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_ERROR_API);
189
        }
190
        break;
191
    case 'change_yn':
192
        if ($dirId > 0) {
193
            $directoriesObj = $directoriesHandler->get($dirId);
194
            $directoriesObj->setVar(Request::getString('field'), Request::getInt('value', 0));
195
            // Insert Data
196
            if ($directoriesHandler->insert($directoriesObj, true)) {
197
                \redirect_header('directories.php?op=list&amp;start=' . $start . '&amp;limit=' . $limit, 2, \_AM_WGGITHUB_FORM_OK);
198
            }
199
        }
200
        break;
201
    case 'order':
202
        $dorder = $_POST['dorder'];
203
        for ($i = 0, $iMax = \count($dorder); $i < $iMax; $i++) {
204
            $directoriesObj = $directoriesHandler->get($dorder[$i]);
205
            $directoriesObj->setVar('dir_weight', $i + 1);
206
            $directoriesHandler->insert($directoriesObj);
207
        }
208
        break;
209
}
210
require __DIR__ . '/footer.php';
211