View Full Version : Problem with use of plugins and variables
jfxcube
12-27-2011, 05:26 PM
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:
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
vB_Template::preRegister('footer',array('google_an alytics ' => $google_analytics));
and i recalled my variable inside the template with
{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:
// 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
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.
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
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
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
Lynne
12-29-2011, 04:03 PM
This is not valid:
<vb:if is_array ($navbits) >
You would want something like:
<vb:if condition="is_array($navbits)" >
https://www.vbulletin.com/docs/html/functions_in_conditionals
jfxcube
12-29-2011, 06:31 PM
This is not valid:
<vb:if is_array ($navbits) >
You would want something like:
<vb:if condition="is_array($navbits)" >
https://www.vbulletin.com/docs/html/functions_in_conditionals
yes of course was <vb:if condition="is_array($navbits)" > just i ate the condition and some quote while i wrote on here,sorry. That conditional give me always false.
$navbits is set by each script after global.php is included, so you'll have to figure out some other way to handle it.
jfxcube
12-30-2011, 11:10 AM
someone has some idea why when i try to change some stylevars value with stylevars editor it does not work at all.
When i try to change forumbits border, for example, if i change the colorof the border, the width is automatically set to 0 and no way to set a different value
only thing is to revert the stylevar ((stylevarid: forumbits_border), same if i try to set a different width the width is set to 0.
And that's happen for a lot of other stlevar especially when i try to change border or font.
Can someone please tell me if it s a terrible bug cause it's getting really annoying.
vB 4.1.9
Thanks a lot
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.