wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r15046: LJSUP-3912. lj user: "title" parameter i...

Committer: wisest-owl
LJSUP-3912. lj user: "title" parameter is not processed / displayed correctly

U   trunk/cgi-bin/cleanhtml.pl
U   trunk/cgi-bin/ljlib.pl
Modified: trunk/cgi-bin/cleanhtml.pl
===================================================================
--- trunk/cgi-bin/cleanhtml.pl	2009-03-26 11:42:54 UTC (rev 15045)
+++ trunk/cgi-bin/cleanhtml.pl	2009-03-26 12:35:01 UTC (rev 15046)
@@ -412,11 +412,18 @@
             # this is so the rte converts its source to the standard ljuser html
             my $ljuser_div = $tag eq "div" && $attr->{class} eq "ljuser";
             if ($ljuser_div) {
+                
+                my $href = $p->get_tag("a");
+                my $href_attr = $href->[1]->{"href"};
+                my $username = LJ::get_user_by_url ( $href_attr );
+                $attr->{'user'} = $username ? $username : '';
+                
                 my $ljuser_text = $p->get_text("/b");
                 $p->get_tag("/div");
                 $ljuser_text =~ s/\[info\]//;
                 $tag = "lj";
-                $attr->{'user'} = $ljuser_text;
+                $attr->{'title'} = $ljuser_text;
+                                                                    
             }
             # stupid hack to remove the class='ljcut' from divs when we're
             # disabling them, so we account for the open div normally later.

Modified: trunk/cgi-bin/ljlib.pl
===================================================================
--- trunk/cgi-bin/ljlib.pl	2009-03-26 11:42:54 UTC (rev 15045)
+++ trunk/cgi-bin/ljlib.pl	2009-03-26 12:35:01 UTC (rev 15046)
@@ -213,6 +213,58 @@
     $SIG{'HUP'} = \&LJ::clear_caches;
 }
 
+sub get_user_by_url
+{
+    my $url = shift;
+    
+    my $username = '';
+   
+    # drop protocol
+    $url =~ s/http(?:s)?:\/\///;
+   
+    #try to get username from domain name
+    if ($url =~ /^([\w\-]{1,15})\.\Q$LJ::USER_DOMAIN\E/ &&
+        $1 ne "www"
+    ) 
+    {
+        my $user = $1;
+        
+        # see if the "user" is really functional code
+        my $func = $LJ::SUBDOMAIN_FUNCTION{$user};
+        my $uri = '';
+        if ($func eq "journal") {
+            ($user, $uri) = $url =~ m!^[\w\-]{1,15}\.\Q$LJ::USER_DOMAIN\E/(\w{1,15})(/.*)?$!;
+            $uri ||= "/";
+            
+        }
+       
+        my $u = LJ::load_user($user);
+        if ($u && $u->{'journaltype'} eq 'R' && $u->{'statusvis'} eq 'R') {
+            LJ::load_user_props($u, 'renamedto');
+            my $renamedto = $u->{'renamedto'};
+            if ($renamedto ne '') {
+                $username = $renamedto;
+            }
+        } elsif ($u) {
+            $username = $u->user;
+        }
+    }
+    
+    # try to find userid in user domains
+    unless ($username) {
+        my $dbr = LJ::get_db_reader();
+        my ($checkhost) = $url =~ /^([\w\-.]+\.\Q$LJ::USER_DOMAIN\E)/;
+        $checkhost = lc($checkhost);
+        $checkhost =~ s/^www\.//i;
+        $checkhost = $dbr->quote($checkhost);
+        my $user = $dbr->selectrow_array(qq{
+            SELECT u.user FROM useridmap u, domains d WHERE
+            u.userid=d.userid AND d.domain=$checkhost
+        });
+        $username = $user if $user;
+    }
+    return $username;
+}
 
 sub get_blob_domainid
 {

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