Page 1 of 1

Modify the calendar so it uses future years

Posted: Fri Jul 15, 2005 2:01 am
by lkelly
I'm trying to set up a blog which appears to have entries posted in the future. For example, I want the calendar to show 2010 instead of 2005. Is there a quick change I can make to the underlying code to allow it to add several years to the dates and still calculate the right days of the month/days of the week?

Thanks.

Re: Modify the calendar so it uses future years

Posted: Fri Jul 15, 2005 10:17 am
by garvinhicking
Yes, you can patch up the code.

Have a look at the file include/plugin_internal.inc.php. Look for the first class serendipity_calendar_plugin.

At around line 54 you can see this:

Code: Select all

 $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour(time());
This is responsible for setting the default calendar range when none other is selected. Change this to:

Code: Select all

 $serendipity['GET']['calendarZoom'] = serendipity_serverOffsetHour(mktime(0,0,0,date('m'),date('d'),2010));
That will set the default time to the current day, month but in the year 2010.

HTH,
Garvin

Posted: Wed Jul 20, 2005 5:56 am
by lkelly
OK, a follow up to this...

I can get the calendar to come up with the future year (i.e. July 2010) when the page loads, but if I post-date new entries on the admin page when creating them, they don't show up. If I enter new ones with today's date in 2005, those do show up in the 2005 archive. Anything else post-dated just vanishes.

(edit - more detail) I looked in the table "serendipity_entries" and did see the posts I'd added. The value in 'timestamp' seemed to be a bigger number than the test entry for 2005, so the data appears to be there. I just isn't returned by the code that pulls it from the database.

(second edit) Posts are definitely there, but show as "not yet published" under the admin tool. Sounds like I just need to know how to publish the future entries now.

Assuming I can get post-dated entries working, the follow up question will be can I get the default date on the new entry page changed so that it defaults to 2010 (for example).

Thanks.

Posted: Wed Jul 20, 2005 7:20 am
by gwilsonmail
My guess is you need to set your server time to the year 2010.

your posts aren't being displayed because the server thinks it's 2005 and posts for 2010 haven't happened yet

Strangely I think it's 2005 as well ...

Posted: Wed Jul 20, 2005 11:33 am
by garvinhicking
The actual problem is that in the default setup Serendipity does not show future entries. This helps to create new articles which are only shown when the date has arrived.

For this to work, go to your Serendipity Configuration and set the Option "Show Entries from the future" to "true". :-)

Regards,
Garvin

Posted: Wed Jul 20, 2005 3:50 pm
by lkelly
Garvin, that did the trick. I should have seen that option. Thanks so much.

Another thing - the code to hack so that the archive dates displayed on the right hand column (i.e. "July 2005" and "June 2005" etc.) are also offset from the future calendar year I'm using, instead of the present... I would assume it's in that same plugin_internal.inc.php file, just a little further down.

Final question for now is can the code be hacked so that the default time shown in the UI for adding entries is offset by several years? I haven't dug too deep into the source yet, but I imagine there's a function that returns the current time to that field. The "reset date" button does just that.

Thanks again.

Posted: Wed Jul 20, 2005 4:02 pm
by garvinhicking
Ikelly, sure:

Open your include/functions_entries.inc.php, search for the function serendipity_printEntryForm(). Then locate this line:

Code: Select all

    $hidden .= '        <input type="hidden" name="serendipity[timestamp]" value="' . (isset($entry['timestamp']) ? serendipity_serverOffsetHour($entry['timestamp']) : serendipity_serverOffsetHour(time())) . '" />' . $n;
modify this to:

Code: Select all

    $hidden .= '        <input type="hidden" name="serendipity[timestamp]" value="' . (isset($entry['timestamp']) ? serendipity_serverOffsetHour($entry['timestamp']) : serendipity_serverOffsetHour(mktime(date('H'), date('i'), 0, date('m'), date('d'), date('Y') + 10))) . '" />' . $n;
Note that time() got replaced with the mktime(...) command that uses todays input as default, but adds 10 Years to the year.

HTH,
Garvin

Posted: Wed Jul 20, 2005 4:04 pm
by lkelly
Thanks again. I did just edit my post while you were responding with another (probably simple for you) question. :)