📄 icalcreator.class.php
字号:
break; } } if( $newProp ) { $newProp = FALSE; $lastix++; $proprows[$lastix] = $line; } else { /* remove line breaks */ if(( '\n' == substr( $proprows[$lastix], -2 )) && ( ' ' == substr( $line, 0, 1 ))) { $proprows[$lastix] = substr( $proprows[$lastix], 0, strlen( $proprows[$lastix] ) - 2 ); $line = substr( $line, 1 ); } $proprows[$lastix] .= $line; } } $toolbox = new calendarComponent(); foreach( $proprows as $line ) { if( '\n' == substr( $line, -2 )) $line = substr( $line, 0, strlen( $line ) - 2 ); /* get propname */ $cix = $propname = null; for( $cix=0; $cix < strlen( $line ); $cix++ ) { if( in_array( $line{$cix}, array( ':', ';' ))) break; else $propname .= $line{$cix}; } /* ignore version/prodid properties */ if( in_array( strtoupper( $propname ), array( 'VERSION', 'PRODID' ))) continue; $line = substr( $line, $cix); /* separate attributes from value */ $attr = array(); $attrix = -1; $strlen = strlen( $line ); for( $cix=0; $cix < $strlen; $cix++ ) { if(( ':' == $line{$cix} ) && ( '://' != substr( $line, $cix, 3 )) && ( 'mailto:' != strtolower( substr( $line, $cix - 6, 7 )))) { $attrEnd = TRUE; if(( $cix < ( $strlen - 4 )) && ctype_digit( substr( $line, $cix+1, 4 ))) { // an URI with a (4pos) portnr?? for( $c2ix = $cix; 3 < $c2ix; $c2ix-- ) { if( '://' == substr( $line, $c2ix - 2, 3 )) { $attrEnd = FALSE; break; // an URI with a portnr!! } } } if( $attrEnd) { $line = substr( $line, $cix + 1 ); break; } } if( ';' == $line{$cix} ) $attr[++$attrix] = null; else $attr[$attrix] .= $line{$cix}; } /* make attributes in array format */ $propattr = array(); foreach( $attr as $attribute ) { $attrsplit = explode( '=', $attribute, 2 ); if( 1 < count( $attrsplit )) $propattr[$attrsplit[0]] = $attrsplit[1]; else $propattr[] = $attribute; } /* update Property */ if( FALSE !== strpos( $line, ',' )) { $content = explode( ',', $line ); $clen = count( $content ); for( $cix = 0; $cix < $clen; $cix++ ) { if( "\\" == substr( $content[$cix], -1 )) { $content[$cix] .= ','.$content[$cix + 1]; unset( $content[$cix + 1] ); $cix++; } } if( 1 < count( $content )) { foreach( $content as $cix => $contentPart ) $content[$cix] = $toolbox->_strunrep( $contentPart ); $this->setProperty( $propname, $content, $propattr ); continue; } else $line = reset( $content ); $line = $toolbox->_strunrep( $line ); } $this->setProperty( $propname, trim( $line ), $propattr ); } // end - foreach( $this->unparsed.. . } // end - if( is_array( $this->unparsed.. . /* parse Components */ if( is_array( $this->components ) && ( 0 < count( $this->components ))) { for( $six = 0; $six < count( $this->components ); $six++ ) $this->components[$six]->parse(); } else return FALSE; /* err 91 or something.. . */ }/*********************************************************************************//** * creates formatted output for calendar object instance * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.13 - 2007-10-25 * @return string */ function createCalendar() { $calendarInit1 = $calendarInit2 = $calendarxCaldecl = $calendarStart = $calendar = null; switch( $this->format ) { case 'xcal': $calendarInit1 = '<?xml version="1.0" encoding="UTF-8"?>'.$this->nl. '<!DOCTYPE iCalendar PUBLIC "-//IETF//DTD XCAL/iCalendar XML//EN"'.$this->nl. '"http://www.ietf.org/internet-drafts/draft-ietf-calsch-many-xcal-01.txt"'; $calendarInit2 = '>'.$this->nl; $calendarStart = '<vcalendar'; break; default: $calendarStart = 'BEGIN:VCALENDAR'.$this->nl; break; } $calendarStart .= $this->createCalscale(); $calendarStart .= $this->createMethod(); $calendarStart .= $this->createProdid(); $calendarStart .= $this->createVersion(); switch( $this->format ) { case 'xcal': $nlstrlen = strlen( $this->nl ); if( $this->nl == substr( $calendarStart, ( 0 - $nlstrlen ))) $calendarStart = substr( $calendarStart, 0, ( strlen( $calendarStart ) - $nlstrlen )); $calendarStart .= '>'.$this->nl; break; default: break; } $calendar .= $this->createXprop(); foreach( $this->components as $component ) { if( '' >= $component->getConfig( 'language')) $component->setConfig( 'language', $this->getConfig( 'language' )); $component->setConfig( 'allowEmpty', $this->getConfig( 'allowEmpty' )); $component->setConfig( 'nl', $this->getConfig( 'nl' )); $component->setConfig( 'unique_id', $this->getConfig( 'unique_id' )); $component->setConfig( 'format', $this->getConfig( 'format' )); $calendar .= $component->createComponent( $this->xcaldecl ); } if(( 0 < count( $this->xcaldecl )) && ( 'xcal' == $this->format )) { // xCal only $calendarInit1 .= $this->nl.'['.$this->nl; $old_xcaldecl = array(); foreach( $this->xcaldecl as $declix => $declPart ) { if(( 0 < count( $old_xcaldecl)) && ( in_array( $declPart['uri'], $old_xcaldecl['uri'] )) && ( in_array( $declPart['external'], $old_xcaldecl['external'] ))) continue; // no duplicate uri and ext. references $calendarxCaldecl .= '<!'; foreach( $declPart as $declKey => $declValue ) { switch( $declKey ) { // index case 'xmldecl': // no 1 $calendarxCaldecl .= $declValue.' '; break; case 'uri': // no 2 $calendarxCaldecl .= $declValue.' '; $old_xcaldecl['uri'][] = $declValue; break; case 'ref': // no 3 $calendarxCaldecl .= $declValue.' '; break; case 'external': // no 4 $calendarxCaldecl .= '"'.$declValue.'" '; $old_xcaldecl['external'][] = $declValue; break; case 'type': // no 5 $calendarxCaldecl .= $declValue.' '; break; case 'type2': // no 6 $calendarxCaldecl .= $declValue; break; } } $calendarxCaldecl .= '>'.$this->nl; } $calendarInit2 = ']'.$calendarInit2; } switch( $this->format ) { case 'xcal': $calendar .= '</vcalendar>'.$this->nl; break; default: $calendar .= 'END:VCALENDAR'.$this->nl; break; } return $calendarInit1.$calendarxCaldecl.$calendarInit2.$calendarStart.$calendar; }/** * a HTTP redirect header is sent with created, updated and/or parsed calendar * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.12 - 2007-10-23 * @return redirect */ function returnCalendar() { $filename = $this->getConfig( 'filename' ); $output = $this->createCalendar(); $filesize = strlen( $output );// if( headers_sent( $filename, $linenum ))// die( "Headers already sent in $filename on line $linenum\n" ); if( 'xcal' == $this->format ) header( 'Content-Type: application/calendar+xml; charset=utf-8' ); else header( 'Content-Type: text/calendar; charset=utf-8' ); header( 'Content-Length: '.$filesize ); header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); header( 'Cache-Control: max-age=10' ); echo $output; die(); }/** * save content in a file * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.12 - 2007-12-30 * @param string $directory optional * @param string $filename optional * @param string $delimiter optional * @return bool */ function saveCalendar( $directory=FALSE, $filename=FALSE, $delimiter=FALSE ) { if( $directory ) $this->setConfig( 'directory', $directory ); if( $filename ) $this->setConfig( 'filename', $filename ); if( $delimiter && ($delimiter != DIRECTORY_SEPARATOR )) $this->setConfig( 'delimiter', $delimiter ); if( FALSE === ( $dirfile = $this->getConfig( 'url' ))) $dirfile = $this->getConfig( 'dirfile' ); $iCalFile = @fopen( $dirfile, 'w' ); if( $iCalFile ) { if( FALSE === fwrite( $iCalFile, $this->createCalendar() )) return FALSE; fclose( $iCalFile ); return TRUE; } else return FALSE; }/** * if recent version of calendar file exists (default one hour), an HTTP redirect header is sent * else FALSE is returned * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.12 - 2007-10-28 * @param string $directory optional alt. int timeout * @param string $filename optional * @param string $delimiter optional * @param int timeout optional, default 3600 sec * @return redirect/FALSE */ function useCachedCalendar( $directory=FALSE, $filename=FALSE, $delimiter=FALSE, $timeout=3600) { if ( $directory && ctype_digit( (string) $directory ) && !$filename ) { $timeout = (int) $directory; $directory = FALSE; } if( $directory ) $this->setConfig( 'directory', $directory ); if( $filename ) $this->setConfig( 'filename', $filename ); if( $delimiter && ( $delimiter != DIRECTORY_SEPARATOR )) $this->setConfig( 'delimiter', $delimiter ); $filesize = $this->getConfig( 'filesize' ); if( 0 >= $filesize ) return FALSE; $dirfile = $this->getConfig( 'dirfile' ); if( time() - filemtime( $dirfile ) < $timeout) { clearstatcache(); $dirfile = $this->getConfig( 'dirfile' ); $filename = $this->getConfig( 'filename' );// if( headers_sent( $filename, $linenum ))// die( "Headers already sent in $filename on line $linenum\n" ); if( 'xcal' == $this->format ) header( 'Content-Type: application/calendar+xml; charset=utf-8' ); else header( 'Content-Type: text/calendar; charset=utf-8' ); header( 'Content-Length: '.$filesize ); header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); header( 'Cache-Control: max-age=10' ); $fp = @$fopen( $dirfile, 'r' ); if( $fp ) { fpassthru( $fp ); fclose( $fp ); } die(); } else return FALSE; }}/*********************************************************************************//*********************************************************************************//** * abstract class for calendar components * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.3.1 - 2007-11-19 */class calendarComponent { // component property variables var $uid; var $dtstamp; var $action; var $attach; var $attendee; var $categories; var $comment; var $completed; var $contact; var $class; var $created; var $description; var $dtend; var $dtstart; var $due; var $duration; var $exdate; var $exrule; var $freebusy; var $geo; var $lastmodified; var $location; var $organizer; var $percentcomplete; var $priority; var $rdate; var $recurrenceid; var $relatedto; var $repeat; var $requeststatus; var $resources; var $rrule; var $sequence; var $status; var $summary; var $transp; var $trigger; var $tzid; var $tzname; var $tzoffsetfrom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -