Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-26-2010, 02:34 AM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Getting &u=* to work

If you notice private.php has it so adding &u=90 will make member ID 90's username show up in the recipient field.

My question, how would I go about doing this in my own custom PHP file and template? What snippet controls this- if any.
Reply With Quote
  #2  
Old 03-26-2010, 06:15 PM
Anseur's Avatar
Anseur Anseur is offline
 
Join Date: Jun 2004
Location: Nottingham, UK.
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think your looking for something like this:

PHP Code:

if ($_REQUEST['do'] == 'blah')
{
some code here

In this case 'some code here' gets run if you visit the PHP file in question with somefile.php?&do=blah in the URL.

In the case of your example above it might look something more like

PHP Code:

<form>
Username:
<
input type="text" name="Username" 

if ($_REQUEST['u'] != '' )

value="$_REQUEST['u']"
}
/>

</
form
This would put the user id into the username box, not the username, but it should give you an idea of the general method.

(untested)

However, using superglobals like this is a really bad idea, because it would allow someone to inject code into the php file by the address bar. At the very least you should attempt to sanitize the input before using it. (with regex maybe?)

There may be a safer or better way of doing this, but I'll leave that reply to someone more experienced than myself at PHP.
Reply With Quote
  #3  
Old 03-26-2010, 08:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Pandemikk View Post
If you notice private.php has it so adding &u=90 will make member ID 90's username show up in the recipient field.

My question, how would I go about doing this in my own custom PHP file and template? What snippet controls this- if any.
Anseur's post above is basically right, you could just use something like:

PHP Code:
$userid intval($_REQUEST['u']); 
And then check to make sure $userid > 0 before using it (otherwise, $_REQUEST['u'] didn't exist, was not an integer, or was <= 0).

If you're wondering how private.php does it: around line 1350 or so in private.php is this code

PHP Code:
$vbulletin->input->clean_array_gpc('r', array(
    
'stripquote' => TYPE_BOOL,
    
'forward'    => TYPE_BOOL,
    
'userid'     => TYPE_NOCLEAN,
)); 
The function clean_array_gpc is found in includes/class_core.php. It uses a list of short versions of some parameters, one of which allows "u" for "userid". So it's this line that gets the value from the "&u=NN" on the URL and puts the value of NN into $vbulletin->GPC['userid']. (Also the 'r' that's passed means to look for it in $_REQUEST).

So a little farther down in private.php is

PHP Code:
//set up for standard new PM
// insert username(s) of specified recipients
if ($vbulletin->GPC['userid'])

GPC['userid'] will have been set by the previous call to clean_array_gpc. In this case it's using TYPE_NOCLEAN for 'userid', I think because there can be more than one userid for a new PM. You'd probably want to use TYPE_UINT if you know you are just passing one number.
Reply With Quote
  #4  
Old 03-26-2010, 08:59 PM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That solved the first problem^.

I know have the u=9 displaying 9 in the field. But how could I make it so it will show userid 9's username in the field?

I looked a little farther down in private.php and used that code with my own variables but it didn't do anything. I've also cleaned u and made sure it was greater than 0.
Reply With Quote
  #5  
Old 03-26-2010, 09:41 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You'd have to read the user name from the database. If you have $userid and the user name is all you want, then something like:

PHP Code:
$result $db->query_first("SELECT username 
         FROM " 
TABLE_PREFIX "user
        WHERE userid=" 
$userid
    
); 
and the name will be in $result['username'];

private.php does a more complex query (around line 1481) to get more info about (possibly multiple) users in one query. (BTW, I don't know what the "query_slave" versions of the calls do so I don't know why query_first_slave is used in private.php).
Reply With Quote
  #6  
Old 03-26-2010, 10:21 PM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you so much for your help^.

I have it working perfectly now.
Reply With Quote
  #7  
Old 03-26-2010, 10:29 PM
ForumsMods ForumsMods is offline
 
Join Date: Aug 2007
Location: Argentina
Posts: 667
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why dont you use fetch_userinfo function?
Reply With Quote
  #8  
Old 03-26-2010, 11:06 PM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Would that be better?

And the reason being I'm not aware of it.
Reply With Quote
  #9  
Old 03-26-2010, 11:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't know about that either. Cool. I think it would be better because it's always better to keep the details out of your code as much as possible (such as how the database is structured), and also it looks that function caches user info so that if some other code has already looked up that user, you won't have to do another db query.
Reply With Quote
  #10  
Old 03-27-2010, 01:52 AM
Pandemikk Pandemikk is offline
 
Join Date: Jul 2009
Posts: 292
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well hopefully someone can enlighten me on this. I'm always looking to make the codes as best as possible.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:52 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04540 seconds
  • Memory Usage 2,261KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete