|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Sep 18, 2012 1:32 pm Post subject: modifier fix_http |
|
|
Adds http: if necessary for URLs. Works for smarty2, might need to be changed for smarty3, I don't know.
/**
* Smarty fix_http modifier plugin
*
* Type: modifier<br>
* Name: fix_http<br>
* Purpose: add http:// to beginning of link if necessary
* used as smarty filter
*
* @author Doug Davis
* @param $url string
*/
function smarty_modifier_fix_http($url)
{
$url = trim($url);
if ($url && strncasecmp($url,'http:', 5) != 0 && strncasecmp($url,'https:', 6) != 0) {
$url = 'http://'.$url;
}
return $url;
} |
|
Back to top |
|
rodneyrehm Administrator
Joined: 30 Mar 2007 Posts: 674 Location: Germany, border to Switzerland
|
Posted: Tue Sep 18, 2012 2:32 pm Post subject: |
|
|
I'd probably prefer something along the lines of:
Code: | function smarty_modifier_scheme($string)
if (!preg_match('#^[a-zA-Z0-9-]://#', $string)) {
return '//' . $string;
}
return $string;
} |
Note that "//google.com" is a valid URL. it makes the browser decide if HTTP or HTTPS should be used depending on the scheme used for the current document. _________________ Twitter |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Sep 18, 2012 2:33 pm Post subject: |
|
|
rodneyrehm wrote: | I'd probably prefer something along the lines of:
Code: | function smarty_modifier_scheme($string)
if (!preg_match('#^[a-zA-Z0-9-]://#', $string)) {
return '//' . $string;
}
return $string;
} |
Note that "//google.com" is a valid URL. it makes the browser decide if HTTP or HTTPS should be used depending on the scheme used for the current document. |
That's useful to know. Thanks. |
|
Back to top |
|
|
|
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
|