Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rodrigoprimo/social-connect
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoprimo committed Aug 4, 2014
2 parents 5086666 + 6be370c commit 044de0c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions social-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
License: GPL2
*/

/**
/**
* Check technical requirements are fulfilled before activating.
**/
function sc_activate(){
Expand Down Expand Up @@ -63,7 +63,7 @@ function sc_parse_request($wp) {
if (!session_id()) {
session_start();
}

switch ($wp->query_vars['social-connect']) {
case 'twitter':
require_once 'twitter/connect.php';
Expand All @@ -86,7 +86,7 @@ function sc_parse_request($wp) {
default:
break;
}

wp_die();
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ function sc_social_connect_process_login( $is_ajax = false ) {
$sc_provider_identity = $_REQUEST[ 'social_connect_twitter_identity' ];
social_connect_verify_signature( $sc_provider_identity, $sc_provided_signature, $redirect_to );
$sc_name = $_REQUEST[ 'social_connect_name' ];
$names = explode(" ", $sc_name );
$names = explode( ' ', $sc_name, 2 );
$sc_first_name = $names[0];
$sc_last_name = $names[1];
$sc_screen_name = $_REQUEST[ 'social_connect_screen_name' ];
Expand Down Expand Up @@ -157,12 +157,12 @@ function sc_social_connect_process_login( $is_ajax = false ) {
$sc_first_name = $sc_name;
$sc_last_name = '';
} else {
$names = explode(" ", $sc_username );
$names = explode( ' ', $sc_username, 2 );
$sc_first_name = $names[0];
$sc_last_name = $names[1];
}
} else {
$names = explode(" ", $sc_name );
$names = explode( ' ', $sc_name, 2 );
$sc_first_name = $names[0];
$sc_last_name = $names[1];
}
Expand All @@ -180,7 +180,7 @@ function sc_social_connect_process_login( $is_ajax = false ) {
$sc_first_name = $sc_name;
$sc_last_name = '';
} else {
$names = explode(" ", $sc_name );
$names = explode( ' ', $sc_name, 2 );
$sc_first_name = $names[0];
$sc_last_name = $names[1];
}
Expand All @@ -207,18 +207,18 @@ function sc_social_connect_process_login( $is_ajax = false ) {
} else { // Create new user and associate provider identity
if ( get_option( 'users_can_register' ) ) {
$user_login = sc_get_unique_username($user_login);

$userdata = array( 'user_login' => $user_login, 'user_email' => $sc_email, 'first_name' => $sc_first_name, 'last_name' => $sc_last_name, 'user_url' => $sc_profile_url, 'user_pass' => wp_generate_password() );

// Create a new user
$user_id = wp_insert_user( $userdata );

if ( $user_id && is_integer( $user_id ) ) {
update_user_meta( $user_id, $sc_provider_identity_key, $sc_provider_identity );
}
} else {
add_filter( 'wp_login_errors', 'sc_login_errors' );

return;
}
}
Expand All @@ -232,14 +232,14 @@ function sc_social_connect_process_login( $is_ajax = false ) {
} else {
wp_safe_redirect( $redirect_to );
}

exit();
}

/**
* Add error message when user try to login
* with an nonexistent e-mail and registration is disabled
*
*
* @param WP_Error $errors
* @return WP_Error
*/
Expand All @@ -256,7 +256,7 @@ function sc_get_unique_username($user_login, $c = 1) {
$append = '_'.substr(md5($user_login),0,3) . $c;
else
$append = $c;

$user_login = apply_filters( 'social_connect_username_exists', $user_login . $append );
return sc_get_unique_username($user_login,++$c);
} else {
Expand Down Expand Up @@ -286,17 +286,17 @@ function sc_filter_avatar($avatar, $id_or_email, $size, $default, $alt) {
$social_id = '';
$provider_id = '';
$user_id = (!is_integer($id_or_email) && !is_string($id_or_email) && get_class($id_or_email)) ? $id_or_email->user_id : $id_or_email;

if (!empty($user_id)) {
// Providers to search for (assume user prefers their current logged in service)
// Note: OpenID providers use gravatars
$providers = array('facebook', 'twitter');

$social_connect_provider = isset( $_COOKIE['social_connect_current_provider']) ? $_COOKIE['social_connect_current_provider'] : '';
if (!empty($social_connect_provider) && $social_connect_provider == 'twitter') {
$providers = array('twitter', 'facebook');
}

foreach($providers as $search_provider) {
$social_id = get_user_meta($user_id, 'social_connect_'.$search_provider.'_id', true);
if (!empty($social_id)) {
Expand All @@ -305,7 +305,7 @@ function sc_filter_avatar($avatar, $id_or_email, $size, $default, $alt) {
}
}
}

// At least one social ID was found
if (!empty($social_id)) {
switch($provider_id) {
Expand All @@ -316,32 +316,32 @@ function sc_filter_avatar($avatar, $id_or_email, $size, $default, $alt) {
// large (about 200 pixels wide, variable height)

$size_label = 'large';

if($size <= 100)
$size_label = 'normal';
else if($size <= 50)
$size_label = 'small';

$custom_avatar = "http://graph.facebook.com/$social_id/picture?type=$size_label";
break;
case 'twitter':
// bigger - 73px by 73px
// normal - 48px by 48px
// mini - 24px by 24px

$size_label = 'bigger';

if ($size <= 48) {
$size_label = 'normal';
} else if ($size <= 24) {
$size_label = 'mini';
}

$custom_avatar = "http://api.twitter.com/1/users/profile_image?id=$social_id&size=$size_label";
break;
}
}

if (!empty($custom_avatar)) {
// return the custom avatar from the social network
$return = '<img class="avatar" src="'.$custom_avatar.'" style="width:'.$size.'px" alt="'.$alt.'" />';
Expand All @@ -359,7 +359,7 @@ function sc_filter_avatar($avatar, $id_or_email, $size, $default, $alt) {

/**
* Add link to Social Connect settings page in the plugins page
*
*
* @return array plugin links
*/
function sc_add_settings_link( $default_links ) {
Expand Down

0 comments on commit 044de0c

Please sign in to comment.