ssafronova (ssafronova) wrote in changelog,
ssafronova
ssafronova
changelog

[livejournal] r18823: LJSUP-8318: SEO: rel=nofollow for the li...

Committer: ssafronova
LJSUP-8318: SEO: rel=nofollow for the links in entries and comments
U   trunk/cgi-bin/LJ/Entry.pm
U   trunk/cgi-bin/LJ/S2/DayPage.pm
U   trunk/cgi-bin/LJ/S2/EntryPage.pm
U   trunk/cgi-bin/LJ/S2/FriendsPage.pm
U   trunk/cgi-bin/LJ/S2/RecentPage.pm
U   trunk/cgi-bin/LJ/Talk.pm
U   trunk/cgi-bin/cleanhtml.pl
U   trunk/cgi-bin/ljfeed.pl
U   trunk/cgi-bin/ljviews.pl
U   trunk/htdocs/community/moderate.bml
U   trunk/htdocs/edittags.bml
U   trunk/htdocs/preview/entry.bml
U   trunk/htdocs/talkpost.bml
U   trunk/htdocs/talkread.bml
U   trunk/htdocs/update.bml
Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/Entry.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -822,6 +822,7 @@
         $opts->{cuturl}     = $self->url;
     }
     $opts->{journalid} = $self->journalid;
+    $opts->{posterid} = $self->posterid;
     
     $self->_load_text unless $self->{_loaded_text};
     my $event = $self->{event};
@@ -841,7 +842,7 @@
 {
     my $self = shift;
     my $event = $self->event_raw;
-    LJ::CleanHTML::clean_event( \$event, { textonly => 1, journalid => $self->journalid, } ) if $event;
+    LJ::CleanHTML::clean_event( \$event, { textonly => 1, journalid => $self->journalid, posterid => $self->posterid } ) if $event;
     return $event;
 }
 

Modified: trunk/cgi-bin/LJ/S2/DayPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/DayPage.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/S2/DayPage.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -159,7 +159,9 @@
                                              'ljcut_disable' => $remote ? $remote->{'opt_ljcut_disable_lastn'} : undef,
                                              'suspend_msg' => $suspend_msg,
                                              'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0, 
-                                             'journalid' =>  $entry_obj->journalid, });
+                                             'journalid' => $entry_obj->journalid,
+                                             'posterid' => $entry_obj->posterid,
+                                            });
         LJ::expand_embedded($u, $ditemid, $remote, \$text);
 
         $text = LJ::ContentFlag->transform_post(post => $text, journal => $u,

Modified: trunk/cgi-bin/LJ/S2/EntryPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/EntryPage.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/S2/EntryPage.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -152,6 +152,7 @@
             LJ::CleanHTML::clean_comment(\$text, { 'preformatted' => $com->{'props'}->{'opt_preformatted'},
                                                    'anon_comment' => (!$pu || $pu->{'journaltype'} eq 'I'),
                                                    'nocss'        => 1,
+                                                   'posterid'     => $com->{'posterid'},
                                                    });
 
             # local time in mysql format to gmtime

Modified: trunk/cgi-bin/LJ/S2/FriendsPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/FriendsPage.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/S2/FriendsPage.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -249,7 +249,9 @@
                                              'ljcut_disable' => $remote ? $remote->{'opt_ljcut_disable_friends'} : undef,
                                              'suspend_msg' => $suspend_msg,
                                              'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
-                                             'journalid' =>  $entry_obj->journalid, });
+                                             'journalid' => $entry_obj->journalid,
+                                             'posterid' => $entry_obj->posterid,
+                                           });
         LJ::expand_embedded($friends{$friendid}, $ditemid, $remote, \$text);
 
         $text = LJ::ContentFlag->transform_post(post => $text, journal => $friends{$friendid},

Modified: trunk/cgi-bin/LJ/S2/RecentPage.pm
===================================================================
--- trunk/cgi-bin/LJ/S2/RecentPage.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/S2/RecentPage.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -188,7 +188,9 @@
                                               'ljcut_disable' => ($remote) ? $remote->prop("opt_ljcut_disable_lastn") : undef,
                                               'suspend_msg' => $suspend_msg,
                                               'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
-                                              'journalid' =>  $entry_obj->journalid, });
+                                              'journalid' => $entry_obj->journalid,
+                                              'posterid' => $entry_obj->posterid,
+                                           });
         LJ::expand_embedded($u, $ditemid, $remote, \$text);
 
         $text = LJ::ContentFlag->transform_post(post => $text, journal => $u,

Modified: trunk/cgi-bin/LJ/Talk.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk.pm	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/LJ/Talk.pm	2011-04-08 07:34:25 UTC (rev 18823)
@@ -2705,6 +2705,7 @@
                         preformatted => $post->{'props'}->{'opt_preformatted'},
                         anon_comment => (!$pu || $pu->{'journaltype'} eq 'I'),
                         nocss        => 1,
+                        posterid     => ($pu ? $pu->userid : 0),
                     }
                 );
 

