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.

103 lines
2.8 KiB

  1. <?php include "conf.php"; /* load a local configuration */ ?>
  2. <?php session_start(); ?>
  3. <?php require 'vendor/autoload.php'; /* composer includes */ ?>
  4. <?php include "modulekit/loader.php"; /* loads all php-includes */ ?>
  5. <?php include "node_modules/json-multiline-strings/src/json-multiline-strings.php"; ?>
  6. <?php call_hooks("init"); /* initialize submodules */ ?>
  7. <?php
  8. $allRepositories = getRepositories();
  9. if (!isset($_REQUEST['repo'])) {
  10. Header("Content-Type: application/json; charset=utf-8");
  11. print '{';
  12. $c = 0;
  13. foreach ($allRepositories as $repoId => $repoData) {
  14. $repo = getRepo($repoId, $repoData);
  15. print $c++ ? ',' : '';
  16. print json_encode($repoId, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) . ':';
  17. $info = $repo->info();
  18. if (isset($repoData['repositoryUrl'])) {
  19. $info['repositoryUrl'] = $repoData['repositoryUrl'];
  20. }
  21. if (isset($repoData['categoryUrl'])) {
  22. $info['categoryUrl'] = $repoData['categoryUrl'];
  23. }
  24. print json_encode($info, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT);
  25. }
  26. print '}';
  27. exit(0);
  28. }
  29. $fullRepoId = $_REQUEST['repo'];
  30. list($repoId, $branchId) = explode('~', $fullRepoId);
  31. if (array_key_exists('lang', $_REQUEST)) {
  32. $fullRepoId .= '~' . $_REQUEST['lang'];
  33. }
  34. if (!array_key_exists($repoId, $allRepositories)) {
  35. Header("HTTP/1.1 404 Repository not found");
  36. exit(0);
  37. }
  38. $repoData = $allRepositories[$repoId];
  39. $repo = getRepo($repoId, $repoData);
  40. if ($branchId) {
  41. try {
  42. $repo->setBranch($branchId);
  43. }
  44. catch (Exception $e) {
  45. Header("HTTP/1.1 404 No such branch");
  46. exit(0);
  47. }
  48. }
  49. $cacheDir = null;
  50. $ts = $repo->timestamp($path);
  51. if (isset($config['cache'])) {
  52. $cacheDir = "{$config['cache']}/repo";
  53. @mkdir($cacheDir);
  54. $cacheTs = filemtime("{$cacheDir}/{$fullRepoId}.json");
  55. if ($cacheTs === $ts) {
  56. Header("Content-Type: application/json; charset=utf-8");
  57. readfile("{$cacheDir}/{$fullRepoId}.json");
  58. exit(0);
  59. }
  60. }
  61. $data = $repo->data($_REQUEST);
  62. $repo->updateLang($data, $_REQUEST);
  63. if (!array_key_exists('index', $data['categories'])) {
  64. $data['categories']['index'] = array(
  65. 'type' => 'index',
  66. 'subCategories' => array_map(
  67. function ($k) {
  68. return array('id' => $k);
  69. }, array_keys($data['categories']))
  70. );
  71. }
  72. if (isset($repoData['repositoryUrl'])) {
  73. $data['repositoryUrl'] = $repoData['repositoryUrl'];
  74. }
  75. if (isset($repoData['categoryUrl'])) {
  76. $data['categoryUrl'] = $repoData['categoryUrl'];
  77. }
  78. $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  79. Header("Content-Type: application/json; charset=utf-8");
  80. print $ret;
  81. if ($cacheDir) {
  82. @mkdir(dirname("{$cacheDir}/{$fullRepoId}"));
  83. file_put_contents("{$cacheDir}/{$fullRepoId}.json", $ret);
  84. touch("{$cacheDir}/{$fullRepoId}.json", $ts);
  85. }