Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
smarty modifier for url to link
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/19/11 01:27 
Is there a smarty modifier to turn url's into links?

somehting like
{$MESSAGE_BODY}

im hoping for something like
{$MESSAGE_BODY|urls2links}

that will make a clickable link out of something like:
http://google.com


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/19/11 01:43 
figured it out by building a function in a module.

If there is a jamrom way, then I would love to know, but this works if anyone else is needing it and there isnt a jamroom way.

put this function in a jamroom module (and activate it.).

Code

/**
 * takes a block of text and changes any http:// int an href.
 * @param  $text
 * @return mixed
 */
function urls2links($text) {
    // The Regular Expression filter
    $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

    // The Text you want to filter for urls
    //$text = "The text you want to filter goes here. http://google.com";

    // Check if there is a url in the text
    if (preg_match($reg_exUrl, $text, $url)) {
        // make the urls hyper links
       $ret =  preg_replace($reg_exUrl, '<a href="'.$url[0].'">'.$url[0].'</a> ', $text);
    } else {
        // if no urls in the text just return the text
        $ret =  $text;
    }
    return $ret;
}


then use:
{$MESSAGE_TEXT|urls2links}
and its good to go.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
smith.kyle
CodeSmith


Joined: 27 Apr 2006
Posts: 22009
Location: Southern California

Posted: 05/22/11 16:19 
The jr_html_autolinks modifier?

http://www.jamroom.net/Jamroom4_Variable_Modifiers#jr_html_autolinks

Kyle


_________________
kyle[at]jamroom.net

Yes...that's a soda machine...

I get bored when no one's posting...
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 05/22/11 20:24 
Kyle You ROCK!

My code above stuffed up when there was more than one link, so i took it out. You made my day! Thanks

Smile Smile


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.