-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheaster.php
189 lines (165 loc) · 8.62 KB
/
easter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use LiturgicalCalendar\Frontend\Utilities;
include_once "common.php";
$AllAvailableLocales = array_filter(ResourceBundle::getLocales(''), function ($value) {
return strpos($value, 'POSIX') === false;
});
$currentLocale = isset($_GET["locale"]) && in_array($_GET["locale"], $AllAvailableLocales) ? $_GET["locale"] : "en_US"; //default to English
ini_set('date.timezone', 'Europe/Vatican');
$AvailableLocalesWithRegion = array_filter($AllAvailableLocales, function ($value) {
return strpos($value, '_') === false;
});
$AvailableLocalesWithRegion = array_reduce($AvailableLocalesWithRegion, function ($carry, $item) use ($currentLocale) {
$carry[$item] = Locale::getDisplayLanguage($item, $currentLocale);
return $carry;
}, []);
$baseLocale = Locale::getPrimaryLanguage($currentLocale);
$localeArray = [
$currentLocale . '.utf8',
$currentLocale . '.UTF-8',
$currentLocale,
$baseLocale . '.utf8',
$baseLocale . '.UTF-8',
$baseLocale
];
setlocale(LC_ALL, $localeArray);
bindtextdomain("litcal", "i18n");
textdomain("litcal");
$c = new Collator($currentLocale);
$c->asort($AvailableLocalesWithRegion);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $dateOfEasterURL . "?locale=" . $currentLocale);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
curl_close($ch);
die($error_msg);
}
curl_close($ch);
$responseJson = json_decode($response);
if (json_last_error() !== JSON_ERROR_NONE) {
$error_msg = json_last_error_msg();
die($error_msg);
}
if (
false === property_exists($responseJson, "litcal_easter")
||
false === is_array($responseJson->litcal_easter)
) {
$error_msg = "Missing data from response: litcal_easter property does not exist or is not an array";
die($error_msg);
}
$DatesOfEaster = $responseJson->litcal_easter;
?>
<!DOCTYPE html>
<head>
<title><?php echo _('Date of Easter from 1583 to 9999')?></title>
<meta charset="UTF-8">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-TileImage" content="easter-egg-5-144-279148.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="easter-egg-5-152-279148.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="easter-egg-5-144-279148.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="easter-egg-5-120-279148.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="easter-egg-5-114-279148.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="easter-egg-5-72-279148.png">
<link rel="apple-touch-icon-precomposed" href="easter-egg-5-57-279148.png">
<link rel="icon" href="easter-egg-5-32-279148.png" sizes="32x32">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="assets/css/easter.css">
</head>
<body>
<div id="clipDiv" style="position:absolute;top:-500px;height:7em;z-index:0;background-image:linear-gradient(to bottom, rgba(255,255,255, 1), rgba(255,255,255, 1), rgba(255,255,255, 0) );left: 0px;width: 100%;"></div>
<div><a class="backNav" href="/">↩ <?php echo _('Go back')?> ↩</a></div>
<select id="langSelect">
<?php
foreach ($AvailableLocalesWithRegion as $Lcl => $DisplayLang) {
$optionContent = $baseLocale === 'en' ? $DisplayLang : $DisplayLang . ' (' . Locale::getDisplayLanguage($Lcl, 'en') . ')';
echo '<option value="' . $Lcl . '"' . ($baseLocale === $Lcl ? " selected" : "") . ' title="' . Locale::getDisplayLanguage($Lcl, 'en') . '">' . $optionContent . '</option>';
}
?>
</select>
<div id="HistoryNavigationLeftSidebar">
<div id="slider-vertical"></div>
<div id="TimelineCenturiesContainer">
<?php
for ($i = 16; $i <= 100; $i++) {
$century = strtolower($currentLocale) === "en" ? Utilities::ordinal($i) : Utilities::romanNumeral($i);
echo "<div class=\"TimelineCenturyMarker\">" . $century . " " . _("Century") . "</div>";
}
?>
</div>
</div>
<?php
echo '<h3 style="text-align:center;">' . _("Easter Day Calculation in PHP (Years in which Julian and Gregorian easter coincide are marked in yellow)") . '</h3>';
$EasterTableContainer = '<div id="EasterTableContainer">';
$EasterTableContainer .= '<table style="width:60%;margin:30px auto;border:1px solid Blue;border-radius: 6px; padding:10px;background:LightBlue;">';
$EasterTableContainer .= '<thead><tr><th width="300">' . _('Gregorian Easter') . '</th><th width="300">' . _('Julian Easter') . '</th><th width="300">' . _('Julian Easter in Gregorian Calendar') . '</th></tr></thead>';
$EasterTableContainer .= '<tbody>';
//$Y = (int)date("Y");
//for($i=1997;$i<=2037;$i++){
for ($i = 1583; $i <= 9999; $i++) {
$gregDateString = $DatesOfEaster[$i - 1583]->gregorianDateString;
$julianDateString = $DatesOfEaster[$i - 1583]->julianDateString;
$westernJulianDateString = $DatesOfEaster[$i - 1583]->westernJulianDateString;
$style_str = $DatesOfEaster[$i - 1583]->coinciding ? ' style="background-color:Yellow;font-weight:bold;color:Blue;"' : '';
$EasterTableContainer .= '<tr' . $style_str . '><td width="300">' . $gregDateString . '</td><td width="300">' . $julianDateString . '</td><td width="300">' . $westernJulianDateString . '</td></tr>';
}
$EasterTableContainer .= '</tbody></table>';
$EasterTableContainer .= '</div>';
echo '<div style="text-align:center;width:40%;margin:0px auto;font-size:.7em;z-index:10;position:relative;"><i>The last coinciding Easter will be: ' . $responseJson->lastCoincidenceString . '</i></div>';
echo $EasterTableContainer;
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script>
const scale = (num, in_min, in_max, out_min, out_max) => {
return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
//const isStaging = window.location.pathname.includes('-staging');
$(document).ready(function(){
//if(isStaging){ $('.backNav').attr('href','/LiturgicalCalendar-staging/'); }
let tableH = $('#EasterTableContainer table').height();
let timelineH = $("#TimelineCenturiesContainer").children().last().offset().top - $("#TimelineCenturiesContainer").children().first().offset().top;
timelineH /= 2;
timelineH -= $("#TimelineCenturiesContainer").children().first().outerHeight();
$('#TimelineCenturiesContainer div:first-child').addClass('highlight');
let distFromTop = Math.round($('thead tr').offset().top) + 'px';
$('#clipDiv').css({'top':'calc('+distFromTop+' - 3em)'});
$("html,body").animate({scrollTop: 0}, 1000);
$( "#slider-vertical" ).slider({
orientation: "vertical",
range: "min",
step: 1,
min: 0,
max: 1000,
value: 1000,
slide: function( event, ui ) {
let slideVal = 1000 - ui.value;
let scrollAmount = scale(slideVal, 0, 1000, 0, tableH);
let scrollAmount2 = scale(slideVal, 0, 1000, 0, timelineH);
let nthCentury = Math.ceil(scale(slideVal, 0, 1000, 0, 84)) + 1;
$('#EasterTableContainer').scrollTop(scrollAmount);
$('#TimelineCenturiesContainer').scrollTop(scrollAmount2);
$('.highlight').removeClass('highlight');
$('#TimelineCenturiesContainer div:nth-child('+nthCentury+')').addClass('highlight');
if(nthCentury > 80 && $('#TimelineCenturiesContainer').hasClass('scrollBottom') === false ){
$('#TimelineCenturiesContainer').addClass('scrollBottom');
}
else if(nthCentury < 81 && $('#TimelineCenturiesContainer').hasClass('scrollBottom') ){
$('#TimelineCenturiesContainer').removeClass('scrollBottom');
}
//$( "#amount" ).val( ui.value );
}
});
$('#langSelect').on('change', function(){
let lcl = $(this).val();
location.href = '?locale='+lcl;
});
});
</script>
</body>