Skip to content
Browse files

Adding user-selectable date and time formats.

  • Loading branch information...
1 parent a1ef211 commit a54080bcd9870238e214878890b7c7434fb37e52 Ben Fondu committed May 3, 2009
Showing with 74 additions and 17 deletions.
  1. +5 −1 upload/db_update.php
  2. +24 −13 upload/include/functions.php
  3. +3 −0 upload/lang/English/prof_reg.php
  4. +42 −3 upload/profile.php
View
6 upload/db_update.php
@@ -11,7 +11,7 @@
define('UPDATE_TO', '1.4');
-define('UPDATE_TO_DB_REVISION', 0);
+define('UPDATE_TO_DB_REVISION', 1);
// The number of items to process per pageview (lower this if the update script times out during UTF-8 conversion)
define('PER_PAGE', 300);
@@ -605,6 +605,10 @@ function convert_table_utf8($table)
// Add the ban_creator column to the bans table
$db->add_field('bans', 'ban_creator', 'INT(10) UNSIGNED', false, 0);
+ // Add the time/date format settings to the user table
+ $db->add_field('users', 'time_format', 'INT(10)', false, 0, 'dst');
+ $db->add_field('users', 'date_format', 'INT(10)', false, 0, 'dst');
+
// Should we do charset conversion or not?
if (strpos($cur_version, '1.2') === 0 && isset($_GET['convert_charset']))
$query_str = '?stage=conv_misc&req_old_charset='.$old_charset.'&req_per_page='.PER_PAGE;
View
37 upload/include/functions.php
@@ -786,9 +786,9 @@ function message($message, $no_back_link = false)
//
// Format a time string according to $time_format and timezones
//
-function format_time($timestamp, $date_only = false)
+function format_time($timestamp, $date_only = false, $date_format = null, $time_format = null, $time_only = false, $no_text = false)
{
- global $pun_config, $lang_common, $pun_user;
+ global $pun_config, $lang_common, $pun_user, $forum_date_formats, $forum_time_formats;
if ($timestamp == '')
return $lang_common['Never'];
@@ -797,19 +797,30 @@ function format_time($timestamp, $date_only = false)
$timestamp += $diff;
$now = time();
- $date = gmdate($pun_config['o_date_format'], $timestamp);
- $today = gmdate($pun_config['o_date_format'], $now+$diff);
- $yesterday = gmdate($pun_config['o_date_format'], $now+$diff-86400);
+ if($date_format == null)
+ $date_format = $forum_date_formats[$pun_user['date_format']];
- if ($date == $today)
- $date = $lang_common['Today'];
- else if ($date == $yesterday)
- $date = $lang_common['Yesterday'];
+ if($time_format == null)
+ $time_format = $forum_time_formats[$pun_user['time_format']];
- if (!$date_only)
- return $date.' '.gmdate($pun_config['o_time_format'], $timestamp);
- else
+ $date = gmdate($date_format, $timestamp);
+ $today = gmdate($date_format, $now+$diff);
+ $yesterday = gmdate($date_format, $now+$diff-86400);
+
+ if(!$no_text)
+ {
+ if ($date == $today)
+ $date = $lang_common['Today'];
+ else if ($date == $yesterday)
+ $date = $lang_common['Yesterday'];
+ }
+
+ if ($date_only)
return $date;
+ else if ($time_only)
+ return gmdate($time_format, $timestamp);
+ else
+ return $date.' '.gmdate($time_format, $timestamp);
}
@@ -877,7 +888,7 @@ function confirm_referrer($script)
{
global $pun_config, $lang_common;
- if (!preg_match('#^'.preg_quote(str_replace('www.', '', $pun_config['o_base_url']).'/'.$script, '#').'#i', str_replace('www.', '', (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''))))
+ if (!preg_match('#^'.preg_quote(str_replace('www.', '', $pun_config['o_base_url']).'/'.$script, '#').'#i', str_replace('www.', '', (isset($_SERVER['HTTP_REFERER']) ? urldecode($_SERVER['HTTP_REFERER']) : ''))))
message($lang_common['Bad referrer']);
}
View
3 upload/lang/English/prof_reg.php
@@ -10,6 +10,9 @@
'Timezone info' => 'For the forum to display times correctly you must select your local timezone.',
'DST' => 'Adjust for DST: This box should be checked properly so that the forum can display the correct time.',
'DST info' => 'Daylight savings is in effect (advance times by 1 hour).',
+'Time format' => 'Time format',
+'Date format' => 'Date format',
+'Default' => 'Default',
'Language' => 'Language',
'Language info' => 'You can choose which language you wish to use to view the forum.',
'E-mail setting info' => 'Select whether you want your e-mail address to be viewable to other users or not and if you want other users to be able to send you e-mail via the forum (form e-mail) or not.',
View
45 upload/profile.php
@@ -689,7 +689,7 @@ function extract_elements($allowed_elements)
{
case 'essentials':
{
- $form = extract_elements(array('timezone', 'dst', 'language'));
+ $form = extract_elements(array('timezone', 'dst', 'language', 'time_format', 'date_format'));
if ($pun_user['is_admmod'])
{
@@ -744,6 +744,9 @@ function extract_elements($allowed_elements)
message($lang_common['Bad request']);
}
+ $form['time_format'] = (isset($form['time_format'])) ? intval($form['time_format']) : 0;
+ $form['date_format'] = (isset($form['date_format'])) ? intval($form['date_format']) : 0;
+
if (!isset($form['dst']) || $form['dst'] != '1') $form['dst'] = '0';
break;
@@ -907,7 +910,7 @@ function extract_elements($allowed_elements)
}
-$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
+$result = $db->query('SELECT u.username, u.email, u.title, u.realname, u.url, u.jabber, u.icq, u.msn, u.aim, u.yahoo, u.location, u.signature, u.disp_topics, u.disp_posts, u.email_setting, u.notify_with_post, u.auto_notify, u.show_smilies, u.show_img, u.show_img_sig, u.show_avatars, u.show_sig, u.timezone, u.dst, u.language, u.style, u.num_posts, u.last_post, u.registered, u.registration_ip, u.admin_note, u.date_format, u.time_format, g.g_id, g.g_user_title, g.g_moderator FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id='.$id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang_common['Bad request']);
@@ -1115,7 +1118,8 @@ function extract_elements($allowed_elements)
<legend><?php echo $lang_prof_reg['Localisation legend'] ?></legend>
<div class="infldset">
<label><?php echo $lang_prof_reg['Timezone'] ?>: <?php echo $lang_prof_reg['Timezone info'] ?>
- <br /><select name="form[timezone]">
+
+ <br /><select name="form[timezone]">
<option value="-12"<?php if ($user['timezone'] == -12) echo ' selected="selected"' ?>>-12</option>
<option value="-11"<?php if ($user['timezone'] == -11) echo ' selected="selected"' ?>>-11</option>
<option value="-10"<?php if ($user['timezone'] == -10) echo ' selected="selected"' ?>>-10</option>
@@ -1159,6 +1163,41 @@ function extract_elements($allowed_elements)
<div class="rbox">
<label><input type="checkbox" name="form[dst]" value="1"<?php if ($user['dst'] == '1') echo ' checked="checked"' ?> /><?php echo $lang_prof_reg['DST info'] ?><br /></label>
</div>
+ <label><?php echo $lang_prof_reg['Time format'] ?>
+
+ <br /><select name="form[time_format]">
+<?php
+ foreach (array_unique($forum_time_formats) as $key => $time_format)
+ {
+ echo "\t\t\t\t\t\t\t\t".'<option value="'.$key.'"';
+ if ($user['time_format'] == $key)
+ echo ' selected="selected"';
+ echo '>'. format_time(time(), false, null, $time_format, true, true);
+ if ($key == 0)
+ echo ' ('.$lang_prof_reg['Default'].')';
+ echo "</option>\n";
+ }
+ ?>
+ </select>
+ <br /></label>
+ <label><?php echo $lang_prof_reg['Date format'] ?>
+
+ <br /><select name="form[date_format]">
+<?php
+ foreach (array_unique($forum_date_formats) as $key => $date_format)
+ {
+ echo "\t\t\t\t\t\t\t\t".'<option value="'.$key.'"';
+ if ($user['date_format'] == $key)
+ echo ' selected="selected"';
+ echo '>'. format_time(time(), true, $date_format, null, false, true);
+ if ($key == 0)
+ echo ' ('.$lang_prof_reg['Default'].')';
+ echo "</option>\n";
+ }
+ ?>
+ </select>
+ <br /></label>
+
<?php
$languages = array();

0 comments on commit a54080b

Please sign in to comment.
Something went wrong with that request. Please try again.