@@ -10,53 +10,53 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Wordlift_Chord_Widget extends WP_Widget { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Sets up the widgets name etc |
|
| 15 | - */ |
|
| 16 | - public function __construct() { |
|
| 17 | - // widget actual processes. |
|
| 18 | - parent::__construct( |
|
| 19 | - 'wl_chord_widget', // Base ID. |
|
| 20 | - __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 21 | - array( |
|
| 22 | - 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 23 | - ) // Args. |
|
| 24 | - ); |
|
| 25 | - } |
|
| 13 | + /** |
|
| 14 | + * Sets up the widgets name etc |
|
| 15 | + */ |
|
| 16 | + public function __construct() { |
|
| 17 | + // widget actual processes. |
|
| 18 | + parent::__construct( |
|
| 19 | + 'wl_chord_widget', // Base ID. |
|
| 20 | + __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 21 | + array( |
|
| 22 | + 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 23 | + ) // Args. |
|
| 24 | + ); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Outputs the content of the widget |
|
| 29 | - * |
|
| 30 | - * @param array $args widget args. |
|
| 31 | - * @param array $instance widget instance. |
|
| 32 | - */ |
|
| 33 | - public function widget( $args, $instance ) { |
|
| 34 | - // outputs the content of the widget. |
|
| 35 | - echo do_shortcode( '[wl_chord]' ); |
|
| 36 | - } |
|
| 27 | + /** |
|
| 28 | + * Outputs the content of the widget |
|
| 29 | + * |
|
| 30 | + * @param array $args widget args. |
|
| 31 | + * @param array $instance widget instance. |
|
| 32 | + */ |
|
| 33 | + public function widget( $args, $instance ) { |
|
| 34 | + // outputs the content of the widget. |
|
| 35 | + echo do_shortcode( '[wl_chord]' ); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Outputs the options form on admin |
|
| 40 | - * |
|
| 41 | - * @param array $instance The widget options. |
|
| 42 | - * |
|
| 43 | - * @return string|void |
|
| 44 | - */ |
|
| 45 | - public function form( $instance ) { |
|
| 46 | - // outputs the options form on admin. |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Outputs the options form on admin |
|
| 40 | + * |
|
| 41 | + * @param array $instance The widget options. |
|
| 42 | + * |
|
| 43 | + * @return string|void |
|
| 44 | + */ |
|
| 45 | + public function form( $instance ) { |
|
| 46 | + // outputs the options form on admin. |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Processing widget options on save |
|
| 51 | - * |
|
| 52 | - * @param array $new_instance The new options. |
|
| 53 | - * @param array $old_instance The previous options. |
|
| 54 | - * |
|
| 55 | - * @return array|void |
|
| 56 | - */ |
|
| 57 | - public function update( $new_instance, $old_instance ) { |
|
| 58 | - // processes widget options to be saved. |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * Processing widget options on save |
|
| 51 | + * |
|
| 52 | + * @param array $new_instance The new options. |
|
| 53 | + * @param array $old_instance The previous options. |
|
| 54 | + * |
|
| 55 | + * @return array|void |
|
| 56 | + */ |
|
| 57 | + public function update( $new_instance, $old_instance ) { |
|
| 58 | + // processes widget options to be saved. |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function wl_register_chord_widget() { |
| 68 | 68 | |
| 69 | - register_widget( 'WordLift_Chord_Widget' ); |
|
| 69 | + register_widget( 'WordLift_Chord_Widget' ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | add_action( 'widgets_init', 'wl_register_chord_widget' ); |
@@ -17,9 +17,9 @@ discard block |
||
| 17 | 17 | // widget actual processes. |
| 18 | 18 | parent::__construct( |
| 19 | 19 | 'wl_chord_widget', // Base ID. |
| 20 | - __( 'Chord Widget', 'wordlift' ), // Name. |
|
| 20 | + __('Chord Widget', 'wordlift'), // Name. |
|
| 21 | 21 | array( |
| 22 | - 'description' => __( 'The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift' ), |
|
| 22 | + 'description' => __('The Chord Widget depicts the main topics of your blog in concise graph.', 'wordlift'), |
|
| 23 | 23 | ) // Args. |
| 24 | 24 | ); |
| 25 | 25 | } |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @param array $args widget args. |
| 31 | 31 | * @param array $instance widget instance. |
| 32 | 32 | */ |
| 33 | - public function widget( $args, $instance ) { |
|
| 33 | + public function widget($args, $instance) { |
|
| 34 | 34 | // outputs the content of the widget. |
| 35 | - echo do_shortcode( '[wl_chord]' ); |
|
| 35 | + echo do_shortcode('[wl_chord]'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return string|void |
| 44 | 44 | */ |
| 45 | - public function form( $instance ) { |
|
| 45 | + public function form($instance) { |
|
| 46 | 46 | // outputs the options form on admin. |
| 47 | 47 | } |
| 48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return array|void |
| 56 | 56 | */ |
| 57 | - public function update( $new_instance, $old_instance ) { |
|
| 57 | + public function update($new_instance, $old_instance) { |
|
| 58 | 58 | // processes widget options to be saved. |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function wl_register_chord_widget() { |
| 68 | 68 | |
| 69 | - register_widget( 'WordLift_Chord_Widget' ); |
|
| 69 | + register_widget('WordLift_Chord_Widget'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | -add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
| 73 | -add_filter( 'widget_text', 'do_shortcode' ); |
|
| 72 | +add_action('widgets_init', 'wl_register_chord_widget'); |
|
| 73 | +add_filter('widget_text', 'do_shortcode'); |
|
@@ -16,87 +16,87 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Chord_Shortcode extends Wordlift_Shortcode { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * {@inheritdoc} |
|
| 21 | - */ |
|
| 22 | - const SHORTCODE = 'wl_chord'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Create a {@link Wordlift_Chord_Shortcode} instance. |
|
| 26 | - * |
|
| 27 | - * @since 3.5.4 |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - parent::__construct(); |
|
| 31 | - |
|
| 32 | - // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
|
| 33 | - // rendering. |
|
| 34 | - add_action( 'amp_post_template_css', array( |
|
| 35 | - $this, |
|
| 36 | - 'amp_post_template_css', |
|
| 37 | - ) ); |
|
| 38 | - |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Render shordcode. |
|
| 43 | - * |
|
| 44 | - * @param array $atts shortcode attributes. |
|
| 45 | - */ |
|
| 46 | - public function render( $atts ) { |
|
| 47 | - |
|
| 48 | - // extract attributes and set default values. |
|
| 49 | - $chord_atts = shortcode_atts( array( |
|
| 50 | - 'width' => '100%', |
|
| 51 | - 'height' => '500px', |
|
| 52 | - 'main_color' => '000', |
|
| 53 | - 'depth' => 2, |
|
| 54 | - 'global' => false, |
|
| 55 | - ), $atts ); |
|
| 56 | - |
|
| 57 | - if ( $chord_atts['global'] ) { |
|
| 58 | - |
|
| 59 | - $post_id = wl_shortcode_chord_most_referenced_entity_id(); |
|
| 60 | - |
|
| 61 | - if ( null === $post_id ) { |
|
| 62 | - return 'WordLift Chord: no entities found.'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // Use the provided height if any, otherwise use a default of 200px. |
|
| 66 | - // |
|
| 67 | - // See https://github.com/insideout10/wordlift-plugin/issues/443. |
|
| 68 | - $chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px'; |
|
| 69 | - |
|
| 70 | - } else { |
|
| 71 | - $post_id = get_the_ID(); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // Adding css. |
|
| 75 | - wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 76 | - |
|
| 77 | - // Adding javascript code. |
|
| 78 | - wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js' ); |
|
| 79 | - |
|
| 80 | - $this->enqueue_scripts(); |
|
| 81 | - |
|
| 82 | - wp_localize_script( 'wordlift-ui', 'wl_chord_params', array( |
|
| 83 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 84 | - 'action' => 'wl_chord', |
|
| 85 | - )); |
|
| 86 | - |
|
| 87 | - // Escaping atts. |
|
| 88 | - $esc_class = esc_attr( 'wl-chord' ); |
|
| 89 | - $esc_id = esc_attr( uniqid( 'wl-chord-' ) ); |
|
| 90 | - $esc_width = esc_attr( $chord_atts['width'] ); |
|
| 91 | - $esc_height = esc_attr( $chord_atts['height'] ); |
|
| 92 | - |
|
| 93 | - $esc_post_id = esc_attr( $post_id ); |
|
| 94 | - $esc_depth = esc_attr( $chord_atts['depth'] ); |
|
| 95 | - $esc_main_color = esc_attr( $chord_atts['main_color'] ); |
|
| 96 | - |
|
| 97 | - // Building template. |
|
| 98 | - // TODO: in the HTML code there are static CSS rules. Move them to the CSS file. |
|
| 99 | - return <<<EOF |
|
| 19 | + /** |
|
| 20 | + * {@inheritdoc} |
|
| 21 | + */ |
|
| 22 | + const SHORTCODE = 'wl_chord'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Create a {@link Wordlift_Chord_Shortcode} instance. |
|
| 26 | + * |
|
| 27 | + * @since 3.5.4 |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + parent::__construct(); |
|
| 31 | + |
|
| 32 | + // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
|
| 33 | + // rendering. |
|
| 34 | + add_action( 'amp_post_template_css', array( |
|
| 35 | + $this, |
|
| 36 | + 'amp_post_template_css', |
|
| 37 | + ) ); |
|
| 38 | + |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Render shordcode. |
|
| 43 | + * |
|
| 44 | + * @param array $atts shortcode attributes. |
|
| 45 | + */ |
|
| 46 | + public function render( $atts ) { |
|
| 47 | + |
|
| 48 | + // extract attributes and set default values. |
|
| 49 | + $chord_atts = shortcode_atts( array( |
|
| 50 | + 'width' => '100%', |
|
| 51 | + 'height' => '500px', |
|
| 52 | + 'main_color' => '000', |
|
| 53 | + 'depth' => 2, |
|
| 54 | + 'global' => false, |
|
| 55 | + ), $atts ); |
|
| 56 | + |
|
| 57 | + if ( $chord_atts['global'] ) { |
|
| 58 | + |
|
| 59 | + $post_id = wl_shortcode_chord_most_referenced_entity_id(); |
|
| 60 | + |
|
| 61 | + if ( null === $post_id ) { |
|
| 62 | + return 'WordLift Chord: no entities found.'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // Use the provided height if any, otherwise use a default of 200px. |
|
| 66 | + // |
|
| 67 | + // See https://github.com/insideout10/wordlift-plugin/issues/443. |
|
| 68 | + $chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px'; |
|
| 69 | + |
|
| 70 | + } else { |
|
| 71 | + $post_id = get_the_ID(); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // Adding css. |
|
| 75 | + wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 76 | + |
|
| 77 | + // Adding javascript code. |
|
| 78 | + wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js' ); |
|
| 79 | + |
|
| 80 | + $this->enqueue_scripts(); |
|
| 81 | + |
|
| 82 | + wp_localize_script( 'wordlift-ui', 'wl_chord_params', array( |
|
| 83 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 84 | + 'action' => 'wl_chord', |
|
| 85 | + )); |
|
| 86 | + |
|
| 87 | + // Escaping atts. |
|
| 88 | + $esc_class = esc_attr( 'wl-chord' ); |
|
| 89 | + $esc_id = esc_attr( uniqid( 'wl-chord-' ) ); |
|
| 90 | + $esc_width = esc_attr( $chord_atts['width'] ); |
|
| 91 | + $esc_height = esc_attr( $chord_atts['height'] ); |
|
| 92 | + |
|
| 93 | + $esc_post_id = esc_attr( $post_id ); |
|
| 94 | + $esc_depth = esc_attr( $chord_atts['depth'] ); |
|
| 95 | + $esc_main_color = esc_attr( $chord_atts['main_color'] ); |
|
| 96 | + |
|
| 97 | + // Building template. |
|
| 98 | + // TODO: in the HTML code there are static CSS rules. Move them to the CSS file. |
|
| 99 | + return <<<EOF |
|
| 100 | 100 | <div class="$esc_class" |
| 101 | 101 | id="$esc_id" |
| 102 | 102 | data-post-id="$esc_post_id" |
@@ -109,23 +109,23 @@ discard block |
||
| 109 | 109 | margin-bottom:10px"> |
| 110 | 110 | </div> |
| 111 | 111 | EOF; |
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Customize the CSS when in AMP. |
|
| 116 | - * |
|
| 117 | - * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css |
|
| 118 | - * |
|
| 119 | - * @since 3.14.0 |
|
| 120 | - * |
|
| 121 | - * @param object $amp_template The template. |
|
| 122 | - */ |
|
| 123 | - public function amp_post_template_css( $amp_template ) { |
|
| 124 | - |
|
| 125 | - // Hide the `wl-chord` when in AMP. |
|
| 126 | - ?> |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Customize the CSS when in AMP. |
|
| 116 | + * |
|
| 117 | + * See https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-css |
|
| 118 | + * |
|
| 119 | + * @since 3.14.0 |
|
| 120 | + * |
|
| 121 | + * @param object $amp_template The template. |
|
| 122 | + */ |
|
| 123 | + public function amp_post_template_css( $amp_template ) { |
|
| 124 | + |
|
| 125 | + // Hide the `wl-chord` when in AMP. |
|
| 126 | + ?> |
|
| 127 | 127 | .wl-chord { display: none; } |
| 128 | 128 | <?php |
| 129 | - } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | } |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // Hook to the `amp_post_template_css` to hide ourselves when in AMP |
| 33 | 33 | // rendering. |
| 34 | - add_action( 'amp_post_template_css', array( |
|
| 34 | + add_action('amp_post_template_css', array( |
|
| 35 | 35 | $this, |
| 36 | 36 | 'amp_post_template_css', |
| 37 | - ) ); |
|
| 37 | + )); |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -43,56 +43,56 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @param array $atts shortcode attributes. |
| 45 | 45 | */ |
| 46 | - public function render( $atts ) { |
|
| 46 | + public function render($atts) { |
|
| 47 | 47 | |
| 48 | 48 | // extract attributes and set default values. |
| 49 | - $chord_atts = shortcode_atts( array( |
|
| 49 | + $chord_atts = shortcode_atts(array( |
|
| 50 | 50 | 'width' => '100%', |
| 51 | 51 | 'height' => '500px', |
| 52 | 52 | 'main_color' => '000', |
| 53 | 53 | 'depth' => 2, |
| 54 | 54 | 'global' => false, |
| 55 | - ), $atts ); |
|
| 55 | + ), $atts); |
|
| 56 | 56 | |
| 57 | - if ( $chord_atts['global'] ) { |
|
| 57 | + if ($chord_atts['global']) { |
|
| 58 | 58 | |
| 59 | 59 | $post_id = wl_shortcode_chord_most_referenced_entity_id(); |
| 60 | 60 | |
| 61 | - if ( null === $post_id ) { |
|
| 61 | + if (null === $post_id) { |
|
| 62 | 62 | return 'WordLift Chord: no entities found.'; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Use the provided height if any, otherwise use a default of 200px. |
| 66 | 66 | // |
| 67 | 67 | // See https://github.com/insideout10/wordlift-plugin/issues/443. |
| 68 | - $chord_atts['height'] = isset( $chord_atts['height'] ) ? $chord_atts['height'] : '200px'; |
|
| 68 | + $chord_atts['height'] = isset($chord_atts['height']) ? $chord_atts['height'] : '200px'; |
|
| 69 | 69 | |
| 70 | 70 | } else { |
| 71 | - $post_id = get_the_ID(); |
|
| 71 | + $post_id = get_the_ID(); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // Adding css. |
| 75 | - wp_enqueue_style( 'wordlift-ui', dirname( plugin_dir_url( __FILE__ ) ) . '/css/wordlift-ui.min.css' ); |
|
| 75 | + wp_enqueue_style('wordlift-ui', dirname(plugin_dir_url(__FILE__)).'/css/wordlift-ui.min.css'); |
|
| 76 | 76 | |
| 77 | 77 | // Adding javascript code. |
| 78 | - wp_enqueue_script( 'd3', dirname( plugin_dir_url( __FILE__ ) ) . '/bower_components/d3/d3.min.js' ); |
|
| 78 | + wp_enqueue_script('d3', dirname(plugin_dir_url(__FILE__)).'/bower_components/d3/d3.min.js'); |
|
| 79 | 79 | |
| 80 | 80 | $this->enqueue_scripts(); |
| 81 | 81 | |
| 82 | - wp_localize_script( 'wordlift-ui', 'wl_chord_params', array( |
|
| 83 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 82 | + wp_localize_script('wordlift-ui', 'wl_chord_params', array( |
|
| 83 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 84 | 84 | 'action' => 'wl_chord', |
| 85 | 85 | )); |
| 86 | 86 | |
| 87 | 87 | // Escaping atts. |
| 88 | - $esc_class = esc_attr( 'wl-chord' ); |
|
| 89 | - $esc_id = esc_attr( uniqid( 'wl-chord-' ) ); |
|
| 90 | - $esc_width = esc_attr( $chord_atts['width'] ); |
|
| 91 | - $esc_height = esc_attr( $chord_atts['height'] ); |
|
| 88 | + $esc_class = esc_attr('wl-chord'); |
|
| 89 | + $esc_id = esc_attr(uniqid('wl-chord-')); |
|
| 90 | + $esc_width = esc_attr($chord_atts['width']); |
|
| 91 | + $esc_height = esc_attr($chord_atts['height']); |
|
| 92 | 92 | |
| 93 | - $esc_post_id = esc_attr( $post_id ); |
|
| 94 | - $esc_depth = esc_attr( $chord_atts['depth'] ); |
|
| 95 | - $esc_main_color = esc_attr( $chord_atts['main_color'] ); |
|
| 93 | + $esc_post_id = esc_attr($post_id); |
|
| 94 | + $esc_depth = esc_attr($chord_atts['depth']); |
|
| 95 | + $esc_main_color = esc_attr($chord_atts['main_color']); |
|
| 96 | 96 | |
| 97 | 97 | // Building template. |
| 98 | 98 | // TODO: in the HTML code there are static CSS rules. Move them to the CSS file. |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * |
| 121 | 121 | * @param object $amp_template The template. |
| 122 | 122 | */ |
| 123 | - public function amp_post_template_css( $amp_template ) { |
|
| 123 | + public function amp_post_template_css($amp_template) { |
|
| 124 | 124 | |
| 125 | 125 | // Hide the `wl-chord` when in AMP. |
| 126 | 126 | ?> |