2heoh (2heoh) wrote in changelog,
2heoh
2heoh
changelog

[livejournal] r19334: LJM-1839: Integration m.livejournal.com ...

Committer: slobin
LJM-1839: Integration m.livejournal.com into big version LiveJournal

U   branches/mobile/cgi-bin/Apache/LiveJournal.pm
U   branches/mobile/htdocs/talkpost_do.bml
Modified: branches/mobile/cgi-bin/Apache/LiveJournal.pm
===================================================================
--- branches/mobile/cgi-bin/Apache/LiveJournal.pm	2011-06-21 04:39:09 UTC (rev 19333)
+++ branches/mobile/cgi-bin/Apache/LiveJournal.pm	2011-06-21 08:05:59 UTC (rev 19334)
@@ -28,6 +28,7 @@
                       LJ::AccessLogSink::Database
                       LJ::AccessLogSink::DInsertd
                       LJ::AccessLogSink::DBIProfile
+                      LJ::Mob::Router
                       );
 
 # these aren't lazily loaded in the typical call-a-package-method way,
@@ -183,7 +184,29 @@
 
         LJ::work_report_start();
     }
+    # try to match controller
+    LJ::Mob::Router::match_controller($r);
 
+
+    if(my $controller = LJ::Request->notes('controller')) {
+        # clear cookie's cache
+        LJ::start_request();
+        my $url = $controller->check_access(LJ::Request->notes('branding_id'), LJ::get_remote_ip);
+        if(LJ::Request->notes('method') eq '__setdomsess') {
+            return redir(LJ::Session->setdomsess_handler())
+        } else {
+            my $session = LJ::Session->session_from_cookies(
+                tried_fast   => 0,
+                redirect_ref => \$LJ::CACHE_REMOTE_BOUNCE_URL,
+                ignore_ip    => 1
+            );
+
+            if( !$session && $LJ::CACHE_REMOTE_BOUNCE_URL ) {       
+                return redir($LJ::CACHE_REMOTE_BOUNCE_URL);
+            }
+        }
+    }      
+
     LJ::Request->set_handlers(PerlTransHandler => [ \&trans ]);
 
     return LJ::Request::OK;
@@ -314,6 +337,32 @@
 
     my $is_ssl = $LJ::IS_SSL = LJ::run_hook("ssl_check");
 
+    # process controller
+    # if defined
+    if( LJ::Request->notes('controller') ) {
+        my @args = split (/\//, LJ::Request->uri);
+        
+        my $responce = LJ::Request->notes('controller')->process([@args[1 .. @args-1]], LJ::Request::request->{r});
+        LJ::Request->handler("perl-script");
+        LJ::Request->set_handlers(PerlHandler => sub {
+            # processing result of controller
+            my $result = eval{$responce->output};
+
+            return LJ::Request::OK
+                if $responce->isa('LJ::Mob::Responce::Template');
+
+            if ($responce->isa('LJ::Mob::Responce::Redirect')) {
+                LJ::Request->send_cookies;
+                LJ::Request->redirect($responce->location);
+                LJ::Request->send_http_header();
+                return LJ::Request::REDIRECT;
+            }
+
+            #return $result; 
+        } );
+        return LJ::Request::OK;
+    }
+
     my $bml_handler = sub {
         my $filename = shift;
 
@@ -426,10 +475,23 @@
     # see if we should setup a minimal scheme based on the initial part of the
     # user-agent string; FIXME: maybe this should do more than just look at the
     # initial letters?
+
+#my %cookies = LJ::Request->cookies;
+#use Data::Dumper;
+#warn Dumper \%cookies;
+
     if (my $ua = LJ::Request->header_in('User-Agent')) {
-        if (($ua =~ /^([a-z]+)/i) && $LJ::MINIMAL_USERAGENT{$1}) {
+        if ( Apache::WURFL->is_mobile && $BML::COOKIE{fullversion} ne 'yes' 
+            #($ua =~ /^([a-z]+)/i) && $LJ::MINIMAL_USERAGENT{$1}
+           ) {
             LJ::Request->notes('use_minimal_scheme' => 1);
             LJ::Request->notes('bml_use_scheme' => $LJ::MINIMAL_BML_SCHEME);
+
+            my $mobile_url = LJ::Mob::Uri->find("http://".LJ::Request->hostname.LJ::Request->uri);
+
+            return redir("http://m.$LJ::DOMAIN$mobile_url")
+                if $mobile_url;
+#warn "URI: $mobile_url ($LJ::DOMAIN)";
         }
     }
 

Modified: branches/mobile/htdocs/talkpost_do.bml
===================================================================
--- branches/mobile/htdocs/talkpost_do.bml	2011-06-21 04:39:09 UTC (rev 19333)
+++ branches/mobile/htdocs/talkpost_do.bml	2011-06-21 08:05:59 UTC (rev 19334)
@@ -295,6 +295,15 @@
         $commentlink = LJ::Talk::talkargs($talkurl, "thread=$POST{viewing_thread}", $stylemine) . "#t$dtalkid";
     }
 
+    if( Apache::WURFL->is_mobile && $BML::COOKIE{fullversion} ne 'yes') {
+        my $mobile_link = LJ::Mob::Uri->find($commentlink);
+        $commentlink = "http://m.$LJ::DOMAIN$mobile_link"
+            if $mobile_link ;
+    }
+        
+
+warn "\$commentlink = $commentlink";
+
     my $ret = "";
     $ret .= "<h1>$ML{'.success.title'}</h1>";
 

Tags: 2heoh, bml, livejournal, 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