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 11-22-2010, 10:18 AM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Need some advice regards register.php

Hi
Can anyone give me some information regards the registration process and the structure of the register.php file?

There are some parts of the code that I am unable to figure out quite what is going on as I don't have sufficient knowledge of the way vbulletin works (I find it very convoluted and hard to follow at times - though once I do figure something out just how someting works the code is always elegant)

Anyway the modifications I am trying to make mean I need to understand the registration process better

I have already figured out I need to look at a particular section of register.php which is this section:

Code:
if ($_POST['do'] == 'addmember')
Here are a few extracts I am looking at

Code:
	// assign user to usergroup 3 if email needs verification
	if ($vbulletin->options['verifyemail'])
	{
		$newusergroupid = 3;
	}
	else if ($vbulletin->options['moderatenewmembers'] OR $vbulletin->GPC['coppauser'])
	{
		$newusergroupid = 4;
	}
	else
	{
		$newusergroupid = 2;
	}

$userdata->set('usergroupid', $newusergroupid);
I understand what this is doing in principle

The bit I am not sure about exactly is $userdata->set('usergroupid', $newusergroupid);

the $userdata->set() is a method (function) which is part of an array of methods?


Code:
       // set languageid
	$userdata->set('languageid', $vbulletin->userinfo['languageid']);

	// set user title
	$userdata->set_usertitle('', false, $vbulletin->usergroupcache["$newusergroupid"], false, false);

	// set profile fields
	$customfields = $userdata->set_userfields($vbulletin->GPC['userfield'], true, 'register');

	// register IP address
	$userdata->set('ipaddress', IPADDRESS);

More use of this $userdata->set() - but is set() the actual function that is writing the fields to the userfields file in the database or are we just building an array here? I guess really I need to know where the code for $userdata->set() is before i could answer that myself, which is what I am asking here

Also what exactly is GPC() it crops up a lot but I have never really understood it (or had the need to yet)

Code:
	($hook = vBulletinHook::fetch_hook('register_addmember_process')) ? eval($hook) : false;
Now this fetch_hook thing is something that has me totally puzzled. I'm not rightly sure where the fetch_hook function is (so I can llok at the code) but I found 'register_addmember_process' in a file forum/includes/xml. But that doesn't seem to "do" anything as far as I can see in as much as it does not contain any executable code, it is just simply a list of all these hook names arrranged into hook type groups.

Can someone explain (or point me in the direction of understanding) what this line of code actually does - I know the eval($hook) executes the contents of the variable $hook as though it was php. But what code is this $hook variable containing here and how did it get there? And why not simply put the necessary executable php in register.php without all this hook malarky to confuse things?


Code:
	$userdata->pre_save();
What does this presave function do?


