Lampwrights Forum

Lampwrights Forum (http://www.lampwrights.com/index.php)
-   vBulletin Talk (http://www.lampwrights.com/forumdisplay.php?f=12)
-   -   Including global.php in a function (http://www.lampwrights.com/showthread.php?t=298)

Jeff 02-23-2012 05:25 PM

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. :)


All times are GMT -4. The time now is 02:05 PM.

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