Skip to content
Snippets Groups Projects
Commit 055bcc78 authored by Maximilian Giller's avatar Maximilian Giller
Browse files

Implemented empty graph fallback

parent 34bbb6ae
No related branches found
No related tags found
No related merge requests found
Pipeline #50400 passed
<?php
$EMPTY_SPACE_FILE = kg_get_space_file_path("default").".hidden";
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
function kg_get_space() {
$file_path = kg_get_space_file_path($_POST["space"]);
// If it doesn't exist, create new empty space
if (!file_exists($file_path)) {
kg_create_empty_space($file_path);
}
$content = file_get_contents($file_path);
echo $content;
......@@ -69,6 +77,18 @@ function kg_get_list_of_spaces() {
return $spaces;
}
function kg_create_empty_space($file_path) {
// Don't do anything, if it exists
if (file_exists($file_path)) {
return;
}
// Read and copy default empty graph from default file
global $EMPTY_SPACE_FILE;
$empty_graph = file_get_contents($EMPTY_SPACE_FILE);
file_put_contents($file_path, $empty_graph);
}
function endsWith( $haystack, $needle ) {
# Source: https://stackoverflow.com/a/834355/7376120
$length = strlen( $needle );
......
{"links":[],"nodes":[]}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment