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 01-03-2012, 09:35 PM
mrbiesheuvel mrbiesheuvel is offline
 
Join Date: Dec 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Writing a variable from a php page into a template.

If written code in an external file witch loads at init startup. I use the code for plugins. It loads an external html or php file and then splits the head and body from that file. The body is used in a plugin to any kind of template that and the head is added to the headinclude template {vb:raw head_include}. By doing so I can load every external file (php or html) into a template and create widgets to place them on the screen. Because the head of the external (html/php)file is written to the head include i can also load the css and javascript from the external file.

So this works fine with plugins -> template -> widget

PHP Code:
function load_file_for_plugin ($pathToFile) {
    
    global 
$custom_header;
    
$content get_file_content($pathToFile);
    
$head get_head_section($content);
    
$custom_header .= $head;
    
preregister("headinclude","head_include",$custom_header);
    return 
get_body_section($content);
        

Now ihave tried to create a (cms-)php page in the cms wich loads a html file into the page and also writes the head of the html file to {vb:raw head_include} template. The code of the php page looks like this:

PHP Code:
$outputload_file_for_plugin ($_SERVER['DOCUMENT_ROOT']."/custom/static_html/voorpagina.html"); 
Now the body of the external html file loads perfectly into the (cms-)php page, but the head isn't written to {vb:raw head_include}

Is there any way to write a variable from a (cms-)php page to a template using vb:raw?
Reply With Quote
  #2  
Old 01-04-2012, 02:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm...seems like it should work. Have you tried two widgets to see if it's really a cms page that's the problem? Maybe it's just the second file you load that has a problem.

Also, what does your preregister() function look like?
Reply With Quote
  #3  
Old 01-04-2012, 02:50 PM
mrbiesheuvel mrbiesheuvel is offline
 
Join Date: Dec 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There are two widget on every page active they work like a charm. The head section of the external files gets copied in the head section of vbulletin like they should.

The preregister function looks like this:

PHP Code:
function preregister ($template,$rawName,$variable){
   
vB_Template::preRegister($template,array($rawName => $variable));
    

If I look in the hooks of a debug:

init_startup
database_pre_fetch_array
database_post_fetch_array
friendlyurl_resolve_class
fetch_userinfo_query
fetch_musername
fetch_userinfo
global_bootstrap_init_start
global_bootstrap_init_complete
cache_permissions
global_state_check
global_bootstrap_complete
style_fetch
vbcms_phpeval_save_start
database_pre_fetch_row
database_post_fetch_row
vbcms_collection_content_querydata
vbcms_phpeval_save_end
vbcms_content_querydata
vbcms_phpeval_populate_start
vbcms_content_populate_start
vbcms_content_populate_end
tag_fetchbit_complete
cache_templates
template_register_var
parse_templates
notices_check_start
notifications_list
process_templates_complete
memberaction_dropdown
vbcms_phpeval_populate_end
vbcms_layout_querydata
vbcms_collection_widget_querydata
navbits
navbits_complete

vbcms_phpeval_populate_start is before parse_templates, I don't understand why the value isn'wriiten to the headinclude template on {vb:raw headinclude}
Reply With Quote
  #4  
Old 01-04-2012, 03:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I put a printout in parse_templates and found that it's actually being called twice, and I suppose that the list of hooks in the debug info just shows the latest call or something like that. And the first time it's called before the widget code is evaled, so that's probably the problem. I'm not exactly sure why you had it working for widgets, but I'd guess it's because the timing of the first call to parse_templates depends on what's on the page. I have a couple other test widgets and a php page, so one of them is probably triggering the call before it gets to the test widget I created with your code in it.

So I'm not sure how to get around that - I'm not an html expert, is there any reason the CSS and js has to go in the header?
Reply With Quote
  #5  
Old 01-08-2012, 10:18 AM
mrbiesheuvel mrbiesheuvel is offline
 
Join Date: Dec 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for your help.

The reason why I want to write the head variables form the include page in to the vbulletin page is the css link. They should officially been written into the head section.

Now I worked on a workaround but the php code get's fragile. I found that none of the browsers gives a problem when I write the html-head section of the included into the body of the vbulletin page. It gives a w3c error but that's all.

So while it's maybe not the best coding practive I think I'm going to stick with that instead of using fragile and error prone php code.

Thank you for your time and patience,
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 05:38 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03768 seconds
  • Memory Usage 2,205KB
  • 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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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