/**
 * Sets-up the widget. This is called by WordPress when the shortcode is inserted in the body.
 */
function wl_shortcode_blog_map($atts)
{
    //extract attributes and set default values
    $chord_atts = shortcode_atts(array('width' => '100%', 'height' => '500px', 'depth' => 3), $atts);
    $post_id = wl_shortcode_chord_most_referenced_entity_id();
    if ($post_id == null) {
        return "Blog-map: no entities found.";
    }
    $widget_id = 'wl-blog-map';
    // Adding css
    wp_enqueue_style('vis', dirname(plugin_dir_url(__FILE__)) . '/public/js/visjs/vis.css');
    // Adding javascript code
    wp_enqueue_script('vis', dirname(plugin_dir_url(__FILE__)) . '/public/js/visjs/vis.js');
    wp_enqueue_script('blog-map-launcher', dirname(plugin_dir_url(__FILE__)) . '/public/js/wordlift_shortcode_blog_map.js');
    wp_localize_script('blog-map-launcher', 'blog_map_params', array('ajax_url' => admin_url('admin-ajax.php'), 'action' => 'wl_chord', 'default_thumbnail' => dirname(plugin_dir_url(__FILE__)) . '/images/wordlift-logo-black-32x32'));
    // Escaping atts.
    $esc_id = esc_attr($widget_id);
    $esc_width = esc_attr($chord_atts['width']);
    $esc_height = esc_attr($chord_atts['height']);
    $esc_post_id = esc_attr($post_id);
    $esc_depth = esc_attr($chord_atts['depth']);
    // Building template.
    return <<<EOF
<div id="{$esc_id}"
    data-post-id="{$esc_post_id}"
    data-depth="{$esc_depth}"
    style="width:{$esc_width};
    height:{$esc_height};
    background-color:white;
    margin-top:10px;
    margin-bottom:10px">
</div>
EOF;
}
 function testChordShortcodeMostConnectedEntity()
 {
     // Check there is a number
     $e = wl_shortcode_chord_most_referenced_entity_id();
     $this->assertNotNull($e);
     $this->assertEquals(self::$MOST_CONNECTED_ENTITY_ID, $e);
 }
/**
 * Sets-up the widget. This is called by WordPress when the shortcode is inserted in the body.
 *
 * @uses wl_shortcode_chord_most_referenced_entity_id() to get the most connected entity.
 *
 * @param array $atts An array of parameters set by the editor to customize the shortcode behaviour.
 * @return string
 */
function wl_shortcode_chord($atts)
{
    //extract attributes and set default values
    $chord_atts = shortcode_atts(array('width' => '100%', 'height' => '500px', 'main_color' => '000', 'depth' => 2, 'global' => false), $atts);
    if ($chord_atts['global']) {
        $post_id = wl_shortcode_chord_most_referenced_entity_id();
        if ($post_id == null) {
            return "WordLift Chord: no entities found.";
        }
        $widget_id = 'wl_chord_global';
        $chord_atts['height'] = '200px';
    } else {
        $post_id = get_the_ID();
        $widget_id = 'wl_chord_' . $post_id;
    }
    // Adding css
    wp_enqueue_style('wordlift-ui-css', plugins_url('css/wordlift.ui.min.css', __FILE__));
    // Adding javascript code
    wp_enqueue_script('d3', plugins_url('bower_components/d3/d3.min.js', __FILE__));
    wp_enqueue_script('wordlift-ui', plugins_url('js/wordlift.ui.min.js', __FILE__));
    wp_localize_script('wordlift-ui', 'wl_chord_params', array('ajax_url' => admin_url('admin-ajax.php'), 'action' => 'wl_chord'));
    // Escaping atts.
    $esc_class = esc_attr('wl-chord');
    $esc_id = esc_attr($widget_id);
    $esc_width = esc_attr($chord_atts['width']);
    $esc_height = esc_attr($chord_atts['height']);
    $esc_post_id = esc_attr($post_id);
    $esc_depth = esc_attr($chord_atts['depth']);
    $esc_main_color = esc_attr($chord_atts['main_color']);
    // Building template.
    // TODO: in the HTML code there are static CSS rules. Move them to the CSS file.
    return <<<EOF
<div class="{$esc_class}" 
\tid="{$esc_id}"
\tdata-post-id="{$esc_post_id}"
    data-depth="{$esc_depth}"
    data-main-color="{$esc_main_color}"
\tstyle="width:{$esc_width};
        height:{$esc_height};
        background-color:white;
        margin-top:10px;
        margin-bottom:10px">
</div>
EOF;
}