|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The `wl_chord` shortcode. |
|
5
|
|
|
* |
|
6
|
|
|
* @since 3.5.4 |
|
7
|
|
|
*/ |
|
8
|
|
|
class Wordlift_Chord_Shortcode extends Wordlift_Shortcode { |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* {@inheritdoc} |
|
12
|
|
|
*/ |
|
13
|
|
|
const SHORTCODE = 'wl_chord'; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
public function render( $atts ) { |
|
19
|
|
|
|
|
20
|
|
|
//extract attributes and set default values |
|
21
|
|
|
$chord_atts = shortcode_atts( array( |
|
22
|
|
|
'width' => '100%', |
|
23
|
|
|
'height' => '500px', |
|
24
|
|
|
'main_color' => '000', |
|
25
|
|
|
'depth' => 2, |
|
26
|
|
|
'global' => FALSE |
|
27
|
|
|
), $atts ); |
|
28
|
|
|
|
|
29
|
|
|
if ( $chord_atts['global'] ) { |
|
30
|
|
|
$post_id = wl_shortcode_chord_most_referenced_entity_id(); |
|
31
|
|
|
if ( $post_id == NULL ) { |
|
32
|
|
|
return "WordLift Chord: no entities found."; |
|
33
|
|
|
} |
|
34
|
|
|
$widget_id = 'wl_chord_global'; |
|
35
|
|
|
$chord_atts['height'] = '200px'; |
|
36
|
|
|
} else { |
|
37
|
|
|
$post_id = get_the_ID(); |
|
38
|
|
|
$widget_id = 'wl_chord_' . $post_id; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// Adding css |
|
42
|
|
|
wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
43
|
|
|
|
|
44
|
|
|
// Adding javascript code |
|
45
|
|
|
wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js' ); |
|
46
|
|
|
|
|
47
|
|
|
$this->enqueue_scripts(); |
|
48
|
|
|
|
|
49
|
|
|
wp_localize_script( 'wordlift-ui', 'wl_chord_params', array( |
|
50
|
|
|
'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
51
|
|
|
'action' => 'wl_chord' |
|
52
|
|
|
) |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
// Escaping atts. |
|
56
|
|
|
$esc_class = esc_attr( 'wl-chord' ); |
|
57
|
|
|
$esc_id = esc_attr( $widget_id ); |
|
58
|
|
|
$esc_width = esc_attr( $chord_atts['width'] ); |
|
59
|
|
|
$esc_height = esc_attr( $chord_atts['height'] ); |
|
60
|
|
|
|
|
61
|
|
|
$esc_post_id = esc_attr( $post_id ); |
|
62
|
|
|
$esc_depth = esc_attr( $chord_atts['depth'] ); |
|
63
|
|
|
$esc_main_color = esc_attr( $chord_atts['main_color'] ); |
|
64
|
|
|
|
|
65
|
|
|
// Building template. |
|
66
|
|
|
// TODO: in the HTML code there are static CSS rules. Move them to the CSS file. |
|
67
|
|
|
return <<<EOF |
|
68
|
|
|
<div class="$esc_class" |
|
69
|
|
|
id="$esc_id" |
|
70
|
|
|
data-post-id="$esc_post_id" |
|
71
|
|
|
data-depth="$esc_depth" |
|
72
|
|
|
data-main-color="$esc_main_color" |
|
73
|
|
|
style="width:$esc_width; |
|
74
|
|
|
height:$esc_height; |
|
75
|
|
|
background-color:white; |
|
76
|
|
|
margin-top:10px; |
|
77
|
|
|
margin-bottom:10px"> |
|
78
|
|
|
</div> |
|
79
|
|
|
EOF; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |