Issues (924)

classes/frontend/class-output.php (182 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx\sharing\classes\frontend;
3
4
/**
5
 * Houses the functions for the Settings page.
6
 *
7
 * @package lsx-sharing
8
 */
9
class Output {
10
11
12
    /**
13
     * Holds class instance
14
     *
15
     * @since 1.0.0
16
     *
17
     * @var object \lsx\sharing\classes\frontend\Output()
18
     */
19
    protected static $instance = null;
0 ignored issues
show
Expected 1 blank line(s) before first member var; 2 found
Loading history...
20
21
    /**
22
     * Contructor
23
     */
24
    public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
25
         add_action('wp_enqueue_scripts', array( $this, 'assets' ), 5);
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
26
        add_filter('wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
27
        add_shortcode('lsx_sharing_buttons', array( $this, 'sharing_buttons_shortcode' ));
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
28
        // Storefront (storefront_loop_post, storefront_single_post).
29
        add_action('storefront_post_content_before', array( $this, 'sharing_buttons_template' ), 20);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
30
        // WooCommerce.
31
        add_action('woocommerce_share', array( $this, 'sharing_buttons_template' ));
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
32
33
        // General Post Types.
34
        add_action('lsx_entry_after', array( $this, 'output_sharing' ));
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
35
36
        // Tribe Events.
37
        add_filter('tribe_events_ical_single_event_links', array( $this, 'output_event_sharing' ), 10, 1);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
38
39
        // Sensei Integration.
40
        add_action('sensei_pagination', array( $this, 'output_sharing' ), 20);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
41
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
42
43
    /**
44
     * Return an instance of this class.
45
     *
46
     * @since 1.0.0
47
     *
48
     * @return object \lsx\sharing\classes\frontend\Output()    A single instance of this class.
49
     */
50
    public static function get_instance() {
51
         // If the single instance hasn't been set, set it now.
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
52
        if ( null == self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
53
            self::$instance = new self();
54
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
55
        return self::$instance;
56
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
57
58
    /**
59
     * Enques the assets.
60
     */
61
    public function assets() {
62
         if ( defined('WP_DEBUG') && true === WP_DEBUG ) {
0 ignored issues
show
The condition true === lsx\sharing\classes\frontend\WP_DEBUG is always false.
Loading history...
Found precision alignment of 1 spaces.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
63
            $min = '';
64
        } else {
0 ignored issues
show
Closing brace indented incorrectly; expected 9 spaces, found 8
Loading history...
65
            $min = '.min';
66
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
67
        /* Remove assets completely if all sharing options are off */
68
69
        if ( \lsx\sharing\includes\functions\is_disabled() ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
70
            return '';
71
        }
72
73
        // Set our variables.
74
        $post_type = get_post_type();
75
76
        /* Only show the assets if the post type sharing option is on */
77
        if ( ! \lsx\sharing\includes\functions\is_pt_disabled($post_type) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
78
79
            wp_enqueue_script('lsx-sharing', LSX_SHARING_URL . 'assets/js/lsx-sharing' . $min . '.js', array( 'jquery' ), LSX_SHARING_VER, true);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
80
81
            $params = apply_filters(
82
                'lsx_sharing_js_params', array(
0 ignored issues
show
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
83
					'ajax_url' => admin_url('admin-ajax.php'),
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
84
                )
85
            );
86
87
            wp_localize_script('lsx-sharing', 'lsx_sharing_params', $params);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
88
89
            wp_enqueue_style('lsx-sharing', LSX_SHARING_URL . 'assets/css/lsx-sharing.css', array(), LSX_SHARING_VER);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
90
            wp_style_add_data('lsx-sharing', 'rtl', 'replace');
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
91
        }
92
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
93
94
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$buttons" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$echo" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$post_id" missing
Loading history...
95
     * Display/return sharing buttons.
96
     */
97
    public function sharing_buttons( $buttons = array( 'facebook', 'twitter', 'pinterest' ), $echo = false, $post_id = false ) {
98
         $sharing_content = '';
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
99
100
        if ( ( is_preview() || is_admin() ) && ! ( defined('DOING_AJAX') && DOING_AJAX ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
101
            return '';
102
        }
103
104
        if ( empty($this->options) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
105
            $this->options = array();
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
106
        }
107
108
        //Set our variables
0 ignored issues
show
No space found before comment text; expected "// Set our variables" but found "//Set our variables"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
109
        global $post;
110
        $share_post = $post;
111
        if ( false !== $post_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
112
            $share_post = get_post($post_id);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
113
            $post_type = get_post_type($post_id);
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
114
        } else {
115
            $post_type = get_post_type();
116
        }
117
118
        if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled($post_type) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
119
            return '';
120
        }
121
122
        if ( ( is_array($buttons) && count($buttons) > 0 ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
123
            $sharing_content .= '<div class="lsx-sharing-content"><p>';
124
125
            $sharing_text = \lsx\sharing\includes\functions\get_sharing_text($post_type);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
126
            if ( '' !== $sharing_text ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
127
                $sharing_content .= '<span class="lsx-sharing-label">' . $sharing_text . '</span>';
128
            }
129
130
            foreach ( $buttons as $id => $button ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
131
                $button_obj = new \lsx\sharing\classes\frontend\Button($button, $this->options, $post_type);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
132
133
                if ( ! empty($button_obj) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
134
                    $url = $button_obj->get_link($share_post);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
135
136
                    if ( ! empty($url) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
137
                        if ( 'email' === $button ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
138
                            if ( ! isset($this->options['display']) || empty($this->options['display']['sharing_email_form_id']) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
139
                                continue;
140
                            }
0 ignored issues
show
No blank line found after control structure
Loading history...
141
                            $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="#lsx-sharing-email" data-toggle="modal" data-link="' . esc_url($url) . '"><span class="fa" aria-hidden="true"></span></a></span>';
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
142
                        } else {
143
                            $sharing_content .= '<span class="lsx-sharing-button lsx-sharing-button-' . esc_attr($button) . '"><a href="' . esc_url($url) . '" target="_blank" rel="noopener noreferrer"><span class="fa" aria-hidden="true"></span></a></span>';
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
144
                        }
145
                    }
146
                }
147
            }
0 ignored issues
show
No blank line found after control structure
Loading history...
148
            $sharing_content .= '</p></div>';
149
        }
150
151
        if ( $echo ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
152
            echo wp_kses_post($sharing_content);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
153
        } else {
154
            return $sharing_content;
155
        }
156
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
157
158
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$atts" missing
Loading history...
159
     * Sharing buttons shortcode.
160
     */
161
    public function sharing_buttons_shortcode( $atts ) {
162
         $atts = shortcode_atts(
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Opening statement of multi-line function call not indented correctly; expected 8 spaces but found 9
Loading history...
163
            array(
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 13 spaces, but found 12.
Loading history...
164
				'buttons' => '',
165
            ), $atts, 'lsx_sharing_buttons' 
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 13 spaces, but found 12.
Loading history...
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
166
        );
0 ignored issues
show
This line of the multi-line function call does not seem to be indented correctly. Expected 9 spaces, but found 8.
Loading history...
167
168
        if ( empty($atts['buttons']) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
169
            return '';
170
        }
171
172
        $no_whitespaces = preg_replace('/\s*,\s*/', ',', filter_var($atts['buttons'], FILTER_SANITIZE_STRING));
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
173
        $buttons        = explode(',', $no_whitespaces);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
174
175
        if ( is_array($buttons) && count($buttons) > 0 ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
176
            return $this->sharing_buttons($buttons);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
177
        }
178
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
179
180
    /**
181
     * Display buttons (template hook).
182
     */
183
    public function sharing_buttons_template() {
184
         echo wp_kses_post($this->sharing_buttons());
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
185
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
186
187
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$allowedtags" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$context" missing
Loading history...
188
     * Allow data params for Bootstrap modal.
189
     */
190
    public function wp_kses_allowed_html( $allowedtags, $context ) {
191
         $allowedtags['a']['data-toggle'] = true;
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
192
        $allowedtags['a']['data-link']   = true;
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 3 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
193
        return $allowedtags;
194
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
195
196
    /**
197
     * Outputs the sharing to the templates.
198
     *
199
     * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
200
     */
201
    public function output_sharing() {
202
         if ( is_main_query() && is_single() && ! is_singular(array( 'post', 'page', 'product' )) ) {
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
Blank line found at start of control structure
Loading history...
203
204
            if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled(get_post_type()) || in_array(get_post_type(), \lsx\sharing\includes\functions\get_restricted_post_types()) || in_array(get_post_type(), \lsx\sharing\includes\functions\get_to_post_types()) || in_array(get_post_type(), \lsx\sharing\includes\functions\get_hp_post_types()) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
205
                return '';
206
            }
207
            ?>
208
            <footer class="lsx-sharing-wrapper footer-meta clearfix">
209
                <div class="post-tags-wrapper">
210
            <?php $this->sharing_buttons_template(); ?>
211
                </div>
212
            </footer><!-- .footer-meta -->
213
            <?php
214
        }
0 ignored issues
show
Closing brace indented incorrectly; expected 9 spaces, found 8
Loading history...
215
    }
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
216
217
    /**
218
     * Outputs the sharing below the events.
219
     *
220
     * @param  string $ical_links
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
221
     * @return string
222
     */
223
    public function output_event_sharing( $ical_links = '' ) {
224
         if ( \lsx\sharing\includes\functions\is_disabled() || \lsx\sharing\includes\functions\is_pt_disabled(get_post_type()) ) {
0 ignored issues
show
Found precision alignment of 1 spaces.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
225
            return '';
226
        } else {
0 ignored issues
show
Closing brace indented incorrectly; expected 9 spaces, found 8
Loading history...
227
            $ical_links .= $this->sharing_buttons();
228
        }
0 ignored issues
show
No blank line found after control structure
Loading history...
229
        return $ical_links;
230
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
231
}
232