Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 'urlify' plugin

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
ironik
Smarty n00b


Joined: 27 Feb 2005
Posts: 2

PostPosted: Mon Feb 28, 2005 10:46 pm    Post subject: Smarty 'urlify' plugin Reply with quote

Not sure if this is the place for it, but I thought this might be useful. I use a urlify function to create links out of plain text matches using this regular expression. I haven't been able to test it fully in smarty yet, but the regex works fine so in theory it should just transfer over. Works well in community building where users don't need bb code or knowledge of html <a> links to create hyperlinks.

Hoping someone has a chance to test it in smarty... see how it goes?

Code:

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * @file  modifier.urlify.php
 * Smarty 'urlify' modifier plugin
 *
 * Type:     modifier<br>
 * Name:     urlify<br>
 * Purpose:  turn url text into hyperlinks
 * Example:  {$var|urlify}
 * @param string
 * @return string
 */
function smarty_modifier_urlify($string)
{
   $pattern ="{\\b((https?|telnet|gopher|file|wais|ftp) : [\\w/\\#~:.?+=&%@!\\-]+?) (?= [.:?\\-]* (?:[^\\w/\\#~:.?+=&%@!\\-] |$) ) }x";
   return preg_replace ($pattern, "<a href=\"$1\" target=\"" . $target . "\">$1</a>", $string);
}
?>


Last edited by ironik on Mon Feb 28, 2005 11:00 pm; edited 1 time in total
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 28, 2005 10:55 pm    Post subject: Reply with quote

I think you want $string and not $html (just looking at it)
Back to top
View user's profile Send private message Visit poster's website
ironik
Smarty n00b


Joined: 27 Feb 2005
Posts: 2

PostPosted: Mon Feb 28, 2005 11:01 pm    Post subject: Reply with quote

d'oh! thats what I get for not testing first Rolling Eyes . My orginal function used a $html var.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP