diff --git a/php/index.php b/php/index.php index 7a1ea4b..d1b109c 100644 --- a/php/index.php +++ b/php/index.php @@ -29,7 +29,8 @@ $directAccess = (basename(__FILE__) === basename($_SERVER['SCRIPT_FILENAME'])); $baseLocale = Locale::getPrimaryLanguage(setlocale(LC_ALL, 0)); -$litSettings = new LitSettings($_GET, $directAccess); +$Metadata = Utilities::retrieveMetadata(); +$litSettings = new LitSettings($_GET, $directAccess, $Metadata); // debug value of expected textdomain path echo ''; @@ -39,9 +40,7 @@ $nationalCalendarOptions = ''; $diocesanCalendarOptions = ''; -$Metadata = Utilities::retrieveMetadata(); if ($Metadata !== null) { - $litSettings->setMetadata($Metadata, $stagingURL); $nationalCalendarOptions = Utilities::buildNationOptions($Metadata["national_calendars_keys"], $litSettings->NationalCalendar, $litSettings->Locale); [$diocesanCalendarOptions, $diocesesCount] = Utilities::buildDioceseOptions($Metadata, $litSettings->NationalCalendar, $litSettings->DiocesanCalendar); } else { diff --git a/php/src/LitSettings.php b/php/src/LitSettings.php index dd9e088..e7b6a3c 100644 --- a/php/src/LitSettings.php +++ b/php/src/LitSettings.php @@ -57,7 +57,7 @@ class LitSettings * @param array $DATA An array of input parameters to initialize the settings. * @param bool $directAccess A flag indicating if the access is direct, default is false. */ - public function __construct(array $DATA, bool $directAccess = false) + public function __construct(array $DATA, bool $directAccess = false, array|null $Metadata = null) { // set default year value $this->Year = (int)date("Y"); @@ -76,6 +76,8 @@ public function __construct(array $DATA, bool $directAccess = false) $this->currentTextDomainPath = bindtextdomain("litexmplphp", $this->expectedTextDomainPath); $this->directAccess = $directAccess; + $this->setMetadata($Metadata); + $this->setVars($DATA); } @@ -169,9 +171,8 @@ private function isValidDiocesanCalendar($value) * NationalCalendarMetadata array. * If the directAccess flag is set to true, the function also sets the locale for the current PHP script using the * setlocale() function, and sets a cookie to store the current locale. - * @param string $stagingURL the URL of the staging site (used to set the domain of the cookie) */ - private function updateSettingsByNation(string $stagingURL) + private function updateSettingsByNation() { $NationalCalendarMetadata = null; if ($this->NationalCalendar !== null && $this->NationalCalendar !== "VA") { @@ -207,6 +208,8 @@ private function updateSettingsByNation(string $stagingURL) ]; setlocale(LC_ALL, $localeArray); if (!isset($_COOKIE["currentLocale"]) || $_COOKIE["currentLocale"] !== $this->Locale) { + $isStaging = ( strpos($_SERVER['HTTP_HOST'], "-staging") !== false ); + $stagingURL = $isStaging ? "-staging" : ""; setcookie( "currentLocale", //name $this->Locale, //value @@ -224,15 +227,14 @@ private function updateSettingsByNation(string $stagingURL) * Updates the internal metadata reference and then updates the settings based on the selected nation. * * @param array $Metadata A list of metadata about the diocesan calendars available. - * @param string $stagingURL If the current page is a staging site, this will contain the identifier of the staging site such as "-staging". * @return void */ - public function setMetadata(array $Metadata, string $stagingURL) + public function setMetadata(array $Metadata) { $this->Metadata = $Metadata; if ($this->DiocesanCalendar !== null) { $this->NationalCalendar = array_values(array_filter($this->Metadata["diocesan_calendars"], fn ($calendar) => $calendar["calendar_id"] === $this->DiocesanCalendar))[0]["nation"]; } - $this->updateSettingsByNation($stagingURL); + $this->updateSettingsByNation(); } }