⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icalcreator.class.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
      $input['year']   = $year;      $input['month']  = $month;      $input['day']    = $day;      if(( $hour !== FALSE ) || ( $min !== FALSE ) || ( $sec !== FALSE )) {        $parno = 6;        if( $hour !== FALSE )          $input['hour'] = $hour;        if( $min !== FALSE )          $input['min']  = $min;        if( $sec !== FALSE )          $input['sec']  = $sec;      }      if( $tz !== FALSE ) {        $parno = 7;        $input['tz']  = $tz;      }      elseif( !$parno )        $parno = 3;      $input = $toolbox->_date_time_array( $input, $parno );    }    else      return FALSE;    if( !checkdate ( $input['month'], $input['day'], $input['year'] ))      return FALSE;    if( isset( $input['hour'] ) &&        (( 0 > $input['hour'] ) || ( 23 < $input['hour'] )))      return FALSE;    if( isset( $input['min'] ) &&        (( 0 > $input['min'] ) || ( 59 < $input['min'] )))      return FALSE;    if( isset( $input['sec'] ) &&        (( 0 > $input['sec'] ) || ( 59 < $input['sec'] )))      return FALSE;    if( isset( $input['tz'] ) && ( '' < trim ( $input['tz'] ))) {      $input['tz'] = (string) trim( $input['tz'] );      if( ctype_digit( $input['tz']{1} )) { // only numeric tz=offset        $offset = 0;        if( ctype_digit( $input['tz']{0} ))          $input['tz'] = '+'.$input['tz'];        $offset = $toolbox->_tz2offset( $input['tz'] );        if( 0 != $offset) {          if( !isset( $input['hour'] ))            $input['hour'] = 0;          if( !isset( $input['min'] ))            $input['min'] = 0;          if( !isset( $input['sec'] ))            $input['sec'] = 0;          $input = date('Y-m-d H:i:s\Z', mktime( $input['hour']                                                , $input['min']                                                , $input['sec'] + $offset                                                , $input['month']                                                , $input['day']                                                , $input['year']));          $parno = ( $utc ) ? 7 : 6 ;          $input = $toolbox->_date_time_string( $input, $parno );          if( !$utc && isset( $input['tz'] ) && ( 'Z' == $input['tz'] ))            unset( $input['tz'] );        }      }    }    return $input;  }/*********************************************************************************//** * add calendar component to container * * alias to setComponent * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 1.x.x - 2007-04-24 * @param object $component calendar component * @return void */  function addComponent( $component ) {    $this->setComponent( $component );  }/** * delete calendar component from container * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.0.4 - 2007-06-14 * @param mixed $arg1 ordno / component type / component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return void */  function deleteComponent( $arg1, $arg2=FALSE  ) {    $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   = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 1;    }    $cix1dC = 0;    foreach ( $this->components as $cix => $component) {      unset( $component->propix );      if(( 'INDEX' == $argType ) && ( $index == $cix )) {        unset( $this->components[$cix] );        return TRUE;      }      elseif( $argType == $component->objName ) {        if( $index == $cix1dC ) {          unset( $this->components[$cix] );          return TRUE;        }        $cix1dC++;      }      elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {        unset( $this->components[$cix] );        return TRUE;      }    }    return FALSE;  }/** * get calendar component from container * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.2.16 - 2007-11-11 * @param mixed $arg1 optional, ordno/component type/ component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return object */  function getComponent( $arg1=FALSE, $arg2=FALSE ) {    $index = $argType = null;    if ( !$arg1 ) {      $argType = 'INDEX';      $index   = $this->compix['INDEX'] =        ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;    }    elseif ( ctype_digit( (string) $arg1 )) {      $argType = 'INDEX';      $index   = (int) $arg1;      unset( $this->compix );    }    elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {      unset( $this->compix['INDEX'] );      $argType = strtolower( $arg1 );      if( !$arg2 )        $index = $this->compix[$argType] =        ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;      else        $index = (int) $arg2;    }    $index  -= 1;    $ckeys =  array_keys( $this->components );    if( !empty( $index) && ( $index > end(  $ckeys )))      return FALSE;    $cix1gC = 0;    foreach ( $this->components as $cix => $component) {      unset( $component->propix );      if(( 'INDEX' == $argType ) && ( $index == $cix ))        return $component->copy();      elseif( $argType == $component->objName ) {         if( $index == $cix1gC )           return $component->copy();         $cix1gC++;      }      elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {        unset( $component->propix );        return $component->copy();      }    }            /* not found.. . */    unset( $this->compix );    return false;  }/** * select components from calendar on date basis * * Ensure DTSTART is set for every component. * No date controls occurs. * * @author Kjell-Inge Gustafsson <ical@kigkonsult.se> * @since 2.4.1 - 2008-02-05 * @param int $startY optional,  start Year, default current Year * @param int $startM optional,  start Month, default current Month * @param int $startD optional,  start Day, default current Day * @param int $endY optional,    end Year, default $startY * @param int $endY optional,    end Month, default $startM * @param int $endY optional,    end Day, default $startD * @param mixed $cType optional, calendar component type(-s), default FALSE=all else string/array type(-s) * @param bool $flat optional,   FALSE (default) => output : array[Year][Month][Day][] *                               TRUE => output : array[] (ignores split) * @param bool $any optional,    TRUE (default) - select component that take place within period *                               FALSE - only components that starts within period * @param bool $split optional,  TRUE (default) - one component copy every day it take place during the *                                       period (implies flat=FALSE) *                               FALSE - one occurance of component only in output array</tr> * @return array or FALSE */  function selectComponents( $startY=FALSE, $startM=FALSE, $startD=FALSE, $endY=FALSE, $endM=FALSE, $endD=FALSE, $cType=FALSE, $flat=FALSE, $any=TRUE, $split=TRUE ) {            /* check  if empty calendar */    if( 0 >= count( $this->components ))      return FALSE;            /* check default dates */    if( !$startY ) $startY = date( 'Y' );    if( !$startM ) $startM = date( 'm' );    if( !$startD ) $startD = date( 'd' );    $startDate = mktime( 0, 0, 0, $startM, $startD, $startY );    if( !$endY )   $endY   = $startY;    if( !$endM )   $endM   = $startM;    if( !$endD )   $endD   = $startD;    $endDate   = mktime( 23, 59, 59, $endM, $endD, $endY );            /* check component types */    $validTypes = array('vevent', 'vtodo', 'vjournal', 'vfreebusy' );    if( is_array( $cType )) {      foreach( $cType as $cix => $theType ) {        $cType[$cix] = $theType = strtolower( $theType );        if( !in_array( $theType, $validTypes ))          $cType[$cix] = 'vevent';      }      $cType = array_unique( $cType );    }    elseif( !empty( $cType )) {      $cType = strtolower( $cType );      if( !in_array( $cType, $validTypes ))        $cType = array( 'vevent' );      else        $cType = array( $cType );    }    else      $cType = $validTypes;    if( 0 >= count( $cType ))      $cType = $validTypes;            /* iterate components */    $result = array();    foreach ( $this->components as $cix => $component ) {      unset( $component->propix, $start );            /* deselect unvalid type components */      if( !in_array( $component->objName, $cType ))        continue;            /* deselect components without dtstart set */      if( FALSE === ( $start = $component->getProperty( 'dtstart' )))        continue;      $dtendExist = $dueExist = FALSE;      unset( $end, $startWdate, $endWdate, $rdurWsecs, $rdur, $exdatelist, $workstart, $workend ); // clean up      $startWdate = $component->_date2timestamp( $start );            /* get end date from dtend/due/duration properties */      $end = $component->getProperty( 'dtend' );      if( !empty( $end ))        $dtendExist = TRUE;      //if( !empty($end))  echo 'selectComponents 1 start='.implode('-',$start).' end='.implode('-',$end)."<br />\n"; // test ###      if( empty($end) && ( $component->objName == 'vtodo' )) {        $end = $component->getProperty( 'due' );        if( !empty( $end ))          $dueExist = TRUE;        //if( !empty($end))  echo 'selectComponents 2 start='.implode('-',$start).' end='.implode('-',$end)."<br />\n"; // test ###      }      elseif( !empty($end) && !isset( $end['hour'] )) {          /* a DTEND without time part regards an event that ends the day before,             for an all-day event DTSTART=20071201 DTEND=20071202 (taking place 20071201!!! */        $end = array( 'year' => $end['year'], 'month' => $end['month'], 'day' => ($end['day'] - 1), 'hour' => 23, 'min' => 59, 'sec' => 59 );        //if( !empty($end))  echo 'selectComponents 3 start='.implode('-',$start).' end='.implode('-',$end)."<br />\n"; // test ###      }      if( empty( $end )) {        $end = $component->getProperty( 'duration', FALSE, FALSE, TRUE );// in dtend (array) format        //if( !empty($end))  echo 'selectComponents 4 start='.implode('-',$start).' end='.implode('-',$end)."<br />\n"; // test ###      }      if( empty( $end )) { // assume one day duration if missing end date        $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );        //if( isset($end))  echo 'selectComponents 5 start='.implode('-',$start).' end='.implode('-',$end)."<br />\n"; // test ###      }      $endWdate = $component->_date2timestamp( $end );      if( $endWdate < $startWdate ) { // MUST be after start date!!        $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );        $endWdate = $component->_date2timestamp( $end );      }      $rdurWsecs  = $endWdate - $startWdate; // compute component duration in seconds      $rdur       = $component->_date2duration( $start, $end ); // compute component duration, array            /* make a list of optional exclude dates for component occurence, exrule, exdate */      $exdatelist = array();      $workstart  = $component->_date_time_string( date('Y-m-d H:i:s', ( $startDate - $rdurWsecs )), 6);      $workend    = $component->_date_time_string( date('Y-m-d H:i:s', ( $endDate + $rdurWsecs )), 6);      while( FALSE !== ( $exrule = $component->getProperty( 'exrule' )))        $component->_recur2date( $exdatelist, $exrule, $start, $workstart, $workend );      while( FALSE !== ( $exdate = $component->getProperty( 'exdate' ))) {        foreach( $exdate as $theExdate ) {          $exWdate = $component->_date2timestamp( $theExdate );          if((( $startDate - $rdurWsecs ) <= $exWdate ) && ( $endDate >= $exWdate ))            $exdatelist[$exWdate] = TRUE;        }      }            /* if 'any' components, check repeating components, removing all excluding dates */      if( TRUE === $any ) {            /* make a list of optional repeating dates for component occurence, rrule, rdate */        $recurlist = array();        while( FALSE !== ( $rrule = $component->getProperty( 'rrule' )))    // check rrule          $component->_recur2date( $recurlist, $rrule, $start, $workstart, $workend );        foreach( $recurlist as $recurkey => $recurvalue ) // key=match date as timestamp          $recurlist[$recurkey] = $rdurWsecs; // add duration in seconds        while( FALSE !== ( $rdate = $component->getProperty( 'rdate' ))) {  // check rdate          foreach( $rdate as $theRdate ) {            if( is_array( $theRdate ) && ( 2 == count( $theRdate )) &&  // PERIOD                   array_key_exists( '0', $theRdate ) &&  array_key_exists( '1', $theRdate )) {              $rstart = $component->_date2timestamp( $theRdate[0] );              if(( $rstart < ( $startDate - $rdurWsecs )) || ( $rstart > $endDate ))                continue;              if( isset( $theRdate[1]['year'] )) // date-date period                $rend = $component->_date2timestamp( $theRdate[1] );              else {                             // date-duration period                $rend = $component->duration2date( $theRdate[0], $theRdate[1] );                $rend = $component->_date2timestamp( $rend );              }              if((( $startDate - $rdurWsecs ) <= $rstart ) && ( $endDate >= $rstart ))                $recurlist[$rstart] = ( $rstart - $rend ); // set start date + rdate duration in seconds            }            else { // single date              $theRdate = $component->_date2timestamp( $theRdate );              if((( $startDate - $rdurWsecs ) <= $theRdate ) && ( $endDate >= $theRdate ))                $recurlist[$theRdate] = $rdurWsecs; // set start date + event duration in seconds            }          }        }        if( 0 < count( $recurlist )) {          ksort( $recurlist );          foreach( $recurlist as $recurkey => $durvalue ) {            if((( $startDate - $rdurWsecs ) > $recurkey ) || ( $endDate < $recurkey )) // not within period              continue;            if( isset( $exdatelist[$recurkey] )) // check excluded dates              continue;            if( $startWdate >= $recurkey ) // exclude component start date              continue;            $component2 = $component->copy();            $rstart     = $component2->_date_time_string( date('Y-m-d H:i:s', $recurkey ), 6);            $datevalue  = $rstart['month'].'/'.$rstart['day'].'/'.$rstart['year'];            $dateformat = 'Y-m-d';            if( isset( $start['hour'] ) || isset( $start['min'] ) || isset( $start['sec'] )) {              $datevalue  .= ( isset( $rstart['hour'] )) ? ' '.$rstart['hour'] : ' 00';              $datevalue  .= ( isset( $rstart['min'] ))  ? ':'.$rstart['min']  : ':00';              $datevalue  .= ( isset( $rstart['sec'] ))  ? ':'.$rstart['sec']  : ':00';              $dateformat .= ' H:i:s';            }            $datestring = date( $dateformat, strtotime( $datevalue ));            if( isset( $start['tz'] ))              $datestring .= ' '.$start['tz'];            $component2->setProperty( 'x-current-dtstart', $datestring );            $rend   = $component2->_date_time_string( date('Y-m-d H:i:s', ( $recurkey + $durvalue )), 6);            if( isset( $datevalue ) && ( $dtendExist || $dueExist )) {              $datevalue  = $rend['month'].'/'.$rend['day'].'/'.$rend['year'];              $dateformat = 'Y-m-d';              if( isset( $end['hour'] ) || isset( $end['min'] ) || isset( $end['sec'] )) {                $datevalue  .= ( isset( $rend['hour'] )) ? ' '.$rend['hour'] : ' 00';                $datevalue  .= ( isset( $rend['min'] ))  ? ':'.$rend['min']  : ':00';                $datevalue  .= ( isset( $rend['sec'] ))  ? ':'.$rend['sec']  : ':00';                $dateformat .= ' H:i:s';              }              $datestring = date( $dateformat, strtotime( $datevalue ));              if( isset( $end['tz'] ))                $datestring .= ' '.$end['tz'];              if( $dtendExist )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -