vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   List of changed var/array/function names (https://vborg.vbsupport.ru/showthread.php?t=82632)

Brad 06-06-2005 10:00 PM

List of changed var/array/function names
 
A lot of things changed in 3.5 and you might find yourself lost for awhile as you figure out how to work with the new var/array/function names. This list should help you port your old 3.0.x hacks quicker, if you have anything to add to the list reply to this thread and I will edit the first post! :)

Note that some of these might not work in some parts of the new code, OOP changes a lot of things, in some cases you might be using $this-> or some other alternative to get to these.

On the front end they will work for the most part. Do remember that there are hooks littered in the 'build' functions like the one that builds postbit. For an example of working with such hooks you can check out a plug-in I released, I spend 5 minutes wondering why $post would not work until I realized I was begin an idiot!

Anyway check out the .xml file: https://vborg.vbsupport.ru/showthread.php?t=82623

Turned out I needed to use $this->post because that hook was inside of a function! Doh!

[high]The big list...[/high]

3.0.x version of the var will be on the left, 3.5 on the right as so:

3.0.x => 3.5

[high]Global[/high]

$DB_site-> => $db->
$bbuserinfo[] => $vbulletin->userinfo[]
$vboptions[] => $vbulletin->options[]
$_GET/$_REQUEST/$_POST/$_COOKIE => $vbulletin->GPC[]
globalize() => $vbulletin->input->clean_array_gpc()

Colin F 06-07-2005 04:12 PM

$DB_site->query(); => $db->query_read();

Andreas 06-07-2005 04:22 PM

Hmm ... not always.
Only for SELECT.
For REPLACE/UPDATE/INSERT it would be query_write(), to support mySQL 4.1 Master/Slave.
To keep compatibility, query() is also available and will call the correct connection.

Brad 06-08-2005 12:51 AM

Yea I'll need to add that one, will cause alot of questions when this goes public, thanks guys and keep adding them as you find them :)

Wayne Luke 06-08-2005 03:50 PM

The following was written by Kier for the developers. He has agreed to release it here.


Variables in the $vbulletin (vB_Registry) class


Just about all the variables that used to get set up by init.php have now been migrated to the $vbulletin class.

When migrating the old code, I don't want to see this sort of thing unless there's a specific reason for it:
PHP Code:

function foo()
{
    global 
$forumcache$vbulletin$vboptions;

    
$forumcache =& $vbulletin->forumcache;
    
$vboptions =& $vbulletin->options;

    foreach (
$forumcache AS $forumid => $forum)
    {
        if (
$vboptions['something'])
        {
            
// do stuff
        
}
    }


Rather, the code should look like this:
PHP Code:

function foo()
{
    global 
$vbulletin;

    foreach (
$vbulletin->forumcache AS $forumid => $forum)
    {
        if (
$vbulletin->options['something'])
        {
            
// do something
        
}
    }


Database

The MySQL database class has been totally rewritten, and the object is now called $db, rather than the old $DB_site.

You can also reference the database object via $vbulletin->db, so there is no real need to put $db into the list of globals in functions.
PHP Code:

function foo()
{
    global 
$vbulletin;

    
$items $vbulletin->db->query_read("SELECT * FROM " TABLE_PREFIX "user");
    while (
$item $vbulletin->db->fetch_array($items))
    {
        
// do stuff
    
}
    
$vbulletin->db->free_result($items);


Outside of function scope however, continue to use $db rather than $vbulletin->db.

Whereas we used to have a single $DB_site->query() function to run SQL queries, there are now three public functions to execute SQL. They are:

$db->query_read
Use this function to execute SELECT and SHOW queries only. If the user is using MySQL replication, these queries will execute on their slave server.
PHP Code:

$db->query_read("SELECT * FROM customer WHERE clue > 0"); 

$db->query_write
Use this function to execute UPDATE, ALTER and all other data-modifying queries. query_write() will execute on the master server in a replication situation.
PHP Code:

$db->query_write("UPDATE customer SET description = 'Clueless' WHERE clue <= 0"); 


addslashes() and addslashes_like() should be dropped in query strings, as it's problematic for some non-MySQL systems. Right now, the correct way to replace these functions is to use the newly defined functions in the database class, like this:
PHP Code:

$item $db->query_first("
    SELECT * FROM table
    WHERE foo = '" 
$db->escape_string($foo) . "'
    AND bar LIKE('%" 
$db->escape_string_like($bar) . "%')
"
); 

Please also note that when escaping quotes for Javascript strings, you should no longer use 'addslashes()', but rather use 'js_addslashes()'.

Datastore

All items from the datastore now get fed directly into the $vbulletin class.
They become $vbulletin->itemname.

If their title is in the $unserialize array in the datastore class, they will be automatically unserialized when they are fetched.

Note that the code currently has a lot of code that is equivalent to
PHP Code:

if (isset($datastore_item)) 

That will not work any more, as the datastore item variables are initialized with the datastore class.

Therefore, instead of checking 'isset' you will need to check
PHP Code:

if ($vbulletin->datastore_item !== null

Bitfields

The old $_BITFIELDS, $_FORUMOPTIONS, $_USEROPTIONS etc. arrays no longer exist as individual entities. They are now part of the $vbulletin data registry object and go by different names. All the data they contained is still there, but you'll need to talk to them differently.

If you look at the top of includes/class_core.php I have left a 'translation lookup table' so that it's easier to see where the data you are looking for has gone.

To avoid too much $object->array[key1][key2][key3][key4] stuff, there are references set up to allow you to talk to deep elements quickly. For example, $vbulletin->bf_ugp_adminpermissions is a reference to $vbulletin->bf_ugp['adminpermissions']... it makes more sense when you start using them

Oh... 'ugp' stands for usergroup permissions.

vB_Input Class

If you read includes/class_core.php, you'll notice that there's a class called vB_Input. This class deals with input into vBulletin and stuff that's related to the superglobal arrays ($_REQUEST, $_ENV, $_SERVER etc.)


Misc


As lots of variables have been shuffled around, you'll need to keep your eyes open for them. For example, $scriptpath is now $vbulletin->scriptpath and $nozip is now $vbulletin->nozip.

I strongly suggest that you read and familiarize yourself with the new init.php and the contents of includes/class_core.php before diving in.

Revan 06-09-2005 07:51 PM

Thank you for this update, Wayne. It helped me answer my question about query_read vs query_write :)
[Removed question as more indepth studies of the files answered it]

Andreas 06-09-2005 08:00 PM

You can use query_first() as this basically does the same as query_read() and fetch_array().

Brad 06-09-2005 09:07 PM

You can also use the old school query();, but it preforms a preg call to check for the query type (SELECT = read, everything else = write). Really you should not use query(); anymore, but there is nothing stoping you from doing it ;)

Revan 06-09-2005 09:17 PM

Ah I see, thanks :)
I really wish they didn't add support for the old query(), this will only lead to lazy coders writing shi'ite stuff that keeps using these old, outdated versions, forcing vB to sacrifice performance in order to determine the correct function which again leads to a performance hit. :(.
I guess this means I will have to be more selective and conservative with the stuff I install, as I like things running fast and smooth :)

AN-net 06-09-2005 09:36 PM

god everything i have worked for has to be rewritten, damn u!!!!

also is $vbulletin->bbuserinfo[] now used in templates and where is official vbulletin.com documentation?

Andreas 06-09-2005 09:52 PM

Quote:

god everything i have worked for has to be rewritten, damn u!!!!
That was to be expected :)

As far as I can see $bbuserinfo/$vboptions/$session is being unsed in the Templates.
But I am not sure if this will be changed.

Zachery 06-09-2005 10:14 PM

Quote:

Originally Posted by AN-net
god everything i have worked for has to be rewritten, damn u!!!!

also is $vbulletin->bbuserinfo[] now used in templates and where is official vbulletin.com documentation?

No, the old way still works in the templates.

Zero Tolerance 06-09-2005 11:32 PM

if you're not in the mood to re-write all the variables, you can put stuff like:

$bbuserinfo = $vbulletin->userinfo;
unset($vbulletin->userinfo);

At the top of your files (after you've included the files you require), ofcourse if your embedding code into an existing vB 3.5 php file, like forumdisplay, i wouldn't use the unset function.

It's a quick and easy method, until you get time to properly convert everything :)

- Zero Tolerance

Andreas 06-09-2005 11:33 PM

*cough* functions_legacy.php, enable_legacy() *cough*

Zero Tolerance 06-09-2005 11:36 PM

Quote:

Originally Posted by KirbyDE
*cough* functions_legacy.php, enable_legacy() *cough*

Or that will do too :p I really need to look through the files more.

- Zero Tolerance

calorie 06-10-2005 12:03 AM

Quote:

Originally Posted by KirbyDE
That was to be expected :)

As far as I can see $bbuserinfo/$vboptions/$session is being unsed in the Templates.
But I am not sure if this will be changed.

Can the new way also be used, and if so, what way?

Andreas 06-10-2005 12:11 AM

I doubt so. But to get a definitive answer you should ask the developers :)

