PDA

View Full Version : Using Variables outside vBulletin


ScottC2105
04-19-2009, 11:46 AM
I'm having some issues using variables outside vbulletin. For the username I'm using $vbulletin->userinfo['username'] which is fine. Now, for notifications I'm using $notifications_total which works outside of vBulletin but for some reason this variable doesn't work when I include a php file in the header of vBulletin it is just "blank".

Is there anyway around this? Also, I am using $pmbox['lastvisitdate'] to show the last time a user visited outside vBulletin which, again, is fine but again, on vBulletin it is "blank".

Can anyone help me with this?

Thanks very much!

snakes1100
04-19-2009, 12:12 PM
You would get a better and most likely a faster answer by posting in the right forum.

https://vborg.vbsupport.ru/forumdisplay.php?f=15

ScottC2105
04-19-2009, 12:13 PM
You would get a better and most likely a faster answer by posting in the right forum.

https://vborg.vbsupport.ru/forumdisplay.php?f=15

Could someone move this then please?

Lynne
04-19-2009, 03:35 PM
Moved to Programming Discussions.

I don't understand when you say you are using things "outside vbulletin". Did you create some new page for your site? And did you include global.php at all? Did you follow something like this article - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009) You can only use a variable if it's been defined. And some variables are only defined for some specific pages. So, you would need to include the code in your page in order to use some of them.

ScottC2105
04-19-2009, 07:03 PM
Moved to Programming Discussions.

I don't understand when you say you are using things "outside vbulletin". Did you create some new page for your site? And did you include global.php at all? Did you follow something like this article - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009) You can only use a variable if it's been defined. And some variables are only defined for some specific pages. So, you would need to include the code in your page in order to use some of them.

Right I have managed to do it. Now I need to get the first post from threads in one particular forum that i am using for news, limit it to 500 characters and show it on my homepage. Maximum of 10 posts. Any idea where I start?

Lynne
04-19-2009, 08:09 PM
Start by searching for a modification that does something similar to what you want and then modifying it to do what you need. Or, find a the queries in the existing vb code and modify it to do what you want.

ScottC2105
04-19-2009, 11:04 PM
I've been looking everywhere. I just can't seem to get $notifications_total to work in the header template of my vbulletin skin. $notifications_total works outside vbulletin now but not in the healer of my skin.

Lynne
04-20-2009, 12:08 AM
I would guess it hasn't been defined prior to you evaling your header template. It's too hard to tell with such vague descriptions of what you have done.

ScottC2105
04-20-2009, 12:12 AM
I would guess it hasn't been defined prior to you evaling your header template. It's too hard to tell with such vague descriptions of what you have done.

I have moved the notifications_total code to my header template on my vbulletin skin and as you said I dont think it has been defined yet. Is there anyway around this?

Lynne
04-20-2009, 12:15 AM
The way around it is to move the code to a spot prior to the header being evaled, or move the notifications back to the navbar template.

ScottC2105
04-20-2009, 12:49 AM
"spot prior to the header being evaled" - Which template bit would that be?

Lynne
04-20-2009, 03:02 AM
You don't put php code in templates. So, you would have to copy the code that creates $notifications_total into a plugin, or into the actual page (if you can't find a good hook location) to a spot that is prior to the header template being evaled. I believe the $notifications_total is defined in global.php, so you can copy the code from there.

ScottC2105
04-20-2009, 10:43 AM
You don't put php code in templates. So, you would have to copy the code that creates $notifications_total into a plugin, or into the actual page (if you can't find a good hook location) to a spot that is prior to the header template being evaled. I believe the $notifications_total is defined in global.php, so you can copy the code from there.

I've copied the code (not sure if I an post it here) and made ther hook global_start and it still isn't working. What am I doing wrong?

