1
Jakobo
Trim Long URLS in all Text
  • 2004/3/25 17:19

  • Jakobo

  • Just popping in

  • Posts: 61

  • Since: 2003/12/18


Very quick and dirty fix for people who do things like

http://oh_my_god_this_is_a_long_url_that_will_screw_up_all_your_pretty_layouts.com/youuknow/you/hate/this/to?and=annoying

So, here is the quick fix:

file: /class/module.textsanitizer.php
version: 2.0.5.x
method: replace function &makeClickable(&$text)
function &makeClickable(&$text)
   {
      
$patterns = array("/(^|[^]_a-z0-9-="'/])([a-z]+?)://([^, rn"()'<>]+)/i", "/(^|[^]_a-z0-9-="'/])www.([a-z0-9-]+).([^, rn"()'<>]+)/i", "/(^|[^]_a-z0-9-="'/])ftp.([a-z0-9-]+).([^, rn"()'<>]+)/i""/(^|[^]_a-z0-9-="'/:.])([a-z0-9-_.]+?)@([^, rn"()'<>[]]+)/i");
      
$replacements = array("\1<a href="\2://\3" target="_blank">\2://\3</a>", "\1<a href="http://www.\2.\3" target="_blank">www.\2.\3</a>", "\1<a href="ftp://ftp.\2.\3" target="_blank">ftp.\2.\3</a>", "\1<a href="mailto:\2@\3">\2@\3</a>");
      
[b]$string preg_replace($patterns$replacements$text);
      
$wrap_at 60;
      
$string preg_replace('%(s*)([^>]{'.$wrap_at.',})(<|$)%e',
          
"'\1'.wordwrap('\2', '".$wrap_at."', '<br />', 1).'\3'"$string);
      return 
$string;[/b]
   }

2
Jakobo
Re: Trim Long URLS in all Text
  • 2004/3/25 17:23

  • Jakobo

  • Just popping in

  • Posts: 61

  • Since: 2003/12/18


Some additional notes:
it will break the url XOOPS tag (not sure why yet)

it will auto-format all urls

If anyone else is better with RegEx it would be a huge help so that it wouldn't ignore the url tag.

3
Jakobo
Re: Trim Long URLS in all Text
  • 2004/3/25 17:39

  • Jakobo

  • Just popping in

  • Posts: 61

  • Since: 2003/12/18


And lastly, an elegant CSS solution:

/* The text of the story itself */
.itemBody {padding-left5pxoverflowhidden;}



Hopefully these will help everyone when
they have users who don't know how to use
the URL tag to clean up their really long
links.


(manual breaks because of above post)

Cheers!

4
carnuke
Re: Trim Long URLS in all Text
  • 2004/3/25 17:51

  • carnuke

  • Home away from home

  • Posts: 1955

  • Since: 2003/11/5


Thanks for your idea ... and good luck with the development, oh anyone who like zero 7 is ok by me

Richard

Login

Who's Online

179 user(s) are online (82 user(s) are browsing Support Forums)


Members: 0


Guests: 179


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits