diff options
author | Jim Hu <jimhu@users.sourceforge.net> | 2006-03-20 01:08:29 +0000 |
---|---|---|
committer | Jim Hu <jimhu@users.sourceforge.net> | 2006-03-20 01:08:29 +0000 |
commit | edfac56f9d97c1754bb05c60bbc723fee7839fc8 (patch) | |
tree | 18719e21fbb15d4678422c49efe3af1a61080848 /functions | |
parent | c35649f1127a646c662a21a069c2031f24a772bd (diff) | |
download | phpicalendar-edfac56f9d97c1754bb05c60bbc723fee7839fc8.tar.gz phpicalendar-edfac56f9d97c1754bb05c60bbc723fee7839fc8.tar.bz2 phpicalendar-edfac56f9d97c1754bb05c60bbc723fee7839fc8.zip |
Display real calendar names where possible
Diffstat (limited to 'functions')
-rw-r--r-- | functions/calendar_functions.php | 31 | ||||
-rw-r--r-- | functions/ical_parser.php | 18 | ||||
-rw-r--r-- | functions/init.inc.php | 2 |
3 files changed, 40 insertions, 11 deletions
diff --git a/functions/calendar_functions.php b/functions/calendar_functions.php index 096246c..0724383 100644 --- a/functions/calendar_functions.php +++ b/functions/calendar_functions.php @@ -205,8 +205,7 @@ function getCalendarName($cal_path) { // // $cals = The calendars (entire path, e.g. from availableCalendars). function display_ical_list($cals, $pick=FALSE) { - global $cal, $ALL_CALENDARS_COMBINED, $current_view, $getdate, $calendar_lang, $all_cal_comb_lang; - + global $cal, $ALL_CALENDARS_COMBINED, $current_view, $getdate, $calendar_lang, $all_cal_comb_lang, $cal_filelist, $cal_displaynames; // Print each calendar option. foreach ($cals as $cal_tmp) { // Format the calendar path for display. @@ -215,6 +214,34 @@ function display_ical_list($cals, $pick=FALSE) { // and remove the .ics suffix. $cal_displayname_tmp = getCalendarName($cal_tmp); $cal_displayname_tmp = str_replace("32", " ", $cal_displayname_tmp); + #overwrite the display name if we already have a real name + if (is_numeric(array_search($cal_tmp, $cal_filelist))){ + $cal_displayname_tmp = $cal_displaynames[array_search($cal_tmp,$cal_filelist)]; + }else{ + # pull the name from the $cal_tmp file + $ifile = @fopen($cal_tmp, "r"); + if ($ifile == FALSE) exit(error($lang['l_error_cantopen'], $cal_tmp)); + while (!feof($ifile)) { + $line = fgets($ifile, 1024); + $line = trim($line); + if (ereg ("([^:]+):(.*)", $line, $regs)){ + $field = $regs[1]; + $data = $regs[2]; + $property = $field; + $prop_pos = strpos($property,';'); + if ($prop_pos !== false) $property = substr($property,0,$prop_pos); + $property = strtoupper($property); + if ($property == "X-WR-CALNAME"){ + $cal_displayname_tmp = $data; + break; + } + } + #stop reading if we find an event or timezone before there's a name + if ($line == "BEGIN:VTIMEZONE" ||$line == "BEGIN:VEVENT") break; + } + echo "</pre>"; + + } // If this is a webcal, add 'Webcal' to the display name. if (preg_match("/^(https?|webcal):\/\//i", $cal_tmp)) { diff --git a/functions/ical_parser.php b/functions/ical_parser.php index e8c5898..e24b953 100644 --- a/functions/ical_parser.php +++ b/functions/ical_parser.php @@ -1130,6 +1130,14 @@ if ($parse_file) { } } + +// Set a calender name for all calenders combined +if ($cal == $ALL_CALENDARS_COMBINED) { + $calendar_name = $all_cal_comb_lang; +} +$cal_displayname = implode(', ', $cal_displaynames); #reset this with the correct names +$template_started = getmicrotime(); + //If you want to see the values in the arrays, uncomment below. //print '<pre>'; @@ -1138,13 +1146,7 @@ if ($parse_file) { //print_r($day_array); //print_r($rrule_array); //print_r($recurrence_delete); +//print_r($cal_displaynames); +//print_r($cal_filelist); //print '</pre>'; - -// Set a calender name for all calenders combined -if ($cal == $ALL_CALENDARS_COMBINED) { - $calendar_name = $all_cal_comb_lang; -} -$cal_displayname = implode(', ', $cal_displaynames); #reset this with the correct names -$template_started = getmicrotime(); - ?> diff --git a/functions/init.inc.php b/functions/init.inc.php index 58be0ad..d22ba78 100644 --- a/functions/init.inc.php +++ b/functions/init.inc.php @@ -105,7 +105,7 @@ if (isset($_GET['cal'])) { $_GET['cal'] = explode(',', $_GET['cal']); // Grab the calendar filenames off the cal value array. - $cal_filenames = array_map("urldecode", $_GET['cal']); + $cal_filenames = $_GET['cal']; } else { if (isset($default_cal_check)) { if ($default_cal_check != $ALL_CALENDARS_COMBINED) { |