mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
* Calendar: update holidays with new thunderbird.net URLs/data for a lot more countries
This commit is contained in:
parent
ce34b5eaf9
commit
d0ddbcb16c
@ -1939,7 +1939,8 @@ class calendar_bo
|
||||
$holidays = calendar_holidays::read(
|
||||
!empty($GLOBALS['egw_info']['server']['ical_holiday_url']) ?
|
||||
$GLOBALS['egw_info']['server']['ical_holiday_url'] :
|
||||
$GLOBALS['egw_info']['user']['preferences']['common']['country'], $year);
|
||||
$GLOBALS['egw_info']['user']['preferences']['common']['country'], $year,
|
||||
$GLOBALS['egw_info']['user']['preferences']['common']['lang']);
|
||||
|
||||
// search for birthdays
|
||||
if ($GLOBALS['egw_info']['server']['hide_birthdays'] != 'yes')
|
||||
|
@ -17,7 +17,8 @@ use EGroupware\Api;
|
||||
*
|
||||
* Holidays are read from:
|
||||
* - a given iCal URL or
|
||||
* - json file with 2-digit iso country-code: URL pairs is read from https://community.egroupware.org or
|
||||
* - json file with 2-digit uppercase iso country-code and 2-digit lowercase iso language-code: URL pairs is read from https://community.egroupware.org or
|
||||
* - json file with 2-digit uppercase iso country-code: URL pairs is read from https://community.egroupware.org or
|
||||
* - json file is read from /calendar/setup/ical_holiday_urls.json
|
||||
*
|
||||
* Holidays are cached on tree or instance level, later for custom urls.
|
||||
@ -25,8 +26,8 @@ use EGroupware\Api;
|
||||
* from previous (requested) year until next 5 years.
|
||||
*
|
||||
* Holiday urls are from Mozilla Calendar project:
|
||||
* @link https://www.mozilla.org/en-US/projects/calendar/holidays/
|
||||
* @link https://www.mozilla.org/media/caldata/calendars.json (json from which above page is generated)
|
||||
* @link https://www.thunderbird.net/en-US/calendar/holidays/
|
||||
* @link https://www.thunderbird.net/media/caldata/calendars.json (json from which above page is generated)
|
||||
* @link https://github.com/mozilla/bedrock/tree/master/media/caldata
|
||||
*/
|
||||
class calendar_holidays
|
||||
@ -42,21 +43,25 @@ class calendar_holidays
|
||||
*
|
||||
* @param string $country 2-digit iso country code or URL
|
||||
* @param int $year =null default current year
|
||||
* @param ?string $lang s-digit is language code
|
||||
* @return array of Ymd => array of array with values for keys 'occurence','month','day','name', (commented out) 'title'
|
||||
*/
|
||||
public static function read($country, $year=null)
|
||||
public static function read($country, $year=null, $lang=null)
|
||||
{
|
||||
if (!$year) $year = (int)Api\DateTime::to('now', 'Y');
|
||||
$level = self::is_url($country) ? Api\Cache::INSTANCE : Api\Cache::TREE;
|
||||
|
||||
$holidays = Api\Cache::getCache($level, __CLASS__, $country.':'.$year);
|
||||
if (empty($lang) || !($holidays = Api\Cache::getCache($level, __CLASS__, $country.':'.$year.':'.$lang)))
|
||||
{
|
||||
$holidays = Api\Cache::getCache($level, __CLASS__, $country.':'.$year);
|
||||
}
|
||||
|
||||
// if we dont find holidays in cache, we render from previous year until next 5 years
|
||||
if (!isset($holidays) && ($years = self::render($country, $year-1, $year+5)))
|
||||
// if we don't find holidays in cache, we render from previous year until next 5 years
|
||||
if (!isset($holidays) && ($years = self::render($country, $year-1, $year+5, $lang)))
|
||||
{
|
||||
foreach($years as $y => $data)
|
||||
{
|
||||
Api\Cache::setCache($level, __CLASS__, $country.':'.$y, $data, self::HOLIDAY_CACHE_TIME);
|
||||
Api\Cache::setCache($level, __CLASS__, $country.':'.$y.($lang?':'.$lang:''), $data, self::HOLIDAY_CACHE_TIME);
|
||||
}
|
||||
$holidays = $years[$year];
|
||||
}
|
||||
@ -69,15 +74,16 @@ class calendar_holidays
|
||||
* @param string $country 2-digit iso country code or URL
|
||||
* @param int $year =null default current year
|
||||
* @param int $until_year =null default, fetch only one year, if given result is indexed additional by year
|
||||
* @param ?string $lang =null 2-digit iso language code
|
||||
* @return array of Ymd => array of array with values for keys 'occurence','month','day','name', (commented out) 'title'
|
||||
*/
|
||||
public static function render($country, $year=null, $until_year=null)
|
||||
public static function render($country, $year=null, $until_year=null, $lang=null)
|
||||
{
|
||||
if (!$year) $year = (int)Api\DateTime::to('now', 'Y');
|
||||
$end_year = $until_year && $year < $until_year ? $until_year : $year;
|
||||
|
||||
$starttime = microtime(true);
|
||||
if (!($holidays = self::fetch($country)))
|
||||
if (!($holidays = self::fetch($country, $lang)) && !($holidays = self::fetch($country)))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@ -149,11 +155,12 @@ class calendar_holidays
|
||||
* Fetch iCal for given country
|
||||
*
|
||||
* @param string $country 2-digit iso country code or URL
|
||||
* @param ?string $lang 2-digit iso language code or NULL
|
||||
* @return array|Iterator parsed events
|
||||
*/
|
||||
protected static function fetch($country)
|
||||
protected static function fetch($country, $lang=null)
|
||||
{
|
||||
if (!($url = self::is_url($country) ? $country : self::ical_url($country)))
|
||||
if (!($url = self::is_url($country) ? $country : self::ical_url($country, $lang)))
|
||||
{
|
||||
error_log("No holiday iCal for '$country'!");
|
||||
return array();
|
||||
@ -188,9 +195,10 @@ class calendar_holidays
|
||||
* We first try to fetch urls from https://community.egroupware.org and if that fails we use the local one.
|
||||
*
|
||||
* @param string $country
|
||||
* @param ?string $lang
|
||||
* @return string|boolean|null string with url, false if we cant load urls, NULL if $country is not included
|
||||
*/
|
||||
protected static function ical_url($country)
|
||||
protected static function ical_url($country, $lang=null)
|
||||
{
|
||||
$urls = Api\Cache::getTree(__CLASS__, 'ical_holiday_urls');
|
||||
|
||||
@ -208,7 +216,7 @@ class calendar_holidays
|
||||
}
|
||||
Api\Cache::setTree(__CLASS__, 'ical_holiday_urls', $urls, $urls ? self::URL_CACHE_TIME : self::URL_FAIL_CACHE_TIME);
|
||||
}
|
||||
return $urls[$country];
|
||||
return $urls[$country.'_'.$lang] ?? $urls[$country];
|
||||
}
|
||||
|
||||
}
|
||||
@ -229,4 +237,4 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_
|
||||
|
||||
Api\Header\Content::type('holidays-'.$country.'.txt', 'text/plain', 0, true, false);
|
||||
print_r(calendar_holidays::render($country, $year, $year_until));
|
||||
}
|
||||
}
|
@ -1,72 +1,85 @@
|
||||
{
|
||||
"_origin": "https://www.thunderbird.net/en-US/calendar/holidays/",
|
||||
"DZ": "https://www.mozilla.org/media/caldata/AlgeriaHolidays.ics",
|
||||
"AR": "https://www.mozilla.org/media/caldata/ArgentinaHolidays.ics",
|
||||
"AU": "https://www.mozilla.org/media/caldata/AustraliaHolidays.ics",
|
||||
"AT": "https://www.mozilla.org/media/caldata/AustrianHolidays.ics",
|
||||
"BE": "https://www.mozilla.org/media/caldata/BelgianHolidays.ics",
|
||||
"BO": "https://www.mozilla.org/media/caldata/BoliviaHolidays.ics",
|
||||
"BR": "https://www.mozilla.org/media/caldata/BrazilHolidays.ics",
|
||||
"BG": "https://www.mozilla.org/media/caldata/BulgarianHolidays.ics",
|
||||
"CA": "https://www.mozilla.org/media/caldata/CanadaHolidays.ics",
|
||||
"CL": "https://www.mozilla.org/media/caldata/ChileHolidays.ics",
|
||||
"CN": "https://www.mozilla.org/media/caldata/ChinaHolidays.ics",
|
||||
"CO": "https://www.mozilla.org/media/caldata/ColombianHolidays.ics",
|
||||
"CR": "https://www.mozilla.org/media/caldata/CostaRicaHolidays.ics",
|
||||
"HR": "https://www.mozilla.org/media/caldata/CroatiaHolidays.ics",
|
||||
"CZ": "https://www.mozilla.org/media/caldata/CzechHolidays.ics",
|
||||
"DK": "https://www.mozilla.org/media/caldata/DanishHolidays.ics",
|
||||
"DO": "https://www.mozilla.org/media/caldata/DominicanRepublicSpanish.ics",
|
||||
"EE": "https://www.mozilla.org/media/caldata/EstoniaHolidays.ics",
|
||||
"FI": "https://www.mozilla.org/media/caldata/FinlandHolidays.ics",
|
||||
"FR": "https://www.mozilla.org/media/caldata/FrenchHolidays.ics",
|
||||
"DE": "https://www.mozilla.org/media/caldata/GermanHolidays.ics",
|
||||
"GR": "https://www.mozilla.org/media/caldata/GreeceHolidays.ics",
|
||||
"GY": "https://www.mozilla.org/media/caldata/GuyanaHolidays.ics",
|
||||
"HT": "https://www.mozilla.org/media/caldata/HaitiHolidays.ics",
|
||||
"HK": "https://www.mozilla.org/media/caldata/HongKongHolidays.ics",
|
||||
"HU": "https://www.mozilla.org/media/caldata/HungarianHolidays.ics",
|
||||
"IS": "https://www.mozilla.org/media/caldata/IcelandHolidays.ics",
|
||||
"IN": "https://www.mozilla.org/media/caldata/IndiaHolidays.ics",
|
||||
"ID": "https://www.mozilla.org/media/caldata/IndonesianHolidays.ics",
|
||||
"IR": "https://www.mozilla.org/media/caldata/IranHolidays_Persian.ics",
|
||||
"IE": "https://www.mozilla.org/media/caldata/IrelandHolidays2014-2021.ics",
|
||||
"IT": "https://www.mozilla.org/media/caldata/ItalianHolidays.ics",
|
||||
"JP": "https://www.mozilla.org/media/caldata/JapanHolidays.ics",
|
||||
"KZ": "https://www.mozilla.org/media/caldata/KazakhstanHolidaysRussian.ics",
|
||||
"KE": "https://www.mozilla.org/media/caldata/KenyaHolidays.ics",
|
||||
"KR": "https://www.mozilla.org/media/caldata/SouthKoreaHolidays.ics",
|
||||
"LV": "https://www.mozilla.org/media/caldata/LatviaHolidays.ics",
|
||||
"LI": "https://www.mozilla.org/media/caldata/LiechtensteinHolidays.ics",
|
||||
"LT": "https://www.mozilla.org/media/caldata/LithuanianHolidays.ics",
|
||||
"LU": "https://www.mozilla.org/media/caldata/LuxembourgHolidays.ics",
|
||||
"MA": "https://www.mozilla.org/media/caldata/MoroccoHolidays.ics",
|
||||
"NL": "https://www.mozilla.org/media/caldata/DutchHolidays.ics",
|
||||
"NZ": "https://www.mozilla.org/media/caldata/NewZealandHolidays.ics",
|
||||
"NI": "https://www.mozilla.org/media/caldata/NicaraguaHolidays.ics",
|
||||
"NO": "https://www.mozilla.org/media/caldata/NorwegianHolidays.ics",
|
||||
"PK": "https://www.mozilla.org/media/caldata/PakistanHolidays.ics",
|
||||
"PE": "https://www.mozilla.org/media/caldata/PeruHolidays.ics",
|
||||
"PH": "https://www.mozilla.org/media/caldata/PhilippinesHolidays.ics",
|
||||
"PL": "https://www.mozilla.org/media/caldata/PolishHolidays.ics",
|
||||
"PT": "https://www.mozilla.org/media/caldata/PortugalHolidays.ics",
|
||||
"RO": "https://www.mozilla.org/media/caldata/RomaniaHolidays.ics",
|
||||
"RU": "https://www.mozilla.org/media/caldata/RussiaHolidays.ics",
|
||||
"SG": "https://www.mozilla.org/media/caldata/SingaporeHolidays.ics",
|
||||
"SK": "https://www.mozilla.org/media/caldata/SlovakHolidays.ics",
|
||||
"SI": "https://www.mozilla.org/media/caldata/SlovenianHolidays.ics",
|
||||
"ZA": "https://www.mozilla.org/media/caldata/SouthAfricaHolidays.ics",
|
||||
"ES": "https://www.mozilla.org/media/caldata/SpanishHolidays.ics",
|
||||
"LK": "https://www.mozilla.org/media/caldata/SriLankaHolidays.ics",
|
||||
"SE": "https://www.mozilla.org/media/caldata/SwedishHolidays.ics",
|
||||
"CH": "https://www.mozilla.org/media/caldata/SwissHolidays.ics",
|
||||
"TW": "https://www.mozilla.org/media/caldata/TaiwanHolidays.ics",
|
||||
"TH": "https://www.mozilla.org/media/caldata/ThaiHolidays.ics",
|
||||
"TT": "https://www.mozilla.org/media/caldata/TrinidadTobagoHolidays.ics",
|
||||
"TR": "https://www.mozilla.org/media/caldata/TurkeyHolidays.ics",
|
||||
"UA": "https://www.mozilla.org/media/caldata/UkraineHolidays.ics",
|
||||
"GB": "https://www.mozilla.org/media/caldata/UKHolidays.ics",
|
||||
"US": "https://www.mozilla.org/media/caldata/USHolidays.ics",
|
||||
"UY": "https://www.mozilla.org/media/caldata/UruguayHolidays.ics",
|
||||
"VN": "https://www.mozilla.org/media/caldata/VietnamHolidays.ics"
|
||||
}
|
||||
"AL": "https://www.thunderbird.net/media/caldata/autogen/Albania-Holidays.ics",
|
||||
"DZ": "https://www.thunderbird.net/media/caldata/autogen/Algeria-(Arabic)-Holidays.ics",
|
||||
"DZ_fr": "https://www.thunderbird.net/media/caldata/autogen/Algeria-(French)-Holidays.ics",
|
||||
"AR": "https://www.thunderbird.net/media/caldata/autogen/Argentina-Holidays.ics",
|
||||
"AM": "https://www.thunderbird.net/media/caldata/autogen/Armenia-Holidays.ics",
|
||||
"AU": "https://www.thunderbird.net/media/caldata/autogen/Australia-Holidays.ics",
|
||||
"AT": "https://www.thunderbird.net/media/caldata/autogen/Austrian-Holidays.ics",
|
||||
"BE": "https://www.thunderbird.net/media/caldata/autogen/Belgian-(Dutch)-Holidays.ics",
|
||||
"BE_fr": "https://www.thunderbird.net/media/caldata/autogen/Belgian-(French)-Holidays.ics",
|
||||
"BO": "https://www.thunderbird.net/media/caldata/autogen/Bolivia-Holidays.ics",
|
||||
"BR": "https://www.thunderbird.net/media/caldata/autogen/Brazil-Holidays.ics",
|
||||
"BG": "https://www.thunderbird.net/media/caldata/autogen/Bulgarian-Holidays.ics",
|
||||
"CA": "https://www.thunderbird.net/media/caldata/autogen/Canada-(English)-Holidays.ics",
|
||||
"CA_fr": "https://www.thunderbird.net/media/caldata/autogen/Canada-(French)-Holidays.ics",
|
||||
"CL": "https://www.thunderbird.net/media/caldata/autogen/Chile-Holidays.ics",
|
||||
"CN": "https://www.thunderbird.net/media/caldata/autogen/China-Holidays.ics",
|
||||
"CO": "https://www.thunderbird.net/media/caldata/autogen/Colombian-Holidays.ics",
|
||||
"CR": "https://www.thunderbird.net/media/caldata/autogen/Costa-Rica-Holidays.ics",
|
||||
"HR": "https://www.thunderbird.net/media/caldata/autogen/Croatia-Holidays.ics",
|
||||
"CZ": "https://www.thunderbird.net/media/caldata/autogen/Czech-Holidays.ics",
|
||||
"DK": "https://www.thunderbird.net/media/caldata/autogen/Danmark-Holidays.ics",
|
||||
"DO": "https://www.thunderbird.net/media/caldata/Dominican-Republic.ics",
|
||||
"EE": "https://www.thunderbird.net/media/caldata/autogen/Estonia-Holidays.ics",
|
||||
"FI": "https://www.thunderbird.net/media/caldata/autogen/Finland-Holidays.ics",
|
||||
"FR": "https://www.thunderbird.net/media/caldata/autogen/France-Holidays.ics",
|
||||
"DE": "https://www.thunderbird.net/media/caldata/autogen/Germany-Holidays.ics",
|
||||
"GR": "https://www.thunderbird.net/media/caldata/autogen/Greece-Holidays.ics",
|
||||
"GY": "https://www.thunderbird.net/media/caldata/autogen/Guyana-Holidays.ics",
|
||||
"HT": "https://www.thunderbird.net/media/caldata/autogen/Haiti-Holidays.ics",
|
||||
"HK": "https://www.thunderbird.net/media/caldata/autogen/Hong-Kong-Holidays.ics",
|
||||
"HU": "https://www.thunderbird.net/media/caldata/autogen/Hungary-Holidays.ics",
|
||||
"IS": "https://www.thunderbird.net/media/caldata/autogen/Iceland-Holidays.ics",
|
||||
"IN": "https://www.thunderbird.net/media/caldata/autogen/India-Holidays.ics",
|
||||
"ID": "https://www.thunderbird.net/media/caldata/autogen/Indonesia-Holidays.ics",
|
||||
"IE": "https://www.thunderbird.net/media/caldata/Ireland-(English)-Holidays.ics",
|
||||
"IE_ga": "https://www.thunderbird.net/media/caldata/Ireland-(Irish)-Holidays.ics",
|
||||
"IS": "https://www.thunderbird.net/media/caldata/autogen/Israel-Holidays.ics",
|
||||
"IT": "https://www.thunderbird.net/media/caldata/autogen/Italy-Holidays.ics",
|
||||
"JP": "https://www.thunderbird.net/media/caldata/autogen/Japan-Holidays.ics",
|
||||
"KZ": "https://www.thunderbird.net/media/caldata/autogen/Kazakhstan-Holidays.ics",
|
||||
"KE": "https://www.thunderbird.net/media/caldata/autogen/Kenya-Holidays.ics",
|
||||
"LV": "https://www.thunderbird.net/media/caldata/autogen/Latvia-Holidays.ics",
|
||||
"LB": "https://www.thunderbird.net/media/caldata/autogen/Lebanon-Holidays.ics",
|
||||
"LI": "https://www.thunderbird.net/media/caldata/autogen/Liechtenstein-Holidays.ics",
|
||||
"LT": "https://www.thunderbird.net/media/caldata/autogen/Lithuania-Holidays.ics",
|
||||
"LU": "https://www.thunderbird.net/media/caldata/autogen/Luxembourg-(Germany)-Holidays.ics",
|
||||
"LU_fr": "https://www.thunderbird.net/media/caldata/autogen/Luxembourg-(French)-Holidays.ics",
|
||||
"MY": "https://www.thunderbird.net/media/caldata/autogen/Malaysia-Holidays.ics",
|
||||
"MT": "https://www.thunderbird.net/media/caldata/autogen/Malta-Holidays.ics",
|
||||
"MX": "https://www.thunderbird.net/media/caldata/autogen/Mexico-Holidays.ics",
|
||||
"MA": "https://www.thunderbird.net/media/caldata/autogen/Morocco-Holidays.ics",
|
||||
"NA": "https://www.thunderbird.net/media/caldata/autogen/Nabimia-Holidays.ics",
|
||||
"NL": "https://www.thunderbird.net/media/caldata/autogen/Netherlands-Holidays.ics",
|
||||
"NZ": "https://www.thunderbird.net/media/caldata/autogen/New-Zealand-Holidays.ics",
|
||||
"NI": "https://www.thunderbird.net/media/caldata/autogen/Nicaragua-Holidays.ics",
|
||||
"NO": "https://www.thunderbird.net/media/caldata/autogen/Norway-Holidays.ics",
|
||||
"PK": "https://www.thunderbird.net/media/caldata/autogen/Pakistan-Holidays.ics",
|
||||
"PE": "https://www.thunderbird.net/media/caldata/autogen/Peru-Holidays.ics",
|
||||
"PH": "https://www.thunderbird.net/media/caldata/autogen/Philippines-Holidays.ics",
|
||||
"PL": "https://www.thunderbird.net/media/caldata/autogen/Polish-Holidays.ics",
|
||||
"PT": "https://www.thunderbird.net/media/caldata/autogen/Portugal-Holidays.ics",
|
||||
"PR": "https://www.thunderbird.net/media/caldata/autogen/Puerto-Rico-Holidays.ics",
|
||||
"RO": "https://www.thunderbird.net/media/caldata/autogen/Romania-Holidays.ics",
|
||||
"RU": "https://www.thunderbird.net/media/caldata/autogen/Russia-Holidays.ics",
|
||||
"SG": "https://www.thunderbird.net/media/caldata/autogen/Singapore-Holidays.ics",
|
||||
"SK": "https://www.thunderbird.net/media/caldata/autogen/Slovakia-Holidays.ics",
|
||||
"SI": "https://www.thunderbird.net/media/caldata/autogen/Slovenia-Holidays.ics",
|
||||
"ZA": "https://www.thunderbird.net/media/caldata/autogen/South-Africa-Holidays.ics",
|
||||
"KR": "https://www.thunderbird.net/media/caldata/autogen/South-Korea-Holidays.ics",
|
||||
"ES": "https://www.thunderbird.net/media/caldata/autogen/Spain-Holidays.ics",
|
||||
"LK": "https://www.thunderbird.net/media/caldata/autogen/Sri-Lanka-Holidays.ics",
|
||||
"SE": "https://www.thunderbird.net/media/caldata/autogen/Swedish-Holidays.ics",
|
||||
"CH": "https://www.thunderbird.net/media/caldata/autogen/Switzerland-Holidays.ics",
|
||||
"TW": "https://www.thunderbird.net/media/caldata/autogen/Taiwan-Holidays.ics",
|
||||
"TH": "https://www.thunderbird.net/media/caldata/autogen/Thailand-Holidays.ics",
|
||||
"TT": "https://www.thunderbird.net/media/caldata/autogen/Trinidad-and-Tobago-Holidays.ics",
|
||||
"TR": "https://www.thunderbird.net/media/caldata/autogen/Turkey-Holidays.ics",
|
||||
"UA": "https://www.thunderbird.net/media/caldata/autogen/Ukraine-Holidays.ics",
|
||||
"GB": "https://www.thunderbird.net/media/caldata/autogen/United-Kingdom-Holidays.ics",
|
||||
"US": "https://www.thunderbird.net/media/caldata/autogen/United-States-Holidays.ics",
|
||||
"UY": "https://www.thunderbird.net/media/caldata/autogen/Uruguay-Holidays.ics",
|
||||
"VN": "https://www.thunderbird.net/media/caldata/autogen/Vietnam-Holidays.ics"
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
<row>
|
||||
<et2-vbox>
|
||||
<et2-description value="Custom URL for iCal with holidays for all users" label="%s:"></et2-description>
|
||||
<et2-description label="(Without a custom URL we use nation of user preference to load holidays from %s)" href="https://www.mozilla.org/en-US/projects/calendar/holidays/" value="Mozilla Holiday Calendars" extraLinkTarget="_blank"></et2-description>
|
||||
<et2-description label="(Without a custom URL we use nation of user preference to load holidays from %s)" href="https://www.thuderbird.net/en-US/calendar/holidays/" value="Mozilla Holiday Calendars" extraLinkTarget="_blank"></et2-description>
|
||||
</et2-vbox>
|
||||
<et2-url id="newsettings[ical_holiday_url]"></et2-url>
|
||||
</row>
|
||||
|
Loading…
Reference in New Issue
Block a user