ddatefunc/ddatefunc.php

390 lines
14 KiB
PHP
Raw Normal View History

2017-03-18 05:20:33 +00:00
<?php
/*
Plugin Name: Discordian Date Function
Plugin URI: https://is3.soundragon.su/discordian-date-function
2017-03-19 11:18:04 +00:00
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.
2020-03-01 09:46:42 +00:00
Version: 0.555
2017-03-18 05:20:33 +00:00
Author: ivan zlax
Author URI: https://is3.soundragon.su/about
*/
function get_ddate($content, $format = "", $originalRequest = null) {
/*
Based on: http://www.dexterityunlimited.com/wordpress-plugins/discordian-date/ by Dan Johnson
*/
$season_list = array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath");
$day_list = array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
switch ($originalRequest) {
case "get_the_date":
$post = get_post( $format );
$standard_date = getdate (mysql2date( 'U', $post->post_date ));
break;
case "get_comment_date":
$comment = get_comment( $format );
$standard_date = getdate (mysql2date( 'U', $comment->comment_date ));
break;
case "now":
$standard_date = getdate();
}
$dyear=$standard_date["year"]+1166;
2020-03-01 09:46:42 +00:00
$gyear=$standard_date["year"];
2017-03-18 05:20:33 +00:00
$yday=$standard_date["yday"];
2020-03-01 09:46:42 +00:00
// Check Tib's day according to Gregorian calendar
if ($gyear%4==0&&$gyear%100!=0 || $gyear%400==0) {
if ($standard_date["yday"]==59) $sttib="St. Tib's";
if ($standard_date["yday"]>59) $yday=$standard_date["yday"]-1;
}
2017-03-18 05:20:33 +00:00
$mon=$standard_date["mon"];
$mday=$standard_date["mday"];
$dseason=(int)($yday/73);
$name_season=$season_list[$dseason];
$dday=($yday-(73*$dseason))+1;
2017-03-19 11:18:04 +00:00
$clear_dday=$dday;
2017-03-18 05:20:33 +00:00
$suff=$dday%10;
switch ($suff) {
case 1:
$dday.="st";
break;
case 2:
$dday.="nd";
break;
case 3:
$dday.="rd";
break;
default:
$dday.="th";
}
$dweekday=$day_list[($yday%5)];
2017-03-19 11:18:04 +00:00
if ($originalRequest == "now") {
$ddate=$dweekday.", the ".$dday." day of ".$name_season.", in the yold ".$dyear;
2020-03-01 09:46:42 +00:00
if (isset($sttib)) $ddate=$sttib." day, in the yold ".$dyear;
2017-03-19 11:18:04 +00:00
} else {
$patterns = array();
$patterns[0] = '%DY';
$patterns[1] = '%DS';
$patterns[2] = '%DD';
$patterns[3] = '%DC';
$patterns[4] = '%DW';
$patterns[5] = '%GY';
$patterns[6] = '%GM';
$patterns[7] = '%GN';
$patterns[8] = '%GD';
$patterns[9] = '%GW';
$replacements = array();
$replacements[0] = $dyear;
$replacements[1] = $name_season;
$replacements[2] = $dday;
$replacements[3] = $clear_dday;
2020-03-01 09:46:42 +00:00
if (isset($sttib)) {
$replacements[2] = $sttib;
$replacements[3] = "tib";
}
2017-03-19 11:18:04 +00:00
$replacements[4] = $dweekday;
$replacements[5] = $standard_date["year"];
$replacements[6] = $standard_date["month"];
$replacements[7] = $standard_date["mon"];
$replacements[8] = $standard_date["mday"];
$replacements[9] = $standard_date["weekday"];
$ddate = str_replace($patterns, $replacements, get_option('ddatefunc_string'));
}
2017-03-18 05:20:33 +00:00
return $ddate;
}
class Discordian_Date_Widget extends WP_Widget {
function Discordian_Date_Widget() {
$widget_ops = array('classname' => 'discordian_date_func', 'description' => 'Display the current date according to the Discordian Calendar.');
$control_ops = array('width' => 200, 'height' => 120);
$this->WP_Widget('discordian_date_func', 'Discordian Date Widget', $widget_ops, $control_ops);
}
function widget($args, $instance) {
$now = getdate();
$yday=$now["yday"];
$mon=$now["mon"];
$mday=$now["mday"];
$dseason=(int)($yday/73);
if ($now["year"]%4==0&&$now["year"]%100!=0 || $now["year"]%400==0)
if ($now["yday"]>59) $yday=$now["yday"]-1;
2017-03-18 05:20:33 +00:00
$dday=($yday-(73*$dseason))+1;
$a_holiday=array("Mungday", "Mojoday", "Syaday", "Zaraday", "Maladay");
$s_holiday=array("Chaoflux", "Discoflux", "Confuflux", "Bureflux", "Afflux");
2017-03-19 11:18:04 +00:00
$m_holyday=array("Chaomas", "Discomas", "Confumas", "Buremas", "Afmas");
$t_holyday=array("Chaosloth", "Discosloth", "Confusloth", "Buresloth", "Afsloth");
$e_holyday=array("Mungeye", "Mojeye", "Syadeye", "Zareye", "Maleye");
2017-03-18 05:20:33 +00:00
$holyday="";
if ($dday==5) {
2017-03-19 11:18:04 +00:00
$holyday = " Celebrate Apostle Day, ".$a_holiday[$dseason].".";
2017-03-18 05:20:33 +00:00
} elseif ($dday==23) {
2017-03-19 11:18:04 +00:00
$holyday = " Celebrate Synaptyclypse Day, ".$m_holiday[$dseason].".";
2017-03-18 05:20:33 +00:00
} elseif ($dday==27) {
2017-03-19 11:18:04 +00:00
$holyday = " Celebrate Sloth Day, ".$t_holiday[$dseason].".";
2020-03-01 09:46:42 +00:00
} elseif ($dday==50) {
$holyday = " Celebrate Flux Day, ".$s_holiday[$dseason].".";
2017-03-18 05:20:33 +00:00
} elseif ($dday==73) {
2017-03-19 11:18:04 +00:00
$holyday = " Celebrate Eye Day, ".$e_holiday[$dseason].".";
2020-03-01 09:46:42 +00:00
} elseif ($mon==2 && $mday==29) {
$holyday = " Celebrate St. Tib's Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==0 && $dday==8) {
$holyday = " Celebrate Death of Emperor Norton.";
} elseif ($dseason==0 && $dday==10) {
2020-03-01 09:46:42 +00:00
$holyday = " Celebrate Backwards/Binary Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==0 && $dday==11) {
$holyday = " Celebrate RAW Day.";
} elseif ($dseason==0 && $dday==14) {
$holyday = " Celebrate Golden Apple Presentation Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==0 && $dday==17) {
$holyday = " Celebrate Joshmas.";
} elseif ($dseason==0 && $dday==18) {
$holyday = " Celebrate Pat Pineapple Day.";
} elseif ($dseason==0 && $dday==21) {
$holyday = " Celebrate Hug Day.";
} elseif ($dseason==0 && $dday==26) {
$holyday = " Celebrate Backwards Day (Traditional).";
} elseif ($dseason==0 && $dday==37) {
$holyday = " Celebrate Aaron Burrs Birthday.";
} elseif ($dseason==0 && $dday==49) {
$holyday = " Celebrate The Mary Day.";
} elseif ($dseason==0 && $dday==51) {
$holyday = " Celebrate Pet Loving Day.";
} elseif ($dseason==0 && $dday==69) {
$holyday = " Celebrate Head Chicken/Chicken Head Day.";
} elseif ($dseason==0 && $dday==72) {
$holyday = " Celebrate Daytime.";
} elseif ($dseason==1 && $dday==4) {
$holyday = " Celebrate Grover Clevelands Birthday.";
} elseif ($dseason==1 && $dday==11) {
$holyday = " Celebrate Discordians for Jesus/Love Your Neighbor Day.";
} elseif ($dseason==1 && $dday==18) {
2020-03-01 09:46:42 +00:00
$holyday = " Celebrate Fools Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==1 && $dday==19) {
2020-03-01 09:46:42 +00:00
$holyday = " Celebrate St. John the Blasphemists Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==1 && $dday==34) {
$holyday = " Celebrate Omarmas.";
} elseif ($dseason==1 && $dday==43) {
$holyday = " Celebrate Universal Ordination Day.";
} elseif ($dseason==1 && $dday==68) {
$holyday = " Celebrate Mal-2mas.";
} elseif ($dseason==1 && $dday==70) {
$holyday = " Celebrate Jake Day Jr. (DJ)/Day of the Elppin.";
} elseif ($dseason==1 && $dday==72) {
$holyday = " Celebrate Towel Day.";
} elseif ($dseason==2 && $dday==26) {
$holyday = " Celebrate Imaginary Friend/Captain Tuttle Day.";
2020-03-01 09:46:42 +00:00
} elseif ($dseason==2 && $dday==28) {
$holyday = " Celebrate St. Georges Day.";
} elseif ($dseason==2 && $dday==30) {
$holyday = " Celebrate Zoog Day.";
} elseif ($dseason==2 && $dday==36) {
$holyday = " Celebrate June 31st for Popes.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==2 && $dday==37) {
$holyday = " Celebrate Mid-Years Day.";
} elseif ($dseason==2 && $dday==40) {
$holyday = " Celebrate X-Day.";
} elseif ($dseason==2 && $dday==55) {
$holyday = " Celebrate Mal-2 Day.";
2020-03-01 09:46:42 +00:00
} elseif ($dseason==2 && $dday==57) {
$holyday = " Celebrate John Dillinger Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==3 && $dday==3) {
$holyday = " Celebrate Multiversal Underwear Day.";
} elseif ($dseason==3 && $dday==18) {
$holyday = " Celebrate Festival of Hanky-Panky Spankies.";
} elseif ($dseason==3 && $dday==33) {
2020-03-01 09:46:42 +00:00
$holyday = " Celebrate Cat Dancing & Pussyfoot Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==3 && $dday==37) {
$holyday = " Celebrate Mass of Planet Eris/Eristotle.";
2020-03-01 09:46:42 +00:00
} elseif ($dseason==3 && $dday==39) {
$holyday = " Celebrate St. Mammes's Day.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==3 && $dday==41) {
$holyday = " Celebrate Emperor Norton Proclamation Day.";
} elseif ($dseason==3 && $dday==57) {
$holyday = " Celebrate Shamlicht Kids Club Day.";
} elseif ($dseason==3 && $dday==59) {
$holyday = " Celebrate Gonkulator Day (Gonculator Day).";
} elseif ($dseason==3 && $dday==60) {
$holyday = " Celebrate Mad Hatter Day.";
} elseif ($dseason==3 && $dday==66) {
$holyday = " Celebrate Habeas Corpus Remembrance Day.";
} elseif ($dseason==4 && $dday==28) {
$holyday = " Celebrate Ek-sen-triks CluborGuild Day.";
} elseif ($dseason==4 && $dday==36) {
$holyday = " Celebrate Spanking Fest.";
} elseif ($dseason==4 && $dday==37) {
$holyday = " Celebrate 537 Day, sometimes Turkey Day.";
} elseif ($dseason==4 && $dday==40) {
$holyday = " Celebrate Omars Day.";
} elseif ($dseason==4 && $dday==43) {
$holyday = " Celebrate Day D.";
2017-03-18 05:20:33 +00:00
} elseif ($dseason==4 && $dday==46) {
$holyday = " Celebrate Hug Day II.";
2020-03-01 09:46:42 +00:00
} elseif ($dseason==4 && $dday==65) {
$holyday = " Celebrate Circlemas.";
2017-03-18 05:20:33 +00:00
}
extract($args);
$title = $instance['title'];
$body = apply_filters('widget_text', $instance['body']);
ob_start();
echo "<div class=\"discordian_date_func\" style=\"width:100%;text-align:center;font-size:18px;line-height:36px;padding-top:40px;padding-bottom:40px;\"> Today is ";
echo get_ddate($content, $format, "now").".";
if ($holyday) echo "<br><b>".$holyday."</b>";
echo "</div>";
$body2 = ob_get_contents();
ob_end_clean();
if (!empty($title2)||!empty($body2)) echo $before_widget;
if (!empty($title2)) echo $before_title,$title2,$after_title;
if (!empty($body2)) echo $body2;
if (!empty($title2)||!empty($body2)) echo $after_widget;
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
$title = $instance['title'];
$title_id = $this->get_field_id('title');
$title_name = $this->get_field_name('title');
?>
<p>
<label for="<?php echo $title_id; ?>"><strong>Title:</strong></label>
<input class="widefat" id="<?php echo $title_id; ?>" name="<?php echo $title_name; ?>"
type="text" value="<?php echo esc_attr($title); ?>"/>
</p>
2017-03-19 11:18:04 +00:00
<?php
2017-03-18 05:20:33 +00:00
}
}
function get_the_ddate_post($content, $format = null) {
2017-03-18 05:20:33 +00:00
return get_ddate($content, $format, "get_the_date"); }
function get_the_ddate_comment($content, $format = null) {
2017-03-18 05:20:33 +00:00
return get_ddate($content, $format, "get_comment_date"); }
function register_ddatefunc_widget() {
register_widget( 'Discordian_Date_Widget' );
}
2017-03-19 11:18:04 +00:00
function today_ddate() {
2017-03-18 05:20:33 +00:00
echo return_today_hebDate();
}
function return_today_ddate() {
return get_ddate($content, $format, "now");
}
2017-03-19 11:18:04 +00:00
$settings_name = "Discordian Date Function Settings";
function ddatefunc_add_admin() {
global $settings_name;
add_options_page(__('Settings').': '.$settings_name, $settings_name, 'edit_themes', basename(__FILE__), 'ddatefunc_admin');
}
function ddatefunc_admin() {
global $settings_name;
?>
<div class="wrap">
<?php
screen_icon();
echo '<h2>'.$settings_name.'</h2>';
if (isset($_POST['save'])) {
update_option('ddatefunc_string', stripslashes($_POST['textfield']));
if (isset($_POST['checkbox']))
update_option('ddatefunc_change', "1");
else
update_option('ddatefunc_change', "0");
echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><b>'.__('Settings saved.').'</b></p></div>';
}
?>
<form method="post">
<table class="form-table">
<tr valign="top">
<th scope="row">Date string:</th>
<td>
<input name="textfield" class="regular-text" type="text" value="<?php echo get_option('ddatefunc_string'); ?>" >
</td>
</tr>
<tr valign="top">
<th scope="row">Legend:</th>
<td>
<b>%DY</b> - Discordian yold (example: 3180)<br>
<b>%DS</b> - Erisian season name (example: Chaos)<br>
<b>%DD</b> - Discordian season day (example: 5th)<br>
<b>%DC</b> - Clear erisian day number (example: 5)<br>
<b>%DW</b> - Discordian week day (example: Setting Orange)<br>
<b>%GY</b> - Gregorian year (example: 2014)<br>
<b>%GM</b> - Gregorian month (example: January)<br>
<b>%GN</b> - Gregorian month number (example: 1)<br>
<b>%GD</b> - Gregorian month day (example: 5)<br>
<b>%GW</b> - Gregorian weekday (example: Friday)<br>
<br>
Examples<br>
<br>
<b>%DW, the %DD day of %DS, in the yold %DY</b><br> returns:<br><b>Setting Orange, the 5th day of Chaos, in the yold 3180</b><br>
<br>
<b>%DC %DS, %DY (%GN.%GN.%GY)</b><br> returns:<br><b>5 Chaos, 3180 (5.1.2014)</br>
</td>
</tr>
<tr valign="top">
<th scope="row">Convert all post and comments dates:</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<span>Convert to Discordian dates</span>
</legend>
<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"'; } ?>>
</label>
</fieldset>
</td>
</tr>
</table>
<div class="submit">
<input name="save" type="submit" class="button-primary" value="<?php echo __('Save Cganges'); ?>" />
</div>
</form>
</div>
<?php
}
function ddatefunc_settings( $actions, $plugin_file ) {
if( false === strpos( $plugin_file, basename(__FILE__) ) )
return $actions;
$settings_link = '<a href="options-general.php?page=ddatefunc.php' .'">Settings</a>';
array_unshift( $actions, $settings_link );
return $actions;
}
function ddatefunc_deinstall() {
delete_option('ddatefunc_string');
delete_option('ddatefunc_change');
}
add_shortcode( 'today_ddate', 'return_today_ddate' );
2017-03-18 05:20:33 +00:00
add_action( 'widgets_init', 'register_ddatefunc_widget' );
2017-03-19 11:18:04 +00:00
add_option( 'ddatefunc_string', '%DD day of %DS, in the yold %DY');
add_option( 'ddatefunc_change', '1');
add_filter( 'plugin_action_links', 'ddatefunc_settings', 10, 2 );
add_action( 'admin_menu', 'ddatefunc_add_admin' );
if ( get_option('ddatefunc_change') == '1' ) {
add_filter( 'get_the_date','get_the_ddate_post' );
add_filter( 'get_comment_date','get_the_ddate_comment' );
}
if (function_exists('register_uninstall_hook'))
2020-03-01 09:46:42 +00:00
register_uninstall_hook(__FILE__, 'ddatefunc_deinstall');