lightspeeddevelopment /
lsx-sharing
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
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
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * Contructor |
||
| 23 | */ |
||
| 24 | public function __construct() { |
||
|
0 ignored issues
–
show
|
|||
| 25 | add_action('wp_enqueue_scripts', array( $this, 'assets' ), 5); |
||
|
0 ignored issues
–
show
|
|||
| 26 | add_filter('wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2); |
||
|
0 ignored issues
–
show
|
|||
| 27 | add_shortcode('lsx_sharing_buttons', array( $this, 'sharing_buttons_shortcode' )); |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 30 | // WooCommerce. |
||
| 31 | add_action('woocommerce_share', array( $this, 'sharing_buttons_template' )); |
||
|
0 ignored issues
–
show
|
|||
| 32 | |||
| 33 | // General Post Types. |
||
| 34 | add_action('lsx_entry_after', array( $this, 'output_sharing' )); |
||
|
0 ignored issues
–
show
|
|||
| 35 | |||
| 36 | // Tribe Events. |
||
| 37 | add_filter('tribe_events_ical_single_event_links', array( $this, 'output_event_sharing' ), 10, 1); |
||
|
0 ignored issues
–
show
|
|||
| 38 | |||
| 39 | // Sensei Integration. |
||
| 40 | add_action('sensei_pagination', array( $this, 'output_sharing' ), 20); |
||
|
0 ignored issues
–
show
|
|||
| 41 | } |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 52 | if ( null == self::$instance ) { |
||
|
0 ignored issues
–
show
|
|||
| 53 | self::$instance = new self(); |
||
| 54 | } |
||
|
0 ignored issues
–
show
|
|||
| 55 | return self::$instance; |
||
| 56 | } |
||
|
0 ignored issues
–
show
|
|||
| 57 | |||
| 58 | /** |
||
| 59 | * Enques the assets. |
||
| 60 | */ |
||
| 61 | public function assets() { |
||
| 62 | if ( defined('WP_DEBUG') && true === WP_DEBUG ) { |
||
|
0 ignored issues
–
show
|
|||
| 63 | $min = ''; |
||
| 64 | } else { |
||
|
0 ignored issues
–
show
|
|||
| 65 | $min = '.min'; |
||
| 66 | } |
||
|
0 ignored issues
–
show
|
|||
| 67 | /* Remove assets completely if all sharing options are off */ |
||
| 68 | |||
| 69 | if ( \lsx\sharing\includes\functions\is_disabled() ) { |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 80 | |||
| 81 | $params = apply_filters( |
||
| 82 | 'lsx_sharing_js_params', array( |
||
|
0 ignored issues
–
show
|
|||
| 83 | 'ajax_url' => admin_url('admin-ajax.php'), |
||
|
0 ignored issues
–
show
|
|||
| 84 | ) |
||
| 85 | ); |
||
| 86 | |||
| 87 | wp_localize_script('lsx-sharing', 'lsx_sharing_params', $params); |
||
|
0 ignored issues
–
show
|
|||
| 88 | |||
| 89 | wp_enqueue_style('lsx-sharing', LSX_SHARING_URL . 'assets/css/lsx-sharing.css', array(), LSX_SHARING_VER); |
||
|
0 ignored issues
–
show
|
|||
| 90 | wp_style_add_data('lsx-sharing', 'rtl', 'replace'); |
||
|
0 ignored issues
–
show
|
|||
| 91 | } |
||
| 92 | } |
||
|
0 ignored issues
–
show
|
|||
| 93 | |||
| 94 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 99 | |||
| 100 | if ( ( is_preview() || is_admin() ) && ! ( defined('DOING_AJAX') && DOING_AJAX ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 101 | return ''; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ( empty($this->options) ) { |
||
|
0 ignored issues
–
show
|
|||
| 105 | $this->options = array(); |
||
|
0 ignored issues
–
show
|
|||
| 106 | } |
||
| 107 | |||
| 108 | //Set our variables |
||
|
0 ignored issues
–
show
|
|||
| 109 | global $post; |
||
| 110 | $share_post = $post; |
||
| 111 | if ( false !== $post_id ) { |
||
|
0 ignored issues
–
show
|
|||
| 112 | $share_post = get_post($post_id); |
||
|
0 ignored issues
–
show
|
|||
| 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...
|
|||
| 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
|
|||
| 119 | return ''; |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( ( is_array($buttons) && count($buttons) > 0 ) ) { |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 126 | if ( '' !== $sharing_text ) { |
||
|
0 ignored issues
–
show
|
|||
| 127 | $sharing_content .= '<span class="lsx-sharing-label">' . $sharing_text . '</span>'; |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ( $buttons as $id => $button ) { |
||
|
0 ignored issues
–
show
|
|||
| 131 | $button_obj = new \lsx\sharing\classes\frontend\Button($button, $this->options, $post_type); |
||
|
0 ignored issues
–
show
|
|||
| 132 | |||
| 133 | if ( ! empty($button_obj) ) { |
||
|
0 ignored issues
–
show
|
|||
| 134 | $url = $button_obj->get_link($share_post); |
||
|
0 ignored issues
–
show
|
|||
| 135 | |||
| 136 | if ( ! empty($url) ) { |
||
|
0 ignored issues
–
show
|
|||
| 137 | if ( 'email' === $button ) { |
||
|
0 ignored issues
–
show
|
|||
| 138 | if ( ! isset($this->options['display']) || empty($this->options['display']['sharing_email_form_id']) ) { |
||
|
0 ignored issues
–
show
|
|||
| 139 | continue; |
||
| 140 | } |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
|
0 ignored issues
–
show
|
|||
| 148 | $sharing_content .= '</p></div>'; |
||
| 149 | } |
||
| 150 | |||
| 151 | if ( $echo ) { |
||
|
0 ignored issues
–
show
|
|||
| 152 | echo wp_kses_post($sharing_content); |
||
|
0 ignored issues
–
show
|
|||
| 153 | } else { |
||
| 154 | return $sharing_content; |
||
| 155 | } |
||
| 156 | } |
||
|
0 ignored issues
–
show
|
|||
| 157 | |||
| 158 | /** |
||
|
0 ignored issues
–
show
|
|||
| 159 | * Sharing buttons shortcode. |
||
| 160 | */ |
||
| 161 | public function sharing_buttons_shortcode( $atts ) { |
||
| 162 | $atts = shortcode_atts( |
||
|
0 ignored issues
–
show
|
|||
| 163 | array( |
||
|
0 ignored issues
–
show
|
|||
| 164 | 'buttons' => '', |
||
| 165 | ), $atts, 'lsx_sharing_buttons' |
||
|
0 ignored issues
–
show
|
|||
| 166 | ); |
||
|
0 ignored issues
–
show
|
|||
| 167 | |||
| 168 | if ( empty($atts['buttons']) ) { |
||
|
0 ignored issues
–
show
|
|||
| 169 | return ''; |
||
| 170 | } |
||
| 171 | |||
| 172 | $no_whitespaces = preg_replace('/\s*,\s*/', ',', filter_var($atts['buttons'], FILTER_SANITIZE_STRING)); |
||
|
0 ignored issues
–
show
|
|||
| 173 | $buttons = explode(',', $no_whitespaces); |
||
|
0 ignored issues
–
show
|
|||
| 174 | |||
| 175 | if ( is_array($buttons) && count($buttons) > 0 ) { |
||
|
0 ignored issues
–
show
|
|||
| 176 | return $this->sharing_buttons($buttons); |
||
|
0 ignored issues
–
show
|
|||
| 177 | } |
||
| 178 | } |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 185 | } |
||
|
0 ignored issues
–
show
|
|||
| 186 | |||
| 187 | /** |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 195 | |||
| 196 | /** |
||
| 197 | * Outputs the sharing to the templates. |
||
| 198 | * |
||
| 199 | * @return void |
||
|
0 ignored issues
–
show
|
|||
| 200 | */ |
||
| 201 | public function output_sharing() { |
||
| 202 | if ( is_main_query() && is_single() && ! is_singular(array( 'post', 'page', 'product' )) ) { |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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
|
|||
| 215 | } |
||
|
0 ignored issues
–
show
|
|||
| 216 | |||
| 217 | /** |
||
| 218 | * Outputs the sharing below the events. |
||
| 219 | * |
||
| 220 | * @param string $ical_links |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 225 | return ''; |
||
| 226 | } else { |
||
|
0 ignored issues
–
show
|
|||
| 227 | $ical_links .= $this->sharing_buttons(); |
||
| 228 | } |
||
|
0 ignored issues
–
show
|
|||
| 229 | return $ical_links; |
||
| 230 | } |
||
|
0 ignored issues
–
show
|
|||
| 231 | } |
||
| 232 |