PDA

View Full Version : Failing to include PHP files into a hook


Galenorn
04-18-2013, 11:52 PM
I?m trying to set up the forums at my site and I need to include a few php files into the header, at the top of the vBulletin site, right after the <BODY> tag.

I?ve read https://vborg.vbsupport.ru/showthread.php?t=248309&highlight=include+php over and over, but it won?t register any variables.

Here is what I did:

I created a Plugin:

//#### Begin Plugin ####
ob_start();
// Included file is located one directory from the Forums, and in another directory
include("../AnotherDirectory/IncludeThisFile.php");
$includephp = ob_get_contents();
ob_end_clean();
// The 'header' template is where I want to output the files
vB_Template::preRegister('header', array('includedphp ' => $includedphp));
//#### End Plugin ####

I used a variety of hook locations. I?m positive it is correct.
For this, I used 'forumhome_start' and 'global_bootstrap_start', and I got the same results.

Then I went to the 'header' template, and at the top I added:
{vb:raw includephp}

However, when I run the forums, the additional PHP content doesn't appear.

So, I altered the Plugin:

//#### Begin Plugin ####
ob_start();
// Included file is invalid
include("../AnotherDirectory/InvalidFileDoesNotExist.php");
$includephp = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header', array('includedphp ' => $includedphp));
//#### End Plugin ####

When I run the forums again, I get a PHP error message, saying file not found.
Therefore, I concluded that the first plugin code is fine.

So, I altered the Plugin to something simple:

//#### Begin Plugin ####
$includephp = ?<p>Hello</p>?;
vB_Template::preRegister('header', array('includedphp ' => $includedphp));
//#### End Plugin ####

When I run the forums again, additional content doesn't output.
I can?t find 'Hello' on the page.
So, now I edited the 'header' template, and entered at the top:
<p>Hello</p>

When I run the forums again, '<p>Hello</p>' is outputted on the top of the page before anything else is generated.
Therefore, I concluded that I need to register the variable in the hook.
Where do I register variables? Am I even doing it right?
I have been spending several days trying to get this to work, and nothing.
And yes, I explicidly followed the instructions on the forums, and nothing.

Samwise Galenorn

Lynne
04-19-2013, 12:10 AM
$includephp = “<p>Hello</p>”;
vB_Template::preRegister('header', array('includedphp ' => $includedphp));

See the variable names in bold. One of them has an additional d - includedphp

Galenorn
04-19-2013, 12:31 AM
Thanks. I knew it had to be something dumb by me.

However...

Here is the plugin now:

//#### Begin Plugin ####
ob_start();
// Included file is located one directory from the Forums, and in another directory
include("../AnotherDirectory/IncludeThisFile.php");
$includephp = ob_get_contents();
ob_end_clean();
// The 'header' template is where I want to output the files
vB_Template::preRegister('header', array('includephp ' => $includephp));
//#### End Plugin ####

And I tried:

//#### Begin Plugin ####
$includephp = “<p>Hello</p>”;
vB_Template::preRegister('header', array('includephp ' => $includephp));
//#### End Plugin ####

And I still get no output either way.
Am I supposed to register the variable in the hook itself, or do I alter the actual code file?

Samwise Galenorn

Lynne
04-19-2013, 01:39 AM
This works perfectly fine for me at global_bootstrap_complete:

$includephp = "<p>Hello</p>";
vB_Template::preRegister('header', array('includephp' => $includephp));


(Stop using those directional double-quotes you keep typing. Use a plain text editor like notepad++ or bbedit if you are going to code or you will have problems.)

Galenorn
04-19-2013, 02:32 AM
Before, I did:

//#### Begin Plugin ####
$includephp = '<p>Hello</p>';
vB_Template::preRegister('header', array('includephp ' => $includephp));
//#### End Plugin ####

I put into the array variable 'include ' (with a space).
I need to put into the array variable 'include' (with no space).
Corrected:

//#### Begin Plugin ####
$includephp = '<p>Hello</p>';
vB_Template::preRegister('header', array('includephp' => $includephp));
//#### End Plugin ####

(Glorious results of copy/paste of someone's code... *groan*...)

And now it works

Thank you

Lynne
04-19-2013, 02:47 PM
I'm glad you got it working. :)