From 616add5c9342bfa3016e5e92ae9644b7a43f0755 Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Thu, 20 Feb 2020 00:03:16 +0100 Subject: [PATCH] Code deduplication in signup_shortcodes for XUP login Also fixed variable passing weirdness in API of e_user_provider --- .../shortcodes/batch/signup_shortcodes.php | 140 ++++++++---------- e107_handlers/user_handler.php | 6 +- 2 files changed, 63 insertions(+), 83 deletions(-) diff --git a/e107_core/shortcodes/batch/signup_shortcodes.php b/e107_core/shortcodes/batch/signup_shortcodes.php index 3f871b958..82a929565 100755 --- a/e107_core/shortcodes/batch/signup_shortcodes.php +++ b/e107_core/shortcodes/batch/signup_shortcodes.php @@ -66,106 +66,86 @@ class signup_shortcodes extends e_shortcode function sc_signup_xup_login($parm) { $pref = e107::getPref('social_login_active'); - $tp = e107::getParser(); - + if (empty($pref)) return ''; + $size = empty($parm['size']) ? '3x' : $parm['size']; $class = empty($parm['class']) ? 'btn btn-primary' : $parm['class'] ; - - if(!empty($pref)) - { - $text = ""; - $manager = new SocialLoginConfigManager(e107::getConfig()); - $providers = $manager->getValidConfiguredProviderConfigs(); - - foreach($providers as $p=>$v) - { - if($v['enabled'] == 1) - { - - // $text .= ""; - - $ic = strtolower($p); - - switch ($ic) - { - case 'windowslive': - $ic = 'windows'; - break; - } - - // 'signup' Creates a new XUP user if not found, otherwise it logs the person in. - - if (defset('FONTAWESOME') && in_array($ic, e107::getMedia()->getGlyphs())) - $button = "" . $tp->toGlyph('fa-' . $ic, array('size' => $size, 'fw' => true)) . ""; - elseif (is_file(e107::getFolder('images') . "xup/{$ic}.png")) - $button = ""; - else - $button = "$p"; - - $text .= " ".$button." "; - } - //TODO different icon options. see: http://zocial.smcllns.com/ - } - - // $text .= "
"; - return $text; - } + return $this->generateXupLoginButtons("login", $size, $class); } // TODO - template function sc_signup_xup_signup($parm) { $pref = e107::getPref('social_login_active'); + if (empty($pref)) return ''; + + $size = empty($parm['size']) ? '2x' : $parm['size']; + $class = empty($parm['class']) ? 'btn btn-primary' : $parm['class'] ; + + if($size == '2x') + { + $class .= ' btn-lg'; + } + + return $this->generateXupLoginButtons("signup", $size, $class); + } + + /** + * @param string $type + * @param $size + * @param $class + * @return string + */ + private function generateXupLoginButtons($type, $size, $class) + { + $text = ""; $tp = e107::getParser(); - - - if(!empty($pref)) + $lan_plugin_social_xup = ''; + switch ($type) { - $text = ""; - $manager = new SocialLoginConfigManager(e107::getConfig()); - $providers = $manager->getValidConfiguredProviderConfigs(); + case "login": + $lan_plugin_social_xup = LAN_PLUGIN_SOCIAL_XUP_REG; + break; + case "signup": + $lan_plugin_social_xup = LAN_PLUGIN_SOCIAL_XUP_SIGNUP; + break; + } - $size = empty($parm['size']) ? '2x' : $parm['size']; - $class = empty($parm['class']) ? 'btn btn-primary' : $parm['class'] ; - - if($size == '2x') + + $manager = new SocialLoginConfigManager(e107::getConfig()); + $providers = $manager->getValidConfiguredProviderConfigs(); + + foreach ($providers as $p => $v) + { + if ($v['enabled'] == 1) { - $class .= ' btn-lg'; - } + $ic = strtolower($p); - - foreach($providers as $p=>$v) - { - if($v['enabled'] == 1) + switch ($ic) { - $ic = strtolower($p); + case 'windowslive': + $ic = 'windows'; + break; + } - switch ($ic) - { - case 'windowslive': - $ic = 'windows'; - break; - } + if (defset('FONTAWESOME') && in_array($ic, e107::getMedia()->getGlyphs())) + $button = "" . $tp->toGlyph('fa-' . $ic, array('size' => $size, 'fw' => true)) . ""; + elseif (is_file(e107::getFolder('images') . "xup/{$ic}.png")) + $button = ""; + else + $button = "$p"; - if (defset('FONTAWESOME') && in_array($ic, e107::getMedia()->getGlyphs())) - $button = "" . $tp->toGlyph('fa-' . $ic, array('size' => $size, 'fw' => true)) . ""; - elseif (is_file(e107::getFolder('images') . "xup/{$ic}.png")) - $button = ""; - else - $button = "$p"; - $text .= " " . $button . " "; + $callback_url = e107::getUserProvider($p)->generateCallbackUrl($type, e_REQUEST_URL); + $text .= " $button "; } - //TODO different icon options. see: http://zocial.smcllns.com/ - } - - // $text .= "
"; - return $text; - } + //TODO different icon options. see: http://zocial.smcllns.com/ + } + + return $text; } - - + function sc_signup_form_open() { return "
".e107::getForm()->token()."
"; diff --git a/e107_handlers/user_handler.php b/e107_handlers/user_handler.php index 1713b82d6..2578f8980 100644 --- a/e107_handlers/user_handler.php +++ b/e107_handlers/user_handler.php @@ -1157,7 +1157,7 @@ class e_user_provider public function setBackUrl($url, $action) { # system/xup/login by default - $this->_config['callback'] = $this->generateCallbackUrl($this->getProvider(), $action, $url); + $this->_config['callback'] = $this->generateCallbackUrl($action, $url); $this->respawnHybridauth(); } @@ -1519,12 +1519,12 @@ class e_user_provider * @param string $backUrl * @return string */ - private function generateCallbackUrl($provider, $xupAction = "login", $backUrl = null) + public function generateCallbackUrl($xupAction = "login", $backUrl = null) { return e107::getUrl()->create( "system/xup/$xupAction", array( - 'provider' => $provider, + 'provider' => $this->getProvider(), 'back' => $backUrl, ), array('full' => true, 'encode' => false)