@@ -16,35 +16,35 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Wordlift_Related_Entities_Cloud_Widget extends Wordlift_Widget { |
18 | 18 | |
19 | - /** |
|
20 | - * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
21 | - * |
|
22 | - * @since 3.11.0 |
|
23 | - */ |
|
24 | - public function __construct() { |
|
25 | - parent::__construct( |
|
26 | - 'wl_related_entities_cloud', |
|
27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
28 | - array( |
|
29 | - 'classname' => 'wl_related_entities_cloud', |
|
30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
31 | - ) |
|
32 | - ); |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @inheritdoc |
|
38 | - */ |
|
39 | - public function form( $instance ) { |
|
40 | - $title_id = $this->get_field_id( 'title' ); |
|
41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
42 | - ?> |
|
19 | + /** |
|
20 | + * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
21 | + * |
|
22 | + * @since 3.11.0 |
|
23 | + */ |
|
24 | + public function __construct() { |
|
25 | + parent::__construct( |
|
26 | + 'wl_related_entities_cloud', |
|
27 | + __( 'WordLift Entities Cloud', 'wordlift' ), |
|
28 | + array( |
|
29 | + 'classname' => 'wl_related_entities_cloud', |
|
30 | + 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
31 | + ) |
|
32 | + ); |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @inheritdoc |
|
38 | + */ |
|
39 | + public function form( $instance ) { |
|
40 | + $title_id = $this->get_field_id( 'title' ); |
|
41 | + $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
42 | + ?> |
|
43 | 43 | |
44 | 44 | <p><label for="<?php echo esc_attr( $title_id ); ?>"> |
45 | 45 | <?php |
46 | - esc_html_e( 'Title:', 'wordlift' ); |
|
47 | - ?> |
|
46 | + esc_html_e( 'Title:', 'wordlift' ); |
|
47 | + ?> |
|
48 | 48 | </label> |
49 | 49 | <input type="text" class="widefat" |
50 | 50 | id="<?php echo esc_attr( $title_id ); ?>" |
@@ -54,67 +54,67 @@ discard block |
||
54 | 54 | |
55 | 55 | <?php |
56 | 56 | |
57 | - return 'wl_related_entities_cloud_form'; |
|
58 | - } |
|
57 | + return 'wl_related_entities_cloud_form'; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritdoc |
|
62 | - */ |
|
63 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
64 | - public function update( $new_instance, $old_instance ) { |
|
60 | + /** |
|
61 | + * @inheritdoc |
|
62 | + */ |
|
63 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
64 | + public function update( $new_instance, $old_instance ) { |
|
65 | 65 | |
66 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
67 | - } |
|
66 | + return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @inheritdoc |
|
71 | - */ |
|
72 | - public function widget( $args, $instance ) { |
|
69 | + /** |
|
70 | + * @inheritdoc |
|
71 | + */ |
|
72 | + public function widget( $args, $instance ) { |
|
73 | 73 | |
74 | - /* |
|
74 | + /* |
|
75 | 75 | * Use the shortcode to calculate the HTML required to show the cloud |
76 | 76 | * if there is no such html do not render the widget at all. |
77 | 77 | */ |
78 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
79 | - if ( empty( $cloud_html ) ) { |
|
80 | - return false; |
|
81 | - } |
|
82 | - |
|
83 | - // The widget title. |
|
84 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
85 | - |
|
86 | - // Standard filter all widgets should apply |
|
87 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
88 | - |
|
89 | - echo wp_kses( $args['before_widget'], wp_kses_allowed_html( 'post' ) ); |
|
90 | - |
|
91 | - if ( $title ) { |
|
92 | - echo wp_kses( $args['before_title'], wp_kses_allowed_html( 'post' ) ); |
|
93 | - echo esc_html( $title ); |
|
94 | - echo wp_kses( $args['after_title'], wp_kses_allowed_html( 'post' ) ); |
|
95 | - } |
|
96 | - |
|
97 | - echo wp_kses( |
|
98 | - $cloud_html, |
|
99 | - array( |
|
100 | - 'div' => array( 'class' => array() ), |
|
101 | - 'span' => array( 'class' => array() ), |
|
102 | - 'a' => array( |
|
103 | - 'href' => array(), |
|
104 | - 'class' => array(), |
|
105 | - 'style' => array(), |
|
106 | - 'aria-label' => array(), |
|
107 | - ), |
|
108 | - 'ul' => array( |
|
109 | - 'class' => array(), |
|
110 | - 'role' => array(), |
|
111 | - ), |
|
112 | - 'li' => array(), |
|
113 | - ) |
|
114 | - ); |
|
115 | - |
|
116 | - echo wp_kses( $args['after_widget'], wp_kses_allowed_html( 'post' ) ); |
|
117 | - |
|
118 | - } |
|
78 | + $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
79 | + if ( empty( $cloud_html ) ) { |
|
80 | + return false; |
|
81 | + } |
|
82 | + |
|
83 | + // The widget title. |
|
84 | + $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
85 | + |
|
86 | + // Standard filter all widgets should apply |
|
87 | + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
88 | + |
|
89 | + echo wp_kses( $args['before_widget'], wp_kses_allowed_html( 'post' ) ); |
|
90 | + |
|
91 | + if ( $title ) { |
|
92 | + echo wp_kses( $args['before_title'], wp_kses_allowed_html( 'post' ) ); |
|
93 | + echo esc_html( $title ); |
|
94 | + echo wp_kses( $args['after_title'], wp_kses_allowed_html( 'post' ) ); |
|
95 | + } |
|
96 | + |
|
97 | + echo wp_kses( |
|
98 | + $cloud_html, |
|
99 | + array( |
|
100 | + 'div' => array( 'class' => array() ), |
|
101 | + 'span' => array( 'class' => array() ), |
|
102 | + 'a' => array( |
|
103 | + 'href' => array(), |
|
104 | + 'class' => array(), |
|
105 | + 'style' => array(), |
|
106 | + 'aria-label' => array(), |
|
107 | + ), |
|
108 | + 'ul' => array( |
|
109 | + 'class' => array(), |
|
110 | + 'role' => array(), |
|
111 | + ), |
|
112 | + 'li' => array(), |
|
113 | + ) |
|
114 | + ); |
|
115 | + |
|
116 | + echo wp_kses( $args['after_widget'], wp_kses_allowed_html( 'post' ) ); |
|
117 | + |
|
118 | + } |
|
119 | 119 | |
120 | 120 | } |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | public function __construct() { |
25 | 25 | parent::__construct( |
26 | 26 | 'wl_related_entities_cloud', |
27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
27 | + __('WordLift Entities Cloud', 'wordlift'), |
|
28 | 28 | array( |
29 | 29 | 'classname' => 'wl_related_entities_cloud', |
30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
30 | + 'description' => __('Display entities related to the current post/entity in a tag cloud.', 'wordlift'), |
|
31 | 31 | ) |
32 | 32 | ); |
33 | 33 | |
@@ -36,20 +36,20 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @inheritdoc |
38 | 38 | */ |
39 | - public function form( $instance ) { |
|
40 | - $title_id = $this->get_field_id( 'title' ); |
|
41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
39 | + public function form($instance) { |
|
40 | + $title_id = $this->get_field_id('title'); |
|
41 | + $instance['title'] = ! empty($instance['title']) ? esc_attr($instance['title']) : ''; |
|
42 | 42 | ?> |
43 | 43 | |
44 | - <p><label for="<?php echo esc_attr( $title_id ); ?>"> |
|
44 | + <p><label for="<?php echo esc_attr($title_id); ?>"> |
|
45 | 45 | <?php |
46 | - esc_html_e( 'Title:', 'wordlift' ); |
|
46 | + esc_html_e('Title:', 'wordlift'); |
|
47 | 47 | ?> |
48 | 48 | </label> |
49 | 49 | <input type="text" class="widefat" |
50 | - id="<?php echo esc_attr( $title_id ); ?>" |
|
51 | - name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
|
52 | - value="<?php echo esc_attr( $instance['title'] ); ?>"/> |
|
50 | + id="<?php echo esc_attr($title_id); ?>" |
|
51 | + name="<?php echo esc_attr($this->get_field_name('title')); ?>" |
|
52 | + value="<?php echo esc_attr($instance['title']); ?>"/> |
|
53 | 53 | </p> |
54 | 54 | |
55 | 55 | <?php |
@@ -61,44 +61,44 @@ discard block |
||
61 | 61 | * @inheritdoc |
62 | 62 | */ |
63 | 63 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
64 | - public function update( $new_instance, $old_instance ) { |
|
64 | + public function update($new_instance, $old_instance) { |
|
65 | 65 | |
66 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
66 | + return array('title' => sanitize_text_field($new_instance['title'])); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @inheritdoc |
71 | 71 | */ |
72 | - public function widget( $args, $instance ) { |
|
72 | + public function widget($args, $instance) { |
|
73 | 73 | |
74 | 74 | /* |
75 | 75 | * Use the shortcode to calculate the HTML required to show the cloud |
76 | 76 | * if there is no such html do not render the widget at all. |
77 | 77 | */ |
78 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
79 | - if ( empty( $cloud_html ) ) { |
|
78 | + $cloud_html = do_shortcode('[wl_cloud]'); |
|
79 | + if (empty($cloud_html)) { |
|
80 | 80 | return false; |
81 | 81 | } |
82 | 82 | |
83 | 83 | // The widget title. |
84 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
84 | + $title = empty($instance['title']) ? __('Related Entities', 'wordlift') : $instance['title']; |
|
85 | 85 | |
86 | 86 | // Standard filter all widgets should apply |
87 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
87 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
88 | 88 | |
89 | - echo wp_kses( $args['before_widget'], wp_kses_allowed_html( 'post' ) ); |
|
89 | + echo wp_kses($args['before_widget'], wp_kses_allowed_html('post')); |
|
90 | 90 | |
91 | - if ( $title ) { |
|
92 | - echo wp_kses( $args['before_title'], wp_kses_allowed_html( 'post' ) ); |
|
93 | - echo esc_html( $title ); |
|
94 | - echo wp_kses( $args['after_title'], wp_kses_allowed_html( 'post' ) ); |
|
91 | + if ($title) { |
|
92 | + echo wp_kses($args['before_title'], wp_kses_allowed_html('post')); |
|
93 | + echo esc_html($title); |
|
94 | + echo wp_kses($args['after_title'], wp_kses_allowed_html('post')); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | echo wp_kses( |
98 | 98 | $cloud_html, |
99 | 99 | array( |
100 | - 'div' => array( 'class' => array() ), |
|
101 | - 'span' => array( 'class' => array() ), |
|
100 | + 'div' => array('class' => array()), |
|
101 | + 'span' => array('class' => array()), |
|
102 | 102 | 'a' => array( |
103 | 103 | 'href' => array(), |
104 | 104 | 'class' => array(), |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | ) |
114 | 114 | ); |
115 | 115 | |
116 | - echo wp_kses( $args['after_widget'], wp_kses_allowed_html( 'post' ) ); |
|
116 | + echo wp_kses($args['after_widget'], wp_kses_allowed_html('post')); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 |
@@ -17,124 +17,124 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class Wordlift_Faceted_Search_Shortcode extends Wordlift_Shortcode { |
19 | 19 | |
20 | - /** |
|
21 | - * {@inheritdoc} |
|
22 | - */ |
|
23 | - const SHORTCODE = 'wl_faceted_search'; |
|
24 | - |
|
25 | - public function __construct() { |
|
26 | - parent::__construct(); |
|
27 | - $this->register_block_type(); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * {@inheritdoc} |
|
32 | - */ |
|
33 | - public function render( $atts ) { |
|
34 | - |
|
35 | - return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
36 | - : $this->web_shortcode( $atts ); |
|
37 | - } |
|
38 | - |
|
39 | - private function register_block_type() { |
|
40 | - |
|
41 | - $scope = $this; |
|
42 | - |
|
43 | - add_action( |
|
44 | - 'init', |
|
45 | - function () use ( $scope ) { |
|
46 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
47 | - // Gutenberg is not active. |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - register_block_type( |
|
52 | - 'wordlift/faceted-search', |
|
53 | - array( |
|
54 | - 'editor_script' => 'wl-block-editor', |
|
55 | - 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
56 | - $attr_code = ''; |
|
57 | - foreach ( $attributes as $key => $value ) { |
|
58 | - $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
59 | - } |
|
60 | - |
|
61 | - return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
62 | - }, |
|
63 | - |
|
64 | - 'attributes' => $scope->get_block_attributes(), |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Shared function used by web_shortcode and amp_shortcode |
|
73 | - * Bootstrap logic for attributes extraction and boolean filtering |
|
74 | - * |
|
75 | - * @param array $atts Shortcode attributes. |
|
76 | - * |
|
77 | - * @return array $shortcode_atts |
|
78 | - * @since 3.20.0 |
|
79 | - */ |
|
80 | - private function make_shortcode_atts( $atts ) { |
|
81 | - |
|
82 | - // Extract attributes and set default values. |
|
83 | - $shortcode_atts = shortcode_atts( |
|
84 | - array( |
|
85 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
86 | - 'limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
87 | - 'post_id' => '', |
|
88 | - 'template_id' => '', |
|
89 | - 'uniqid' => uniqid( 'wl-faceted-widget-' ), |
|
90 | - 'post_types' => '', |
|
91 | - ), |
|
92 | - $atts |
|
93 | - ); |
|
94 | - |
|
95 | - return $shortcode_atts; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Function in charge of diplaying the [wl-faceted-search] in web mode. |
|
100 | - * |
|
101 | - * @param array $atts Shortcode attributes. |
|
102 | - * |
|
103 | - * @return string Shortcode HTML for web |
|
104 | - * @since 3.20.0 |
|
105 | - */ |
|
106 | - private function web_shortcode( $atts ) { |
|
107 | - |
|
108 | - // attributes extraction and boolean filtering |
|
109 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
110 | - |
|
111 | - // avoid building the widget when no post_id is specified and there is a list of posts. |
|
112 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
117 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | - $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
121 | - |
|
122 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
123 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
124 | - $rest_url = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] ); |
|
125 | - $rest_url = esc_attr( $rest_url ); |
|
126 | - |
|
127 | - // avoid building the widget when no valid $rest_url |
|
128 | - if ( ! $rest_url ) { |
|
129 | - return; |
|
130 | - } |
|
131 | - |
|
132 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
133 | - $template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' ); |
|
134 | - |
|
135 | - return wp_kses( |
|
136 | - sprintf( |
|
137 | - ' |
|
20 | + /** |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | + const SHORTCODE = 'wl_faceted_search'; |
|
24 | + |
|
25 | + public function __construct() { |
|
26 | + parent::__construct(); |
|
27 | + $this->register_block_type(); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * {@inheritdoc} |
|
32 | + */ |
|
33 | + public function render( $atts ) { |
|
34 | + |
|
35 | + return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
36 | + : $this->web_shortcode( $atts ); |
|
37 | + } |
|
38 | + |
|
39 | + private function register_block_type() { |
|
40 | + |
|
41 | + $scope = $this; |
|
42 | + |
|
43 | + add_action( |
|
44 | + 'init', |
|
45 | + function () use ( $scope ) { |
|
46 | + if ( ! function_exists( 'register_block_type' ) ) { |
|
47 | + // Gutenberg is not active. |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + register_block_type( |
|
52 | + 'wordlift/faceted-search', |
|
53 | + array( |
|
54 | + 'editor_script' => 'wl-block-editor', |
|
55 | + 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
56 | + $attr_code = ''; |
|
57 | + foreach ( $attributes as $key => $value ) { |
|
58 | + $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
59 | + } |
|
60 | + |
|
61 | + return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
62 | + }, |
|
63 | + |
|
64 | + 'attributes' => $scope->get_block_attributes(), |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Shared function used by web_shortcode and amp_shortcode |
|
73 | + * Bootstrap logic for attributes extraction and boolean filtering |
|
74 | + * |
|
75 | + * @param array $atts Shortcode attributes. |
|
76 | + * |
|
77 | + * @return array $shortcode_atts |
|
78 | + * @since 3.20.0 |
|
79 | + */ |
|
80 | + private function make_shortcode_atts( $atts ) { |
|
81 | + |
|
82 | + // Extract attributes and set default values. |
|
83 | + $shortcode_atts = shortcode_atts( |
|
84 | + array( |
|
85 | + 'title' => __( 'Related articles', 'wordlift' ), |
|
86 | + 'limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
87 | + 'post_id' => '', |
|
88 | + 'template_id' => '', |
|
89 | + 'uniqid' => uniqid( 'wl-faceted-widget-' ), |
|
90 | + 'post_types' => '', |
|
91 | + ), |
|
92 | + $atts |
|
93 | + ); |
|
94 | + |
|
95 | + return $shortcode_atts; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Function in charge of diplaying the [wl-faceted-search] in web mode. |
|
100 | + * |
|
101 | + * @param array $atts Shortcode attributes. |
|
102 | + * |
|
103 | + * @return string Shortcode HTML for web |
|
104 | + * @since 3.20.0 |
|
105 | + */ |
|
106 | + private function web_shortcode( $atts ) { |
|
107 | + |
|
108 | + // attributes extraction and boolean filtering |
|
109 | + $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
110 | + |
|
111 | + // avoid building the widget when no post_id is specified and there is a list of posts. |
|
112 | + if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
117 | + $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | + $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | + $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | + $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
121 | + |
|
122 | + $permalink_structure = get_option( 'permalink_structure' ); |
|
123 | + $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
124 | + $rest_url = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] ); |
|
125 | + $rest_url = esc_attr( $rest_url ); |
|
126 | + |
|
127 | + // avoid building the widget when no valid $rest_url |
|
128 | + if ( ! $rest_url ) { |
|
129 | + return; |
|
130 | + } |
|
131 | + |
|
132 | + wp_enqueue_script( 'wordlift-cloud' ); |
|
133 | + $template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' ); |
|
134 | + |
|
135 | + return wp_kses( |
|
136 | + sprintf( |
|
137 | + ' |
|
138 | 138 | <div id="%s" |
139 | 139 | class="wl-faceted" |
140 | 140 | data-rest-url="%s" |
@@ -142,77 +142,77 @@ discard block |
||
142 | 142 | data-template-id="%s" |
143 | 143 | data-template-url="%s"></div> |
144 | 144 | ', |
145 | - esc_attr( $faceted_id ), |
|
146 | - esc_attr( $rest_url ), |
|
147 | - esc_attr( $title ), |
|
148 | - esc_attr( $template_id ), |
|
149 | - esc_url( $template_url ) |
|
150 | - ), |
|
151 | - array( |
|
152 | - 'div' => array( |
|
153 | - 'id' => array(), |
|
154 | - 'class' => array(), |
|
155 | - 'data-rest-url' => array(), |
|
156 | - 'data-title' => array(), |
|
157 | - 'data-template-id' => array(), |
|
158 | - 'data-template-url' => array(), |
|
159 | - ), |
|
160 | - ) |
|
161 | - ); |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Function in charge of diplaying the [wl-faceted-search] in amp mode. |
|
167 | - * |
|
168 | - * @param array $atts Shortcode attributes. |
|
169 | - * |
|
170 | - * @return string Shortcode HTML for amp |
|
171 | - * @since 3.20.0 |
|
172 | - */ |
|
173 | - private function amp_shortcode( $atts ) { |
|
174 | - |
|
175 | - // attributes extraction and boolean filtering |
|
176 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
177 | - |
|
178 | - // avoid building the widget when no post_id is specified and there is a list of posts. |
|
179 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
180 | - return; |
|
181 | - } |
|
182 | - |
|
183 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
184 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
185 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
186 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
187 | - $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
188 | - |
|
189 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
190 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
191 | - $rest_url = $post ? rest_url( |
|
192 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
193 | - array( |
|
194 | - 'amp' => 1, |
|
195 | - 'post_id' => $post->ID, |
|
196 | - 'limit' => $limit, |
|
197 | - ) |
|
198 | - ) |
|
199 | - ) : false; |
|
200 | - |
|
201 | - // avoid building the widget when no valid $rest_url |
|
202 | - if ( ! $rest_url ) { |
|
203 | - return; |
|
204 | - } |
|
205 | - |
|
206 | - // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
|
207 | - // This is a hackish way, but this works for http and https URLs |
|
208 | - $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
209 | - |
|
210 | - if ( empty( $template_id ) ) { |
|
211 | - $template_id = 'template-' . $faceted_id; |
|
212 | - wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
213 | - } |
|
214 | - |
|
215 | - return <<<HTML |
|
145 | + esc_attr( $faceted_id ), |
|
146 | + esc_attr( $rest_url ), |
|
147 | + esc_attr( $title ), |
|
148 | + esc_attr( $template_id ), |
|
149 | + esc_url( $template_url ) |
|
150 | + ), |
|
151 | + array( |
|
152 | + 'div' => array( |
|
153 | + 'id' => array(), |
|
154 | + 'class' => array(), |
|
155 | + 'data-rest-url' => array(), |
|
156 | + 'data-title' => array(), |
|
157 | + 'data-template-id' => array(), |
|
158 | + 'data-template-url' => array(), |
|
159 | + ), |
|
160 | + ) |
|
161 | + ); |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Function in charge of diplaying the [wl-faceted-search] in amp mode. |
|
167 | + * |
|
168 | + * @param array $atts Shortcode attributes. |
|
169 | + * |
|
170 | + * @return string Shortcode HTML for amp |
|
171 | + * @since 3.20.0 |
|
172 | + */ |
|
173 | + private function amp_shortcode( $atts ) { |
|
174 | + |
|
175 | + // attributes extraction and boolean filtering |
|
176 | + $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
177 | + |
|
178 | + // avoid building the widget when no post_id is specified and there is a list of posts. |
|
179 | + if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
180 | + return; |
|
181 | + } |
|
182 | + |
|
183 | + $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
184 | + $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
185 | + $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
186 | + $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
187 | + $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
188 | + |
|
189 | + $permalink_structure = get_option( 'permalink_structure' ); |
|
190 | + $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
191 | + $rest_url = $post ? rest_url( |
|
192 | + WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
193 | + array( |
|
194 | + 'amp' => 1, |
|
195 | + 'post_id' => $post->ID, |
|
196 | + 'limit' => $limit, |
|
197 | + ) |
|
198 | + ) |
|
199 | + ) : false; |
|
200 | + |
|
201 | + // avoid building the widget when no valid $rest_url |
|
202 | + if ( ! $rest_url ) { |
|
203 | + return; |
|
204 | + } |
|
205 | + |
|
206 | + // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
|
207 | + // This is a hackish way, but this works for http and https URLs |
|
208 | + $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
209 | + |
|
210 | + if ( empty( $template_id ) ) { |
|
211 | + $template_id = 'template-' . $faceted_id; |
|
212 | + wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
213 | + } |
|
214 | + |
|
215 | + return <<<HTML |
|
216 | 216 | <div id="{$faceted_id}" class="wl-amp-faceted"> |
217 | 217 | <h2 class="wl-headline">{$title}</h2> |
218 | 218 | <amp-state id="referencedPosts"> |
@@ -278,66 +278,66 @@ discard block |
||
278 | 278 | </section> |
279 | 279 | </div> |
280 | 280 | HTML; |
281 | - } |
|
282 | - |
|
283 | - public function get_block_attributes() { |
|
284 | - return array( |
|
285 | - 'title' => array( |
|
286 | - 'type' => 'string', |
|
287 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
288 | - ), |
|
289 | - 'template_id' => array( |
|
290 | - 'type' => 'string', |
|
291 | - 'default' => '', |
|
292 | - ), |
|
293 | - 'post_id' => array( |
|
294 | - 'type' => 'number', |
|
295 | - 'default' => '', |
|
296 | - ), |
|
297 | - 'uniqid' => array( |
|
298 | - 'type' => 'string', |
|
299 | - 'default' => '', |
|
300 | - ), |
|
301 | - 'limit' => array( |
|
302 | - 'type' => 'number', |
|
303 | - 'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
304 | - ), |
|
305 | - 'preview' => array( |
|
306 | - 'type' => 'boolean', |
|
307 | - 'default' => false, |
|
308 | - ), |
|
309 | - 'preview_src' => array( |
|
310 | - 'type' => 'string', |
|
311 | - 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png', |
|
312 | - ), |
|
313 | - 'post_types' => array( |
|
314 | - 'type' => 'string', |
|
315 | - 'default' => '', |
|
316 | - ), |
|
317 | - ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * @param $post |
|
322 | - * @param $delimiter |
|
323 | - * @param $limit |
|
324 | - * |
|
325 | - * @param $post_types |
|
326 | - * |
|
327 | - * @return bool|string |
|
328 | - */ |
|
329 | - public function get_rest_url( $post, $delimiter, $limit, $post_types ) { |
|
330 | - $rest_url = $post ? rest_url( |
|
331 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
332 | - array( |
|
333 | - 'post_id' => $post->ID, |
|
334 | - 'limit' => $limit, |
|
335 | - 'post_types' => $post_types, |
|
336 | - ) |
|
337 | - ) |
|
338 | - ) : false; |
|
339 | - |
|
340 | - return $rest_url; |
|
341 | - } |
|
281 | + } |
|
282 | + |
|
283 | + public function get_block_attributes() { |
|
284 | + return array( |
|
285 | + 'title' => array( |
|
286 | + 'type' => 'string', |
|
287 | + 'default' => __( 'Related articles', 'wordlift' ), |
|
288 | + ), |
|
289 | + 'template_id' => array( |
|
290 | + 'type' => 'string', |
|
291 | + 'default' => '', |
|
292 | + ), |
|
293 | + 'post_id' => array( |
|
294 | + 'type' => 'number', |
|
295 | + 'default' => '', |
|
296 | + ), |
|
297 | + 'uniqid' => array( |
|
298 | + 'type' => 'string', |
|
299 | + 'default' => '', |
|
300 | + ), |
|
301 | + 'limit' => array( |
|
302 | + 'type' => 'number', |
|
303 | + 'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
304 | + ), |
|
305 | + 'preview' => array( |
|
306 | + 'type' => 'boolean', |
|
307 | + 'default' => false, |
|
308 | + ), |
|
309 | + 'preview_src' => array( |
|
310 | + 'type' => 'string', |
|
311 | + 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png', |
|
312 | + ), |
|
313 | + 'post_types' => array( |
|
314 | + 'type' => 'string', |
|
315 | + 'default' => '', |
|
316 | + ), |
|
317 | + ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * @param $post |
|
322 | + * @param $delimiter |
|
323 | + * @param $limit |
|
324 | + * |
|
325 | + * @param $post_types |
|
326 | + * |
|
327 | + * @return bool|string |
|
328 | + */ |
|
329 | + public function get_rest_url( $post, $delimiter, $limit, $post_types ) { |
|
330 | + $rest_url = $post ? rest_url( |
|
331 | + WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
332 | + array( |
|
333 | + 'post_id' => $post->ID, |
|
334 | + 'limit' => $limit, |
|
335 | + 'post_types' => $post_types, |
|
336 | + ) |
|
337 | + ) |
|
338 | + ) : false; |
|
339 | + |
|
340 | + return $rest_url; |
|
341 | + } |
|
342 | 342 | |
343 | 343 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * {@inheritdoc} |
32 | 32 | */ |
33 | - public function render( $atts ) { |
|
33 | + public function render($atts) { |
|
34 | 34 | |
35 | - return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts ) |
|
36 | - : $this->web_shortcode( $atts ); |
|
35 | + return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts) |
|
36 | + : $this->web_shortcode($atts); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | private function register_block_type() { |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | |
43 | 43 | add_action( |
44 | 44 | 'init', |
45 | - function () use ( $scope ) { |
|
46 | - if ( ! function_exists( 'register_block_type' ) ) { |
|
45 | + function() use ($scope) { |
|
46 | + if ( ! function_exists('register_block_type')) { |
|
47 | 47 | // Gutenberg is not active. |
48 | 48 | return; |
49 | 49 | } |
@@ -52,13 +52,13 @@ discard block |
||
52 | 52 | 'wordlift/faceted-search', |
53 | 53 | array( |
54 | 54 | 'editor_script' => 'wl-block-editor', |
55 | - 'render_callback' => function ( $attributes ) use ( $scope ) { |
|
55 | + 'render_callback' => function($attributes) use ($scope) { |
|
56 | 56 | $attr_code = ''; |
57 | - foreach ( $attributes as $key => $value ) { |
|
58 | - $attr_code .= $key . '="' . htmlentities( $value ) . '" '; |
|
57 | + foreach ($attributes as $key => $value) { |
|
58 | + $attr_code .= $key.'="'.htmlentities($value).'" '; |
|
59 | 59 | } |
60 | 60 | |
61 | - return '[' . $scope::SHORTCODE . ' ' . $attr_code . ']'; |
|
61 | + return '['.$scope::SHORTCODE.' '.$attr_code.']'; |
|
62 | 62 | }, |
63 | 63 | |
64 | 64 | 'attributes' => $scope->get_block_attributes(), |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | * @return array $shortcode_atts |
78 | 78 | * @since 3.20.0 |
79 | 79 | */ |
80 | - private function make_shortcode_atts( $atts ) { |
|
80 | + private function make_shortcode_atts($atts) { |
|
81 | 81 | |
82 | 82 | // Extract attributes and set default values. |
83 | 83 | $shortcode_atts = shortcode_atts( |
84 | 84 | array( |
85 | - 'title' => __( 'Related articles', 'wordlift' ), |
|
86 | - 'limit' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
85 | + 'title' => __('Related articles', 'wordlift'), |
|
86 | + 'limit' => apply_filters('wl_faceted_search_default_limit', 10), |
|
87 | 87 | 'post_id' => '', |
88 | 88 | 'template_id' => '', |
89 | - 'uniqid' => uniqid( 'wl-faceted-widget-' ), |
|
89 | + 'uniqid' => uniqid('wl-faceted-widget-'), |
|
90 | 90 | 'post_types' => '', |
91 | 91 | ), |
92 | 92 | $atts |
@@ -103,34 +103,34 @@ discard block |
||
103 | 103 | * @return string Shortcode HTML for web |
104 | 104 | * @since 3.20.0 |
105 | 105 | */ |
106 | - private function web_shortcode( $atts ) { |
|
106 | + private function web_shortcode($atts) { |
|
107 | 107 | |
108 | 108 | // attributes extraction and boolean filtering |
109 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
109 | + $shortcode_atts = $this->make_shortcode_atts($atts); |
|
110 | 110 | |
111 | 111 | // avoid building the widget when no post_id is specified and there is a list of posts. |
112 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
112 | + if (empty($shortcode_atts['post_id']) && ! is_singular()) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
117 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
118 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
119 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
120 | - $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
116 | + $post = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post(); |
|
117 | + $title = esc_attr(sanitize_text_field($shortcode_atts['title'])); |
|
118 | + $template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id'])); |
|
119 | + $limit = esc_attr(sanitize_text_field($shortcode_atts['limit'])); |
|
120 | + $faceted_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-'); |
|
121 | 121 | |
122 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
123 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
124 | - $rest_url = $this->get_rest_url( $post, $delimiter, $limit, $shortcode_atts['post_types'] ); |
|
125 | - $rest_url = esc_attr( $rest_url ); |
|
122 | + $permalink_structure = get_option('permalink_structure'); |
|
123 | + $delimiter = empty($permalink_structure) ? '&' : '?'; |
|
124 | + $rest_url = $this->get_rest_url($post, $delimiter, $limit, $shortcode_atts['post_types']); |
|
125 | + $rest_url = esc_attr($rest_url); |
|
126 | 126 | |
127 | 127 | // avoid building the widget when no valid $rest_url |
128 | - if ( ! $rest_url ) { |
|
128 | + if ( ! $rest_url) { |
|
129 | 129 | return; |
130 | 130 | } |
131 | 131 | |
132 | - wp_enqueue_script( 'wordlift-cloud' ); |
|
133 | - $template_url = get_rest_url( null, '/wordlift/v1/faceted-search/template' ); |
|
132 | + wp_enqueue_script('wordlift-cloud'); |
|
133 | + $template_url = get_rest_url(null, '/wordlift/v1/faceted-search/template'); |
|
134 | 134 | |
135 | 135 | return wp_kses( |
136 | 136 | sprintf( |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | data-template-id="%s" |
143 | 143 | data-template-url="%s"></div> |
144 | 144 | ', |
145 | - esc_attr( $faceted_id ), |
|
146 | - esc_attr( $rest_url ), |
|
147 | - esc_attr( $title ), |
|
148 | - esc_attr( $template_id ), |
|
149 | - esc_url( $template_url ) |
|
145 | + esc_attr($faceted_id), |
|
146 | + esc_attr($rest_url), |
|
147 | + esc_attr($title), |
|
148 | + esc_attr($template_id), |
|
149 | + esc_url($template_url) |
|
150 | 150 | ), |
151 | 151 | array( |
152 | 152 | 'div' => array( |
@@ -170,26 +170,26 @@ discard block |
||
170 | 170 | * @return string Shortcode HTML for amp |
171 | 171 | * @since 3.20.0 |
172 | 172 | */ |
173 | - private function amp_shortcode( $atts ) { |
|
173 | + private function amp_shortcode($atts) { |
|
174 | 174 | |
175 | 175 | // attributes extraction and boolean filtering |
176 | - $shortcode_atts = $this->make_shortcode_atts( $atts ); |
|
176 | + $shortcode_atts = $this->make_shortcode_atts($atts); |
|
177 | 177 | |
178 | 178 | // avoid building the widget when no post_id is specified and there is a list of posts. |
179 | - if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) { |
|
179 | + if (empty($shortcode_atts['post_id']) && ! is_singular()) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
183 | - $post = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( sanitize_text_field( $shortcode_atts['post_id'] ) ) ) : get_post(); |
|
184 | - $title = esc_attr( sanitize_text_field( $shortcode_atts['title'] ) ); |
|
185 | - $template_id = esc_attr( sanitize_text_field( $shortcode_atts['template_id'] ) ); |
|
186 | - $limit = esc_attr( sanitize_text_field( $shortcode_atts['limit'] ) ); |
|
187 | - $faceted_id = ! empty( $shortcode_atts['uniqid'] ) ? esc_attr( sanitize_text_field( $shortcode_atts['uniqid'] ) ) : uniqid( 'wl-faceted-widget-' ); |
|
183 | + $post = ! empty($shortcode_atts['post_id']) ? get_post(intval(sanitize_text_field($shortcode_atts['post_id']))) : get_post(); |
|
184 | + $title = esc_attr(sanitize_text_field($shortcode_atts['title'])); |
|
185 | + $template_id = esc_attr(sanitize_text_field($shortcode_atts['template_id'])); |
|
186 | + $limit = esc_attr(sanitize_text_field($shortcode_atts['limit'])); |
|
187 | + $faceted_id = ! empty($shortcode_atts['uniqid']) ? esc_attr(sanitize_text_field($shortcode_atts['uniqid'])) : uniqid('wl-faceted-widget-'); |
|
188 | 188 | |
189 | - $permalink_structure = get_option( 'permalink_structure' ); |
|
190 | - $delimiter = empty( $permalink_structure ) ? '&' : '?'; |
|
189 | + $permalink_structure = get_option('permalink_structure'); |
|
190 | + $delimiter = empty($permalink_structure) ? '&' : '?'; |
|
191 | 191 | $rest_url = $post ? rest_url( |
192 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
192 | + WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query( |
|
193 | 193 | array( |
194 | 194 | 'amp' => 1, |
195 | 195 | 'post_id' => $post->ID, |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | ) : false; |
200 | 200 | |
201 | 201 | // avoid building the widget when no valid $rest_url |
202 | - if ( ! $rest_url ) { |
|
202 | + if ( ! $rest_url) { |
|
203 | 203 | return; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS. |
207 | 207 | // This is a hackish way, but this works for http and https URLs |
208 | - $rest_url = str_replace( array( 'http:', 'https:' ), '', $rest_url ); |
|
208 | + $rest_url = str_replace(array('http:', 'https:'), '', $rest_url); |
|
209 | 209 | |
210 | - if ( empty( $template_id ) ) { |
|
211 | - $template_id = 'template-' . $faceted_id; |
|
212 | - wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( __DIR__ ) . '/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION ); |
|
210 | + if (empty($template_id)) { |
|
211 | + $template_id = 'template-'.$faceted_id; |
|
212 | + wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(__DIR__).'/css/wordlift-amp-custom.min.css', array(), WORDLIFT_VERSION); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return <<<HTML |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | return array( |
285 | 285 | 'title' => array( |
286 | 286 | 'type' => 'string', |
287 | - 'default' => __( 'Related articles', 'wordlift' ), |
|
287 | + 'default' => __('Related articles', 'wordlift'), |
|
288 | 288 | ), |
289 | 289 | 'template_id' => array( |
290 | 290 | 'type' => 'string', |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ), |
301 | 301 | 'limit' => array( |
302 | 302 | 'type' => 'number', |
303 | - 'default' => apply_filters( 'wl_faceted_search_default_limit', 10 ), |
|
303 | + 'default' => apply_filters('wl_faceted_search_default_limit', 10), |
|
304 | 304 | ), |
305 | 305 | 'preview' => array( |
306 | 306 | 'type' => 'boolean', |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | ), |
309 | 309 | 'preview_src' => array( |
310 | 310 | 'type' => 'string', |
311 | - 'default' => WP_CONTENT_URL . '/plugins/wordlift/images/block-previews/faceted-search.png', |
|
311 | + 'default' => WP_CONTENT_URL.'/plugins/wordlift/images/block-previews/faceted-search.png', |
|
312 | 312 | ), |
313 | 313 | 'post_types' => array( |
314 | 314 | 'type' => 'string', |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @return bool|string |
328 | 328 | */ |
329 | - public function get_rest_url( $post, $delimiter, $limit, $post_types ) { |
|
329 | + public function get_rest_url($post, $delimiter, $limit, $post_types) { |
|
330 | 330 | $rest_url = $post ? rest_url( |
331 | - WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faceted-search' . $delimiter . build_query( |
|
331 | + WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faceted-search'.$delimiter.build_query( |
|
332 | 332 | array( |
333 | 333 | 'post_id' => $post->ID, |
334 | 334 | 'limit' => $limit, |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | private $custom_fields; |
10 | 10 | |
11 | - public function __construct( $schema_type, $custom_fields ) { |
|
11 | + public function __construct($schema_type, $custom_fields) { |
|
12 | 12 | $this->schema_type = $schema_type; |
13 | 13 | $this->custom_fields = $custom_fields; |
14 | 14 | } |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | class Schema_Field_Group { |
6 | 6 | |
7 | - private $schema_type; |
|
8 | - |
|
9 | - private $custom_fields; |
|
10 | - |
|
11 | - public function __construct( $schema_type, $custom_fields ) { |
|
12 | - $this->schema_type = $schema_type; |
|
13 | - $this->custom_fields = $custom_fields; |
|
14 | - } |
|
15 | - |
|
16 | - /** |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - public function get_schema_type() { |
|
20 | - return $this->schema_type; |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * @return mixed |
|
25 | - */ |
|
26 | - public function get_custom_fields() { |
|
27 | - return $this->custom_fields; |
|
28 | - } |
|
7 | + private $schema_type; |
|
8 | + |
|
9 | + private $custom_fields; |
|
10 | + |
|
11 | + public function __construct( $schema_type, $custom_fields ) { |
|
12 | + $this->schema_type = $schema_type; |
|
13 | + $this->custom_fields = $custom_fields; |
|
14 | + } |
|
15 | + |
|
16 | + /** |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + public function get_schema_type() { |
|
20 | + return $this->schema_type; |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * @return mixed |
|
25 | + */ |
|
26 | + public function get_custom_fields() { |
|
27 | + return $this->custom_fields; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | } |
@@ -7,6 +7,6 @@ |
||
7 | 7 | exit(1); |
8 | 8 | } |
9 | 9 | |
10 | -require_once __DIR__ . '/composer/autoload_real.php'; |
|
10 | +require_once __DIR__.'/composer/autoload_real.php'; |
|
11 | 11 | |
12 | 12 | return ComposerAutoloaderInit1fa7477671b8ce4e96024c7b54cda86e::getLoader(); |
@@ -4,23 +4,23 @@ |
||
4 | 4 | |
5 | 5 | $issues = array(); |
6 | 6 | |
7 | -if (!(PHP_VERSION_ID >= 50600)) { |
|
8 | - $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running ' . PHP_VERSION . '.'; |
|
7 | +if ( ! (PHP_VERSION_ID >= 50600)) { |
|
8 | + $issues[] = 'Your Composer dependencies require a PHP version ">= 5.6.0". You are running '.PHP_VERSION.'.'; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ($issues) { |
12 | - if (!headers_sent()) { |
|
12 | + if ( ! headers_sent()) { |
|
13 | 13 | header('HTTP/1.1 500 Internal Server Error'); |
14 | 14 | } |
15 | - if (!ini_get('display_errors')) { |
|
15 | + if ( ! ini_get('display_errors')) { |
|
16 | 16 | if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
17 | - fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL); |
|
18 | - } elseif (!headers_sent()) { |
|
19 | - echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL; |
|
17 | + fwrite(STDERR, 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.implode(PHP_EOL, $issues).PHP_EOL.PHP_EOL); |
|
18 | + } elseif ( ! headers_sent()) { |
|
19 | + echo 'Composer detected issues in your platform:'.PHP_EOL.PHP_EOL.str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)).PHP_EOL.PHP_EOL; |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | trigger_error( |
23 | - 'Composer detected issues in your platform: ' . implode(' ', $issues), |
|
23 | + 'Composer detected issues in your platform: '.implode(' ', $issues), |
|
24 | 24 | E_USER_ERROR |
25 | 25 | ); |
26 | 26 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = dirname($vendorDir); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Wordlift\\Modules\\Pods\\' => array($baseDir . '/includes'), |
|
9 | + 'Wordlift\\Modules\\Pods\\' => array($baseDir.'/includes'), |
|
10 | 10 | ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | 'version' => 'dev-master', |
6 | 6 | 'reference' => 'b333eb73cb4a7848d2797684071cc0f7264565da', |
7 | 7 | 'type' => 'wordpress-plugin', |
8 | - 'install_path' => __DIR__ . '/../../', |
|
8 | + 'install_path' => __DIR__.'/../../', |
|
9 | 9 | 'aliases' => array(), |
10 | 10 | 'dev' => true, |
11 | 11 | ), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | 'version' => 'dev-master', |
16 | 16 | 'reference' => 'b333eb73cb4a7848d2797684071cc0f7264565da', |
17 | 17 | 'type' => 'wordpress-plugin', |
18 | - 'install_path' => __DIR__ . '/../../', |
|
18 | + 'install_path' => __DIR__.'/../../', |
|
19 | 19 | 'aliases' => array(), |
20 | 20 | 'dev_requirement' => false, |
21 | 21 | ), |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | public static function loadClassLoader($class) |
10 | 10 | { |
11 | 11 | if ('Composer\Autoload\ClassLoader' === $class) { |
12 | - require __DIR__ . '/ClassLoader.php'; |
|
12 | + require __DIR__.'/ClassLoader.php'; |
|
13 | 13 | } |
14 | 14 | } |
15 | 15 | |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | return self::$loader; |
23 | 23 | } |
24 | 24 | |
25 | - require __DIR__ . '/platform_check.php'; |
|
25 | + require __DIR__.'/platform_check.php'; |
|
26 | 26 | |
27 | 27 | spl_autoload_register(array('ComposerAutoloaderInit1fa7477671b8ce4e96024c7b54cda86e', 'loadClassLoader'), true, true); |
28 | 28 | self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); |
29 | 29 | spl_autoload_unregister(array('ComposerAutoloaderInit1fa7477671b8ce4e96024c7b54cda86e', 'loadClassLoader')); |
30 | 30 | |
31 | - require __DIR__ . '/autoload_static.php'; |
|
31 | + require __DIR__.'/autoload_static.php'; |
|
32 | 32 | call_user_func(\Composer\Autoload\ComposerStaticInit1fa7477671b8ce4e96024c7b54cda86e::getInitializer($loader)); |
33 | 33 | |
34 | 34 | $loader->register(true); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getPrefixes() |
115 | 115 | { |
116 | - if (!empty($this->prefixesPsr0)) { |
|
116 | + if ( ! empty($this->prefixesPsr0)) { |
|
117 | 117 | return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
118 | 118 | } |
119 | 119 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function add($prefix, $paths, $prepend = false) |
185 | 185 | { |
186 | - if (!$prefix) { |
|
186 | + if ( ! $prefix) { |
|
187 | 187 | if ($prepend) { |
188 | 188 | $this->fallbackDirsPsr0 = array_merge( |
189 | 189 | (array) $paths, |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | $first = $prefix[0]; |
203 | - if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
203 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
204 | 204 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
205 | 205 | |
206 | 206 | return; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | */ |
233 | 233 | public function addPsr4($prefix, $paths, $prepend = false) |
234 | 234 | { |
235 | - if (!$prefix) { |
|
235 | + if ( ! $prefix) { |
|
236 | 236 | // Register directories for the root namespace. |
237 | 237 | if ($prepend) { |
238 | 238 | $this->fallbackDirsPsr4 = array_merge( |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | (array) $paths |
246 | 246 | ); |
247 | 247 | } |
248 | - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
248 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
249 | 249 | // Register directories for a new namespace. |
250 | 250 | $length = strlen($prefix); |
251 | 251 | if ('\\' !== $prefix[$length - 1]) { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function set($prefix, $paths) |
281 | 281 | { |
282 | - if (!$prefix) { |
|
282 | + if ( ! $prefix) { |
|
283 | 283 | $this->fallbackDirsPsr0 = (array) $paths; |
284 | 284 | } else { |
285 | 285 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function setPsr4($prefix, $paths) |
301 | 301 | { |
302 | - if (!$prefix) { |
|
302 | + if ( ! $prefix) { |
|
303 | 303 | $this->fallbackDirsPsr4 = (array) $paths; |
304 | 304 | } else { |
305 | 305 | $length = strlen($prefix); |
@@ -493,18 +493,18 @@ discard block |
||
493 | 493 | private function findFileWithExtension($class, $ext) |
494 | 494 | { |
495 | 495 | // PSR-4 lookup |
496 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
496 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
497 | 497 | |
498 | 498 | $first = $class[0]; |
499 | 499 | if (isset($this->prefixLengthsPsr4[$first])) { |
500 | 500 | $subPath = $class; |
501 | 501 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
502 | 502 | $subPath = substr($subPath, 0, $lastPos); |
503 | - $search = $subPath . '\\'; |
|
503 | + $search = $subPath.'\\'; |
|
504 | 504 | if (isset($this->prefixDirsPsr4[$search])) { |
505 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
505 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
506 | 506 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
507 | - if (file_exists($file = $dir . $pathEnd)) { |
|
507 | + if (file_exists($file = $dir.$pathEnd)) { |
|
508 | 508 | return $file; |
509 | 509 | } |
510 | 510 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | |
515 | 515 | // PSR-4 fallback dirs |
516 | 516 | foreach ($this->fallbackDirsPsr4 as $dir) { |
517 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
517 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
518 | 518 | return $file; |
519 | 519 | } |
520 | 520 | } |
@@ -526,14 +526,14 @@ discard block |
||
526 | 526 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
527 | 527 | } else { |
528 | 528 | // PEAR-like class name |
529 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
529 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | if (isset($this->prefixesPsr0[$first])) { |
533 | 533 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
534 | 534 | if (0 === strpos($class, $prefix)) { |
535 | 535 | foreach ($dirs as $dir) { |
536 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
536 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
537 | 537 | return $file; |
538 | 538 | } |
539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | // PSR-0 fallback dirs |
545 | 545 | foreach ($this->fallbackDirsPsr0 as $dir) { |
546 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
546 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
547 | 547 | return $file; |
548 | 548 | } |
549 | 549 | } |