• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Check if URL has "http://" with a small UDT
PostPosted: Fri May 02, 2014 7:24 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 350
Issue:
- users are allowed to enter URL's in a text input box.
- That URL has to be used later on to create a href
- If the user didn't enter "http://", the href will be send visitors to "http://www.yourwebsite.com/www.someotherwebsite.com" instead of "http://someotherwebsite.com" (may be only the case if you use pretty URL's, didn't test...)

Solution:

Use http://stackoverflow.com/a/8591679/1338546 in a UDT
In the template:
\$1:
<a href="{checkurl url="{$oneuser.properties.website}"}">...</a>

The UDT named checkurl:
\$1:
$urlStr = $params['url'];
$parsed = parse_url($urlStr);
if (empty($parsed['scheme'])) {
    $urlStr = 'http://' . ltrim($urlStr, '/');
};
echo $urlStr;

_________________
Do you like your open source cms? Buy from the CMSMS partners || Donate
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Check if URL has "http://" with a small UDT
PostPosted: Fri May 02, 2014 7:31 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 350
ps: you can also save the result in a variable instead of using echo...

Replace the echo with the code below and a variable called "newurl" will be available in your template after the calling the fixurl UDT.
\$1:
$smarty = cmsms()->GetSmarty();
$smarty->assign('newurl', $urlStr);

_________________
Do you like your open source cms? Buy from the CMSMS partners || Donate
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


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 post attachments in this forum

Search for:
Jump to:  
cron
Hosting Nation - Managed CMSMS Hosting