Skip to content
Snippets Groups Projects
knowledge-space.php 1.84 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?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
    {
    
        $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__);
    
        //$dataset = $plugin_dir.'datasets/miserables.json';
    
        $variables = "<script> 
    
                      var plugin_path = '$plugin_dir';
    
        $script_path = $plugin_dir . 'build' . DIRECTORY_SEPARATOR . $GLOBALS['build'] . DIRECTORY_SEPARATOR . 'graph.js';
    
        $script = "<script src='$script_path'></script>";
        //wp_enqueue_script('kg-script', $script_path);
    
    
        return $div . $variables . $script;
    
    function ks_add_editor()
    {
        ks_add_editor_dependencies();
    
    Maximilian Giller's avatar
    Maximilian Giller committed
    
    
        $plugin_dir = plugin_dir_url(__FILE__);
        echo "<script> 
            var plugin_path = '$plugin_dir';
            </script>";
    
        require_once(__DIR__ . '/editor/editor.php');
    
    Maximilian Giller's avatar
    Maximilian Giller committed
    }
    
    
    function ks_add_editor_dependencies()
    
        $script_path = 'build' . DIRECTORY_SEPARATOR . $GLOBALS['build'] . DIRECTORY_SEPARATOR . 'graph.js';
    
        wp_enqueue_script('jquery');
        wp_enqueue_script("ks-editor-js", plugins_url($script_path, __FILE__), array(), false);
    
        $style_file_version = date("ymd-Gis", filemtime(plugin_dir_path(__FILE__) . "editor/css/editor.css"));
        wp_enqueue_style("ks-editor-css", plugins_url("editor/css/editor.css", __FILE__), array(), $style_file_version);
    
        $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');
    
    Maximilian Giller's avatar
    Maximilian Giller committed
    add_shortcode('knowledge-space-editor', 'ks_add_editor');