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