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 / 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 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
counter.php
461 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 $hoverStyles = \WP_Social_Pro\Inc\Admin_Settings::$counter_hover_effects;
150 }
151
152 $globalShareSettings = get_option('xs_counter_global_setting_data', '');
153 $themeFontClass = empty($globalShareSettings['show_font_from_theme']) ? 'wslu-theme-font-no' : 'wslu-theme-font-yes';
154
155 $style = get_option('xs_style_setting_data_counter', '');
156
157 $styleConfig = isset($style['login_button_style']['style']) ? $style['login_button_style']['style'] : 'style-1:none-none';
158
159 $bArr = explode(':', $styleConfig);
160
161 $cntStyleKey = empty($config['style']) ? $bArr[0] : $config['style'];
162 $cntHoverKey = empty($config['hover']) ? $bArr[1] : $config['hover'];
163
164 $mainStyleCls = isset($styleArr[$cntStyleKey]['class']) ? 'wslu-' . $cntStyleKey . ' ' . $styleArr[$cntStyleKey]['class'] : '';
165 $hoverClass = empty($hoverStyles[$cntHoverKey]) ? $hoverStyles['none-none']['class'] : $hoverStyles[$cntHoverKey]['class'];
166 $widget_style = $mainStyleCls . ' ' . $hoverClass . ' ' . $themeFontClass;
167
168 $counter_data = \WP_Social\App\Settings::get_counter_cached_data();
169 $counter_provider = \WP_Social\App\Settings::get_counter_provider_settings();
170
171 ob_start();
172 require(WSLU_LOGIN_PLUGIN . '/template/counter/counter-html.php');
173 $counter = ob_get_contents();
174 ob_end_clean();
175
176 return $counter;
177 }
178
179
180 public function counter_access_key_setup() {
181
182 if(isset($_POST['xs_provider_submit_form_access_counter'])) {
183
184 $getpage = isset($_GET['page']) ? Admin_Settings::sanitize($_GET['page']) : '';
185 $getType = isset($_GET['xs_access']) ? Admin_Settings::sanitize($_GET['xs_access']) : '';
186
187 if($getpage != 'wslu_counter_setting') {
188 return '';
189 }
190
191 $accesskey = isset($_POST['accesskey']) ? Admin_Settings::sanitize($_POST['accesskey']) : '';
192 $app_id = isset($accesskey[$getType]['app_id']) ? $accesskey[$getType]['app_id'] : '';
193 $app_secret = isset($accesskey[$getType]['app_secret']) ? $accesskey[$getType]['app_secret'] : '';
194
195 if($getType == 'twitter') {
196 // preparing credentials
197 $credentials = $app_id . ':' . $app_secret;
198 $toSend = base64_encode($credentials);
199
200 // http post arguments
201 $args = [
202 'method' => 'POST',
203 'httpversion' => '1.1',
204 'blocking' => true,
205 'headers' => [
206 'Authorization' => 'Basic ' . $toSend,
207 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
208 ],
209 'body' => ['grant_type' => 'client_credentials'],
210 ];
211
212 add_filter('https_ssl_verify', '__return_false');
213 $response = wp_remote_post('https://api.twitter.com/oauth2/token', $args);
214
215 $keys = json_decode(wp_remote_retrieve_body($response));
216 if(!isset($keys->access_token)) {
217 return '';
218 }
219 if(!empty($keys->access_token)) {
220 update_option('xs_counter_' . $getType . '_token', $keys->access_token);
221 update_option('xs_counter_' . $getType . '_app_id', $app_id);
222 update_option('xs_counter_' . $getType . '_app_secret', $app_secret);
223 $redirect_url = admin_url() . "admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=$getType";
224 ?>
225 <script type='text/javascript'>window.location='<?php echo esc_url($redirect_url); ?>'</script>
226 <?php
227 exit;
228 }
229 } elseif($getType == 'instagram') {
230 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
231
232 $params = [
233 'client_id' => $app_id,
234 'response_type' => 'code',
235 'scope' => 'basic',
236 'redirect_uri' => $cur_page,
237 ];
238
239 $url = "https://api.instagram.com/oauth/authorize/?" . http_build_query($params);
240
241 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
242 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
243 header("Location: $url");
244
245 } elseif($getType == 'linkedin') {
246 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
247 $params = [
248 'response_type' => 'code',
249 'client_id' => $app_id,
250 //'scope' => 'rw_company_admin r_basicprofile',
251 'scope' => 'r_liteprofile r_emailaddress w_member_social r_ad_campaigns rw_organization',
252 'state' => uniqid('', true), // unique long string
253 'redirect_uri' => $cur_page,
254 ];
255
256 $url = 'https://www.linkedin.com/oauth/v2/authorization?' . http_build_query($params);
257
258 set_transient('xs_counter_' . $getType . '_api_key', $app_id, 60 * 60);
259 set_transient('xs_counter_' . $getType . '_secret_key', $app_secret, 60 * 60);
260
261 header("Location: $url");
262 } elseif($getType == 'facebook') {
263 $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
264 &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';
265
266 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
267
268 $params = [
269 'skip_api_login' => 1,
270 'api_key' => 1203050406491591,
271 'signed_next' => 1,
272 'next' => 'https://www.facebook.com/v2.12/dialog/oauth?redirect_uri=' . $cur_page,
273 'display' => 'popup',
274 'response_type' => 'code',
275 'client_id' => $app_id,
276 'scope' => 'public_profile email',
277 'ret' => 'login',
278 'logger_id' => '49a9a593-e908-a451-16d4-eb38a4ae7882',
279 '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',
280 'state' => uniqid('', true), // unique long string
281 'redirect_uri' => $cur_page,
282 ];
283 $url = 'https://www.facebook.com/login.php?' . http_build_query($params);
284 header("Location: $url");
285 } elseif($getType == 'dribbble') {
286 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
287
288 $params = [
289 'client_id' => $app_id,
290 'response_type' => 'code',
291 'scope' => 'public',
292 'redirect_uri' => $cur_page,
293 'state' => substr(md5(microtime()), rand(0, 26), 10),
294 ];
295
296 $url = "https://dribbble.com/oauth/authorize?" . http_build_query($params);
297
298 /**
299 * Why saved in transient!!!!
300 *
301 */
302 update_option('xs_counter_dribbble_app_id', $app_id);
303 update_option('xs_counter_dribbble_app_secret', $app_secret);
304
305 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
306 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
307
308 header("Location: $url");
309 }
310 }
311 }
312
313
314 public function xs_counter_providers() {
315 $providers = [
316 'facebook' => [
317 'label' => 'Facebook',
318 'data' => ['text' => __('Fans', 'wp-social'), 'url' => 'http://www.facebook.com/%s'],
319 ],
320 'twitter' => [
321 'label' => 'Twitter',
322 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://twitter.com/%s'],
323 ],
324 //'linkedin' => [ 'label' => 'LinkedIn', 'data' => ['text' => __( 'Followers', 'wp-social' ), 'url' => 'https://www.linkedin.com/%s/%s'] ],
325 'pinterest' => [
326 'label' => 'Pinterest',
327 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://www.pinterest.com/%s'],
328 ],
329 'dribbble' => [
330 'label' => 'Dribbble',
331 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://dribbble.com/%s'],
332 ],
333 'instagram' => [
334 'label' => 'Instagram',
335 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://instagram.com/%s'],
336 ],
337 'youtube' => [
338 'label' => 'YouTube',
339 'data' => ['text' => __('Subscribers', 'wp-social'), 'url' => 'http://youtube.com/%s/%s'],
340 ],
341 'mailchimp' => ['label' => 'Mailchimp', 'data' => ['text' => __('Subscribers', 'wp-social')]],
342 'comments' => ['label' => 'Comments', 'data' => ['text' => __('Count', 'wp-social')]],
343 'posts' => ['label' => 'Posts', 'data' => ['text' => __('Count', 'wp-social')]],
344 //'vimeo' => [ 'label' => 'Vimeo', 'data' => ['text' => __( 'Subscribers', 'wp-social' ), 'url' => 'https://vimeo.com/channels/%s'] ],
345 //'vkontakte' => [ 'label' => 'Vkontakte', 'data' => ['text' => __( 'Members', 'wp-social' ), 'url' => 'http://vk.com/%s'] ],
346 ];
347
348 $providers_order = get_option(self::ORDER_LIST_PROVIDER_COUNTER);
349
350 return Providers::providers_sort($providers_order, $providers);
351 }
352
353
354 public function xs_counter_providers_data() {
355
356 // todo - alamin : make all label as translatable
357
358 return [
359 'facebook' => ['id' => ['type' => 'normal', 'label' => 'Page ID/Name', 'input' => 'text'],],
360 'twitter' => [
361 'id' => ['type' => 'normal', 'label' => 'Username', 'input' => 'text'],
362 'api' => [
363 'type' => 'access',
364 'label' => 'Access Token Key',
365 'input' => 'text',
366 'filed' => ['app_id' => 'Consumer key', 'app_secret' => 'Consumer secret'],
367 ],
368 ],
369
370 'instagram' => [
371
372 'user_name' => [
373 'type' => 'normal',
374 'label' => 'Username',
375 'input' => 'text',
376 ],
377
378 'get_token' => [
379 'type' => 'link',
380 'label' => esc_html__('Get access token ', 'wp-social'),
381 'input' => 'link',
382 'url' => 'https://token.wpmet.com/social_token.php?provider=instagram',
383 'class' => 'wslu-btn wslu-target-link',
384 ],
385
386 'access_token' => [
387 'type' => 'normal',
388 'label' => 'Access token',
389 'input' => 'text',
390 ],
391 'user_id' => [
392 'type' => 'normal',
393 'label' => 'User ID',
394 'input' => 'text',
395 ],
396 ],
397
398 'linkedin' => [
399 'type' => [
400 'type' => 'normal',
401 'label' => 'Account Type',
402 'input' => 'select',
403 'data' => ['Company' => 'Company', 'Profile' => 'Profile'],
404 ],
405 'id' => ['type' => 'normal', 'label' => 'Your ID', 'input' => 'text'],
406 'api' => [
407 'type' => 'access',
408 'label' => 'Access Token Key',
409 'input' => 'text',
410 'filed' => ['app_id' => 'API Key', 'app_secret' => 'Secret Key'],
411 ],
412 ],
413 'pinterest' => [
414 'username' => [
415 'type' => 'normal',
416 'label' => 'Username',
417 'input' => 'text',
418 ],
419 ],
420
421 'youtube' => [
422 'type' => [
423 'type' => 'normal',
424 'label' => 'Account Type',
425 'input' => 'select',
426 'data' => ['Channel' => 'Channel', 'User' => 'User'],
427 ],
428 'id' => ['type' => 'normal', 'label' => 'Username or Channel ID', 'input' => 'text'],
429 'key' => ['type' => 'normal', 'label' => 'YouTube API Key', 'input' => 'text'],
430 ],
431 'dribbble' => [
432 'api' => [
433 'type' => 'access',
434 'label' => 'Access Token Key',
435 'input' => 'text',
436 'filed' => ['app_id' => 'Client ID', 'app_secret' => 'Client Secret'],
437 ],
438 ],
439 'mailchimp' => [
440 'id' => ['type' => 'normal', 'label' => 'List ID (Optional)', 'input' => 'text'],
441 'api' => ['type' => 'normal', 'label' => 'API Key', 'input' => 'text'],
442 ],
443 ];
444 }
445
446
447 public function xs_counter_defalut_providers() {
448 if(!get_option('xs_counter_active')) {
449 $default_data = [
450 'social' => $this->xs_counter_providers(),
451 'cache' => 5,
452 ];
453
454 update_option('xs_counter_providers_data', $default_data);
455 update_option('xs_counter_active', WSLU_VERSION);
456 }
457 }
458 }
459
460
461