Lampwrights Forum > Other Stuff > vBulletin Talk
Register Community Today's Posts Search

Reply
 
Thread Tools
02-23-2012, 05:25 PM   #1
Jeff
Administrator
 
Jeff's Avatar
 
Join Date: Jul 2010
Posts: 402
Rep Power: 10
Jeff is getting browny points
Including global.php in a function

It is not easy including vbulletins global.php file inside a function or method. I have tinkered around with it a bit and found some ways to do it:

PHP Code:
$cwd getcwd();

chdir('/PATH/TO/VB');

define('THIS_SCRIPT','SOMESCRIPT');

define('DISABLE_HOOKS',true);

$_COOKIE = array();

define('VB_AREA','Forum');

require_once(
'./includes/init.php');

$GLOBALS['vbulletin'] = $vbulletin;

include_once(
'./global.php');

chdir($cwd); 
Now the above code will work but it will not have any userinfo data nor will any of the plugins in vb be activated during the session. The main reason this is, is because $vbulletin is declared in init.php and cannot be globalized without editing the source code.

Now there are two ways around this. First, you could create a plugin at the init_startup hook with these contents:

PHP Code:
$GLOBALS['vbulletin'] = $vbulletin
But you have to make absolutely certain that it is the FIRST plugin to run at that hook. Nothing else can come first.

Then your function can look like this:

PHP Code:
$cwd getcwd();

chdir('/PATH/TO/VB');

define('THIS_SCRIPT','SOMESCRIPT');

define('VB_AREA','Forum');

require_once(
'./includes/init.php');

$GLOBALS['vbulletin'] = $vbulletin;

include_once(
'./global.php');

chdir($cwd); 
Now this is fine, but you always have to worry about that plugin. Another way, is to make a copy of your global.php and init.php file and then edit them for your instance.

Make this the first line in global.php copy (after the <?php):

PHP Code:
$cwd getcwd(); 
Then change the line that defines DIR to this:

PHP Code:
define('CWD''/PATH/TO/FORUM');  ## Might want to use a constant or variable here 
Then replace the require for init.php to:

PHP Code:
require_once('/PATH/TO/COPY/OF' '/init.php');

chdir($cwd); 
Then in the init.php copy, make these your first two lines:

PHP Code:
$cwd getcwd();

chdir('/PATH/TO/FORUM'); 
Then your function can look like this:

PHP Code:
            define('THIS_SCRIPT','SOMESCRIPT');
            
            include_once(
'/PATH/TO/COPY/Of' '/global.php'); 
There ya go, three ways to do it.
Jeff is offline   Reply With Quote

Reply

Tags

vbulletin code

,

vbulletin integration

,

vbulletin other

,

vbulletin plugins



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert WP Authors function give me error wacnstac vBulletin Wordpress Bridge 3 09-26-2011 10:08 AM
Warning: call_user_func_array() [function.call-user-func-array] MrBoombastic vBulletin Wordpress Bridge 3 06-06-2011 07:11 AM


All times are GMT -4. The time now is 03:22 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2024, vBulletin Solutions, Inc.