tips and tricks for movable type
nicer autolinked urls in comments
November 16, 2003
Movable Type offers an autolink feature for URLs in comments, which is rather handy. However, if a URL is lengthy, it can mess up the display in other areas of your site (such as a Recent Comments Listing in your sidebar).
Dylan Cuthbert posted a hack that will extract just the site name as the text of the link.
You'll need to hack two MT files: lib/MT/Util.pm and lib/MT/Template/Context.pm (line numbers referenced are as of v2.64, and code changes are in color):
lib/MT/Util.pm, lines 403-412:
my($text, $blog) = @_;
unless ($blog->allow_comment_html) {
$text = remove_html($text);
if ($blog->autolink_urls) {
$text =~ s!(http://([^\s/]+)\S*)!<a href="$1">$2</a>!g;
}
}
$text;
}
lib/MT/Template/Context.pm, lines 1215-1230:
my($ctx, $arg) = @_;
sanitize_on($arg);
my $tag = $ctx->stash('tag');
my $c = $ctx->stash($tag =~ /Preview/ ? 'comment_preview' : 'comment')
or return $ctx->_no_comment_error('MT' . $tag);
my $blog = $ctx->stash('blog');
my $t = defined $c->text ? $c->text : '';
$t = ($tag =~ /Preview/ ? $t : munge_comment($t, $blog) );
my $convert_breaks = exists $arg->{convert_breaks} ?
$arg->{convert_breaks} :
$blog->convert_paras_comments;
return $convert_breaks ?
MT->apply_text_filters($t, $blog->comment_text_filters, $ctx) :
$t;
}
I have not tested this hack personally (believe it or not, I do very little actual hacking to my own MT files). but I thought it was worth adding here and to the Requested Features List.
TrackBack: 2
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/161)
» Bloggie Scripty Reverb
Excerpt: BB's Script, Plugin and Hack Archive as of 3/1/04: Collapse...
Weblog: Bloggie Broad
Tracked: 03.01.04 05:42 PM
» nicer autolinked urls in comments
Excerpt: Idee für schönere automatisch verlinkte URLs in Movabletype.
Weblog: einfach-persoenlich Sideblog
Tracked: 01.18.05 03:56 AM
Comments
wow, your site! Seems all the best and most informative are MT - must get over the fear of progress... in short, your site rocks, red!
Has anyone tried out this hack and been successful?
I:
1. Downloaded the stated files and copied in the appropriate code changes
2. Uploaded the files back into their originating directories via ASCII
3. Edited/saved a comment to include a long URL that is known to mess up the page layout
4. Rebuilt
In the end, the page layout was still affected by the long URL.
Hmmm...
Great hack, thanks.
Nice hack... i been looking for this fix awhile now. thanks!