Makestation
Greetings according to the time of day in the forum - Printable Version

+- Makestation (https://makestation.net)
+-- Forum: Technical Arts (https://makestation.net/forumdisplay.php?fid=45)
+--- Forum: Web Design & Internet (https://makestation.net/forumdisplay.php?fid=62)
+---- Forum: MyBB Related (https://makestation.net/forumdisplay.php?fid=120)
+---- Thread: Greetings according to the time of day in the forum (/showthread.php?tid=3369)



Greetings according to the time of day in the forum - tc4me - February 3rd, 2021

Greetings according to the time of day in the forum

Hello Darth-Apple Hello folks, My question to you about my small adjustment in the forum, greeting after day / night time in the Mybb forum.
It was important to me not to generate it according to the server time, but according to the user-specific set time zone in the user Cp.
I managed to do that.
How far I have errors in the whole, I ask you to point out and to improve.


instructions:

####################################################
Code:
add you and you in the global language file English and German
]I have it right under (about line 38 be more or less) this
$l['welcome_current_time'] = "<strong>Current time:</strong> {1}";
HERE:

German:

$l['welcome_back_night'] = "<strong>Gute Nacht {1}</strong> - Letzter Besuch: {2}";
$l['welcome_back_morning'] = "<strong>Guten Morgen {1}</strong> - Letzter Besuch: {2}";
$l['welcome_back_day'] = "<strong>Guten Tag {1}</strong> - Letzter Besuch: {2}";
$l['welcome_back_evening'] = "<strong>Guten Abend {1}</strong> - Letzter Besuch: {2}";

english

$l['welcome_back_night'] = "<strong>Good Night {1}</strong>. You last visited: {2}";
$l['welcome_back_morning'] = "<strong>Good Morning {1}</strong>. You last visited: {2}";
$l['welcome_back_day'] = "<strong>Good Day {1}</strong>. You last visited: {2}";
$l['welcome_back_evening'] = "<strong>Good Evening {1}</strong>. You last visited: {2}";


###################
then change the main directory global.php
###################

Code:
gobal.php

replace line 530:

$lang->welcome_back = $lang->sprintf($lang->welcome_back, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);

replaced with:

//Begin Time welcome Tc4me
$uhrzeit = gmdate($mybb->settings['timeformat'],TIME_NOW + $mybb->user['timezone'] * 3600);
if ($uhrzeit >= 0 && $uhrzeit < 4) 
{
$lang->welcome_back = $lang->sprintf($lang->welcome_back_night, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);
}
elseif ($uhrzeit < 10 && $uhrzeit >= 4)
{
$lang->welcome_back = $lang->sprintf($lang->welcome_back_morning, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);
}
elseif ($uhrzeit <= 18 && $uhrzeit >= 10)
{
$lang->welcome_back = $lang->sprintf($lang->welcome_back_day, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);
}
  else//if ($uhrzeit >= 19)
{
$lang->welcome_back = $lang->sprintf($lang->welcome_back_evening, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $lastvisit);
}
//End Time welcome Tc4me


Please take a look at that and if necessary, please improve it!

Greets Tc4me


RE: Greetings according to the time of day in the forum - Thomas - February 4th, 2021

Greetings to you too!


RE: Greetings according to the time of day in the forum - tc4me - February 9th, 2021

Hey friends, I have now changed it to a switch instruction.

If you have the time, please post improvements :-) THANK YOU

Code:
//Begin Time welcome Tc4me
    $uhrzeit = gmdate($mybb->settings['timeformat'],TIME_NOW + $mybb->user['timezone'] * 3600);
switch ($uhrzeit) {
    case $uhrzeit <= 4:
    $lang->welcome_back = $lang->sprintf($lang->welcome_back_night, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $timenow);
    break;

    case $uhrzeit <= 10:
    $lang->welcome_back = $lang->sprintf($lang->welcome_back_morning, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $timenow);
    break;

    case $uhrzeit <= 18:
    $lang->welcome_back = $lang->sprintf($lang->welcome_back_day, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $timenow);
    break;

    case $uhrzeit <= 22:
    $lang->welcome_back = $lang->sprintf($lang->welcome_back_evening, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $timenow);
    break;

    default:
  $lang->welcome_back = $lang->sprintf($lang->welcome_back_night, build_profile_link(htmlspecialchars_uni($mybb->user['username']), $mybb->user['uid']), $timenow);
}
//End Time welcome Tc4me