PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 1.8.2
Wp Social Login and Register Social Counter v1.8.2
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 4 years ago admin-create-shortcode.php 7 years ago admin-create-user.php 4 years ago admin-custom-function.php 4 years ago admin-rest-api.php 4 years ago admin-settings.php 4 years ago admin-social-button.php 4 years ago admin-social-enque-script.php 5 years ago counter-widget.php 4 years ago counter.php 4 years ago custom-function.php 4 years ago login-widget.php 4 years ago login.php 5 years ago share-widget.php 4 years ago share.php 4 years ago
counter.php
459 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
224 echo "<script type='text/javascript'>window.location='" . admin_url() . "admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=" . $getType . "';</script>";
225 exit;
226 }
227 } elseif($getType == 'instagram') {
228 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
229
230 $params = [
231 'client_id' => $app_id,
232 'response_type' => 'code',
233 'scope' => 'basic',
234 'redirect_uri' => $cur_page,
235 ];
236
237 $url = "https://api.instagram.com/oauth/authorize/?" . http_build_query($params);
238
239 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
240 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
241 header("Location: $url");
242
243 } elseif($getType == 'linkedin') {
244 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
245 $params = [
246 'response_type' => 'code',
247 'client_id' => $app_id,
248 //'scope' => 'rw_company_admin r_basicprofile',
249 'scope' => 'r_liteprofile r_emailaddress w_member_social r_ad_campaigns rw_organization',
250 'state' => uniqid('', true), // unique long string
251 'redirect_uri' => $cur_page,
252 ];
253
254 $url = 'https://www.linkedin.com/oauth/v2/authorization?' . http_build_query($params);
255
256 set_transient('xs_counter_' . $getType . '_api_key', $app_id, 60 * 60);
257 set_transient('xs_counter_' . $getType . '_secret_key', $app_secret, 60 * 60);
258
259 header("Location: $url");
260 } elseif($getType == 'facebook') {
261 $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
262 &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';
263
264 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
265
266 $params = [
267 'skip_api_login' => 1,
268 'api_key' => 1203050406491591,
269 'signed_next' => 1,
270 'next' => 'https://www.facebook.com/v2.12/dialog/oauth?redirect_uri=' . $cur_page,
271 'display' => 'popup',
272 'response_type' => 'code',
273 'client_id' => $app_id,
274 'scope' => 'public_profile email',
275 'ret' => 'login',
276 'logger_id' => '49a9a593-e908-a451-16d4-eb38a4ae7882',
277 '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',
278 'state' => uniqid('', true), // unique long string
279 'redirect_uri' => $cur_page,
280 ];
281 $url = 'https://www.facebook.com/login.php?' . http_build_query($params);
282 header("Location: $url");
283 } elseif($getType == 'dribbble') {
284 $cur_page = admin_url() . 'admin.php?page=wslu_counter_setting&tab=wslu_providers&xs_access=' . $getType . '';
285
286 $params = [
287 'client_id' => $app_id,
288 'response_type' => 'code',
289 'scope' => 'public',
290 'redirect_uri' => $cur_page,
291 'state' => substr(md5(microtime()), rand(0, 26), 10),
292 ];
293
294 $url = "https://dribbble.com/oauth/authorize?" . http_build_query($params);
295
296 /**
297 * Why saved in transient!!!!
298 *
299 */
300 update_option('xs_counter_dribbble_app_id', $app_id);
301 update_option('xs_counter_dribbble_app_secret', $app_secret);
302
303 set_transient('xs_counter_' . $getType . '_client_id', $app_id, 60 * 60);
304 set_transient('xs_counter_' . $getType . '_client_secret', $app_secret, 60 * 60);
305
306 header("Location: $url");
307 }
308 }
309 }
310
311
312 public function xs_counter_providers() {
313 $providers = [
314 'facebook' => [
315 'label' => 'Facebook',
316 'data' => ['text' => __('Fans', 'wp-social'), 'url' => 'http://www.facebook.com/%s'],
317 ],
318 'twitter' => [
319 'label' => 'Twitter',
320 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://twitter.com/%s'],
321 ],
322 //'linkedin' => [ 'label' => 'LinkedIn', 'data' => ['text' => __( 'Followers', 'wp-social' ), 'url' => 'https://www.linkedin.com/%s/%s'] ],
323 'pinterest' => [
324 'label' => 'Pinterest',
325 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://www.pinterest.com/%s'],
326 ],
327 'dribbble' => [
328 'label' => 'Dribbble',
329 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://dribbble.com/%s'],
330 ],
331 'instagram' => [
332 'label' => 'Instagram',
333 'data' => ['text' => __('Followers', 'wp-social'), 'url' => 'http://instagram.com/%s'],
334 ],
335 'youtube' => [
336 'label' => 'YouTube',
337 'data' => ['text' => __('Subscribers', 'wp-social'), 'url' => 'http://youtube.com/%s/%s'],
338 ],
339 'mailchimp' => ['label' => 'Mailchimp', 'data' => ['text' => __('Subscribers', 'wp-social')]],
340 'comments' => ['label' => 'Comments', 'data' => ['text' => __('Count', 'wp-social')]],
341 'posts' => ['label' => 'Posts', 'data' => ['text' => __('Count', 'wp-social')]],
342 //'vimeo' => [ 'label' => 'Vimeo', 'data' => ['text' => __( 'Subscribers', 'wp-social' ), 'url' => 'https://vimeo.com/channels/%s'] ],
343 //'vkontakte' => [ 'label' => 'Vkontakte', 'data' => ['text' => __( 'Members', 'wp-social' ), 'url' => 'http://vk.com/%s'] ],
344 ];
345
346 $providers_order = get_option(self::ORDER_LIST_PROVIDER_COUNTER);
347
348 return Providers::providers_sort($providers_order, $providers);
349 }
350
351
352 public function xs_counter_providers_data() {
353
354 // todo - alamin : make all label as translatable
355
356 return [
357 'facebook' => ['id' => ['type' => 'normal', 'label' => 'Page ID/Name', 'input' => 'text'],],
358 'twitter' => [
359 'id' => ['type' => 'normal', 'label' => 'Username', 'input' => 'text'],
360 'api' => [
361 'type' => 'access',
362 'label' => 'Access Token Key',
363 'input' => 'text',
364 'filed' => ['app_id' => 'Consumer key', 'app_secret' => 'Consumer secret'],
365 ],
366 ],
367
368 'instagram' => [
369
370 'user_name' => [
371 'type' => 'normal',
372 'label' => 'Username',
373 'input' => 'text',
374 ],
375
376 'get_token' => [
377 'type' => 'link',
378 'label' => esc_html__('Get access token ', 'wp-social'),
379 'input' => 'link',
380 'url' => 'https://token.wpmet.com/social_token.php?provider=instagram',
381 'class' => 'wslu-btn wslu-target-link',
382 ],
383
384 'access_token' => [
385 'type' => 'normal',
386 'label' => 'Access token',
387 'input' => 'text',
388 ],
389 'user_id' => [
390 'type' => 'normal',
391 'label' => 'User ID',
392 'input' => 'text',
393 ],
394 ],
395
396 'linkedin' => [
397 'type' => [
398 'type' => 'normal',
399 'label' => 'Account Type',
400 'input' => 'select',
401 'data' => ['Company' => 'Company', 'Profile' => 'Profile'],
402 ],
403 'id' => ['type' => 'normal', 'label' => 'Your ID', 'input' => 'text'],
404 'api' => [
405 'type' => 'access',
406 'label' => 'Access Token Key',
407 'input' => 'text',
408 'filed' => ['app_id' => 'API Key', 'app_secret' => 'Secret Key'],
409 ],
410 ],
411 'pinterest' => [
412 'username' => [
413 'type' => 'normal',
414 'label' => 'Username',
415 'input' => 'text',
416 ],
417 ],
418
419 'youtube' => [
420 'type' => [
421 'type' => 'normal',
422 'label' => 'Account Type',
423 'input' => 'select',
424 'data' => ['Channel' => 'Channel', 'User' => 'User'],
425 ],
426 'id' => ['type' => 'normal', 'label' => 'Username or Channel ID', 'input' => 'text'],
427 'key' => ['type' => 'normal', 'label' => 'YouTube API Key', 'input' => 'text'],
428 ],
429 'dribbble' => [
430 'api' => [
431 'type' => 'access',
432 'label' => 'Access Token Key',
433 'input' => 'text',
434 'filed' => ['app_id' => 'Client ID', 'app_secret' => 'Client Secret'],
435 ],
436 ],
437 'mailchimp' => [
438 'id' => ['type' => 'normal', 'label' => 'List ID (Optional)', 'input' => 'text'],
439 'api' => ['type' => 'normal', 'label' => 'API Key', 'input' => 'text'],
440 ],
441 ];
442 }
443
444
445 public function xs_counter_defalut_providers() {
446 if(!get_option('xs_counter_active')) {
447 $default_data = [
448 'social' => $this->xs_counter_providers(),
449 'cache' => 5,
450 ];
451
452 update_option('xs_counter_providers_data', $default_data);
453 update_option('xs_counter_active', WSLU_VERSION);
454 }
455 }
456 }
457
458
459