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