Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
brentnhunter
Client


Joined: Sep 10, 2004
Posts: 166

PostPosted: Mon Oct 18, 2004 11:34 pm Reply with quote

I would like the time on my nuke website to be my local time, not the time of the server. Anyone know how I can change it?

Thank you for your help.

Brent Hunter Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17077

PostPosted: Tue Oct 19, 2004 5:09 am Reply with quote

The forums are easy - use forum admin but people can adjust it as they wish. If you are talking about the news items, many have tried - many have died Laughing.

You can try this little diddy Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
brentnhunter
PostPosted: Tue Oct 19, 2004 7:56 am Reply with quote

OK thanks Sad
 
Holbrookau
Hangin' Around


Joined: Jun 25, 2004
Posts: 32

PostPosted: Tue Oct 19, 2004 9:01 pm Reply with quote

The following is an adaption of what we use at IPBNuke.net (InvisionPowerBoard rather then phpBB). It is by no means a finished solution but could be a basis to work with.
When a user is logged in, their timezone offset from the phpBB forums is applied to post times in news articles and comments (and anywhere else the formatTimstamp funtion is called upon). If not logged in, the times shown will be in GMT.

In mainfile.php -
Find:
Code:
function formatTimestamp($time) {

    global $datetime, $locale;
    setlocale (LC_TIME, $locale);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    $datetime = strftime(""._DATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    return($datetime);
}

Replace with:
Code:
function formatTimestamp($time) {

    global $db, $prefix, $datetime, $user, $cookie;
   $convtime = strtotime($time);
   if (is_user($user)) {
      $result = $db->sql_query("SELECT user_timezone FROM ".$prefix."_users WHERE user_id='$cookie[0]'");
      $row = $db->sql_fetchrow($result);
      $timeoffset = intval($row['user_timezone']*3600);
   $datetime = gmdate(""._DATESTRING3."", $convtime + $timeoffset);
   } else {
   $datetime = gmdate(""._DATESTRING4."", $convtime);
   }
    return($datetime);
}


In language/lang-XXXX.php (where XXXX is your language) -
Find:
Code:
define("_BANTHIS","Ban This IP");
(or whatever the last define line is in your file)

Add After:
Code:
define("_DATESTRING3","l, jS F @ g:i a");

define("_DATESTRING4","l, jS F @ g:i a \G\M\T");


Save both and upload.
 
View user's profile Send private message
brentnhunter
PostPosted: Tue Oct 19, 2004 11:33 pm Reply with quote

Thanks, this would be great if it works (I don't use InvisionPowerBoard, I use phpbb) but I'll give it a try.

But first I can't figure out how to change the system timezone. When I go to Admin CP, Forums, then Configuration under the General Admin area, there is an option in there that is titled "System Timezone". No matter what I put in there, when I make a post, it shows the time as being 1 hour earlier than what it is in my local area. I'm not sure why it won't work for me, but is that the timezone you are talking about?
 
Holbrookau
PostPosted: Wed Oct 20, 2004 12:20 am Reply with quote

Its an adaption of what we use with IPB - I rewrote it to work for phpBB..
The System Timezone should be set so that the board is in GMT time. Then, each member can enter their true Timezone in their Profile and have posts show in local time.
This is the way all boards should be setup.
 
brentnhunter
PostPosted: Wed Oct 20, 2004 4:34 am Reply with quote

Agreed... and where do I set the System Timezone? In the server itself (in which case, Raven would change) or somewhere in my own nuke or phpbb setup? What about the question I asked above about the place I was trying to change?

Brent
 
Raven
PostPosted: Wed Oct 20, 2004 6:08 am Reply with quote

There isn't a single setting in nuke to do this,; that's the problem. What Holbrook is saying, if I understand him correctly, is that he is offering a means to take the timezone setting from the forums (which people can change) and adapt an offset to any nuke code that calls 'formatTimestamp'. That way everyone sees the times in THEIR timezone, just as we do in the forums. Holbrook, correct me if I'm wrong.
 
sixonetonoffun
Spouse Contemplates Divorce


Joined: Jan 02, 2003
Posts: 2496

PostPosted: Wed Oct 20, 2004 6:38 am Reply with quote

This is nice! I'm still and hour off for some reason but one heck of a lot nicer then it was. I set Forums Sytem Time to GMT and my preference to -6 but the time in comments shows and hour earlier 6:30 instead of 7:30.

_________________
[b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 
View user's profile Send private message
Raven
PostPosted: Wed Oct 20, 2004 6:48 am Reply with quote

Aren't you on CDT? If so, you should be -5 shouldn't you?
 
sixonetonoffun
PostPosted: Wed Oct 20, 2004 7:03 am Reply with quote

Your right Grr!
 
Holbrookau
PostPosted: Wed Oct 20, 2004 7:18 am Reply with quote

Quote:
where do I set the System Timezone?
I assumed here: "When I go to Admin CP, Forums, then Configuration under the General Admin area, there is an option in there that is titled "System Timezone"." If that isn't the right place perhaps one of the other guys can point you in the right direction - it's has been a while since I played with phpBB.
Quote:
correct me if I'm wrong
No correction required. Wink
 
brentnhunter
PostPosted: Wed Oct 20, 2004 8:21 am Reply with quote

Hi Raven, yes I understood what what being proposed, the problem is that if my time isn;t set correctly in the first place, then it won't do much good to put in a code snippet to make a correction to offset it it to get my correct local time. And even now I'm still trying to find out why I can't change the time zone in the forums. Maybe I'll describe the problem again, pasted from my earlier post:

But first I can't figure out how to change the system timezone. When I go to Admin CP, Forums, then Configuration under the General Admin area, there is an option in there that is titled "System Timezone". No matter what I put in there, when I make a post, it shows the time as being 1 hour earlier than what it is in my local area. I'm not sure why it won't work for me <snip>

Thanks for any help anyone can provide!

Brent
 
Raven
PostPosted: Wed Oct 20, 2004 8:45 am Reply with quote

That's not where you make your changes Laughing - You have to make it in your Profile Timezone, not the System Timezone.
 
brentnhunter
PostPosted: Wed Oct 20, 2004 8:58 am Reply with quote

Ah! That worked! Thank you.

I'll check out the script mods sometime soon.

In the meantime, the other time the time zone difference bothers me is when I go to my website and look at the User Info stats, like how many members signed up that day, yesterday, etc. Will the above script mod fix that problem too?

Thanks again!

Brent
 
Holbrookau
PostPosted: Wed Oct 20, 2004 9:19 am Reply with quote

Quote:
Will the above script mod fix that problem too
Unless the block code is rewritten to use the formatTimstamp function, then no it won't.
 
Raven
PostPosted: Wed Oct 20, 2004 10:04 am Reply with quote

I have published that fix somewhere in the forums. See if you can find it - if not I'll look later.
 
sixonetonoffun
PostPosted: Sun Jan 09, 2005 2:26 pm Reply with quote

Holbrookau wrote:
The following is an adaption of what we use at IPBNuke.net (InvisionPowerBoard rather then phpBB). It is by no means a finished solution but could be a basis to work with.
When a user is logged in, their timezone offset from the phpBB forums is applied to post times in news articles and comments (and anywhere else the formatTimstamp funtion is called upon). If not logged in, the times shown will be in GMT.

In mainfile.php -
Find:
Code:
function formatTimestamp($time) {

    global $datetime, $locale;
    setlocale (LC_TIME, $locale);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    $datetime = strftime(""._DATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    return($datetime);
}

Replace with:
Code:
function formatTimestamp($time) {

    global $db, $prefix, $datetime, $user, $cookie;
   $convtime = strtotime($time);
   if (is_user($user)) {
      $result = $db->sql_query("SELECT user_timezone FROM ".$prefix."_users WHERE user_id='$cookie[0]'");
      $row = $db->sql_fetchrow($result);
      $timeoffset = intval($row['user_timezone']*3600);
   $datetime = gmdate(""._DATESTRING3."", $convtime + $timeoffset);
   } else {
   $datetime = gmdate(""._DATESTRING4."", $convtime);
   }
    return($datetime);
}


In language/lang-XXXX.php (where XXXX is your language) -
Find:
Code:
define("_BANTHIS","Ban This IP");
(or whatever the last define line is in your file)

Add After:
Code:
define("_DATESTRING3","l, jS F @ g:i a");

define("_DATESTRING4","l, jS F @ g:i a \G\M\T");


Save both and upload.


Just wanted to bump this because it is so cool and got so lost I could hardly find it.
 
Muffin
Client


Joined: Apr 10, 2004
Posts: 649
Location: UK

PostPosted: Sun Jan 09, 2005 6:17 pm Reply with quote

So if a sites in the UK and the server is in the US that wouldnt make any difference, the news articles and stuff would be the same as the user's profile time right?

hey this is really good, I've wanted to get this sorted for ages. Solves the problem of daylight saving time changes too.

Thanks a lot!!!

One question, when a news article is posted with the date you post it, how does this mod affect that, and old articles????

_________________
Classic Mini rules the bends & bends the rules!
[img] 
View user's profile Send private message
sixonetonoffun
PostPosted: Sun Jan 09, 2005 8:57 pm Reply with quote

It doesn't effect that at all just how the time is displayed to the user.
 
Muffin
PostPosted: Mon Jan 10, 2005 7:01 am Reply with quote

Thanks Six, thought that was the case.
 
Holbrookau
PostPosted: Mon Jan 17, 2005 2:31 am Reply with quote

I've just updated our IPBNuke version of this code to use the Locale Time Format setting in Administration->Preferances, and thought I should do the same for the phpBB code posted here.
In mainfile.php -
Find:
Code:
function formatTimestamp($time) { 

    global $datetime, $locale;
    setlocale (LC_TIME, $locale);
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
    $datetime = strftime(""._DATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
    $datetime = ucfirst($datetime);
    return($datetime);
}
Replace it with:
Code:
function formatTimestamp($time) { 

    global $db, $prefix, $datetime, $user, $cookie, $locale;
    setlocale (LC_TIME, $locale);
   $convtime = strtotime($time);
   if (is_user($user)) {
      $result = $db->sql_query("SELECT user_timezone FROM ".$prefix."_users WHERE user_id='$cookie[0]'");
      $row = $db->sql_fetchrow($result);
      $timeoffset = intval($row['user_timezone']*3600);
      $datetime = gmstrftime(""._DATESTRING3."", $convtime + $timeoffset);
      } else {
      $datetime = gmstrftime(""._DATESTRING4."", $convtime);
      }
    return($datetime);
}

In language/lang-XXXX.php (where XXXX is your language) -
Find:
Code:
define("_BANTHIS","Ban This IP");
(or whatever the last define line is in your file).
Add After:
Code:
define("_DATESTRING3","%A, %B %e, %Y @ %I:%M %p");

define("_DATESTRING4","%A, %B %e, %Y @ %I:%M %p %Z");
 
Raven
PostPosted: Mon Jan 17, 2005 5:03 am Reply with quote

I have made this a Sticky Smile - Thanks!
 
Holbrookau
PostPosted: Mon Jan 17, 2005 7:57 am Reply with quote

Cool - never been a sticky before! Dance-Y

Some info regarding locale settings..
The default PHP-Nuke setting for Locale Time Format is en_US (English languge/United States location). If, for example, you wanted the date/time displayed in Spanish you would probably use es_ES, French would be fr_FR, etc.
However, some server operating systems don't use the exact same format - FreeBSD for example requires a longer string, eg: en_US.ISO8859-1. So if changing your Locale setting makes no differance to the timestamps shown, you should probably contact your host for advice on the correct format.
But wait, there's more!
If you wish to use a Locale string of more than 10 characters you will need to modify your PHP-Nuke database. The locale field in the nuke_config table has a limit of 10 characters - this needs to be increased to at least the same length as your Locale string. The longest string for FreeBSD is 16 characters, so that is what I've used.
The backend_language field in the same table also has a default limit of 10 characters and should be increased as well.
Hope this helps.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©