Skip to content

Commit

Permalink
Merge pull request SimpleMachines#6344 from Sesquipedalian/timezones_…
Browse files Browse the repository at this point in the history
…redux

Revises smf_list_timezones & related langfile; adds Subs-Timezones.php
  • Loading branch information
Sesquipedalian authored Nov 23, 2020
2 parents 160bdd7 + ff8bd6b commit a138346
Show file tree
Hide file tree
Showing 11 changed files with 2,562 additions and 283 deletions.
16 changes: 7 additions & 9 deletions Sources/ManageMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,12 @@ function ViewMemberlist()
// Make sure numeric values are really numeric.
if (in_array($param_info['type'], array('int', 'age')))
$search_params[$param_name] = (int) $search_params[$param_name];
// Date values have to match the specified format.
// Date values have to match a date format that PHP recognizes.
elseif ($param_info['type'] == 'date')
{
// Check if this date format is valid.
if (preg_match('/^\d{4}-\d{1,2}-\d{1,2}$/', $search_params[$param_name]) == 0)
$search_params[$param_name] = strtotime($search_params[$param_name] . ' ' . getUserTimezone());
if (!is_int($search_params[$param_name]))
continue;

$search_params[$param_name] = strtotime($search_params[$param_name]);
}
elseif ($param_info['type'] == 'inet')
{
Expand Down Expand Up @@ -336,20 +334,20 @@ function ViewMemberlist()
{
if ($search_params['types'][$param_name] == '=')
{
$query_parts[] = $param_info['db_fields'][0] . ' >= ' . forum_time(true, $search_params[$param_name], true) . ' AND ' . $param_info['db_fields'][0] . ' < ' . (forum_time(true, $search_params[$param_name], true) + 86400);
$query_parts[] = $param_info['db_fields'][0] . ' >= ' . forum_time(true, $search_params[$param_name]) . ' AND ' . $param_info['db_fields'][0] . ' < ' . (forum_time(true, $search_params[$param_name]) + 86400);
}
// Less than or equal to
elseif ($search_params['types'][$param_name] == '-')
{
$query_parts[] = $param_info['db_fields'][0] . ' < ' . (forum_time(true, $search_params[$param_name], true) + 86400);
$query_parts[] = $param_info['db_fields'][0] . ' < ' . (forum_time(true, $search_params[$param_name]) + 86400);
}
// Greater than
elseif ($search_params['types'][$param_name] == '++')
{
$query_parts[] = $param_info['db_fields'][0] . ' >= ' . (forum_time(true, $search_params[$param_name], true) + 86400);
$query_parts[] = $param_info['db_fields'][0] . ' >= ' . (forum_time(true, $search_params[$param_name]) + 86400);
}
else
$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . forum_time(true, $search_params[$param_name], true);
$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . forum_time(true, $search_params[$param_name]);
}
else
$query_parts[] = $param_info['db_fields'][0] . ' ' . $range_trans[$search_params['types'][$param_name]] . ' ' . $search_params[$param_name];
Expand Down
13 changes: 1 addition & 12 deletions Sources/ManageSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ function ModifyBasicSettings($return_config = false)
'min' => -23.5,
'max' => 23.5
),
'default_timezone' => array('select', 'default_timezone', array()),
array('select', 'default_timezone', array_filter(smf_list_timezones(), 'is_string', ARRAY_FILTER_USE_KEY)),
array('text', 'timezone_priority_countries', 'subtext' => $txt['setting_timezone_priority_countries_note']),
'',

Expand Down Expand Up @@ -243,17 +243,6 @@ function ModifyBasicSettings($return_config = false)
),
);

// Get all the time zones.
if (function_exists('timezone_identifiers_list') && function_exists('date_default_timezone_set'))
{
$all_zones = timezone_identifiers_list();
// Make sure we set the value to the same as the printed value.
foreach ($all_zones as $zone)
$config_vars['default_timezone'][2][$zone] = $zone;
}
else
unset($config_vars['default_timezone']);

call_integration_hook('integrate_modify_basic_settings', array(&$config_vars));

if ($return_config)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ function Post($post_errors = array())
}

// Gotta post it somewhere.
if (empty($board) && !$context['make_event'])
if (empty($board))
{
$context['posting_fields']['board'] = array(
'label' => array(
Expand Down
50 changes: 0 additions & 50 deletions Sources/Subs-Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1776,56 +1776,6 @@ function buildEventDatetimes($row)
return array($start, $end, $allday, $span, $tz, $tz_abbrev);
}

/**
* Gets a member's selected timezone identifier directly from the database
*
* @param int $id_member The member id to look up. If not provided, the current user's id will be used.
* @return string The timezone identifier string for the user's timezone.
*/
function getUserTimezone($id_member = null)
{
global $smcFunc, $context, $user_info, $modSettings, $user_settings;
static $member_cache = array();

if (is_null($id_member) && $user_info['is_guest'] == false)
$id_member = $context['user']['id'];

//check if the cache got the data
if (isset($id_member) && isset($member_cache[$id_member]))
{
return $member_cache[$id_member];
}

//maybe the current user is the one
if (isset($user_settings['id_member']) && $user_settings['id_member'] == $id_member && !empty($user_settings['timezone']))
{
$member_cache[$id_member] = $user_settings['timezone'];
return $user_settings['timezone'];
}

if (isset($id_member))
{
$request = $smcFunc['db_query']('', '
SELECT timezone
FROM {db_prefix}members
WHERE id_member = {int:id_member}',
array(
'id_member' => $id_member,
)
);
list($timezone) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
}

if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC)))
$timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get();

if (isset($id_member))
$member_cache[$id_member] = $timezone;

return $timezone;
}

/**
* Gets all of the holidays for the listing
*
Expand Down
Loading

0 comments on commit a138346

Please sign in to comment.