PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 3.2.1
Wp Social Login and Register Social Counter v3.2.1
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 / counter.php
wp-social / inc Last commit date
elementor 3 years ago admin-create-shortcode.php 7 years ago admin-create-user.php 1 week ago admin-custom-function.php 1 week ago admin-rest-api.php 1 week ago admin-settings.php 2 years ago admin-social-button.php 1 week ago admin-social-enque-script.php 5 years ago counter-widget.php 1 week ago counter.php 1 week ago custom-function.php 5 years ago login-widget.php 3 years ago login.php 5 years ago share-widget.php 1 week ago share.php 1 week ago
counter.php
521 lines
1 <?php
2
3 namespace WP_Social\Inc;
4
5 defined('ABSPATH') || exit;
6
7 require_once( WSLU_LOGIN_PLUGIN . 'lib/composer/vendor/autoload.php' );
8 use WP_Social\App\Providers;
9 use WP_Social\Lib\Provider\Counter_Factory;
10 use TikTok\Authentication\Authentication;
11
12 /**
13 * Class Name : XS_Social_Counter;
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 *
18 * @return : void
19 *
20 * @since : 1.0
21 */
22 class Counter {
23
24 const ORDER_LIST_PROVIDER_COUNTER = 'xs_counter_providers_order_frontend';
25
26 public function __construct($load = true) {
27
28 if($load) {
29 $this->social_counter_action();
30 add_action('init', [$this, 'counter_access_key_setup']);
31
32 add_shortcode('xs_social_counter', [$this, 'social_counter_shortcode']);
33 }
34 }
35
36
37 public function social_counter_action() {
38
39
40 /**
41 * AR:20201110 - below caching is confusing and it is causing not showing datas for provider whose settings is set later
42 * Current flow:
43 * - loop through every provider
44 * -- call the dedicated 'xsc_' . $key . '_count'; function
45 * --- check the transient time there
46 * --- transient time should get from global settings
47 * --- call api and update the count
48 * ---- if count fail do not update transient
49 * ---- //this way next time for specific provider can update their count
50 *
51 * Count precedence : bigger of actual & defaults get precedence
52 *
53 */
54
55 $return = [];
56 $xsc_transient = [];
57
58 $option_key = 'xs_counter_providers_data';
59 $xsc_options = get_option($option_key) ? get_option($option_key) : []; //these are used as global so right now we can not remove
60
61 $counter_provider = \WP_Social\App\Settings::get_counter_provider_settings();
62 $cache_time = \WP_Social\App\Settings::get_counter_cache_time();
63 $enabled_providers = \WP_Social\App\Settings::get_enabled_provider_conf_counter();
64
65 /**
66 * Note - these need to be updated, very messier code
67 * for now just patching :( ARa
68 *
69 * Cleaning idea
70 * - each provider should have its transient and api call must not be performed in constructor call!
71 * - todo - etc etc
72 *
73 */
74 if(!empty($counter_provider)) {
75
76 $factory = new Counter_Factory();
77
78 foreach($counter_provider as $key => $conf) {
79
80 if(!empty($enabled_providers[$key]['enable'])) {
81
82 $obj = $factory->make($key);
83
84 if($obj->need_to_call_legacy_function()) {
85
86 $function = 'xsc_' . $key . '_count';
87 $return['data'][$key] = function_exists( $function ) ? $function( $cache_time ) : 0;
88 $xsc_transient[$key] = $return['data'][$key];
89
90 } else {
91
92 $count = $obj->set_config_data($conf)->get_count($cache_time);
93 $return['data'][$key] = $count;
94 $xsc_transient[$key] = $count;
95 }
96 }
97 }
98 }
99
100 update_option(\WP_Social\App\Settings::$ok_counter_cached_data, $return);
101 }
102
103
104 public function social_counter_shortcode($atts, $content = null) {
105
106 $atts = shortcode_atts(
107 [
108 'provider' => 'all',
109 'class' => '',
110 'style' => '',
111 'hover' => '',
112 ],
113 $atts,
114 'xs_social_counter'
115 );
116
117 if(isset($atts['provider']) && $atts['provider'] != 'all') {
118 $provider = explode(',', $atts['provider']);
119 } else {
120 $provider = 'all';
121 }
122
123 $config = [];
124 $config['class'] = trim($atts['class']);
125 $config['style'] = trim($atts['style']);
126 $config['hover'] = trim($atts['hover']);
127
128 return $this->get_counter_data($provider, $config);
129 }
130
131
132 public function get_counter_data($provider = 'all', $config = []) {
133
134 $core_provider = $this->xs_counter_providers();
135
136 $className = isset($config['class']) ? $config['class'] : '';
137 $provider = ($provider == 'all') ? array_keys($core_provider) : $provider;
138
139 $styleArr = \WP_Social\Inc\Admin_Settings::counter_styles();
140
141 $hoverStyles = [
142 'none-none' => [
143 'name' => __('None', 'wp-social'),
144 'class' => 'wslu-none',
145 ],
146 ];
147
148 if(did_action('wslu_social_pro/plugin_loaded')) {
149
150 if( method_exists( \WP_Social_Pro\Inc\Admin_Settings::class, 'counter_hover_effects' ) ){
151
152 $hoverStyles = \WP_Social_Pro\Inc\Admin_Settings::counter_hover_effects();
153
154 }else{
155
156 $hoverStyles = \WP_Social_Pro\Inc\Admin_Settings::$counter_hover_effects;
157
158 }
159
160 }
161
162 $globalShareSettings = get_option('xs_counter_global_setting_data', '');
163 $themeFontClass = empty($globalShareSettings['show_font_from_theme']) ? 'wslu-theme-font-no' : 'wslu-theme-font-yes';
164
165 $style = get_option('xs_style_setting_data_counter', '');
166
167 $styleConfig = isset($style['login_button_style']['style']) ? $style['login_button_style']['style'] : 'style-1:none-none';
168
169 $bArr = explode(':', $styleConfig);
170
171 $cntStyleKey = empty($config['style']) ? $bArr[0] : $config['style'];
172 $cntHoverKey = empty($config['hover']) ? $bArr[1] : $config['hover'];
173
174 $mainStyleCls = isset($styleArr[$cntStyleKey]['class']) ? 'wslu-' . $cntStyleKey . ' ' . $styleArr[$cntStyleKey]['class'] : '';
175 $hoverClass = empty($hoverStyles[$cntHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$cntHoverKey]['class'];
176 $widget_style = $mainStyleCls . ' ' . $hoverClass . ' ' . $themeFontClass;
177
178 $counter_data = \WP_Social\App\Settings::get_counter_cached_data();
179 $counter_provider = \WP_Social\App\Settings::get_counter_provider_settings();
180
181 ob_start();
182 require(WSLU_LOGIN_PLUGIN . '/template/counter/counter-html.php');
183 $counter = ob_get_contents();
184 ob_end_clean();
185
186 return $counter;
187 }
188
189
190 public function counter_access_key_setup() {
191
192 if( !isset( $_POST['xs_provider_submit_form_access_counter_nonce'] ) || ! wp_verify_nonce( $_POST['xs_provider_submit_form_access_counter_nonce'], 'xs_provider_submit_form_access_counter_nonce' ) || ! current_user_can( 'manage_options' ) ) {
193 return;
194 }
195
196 if(isset($_POST['xs_provider_submit_form_access_counter'])) {
197
198 $getpage = isset($_GET['page']) ? Admin_Settings::sanitize($_GET['page']) : '';
199 $getType = isset($_GET['xs_access']) ? Admin_Settings::sanitize($_GET['xs_access']) : '';
200
201 if($getpage != 'wslu_counter_setting') {
202 return '';
203 }
204
205 $accesskey = isset($_POST['accesskey']) ? Admin_Settings::sanitize($_POST['accesskey']) : '';
206 $app_id = isset($accesskey[$getType]['app_id']) ? $accesskey[$getType]['app_id'] : '';
207 $app_secret = isset($accesskey[$getType]['app_secret']) ? $accesskey[$getType]['app_secret'] : '';
208
209 if($getType == 'twitter') {
210 // preparing credentials
211 $credentials = $app_id . ':' . $app_secret;
212 $toSend = base64_encode($credentials);
213
214 // http post arguments
215 $args = [
216 'method' => 'POST',
217 'httpversion' => '1.1',
218 'blocking' => true,
219 'headers' => [
220 'Authorization' => 'Basic ' . $toSend,
221 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
222 ],
223 'body' => ['grant_type' => 'client_credentials'],
224 ];
225
226 add_filter('https_ssl_verify', '__return_false');
227 $response = wp_remote_post('https://api.twitter.com/oauth2/token', $args);
228
229 $keys = json_decode(wp_remote_retrieve_body($response));
230 if(!isset($keys->access_token)) {
231 return '';
232 }
233 if(!empty($keys->access_token)) {
234 update_option('xs_counter_' . $getType . '_token', $keys->access_token);
235 update_option('xs_counter_' . $getType . '_app_id', $app_id);
236 update_option('xs_counter_' . $getType . '_app_secret', $app_secret);
237 $redirect_url = admin_url() . "admin.php?page=wslu_counter_setting&tab=wslu_providers&code=true&xs_access=" . $getType . '';
238 header("Location: $redirect_url");
239 exit;
240 }
241 } elseif($getType == 'instagram') {
242 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
243
244 $params = [
245 'client_id' => $app_id,
246 'response_type' => 'code',
247 'scope' => 'basic',
248 'redirect_uri' => $cur_page,
249 ];
250
251 $url = "https://api.instagram.com/oauth/authorize/?" . http_build_query($params);
252
253 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
254 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
255 header("Location: $url");
256
257 } elseif($getType == 'linkedin') {
258 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
259 $params = [
260 'response_type' => 'code',
261 'client_id' => $app_id,
262 //'scope' => 'rw_company_admin r_basicprofile',
263 'scope' => 'r_liteprofile r_emailaddress w_member_social r_ad_campaigns rw_organization',
264 'state' => uniqid('', true), // unique long string
265 'redirect_uri' => $cur_page,
266 ];
267
268 $url = 'https://www.linkedin.com/oauth/v2/authorization?' . http_build_query($params);
269
270 set_transient('xs_counter_' . $getType . '_api_key', $app_id, 60 * 60);
271 set_transient('xs_counter_' . $getType . '_secret_key', $app_secret, 60 * 60);
272
273 header("Location: $url");
274 } elseif($getType == 'facebook') {
275 $url = 'https://www.facebook.com/login.php?skip_api_login=1&api_key=1203050406491591&signed_next=1&next=https://www.facebook.com/v2.12/dialog/oauth?redirect_uri=https%3A%2F%2Fwww.ajuda.me%2Fwp-login.php%3FloginSocial%3Dfacebook
276 &display=popup&state=d4a4c6d6df98117acfa25d4343483c69&scope=public_profile%2Cemail&response_type=code&client_id=1203050406491591&ret=login&logger_id=49a9a593-e908-a451-16d4-eb38a4ae7882&cancel_url=https://www.ajuda.me/wp-login.php?loginSocial=facebook&error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=d4a4c6d6df98117acfa25d4343483c69#_=_&display=popup&locale=pt_PT&logger_id=49a9a593-e908-a451-16d4-eb38a4ae7882';
277
278 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
279
280 $params = [
281 'skip_api_login' => 1,
282 'api_key' => 1203050406491591,
283 'signed_next' => 1,
284 'next' => 'https://www.facebook.com/v2.12/dialog/oauth?redirect_uri=' . $cur_page,
285 'display' => 'popup',
286 'response_type' => 'code',
287 'client_id' => $app_id,
288 'scope' => 'public_profile email',
289 'ret' => 'login',
290 'logger_id' => '49a9a593-e908-a451-16d4-eb38a4ae7882',
291 'cancel_url' => 'https://www.ajuda.me/wp-login.php?loginSocial=facebook&error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=d4a4c6d6df98117acfa25d4343483c69#_=_&display=popup&locale=pt_PT&logger_id=49a9a593-e908-a451-16d4-eb38a4ae7882',
292 'state' => uniqid('', true), // unique long string
293 'redirect_uri' => $cur_page,
294 ];
295 $url = 'https://www.facebook.com/login.php?' . http_build_query($params);
296 header("Location: $url");
297 } elseif($getType == 'dribbble') {
298 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
299
300 $params = [
301 'client_id' => $app_id,
302 'response_type' => 'code',
303 'scope' => 'public',
304 'redirect_uri' => $cur_page,
305 'state' => substr(md5(microtime()), rand(0, 26), 10),
306 ];
307
308 $url = "https://dribbble.com/oauth/authorize?" . http_build_query($params);
309
310 /**
311 * Why saved in transient!!!!
312 *
313 */
314 update_option('xs_counter_dribbble_app_id', $app_id);
315 update_option('xs_counter_dribbble_app_secret', $app_secret);
316
317 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
318 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
319
320 header("Location: $url");
321 } elseif ($getType == 'tiktok') {
322
323 $tiktok_login_url = $this->get_tiktok_login_url( $app_id, $app_secret );
324
325 update_option( 'xs_counter_tiktok_app_id', $app_id) ;
326 update_option( 'xs_counter_tiktok_app_secret', $app_secret) ;
327
328 wp_redirect($tiktok_login_url);
329
330 exit;
331 }
332 }
333 }
334
335
336 public function xs_counter_providers() {
337 $providers = [
338 'facebook' => [
339 'label' => 'Facebook',
340 'data' => ['text' => __('Fans', 'wp-social'), 'url' => 'http://www.facebook.com/%s'],
341 ],
342 'twitter' => [
343 'label' => 'Twitter',
344 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://twitter.com/%s'],
345 ],
346 //'linkedin' => [ 'label' => 'LinkedIn', 'data' => ['text' => __( 'Followers', 'wp-social' ), 'url' => 'https://www.linkedin.com/%s/%s'] ],
347 'pinterest' => [
348 'label' => 'Pinterest',
349 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://www.pinterest.com/%s'],
350 ],
351 'dribbble' => [
352 'label' => 'Dribbble',
353 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://dribbble.com/%s'],
354 ],
355 'instagram' => [
356 'label' => 'Instagram',
357 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://instagram.com/%s'],
358 ],
359 'tiktok' => [
360 'label' => 'TikTok',
361 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://tiktok.com/%s'],
362 ],
363 'youtube' => [
364 'label' => 'YouTube',
365 'data' => ['text' => __('Subscribers', 'wp-social'), 'url' => 'http://youtube.com/%s'],
366 ],
367 'mailchimp' => ['label' => 'Mailchimp', 'data' => ['text' => __('Subscribers', 'wp-social')]],
368 'comments' => ['label' => 'Comments', 'data' => ['text' => __('Count', 'wp-social')]],
369 'posts' => ['label' => 'Posts', 'data' => ['text' => __('Count', 'wp-social')]],
370 //'vimeo' => [ 'label' => 'Vimeo', 'data' => ['text' => __( 'Subscribers', 'wp-social' ), 'url' => 'https://vimeo.com/channels/%s'] ],
371 //'vkontakte' => [ 'label' => 'Vkontakte', 'data' => ['text' => __( 'Members', 'wp-social' ), 'url' => 'http://vk.com/%s'] ],
372 ];
373
374 $providers_order = get_option(self::ORDER_LIST_PROVIDER_COUNTER);
375
376 return Providers::providers_sort($providers_order, $providers);
377 }
378
379
380 public function xs_counter_providers_data() {
381
382 // todo - alamin : make all label as translatable
383
384 return [
385 'facebook' => ['id' => ['type' => 'normal', 'label' => __('Page ID/Name', 'wp-social'), 'input' => 'text'],],
386 'twitter' => [
387 'id' => ['type' => 'normal', 'label' => __('Username', 'wp-social'), 'input' => 'text'],
388 'api' => [
389 'type' => 'access',
390 'label' => __('Access Token Key', 'wp-social'),
391 'input' => 'text',
392 'filed' => ['app_id' => __('Consumer key', 'wp-social'), 'app_secret' => __('Consumer secret', 'wp-social')],
393 ],
394 ],
395
396 'instagram' => [
397
398 'user_name' => [
399 'type' => 'normal',
400 'label' => __('Username', 'wp-social'),
401 'input' => 'text',
402 ],
403
404 'get_token' => [
405 'type' => 'link',
406 'label' => esc_html__('Documentation to get access token & account ID.', 'wp-social'),
407 'input' => 'link',
408 'url' => 'https://wpmet.com/doc/social-counter-instagram/',
409 'class' => 'wslu-btn wslu-target-link',
410 ],
411
412 'access_token' => [
413 'type' => 'normal',
414 'label' => __('Access token', 'wp-social'),
415 'input' => 'text',
416 ],
417 'user_id' => [
418 'type' => 'normal',
419 'label' => __('Account ID', 'wp-social'),
420 'input' => 'text',
421 ],
422 ],
423
424 'tiktok' => [
425 'api' => [
426 'type' => 'access',
427 'label' => __('Access Token', 'wp-social'),
428 'input' => 'text',
429 'filed' => ['app_id' => __('Client ID', 'wp-social'), 'app_secret' => __('Client Secret', 'wp-social')],
430 ],
431 ],
432
433 'linkedin' => [
434 'type' => [
435 'type' => 'normal',
436 'label' => __('Account Type', 'wp-social'),
437 'input' => 'select',
438 'data' => ['Company' => 'Company', 'Profile' => 'Profile'],
439 ],
440 'id' => ['type' => 'normal', 'label' => __('Your ID', 'wp-social'), 'input' => 'text'],
441 'api' => [
442 'type' => 'access',
443 'label' => __('Access Token Key', 'wp-social'),
444 'input' => 'text',
445 'filed' => ['app_id' => __('API Key', 'wp-social'), 'app_secret' => __('Secret Key', 'wp-social')],
446 ],
447 ],
448 'pinterest' => [
449 'username' => [
450 'type' => 'normal',
451 'label' => __('Username', 'wp-social'),
452 'input' => 'text',
453 ],
454 ],
455
456 'youtube' => [
457 'type' => [
458 'type' => 'normal',
459 'label' => __('Account Type', 'wp-social'),
460 'input' => 'select',
461 'data' => ['Channel' => 'Channel', 'User' => 'User'],
462 ],
463 'id' => ['type' => 'normal', 'label' => __('Username or Channel ID', 'wp-social'), 'input' => 'text'],
464 'key' => ['type' => 'normal', 'label' => __('YouTube API Key', 'wp-social'), 'input' => 'text'],
465 ],
466 'dribbble' => [
467 'api' => [
468 'type' => 'access',
469 'label' => __('Access Token Key', 'wp-social'),
470 'input' => 'text',
471 'filed' => ['app_id' => __('Client ID', 'wp-social'), 'app_secret' => __('Client Secret', 'wp-social')],
472 ],
473 ],
474 'mailchimp' => [
475 'id' => ['type' => 'normal', 'label' => __('List ID (Optional)', 'wp-social'), 'input' => 'text'],
476 'api' => ['type' => 'normal', 'label' => __('API Key', 'wp-social'), 'input' => 'text'],
477 ],
478 ];
479 }
480
481 /**
482 * Get tiktok login url
483 *
484 * @param string $client_id
485 * @param string $client_secret
486 *
487 * @return string
488 */
489 public function get_tiktok_login_url( $client_id, $client_secret ) {
490
491 $authentication = new Authentication( array(
492 'client_key' => $client_id,
493 'client_secret' => $client_secret
494 ));
495
496 $redirect_url = site_url() . '/wp-json/wslu-social-counter/type/tiktok';
497
498 $scopes = array(
499 'user.info.stats'
500 );
501
502 $authentication_url= $authentication->getAuthenticationUrl( $redirect_url, $scopes );
503
504 return $authentication_url;
505 }
506
507 public function xs_counter_defalut_providers() {
508 if(!get_option('xs_counter_active')) {
509 $default_data = [
510 'social' => $this->xs_counter_providers(),
511 'cache' => 5,
512 ];
513
514 update_option('xs_counter_providers_data', $default_data);
515 update_option('xs_counter_active', WSLU_VERSION);
516 }
517 }
518 }
519
520
521