Update of /cvsroot/phpicalendar/phpicalendar3/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15653 Added Files: class.Daylight.php class.Parser.php class.Settings.php class.Standard.php class.Valarm.php class.Vcalendar.php class.Vevent.php class.Vfreebusy.php class.Vjournal.php class.Vtimezone.php class.Vtodo.php class.iCalObj.php Log Message: ical parser class files --- NEW FILE: class.Daylight.php --- <?php /*=====================class.Daylight.php===================== This class is for calendars. */ class Daylight extends Vtimezone{ function Daylight(){ } } ?> --- NEW FILE: class.Parser.php --- <?php /*=====================class.Parser.php===================== Refactoring of the ical parser in phpicalendar to make the code more maintainable gets a calendar object and creates a series of event objects. This object should probably only be invoked in situations where the input is an ics file, either a local cal or a webcal. Unserializing a saved cal should go somewhere else. The function process_file is the meat of the operation. Note that Parser determines the kind of object that should handle a content line, but delegates further parsing of that content-line to the object. In other words, the Parser class just deals with BEGIN and END events, which are involved in creating and organizing objects. */ class Parser{ var $cal, # calendar object $fh, # filehandle for the calendar file being parsed $lookahead, # buffer for last line read by read_line lookahead $mArray; # temporary master array entries function Parser(){ $this->lookahead = ''; } function set_cal($cal){ $this->cal = $cal; } function process_cal(){ process_file($this->cal->filename); } /* The structure of an ics file is somewhat like xml. Objects are hierarchical The top level object is VCALENDAR, which has children including VTIMEZONE, VEVENT, VTODO etc. Each of these has child objects, such as DAYLIGHT and STANDARD in VTIMEZONE, DTSTART in the others, etc. We will use this hiearchy, but not to full granularity. */ function process_file($filename){ $obj = null; $obj_stack = array(); if (!$this->open_file($filename)) return "can't open file"; $i = 0; while (!feof($this->fh)){ $line = $this->read_line(); # echo "$i:$line\n";$i++; if($line){ $tmp = explode(":", $line); $tmp2 = explode(";", $tmp[0]); $key = $tmp2[0]; #want the first string before either a colon or semicolon # echo "key:$key\n"; switch ($key){ case 'BEGIN': $type = ucfirst(strtolower($tmp[1])); if($type == 'Vcalendar'){ if (!is_object($this->cal)) $this->cal = new Vcalendar; echo "Make vcal obj\n"; $obj = $this->cal; $obj_stack[] = $obj; # echo "BEGIN: make new obj of type ".get_class($obj)." and push it onto the stack\n"; }elseif(in_array($type, array('Vtimezone','Daylight','Standard','Vevent','Vtodo','Vfreebusy'))){ $obj = new $type; # $obj_stack[] = $obj; # echo "BEGIN: make new obj of type ".get_class($obj)." and push it onto the stack\n"; }else{ # Handle BEGIN for undefined object types # Parser delegates further parsing to the object if(is_object($obj)) $obj->process_line($key,$line); } break; case 'END': $obj = array_pop($obj_stack); if(is_object(end($obj_stack))){ $parent_obj = end($obj_stack); $parent_obj->process_child($obj); # let the parent object set whatever it needs from the child } if(is_object($obj)) $obj->finish(); # "make the working object the last one on the stack\n"; if(is_object(end($obj_stack))){ $obj = $parent_obj; } break; default: # Parser delegates further parsing to the object if(is_object($obj)) $obj->process_line($key,$line); } # print_r($obj_stack); } } # "finished stack on line:$line. Lookahead:$this->lookahead\n"; #deal with possible lack of \n at eof if(trim($this->lookahead) != "" && is_object($obj)){ $obj = array_pop($obj_stack); if(is_object(end($obj_stack))){ $parent_obj = end($obj_stack); $parent_obj->process_child($obj); # let the parent object set whatever it } $obj->finish(); if(is_object($parent_obj)) $parent_obj->finish(); } print_r($this->cal); return true; } function open_file($filename){ $this->fh = fopen("./".$filename, "r"); if ($this->fh == FALSE) return false; return true; } # takes a filehandle and folds multiple line input to $this->line function read_line(){ if (feof($this->fh)){ return; } $tmp_line = $this->lookahead; $read_more = true; do { $this->lookahead = fgets($this->fh, 1024); $this->lookahead = ereg_replace("[\r\n]", "", $this->lookahead); if (($this->lookahead !='' && ($this->lookahead{0} == " " || $this->lookahead{0} == "\t")) || $tmp_line == '' || $tmp_line == "\n"){ $tmp_line = rtrim($tmp_line) . str_replace("\t"," ", $this->lookahead); }else{ $read_more = false; } }while ($read_more & !feof($this->fh)); return trim($tmp_line); } } # end class parser ?> --- NEW FILE: class.Settings.php --- <?php /*=====================class.Settings.php===================== Settings for phpicalendar 3 New creates an object with default settings Methods to overwrite from config.inc.php read from cookie set cookie */ class Settings{ function Settings(){ $this->template = 'default'; // Template support $this->default_view = 'day'; // Default view for calendars = 'day', 'week', 'month', 'year' $this->minical_view = 'current'; // Where do the mini-calendars go when clicked? = 'day', 'week', 'month', 'current' $this->default_cal = $this->ALL_CALENDARS_COMBINED; // $this->language = 'English'; // Language support $this->week_start_day = 'Sunday'; // Day of the week your week starts on $this->week_length = '7'; // Number of days to display in the week view $this->day_start = '0700'; // Start time for day grid $this->day_end = '2300'; // End time for day grid $this->gridLength = '15'; // Grid distance in minutes for day view, multiples of 15 preferred $this->num_years = '1'; // Number of years (up and back) to display in 'Jump to' $this->month_event_lines = '1'; // Number of lines to wrap each event title in month view, 0 means display all lines. $this->tomorrows_events_lines = '1'; // Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines. $this->allday_week_lines = '1'; // Number of lines to wrap each event title in all-day events in week view, 0 means display all lines. $this->week_events_lines = '1'; // Number of lines to wrap each event title in the 'Tommorrow's events' box, 0 means display all lines. $this->timezone = ''; // Set timezone. Read TIMEZONES file for more information $this->calendar_path = ''; // Leave this blank on most installs $this->second_offset = ''; // The time in seconds between your time and your server's time. $this->bleed_time = '-1'; // Allows events past midnight to just be displayed on the starting date, only good up to 24 hours. // Range from '0000' to '2359', or '-1' for no bleed time. $this->cookie_uri = ''; // The HTTP URL to the PHP iCalendar directory, // ie. http://www.example.com/phpicalendar -- AUTO SETTING -- Only set if you are having cookie issues. $this->download_uri = ''; // The HTTP URL to your calendars directory, ie. http://www.example.com/phpicalendar/calendars // -- AUTO SETTING -- Only set if you are having subscribe issues. $this->default_path = ''; // The HTTP URL to the PHP iCalendar directory, ie. http://www.example.com/phpicalendar $this->charset = 'UTF-8'; // Character set your calendar is in, suggested UTF-8, or iso-8859-1 for most languages. // Yes/No questions --- 'yes' means Yes, anything else means no. 'yes' must be lowercase. $this->allow_webcals = 'no'; // Allow http:// and webcal:// $this->this_months_events = 'yes'; // Display "This month's events" at the bottom off the month page. $this->enable_rss = 'yes'; // Enable RSS access to your calendars (good thing). $this->show_search = 'yes'; // Show the search box in the sidebar. $this->allow_preferences = 'yes'; // Allow visitors to change various preferences via cookies. $this->printview_default = 'no'; // Set print view as the default view. $this->show_todos = 'yes'; // Show your todo list on the side of day and week view. $this->show_completed = 'yes'; // Show completed todos on your todo list. $this->allow_login = 'yes'; // Set to yes to prompt for login to unlock calendars. $this->login_cookies = 'no'; // Set to yes to store authentication information via (unencrypted) cookies. Set to no to use sessions. $this->support_ical = 'no'; // Set to yes to support the Apple iCal calendar database structure. $this->recursive_path = 'no'; // Set to yes to recurse into subdirectories of the calendar path. // 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 for saving parsed cals $this->webcal_hours = '24'; // Number of hours to cache webcals. Setting to '0' will always re-parse webcals. // Webdav style publishing $this->phpicalendar_publishing = ''; // Set to '1' to enable remote webdav style publish. See 'calendars/publish.php' for complete information; // Administration settings (/admin/) $this->allow_admin = 'yes'; // Set to yes to allow the admin page // - remember to change the default password if using 'internal' as the $this->auth_method $this->auth_method = 'internal'; // Valid values are: 'ftp', 'internal', or 'none'. // 'ftp' uses the ftp server's username and password as well as ftp commands to delete and copy files. // 'internal' uses $this->auth_internal_username and $this->auth_internal_password defined below // - CHANGE the password. // 'none' uses NO authentication - meant to be used with another form of authentication such as http basic. $this->auth_internal_username = 'admin'; // Only used if $this->auth_method='internal'. The username for the administrator. $this->auth_internal_password = 'admin'; // Only used if $this->auth_method='internal'. The password for the administrator. $this->ftp_server = 'localhost'; // Only used if $this->auth_method='ftp'. The ftp server name. 'localhost' will work for most servers. $this->ftp_port = '21'; // Only used if $this->auth_method='ftp'. The ftp port. '21' is the default for ftp servers. $this->ftp_calendar_path = ''; // Only used if $this->auth_method='ftp'. The full path to the calendar directory on the ftp server. // If = '', will attempt to deduce the path based on $this->calendar_path, // but may not be accurate depending on ftp server config. // Calendar colors // You can increase the number of unique colors by adding additional images (monthdot_n.gif) // and in the css file (default.css) classes .alldaybg_n, .eventbg_n and .eventbg2_n // Colors will repeat from the beginning for calendars past $this->unique_colors (7 by default), with no limit. $this->unique_colors = '7'; $this->blacklisted_cals = array(); $this->list_webcals = array(); #$this->more_webcals['cpath'][] = '' //add webcals that will show up only for a particular cpath. $this->locked_cals = array(); // Fill in-between the quotes the names of the calendars you wish to hide $this->locked_map = array(); // Map username:password accounts to locked calendars that should be $this->apache_map = array(); // Map HTTP authenticated users to specific calendars. Users listed here and } function setLang(){ } } # end class Settings ?> --- NEW FILE: class.Standard.php --- <?php /*=====================class.Standard.php===================== This class is for calendars. */ class Standard extends Vtimezone{ function Standard(){ } } ?> --- NEW FILE: class.Valarm.php --- <?php /*=====================class.Valarm.php===================== This class is for events. */ class Valarm extends iCalObj{ function Valarm(){ } } ?> --- NEW FILE: class.Vcalendar.php --- <?php /*=====================class.Vcalendar.php===================== This class is for calendars. */ class Vcalendar extends iCalObj{ function Vcalendar(){ } } ?> --- NEW FILE: class.Vevent.php --- <?php /*=====================class.Vevent.php===================== This class is for events. */ class Vevent extends iCalObj{ function Vevent(){ } } ?> --- NEW FILE: class.Vfreebusy.php --- <?php /*=====================class.Vfreebusy.php===================== This class is for calendars. */ class Vfreebusy extends iCalObj{ function Vfreebusy(){ } } ?> --- NEW FILE: class.Vjournal.php --- <?php /*=====================class.Vjournal.php===================== This class is for calendars. */ class Vjournal extends iCalObj{ function Vjournal(){ } } ?> --- NEW FILE: class.Vtimezone.php --- <?php /*=====================class.Vtimezone.php===================== This class is for calendars. */ class Vtimezone extends iCalObj{ function Vtimezone(){ } } ?> --- NEW FILE: class.Vtodo.php --- <?php /*=====================class.Vtodo.php===================== This class is for calendars. */ class Vtodo extends iCalObj{ function Vtodo(){ } } ?> --- NEW FILE: class.iCalObj.php --- <?php /*=====================class.iCalObj.php===================== Refactoring of the ical parser in phpicalendar to make the code more maintainable Base class for icalendar objects. Some methods used by all, others only for timed events */ class iCalObj{ # var $var; # comment var $children; # comment function iCalObj(){ $this->children = array(); } /* Parser passes key - everything before the first colon or semicolon line - the whole line From the icalendar spec page 13: contentline = name *(";" param ) ":" value CRLF examples: ATTENDEE;CUTYPE=GROUP:MAILTO:iet...@im... RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1 Thus, note that key and value are both complex entities that can have multipart info */ function process_line($key, $line){ echo "\tfeed key= $key line=$line to the object of type ".get_class($this)."\n"; switch ($key){ case '': default: $line = str_replace("$key:","",$line); $varname = strtolower($key); $this->$varname = $this->clean_string($line); } } function process_child($obj){ echo "\t".get_class($this)." object processing child of type ".get_class($obj)."\n"; $this->children[] = $obj; } function finish(){ echo "END:tell the ".get_class($this)." object to finish up, pop it off the stack\n"; } function clean_string($data){ $data = str_replace("\\n", "<br />", $data); $data = str_replace("\\t", " ", $data); $data = str_replace("\\r", "<br />", $data); $data = str_replace('$', '$', $data); $data = stripslashes($data); return $data; } } ?> |