Modified: trunk/cgi-bin/cleanhtml.pl
===================================================================
--- trunk/cgi-bin/cleanhtml.pl	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/cleanhtml.pl	2011-04-08 07:34:25 UTC (rev 18823)
@@ -156,6 +156,9 @@
     my $target = $opts->{'target'} || '';
     my $ljrepost_allowed = ($opts->{ljrepost_allowed} && ! $opts->{'textonly'}) || 0;
 
+    my $poster = LJ::load_userid($opts->{posterid});
+    my $put_nofollow = not ($poster and $poster->get_cap('paid'));
+
     my $viewer_lang = $opts->{'viewer_lang'};
     unless ($viewer_lang) {
         $viewer_lang = LJ::Lang::get_remote_lang();
@@ -981,11 +984,21 @@
 
                 if ($tag eq "a" && $extractlinks)
                 {
-                    push @canonical_urls, canonical_url($token->[2]->{href}, 1);
+                    push @canonical_urls, canonical_url($attr->{href}, 1);
                     $newdata .= "<b>";
                     next;
                 }
 
+                if ($tag eq "a" and $hash->{href} and $put_nofollow) {
+                    if ($hash->{href} =~ m!^https?://([^/]+?)(/.*)?$!) {
+                        my $host = $1;
+                        unless ($host =~ /\Q$LJ::DOMAIN\E$/i) {
+                            $hash->{rel} = "nofollow";
+                            push @$attrs, 'rel';
+                        }
+                    }
+                }
+
                 # Through the xsl namespace in XML, it is possible to embed scripting lanaguages
                 # as elements which will then be executed by the browser.  Combining this with
                 # customview.cgi makes it very easy for someone to replace their entire journal
@@ -1235,6 +1248,7 @@
         }
         elsif ($type eq "T") {
             my %url = ();
+            my %nofollow;
             my $urlcount = 0;
 
             if (@eatuntil) {
@@ -1261,13 +1275,21 @@
             if ($auto_format && ! $noautolinks && ! $opencount{'a'} && ! $opencount{'textarea'}) {
                 my $match = sub {
                     my $str = shift;
+                    my $end = '';
                     if ($str =~ /^(.*?)(&(#39|quot|lt|gt)(;.*)?)$/) {
                         $url{++$urlcount} = $1;
-                        return "&url$urlcount;$1&urlend;$2";
+                        $end = $2;
                     } else {
                         $url{++$urlcount} = $str;
-                        return "&url$urlcount;$str&urlend;";
                     }
+                    $nofollow{$urlcount} = 0;
+                    if ($put_nofollow and $url{$urlcount} =~ m!^https?://([^/]+?)(/.*)?$!) {
+                        my $host = $1;
+                        unless ($host =~ /\Q$LJ::DOMAIN\E$/i) {
+                            $nofollow{$urlcount} = 1;
+                        }
+                    }
+                    return "&url$urlcount;$url{$urlcount}&urlend;$end";
                 };
                 ## URL is http://anything-here-but-space-and-quotes/and-last-symbol-isn't-space-comma-period-etc
                 ## like this (http://example.com) and these: http://foo.bar, http://bar.baz.
@@ -1289,7 +1311,12 @@
             if ($auto_format && !$opencount{'textarea'}) {
                 $token->[1] =~ s/\r?\n/<br \/>/g;
                 if (! $opencount{'a'}) {
-                    $token->[1] =~ s|&url(\d+);(.*?)&urlend;|<a href="$url{$1}">$2</a>|g;
+                    my $tag_a = sub {
+                        my ($key, $title) = @_;
+                        my $nofollow = $nofollow{$key} ? " rel='nofollow'" : "";
+                        return "<a href='$url{$key}'$nofollow>$title</a>";
+                    };
+                    $token->[1] =~ s|&url(\d+);(.*?)&urlend;|$tag_a->($1,$2)|ge;
                 }
             }
 
@@ -1766,6 +1793,7 @@
         'nocss' => $opts->{'nocss'},
         'textonly' => $opts->{'textonly'} ? 1 : 0,
         'remove_positioning' => 1,
+        'posterid' => $opts->{'posterid'},
     });
 }
 

Modified: trunk/cgi-bin/ljfeed.pl
===================================================================
--- trunk/cgi-bin/ljfeed.pl	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/ljfeed.pl	2011-04-08 07:34:25 UTC (rev 18823)
@@ -235,6 +235,7 @@
                 {   'wordlength'    => 0, 
                     'preformatted'  => $logprops{$itemid}->{'opt_preformatted'},
                     'journalid'     => $u->userid,
+                    'posterid'      => $it->{'posterid'},
                 }
             );
 

Modified: trunk/cgi-bin/ljviews.pl
===================================================================
--- trunk/cgi-bin/ljviews.pl	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/cgi-bin/ljviews.pl	2011-04-08 07:34:25 UTC (rev 18823)
@@ -1337,7 +1337,9 @@
                                                'ljcut_disable' => ($remote) ? $remote->{'opt_ljcut_disable_lastn'} : undef,
                                                'suspend_msg' => $suspend_msg,
                                                'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
-                                               'journalid' =>  $entry_obj->journalid, });
+                                               'journalid' => $entry_obj->journalid,
+                                               'posterid' => $entry_obj->posterid,
+                                            });
         LJ::expand_embedded($u, $ditemid, $remote, \$event);
 
         $event = LJ::ContentFlag->transform_post(post => $event, journal => $u,
@@ -1860,7 +1862,9 @@
                                               'ljcut_disable' => ($remote) ? $remote->{'opt_ljcut_disable_friends'} : undef,
                                               'suspend_msg' => $suspend_msg,
                                               'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
-                                              'journalid' =>  $entry_obj->journalid, });
+                                              'journalid' => $entry_obj->journalid,
+                                              'posterid' => $entry_obj->posterid,
+                                            });
         LJ::expand_embedded($friends{$friendid}, $ditemid, $remote, \$event);
 
         $event = LJ::ContentFlag->transform_post(post => $event, journal => $friends{$friendid},
@@ -2585,7 +2589,9 @@
                                               'ljcut_disable' => ($remote) ? $remote->{'opt_ljcut_disable_lastn'} : undef,
                                               'suspend_msg' => $suspend_msg,
                                               'unsuspend_supportid' => $suspend_msg ? $entry_obj->prop("unsuspend_supportid") : 0,
-                                              'journalid' =>  $entry_obj->journalid, });
+                                              'journalid' => $entry_obj->journalid,
+                                              'posterid' => $entry_obj->posterid,
+                                            });
         LJ::expand_embedded($u, $ditemid, $remote, \$event);
 
         $event = LJ::ContentFlag->transform_post(post => $event, journal => $u,

Modified: trunk/htdocs/community/moderate.bml
===================================================================
--- trunk/htdocs/community/moderate.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/community/moderate.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -365,6 +365,8 @@
         LJ::CleanHTML::clean_event(\$event, {'preformatted' => $req->{'props'}->{'opt_preformatted'},
                                              'cutpreview' => 1,
                                              'cuturl' => '#',
+                                             'journalid' => $c->{'userid'},
+                                             'posterid' => $posterid,
                                          });
         
         # create iframe from <lj-embed> tag

Modified: trunk/htdocs/edittags.bml
===================================================================
--- trunk/htdocs/edittags.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/edittags.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -76,6 +76,8 @@
     my (%props, %opts);
     LJ::load_log_props2($u->{userid}, [$jitemid], \%props);
     $opts{'preformatted'} = $props{$jitemid}{'opt_preformatted'};
+    $opts{'journalid'} = $u->userid;
+    $opts{'posterid'} = $logrow->{posterid};
 
     LJ::CleanHTML::clean_subject(\$subj);
     LJ::CleanHTML::clean_event(\$evt, \%opts);

Modified: trunk/htdocs/preview/entry.bml
===================================================================
--- trunk/htdocs/preview/entry.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/preview/entry.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -46,6 +46,7 @@
     LJ::CleanHTML::clean_event(\$event, {
         preformatted => $req{'prop_opt_preformatted'},
         journalid    => $u->userid,
+        posterid     => $up->userid,
     });
     # expand the embedded content for reals
     LJ::EmbedModule->expand_entry($u, \$event, preview => 1,);

Modified: trunk/htdocs/talkpost.bml
===================================================================
--- trunk/htdocs/talkpost.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/talkpost.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -209,6 +209,7 @@
                                           'cuturl' => $talkurl,
                                           'expand_cut' => 1,
                                           'journalid' =>  $entry->journalid,
+                                          'posterid' => $entry->posterid,
                                           });
     LJ::expand_embedded($u, $ditemid, $remote, \$event);
     BML::ebml(\$event);

