- Moderated by:
- Support Team
-
- rank:
-
Professional
- registered:
- March 2003
- Status:
- offline
- last visit:
- 13.08.06
- Posts:
- 1185
Edited: Please note the hack has been posted and can be found below.
One problem (in my opinion) with PostNuke is the out-of-the-box configuration assumes your server is set to the time zone you want but we know this isn't always true.
For example my servers are set to GMT but I host some of the (many, many,...too many?) service clubs I'm in and they could care less about GMT...they're community groups...so anything but the Pacific time zone is wrong, wrong, wrong,...as far as they're concerned.
I can fudge the TZ offset so the club site shows the correct time but then users can't set their own preference because, it'll be off by the same fudge factor I put in when I set up the site. Dah!
Soooo, what to do. The answer is that PostNuke's admin settings panel should have two time zones. One...your server's time zone and the other, the default you want for your site. Actually it's an time offset but that's just minutia.
Done properly, your users can set their preferences and they'll actually work. OK, I've done this hack many many times times. Now, it occurs to me that somebody else might be interested. If so, I'll write it up in the tutorials section. But, before I invest the time, I'd like to know if this is anything anybody could use?
Slugger -
- rank:
-
Freshman
- registered:
- December 2005
- Status:
- offline
- last visit:
- 26.04.06
- Posts:
- 20
Quote
PostNuke's admin settings panel should have two time zones. One...your server's time zone and the other, the default you want for your site
cool, submit this patch to the cvs if you can.. it should be welcomed :)
Where in here? ;)
http://www.markwest.me.uk/temp/settings/
this admin wanted to add a new GMT time select for his users
http://forums.postnuke.com/index.php?name=PNphpBB2&file=viewtopic&t=44089&highlight=nepal -
- rank:
-
Professional
- registered:
- March 2003
- Status:
- offline
- last visit:
- 13.08.06
- Posts:
- 1185
For those who may want to try this, you will be modifying core files so please, please, please, remember to back up your files.
First, we will add a new config variable in your site settings for the server time zone and then we will take that and offset it by the time zone offset variable to determine your site's new default time zone. We will do this by modifying three files, pnAPI.php in your includes directory and admin.php in your Settings module directory and your language(s) global.php file(s) for the Settings module.
Ok, let's go hacking...
Open modules/Settings/admin.php and somewhere between:Code
// Set the current settings for select fields, radio buttons and checkboxes.
// Much better then using if() statements all over the place <img src="images/smilies/icon_smile.gif" alt="icon_smile" />
andCode
// done, now on to the form
add the followingCode
$sel_tzserver[pnConfigGetVar('timezone_server')] = ' selected="selected"'; //Server Time Zone Hack
Still in the modules/Settings/admin.php, findCode
._TIMEZONEOFFSET.':</td><td>';
$tzoffset = pnConfigGetVar('timezone_offset');
global $tzinfo;
echo "<select name=\"xtimezone_offset\" size=\"1\">\n";
foreach ($tzinfo as $tzindex => $tzdata) {
echo "<option value=\"$tzindex\"";
if ($tzoffset == $tzindex) {
echo ' selected="selected"';
}
echo ">";
echo pnVarPrepHTMLDisplay($tzdata);
echo "</option>";
}
echo "</select>"
."</td></tr>"
and insert the following after itCode
.'<tr><td>'
._TIMEZONESERVER.':</td><td>';
$tzserver = pnConfigGetVar('timezone_server');
global $tzinfo;
echo "<select name=\"xtimezone_server\" size=\"1\">\n";
foreach ($tzinfo as $tzindex => $tzdata) {
echo "<option value=\"$tzindex\"";
if ($tzserver == $tzindex) {
echo ' selected="selected"';
}
echo ">";
echo pnVarPrepHTMLDisplay($tzdata);
echo "</option>";
}
echo "</select>"
."</td></tr>"
They look similar...because they are so, remember, you're going to want both of the above...the top one for your offset and the bottom for your server's time.
Save your changes and open your global.php language file(s) for the Settings module. Add the following and save your changes.Code
Now for the final modification. Open pnAPI.php, which is found in the includes directory on the root level and find(edited... thanks to AdrianChapman for pointing out typo :wink:)Code
if (pnUserLoggedIn()) {
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
} else {
$time += (12 - pnConfigGetVar('timezone_offset')) * 3600;
}
and change it toCode
if (pnUserLoggedIn()) {
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_server')) * 3600;
} else {
$time += (pnConfigGetVar('timezone_offset') - pnConfigGetVar('timezone_server')) * 3600;
}
Now your site can have any default time zone, regardless of what your servers time is set to.
Have fun!
Slugger -
- rank:
-
Helper
- registered:
- April 2004
- Status:
- offline
- last visit:
- 03.09.08
- Posts:
- 143
Slugger
Now your site can have any default time zone, regardless of what your servers time is set to.
Have fun!
Slugger
Hmmm. Problem...
The pnAPI changes are killing my site -
Quote
Parse error: syntax error, unexpected T_ELSE in /home2/cccuk/public_html/PostNuke/includes/pnAPI.php on line 1107
I'm cutting and pasting, so it's not my typo, and it's not my editing (via Notepad), as the problem goes away if I cut'n'paste the original back in...
Oh, and I've been into the Settings module and set the new timezone var - to the same as the server's at the mo - so it's not a case of the timezone setting not being present yet. -
- rank:
-
Helper
- registered:
- April 2004
- Status:
- offline
- last visit:
- 03.09.08
- Posts:
- 143
AdrianChapman
Hmmm. Problem...
The pnAPI changes are killing my site -
Quote
Parse error: syntax error, unexpected T_ELSE in /home2/cccuk/public_html/PostNuke/includes/pnAPI.php on line 1107
<slaps forehead="forehead">
It's not just
Code
if (pnUserLoggedIn()) {
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
}
that gets replaced - in fact, that snippet *misses* the bit that needs to be replaced.
What SHOULD be replaced is
Code
if (pnUserLoggedIn()) {
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
} else {
$time += (12 - pnConfigGetVar('timezone_offset')) * 3600;
}
With that in place, there's only one thing I can say...
SLUGGER, I LOVE YOU! You, Sir, are a bloody HERO.
Now, about daylight saving...</slaps> -
- rank:
-
Freshman
- registered:
- February 2003
- Status:
- offline
- last visit:
- 04.10.07
- Posts:
- 17
Being the lazy guy that I am, I just added 8 (since site and server is +8GMT) to the 12 = 20 to ver .726 includes/pnAPI.php
Code
function GetUserTime($time)
{
if(empty($time)) {
return;
}
if (pnUserLoggedIn()) {
$time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
} else {
$time += (20 - pnConfigGetVar('timezone_offset')) * 3600;
}
return($time);
I did not make any changes elswhere..
Seems to work fine..
.. showing correct TMZ for unregistered users and correct TMZ for registered users who have set their TZ.
I'm not sure if this will mess up stuff elswhere as I'm not very well versed with programing. In fact, on second thoughts, I'm not sure I should have post this here, this being a KB Tutorial Section of the Forum. So please, if I'm wrong.. kick me.. HARD...
-
- rank:
-
Professional
- registered:
- March 2003
- Status:
- offline
- last visit:
- 13.08.06
- Posts:
- 1185
KICK!!!
The goal was to do this so that, when server, and site time zone's don't match. If we know the server's offset plus our intended default site time, we can get the clocks synched. The reason I wrote it with the admin panel config is in response to Drak's request and the hope that 0.8 will have a similar configuration built-in so we don't have to hack the API.
Slugger -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
Slugger,
A .8x version of this hack is now in cvs. Can you please check this logic for me using the next daily.
In addition to adding this change i've also added a few missing timezones and altered the offsets to go from -12 -> +12 (actually +14 since there's a GMT+13 and GMT+14 timezone...). This makes the logic somewhat easier to handle.
The source for all the info used was wikipedia (http://en.wikipedia.org/wiki/List_of_time_zones).
By the end of working on this my head was spinning a little so no doubt there'll be a few bugs - especially since my server was reallyin GMT so i'd a further offset to take into account while testing this....
-Mark
