Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Prev Previous Post   Next Post Next
  #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
 

Thread Tools
Display Modes

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:41 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.12440 seconds
  • Memory Usage 2,404KB
  • 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
  • (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)showthread_list
  • (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_threadedmode.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_threaded
  • showthread_threaded_construct_link
  • 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