Time Zone Configuration
This plugin allows to specify a time zone and to format time/date display
';
if( defined('YOURLS_HOURS_OFFSET') ) {
print 'Note: you have YOURLS_HOURS_OFFSET
defined in your config.php. This plugin will override this setting.
';
}
print '
Note: custom formats need a PHP date()
string.';
}
/**
* Output CSS & JS
*/
function yourls_tzp_js_css() {
$plugin_url = yourls_plugin_url( __DIR__ );
print <<
JSCSS;
}
/**
* Draw the time zone drop down
*
* @param string $user_time_zone Timezone to be marked as "selected" in the dropdown
*/
function yourls_tzp_tz_dropdown( $user_time_zone ) {
// Continent list
$continent = array(
'Africa' => DateTimeZone::AFRICA,
'America' => DateTimeZone::AMERICA,
'Antarctica' => DateTimeZone::ANTARCTICA,
'Asia' => DateTimeZone::ASIA,
'Atlantic' => DateTimeZone::ATLANTIC,
'Australia' => DateTimeZone::AUSTRALIA,
'Europe' => DateTimeZone::EUROPE,
'Indian' => DateTimeZone::INDIAN,
'Pacific' => DateTimeZone::PACIFIC,
);
// Timezones per continents
$timezones = array();
foreach ($continent as $name => $mask) {
$zones = DateTimeZone::listIdentifiers($mask);
foreach($zones as $timezone) {
// Remove region name
$timezones[$name][$timezone] = substr($timezone, strlen($name) +1);
}
}
// Manual UTC offset
$offset_range = array(
'-12', '-11:30', '-11', '-10:30', '-10', '-9.5', '-9',
'-8:30', '-8', '-7:30', '-7', '-6:30', '-6', '-5:30',
'-5', '-4:30', '-4', '-3:30', '-3', '-2:30', '-2',
'-1:30', '-1', '-0:30', 'UTC', '+0:30', '+1', '+1:30',
'+2', '+2:30', '+3', '+3:30', '+4', '+4:30', '+5',
'+5:30', '+5:45', '+6', '+6:30', '+7', '+7:30', '+8',
'+8:30', '+8:45', '+9', '+9:30', '+10', '+10:30', '+11',
'+11:30', '+12', '+12:45', '+13', '+13:45', '+14'
);
foreach( $offset_range as $offset_name ) {
$offset_value = $offset_name;
$offset_name = str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), $offset_name );
if ($offset_name != 'UTC') {
$offset_name = 'UTC' . $offset_name;
}
// $offset_value = 'UTC' . $offset_value;
$timezones['UTC'][$offset_value] = $offset_name;
}
print '';
}
/**
* Output radio button list
*
* @param string $title Dropdown title
* @param string $input_name Dropdown 'radio' name
* @param array $formats List of available choices, to which 'custom' will be appended
* @param string $tz Time zone
* @param string $selected Checked radio value
* @param string $custom Custom format value
*/
function yourls_tzp_format_radio( $title, $input_name, $formats, $tz, $selected, $custom ) {
print "
$title:
';
}
/**
* Update time zone in database
*/
function yourls_tzp_config_update_settings() {
$settings = array(
'time_zone' => yourls_tzp_get_value($_POST, 'time_zone', 'UTC'),
'date_format' => yourls_tzp_get_value($_POST, 'date_format', 'Y/m/d'),
'date_format_custom' => yourls_tzp_get_value($_POST, 'date_format_custom_value', 'Y/m/d'),
'time_format' => yourls_tzp_get_value($_POST, 'time_format', 'H:i'),
'time_format_custom' => yourls_tzp_get_value($_POST, 'time_format_custom_value', 'H:i'),
);
yourls_update_option( 'timezone', $settings );
return $settings;
}