Recent Topics

1 Jul 01, 2006 16:40    

Just a reminder for francois and a heads up for blueeyed in the event he doesnt read my other thread about this.

I put together a quick wordpress plugin that shortens urls within comments; its very nice for those folks that have fixed width size divs or sites that often break when someone posts a link within a comment.

Essentially its a just rewrite of make_clickable, of which b2evo has a similar function.

code:


function make_chunk_links($ret) {
$ret = ' ' . $ret . ' ';
$ret = preg_replace("#([\s>])(https?)://([^\s<>{}()]+[^\s.,<>{}()])#i", "$1<a href='$2://$3' rel='nofollow'>$2://$3</a>", $ret);
$ret = preg_replace("#(\s)www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^ <>{}()\n\r]*[^., <>{}()\n\r]?)?)#i", "$1<a href='http://www.$2.$3$4' rel='nofollow'>www.$2.$3$4</a>", $ret);
$ret = preg_replace("#(\s)([a-z0-9\-_.]+)@([^,< \n\r]+)#i", "$1<a href=\"mailto:$2@$3\">$2@$3</a>", $ret);



$links = explode('<a', $ret);
   $countlinks = count($links);
   for ($i = 0; $i < $countlinks; $i++)
   {
      $link = $links[$i];
}
$link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;

$begin = strpos($link, '>') + 1;
$end = strpos($link, '<', $begin);
$length = $end - $begin;
$urlname = substr($link, $begin, $length);
$chunked = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -10) : $urlname;
$ret = str_replace('>' . $urlname . '<', '>' . $chunked . '<', $ret);

$ret = trim($ret);
return $ret;
} 

Im sure folks would love to see this available in the upcoming b2evolution releases :)


Form is loading...