Ejemplo n.º 1
0
/**
 * Return the current url
 */
function oa_social_login_get_current_url()
{
    //Extract parts
    $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : $_SERVER['PHP_SELF'];
    $request_protocol = oa_social_login_https_on() ? 'https' : 'http';
    $request_host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']);
    //Port of this request
    $request_port = '';
    //We are using a proxy
    if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
        // SERVER_PORT is usually wrong on proxies, don't use it!
        $request_port = intval($_SERVER['HTTP_X_FORWARDED_PORT']);
    } elseif (isset($_SERVER['SERVER_PORT'])) {
        $request_port = intval($_SERVER['SERVER_PORT']);
    }
    // Remove standard ports
    $request_port = !in_array($request_port, array(80, 443)) ? $request_port : '';
    //Add your own filters
    $request_port = apply_filters('oa_social_login_filter_current_url_port', $request_port);
    $request_protocol = apply_filters('oa_social_login_filter_current_url_protocol', $request_protocol);
    $request_host = apply_filters('oa_social_login_filter_current_url_host', $request_host);
    $request_uri = apply_filters('oa_social_login_filter_current_url_uri', $request_uri);
    //Build url
    $current_url = $request_protocol . '://' . $request_host . (!empty($request_port) ? ':' . $request_port : '') . $request_uri;
    //Remove the oa_social_login_source argument
    if (strpos($current_url, 'oa_social_login_source') !== false) {
        //Break up url
        list($url_part, $query_part) = array_pad(explode('?', $current_url), 2, '');
        parse_str($query_part, $query_vars);
        //Remove oa_social_login_source argument
        if (is_array($query_vars) and isset($query_vars['oa_social_login_source'])) {
            unset($query_vars['oa_social_login_source']);
        }
        //Build new url
        $current_url = $url_part . ((is_array($query_vars) and count($query_vars) > 0) ? '?' . http_build_query($query_vars) : '');
    }
    //Apply filters
    $current_url = apply_filters('oa_social_login_filter_current_url', $current_url);
    //Done
    return $current_url;
}
/**
 * Return the current url
 */
function oa_social_login_get_current_url()
{
    //Get request URI - Should work on Apache + IIS
    $request_uri = !isset($_SERVER['REQUEST_URI']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
    $request_port = (!empty($_SERVER['SERVER_PORT']) and $_SERVER['SERVER_PORT'] != '80') ? ":" . $_SERVER['SERVER_PORT'] : '';
    $request_protocol = (oa_social_login_https_on() ? 'https' : 'http') . "://";
    $redirect_to = $request_protocol . $_SERVER['SERVER_NAME'] . $request_port . $request_uri;
    //Remove the oa_social_login_source argument
    if (strpos($redirect_to, 'oa_social_login_source') !== false) {
        //Break up url
        list($url_part, $query_part) = array_pad(explode('?', $redirect_to), 2, '');
        parse_str($query_part, $query_vars);
        //Remove oa_social_login_source argument
        if (is_array($query_vars) and isset($query_vars['oa_social_login_source'])) {
            unset($query_vars['oa_social_login_source']);
        }
        //Build new url
        $redirect_to = $url_part . ((is_array($query_vars) and count($query_vars) > 0) ? '?' . http_build_query($query_vars) : '');
    }
    return $redirect_to;
}
Ejemplo n.º 3
0
/**
 * Display the provider grid
 */
function oa_social_login_render_login_form($source, $args = array())
{
    //Import providers
    global $oa_social_login_providers;
    //Container for returned value
    $output = '';
    //Read settings
    $settings = get_option('oa_social_login_settings');
    //API Subdomain
    $api_subdomain = !empty($settings['api_subdomain']) ? $settings['api_subdomain'] : '';
    //API Subdomain Required
    if (!empty($api_subdomain)) {
        //Build providers
        $providers = array();
        if (is_array($settings['providers'])) {
            foreach ($settings['providers'] as $settings_provider_key => $settings_provider_name) {
                if (isset($oa_social_login_providers[$settings_provider_key])) {
                    $providers[] = $settings_provider_key;
                }
            }
        }
        //Themes are served from the CDN
        $theme_uri_prefix = oa_social_login_https_on() ? 'https://secure.oneallcdn.com' : 'http://public.oneallcdn.com';
        //Themes
        $css_theme_uri_small = $theme_uri_prefix . '/css/api/socialize/themes/wordpress/small.css';
        $css_theme_uri_default = $theme_uri_prefix . '/css/api/socialize/themes/wordpress/default.css';
        //Widget
        if ($source == 'widget') {
            //Read widget settings
            $widget_settings = is_array($args) ? $args : array();
            //Don't show the title - this is handled insided the widget
            $plugin_caption = '';
            //Buttons size
            $css_theme_uri = (array_key_exists('widget_use_small_buttons', $widget_settings) and !empty($widget_settings['widget_use_small_buttons'])) ? $css_theme_uri_small : $css_theme_uri_default;
            //Custom CSS
            $css_theme_uri = apply_filters('oa_social_login_widget_css', $css_theme_uri);
        } else {
            //Show title if set
            $plugin_caption = !empty($settings['plugin_caption']) ? $settings['plugin_caption'] : '';
            //Buttons size
            $css_theme_uri = !empty($settings['plugin_use_small_buttons']) ? $css_theme_uri_small : $css_theme_uri_default;
            //Custom CSS
            $css_theme_uri = apply_filters('oa_social_login_default_css', $css_theme_uri);
        }
        //No providers selected
        if (count($providers) == 0) {
            $output = '<div style="color:white;background-color:red;">[Social Login] ' . __('Please enable at least one social network!', 'oa_social_login') . '</div>';
        } else {
            //Random integer
            $rand = mt_rand(99999, 9999999);
            //Setup output
            $output = array();
            $output[] = '<div class="oneall_social_login">';
            //Add the caption?
            if (!empty($plugin_caption)) {
                $output[] = ' <div class="oneall_social_login_label" style="margin-bottom: 3px;"><label>' . __($plugin_caption) . '</label></div>';
            }
            //Add the Plugin
            $output[] = ' <div class="oneall_social_login_providers" id="oneall_social_login_providers_' . $rand . '"></div>';
            $output[] = ' <script type="text/javascript">';
            $output[] = '  oneall.api.plugins.social_login.build("oneall_social_login_providers_' . $rand . '", {';
            $output[] = '   "providers": ["' . implode('","', $providers) . '"], ';
            //$output [] = '   "same_window": true, ';
            $output[] = '   "callback_uri": (window.location.href + ((window.location.href.split(\'?\')[1] ? \'&amp;\':\'?\') + "oa_social_login_source=' . $source . '")), ';
            $output[] = '   "css_theme_uri": "' . $css_theme_uri . '" ';
            $output[] = '  });';
            $output[] = ' </script>';
            $output[] = ' <!-- OneAll.com / Social Login for WordPress / v' . constant('OA_SOCIAL_LOGIN_VERSION') . ' -->';
            $output[] = '</div>';
            //Done
            $output = implode("\n", $output);
        }
        //Return a string and let the calling function do the actual outputting
        return $output;
    }
}
Ejemplo n.º 4
0
/**
 * Display the provider grid
 */
function oa_social_login_render_login_form($source, $args = array())
{
    //Import providers
    global $oa_social_login_providers;
    //Parse args
    $args = is_array($args) ? $args : array();
    //Container for returned value
    $output = '';
    //Read settings
    $settings = get_option('oa_social_login_settings');
    //API Subdomain
    $api_subdomain = !empty($settings['api_subdomain']) ? $settings['api_subdomain'] : '';
    //API Subdomain Required
    if (!empty($api_subdomain)) {
        //Build providers
        $providers = array();
        if (is_array($settings['providers'])) {
            foreach ($settings['providers'] as $settings_provider_key => $settings_provider_name) {
                if (isset($oa_social_login_providers[$settings_provider_key])) {
                    $providers[] = $settings_provider_key;
                }
            }
        }
        //Themes are served from the CDN
        $theme_uri_prefix = oa_social_login_https_on() ? 'https://secure.oneallcdn.com' : 'http://public.oneallcdn.com';
        //Themes
        $css_theme_uri_small = $theme_uri_prefix . '/css/api/socialize/themes/wordpress/small.css';
        $css_theme_uri_default = $theme_uri_prefix . '/css/api/socialize/themes/wordpress/default.css';
        //Widget
        if ($source == 'widget') {
            //Read widget settings
            $widget_settings = is_array($args) ? $args : array();
            //Don't show the title - this is handled insided the widget
            $plugin_caption = '';
            //Buttons size
            $css_theme_uri = (array_key_exists('widget_use_small_buttons', $widget_settings) and !empty($widget_settings['widget_use_small_buttons'])) ? $css_theme_uri_small : $css_theme_uri_default;
            //Custom CSS
            $css_theme_uri = apply_filters('oa_social_login_widget_css', $css_theme_uri);
        } else {
            //Show title if set
            $plugin_caption = !empty($settings['plugin_caption']) ? $settings['plugin_caption'] : '';
            //Buttons size
            $css_theme_uri = !empty($settings['plugin_use_small_buttons']) ? $css_theme_uri_small : $css_theme_uri_default;
            //Custom CSS
            $css_theme_uri = apply_filters('oa_social_login_default_css', $css_theme_uri);
        }
        //Build Callback URI
        if (array_key_exists('callback_uri', $args) and !empty($args['callback_uri'])) {
            $callback_uri = "'" . $args['callback_uri'] . "'";
        } else {
            $callback_uri = "(window.location.href + ((window.location.href.split('?')[1] ? '&amp;': '?') + \"oa_social_login_source=" . $source . "\"))";
        }
        //No providers selected
        if (count($providers) == 0) {
            $output = '<div style="color:white;background-color:red;">[Social Login] ' . __('Please enable at least one social network!', 'oa_social_login') . '</div>';
        } else {
            //Setup output
            $output = array();
            $output[] = " <!-- OneAll.com / Social Login for WordPress / v" . constant('OA_SOCIAL_LOGIN_VERSION') . " -->";
            $output[] = '<div class="oneall_social_login">';
            //Add the caption?
            if (!empty($plugin_caption)) {
                $output[] = ' <div class="oneall_social_login_label" style="margin-bottom: 3px;"><label>' . __($plugin_caption) . '</label></div>';
            }
            //Add the Plugin
            $containerid = 'oneall_social_login_providers_' . mt_rand(99999, 9999999);
            $output[] = ' <div class="oneall_social_login_providers" id="' . $containerid . '"></div>';
            $output[] = ' <script type="text/javascript">';
            //Synchronous JavaScript: This is the default to stay compatible with existing installations.
            if (empty($settings['asynchronous_javascript'])) {
                $output[] = "  oneall.api.plugins.social_login.build('" . $containerid . "', {";
                $output[] = "   'providers': ['" . implode("','", $providers) . "'], ";
                $output[] = "   'callback_uri': " . $callback_uri . ", ";
                $output[] = "   'css_theme_uri': '" . $css_theme_uri . "' ";
                $output[] = "  });";
            } else {
                //JavaScript Method Reference: http://docs.oneall.com/api/javascript/library/methods/
                $output[] = "  var _oneall = _oneall || [];";
                $output[] = "  _oneall.push(['social_login', 'set_providers', ['" . implode("','", $providers) . "']]);";
                $output[] = "  _oneall.push(['social_login', 'set_callback_uri', " . $callback_uri . "]);";
                $output[] = "  _oneall.push(['social_login', 'set_custom_css_uri', '" . $css_theme_uri . "']);";
                $output[] = "  _oneall.push(['social_login', 'do_render_ui', '" . $containerid . "']);";
            }
            $output[] = " </script>";
            $output[] = '</div>';
            //Done
            $output = implode("\n", $output);
        }
        //Return a string and let the calling function do the actual outputting
        return $output;
    }
}