Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: Azashub - maaliskuu 07, 2007, 10:46:49 AP

Otsikko: Dynamic link with space in the username
Kirjoitti: Azashub - maaliskuu 07, 2007, 10:46:49 AP
Hello,

I have made a little script that displays an icon with a dynamic link, in order to allow my users to join a teamspeak server with the same name they have on the forum.
I'm not a PHP guru, sorry if my code isn't perfect.

Any member that belongs to membergroup #9 can see this icon with that link:
teamspeak://ts.mysite.com:9022/loginname=UserName?password=bingo?nickname=UserName

Example : Peter belongs to membergroup #9 he can see this link:
teamspeak://ts.mysite.com:9022/loginname=Peter?password=bingo?nickname=Peter



         //Logo TS
         if (in_array(9, $GLOBALS['user_info']['groups']))
         {
         echo '<a href=teamspeak://ts.mysite.com:9022/loginname=';
         echo $context['user']['name'];
         echo '?password=bingo?nickname=';
         echo $context['user']['name'];
         echo '><img src=Themes/SullenMadness_RC2/images/ts_ico2.jpg border=0></a>';
         }
         //end logo


This is working fine...but my problem is when a member has a UserName composed of at least 2 words (for instance "John Wayne") my code returns this link:
teamspeak://ts.mysite.com:9022/loginname=John   

...The link ends at the 1st space in the UserName...

Why I don't have this kind of link?
teamspeak://ts.mysite.com:9022/loginname=John Wayne?password=bingo?nickname=John Wayne


Is there anything I can adapt in my code?

Thank you for the help (as usual)  :)
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Rudolf - maaliskuu 07, 2007, 11:27:01 AP
try

         //Logo TS
         if (in_array(9, $GLOBALS['user_info']['groups']))
         {
         echo '<a href=teamspeak://ts.mysite.com:9022/loginname=';
         echo urlencode($context['user']['name']);
         echo '?password=bingo?nickname=';
         echo urlencode($context['user']['name']);
         echo '><img src=Themes/SullenMadness_RC2/images/ts_ico2.jpg border=0></a>';
         }
         //end logo

Non-alphanumeric characters should be encoded in urls.
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Azashub - maaliskuu 07, 2007, 01:02:49 IP
Hello and thank you for the answer :)

It doesn't not work (but it's a good start!) because it returns this:
teamspeak://ts.mysite.com:9022/loginname=John+Wayne?password=bingo?nickname=John+Wayne

Do you have an idea?
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Rudolf - maaliskuu 07, 2007, 01:20:15 IP
That's what it has to return. The space in urls should be +
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Azashub - maaliskuu 07, 2007, 02:30:05 IP
You're right but now my user is logged on teamspeak with John+Wayne instead of John Wayne  :(

Or is any way to convert any + into space? (just for this part of code...I don't want to break the whole forum :D)
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Rudolf - maaliskuu 07, 2007, 04:11:41 IP
Sorry.
Try

         //Logo TS
         if (in_array(9, $GLOBALS['user_info']['groups']))
         {
         echo '<a href=teamspeak://ts.mysite.com:9022/loginname=';
         echo urlencode($context['user']['name']);
         echo '?password=bingo?nickname=';
         echo urlencode($context['user']['name']);
         echo '><img src=Themes/SullenMadness_RC2/images/ts_ico2.jpg border=0></a>';
         }
         //end logo

This will replace spaces with %20 maybe teampseak will understand it that it's the space character.
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Azashub - maaliskuu 07, 2007, 04:48:57 IP
I am sorry but I don't see the difference between your last answer an your previous code  ::)
Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Rudolf - maaliskuu 07, 2007, 06:19:59 IP
Because there wasn't any.  :-[
Here's the one it was supposed to be.

         //Logo TS
         if (in_array(9, $GLOBALS['user_info']['groups']))
         {
         echo '<a href=teamspeak://ts.mysite.com:9022/loginname=';
         echo rawurlencode($context['user']['name']);
         echo '?password=bingo?nickname=';
         echo rawurlencode($context['user']['name']);
         echo '><img src=Themes/SullenMadness_RC2/images/ts_ico2.jpg border=0></a>';
         }
         //end logo

Otsikko: Re: Dynamic link with space in the username
Kirjoitti: Azashub - maaliskuu 08, 2007, 03:51:08 AP
It works!

Thank you a lot  :)