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