ggoffy /
wggithub
| 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
|
|||||||
| 24 | use XoopsModules\Wggithub; |
||||||
| 25 | use XoopsModules\Wggithub\{
|
||||||
| 26 | Constants, |
||||||
| 27 | Helper, |
||||||
| 28 | Github\GithubClient |
||||||
| 29 | }; |
||||||
| 30 | |||||||
| 31 | require __DIR__ . '/header.php'; |
||||||
| 32 | $GLOBALS['xoopsOption']['template_main'] = 'wggithub_index.tpl'; |
||||||
| 33 | include_once \XOOPS_ROOT_PATH . '/header.php'; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 34 | |||||||
| 35 | // Permissions |
||||||
| 36 | $permGlobalView = $permissionsHandler->getPermGlobalView(); |
||||||
| 37 | if (!$permGlobalView) {
|
||||||
| 38 | $GLOBALS['xoopsTpl']->assign('error', _NOPERM);
|
||||||
|
0 ignored issues
–
show
|
|||||||
| 39 | require __DIR__ . '/footer.php'; |
||||||
| 40 | } |
||||||
| 41 | $permGlobalRead = $permissionsHandler->getPermGlobalRead(); |
||||||
| 42 | $permReadmeUpdate = $permissionsHandler->getPermReadmeUpdate(); |
||||||
| 43 | |||||||
| 44 | $op = Request::getCmd('op', 'list');
|
||||||
| 45 | $filterRelease = Request::getString('frelease', 'any');
|
||||||
| 46 | $filterSortby = Request::getString('fsortby', 'update');
|
||||||
| 47 | $repoId = Request::getInt('repo_id', 0);
|
||||||
| 48 | |||||||
| 49 | $GLOBALS['xoopsTpl']->assign('frelease', $filterRelease);
|
||||||
| 50 | $GLOBALS['xoopsTpl']->assign('fsortby', $filterSortby);
|
||||||
| 51 | |||||||
| 52 | // Define Stylesheet |
||||||
| 53 | $GLOBALS['xoTheme']->addStylesheet($style, null); |
||||||
| 54 | $GLOBALS['xoTheme']->addStylesheet(\WGGITHUB_URL . '/assets/css/tabs.css', null); |
||||||
| 55 | $keywords = []; |
||||||
| 56 | // |
||||||
| 57 | $GLOBALS['xoopsTpl']->assign('xoops_icons32_url', XOOPS_ICONS32_URL);
|
||||||
| 58 | $GLOBALS['xoopsTpl']->assign('wggithub_url', \WGGITHUB_URL);
|
||||||
| 59 | $GLOBALS['xoopsTpl']->assign('wggithub_image_url', \WGGITHUB_IMAGE_URL);
|
||||||
| 60 | // |
||||||
| 61 | $GLOBALS['xoopsTpl']->assign('permReadmeUpdate', $permReadmeUpdate);
|
||||||
| 62 | $GLOBALS['xoopsTpl']->assign('permGlobalRead', $permGlobalRead);
|
||||||
| 63 | |||||||
| 64 | $dirStart = []; |
||||||
| 65 | $dirLimit = []; |
||||||
| 66 | |||||||
| 67 | switch ($op) {
|
||||||
| 68 | case 'show': |
||||||
| 69 | if ($repoId > 0) {
|
||||||
| 70 | $GLOBALS['xoopsTpl']->assign('showSingle', true);
|
||||||
| 71 | $repositoriesObj = $repositoriesHandler->get($repoId); |
||||||
| 72 | $repo = $repositoriesObj->getValuesRepositories(); |
||||||
| 73 | $repo['readme_val'] = ['content_clean' => \_MA_WGGITHUB_README_NOFILE]; |
||||||
| 74 | if ($repositoriesObj->getVar('repo_readme') > 0) {
|
||||||
| 75 | $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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 76 | $crReadmes->add(new \Criteria('rm_repoid', $repoId));
|
||||||
|
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 77 | $readmesAll = $readmesHandler->getAll($crReadmes); |
||||||
| 78 | foreach ($readmesAll as $readme) {
|
||||||
| 79 | $repo['readme_val'] = $readme->getValuesReadmes(); |
||||||
| 80 | } |
||||||
| 81 | unset($crReadmes, $readmesAll); |
||||||
| 82 | } |
||||||
| 83 | if ($repositoriesObj->getVar('repo_prerelease') > 0 || $repositoriesObj->getVar('repo_release') > 0) {
|
||||||
| 84 | //$repos[$j]['releases'] = []; |
||||||
| 85 | $crReleases = new \CriteriaCompo(); |
||||||
| 86 | $crReleases->add(new \Criteria('rel_repoid', $repoId));
|
||||||
| 87 | $releasesAll = $releasesHandler->getAll($crReleases); |
||||||
| 88 | foreach ($releasesAll as $release) {
|
||||||
| 89 | $repo['releases'][] = $release->getValuesReleases(); |
||||||
| 90 | } |
||||||
| 91 | unset($crReleases, $releasesAll); |
||||||
| 92 | } |
||||||
| 93 | unset($repositoriesAll); |
||||||
| 94 | $GLOBALS['xoopsTpl']->assign('repo', $repo);
|
||||||
| 95 | } |
||||||
| 96 | break; |
||||||
| 97 | case 'list': |
||||||
| 98 | case 'apiexceed': |
||||||
| 99 | default: |
||||||
| 100 | //check number of directories with auto_update |
||||||
| 101 | $crDirectories = new \CriteriaCompo(); |
||||||
| 102 | $crDirectories->add(new \Criteria('dir_autoupdate', 1));
|
||||||
| 103 | $directoriesCount = $directoriesHandler->getCount($crDirectories); |
||||||
| 104 | if ($directoriesCount > 0) {
|
||||||
| 105 | //check number of API calls |
||||||
| 106 | $lastUpdate = 0; |
||||||
| 107 | $crLogs = new \CriteriaCompo(); |
||||||
| 108 | $crLogs->add(new \Criteria('log_datecreated', (\time() - 3600), '>'));
|
||||||
| 109 | $logsCount = $logsHandler->getCount($crLogs); |
||||||
| 110 | if ($permGlobalRead && $logsCount < 60 && 'list' === $op) {
|
||||||
| 111 | $githubClient = GithubClient::getInstance(); |
||||||
| 112 | $githubClient->executeUpdate(); |
||||||
| 113 | } |
||||||
| 114 | unset($crLogs); |
||||||
| 115 | } |
||||||
| 116 | unset($crDirectories); |
||||||
| 117 | $crLogs = new \CriteriaCompo(); |
||||||
| 118 | $crLogs->add(new \Criteria('log_type', Constants::LOG_TYPE_UPDATE_END));
|
||||||
| 119 | $crLogs->add(new \Criteria('log_result', 'OK'));
|
||||||
| 120 | $crLogs->setStart(0); |
||||||
| 121 | $crLogs->setLimit(1); |
||||||
| 122 | $crLogs->setSort('log_id');
|
||||||
| 123 | $crLogs->setOrder('DESC');
|
||||||
| 124 | $logsAll = $logsHandler->getAll($crLogs); |
||||||
| 125 | foreach (\array_keys($logsAll) as $i) {
|
||||||
| 126 | $lastUpdate = $logsAll[$i]->getVar('log_datecreated');
|
||||||
| 127 | $GLOBALS['xoopsTpl']->assign('lastUpdate', \formatTimestamp($lastUpdate, 'm'));
|
||||||
|
0 ignored issues
–
show
The function
formatTimestamp 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
Loading history...
|
|||||||
| 128 | } |
||||||
| 129 | unset($crLogs); |
||||||
| 130 | $crLogs = new \CriteriaCompo(); |
||||||
| 131 | $crLogs->setStart(0); |
||||||
| 132 | $crLogs->setLimit(1); |
||||||
| 133 | $crLogs->setSort('log_id');
|
||||||
| 134 | $crLogs->setOrder('DESC');
|
||||||
| 135 | $logsAll = $logsHandler->getAll($crLogs); |
||||||
| 136 | foreach (\array_keys($logsAll) as $i) {
|
||||||
| 137 | if ($lastUpdate < $logsAll[$i]->getVar('log_datecreated')) {
|
||||||
| 138 | if (\strpos($logsAll[$i]->getVar('log_result'), 'API rate limit exceeded') > 0) {
|
||||||
| 139 | $GLOBALS['xoopsTpl']->assign('apiexceed', true);
|
||||||
| 140 | } else {
|
||||||
| 141 | $GLOBALS['xoopsTpl']->assign('apierror', true);
|
||||||
| 142 | } |
||||||
| 143 | } |
||||||
| 144 | } |
||||||
| 145 | unset($crLogs); |
||||||
| 146 | |||||||
| 147 | $menu = Request::getInt('menu', 0);
|
||||||
| 148 | |||||||
| 149 | $crDirectories = new \CriteriaCompo(); |
||||||
| 150 | $crDirectories->add(new \Criteria('dir_online', 1));
|
||||||
| 151 | $crDirectories->setSort('dir_weight ASC, dir_id');
|
||||||
| 152 | $crDirectories->setOrder('ASC');
|
||||||
| 153 | $directoriesCount = $directoriesHandler->getCount($crDirectories); |
||||||
| 154 | $GLOBALS['xoopsTpl']->assign('directoriesCount', $directoriesCount);
|
||||||
| 155 | if ($directoriesCount > 0) {
|
||||||
| 156 | $directoriesAll = $directoriesHandler->getAll($crDirectories); |
||||||
| 157 | // Get All Directories |
||||||
| 158 | $directories = []; |
||||||
| 159 | foreach (\array_keys($directoriesAll) as $i) {
|
||||||
| 160 | $directories[$i] = $directoriesAll[$i]->getValuesDirectories(); |
||||||
| 161 | $dirName = $directoriesAll[$i]->getVar('dir_name');
|
||||||
| 162 | $dirFilterRelease = (bool)$directoriesAll[$i]->getVar('dir_filterrelease');
|
||||||
| 163 | $repos = []; |
||||||
| 164 | $crRepositories = new \CriteriaCompo(); |
||||||
| 165 | //first block/parentheses |
||||||
| 166 | $crRepo1 = new \CriteriaCompo(); |
||||||
| 167 | $crRepo1->add(new \Criteria('repo_user', $dirName));
|
||||||
| 168 | $crRepositories->add($crRepo1); |
||||||
| 169 | //second |
||||||
| 170 | $crRepo2 = new \CriteriaCompo(); |
||||||
| 171 | $crRepo2->add(new \Criteria('repo_status', Constants::STATUS_UPDATED));
|
||||||
| 172 | $crRepo2->add(new \Criteria('repo_status', Constants::STATUS_UPTODATE), 'OR');
|
||||||
| 173 | $crRepositories->add($crRepo2); |
||||||
| 174 | //third |
||||||
| 175 | $autoApproved = (int)$helper->getConfig('autoapproved');
|
||||||
| 176 | if (!$autoApproved) {
|
||||||
| 177 | //third |
||||||
| 178 | $crRepo3 = new \CriteriaCompo(); |
||||||
| 179 | $crRepo3->add(new \Criteria('repo_approved', 1));
|
||||||
| 180 | $crRepositories->add($crRepo3); |
||||||
| 181 | } |
||||||
| 182 | |||||||
| 183 | $repositoriesCountTotal = $repositoriesHandler->getCount($crRepositories); |
||||||
| 184 | //fourth |
||||||
| 185 | if ('any' === $filterRelease && $dirFilterRelease) {
|
||||||
| 186 | $crRepo4 = new \CriteriaCompo(); |
||||||
| 187 | $crRepo4->add(new \Criteria('repo_prerelease', 1));
|
||||||
| 188 | $crRepo4->add(new \Criteria('repo_release', 1), 'OR');
|
||||||
| 189 | $crRepositories->add($crRepo4); |
||||||
| 190 | } elseif ('final' === $filterRelease && $dirFilterRelease) {
|
||||||
| 191 | $crRepo4 = new \CriteriaCompo(); |
||||||
| 192 | $crRepo4->add(new \Criteria('repo_release', 1));
|
||||||
| 193 | $crRepositories->add($crRepo4); |
||||||
| 194 | } |
||||||
| 195 | $repositoriesCount = $repositoriesHandler->getCount($crRepositories); |
||||||
| 196 | |||||||
| 197 | $dirId = Request::getInt('dirId', 0);
|
||||||
| 198 | $dirStart[$i] = 0; |
||||||
| 199 | $dirLimit[$i] = $helper->getConfig('userpager');
|
||||||
| 200 | if ($i == $dirId) {
|
||||||
| 201 | $dirStart[$i] = Request::getInt('start', 0);
|
||||||
| 202 | $dirLimit[$i] = Request::getInt('limit', 0);
|
||||||
| 203 | } |
||||||
| 204 | |||||||
| 205 | $crRepositories->setStart($dirStart[$i]); |
||||||
| 206 | $crRepositories->setLimit($dirLimit[$i]); |
||||||
| 207 | switch ($filterSortby) {
|
||||||
| 208 | case 'name': |
||||||
| 209 | default: |
||||||
| 210 | $crRepositories->setSort('repo_name');
|
||||||
| 211 | $crRepositories->setOrder('ASC');
|
||||||
| 212 | break; |
||||||
| 213 | case 'update': |
||||||
| 214 | $crRepositories->setSort('repo_updatedat');
|
||||||
| 215 | $crRepositories->setOrder('DESC');
|
||||||
| 216 | break; |
||||||
| 217 | } |
||||||
| 218 | if ($repositoriesCount > 0) {
|
||||||
| 219 | $repositoriesAll = $repositoriesHandler->getAll($crRepositories); |
||||||
| 220 | foreach (\array_keys($repositoriesAll) as $j) {
|
||||||
| 221 | $repoId = $repositoriesAll[$j]->getVar('repo_id');
|
||||||
| 222 | $repos[$j] = $repositoriesAll[$j]->getValuesRepositories(); |
||||||
| 223 | $repos[$j]['readme'] = ['content_clean' => \_MA_WGGITHUB_README_NOFILE]; |
||||||
| 224 | if ($repositoriesAll[$j]->getVar('repo_readme') > 0) {
|
||||||
| 225 | $crReadmes = new \CriteriaCompo(); |
||||||
| 226 | $crReadmes->add(new \Criteria('rm_repoid', $repoId));
|
||||||
| 227 | $readmesAll = $readmesHandler->getAll($crReadmes); |
||||||
| 228 | foreach ($readmesAll as $readme) {
|
||||||
| 229 | $repos[$j]['readme'] = $readme->getValuesReadmes(); |
||||||
| 230 | } |
||||||
| 231 | unset($crReadmes, $readmesAll); |
||||||
| 232 | } |
||||||
| 233 | if ($repositoriesAll[$j]->getVar('repo_prerelease') > 0 || $repositoriesAll[$j]->getVar('repo_release') > 0) {
|
||||||
| 234 | //$repos[$j]['releases'] = []; |
||||||
| 235 | $crReleases = new \CriteriaCompo(); |
||||||
| 236 | $crReleases->add(new \Criteria('rel_repoid', $repoId));
|
||||||
| 237 | $releasesAll = $releasesHandler->getAll($crReleases); |
||||||
| 238 | foreach ($releasesAll as $release) {
|
||||||
| 239 | $repos[$j]['releases'][] = $release->getValuesReleases(); |
||||||
| 240 | } |
||||||
| 241 | unset($crReleases, $releasesAll); |
||||||
| 242 | } |
||||||
| 243 | } |
||||||
| 244 | unset($repositoriesAll); |
||||||
| 245 | } |
||||||
| 246 | unset($crRepo1, $crRepo2, $crRepo3, $crRepo4, $crRepositories); |
||||||
| 247 | if ($repositoriesCount === $repositoriesCountTotal) {
|
||||||
| 248 | $directories[$i]['countRepos'] = \str_replace(['%s', '%t'], [$dirName, $repositoriesCountTotal], \_MA_WGGITHUB_REPOSITORIES_COUNT2); |
||||||
| 249 | } else {
|
||||||
| 250 | $directories[$i]['countRepos'] = \str_replace(['%s', '%r', '%t'], [$dirName, $repositoriesCount, $repositoriesCountTotal], \_MA_WGGITHUB_REPOSITORIES_COUNT1); |
||||||
| 251 | } |
||||||
| 252 | $directories[$i]['repos'] = $repos; |
||||||
| 253 | $directories[$i]['previousRepos'] = $dirStart[$i] > 0; |
||||||
| 254 | $directories[$i]['previousOp'] = '&dirId=' . $i . '&start=' . ($dirStart[$i] - $dirLimit[$i]) . '&limit=' . $dirLimit[$i] . '&frelease=' . $filterRelease . '&fsortby=' . $filterSortby; |
||||||
| 255 | $directories[$i]['nextRepos'] = ($repositoriesCount - $dirStart[$i]) > $dirLimit[$i]; |
||||||
| 256 | $directories[$i]['nextOp'] = '&dirId=' . $i . '&start=' . ($dirStart[$i] + $dirLimit[$i]) . '&limit=' . $dirLimit[$i] . '&frelease=' . $filterRelease . '&fsortby=' . $filterSortby; |
||||||
| 257 | $GLOBALS['xoopsTpl']->assign('menu', $menu);
|
||||||
| 258 | $GLOBALS['xoopsTpl']->assign('directories', $directories);
|
||||||
| 259 | } |
||||||
| 260 | |||||||
| 261 | unset($crDirectories, $directories); |
||||||
| 262 | |||||||
| 263 | $GLOBALS['xoopsTpl']->assign('lang_thereare', \sprintf(\_MA_WGGITHUB_INDEX_THEREARE, $directoriesCount));
|
||||||
| 264 | $GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby'));
|
||||||
| 265 | $GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col'));
|
||||||
| 266 | $GLOBALS['xoopsTpl']->assign('showBtnAll', (Constants::FILTER_TYPE_ALL == $helper->getConfig('filter_type')));
|
||||||
| 267 | } |
||||||
| 268 | |||||||
| 269 | break; |
||||||
| 270 | case 'update_dir': |
||||||
| 271 | // Permissions |
||||||
| 272 | if (!$permGlobalRead) {
|
||||||
| 273 | $GLOBALS['xoopsTpl']->assign('error', \_NOPERM);
|
||||||
| 274 | require __DIR__ . '/footer.php'; |
||||||
| 275 | } |
||||||
| 276 | $dirName = Request::getString('dir_name', '');
|
||||||
| 277 | $redir = 'index.php?op=list_afterupdate&frelease=' . $filterRelease . '&fsortby=' . $filterSortby; |
||||||
| 278 | $githubClient = GithubClient::getInstance(); |
||||||
| 279 | $result = $githubClient->executeUpdate($dirName); |
||||||
| 280 | if ($result) {
|
||||||
| 281 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_SUCCESS); |
||||||
|
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
Loading history...
|
|||||||
| 282 | } else {
|
||||||
| 283 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_ERROR_API); |
||||||
| 284 | } |
||||||
| 285 | |||||||
| 286 | break; |
||||||
| 287 | case 'update_readme': |
||||||
| 288 | // Permissions |
||||||
| 289 | if (!$permReadmeUpdate) {
|
||||||
| 290 | $GLOBALS['xoopsTpl']->assign('error', \_NOPERM);
|
||||||
| 291 | require __DIR__ . '/footer.php'; |
||||||
| 292 | } |
||||||
| 293 | $repoId = Request::getInt('repo_id', 0);
|
||||||
| 294 | $repoUser = Request::getString('repo_user', 'none');
|
||||||
| 295 | $repoName = Request::getString('repo_name', 'none');
|
||||||
| 296 | $redir = 'index.php?op=list_afterupdate&frelease=' . $filterRelease . '&fsortby=' . $filterSortby; |
||||||
| 297 | $result = $helper->getHandler('Readmes')->updateReadmes($repoId, $repoUser, $repoName);
|
||||||
| 298 | if ($result) {
|
||||||
| 299 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_SUCCESS); |
||||||
| 300 | } else {
|
||||||
| 301 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_ERROR_API); |
||||||
| 302 | } |
||||||
| 303 | break; |
||||||
| 304 | case 'api_error': |
||||||
| 305 | $error = Request::getString('message') . '<br>' . Request::getString('url');
|
||||||
| 306 | $GLOBALS['xoopsTpl']->assign('error', $error);
|
||||||
| 307 | break; |
||||||
| 308 | } |
||||||
| 309 | |||||||
| 310 | $GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type'));
|
||||||
| 311 | // Breadcrumbs |
||||||
| 312 | $xoBreadcrumbs[] = ['title' => \_MA_WGGITHUB_INDEX]; |
||||||
| 313 | // Keywords |
||||||
| 314 | wggithubMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords));
|
||||||
| 315 | unset($keywords); |
||||||
| 316 | // Description |
||||||
| 317 | wggithubMetaDescription(\_MA_WGGITHUB_INDEX_DESC); |
||||||
| 318 | $GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGGITHUB_URL.'/index.php');
|
||||||
| 319 | $GLOBALS['xoopsTpl']->assign('xoops_icons32_url', XOOPS_ICONS32_URL);
|
||||||
| 320 | $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', \WGGITHUB_UPLOAD_URL);
|
||||||
| 321 | require __DIR__ . '/footer.php'; |
||||||
| 322 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths