array( 'path' => $config['categoriesDir'], ), ); } function getRepo ($repoId, $repoData) { switch (array_key_exists('type', $repoData) ? $repoData['type'] : 'dir') { case 'git': $repo = new RepositoryGit($repoId, $repoData); break; default: $repo = new RepositoryDir($repoId, $repoData); } return $repo; } if (!isset($_REQUEST['repo'])) { Header("Content-Type: application/json; charset=utf-8"); print '{'; $c = 0; foreach ($repositories as $repoId => $repoData) { $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; print json_encode($repoId) . ':'; print json_encode($repo->info(), JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_FORCE_OBJECT); } print '}'; exit(0); } $repoId = $_REQUEST['repo']; if (!array_key_exists($repoId, $repositories)) { Header("HTTP/1.1 404 Repository not found"); exit(0); } $repo = getRepo($repoId, $repositories[$repoId]); $cacheDir = null; $ts = $repo->newestTimestamp($path); if (isset($config['cache'])) { $cacheDir = "{$config['cache']}/repo"; @mkdir($cacheDir); $cacheTs = filemtime("{$cacheDir}/{$repoId}.json"); if ($cacheTs === $ts) { Header("Content-Type: application/json; charset=utf-8"); readfile("{$cacheDir}/{$repoId}.json"); exit(0); } } $data = $repo->data(); $ret = json_encode($data, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); Header("Content-Type: application/json; charset=utf-8"); print $ret; file_put_contents("{$cacheDir}/{$repoId}.json", $ret); touch("{$cacheDir}/{$repoId}.json", $ts);