Modified: trunk/htdocs/talkread.bml
===================================================================
--- trunk/htdocs/talkread.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/talkread.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -272,6 +272,7 @@
             cuturl              => $talkurl, 
             expand_cut          => !$no_cut_expand,
             journalid           => $entry->journalid,
+            posterid            => $entry->posterid,
         }
     );
     LJ::expand_embedded($u, $ditemid, $remote, \$event);

Modified: trunk/htdocs/update.bml
===================================================================
--- trunk/htdocs/update.bml	2011-04-08 06:29:22 UTC (rev 18822)
+++ trunk/htdocs/update.bml	2011-04-08 07:34:25 UTC (rev 18823)
@@ -167,7 +167,7 @@
             $subject ||= (LJ::ehtml($entry->subject_orig) || LJ::Lang::ml("repost.default_subject"));
             unless ($event){
                 $event = $entry->event_raw;
-                LJ::CleanHTML::clean_event(\$event, { cuturl => $entry->url, journalid => $entry->journalid });
+                LJ::CleanHTML::clean_event(\$event, { cuturl => $entry->url, journalid => $entry->journalid, posterid => $entry->posterid });
                 $event = LJ::Lang::ml("repost.wrapper", { 
                                             username => $entry->poster->username,
                                             url      => $entry->url,

Tags: bml, livejournal, pl, pm, ssafronova
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