aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Miaw <josuah@users.sourceforge.net>2005-11-24 04:28:34 +0000
committerWesley Miaw <josuah@users.sourceforge.net>2005-11-24 04:28:34 +0000
commitf327c0bbc3252553eea7f66db88e031554a3fe11 (patch)
tree46429b537a40d1cdae77f144374de5236860bbe7
parente2ef86112facc0b3988308397ce6c70b76f9786a (diff)
downloadphpicalendar-f327c0bbc3252553eea7f66db88e031554a3fe11.tar.gz
phpicalendar-f327c0bbc3252553eea7f66db88e031554a3fe11.tar.bz2
phpicalendar-f327c0bbc3252553eea7f66db88e031554a3fe11.zip
Fixed support for multiple selection web calendars. You can now select
multiple local and web calendars, in any number and combination. The calendar name will also be displayed correctly, instead of only displaying a single calendar name when multiple calendars are chosen.
-rw-r--r--README2
-rw-r--r--day.php2
-rw-r--r--functions/calendar_functions.php9
-rw-r--r--functions/init.inc.php186
-rw-r--r--month.php4
-rw-r--r--print.php2
-rw-r--r--search.php4
-rw-r--r--week.php2
-rw-r--r--year.php2
9 files changed, 128 insertions, 85 deletions
diff --git a/README b/README
index 1561c0c..90e0567 100644
--- a/README
+++ b/README
@@ -84,6 +84,7 @@ Changes:
2.2
-Added Apple iCal native repository support.
-Added support for finding calendars in subdirectories.
+ -Can now select multiple local and web calendars.
-rss.php
new feed types for different kinds of date ranges
changed handling of multi-day events
@@ -91,7 +92,6 @@ Changes:
handling of webcals
popup encoding
display when individual calendars displayed
- -known bug: webcals don't work with multiple calendar selection
2.1
-Updated languages: Finnish
diff --git a/day.php b/day.php
index c64728a..905c220 100644
--- a/day.php
+++ b/day.php
@@ -60,7 +60,7 @@ $page->replace_tags(array(
'getdate' => $getdate,
'getcpath' => "&cpath=$cpath",
'cpath' => $cpath,
- 'calendar_name' => (is_array($calendar_name) ? "Multiple" : $calendar_name),
+ 'calendar_name' => $cal_displayname,
'current_view' => $current_view,
'display_date' => $display_date,
'sidebar_date' => $sidebar_date,
diff --git a/functions/calendar_functions.php b/functions/calendar_functions.php
index 1281f95..a587d2c 100644
--- a/functions/calendar_functions.php
+++ b/functions/calendar_functions.php
@@ -30,6 +30,7 @@ function availableCalendars($username, $password, $cal_filename, $admin = false)
if (isset($locked_map["$username:$password"])) {
$unlocked_cals = $locked_map["$username:$password"];
}
+
// Make a local copy of the requested calendars.
if (!is_array($cal_filename))
$cal_filename_local = array($cal_filename);
@@ -43,7 +44,7 @@ function availableCalendars($username, $password, $cal_filename, $admin = false)
$search_paths = array($calendar_path);
// Add web calendars.
- if ($cal_filename == $ALL_CALENDARS_COMBINED || $admin) {
+ if ($cal_filename_local[0] == $ALL_CALENDARS_COMBINED || $admin) {
if (!isset($http_user) && !$admin) {
foreach ($list_webcals as $file) {
// Make sure the URL ends with .ics.
@@ -56,7 +57,7 @@ function availableCalendars($username, $password, $cal_filename, $admin = false)
}
// Set some booleans that will dictate our search.
- $find_all = ($cal_filename == $ALL_CALENDARS_COMBINED || $admin);
+ $find_all = ($cal_filename_local[0] == $ALL_CALENDARS_COMBINED || $admin);
// Process all search paths.
while (!empty($search_paths)) {
@@ -76,9 +77,9 @@ function availableCalendars($username, $password, $cal_filename, $admin = false)
if ($find_all || $recursive_path == 'yes' || $support_ical == 'yes') {
// Open the directory.
$dir_handle = @opendir($search_path)
- or die(error(sprintf($lang['l_error_path'], $search_path), $cal_filename));
+ or die(error(sprintf($lang['l_error_path'], $search_path), implode(',', $cal_filename)));
if ($dir_handle === false)
- die(error(sprintf($lang['l_error_path'], $search_path), $cal_filename));
+ die(error(sprintf($lang['l_error_path'], $search_path), implode(',', $cal_filename)));
// Add each file in the directory that does not begin with a dot.
while (false !== ($file = readdir($dir_handle))) {
diff --git a/functions/init.inc.php b/functions/init.inc.php
index ac3141e..d7d0dc4 100644
--- a/functions/init.inc.php
+++ b/functions/init.inc.php
@@ -76,106 +76,148 @@ if (ini_get('max_execution_time') < 60) {
}
-
if ($calendar_path == '') {
$calendar_path = BASE.'calendars';
}
-$is_webcal = FALSE;
+// Pull the calendars off the GET line if provided. The $cal_filename
+// is always an array, because this makes it easier to deal with below.
+$cal_filenames = array();
if (isset($_GET['cal'])) {
- //if we get a comma-separated list of calendars, split into array
- if(stristr($_GET['cal'], ",")) {
- $_GET['cal'] = explode(",", $_GET['cal']);
- }
- //if we have an array of calendars, decode each (though I'm not sure this is necessary)
- if(is_array($_GET['cal'])) {
- $cal_filename = array();
- foreach($_GET['cal'] as $c) {
- $cal_filename[] = urldecode($c);
- }
- }else {
- $cal_filename = urldecode($_GET['cal']);
- }
+ // If the cal value is not an array, split it into an array on
+ // commas.
+ if (!is_array($_GET['cal']))
+ $_GET['cal'] = explode(',', $_GET['cal']);
+
+ // Grab the calendar filenames off the cal value array.
+ $cal_filenames = array_map("urldecode", $_GET['cal']);
} else {
if (isset($default_cal_check)) {
if ($default_cal_check != $ALL_CALENDARS_COMBINED) {
$calcheck = $calendar_path.'/'.$default_cal_check.'.ics';
$calcheckopen = @fopen($calcheck, "r");
if ($calcheckopen == FALSE) {
- $cal_filename = $default_cal;
+ $cal_filenames[0] = $default_cal;
} else {
- $cal_filename = $default_cal_check;
+ $cal_filenames[0] = $default_cal_check;
}
} else {
- $cal_filename = $ALL_CALENDARS_COMBINED;
+ $cal_filenames[0] = $ALL_CALENDARS_COMBINED;
}
} else {
- $cal_filename = $default_cal;
+ $cal_filenames[0] = $default_cal;
}
}
-if (!is_array($cal_filename) && (substr($cal_filename, 0, 7) == 'http://' || substr($cal_filename, 0, 8) == 'https://' || substr($cal_filename, 0, 9) == 'webcal://')) {
- $is_webcal = TRUE;
- $cal_webcalPrefix = str_replace('http://','webcal://',$cal_filename);
- $cal_httpPrefix = str_replace('webcal://','http://',$cal_filename);
- $cal_httpsPrefix = str_replace('webcal://','https://',$cal_filename);
- $cal_httpsPrefix = str_replace('http://','https://',$cal_httpsPrefix);
- $cal_filename = $cal_httpPrefix;
-}
-
-if ($is_webcal == TRUE) {
- if ($allow_webcals == 'yes' || in_array($cal_webcalPrefix, $list_webcals) || in_array($cal_httpPrefix, $list_webcals) || in_array($cal_httpsPrefix, $list_webcals)) {
- $cal_displayname = substr(str_replace('32', ' ', basename($cal_filename)), 0, -4);
- $cal = urlencode($cal_filename);
- $filename = $cal_filename;
- $subscribe_path = $cal_webcalPrefix;
- // empty the filelist array
- $cal_filelist = array();
- array_push($cal_filelist,$filename);
- } else {
- exit(error($lang['l_error_remotecal'], $_GET['cal']));
- }
-} else {
- $cal_displayname = str_replace('32', ' ', (is_array($cal_filename) ? implode(", ", $cal_filename) : $cal_filename));
- if(is_array($cal_filename)) {
- $cal = array();
- $blacklisted = FALSE;
- foreach($cal_filename as $c) {
- $cal[] = urlencode($c);
- if(in_array($c, $blacklisted_cals)) $blacklisted = TRUE;
- }
- $cal = implode(",", $cal);
+// Separate the calendar identifiers into web calendars and local
+// calendars.
+$web_cals = array();
+$local_cals = array();
+foreach ($cal_filenames as $cal_filename) {
+ // If the calendar identifier begins with a web protocol, this is a web
+ // calendar.
+ if (substr($cal_filename, 0, 7) == 'http://' ||
+ substr($cal_filename, 0, 8) == 'https://' ||
+ substr($cal_filename, 0, 9) == 'webcal://')
+ {
+ $web_cals[] = $cal_filename;
}
+
+ // Otherwise it is a local calendar.
else {
- $cal = urlencode($cal_filename);
- $blacklisted = in_array($cal_filename, $blacklisted_cals);
+ // Check blacklisted.
+ if (in_array($cal_filename, $blacklisted_cals)) {
+ exit(error($lang['l_error_restrictedcal'], $cal_filename));
+ }
+ $local_cals[] = $cal_filename;
}
+}
- if ($blacklisted) {
- exit(error($lang['l_error_restrictedcal'], $cal_filename));
- } else {
- if (!isset($filename)) {
- $cal_filelist = availableCalendars($username, $password, $cal_filename);
- if (count($cal_filelist) == 1) $filename = $cal_filelist[0];
- }
+// We will build the calendar display name as we go. The final display
+// name will get constructed at the end.
+$cal_displaynames = array();
+
+// This is our list of final calendars.
+$cal_filelist = array();
+
+// This is our list of URL encoded calendars.
+$cals = array();
+
+// Process the web calendars.
+foreach ($web_cals as $web_cal) {
+ // Make some protocol alternatives, and set our real identifier to the
+ // HTTP protocol.
+ $cal_webcalPrefix = str_replace('http://','webcal://',$web_cal);
+ $cal_httpPrefix = str_replace('webcal://','http://',$web_cal);
+ $cal_httpsPrefix = str_replace('webcal://','https://',$web_cal);
+ $cal_httpsPrefix = str_replace('http://','https://',$web_cal);
+ $web_cal = $cal_httpPrefix;
- // Sets the download and subscribe paths from the config if present.
- if (isset($filename)) {
- if (($download_uri == '') && (preg_match('/(^\/|\.\.\/)/', $filename) == 0)) {
- $subscribe_path = 'webcal://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'."$cpath/".$filename;
- $download_filename = $filename;
- } elseif ($download_uri != '') {
- $newurl = eregi_replace("^(http://)", "", $download_uri);
- $subscribe_path = 'webcal://'.$newurl.'/'."$cpath/".$cal_filename.'.ics';
- $download_filename = $download_uri.'/'."$cpath/".$cal_filename.'.ics';
- } else {
- $subscribe_path = "$cpath/";
- $download_filename = "$cpath/";
- }
+ // We can only include this web calendar if we allow all web calendars
+ // (as defined by $allow_webcals) or if the web calendar shows up in the
+ // list of web calendars defined in config.inc.php.
+ if ($allow_webcals != 'yes' &&
+ !in_array($cal_webcalPrefix, $list_webcals) &&
+ !in_array($cal_httpPrefix, $list_webcals) &&
+ !in_array($cal_httpsPrefix, $list_webcals))
+ {
+ exit(error($lang['l_error_remotecal'], $web_cal));
+ }
+
+ // Pull the display name off the URL.
+ $cal_displaynames[] = substr(str_replace('32', ' ', basename($web_cal)), 0, -4);
+
+ // FIXME
+ $cals[] = urlencode($web_cal);
+ //$filename = $cal_filename;
+ $subscribe_path = $cal_webcalPrefix;
+
+ // Add the webcal to the available calendars.
+ $cal_filelist[] = $web_cal;
+}
+
+// Process the local calendars.
+if (count($local_cals) > 0) {
+ $local_cals = availableCalendars($username, $password, $local_cals);
+ foreach ($local_cals as $local_cal) {
+ $cal_displaynames[] = str_replace('32', ' ', getCalendarName($local_cal));
+ }
+ $cal_filelist = array_merge($cal_filelist, $local_cals);
+ $cals = array_merge($cals, array_map("urlencode", array_map("getCalendarName", $local_cals)));
+
+ // Set the download and subscribe paths from the config, if there is
+ // only one calendar being displayed and those paths are defined.
+ if (count($local_cals) == 1) {
+ $filename = $local_cals[0];
+ if (($download_uri == '') && (preg_match('/(^\/|\.\.\/)/', $filename) == 0)) {
+ $subscribe_path = 'webcal://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).'/'."$cpath/".$filename;
+ $download_filename = $filename;
+ } elseif ($download_uri != '') {
+ $newurl = eregi_replace("^(http://)", "", $download_uri);
+ $subscribe_path = 'webcal://'.$newurl.'/'."$cpath/".$filename.'.ics';
+ $download_filename = $download_uri.'/'."$cpath/".$filename.'.ics';
+ } else {
+ $subscribe_path = "$cpath/";
+ $download_filename = "$cpath/";
}
}
}
+// We should only allow a download filename and subscribe path if there is
+// only one calendar being displayed.
+if (count($cal_filelist) > 1) {
+ $subscribe_path = '';
+ $download_filename = '';
+}
+
+// Build the final cal list. This is a comma separated list of the
+// url-encoded calendar names and web calendar URLs.
+$cal = implode(',', $cals);
+
+// Build the final display name used for template substitution.
+asort($cal_displaynames);
+$cal_displayname = implode(', ', $cal_displaynames);
+
$rss_powered = ($enable_rss == 'yes') ? 'yes' : '';
function getmicrotime() {
diff --git a/month.php b/month.php
index 527e75c..0a08ea0 100644
--- a/month.php
+++ b/month.php
@@ -67,7 +67,7 @@ $page->replace_tags(array(
'getdate' => $getdate,
'getcpath' => "&cpath=$cpath",
'cpath' => $cpath,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'display_date' => $display_date,
'rss_powered' => $rss_powered,
'default_path' => '',
@@ -138,4 +138,4 @@ $page->output();
-?> \ No newline at end of file
+?>
diff --git a/print.php b/print.php
index e173765..8aa9b75 100644
--- a/print.php
+++ b/print.php
@@ -51,7 +51,7 @@ $page->replace_tags(array(
'template' => $template,
'cal' => $cal,
'getdate' => $getdate,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'current_view' => $current_view,
'printview' => $printview,
'display_date' => $display_date,
diff --git a/search.php b/search.php
index e264e69..08c3aa4 100644
--- a/search.php
+++ b/search.php
@@ -292,7 +292,7 @@ $page->replace_files(array(
'template' => $template,
'cal' => $cal,
'getdate' => $getdate,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'display_date' => $display_date,
'current_view' => $current_view,
'sidebar_date' => $sidebar_date,
@@ -320,7 +320,7 @@ $page->replace_tags(array(
'cal' => $cal,
'getdate' => $getdate,
'cpath' => $cpath,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'display_date' => $display_date,
'rss_powered' => $rss_powered,
'default_path' => '',
diff --git a/week.php b/week.php
index 7cde70a..ed95bd0 100644
--- a/week.php
+++ b/week.php
@@ -62,7 +62,7 @@ $page->replace_tags(array(
'getdate' => $getdate,
'getcpath' => "&cpath=$cpath",
'cpath' => $cpath,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'display_date' => $display_date,
'current_view' => $current_view,
'sidebar_date' => $sidebar_date,
diff --git a/year.php b/year.php
index 84d5780..780c910 100644
--- a/year.php
+++ b/year.php
@@ -31,7 +31,7 @@ $page->replace_tags(array(
'getcpath' => "&cpath=$cpath",
'cpath' => $cpath,
'getdate' => $getdate,
- 'calendar_name' => $calendar_name,
+ 'calendar_name' => $cal_displayname,
'display_date' => $this_year,
'default_path' => '',
'rss_powered' => $rss_powered,

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