calorie 06-10-2005 12:53 AM

Quote:

Originally Posted by KirbyDE
I doubt so. But to get a definitive answer you should ask the developers :)

See this vB 3.5.0 mod, and look at the attached TXT file in that thread. It has <if condition="$vbulletin->userinfo['userid'] != '0' AND... in it, so is it that conditions use the new way, but things to be echoed use the old way, or ???

Zachery 06-10-2005 12:58 AM

Quote:

Originally Posted by calorie
See this vB 3.5.0 mod, and look at the attached TXT file in that thread. It has <if condition="$vbulletin->userinfo['userid'] != '0' AND... in it, so is it that conditions use the new way, but things to be echoed use the old way, or ???

In a conditional, which is executed as raw php code. I could have used $bbuserinfo but I prefered to update and use the new code.

calorie 06-10-2005 01:05 AM

Quote:

Originally Posted by Zachery
In a conditional, which is executed as raw php code. I could have used $bbuserinfo but I prefered to update and use the new code.

Okay, good, but what about vars in templates that just sit there to be echoed? New way or old way? If old, any hint as to what method (new vs. old) will be used in vB 3.5.0 final?

noppid 06-10-2005 04:57 AM

Very good explainations, thanks.

Logikos 06-10-2005 06:03 AM

When using something like this for an example:

PHP Code:

$db->query_write("UPDATE thread SET open = '0' WHERE threadid <= 99"); 

That obviously will close a threadID 99. My question is. Do we have to use the TABLE_PREFIX before we define the table to update?

Cap'n Steve 06-10-2005 06:13 AM

What's the reason for changing the $_GET, $_POST, etc.? Is there any benefit to using the new versions?

Zachery 06-10-2005 08:27 AM

Quote:

Originally Posted by Cap'n Steve
What's the reason for changing the $_GET, $_POST, etc.? Is there any benefit to using the new versions?

Security

calorie 06-10-2005 06:52 PM

Quote:

Originally Posted by Live Wire
When using something like this for an example:

PHP Code:

$db->query_write("UPDATE thread SET open = '0' WHERE threadid <= 99"); 

That obviously will close a threadID 99. My question is. Do we have to use the TABLE_PREFIX before we define the table to update?

