Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9318: LJSUP-6137 (FaceBook authorization. Serv...

Committer: ailyin
LJSUP-6137 (FaceBook authorization. Server side)
U   branches/facebook-integration2/cgi-bin/LJ/Identity/Facebook.pm
Modified: branches/facebook-integration2/cgi-bin/LJ/Identity/Facebook.pm
===================================================================
--- branches/facebook-integration2/cgi-bin/LJ/Identity/Facebook.pm	2010-08-09 02:16:54 UTC (rev 9317)
+++ branches/facebook-integration2/cgi-bin/LJ/Identity/Facebook.pm	2010-08-09 03:41:05 UTC (rev 9318)
@@ -31,6 +31,34 @@
     return LJ::Request->redirect($addr);
 }
 
+sub parse_city {
+    my ($self, $city) = @_;
+
+    my $ret = {
+        'city' => $city,
+        'state' => '',
+        'country' => '',
+    };
+
+    my @city_split = split /,\s+/, $city;
+
+    return $ret if scalar(@city_split) == 1;
+
+    my $last_part = pop @city_split;
+    my $head      = join(', ', @city_split);
+
+    if (my $country = $LJ::FACEBOOK_COUNTRIES_MAP->{$last_part}) {
+        $ret->{'city'} = $head;
+        $ret->{'country'} = $country;
+    } elsif (my $state = $LJ::FACEBOOK_US_STATES_MAP->{$last_part}) {
+        $ret->{'city'} = $head;
+        $ret->{'state'} = $state;
+        $ret->{'country'} = 'US';
+    }
+
+    return $ret;
+}
+
 sub initialize_user {
     my ($self, $u, $extra) = @_;
 
@@ -67,8 +95,14 @@
 
     # hometown
     my $city = $userdata->{'hometown'} ? $userdata->{'hometown'}{'name'} : '';
-    $u->set_prop('city'   => $city) if $city;
+    if ($city) {
+        my $city_parsed = $self->parse_city($city);
 
+        $u->set_prop( 'city'    => $city_parsed->{'city'} );
+        $u->set_prop( 'state'   => $city_parsed->{'state'} );
+        $u->set_prop( 'country' => $city_parsed->{'country'} );
+    }
+
     # birthday
     if (my $birthday = $userdata->{'birthday'}) {
         my ($month, $day, $year) = ($birthday =~ /(\d+)\/(\d+)\/(\d+)/);

Tags: andy, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments