📄 icalcreator.class.php
字号:
$component2->setProperty( 'x-current-dtend', $datestring ); else $component2->setProperty( 'x-current-due', $datestring ); } $rend = $component2->_date2timestamp( $rend ); $rstart = $recurkey; /* add repeating components within valid dates to output array, only start date */ if( $flat ) $result[] = $component2; // copy to output elseif( $split ) { if( $rend > $endDate ) $rend = $endDate; while( $rstart <= $rend ) { // iterate $wd = getdate( $rstart );// if(( $rstart >= $startDate ) && // date within period if(( $rstart > $startDate ) && // date after dtstart !isset( $exdatelist[$rstart] )) // check exclude date $result[$wd['year']][$wd['mon']][$wd['mday']][] = $component2->copy(); // copy to output $rstart += ( 24*60*60 ); // step one day } } elseif(( $rstart >= $startDate ) && // date within period !isset( $exdatelist[$rstart] )) { // check exclude date $wd = getdate( $rstart ); $result[$wd['year']][$wd['mon']][$wd['mday']][] = $component2->copy(); // copy to output } } } /* deselect components with startdate/enddate not within period */ if(( $endWdate < $startDate ) || ( $startWdate > $endDate )) continue; } /* deselect components with startdate not within period */ elseif(( $startWdate < $startDate ) || ( $startWdate > $endDate )) continue; /* add selected components within valid dates to output array */ if( $flat ) { $result[] = $component->copy(); // copy to output; } elseif( $split ) { if( $endWdate > $endDate ) $endWdate = $endDate; // use period end date if( !isset( $exdatelist[$startWdate] )) { // check excluded dates if( $startWdate < $startDate ) $startWdate = $startDate; // use period start date while( $startWdate <= $endWdate ) { // iterate $wd = getdate( $startWdate ); $result[$wd['year']][$wd['mon']][$wd['mday']][] = $component->copy(); // copy to output $startWdate += ( 24*60*60 ); // step one day } } } // use component date elseif( !isset( $exdatelist[$startWdate] ) && // check excluded dates ( $startWdate >= $startDate )) { // within period $wd = getdate( $startWdate ); $result[$wd['year']][$wd['mon']][$wd['mday']][] = $component->copy(); // copy to output } } if( 0 >= count( $result )) return FALSE; elseif( !$flat ) { foreach( $result as $y => $yeararr ) { foreach( $yeararr as $m => $montharr ) { ksort( $result[$y][$m] ); } ksort( $result[$y] ); } ksort( $result ); } return $result; }/** * add calendar component to container * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.16 - 2007-11-11 * @param object $component calendar component * @param mixed $arg1 optional, ordno/component type/ component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return void */ function setComponent( $component, $arg1=FALSE, $arg2=FALSE ) { 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' )); if( !in_array( $component->objName, array( 'valarm', 'vtimezone' ))) { unset( $component->propix ); /* make sure dtstamp and uid is set */ $dummy = $component->getProperty( 'dtstamp' ); $dummy = $component->getProperty( 'uid' ); } if( !$arg1 ) { $this->components[] = $component->copy(); return TRUE; } $argType = $index = null; if ( ctype_digit( (string) $arg1 )) { $argType = 'INDEX'; $index = (int) $arg1 - 1; } elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) { $argType = strtolower( $arg1 ); $index = ( ctype_digit( (string) $arg2 )) ? ((int) $arg2) - 1 : 0; } $cix1sC = 0; foreach ( $this->components as $cix => $component2) { unset( $component2->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) { $this->components[$cix] = $component->copy(); return TRUE; } elseif( $argType == $component2->objName ) { if( $index == $cix1sC ) { $this->components[$cix] = $component->copy(); return TRUE; } $cix1sC++; } elseif( !$argType && ( $arg1 == $component2->getProperty( 'uid' ))) { $this->components[$cix] = $component->copy(); return TRUE; } } /* not found.. . insert last in chain anyway .. .*/ $this->components[] = $component->copy(); }/** * sort iCal compoments, only local date sort * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.9 - 2007-10-02 * @return sort param * */ function _cmpfcn( $a, $b ) { if( 'vtimezone' == $a->objName) return -1; if( 'vtimezone' == $b->objName) return 1; if( isset( $a->dtstart['value'] ) || isset( $b->dtstart['value'] )) { foreach( $this->_sortkeys as $key ) { if( !isset( $a->dtstart['value'][$key] )) return -1; elseif( !isset( $b->dtstart['value'][$key] )) return 1; if ( $a->dtstart['value'][$key] == $b->dtstart['value'][$key] ) continue; if (( (int) $a->dtstart['value'][$key] ) < ( (int) $b->dtstart['value'][$key] )) return -1; elseif(( (int) $a->dtstart['value'][$key] ) > ( (int) $b->dtstart['value'][$key] )) return 1; } } if( isset( $a->dtend['value'] )) $c = $a->dtend['value']; if( empty( $c ) && !empty( $a->due['value'] )) $c = $a->due['value']; if( empty( $c ) && !empty( $a->duration['value'] )) $c = $a->duration2date(); if( isset( $b->dtend['value'] )) $d = $b->dtend['value']; if( empty( $d ) && !empty( $b->due['value'] )) $d = $b->due['value']; if( empty( $d ) && !empty( $b->duration['value'] )) $d = $b->duration2date(); if( isset( $c ) || isset( $d )) { if( !isset( $c ) && isset( $d )) return -1; if( isset( $c ) && !isset( $d )) return 1; foreach( $this->_sortkeys as $key ) { if ( !isset( $c[$key] )) return -1; elseif( !isset( $d[$key] )) return 1; if ( $c[$key] == $d[$key] ) continue; if (( (int) $c[$key] ) < ( (int) $d[$key] )) return -1; elseif(( (int) $c[$key] ) > ( (int) $d[$key] )) return 1; } } $c = ( isset( $a->created['value'] )) ? $a->created['value'] : $a->dtstamp['value']; $d = ( isset( $b->created['value'] )) ? $b->created['value'] : $b->dtstamp['value']; foreach( $this->_sortkeys as $key ) { if( !isset( $a->created['value'][$key] )) return -1; elseif( !isset( $b->created['value'][$key] )) return 1; if ( $a->created['value'][$key] == $b->created['value'][$key] ) continue; if (( (int) $a->created['value'][$key] ) < ( (int) $b->created['value'][$key] )) return -1; elseif(( (int) $a->created['value'][$key] ) > ( (int) $b->created['value'][$key] )) return 1; } if (( $a->uid['value'] ) < ( $b->uid['value'] )) return -1; elseif(( $a->uid['value'] ) > ( $b->uid['value'] )) return 1; return 0; } function sort() { if( is_array( $this->components )) { $this->_sortkeys = array( 'year', 'month', 'day', 'hour', 'min', 'sec' ); usort( $this->components, array( $this, '_cmpfcn' )); } }/** * parse iCal file into vcalendar, components, properties and parameters * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.4.3 - 2008-02-13 * @param string $filename optional filname (incl. opt. directory/path) or URL * @return bool FALSE if error occurs during parsing * */ function parse( $filename=FALSE ) { if( !$filename ) { /* directory/filename previous set via setConfig directory+filename / url */ if( FALSE === ( $filename = $this->getConfig( 'url' ))) $filename = $this->getConfig( 'dirfile' ); } elseif(( 'http://' == strtolower( substr( $filename, 0, 7 ))) || ( 'webcal://' == strtolower( substr( $filename, 0, 9 )))) { /* remote file - URL */ $this->setConfig( 'URL', $filename ); if( !$filename = $this->getConfig( 'url' )) return FALSE; /* err 2 */ } else { /* local directory/filename */ $parts = pathinfo( $filename ); if( !empty( $parts['dirname'] ) && ( '.' != $parts['dirname'] )) { if( !$this->setConfig( 'directory', $parts['dirname'] )) return FALSE; /* err 3 */ } if( !$this->setConfig( 'filename', $parts['basename'] )) return FALSE; /* err 4 */ } if( 'http://' != substr( $filename, 0, 7 )) { /* local file error tests */ if( !is_file( $filename )) /* err 5 */ return FALSE; if( !is_readable( $filename )) return FALSE; /* err 6 */ if( !filesize( $filename )) return FALSE; /* err 7 */ clearstatcache(); } /* READ FILE */ if( FALSE === ( $rows = file( $filename ))) return FALSE; /* err 1 */ /* identify BEGIN:VCALENDAR, MUST be first row */ if( 'BEGIN:VCALENDAR' != strtoupper( trim( $rows[0] ))) return FALSE; /* err 8 */ /* remove empty trailing lines */ while( '' == trim( $rows[count( $rows ) - 1] )) { unset( $rows[count( $rows ) - 1] ); $rows = array_values( $rows ); } /* identify ending END:VCALENDAR row */ if( 'END:VCALENDAR' != strtoupper( trim( $rows[count( $rows ) - 1] ))) { return FALSE; /* err 9 */ } if( 3 > count( $rows )) return FALSE; /* err 10 */ $comp = $subcomp = null; $actcomp = & $this; $nl = $this->getConfig( 'nl' ); $calsync = 0; /* identify components and update unparsed data within component */ foreach( $rows as $line ) { if( '' == trim( $line )) continue; if( $nl == substr( $line, 0 - strlen( $nl ))) $line = substr( $line, 0, ( strlen( $line ) - strlen( $nl ))).'\n'; if( 'BEGIN:VCALENDAR' == strtoupper( substr( $line, 0, 15 ))) { $calsync++; continue; } elseif( 'END:VCALENDAR' == strtoupper( substr( $line, 0, 13 ))) { $calsync--; continue; } elseif( 1 != $calsync ) return FALSE; /* err 20 */ if( 'END:' == strtoupper( substr( $line, 0, 4 ))) { if( null != $subcomp ) { $comp->setComponent( $subcomp ); $subcomp = null; } else { $this->setComponent( $comp ); $comp = null; } $actcomp = null; continue; } // end - if ( 'END:' ==.. . elseif( 'BEGIN:' == strtoupper( substr( $line, 0, 6 ))) { $line = str_replace( '\n', '', $line ); $compname = trim (strtoupper( substr( $line, 6 ))); if( null != $comp ) { if( 'VALARM' == $compname ) $subcomp = new valarm(); elseif( 'STANDARD' == $compname ) $subcomp = new vtimezone( 'STANDARD' ); elseif( 'DAYLIGHT' == $compname ) $subcomp = new vtimezone( 'DAYLIGHT' ); else return FALSE; /* err 6 */ $actcomp = & $subcomp; } else { switch( $compname ) { case 'VALARM': $comp = new valarm(); break; case 'VEVENT': $comp = new vevent(); break; case 'VFREEBUSY'; $comp = new vfreebusy(); break; case 'VJOURNAL': $comp = new vjournal(); break; case 'VTODO': $comp = new vtodo(); break; case 'VTIMEZONE': $comp = new vtimezone(); break; default: return FALSE; // err 7 break; } // end - switch $actcomp = & $comp; } continue; } // end - elsif ( 'BEGIN:'.. . /* update selected component with unparsed data */ $actcomp->unparsed[] = $line; } // end - foreach( rows.. . /* parse data for calendar (this) object */ if( is_array( $this->unparsed ) && ( 0 < count( $this->unparsed ))) { /* concatenate property values spread over several lines */ $lastix = -1; $propnames = array( 'calscale','method','prodid','version','x-' ); $proprows = array(); foreach( $this->unparsed as $line ) { $newProp = FALSE; foreach ( $propnames as $propname ) { if( $propname == strtolower( substr( $line, 0, strlen( $propname )))) { $newProp = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -