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 12-27-2011, 05:26 PM
jfxcube jfxcube is offline
 
Join Date: Dec 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem with use of plugins and variables

Hello,


i wanted to include a file inside a custom template (but the problem is for any variable defined in a plugins that i want to use in a custom template) vB version 4.1.9.

i created a new plugins called google_analytics with hooklocation global_start

that's the code of the plugins:

Code:
ob_start();
include("../google_forum.inc.php");
$google_analytics = ob_get_contents();
ob_end_clean();
echo "pippo";
echo date("Y");
(i'll explain later thereason of the 2 last lines......)

then i put in my global.php the following line

Code:
vB_Template::preRegister('footer',array('google_analytics ' => $google_analytics));
and i recalled my variable inside the template with

Code:
{vb:raw google_analytics}
but nothing has been inserted in the html source code

now the questions are:
should i use the preRegister method to have the variables correctly addressed in my templates????
where to put this code (i mean the vBTemplate........et...etc...) cause anytime i ugrade the version i overwrite almost all files such as global.php for example??
why if i comment out the line in the global.php for variable registration and i delete the declaration of the variable in my template i get always at the beginning of my html source code (and never in the place where i put the variable in the template) "pippo2011"????

Thank you and
Regards

Franco
Reply With Quote
  #2  
Old 12-28-2011, 12:51 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First off, global_start is a deprecated hook location:
Quote:
// Deprecated as of release 4.0.2, replaced by global_bootstrap_init_start
($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;
And secondly, stating you added something to global.php tells us nothing - *where* did you add it? Why didn't you use a hook to preregister it?
Reply With Quote
  #3  
Old 12-28-2011, 07:18 AM
jfxcube jfxcube is offline
 
Join Date: Dec 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
First off, global_start is a deprecated hook location:


And secondly, stating you added something to global.php tells us nothing - *where* did you add it? Why didn't you use a hook to preregister it?
i got it to work but using global_start as hook. If i change to global_bootstrap_init_start it does not work and yes, i have read the code of includes/class_bootstrap.php and there is no reason why it should not work, but if i change the hook it does not.
Anyway to preregister variables may i create a plugin with an appropriate hook????
Reply With Quote
  #4  
Old 12-28-2011, 03:44 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It is much easier to write a plugin to preregister the variables than to edit the code. But that is your choice.

You may be better off figuring out why is isn't working using the global_bootstrap_init_start rather than continuing to use global_start. global_start will disappear soon. It's been almost two years since it's been deprecated now.
Reply With Quote
  #5  
Old 12-28-2011, 04:26 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by jfxcube View Post
Anyway to preregister variables may i create a plugin with an appropriate hook????
You should be able to put your vB_Template:reRegister line at the end of the same plugin as the other code, and if you do that I'm guessing it will work using global_bootstrap_init_start.
Reply With Quote
  #6  
Old 12-28-2011, 06:53 PM
jfxcube jfxcube is offline
 
Join Date: Dec 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ty Lynne and Kh99 for the answers.
Now i got it to work..... i put all preregisters in a plugin but the funny things was that some were working and some not and just changing execution order they got to work, all but one that there is no way to make it work except putting the preregister in the global.php file with the hook global_start
i tried really everything


Ty a lot
Reply With Quote
  #7  
Old 12-28-2011, 07:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you using more than one plugin? You should be able to put everything in one plugin, especially if they're using the same hook. If you have to use different hooks for some reason then you may have to declare some variable global.
Reply With Quote
  #8  
Old 12-28-2011, 07:22 PM
jfxcube jfxcube is offline
 
Join Date: Dec 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yes i m using more plugin and the variables are all in the footer and in the same hook ; i tried to put preregistration in the same plugin like the variable declaration and assignment, as you suggested, but it did not work

ty

well i realized it's a problem of variable scope; i'm assigning to a variable the value of $forumid.... if i set in the plugin global_start as hook the variable exists and it assumes the right value... if i use global_bootstrap_init_start ashook the variable is not set or visible and is NULL.


i used global_bootstrap_complete as hook, defined the var forumid global, and put the preregister in the same plugin and nowit works but that' s really an ugly workaround. if i use global_start all works perfectly without needs of global or preregister in the same plugin; with global_bootstrap_intit_start no way to make it work whatever i tried.
there isan equivalent hook for global_start cause the one suggested is not workingat all...........

Ty
Reply With Quote
  #9  
Old 12-28-2011, 11:40 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try $GLOBALS[forumid] instead of $forumid
Reply With Quote
  #10  
Old 12-29-2011, 02:55 PM
jfxcube jfxcube is offline
 
Join Date: Dec 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Try $GLOBALS[forumid] instead of $forumid
If i use global_bootstrap_complete as hook it works with $GLOBALS[forumid] but if i change hook as global_bootstrap_init_start does not work anymore.
i think itwould be nice for variable scope keep global_start as hook............

ty a lot Lynne
may i ask u something more on this thread???

for example i need an equivalent for the conditional <if is_array($navbits)>....
if i use the vB4 version <vb:if is_array ($navbits) > it gives me always FALSE.
I need that for thebreadcrumb
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 12:46 PM.


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.06505 seconds
  • Memory Usage 2,260KB
  • 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_code
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete