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