I found $db->query_write("UPDATE " . TABLE_PREFIX . " in vB 3.5.0 code, so I'd guess yes.

Erwin 06-10-2005 10:58 PM

Quote:

Originally Posted by Zachery
Security

Absolutely. You'd be surprised how many older hacks still use these variables without checking them.

Revan 06-10-2005 11:42 PM

Then again, as far as I can see theres nothing stopping a lazy coder from just using the superglobals.

Cap'n Steve 06-11-2005 04:44 AM

Quote:

Originally Posted by Erwin
Absolutely. You'd be surprised how many older hacks still use these variables without checking them.

Ah, ok. So what does this class actually do to the variables? Is it basically a replacement for globalize()?

Brad 06-11-2005 05:18 AM

Quote:

Originally Posted by Cap'n Steve
Ah, ok. So what does this class actually do to the variables? Is it basically a replacement for globalize()?

Basicly yes :)

zetetic 06-12-2005 04:24 AM

In 3.0.7 I put this code in phpinclude_start:
PHP Code:

$buddyarray explode(' '$bbuserinfo['buddylist']); 

And referenced that array using $GLOBALS['buddyarray'] in the templates.

In 3.5 I made a global_start plugin using this code:
PHP Code:

$buddyarray explode(' '$vbulletin->userinfo['buddylist']); 

But $GLOBALS['buddyarray'] doesn't seem to work.

Also the u=$userinfo[userid] doesn't seem to work in the postbit either. :ermm:

tamarian 06-12-2005 01:57 PM

Thanks for the how-to's :up:

I needed to use $session outside the templates, it's now:

$session => $vbulletin->session->vars

noppid 06-12-2005 02:57 PM

Quote:

Originally Posted by tamarian
Thanks for the how-to's :up:

I needed to use $session outside the templates, it's now:

$session => $vbulletin->session->vars

That syntax you used may be confusing. It took me about 3 minutes to catch your drift. I see now that you were making a relation though. But here's what the new one looks like for the other folks.

$vbulletin->session->vars['sessionurl']

tamarian 06-12-2005 03:10 PM

Quote:

Originally Posted by noppid
That syntax you used may be confusing.

It shouldn't be :) That's the syntax suggested by the first post, left to right.

noppid 06-12-2005 03:19 PM

Quote:

Originally Posted by tamarian
It shouldn't be :) That's the syntax suggested by the first post, left to right.

Sorry I tried to help. Perhaps I should just shut up. :/

I was not trying to start an argument.

tamarian 06-12-2005 03:32 PM

Quote:

Originally Posted by noppid
Sorry I tried to help. Perhaps I should just shut up. :/

I was not trying to start an argument.

Me neither. My post was not meant to offende you, and if it did, I apologize. I just meant that was the syntax used by Brad in his first post. Anyway, between the both of us, we may have actually helped someone. :)

sabret00the 06-14-2005 08:06 AM

what is the new array for $userinfo (not $bbuserinfo)

Colin F 06-14-2005 08:20 AM

Quote:

Originally Posted by sabret00the
what is the new array for $userinfo (not $bbuserinfo)

That's the one that's used on the members profile and so, right?

I just checked the memberinfo template, and it hasn't changed there...

zetetic 06-14-2005 01:38 PM

Yeah, I mentioned that u=$userinfo[userid] wasn't working in the postbit a few posts ago. I think we might have to wait for the documentation to find out all the new conditionals.

tamarian 06-14-2005 02:03 PM

userinfo is not a global variable like bbuserinfo. So it won't be part of the new $vbulletin object and other globals. The variable name for userinfo will be different depending on the script or template being edited.

zetetic 06-14-2005 02:38 PM

Quote:

Originally Posted by tamarian
userinfo is not a global variable like bbuserinfo. So it won't be part of the new $vbulletin object and other globals. The variable name for userinfo will be different depending on the script or template being edited.

Thanks for the info, tamarian. I'll just use $post[userid] in the postbit instead. :)

Do you have any idea how I can solve this problem? Is there a replacement for $GLOBALS?


All times are GMT. The time now is 11:02 AM.

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.03142 seconds
  • Memory Usage 1,865KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (12)bbcode_php_printable
  • (18)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete