Skip to content

Commit

Permalink
Merge pull request #71 from Liturgical-Calendar/development
Browse files Browse the repository at this point in the history
Finish i18n and refactoring
  • Loading branch information
JohnRDOrazio authored Dec 19, 2021
2 parents 1f487e7 + 34e5dee commit 15fb8b7
Show file tree
Hide file tree
Showing 34 changed files with 1,225 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Update source file translation strings
run: |
sudo apt-get install -y gettext
xgettext --from-code=UTF-8 --add-comments='translators:' --keyword="pgettext:1c,2" -o i18n/litcal.pot includes/LitCalAPI.php includes/LitCalMessages.php includes/FestivityCollection.php includes/enums/LitColor.php includes/enums/LitCommon.php includes/enums/LitGrade.php
xgettext --from-code=UTF-8 --add-comments='translators:' --keyword="pgettext:1c,2" -o i18n/litcal.pot includes/LitCalAPI.php includes/LitMessages.php includes/FestivityCollection.php includes/enums/LitColor.php includes/enums/LitCommon.php includes/enums/LitGrade.php
- name: Push changes # push the output folder to your repo
uses: actions-x/commit@v4
Expand Down
95 changes: 95 additions & 0 deletions DateOfEaster.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);
ini_set('date.timezone', 'Europe/Vatican');

include_once( 'includes/enums/LitLocale.php' );
$LOCALE = isset($_GET["locale"]) && LitLocale::isValid(strtoupper($_GET["locale"])) ? strtoupper($_GET["locale"]) : LitLocale::LATIN;

if(file_exists('engineCache/easter/' . $LOCALE . '.json') ){
header('Content-Type: application/json');
echo file_get_contents('engineCache/easter/' . $LOCALE . '.json');
die();
}

include_once( 'includes/LitFunc.php' );
include_once( 'includes/LitMessages.php' );

$localeArray = [
strtolower( $LOCALE ) . '_' . $LOCALE . '.utf8',
strtolower( $LOCALE ) . '_' . $LOCALE . '.UTF-8',
strtolower( $LOCALE ) . '_' . $LOCALE,
strtolower( $LOCALE )
];
setlocale( LC_ALL, $localeArray );
$dayOfTheWeekDayMonthYear = IntlDateFormatter::create( strtolower( $LOCALE ), IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'UTC', IntlDateFormatter::GREGORIAN, "EEEE d MMMM yyyy" );
$dayMonthYear = IntlDateFormatter::create( strtolower( $LOCALE ), IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'UTC', IntlDateFormatter::GREGORIAN, "d MMMM yyyy" );
$dayOfTheWeek = IntlDateFormatter::create( strtolower( $LOCALE ), IntlDateFormatter::FULL, IntlDateFormatter::NONE, 'UTC', IntlDateFormatter::GREGORIAN, "EEEE" );

$EasterDates = new stdClass();
$EasterDates->DatesArray = [];
$last_coincidence = "";
$dateLastCoincidence = null;

for($i=1583;$i<=9999;$i++){
$EasterDates->DatesArray[$i-1583] = new stdClass();
$gregorian_easter = LitFunc::calcGregEaster( $i );
$julian_easter = LitFunc::calcJulianEaster( $i );
$western_julian_easter = LitFunc::calcJulianEaster( $i, true );
$same_easter = false;

if($gregorian_easter->format( 'l, F jS, Y' ) === $western_julian_easter->format( 'l, F jS, Y' ) ) {
$same_easter = true;
$last_coincidence = $gregorian_easter->format( 'l, F jS, Y' );
$dateLastCoincidence = $gregorian_easter;
}

$gregDateString = "";
$julianDateString = "";
$westernJulianDateString = "";
switch ($LOCALE) {
case LitLocale::LATIN:
$month = (int)$gregorian_easter->format('n'); //n = 1-January to 12-December
$monthLatin = LitMessages::LATIN_MONTHS[$month];
$gregDateString = 'Dies Domini, ' . $gregorian_easter->format('j') . ' ' . $monthLatin . ' ' . $gregorian_easter->format('Y');
$month = (int)$julian_easter->format('n'); //n = 1-January to 12-December
$monthLatin = LitMessages::LATIN_MONTHS[$month];
$julianDateString = 'Dies Domini, ' . $julian_easter->format('j') . ' ' . $monthLatin . ' ' . $julian_easter->format('Y');
$month = (int)$western_julian_easter->format('n'); //n = 1-January to 12-December
$monthLatin = LitMessages::LATIN_MONTHS[$month];
$westernJulianDateString = 'Dies Domini, ' . $western_julian_easter->format('j') . ' ' . $monthLatin . ' ' . $western_julian_easter->format('Y');
break;
case LitLocale::ENGLISH:
$gregDateString = $gregorian_easter->format('l, F jS, Y');
$julianDateString = 'Sunday' . $julian_easter->format(', F jS, Y');
$westernJulianDateString = $western_julian_easter->format('l, F jS, Y');
break;
default:
$gregDateString = $dayOfTheWeekDayMonthYear->format( $gregorian_easter->format('U') );
$julianDateString = $dayOfTheWeek->format( $gregorian_easter->format('U') ) . ', ' . $dayMonthYear->format( $julian_easter->format('U') );
$westernJulianDateString = $dayOfTheWeekDayMonthYear->format( $western_julian_easter->format('U') );
}

$EasterDates->DatesArray[$i-1583]->gregorianEaster = $gregorian_easter->format('U');
$EasterDates->DatesArray[$i-1583]->julianEaster = $julian_easter->format('U');
$EasterDates->DatesArray[$i-1583]->westernJulianEaster = $western_julian_easter->format('U');
$EasterDates->DatesArray[$i-1583]->coinciding = $same_easter;
$EasterDates->DatesArray[$i-1583]->gregorianDateString = $gregDateString;
$EasterDates->DatesArray[$i-1583]->julianDateString = $julianDateString;
$EasterDates->DatesArray[$i-1583]->westernJulianDateString = $westernJulianDateString;

}

$EasterDates->lastCoincidenceString = $dateLastCoincidence->format( 'l, F jS, Y' );
$EasterDates->lastCoincidence = $dateLastCoincidence->format( 'U' );

if ( !is_dir( 'engineCache/easter/' ) ) {
mkdir( 'engineCache/easter/', 0774, true );
}
file_put_contents( 'engineCache/easter/' . $LOCALE . '.json', json_encode( $EasterDates ) );

header('Content-Type: application/json');
echo json_encode($EasterDates);
die();
?>
28 changes: 14 additions & 14 deletions LitCalDiocesanData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
$LitCalDiocesanData->APICore->setAllowedOrigins( $allowedOrigins );
$LitCalDiocesanData->APICore->setAllowedReferers( array_map( function($el){ return $el . "/"; }, $allowedOrigins ) );

$LitCalDiocesanData->APICore->setAllowedAcceptHeaders( [ ACCEPT_HEADER::JSON ] );
$LitCalDiocesanData->APICore->setAllowedRequestContentTypes( [ REQUEST_CONTENT_TYPE::JSON, REQUEST_CONTENT_TYPE::FORMDATA ] );
$LitCalDiocesanData->APICore->setAllowedAcceptHeaders( [ AcceptHeader::JSON ] );
$LitCalDiocesanData->APICore->setAllowedRequestContentTypes( [ RequestContentType::JSON, RequestContentType::FORMDATA ] );
$LitCalDiocesanData->Init();

class LitCalDiocesanData {
Expand Down Expand Up @@ -56,9 +56,9 @@ private function handlePutPatchDeleteRequests( string $requestMethod ) {
$this->APICore->enforceReferer();
if( $this->APICore->getRequestContentType() === 'application/json' ) {
$this->DATA = $this->APICore->retrieveRequestParamsFromJsonBody();
if( REQUEST_METHOD::PUT === $requestMethod ) {
if( RequestMethod::PUT === $requestMethod ) {
$this->writeDiocesanCalendar();
} elseif( REQUEST_METHOD::DELETE === $requestMethod ) {
} elseif( RequestMethod::DELETE === $requestMethod ) {
$this->deleteDiocesanCalendar();
}

Expand All @@ -72,26 +72,26 @@ private function handlePutPatchDeleteRequests( string $requestMethod ) {
private function handleRequestedMethod() {

switch( strtoupper( $_SERVER[ "REQUEST_METHOD" ] ) ) {
case 'GET':
case RequestMethod::GET:
$this->handleGetPostRequests( $_GET );
break;
case 'POST':
case RequestMethod::POST:
$this->handleGetPostRequests( $_POST );
break;
case 'PUT':
case 'PATCH':
$this->handlePutPatchDeleteRequests( REQUEST_METHOD::PUT );
case RequestMethod::PUT:
case RequestMethod::PATCH:
$this->handlePutPatchDeleteRequests( RequestMethod::PUT );
break;
case 'DELETE':
$this->handlePutPatchDeleteRequests( REQUEST_METHOD::DELETE );
case RequestMethod::DELETE:
$this->handlePutPatchDeleteRequests( RequestMethod::DELETE );
break;
case 'OPTIONS':
case RequestMethod::OPTIONS:
//continue;
break;
default:
header( $_SERVER[ "SERVER_PROTOCOL" ]." 405 Method Not Allowed", true, 405 );
$errorMessage = '{"error":"You seem to be forming a strange kind of request? Allowed Request Methods are ';
$errorMessage .= implode( ' and ', $this->ALLOWED_REQUEST_METHODS );
$errorMessage .= implode( ' and ', $this->AllowedRequestMethods );
$errorMessage .= ', but your Request Method was ' . strtoupper( $_SERVER[ 'REQUEST_METHOD' ] ) . '"}';
die( $errorMessage );
}
Expand Down Expand Up @@ -197,4 +197,4 @@ public function Init() {

}

}
}
10 changes: 5 additions & 5 deletions LitCalEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
"https://litcal.johnromanodorazio.com",
"https://litcal-staging.johnromanodorazio.com"
] );
$LitCalEngine->APICore->setAllowedRequestMethods( [ REQUEST_METHOD::GET, REQUEST_METHOD::POST ] );
$LitCalEngine->APICore->setAllowedRequestContentTypes( [ REQUEST_CONTENT_TYPE::JSON, REQUEST_CONTENT_TYPE::FORMDATA ] );
$LitCalEngine->APICore->setAllowedAcceptHeaders( [ ACCEPT_HEADER::JSON, ACCEPT_HEADER::XML, ACCEPT_HEADER::ICS ] );
$LitCalEngine->setAllowedReturnTypes( [ RETURN_TYPE::JSON, RETURN_TYPE::XML, RETURN_TYPE::ICS ] );
$LitCalEngine->setCacheDuration( CACHEDURATION::MONTH );
$LitCalEngine->APICore->setAllowedRequestMethods( [ RequestMethod::GET, RequestMethod::POST ] );
$LitCalEngine->APICore->setAllowedRequestContentTypes( [ RequestContentType::JSON, RequestContentType::FORMDATA ] );
$LitCalEngine->APICore->setAllowedAcceptHeaders( [ AcceptHeader::JSON, AcceptHeader::XML, AcceptHeader::ICS ] );
$LitCalEngine->setAllowedReturnTypes( [ ReturnType::JSON, ReturnType::XML, ReturnType::ICS ] );
$LitCalEngine->setCacheDuration( CacheDuration::MONTH );
$LitCalEngine->Init();
Loading

0 comments on commit 15fb8b7

Please sign in to comment.