From 14d44c80c1af752bce8b25a4d3592a2649057231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Mon, 25 Dec 2017 18:48:02 +0100 Subject: [PATCH] Repositories: move code to src/repositories.php; configure $config['repositories'] --- conf.php-dist | 9 +++++++-- modulekit.php | 1 + repo.php | 26 ++++---------------------- src/repositories.php | 30 ++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 src/repositories.php diff --git a/conf.php-dist b/conf.php-dist index 600dd113..aedbd643 100644 --- a/conf.php-dist +++ b/conf.php-dist @@ -1,6 +1,11 @@ array( + 'path' => 'node_modules/openstreetbrowser-categories-main', + 'type' => 'dir', + ), +); // Set to true to reload categories on every page visit. $config['categoriesAlwaysReload'] = true; diff --git a/modulekit.php b/modulekit.php index 28a9b88a..52af002a 100644 --- a/modulekit.php +++ b/modulekit.php @@ -18,6 +18,7 @@ $include = array( 'src/ImageLoader.php', 'src/RepositoryDir.php', 'src/RepositoryGit.php', + 'src/repositories.php', ), 'css' => array( 'style.css', diff --git a/repo.php b/repo.php index 74231247..ca51897d 100644 --- a/repo.php +++ b/repo.php @@ -5,32 +5,14 @@ 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; -} +$allRepositories = getRepositories(); if (!isset($_REQUEST['repo'])) { Header("Content-Type: application/json; charset=utf-8"); print '{'; $c = 0; - foreach ($repositories as $repoId => $repoData) { + foreach (getRepositories() as $repoId => $repoData) { $repo = getRepo($repoId, $repoData); print $c++ ? ',' : ''; @@ -43,12 +25,12 @@ if (!isset($_REQUEST['repo'])) { } $repoId = $_REQUEST['repo']; -if (!array_key_exists($repoId, $repositories)) { +if (!array_key_exists($repoId, $allRepositories)) { Header("HTTP/1.1 404 Repository not found"); exit(0); } -$repo = getRepo($repoId, $repositories[$repoId]); +$repo = getRepo($repoId, $allRepositories[$repoId]); $cacheDir = null; $ts = $repo->newestTimestamp($path); diff --git a/src/repositories.php b/src/repositories.php new file mode 100644 index 00000000..50989f9d --- /dev/null +++ b/src/repositories.php @@ -0,0 +1,30 @@ + array( + 'path' => $config['categoriesDir'], + ), + ); + } + + return $repositories; +} + +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; +}