vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Problem with use of plugins and variables (https://vborg.vbsupport.ru/showthread.php?t=276081)

jfxcube 12-27-2011 05:26 PM

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

Lynne 12-28-2011 12:51 AM

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?

jfxcube 12-28-2011 07:18 AM

Quote:

Originally Posted by Lynne (Post 2281530)
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????

Lynne 12-28-2011 03:44 PM

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.

kh99 12-28-2011 04:26 PM

Quote:

Originally Posted by jfxcube (Post 2281576)
Anyway to preregister variables may i create a plugin with an appropriate hook????

You should be able to put your vB_Template::preRegister 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.

jfxcube 12-28-2011 06:53 PM

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

kh99 12-28-2011 07:11 PM

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.

jfxcube 12-28-2011 07:22 PM

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

Lynne 12-28-2011 11:40 PM

Try $GLOBALS[forumid] instead of $forumid

jfxcube 12-29-2011 02:55 PM

Quote:

Originally Posted by Lynne (Post 2281784)
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


All times are GMT. The time now is 09:06 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.01094 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete