# Auto shorten url with shorturl gem.
# FIXME: There're 2 bugs in ShortURL by Vincent Foley.
# [#8376] tinyurls redirect to URLs with encoded chars, causing 404.
# http://rubyforge.org/tracker/index.php?func=detail&aid=8376&group_id=732&atid=2893
# [#15415] Invalid RubyURL
# http://rubyforge.org/tracker/index.php?func=detail&aid=15415&group_id=732&atid=2893
defauto_short_urls(text, service =:tinyurl)
text.gsub(Helper::AUTO_LINK_RE)do
all, a, b, c, d =$&,$1,$2,$3,$4if a =~/<a\s/i# don't replace URL's that are already linked
all
else
long_url = b + c
short_url =WWW::ShortURL.shorten(long_url,service)%(#{a}<a href="#{short_url}">#{short_url}</a>#{d})endendend