Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Local Timezone Mod for sNews 1.7.1  (Read 232 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Local Timezone Mod for sNews 1.7.1
« on: December 28, 2012, 04:53:35 PM »

This Mod began as a convenient solution to the problem experienced and posted in this thread.

Purpose: Provides the site owner/administrator with the ability to convert the host server's timezone setting to the site owner's local timezone so that article and page posting date/time will be displayed for the local timezone.

Usage: This mod adds a new "Local Timezone" field under the "Date Format" field in the Admin => Settings => Time and Locale Settings panel. You enter the local timezone setting you want to use in the field, save the settings, and the new 'timezone' value is saved to the settings table in your database. It is them automatically applied to the date/time displayed under published articles and pages.

Modifications

1. Add the new timezone data row to the settings table in your database by running the following SQL query on your database using phpMyAdmin:  INSERT INTO `settings` VALUES ('', 'timezone', 'Europe/London');

The default value is Europe/London and you can change it to whatever you want once the mods are completed. For example, for EST and EDT in the U.S. America/New_York or in Canada Canada/Eastern works for me. ( Valid Time Zone Values )

2. Add a new Language Variable to your lang/EN.php file (and any other language files used).
Search your languaage file for $l['a_date_format'] = 'Date Format'; and, paste $l['a_timezone'] = 'Local Timezone'; // Timezone Mod under it.

The rest of the modifications are all in the engine file (snews.php or whatever your main functions file is named).

3. Add the new "Local Timezone" input field to the Admin => Settings => Time and Locale Settings panel.
Search for and locate this string in function settings():
Code: [Select]
echo html_input('text', 'date_format', 'dt', s('date_format'), l('a_date_format'), '', '', '', '', '', '', '', '', '', '');

... and paste the following under it:
Code: [Select]
// Timezone Mod, 1 string
echo html_input('text', 'timezone', 'tz', s('timezone'), l('a_timezone'), '', '', '', '', '', '', '', '', '', '');

4. Saving the setting value to the settings table in the database
a) In function processing(), search for and locate $date_format = $_POST['date_format']; and, under it, paste in $timezone = $_POST['timezone']; // Timezone Mod

b) Further down in the same function, find 'date_format' => $date_format, and, under it, paste in: 'timezone' => $timezone,

Result: You can now view and change the "Local Timezone" setting in the Admin => Settings => Time and Locale Settings panel.

5. Apply the Local Timezone Setting to date/time lines for Articles and Pages
In function articles, locate this string: $a_date_format = date(s('date_format'), strtotime($r['date'])); and replace it with the following:
Code: [Select]

// Timezone Mod, 4 strings replace the default string.
$format = s('date_format');
$timestamp = strtotime($r['date']);
date_default_timezone_set(''.s('timezone').'');
$a_date_format = date($format, $timestamp);
//$a_date_format = date(s('date_format'), strtotime($r['date'])); // default string


This completes the steps required to have your Local Timezone setting apply to the date/time displayed for published articles and pages in your sNews website.

TZ Time Zone References: - Valid Time Zone Values
« Last Edit: December 28, 2012, 08:25:18 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

jmonroe

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
Re: Local Timezone Mod for sNews 1.7.1
« Reply #1 on: January 04, 2013, 07:05:46 PM »

This seems to rid most of the errors for me except error with line 724....I replace it with

// Timezone Mod, 4 strings replace the default string.
$format = s('date_format');
$timestamp = strtotime($r['date']);
date_default_timezone_set(''.s('timezone').'');
$a_date_format = date($format, $timestamp);
//$a_date_format = date(s('date_format'), strtotime($r['date'])); // default string


Thats when the sidebar errors go away. However, left right above the upper most H2 heading Welcome to snews1.7MU is the following error...


faultCode0faultStringWarning:strtotime() [function.strtotime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Denver' for 'MST/-7.0/no DST' instead in /snews17MU.php on line 726

Now...that is the error I get even after replacing the code. I am going to try and tinker with it a bit and see if i can find a solution.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Local Timezone Mod for sNews 1.7.1
« Reply #2 on: January 04, 2013, 10:00:43 PM »

I can't test this mod to see if it gets rid of the errors since I don't get the errors without the mod.  :-\
Which of the mod strings is on line 726?
Maybe it doesn't like the timezone setting we're using for your timezone.

Have you tried just changing the timezone setting (in the new settings panel field) to "America/Denver" ... just to see if it eliminates the error? That might give us a clue...
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

jmonroe

  • Newbie
  • *
  • Karma: 1
  • Posts: 21
Re: Local Timezone Mod for sNews 1.7.1
« Reply #3 on: January 07, 2013, 07:41:16 PM »

The line is part of the mod. This is the line 726

date_default_timezone_set(''.s('timezone').'');

I am going to contact Godaddy because I am starting to have this timezone issue on a few sites. I have had snews installed before on Godaddy long time ago when i first joined the forum in 2010 and never had this issue. Looks like I may switch host eventually.
« Last Edit: January 07, 2013, 11:23:10 PM by jmonroe »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Local Timezone Mod for sNews 1.7.1
« Reply #4 on: January 08, 2013, 02:39:32 AM »

The line is part of the mod. This is the line 726
date_default_timezone_set(''.s('timezone').'');

OK, well all we're doing with this string is using the s('timezone') variable to retrieve the value for timezone from the settings table in the d-base (the value we saved from the Settings panel field mod) and setting it as the default timezone for the site.

I am going to contact Godaddy because I am starting to have this timezone issue on a few sites. I have had snews installed before on Godaddy long time ago when i first joined the forum in 2010 and never had this issue. Looks like I may switch host eventually.

I would not have put up with this for as long as you have... you are too patient.   ;D
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU