From 8d4134f6830eced698f80f2e905ed33f12dd2187 Mon Sep 17 00:00:00 2001 From: ralf Date: Wed, 10 Apr 2024 10:46:01 +0200 Subject: [PATCH] fix caching in browser, if iCal holiday url get set or changed --- api/js/jsapi/egw_calendar.js | 2 +- api/src/Config.php | 2 +- calendar/inc/class.calendar_holidays.inc.php | 2 +- calendar/inc/class.calendar_hooks.inc.php | 21 +++++++++++++++++++- calendar/templates/default/config.xet | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/api/js/jsapi/egw_calendar.js b/api/js/jsapi/egw_calendar.js index e2e44f2f74..d3084c8a86 100644 --- a/api/js/jsapi/egw_calendar.js +++ b/api/js/jsapi/egw_calendar.js @@ -139,7 +139,7 @@ egw.extend('calendar', egw.MODULE_GLOBAL, function (_app, _wnd) // one widget listening for the response by the time it gets back, // and we can't do that when it's queued. _holiday_cache[year] = window.fetch( - egw.link('/calendar/holidays.php', {year: year}) + egw.link('/calendar/holidays.php', {year: year, url: this.config('ical_holiday_url') || ''}) ).then((response) => { return _holiday_cache[year] = response.json(); diff --git a/api/src/Config.php b/api/src/Config.php index 79ae07e0dd..67763e2567 100755 --- a/api/src/Config.php +++ b/api/src/Config.php @@ -257,7 +257,7 @@ class Config 'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file', 'markuntranslated','link_list_thumbnail','enabled_spellcheck','debug_minify', 'call_link','call_popup','fax_email','fax_email_regexp','geolocation_url', // addressbook - 'hide_birthdays','calview_no_consolidate','fw_mobile_app_list'), // calendar + 'hide_birthdays','calview_no_consolidate','fw_mobile_app_list', 'ical_holiday_url'), // calendar 'projectmanager' => array('hours_per_workday', 'duration_units'), 'manual' => array('manual_remote_egw_url'), 'infolog' => array('status'), diff --git a/calendar/inc/class.calendar_holidays.inc.php b/calendar/inc/class.calendar_holidays.inc.php index 38cc6d9440..c6a7ee97bd 100644 --- a/calendar/inc/class.calendar_holidays.inc.php +++ b/calendar/inc/class.calendar_holidays.inc.php @@ -158,7 +158,7 @@ class calendar_holidays * @param ?string $lang 2-digit iso language code or NULL * @return array|Iterator parsed events */ - protected static function fetch($country, $lang=null) + public static function fetch($country, $lang=null) { if (!($url = self::is_url($country) ? $country : self::ical_url($country, $lang))) { diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 59838312ed..9ba8ab1d1d 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -840,7 +840,26 @@ END:VALARM'; public static function config_validate() { - $GLOBALS['egw_info']['server']['found_validation_hook'] = array('calendar_purge_old'); + $GLOBALS['egw_info']['server']['found_validation_hook'] = [ + 'calendar_purge_old', + 'ical_holiday_url' => 'calendar_hooks::ical_holiday_url', + ]; + } + + /** + * Validate the iCal URL + * + * @param string $url + * @param Api\Config $c + * @return string|null error message or null on success + */ + public static function ical_holiday_url(string $url, Api\Config $c) : ?string + { + if (!empty($url) && (!preg_match('#^(/|https?://[^/]+/[^/]+)#', $url) || !calendar_holidays::fetch($url))) + { + return "Invalid iCalendar URL: $url"; + } + return null; } /** diff --git a/calendar/templates/default/config.xet b/calendar/templates/default/config.xet index 467fb630a1..a958f5f364 100644 --- a/calendar/templates/default/config.xet +++ b/calendar/templates/default/config.xet @@ -11,7 +11,7 @@ - +