aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--default_config.php1
-rw-r--r--functions/date_functions.php24
-rw-r--r--functions/ical_parser.php21
3 files changed, 36 insertions, 10 deletions
diff --git a/default_config.php b/default_config.php
index 0384d5f..9aac854 100644
--- a/default_config.php
+++ b/default_config.php
@@ -55,7 +55,6 @@ class Configs{
// Calendar Caching (decreases page load times)
$this->save_parsed_cals = 'no'; // Saves a copy of the cal in /tmp after it's been parsed. Improves performance.
$this->tmp_dir = '/tmp'; // The temporary directory on your system (/tmp is fine for UNIXes including Mac OS X). Any php-writable folder works.
- $this->webcal_hours = '24'; // Number of hours to cache webcals. Setting to '0' will always re-parse webcals.
// Webdav style publishing
$this->phpicalendar_publishing = '0'; // Set to '1' to enable remote webdav style publish. See 'calendars/publish.php' for complete information;
diff --git a/functions/date_functions.php b/functions/date_functions.php
index 9eba84e..4751ad2 100644
--- a/functions/date_functions.php
+++ b/functions/date_functions.php
@@ -4,6 +4,30 @@ require_once(BASE."functions/is_daylight.php");
// functions for returning or comparing dates
+// get remote file last modification date (returns unix timestamp)
+function remote_filemtime($url) {
+ $fp = fopen($url, 'r');
+ if (!$fp) return 0;
+ $metadata = stream_get_meta_data($fp);
+ fclose($fp);
+
+ $unixtime = 0;
+ foreach ($metadata['wrapper_data'] as $response) {
+ // case: redirection
+ // WARNING: does not handle relative redirection
+ if (substr(strtolower($response), 0, 10) == 'location: ') {
+ return GetRemoteLastModified(substr($response, 10));
+ }
+ // case: last-modified
+ else if (substr(strtolower($response), 0, 15) == 'last-modified: ') {
+ $unixtime = strtotime(substr($response, 15));
+ break;
+ }
+ }
+
+ return $unixtime;
+}
+
// takes iCalendar 2 day format and makes it into 3 characters
// if $txt is true, it returns the 3 letters, otherwise it returns the
// integer of that day; 0=Sun, 1=Mon, etc.
diff --git a/functions/ical_parser.php b/functions/ical_parser.php
index 6f8111d..6a10272 100644
--- a/functions/ical_parser.php
+++ b/functions/ical_parser.php
@@ -19,17 +19,16 @@ if ($phpiCal_config->save_parsed_cals == 'yes') {
$master_array = unserialize($contents);
$z=1;
$y=0;
- $webcal_mtime = time() - ($phpiCal_config->webcal_hours * 3600);
if (sizeof($master_array['-4']) == (sizeof($cal_filelist))) {
foreach ($master_array['-4'] as $temp_array) {
$mtime = $master_array['-4'][$z]['mtime'];
$fname = $master_array['-4'][$z]['filename'];
$wcalc = $master_array['-4'][$z]['webcal'];
+
if ($wcalc == 'no') $realcal_mtime = filemtime($fname);
- if (isset($realcal_mtime) && ($mtime == $realcal_mtime) && ($wcalc == 'no')) {
- $y++;
- } elseif (($wcalc == 'yes') && ($mtime > $webcal_mtime)) {
- //echo date('H:i',$mtime). ' > '. date('H:i',$webcal_mtime);
+ else $realcal_mtime = remote_filemtime($fname);
+
+ if ($mtime == $realcal_mtime) {
$y++;
}
$z++;
@@ -50,7 +49,13 @@ if ($phpiCal_config->save_parsed_cals == 'yes') {
if ($parse_file == true) unset($master_array);
} else {
foreach ($cal_filelist as $filename) {
- $realcal_mtime = filemtime($filename);
+ if (substr($filename, 0, 7) == 'http://' || substr($filename, 0, 8) == 'https://' || substr($filename, 0, 9) == 'webcal://') {
+ $realcal_mtime = remote_filemtime($filename);
+ }
+ else {
+ $realcal_mtime = filemtime($filename);
+ }
+
$parsedcal = $phpiCal_config->tmp_dir.'/parsedcal-'.urlencode($cpath.'::'.$cal_filename).'-'.$this_year;
if (file_exists($parsedcal)) {
$parsedcal_mtime = filemtime($parsedcal);
@@ -84,15 +89,13 @@ foreach ($cal_filelist as $cal_key=>$filename) {
if ($parse_file) {
// Let's see if we're doing a webcal
- $is_webcal = FALSE;
if (substr($filename, 0, 7) == 'http://' || substr($filename, 0, 8) == 'https://' || substr($filename, 0, 9) == 'webcal://') {
- $is_webcal = TRUE;
$cal_webcalPrefix = str_replace(array('http://', 'https://'), 'webcal://', $filename);
$cal_httpPrefix = str_replace(array('webcal://', 'https://'), 'http://', $filename);
$cal_httpsPrefix = str_replace(array('http://', 'webcal://'), 'https://', $filename);
$filename = $cal_httpPrefix;
$master_array['-4'][$calnumber]['webcal'] = 'yes';
- $actual_mtime = time();
+ $actual_mtime = @remote_filemtime($filename);
} else {
$actual_mtime = @filemtime($filename);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy