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