Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix up getRelated/otherLinks stuff for html_update

  • Loading branch information...
commit b832d674ca8a7c778af25e67d6f58a5fa31d5efa 1 parent 2af9cff
@pudge pudge authored
View
129 plugins/Admin/Admin.pm
@@ -8,6 +8,7 @@ package Slash::Admin;
use strict;
use DBIx::Password;
use Slash;
+use Slash::Display;
use Slash::Utility;
use vars qw($VERSION);
@@ -118,6 +119,134 @@ sub getAccesslogAbusersByID {
}
+##################################################################
+# Generates the 'Related Links' for Stories
+sub getRelated {
+ my($self, $story_content, $tid) = @_;
+
+ my $slashdb = getCurrentDB();
+ my $user = getCurrentUser();
+
+ my $rl = $slashdb->getRelatedLinks;
+ my @related_text = ( );
+ my @rl_keys = sort keys %$rl;
+
+ my @tids = ( $tid );
+ if (ref($tid) && ref($tid) eq 'ARRAY') {
+ @tids = @$tid;
+ }
+ my $tid_regex = "^_topic_id_"
+ . "(?:"
+ . join("|", map { "\Q$_" } @tids)
+ . ")"
+ . "(?!\\d)";
+
+ if ($rl) {
+ my @matchkeys =
+ sort grep {
+ $rl->{$_}{keyword} =~ $tid_regex
+ ||
+ $rl->{$_}{keyword} !~ /^_topic_id_/
+ && $story_content =~ /\b$rl->{$_}{keyword}\b/i
+ } @rl_keys;
+ for my $key (@matchkeys) {
+ # Instead of hard-coding the HTML here, we should
+ # do something a little more flexible.
+ my $str = qq[<li><a href="$rl->{$key}{link}">$rl->{$key}{name}</a></li>\n];
+ push @related_text, $str;
+ }
+ }
+
+ # And slurp in all of the anchor links (<A>) from the story just for
+ # good measure. If TITLE attribute is present, use that for the link
+ # label; otherwise just use the A content.
+ while ($story_content =~ m|<a\s+(.*?)>(.*?)</a>|sgi) {
+ my($a_attr, $label) = ($1, $2);
+ next unless $a_attr =~ /\bhref\s*=\s*["']/si;
+ if ($a_attr =~ m/(\btitle\s*=\s*(["'])(.*?)\2)/si) {
+ $label = $3;
+ $a_attr =~ s/\Q$1\E//;
+ }
+
+ $a_attr =~ /\bhref\s*=\s*(["'])(.*?)\1/;
+ my $a_href = $2;
+ # If we want to exclude certain types of links from appearing
+ # in Related Links, we can make that decision based on the
+ # link target here.
+
+ $a_href =~ /(\w\.\w?)$/;
+ my $a_href_domain = $1;
+
+ $label = strip_notags($label);
+ $label =~ s/(\S{30})/$1 /g;
+ # Instead of hard-coding the HTML here, we should
+ # do something a little more flexible.
+ my $str;
+ if (submitDomainAllowed($a_href_domain)) {
+ $str = qq[<li><a $a_attr>$label</a></li>\n];
+ } else {
+ $str = qq[<li><blink><b><a style="color: #FF0000;" $a_attr>$label</a></b></blink></li>\n];
+ }
+ push @related_text, $str unless $label eq "?" || $label eq "[?]";
+ }
+
+ for (@{$user->{state}{related_links}}) {
+ push @related_text, sprintf(
+ # Instead of hard-coding the HTML here, we should
+ # do something a little more flexible.
+ qq[<li><a href="%s">%s</a></li>\n],
+ strip_attribute($_->[1]), $_->[0]
+ );
+ }
+
+ # Check to make sure we don't include the same link twice.
+ my %related_text = ( );
+ my $return_str = "";
+ for my $rt (@related_text) {
+ next if $related_text{$rt};
+ $return_str .= $rt;
+ $related_text{$rt} = 1;
+ }
+ return $return_str;
+}
+
+##################################################################
+sub otherLinks {
+ my($self, $aid, $tid, $uid) = @_;
+
+ my $reader = getObject('Slash::DB', { db_type => 'reader' });
+
+ my $topics = $reader->getTopics;
+ my @tids = ( $tid );
+ if (ref($tid) && ref($tid) eq 'ARRAY') {
+ @tids = @$tid;
+ }
+
+ return slashDisplay('otherLinks', {
+ uid => $uid,
+ aid => $aid,
+ tids => \@tids,
+ topics => $topics,
+ }, { Return => 1, Nocomm => 1 });
+}
+
+##################################################################
+sub relatedLinks {
+ my($self, $story_content, $tids, $nick, $uid) = @_;
+ my $relatedtext = $self->getRelated($story_content, $tids) .
+ $self->otherLinks($nick, $tids, $uid);
+
+ # If getRelated and otherLinks seem to be putting <li>
+ # tags around each item, they probably want a <ul></ul>
+ # surrounding the whole list. This is a bit hacky but
+ # should help make strictly parsed versions of HTML
+ # work better.
+ $relatedtext = "<ul>\n$relatedtext\n</ul>"
+ if $relatedtext && $relatedtext =~ /^\s*<li>/;
+
+ return $relatedtext;
+}
+
sub DESTROY {
my($self) = @_;
$self->{_dbh}->disconnect if !$ENV{GATEWAY_INTERFACE} && $self->{_dbh};
View
157 plugins/Admin/admin.pl
@@ -1093,117 +1093,6 @@ sub importText {
}
##################################################################
-# Generates the 'Related Links' for Stories
-sub getRelated {
- my($story_content, $tid) = @_;
-
- my $slashdb = getCurrentDB();
- my $user = getCurrentUser;
-
- my $rl = $slashdb->getRelatedLinks;
- my @related_text = ( );
- my @rl_keys = sort keys %$rl;
-
- my @tids = ( $tid );
- if (ref($tid) && ref($tid) eq 'ARRAY') {
- @tids = @$tid;
- }
- my $tid_regex = "^_topic_id_"
- . "(?:"
- . join("|", map { "\Q$_" } @tids)
- . ")"
- . "(?!\\d)";
-
- if ($rl) {
- my @matchkeys =
- sort grep {
- $rl->{$_}{keyword} =~ $tid_regex
- ||
- $rl->{$_}{keyword} !~ /^_topic_id_/
- && $story_content =~ /\b$rl->{$_}{keyword}\b/i
- } @rl_keys;
- for my $key (@matchkeys) {
- # Instead of hard-coding the HTML here, we should
- # do something a little more flexible.
- my $str = qq[&middot; <a href="$rl->{$key}{link}">$rl->{$key}{name}</a><br>\n];
- push @related_text, $str;
- }
- }
-
- # And slurp in all of the anchor links (<A>) from the story just for
- # good measure. If TITLE attribute is present, use that for the link
- # label; otherwise just use the A content.
- while ($story_content =~ m|<a\s+(.*?)>(.*?)</a>|sgi) {
- my($a_attr, $label) = ($1, $2);
- next unless $a_attr =~ /\bhref\s*=\s*["']/si;
- if ($a_attr =~ m/(\btitle\s*=\s*(["'])(.*?)\2)/si) {
- $label = $3;
- $a_attr =~ s/\Q$1\E//;
- }
-
- $a_attr =~ /\bhref\s*=\s*(["'])(.*?)\1/;
- my $a_href = $2;
- # If we want to exclude certain types of links from appearing
- # in Related Links, we can make that decision based on the
- # link target here.
-
- $a_href =~ /(\w\.\w?)$/;
- my $a_href_domain = $1;
-
- $label = strip_notags($label);
- $label =~ s/(\S{30})/$1 /g;
- # Instead of hard-coding the HTML here, we should
- # do something a little more flexible.
- my $str;
- if (submitDomainAllowed($a_href_domain)) {
- $str = qq[&middot; <a $a_attr>$label</a><br>\n];
- } else {
- $str = qq[&middot; <blink><b><a style="color: #FF0000;" $a_attr>$label</a></b></blink><br>\n];
- }
- push @related_text, $str unless $label eq "?" || $label eq "[?]";
- }
-
- for (@{$user->{state}{related_links}}) {
- push @related_text, sprintf(
- # Instead of hard-coding the HTML here, we should
- # do something a little more flexible.
- qq[&middot; <a href="%s">%s</a><br>\n],
- strip_attribute($_->[1]), $_->[0]
- );
- }
-
- # Check to make sure we don't include the same link twice.
- my %related_text = ( );
- my $return_str = "";
- for my $rt (@related_text) {
- next if $related_text{$rt};
- $return_str .= $rt;
- $related_text{$rt} = 1;
- }
- return $return_str;
-}
-
-##################################################################
-sub otherLinks {
- my($aid, $tid, $uid) = @_;
-
- my $reader = getObject('Slash::DB', { db_type => 'reader' });
-
- my $topics = $reader->getTopics();
- my @tids = ( $tid );
- if (ref($tid) && ref($tid) eq 'ARRAY') {
- @tids = ( @$tid );
- }
-
- return slashDisplay('otherLinks', {
- uid => $uid,
- aid => $aid,
- tids => \@tids,
- topics => $topics,
- }, { Return => 1, Nocomm => 1 });
-}
-
-##################################################################
sub get_slashd_box {
my $slashdb = getCurrentDB();
my $sldst = $slashdb->getSlashdStatuses();
@@ -1458,21 +1347,13 @@ sub editStory {
}
# Get the related text.
- $storyref->{relatedtext} = getRelated(
+ my $admindb = getObject('Slash::Admin');
+ $storyref->{relatedtext} = $admindb->relatedLinks(
"$story_copy{title} $story_copy{introtext} $story_copy{bodytext}",
- $storyref->{topic}
- ) . otherLinks(
+ $storyref->{topiclist},
$slashdb->getAuthor($storyref->{uid}, 'nickname'),
- $storyref->{tid},
$storyref->{uid}
);
- # If getRelated and otherLinks seem to be putting <li>
- # tags around each item, they probably want a <ul></ul>
- # surrounding the whole list. This is a bit hacky but
- # should help make strictly parsed versions of HTML
- # work better.
- $storyref->{relatedtext} = "<ul>\n$storyref->{relatedtext}\n</ul>"
- if $storyref->{relatedtext} && $storyref->{relatedtext} =~ /^\s*<li>/;
my $author = $slashdb->getAuthor($storyref->{uid});
my $topiclist = $slashdb->getTopiclistFromChosen($storyref->{topics_chosen});
@@ -1980,21 +1861,13 @@ sub updateStory {
# grab our links for getRelated, but toss away the result -- pudge
processSlashTags("$form->{bodytext} $form->{introtext}");
- $form->{relatedtext} = getRelated(
- "$form->{title} $form->{bodytext} $form->{introtext}",
- $topic
- ) . otherLinks(
- $slashdb->getAuthor($form->{uid}, 'nickname'),
+ my $admindb = getObject('Slash::Admin');
+ $form->{relatedtext} = $admindb->relatedLinks(
+ "$form->{title} $form->{introtext} $form->{bodytext}",
$topic,
+ $slashdb->getAuthor($form->{uid}, 'nickname'),
$form->{uid}
);
- # If getRelated and otherLinks seem to be putting <li>
- # tags around each item, they probably want a <ul></ul>
- # surrounding the whole list. This is a bit hacky but
- # should help make strictly parsed versions of HTML
- # work better.
- $form->{relatedtext} = "<ul>\n$form->{relatedtext}\n</ul>"
- if $form->{relatedtext} && $form->{relatedtext} =~ /^\s*<li>/;
$slashdb->setCommonStoryWords();
@@ -2284,17 +2157,11 @@ sub saveStory {
my($chosen_hr) = extractChosenFromForm($form);
my($tids) = $slashdb->getTopiclistFromChosen($chosen_hr);
- my $story_text = "$form->{title} $form->{bodytext} $form->{introtext}";
- $form->{relatedtext} = getRelated($story_text, $tids)
- . otherLinks($edituser->{nickname}, $tids, $edituser->{uid});
-
- # If getRelated and otherLinks seem to be putting <li>
- # tags around each item, they probably want a <ul></ul>
- # surrounding the whole list. This is a bit hacky but
- # should help make strictly parsed versions of HTML
- # work better.
- $form->{relatedtext} = "<ul>\n$form->{relatedtext}\n</ul>"
- if $form->{relatedtext} && $form->{relatedtext} =~ /^\s*<li>/;
+ my $story_text = "$form->{title} $form->{introtext} $form->{bodytext}";
+ my $admindb = getObject('Slash::Admin');
+ $form->{relatedtext} = $admindb->relatedLinks(
+ $story_text, $tids, $edituser->{nickname}, $edituser->{uid}
+ );
for my $field (qw( introtext bodytext )) {
local $Slash::Utility::Data::approveTag::admin = 1;
View
8 plugins/Admin/templates/otherLinks;admin;default
@@ -16,10 +16,10 @@ en_US
__name__
otherLinks
__template__
-[% FOR tid = tids %]
-&middot; <A HREF="[% gSkin.rootdir %]/search.pl?tid=[% tid | fixparam %]">More [% topics.$tid.textname %] stories</A><BR>
-[% END %]
-&middot; <A HREF="[% gSkin.rootdir %]/search.pl?op=stories&amp;author=[% uid | fixparam %]">Also by [% aid %]</A>
+ [% FOR tid = tids %]
+ <li><a href="[% gSkin.rootdir %]/search.pl?tid=[% tid | fixparam %]">More [% topics.$tid.textname %] stories</a></li>
+ [% END %]
+ <li><a href="[% gSkin.rootdir %]/search.pl?op=stories&amp;author=[% uid | fixparam %]">Also by [% aid %]</a></li>
__seclev__
500
__version__
View
52 themes/slashcode/tasks/html_update.pl
@@ -10,8 +10,10 @@
use vars qw( %task $me );
$!=0;
-$task{$me}{timespec} = '0 0 * * *';
-$task{$me}{timespec_panic_1} = ''; # if panic, this can wait
+# only run from runtask
+$task{$me}{standalone} = 1;
+# this line should not be needed, but for now, is
+$task{$me}{timespec} = '0 0 0 0 0';
$task{$me}{fork} = SLASHD_NOWAIT;
$task{$me}{code} = sub {
my($virtual_user, $constants, $slashdb, $user, $info, $gSkin) = @_;
@@ -50,15 +52,16 @@
);
- my $time = time();
- my $limit = 3_000;
my $update_num = 10_000;
+ my $admindb = getObject('Slash::Admin');
+ my %authors;
+
for my $name (reverse sort keys %sets) {
my $set = $sets{$name};
- # max is last comment posted under "old" spec, (needs to be figured out manually)
- # lst is last comment updated here
+ # max is last thingy saved under "old" spec, (needs to be figured out manually)
+ # lst is last thingy updated with this task
($set->{max}) = $slashdb->getVar("html_update_$set->{table}_max", 'value', 1);
($set->{lst}) = $slashdb->getVar("html_update_$set->{table}_lst", 'value', 1);
@@ -76,7 +79,7 @@
my $max = $set->{lst} + $update_num;
$max = $set->{max} if $max > $set->{max};
- slashdLog("Updating HTML for $name $next through $set->{max}");
+ slashdLog("Updating HTML for $name $next through $max");
my $cols = join ',', $set->{id}, @{$set->{fields}};
my $fetch = $reader->sqlSelectAllHashref(
@@ -84,7 +87,13 @@
"$set->{id} BETWEEN $next AND $max"
);
- last unless keys %$fetch;
+ my $keycount = scalar keys %$fetch;
+ if (!$keycount) {
+ slashdLog("No records for $name");
+ last;
+ } else {
+ slashdLog("Processing $keycount records for $name");
+ }
my $admin = 0;
$admin = 1 if $name eq 'stories';
@@ -92,18 +101,37 @@
for my $id (sort { $a <=> $b } keys %$fetch) {
my(%oldhtml, %html, $ok);
for my $field (@{$set->{fields}}) {
+ if ($name eq 'stories' && $field eq 'relatedtext') {
+ $oldhtml{$field} = $fetch->{$id}{$field};
+ next;
+ }
+
if (length $fetch->{$id}{$field}) {
$oldhtml{$field} = $fetch->{$id}{$field};
$html{$field} = _html_update_fix($fetch->{$id}{$field}, $field, 0, $admin);
- $ok = 1;
+ $ok = 1 if $oldhtml{$field} ne $html{$field};
}
}
next unless $ok;
+ if ($name eq 'stories') {
+ my $text = "$html{title} $html{introtext} $html{bodytext}";
+ my $tids = $slashdb->getTopiclistFromChosen($slashdb->getStoryTopicsChosen($id));
+ my $uid = $slashdb->getStory($id, 'uid');
+ my $nick = $authors{$uid} ||= $reader->getUser($uid, 'nickname');
+ $html{relatedtext} = $admindb->relatedLinks(
+ $text, $tids, $nick, $uid
+ );
+
+use Data::Dumper;
+print Dumper [$uid, $nick, $tids, $html{relatedtext}];
+exit;
+ }
+
$slashdb->sqlInsert($set->{table_old}, {
$set->{id} => $id,
%oldhtml
- });
+ }, { ignore => 1 });
if ($name eq 'stories') {
$html{is_dirty} = 1;
@@ -131,9 +159,7 @@
}
}
- slashdLog("Done updating HTML for $name $next through $set->{max}");
-
- last if time() > $time + $limit;
+ slashdLog("Done updating HTML for $name $next through $max");
}
$slashdb->setVar("html_update_$set->{table}_lst", $set->{lst})
Please sign in to comment.
Something went wrong with that request. Please try again.