Changeset 845 in ExiteCMS


Ignore:
Timestamp:
09/28/07 00:02:59 (4 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!)

Location:
trunk/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core_functions.php

    r843 r845  
    268268 
    269269// Trim a line of text to a preferred length 
    270 function trimlink($text, $length) { 
     270function trimlink($text, $length, $filler="...") { 
    271271    $dec = array("\"", "'", "\\", '\"', "\'", "<", ">"); 
    272272    $enc = array("&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;"); 
    273273    $text = str_replace($enc, $dec, $text); 
    274     if (strlen($text) > $length) $text = substr($text, 0, ($length-3))."..."; 
     274    if (strlen($text) > $length) $text = substr($text, 0, ($length-3)).$filler; 
    275275    $text = str_replace($dec, $enc, $text); 
    276276    return $text; 
     277} 
     278 
     279// Trim a URI to a preferred length by cutting out the middle (preserve the hostname if possible) 
     280function shortenlink($text, $length, $filler="...") { 
     281 
     282    $dec = array("\"", "'", "\\", '\"', "\'", "<", ">"); 
     283    $enc = array("&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;"); 
     284    $returner = str_replace($enc, $dec, $text); 
     285    if (strlen($returner) > $length) { 
     286        $url = preg_match("=[^/]/[^/]=",$returner,$treffer,PREG_OFFSET_CAPTURE); 
     287        $cutpos = $treffer[0][1]+2; 
     288        $part[0] = substr($returner,0,$cutpos); 
     289        $part[1] = substr($returner,$cutpos); 
     290        $strlen1 = $cutpos; 
     291        if ($strlen1 > $length) { 
     292            $returner = substr($returner,0,$length-3).$filler; 
     293        } else { 
     294            $strlen2 = strlen($part[1]); 
     295            $cutpos = $strlen2-($length-3-$strlen1); 
     296            $returner = $part[0].$filler.substr($part[1],$cutpos); 
     297        } 
     298    } 
     299    $returner = str_replace($dec, $enc, $returner); 
     300    return $returner; 
    277301} 
    278302 
     
    490514    $text = preg_replace('#\[url=([\r\n]*)(http://|ftp://|https://|ftps://)([^\'\";]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'\2\3\' target=\'_blank\'>\4</a>', $text); 
    491515    $text = preg_replace('#\[url=([\r\n]*)([^\s\'\";\+]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\'>\3</a>', $text); 
    492      
     516 
    493517    $text = preg_replace('#\[mail\]([\r\n]*)([^\s\'\";:\+]*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\2</a>', $text); 
    494518    $text = preg_replace('#\[mail=([\r\n]*)([^\s\'\";:\+]*?)\](.*?)([\r\n]*)\[/mail\]#si', '<a href=\'mailto:\2\'>\2</a>', $text); 
  • 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 
  • trunk/includes/templates/forum.renderpost.tpl

    r843 r845  
    1616{***************************************************************************} 
    1717    <tr> 
    18         <td class='tbl1' colspan='3' height='5'> 
     18        <td class='tbl1' colspan='4' height='5'> 
    1919            <a name='post_{$posts[pid].post_id}' id='post_{$posts[pid].post_id}'></a> 
    2020        </td> 
     
    3737            {/if} 
    3838        </td> 
    39         <td class='tbl_top_right' style='text-align:right;'> 
     39        <td class='tbl_top_mid' style='text-align:right;'> 
    4040        {if $smarty.const.iMEMBER && $user_can_post} 
    4141            {if $posts[pid].user_can_edit} 
     
    5252                {buttonlink name=$locale.569 link="post.php?action=quote&amp;forum_id="|cat:$forum_id|cat:"&amp;thread_id="|cat:$posts[pid].thread_id|cat:"&amp;reply_id="|cat:$posts[pid].post_id} 
    5353            {/if} 
     54        {/if} 
     55        </td> 
     56        <td width='1%' class='tbl_top_right'> 
    5457            {if $posts[pid].show_ip} 
    5558                {if $user_can_blacklist} 
     
    6164                {/if} 
    6265            {/if} 
    63         {/if} 
    6466        </td> 
    6567    </tr> 
     
    123125            <span class='alt'>{$locale.504}</span> {$posts[pid].user_joined|date_format:"%d.%m.%y"} 
    124126        </td> 
    125         <td valign='top' colspan='2' height='{$height}' class='{if $posts[pid].unread}unread{else}tbl_right{/if}' style='border-bottom:none;'> 
     127        <td valign='top' colspan='3' height='{$height}' class='{if $posts[pid].unread}unread{else}tbl_right{/if}' style='border-bottom:none;'> 
    126128        {$posts[pid].post_message|default:"&nbsp;"} 
    127129        {section name=id loop=$posts[pid].attachments} 
     
    146148                                    <td> 
    147149                                        {if $smarty.const.DOWNLOAD_IMAGES} 
    148                                             <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' alt='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname} 
     150                                            <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' title='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname} 
    149151                                        {else} 
    150152                                            <a href='{$posts[pid].attachments[id].link}' alt='{$posts[pid].attachments[id].attach_comment}' target='_blank'>{$posts[pid].attachments[id].attach_realname} 
     
    161163                        {else} 
    162164                            {if $smarty.const.DOWNLOAD_IMAGES} 
    163                                 <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' alt='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname}</a> ({$posts[pid].attachments[id].imagesize.x} x {$posts[pid].attachments[id].imagesize.y} {$locale.518}) 
     165                                <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' title='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname}</a> ({$posts[pid].attachments[id].imagesize.x} x {$posts[pid].attachments[id].imagesize.y} {$locale.518}) 
    164166                            {else} 
    165167                                <a href='{$posts[pid].attachments[id].link}' alt='{$posts[pid].attachments[id].attach_comment}' target='_blank'>{$posts[pid].attachments[id].attach_realname}</a> ({$posts[pid].attachments[id].imagesize.x} x {$posts[pid].attachments[id].imagesize.y} {$locale.518}) 
     
    171173                        {$posts[pid].attachments[id].attach_realname} ( {$posts[pid].attachments[id].size} ) 
    172174                    {else} 
    173                         <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' alt='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname}</a> ( {$posts[pid].attachments[id].size} ) 
     175                        <a href='{$smarty.const.BASEDIR}getfile.php?type=a&amp;file_id={$posts[pid].attachments[id].attach_id}' title='{$posts[pid].attachments[id].attach_comment}'>{$posts[pid].attachments[id].attach_realname}</a> ( {$posts[pid].attachments[id].size} ) 
    174176                    {/if} 
    175177 
     
    230232        {/if} 
    231233        </td> 
    232         <td colspan='2' class='{if $posts[pid].unread}unread{else}tbl_right{/if}' style='border-top:none;'> 
     234        <td colspan='3' class='{if $posts[pid].unread}unread{else}tbl_right{/if}' style='border-top:none;'> 
    233235        {if $posts[pid].post_showsig && $posts[pid].user_sig|default:"" != ""} 
    234236            <hr /> 
Note: See TracChangeset for help on using the changeset viewer.