Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-18-2013, 11:52 PM
Galenorn Galenorn is offline
 
Join Date: Apr 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Failing to include PHP files into a hook

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/showthrea...ht=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:reRegister('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:reRegister('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:reRegister('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
Reply With Quote
  #2  
Old 04-19-2013, 12:10 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$includephp = “<p>Hello</p>”;
vB_Template:reRegister('header', array('includedphp ' => $includedphp));

See the variable names in bold. One of them has an additional d - includedphp
Reply With Quote
  #3  
Old 04-19-2013, 12:31 AM
Galenorn Galenorn is offline
 
Join Date: Apr 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:reRegister('header', array('includephp ' => $includephp));
//#### End Plugin ####

And I tried:

//#### Begin Plugin ####
$includephp = “<p>Hello</p>”;
vB_Template:reRegister('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
Reply With Quote
  #4  
Old 04-19-2013, 01:39 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This works perfectly fine for me at global_bootstrap_complete:

PHP Code:
$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.)
Reply With Quote
  #5  
Old 04-19-2013, 02:32 AM
Galenorn Galenorn is offline
 
Join Date: Apr 2013
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Before, I did:

//#### Begin Plugin ####
$includephp = '<p>Hello</p>';
vB_Template:reRegister('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:reRegister('header', array('includephp' => $includephp));
//#### End Plugin ####

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

And now it works

Thank you
Reply With Quote
  #6  
Old 04-19-2013, 02:47 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm glad you got it working.
Reply With Quote
Reply


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:50 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05114 seconds
  • Memory Usage 2,214KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (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_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
  • 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