version 2.5

This commit is contained in:
ivan 2020-04-04 11:52:59 +03:00
parent 4ea02f909d
commit 658ecbd0ff
3 changed files with 119 additions and 16 deletions

View File

@ -4,10 +4,10 @@ under DWTWL 2.55 license: https://soundragon.su/license/license.html
https://wordpress.org/plugins/discordian-date-function/ https://wordpress.org/plugins/discordian-date-function/
This plugin allows WordPress to easily show Erisian dates instead of the standard Gregorian dates. No theme changes are required. This plugin allows WordPress to easily show Erisian dates and time (decimal) instead of the standard Gregorian dates. No theme changes are required.
This functional based on the Discordian Date plugin by Dan Johnson. This functional based on the Discordian Date plugin by Dan Johnson.
Also provides a widget which displays the current date according to the Discordian calendar, with notification of more than 70 holydays. Also provides a widget which displays the current date according to the Discordian calendar, with notification of more than 70 holidays.
And you can add the shortcode [todаy_ddate] in posts or pages for show the Discordian date of today. And you can add the shortcode [todаy_ddate] in posts or pages for show the Discordian date of today.

View File

@ -2,8 +2,8 @@
/* /*
Plugin Name: Discordian Date Function Plugin Name: Discordian Date Function
Plugin URI: https://is3.soundragon.su/discordian-date-function Plugin URI: https://is3.soundragon.su/discordian-date-function
Description: Convert dates in Wordpress to customizable Discordian dates. Also, this plugin provides shortcode and widget used to display the current erisian date with notification of 70 holydays. Based on the Discordian Date plugin by Dan Johnson. Description: Convert dates in Wordpress to customizable Discordian dates and time (decimal). Also, this plugin provides shortcode and widget used to display the current erisian date with notification of 70 holydays. Based on the Discordian Date plugin by Dan Johnson.
Version: 0.555 Version: 2.5
Author: ivan zlax Author: ivan zlax
Author URI: https://is3.soundragon.su/about Author URI: https://is3.soundragon.su/about
*/ */
@ -19,17 +19,31 @@ function get_ddate($content, $format = "", $originalRequest = null) {
switch ($originalRequest) { switch ($originalRequest) {
case "get_the_date": case "get_the_date":
case "get_the_time":
$post = get_post( $format ); $post = get_post( $format );
$standard_date = getdate (mysql2date( 'U', $post->post_date )); if ( get_option('dtime_convert') == '1' )
$standard_date = utcm5_convert(mysql2date( 'U', $post->post_date_gmt ));
else
$standard_date = getdate (mysql2date( 'U', $post->post_date ));
break; break;
case "get_comment_date": case "get_comment_date":
case "get_comment_time":
$comment = get_comment( $format ); $comment = get_comment( $format );
$standard_date = getdate (mysql2date( 'U', $comment->comment_date )); if ( get_option('dtime_convert') == '1' )
$standard_date = utcm5_convert(mysql2date( 'U', $comment->comment_date_gmt ));
else
$standard_date = getdate (mysql2date( 'U', $comment->comment_date ));
break; break;
case "now": case "now":
$standard_date = getdate(); if ( get_option('dtime_convert') == '1' )
$standard_date = utcm5_convert(getdate()[0]);
else
$standard_date = getdate();
} }
if ($originalRequest == "get_comment_time") return dtime_convert($standard_date);
if ($originalRequest == "get_the_time") return dtime_convert($standard_date);
$dyear=$standard_date["year"]+1166; $dyear=$standard_date["year"]+1166;
$gyear=$standard_date["year"]; $gyear=$standard_date["year"];
$yday=$standard_date["yday"]; $yday=$standard_date["yday"];
@ -77,6 +91,9 @@ function get_ddate($content, $format = "", $originalRequest = null) {
$patterns[7] = '%GN'; $patterns[7] = '%GN';
$patterns[8] = '%GD'; $patterns[8] = '%GD';
$patterns[9] = '%GW'; $patterns[9] = '%GW';
$patterns[10] = '%DT';
$patterns[11] = '%CT';
$patterns[12] = '%UT';
$replacements = array(); $replacements = array();
$replacements[0] = $dyear; $replacements[0] = $dyear;
$replacements[1] = $name_season; $replacements[1] = $name_season;
@ -92,11 +109,40 @@ function get_ddate($content, $format = "", $originalRequest = null) {
$replacements[7] = $standard_date["mon"]; $replacements[7] = $standard_date["mon"];
$replacements[8] = $standard_date["mday"]; $replacements[8] = $standard_date["mday"];
$replacements[9] = $standard_date["weekday"]; $replacements[9] = $standard_date["weekday"];
$replacements[10] = dtime_convert($standard_date);
$replacements[11] = $standard_date["hours"] . ":" . str_pad($standard_date["minutes"], 2, '0', STR_PAD_LEFT);
$replacements[12] = $standard_date[0];
$ddate = str_replace($patterns, $replacements, get_option('ddatefunc_string')); $ddate = str_replace($patterns, $replacements, get_option('ddatefunc_string'));
} }
return $ddate; return $ddate;
} }
function dtime_convert($standard_date) {
$standard_msday = $standard_date["hours"]*3600000+$standard_date["minutes"]*60000+$standard_date["seconds"]*1000;
$discordian_sday = round($standard_msday/864);
$discordian_minutes = $discordian_sday%10000;
$dtime = floor($discordian_sday/10000) . ":" . str_pad(floor($discordian_minutes/100), 2, '0', STR_PAD_LEFT);
return $dtime;
}
function utcm5_convert($standard_date) {
// Easter Island Winter Time Zone offset (-5*60*60)
$utcm5_date = array();
$utcm5_date[0] = $standard_date;
$unixtime_utcm5 = $standard_date-18000;
$utcm5_date["seconds"] = gmdate("s", $unixtime_utcm5);
$utcm5_date["minutes"] = gmdate("i", $unixtime_utcm5);
$utcm5_date["hours"] = gmdate("G", $unixtime_utcm5);
$utcm5_date["mday"] = gmdate("j", $unixtime_utcm5);
$utcm5_date["wday"] = gmdate("w", $unixtime_utcm5);
$utcm5_date["mon"] = gmdate("n", $unixtime_utcm5);
$utcm5_date["year"] = gmdate("Y", $unixtime_utcm5);
$utcm5_date["yday"] = gmdate("z", $unixtime_utcm5);
$utcm5_date["weekday"] = gmdate("l", $unixtime_utcm5);
$utcm5_date["month"] = gmdate("F", $unixtime_utcm5);
return $utcm5_date;
}
class Discordian_Date_Widget extends WP_Widget { class Discordian_Date_Widget extends WP_Widget {
function Discordian_Date_Widget() { function Discordian_Date_Widget() {
@ -269,9 +315,15 @@ class Discordian_Date_Widget extends WP_Widget {
function get_the_ddate_post($content, $format = null) { function get_the_ddate_post($content, $format = null) {
return get_ddate($content, $format, "get_the_date"); } return get_ddate($content, $format, "get_the_date"); }
function get_the_dtime_post($content, $format = null) {
return get_ddate($content, $format, "get_the_time"); }
function get_the_ddate_comment($content, $format = null) { function get_the_ddate_comment($content, $format = null) {
return get_ddate($content, $format, "get_comment_date"); } return get_ddate($content, $format, "get_comment_date"); }
function get_the_dtime_comment($content, $format = null) {
return get_ddate($content, $format, "get_comment_time"); }
function register_ddatefunc_widget() { function register_ddatefunc_widget() {
register_widget( 'Discordian_Date_Widget' ); register_widget( 'Discordian_Date_Widget' );
} }
@ -300,10 +352,18 @@ function ddatefunc_admin() {
echo '<h2>'.$settings_name.'</h2>'; echo '<h2>'.$settings_name.'</h2>';
if (isset($_POST['save'])) { if (isset($_POST['save'])) {
update_option('ddatefunc_string', stripslashes($_POST['textfield'])); update_option('ddatefunc_string', stripslashes($_POST['textfield']));
if (isset($_POST['checkbox'])) if (isset($_POST['ddatefunc_change_checkbox']))
update_option('ddatefunc_change', "1"); update_option('ddatefunc_change', "1");
else else
update_option('ddatefunc_change', "0"); update_option('ddatefunc_change', "0");
if (isset($_POST['dtimefunc_change_checkbox']))
update_option('dtimefunc_change', "1");
else
update_option('dtimefunc_change', "0");
if (isset($_POST['dtime_convert_checkbox']))
update_option('dtime_convert', "1");
else
update_option('dtime_convert', "0");
echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><b>'.__('Settings saved.').'</b></p></div>'; echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><b>'.__('Settings saved.').'</b></p></div>';
} }
?> ?>
@ -328,6 +388,9 @@ function ddatefunc_admin() {
<b>%GN</b> - Gregorian month number (example: 1)<br> <b>%GN</b> - Gregorian month number (example: 1)<br>
<b>%GD</b> - Gregorian month day (example: 5)<br> <b>%GD</b> - Gregorian month day (example: 5)<br>
<b>%GW</b> - Gregorian weekday (example: Friday)<br> <b>%GW</b> - Gregorian weekday (example: Friday)<br>
<b>%DT</b> - Discordian (decimal) time (example: 5:67)<br>
<b>%CT</b> - Christian time (example: 23:00)<br>
<b>%UT</b> - Unix time (example: 1555222555)<br>
<br> <br>
Examples<br> Examples<br>
<br> <br>
@ -337,14 +400,40 @@ Examples<br>
</td> </td>
</tr> </tr>
<tr valign="top"> <tr valign="top">
<th scope="row">Convert all post and comments dates:</th> <th scope="row">Convert all post and comment dates:</th>
<td> <td>
<fieldset> <fieldset>
<legend class="screen-reader-text"> <legend class="screen-reader-text">
<span>Convert to Discordian dates</span> <span>Convert to Discordian dates</span>
</legend> </legend>
<label for="users_can_register"> <label for="users_can_register">
<input name="checkbox" id="users_can_register" type="checkbox" value="1" <?php if(get_option('ddatefunc_change')==1) { echo 'checked="checked"'; } ?>> <input name="ddatefunc_change_checkbox" id="users_can_register" type="checkbox" value="1" <?php if(get_option('ddatefunc_change')==1) { echo 'checked="checked"'; } ?>>
</label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row">Convert Christian time to Discordian (decimal) time:</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span>Convert to Erisian time</span>
</legend>
<label for="users_can_register">
<input name="dtimefunc_change_checkbox" id="users_can_register" type="checkbox" value="1" <?php if(get_option('dtimefunc_change')==1) { echo 'checked="checked"'; } ?>>
</label>
</fieldset>
</td>
</tr>
<tr valign="top">
<th scope="row">Use Erisian start of the day - <a href="https://www.reddit.com/r/Time/comments/fhys8v/erisian_time/">starts 5 Christian hours later than the day in London</a>:</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span>Erisian start of the day</span>
</legend>
<label for="users_can_register">
<input name="dtime_convert_checkbox" id="users_can_register" type="checkbox" value="1" <?php if(get_option('dtime_convert')==1) { echo 'checked="checked"'; } ?>>
</label> </label>
</fieldset> </fieldset>
</td> </td>
@ -370,12 +459,16 @@ function ddatefunc_settings( $actions, $plugin_file ) {
function ddatefunc_deinstall() { function ddatefunc_deinstall() {
delete_option('ddatefunc_string'); delete_option('ddatefunc_string');
delete_option('ddatefunc_change'); delete_option('ddatefunc_change');
delete_option('dtimefunc_change');
delete_option('dtime_convert');
} }
add_shortcode( 'today_ddate', 'return_today_ddate' ); add_shortcode( 'today_ddate', 'return_today_ddate' );
add_action( 'widgets_init', 'register_ddatefunc_widget' ); add_action( 'widgets_init', 'register_ddatefunc_widget' );
add_option( 'ddatefunc_string', '%DD day of %DS, in the yold %DY'); add_option( 'ddatefunc_string', '%DD day of %DS, in the yold %DY');
add_option( 'ddatefunc_change', '1'); add_option( 'ddatefunc_change', '1');
add_option( 'dtimefunc_change', '1');
add_option( 'dtime_convert', '1');
add_filter( 'plugin_action_links', 'ddatefunc_settings', 10, 2 ); add_filter( 'plugin_action_links', 'ddatefunc_settings', 10, 2 );
add_action( 'admin_menu', 'ddatefunc_add_admin' ); add_action( 'admin_menu', 'ddatefunc_add_admin' );
@ -385,5 +478,10 @@ if ( get_option('ddatefunc_change') == '1' ) {
add_filter( 'get_comment_date','get_the_ddate_comment' ); add_filter( 'get_comment_date','get_the_ddate_comment' );
} }
if ( get_option('dtimefunc_change') == '1' ) {
add_filter( 'get_the_time','get_the_dtime_post' );
add_filter( 'get_comment_time','get_the_dtime_comment' );
}
if (function_exists('register_uninstall_hook')) if (function_exists('register_uninstall_hook'))
register_uninstall_hook(__FILE__, 'ddatefunc_deinstall'); register_uninstall_hook(__FILE__, 'ddatefunc_deinstall');

View File

@ -1,19 +1,19 @@
=== Discordian Date Function === === Discordian Date Function ===
Contributors: zlaxyi Contributors: zlaxyi
Donate link: https://is3.soundragon.su/discordian-date-function Donate link: https://is3.soundragon.su/discordian-date-function
Tags: date, discordian, erisian, widget, eris, discordia, calendar Tags: date, time, discordian, erisian, widget, eris, discordia, calendar
Requires at least: 2.0 Requires at least: 2.0
Tested up to: 5.3.2 Tested up to: 5.4
Stable tag: trunk Stable tag: trunk
License: DWTWL 2.55 License: DWTWL 2.55
License URI: https://soundragon.su/license/license.html License URI: https://soundragon.su/license/license.html
This plugin provides Erisian (Discordian) dates in Wordpress. This plugin provides Erisian (Discordian) dates and time in Wordpress.
Also provides shortcode and widget which displays the current date according to the Discordian calendar, with notification of 70 holydays. Also provides shortcode and widget which displays the current date according to the Discordian calendar, with notification of more than 70 holidays.
== Description == == Description ==
This plugin allows WordPress to easily show customizable Erisian dates instead of the standard Gregorian dates. No theme changes are required. This plugin allows WordPress to easily show customizable Erisian dates and time (decimal) instead of the standard Gregorian dates. No theme changes are required.
The Discordian Date Function plugin provides a widget which will display the current date according to the [Discordian calendar](http://en.wikipedia.org/wiki/Discordian_calendar). This functional based on the Discordian Date plugin by Dan Johnson. The Discordian Date Function plugin provides a widget which will display the current date according to the [Discordian calendar](http://en.wikipedia.org/wiki/Discordian_calendar). This functional based on the Discordian Date plugin by Dan Johnson.
@ -41,6 +41,11 @@ Feel free to ask any questions about this plugin at the [Discordian Date Functio
== Changelog == == Changelog ==
= 2.5 =
*Release Date - 21st day of Discord, 3186*
* Add optional [Erisian (decimal) time](https://www.reddit.com/r/Time/comments/fhys8v/erisian_time/) support
= 0.555 = = 0.555 =
*Release Date - 60th day of Chaos, 3186* *Release Date - 60th day of Chaos, 3186*
@ -61,5 +66,5 @@ Feel free to ask any questions about this plugin at the [Discordian Date Functio
== Upgrade Notice == == Upgrade Notice ==
= 0.555 = = 2.5 =
This version is actual. This version is actual.