You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

  1. <?php
  2. function getRepositories () {
  3. global $repositories;
  4. global $repositoriesGitea;
  5. $result = array();
  6. if (isset($repositories)) {
  7. $result = $repositories;
  8. }
  9. else {
  10. $result = array(
  11. 'default' => array(
  12. 'path' => $config['categoriesDir'],
  13. ),
  14. );
  15. }
  16. if (isset($repositoriesGitea)) {
  17. $d1 = opendir($repositoriesGitea['path']);
  18. while ($f1 = readdir($d1)) {
  19. if (substr($f1, 0, 1) !== '.') {
  20. $d2 = opendir("{$repositoriesGitea['path']}/{$f1}");
  21. while ($f2 = readdir($d2)) {
  22. if (substr($f2, 0, 1) !== '.') {
  23. $f2id = substr($f2, 0, -4);
  24. $r = array(
  25. 'path' => "{$repositoriesGitea['path']}/{$f1}/{$f2}",
  26. 'type' => 'git',
  27. );
  28. if (array_key_exists('url', $repositoriesGitea)) {
  29. $r['repositoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}";
  30. $r['categoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}/src/{{ categoryId }}.json";
  31. }
  32. $result["{$f1}/{$f2id}"] = $r;
  33. }
  34. }
  35. closedir($d2);
  36. }
  37. }
  38. closedir($d1);
  39. }
  40. return $result;
  41. }
  42. function getRepo ($repoId, $repoData) {
  43. switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') {
  44. case 'git':
  45. $repo = new RepositoryGit($repoId, $repoData);
  46. break;
  47. default:
  48. $repo = new RepositoryDir($repoId, $repoData);
  49. }
  50. return $repo;
  51. }
  52. register_hook('init', function () {
  53. global $repositoriesGitea;
  54. if (isset($repositoriesGitea) && array_key_exists('url', $repositoriesGitea)) {
  55. $d = array('repositoriesGitea' => array(
  56. 'url' => $repositoriesGitea['url'],
  57. ));
  58. html_export_var($d);
  59. }
  60. });