vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   What is the time variable? (https://vborg.vbsupport.ru/showthread.php?t=244745)

Jeremy8 06-16-2010 06:35 PM

What is the time variable?
 
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...

PHP Code:

<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

Quote:

Originally Posted by Jeremy8 (Post 2054649)
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(). You use vbtime and vbdate to see what it is in text form. Or you can use plain old php date().

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

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:

Code:

$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.


All times are GMT. The time now is 09:21 AM.

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.01045 seconds
  • Memory Usage 1,738KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)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