Ignore:
Timestamp:
09/28/07 00:02:59 (5 years ago)
Author:
hverton
Message:

new shortenlink() function to trim URL's in the middle
fixed positioning of the IP icon in the renderpost templates
reworked URL detection in messages (still has an issue with a trailing dot!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/forum_functions_include.php

    r834 r845  
    297297    if (strlen($rawmsg)) $message .= $rawmsg; 
    298298 
    299     // find URL's in the text, and convert them to a [url] BBcode 
    300     $message = preg_replace("#(^|\s)(www|WWW)\.([^\s<>\/]+)\/([^\s\r\n<>\)\,\:\;\[]+)#sm", "\\1[url=http://\\2.\\3/\\4]http://\\2.\\3[/url]", $message); 
    301     $message = preg_replace("#(^|[^\"=\]]{1})(http|HTTP|ftp)(s|S)?://([^\s<>\/]+)\/([^\s\r\n<>\)\,\:\;\[]+)#sm", "\\1[url=\\2\\3://\\4/\\5]\\2\\3://\\4[/url]", $message); 
     299    // Split off the [url] blocks to exclude them from url parsing 
     300    $rawmsg = $message; 
     301    $message = ""; 
     302    $urlblocks = array(); 
     303 
     304    // find the code [url] occurence 
     305    $i = strpos($rawmsg, "[url"); 
     306 
     307    // loop through the message until all are found and processed 
     308    while ($i !== false) { 
     309        // strip the bit before the [url] BBcode, and add a placeholder 
     310        $message .= substr($rawmsg, 0, $i+4)."{@@**@@}"; 
     311        // strip the processed bit 
     312        $rawmsg = substr($rawmsg, $i+4); 
     313        // find the end of the [url] block 
     314        $j = strpos($rawmsg, "[/url]"); 
     315        // if not found, add the remaining bit, a forced [/url], and stop processing 
     316        if ($j === false) { 
     317            $message = str_replace("{@@**@@}", $rawmsg, $message); 
     318            break; 
     319        } 
     320        // store this url block 
     321        $urlblocks[] = substr($rawmsg, 0, $j); 
     322        // strip the processed bit 
     323        $rawmsg = substr($rawmsg, $j); 
     324        // check if there are more code segments 
     325        $i = strpos($rawmsg, "[url"); 
     326    } 
     327 
     328    // any text left? 
     329    if (strlen($rawmsg)) $message .= $rawmsg; 
     330 
     331    // find remaining URL's in the text, and convert them to a href as well 
     332    $pattern = '#(^|[^\"=]{1})(https?://|ftp://|mailto:|news:)([^(,\s<>\[\]\)]+)([,\s\n<>\)]|$)#sme'; 
     333    $message = preg_replace($pattern,"'$1<a href=\'$2$3\' target=\'_blank\'>'.shortenlink('$2$3',75).'</a>$4'",$message); 
     334 
     335    // re-insert the saved url blocks 
     336    foreach($urlblocks as $urlblock) { 
     337        // find the first placeholder 
     338        $i = strpos($message, "{@@**@@}"); 
     339        $message = substr($message, 0, $i).$urlblock.substr($message, $i+8); 
     340    } 
    302341 
    303342    // parse the message, and convert all BBcode found 
Note: See TracChangeset for help on using the changeset viewer.