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

Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2011, 08:17 PM
Dave80 Dave80 is offline
 
Join Date: Aug 2010
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Simple problem but idk how to fix it

Hello

It's very simple to explain. I want to include my custom php header on my forum so i set a plugin with global_start with this code:
Code:
ob_start();
   include('custom/header.php');
   $custom_header = ob_get_contents();
ob_end_clean();
Then i call $custom_header in template. It is not working. I can see nothing so, temporarily, i'm using
Code:
$custom_header = include('custom/header.php');
It works but, as soon as i open a single <div></div> tag in header.php all my forum become totally bugged. Oh and i also tried to ob_start in my file with this in header.php:
Code:
<? ob_start('cache_page'); ?>
<div class="blablablablablablabla"></div>
<? ob_end_clean(); ?>
Again bug is served. Any idea to fix this simple problem?

Thank you!
Reply With Quote
  #2  
Old 10-03-2011, 09:58 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe try this:

PHP Code:
ob_start();
   include(
'custom/header.php');
   
$custom_header ob_get_contents();
ob_end_clean();
vB_Template::preRegister('template_name', array('custom_header' => $custom_header)); 

(of course change 'template_name' to whatever template your want to put your custom header in.

And then in the template:

Code:
{vb:raw custom_header}
Here's an article about that: https://vborg.vbsupport.ru/showthread.php?t=228078


I don't know why the other things you posted didn't work - I learned a couple things about php just trying to figure out your code.
Reply With Quote
  #3  
Old 10-03-2011, 10:19 PM
Mooff Mooff is offline
 
Join Date: Mar 2010
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why are you using ob_start and ob_get_contents instead of file_get_contents or file?

I think it might be possible that you mess parts of the vbulletin php file up, if you use ob_end_clean in the wrong place? Not exactly sure if end_clean closed the last ob_start - or everything. And i do not think you need it if you use file() or file_get_contents() instead?

just realised you use a *.php file, then

$foo = include(YOURFILE); should have the desired effekt as long as your phpfile returns the desired value.
Reply With Quote
  #4  
Old 10-03-2011, 10:37 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm guessing the OP is using ob_start()/ob_end_clean() because the vb manual has that as an example of how to include an external file. I think the reason for doing that is if you have a php file that produces html (as opposed to returning it in a string) then with this method you don't have to make any changes to it.
Reply With Quote
  #5  
Old 10-03-2011, 10:46 PM
Dave80 Dave80 is offline
 
Join Date: Aug 2010
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm using the code published (as guide) in vB forum so the code you are "trying to figure out" is not mine Anyway now it works.

Mooff i'm using ob_start just because it was written in vB forum and the thread has been recently linked by "vBulletin Technical Support Lead" so i thought that it was good.

edit: exactly kh99. There are php and js scripts in the included file

Thanks.
Reply With Quote
  #6  
Old 10-03-2011, 10:50 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dave80 View Post
I'm using the code published (as guide) in vB forum so the code you are "trying to figure out" is not mine...
Yes, I recognized that code as the suggested way to include an external file. The code I was "trying to figure out" was the return value of an include file (which I forgot that you could do), the ob_start('cache_page') where it includes a callback function, and using the <? ... ?> short tags - all things I just didn't know without looking them up in the php manual, so I learned something.

Anyway, 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 09:28 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.05057 seconds
  • Memory Usage 2,219KB
  • Queries Executed 13 (?)
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
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (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_postinfo_query
  • fetch_postinfo
  • 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