Code:
	// check for errors
	if (!empty($userdata->errors))
	{
		$_REQUEST['do'] = 'register';

		$errorlist = '';
		foreach ($userdata->errors AS $index => $error)
		{
			$errorlist .= "<li>$error</li>";
		}

		$username = htmlspecialchars_uni($vbulletin->GPC['username']);
		$email = htmlspecialchars_uni($vbulletin->GPC['email']);
		$emailconfirm = htmlspecialchars_uni($vbulletin->GPC['emailconfirm']);
		$parentemail = htmlspecialchars_uni($vbulletin->GPC['parentemail']);
		$selectdst = array($vbulletin->GPC['dst'] => 'selected="selected"');
		$sbselected = array($vbulletin->GPC['showbirthday'] => 'selected="selected"');
		$show['errors'] = true;
	}
	else
	{
		$show['errors'] = false;
I can kind of see that this sends users back to register.php?do=register if there are any errors in the entered data

Code:
		// save the data
		$vbulletin->userinfo['userid']
			= $userid
			= $userdata->save();
Is this the bit where the user fields get written to the database? But where is the sql to do that, and can someone explain this line with the two equals signs = $userid which also = $userdata->save?

Thanks for any help or guidance

---------------------------------------------------------

OK this next bit describes what I am actually trying to do in case it assists anyone trying to help me. It isn't really necessary for anyone to read this part, if they just want to answer the questions above. But for a deeper understanding of my site....

On my site I have a custom user field called postcode

Basically when a user registers they enter the first part of their postcode which technically is called an 'outcode' and this identifies the town or city the member lives in but not the actual address

There is in my database a postcodes file which contains these five fields: outcode, city/county, town, x and y coordinates

The x and y co-ords are in metres starting from the bottom left hand corner of the UK (Lands End) which is x=0.0000 y=0.0000

The way another programmer working on my site implemented the next bit is the problem. When listing members in memberlist (or in forum postbits) the site uses Ajax to look up each outcode in the postcode database, and display the city or county. On actual profiles it displays the city/county + town.

If someone clicks on the city/county in memberlist or postbits, the site then looks up that city or county in the postcodes database, finds all the outcodes relating to that city or couty, and finally lists all members who live in that city regardless of their actual outcode

Also I have a member search facility that uses the x and y co-ordinates to find all members living within x miles (as the crow flies) using a pythagorean formula

So that's what I have implemented at the moment and it works OK. The problem is that as the memberlist gets bigger, the Ajax that looks up the city/county from the postcodes database everytime is slowing things down too much

So I have now added another custom userfield called 'Location' The memebrs cant' access this field directly. I added some code to memberlist.php so I can run an 'admin' function that looks up each member, uses the outcode to find the city/county and then stores this in the Location field. This all works OK. So if for example I change the postcodes file (add or change an outcode) then I can run this function to update all my members locations

I am now using this Location field to display in memberlists and postbits so I no longer need the Ajax which was slowing the site down a lot

What I now need to do is add code to the registration which looks up the outcode $userinfo[field6] in the postcodes file and stores the returned city/county in $userinfo[field98]

Basically I need to know in the register.php file exactly where I have access to $userinfo[field6] so I can add my code do this. And also will I have access to $userinfo[field98] which is not one of the fields the member can fill in during registration

I also need to do a similar alteration when a user edits their profile (as they may change the outcode) but I haven't got as far as looking at that yet

Rich
Reply With Quote
  #2  
Old 11-22-2010, 07:51 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
...I guess really I need to know where the code for $userdata->set() is before i could answer that myself, which is what I am asking here
$userdata is an object of class vB_DataManager_User. If you look near the beginning of register.php you see that $userdata comes from a call to datamanager_init() which is in includes/functions.php. Essentially it's the result of a "new vB_DataManager_User()'. The code for class vB_DataManager_User is in includes/class_dm_user.php, and since it extends class vB_DataManager, some relevant code will be in includes/class_dm.php.

I believe set() sets a property in the object, and a later call to save() will actually write stuff to the database (and I believe presave() is called when all the set()'s are doen but before the actual database write). There might be info somewhere else on the site about using data managers but I don't know offhand where.

In case you're not familiar with object oriented stuff it's probably worth reading over this section of the php manual: http://us2.php.net/manual/en/language.oop5.php


Quote:
Also what exactly is GPC() it crops up a lot but I have never really understood it (or had the need to yet)
GPC is an array of the "cleaned" values input to the script from get (params on the url), post (form data), and cookies. Again looking at the top of register.php you see calls to clean_gpc, this takes the specified input values and makes sure they are of a specified type (for example if it's supposed to be an integer it makes sure the value is all digits, etc), then inserts it the in the GPC[] array. The code for that is in includes/class_core.php, in class vB_Input_Cleaner.

Quote:
Now this fetch_hook thing is something that has me totally puzzled.
fetch_hook() is part of the plugin system. If you add a plugin (in the admin control panel) using hook location 'register_addmember_process', then the code you enter will be returned by the call to fetch_hook('register_addmember_process') and the eval will "run" it, so that it's as if the code was in the file at that point. It's nice to be able to do modifications entirely through hooks because then you don't modify the php files and updating to a new version of vB becomes a whole lot easier.
Reply With Quote
  #3  
Old 11-22-2010, 08:38 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi

And thanks for that it does clear some stuff up for me. I am not brilliant with OOP (I think it just kinda clouds the issue rather than just getting on with it) but I do understand the principles of it.

Now let's see

What I am trying to do here is take a value the member inputs at registration (the outcode - which is the UK postcode minus the last three digits and specifies the area they live in)

This value gets stored on my site in $userinfo[field6] during the normal registration process

I need to add some code so I can look up this outcode in the database (in my custom postcodes file) and then write the returned value (the city or county) to $userfield[field98] - which the user can not edit directly.

This ensures I guess, amongst other things, that the always get the same city/county for entering the same outcode.

Are you saying I could add the code I need in a 'plugin' and then this would be evaluated as part of the register_addmember_process hook instead of editing the register.php itself? I never even thought of doing it that way (or even knew I could!) as like I say I am a beginner at php and even more so at VB so I just dive in at the deep end and start editing files. Or maybe that's the electronics engineer in me coming out - I understand the low level stuff far better than the layers built upon it!

However I do see what you mean about the advantage of adding mods using the plugin system - in fact it's quite a relevation to me now you explained it . I don't know if you have looked at my site (yeah it is an adult one as we ourselves are swingers which may explain why I don't spend so much time coding as there are other 'things' to do lol)

A lot of stuff was already done by someone I payed to work on the site previously (and a lot of the mess I am trying to clear up now since they did a runner on me!) but as things stand it does restrict me from upgrading to VB4 at the moment due to the amount of modified php files I have

Having said that I do believe I am doing a lot with VB it was never really intended to do - like my site is of a more social (often physically!) networking site than a forum - so if you don't mind the adult content please feel free to take a look at what I have done with it

Rich

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

Oh and PS - now you explained all that hook malarky - like everything else I discover about VB - once it is explained to me, the resulting answer is always elegant
Reply With Quote
  #4  
Old 11-22-2010, 09:15 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
Are you saying I could add the code I need in a 'plugin' and then this would be evaluated as part of the register_addmember_process hook instead of editing the register.php itself?
Yes, but if your register.php is already modified it might not be so important to do it that way. And some things just can't be done that way because of course there's a limited number of hooks and sometimes they're just not in the right places.

I haven't studied register.php that closely so I don't know off the top of my head where you should put your code. Maybe someone else who does will read this. But if you think you still need help figuring it out I could look at it.
Reply With Quote
  #5  
Old 11-23-2010, 08:43 PM
richy96's Avatar
richy96 richy96 is offline
 
Join Date: Apr 2008
Location: England
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK thanks for that - I'll have a go (one factor I worry about is whether the $userfield[field98] will be actually written to the database - as it is not an 'user editable' field as I added it in the ACP - but then I guess the worse that could happen is the locations don't get saved

So I'll have a play and let you know how I get on. Thanks for the info

Rich
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 11:18 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03739 seconds
  • Memory Usage 2,226KB
  • Queries Executed 13 (?)
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
  • (7)bbcode_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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