PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 2.2.0
Wp Social Login and Register Social Counter v2.2.0
3.2.1 trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / inc / share.php
wp-social / inc Last commit date
elementor 3 years ago admin-create-shortcode.php 7 years ago admin-create-user.php 3 years ago admin-custom-function.php 3 years ago admin-rest-api.php 5 years ago admin-settings.php 3 years ago admin-social-button.php 3 years ago admin-social-enque-script.php 5 years ago counter-widget.php 3 years ago counter.php 3 years ago custom-function.php 5 years ago login-widget.php 3 years ago login.php 5 years ago share-widget.php 3 years ago share.php 3 years ago
share.php
471 lines
1 <?php
2
3 namespace WP_Social\Inc;
4
5 use WP_Social\App\Providers;
6 use WP_Social\App\Settings;
7 use WP_Social\App\Share_Settings;
8 use WP_Social\Lib\Provider\Share_Factory;
9
10 defined('ABSPATH') || exit;
11
12 /**
13 * Class Name : Share;
14 * Class Details : this class for showing login button in login and register page for wp, woocommerce, buddyPress and others
15 *
16 * @params : void
17 * @return : void
18 *
19 * @since : 1.0
20 */
21 class Share {
22
23 private $app_key = ['c5752d2f90b7c95dd6fcf1ffc82a8fbb68d8c9e8', '1934f519a63e142e0d3c893e59cc37fe0172e98a'];
24 private $api_url = 'https://api.sharedcount.com/v1.0/?url=%s&apikey=%s';
25
26 public function __construct($load = true) {
27
28 if($load) {
29 //add_filter( 'plugin_row_meta', array( $this, 'xs_plugin_row_meta' ), 10, 2 );
30
31 add_shortcode('xs_social_share', [$this, 'social_share_shortcode']);
32
33 add_action('the_content', [$this, 'share_the_body_content']);
34 //add_action('wp_body_open', [ $this, 'share_the_body_content_body' ] );
35
36 add_action('wp_footer', [$this, 'share_the_body_content_body']);
37 }
38 }
39
40 /*
41 body and content
42 */
43 public function share_the_body_content($content = '') {
44
45 if(Share_Settings::instance()->is_share_content_enabled()) {
46
47 $position = Share_Settings::instance()->get_share_content_position();
48
49 /*
50 check indiviaual social share style positon
51 */
52 Global $post;
53 $page_position = get_post_custom( $post->ID );
54 if( isset($page_position['social_share_style'][0]) ){
55 $inner_position = $page_position['social_share_style'][0];
56 if( $inner_position !== 'global'){
57 $position = $inner_position;
58 }
59 }
60
61
62 $get_content = $this->get_share_data('all', ['class' => $position]);
63
64 if($position == 'after_content') {
65
66 return $content . $get_content;
67 }
68
69 if($position == 'before_content') {
70
71 return $get_content . $content;
72 }
73
74 if($position == 'both_content'){
75 return $get_content . $content . $get_content;
76 }
77 }
78
79 return $content;
80 }
81
82
83 /**
84 * This will give the html for fixed share
85 *
86 * @author UnKnown
87 *
88 */
89 public function share_the_body_content_body() {
90
91 $style = get_option('xs_style_setting_data_share', '');
92 $content_position = isset($style['login_button_content']) ? $style['login_button_content'] : '';
93
94 if(in_array($content_position, ['left_content', 'right_content', 'top_content', 'bottom_content'])) {
95
96 // set default type fixed_display for body
97 echo $this->get_share_data('all', ['class' => $content_position, 'type' => 'fixed_display']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- It's already has been escaped from the /template/share/share-html.php
98 }
99 }
100
101
102 public function social_share_action($post_url = '', $id_post = 0) {
103
104
105 $option_key = 'xs_share_providers_data';
106 $xsc_options = get_option($option_key) ? get_option($option_key) : [];
107 $share_provider = isset($xsc_options['social']) ? $xsc_options['social'] : '';
108
109 if(empty($post_url) || $id_post == 0) {
110 return '';
111 }
112 $cache = 12;
113
114 $api_key_set = 'c5752d2f90b7c95dd6fcf1ffc82a8fbb68d8c9e8';
115
116 $get_transient = get_transient('xs_share_data__' . $id_post);
117 $get_transient_time = get_transient('timeout_xs_share_data__' . $id_post);
118
119 $prev_data = get_post_meta($id_post, 'xs_share_data__', true) ? get_post_meta($id_post, 'xs_share_data__', true) : [];
120
121
122 if($get_transient_time > time()) {
123 return '';
124 }
125
126 $url = sprintf($this->api_url, $post_url, $api_key_set);
127
128 $get_request = wp_remote_get($url, []);
129 $request = wp_remote_retrieve_body($get_request);
130 $api_call = @json_decode($request, true);
131
132 $return = [];
133 $xsc_transient = [];
134
135 if(is_array($share_provider) && sizeof($share_provider) > 0) :
136 foreach($share_provider as $k => $v) :
137 if(isset($v['enable'])) {
138 $before_data = isset($prev_data[$k]) ? $prev_data[$k] : 0;
139 if(!empty($get_transient[$k])) {
140 $result = $get_transient[$k];
141 } else {
142 if($k == 'facebook') {
143 $result = isset($api_call['Facebook']['share_count']) ? $api_call['Facebook']['share_count'] : $before_data;
144 } else {
145 if($k == 'pinterest') {
146 $result = isset($api_call['Pinterest']) ? $api_call['Pinterest'] : $before_data;
147 } else {
148 if($k == 'linkedin') {
149 $result = isset($api_call['LinkedIn']) ? $api_call['LinkedIn'] : $before_data;
150 } else {
151 if($k == 'stumbleUpon') {
152 $result = isset($api_call['StumbleUpon']) ? $api_call['StumbleUpon'] : $before_data;
153 } else {
154 $result = 0;
155 }
156 }
157 }
158 }
159 }
160 $return[$k] = $result;
161 $xsc_transient[$k] = $result;
162 }
163 endforeach;
164 endif;
165
166 update_post_meta($id_post, 'xs_share_data__', $return);
167
168 set_transient('xs_share_data__' . $id_post, $xsc_transient, $cache * 60 * 60);
169 }
170
171
172 /**
173 * Return Content for shortCode
174 *
175 * @author UnKnown
176 *
177 * @param $atts
178 * @param null $content
179 *
180 * @return string
181 */
182 public function social_share_shortcode($atts, $content = null) {
183
184 $atts = shortcode_atts(
185 array(
186 'provider' => 'all',
187 'class' => '',
188 'style' => '',
189 'hover' => '',
190 'layout' => 'horizontal',
191 'count' => 'No',
192 'box_only' => '',
193 ),
194 $atts,
195 'xs_social_share'
196 );
197
198 if(empty(trim($atts['provider'])) || $atts['provider'] == 'all') {
199 $provider = 'all';
200 } else {
201 $provider = explode(',', strtolower($atts['provider']));
202 }
203
204 $config = [];
205 $config['class'] = trim($atts['class']);
206 $config['style'] = trim($atts['style']);
207 $config['hover'] = trim($atts['hover']);
208 $config['hv_effect'] = trim($atts['layout']);
209 $config['show_count'] = ucfirst(strtolower(trim($atts['count'])));
210 $config['show_count'] = in_array($config['show_count'], ['Yes', 'No']) ? $config['show_count'] : 'No';
211 $config['conf_type'] = 'shortCode';
212
213 return $this->get_share_data($provider, $config);
214 }
215
216
217 /**
218 *
219 * @param string $provider
220 * @param array $config
221 *
222 * @return string
223 */
224 public function get_share_data($provider = 'all', $config = []) {
225
226 global $post;
227
228 $postId = isset($post->ID) ? $post->ID : 0;
229
230
231 $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($postId), 'full');
232 $custom_logo_id = get_theme_mod('custom_logo');
233 $image = wp_get_attachment_image_src($custom_logo_id, 'full');
234 $customLogo = isset($image[0]) ? $image[0] : '';
235 $media = isset($thumbnail_src[0]) ? $thumbnail_src[0] : $customLogo;
236 $app_id = '';
237 $details = '';
238 $author = 'xpeedstudio';
239 $title = get_the_title($postId);
240 $source = get_bloginfo();
241
242
243 $config['conf_type'] = empty($config['conf_type']) ? 'content_body' : $config['conf_type'];
244
245
246 $core_provider = Providers::get_core_providers_share();
247 $provider = ($provider == 'all') ? array_keys($core_provider) : $provider;
248
249
250 $themeFontClass = Share_Settings::instance()->is_theme_font_enabled() ? 'wslu-theme-font-yes' : 'wslu-theme-font-no';
251 $customClass = empty($config['class']) ? '' : $config['class'];
252
253 $saved_style_settings = Settings::instance()->get_share_style_settings();
254 //$saved_global_settings = Settings::instance()->get_share_main_settings();
255 //$saved_provider_settings = Settings::instance()->get_share_provider_settings();
256
257
258 $styles = \WP_Social\Inc\Admin_Settings::share_styles();
259 $hvStyles = \WP_Social\Inc\Admin_Settings::$horizontal_style;
260
261 $hoverStyles = [
262 'none-none' => [
263 'name' => 'None',
264 'class' => 'wslu-none',
265 ],
266 ];
267
268 if(did_action('wslu_social_pro/plugin_loaded') && class_exists('\WP_Social_Pro\Inc\Admin_Settings')) {
269
270 $hoverStyles = \WP_Social_Pro\Inc\Admin_Settings::$share_hover_effects;
271 }
272
273 //defaults values
274 $showCountMarkup = false;
275 $shareStyleKey = 'style-1';
276 $shareHoverKey = 'none-none';
277 $vhEffectKey = 'horizontal';
278 $fixedWidget_style = 'main_content';
279 $displayCls = 'wslu-fixed_display';
280
281
282 if($config['conf_type'] == 'widget') {
283
284 #content for widget.....
285 #from widget we always hiding total markup
286 #always main style........................
287
288 if(isset($config['show_count']) && $config['show_count'] === 'yes') {
289 $showCountMarkup = true;
290 }else {
291 $showCountMarkup = false;
292 }
293 $fixed_display = 'main_content';
294 $displayCls = 'wslu-main_content';
295
296 $shareStyleKey = empty($config['style']) ? $shareStyleKey : $config['style']; //after resetting the plugin style-1 will be assigned
297 $shareHoverKey = empty($config['hover']) ? $shareHoverKey : $config['hover'];
298 $vhEffectKey = empty($config['hv_effect']) ? $vhEffectKey : $config['hv_effect'];
299
300 $mainStyleCls = isset($styles[$shareStyleKey]['class']) ? 'wslu-' . $shareStyleKey . ' ' . $styles[$shareStyleKey]['class'] : '';
301 $hoverEffect = empty($hoverStyles[$shareHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$shareHoverKey]['class'];
302 $vhClass = $hvStyles[$vhEffectKey]['class'];
303
304 $widget_style = $mainStyleCls . ' ' . $hoverEffect . ' ' . $vhClass . ' ' . $themeFontClass . ' ' . $displayCls;
305
306 } elseif($config['conf_type'] == 'shortCode') {
307
308 $fixed_display = 'main_content';
309 $displayCls = 'wslu-main_content';
310
311 #here always be the main display settings......
312 $shareStyleKeys = empty($saved_style_settings['main_content']['style']) ?
313 $shareStyleKey . ':' . $shareHoverKey . ':' . $vhEffectKey : $saved_style_settings['main_content']['style'];
314
315 $bArr = explode(':', $shareStyleKeys);
316
317 #Overridden by short-code attribute
318 $shareStyleKey = empty($config['style']) ? $bArr[0] : $config['style'];
319 $shareHoverKey = empty($config['hover']) ? $bArr[1] : $config['hover'];
320 $vhEffectKey = empty($config['hv_effect']) ? $bArr[2] : $config['hv_effect'];
321
322 $mainStyleCls = isset($styles[$shareStyleKey]['class']) ? 'wslu-' . $shareStyleKey . ' ' . $styles[$shareStyleKey]['class'] : '';
323 $hoverEffect = empty($hoverStyles[$shareHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$shareHoverKey]['class'];
324 $vhClass = empty($hvStyles[$vhEffectKey]) ? $hvStyles['horizontal']['class'] : $hvStyles[$vhEffectKey]['class'];
325
326 $widget_style = $mainStyleCls . ' ' . $hoverEffect . ' ' . $vhClass . ' ' . $themeFontClass . ' ' . $displayCls;
327
328 $showCountMarkup = $config['show_count'] == 'Yes';
329
330 } else {
331
332 //for appending/prepending to main content
333
334 $fixed_display = isset($config['type']) ? $config['type'] : 'main_content';
335
336 if($fixed_display == 'fixed_display') {
337
338 $shareStyleKey = 'style-1'; //defaults values
339 $shareHoverKey = 'none-none';
340 $vhEffectKey = 'vertical';
341 $displayCls = 'wslu-fixed_display';
342
343 $shareStyleKeys = empty($saved_style_settings['fixed_display']['style']) ?
344 $shareStyleKey . ':' . $shareHoverKey . ':' . $vhEffectKey : $saved_style_settings['fixed_display']['style'];
345
346 $bArr = explode(':', $shareStyleKeys);
347
348 $shareStyleKey = $bArr[0];
349 $shareHoverKey = $bArr[1];
350 $vhEffectKey = $bArr[2];
351
352 $mainStyleCls = isset($styles[$shareStyleKey]['class']) ? 'wslu-' . $shareStyleKey . ' ' . $styles[$shareStyleKey]['class'] : '';
353 $hoverEffect = empty($hoverStyles[$shareHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$shareHoverKey]['class'];
354 $vhClass = $hvStyles[$vhEffectKey]['class'];
355
356 $widget_style = $mainStyleCls . ' ' . $hoverEffect . ' ' . $vhClass . ' ' . $themeFontClass . ' ' . $displayCls;
357
358
359 $showFixedDisplaySC = empty($config['fixed_share_count']) ?
360 (empty($saved_style_settings['fixed_display']['show_social_count_share']) ? '0' :
361 $saved_style_settings['fixed_display']['show_social_count_share']) :
362 $config['fixed_share_count'];
363
364 $showCountMarkup = $showFixedDisplaySC == '1';
365
366 } else {
367
368 $shareStyleKeys = empty($saved_style_settings['main_content']['style']) ?
369 $shareStyleKey . ':' . $shareHoverKey . ':' . $vhEffectKey :
370 $saved_style_settings['main_content']['style'];
371
372 $bArr = explode(':', $shareStyleKeys);
373
374 $shareStyleKey = $bArr[0];
375 $shareHoverKey = $bArr[1];
376 $vhEffectKey = $bArr[2];
377 $displayCls = 'wslu-main_content';
378
379 $mainStyleCls = isset($styles[$shareStyleKey]['class']) ? 'wslu-' . $shareStyleKey . ' ' . $styles[$shareStyleKey]['class'] : '';
380 $hoverEffect = empty($hoverStyles[$shareHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$shareHoverKey]['class'];
381 $vhClass = $hvStyles[$vhEffectKey]['class'];
382
383 $widget_style = $mainStyleCls . ' ' . $hoverEffect . ' ' . $vhClass . ' ' . $themeFontClass . ' ' . $displayCls;
384
385 $showMainDisplaySC = empty($config['main_share_count']) ?
386 (empty($saved_style_settings['main_content']['show_social_count_share']) ? '0' :
387 $saved_style_settings['main_content']['show_social_count_share']) :
388 $config['main_share_count'];
389
390 $showCountMarkup = $showMainDisplaySC == '1';
391 }
392 }
393
394
395 $enabled_providers = Settings::instance()->get_enabled_providers_share();
396 $share_counting = [];
397
398 $currentUrl = (isset($_SERVER['HTTPS']) && sanitize_text_field($_SERVER['HTTPS']) === 'on' ? 'https' : 'http') . '://' . sanitize_text_field($_SERVER['HTTP_HOST']) . sanitize_url($_SERVER['REQUEST_URI']);
399
400 $share_counting = Share_Settings::instance()->get_share_count($post, $enabled_providers);
401
402
403 $totalSCount = 0;
404
405 if($showCountMarkup) {
406
407 foreach($enabled_providers as $key => $arr) {
408 if(!empty($arr['enable'])) {
409 $totalSCount += $share_counting[$key]['count'];
410 }
411 }
412 }
413
414
415 if(!empty($post->post_excerpt)) {
416
417 $details = $post->post_excerpt;
418 }
419
420
421 ob_start();
422 require(WSLU_LOGIN_PLUGIN . '/template/share/share-html.php');
423 $counter = ob_get_contents();
424 ob_end_clean();
425
426 return $counter;
427 }
428
429
430 /**
431 * This function should be replace with Providers::get_core_providers_share() methods for all places
432 *
433 */
434 public function social_share_link() {
435
436 $link = [];
437 $link['facebook'] = ['label' => 'Facebook', 'url' => 'http://www.facebook.com/sharer.php', 'params' => ['u' => '[%url%]', 't' => '[%title%]', 'v' => 3]];
438 $link['twitter'] = ['label' => 'Twitter', 'url' => 'https://twitter.com/intent/tweet', 'params' => ['text' => '[%title%] [%url%]', 'original_referer' => '[%url%]', 'related' => '[%author%]']];
439 $link['linkedin'] = ['label' => 'LinkedIn', 'url' => 'https://www.linkedin.com/shareArticle', 'params' => ['url' => '[%url%]', 'title' => '[%title%]', 'summary' => '[%details%]', 'source' => '[%source%]', 'mini' => true]];
440 $link['pinterest'] = ['label' => 'Pinterest', 'url' => 'https://pinterest.com/pin/create/button/', 'params' => ['url' => '[%url%]', 'media' => '[%media%]', 'description' => '[%details%]']];
441 $link['facebook-messenger'] = ['label' => 'Facebook Messenger', 'url' => 'https://www.facebook.com/dialog/send', 'params' => ['link' => '[%url%]', 'redirect_uri' => '[%url%]', 'display' => 'popup', 'app_id' => '[%app_id%]']];
442 $link['kik'] = ['label' => 'Kik', 'url' => 'https://www.kik.com/send/article/', 'params' => ['url' => '[%url%]', 'text' => '[%details%]', 'title' => '[%title%]']];
443 $link['skype'] = ['label' => 'Skype', 'url' => 'https://web.skype.com/share', 'params' => ['url' => '[%url%]']];
444 $link['trello'] = ['label' => 'Trello', 'url' => 'https://trello.com/add-card', 'params' => ['url' => '[%url%]', 'name' => '[%title%]', 'desc' => '[%details%]', 'mode' => 'popup']];
445 $link['viber'] = ['label' => 'Viber', 'url' => 'viber://forward', 'params' => ['text' => '[%title%] [%url%]']];
446 $link['whatsapp'] = ['label' => 'WhatsApp', 'url' => 'whatsapp://send', 'params' => ['text' => '[%title%] [%url%]']];
447 $link['telegram'] = ['label' => 'Telegram', 'url' => 'https://telegram.me/share/url', 'params' => ['url' => '[%url%]', 'text' => '[%title%]']];
448 $link['email'] = ['label' => 'Email', 'url' => 'mailto:', 'params' => ['body' => 'Title: [%title%] \n\n URL: [%url%]', 'subject' => '[%title%]']];
449 $link['reddit'] = ['label' => 'Reddit', 'url' => 'http://reddit.com/submit', 'params' => ['url' => '[%url%]', 'title' => '[%title%]']];
450 $link['digg'] = ['label' => 'Digg', 'url' => 'http://digg.com/submit', 'params' => ['url' => '[%url%]', 'title' => '[%title%]', 'phase' => 2]];
451 $link['stumbleupon'] = ['label' => 'StumbleUpon', 'url' => 'http://www.stumbleupon.com/submit', 'params' => ['url' => '[%url%]', 'title' => '[%title%]']];
452
453 return $link;
454 }
455
456
457 public function xs_plugin_row_meta($links, $file) {
458 if(strpos($file, 'wp-social.php') !== false) {
459 $new_links = array(
460 'demo' => '<a href="#" target="_blank"><span class="dashicons dashicons-welcome-view-site"></span>Live Demo</a>',
461 'doc' => '<a href="#" target="_blank"><span class="dashicons dashicons-media-document"></span>User Guideline</a>',
462 'support' => '<a href="https://help.wpmet.com/" target="_blank"><span class="dashicons dashicons-admin-users"></span>Support</a>',
463 'pro' => '<a href="#" target="_blank"><span class="dashicons dashicons-cart"></span>Premium version</a>',
464 );
465 $links = array_merge($links, $new_links);
466 }
467
468 return $links;
469 }
470 }
471