PluginProbe ʕ •ᴥ•ʔ
Nextend Social Login and Register / 3.1.9
Nextend Social Login and Register v3.1.9
trunk 1.0 1.1 1.2 1.4 1.4.9 1.6.0 2.0.2 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.27 3.0.28 3.0.29 3.0.3 3.0.4 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.23 3.1.25 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9
nextend-facebook-connect / admin / admin.php
nextend-facebook-connect / admin Last commit date
images 3 years ago templates 3 years ago templates-provider 3 years ago EditUser.php 6 years ago admin.php 3 years ago interim.php 6 years ago notice.php 3 years ago style.css 4 years ago upgrader.php 4 years ago
admin.php
1031 lines
1 <?php
2
3 use NSL\Notices;
4
5 define('NSL_ADMIN_PATH', __FILE__);
6
7 require_once dirname(__FILE__) . '/upgrader.php';
8
9 class NextendSocialLoginAdmin {
10
11 public static function init() {
12 add_action('admin_menu', 'NextendSocialLoginAdmin::admin_menu', 1);
13 add_action('admin_init', 'NextendSocialLoginAdmin::admin_init');
14
15 add_filter('plugin_action_links', 'NextendSocialLoginAdmin::plugin_action_links', 10, 2);
16
17 add_filter('nsl_update_settings_validate_nextend_social_login', 'NextendSocialLoginAdmin::validateSettings', 10, 2);
18
19 add_action('wp_ajax_nsl_save_review_state', 'NextendSocialLoginAdmin::save_review_state');
20 }
21
22 public static function getAdminUrl($view = 'providers') {
23
24 return add_query_arg(array(
25 'page' => 'nextend-social-login',
26 'view' => $view
27 ), admin_url('options-general.php'));
28 }
29
30 public static function getAdminSettingsUrl($subview = 'general') {
31
32 return add_query_arg(array(
33 'page' => 'nextend-social-login',
34 'view' => 'global-settings',
35 'subview' => $subview
36 ), admin_url('options-general.php'));
37 }
38
39 public static function admin_menu() {
40 $menu = add_options_page('Nextend Social Login', 'Nextend Social Login', NextendSocialLogin::getRequiredCapability(), 'nextend-social-login', array(
41 'NextendSocialLoginAdmin',
42 'display_admin'
43 ));
44
45 add_action('admin_print_styles-' . $menu, 'NextendSocialLoginAdmin::admin_css');
46 }
47
48 public static function admin_css() {
49 wp_enqueue_style('nsl-admin-stylesheet', plugins_url('/style.css?nsl-ver=' . urlencode(NextendSocialLogin::$version), NSL_ADMIN_PATH));
50 }
51
52 public static function display_admin() {
53 $view = !empty($_REQUEST['view']) ? $_REQUEST['view'] : '';
54
55 if (substr($view, 0, 9) == 'provider-') {
56 $providerID = substr($view, 9);
57 if (isset(NextendSocialLogin::$providers[$providerID])) {
58 self::display_admin_area('provider', $providerID);
59
60 return;
61 }
62 }
63 switch ($view) {
64 case 'fix-redirect-uri':
65 self::display_admin_area('fix-redirect-uri');
66 break;
67 case 'debug':
68 self::display_admin_area('debug');
69 break;
70 case 'test-connection':
71 self::display_admin_area('test-connection');
72 break;
73 case 'global-settings':
74 self::display_admin_area('global-settings');
75 break;
76 case 'pro-addon':
77 self::display_admin_area('pro-addon');
78 break;
79 case 'install-pro':
80 if (check_admin_referer('nextend-social-login')) {
81 self::display_admin_area('install-pro');
82 } else {
83 self::display_admin_area('providers');
84 }
85 break;
86 default:
87 self::display_admin_area('providers');
88 break;
89 }
90 }
91
92 /**
93 * @param string $view
94 * @param string $currentProvider
95 */
96 private static function display_admin_area($view, $currentProvider = '') {
97 if (empty($currentProvider)) {
98 include(dirname(__FILE__) . '/templates/header.php');
99 include(dirname(__FILE__) . '/templates/menu.php');
100
101 Notices::displayNotices();
102
103 /** @var string $view */
104 include(dirname(__FILE__) . '/templates/' . $view . '.php');
105 include(dirname(__FILE__) . '/templates/footer.php');
106 } else {
107 include(dirname(__FILE__) . '/templates/' . $view . '.php');
108 }
109 }
110
111 public static function renderProSettings() {
112 include(dirname(__FILE__) . '/templates/global-settings-pro.php');
113 }
114
115 public static function admin_init() {
116
117 if (current_user_can(NextendSocialLogin::getRequiredCapability())) {
118 if (!defined('NSL_PRO_PATH')) {
119 require_once(dirname(__FILE__) . '/notice.php');
120 }
121
122 if (!isset($_GET['page']) || $_GET['page'] != 'nextend-social-login' || !isset($_GET['view']) || $_GET['view'] != 'fix-redirect-uri') {
123 add_action('admin_notices', 'NextendSocialLoginAdmin::show_oauth_uri_notice');
124 }
125
126 if (!self::isPro() && NextendSocialLogin::$settings->get('woocommerce_dismissed') == 0 && class_exists('woocommerce', false) && count(NextendSocialLogin::$enabledProviders)) {
127 add_action('admin_notices', 'NextendSocialLoginAdmin::show_woocommerce_notice');
128 }
129
130
131 if (defined('THEME_MY_LOGIN_VERSION') && version_compare(THEME_MY_LOGIN_VERSION, '7.0.0', '>=')) {
132 if (!NextendSocialLogin::getRegisterFlowPage() || !NextendSocialLogin::getProxyPage()) {
133 add_action('admin_notices', 'NextendSocialLoginAdmin::show_theme_my_login_notice');
134 }
135 }
136 }
137
138 if (isset($_GET['page']) && $_GET['page'] == 'nextend-social-login') {
139 if (!empty($_GET['view'])) {
140 switch ($_GET['view']) {
141 case 'enable':
142 case 'sub-enable':
143 if (!empty($_GET['provider'])) {
144 if (check_admin_referer('nextend-social-login_enable_' . $_GET['provider'])) {
145 NextendSocialLogin::enableProvider($_GET['provider']);
146 }
147 if ($_GET['view'] == 'sub-enable') {
148 wp_redirect(NextendSocialLogin::$providers[$_GET['provider']]->getAdmin()
149 ->getUrl('settings'));
150 exit;
151 }
152
153 wp_redirect(self::getAdminUrl());
154 exit;
155 }
156 break;
157 case 'disable':
158 case 'sub-disable':
159 if (!empty($_GET['provider'])) {
160 if (check_admin_referer('nextend-social-login_disable_' . $_GET['provider'])) {
161 NextendSocialLogin::disableProvider($_GET['provider']);
162 }
163 if ($_GET['view'] == 'sub-disable') {
164 wp_redirect(NextendSocialLogin::$providers[$_GET['provider']]->getAdmin()
165 ->getUrl('settings'));
166 exit;
167 }
168
169 wp_redirect(self::getAdminUrl());
170 exit;
171 }
172 break;
173 case 'update_oauth_redirect_url':
174 if (check_admin_referer('nextend-social-login_update_oauth_redirect_url')) {
175 foreach (NextendSocialLogin::$enabledProviders as $provider) {
176 $provider->updateAuthRedirectUrl();
177 }
178 }
179
180 wp_redirect(self::getAdminUrl());
181 exit;
182
183 case 'dismiss_woocommerce':
184 if (check_admin_referer('nsl_dismiss_woocommerce')) {
185 NextendSocialLogin::$settings->update(array(
186 'woocommerce_dismissed' => 1
187 ));
188
189 if (!empty($_REQUEST['redirect_to'])) {
190 wp_safe_redirect($_REQUEST['redirect_to']);
191 exit;
192 }
193 }
194
195 wp_redirect(self::getAdminUrl());
196 break;
197 }
198 }
199 }
200 add_action('admin_post_nextend-social-login', 'NextendSocialLoginAdmin::save_form_data');
201 add_action('wp_ajax_nextend-social-login', 'NextendSocialLoginAdmin::ajax_save_form_data');
202
203
204 add_action('admin_enqueue_scripts', 'NextendSocialLoginAdmin::admin_enqueue_scripts');
205
206 if (!function_exists('json_decode')) {
207 add_settings_error('nextend-social', 'settings_updated', printf(__('%s needs json_decode function.', 'nextend-facebook-connect'), 'Nextend Social Login') . ' ' . __('Please contact your server administrator and ask for solution!', 'nextend-facebook-connect'), 'error');
208 }
209
210 add_action('show_user_profile', array(
211 'NextendSocialLoginAdmin',
212 'showUserFields'
213 ));
214 add_action('edit_user_profile', array(
215 'NextendSocialLoginAdmin',
216 'showUserFields'
217 ));
218
219 add_filter('display_post_states', array(
220 'NextendSocialLoginAdmin',
221 'display_post_states'
222 ), 10, 2);
223
224 if (defined('WPML_PLUGIN_BASENAME')) {
225 add_action('nsl_getting_started_warnings', array(
226 'NextendSocialLoginAdmin',
227 'show_WPML_warning'
228 ));
229 add_filter('nsl_redirect_uri_override', array(
230 'NextendSocialLoginAdmin',
231 'WPML_override_provider_redirect_uris'
232 ), 10, 2);
233
234 };
235
236 add_action('nsl_getting_started_warnings', array(
237 'NextendSocialLoginAdmin',
238 'show_getting_started_warning'
239 ), 100, 2);
240 }
241
242 public static function save_form_data() {
243 if (current_user_can(NextendSocialLogin::getRequiredCapability()) && check_admin_referer('nextend-social-login')) {
244 foreach ($_POST as $k => $v) {
245 if (is_string($v)) {
246 $_POST[$k] = stripslashes($v);
247 }
248 }
249
250 $view = !empty($_REQUEST['view']) ? $_REQUEST['view'] : '';
251
252 if ($view == 'global-settings') {
253
254 NextendSocialLogin::$settings->update($_POST);
255
256 Notices::addSuccess(__('Settings saved.'));
257
258 wp_redirect(self::getAdminSettingsUrl(!empty($_REQUEST['subview']) ? $_REQUEST['subview'] : ''));
259 exit;
260 } else if ($view == 'pro-addon') {
261
262 NextendSocialLogin::$settings->update($_POST);
263
264 if (NextendSocialLogin::hasLicense()) {
265 Notices::addSuccess(__('The activation was successful', 'nextend-facebook-connect'));
266 }
267
268 wp_redirect(self::getAdminUrl($view));
269 exit;
270 } else if ($view == 'pro-addon-deauthorize') {
271
272 NextendSocialLogin::$settings->update(array(
273 'license_key' => ''
274 ));
275
276 Notices::addSuccess(__('Deactivate completed.', 'nextend-facebook-connect'));
277
278 wp_redirect(self::getAdminUrl('pro-addon'));
279 exit;
280
281 } else if (substr($view, 0, 9) == 'provider-') {
282 $providerID = substr($view, 9);
283 if (isset(NextendSocialLogin::$providers[$providerID])) {
284
285 if (NextendSocialLogin::$providers[$providerID]->settings->update($_POST)) {
286 Notices::addSuccess(__('Settings saved.'));
287 }
288
289 wp_redirect(NextendSocialLogin::$providers[$providerID]->getAdmin()
290 ->getUrl(isset($_POST['subview']) ? $_POST['subview'] : ''));
291 exit;
292 }
293 }
294 }
295
296 wp_redirect(self::getAdminUrl());
297 exit;
298 }
299
300 public static function ajax_save_form_data() {
301 check_ajax_referer('nextend-social-login');
302 if (current_user_can(NextendSocialLogin::getRequiredCapability())) {
303 $view = !empty($_POST['view']) ? $_POST['view'] : '';
304 switch ($view) {
305 case 'orderProviders':
306 if (!empty($_POST['ordering'])) {
307 NextendSocialLogin::$settings->update(array(
308 'ordering' => $_POST['ordering']
309 ));
310 }
311 break;
312 case 'newsletterSubscribe':
313 $user_info = wp_get_current_user();
314 update_user_meta($user_info->ID, 'nsl_newsletter_subscription', 1);
315 break;
316 }
317 }
318 }
319
320 public static function validateSettings($newData, $postedData) {
321
322 if (isset($postedData['redirect'])) {
323 if (isset($postedData['custom_redirect_enabled']) && $postedData['custom_redirect_enabled'] == '1') {
324 $newData['redirect'] = trim(sanitize_text_field($postedData['redirect']));
325 } else {
326 $newData['redirect'] = '';
327 }
328 }
329
330 if (isset($postedData['redirect_reg'])) {
331 if (isset($postedData['custom_redirect_reg_enabled']) && $postedData['custom_redirect_reg_enabled'] == '1') {
332 $newData['redirect_reg'] = trim(sanitize_text_field($postedData['redirect_reg']));
333 } else {
334 $newData['redirect_reg'] = '';
335 }
336 }
337
338 if (isset($postedData['default_redirect'])) {
339 if (isset($postedData['default_redirect_enabled']) && $postedData['default_redirect_enabled'] == '1') {
340 $newData['default_redirect'] = trim(sanitize_text_field($postedData['default_redirect']));
341 } else {
342 $newData['default_redirect'] = '';
343 }
344 }
345
346 if (isset($postedData['default_redirect_reg'])) {
347 if (isset($postedData['default_redirect_reg_enabled']) && $postedData['default_redirect_reg_enabled'] == '1') {
348 $newData['default_redirect_reg'] = trim(sanitize_text_field($postedData['default_redirect_reg']));
349 } else {
350 $newData['default_redirect_reg'] = '';
351 }
352 }
353
354 foreach ($postedData as $key => $value) {
355 switch ($key) {
356 case 'debug':
357 case 'bypass_cache':
358 case 'login_restriction':
359 case 'avatars_in_all_media':
360 case 'custom_register_label':
361 case 'terms_show':
362 case 'store_name':
363 case 'store_email':
364 case 'avatar_store':
365 case 'store_access_token':
366 case 'redirect_prevent_external':
367 if ($value == 1) {
368 $newData[$key] = 1;
369 } else {
370 $newData[$key] = 0;
371 }
372 break;
373 case 'terms':
374 $newData[$key] = wp_kses_post($value);
375 break;
376 case 'blacklisted_urls':
377 $newData[$key] = sanitize_textarea_field($postedData[$key]);
378 break;
379 case 'show_login_form':
380 case 'login_form_button_align':
381 case 'show_registration_form':
382 case 'show_embedded_login_form':
383 case 'embedded_login_form_button_align':
384 case 'redirect_overlay':
385 $newData[$key] = sanitize_text_field($value);
386 break;
387 case 'enabled':
388 if (is_array($value)) {
389 $newData[$key] = $value;
390 }
391 break;
392 case 'ordering':
393 if (is_array($value)) {
394 $newData[$key] = $value;
395 }
396 break;
397 case 'license_key':
398 Notices::clear();
399
400 $value = trim(sanitize_text_field($value));
401
402 if (!empty($value)) {
403 try {
404 $response = self::apiCall('test-license', array('license_key' => $value));
405 if ($response === 'OK') {
406 $newData['licenses'] = array(
407 array(
408 'license_key' => $value,
409 'domain' => NextendSocialLogin::getDomain()
410 )
411 );
412 wp_clean_plugins_cache();
413 }
414 } catch (Exception $e) {
415 Notices::addError($e->getMessage());
416 }
417 } else {
418 wp_clean_plugins_cache();
419 $newData['licenses'] = array();
420 }
421 break;
422 case 'review_state':
423 case 'woocommerce_dismissed':
424 $newData[$key] = intval($value);
425 break;
426 case 'register-flow-page':
427 case 'proxy-page':
428 if (get_post($value) !== null) {
429 $newData[$key] = $value;
430 } else {
431 $newData[$key] = '';
432 }
433 break;
434
435 case 'allow_register':
436 if ($value == '0') {
437 $newData[$key] = 0;
438 } else if ($value == '1') {
439 $newData[$key] = 1;
440 } else {
441 $newData[$key] = -1;
442 }
443 break;
444
445
446 }
447 }
448
449 return $newData;
450 }
451
452 public static function plugin_action_links($links, $file) {
453
454 if ($file != NSL_PLUGIN_BASENAME) {
455 return $links;
456 }
457 $settings_link = '<a href="' . esc_url(menu_page_url('nextend-social-login', false)) . '">' . __('Settings') . '</a>';
458 $reactivate_link = sprintf('<a href="%s">%s</a>', wp_nonce_url(admin_url('admin.php?page=nextend-social-login&repairnsl=1'), 'repairnsl'), 'Analyze & Repair');
459 array_unshift($links, $settings_link, $reactivate_link);
460
461 return $links;
462 }
463
464 public static function admin_enqueue_scripts() {
465 if ('settings_page_nextend-social-login' === get_current_screen()->id) {
466
467 // Since WordPress 4.9
468 if (function_exists('wp_enqueue_code_editor')) {
469 // Enqueue code editor and settings for manipulating HTML.
470 $settings = wp_enqueue_code_editor(array('type' => 'text/html'));
471
472 // Bail if user disabled CodeMirror.
473 if (false === $settings) {
474 return;
475 }
476
477 wp_add_inline_script('code-editor', sprintf('jQuery( function() { var settings = %s; jQuery(".nextend-html-editor").each(function(i, el){wp.codeEditor.initialize( el, settings);}); } );', wp_json_encode($settings)));
478
479 $settings['codemirror']['readOnly'] = 'nocursor';
480
481 wp_add_inline_script('code-editor', sprintf('jQuery( function() { var settings = %s; jQuery(".nextend-html-editor-readonly").each(function(i, el){wp.codeEditor.initialize( el, settings);}); } );', wp_json_encode($settings)));
482 }
483
484 if (isset($_GET['view']) && $_GET['view'] == 'pro-addon') {
485 wp_enqueue_script('plugin-install');
486 wp_enqueue_script('updates');
487 }
488 }
489 }
490
491 private static $endpoint = 'https://api.nextendweb.com/v2/nextend-api/v2/';
492
493 public static function getEndpoint($action = '') {
494 return self::$endpoint . 'product/nsl/' . urlencode($action);
495 }
496
497 /**
498 * @param $action
499 * @param array $args
500 *
501 * @return bool|mixed
502 * @throws Exception
503 */
504 public static function apiCall($action, $args = array()) {
505
506 $body = array(
507 'platform' => 'wordpress',
508 'domain' => NextendSocialLogin::getDomain()
509 );
510
511 $activation_data = NextendSocialLogin::getLicense();
512 if ($activation_data !== false) {
513 $body['license_key'] = $activation_data['license_key'];
514 } else {
515 $body['license_key'] = '';
516 }
517
518 $http_args = array(
519 'timeout' => 15,
520 'user-agent' => 'WordPress',
521 'body' => array_merge($body, $args)
522 );
523
524 $request = wp_remote_get(self::getEndpoint($action), $http_args);
525
526 if (is_wp_error($request)) {
527
528 throw new Exception($request->get_error_message());
529 } else if (wp_remote_retrieve_response_code($request) !== 200) {
530
531 $response = json_decode(wp_remote_retrieve_body($request), true);
532 if (isset($response['message'])) {
533 $message = 'Nextend Social Login Pro Addon: ' . $response['message'];
534
535 Notices::addError($message);
536
537 return new WP_Error('error', $message);
538 }
539
540 throw new Exception(sprintf(__('Unexpected response: %s', 'nextend-facebook-connect'), wp_remote_retrieve_body($request)));
541 }
542
543 $response = json_decode(wp_remote_retrieve_body($request), true);
544
545 return $response;
546 }
547
548 public static function showProBox() {
549 if (!self::isPro()) {
550 include(dirname(__FILE__) . '/templates/pro.php');
551 }
552 }
553
554 public static function getProState() {
555
556 if (NextendSocialLogin::hasLicense()) {
557 if (self::isPro()) {
558 return 'activated';
559 } else if (!current_user_can('install_plugins')) {
560 return 'no-capability';
561 } else if (class_exists('NextendSocialLoginPRO', false) && version_compare(NextendSocialLogin::$version, NextendSocialLoginPRO::$nslMinVersion, '<')) {
562 return 'free-not-compatible';
563 } else if (class_exists('NextendSocialLoginPRO', false) && version_compare(NextendSocialLoginPRO::$version, NextendSocialLogin::$nslPROMinVersion, '<')) {
564 return 'pro-not-compatible';
565 } else {
566 if (file_exists(WP_PLUGIN_DIR . '/nextend-social-login-pro/nextend-social-login-pro.php')) {
567 return 'installed';
568 } else {
569 return 'not-installed';
570 }
571 }
572 }
573
574 return 'no-license';
575 }
576
577 public static function trackUrl($url, $source) {
578 return add_query_arg(array(
579 'utm_campaign' => 'nsl',
580 'utm_source' => urlencode($source),
581 'utm_medium' => 'nsl-wordpress-' . (apply_filters('nsl-pro', false) ? 'pro' : 'free')
582 ), $url);
583 }
584
585 public static function save_review_state() {
586 check_ajax_referer('nsl_save_review_state');
587 if (isset($_POST['review_state'])) {
588 $review_state = intval($_POST['review_state']);
589 if ($review_state > 0) {
590
591 NextendSocialLogin::$settings->update(array(
592 'review_state' => $review_state
593 ));
594 }
595 }
596 wp_die();
597 }
598
599 public static function show_oauth_uri_notice() {
600 foreach (NextendSocialLogin::$enabledProviders as $provider) {
601 if (!$provider->checkAuthRedirectUrl()) {
602 echo '<div class="error">
603 <p>' . sprintf(__('%s detected that your login url changed. You must update the Oauth redirect URIs in the related social applications.', 'nextend-facebook-connect'), '<b>Nextend Social Login</b>') . '</p>
604 <p class="submit"><a href="' . NextendSocialLoginAdmin::getAdminUrl('fix-redirect-uri') . '" class="button button-primary">' . __('Fix Error', 'nextend-facebook-connect') . ' - ' . __('Oauth Redirect URI', 'nextend-facebook-connect') . '</a></p>
605 </div>';
606 break;
607 }
608 }
609 }
610
611 public static function show_woocommerce_notice() {
612 $redirectTo = array();
613
614 $currentPageUrl = NextendSocialLogin::getCurrentPageURL();
615 if ($currentPageUrl !== false) {
616 $redirectTo['redirect_to'] = urlencode($currentPageUrl);
617 }
618
619 $dismissUrl = wp_nonce_url(add_query_arg($redirectTo, NextendSocialLoginAdmin::getAdminUrl('dismiss_woocommerce')), 'nsl_dismiss_woocommerce');
620 echo '<div class="notice notice-info">
621 <p>' . sprintf(__('%1$s detected that %2$s installed on your site. You need the Pro Addon to display Social Login buttons in %2$s login form!', 'nextend-facebook-connect'), '<b>Nextend Social Login</b>', '<b>WooCommerce</b>') . '</p>
622 <p><a href="' . NextendSocialLoginAdmin::trackUrl('https://nextendweb.com/social-login/', 'woocommerce-notice') . '" target="_blank" onclick="window.location.href=\'' . esc_url($dismissUrl) . '\';" class="button button-primary">' . __('Dismiss and check Pro Addon', 'nextend-facebook-connect') . '</a> <a href="' . esc_url($dismissUrl) . '" class="button button-secondary">' . __('Dismiss', 'nextend-facebook-connect') . '</a></p>
623 </div>';
624 }
625
626 public static function show_theme_my_login_notice() {
627 echo '<div class="notice notice-info">
628 <p>' . sprintf(__('%1$s detected that %2$s installed on your site. You must set "<b>Page for register flow</b>" and "<b>OAuth redirect uri proxy page</b>" in %1$s to work properly.', 'nextend-facebook-connect'), '<b>Nextend Social Login</b>', '<b>Theme My Login</b>') . '</p>
629 <p><a href="' . NextendSocialLoginAdmin::getAdminSettingsUrl('general') . '" class="button button-primary">' . __('Fix now', 'nextend-facebook-connect') . '</a></p>
630 </div>';
631 }
632
633 public static function isPro() {
634 return apply_filters('nsl-pro', false);
635 }
636
637 public static function showUserFields($user) {
638 include(dirname(__FILE__) . '/EditUser.php');
639 }
640
641 public static function authorizeBox($view = 'pro-addon') {
642
643 $args = array(
644 'product' => 'nsl',
645 'domain' => NextendSocialLogin::getDomain(),
646 'platform' => 'wordpress'
647
648 );
649
650 $authorizeUrl = NextendSocialLoginAdmin::trackUrl('https://secure.nextendweb.com/authorize/', 'authorize');
651 ?>
652 <div class="nsl-box nsl-box-yellow nsl-box-padlock">
653 <h2 class="title"><?php _e('Activate your Pro Addon', 'nextend-facebook-connect'); ?></h2>
654 <p><?php _e('To be able to use the Pro features, you need to activate Nextend Social Login Pro Addon. You can do this by clicking on the Activate button below then select the related purchase.', 'nextend-facebook-connect'); ?></p>
655
656 <p>
657 <a href="#"
658 onclick="NSLActivate()"
659 class="button button-primary"><?php _e('Activate', 'nextend-facebook-connect'); ?></a>
660 </p>
661 </div>
662
663 <script type="text/javascript">
664 (function ($) {
665
666 var args = <?php echo wp_json_encode($args); ?>;
667 window.addEventListener('message', function (e) {
668 if (e.origin === 'https://secure.nextendweb.com') {
669 if (typeof window.authorizeWindow === 'undefined') {
670 if (typeof e.source !== 'undefined') {
671 window.authorizeWindow = e.source;
672 } else {
673 return false;
674 }
675 }
676
677 try {
678 var envelope = JSON.parse(e.data);
679
680 if (envelope.action) {
681 switch (envelope.action) {
682 case 'ready':
683 window.authorizeWindow.postMessage(JSON.stringify({
684 'action': 'authorize',
685 'data': args
686 }), 'https://secure.nextendweb.com');
687 break;
688 case 'license':
689 $('#nsl_license_key').val(envelope.license_key);
690 $('#nsl_license_form').submit();
691 break;
692 }
693
694 }
695 } catch (ex) {
696 console.error(ex);
697 console.log(e);
698 }
699 }
700 });
701 })(jQuery);
702
703 function NSLActivate() {
704 var isIE = (function detectIE() {
705 var ua = window.navigator.userAgent;
706
707 var msie = ua.indexOf('MSIE ');
708 if (msie > 0) {
709 // IE 10 or older => return version number
710 return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
711 }
712
713 var trident = ua.indexOf('Trident/');
714 if (trident > 0) {
715 // IE 11 => return version number
716 var rv = ua.indexOf('rv:');
717 return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
718 }
719
720 var edge = ua.indexOf('Edge/');
721 if (edge > 0) {
722 // Edge (IE 12+) => return version number
723 return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
724 }
725
726 // other browser
727 return false;
728 })();
729
730 if (isIE <= 11) {
731 /**
732 * Trick for cross origin popup postMessage in IE 11
733 * @see <https://stackoverflow.com/a/36630058/305604>
734 */
735
736 window.authorizeWindow = NSLPopup('/', 'authorize-window', 800, 800);
737 window.authorizeWindow.location.href = 'about:blank';
738 window.authorizeWindow.location.href = '<?php echo $authorizeUrl; ?>';
739 } else {
740 window.authorizeWindow = NSLPopup('<?php echo $authorizeUrl; ?>', 'authorize-window', 800, 800);
741 }
742 return false;
743 }
744 </script>
745
746 <form id="nsl_license_form" method="post" action="<?php echo admin_url('admin-post.php'); ?>"
747 novalidate="novalidate" style="display:none;">
748
749 <?php wp_nonce_field('nextend-social-login'); ?>
750 <input type="hidden" name="action" value="nextend-social-login"/>
751 <input type="hidden" name="view" value="<?php echo $view; ?>"/>
752
753 <table class="form-table">
754 <tbody>
755 <tr>
756 <th scope="row"><label
757 for="nsl_license_key"><?php _e('License key', 'nextend-facebook-connect'); ?></label>
758 </th>
759 <?php
760 $license_key = '';
761 $authorizedData = NextendSocialLogin::getLicense();
762 if ($authorizedData !== false) {
763 $license_key = $authorizedData['license_key'];
764 }
765 ?>
766 <td><input name="license_key" type="text" id="nsl_license_key"
767 value="<?php echo esc_attr($license_key); ?>"
768 class="regular-text">
769 </td>
770 </tr>
771 </tbody>
772 </table>
773
774 </form>
775 <?php
776 }
777
778 public static function display_post_states($post_states, $post) {
779 if (NextendSocialLogin::getProxyPage() === $post->ID) {
780 $post_states['nsl_proxy_page'] = __('OAuth proxy page') . ' — NSL';
781 }
782 if (NextendSocialLogin::getRegisterFlowPage() === $post->ID) {
783 $post_states['nsl_proxy_page'] = __('Register flow page') . ' — NSL';
784 }
785
786 return $post_states;
787 }
788
789 public static function show_WPML_warning() {
790 printf(__('<strong><u>Warning</u></strong>: You are using <b>%1$s</b>! Depending on your %1$s configuration the Redirect URI can be different. For more information please check our %2$s %1$s compatibility tutorial%3$s!', 'nextend-facebook-connect'), 'WPML', '<a href="https://nextendweb.com/nextend-social-login-docs/how-to-make-nextend-social-login-compatible-with-wpml/" target="_blank">', '</a>');
791 }
792
793 /**
794 * @param array $redirectUrls
795 * @param NextendSocialProvider $provider
796 *
797 * Used for:
798 * -overriding the redirect url with the language specific redirect URLs in provider Getting Started
799 * sections.
800 * -generating language specific redirect urls for the OAuth check warning.
801 *
802 * @return array
803 */
804 public static function WPML_override_provider_redirect_uris($redirectUrls, $provider) {
805
806 $addArg = true;
807 if ($provider->authRedirectBehavior !== 'default') {
808 /**
809 * We shouldn't add any query parameters into the redirect url if:
810 * -query parameters are not supported in the redirect uri
811 * -or the redirect is handled over the REST /redirect_uri endpoint of the provider.
812 */
813 $addArg = false;
814 }
815
816
817 global $sitepress;
818 if ($sitepress && method_exists($sitepress, 'get_active_languages')) {
819 $WPML_active_languages = $sitepress->get_active_languages();
820 if (count($WPML_active_languages) > 1 && defined('ICL_LANGUAGE_CODE')) {
821 $originalLanguageCode = ICL_LANGUAGE_CODE;
822 $defaultLanguageCode = self::get_default_WPML_language_code();
823 $languageCodeWasOverridden = false;
824
825 $converted_URLs = array();
826 $args = array('loginSocial' => $provider->getId());
827
828
829 if ($provider->authRedirectBehavior !== 'rest_redirect') {
830 $proxyPage = NextendSocialLogin::getProxyPage();
831
832 if ($proxyPage) {
833 /**
834 * OAuth flow handled over OAuth redirect uri proxy page
835 * This needs to be handled differently than /wp-login.php URLs, because in these cases
836 * the slug of the translated OAuth redirect uri proxy page can be different as well!
837 */
838
839 foreach ($WPML_active_languages as $lang) {
840 $convertedURL = get_permalink(apply_filters('wpml_object_id', $proxyPage, 'page', false, $lang['code']));
841 if ($convertedURL) {
842 if ($addArg) {
843 $convertedURL = add_query_arg($args, $convertedURL);
844 } else {
845 /**
846 * Converted URLs may contain GET parameters, so we need to remove them for the providers that don't support GET parameters in the redirect urls.
847 */
848 $convertedURLPieces = explode('?', $convertedURL);
849 $convertedURL = $convertedURLPieces[0];
850 }
851 $converted_URLs[] = $convertedURL;
852 }
853 }
854 } else {
855 //OAuth flow handled over wp-login.php
856
857 $WPML_language_url_format = false;
858 if (method_exists($sitepress, 'get_setting')) {
859 $WPML_language_url_format = $sitepress->get_setting('language_negotiation_type');
860 }
861
862 if ($WPML_language_url_format && $WPML_language_url_format == 3 && (!class_exists('\WPML\UrlHandling\WPLoginUrlConverter') || (class_exists('\WPML\UrlHandling\WPLoginUrlConverter') && (!get_option(\WPML\UrlHandling\WPLoginUrlConverter::SETTINGS_KEY, false) || (get_option(\WPML\UrlHandling\WPLoginUrlConverter::SETTINGS_KEY, false) && !$addArg))))) {
863 /**
864 * We need to display the original redirect url when the
865 * Language URL format is set to "Language name added as a parameter and:
866 * -when the WPLoginUrlConverter class doesn't exists, since that case it is an old WPML version that can not translate the /wp-login.php page
867 * -if "Login and registration pages - Allow translating the login and registration pages" is disabled
868 * -if "Login and registration pages - Allow translating the login and registration pages" is enabled, but the provider doesn't support GET parameters in the redirect URL
869 */
870 return $redirectUrls;
871 } else {
872 global $wpml_url_converter;
873 /**
874 * when the language URL format is set to "Different languages in directories" or "A different domain per language", then the Redirect URI will be different for each languages
875 * Also when the language URL format is set to "Language name added as a parameter" and the "Login and registration pages - Allow translating the login and registration pages" setting is enabled, the urls will be different.
876 */
877 if ($wpml_url_converter && method_exists($wpml_url_converter, 'convert_url')) {
878
879
880 /**
881 * When WPML is set to a non-default language in the backend, then the $wpml_url_converter->convert_url() function won't generate language specific URL
882 * if the provided language code is the same the the language code that the backend currently uses.
883 */
884 if ($originalLanguageCode && $defaultLanguageCode && $originalLanguageCode !== $defaultLanguageCode) {
885 self::change_WPML_language_code($defaultLanguageCode, false);
886 $languageCodeWasOverridden = true;
887 }
888
889 foreach ($WPML_active_languages as $lang) {
890 $convertedURL = $wpml_url_converter->convert_url(site_url('wp-login.php'), $lang['code']);
891 if ($addArg) {
892 $convertedURL = add_query_arg($args, $convertedURL);
893 }
894 $converted_URLs[] = $convertedURL;
895 }
896
897 if ($languageCodeWasOverridden) {
898 /**
899 * we need to switch back to the original language if we had to switch earlier
900 */
901 self::change_WPML_language_code($originalLanguageCode, true);
902 $languageCodeWasOverridden = false;
903 }
904 }
905 }
906 }
907 } else {
908 /**
909 * For providers with REST API redirect url, we should generate language specific versions from the rest route.
910 * These urls should never contain the ?loginSocial={{providerID}} parameter. Since that is the main reason of the provider prefers uses the REST API endpoint.
911 * The redirect url is not affected by the "/wp-login.php" or "OAuth redirect uri proxy page" changes in this case.
912 */
913
914 $WPML_language_url_format = false;
915 if (method_exists($sitepress, 'get_setting')) {
916 $WPML_language_url_format = $sitepress->get_setting('language_negotiation_type');
917 }
918 if (!$WPML_language_url_format || ($WPML_language_url_format && $WPML_language_url_format == 3)) {
919 /**
920 * We need to return the original provider REST API url when:
921 * -the Language URL format is set to "Language name added as a parameter
922 * -or if there is no Language URL format set
923 */
924 $converted_URLs = $redirectUrls;
925 } else {
926 global $wpml_url_converter;
927 if ($wpml_url_converter && method_exists($wpml_url_converter, 'convert_url')) {
928
929 /**
930 * When the WPML language in the backend is set to "All", then WPML will generate an invalid REST API url with this "all" string appearing in it,
931 * so we would generate wrong redirect urls.
932 * For this reason it is better if we always use the default language for the URL generation here, too.
933 */
934 if ($originalLanguageCode && $defaultLanguageCode && $originalLanguageCode !== $defaultLanguageCode) {
935 self::change_WPML_language_code($defaultLanguageCode, false);
936 $languageCodeWasOverridden = true;
937 }
938
939 $redirectUrl = $provider->getBaseRedirectUriForAppCreation();
940
941 foreach ($WPML_active_languages as $lang) {
942 $convertedURL = $wpml_url_converter->convert_url($redirectUrl, $lang['code']);
943 /**
944 * WPML might generate URLs with trailing slash, however we use the REST redirect URL without trailing slash.
945 */
946 $convertedURL = rtrim($convertedURL, '/');
947 if ($addArg) {
948 $convertedURL = add_query_arg($args, $convertedURL);
949 }
950 $converted_URLs[] = $convertedURL;
951 }
952
953 if ($languageCodeWasOverridden) {
954 /**
955 * we need to switch back to the original language if we had to switch earlier
956 */
957 self::change_WPML_language_code($originalLanguageCode, true);
958 $languageCodeWasOverridden = false;
959 }
960 }
961 }
962 }
963
964 if (!empty($converted_URLs)) {
965 return $converted_URLs;
966 }
967 }
968 }
969
970 return $redirectUrls;
971 }
972
973 /**
974 * Returns the default language code used by WPML.
975 *
976 * @return bool|string
977 */
978 public static function get_default_WPML_language_code() {
979 global $sitepress;
980
981 if ($sitepress) {
982 return $sitepress->get_default_language();
983 }
984
985 return false;
986 }
987
988 /**
989 * Thins function can be used for changing the language code that WPML use during URL conversion.
990 *
991 * @param string $languageCode - the language code that WPML will switch to
992 * @param bool $restore - if true, that means we shouldn't override the language for the
993 * get_language_from_url() function of WPML.
994 */
995 public static function change_WPML_language_code($languageCode, $restore) {
996 global $sitepress;
997
998 if ($sitepress) {
999 $sitepress->switch_lang($languageCode, true);
1000 if ($restore) {
1001 remove_filter('wpml_get_language_from_url', 'NextendSocialLoginAdmin::get_default_WPML_language_code', 1000000000);
1002 } else {
1003 add_filter('wpml_get_language_from_url', 'NextendSocialLoginAdmin::get_default_WPML_language_code', 1000000000);
1004 }
1005 }
1006 }
1007
1008 /**
1009 * @param NextendSocialProviderDummy $provider
1010 * @param string $lastUpdated
1011 */
1012 public static function show_getting_started_warning($provider, $lastUpdated) {
1013 if ($provider && $lastUpdated) {
1014
1015 $lastUpdatedDate = date_format(date_create_from_format('Y-m-d', $lastUpdated), get_option('date_format'));
1016
1017 $supportURL = 'https://nextendweb.com/contact-us/nextend-social-login-support/';
1018 $version = defined('NSL_PRO_PATH') ? 'Pro-Addon' : 'Free';
1019 $args = array(
1020 'topic' => 'Wrong-Steps',
1021 'provider' => $provider->getLabel(),
1022 'version' => $version
1023 );
1024 $supportUrlWithArgs = add_query_arg($args, $supportURL);
1025
1026 $documentationURL = 'https://nextendweb.com/nextend-social-login-docs/provider-' . $provider->getId() . '/';
1027
1028 printf(__('<p><strong><u>Warning</u></strong>: Providers change the App setup process quite often, which means some steps below might not be accurate. If you see significant difference in the written instructions and what you see at the provider, check the guide in the %1$sonline documentation%2$s first, just in case if we are already aware of the changes hence updated the guide. Otherwise feel free to %3$sreport the changes%4$s, so we can check and update the instructions.<br><strong>Last updated:</strong> %5$s.</p>', 'nextend-facebook-connect'), '<a href="' . $documentationURL . '" target="_blank">', '</a>', '<a href="' . $supportUrlWithArgs . '" target="_blank">', '</a>', $lastUpdatedDate);
1029 }
1030 }
1031 }