Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Offsetting your site's defaut time zone
  • Posted: 23.03.2006, 09:08
     
    Slugger
    rank:
    Professional 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
  • Posted: 23.03.2006, 17:04
     
    mar
    rank:
    Freshman 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
  • Posted: 24.03.2006, 01:55
     
    drak
    rank:
    Software Foundation Software Foundation
    registered:
     December 1969
    Status:
    offline
    last visit:
    16.10.08
    Posts:
    157
    Sounds reasonable. Have you coded a solution? Maybe if you send it on I can commit it to the 0.8 tree.
  • Posted: 26.03.2006, 11:20
     
    Slugger
    rank:
    Professional 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" />


    and

    Code

    // done, now on to the form


    add the following

    Code

    $sel_tzserver[pnConfigGetVar('timezone_server')] = ' selected="selected"'; //Server Time Zone Hack



    Still in the modules/Settings/admin.php, find

    Code

    ._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 it

    Code

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

    define('_TIMEZONESERVER','Server time zone');



    Now for the final modification. Open pnAPI.php, which is found in the includes directory on the root level and find

    Code

    if (pnUserLoggedIn()) {
                $time += (pnUserGetVar('timezone_offset') - pnConfigGetVar('timezone_offset')) * 3600;
            } else {
                $time += (12 - pnConfigGetVar('timezone_offset')) * 3600;
            }
    (edited... thanks to AdrianChapman for pointing out typo :wink:)

    and change it to

    Code

    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
  • Posted: 26.03.2006, 18:56
     
    AdrianChapman
    rank:
    Helper 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.
  • Posted: 26.03.2006, 19:04
     
    AdrianChapman
    rank:
    Helper 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>
  • Posted: 26.03.2006, 19:09
     
    Slugger
    rank:
    Professional Professional
    registered:
     March 2003
    Status:
    offline
    last visit:
    13.08.06
    Posts:
    1185
    AdrianChapman,

    I'm glad you found the problem. I'm not so good at cut and paste in the wee hours, myself. icon_lol

    Slugger
  • Posted: 31.03.2006, 14:46
     
    byte10
    rank:
    Freshman 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... icon_lol
  • Posted: 04.04.2006, 04:02
     
    Slugger
    rank:
    Professional Professional
    registered:
     March 2003
    Status:
    offline
    last visit:
    13.08.06
    Posts:
    1185
    KICK!!! icon_lol

    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
  • Posted: 04.04.2006, 04:54
     
    rank:
    Moderator Moderator
    registered:
     March 2002
    Status:
    offline
    last visit:
    26.08.08
    Posts:
    7720
    Slugger,

    I'm aware of this thread and will incorporate the changes over the next few days. It's not as simple as copy and paste since .8x is a significantly different codebase.

    -Mark
  • Posted: 04.04.2006, 06:49
     
    mhalbrook
    rank:
    Legend Legend
    registered:
     December 1969
    Status:
    offline
    last visit:
    21.11.08
    Posts:
    6520
    Good work Slugger, this was one of the feature requests I put in for PN a while back. Never even bothered to look in to working on it myself.
  • Posted: 18.04.2006, 20:06
     
    rank:
    Moderator 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

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula