[geeklog-users] Auto-parsing for URLs

Kyle Rove krove at pyramid.net
Tue Feb 4 11:50:49 EST 2003


Found it! Based on the GL codebase, wouldn't this function need to be  
used upon time of display and NOT after posting because the posts to  
which this applies are plain-text?

        function magic_url(&$message, $url)
         {
                 global $config;

                 if ($url)
                 {
                         $server_protocol = ( $config['cookie_secure'] )  
? 'https://' : 'http://';
                         $server_port = ( $config['server_port'] <> 80 )  
? ':' . trim($config['server_port']) . '/' : '/';

                         $match = array();
                         $replace = array();

                         // relative urls for this board
                         $match[] = '#' . $server_protocol .  
trim($config['server_name']) . $server_port .  
preg_replace('/^\/?(.*?)(\/)?$/', '\1', trim($config['script_path'])) .  
'/([^\t\n\r <"\']+)#i';
                         $replace[] = '<!-- l --><a href="\1"  
target="_blank">\1</a><!-- l -->';

                         // matches a xxxx://aaaaa.bbb.cccc. ...
                         $match[] = '#(^|[\n  
])([\w]+?://.*?[^\t\n\r<"]*)#ie';
                         $replace[] = "'\\1<!-- m --><a href=\"\\2\"  
target=\"_blank\">' . ( ( strlen(str_replace(' ', '%20', '\\2')) > 55 )  
?substr(str_replace(' ', '%20', '\\2'), 0, 39) . ' ... ' .  
substr(str_replace(' ', '%20', '\\2'), -10) : str_replace(' ', '%20',  
'\\2') ) . '</a><!-- m -->'";

                         // matches a "www.xxxx.yyyy[/zzzz]" kinda lazy  
URL thing
                         $match[] = '#(^|[\n  
])(www\.[\w\-]+\.[\w\-.\~]+(?:/[^\t\n\r<"]*)?)#ie';
                         $replace[] = "'\\1<!-- w --><a  
href=\"http://\\2\" target=\"_blank\">' . ( ( strlen(str_replace(' ',  
'%20', '\\2')) > 55 ) ? substr(str_replace(' ', '%20', '\\2'), 0, 39) .  
' ... ' . substr(str_replace(' ', '%20', '\\2'), -10) : str_replace('  
', '%20', '\\2') ) . '</a><!-- w -->'";

                         // matches an email at domain type address at the  
start of a line, or after a space.
                         $match[] = '#(^|[\n  
])([a-z0-9\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)#ie';
                         $replace[] = "'\\1<!-- e --><a  
href=\"mailto:\\2\">' . ( ( strlen('\\2') > 55 ) ?substr('\\2', 0, 39)  
. ' ... ' . substr('\\2', -10) : '\\2' ) . '</a><!-- e -->'";

                         $message = preg_replace($match, $replace,  
$message);
                 }
         }

Kyle

On Tuesday, February 4, 2003, at 08:44  AM, Tony Bibbs wrote:

> Search CVS in phpBB at http://sf.net/projects/phpbb
>
> They should have this code some where.  If you find it, post here and
> we'll look at possibly adding it to our code.
>
> --Tony
>
> On Tue, 4 Feb 2003, Kyle Rove wrote:
>
>> Does anyone have any code that would allow one to auto-parse  
>> plain-text
>> postings for urls? Some of my users are requesting this, and I believe
>> it would be a great addition to the code base if done properly so as  
>> to
>> make it easier to post linked content without the knowledge of html.
>>
>> Thanks,
>> Kyle
>>
>> _______________________________________________
>> geeklog-users mailing list
>> geeklog-users at lists.geeklog.net
>> http://lists.geeklog.net/listinfo/geeklog-users
>>
>
> --  
> ----------------------------------------------------------------------- 
> -|
> Tony Bibbs         | "I guess you have to remember that those who  
> don't |
> tony at tonybibbs.com | hunt or fish often see those of us who do as       
>  |
>                    | harmlessly strange and sort of amusing. When you   
>  |
>                    | think about it, that might be a fair assessment."  
>  |
>                    | --Unknown                                          
>  |
> ----------------------------------------------------------------------- 
> -|
>
>
> _______________________________________________
> geeklog-users mailing list
> geeklog-users at lists.geeklog.net
> http://lists.geeklog.net/listinfo/geeklog-users
>




More information about the geeklog-users mailing list