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', 'all'); |
||||||
| 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(); |
||||||
|
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...
|
|||||||
| 70 | $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...
|
|||||||
| 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')); |
||||||
|
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...
|
|||||||
| 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 | $directoriesCount = $directoriesHandler->getCount($crDirectories); |
||||||
| 122 | $GLOBALS['xoopsTpl']->assign('directoriesCount', $directoriesCount); |
||||||
| 123 | if ($directoriesCount > 0) { |
||||||
| 124 | $directoriesAll = $directoriesHandler->getAll($crDirectories); |
||||||
| 125 | // Get All Directories |
||||||
| 126 | $directories = []; |
||||||
| 127 | foreach (\array_keys($directoriesAll) as $i) { |
||||||
| 128 | $directories[$i] = $directoriesAll[$i]->getValuesDirectories(); |
||||||
| 129 | $dirName = $directoriesAll[$i]->getVar('dir_name'); |
||||||
| 130 | $dirFilterRelease = (bool)$directoriesAll[$i]->getVar('dir_filterrelease'); |
||||||
| 131 | $repos = []; |
||||||
| 132 | $crRepositories = new \CriteriaCompo(); |
||||||
| 133 | //first block/parentheses |
||||||
| 134 | $crRepo1 = new CriteriaCompo(); |
||||||
| 135 | $crRepo1->add(new Criteria('repo_user', $dirName)); |
||||||
| 136 | $crRepositories->add($crRepo1); |
||||||
| 137 | //second |
||||||
| 138 | $crRepo2 = new CriteriaCompo(); |
||||||
| 139 | $crRepo2->add(new Criteria('repo_status', Constants::STATUS_UPDATED)); |
||||||
| 140 | $crRepo2->add(new Criteria('repo_status', Constants::STATUS_UPTODATE), 'OR'); |
||||||
| 141 | $crRepositories->add($crRepo2); |
||||||
| 142 | $repositoriesCountTotal = $repositoriesHandler->getCount($crRepositories); |
||||||
| 143 | //third |
||||||
| 144 | if ('any' === $filterRelease && $dirFilterRelease) { |
||||||
| 145 | $crRepo3 = new CriteriaCompo(); |
||||||
| 146 | $crRepo3->add(new Criteria('repo_prerelease', 1)); |
||||||
| 147 | $crRepo3->add(new Criteria('repo_release', 1), 'OR'); |
||||||
| 148 | $crRepositories->add($crRepo3); |
||||||
| 149 | } elseif ('final' === $filterRelease && $dirFilterRelease) { |
||||||
| 150 | $crRepo3 = new CriteriaCompo(); |
||||||
| 151 | $crRepo3->add(new Criteria('repo_release', 1)); |
||||||
| 152 | $crRepositories->add($crRepo3); |
||||||
| 153 | } |
||||||
| 154 | $repositoriesCount = $repositoriesHandler->getCount($crRepositories); |
||||||
| 155 | |||||||
| 156 | $crRepositories->setStart($start); |
||||||
| 157 | $crRepositories->setLimit($limit); |
||||||
| 158 | switch ($filterSortby) { |
||||||
| 159 | case 'name': |
||||||
| 160 | default: |
||||||
| 161 | $crRepositories->setSort('repo_name'); |
||||||
| 162 | $crRepositories->setOrder('ASC'); |
||||||
| 163 | break; |
||||||
| 164 | case 'update': |
||||||
| 165 | $crRepositories->setSort('repo_updatedat'); |
||||||
| 166 | $crRepositories->setOrder('DESC'); |
||||||
| 167 | break; |
||||||
| 168 | } |
||||||
| 169 | if ($repositoriesCount > 0) { |
||||||
| 170 | $repositoriesAll = $repositoriesHandler->getAll($crRepositories); |
||||||
| 171 | foreach (\array_keys($repositoriesAll) as $j) { |
||||||
| 172 | $repoId = $repositoriesAll[$j]->getVar('repo_id'); |
||||||
| 173 | $repos[$j] = $repositoriesAll[$j]->getValuesRepositories(); |
||||||
| 174 | $repos[$j]['readme'] = ['content_clean' => _MA_WGGITHUB_README_NOFILE]; |
||||||
| 175 | if ($repositoriesAll[$j]->getVar('repo_readme') > 0) { |
||||||
| 176 | $crReadmes = new \CriteriaCompo(); |
||||||
| 177 | $crReadmes->add(new \Criteria('rm_repoid', $repoId)); |
||||||
| 178 | $readmesAll = $readmesHandler->getAll($crReadmes); |
||||||
| 179 | foreach ($readmesAll as $readme) { |
||||||
| 180 | $repos[$j]['readme'] = $readme->getValuesReadmes(); |
||||||
| 181 | } |
||||||
| 182 | unset($crReadmes, $readmesAll); |
||||||
| 183 | } |
||||||
| 184 | if ($repositoriesAll[$j]->getVar('repo_prerelease') > 0 || $repositoriesAll[$j]->getVar('repo_release') > 0) { |
||||||
| 185 | //$repos[$j]['releases'] = []; |
||||||
| 186 | $crReleases = new \CriteriaCompo(); |
||||||
| 187 | $crReleases->add(new \Criteria('rel_repoid', $repoId)); |
||||||
| 188 | $releasesAll = $releasesHandler->getAll($crReleases); |
||||||
| 189 | foreach ($releasesAll as $release) { |
||||||
| 190 | $repos[$j]['releases'][] = $release->getValuesReleases(); |
||||||
| 191 | } |
||||||
| 192 | unset($crReleases, $releasesAll); |
||||||
| 193 | } |
||||||
| 194 | } |
||||||
| 195 | unset($repositoriesAll); |
||||||
| 196 | } |
||||||
| 197 | unset($crRepo1, $crRepo2, $crRepo3, $crRepositories); |
||||||
| 198 | if ($repositoriesCount === $repositoriesCountTotal) { |
||||||
| 199 | $directories[$i]['countRepos'] = str_replace(['%s', '%t'], [$dirName, $repositoriesCountTotal], _MA_WGGITHUB_REPOSITORIES_COUNT2); |
||||||
| 200 | } else { |
||||||
| 201 | $directories[$i]['countRepos'] = str_replace(['%s', '%r', '%t'], [$dirName, $repositoriesCount, $repositoriesCountTotal], _MA_WGGITHUB_REPOSITORIES_COUNT1); |
||||||
| 202 | } |
||||||
| 203 | $directories[$i]['repos'] = $repos; |
||||||
| 204 | $directories[$i]['previousRepos'] = $start > 0; |
||||||
| 205 | $directories[$i]['previousOp'] = '&start=' . ($start - $limit) . '&limit=' . $limit . '&release=' . $filterRelease . '&sortby=' . $filterSortby; |
||||||
| 206 | $directories[$i]['nextRepos'] = ($repositoriesCount - $start) > $limit; |
||||||
| 207 | $directories[$i]['nextOp'] = '&start=' . ($start + $limit) . '&limit=' . $limit . '&release=' . $filterRelease . '&sortby=' . $filterSortby; |
||||||
| 208 | $GLOBALS['xoopsTpl']->assign('start', $start); |
||||||
| 209 | $GLOBALS['xoopsTpl']->assign('limit', $limit); |
||||||
| 210 | $GLOBALS['xoopsTpl']->assign('menu', $menu); |
||||||
| 211 | $GLOBALS['xoopsTpl']->assign('directories', $directories); |
||||||
| 212 | } |
||||||
| 213 | |||||||
| 214 | unset($crDirectories, $directories); |
||||||
| 215 | // Display Navigation |
||||||
| 216 | if ($directoriesCount > $limit) { |
||||||
| 217 | require_once \XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||||||
| 218 | $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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 219 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
||||||
| 220 | } |
||||||
| 221 | $GLOBALS['xoopsTpl']->assign('lang_thereare', \sprintf(\_MA_WGGITHUB_INDEX_THEREARE, $directoriesCount)); |
||||||
| 222 | $GLOBALS['xoopsTpl']->assign('divideby', $helper->getConfig('divideby')); |
||||||
| 223 | $GLOBALS['xoopsTpl']->assign('numb_col', $helper->getConfig('numb_col')); |
||||||
| 224 | } |
||||||
| 225 | |||||||
| 226 | break; |
||||||
| 227 | case 'update_dir': |
||||||
| 228 | // Permissions |
||||||
| 229 | if (!$permGlobalRead) { |
||||||
| 230 | $GLOBALS['xoopsTpl']->assign('error', \_NOPERM); |
||||||
| 231 | require __DIR__ . '/footer.php'; |
||||||
| 232 | } |
||||||
| 233 | $dirName = Request::getString('dir_name', ''); |
||||||
| 234 | $start = 0; //reset to default |
||||||
| 235 | $limit = Request::getInt('limit', $helper->getConfig('userpager')); |
||||||
| 236 | $redir = 'index.php?op=list_afterupdate&start=' . $start . '&limit=' . $limit . '&release=' . $filterRelease . '&sortby=' . $filterSortby; |
||||||
| 237 | $githubClient = GithubClient::getInstance(); |
||||||
| 238 | $result = $githubClient->executeUpdate($dirName); |
||||||
| 239 | if ($result) { |
||||||
| 240 | \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...
|
|||||||
| 241 | } else { |
||||||
| 242 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_ERROR_API); |
||||||
| 243 | } |
||||||
| 244 | |||||||
| 245 | break; |
||||||
| 246 | case 'update_readme': |
||||||
| 247 | // Permissions |
||||||
| 248 | if (!$permReadmeUpdate) { |
||||||
| 249 | $GLOBALS['xoopsTpl']->assign('error', \_NOPERM); |
||||||
| 250 | require __DIR__ . '/footer.php'; |
||||||
| 251 | } |
||||||
| 252 | $start = 0; //reset to default |
||||||
| 253 | $limit = Request::getInt('limit', $helper->getConfig('userpager')); |
||||||
| 254 | $repoId = Request::getInt('repo_id', 0); |
||||||
| 255 | $repoUser = Request::getString('repo_user', 'none'); |
||||||
| 256 | $repoName = Request::getString('repo_name', 'none'); |
||||||
| 257 | $redir = 'index.php?op=list_afterupdate&start=' . $start . '&limit=' . $limit . '&release=' . $filterRelease . '&sortby=' . $filterSortby; |
||||||
| 258 | $result = $helper->getHandler('Readmes')->updateReadmes($repoId, $repoUser, $repoName); |
||||||
| 259 | if ($result) { |
||||||
| 260 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_SUCCESS); |
||||||
| 261 | } else { |
||||||
| 262 | \redirect_header($redir, 2, \_MA_WGGITHUB_READGH_ERROR_API); |
||||||
| 263 | } |
||||||
| 264 | break; |
||||||
| 265 | } |
||||||
| 266 | |||||||
| 267 | $GLOBALS['xoopsTpl']->assign('table_type', $helper->getConfig('table_type')); |
||||||
| 268 | // Breadcrumbs |
||||||
| 269 | $xoBreadcrumbs[] = ['title' => \_MA_WGGITHUB_INDEX]; |
||||||
| 270 | // Keywords |
||||||
| 271 | wggithubMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords)); |
||||||
| 272 | unset($keywords); |
||||||
| 273 | // Description |
||||||
| 274 | wggithubMetaDescription(\_MA_WGGITHUB_INDEX_DESC); |
||||||
| 275 | $GLOBALS['xoopsTpl']->assign('xoops_mpageurl', WGGITHUB_URL.'/index.php'); |
||||||
| 276 | $GLOBALS['xoopsTpl']->assign('xoops_icons32_url', XOOPS_ICONS32_URL); |
||||||
| 277 | $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', WGGITHUB_UPLOAD_URL); |
||||||
| 278 | require __DIR__ . '/footer.php'; |
||||||
| 279 |
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