Let the html_trim function tell us when we have truncated something,
rather than trying to guess.
Patch by fu.
diffs (52 lines):
diff -r 567751911423 -r fcf85d9cf6a0 cgi-bin/LJ/Entry.pm
--- a/cgi-bin/LJ/Entry.pm Wed Sep 01 23:02:45 2010 +0800
+++ b/cgi-bin/LJ/Entry.pm Thu Sep 02 22:07:27 2010 +0800
@@ -738,8 +738,8 @@ sub event_html
# like event_html, but trimmed to $char_max
sub event_html_summary {
- my ($self, $char_max, $opts) = @_;
- return LJ::html_trim($self->event_html($opts), $char_max);
+ my ($self, $char_max, $opts, $trunc_ref) = @_;
+ return LJ::html_trim($self->event_html($opts), $char_max, $trunc_ref);
}
sub event_text
diff -r 567751911423 -r fcf85d9cf6a0 cgi-bin/ljtextutil.pl
--- a/cgi-bin/ljtextutil.pl Wed Sep 01 23:02:45 2010 +0800
+++ b/cgi-bin/ljtextutil.pl Thu Sep 02 22:07:27 2010 +0800
@@ -511,7 +511,7 @@ sub text_uncompress
# function to trim a string containing HTML. this will auto-close any
# html tags that were still open when the string was truncated
sub html_trim {
- my ($text, $char_max) = @_;
+ my ( $text, $char_max, $truncated ) = @_;
return $text unless $char_max;
@@ -560,6 +560,7 @@ sub html_trim {
# truncate and stop parsing
$content = LJ::text_trim($content, undef, ($char_max -
$content_len));
$out .= $content;
+ $$truncated = 1;
last;
}
diff -r 567751911423 -r fcf85d9cf6a0 htdocs/latest.bml
--- a/htdocs/latest.bml Wed Sep 01 23:02:45 2010 +0800
+++ b/htdocs/latest.bml Thu Sep 02 22:07:27 2010 +0800
@@ -161,10 +161,10 @@ EOC
}
my $time = LJ::ago_text( $now - $obj->logtime_unix );
my $url = $obj->url;
- my $evt = $obj->event_html_summary( 2000, { cuturl => $url,
preformatted => $obj->prop( 'opt_preformatted' ) } );
- # put a "(Read more)" link at the end of the text if the entry had
to be shortened - this will be unnecessarily printed if
- # the text is exactly 2,000 characters long
- $evt .= ' <a href="' . $url . '">(Read more)</a>' if length( $evt
) >= 2000;
+ my $truncated;
+ my $evt = $obj->event_html_summary( 2000, { cuturl => $url,
preformatted => $obj->prop( 'opt_preformatted' ) }, \$truncated );
+ # put a "(Read more)" link at the end of the text if the entry had
to be shortened
+ $evt .= ' <a href="' . $url . '">(Read more)</a>' if $truncated;
my $comments = $obj->reply_count == 1 ? "1 comment" : (
$obj->reply_count > 0 ? $obj->reply_count . ' comments' : 'no comments' );
my $replyurl = $obj->reply_url;
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog