View Full Version : What is the time variable?
Jeremy8
06-16-2010, 06:35 PM
Here's an example of what I'm trying to do.
<vb:if condition="$time==1">stuff to do here</vb:if>
So it will do something at a certain time.
I just made "$time==1" up... I'm trying to figure out what goes there. Can anyone help?
noppid
06-16-2010, 07:13 PM
The vB constant for the time is...
<vb:if condition="TIMENOW==1">stuff to do here</vb:if>
Jeremy8
06-16-2010, 07:22 PM
What do I put where the 1 is? I'm not sure what TIMENOW looks like.
For example, what if I want 6:00 AM?
noppid
06-16-2010, 07:28 PM
What do I put where the 1 is? I'm not sure what TIMENOW looks like.
For example, what if I want 6:00 AM?
TIMENOW is a 10 digit number derived from php time() (http://us.php.net/manual/en/function.time.php). You use vbtime and vbdate to see what it is in text form. Or you can use plain old php date() (http://us.php.net/manual/en/function.date.php).
It's in seconds. So to get an hour ago, minus 3600. To go an hour in the future, add 3600.
Maybe this will help Free Tool: Convert Unix Time Stamps To Readable Time and Date (http://www.cpurigs.com/forums/showthread.php?t=4262&highlight=unix+time)
Jeremy8
06-16-2010, 07:52 PM
So what exactly do I make condition equal to if I want
6:00 AM
or 8:00 PM
etc
noppid
06-16-2010, 08:13 PM
Well, first you have to work out the users timezone if they are a member. So look at $vbulletin->options['hourdiff']
something like
$timestamp = TIMENOW - $vbulletin->options['hourdiff'];
Then you can get the hour with $hourofday = date("G", $timestamp )
Then you can work out the condition.
if ($hourofday == 6) $message = "6AM";
if ($hourofday == 20) $message = "8PM";
Jeremy8
06-16-2010, 09:56 PM
OK, well I'm doing this in my templates. I put that stuff in a plugin... but I don't really understand how plugins work.
Because then I went to my template and put <vb:if condition="$hourofday==6">stuff to do here</vb:if> and messed with the times
I also did <vb:if condition="$hourofday">test</vb:if> to see if it even existed... but $hourofday didn't have any value apparently... ?
this was my plugin:
$timestamp = TIMENOW - $vbulletin->options['hourdiff'];
$hourofday = date("G", $timestamp );
noppid
06-16-2010, 09:58 PM
Try:
$hourofday = intval(date("G", $timestamp ));
I've seen that resolve a similar situation.
Of course, it has to be 6 am to work too.
Jeremy8
06-16-2010, 10:48 PM
Actually, I'm seeing now that it works as a plugin alone. But what I don't understand is how I take that variable from the plugin and use it as the condition for my if-statement in the template.
noppid
06-17-2010, 12:15 AM
Post your code so we can see where you are.
Jeremy8
06-17-2010, 12:22 AM
OK, I was just testing it out on forumhome. I don't really know how hook locations work, but I knew forumhome_start would work for my template in forumhome (I thought so).
The following code, though, works.
$timestamp = TIMENOW - $vbulletin->options['hourdiff'];
$hourofday = date("G", $timestamp );
if ($hourofday == 6) $message = "6AM";
if ($hourofday == 19) $message = "7PM";
$template_hook['forumhome_above_forums'] .= $message;
But I don't want to do that exactly. I was trying to do it with the condition in a template's if-statement as I said. So this is what I tried:
My plugin with hook location forumhome_start:
$timestamp = TIMENOW - $vbulletin->options['hourdiff'];
$hourofday = date("G", $timestamp );
Then in my template:
<vb:if condition="$hourofday==19">stuff to do here</vb:if>
(it was 7PM when I tried it. It's not a problem with the time though, because I also checked if the variable had any value at all and it didn't.)
What I'm really trying to do is change the background (CSS) depending on the time of day. There might be an easier way than the templates... I just don't exactly understand how plugins work because I'm still new to vB.
noppid
06-17-2010, 01:24 PM
Did you register $hourofday?
$templater->register('hourofday', $hourofday);
Boofo
06-17-2010, 01:32 PM
Doesn't he have to make that global since he is not rendering any templates?
Jeremy8, Take a look at this hack and it will give you an idea of how to do what you are wanting to do.
https://vborg.vbsupport.ru/showthread.php?t=244519
noppid
06-17-2010, 02:29 PM
His question specifically is that when the uses "his" template, the var don't work. The first example was to prove his logic where he tagged it to an existing template hook var.
So where I see the problem is in rendering his template and registering his vars.
Boofo
06-17-2010, 02:33 PM
Ok, I must have misunderstood. I thought he was just adding it to an already rendered template. I'll let you handle it then, sir. ;)
noppid
06-17-2010, 02:40 PM
No problem I read that post twice last night, didn't reply, then read it again a few times before I answered again this morning. I even mocked up some code to make sure I made sense. But if we get him going, we'll have done good.
Jeremy8
06-17-2010, 04:16 PM
Well I think I have not been so clear about what I'm trying to do lol.
I was really just testing the time stuff out with that code I posted in my previous post.
So let me say what I'm really trying to do, and then you could maybe put me in the right direction. Because I don't really know what approach to take. Plugins? Templates? CSS? Xml thingies... lol idk.
Anyway, what I'm trying to do is have the background of one of my styles change according to the time (hour of day). Do I make a plugin at one of the CSS hook locations? I don't know...
edit: I've moved on to this topic: https://vborg.vbsupport.ru/showthread.php?t=244834
Thanks for the info.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.