Lynne
04-20-2009, 02:06 PM
In looking at global.php, you shouldn't have even had to copy the code. It looks like the header template is evaled right after the code (just a few lines later). If it isn't showing up, then there is something else going on. Either there are no notifications, or some other error is causing problems. Check your error_logs and see if anything is showing up there. Otherwise, I'm not sure what else to suggest.

ScottC2105
04-20-2009, 07:26 PM
In looking at global.php, you shouldn't have even had to copy the code. It looks like the header template is evaled right after the code (just a few lines later). If it isn't showing up, then there is something else going on. Either there are no notifications, or some other error is causing problems. Check your error_logs and see if anything is showing up there. Otherwise, I'm not sure what else to suggest.

I see what you mean, it does work. I am using the plugin system to include a custom login box .php file I have made and inserting it in the header. Now, if this file is on any other page but a vBulletin one it shows $notifications_total fine. If it is included using the plugin system into my vbulletin skin $notifications_total doesn't work in my php file but it does in the template header.

I am using global_start hook for the plugin. Am I doing something wrong?

Lynne
04-20-2009, 07:32 PM
We went through a strange issue a week or so ago where plugins weren't getting parsed on external pages. The solution for that was here (https://vborg.vbsupport.ru/showpost.php?p=1788960&postcount=17). I'm not sure if that would help out here cuz I never did go research exactly what was going on, but at this point it might be worth a shot.

ScottC2105
04-20-2009, 08:22 PM
We went through a strange issue a week or so ago where plugins weren't getting parsed on external pages. The solution for that was here (https://vborg.vbsupport.ru/showpost.php?p=1788960&postcount=17). I'm not sure if that would help out here cuz I never did go research exactly what was going on, but at this point it might be worth a shot.

If I add that code to my plugin or php file I get:

Warning: mysql_query(): 7 is not a valid MySQL-Link resource in [path]/includes/class_core.php on line 408 :(. I'm not trying to run a plugin on an external page I 'm trying to include my php file in the header template of vbulletin which contains $notifications_total in it. It works outside vB but in vB it doesn't work.

Lynne
04-20-2009, 08:39 PM
OK, I'm not understanding something.... when you talk about the header template, you are talking about the regular vb header template, right? Not a special header template you wrote for another page. And in the header template, you have written the word "$notifications_total" that is giving the total in your vb pages but not your external page, right? Are you evaling the header template yourself, or is it getting evaled in the global.php file like normal?

And it sounds like you *are* trying to use a plugin to include your stuff. You said you were using the global_start plugin for your code. Is that not right? So, that is running the global_start plugin on your external page.

Perhaps you need to start posting your code, cuz I'm getting confused now with what you are doing.

ScottC2105
04-20-2009, 09:23 PM
OK, I'm not understanding something.... when you talk about the header template, you are talking about the regular vb header template, right? Not a special header template you wrote for another page. And in the header template, you have written the word "$notifications_total" that is giving the total in your vb pages but not your external page, right? Are you evaling the header template yourself, or is it getting evaled in the global.php file like normal?

And it sounds like you *are* trying to use a plugin to include your stuff. You said you were using the global_start plugin for your code. Is that not right? So, that is running the global_start plugin on your external page.

Perhaps you need to start posting your code, cuz I'm getting confused now with what you are doing.

Sorry Lynne. I have managed to get it to work by recoding my php file inside the vB header template using vBs if conditions and else etc. What was happening was, my login php file that is on all my pages shows a login box if you are not logged in. If you are logged in, it says hello and tells you if you have any current norifications. Now, this was working fine on all other pages EXCEPT for vBulletin. I used a plugin to include my login php file and the php file uses $notifications_total but for some reason, the included php file ON vBulletin pages was showing $notifications_total as "" (blank). So, I have rewritten the php file inside the header for my vBulletin template and $notifications_total works fine. The only thing is I now have a php file for my website and the same code in my header on vbulletin so if I ever want to change it I have to change my code in two places.

Thank you for all you help, much appreciated.

Lynne
04-20-2009, 10:01 PM
Glad you got it working.