From 882a7022badef7916fc9e9707f7f3e6d6855af7b Mon Sep 17 00:00:00 2001 From: Max <m.giller.dev@gmail.com> Date: Wed, 1 Dec 2021 23:48:24 +0100 Subject: [PATCH] Extracted spaces to extra directory --- datasets/datasets.php | 14 +++++++++++--- datasets/{default.json.hidden => empty-space.json} | 0 datasets/{ => spaces}/aud1.json | 0 datasets/{ => spaces}/blocks.json | 0 datasets/spaces/crazy.json | 1 + datasets/{ => spaces}/miserables.json | 0 datasets/{ => spaces}/space.json | 0 7 files changed, 12 insertions(+), 3 deletions(-) rename datasets/{default.json.hidden => empty-space.json} (100%) rename datasets/{ => spaces}/aud1.json (100%) rename datasets/{ => spaces}/blocks.json (100%) create mode 100644 datasets/spaces/crazy.json rename datasets/{ => spaces}/miserables.json (100%) rename datasets/{ => spaces}/space.json (100%) diff --git a/datasets/datasets.php b/datasets/datasets.php index ef40e24..6507dda 100644 --- a/datasets/datasets.php +++ b/datasets/datasets.php @@ -1,6 +1,7 @@ <?php -$EMPTY_SPACE_FILE = kg_get_space_file_path("default").".hidden"; +$EMPTY_SPACE_FILE = __DIR__."/empty-space.json"; +$SPACES_DIR = __DIR__."/spaces/"; add_action("wp_ajax_get_space", "kg_get_space"); // Fires only for logged-in-users add_action("wp_ajax_nopriv_get_space", 'kg_get_space' ); // Fires for everyone @@ -56,11 +57,18 @@ function kg_store_new_graph($graph, $space_id) { } function kg_get_space_file_path($space_id) { - return __DIR__."/".$space_id.".json"; + // Cleaning up the space id + $space_id = str_replace("/", "-", $space_id); + $space_id = str_replace("\\", "-", $space_id); + $space_id = str_replace(".", "-", $space_id); + + global $SPACES_DIR; + return $SPACES_DIR.$space_id.".json"; } function kg_get_list_of_spaces() { - $all_files = scandir(__DIR__); + global $SPACES_DIR; + $all_files = scandir($SPACES_DIR); if ($all_files == false) { return []; diff --git a/datasets/default.json.hidden b/datasets/empty-space.json similarity index 100% rename from datasets/default.json.hidden rename to datasets/empty-space.json diff --git a/datasets/aud1.json b/datasets/spaces/aud1.json similarity index 100% rename from datasets/aud1.json rename to datasets/spaces/aud1.json diff --git a/datasets/blocks.json b/datasets/spaces/blocks.json similarity index 100% rename from datasets/blocks.json rename to datasets/spaces/blocks.json diff --git a/datasets/spaces/crazy.json b/datasets/spaces/crazy.json new file mode 100644 index 0000000..957a203 --- /dev/null +++ b/datasets/spaces/crazy.json @@ -0,0 +1 @@ +{"links":[{"source":"tNp3gydg","target":"flL8y4fI"},{"source":"flL8y4fI","target":"HL2mJfY7"},{"source":"HL2mJfY7","target":"c2kVhY7g"},{"source":"c2kVhY7g","target":"flL8y4fI"},{"source":"flL8y4fI","target":"6PDvcacV"}],"nodes":[{"id":"flL8y4fI","name":"Musik","type":"Beispiel"},{"id":"6PDvcacV","name":"Comics","type":"Beispiel"},{"id":"HL2mJfY7","name":"Peter Fox","type":"Beispiel"},{"id":"c2kVhY7g","name":"Haus Am See","type":"Vorlesung"},{"id":"tNp3gydg","name":"Filme","type":"Ãœbung"}]} \ No newline at end of file diff --git a/datasets/miserables.json b/datasets/spaces/miserables.json similarity index 100% rename from datasets/miserables.json rename to datasets/spaces/miserables.json diff --git a/datasets/space.json b/datasets/spaces/space.json similarity index 100% rename from datasets/space.json rename to datasets/spaces/space.json -- GitLab