aboutsummaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorJason Oster <parasytic@users.sourceforge.net>2009-06-19 20:39:46 +0000
committerJason Oster <parasytic@users.sourceforge.net>2009-06-19 20:39:46 +0000
commitb690f955bb712d2cdafbdb3fddb8469cde6b25ae (patch)
treebf4bb03cf340f64dda6e14e96b41a26da8c3ccd3 /functions
parent6836bebf950e2f69a310e92df6af730913f10945 (diff)
downloadphpicalendar-b690f955bb712d2cdafbdb3fddb8469cde6b25ae.tar.gz
phpicalendar-b690f955bb712d2cdafbdb3fddb8469cde6b25ae.tar.bz2
phpicalendar-b690f955bb712d2cdafbdb3fddb8469cde6b25ae.zip
Use http "last-modified" time on webcals and remove "webcals_hours" config setting
Diffstat (limited to 'functions')
-rw-r--r--functions/date_functions.php24
-rw-r--r--functions/ical_parser.php21
2 files changed, 36 insertions, 9 deletions
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-2022 Faster IT GmbH | imprint | privacy policy