Usernames in URL
Posted: 11 April 2008 05:47 AM   [ Ignore ]
Member
RankRankRank
Total Posts:  67
Joined  2007-07-19

In the docs it mentions that the stats tag can automatically recognize usernames in the URL.

It recognizes member IDs but not usernames.

This works:
www.example.com/profile_stats/13

These don’t
www.example.com/profile_stats/user/joebloggs
www.example.com/profile_stats/joebloggs

I assume i could get around this using segment variables, but I am unsure what I am doing wrong regarding the automatic process.

Profile
 
 
Posted: 11 April 2008 06:08 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2692
Joined  2006-10-18

Strange…

The documentation says usernames NEED to be preceeded by the word “user”.
Funny thing is though, I’m managed to get mine to work with both:

mysite.com/user/username
and
mysite.com/pants/username

Which versions of EE and User are you running? smile

 Signature 
Profile
 
 
Posted: 12 April 2008 04:02 AM   [ Ignore ]   [ # 2 ]
Member
Avatar
RankRankRank
Total Posts:  52
Joined  2007-07-16

I use a plugin called memberinfo on the index of the member template group. EG:

/members/username

If /username is not a valid user, then a list of members is returned. Might be handy for you:

<?php

$plugin_info
= array(
   
'pi_name'   => 'Member info',
   
'pi_version'  => '1.0',
   
'pi_author'   => 'Tom Kiss',
   
'pi_author_url'  => 'http://www.tomkiss.net',
   
'pi_description' => 'Get member information.',
   
'pi_usage'   => memberinfo::usage()
);


class
memberinfo {

  
var $return_data;

// isMember function - returns true/false from username parameter
function exists() {
  
global $TMPL, $FNS, $DB, $SESS, $PREFS, $LOC;
  
// Parameters
  
$username = (!$TMPL->fetch_param('username')) ? '' : $TMPL->fetch_param('username');
  
// DB Query
  
$query = $DB->query("SELECT screen_name FROM exp_members WHERE username = '".$username."'");
  
// Return data
  
if ($query->num_rows == 1) {
return true;
   
}  else {
return false;
   
}
}


// Member URL
function getMemberURL() {
  
if (func_num_args() > 0) {
   $username
= func_get_args();
   
$username = $username[0];
  
}
  
global $TMPL, $DB;
  
// Return data
  
if (empty($username)) {
   $id
= (!$TMPL->fetch_param('id')) ? '0' : $TMPL->fetch_param('id');
   
$screen_name = (!$TMPL->fetch_param('screen_name')) ? '' : $TMPL->fetch_param('screen_name');
   
$query = $DB->query("SELECT username FROM exp_members WHERE member_id = '".$id."' OR screen_name = '".$screen_name."'");
   if (
$query->num_rows == 1) {
$username
= $query->row["username"];
   
}
  }
  
if (!empty($username)) {
   
return '/members/'.rawurlencode($username);
  
} else {
   
return "";
  
}
}
  


function usage() {
ob_start
();

?>





<?php

$buffer
= ob_get_contents();
  
ob_end_clean();

return
$buffer;
}



}

?>

Then in my template I can just have:

{if "{exp:memberinfo:exists username="{segment_2}"}"}

{embed
=/member-profile-code}


{if
:else}

List members

{
/if}

Profile
 
 
Posted: 14 April 2008 06:59 AM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2692
Joined  2006-10-18

neat! smile

 Signature 
Profile
 
 
Posted: 14 April 2008 07:33 AM   [ Ignore ]   [ # 4 ]
Member
Avatar
RankRankRank
Total Posts:  52
Joined  2007-07-16

I would mention some problems i’ve had with this though.

Usernames are not verified for spaces or other characters. So you can find problems with URLs containing usernames with spaces.

My plugin there will encode the URL first, but I’ve had problems elsewhere.

An extension and a control panel option would be good. To force usernames to be like weblog url_titles - eg: lowercase without dodgy characters or spaces.

smile

Profile
 
 
Posted: 14 April 2008 07:46 AM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2692
Joined  2006-10-18

ahhh… I see… I’ll make a note of that for Mitchell wink

Thanks Tony! smile

 Signature 
Profile
 
 
Posted: 01 May 2008 07:43 PM   [ Ignore ]   [ # 6 ]
Member
RankRankRank
Total Posts:  67
Joined  2007-07-19
Pie Man - 11 April 2008 06:08 AM

Strange…

The documentation says usernames NEED to be preceeded by the word “user”.
Funny thing is though, I’m managed to get mine to work with both:

mysite.com/user/username
and
mysite.com/pants/username

Which versions of EE and User are you running? smile

I forgot to checkup on this thread.  My EE/User install was up-to-date when I made this post in april.

If it’s working as expected for youy, is there anything different I have to do in my template code to get the username segments to work?

Profile
 
 
Posted: 02 May 2008 06:14 AM   [ Ignore ]   [ # 7 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  2692
Joined  2006-10-18

What does your template code look like? smile

 Signature 
Profile