vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Morning, afternoon, evening? (https://vborg.vbsupport.ru/showthread.php?t=288240)

qpurser 09-24-2012 09:50 AM

Morning, afternoon, evening?
 
In my postbit I would like to use the words "morning, afternoon or evening" depending on the time for the day. I am using postbit_legacy in vB4.

For example from 6am to 12PM I want to replace the actual time with "Good Morning", from 12pm until 4pm "Good Afternoon" and for the rest of the day "Good Evening".

What would be the the formula to calculate this and how do I store it in a variable I can use in the postbit_legacy?

Thanks for any help

kh99 09-24-2012 10:09 AM

You could do this:

Code:

$hour = vbdate('G');
if ($hour >= 6 AND $hour < 12)
{
    $greeting = "Good Morning";

else if ($hour >= 12 AND $hour < 16)
{
    $greeting = "Good Afternoon";
}
else
{
    $greeting = "Good Evening";
}
vB_Template::preRegister('postbit_legacy', array('greeting' => $greeting));

Then in postbit_legacy, use {vb:raw greeting}

This goes by the user's local time (based on the timezone they selected in their profile). If for some reason you wanted to use the server's time for everybody, you could change vbdate to just date.

I'm kind of curious why you want to put this in postbit_legacy - wouldn't that just repeat the same greeting in every post?

Edit: after posting this I noticed that the similar threads has an existing mod something like this: https://vborg.vbsupport.ru/showthread.php?t=178745

qpurser 09-24-2012 10:56 AM

Thanks so much for your quick reply. Without people like you many of the newbies would be lost in their attempts to make their forums a little more personal and individual.

You were right it would be silly to put it in the postbit_legacy
I used now your code in my Welcome block and replaced the standard "Welcome back" with the $Greeting variable.
Works like a charm.


All times are GMT. The time now is 01:14 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.01036 seconds
  • Memory Usage 1,712KB
  • 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)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete