diff options
author | Wesley Miaw <josuah@users.sourceforge.net> | 2003-11-23 01:31:30 +0000 |
---|---|---|
committer | Wesley Miaw <josuah@users.sourceforge.net> | 2003-11-23 01:31:30 +0000 |
commit | 2751b93b7178bebdd6b33dc69b847e987c6a496e (patch) | |
tree | 128fd7535fc2150f35bdd3b7808d349f9ab3dc46 /functions | |
parent | 4f5013dc4bf5cb67032eb75f36a65ba634351774 (diff) | |
download | phpicalendar-2751b93b7178bebdd6b33dc69b847e987c6a496e.tar.gz phpicalendar-2751b93b7178bebdd6b33dc69b847e987c6a496e.tar.bz2 phpicalendar-2751b93b7178bebdd6b33dc69b847e987c6a496e.zip |
Fixed problems with the list_icals logic. Previous cvs update merged
files incorrectly.
Diffstat (limited to 'functions')
-rw-r--r-- | functions/list_icals.php | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/functions/list_icals.php b/functions/list_icals.php index c2e6ce4..f739e07 100644 --- a/functions/list_icals.php +++ b/functions/list_icals.php @@ -1,27 +1,51 @@ <?php if ($display_ical_list == "yes") { - // start of <select> tag echo "<select name=\"action\" class=\"query_style\" onChange=\"window.location=(this.options[this.selectedIndex].value+'"; if (isset($query)) echo $query; echo "');\">"; - // open file - $dir_handle = @opendir($calendar_path) or die(error(sprintf($error_path_lang, $calendar_path), $cal_filename)); - - // Grab all calendars. - $filelist = availableCalendarNames($username, $password, $ALL_CALENDARS_COMBINED); - foreach ($filelist as $file) { - - // $cal_filename is the filename of the calendar without .ics - // $cal is a urlencoded version of $cal_filename - // $cal_displayname is $cal_filename with occurrences of "32" replaced with " " - $cal_filename_tmp = substr($file,0,-4); - $cal_tmp = urlencode($cal_filename_tmp); - $cal_displayname_tmp = str_replace("32", " ", $cal_filename_tmp); - if ($cal_tmp == $cal) { - print "<option value=\"$current_view.php?cal=$cal_tmp\" selected>$cal_displayname_tmp $calendar_lang</option>\n"; + + // Get all calendars. + $all_cals = availableCalendars($username, $password, $ALL_CALENDARS_COMBINED); + foreach ($all_cals as $cal_tmp) { + // Format the calendar path for display. + // + // Only display the calendar name, replace all instances of "32" with " ", + // and remove the .ics suffix. + $cal_displayname_tmp = basename($cal_tmp); + $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp); + $cal_displayname_tmp = substr($cal_displayname_tmp, 0, -4); + + // If this is a webcal, add 'Webcal' to the display name. + if (preg_match("/^(https?|webcal):\/\//i", $cal_tmp)) { + $cal_displayname_tmp .= " Webcal"; + } + + // Otherwise, remove all the path information, since that should + // not be used to identify local calendars. Also add the calendar + // label to the display name. + else { + // Strip path and .ics suffix. + $cal_tmp = basename($cal_tmp); + $cal_tmp = substr($cal_tmp, 0, -4); + + // Add calendar label. + $cal_displayname_tmp .= " $calendar_lang"; + } + + // Encode the calendar path. + $cal_encoded_tmp = urlencode($cal_tmp); + + // Display the option. + // + // The submitted calendar will be encoded, and always use http:// + // if it is a webcal. So that is how we perform the comparison when + // trying to figure out if this is the selected calendar. + $cal_httpPrefix_tmp = str_replace('webcal://', 'http://', $cal_tmp); + if ($cal_httpPrefix_tmp == urldecode($cal)) { + print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\" selected>$cal_displayname_tmp</option>"; } else { - print "<option value=\"$current_view.php?cal=$cal_tmp\">$cal_displayname_tmp $calendar_lang</option>\n"; + print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\">$cal_displayname_tmp</option>"; } } @@ -31,23 +55,8 @@ if ($display_ical_list == "yes") { } else { print "<option value=\"$current_view.php?cal=$ALL_CALENDARS_COMBINED&getdate=$getdate\">$all_cal_comb_lang</option>"; } - - foreach($list_webcals as $cal_tmp) { - if ($cal_tmp != '') { - $cal_displayname_tmp = basename($cal_tmp); - $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp); - $cal_displayname_tmp = substr($cal_displayname_tmp,0,-4); - $cal_encoded_tmp = urlencode($cal_tmp); - if ($cal_tmp == $cal_httpPrefix || $cal_tmp == $cal_webcalPrefix) { - print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\" selected>$cal_displayname_tmp Webcal</option>"; - } else { - print "<option value=\"$current_view.php?cal=$cal_encoded_tmp&getdate=$getdate\">$cal_displayname_tmp Webcal</option>"; - } - } - } // finish <select> print "</select>"; - } ?> |