Skip to content
Snippets Groups Projects
knowledge-space.php 1.16 KiB
Newer Older
<?php

/*
Plugin Name: Knowledge Space
Description: This plugin adds a knowledge space to the website via a shortcode.
Version: 1.0
Author: Matthias Konitzny
*/

function ks_add_graph(): string
{
    $graph = '<script src="//unpkg.com/3d-force-graph"></script>';
    $three = '<script src="//unpkg.com/three"></script>';
    $renderer = '<script src="//unpkg.com/three/examples/js/renderers/CSS2DRenderer.js"></script>';
    $renderer2 = '<script src="//unpkg.com/three/examples/js/renderers/CSS3DRenderer.js"></script>';
    $div = '<div id="3d-graph"></div>';
    $plugin_dir = plugin_dir_url(__FILE__);
    //$dataset = $plugin_dir.'datasets/miserables.json';
    $variables = "<script> 
                  var plugin_path = '$plugin_dir';
                  </script>";
    $script_path = $plugin_dir.'graph.js';
    $script = "<script src='$script_path'></script>";

    return $three . $renderer .$renderer2 . $graph . $div . $variables . $script;
function kg_load_css() {
    $plugin_dir = plugin_dir_url(__FILE__);
    wp_enqueue_style('kg-style', $plugin_dir.'kg-style.css');
}

add_action('wp_enqueue_scripts', 'kg_load_css');
add_shortcode('knowledge-space', 'ks_add_graph');