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 04-01-2011, 08:49 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default when a user logs in to the forum, where is the $userinfo array built?

Hi Just a quick question to save me some time of looking around really

The title says it all really - but when a member logs in successfully, where is the sql that builds the $vbulletin->userinfo array executed (which php file) - I want to change something in the way one of the array variables is set

cheers

Rich
Reply With Quote
  #2  
Old 04-01-2011, 09:29 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think it's fetch_userinfo() in includes/class_core.php.
Reply With Quote
  #3  
Old 04-02-2011, 04:27 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@kh99
Thanks again for a reply

I had a look at the code you suggested and didn't really see what I hoped to see


Code:
	/**
	* Returns appropriate user info for the owner of this session.
	*
	* @return	array	Array of user information.
	*/
	function &fetch_userinfo()
	{
		if ($this->userinfo)
		{
			// we already calculated this
			return $this->userinfo;
		}
		else if ($this->vars['userid'] AND !defined('SKIP_USERINFO'))
		{
			// user is logged in
			$useroptions = (defined('IN_CONTROL_PANEL') ? FETCH_USERINFO_ADMIN : 0) + (defined('AVATAR_ON_NAVBAR') ? FETCH_USERINFO_AVATAR : 0);
			$this->userinfo = fetch_userinfo($this->vars['userid'], $useroptions, $this->vars['languageid']);
			return $this->userinfo;
		}
		else
		{
			// guest setup
			$this->userinfo = array(
				'userid'         => 0,
				'usergroupid'    => 1,
				'username'       => (!empty($_REQUEST['username']) ? htmlspecialchars_uni($_REQUEST['username']) : ''),
				'password'       => '',
				'email'          => '',
				'styleid'        => $this->vars['styleid'],
				'languageid'     => $this->vars['languageid'],
				'lastactivity'   => $this->vars['lastactivity'],
				'daysprune'      => 0,
				'timezoneoffset' => $this->registry->options['timeoffset'],
				'dstonoff'       => $this->registry->options['dstonoff'],
				'showsignatures' => 1,
				'showavatars'    => 1,
				'showimages'     => 1,
				'showusercss'    => 1,
				'dstauto'        => 0,
				'maxposts'       => -1,
				'startofweek'    => 1,
				'threadedmode'   => $this->registry->options['threadedmode'],
				'securitytoken'  => sha1(sha1(COOKIE_SALT) . USER_AGENT)
			);
I guess that's the relevant part of the fetch_userinfo() function as the rest seems to be to do with avatars, and selecting the correct phrase (languages)


Prob is here my php knowledge ain't quite good enough

function &fetch_userinfo() - what's the & for? I did do a bit of a google on this '&function' stuff but non of it seems to make much sense to me. In fact the info I found on php forms seems to say it doesn't really do anything much useful - or at least I couldn't find a sensible example.

$this->userinfo = fetch_userinfo($this->vars['userid'], $useroptions, $this->vars['languageid']);

Now the fetch_userinfo() function them seems to call itself with some arguments (constants) here, even though fetch_userinfo() doesn't seem to be declared to have any arguments - or at least I can't see it doing anything with arguments in the code - hence the empty ()

I can see the stuff where it builds the userinfo array for a guest, thats easy enough to follow.

I was rather expecting to see some SQL here that reads various tables and builds the userinfo array if you are logged in

Your php is a lot better than mine m8 - I think I just hit the limit of my understanding so far. Help!

--------------- Added [DATE]1301768461[/DATE] at [TIME]1301768461[/TIME] ---------------

OK I have managed to do what I needed to do by adding some code to login.php to rebuild a couple of the counters in userinfo array the way I want them.

I still didn't find the SQL that initialises them on log in but what the hell it works the way I want it to now - and a couple extra SQL on login ain't gonna effect performance much

I would (for my own understanding) still like to know how the php above works though.

Rich
Reply With Quote
  #4  
Old 04-02-2011, 05:40 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, you did say you were looking for where the sql is built. There's another function called fetch_userinfo (with parameters) that's in includes/functions.php.

The & means the function returns a reference (you might want to look at this: http://us2.php.net/manual/en/language.references.php if you haven't already). Without that the returned value would be a copy. Say you had, for instance, an array somewhere that was being used to cache user info (to avoid doing the sql for a particular user more than once). If a function returned a value from that array, any changes to the returned userinfo wouldn't change the cached value. But if the function returns a reference, then any changes *would* change the cached value. I hope that makes some sense.
Reply With Quote
  #5  
Old 04-03-2011, 10:14 AM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cheers kh99 - I probably don't need to read the link you gave now - as that succinct little explanation that makes perfect sense to me.

In my mind I now see the & operator used in this way as returning the address of the userinfo array rather making a copy of the array (or array value) and returning the copy



Rich
Reply With Quote
  #6  
Old 04-03-2011, 01:16 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by richy96 View Post
Cheers In my mind I now see the & operator used in this way as returning the address of the userinfo array rather making a copy of the array (or array value) and returning the copy
Yeah, pretty much. I would just have said something like that but I wasn't sure what kind of background you have in programming.
Reply With Quote
  #7  
Old 04-03-2011, 03:42 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ahh not your average programmer i guess - I come from machine code and assembly language (i loved my spectrum/C64/commodore Amiga too lol) it's just higher level languages I struggle with sometimes lol at least with assembly language you could see exactly how it all works

Used to work in industrial electronics in the 80s/90s(when things were actually worth repairing that was) we'd sometimes have to reverse engineer microprocessor based boards blow our own eprom to create some test routines that actually made the board do something - then you could figure out what was going wrong with a logic analyser or at least a scope.

Of course then they invented MICE (micro in circuit emulator) you could have a lot of fun with one of those

Rich
Reply With Quote
  #8  
Old 04-03-2011, 04:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sounds great, I always wanted to do that kind of thing but never managed to get hired without experience in it.

Anyway, I know what you mean, kind of - my first 7 years of programming was in C and I was used to doing things using pointers extensively, then when I switched to C++ it took me a while to understand the point of adding references to the language when it seemed like using pointers was good enough.
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 06:36 AM.


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.05627 seconds
  • Memory Usage 2,235KB
  • 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
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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