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

Implented adming pages

parent e2e8b710
No related branches found
No related tags found
No related merge requests found
<?php
add_action("wp_ajax_get_space", "get_space"); // Fires only for logged-in-users
add_action("wp_ajax_nopriv_get_space", 'get_space' ); // Fires for everyone
function get_space() {
$file_path = get_space_file_path($_POST["space"]);
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"]);
$content = file_get_contents($file_path);
echo $content;
wp_die();
}
add_action("wp_ajax_update_space", "update_space"); // Fires only for logged-in-users
add_action("wp_ajax_update_space", "kg_update_space"); // Fires only for logged-in-users
//add_action("wp_ajax_nopriv_update_space", 'update_space' ); // Fires for everyone
function update_space() {
function kg_update_space() {
// Check user capabilities
if (current_user_can("edit_posts")) {
// Use json encoding.
$graph = stripslashes($_POST["graph"]);
store_new_graph($graph, $_POST["space"]);
kg_store_new_graph($graph, $_POST["space"]);
wp_die();
} else {
......@@ -26,8 +26,8 @@ function update_space() {
}
}
function store_new_graph($graph, $space_id) {
$file_path = get_space_file_path($space_id);
function kg_store_new_graph($graph, $space_id) {
$file_path = kg_get_space_file_path($space_id);
$result = file_put_contents($file_path, $graph);
//echo print_r($_POST);
......@@ -37,6 +37,6 @@ function store_new_graph($graph, $space_id) {
echo $result;
}
function get_space_file_path($space_id) {
function kg_get_space_file_path($space_id) {
return __DIR__."/".$space_id.".json";
}
......@@ -11,7 +11,7 @@ $GLOBALS['build'] = 'debug';
function ks_add_graph($atts = []): string
{
$space_id = get_space_id_from_atts($atts);
$space_id = kg_get_space_id_from_atts($atts);
$div = '<div id="3d-graph"></div>'; // The id "3d-graph" indicates, that the javascript associated with this should automatically be executed
$plugin_dir = plugin_dir_url(__FILE__);
......@@ -27,15 +27,20 @@ function ks_add_graph($atts = []): string
wp_localize_script("ks-display-js", "space", array('id' => $space_id));
wp_localize_script("ks-display-js", "plugin", array('path' => $plugin_dir));
echo $div . $variables;
return $div . $variables;
// return $div . $variables . $script;
}
function ks_echo_graph ($atts = []): void {
echo ks_add_graph($atts);
}
function ks_add_editor($atts = [])
{
ks_add_editor_dependencies();
$space_id = get_space_id_from_atts($atts);
$space_id = kg_get_space_id_from_atts($atts);
$plugin_dir = plugin_dir_url(__FILE__);
wp_localize_script("ks-editor-js", "space", array('id' => $space_id));
wp_localize_script("ks-editor-js", "plugin", array('path' => $plugin_dir));
......@@ -68,7 +73,7 @@ function kg_load_css()
wp_enqueue_style('kg-style', $plugin_dir . 'kg-style.css');
}
function escape_space_id($id)
function kg_escape_space_id($id)
{
return str_replace(
"\\",
......@@ -81,15 +86,35 @@ function escape_space_id($id)
);
}
function get_space_id_from_atts($atts)
function kg_get_space_id_from_atts($atts)
{
if ($atts != "" && array_key_exists("space", $atts)) {
return escape_space_id($atts["space"]);
return kg_escape_space_id($atts["space"]);
} else {
return "space";
}
}
add_action('admin_menu', 'kg_editor_admin_add_page');
function kg_editor_admin_add_page()
{
add_menu_page(
'Knowledge Space',
'Knowledge Space',
'edit_plugins',
'knowledge-space',
'ks_echo_graph'
);
add_submenu_page(
'knowledge-space',
'Knowledge Space - Editor',
'Editor',
'edit_plugins',
'knowledge-space-editor',
'ks_add_editor'
);
}
require_once(__DIR__ . '/datasets/datasets.php');
......
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