From ed9ea6faccc8ff525609e33ac6c18f5133db5912 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 6 May 2010 19:05:32 +0200 Subject: [PATCH] Updating icalcreator to the last version 2.6 --- .../inc/lib/icalcreator/iCalcreator.class.php | 4055 +++++++++-------- 1 file changed, 2073 insertions(+), 1982 deletions(-) mode change 100644 => 100755 main/inc/lib/icalcreator/iCalcreator.class.php diff --git a/main/inc/lib/icalcreator/iCalcreator.class.php b/main/inc/lib/icalcreator/iCalcreator.class.php old mode 100644 new mode 100755 index 29deb95fef..361bf58bc0 --- a/main/inc/lib/icalcreator/iCalcreator.class.php +++ b/main/inc/lib/icalcreator/iCalcreator.class.php @@ -1,7 +1,7 @@ = '5' ) // && ( 'UTC' == date_default_timezone_get() )) { date_default_timezone_set( 'Europe/Stockholm' ); /* version string, do NOT remove!! */ -define( 'ICALCREATOR_VERSION', 'iCalcreator 2.4.3' ); +define( 'ICALCREATOR_VERSION', 'iCalcreator 2.6' ); /*********************************************************************************/ /*********************************************************************************/ /** @@ -117,12 +117,11 @@ class vcalendar { * creates formatted output for calendar property calscale * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createCalscale() { - if( !isset( $this->calscale )) - return; + if( empty( $this->calscale )) return FALSE; switch( $this->format ) { case 'xcal': return ' calscale="'.$this->calscale.'"'.$this->nl; @@ -136,11 +135,12 @@ class vcalendar { * set calendar property calscale * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-13 + * @since 2.4.8 - 2008-10-21 * @param string $value * @return void */ function setCalscale( $value ) { + if( empty( $value )) return FALSE; $this->calscale = $value; } /*********************************************************************************/ @@ -155,8 +155,7 @@ class vcalendar { * @return string */ function createMethod() { - if( !isset( $this->method )) - return; + if( empty( $this->method )) return FALSE; switch( $this->format ) { case 'xcal': return ' method="'.$this->method.'"'.$this->nl; @@ -170,12 +169,14 @@ class vcalendar { * set calendar property method * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-13 - * @param string $method - * @return void + * @since 2.4.8 - 2008-20-23 + * @param string $value + * @return bool */ - function setMethod( $method ) { - $this->method = $method; + function setMethod( $value ) { + if( empty( $value )) return FALSE; + $this->method = $value; + return TRUE; } /*********************************************************************************/ /** @@ -226,10 +227,9 @@ class vcalendar { * @author Kjell-Inge Gustafsson * @since 0.3.0 - 2006-08-10 * @return void - */ function _makeUnique_id() { - $this->unique_id = gethostbyname( $_SERVER['SERVER_NAME'] ); + $this->unique_id = ( isset( $_SERVER['SERVER_NAME'] )) ? gethostbyname( $_SERVER['SERVER_NAME'] ) : 'localhost'; } /*********************************************************************************/ /** @@ -246,7 +246,7 @@ class vcalendar { * @return string */ function createVersion() { - if( !isset( $this->version )) + if( empty( $this->version )) $this->_makeVersion(); switch( $this->format ) { case 'xcal': @@ -271,12 +271,14 @@ class vcalendar { * set calendar version * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 - * @param string version + * @since 2.4.8 - 2008-10-23 + * @param string $value * @return void */ - function setVersion( $version ) { - $this->version = $version; + function setVersion( $value ) { + if( empty( $value )) return FALSE; + $this->version = $value; + return TRUE; } /*********************************************************************************/ /** @@ -286,7 +288,7 @@ class vcalendar { * creates formatted output for calendar property x-prop, iCal format only * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.11 - 2008-11-03 * @return string */ function createXprop() { @@ -294,12 +296,16 @@ class vcalendar { return false; if( 0 >= count( $this->xprop )) return; - $xprop = null; + $output = null; $toolbox = new calendarComponent(); $toolbox->setConfig( 'language', $this->getConfig( 'language' )); $toolbox->setConfig( 'nl', $this->getConfig( 'nl' )); $toolbox->_createFormat( $this->getConfig( 'format' )); foreach( $this->xprop as $label => $xpropPart ) { + if( empty( $xpropPart['value'] )) { + $output .= $toolbox->_createElement( $label ); + continue; + } $attributes = $toolbox->_createParams( $xpropPart['params'], array( 'LANGUAGE' )); if( is_array( $xpropPart['value'] )) { foreach( $xpropPart['value'] as $pix => $theXpart ) @@ -308,35 +314,37 @@ class vcalendar { } else $xpropPart['value'] = $toolbox->_strrep( $xpropPart['value'] ); - $xprop .= $toolbox->_createElement( strtoupper( $label ), $attributes, $xpropPart['value'] ); + $output .= $toolbox->_createElement( $label, $attributes, $xpropPart['value'] ); } - return $xprop; + return $output; } /** * set calendar property x-prop * * @author Kjell-Inge Gustafsson - * @since 2.0.7 - 2007-06-21 + * @since 2.4.11 - 2008-11-04 * @param string $label * @param string $value * @param array $params optional - * @return void + * @return bool */ function setXprop( $label, $value, $params=FALSE ) { - if( empty( $label ) || empty( $value )) - return; - $xprop = array( 'value' => $value ); - $toolbox = new calendarComponent(); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + if( empty( $label )) return FALSE; + $xprop = array( 'value' => $value ); + $toolbox = new calendarComponent(); $xprop['params'] = $toolbox->_setParams( $params ); - $this->xprop[$label] = $xprop; + if( !is_array( $this->xprop )) $this->xprop = array(); + $this->xprop[strtoupper( $label )] = $xprop; + return TRUE; } /*********************************************************************************/ /** * delete calendar property value * * @author Kjell-Inge Gustafsson - * @since 2.2.15 - 2007-10-29 - * @param string $propName + * @since 2.4.5 - 2008-11-14 + * @param mixed $propName, bool FALSE => X-property * @param int @propix, optional, if specific property is wanted in case of multiply occurences * @return bool, if successfull delete */ @@ -348,32 +356,37 @@ class vcalendar { $return = FALSE; switch( $propName ) { case 'CALSCALE': - $this->calscale = null; - $return = TRUE; + if( isset( $this->calscale )) { + $this->calscale = null; + $return = TRUE; + } break; case 'METHOD': - $this->method = null; - $return = TRUE; + if( isset( $this->method )) { + $this->method = null; + $return = TRUE; + } break; default: + $reduced = array(); if( $propName != 'X-PROP' ) { if( !isset( $this->xprop[$propName] )) return FALSE; - unset( $this->xprop[$propName] ); - $return = TRUE; + foreach( $this->xprop as $k => $a ) { + if(( $k != $propName ) && !empty( $a )) + $reduced[$k] = $a; + } } else { if( count( $this->xprop ) <= $propix ) return FALSE; $xpropno = 0; foreach( $this->xprop as $xpropkey => $xpropvalue ) { - if( $propix == $xpropno ) { - unset( $this->xprop[$xpropkey] ); - $return = TRUE; - break 2; - } - else - $xpropno++; + if( $propix != $xpropno ) + $reduced[$xpropkey] = $xpropvalue; + $xpropno++; } } + $this->xprop = $reduced; + return TRUE; } return $return; } @@ -381,7 +394,7 @@ class vcalendar { * get calendar property value/params * * @author Kjell-Inge Gustafsson - * @since 2.0.8 - 2007-07-07 + * @since 2.5.1 - 2008-11-02 * @param string $propName, optional * @param int @propix, optional, if specific property is wanted in case of multiply occurences * @param bool $inclParam=FALSE @@ -389,26 +402,24 @@ class vcalendar { */ function getProperty( $propName=FALSE, $propix=FALSE, $inclParam=FALSE ) { $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP'; - if( !$propix ) - $propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1; - $this->propix[$propName] = --$propix; + if( 'X-PROP' == $propName ) { + if( !$propix ) + $propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1; + $this->propix[$propName] = --$propix; + } switch( $propName ) { case 'CALSCALE': - if( 0 < $propix ) return FALSE; return ( !empty( $this->calscale )) ? $this->calscale : null; break; case 'METHOD': - if( 0 < $propix ) return FALSE; return ( !empty( $this->method )) ? $this->method : null; break; case 'PRODID': - if( 0 < $propix ) return FALSE; if( empty( $this->prodid )) $this->_makeProdid(); return $this->prodid; break; case 'VERSION': - if( 0 < $propix ) return FALSE; return ( !empty( $this->version )) ? $this->version : null; break; default: @@ -418,7 +429,7 @@ class vcalendar { : array( $propName, $this->xprop[$propName]['value'] ); } else { - if( count( $this->xprop ) <= $propix ) return FALSE; + if( empty( $this->xprop )) return FALSE; $xpropno = 0; foreach( $this->xprop as $xpropkey => $xpropvalue ) { if( $propix == $xpropno ) @@ -436,45 +447,38 @@ class vcalendar { * general vcalendar property setting * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-23 + * @since 2.2.13 - 2007-11-04 * @param mixed $args variable number of function arguments, * first argument is ALWAYS component name, * second ALWAYS component value! - * @return void + * @return bool */ function setProperty () { $numargs = func_num_args(); - if( 1 >= $numargs ) + if( 1 > $numargs ) return FALSE; $arglist = func_get_args(); - if( !$this->getConfig( 'allowEmpty' ) && ( !isset( $arglist[1] ) || empty( $arglist[1] ))) - return; $arglist[0] = strtoupper( $arglist[0] ); - for( $argix=$numargs; $argix < 3; $argix++ ) { - if( !isset( $arglist[$argix] )) - $arglist[$argix] = null; - } switch( $arglist[0] ) { case 'CALSCALE': - $this->setCalscale( $arglist[1] ); - break; + return $this->setCalscale( $arglist[1] ); case 'METHOD': - $this->setMethod( $arglist[1] ); - break; + return $this->setMethod( $arglist[1] ); case 'VERSION': - $this->setVersion( $arglist[1] ); - break; + return $this->setVersion( $arglist[1] ); default: - $this->setXprop( $arglist[0], $arglist[1], $arglist[2] ); - break; + if( !isset( $arglist[1] )) $arglist[1] = null; + if( !isset( $arglist[2] )) $arglist[2] = null; + return $this->setXprop( $arglist[0], $arglist[1], $arglist[2] ); } + return FALSE; } /*********************************************************************************/ /** * get vcalendar config values or * calendar components * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-12-30 + * @since 2.4.10 - 2008-10-23 * @param string $config * @return value */ @@ -487,6 +491,7 @@ class vcalendar { unset( $this->compix ); $info = array(); foreach( $this->components as $cix => $component ) { + if( empty( $component )) continue; unset( $component->propix ); $info[$cix]['ordno'] = $cix + 1; $info[$cix]['type'] = $component->objName; @@ -558,18 +563,22 @@ class vcalendar { * general vcalendar config setting * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-12-30 + * @since 2.4.8 - 2008-10-24 * @param string $config * @param string $value * @return void */ function setConfig( $config, $value ) { + $res = FALSE; switch( strtoupper( $config )) { case 'ALLOWEMPTY': $this->allowEmpty = $value; + $subcfg = array( 'ALLOWEMPTY' => $value ); + $res = TRUE; break; case 'DELIMITER': $this->delimiter = $value; + return TRUE; break; case 'DIRECTORY': $value = trim( $value ); @@ -624,19 +633,27 @@ class vcalendar { $this->attributeDelimiter = ';'; $this->valueInit = ':'; } + $subcfg = array( 'FORMAT' => $value ); + $res = TRUE; break; case 'LANGUAGE': // set language for calendar component as defined in [RFC 1766] $value = trim( $value ); $this->language = $value; + $subcfg = array( 'LANGUAGE' => $value ); + $res = TRUE; break; case 'NL': case 'NEWLINECHAR': $this->nl = $value; + $subcfg = array( 'NL' => $value ); + $res = TRUE; break; case 'UNIQUE_ID': $value = trim( $value ); $this->unique_id = $value; + $subcfg = array( 'UNIQUE_ID' => $value ); + $res = TRUE; break; case 'URL': /* remote file - URL */ @@ -650,121 +667,18 @@ class vcalendar { return $this->setConfig( 'filename', $parts['basename'] ); break; } - } -/*********************************************************************************/ -/** - * validDate - * - * convert input parameters to (valid) iCalcreator date in array format (or FALSE) - * if $utc=TRUE and $tz = utc offset ([[+/]-]HHmm) input (local) date array + UTC offset - * returns ouput in UTC format date - * - * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 - * @param mixed $year - * @param mixed $month optional - * @param int $day optional - * @param int $hour optional - * @param int $min optional - * @param int $sec optional - * @param mixed $tz optional - * @param bool $utc optional - * @return bool false / array $date - */ - function validDate( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $utc=FALSE ) { - $input = array(); - $toolbox = new calendarComponent(); - $parno = null; - if( is_array( $year ) && isset( $year['timestamp'] )) { - $input = $toolbox->_date_time_string( date( 'Y-m-d H:i:s', $year['timestamp'] ), 6 ); - $input['tz'] = ( isset( $year['tz'] )) ? $year['tz'] : null; - $utc = ( TRUE === $month ) ? TRUE : FALSE; - } - elseif( is_array( $year ) && ( in_array( count( $year ), array( 3, 4, 6, 7 )))) { - if( isset( $year['tz'] ) || ( 4 == count( $year )) || ( 7 == count( $year ))) - $parno = 7; - elseif( isset( $year['hour'] ) || isset( $year['min'] ) || isset( $year['sec'] ) || - ( 6 == count( $year ))) - $parno = 6; - else - $parno = 3; - $input = $toolbox->_date_time_array( $year, $parno ); - $utc = ( TRUE === $month ) ? TRUE : FALSE; - } - elseif( 8 <= strlen( trim( $year ))) { // ex. 2006-08-03 10:12:18 - $input = $toolbox->_date_time_string( $year ); - $utc = ( TRUE === $month ) ? TRUE : FALSE; - } - elseif(( $year !== FALSE ) && ( $month !== FALSE ) && ( $day !== FALSE )) { - if(( 0 > (int) $year ) || (2100 < (int) $year )) - return FALSE; - $month = (int) $month; - if(( 1 > $month ) || ( 12 < $month )) - return FALSE; - $day = (int) $day; - if(( 1 > $day ) || ( 31 < $day )) - return FALSE; - $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'] ); + if( !$res ) return FALSE; + if( isset( $subcfg ) && !empty( $this->components )) { + foreach( $subcfg as $cfgkey => $cfgvalue ) { + foreach( $this->components as $cix => $component ) { + $res = $component->setConfig( $cfgkey, $cfgvalue ); + if( !$res ) + break 2; + $this->components[$cix] = $component->copy(); // PHP4 compliant } } } - return $input; + return $res; } /*********************************************************************************/ /** @@ -784,7 +698,7 @@ class vcalendar { * delete calendar component from container * * @author Kjell-Inge Gustafsson - * @since 2.0.4 - 2007-06-14 + * @since 2.4.10 - 2008-08-05 * @param mixed $arg1 ordno / component type / component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return void @@ -797,10 +711,11 @@ class vcalendar { } elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) { $argType = strtolower( $arg1 ); - $index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 1; + $index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0; } $cix1dC = 0; foreach ( $this->components as $cix => $component) { + if( empty( $component )) continue; unset( $component->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) { unset( $this->components[$cix] ); @@ -824,7 +739,7 @@ class vcalendar { * get calendar component from container * * @author Kjell-Inge Gustafsson - * @since 2.2.16 - 2007-11-11 + * @since 2.4.10 - 2008-08-06 * @param mixed $arg1 optional, ordno/component type/ component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return object @@ -856,6 +771,7 @@ class vcalendar { return FALSE; $cix1gC = 0; foreach ( $this->components as $cix => $component) { + if( empty( $component )) continue; unset( $component->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) return $component->copy(); @@ -871,7 +787,7 @@ class vcalendar { } /* not found.. . */ unset( $this->compix ); - return false; + return FALSE; } /** * select components from calendar on date basis @@ -880,7 +796,7 @@ class vcalendar { * No date controls occurs. * * @author Kjell-Inge Gustafsson - * @since 2.4.1 - 2008-02-05 + * @since 2.4.16 - 2008-10-18 * @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 @@ -899,8 +815,7 @@ class vcalendar { */ 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; + if( 0 >= count( $this->components )) return FALSE; /* check default dates */ if( !$startY ) $startY = date( 'Y' ); if( !$startM ) $startM = date( 'm' ); @@ -934,40 +849,52 @@ class vcalendar { /* iterate components */ $result = array(); foreach ( $this->components as $cix => $component ) { + if( empty( $component )) continue; unset( $component->propix, $start ); /* deselect unvalid type components */ - if( !in_array( $component->objName, $cType )) - continue; + if( !in_array( $component->objName, $cType )) continue; /* deselect components without dtstart set */ - if( FALSE === ( $start = $component->getProperty( 'dtstart' ))) - continue; - $dtendExist = $dueExist = FALSE; + if( FALSE === ( $start = $component->getProperty( 'dtstart' ))) continue; + $dtendExist = $dueExist = $durationExist = $endAllDayEvent = FALSE; unset( $end, $startWdate, $endWdate, $rdurWsecs, $rdur, $exdatelist, $workstart, $workend ); // clean up $startWdate = $component->_date2timestamp( $start ); + $startDateFormat = ( isset( $start['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d'; /* get end date from dtend/due/duration properties */ $end = $component->getProperty( 'dtend' ); - if( !empty( $end )) + if( !empty( $end )) { $dtendExist = TRUE; - //if( !empty($end)) echo 'selectComponents 1 start='.implode('-',$start).' end='.implode('-',$end)."
\n"; // test ### + $endDateFormat = ( isset( $end['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d'; + } + // if( !empty($end)) echo 'selectComp 1 start='.implode('-',$start).' end='.implode('-',$end)."
\n"; // test ### if( empty($end) && ( $component->objName == 'vtodo' )) { $end = $component->getProperty( 'due' ); - if( !empty( $end )) + if( !empty( $end )) { $dueExist = TRUE; - //if( !empty($end)) echo 'selectComponents 2 start='.implode('-',$start).' end='.implode('-',$end)."
\n"; // test ### + $endDateFormat = ( isset( $end['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d'; + } + // if( !empty($end)) echo 'selectComp 2 start='.implode('-',$start).' end='.implode('-',$end)."
\n"; // test ### } - elseif( !empty($end) && !isset( $end['hour'] )) { + if( !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)."
\n"; // test ### + $endAllDayEvent = TRUE; + $endWdate = mktime( 23, 59, 59, $end['month'], ($end['day'] - 1), $end['year'] ); + $end['year'] = date( 'Y', $endWdate ); + $end['month'] = date( 'm', $endWdate ); + $end['day'] = date( 'd', $endWdate ); + $end['hour'] = 23; + $end['min'] = $end['sec'] = 59; + // if( !empty($end)) echo 'selectComp 3 start='.implode('-',$start).' end='.implode('-',$end)."
\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)."
\n"; // test ### + if( !empty( $end )) + $durationExist = TRUE; + // if( !empty($end)) echo 'selectComp 4 start='.implode('-',$start).' end='.implode('-',$end)."
\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)."
\n"; // test ### + // if( isset($end)) echo 'selectComp 5 start='.implode('-',$start).' end='.implode('-',$end)."
\n"; // test ### } $endWdate = $component->_date2timestamp( $end ); if( $endWdate < $startWdate ) { // MUST be after start date!! @@ -976,13 +903,13 @@ class vcalendar { } $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 */ + /* make a list of optional exclude dates for component occurence from exrule and 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' ))) + $workstart = $component->_timestamp2date(( $startDate - $rdurWsecs ), 6); + $workend = $component->_timestamp2date(( $endDate + $rdurWsecs ), 6); + while( FALSE !== ( $exrule = $component->getProperty( 'exrule' ))) // check exrule $component->_recur2date( $exdatelist, $exrule, $start, $workstart, $workend ); - while( FALSE !== ( $exdate = $component->getProperty( 'exdate' ))) { + while( FALSE !== ( $exdate = $component->getProperty( 'exdate' ))) { // check exdate foreach( $exdate as $theExdate ) { $exWdate = $component->_date2timestamp( $theExdate ); if((( $startDate - $rdurWsecs ) <= $exWdate ) && ( $endDate >= $exWdate )) @@ -999,7 +926,7 @@ class vcalendar { $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 + if( is_array( $theRdate ) && ( 2 == count( $theRdate )) && // all days within PERIOD array_key_exists( '0', $theRdate ) && array_key_exists( '1', $theRdate )) { $rstart = $component->_date2timestamp( $theRdate[0] ); if(( $rstart < ( $startDate - $rdurWsecs )) || ( $rstart > $endDate )) @@ -1012,7 +939,7 @@ class vcalendar { } if((( $startDate - $rdurWsecs ) <= $rstart ) && ( $endDate >= $rstart )) $recurlist[$rstart] = ( $rstart - $rend ); // set start date + rdate duration in seconds - } + } // PERIOD end else { // single date $theRdate = $component->_date2timestamp( $theRdate ); if((( $startDate - $rdurWsecs ) <= $theRdate ) && ( $endDate >= $theRdate )) @@ -1029,50 +956,51 @@ class vcalendar { 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'; + $component2 = $component->copy(); + $rstart = $component2->_timestamp2date( $recurkey, 6); + $datevalue = $rstart['month'].'/'.$rstart['day'].'/'.$rstart['year']; 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'; + $datevalue .= ( isset( $rstart['hour'] )) ? ' '.$rstart['hour'] : ' 00'; + $datevalue .= ( isset( $rstart['min'] )) ? ':'.$rstart['min'] : ':00'; + $datevalue .= ( isset( $rstart['sec'] )) ? ':'.$rstart['sec'] : ':00'; } - $datestring = date( $dateformat, strtotime( $datevalue )); + $datestring = date( $startDateFormat, 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'; + $component2->setProperty( 'X-CURRENT-DTSTART', $datestring ); + $rend = $component2->_timestamp2date(( $recurkey + $durvalue ), 6); + if( $dtendExist || $dueExist ) { + if( $endAllDayEvent ) { + $rend2 = mktime( 0, 0, 0, $rend['month'], ($rend['day'] + 1), $rend['year'] ); + $datevalue = date( 'm', $rend2 ).'/'.date( 'd', $rend2 ).'/'.date( 'Y', $rend2 ); + } + else { + $datevalue = $rend['month'].'/'.$rend['day'].'/'.$rend['year']; + 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'; + } } - $datestring = date( $dateformat, strtotime( $datevalue )); + $datestring = date( $endDateFormat, strtotime( $datevalue )); if( isset( $end['tz'] )) $datestring .= ' '.$end['tz']; if( $dtendExist ) - $component2->setProperty( 'x-current-dtend', $datestring ); - else - $component2->setProperty( 'x-current-due', $datestring ); + $component2->setProperty( 'X-CURRENT-DTEND', $datestring ); + elseif( $dueExist ) + $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 + $result[] = $component2->copy(); // 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 + 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 @@ -1086,16 +1014,13 @@ class vcalendar { } } /* deselect components with startdate/enddate not within period */ - if(( $endWdate < $startDate ) || ( $startWdate > $endDate )) - continue; + if(( $endWdate < $startDate ) || ( $startWdate > $endDate )) continue; } /* deselect components with startdate not within period */ - elseif(( $startWdate < $startDate ) || ( $startWdate > $endDate )) - continue; + elseif(( $startWdate < $startDate ) || ( $startWdate > $endDate )) continue; /* add selected components within valid dates to output array */ - if( $flat ) { + if( $flat ) $result[] = $component->copy(); // copy to output; - } elseif( $split ) { if( $endWdate > $endDate ) $endWdate = $endDate; // use period end date @@ -1110,14 +1035,13 @@ class vcalendar { } } // use component date elseif( !isset( $exdatelist[$startWdate] ) && // check excluded dates - ( $startWdate >= $startDate )) { // within period + ( $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 ) { + if( 0 >= count( $result )) return FALSE; + elseif( !$flat ) { foreach( $result as $y => $yeararr ) { foreach( $yeararr as $m => $montharr ) { ksort( $result[$y][$m] ); @@ -1132,7 +1056,7 @@ class vcalendar { * add calendar component to container * * @author Kjell-Inge Gustafsson - * @since 2.2.16 - 2007-11-11 + * @since 2.4.10 - 2008-08-06 * @param object $component calendar component * @param mixed $arg1 optional, ordno/component type/ component uid * @param mixed $arg2 optional, ordno if arg1 = component type @@ -1148,8 +1072,8 @@ class vcalendar { 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' ); + $dummy1 = $component->getProperty( 'dtstamp' ); + $dummy2 = $component->getProperty( 'uid' ); } if( !$arg1 ) { $this->components[] = $component->copy(); @@ -1166,6 +1090,7 @@ class vcalendar { } $cix1sC = 0; foreach ( $this->components as $cix => $component2) { + if( empty( $component2 )) continue; unset( $component2->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) { $this->components[$cix] = $component->copy(); @@ -1185,71 +1110,88 @@ class vcalendar { } /* not found.. . insert last in chain anyway .. .*/ $this->components[] = $component->copy(); + return TRUE; } /** * sort iCal compoments, only local date sort * + * ascending sort on properties (if exist) x-current-dtstart, dtstart, + * x-current-dtend, dtend, x-current-due, due, duration, created, dtstamp, uid + * * @author Kjell-Inge Gustafsson - * @since 2.2.9 - 2007-10-02 + * @since 2.4.10 - 2008-09-24 * @return sort param * */ + function sort() { + if( is_array( $this->components )) { + $this->_sortkeys = array( 'year', 'month', 'day', 'hour', 'min', 'sec' ); + usort( $this->components, array( $this, '_cmpfcn' )); + } + } function _cmpfcn( $a, $b ) { + if( empty( $a )) return -1; + if( empty( $b )) return 1; 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']; + $astart = ( isset( $a->xprop['X-CURRENT-DTSTART']['value'] )) ? $a->_date_time_string( $a->xprop['X-CURRENT-DTSTART']['value'] ) : null; + if( empty( $astart ) && isset( $a->dtstart['value'] )) + $astart = & $a->dtstart['value']; + $bstart = ( isset( $b->xprop['X-CURRENT-DTSTART']['value'] )) ? $b->_date_time_string( $b->xprop['X-CURRENT-DTSTART']['value'] ) : null; + if( empty( $bstart ) && isset( $b->dtstart['value'] )) + $bstart = & $b->dtstart['value']; + if( empty( $astart )) return -1; + elseif( empty( $bstart )) return 1; + foreach( $this->_sortkeys as $key ) { + if ( empty( $astart[$key] )) return -1; + elseif( empty( $bstart[$key] )) return 1; + if ( $astart[$key] == $bstart[$key]) continue; + if (( (int) $astart[$key] ) < ((int) $bstart[$key] )) + return -1; + elseif(( (int) $astart[$key] ) > ((int) $bstart[$key] )) + return 1; + } + $c = ( isset( $a->xprop['X-CURRENT-DTEND']['value'] )) ? $a->_date_time_string( $a->xprop['X-CURRENT-DTEND']['value'] ) : null; + if( empty( $c ) && !empty( $a->dtend['value'] )) + $c = & $a->dtend['value']; + if( empty( $c ) && isset( $a->xprop['X-CURRENT-DUE']['value'] )) + $c = $a->_date_time_string( $a->xprop['X-CURRENT-DUE']['value'] ); if( empty( $c ) && !empty( $a->due['value'] )) - $c = $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']; + $d = ( isset( $b->xprop['X-CURRENT-DTEND']['value'] )) ? $b->_date_time_string( $b->xprop['X-CURRENT-DTEND']['value'] ) : null; + if( empty( $d ) && !empty( $b->dtend['value'] )) + $d = & $b->dtend['value']; + if( empty( $d ) && isset( $b->xprop['X-CURRENT-DUE']['value'] )) + $d = $b->_date_time_string( $b->xprop['X-CURRENT-DUE']['value'] ); if( empty( $d ) && !empty( $b->due['value'] )) - $d = $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']; + if( empty( $c )) return -1; + elseif( empty( $d )) return 1; 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 ( !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; + } + if( isset( $a->created['value'] )) + $e = & $a->created['value']; + else + $e = & $a->dtstamp['value']; + if( isset( $b->created['value'] )) + $f = & $b->created['value']; + else + $f = & $b->dtstamp['value']; + foreach( $this->_sortkeys as $key ) { + if( !isset( $e[$key] )) return -1; + elseif( !isset( $f[$key] )) return 1; + if ( $e[$key] == $f[$key] ) continue; + if (( (int) $e[$key] ) < ((int) $f[$key])) return -1; + elseif(( (int) $e[$key] ) > ((int) $f[$key])) return 1; } if (( $a->uid['value'] ) < ( $b->uid['value'] )) return -1; @@ -1257,17 +1199,11 @@ class vcalendar { ( $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 - * @since 2.4.3 - 2008-02-13 + * @since 2.4.10 - 2008-08-06 * @param string $filename optional filname (incl. opt. directory/path) or URL * @return bool FALSE if error occurs during parsing * @@ -1508,18 +1444,21 @@ class vcalendar { } // 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(); + for( $six = 0; $six < count( $this->components ); $six++ ) { + if( !empty( $this->components[$six] )) + $this->components[$six]->parse(); + } } else return FALSE; /* err 91 or something.. . */ + return TRUE; } /*********************************************************************************/ /** * creates formatted output for calendar object instance * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-25 + * @since 2.4.10 - 2008-08-06 * @return string */ function createCalendar() { @@ -1552,6 +1491,7 @@ class vcalendar { } $calendar .= $this->createXprop(); foreach( $this->components as $component ) { + if( empty( $component )) continue; if( '' >= $component->getConfig( 'language')) $component->setConfig( 'language', $this->getConfig( 'language' )); $component->setConfig( 'allowEmpty', $this->getConfig( 'allowEmpty' )); @@ -1716,57 +1656,13 @@ class vcalendar { * abstract class for calendar components * * @author Kjell-Inge Gustafsson - * @since 2.3.1 - 2007-11-19 + * @since 2.4.19 - 2008-10-12 */ 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; - var $tzoffsetto; - var $tzurl; - var $url; - var $xprop; - // component subcomponents container - var $components; // component config variables var $allowEmpty; var $language; @@ -1792,7 +1688,7 @@ class calendarComponent { * constructor for calendar component object * * @author Kjell-Inge Gustafsson - * @since 2.3.1 - 2007-11-19 + * @since 2.4.19 - 2008-10-23 */ function calendarComponent() { $this->objName = ( isset( $this->timezonetype )) ? @@ -1800,57 +1696,14 @@ class calendarComponent { $this->uid = array(); $this->dtstamp = array(); - $this->action = array(); - $this->attach = array(); - $this->attendee = array(); - $this->categories = array(); - $this->class = array(); - $this->comment = array(); - $this->completed = array(); - $this->contact = array(); - $this->created = array(); - $this->description = array(); - $this->dtend = array(); - $this->dtstart = array(); - $this->due = array(); - $this->duration = array(); - $this->exdate = array(); - $this->exrule = array(); - $this->freebusy = array(); - $this->geo = array(); - $this->lastmodified = array(); - $this->location = array(); - $this->organizer = array(); - $this->percentcomplete = array(); - $this->priority = array(); - $this->rdate = array(); - $this->recurrenceid = array(); - $this->relatedto = array(); - $this->repeat = array(); - $this->requeststatus = array(); - $this->resources = array(); - $this->sequence = array(); - $this->rrule = array(); - $this->status = array(); - $this->summary = array(); - $this->transp = array(); - $this->trigger = array(); - $this->tzid = array(); - $this->tzname = array(); - $this->tzoffsetfrom = array(); - $this->tzoffsetto = array(); - $this->tzurl = array(); - $this->url = array(); - $this->xprop = array(); - - $this->components = array(); - $this->language = null; $this->nl = null; $this->unique_id = null; + $this->format = null; $this->allowEmpty = TRUE; $this->xcaldecl = array(); + $this->_createFormat(); $this->_makeDtstamp(); } /*********************************************************************************/ @@ -1861,12 +1714,13 @@ class calendarComponent { * creates formatted output for calendar component property action * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createAction() { - if( !isset( $this->action['value'] )) - return; + if( empty( $this->action )) return FALSE; + if( empty( $this->action['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'ACTION' ) : FALSE; $attributes = $this->_createParams( $this->action['params'] ); return $this->_createElement( 'ACTION', $attributes, $this->action['value'] ); } @@ -1874,14 +1728,15 @@ class calendarComponent { * set calendar component property action * * @author Kjell-Inge Gustafsson - * @since 0.9.2 - 2006-11-16 + * @since 2.4.8 - 2008-11-04 * @param string $value "AUDIO" / "DISPLAY" / "EMAIL" / "PROCEDURE" * @param mixed $params - * @return void + * @return bool */ function setAction( $value, $params=FALSE ) { - $this->action['value'] = $value; - $this->action['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->action = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -1891,17 +1746,18 @@ class calendarComponent { * creates formatted output for calendar component property attach * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 0.9.7 - 2006-11-23 * @return string */ function createAttach() { - $cnt = count( $this->attach ); - if( 0 >= $cnt ) - return; - $output = null; + if( empty( $this->attach )) return FALSE; + $output = null; foreach( $this->attach as $attachPart ) { - $attributes = $this->_createParams( $attachPart['params'] ); - $output .= $this->_createElement( 'ATTACH', $attributes, $attachPart['value'] ); + if(! empty( $attachPart['value'] )) { + $attributes = $this->_createParams( $attachPart['params'] ); + $output .= $this->_createElement( 'ATTACH', $attributes, $attachPart['value'] ); + } + elseif( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'ATTACH' ); } return $output; } @@ -1909,16 +1765,16 @@ class calendarComponent { * set calendar component property attach * * @author Kjell-Inge Gustafsson - * @since 0.9.22 - 2007-04-10 + * @since 2.5.1 - 2008-11-06 * @param string $value - * @param string $params - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setAttach( $value, $params=FALSE) { - $attach = array(); - $attach['value'] = $value ; - $attach['params'] = $this->_setParams( $params ); - $this->attach[] = $attach; + function setAttach( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->attach, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -1928,20 +1784,22 @@ class calendarComponent { * creates formatted output for calendar component property attendee * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-20 + * @since 2.4.8 - 2008-09-23 * @return string */ function createAttendee() { - $cnt = count( $this->attendee ); - if( 0 >= $cnt ) - return; - $attendees = null; + if( empty( $this->attendee )) return FALSE; + $output = null; foreach( $this->attendee as $attendeePart ) { // start foreach 1 + if( empty( $attendeePart['value'] )) { + if( $this->getConfig( 'allowEmpty' )) + $output .= $this->_createElement( 'ATTENDEE' ); + continue; + } $attendee1 = $attendee2 = $attendeeLANG = $attendeeCN = null; foreach( $attendeePart as $paramlabel => $paramvalue ) { // start foreach 2 - if( 'value' == $paramlabel ) { + if( 'value' == $paramlabel ) $attendee2 .= 'MAILTO:'.$paramvalue; - } elseif(( 'params' == $paramlabel ) && ( is_array( $paramvalue ))) { // start elseif foreach( $paramvalue as $optparamlabel => $optparamvalue ) { // start foreach 3 $attendee11 = $attendee12 = null; @@ -1987,23 +1845,25 @@ class calendarComponent { } // end foreach 3 } // end elseif } // end foreach 2 - $attendees .= $this->_createElement( 'ATTENDEE', $attendee1.$attendeeLANG.$attendeeCN, $attendee2 ); + $output .= $this->_createElement( 'ATTENDEE', $attendee1.$attendeeLANG.$attendeeCN, $attendee2 ); } // end foreach 1 - return $attendees; + return $output; } /** * set calendar component property attach * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-24 + * @since 2.5.1 - 2008-11-05 * @param string $value - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setAttendee( $value, $params=FALSE ) { + function setAttendee( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; $value = str_replace ( 'MAILTO:', '', $value ); $value = str_replace ( 'mailto:', '', $value ); - $attendee = array( 'value' => $value, 'params' => array() ); + $params2 = array(); if( is_array($params )) { $optarrays = array(); foreach( $params as $optparamlabel => $optparamvalue ) { @@ -2037,33 +1897,26 @@ class calendarComponent { if(( '"' == substr( $optparamvalue, 0, 1 )) && ( '"' == substr( $optparamvalue, -1 ))) $optparamvalue = substr( $optparamvalue, 1, ( strlen( $optparamvalue ) - 2 )); - $attendee['params'][$optparamlabel] = $optparamvalue; + $params2[$optparamlabel] = $optparamvalue; break; } // end switch( $optparamlabel.. . } // end foreach( $optparam.. . foreach( $optarrays as $optparamlabel => $optparams ) - $attendee['params'][$optparamlabel] = $optparams; + $params2[$optparamlabel] = $optparams; } // remove defaults - if( isset( $attendee['params']['CUTYPE' ] ) && - ( strtoupper( $attendee['params']['CUTYPE' ] ) == 'INDIVIDUAL' )) - unset( $attendee['params']['CUTYPE' ] ); - if( isset( $attendee['params']['PARTSTAT'] ) && - ( strtoupper( $attendee['params']['PARTSTAT'] ) == 'NEEDS-ACTION' )) - unset( $attendee['params']['PARTSTAT'] ); - if( isset( $attendee['params']['ROLE'] ) && - ( strtoupper( $attendee['params']['ROLE'] ) == 'REQ-PARTICIPANT' )) - unset( $attendee['params']['ROLE'] ); - if( isset( $attendee['params']['RSVP'] ) && - ( strtoupper( $attendee['params']['RSVP'] ) == 'FALSE' )) - unset( $attendee['params']['RSVP'] ); + $this->_existRem( $params2, 'CUTYPE', 'INDIVIDUAL' ); + $this->_existRem( $params2, 'PARTSTAT', 'NEEDS-ACTION' ); + $this->_existRem( $params2, 'ROLE', 'REQ-PARTICIPANT' ); + $this->_existRem( $params2, 'RSVP', 'FALSE' ); // check language setting - if( isset( $attendee['params']['CN' ] )) { + if( isset( $params2['CN' ] )) { $lang = $this->getConfig( 'language' ); - if( !isset( $attendee['params']['LANGUAGE' ] ) && !empty( $lang )) - $attendee['params']['LANGUAGE' ] = $lang; + if( !isset( $params2['LANGUAGE' ] ) && !empty( $lang )) + $params2['LANGUAGE' ] = $lang; } - $this->attendee[] = $attendee; + $this->_setMval( $this->attendee, $value, $params2, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2073,15 +1926,18 @@ class calendarComponent { * creates formatted output for calendar component property categories * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-24 + * @since 2.4.8 - 2008-10-22 * @return string */ function createCategories() { - $cnt = count( $this->categories ); - if( 0 >= $cnt ) - return; + if( empty( $this->categories )) return FALSE; $output = null; foreach( $this->categories as $category ) { + if( empty( $category['value'] )) { + if ( $this->getConfig( 'allowEmpty' )) + $output .= $this->_createElement( 'CATEGORIES' ); + continue; + } $attributes = $this->_createParams( $category['params'], array( 'LANGUAGE' )); if( is_array( $category['value'] )) { foreach( $category['value'] as $cix => $categoryPart ) @@ -2098,17 +1954,17 @@ class calendarComponent { * set calendar component property categories * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-24 + * @since 2.5.1 - 2008-11-06 * @param mixed $value - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setCategories( $value, $params=FALSE ) { - $category = array(); - $category['value'] = $value; - $category['params'] = $this->_setParams( $params ); - $this->categories[] = $category; - } + function setCategories( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->categories, $value, $params, FALSE, $index ); + return TRUE; + } /*********************************************************************************/ /** * Property Name: CLASS @@ -2121,9 +1977,9 @@ class calendarComponent { * @return string */ function createClass() { - $cnt = count( $this->class ); - if( 0 >= $cnt ) - return; + if( empty( $this->class )) return FALSE; + if( empty( $this->class['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'CLASS' ) : FALSE; $attributes = $this->_createParams( $this->class['params'] ); return $this->_createElement( 'CLASS', $attributes, $this->class['value'] ); } @@ -2131,14 +1987,15 @@ class calendarComponent { * set calendar component property class * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2003-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value "PUBLIC" / "PRIVATE" / "CONFIDENTIAL" / iana-token / x-name * @param array $params optional - * @return void + * @return bool */ function setClass( $value, $params=FALSE ) { - $this->class['value'] = $value; - $this->class['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->class = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -2148,34 +2005,37 @@ class calendarComponent { * creates formatted output for calendar component property comment * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createComment() { - $cnt = count( $this->comment ); - if( 0 >= $cnt ) - return; - $comment = null; + if( empty( $this->comment )) return FALSE; + $output = null; foreach( $this->comment as $commentPart ) { + if( empty( $commentPart['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'COMMENT' ); + continue; + } $attributes = $this->_createParams( $commentPart['params'], array( 'ALTREP', 'LANGUAGE' )); $content = $this->_strrep( $commentPart['value'] ); - $comment .= $this->_createElement( 'COMMENT', $attributes, $content ); + $output .= $this->_createElement( 'COMMENT', $attributes, $content ); } - return $comment; + return $output; } /** * set calendar component property comment * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.5.1 - 2008-11-06 * @param string $value - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setComment( $value, $params=FALSE ) { - $comment['value'] = $value; - $comment['params'] = $this->_setParams( $params ); - $this->comment[] = $comment; + function setComment( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->comment, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2185,17 +2045,20 @@ class calendarComponent { * creates formatted output for calendar component property completed * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createCompleted( ) { + if( empty( $this->completed )) return FALSE; if( !isset( $this->completed['value']['year'] ) && !isset( $this->completed['value']['month'] ) && !isset( $this->completed['value']['day'] ) && !isset( $this->completed['value']['hour'] ) && !isset( $this->completed['value']['min'] ) && !isset( $this->completed['value']['sec'] )) - return; + if( $this->getConfig( 'allowEmpty' )) + return $this->_createElement( 'COMPLETED' ); + else return FALSE; $formatted = $this->_format_date_time( $this->completed['value'], 7 ); $attributes = $this->_createParams( $this->completed['params'] ); return $this->_createElement( 'COMPLETED', $attributes, $formatted ); @@ -2204,7 +2067,7 @@ class calendarComponent { * set calendar component property completed * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-02 + * @since 2.4.8 - 2008-10-23 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -2212,10 +2075,19 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return bool */ function setCompleted( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { + if( empty( $year )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->completed = array( 'value' => null, 'params' => $this->_setParams( $params )); + return TRUE; + } + else + return FALSE; + } $this->completed = $this->_setDate2( $year, $month, $day, $hour, $min, $sec, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -2225,18 +2097,19 @@ class calendarComponent { * creates formatted output for calendar component property contact * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-24 + * @since 2.4.8 - 2008-10-23 * @return string */ function createContact() { - $cnt = count( $this->contact ); - if( 0 >= $cnt ) - return; + if( empty( $this->contact )) return FALSE; $output = null; foreach( $this->contact as $contact ) { - $attributes = $this->_createParams( $contact['params'], array( 'ALTREP', 'LANGUAGE' )); - $content = $this->_strrep( $contact['value'] ); - $output .= $this->_createElement( 'CONTACT', $attributes, $content ); + if( !empty( $contact['value'] )) { + $attributes = $this->_createParams( $contact['params'], array( 'ALTREP', 'LANGUAGE' )); + $content = $this->_strrep( $contact['value'] ); + $output .= $this->_createElement( 'CONTACT', $attributes, $content ); + } + elseif( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'CONTACT' ); } return $output; } @@ -2244,15 +2117,16 @@ class calendarComponent { * set calendar component property contact * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.5.1 - 2008-11-05 * @param string $value - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setContact( $value, $params=FALSE ) { - $contact['value'] = $value; - $contact['params'] = $this->_setParams( $params ); - $this->contact[] = $contact; + function setContact( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->contact, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2262,17 +2136,11 @@ class calendarComponent { * creates formatted output for calendar component property created * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createCreated() { - if( !isset( $this->created['value']['year'] ) && - !isset( $this->created['value']['month'] ) && - !isset( $this->created['value']['day'] ) && - !isset( $this->created['value']['hour'] ) && - !isset( $this->created['value']['min'] ) && - !isset( $this->created['value']['sec'] )) - return; + if( empty( $this->created )) return FALSE; $formatted = $this->_format_date_time( $this->created['value'], 7 ); $attributes = $this->_createParams( $this->created['params'] ); return $this->_createElement( 'CREATED', $attributes, $formatted ); @@ -2281,7 +2149,7 @@ class calendarComponent { * set calendar component property created * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-02 + * @since 2.4.8 - 2008-10-23 * @param mixed $year optional * @param mixed $month optional * @param int $day optional @@ -2289,13 +2157,14 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param mixed $params optional - * @return void + * @return bool */ function setCreated( $year=FALSE, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { if( !isset( $year )) { $year = date('Ymd\THis', mktime( date( 'H' ), date( 'i' ), date( 's' ) - date( 'Z'), date( 'm' ), date( 'd' ), date( 'Y' ))); } $this->created = $this->_setDate2( $year, $month, $day, $hour, $min, $sec, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -2305,34 +2174,36 @@ class calendarComponent { * creates formatted output for calendar component property description * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createDescription() { - $cnt = count( $this->description ); - if( 0 >= $cnt ) - return; - $descriptions = null; + if( empty( $this->description )) return FALSE; + $output = null; foreach( $this->description as $description ) { - $attributes = $this->_createParams( $description['params'], array( 'ALTREP', 'LANGUAGE' )); - $content = $this->_strrep( $description['value'] ); - $descriptions .= $this->_createElement( 'DESCRIPTION', $attributes, $content ); + if( !empty( $description['value'] )) { + $attributes = $this->_createParams( $description['params'], array( 'ALTREP', 'LANGUAGE' )); + $content = $this->_strrep( $description['value'] ); + $output .= $this->_createElement( 'DESCRIPTION', $attributes, $content ); + } + elseif( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'DESCRIPTION' ); } - return $descriptions; + return $output; } /** * set calendar component property description * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.5.1 - 2008-11-05 * @param string $value - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setDescription( $value, $params=FALSE ) { - $description['value'] = $value; - $description['params'] = $this->_setParams( $params ); - $this->description[] = $description; + function setDescription( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) { if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; } + $this->_setMval( $this->description, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2342,17 +2213,20 @@ class calendarComponent { * creates formatted output for calendar component property dtend * * @author Kjell-Inge Gustafsson - * @since 0.9.19 - 2007-03-27 + * @since 2.4.8 - 2008-10-21 * @return string */ function createDtend() { + if( empty( $this->dtend )) return FALSE; if( !isset( $this->dtend['value']['year'] ) && !isset( $this->dtend['value']['month'] ) && !isset( $this->dtend['value']['day'] ) && !isset( $this->dtend['value']['hour'] ) && !isset( $this->dtend['value']['min'] ) && !isset( $this->dtend['value']['sec'] )) - return; + if( $this->getConfig( 'allowEmpty' )) + return $this->_createElement( 'DTEND' ); + else return FALSE; $formatted = $this->_format_date_time( $this->dtend['value'] ); $attributes = $this->_createParams( $this->dtend['params'] ); return $this->_createElement( 'DTEND', $attributes, $formatted ); @@ -2361,7 +2235,7 @@ class calendarComponent { * set calendar component property dtend * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.8 - 2008-10-23 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -2370,10 +2244,19 @@ class calendarComponent { * @param int $sec optional * @param string $tz optional * @param array params optional - * @return void + * @return bool */ function setDtend( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE ) { + if( empty( $year )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->dtend = array( 'value' => null, 'params' => $this->_setParams( $params )); + return TRUE; + } + else + return FALSE; + } $this->dtend = $this->_setDate( $year, $month, $day, $hour, $min, $sec, $tz, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -2383,11 +2266,11 @@ class calendarComponent { * creates formatted output for calendar component property dtstamp * * @author Kjell-Inge Gustafsson - * @since 2.2.4 - 2007-08-01 + * @since 2.4.4 - 2008-03-07 * @return string */ function createDtstamp() { - if( !isset( $htis->dtstamp['value']['year'] ) && + if( !isset( $this->dtstamp['value']['year'] ) && !isset( $this->dtstamp['value']['month'] ) && !isset( $this->dtstamp['value']['day'] ) && !isset( $this->dtstamp['value']['hour'] ) && @@ -2418,7 +2301,7 @@ class calendarComponent { * set calendar component property dtstamp * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-02 + * @since 2.4.8 - 2008-10-23 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -2426,10 +2309,14 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return TRUE */ function setDtstamp( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { - $this->dtstamp = $this->_setDate2( $year, $month, $day, $hour, $min, $sec, $params ); + if( empty( $year )) + $this->_makeDtstamp(); + else + $this->dtstamp = $this->_setDate2( $year, $month, $day, $hour, $min, $sec, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -2439,20 +2326,22 @@ class calendarComponent { * creates formatted output for calendar component property dtstart * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 - * @param bool $localtime optional, default FALSE + * @since 2.4.16 - 2008-10-26 * @return string */ - function createDtstart( $localtime=FALSE ) { + function createDtstart() { + if( empty( $this->dtstart )) return FALSE; if( !isset( $this->dtstart['value']['year'] ) && !isset( $this->dtstart['value']['month'] ) && !isset( $this->dtstart['value']['day'] ) && !isset( $this->dtstart['value']['hour'] ) && !isset( $this->dtstart['value']['min'] ) && !isset( $this->dtstart['value']['sec'] )) - return; - if( $localtime ) - unset( $this->dtstart['value']['tz'] ); + if( $this->getConfig( 'allowEmpty' )) + return $this->_createElement( 'DTSTART' ); + else return FALSE; + if( in_array( $this->objName, array( 'vtimezone', 'standard', 'daylight' ))) + unset( $this->dtstart['value']['tz'], $this->dtstart['params']['TZID'] ); $formatted = $this->_format_date_time( $this->dtstart['value'] ); $attributes = $this->_createParams( $this->dtstart['params'] ); return $this->_createElement( 'DTSTART', $attributes, $formatted ); @@ -2461,7 +2350,7 @@ class calendarComponent { * set calendar component property dtstart * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.16 - 2008-11-04 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -2470,10 +2359,19 @@ class calendarComponent { * @param int $sec optional * @param string $tz optional * @param array $params optional - * @return void + * @return bool */ function setDtstart( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE ) { - $this->dtstart = $this->_setDate( $year, $month, $day, $hour, $min, $sec, $tz, $params ); + if( empty( $year )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->dtstart = array( 'value' => null, 'params' => $this->_setParams( $params )); + return TRUE; + } + else + return FALSE; + } + $this->dtstart = $this->_setDate( $year, $month, $day, $hour, $min, $sec, $tz, $params, 'dtstart' ); + return TRUE; } /*********************************************************************************/ /** @@ -2483,17 +2381,20 @@ class calendarComponent { * creates formatted output for calendar component property due * * @author Kjell-Inge Gustafsson - * @since 0.9.19 - 2007-03-27 + * @since 2.4.8 - 2008-10-22 * @return string */ function createDue() { + if( empty( $this->due )) return FALSE; if( !isset( $this->due['value']['year'] ) && !isset( $this->due['value']['month'] ) && !isset( $this->due['value']['day'] ) && !isset( $this->due['value']['hour'] ) && !isset( $this->due['value']['min'] ) && !isset( $this->due['value']['sec'] )) - return; + if( $this->getConfig( 'allowEmpty' )) + return $this->_createElement( 'DUE' ); + else return FALSE; $formatted = $this->_format_date_time( $this->due['value'] ); $attributes = $this->_createParams( $this->due['params'] ); return $this->_createElement( 'DUE', $attributes, $formatted ); @@ -2502,7 +2403,7 @@ class calendarComponent { * set calendar component property due * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.8 - 2008-11-04 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -2510,10 +2411,19 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return bool */ function setDue( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE ) { + if( empty( $year )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->due = array( 'value' => null, 'params' => $this->_setParams( $params )); + return TRUE; + } + else + return FALSE; + } $this->due = $this->_setDate( $year, $month, $day, $hour, $min, $sec, $tz, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -2523,16 +2433,19 @@ class calendarComponent { * creates formatted output for calendar component property duration * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createDuration() { + if( empty( $this->duration )) return FALSE; if( !isset( $this->duration['value']['week'] ) && !isset( $this->duration['value']['day'] ) && !isset( $this->duration['value']['hour'] ) && !isset( $this->duration['value']['min'] ) && !isset( $this->duration['value']['sec'] )) - return; + if( $this->getConfig( 'allowEmpty' )) + return $this->_createElement( 'DURATION', array(), null ); + else return FALSE; $attributes = $this->_createParams( $this->duration['params'] ); return $this->_createElement( 'DURATION', $attributes, $this->_format_duration( $this->duration['value'] )); } @@ -2540,30 +2453,30 @@ class calendarComponent { * set calendar component property duration * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param mixed $week * @param mixed $day optional * @param int $hour optional * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return bool */ - function setDuration( $week=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { - if( is_array( $week )) { - $this->duration['value'] = $this->_duration_array( $week ); - $this->duration['params'] = $this->_setParams( $day ); - } + function setDuration( $week, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { + if( empty( $week )) if( $this->getConfig( 'allowEmpty' )) $week = null; else return FALSE; + if( is_array( $week ) && ( 1 <= count( $week ))) + $this->duration = array( 'value' => $this->_duration_array( $week ), 'params' => $this->_setParams( $day )); elseif( is_string( $week ) && ( 3 <= strlen( trim( $week )))) { - if( in_array( substr( $week,0, 1 ), array( '+', '-' ))) + $week = trim( $week ); + if( in_array( substr( $week, 0, 1 ), array( '+', '-' ))) $week = substr( $week, 1 ); - $this->duration['value'] = $this->_duration_string( $week ); - $this->duration['params'] = $this->_setParams( $day ); - } - else { - $this->duration['value'] = $this->_duration_array( array( $week, $day, $hour, $min, $sec )); - $this->duration['params'] = $this->_setParams( $params ); + $this->duration = array( 'value' => $this->_duration_string( $week ), 'params' => $this->_setParams( $day )); } + elseif( empty( $week ) && empty( $day ) && empty( $hour ) && empty( $min ) && empty( $sec )) + return FALSE; + else + $this->duration = array( 'value' => $this->_duration_array( array( $week, $day, $hour, $min, $sec )), 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -2573,33 +2486,37 @@ class calendarComponent { * creates formatted output for calendar component property exdate * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createExdate() { - $cnt = count( $this->exdate ); - if( 0 >= $cnt ) - return; + if( empty( $this->exdate )) return FALSE; $output = null; - foreach( $this->exdate as $theExdate ) { + foreach( $this->exdate as $ex => $theExdate ) { + if( empty( $theExdate['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'EXDATE' ); + continue; + } $content = $attributes = null; foreach( $theExdate['value'] as $eix => $exdatePart ) { - $formatted = $this->_format_date_time( $exdatePart ); + $parno = count( $exdatePart ); + $formatted = $this->_format_date_time( $exdatePart, $parno ); if( isset( $theExdate['params']['TZID'] )) $formatted = str_replace( 'Z', '', $formatted); if( 0 < $eix ) { - if( isset( $theExdate['value'][0]['tz'] ) && - ( ctype_digit( substr( $theExdate['value'][0]['tz'], -4 )) || - ( 'Z' == $theExdate['value'][0]['tz'] ))) { - if( 'Z' != substr( $formatted, -1 )) - $formatted .= 'Z'; + if( isset( $theExdate['value'][0]['tz'] )) { + if( ctype_digit( substr( $theExdate['value'][0]['tz'], -4 )) || + ( 'Z' == $theExdate['value'][0]['tz'] )) { + if( 'Z' != substr( $formatted, -1 )) + $formatted .= 'Z'; + } + else + $formatted = str_replace( 'Z', '', $formatted ); } else $formatted = str_replace( 'Z', '', $formatted ); } - if( 0 < $eix ) - $content .= ','; - $content .= $formatted; + $content .= ( 0 < $eix ) ? ','.$formatted : $formatted; } $attributes .= $this->_createParams( $theExdate['params'] ); $output .= $this->_createElement( 'EXDATE', $attributes, $content ); @@ -2610,78 +2527,51 @@ class calendarComponent { * set calendar component property exdate * * @author Kjell-Inge Gustafsson - * @since 2.0.5 - 2007-06-22 + * @since 2.5.1 - 2008-11-05 * @param array exdates - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setExdate( $exdates, $params=FALSE ) { - $exdate = array(); - $exdate['params'] = $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' ) ); - $parno = ( isset( $exdate['params']['TZID'] )) ? 6 : null; - $parno = $this->_existRem( $exdate['params'], 'VALUE', 'DATE-TIME', 7, $parno ); - if( !isset( $parno )) $parno = $this->_existRem( $exdate['params'], 'VALUE', 'DATE', 3 ); - foreach( $exdates as $eix => $theExdate ) { - if( is_array( $theExdate ) && - ( in_array( count( $theExdate ), array( 3, 4, 6, 7 )))) { - if( isset( $exdate['params']['TZID'] )) - $theExdate['tz'] = $exdate['params']['TZID']; - if( !isset( $parno )) { - if( 4 < count( $theExdate )) - $parno = 7; - else - $parno = 3; - } - $exdatea = $this->_date_time_array( $theExdate, $parno ); - } - elseif( is_array( $theExdate ) && isset( $theExdate['timestamp'] )) { - if( isset( $exdate['params']['TZID'] )) - $theExdate['tz'] = $exdate['params']['TZID']; - $tz = ( isset( $theExdate['tz'] )) ? ' '.$theExdate['tz'] : null; - if( !isset( $parno )) - $parno = ( !empty( $tz )) ? 7 : 6; - $exdatea = $this->_date_time_string( date( 'Y-m-d H:i:s', $theExdate['timestamp'] ).$tz, $parno ); - } - elseif( 8 <= strlen( trim( $theExdate ))) { // ex. 2006-08-03 10:12:18 - $exdatea = $this->_date_time_string( $theExdate, $parno ); - if( isset( $exdate['params']['TZID'] )) - $exdatea['tz'] = $exdate['params']['TZID']; - } - if( !isset( $parno )) { - $parno = count( $exdatea ); - if( 6 == $parno ) - $parno = 7; + function setExdate( $exdates, $params=FALSE, $index=FALSE ) { + if( empty( $exdates )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->_setMval( $this->exdate, null, $params, FALSE, $index ); + return TRUE; } - if( isset( $exdatea['tz'] )) + else + return FALSE; + } + $input = array( 'params' => $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' ))); + /* ev. check 1:st date and save ev. timezone **/ + $this->_chkdatecfg( reset( $exdates ), $parno, $input['params'] ); + $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME' ); // remove default parameter + foreach( $exdates as $eix => $theExdate ) { + if( $this->_isArrayTimestampDate( $theExdate )) + $exdatea = $this->_timestamp2date( $theExdate, $parno ); + elseif( is_array( $theExdate )) + $exdatea = $this->_date_time_array( $theExdate, $parno ); + elseif( 8 <= strlen( trim( $theExdate ))) // ex. 2006-08-03 10:12:18 + $exdatea = $this->_date_time_string( $theExdate, $parno ); + if( 3 == $parno ) + unset( $exdatea['hour'], $exdatea['min'], $exdatea['sec'], $exdatea['tz'] ); + elseif( isset( $exdatea['tz'] )) $exdatea['tz'] = (string) $exdatea['tz']; - $exdate['value'][] = $exdatea; - } - if( 0 < count( $exdate['value'] )) { - if( 3 == $parno ) { - $exdate['params']['VALUE'] = 'DATE'; - foreach( $exdate['value'] as $eix => $exdatea ) - unset( $exdate['value'][$eix]['tz'] ); - unset( $exdate['params']['TZID'] ); - } - if( !empty( $exdate['value'][0]['tz'] ) && - ( $exdate['value'][0]['tz'] != 'Z' ) && - ( !( in_array($exdate['value'][0]['tz']{0}, array( '+', '-' )) && - ctype_digit( substr( $exdate['value'][0]['tz'], 1 ))) && - !ctype_digit( $exdate['value'][0]['tz'] ) ) ) { - $exdate['params']['TZID'] = $exdate['value'][0]['tz']; - foreach( $exdate['value'] as $exix => $exdatea ) { - if( !empty( $exdate['value'][0]['tz'] ) && - ( $exdate['value'][0]['tz'] != 'Z' ) && - ( !( in_array($exdate['value'][0]['tz']{0}, array( '+', '-' )) && - ctype_digit( substr( $exdate['value'][0]['tz'], 1 ))) && - !ctype_digit( $exdate['value'][0]['tz'] ) ) ) - unset( $exdate['value'][$exix]['tz'] ); - } - } - elseif( isset( $exdate['params']['TZID'] )) - unset( $exdate['params']['TZID'] ); - $this->exdate[] = $exdate; + if( isset( $input['params']['TZID'] ) || + ( isset( $exdatea['tz'] ) && !$this->_isOffset( $exdatea['tz'] )) || + ( isset( $input['value'][0] ) && ( !isset( $input['value'][0]['tz'] ))) || + ( isset( $input['value'][0]['tz'] ) && !$this->_isOffset( $input['value'][0]['tz'] ))) + unset( $exdatea['tz'] ); + $input['value'][] = $exdatea; + } + if( 0 >= count( $input['value'] )) + return FALSE; + if( 3 == $parno ) { + $input['params']['VALUE'] = 'DATE'; + unset( $input['params']['TZID'] ); } + $this->_setMval( $this->exdate, $input['value'], $input['params'], FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2691,56 +2581,27 @@ class calendarComponent { * creates formatted output for calendar component property exrule * * @author Kjell-Inge Gustafsson - * @since 0.7.28 - 2006-09-13 + * @since 2.4.8 - 2008-10-22 * @return string */ function createExrule() { - $cnt = count( $this->exrule ); - if( 0 >= $cnt ) - return; - $exrule = 'EXRULE'; - return $this->_format_recur( $exrule, $this->exrule ); + if( empty( $this->exrule )) return FALSE; + return $this->_format_recur( 'EXRULE', $this->exrule ); } /** * set calendar component property exdate * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.5.1 - 2008-11-05 * @param array $exruleset - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setExrule( $exruleset, $params=FALSE ) { - $exrule = array(); - foreach( $exruleset as $exrulelabel => $exrulevalue ) { - $exrulelabel = strtoupper( $exrulelabel ); - if( 'UNTIL' != $exrulelabel ) - $exrule['value'][$exrulelabel] = $exrulevalue; - elseif( is_array( $exrulevalue ) && - (( 3 == count( $exrulevalue )) || - ( 6 == count( $exrulevalue )) || - ( 7 == count( $exrulevalue )) || - ( array_key_exists( 'year', $exrulevalue )))) { - $parno = ( 3 < count( $exrulevalue )) ? 7 : 3 ; - $date = $this->_date_time_array( $exrulevalue, $parno ); - if(( 3 < count( $date )) && !isset( $date['tz'] )) - $date['tz'] = 'Z'; - $exrule['value'][$exrulelabel] = $date; - } - elseif( is_array( $exrulevalue ) && isset( $exrulevalue['timestamp'] )) { - $date = $this->_date_time_string( date( 'Y-m-d H:i:s', $exrulevalue['timestamp'] ), 6 ); - $date['tz'] = 'Z'; - $exrule['value'][$exrulelabel] = $date; - } - elseif( 8 <= strlen( trim( $exrulevalue ))) { // ex. 2006-08-03 10:12:18 - $date = $this->_date_time_string( $exrulevalue ); - if(( 3 < count( $date )) && !isset( $date['tz'] )) - $date['tz'] = 'Z'; - $exrule['value'][$exrulelabel] = $date; - } - } - $exrule['params'] = $this->_setParams( $params ); - $this->exrule[] = $exrule; + function setExrule( $exruleset, $params=FALSE, $index=FALSE ) { + if( empty( $exruleset )) if( $this->getConfig( 'allowEmpty' )) $exruleset = null; else return FALSE; + $this->_setMval( $this->exrule, $this->_setRexrule( $exruleset ), $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2750,15 +2611,17 @@ class calendarComponent { * creates formatted output for calendar component property freebusy * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-16 + * @since 2.4.8 - 2008-10-22 * @return string */ function createFreebusy() { - $cnt = count( $this->freebusy ); - if( 0 >= $cnt ) - return; + if( empty( $this->freebusy )) return FALSE; $output = null; foreach( $this->freebusy as $freebusyPart ) { + if( empty( $freebusyPart['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'FREEBUSY' ); + continue; + } $attributes = $content = null; if( isset( $freebusyPart['value']['fbtype'] )) { $attributes .= $this->intAttrDelimiter.'FBTYPE='.$freebusyPart['value']['fbtype']; @@ -2800,35 +2663,39 @@ class calendarComponent { * set calendar component property freebusy * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.5.1 - 2008-11-05 * @param string $fbType * @param array $fbValues - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setFreebusy( $fbType, $fbValues, $params=FALSE ) { + function setFreebusy( $fbType, $fbValues, $params=FALSE, $index=FALSE ) { + if( empty( $fbValues )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->_setMval( $this->freebusy, null, $params, FALSE, $index ); + return TRUE; + } + else + return FALSE; + } $fbType = strtoupper( $fbType ); if(( !in_array( $fbType, array( 'FREE', 'BUSY', 'BUSY-UNAVAILABLE', 'BUSY-TENTATIVE' ))) && ( 'X-' != substr( $fbType, 0, 2 ))) $fbType = 'BUSY'; - $freebusy['value'] = array( 'fbtype' => $fbType ); + $input = array( 'fbtype' => $fbType ); foreach( $fbValues as $fbPeriod ) { // periods => period $freebusyPeriod = array(); foreach( $fbPeriod as $fbMember ) { // pairs => singlepart $freebusyPairMember = array(); if( is_array( $fbMember )) { - $cnt = count( $fbMember ); - if(( 6 == $cnt ) || ( 7 == $cnt ) || ( array_key_exists( 'year', $fbMember ))) { // date-time value - $date = $this->_date_time_array( $fbMember, 7 ); - $date['tz'] = ( !isset( $date['tz'] )) ? 'Z' : $date['tz']; - $freebusyPairMember = $date; + if( $this->_isArrayDate( $fbMember )) { // date-time value + $freebusyPairMember = $this->_date_time_array( $fbMember, 7 ); + $freebusyPairMember['tz'] = 'Z'; } - elseif( array_key_exists( 'timestamp', $fbMember )) { // timestamp value - $tz = ( isset( $fbMember['tz'] )) ? ' '.$fbMember['tz'] : null; - $parno = ( !empty( $tz )) ? 7 : 6; - $date = $this->_date_time_string( date( 'Y-m-d H:i:s', $fbMember['timestamp'] ).$tz, $parno ); - $date['tz'] = ( !isset( $date['tz'] )) ? 'Z' : $date['tz']; - $freebusyPairMember = $date; + elseif( $this->_isArrayTimestampDate( $fbMember )) { // timestamp value + $freebusyPairMember = $this->_timestamp2date( $fbMember['timestamp'], 7 ); + $freebusyPairMember['tz'] = 'Z'; } else { // array format duration $freebusyPairMember = $this->_duration_array( $fbMember ); @@ -2840,17 +2707,16 @@ class calendarComponent { $fbmember = substr( $fbMember, 1 ); $freebusyPairMember = $this->_duration_string( $fbMember ); } - elseif( 8 <= strlen( trim( $fbMember ))) { // ex. 2006-08-03 10:12:18 - $date = $this->_date_time_string( $fbMember, 7 ); - $date['tz'] = ( !isset( $date['tz'] )) ? 'Z' : $date['tz']; - $freebusyPairMember = $date; + elseif( 8 <= strlen( trim( $fbMember ))) { // text date ex. 2006-08-03 10:12:18 + $freebusyPairMember = $this->_date_time_string( $fbMember, 7 ); + $freebusyPairMember['tz'] = 'Z'; } - $freebusyPeriod[] = $freebusyPairMember; + $freebusyPeriod[] = $freebusyPairMember; } - $freebusy['value'][] = $freebusyPeriod; + $input[] = $freebusyPeriod; } - $freebusy['params'] = $this->_setParams( $params ); - $this->freebusy[] = $freebusy; + $this->_setMval( $this->freebusy, $input, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -2860,13 +2726,13 @@ class calendarComponent { * creates formatted output for calendar component property geo * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createGeo() { - $cnt = count( $this->geo ); - if( 0 >= $cnt ) - return; + if( empty( $this->geo )) return FALSE; + if( empty( $this->geo['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'GEO' ) : FALSE; $attributes = $this->_createParams( $this->geo['params'] ); $content = null; $content .= number_format( (float) $this->geo['value']['latitude'], 6, '.', ''); @@ -2878,16 +2744,24 @@ class calendarComponent { * set calendar component property geo * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param float $latitude * @param float $longitude * @param array $params optional - * @return void + * @return bool */ function setGeo( $latitude, $longitude, $params=FALSE ) { - $this->geo['value']['latitude'] = $latitude; - $this->geo['value']['longitude'] = $longitude; - $this->geo['params'] = $this->_setParams( $params ); + if( !empty( $latitude ) && !empty( $longitude )) { + if( !is_array( $this->geo )) $this->geo = array(); + $this->geo['value']['latitude'] = $latitude; + $this->geo['value']['longitude'] = $longitude; + $this->geo['params'] = $this->_setParams( $params ); + } + elseif( $this->getConfig( 'allowEmpty' )) + $this->geo = array( 'value' => null, 'params' => $this->_setParams( $params ) ); + else + return FALSE; + return TRUE; } /*********************************************************************************/ /** @@ -2897,17 +2771,11 @@ class calendarComponent { * creates formatted output for calendar component property last-modified * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createLastModified() { - if( !isset( $this->lastmodified['value']['year'] ) && - !isset( $this->lastmodified['value']['month'] ) && - !isset( $this->lastmodified['value']['day'] ) && - !isset( $this->lastmodified['value']['hour'] ) && - !isset( $this->lastmodified['value']['min'] ) && - !isset( $this->lastmodified['value']['sec'] )) - return; + if( empty( $this->lastmodified )) return FALSE; $attributes = $this->_createParams( $this->lastmodified['params'] ); $formatted = $this->_format_date_time( $this->lastmodified['value'], 7 ); return $this->_createElement( 'LAST-MODIFIED', $attributes, $formatted ); @@ -2916,7 +2784,7 @@ class calendarComponent { * set calendar component property completed * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-02 + * @since 2.4.8 - 2008-10-23 * @param mixed $year optional * @param mixed $month optional * @param int $day optional @@ -2924,14 +2792,13 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return boll */ function setLastModified( $year=FALSE, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { - if( !isset( $year )) { + if( empty( $year )) $year = date('Ymd\THis', mktime( date( 'H' ), date( 'i' ), date( 's' ) - date( 'Z'), date( 'm' ), date( 'd' ), date( 'Y' ))); - } $this->lastmodified = $this->_setDate2( $year, $month, $day, $hour, $min, $sec, $params ); - + return TRUE; } /*********************************************************************************/ /** @@ -2941,13 +2808,13 @@ class calendarComponent { * creates formatted output for calendar component property location * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createLocation() { - $cnt = count( $this->location ); - if( 0 >= $cnt ) - return; + if( empty( $this->location )) return FALSE; + if( empty( $this->location['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'LOCATION' ) : FALSE; $attributes = $this->_createParams( $this->location['params'], array( 'ALTREP', 'LANGUAGE' )); $content = $this->_strrep( $this->location['value'] ); return $this->_createElement( 'LOCATION', $attributes, $content ); @@ -2956,14 +2823,15 @@ class calendarComponent { * set calendar component property location ' * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param array params optional - * @return void + * @return bool */ function setLocation( $value, $params=FALSE ) { - $this->location['value'] = $value; - $this->location['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->location = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -2973,13 +2841,13 @@ class calendarComponent { * creates formatted output for calendar component property organizer * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createOrganizer() { - $cnt = count( $this->organizer ); - if( 0 >= $cnt ) - return; + if( empty( $this->organizer )) return FALSE; + if( empty( $this->organizer['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'ORGANIZER' ) : FALSE; $attributes = $this->_createParams( $this->organizer['params'] , array( 'CN', 'DIR', 'LANGUAGE', 'SENT-BY' )); $content = 'MAILTO:'.$this->organizer['value']; @@ -2989,20 +2857,21 @@ class calendarComponent { * set calendar component property organizer * * @author Kjell-Inge Gustafsson - * @since 2.0.9 - 2007-06-30 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param array params optional - * @return void + * @return bool */ function setOrganizer( $value, $params=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; $value = str_replace ( 'MAILTO:', '', $value ); $value = str_replace ( 'mailto:', '', $value ); - $this->organizer['value'] = $value; - $this->organizer['params'] = $this->_setParams( $params ); - if( isset($this->organizer['params']['SENT-BY'] )) { + $this->organizer = array( 'value' => $value, 'params' => $this->_setParams( $params )); + if( isset( $this->organizer['params']['SENT-BY'] )) { if( 'MAILTO' == strtoupper( substr( $this->organizer['params']['SENT-BY'], 0, 6 ))) $this->organizer['params']['SENT-BY'] = substr( $this->organizer['params']['SENT-BY'], 7 ); } + return TRUE; } /*********************************************************************************/ /** @@ -3012,13 +2881,13 @@ class calendarComponent { * creates formatted output for calendar component property percent-complete * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @return string */ function createPercentComplete() { - $cnt = count( $this->percentcomplete ); - if( 0 >= $cnt ) - return; + if( empty( $this->percentcomplete )) return FALSE; + if( empty( $this->percentcomplete['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'PERCENT-COMPLETE' ) : FALSE; $attributes = $this->_createParams( $this->percentcomplete['params'] ); return $this->_createElement( 'PERCENT-COMPLETE', $attributes, $this->percentcomplete['value'] ); } @@ -3026,14 +2895,15 @@ class calendarComponent { * set calendar component property percent-complete * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param int $value * @param array $params optional - * @return void + * @return bool */ function setPercentComplete( $value, $params=FALSE ) { - $this->percentcomplete['value'] = $value; - $this->percentcomplete['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->percentcomplete = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3043,13 +2913,13 @@ class calendarComponent { * creates formatted output for calendar component property priority * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createPriority() { - $cnt = count( $this->priority ); - if( 0 >= $cnt ) - return; + if( empty( $this->priority )) return FALSE; + if( empty( $this->priority['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'PRIORITY' ) : FALSE; $attributes = $this->_createParams( $this->priority['params'] ); return $this->_createElement( 'PRIORITY', $attributes, $this->priority['value'] ); } @@ -3057,14 +2927,15 @@ class calendarComponent { * set calendar component property priority * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param int $value * @param array $params optional - * @return void + * @return bool */ function setPriority( $value, $params=FALSE ) { - $this->priority['value'] = $value; - $this->priority['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->priority = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3074,44 +2945,43 @@ class calendarComponent { * creates formatted output for calendar component property rdate * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-13 - * @param bool $localtime optional, default FALSE + * @since 2.4.16 - 2008-10-26 * @return string */ - function createRdate( $localtime=FALSE ) { - $cnt = count( $this->rdate ); - if( 0 >= $cnt ) - return; + function createRdate() { + if( empty( $this->rdate )) return FALSE; + $utctime = ( in_array( $this->objName, array( 'vtimezone', 'standard', 'daylight' ))) ? TRUE : FALSE; $output = null; + if( $utctime ) + unset( $this->rdate['params']['TZID'] ); foreach( $this->rdate as $theRdate ) { + if( empty( $theRdate['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'RDATE' ); + continue; + } + if( $utctime ) + unset( $theRdate['params']['TZID'] ); $attributes = $this->_createParams( $theRdate['params'] ); $cnt = count( $theRdate['value'] ); $content = null; $rno = 1; - foreach( $theRdate['value'] as $rpix =>$rdatePart ) { + foreach( $theRdate['value'] as $rpix => $rdatePart ) { $contentPart = null; if( is_array( $rdatePart ) && - ( 2 == count( $rdatePart )) && - array_key_exists( '0', $rdatePart ) && - array_key_exists( '1', $rdatePart )) { // PERIOD - if( $localtime ) + isset( $theRdate['params']['VALUE'] ) && ( 'PERIOD' == $theRdate['params']['VALUE'] )) { // PERIOD + if( $utctime ) unset( $rdatePart[0]['tz'] ); - $formatted = $this->_format_date_time( $rdatePart[0]); - if( isset( $theRdate['params']['TZID'] )) + $formatted = $this->_format_date_time( $rdatePart[0]); // PERIOD part 1 + if( $utctime || !empty( $theRdate['params']['TZID'] )) $formatted = str_replace( 'Z', '', $formatted); if( 0 < $rpix ) { - if( isset( $rdatePart[0]['tz'] ) && - ( ctype_digit( substr( $rdatePart[0]['tz'], -4 )) || - ( 'Z' == $rdatePart[0]['tz'] ))) { - if( 'Z' != substr( $formatted, -1 )) - $formatted .= 'Z'; + if( !empty( $rdatePart[0]['tz'] ) && $this->_isOffset( $rdatePart[0]['tz'] )) { + if( 'Z' != substr( $formatted, -1 )) $formatted .= 'Z'; } else $formatted = str_replace( 'Z', '', $formatted ); } $contentPart .= $formatted; - if( 1 == $rno ) - $attributes .= $this->intAttrDelimiter.'VALUE=PERIOD'; $contentPart .= '/'; $cnt2 = count( $rdatePart[1]); if( array_key_exists( 'year', $rdatePart[1] )) { @@ -3126,16 +2996,13 @@ class calendarComponent { isset( $rdatePart[1]['year'] ) && isset( $rdatePart[1]['month'] ) && isset( $rdatePart[1]['day'] )) { - if( $localtime ) + if( $utctime ) unset( $rdatePart[1]['tz'] ); - $formatted = $this->_format_date_time( $rdatePart[1] ); - if( isset( $theRdate['params']['TZID'] )) + $formatted = $this->_format_date_time( $rdatePart[1] ); // PERIOD part 2 + if( $utctime || !empty( $theRdate['params']['TZID'] )) $formatted = str_replace( 'Z', '', $formatted); - if( isset( $rdatePart[0]['tz'] ) && - ( ctype_digit( substr( $rdatePart[0]['tz'], -4 )) || - ( 'Z' == $rdatePart[0]['tz'] ))) { - if( 'Z' != substr( $formatted, -1 )) - $formatted .= 'Z'; + if( !empty( $rdatePart[0]['tz'] ) && $this->_isOffset( $rdatePart[0]['tz'] )) { + if( 'Z' != substr( $formatted, -1 )) $formatted .= 'Z'; } else $formatted = str_replace( 'Z', '', $formatted ); @@ -3145,18 +3012,14 @@ class calendarComponent { $contentPart .= $this->_format_duration( $rdatePart[1] ); } } // PERIOD end - else { // single date start - if( $localtime ) + else { // SINGLE date start + if( $utctime ) unset( $rdatePart['tz'] ); $formatted = $this->_format_date_time( $rdatePart); - if( isset( $theRdate['params']['TZID'] )) + if( $utctime || !empty( $theRdate['params']['TZID'] )) $formatted = str_replace( 'Z', '', $formatted); - if( 0 < $rpix ) { - $firstPart = ( 2 == count( $theRdate['value'][0] )) - ? $theRdate['value'][0][0] : $theRdate['value'][0]; - if( isset( $firstPart['tz'] ) && - ( ctype_digit( substr( $firstPart['tz'], -4 )) || - ( 'Z' == $firstPart['tz'] ))) { + if( !$utctime && ( 0 < $rpix )) { + if( !empty( $theRdate['value'][0]['tz'] ) && $this->_isOffset( $theRdate['value'][0]['tz'] )) { if( 'Z' != substr( $formatted, -1 )) $formatted .= 'Z'; } @@ -3178,189 +3041,100 @@ class calendarComponent { * set calendar component property rdate * * @author Kjell-Inge Gustafsson - * @since 2.2.14 - 2007-10-30 + * @since 2.5.1 - 2008-11-07 * @param array $rdates - * @param array $params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setRdate( $rdates, $params=FALSE ) { - $input = array(); - $input['params'] = $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' )); - $this->_existRem( $input['params'], 'VALUE', 'PERIOD' ); - $parno = ( isset( $input['params']['TZID'] )) ? 6 : null; - $parno = ( !$parno ) ? $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7 ) : null; - $parno = ( !$parno ) ? $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ) : 6; - $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME' ); - foreach( $rdates as $theRdate ) { - // echo 'setRdate in '; print_r ( $theRdate ); echo "
\n"; // test ## + function setRdate( $rdates, $params=FALSE, $index=FALSE ) { + if( empty( $rdates )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->_setMval( $this->rdate, null, $params, FALSE, $index ); + return TRUE; + } + else + return FALSE; + } + $input = array( 'params' => $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' ))); + if( in_array( $this->objName, array( 'vtimezone', 'standard', 'daylight' ))) { + unset( $input['params']['TZID'] ); + $input['params']['VALUE'] = 'DATE-TIME'; + } + /* check if PERIOD, if not set */ + if((!isset( $input['params']['VALUE'] ) || !in_array( $input['params']['VALUE'], array( 'DATE', 'PERIOD' ))) && + isset( $rdates[0] ) && is_array( $rdates[0] ) && ( 2 == count( $rdates[0] )) && + isset( $rdates[0][0] ) && isset( $rdates[0][1] ) && !isset( $rdates[0]['timestamp'] ) && + (( is_array( $rdates[0][0] ) && ( isset( $rdates[0][0]['timestamp'] ) || + $this->_isArrayDate( $rdates[0][0] ))) || + ( is_string( $rdates[0][0] ) && ( 8 <= strlen( trim( $rdates[0][0] ))))) && + ( is_array( $rdates[0][1] ) || ( is_string( $rdates[0][1] ) && ( 3 <= strlen( trim( $rdates[0][1] )))))) + $input['params']['VALUE'] = 'PERIOD'; + /* check 1:st date, upd. $parno (opt) and save ev. timezone **/ + $date = reset( $rdates ); + if( isset( $input['params']['VALUE'] ) && ( 'PERIOD' == $input['params']['VALUE'] )) // PERIOD + $date = reset( $date ); + $this->_chkdatecfg( $date, $parno, $input['params'] ); + if( in_array( $this->objName, array( 'vtimezone', 'standard', 'daylight' ))) + unset( $input['params']['TZID'] ); + $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME' ); // remove default + foreach( $rdates as $rpix => $theRdate ) { $inputa = null; if( is_array( $theRdate )) { - if(( 2 == count( $theRdate )) && - array_key_exists( '0', $theRdate ) && - array_key_exists( '1', $theRdate ) && - !array_key_exists( 'timestamp', $theRdate )) { // PERIOD + if( isset( $input['params']['VALUE'] ) && ( 'PERIOD' == $input['params']['VALUE'] )) { // PERIOD foreach( $theRdate as $rix => $rPeriod ) { - // echo 'setRdate i2 '; print_r ( $rPeriod ); echo "
\n"; // test ## if( is_array( $rPeriod )) { - // echo 'setRdate i3 '; print_r ( $rPeriod ); echo "
\n"; // test ## - if (( 1 == count( $rPeriod )) && - ( 8 <= strlen( reset( $rPeriod )))) { // text-date - // echo 'setRdate i4 '; print_r ( $rPeriod ); echo "
\n"; // test ## - $inputab = $this->_date_time_string( reset( $rPeriod ), $parno ); - if ( isset( $input['params']['TZID'] )) - $inputab['tz'] = (string) $input['params']['TZID']; - elseif( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - else - unset( $inputab['tz'] ); - $parno = ( !isset( $parno )) ? count( $inputab ) : $parno; - if(( 7 == $parno ) && !isset( $inputab['tz'] )) - $inputab['tz'] = 'Z'; - if( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - $inputa[] = $inputab; - } - elseif (((3 == count( $rPeriod )) && ( $rix < 1 )) || - ( 6 == count( $rPeriod )) || - ( 7 == count( $rPeriod )) || - ( array_key_exists( 'year', $rPeriod ))) { // date[-time] (only 1st rperiod) - if( !isset( $parno ) && 3 < count( $rPeriod )) - $parno = 7; - $inputab = $this->_date_time_array( $rPeriod, $parno ); - if ( isset( $input['params']['TZID'] )) - $inputab['tz'] = (string) $input['params']['TZID']; - elseif( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - else - unset( $inputab['tz'] ); - $parno = ( !isset( $parno )) ? count( $inputab ) : $parno; - if(( 7 == $parno ) && !isset( $inputab['tz'] )) - $inputab['tz'] = 'Z'; - if( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - $inputa[] = $inputab; - } - elseif( isset( $rPeriod['timestamp'] )) { // timestamp - $tz = ( isset( $rPeriod['tz'] )) ? ' '.$rPeriod['tz'] : null; - $tz = ( isset( $input['params']['TZID'] )) ? ' '.$input['params']['TZID'] : $tz; - if( !isset( $parno )) $parno = ( !empty( $tz )) ? 7 : 6; - $inputab = $this->_date_time_string( date( 'Y-m-d H:i:s', $rPeriod['timestamp'] ).$tz, $parno ); - if(( 7 == $parno ) && !isset( $inputab['tz'] )) - $inputab['tz'] = 'Z'; - if( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - $inputa[] = $inputab; - } - else { // array format duration - $inputa[] = $this->_duration_array( $rPeriod ); - } + if( $this->_isArrayTimestampDate( $rPeriod )) // timestamp + $inputab = ( isset( $rPeriod['tz'] )) ? $this->_timestamp2date( $rPeriod, $parno ) : $this->_timestamp2date( $rPeriod, 6 ); + elseif( $this->_isArrayDate( $rPeriod )) + $inputab = ( 3 < count ( $rPeriod )) ? $this->_date_time_array( $rPeriod, $parno ) : $this->_date_time_array( $rPeriod, 6 ); + elseif (( 1 == count( $rPeriod )) && ( 8 <= strlen( reset( $rPeriod )))) // text-date + $inputab = $this->_date_time_string( reset( $rPeriod ), $parno ); + else // array format duration + $inputab = $this->_duration_array( $rPeriod ); } - elseif(( 3 <= strlen( trim( $rPeriod ))) && // string format duration + elseif(( 3 <= strlen( trim( $rPeriod ))) && // string format duration ( in_array( $rPeriod{0}, array( 'P', '+', '-' )))) { if( 'P' != $rPeriod{0} ) - $rPeriod = substr( $rPeriod, 1 ); - $inputa[] = $this->_duration_string( $rPeriod ); - } - elseif( 8 <= strlen( trim( $rPeriod ))) { // ex. 2006-08-03 10:12:18 - $tz = ( isset( $input['params']['TZID'] )) ? ' '.$input['params']['TZID'] : ''; - $inputab = $this->_date_time_string( $rPeriod.$tz, $parno ); - if ( isset( $input['params']['TZID'] )) - $inputab['tz'] = (string) $input['params']['TZID']; - elseif( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - else - unset( $inputab['tz'] ); - $inputa[] = $inputab; - $parno = ( !isset( $parno )) ? count( $inputab ) : $parno; + $rPeriod = substr( $rPeriod, 1 ); + $inputab = $this->_duration_string( $rPeriod ); } + elseif( 8 <= strlen( trim( $rPeriod ))) // text date ex. 2006-08-03 10:12:18 + $inputab = $this->_date_time_string( $rPeriod, $parno ); + if( isset( $input['params']['TZID'] ) || + ( isset( $inputab['tz'] ) && !$this->_isOffset( $inputab['tz'] )) || + ( isset( $inputa[0] ) && ( !isset( $inputa[0]['tz'] ))) || + ( isset( $inputa[0]['tz'] ) && !$this->_isOffset( $inputa[0]['tz'] ))) + unset( $inputab['tz'] ); + $inputa[] = $inputab; } - } - elseif ( array_key_exists( 'timestamp', $theRdate )) { // timestamp - $tz = ( isset( $theRdate['tz'] )) ? ' '.$theRdate['tz'] : null; - $tz = ( isset( $input['params']['TZID'] )) ? ' '.$input['params']['TZID'] : $tz; - if( !isset( $parno )) $parno = ( !empty( $tz )) ? 7 : 6; - $inputab = $this->_date_time_string( date( 'Y-m-d H:i:s', $theRdate['timestamp'] ).$tz, $parno ); - if(( 7 == $parno ) && !isset( $inputab['tz'] )) - $inputab['tz'] = 'Z'; - if( isset( $inputab['tz'] )) - $inputab['tz'] = (string) $inputab['tz']; - $inputa = $inputab; - } - elseif (( in_array( count( $theRdate ), array( 3, 4, 6, 7 ))) || - ( array_key_exists( 'year', $theRdate ))) { // date[-time] - if( isset( $input['params']['TZID'] )) - $theRdate['tz'] = $input['params']['TZID']; - elseif( !isset( $theRdate['tz'] )) { - if(( 7 == count( $theRdate )) && isset( $theRdate[6] )) { - $theRdate['tz'] = $theRdate[6]; - unset( $theRdate[6] ); - } - elseif(( 4 == count( $theRdate )) && isset( $theRdate[3] )) { - $theRdate['tz'] = $theRdate[3]; - unset( $theRdate[3] ); - } - } - if( !isset( $parno ) && 3 < count( $theRdate )) - $parno = ( isset( $theRdate['tz'] )) ? 7 : count( $theRdate ); - elseif( !isset( $parno )) - $parno = 3; + } // PERIOD end + elseif ( $this->_isArrayTimestampDate( $theRdate )) // timestamp + $inputa = $this->_timestamp2date( $theRdate, $parno ); + else // date[-time] $inputa = $this->_date_time_array( $theRdate, $parno ); - if(( 7 == $parno ) && !isset( $inputa['tz'] )) - $inputa['tz'] = 'Z'; - if( isset( $inputa['tz'] )) - $inputa['tz'] = (string) $inputa['tz']; - } } - elseif( 8 <= strlen( trim( $theRdate ))) { // ex. 2006-08-03 10:12:18 + elseif( 8 <= strlen( trim( $theRdate ))) // text date ex. 2006-08-03 10:12:18 $inputa = $this->_date_time_string( $theRdate, $parno ); - if( isset( $input['params']['TZID'] )) - $inputa['tz'] = (string) $input['params']['TZID']; + if( !isset( $input['params']['VALUE'] ) || ( 'PERIOD' != $input['params']['VALUE'] )) { // no PERIOD + if( 3 == $parno ) + unset( $inputa['hour'], $inputa['min'], $inputa['sec'], $inputa['tz'] ); elseif( isset( $inputa['tz'] )) $inputa['tz'] = (string) $inputa['tz']; - else + if( isset( $input['params']['TZID'] ) || + ( isset( $inputa['tz'] ) && !$this->_isOffset( $inputa['tz'] )) || + ( isset( $input['value'][0] ) && ( !isset( $input['value'][0]['tz'] ))) || + ( isset( $input['value'][0]['tz'] ) && !$this->_isOffset( $input['value'][0]['tz'] ))) unset( $inputa['tz'] ); - $parno = ( !isset( $parno )) ? count( $inputa ) : $parno; - if(( 7 == $parno ) && !isset( $inputa['tz'] )) - $inputa['tz'] = 'Z'; - if( isset( $inputa['tz'] )) - $inputa['tz'] = (string) $inputa['tz']; - // echo 'setRdate inputa single string '; print_r ( $inputa ); echo "
\n"; // test ## } $input['value'][] = $inputa; } - if( 0 < count( $input['value'] )) { - // echo 'setRdate ut 1 '; print_r ( $input ); echo "
\n"; // test ## - if( 3 == $parno ) { - $input['params']['VALUE'] = 'DATE'; - foreach( $input['value'] as $eix => $inputa ) - unset( $input['value'][$eix]['tz'] ); - unset( $input['params']['TZID'] ); - } - if( empty( $input['value'][0]['tz'] ) || - ( $input['value'][0]['tz'] == 'Z' )) - $dummy = TRUE; - elseif( in_array($input['value'][0]['tz']{0}, array( '+', '-' )) && - ctype_digit( substr( $input['value'][0]['tz'], 1 ))) - $dummy = TRUE; - elseif( ctype_digit( $input['value'][0]['tz'] )) - $dummy = TRUE; - elseif( isset( $input['value'][0]['tz'] )) { - $input['params']['TZID'] = $input['value'][0]['tz']; - foreach( $input['value'] as $eix => $inputa ) { - if( !empty( $input['value'][0]['tz'] ) && - ( $input['value'][0]['tz'] != 'Z' ) && - ( !( in_array( $input['value'][0]['tz']{0}, array( '+', '-' )) && - ctype_digit( substr( $input['value'][0]['tz'], 1 ))) && - !ctype_digit( $input['value'][0]['tz'] ) ) ) - unset( $input['value'][$eix]['tz'] ); - } - } - elseif( isset( $input['params']['TZID'] )) - unset( $input['params']['TZID'] ); - - $this->rdate[] = $input; - // echo 'setRdate ut 2 '; print_r ( $input ); echo "
\n"; // test ## + if( 3 == $parno ) { + $input['params']['VALUE'] = 'DATE'; + unset( $input['params']['TZID'] ); } + $this->_setMval( $this->rdate, $input['value'], $input['params'], FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3370,13 +3144,13 @@ class calendarComponent { * creates formatted output for calendar component property recurrence-id * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-26 + * @since 2.4.8 - 2008-10-21 * @return string */ function createRecurrenceid() { - $cnt = count( $this->recurrenceid ); - if( 0 >= $cnt ) - return; + if( empty( $this->recurrenceid )) return FALSE; + if( empty( $this->recurrenceid['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'RECURRENCE-ID' ) : FALSE; $formatted = $this->_format_date_time( $this->recurrenceid['value'] ); $attributes = $this->_createParams( $this->recurrenceid['params'] ); return $this->_createElement( 'RECURRENCE-ID', $attributes, $formatted ); @@ -3385,7 +3159,7 @@ class calendarComponent { * set calendar component property recurrence-id * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.8 - 2008-10-23 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -3393,10 +3167,19 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional - * @return void + * @return bool */ function setRecurrenceid( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE ) { + if( empty( $year )) { + if( $this->getConfig( 'allowEmpty' )) { + $this->recurrenceid = array( 'value' => null, 'params' => null ); + return TRUE; + } + else + return FALSE; + } $this->recurrenceid = $this->_setDate( $year, $month, $day, $hour, $min, $sec, $tz, $params ); + return TRUE; } /*********************************************************************************/ /** @@ -3406,17 +3189,21 @@ class calendarComponent { * creates formatted output for calendar component property related-to * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.8 - 2008-10-23 * @return string */ function createRelatedTo() { - $cnt = count( $this->relatedto ); - if( 0 >= $cnt ) - return; + if( empty( $this->relatedto )) return FALSE; $output = null; foreach( $this->relatedto as $relation ) { + if( empty( $relation['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output.= $this->_createElement( 'RELATED-TO', $this->_createParams( $relation['params'] )); + continue; + } $attributes = $this->_createParams( $relation['params'] ); - $content = '<'.$this->_strrep( $relation['value'] ).'>'; + $content = ( 'xcal' != $this->format ) ? '<' : ''; + $content .= $this->_strrep( $relation['value'] ); + $content .= ( 'xcal' != $this->format ) ? '>' : ''; $output .= $this->_createElement( 'RELATED-TO', $attributes, $content ); } return $output; @@ -3425,23 +3212,19 @@ class calendarComponent { * set calendar component property related-to * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-24 + * @since 2.5.1 - 2008-11-07 * @param float $relid - * @param array $params optional - * @return void + * @param array $params, optional + * @param index $index, optional + * @return bool */ - function setRelatedTo( $relid, $params=FALSE ) { - $relation = array(); - if(( '<' == substr( $relid, 0, 1 )) && - ( '>' == substr( $relid, -1 ))) - $relid = substr( $relid, 1, ( strlen( $relid ) - 2 )); - $relation['value'] = $relid; - $relation['params'] = $this->_setParams( $params ); - // remove default - if( isset( $relation['params']['RELTYPE'] ) && - ( strtoupper( $relation['params']['RELTYPE'] ) == 'PARENT' )) - unset( $relation['params']['RELTYPE'] ); - $this->relatedto[] = $relation; + function setRelatedTo( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + if(( '<' == substr( $value, 0, 1 )) && ( '>' == substr( $value, -1 ))) + $value = substr( $value, 1, ( strlen( $value ) - 2 )); + $this->_existRem( $params, 'RELTYPE', 'PARENT', TRUE ); // remove default + $this->_setMval( $this->relatedto, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3451,13 +3234,13 @@ class calendarComponent { * creates formatted output for calendar component property repeat * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createRepeat() { - $cnt = count( $this->repeat ); - if( 0 >= $cnt ) - return; + if( empty( $this->repeat )) return FALSE; + if( empty( $this->repeat['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'REPEAT' ) : FALSE; $attributes = $this->_createParams( $this->repeat['params'] ); return $this->_createElement( 'REPEAT', $attributes, $this->repeat['value'] ); } @@ -3465,14 +3248,15 @@ class calendarComponent { * set calendar component property transp * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param array $params optional * @return void */ function setRepeat( $value, $params=FALSE ) { - $this->repeat['value'] = $value; - $this->repeat['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->repeat = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3481,21 +3265,23 @@ class calendarComponent { /** * creates formatted output for calendar component property request-status * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-16 + * @since 2.4.8 - 2008-10-23 * @return string */ function createRequestStatus() { - $cnt = count( $this->requeststatus ); - if( 0 >= $cnt ) - return; + if( empty( $this->requeststatus )) return FALSE; $output = null; foreach( $this->requeststatus as $rstat ) { - $attributes = $this->_createParams( $rstat['params'], array( 'LANGUAGE' )); - $content = number_format( (float) $rstat['value']['statcode'], 2, '.', ''); - $content .= ';'.$this->_strrep( $rstat['value']['text'] ); + if( empty( $rstat['value']['statcode'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'REQUEST-STATUS' ); + continue; + } + $attributes = $this->_createParams( $rstat['params'], array( 'LANGUAGE' )); + $content = number_format( (float) $rstat['value']['statcode'], 2, '.', ''); + $content .= ';'.$this->_strrep( $rstat['value']['text'] ); if( isset( $rstat['value']['extdata'] )) - $content .= ';'.$this->_strrep( $rstat['value']['extdata'] ); - $output .= $this->_createElement( 'REQUEST-STATUS', $attributes, $content ); + $content .= ';'.$this->_strrep( $rstat['value']['extdata'] ); + $output .= $this->_createElement( 'REQUEST-STATUS', $attributes, $content ); } return $output; } @@ -3503,21 +3289,21 @@ class calendarComponent { * set calendar component property request-status * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-16 + * @since 2.5.1 - 2008-11-05 * @param float $statcode * @param string $text - * @param string $extdata optional - * @param array params optional - * @return void + * @param string $extdata, optional + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setRequestStatus( $statcode, $text, $extdata=FALSE, $params=FALSE ) { - $input = array(); - $input['value']['statcode'] = $statcode; - $input['value']['text'] = $text; + function setRequestStatus( $statcode, $text, $extdata=FALSE, $params=FALSE, $index=FALSE ) { + if( empty( $statcode ) || empty( $text )) if( $this->getConfig( 'allowEmpty' )) $statcode = $text = null; else return FALSE; + $input = array( 'statcode' => $statcode, 'text' => $text ); if( $extdata ) - $input['value']['extdata'] = $extdata; - $input['params'] = $this->_setParams( $params); - $this->requeststatus[] = $input; + $input['extdata'] = $extdata; + $this->_setMval( $this->requeststatus, $input, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3527,23 +3313,26 @@ class calendarComponent { * creates formatted output for calendar component property resources * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-24 + * @since 2.4.8 - 2008-10-23 * @return string */ function createResources() { - if( 0 >= count( $this->resources )) - return; + if( empty( $this->resources )) return FALSE; $output = null; foreach( $this->resources as $resource ) { - $attributes = $this->_createParams( $resource['params'], array( 'ALTREP', 'LANGUAGE' )); + if( empty( $resource['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'RESOURCES' ); + continue; + } + $attributes = $this->_createParams( $resource['params'], array( 'ALTREP', 'LANGUAGE' )); if( is_array( $resource['value'] )) { foreach( $resource['value'] as $rix => $resourcePart ) $resource['value'][$rix] = $this->_strrep( $resourcePart ); - $content = implode( ',', $resource['value'] ); + $content = implode( ',', $resource['value'] ); } else - $content = $this->_strrep( $resource['value'] ); - $output .= $this->_createElement( 'RESOURCES', $attributes, $content ); + $content = $this->_strrep( $resource['value'] ); + $output .= $this->_createElement( 'RESOURCES', $attributes, $content ); } return $output; } @@ -3551,16 +3340,16 @@ class calendarComponent { * set calendar component property recources * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-24 + * @since 2.5.1 - 2008-11-05 * @param mixed $value - * @param array params optional - * @return void + * @param array $params, optional + * @param integer $index, optional + * @return bool */ - function setResources( $value, $params=FALSE ) { - $input = array(); - $input['value'] = $value; - $input['params'] = $this->_setParams( $params ); - $this->resources[] = $input; + function setResources( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->resources, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3570,55 +3359,27 @@ class calendarComponent { * creates formatted output for calendar component property rrule * * @author Kjell-Inge Gustafsson - * @since 0.7.43 - 2006-09-15 + * @since 2.4.8 - 2008-10-21 * @return string */ function createRrule() { - $cnt = count( $this->rrule ); - if( 0 >= $cnt ) - return; + if( empty( $this->rrule )) return FALSE; return $this->_format_recur( 'RRULE', $this->rrule ); } /** * set calendar component property rrule * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.5.1 - 2008-11-05 * @param array $rruleset - * @param array $params optional + * @param array $params, optional + * @param integer $index, optional * @return void */ - function setRrule( $rruleset, $params=FALSE ) { - $exrule = array(); - foreach( $rruleset as $rrulelabel => $rrulevalue ) { - $rrulelabel = strtoupper( $rrulelabel ); - if( 'UNTIL' != $rrulelabel ) - $rrule['value'][$rrulelabel] = $rrulevalue; - elseif( is_array( $rrulevalue ) && - (( 3 == count( $rrulevalue )) || - ( 6 == count( $rrulevalue )) || - ( 7 == count( $rrulevalue )) || - ( array_key_exists( 'year', $rrulevalue )))) { - $parno = ( 3 < count( $rrulevalue )) ? 7 : 3 ; // datetime / date - $date = $this->_date_time_array( $rrulevalue, $parno ); - if(( 3 < count( $date )) && !isset( $date['tz'] )) - $date['tz'] = 'Z'; - $rrule['value'][$rrulelabel] = $date; - } - elseif( is_array( $rrulevalue ) && isset( $rrulevalue['timestamp'] )) { - $date = $this->_date_time_string( date( 'Y-m-d H:i:s', $rrulevalue['timestamp'] ), 6 ); - $date['tz'] = 'Z'; - $rrule['value'][$rrulelabel] = $date; - } - elseif( 8 <= strlen( trim( $rrulevalue ))) { // ex. 2006-08-03 10:12:18 - $date = $this->_date_time_string( $rrulevalue ); - if(( 3 < count( $date )) && !isset( $date['tz'] )) - $date['tz'] = 'Z'; - $rrule['value'][$rrulelabel] = $date; - } - } - $rrule['params'] = $this->_setParams( $params ); - $this->rrule[] = $rrule; + function setRrule( $rruleset, $params=FALSE, $index=FALSE ) { + if( empty( $rruleset )) if( $this->getConfig( 'allowEmpty' )) $rruleset = null; else return FALSE; + $this->_setMval( $this->rrule, $this->_setRexrule( $rruleset ), $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3631,25 +3392,25 @@ class calendarComponent { * @return string */ function createSequence() { - $cnt = count( $this->sequence ); - if( 0 >= $cnt ) - return; + if( empty( $this->sequence )) return FALSE; + if( empty( $this->sequence['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'SEQUENCE' ) : FALSE; $attributes = $this->_createParams( $this->sequence['params'] ); return $this->_createElement( 'SEQUENCE', $attributes, $this->sequence['value'] ); } /** * set calendar component property sequence * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-04-25 + * @since 2.4.8 - 2008-11-04 * @param int $value optional * @param array $params optional - * @return void + * @return bool */ function setSequence( $value=FALSE, $params=FALSE ) { - if( !$value ) - $value = $this->getProperty( 'sequence' ) + 1; - $this->sequence['value'] = $value; - $this->sequence['params'] = $this->_setParams( $params ); + if( empty( $value )) + $value = ( isset( $this->sequence['value'] ) && ( 0 < $this->sequence['value'] )) ? $this->sequence['value'] + 1 : 1; + $this->sequence = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3659,13 +3420,13 @@ class calendarComponent { * creates formatted output for calendar component property status * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createStatus() { - $cnt = count( $this->status ); - if( 0 >= $cnt ) - return; + if( empty( $this->status )) return FALSE; + if( empty( $this->status['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'STATUS' ) : FALSE; $attributes = $this->_createParams( $this->status['params'] ); return $this->_createElement( 'STATUS', $attributes, $this->status['value'] ); } @@ -3673,14 +3434,15 @@ class calendarComponent { * set calendar component property status * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param array $params optional - * @return void + * @return bool */ function setStatus( $value, $params=FALSE ) { - $this->status['value'] = $value; - $this->status['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->status = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3690,13 +3452,13 @@ class calendarComponent { * creates formatted output for calendar component property summary * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createSummary() { - $cnt = count( $this->summary ); - if( 0 >= $cnt ) - return; + if( empty( $this->summary )) return FALSE; + if( empty( $this->summary['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'SUMMARY' ) : FALSE; $attributes = $this->_createParams( $this->summary['params'], array( 'ALTREP', 'LANGUAGE' )); $content = $this->_strrep( $this->summary['value'] ); return $this->_createElement( 'SUMMARY', $attributes, $content ); @@ -3705,14 +3467,15 @@ class calendarComponent { * set calendar component property summary * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setSummary( $value, $params=FALSE ) { - $this->summary['value'] = $value; - $this->summary['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->summary = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3722,13 +3485,13 @@ class calendarComponent { * creates formatted output for calendar component property transp * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTransp() { - $cnt = count( $this->transp ); - if( 0 >= $cnt ) - return; + if( empty( $this->transp )) return FALSE; + if( empty( $this->transp['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TRANSP' ) : FALSE; $attributes = $this->_createParams( $this->transp['params'] ); return $this->_createElement( 'TRANSP', $attributes, $this->transp['value'] ); } @@ -3736,14 +3499,15 @@ class calendarComponent { * set calendar component property transp * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setTransp( $value, $params=FALSE ) { - $this->transp['value'] = $value; - $this->transp['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->transp = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3753,20 +3517,20 @@ class calendarComponent { * creates formatted output for calendar component property trigger * * @author Kjell-Inge Gustafsson - * @since 0.9.19 - 2007-03-27 + * @since 2.4.16 - 2008-10-21 * @return string */ function createTrigger() { - $cnt = count( $this->trigger ); - if( 0 >= $cnt ) - return; + if( empty( $this->trigger )) return FALSE; + if( empty( $this->trigger['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TRIGGER' ) : FALSE; $content = $attributes = null; if( isset( $this->trigger['value']['year'] ) && isset( $this->trigger['value']['month'] ) && isset( $this->trigger['value']['day'] )) $content .= $this->_format_date_time( $this->trigger['value'] ); else { - if( TRUE !== $this->trigger['value']['relatedstart'] ) + if( TRUE !== $this->trigger['value']['relatedStart'] ) $attributes .= $this->intAttrDelimiter.'RELATED=END'; if( $this->trigger['value']['before'] ) $content .= '-'; @@ -3779,7 +3543,7 @@ class calendarComponent { * set calendar component property trigger * * @author Kjell-Inge Gustafsson - * @since 2.1.1 - 2007-07-07 + * @since 2.4.16 - 2008-11-04 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -3787,119 +3551,94 @@ class calendarComponent { * @param int $hour optional * @param int $min optional * @param int $sec optional - * @param bool $relatedEnd optional - * @param bool $after optional - * @param string $tz optional + * @param bool $relatedStart optional + * @param bool $before optional * @param array $params optional - * @return void - * @toto fix is_int + * @return bool */ - function setTrigger( $year=FALSE, $month=FALSE, $day=FALSE, $week=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $relatedEnd=FALSE, $after=FALSE, $tz=FALSE, $params=FALSE ) { - if( is_array( $year ) && array_key_exists( 'timestamp', $year )) { // timestamp - $params = $this->_setParams( $month ); - $this->_existRem( $params, 'VALUE', 'DATE-TIME' ); - if( isset( $params['TZID'] )) { - $year['tz'] = $params['TZID']; - unset( $params['TZID'] ); + function setTrigger( $year, $month=null, $day=null, $week=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $relatedStart=TRUE, $before=TRUE, $params=FALSE ) { + if( empty( $year ) && empty( $month ) && empty( $day ) && empty( $week ) && empty( $hour ) && empty( $min ) && empty( $sec )) + if( $this->getConfig( 'allowEmpty' )) { + $this->trigger = array( 'value' => null, 'params' => $this->_setParams( $params ) ); + return TRUE; } - $tz = ( isset( $year['tz'] )) ? ' '.$year['tz'] : null; - $parno = ( isset( $tz )) ? 7 : 6; - $date = $this->_date_time_string( date( 'Y-m-d H:i:s', $year['timestamp'] ).$tz, $parno ); + else + return FALSE; + if( $this->_isArrayTimestampDate( $year )) { // timestamp + $params = $this->_setParams( $month ); + $date = $this->_timestamp2date( $year, 7 ); foreach( $date as $k => $v ) $$k = $v; } - elseif( is_array( $year )) { - if( array_key_exists( 'year', $year ) && - array_key_exists( 'month', $year ) && - array_key_exists( 'day', $year )) { // date-time - $params = $this->_setParams( $month ); - if( isset( $params['TZID'] )) { - $year['tz'] = $params['TZID']; - unset( $params['TZID'] ); - } - } - else { // duration - $year = $this->_duration_array( $year ); - $relatedEnd = $month; - $after = $day; - $params = $this->_setParams( $week ); + elseif( is_array( $year ) && ( is_array( $month ) || empty( $month ))) { + $params = $this->_setParams( $month ); + if(!(array_key_exists( 'year', $year ) && // exclude date-time + array_key_exists( 'month', $year ) && + array_key_exists( 'day', $year ))) { // so this must be a duration + if( isset( $params['RELATED'] ) && ( 'END' == $params['RELATED'] )) + $relatedStart = FALSE; + else + $relatedStart = ( array_key_exists( 'relatedStart', $year ) && ( TRUE !== $year['relatedStart'] )) ? FALSE : TRUE; + $before = ( array_key_exists( 'before', $year ) && ( TRUE !== $year['before'] )) ? FALSE : TRUE; } - $this->_existRem( $params, 'VALUE', 'DATE-TIME' ); - $this->_existRem( $params, 'VALUE', 'DURATION' ); $SSYY = ( array_key_exists( 'year', $year )) ? $year['year'] : null; $month = ( array_key_exists( 'month', $year )) ? $year['month'] : null; $day = ( array_key_exists( 'day', $year )) ? $year['day'] : null; $week = ( array_key_exists( 'week', $year )) ? $year['week'] : null; - $hour = ( array_key_exists( 'hour', $year )) ? $year['hour'] : null; - $min = ( array_key_exists( 'min', $year )) ? $year['min'] : null; - $sec = ( array_key_exists( 'sec', $year )) ? $year['sec'] : null; - $tz = ( array_key_exists( 'tz', $year )) ? $year['tz'] : null; + $hour = ( array_key_exists( 'hour', $year )) ? $year['hour'] : 0; //null; + $min = ( array_key_exists( 'min', $year )) ? $year['min'] : 0; //null; + $sec = ( array_key_exists( 'sec', $year )) ? $year['sec'] : 0; //null; $year = $SSYY; } - elseif( is_string($year) && !ctype_digit( (string) $year )) { // duration or date in a string + elseif(is_string( $year ) && ( is_array( $month ) || empty( $month ))) { // duration or date in a string $params = $this->_setParams( $month ); - unset( $month ); - $this->_existRem( $params, 'VALUE', 'DATE-TIME' ); // ?? - $this->_existRem( $params, 'VALUE', 'DURATION' ); if( in_array( $year{0}, array( 'P', '+', '-' ))) { // duration - if( '-' == $year{0} ) - $after = FALSE; - elseif( '+' == $year{0} ) - $after = TRUE; - elseif( 'P' == $year{0} ) - $after = TRUE; - if( 'P' != $year{0} ) - $year = substr( $year, 1 ); - $date = $this->_duration_string( $year); - } - else { - $date = $this->_date_time_string( $year, 7 ); // date - if( isset( $params['TZID'] )) { - $date['tz'] = $params['TZID']; - unset( $params['TZID'] ); - } + $relatedStart = ( isset( $params['RELATED'] ) && ( 'END' == $params['RELATED'] )) ? FALSE : TRUE; + $before = ( '-' == $year{0} ) ? TRUE : FALSE; + if( 'P' != $year{0} ) + $year = substr( $year, 1 ); + $date = $this->_duration_string( $year); } + else // date + $date = $this->_date_time_string( $year, 7 ); + unset( $year, $month, $day ); foreach( $date as $k => $v ) $$k = $v; } - else + else // single values in function input parameters $params = $this->_setParams( $params ); - if( !empty( $year ) && !empty( $month ) && !empty( $day ) ) { // date + if( !empty( $year ) && !empty( $month ) && !empty( $day )) { // date $params['VALUE'] = 'DATE-TIME'; + $hour = ( $hour ) ? $hour : 0; + $min = ( $min ) ? $min : 0; + $sec = ( $sec ) ? $sec : 0; + $this->trigger = array( 'params' => $params ); $this->trigger['value'] = array( 'year' => $year , 'month' => $month - , 'day' => $day); - $this->trigger['value']['hour'] = $hour; - $this->trigger['value']['min'] = $min; - $this->trigger['value']['sec'] = $sec; - if( !empty( $tz )) - $this->trigger['value']['tz'] = $tz; - else - $this->trigger['value']['tz'] = 'Z'; - } - else { // duration - $this->_existRem( $params, 'VALUE', 'DURATION' ); - if( $this->_existRem( $params, 'RELATED', 'END', TRUE )) - $relatedEnd = TRUE; - elseif( $this->_existRem( $params, 'RELATED', 'START', TRUE )) - $relatedEnd = FALSE; - if( !empty( $week )) { - $this->trigger['value'] = array( 'week' => $week - , 'relatedstart' => !$relatedEnd - , 'before' => !$after ); - } - else { - $this->trigger['value'] = array( 'day' => $day - , 'hour' => $hour - , 'min' => $min - , 'sec' => $sec - , 'relatedstart' => !$relatedEnd - , 'before' => !$after ); - } + , 'day' => $day + , 'hour' => $hour + , 'min' => $min + , 'sec' => $sec + , 'tz' => 'Z' ); + return TRUE; } - if( !isset( $this->trigger['value'] )) - return; - $this->trigger['params'] = $params; + elseif(( empty( $year ) && empty( $month )) && // duration + (!empty( $week ) || !empty( $day ) || !empty( $hour ) || !empty( $min ) || !empty( $sec ))) { + unset( $params['RELATED'] ); // set at output creation (END only) + unset( $params['VALUE'] ); // 'DURATION' default + $this->trigger = array( 'params' => $params ); + $relatedStart = ( FALSE !== $relatedStart ) ? TRUE : FALSE; + $before = ( FALSE !== $before ) ? TRUE : FALSE; + $this->trigger['value'] = array( 'relatedStart' => $relatedStart + , 'before' => $before ); + if( !empty( $week )) $this->trigger['value']['week'] = $week; + if( !empty( $day )) $this->trigger['value']['day'] = $day; + if( !empty( $hour )) $this->trigger['value']['hour'] = $hour; + if( !empty( $min )) $this->trigger['value']['min'] = $min; + if( !empty( $sec )) $this->trigger['value']['sec'] = $sec; + return TRUE; + } + return FALSE; } /*********************************************************************************/ /** @@ -3909,13 +3648,13 @@ class calendarComponent { * creates formatted output for calendar component property tzid * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTzid() { - $cnt = count( $this->tzid ); - if( 0 >= $cnt ) - return; + if( empty( $this->tzid )) return FALSE; + if( empty( $this->tzid['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TZID' ) : FALSE; $attributes = $this->_createParams( $this->tzid['params'] ); return $this->_createElement( 'TZID', $attributes, $this->_strrep( $this->tzid['value'] )); } @@ -3923,16 +3662,15 @@ class calendarComponent { * set calendar component property tzid * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param array $params optional - * @return void + * @return bool */ function setTzid( $value, $params=FALSE ) { - if( empty( $value )) - return; - $this->tzid['value'] = $value; - $this->tzid['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->tzid = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -3943,17 +3681,18 @@ class calendarComponent { * creates formatted output for calendar component property tzname * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTzname() { - $cnt = count( $this->tzname ); - if( 0 >= $cnt ) - return; + if( empty( $this->tzname )) return FALSE; $output = null; foreach( $this->tzname as $theName ) { - $attributes = $this->_createParams( $theName['params'], array( 'LANGUAGE' )); - $output .= $this->_createElement( 'TZNAME', $attributes, $this->_strrep( $theName['value'] )); + if( !empty( $theName['value'] )) { + $attributes = $this->_createParams( $theName['params'], array( 'LANGUAGE' )); + $output .= $this->_createElement( 'TZNAME', $attributes, $this->_strrep( $theName['value'] )); + } + elseif( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( 'TZNAME' ); } return $output; } @@ -3961,17 +3700,16 @@ class calendarComponent { * set calendar component property tzname * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.5.1 - 2008-11-05 * @param string $value - * @param string $params optional - * @return void + * @param string $params, optional + * @param integer $index, optional + * @return bool */ - function setTzname( $value, $params=FALSE ) { - if( empty( $value )) - return; - $input['value'] = $value; - $input['params'] = $this->_setParams( $params ); - $this->tzname[] = $input; + function setTzname( $value, $params=FALSE, $index=FALSE ) { + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->_setMval( $this->tzname, $value, $params, FALSE, $index ); + return TRUE; } /*********************************************************************************/ /** @@ -3981,13 +3719,13 @@ class calendarComponent { * creates formatted output for calendar component property tzoffsetfrom * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTzoffsetfrom() { - $cnt = count( $this->tzoffsetfrom ); - if( 0 >= $cnt ) - return; + if( empty( $this->tzoffsetfrom )) return FALSE; + if( empty( $this->tzoffsetfrom['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TZOFFSETFROM' ) : FALSE; $attributes = $this->_createParams( $this->tzoffsetfrom['params'] ); return $this->_createElement( 'TZOFFSETFROM', $attributes, $this->tzoffsetfrom['value'] ); } @@ -3995,16 +3733,15 @@ class calendarComponent { * set calendar component property tzoffsetfrom * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-25 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setTzoffsetfrom( $value, $params=FALSE ) { - $this->tzoffsetfrom['value'] = $value; - if( empty( $this->tzoffsetfrom['value'] )) - return; - $this->tzoffsetfrom['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->tzoffsetfrom = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -4014,13 +3751,13 @@ class calendarComponent { * creates formatted output for calendar component property tzoffsetto * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTzoffsetto() { - $cnt = count( $this->tzoffsetto ); - if( 0 >= $cnt ) - return; + if( empty( $this->tzoffsetto )) return FALSE; + if( empty( $this->tzoffsetto['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TZOFFSETTO' ) : FALSE; $attributes = $this->_createParams( $this->tzoffsetto['params'] ); return $this->_createElement( 'TZOFFSETTO', $attributes, $this->tzoffsetto['value'] ); } @@ -4028,16 +3765,15 @@ class calendarComponent { * set calendar component property tzoffsetto * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setTzoffsetto( $value, $params=FALSE ) { - $this->tzoffsetto['value'] = $value; - if( empty( $this->tzoffsetto['value'] )) - return; - $this->tzoffsetto['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->tzoffsetto = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -4047,13 +3783,13 @@ class calendarComponent { * creates formatted output for calendar component property tzurl * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createTzurl() { - $cnt = count( $this->tzurl ); - if( 0 >= $cnt ) - return; + if( empty( $this->tzurl )) return FALSE; + if( empty( $this->tzurl['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'TZURL' ) : FALSE; $attributes = $this->_createParams( $this->tzurl['params'] ); return $this->_createElement( 'TZURL', $attributes, $this->tzurl['value'] ); } @@ -4061,16 +3797,15 @@ class calendarComponent { * set calendar component property tzurl * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return boll */ function setTzurl( $value, $params=FALSE ) { - $this->tzurl['value'] = $value; - if( empty( $this->tzurl['value'] )) - return; - $this->tzurl['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->tzurl = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -4084,10 +3819,8 @@ class calendarComponent { * @return string */ function createUid() { - $cnt = count( $this->uid ); - if( 0 >= $cnt ) { + if( 0 >= count( $this->uid )) $this->_makeuid(); - } $attributes = $this->_createParams( $this->uid['params'] ); return $this->_createElement( 'UID', $attributes, $this->uid['value'] ); } @@ -4108,23 +3841,22 @@ class calendarComponent { $str = null; for( $p = 0; $p < $length; $p++ ) $unique .= $base{mt_rand( $start, $end )}; + $this->uid = array( 'params' => null ); $this->uid['value'] = $date.'-'.$unique.'@'.$this->getConfig( 'unique_id' ); - $this->uid['params'] = null; } /** * set calendar component property uid * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setUid( $value, $params=FALSE ) { - $this->uid['value'] = $value; - if( empty( $this->uid['value'] )) - return; - $this->uid['params'] = $this->_setParams( $params ); + if( empty( $value )) return FALSE; // no allowEmpty check here !!!! + $this->uid = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -4134,13 +3866,13 @@ class calendarComponent { * creates formatted output for calendar component property url * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-21 * @return string */ function createUrl() { - $cnt = count( $this->url ); - if( 0 >= $cnt ) - return; + if( empty( $this->url )) return FALSE; + if( empty( $this->url['value'] )) + return ( $this->getConfig( 'allowEmpty' )) ? $this->_createElement( 'URL' ) : FALSE; $attributes = $this->_createParams( $this->url['params'] ); return $this->_createElement( 'URL', $attributes, $this->url['value'] ); } @@ -4148,16 +3880,15 @@ class calendarComponent { * set calendar component property url * * @author Kjell-Inge Gustafsson - * @since 0.9.18 - 2007-03-18 + * @since 2.4.8 - 2008-11-04 * @param string $value * @param string $params optional - * @return void + * @return bool */ function setUrl( $value, $params=FALSE ) { - $this->url['value'] = $value; - if( empty( $this->url['value'] )) - return; - $this->url['params'] = $this->_setParams( $params ); + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $this->url = array( 'value' => $value, 'params' => $this->_setParams( $params )); + return TRUE; } /*********************************************************************************/ /** @@ -4167,14 +3898,17 @@ class calendarComponent { * creates formatted output for calendar component property x-prop * * @author Kjell-Inge Gustafsson - * @since 2.3.2 - 2007-11-25 + * @since 2.4.11 - 2008-10-22 * @return string */ function createXprop() { - if( 0 >= count( $this->xprop )) - return; - $xprop = null; + if( empty( $this->xprop )) return FALSE; + $output = null; foreach( $this->xprop as $label => $xpropPart ) { + if( empty( $xpropPart['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( $label ); + continue; + } $attributes = $this->_createParams( $xpropPart['params'], array( 'LANGUAGE' )); if( is_array( $xpropPart['value'] )) { foreach( $xpropPart['value'] as $pix => $theXpart ) @@ -4183,27 +3917,29 @@ class calendarComponent { } else $xpropPart['value'] = $this->_strrep( $xpropPart['value'] ); - $xprop .= $this->_createElement( strtoupper( $label ), $attributes, $xpropPart['value'] ); + $output .= $this->_createElement( $label, $attributes, $xpropPart['value'] ); } - return $xprop; + return $output; } /** * set calendar component property x-prop * * @author Kjell-Inge Gustafsson - * @since 2.0.7 - 2007-06-21 + * @since 2.4.11 - 2008-11-04 * @param string $label * @param mixed $value * @param array $params optional - * @return void + * @return bool */ function setXprop( $label, $value, $params=FALSE ) { - if( empty( $label ) || empty( $value )) - return; - $xprop = array( 'value' => $value ); - $toolbox = new calendarComponent(); + if( empty( $label )) return; + if( empty( $value )) if( $this->getConfig( 'allowEmpty' )) $value = null; else return FALSE; + $xprop = array( 'value' => $value ); + $toolbox = new calendarComponent(); $xprop['params'] = $toolbox->_setParams( $params ); - $this->xprop[$label] = $xprop; + if( !is_array( $this->xprop )) $this->xprop = array(); + $this->xprop[strtoupper( $label )] = $xprop; + return TRUE; } /*********************************************************************************/ /*********************************************************************************/ @@ -4250,13 +3986,13 @@ class calendarComponent { * creates formatted output for calendar component property * * @author Kjell-Inge Gustafsson - * @since 0.9.15 - 2007-01-08 + * @since 2.4.8 - 2008-10-23 * @param string $label property name * @param string $attributes property attributes * @param string $content property content (optional) * @return string */ - function _createElement( $label, $attributes, $content=FALSE ) { + function _createElement( $label, $attributes=null, $content=FALSE ) { $label = $this->_formatPropertyName( $label ); $output = $this->elementStart1.$label; $categoriesAttrLang = null; @@ -4338,31 +4074,12 @@ class calendarComponent { return $output; break; default: - $output .= $this->elementStart2; + $output .= $this->elementStart2.$this->valueInit; return $this->_size75( $output ); break; } } $output .= $this->elementStart2; - switch( $label ) { - case 'categories': - // case 'resources': ?? - $output .= $this->nl; - $items = explode(',', $content); - $content = null; - foreach( $items as $item ) - $content .= $this->_createElement( 'item', $categoriesAttrLang, $item ); // max one attribute - break; - case 'geo': - $output .= $this->nl; - list($lat, $lon) = explode(';', $content); - $content = null; - $content .= $this->_createElement( 'lat', null, $lat ); - $content .= $this->_createElement( 'lon', null, $lon ); - break; - default: - break; - } $output .= $this->valueInit.$content; switch( $this->format ) { case 'xcal': @@ -4416,6 +4133,59 @@ class calendarComponent { } return $attrLANG.$attr1.$attr2; } +/** + * check a date(-time) for an opt. timezone and if it is a DATE-TIME or DATE + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-10-25 + * @param array $date, date to check + * @param int $parno, no of date parts (i.e. year, month.. .) + * @return array $params, property parameters + */ + function _chkdatecfg( $theDate, & $parno, & $params ) { + if( isset( $params['TZID'] )) + $parno = 6; + elseif( isset( $params['VALUE'] ) && ( 'DATE' == $params['VALUE'] )) + $parno = 3; + else { + if( isset( $params['VALUE'] ) && ( 'PERIOD' == $params['VALUE'] )) + $parno = 7; + if( is_array( $theDate )) { + if( isset( $theDate['timestamp'] )) + $tzid = ( isset( $theDate['tz'] )) ? $theDate['tz'] : null; + else + $tzid = ( isset( $theDate['tz'] )) ? $theDate['tz'] : ( 7 == count( $theDate )) ? end( $theDate ) : null; + if( !empty( $tzid )) { + $parno = 7; + if( !$this->_isOffset( $tzid )) + $params['TZID'] = $tzid; // save only timezone + } + elseif( !$parno && ( 3 == count( $theDate )) && + ( isset( $params['VALUE'] ) && ( 'DATE' == $params['VALUE'] ))) + $parno = 3; + else + $parno = 6; + } + else { // string + $date = trim( $theDate ); + if( 'Z' == substr( $date, -1 )) + $parno = 7; // UTC DATE-TIME + elseif((( 8 == strlen( $date ) && ctype_digit( $date )) || ( 11 >= strlen( $date ))) && + ( !isset( $params['VALUE'] ) || !in_array( $params['VALUE'], array( 'DATE-TIME', 'PERIOD' )))) + $parno = 3; // DATE + $date = $this->_date_time_string( $date, $parno ); + if( !empty( $date['tz'] )) { + $parno = 7; + if( !$this->_isOffset( $date['tz'] )) + $params['TZID'] = $date['tz']; // save only timezone + } + elseif( empty( $parno )) + $parno = 6; + } + if( isset( $params['TZID'] )) + $parno = 6; + } + } /** * convert local startdate/enddate (Ymd[His]) to duration * @@ -4429,10 +4199,10 @@ class calendarComponent { */ function _date2duration( $startdate=FALSE, $enddate=FALSE ) { if( !$startdate || !$enddate ) { - if( FALSE === ( $startdate = $this->getProperty( 'dtstart' ))) + if( FALSE === ( $startdate = $this->getProperty( 'dtstart' ))) return null; - if( FALSE === ( $enddate = $this->getProperty( 'dtend' ))) // vevent/vfreebusy - if( FALSE === ( $enddate = $this->getProperty( 'due' ))) // vtodo + if( FALSE === ( $enddate = $this->getProperty( 'dtend' ))) // vevent/vfreebusy + if( FALSE === ( $enddate = $this->getProperty( 'due' ))) // vtodo return null; } if( !$startdate || !$enddate ) @@ -4455,7 +4225,7 @@ class calendarComponent { * convert date/datetime to timestamp * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.8 - 2008-10-30 * @param array $datetime datetime/(date) * @param string $tz timezone * @return timestamp @@ -4471,15 +4241,8 @@ class calendarComponent { } if( $tz ) $datetime['tz'] = $tz; - $offset = 0; - if( isset( $datetime['tz'] ) && ( '' < trim ( $datetime['tz'] ))) - $offset = $this->_tz2offset( $datetime['tz'] ); - $output = mktime( $datetime['hour'] - , $datetime['min'] - , $datetime['sec'] + $offset - , $datetime['month'] - , $datetime['day'] - , $datetime['year'] ); + $offset = ( isset( $datetime['tz'] ) && ( '' < trim ( $datetime['tz'] ))) ? $this->_tz2offset( $datetime['tz'] ) : 0; + $output = mktime( $datetime['hour'], $datetime['min'], ($datetime['sec'] + $offset), $datetime['month'], $datetime['day'], $datetime['year'] ); return $output; } /** @@ -4563,7 +4326,6 @@ class calendarComponent { $continue = TRUE; } else { - //echo "_date_time_string 1: $datetime tz=$tz.
\n"; // test ### $cx = $tx = 0; // 19970415T133000 US-Eastern for( $cx = -1; $cx > ( 9 - $len ); $cx-- ) { if(( ' ' == substr( $datetime, $cx, 1 )) || ctype_digit( substr( $datetime, $cx, 1 ))) @@ -4577,10 +4339,8 @@ class calendarComponent { $datetime = trim( substr( $datetime, 0, $len + $tx + 1 )); } } - //echo "_date_time_string 1a: $datetime tz=$tz.
\n"; // test ### if( 0 < substr_count( $datetime, '-' )) { $datetime = str_replace( '-', '/', $datetime ); - //echo "_date_time_string 1b: $datetime tz=$tz.
\n"; // test ### } elseif( ctype_digit( substr( $datetime, 0, 8 )) && ( 'T' == substr( $datetime, 8, 1 )) && @@ -4591,11 +4351,8 @@ class calendarComponent { .' '.substr( $datetime, 9, 2 ) .':'.substr( $datetime, 11, 2 ) .':'.substr( $datetime, 13); - // $datetime = substr( $datetime, 0, 8 ).substr( $datetime, 9 ); // not PHP 4.x compatible - //echo "_date_time_string 1c: $datetime tz=$tz.
\n"; // test ### } $datestring = date( 'Y-m-d H:i:s', strtotime( $datetime )); - // echo "_date_time_string 2: $datestring tz=$tz. datetime=$datetime
\n"; // test ### $tz = trim( $tz ); $output = array(); $output['year'] = substr( $datestring, 0, 4 ); @@ -4647,6 +4404,7 @@ class calendarComponent { } else { foreach( $duration as $durKey => $durValue ) { + if( empty( $durValue )) continue; switch ( $durKey ) { case '0': case 'week': $output['week'] = $durValue; break; case '1': case 'day': $output['day'] = $durValue; break; @@ -4656,30 +4414,32 @@ class calendarComponent { } } } - if( isset( $output['week'] ) && ( 0 < $output['week'] )) + if( isset( $output['week'] ) && ( 0 < $output['week'] )) { + unset( $output['day'], $output['hour'], $output['min'], $output['sec'] ); return $output; - elseif (( isset( $output['hour'] ) && ( 0 < $output['hour'] )) || - ( isset( $output['min'] ) && ( 0 < $output['min'] )) || - (isset( $output['sec'] ) && ( 0 < $output['sec'] ))) { - if( !isset( $output['hour'] )) - $output['hour'] = 0; - if( !isset( $output['min'] )) - $output['min'] = 0; - if( !isset( $output['sec'] )) - $output['sec'] = 0; + } + unset( $output['week'] ); + if( empty( $output['day'] )) + unset( $output['day'] ); + if ( isset( $output['hour'] ) || isset( $output['min'] ) || isset( $output['sec'] )) { + if( !isset( $output['hour'] )) $output['hour'] = 0; + if( !isset( $output['min'] )) $output['min'] = 0; + if( !isset( $output['sec'] )) $output['sec'] = 0; + if(( 0 == $output['hour'] ) && ( 0 == $output['min'] ) && ( 0 == $output['sec'] )) + unset( $output['hour'], $output['min'], $output['sec'] ); } return $output; } /** - * convert duration to date in array format based on dtstart value + * convert duration to date in array format based on input or dtstart value * * @author Kjell-Inge Gustafsson - * @since 2.2.11 - 2007-12-02 + * @since 2.4.8 - 2008-10-30 * @param array $startdate, optional * @param array $duration, optional * @return array, date format */ - function duration2date($startdate=FALSE, $duration=FALSE) { + function duration2date( $startdate=FALSE, $duration=FALSE ) { if( $startdate && $duration ) { $d1 = $startdate; $dur = $duration; @@ -4694,12 +4454,7 @@ class calendarComponent { $d1['hour'] = ( isset( $d1['hour'] )) ? $d1['hour'] : 0; $d1['min'] = ( isset( $d1['min'] )) ? $d1['min'] : 0; $d1['sec'] = ( isset( $d1['sec'] )) ? $d1['sec'] : 0; - $dtend = mktime( $d1['hour'] - , $d1['min'] - , $d1['sec'] - , $d1['month'] - , $d1['day'] - , $d1['year'] ); + $dtend = mktime( $d1['hour'], $d1['min'], $d1['sec'], $d1['month'], $d1['day'], $d1['year'] ); if( isset( $dur['week'] )) $dtend += ( $dur['week'] * 7 * 24 * 60 * 60 ); if( isset( $dur['day'] )) @@ -4776,33 +4531,38 @@ class calendarComponent { return $this->_duration_array( $output ); } /** - * if exist, remove key with expected value from array and return spec. value + * if not preSet, if exist, remove key with expected value from array and return hit value else return elseValue * * @author Kjell-Inge Gustafsson - * @since 0.9.19 - 2007-03-18 + * @since 2.4.16 - 2008-11-08 * @param array $array - * @param string $expkey - * @param string $expval - * @param int $hitval optional + * @param string $expkey, expected key + * @param string $expval, expected value + * @param int $hitVal optional, return value if found + * @param int $elseVal optional, return value if not found + * @param int $preSet optional, return value if already preset * @return int */ - function _existRem( &$array, $expkey, $expval=FALSE, $hitval=null ) { + function _existRem( &$array, $expkey, $expval=FALSE, $hitVal=null, $elseVal=null, $preSet=null ) { + if( $preSet ) + return $preSet; if( !is_array( $array ) || ( 0 == count( $array ))) - return null; - if( !isset( $array[$expkey] )) - return null; - if( !$expval ) - return $hitval; - if( $expval != $array[$expkey] ) - return null; - unset( $array[$expkey] ); - return $hitval; + return $elseVal; + foreach( $array as $key => $value ) { + if( strtoupper( $expkey ) == strtoupper( $key )) { + if( !$expval || ( strtoupper( $expval ) == strtoupper( $array[$key] ))) { + unset( $array[$key] ); + return $hitVal; + } + } + } + return $elseVal; } /** * creates formatted output for calendar component property data value type date/date-time * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.8 - 2008-10-30 * @param array $datetime * @param int $parno, optional, default 6 * @return string @@ -4816,47 +4576,36 @@ class calendarComponent { !isset( $datetime['sec'] )) return ; $output = null; - $output = date('Ymd', mktime( 0, 0, 0 - , (integer) $datetime['month'] - , (integer) $datetime['day'] - , (integer) $datetime['year'])); + // if( !isset( $datetime['day'] )) { $o=''; foreach($datetime as $k=>$v) {if(is_array($v)) $v=implode('-',$v);$o.=" $k=>$v";} echo " day SAKNAS : $o
\n"; } + foreach( $datetime as $dkey => $dvalue ) { + if( 'tz' != $dkey ) + $datetime[$dkey] = (integer) $dvalue; + } + $output = date('Ymd', mktime( 0, 0, 0, $datetime['month'], $datetime['day'], $datetime['year'])); if( isset( $datetime['hour'] ) || isset( $datetime['min'] ) || isset( $datetime['sec'] ) || isset( $datetime['tz'] )) { if( isset( $datetime['tz'] ) && !isset( $datetime['hour'] )) - $datetime['hour'] = '0'; + $datetime['hour'] = 0; if( isset( $datetime['hour'] ) && !isset( $datetime['min'] )) - $datetime['min'] = '0'; + $datetime['min'] = 0; if( isset( $datetime['hour'] ) && isset( $datetime['min'] ) && !isset( $datetime['sec'] )) - $datetime['sec'] = '0'; - foreach( $datetime as $dkey => $dvalue ) { - if( 'tz' != $dkey ) - $datetime[$dkey] = (integer) $dvalue; - } - $output .= date('\THis', mktime( $datetime['hour'] - , $datetime['min'] - , $datetime['sec'] - , $datetime['month'] - , $datetime['day'] - , $datetime['year'])); + $datetime['sec'] = 0; + $date = mktime( $datetime['hour'], $datetime['min'], $datetime['sec'], $datetime['month'], $datetime['day'], $datetime['year']); + $output .= date('\THis', $date ); if( isset( $datetime['tz'] ) && ( '' < trim ( $datetime['tz'] ))) { $datetime['tz'] = trim( $datetime['tz'] ); if( 'Z' == $datetime['tz'] ) $output .= 'Z'; - $offset = 0; $offset = $this->_tz2offset( $datetime['tz'] ); if( 0 != $offset ) { - $output = date('Ymd\THis\Z', mktime( $datetime['hour'] - , $datetime['min'] - , $datetime['sec'] + $offset - , $datetime['month'] - , $datetime['day'] - , $datetime['year'])); + $date = mktime( $datetime['hour'], $datetime['min'], ($datetime['sec'] + $offset), $datetime['month'], $datetime['day'], $datetime['year']); + $output = date( 'Ymd\THis\Z', $date ); } } elseif( 7 == $parno ) @@ -4868,7 +4617,7 @@ class calendarComponent { * creates formatted output for calendar component property data value type duration * * @author Kjell-Inge Gustafsson - * @since 1.x.x - 2007-05-13 + * @since 2.4.16 - 2008-10-10 * @param array $duration ( week, day, hour, min, sec ) * @return string */ @@ -4881,31 +4630,17 @@ class calendarComponent { return; $output = 'P'; if( isset( $duration['week'] ) && ( 0 < $duration['week'] )) - $output .= $duration['week'].'W'; + $output .= $duration['week'].'W'; else { if( isset($duration['day'] ) && ( 0 < $duration['day'] )) - $output .= $duration['day'].'D'; + $output .= $duration['day'].'D'; if(( isset( $duration['hour']) && ( 0 < $duration['hour'] )) || ( isset( $duration['min']) && ( 0 < $duration['min'] )) || ( isset( $duration['sec']) && ( 0 < $duration['sec'] ))) { - $output .= 'T'; - if( 0 < $duration['hour'] ) { - $output .= $duration['hour'].'H'; - if( 0 < $duration['min'] ) { - $output .= $duration['min'].'M'; - if( 0 < $duration['sec'] ) - $output .= $duration['sec'].'S'; - } - elseif( 0 < $duration['sec'] ) - $output .= '0M'.$duration['sec'].'S'; - } - elseif( 0 < $duration['min'] ) { - $output .= '0H'.$duration['min'].'M'; - if( 0 < $duration['sec'] ) - $output .= $duration['sec'].'S'; - } - elseif( 0 < $duration['sec'] ) - $output .= '0H0M'.$duration['sec'].'S'; + $output .= 'T'; + $output .= ( isset( $duration['hour']) && ( 0 < $duration['hour'] )) ? $duration['hour'].'H' : '0H'; + $output .= ( isset( $duration['min']) && ( 0 < $duration['min'] )) ? $duration['min']. 'M' : '0M'; + $output .= ( isset( $duration['sec']) && ( 0 < $duration['sec'] )) ? $duration['sec']. 'S' : '0S'; } } return $output; @@ -4914,14 +4649,18 @@ class calendarComponent { * creates formatted output for calendar component property data value type recur * * @author Kjell-Inge Gustafsson - * @since 0.9.7 - 2006-11-20 + * @since 2.4.8 - 2008-10-22 * @param array $recurlabel * @param array $recurdata * @return string */ - function _format_recur ( $recurlabel, $recurdata ) { - $recur = null; + function _format_recur( $recurlabel, $recurdata ) { + $output = null; foreach( $recurdata as $therule ) { + if( empty( $therule['value'] )) { + if( $this->getConfig( 'allowEmpty' )) $output .= $this->_createElement( $recurlabel ); + continue; + } $attributes = ( isset( $therule['params'] )) ? $this->_createParams( $therule['params'] ) : null; $content1 = $content2 = null; foreach( $therule['value'] as $rulelabel => $rulevalue ) { @@ -4995,9 +4734,9 @@ class calendarComponent { } } } - $recur .= $this->_createElement( $recurlabel, $attributes, $content1.$content2 ); + $output .= $this->_createElement( $recurlabel, $attributes, $content1.$content2 ); } - return $recur; + return $output; } /** * create property name case - lower/upper @@ -5017,13 +4756,95 @@ class calendarComponent { break; } } +/** + * checks if input array contains a date + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-10-25 + * @param array $input + * @return bool + */ + function _isArrayDate( $input ) { + if( isset( $input['week'] ) || ( !in_array( count( $input ), array( 3, 6, 7 )))) + return FALSE; + if( 7 == count( $input )) + return TRUE; + if( isset( $input['year'] ) && isset( $input['month'] ) && isset( $input['day'] )) + return checkdate( (int) $input['month'], (int) $input['day'], (int) $input['year'] ); + if( isset( $input['day'] ) || isset( $input['hour'] ) || isset( $input['min'] ) || isset( $input['sec'] )) + return FALSE; + if( in_array( 0, $input )) + return FALSE; + if(( 1970 > $input[0] ) || ( 12 < $input[1] ) || ( 31 < $input[2] )) + return FALSE; + if(( isset( $input[0] ) && isset( $input[1] ) && isset( $input[2] )) && + checkdate( (int) $input[1], (int) $input[2], (int) $input[0] )) + return TRUE; + $input = $this->_date_time_string( $input[1].'/'.$input[2].'/'.$input[0], 3 ); // m - d - Y + if( isset( $input['year'] ) && isset( $input['month'] ) && isset( $input['day'] )) + return checkdate( (int) $input['month'], (int) $input['day'], (int) $input['year'] ); + return FALSE; + } +/** + * checks if input array contains a timestamp date + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-10-18 + * @param array $input + * @return bool + */ + function _isArrayTimestampDate( $input ) { + return ( is_array( $input ) && isset( $input['timestamp'] )) ? TRUE : FALSE ; + } +/** + * controll if input string contains traling UTC offset + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-10-19 + * @param string $input + * @return bool + */ + function _isOffset( $input ) { + $input = trim( (string) $input ); + if( 'Z' == substr( $input, -1 )) + return TRUE; + elseif(( 5 <= strlen( $input )) && + ( in_array( substr( $input, -5, 1 ), array( '+', '-' ))) && + ( '0000' < substr( $input, -4 )) && ( '9999' >= substr( $input, -4 ))) + return TRUE; + elseif(( 7 <= strlen( $input )) && + ( in_array( substr( $input, -7, 1 ), array( '+', '-' ))) && + ( '000000' < substr( $input, -6 )) && ( '999999' >= substr( $input, -6 ))) + return TRUE; + return FALSE; + + } +/** + * check if property not exists within component + * + * @author Kjell-Inge Gustafsson + * @since 2.5.1 - 2008-10-15 + * @param string $propName + * @return bool + */ + function _notExistProp( $propName ) { + if( empty( $propName )) return FALSE; // when deleting x-prop, an empty propName may be used=allowed + $propName = strtolower( $propName ); + if( 'last-modified' == $propName ) { if( !isset( $this->lastmodified )) return TRUE; } + elseif( 'percent-complete' == $propName ) { if( !isset( $this->percentcomplete )) return TRUE; } + elseif( 'recurrence-id' == $propName ) { if( !isset( $this->recurrenceid )) return TRUE; } + elseif( 'related-to' == $propName ) { if( !isset( $this->relatedto )) return TRUE; } + elseif( 'request-status' == $propName ) { if( !isset( $this->requeststatus )) return TRUE; } + elseif(( 'x-' != substr($propName,0,2)) && !isset( $this->$propName )) return TRUE; + return FALSE; + } /** * remakes a recur pattern to an array of dates * * if missing, UNTIL is set 1 year from startdate (emergency break) * * @author Kjell-Inge Gustafsson - * @since 2.2.11 - 2007-11-26 + * @since 2.4.16 - 2008-10-18 * @param array $result, array to update, array([timestamp] => timestamp) * @param array $recur, pattern for recurrency (only value part, params ignored) * @param array $wdate, component start date @@ -5048,10 +4869,10 @@ class calendarComponent { $tdatets = $this->_date2timestamp( $recur['UNTIL'] ); if( $endDatets > $tdatets ) { $endDatets = $tdatets; // emergency break - $enddate = $this->_date_time_string( date('Y-m-d H:i:s', $endDatets )); + $enddate = $this->_timestamp2date( $endDatets, 6 ); } else - $recur['UNTIL'] = $this->_date_time_string( date('Y-m-d H:i:s', $endDatets )); + $recur['UNTIL'] = $this->_timestamp2date( $endDatets, 6 ); } if( $wdatets > $endDatets ) { //echo "recur out of date ".implode('-',$this->_date_time_string(date('Y-m-d H:i:s',$wdatets),6))."
\n";//test @@ -5395,11 +5216,40 @@ class calendarComponent { } return $intervalix; } +/** + * convert input format for exrule and rrule to internal format + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-10-19 + * @param array $rexrule + * @return array + */ + function _setRexrule( $rexrule ) { + $input = array(); + if( empty( $rexrule )) + return $input; + foreach( $rexrule as $rexrulelabel => $rexrulevalue ) { + $rexrulelabel = strtoupper( $rexrulelabel ); + if( 'UNTIL' != $rexrulelabel ) + $input[$rexrulelabel] = $rexrulevalue; + else { + if( $this->_isArrayTimestampDate( $rexrulevalue )) // timestamp date + $input[$rexrulelabel] = $this->_timestamp2date( $rexrulevalue, 6 ); + elseif( $this->_isArrayDate( $rexrulevalue )) // date-time + $input[$rexrulelabel] = $this->_date_time_array( $rexrulevalue, 6 ); + elseif( 8 <= strlen( trim( $rexrulevalue ))) // ex. 2006-08-03 10:12:18 + $input[$rexrulelabel] = $this->_date_time_string( $rexrulevalue ); + if(( 3 < count( $input[$rexrulelabel] )) && !isset( $input[$rexrulelabel]['tz'] )) + $input[$rexrulelabel]['tz'] = 'Z'; + } + } + return $input; + } /** * convert format for input date to internal date with parameters * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-01 + * @since 2.4.17 - 2008-10-31 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -5407,52 +5257,67 @@ class calendarComponent { * @param int $min optional * @param int $sec optional * @param array $params optional + * @param string $caller optional * @return array */ - function _setDate( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE ) { + function _setDate( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $tz=FALSE, $params=FALSE, $caller=null ) { $input = $parno = null; - if( is_array( $year ) && ( in_array( count( $year ), array( 3, 4, 6, 7 )))) { + $localtime = (( 'dtstart' == $caller ) && in_array( $this->objName, array( 'vtimezone', 'standard', 'daylight' ))) ? TRUE : FALSE; + if( $this->_isArrayDate( $year )) { + if( $localtime ) unset ( $month['VALUE'], $month['TZID'] ); $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' )); - if( isset( $input['params']['TZID'] )) - $year['tz'] = $input['params']['TZID']; - $hitval = ( !empty( $year['tz'] ) || !empty( $year[6] ) || ( 4 == count( $year ))) ? 7 : 6; + if( isset( $input['params']['TZID'] )) { + $input['params']['VALUE'] = 'DATE-TIME'; + unset( $year['tz'] ); + } + $hitval = (( !empty( $year['tz'] ) || !empty( $year[6] ))) ? 7 : 6; $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval ); - if( !isset( $parno )) - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); - if( !isset( $parno )) - $parno = count( $year ); + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3, count( $year ), $parno ); $input['value'] = $this->_date_time_array( $year, $parno ); } - elseif( is_array( $year ) && isset( $year['timestamp'] )) { + elseif( $this->_isArrayTimestampDate( $year )) { + if( $localtime ) unset ( $month['VALUE'], $month['TZID'] ); $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' )); - if( isset( $input['params']['TZID'] )) - $year['tz'] = $input['params']['TZID']; - $tz = ( isset( $year['tz'] )) ? ' '.$year['tz'] : null; - $hitval = ( !empty( $tz )) ? 7 : 6; - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval ); - if( !isset( $parno )) - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); - if( !isset( $parno )) - $parno = $hitval; - $input['value'] = $this->_date_time_string( date('Y-m-d H:i:s',$year['timestamp']).$tz,$parno ); + if( isset( $input['params']['TZID'] )) { + $input['params']['VALUE'] = 'DATE-TIME'; + unset( $year['tz'] ); + } + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); + $hitval = ( isset( $year['tz'] )) ? 7 : 6; + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval, $parno ); + $input['value'] = $this->_timestamp2date( $year, $parno ); } elseif( 8 <= strlen( trim( $year ))) { // ex. 2006-08-03 10:12:18 + if( $localtime ) unset ( $month['VALUE'], $month['TZID'] ); $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' )); - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7 ); - if( !isset( $parno )) - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); + if( isset( $input['params']['TZID'] )) { + $input['params']['VALUE'] = 'DATE-TIME'; + $parno = 6; + } + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7, $parno ); + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3, $parno, $parno ); $input['value'] = $this->_date_time_string( $year, $parno ); - if( isset( $input['params']['TZID'] )) - $input['value']['tz'] = $input['params']['TZID']; } else { - $input['params'] = $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' )); - if( isset( $input['params']['TZID'] )) - $tz = $input['params']['TZID']; - $hitval = ( !empty( $tz )) ? 7 : null; - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval ); - if( !isset( $parno )) - $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); + if( is_array( $params )) { + if( $localtime ) unset ( $params['VALUE'], $params['TZID'] ); + $input['params'] = $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' )); + } + elseif( is_array( $tz )) { + $input['params'] = $this->_setParams( $tz, array( 'VALUE' => 'DATE-TIME' )); + $tz = FALSE; + } + elseif( is_array( $hour )) { + $input['params'] = $this->_setParams( $hour, array( 'VALUE' => 'DATE-TIME' )); + $hour = $min = $sec = $tz = FALSE; + } + if( isset( $input['params']['TZID'] )) { + $tz = null; + $input['params']['VALUE'] = 'DATE-TIME'; + } + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE', 3 ); + $hitval = ( !empty( $tz )) ? 7 : 6; + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', $hitval, $parno, $parno ); $input['value'] = array( 'year' => $year, 'month' => $month, 'day' => $day ); if( 3 != $parno ) { $input['value']['hour'] = ( $hour ) ? $hour : '0'; @@ -5467,25 +5332,21 @@ class calendarComponent { unset( $input['value']['tz'] ); unset( $input['params']['TZID'] ); } + elseif( isset( $input['params']['TZID'] )) + unset( $input['value']['tz'] ); + if( $localtime ) unset( $input['value']['tz'], $input['params']['TZID'] ); if( isset( $input['value']['tz'] )) $input['value']['tz'] = (string) $input['value']['tz']; - if( !empty( $input['value']['tz'] ) && - ( $input['value']['tz'] != 'Z' ) && - ( !( in_array($input['value']['tz']{0}, array( '+', '-' )) && - ctype_digit( substr( $input['value']['tz'], 1 ))) && - !ctype_digit( $input['value']['tz'] ) ) ) { + if( !empty( $input['value']['tz'] ) && ( 'Z' != $input['value']['tz'] ) && + ( !$this->_isOffset( $input['value']['tz'] ))) $input['params']['TZID'] = $input['value']['tz']; - unset( $input['value']['tz'] ); - } - elseif( isset( $input['params']['TZID'] )) - unset( $input['params']['TZID'] ); return $input; } /** * convert format for input date (UTC) to internal date with parameters * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-08-02 + * @since 2.4.17 - 2008-10-31 * @param mixed $year * @param mixed $month optional * @param int $day optional @@ -5495,21 +5356,19 @@ class calendarComponent { * @param array $params optional * @return array */ - function _setDate2( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { + function _setDate2( $year, $month=FALSE, $day=FALSE, $hour=FALSE, $min=FALSE, $sec=FALSE, $params=FALSE ) { $input = null; - if( is_array( $year ) && - (( 6 == count( $year )) || - ( array_key_exists( 'year', $year )))) { + if( $this->_isArrayDate( $year )) { $input['value'] = $this->_date_time_array( $year, 7 ); - $input['params'] = $this->_setParams( $month ); + $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' ) ); } - elseif( is_array( $year ) && isset( $year['timestamp'] )) { - $input['value'] = $this->_date_time_string( date( 'Y-m-d H:i:s', $year['timestamp'] ), 7 ); - $input['params'] = $this->_setParams( $month ); + elseif( $this->_isArrayTimestampDate( $year )) { + $input['value'] = $this->_timestamp2date( $year, 7 ); + $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' ) ); } elseif( 8 <= strlen( trim( $year ))) { // ex. 2006-08-03 10:12:18 $input['value'] = $this->_date_time_string( $year, 7 ); - $input['params'] = $this->_setParams( $month ); + $input['params'] = $this->_setParams( $month, array( 'VALUE' => 'DATE-TIME' ) ); } else { $input['value'] = array( 'year' => $year @@ -5518,17 +5377,44 @@ class calendarComponent { , 'hour' => $hour , 'min' => $min , 'sec' => $sec ); - $input['params'] = $this->_setParams( $params ); + $input['params'] = $this->_setParams( $params, array( 'VALUE' => 'DATE-TIME' )); } + $parno = $this->_existRem( $input['params'], 'VALUE', 'DATE-TIME', 7 ); // remove default if( !isset( $input['value']['hour'] )) $input['value']['hour'] = 0; if( !isset( $input['value']['min'] )) $input['value']['min'] = 0; if( !isset( $input['value']['sec'] )) $input['value']['sec'] = 0; - $input['value']['tz'] = 'Z'; + if( !isset( $input['value']['tz'] ) || !$this->_isOffset( $input['value']['tz'] )) + $input['value']['tz'] = 'Z'; return $input; } +/** + * check index and set (an indexed) content in multiple value array + * + * @author Kjell-Inge Gustafsson + * @since 2.5.1 - 2008-11-06 + * @param array $valArr + * @param mixed $value + * @param array $params + * @param array $defaults + * @param int $index + * @return void + */ + function _setMval( & $valArr, $value, $params=FALSE, $defaults=FALSE, $index=FALSE ) { + if( !is_array( $valArr )) $valArr = array(); + if( $index ) + $index = $index - 1; + elseif( 0 < count( $valArr )) { + $index = end( array_keys( $valArr )); + $index += 1; + } + else + $index = 0; + $valArr[$index] = array( 'value' => $value, 'params' => $this->_setParams( $params, $defaults )); + ksort( $valArr ); + } /** * set input (formatted) parameters- component property attributes * @@ -5570,7 +5456,7 @@ class calendarComponent { * step date, return updated date, array and timpstamp * * @author Kjell-Inge Gustafsson - * @since 2.2.15 - 2007-11-12 + * @since 2.4.16 - 2008-10-18 * @param array $date, date to step * @param int $timestamp * @param array $step, default array( 'day' => 1 ) @@ -5580,44 +5466,60 @@ class calendarComponent { foreach( $step as $stepix => $stepvalue ) $date[$stepix] += $stepvalue; $timestamp = $this->_date2timestamp( $date ); - $date = $this->_date_time_string( date('Y-m-d H:i:s', $timestamp ), 6); + $date = $this->_timestamp2date( $timestamp, 6 ); foreach( $date as $k => $v ) { if( ctype_digit( $v )) $date[$k] = (int) $v; } } /** - * convert (numeric) tz to offset seconds + * convert timestamp to date array + * + * @author Kjell-Inge Gustafsson + * @since 2.4.16 - 2008-11-01 + * @param mixed $timestamp + * @param int $parno + * @return array + */ + function _timestamp2date( $timestamp, $parno=6 ) { + if( is_array( $timestamp )) { + if(( 7 == $parno ) && !empty( $timestamp['tz'] )) + $tz = $timestamp['tz']; + $timestamp = $timestamp['timestamp']; + } + $output = array( 'year' => date( 'Y', $timestamp ) + , 'month' => date( 'm', $timestamp ) + , 'day' => date( 'd', $timestamp )); + if( 3 != $parno ) { + $output['hour'] = date( 'H', $timestamp ); + $output['min'] = date( 'i', $timestamp ); + $output['sec'] = date( 's', $timestamp ); + if( isset( $tz )) + $output['tz'] = $tz; + } + return $output; + } +/** + * convert (numeric) local time offset to seconds correcting localtime to GMT * * @author Kjell-Inge Gustafsson - * @since 2.2.2 - 2007-07-29 + * @since 2.4.16 - 2008-10-19 * @param string $offset * @return integer */ function _tz2offset( $tz ) { - $tz = trim( (string) $tz ); - $offset = 0; - if(( 5 == strlen( $tz )) && - ( '0000' <= substr( $tz, -4 )) && - ( '9999' >= substr( $tz, -4 )) && - (( '+' == substr( $tz, 0, 1 )) || - ( '-' == substr( $tz, 0, 1 )))) { - $hours2sec = substr( $tz, 1, 2 ) * 3600; - $min2sec = substr( $tz, -2 ) * 60; - $sign = substr( $tz, 0, 1 ); - $offset = (int) ( $sign.'1' * ($hours2sec + $min2sec )); - } - elseif(( 7 == strlen( $tz )) && - ( '000000' <= substr( $tz, -6 )) && - ( '999999' >= substr( $tz, -6 )) && - (( '+' == substr( $tz, 0, 1 )) || - ( '-' == substr( $tz, 0, 1 )))) { - $hours2sec = substr( $tz, 1, 2 ) * 3600; - $min2sec = substr( $tz, 3, 2 ) * 60; - $sec = substr( $tz, -2 ); - $sign = substr( $tz, 0, 1 ); - $offset = (int) ( $sign.'1' * ( $hours2sec + $min2sec + $sec )); - } + $tz = trim( (string) $tz ); + $offset = 0; + if((( 5 != strlen( $tz )) && ( 7 != strlen( $tz ))) || + (( '+' != substr( $tz, 0, 1 )) && ( '-' != substr( $tz, 0, 1 ))) || + (( '0000' >= substr( $tz, 1, 4 )) && ( '9999' < substr( $tz, 1, 4 ))) || + (( 7 == strlen( $tz )) && ( '00' > substr( $tz, 5, 2 )) && ( '99' < substr( $tz, 5, 2 )))) + return $offset; + $hours2sec = (int) substr( $tz, 1, 2 ) * 3600; + $min2sec = (int) substr( $tz, 3, 2 ) * 60; + $sec = ( 7 == strlen( $tz )) ? (int) substr( $tz, -2 ) : '00'; + $offset = $hours2sec + $min2sec + $sec; + $offset = ('-' == substr( $tz, 0, 1 )) ? $offset : -1 * $offset; return $offset; } /*********************************************************************************/ @@ -5626,7 +5528,7 @@ class calendarComponent { * get general component config variables or info about subcomponents * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-23 + * @since 2.5.1 - 2008-11-02 * @param string $config * @return value */ @@ -5638,14 +5540,17 @@ class calendarComponent { case 'COMPSINFO': unset( $this->compix ); $info = array(); - foreach( $this->components as $cix => $component ) { - unset( $component->propix ); - $info[$cix]['ordno'] = $cix + 1; - $info[$cix]['type'] = $component->objName; - $info[$cix]['uid'] = $component->getProperty( 'uid' ); - $info[$cix]['props'] = $component->getConfig( 'propinfo' ); - $info[$cix]['sub'] = $component->getConfig( 'compsinfo' ); - unset( $component->propix ); + if( isset( $this->components )) { + foreach( $this->components as $cix => $component ) { + if( empty( $component )) continue; + unset( $component->propix ); + $info[$cix]['ordno'] = $cix + 1; + $info[$cix]['type'] = $component->objName; + $info[$cix]['uid'] = $component->getProperty( 'uid' ); + $info[$cix]['props'] = $component->getConfig( 'propinfo' ); + $info[$cix]['sub'] = $component->getConfig( 'compsinfo' ); + unset( $component->propix ); + } } return $info; break; @@ -5657,106 +5562,63 @@ class calendarComponent { return $this->language; break; case 'NL': + case 'NEWLINECHAR': return $this->nl; break; case 'PROPINFO': $output = array(); - if( 0 < count( $this->action )) - $output['ACTION'] = count( $this->action ) / 2; - if( 0 < count( $this->attach )) - $output['ATTACH'] = count( $this->attach ); - if( 0 < count( $this->attendee )) - $output['ATTENDEE'] = count( $this->attendee ); - if( 0 < count( $this->categories )) - $output['CATEGORIES'] = count( $this->categories ); - if( 0 < count( $this->class )) - $output['CLASS'] = count( $this->class ) / 2; - if( 0 < count( $this->comment )) - $output['COMMENT'] = count( $this->comment ); - if( 0 < count( $this->completed )) - $output['COMPLETED'] = count( $this->completed ) / 2; - if( 0 < count( $this->contact )) - $output['CONTACT'] = count( $this->contact ); - if( 0 < count( $this->created )) - $output['CREATED'] = count( $this->created ) / 2; - if( 0 < count( $this->description )) - $output['DESCRIPTION'] = count( $this->description ); - if( 0 < count( $this->dtend )) - $output['DTEND'] = count( $this->dtend ) / 2; - if( 0 < count( $this->dtstart )) - $output['DTSTART'] = count( $this->dtstart ) / 2; - if( 0 < count( $this->dtstamp )) - $output['DTSTAMP'] = count( $this->dtstamp ) / 2; - if( 0 < count( $this->due )) - $output['DUE'] = count( $this->due ) / 2; - if( 0 < count( $this->duration )) - $output['DURATION'] = count( $this->duration ) / 2; - if( 0 < count( $this->exdate )) - $output['EXDATE'] = count( $this->exdate ); - if( 0 < count( $this->exrule )) - $output['EXRULE'] = count( $this->exrule ); - if( 0 < count( $this->freebusy )) - $output['FREEBUSY'] = count( $this->freebusy ); - if( 0 < count( $this->geo )) - $output['GEO'] = count( $this->geo ) / 2; - if( 0 < count( $this->lastmodified )) - $output['LAST-MODIFIED'] = count( $this->lastmodified ) / 2; - if( 0 < count( $this->location )) - $output['LOCATION'] = count( $this->location ) / 2; - if( 0 < count( $this->organizer )) - $output['ORGANIZER'] = count( $this->organizer ) / 2; - if( 0 < count( $this->percentcomplete )) - $output['PERCENT-COMPLETE'] = count( $this->percentcomplete ) / 2; - if( 0 < count( $this->priority )) - $output['PRIORITY'] = count( $this->priority ) / 2; - if( 0 < count( $this->rdate )) - $output['RDATE'] = count( $this->rdate ); - if( 0 < count( $this->recurrenceid )) - $output['RECURRENCE-ID'] = count( $this->recurrenceid ) / 2; - if( 0 < count( $this->relatedto )) - $output['RELATED-TO'] = count( $this->relatedto ); - if( 0 < count( $this->repeat )) - $output['REPEAT'] = count( $this->repeat ) / 2; - if( 0 < count( $this->requeststatus )) - $output['REQUEST-STATUS'] = count( $this->requeststatus ); - if( 0 < count( $this->resources )) - $output['RESOURCES'] = count( $this->resources ); - if( 0 < count( $this->sequence )) - $output['SEQUENCE'] = count( $this->sequence ) / 2; - if( 0 < count( $this->rrule )) - $output['RRULE'] = count( $this->rrule ); - if( 0 < count( $this->status )) - $output['STATUS'] = count( $this->status ) / 2; - if( 0 < count( $this->summary )) - $output['SUMMARY'] = count( $this->summary ) / 2; - if( 0 < count( $this->transp )) - $output['TRANSP'] = count( $this->transp ) / 2; - if( 0 < count( $this->trigger )) - $output['TRIGGER'] = count( $this->trigger ) / 2; - if( 0 < count( $this->tzid )) - $output['TZID'] = count( $this->tzid ) / 2; - if( 0 < count( $this->tzname )) - $output['TZNAME'] = count( $this->tzname ); - if( 0 < count( $this->tzoffsetfrom )) - $output['TZOFFSETTFROM'] = count( $this->tzoffsetfrom ) / 2; - if( 0 < count( $this->tzoffsetto )) - $output['TZOFFSETTO'] = count( $this->tzoffsetto ) / 2; - if( 0 < count( $this->tzurl )) - $output['TZURL'] = count( $this->tzurl ) / 2; - if( !in_array( $this->objName, array( 'valarm', 'vtimezone' ))) { - if( empty( $this->uid['value'] )) - $this->_makeuid(); - $output['UID'] = 1; + if( !in_array( $this->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) { + if( empty( $this->uid['value'] )) $this->_makeuid(); + $output['UID'] = 1; } - if( 0 < count( $this->url )) - $output['URL'] = count( $this->url ) / 2; - if( 0 < count( $this->xprop )) - $output['X-PROP'] = count( $this->xprop ); + if( !empty( $this->dtstamp )) $output['DTSTAMP'] = 1; + if( !empty( $this->summary )) $output['SUMMARY'] = 1; + if( !empty( $this->description )) $output['DESCRIPTION'] = count( $this->description ); + if( !empty( $this->dtstart )) $output['DTSTART'] = 1; + if( !empty( $this->dtend )) $output['DTEND'] = 1; + if( !empty( $this->due )) $output['DUE'] = 1; + if( !empty( $this->duration )) $output['DURATION'] = 1; + if( !empty( $this->rrule )) $output['RRULE'] = count( $this->rrule ); + if( !empty( $this->rdate )) $output['RDATE'] = count( $this->rdate ); + if( !empty( $this->exdate )) $output['EXDATE'] = count( $this->exdate ); + if( !empty( $this->exrule )) $output['EXRULE'] = count( $this->exrule ); + if( !empty( $this->action )) $output['ACTION'] = 1; + if( !empty( $this->attach )) $output['ATTACH'] = count( $this->attach ); + if( !empty( $this->attendee )) $output['ATTENDEE'] = count( $this->attendee ); + if( !empty( $this->categories )) $output['CATEGORIES'] = count( $this->categories ); + if( !empty( $this->class )) $output['CLASS'] = 1; + if( !empty( $this->comment )) $output['COMMENT'] = count( $this->comment ); + if( !empty( $this->completed )) $output['COMPLETED'] = 1; + if( !empty( $this->contact )) $output['CONTACT'] = count( $this->contact ); + if( !empty( $this->created )) $output['CREATED'] = 1; + if( !empty( $this->freebusy )) $output['FREEBUSY'] = count( $this->freebusy ); + if( !empty( $this->geo )) $output['GEO'] = 1; + if( !empty( $this->lastmodified )) $output['LAST-MODIFIED'] = 1; + if( !empty( $this->location )) $output['LOCATION'] = 1; + if( !empty( $this->organizer )) $output['ORGANIZER'] = 1; + if( !empty( $this->percentcomplete )) $output['PERCENT-COMPLETE'] = 1; + if( !empty( $this->priority )) $output['PRIORITY'] = 1; + if( !empty( $this->recurrenceid )) $output['RECURRENCE-ID'] = 1; + if( !empty( $this->relatedto )) $output['RELATED-TO'] = count( $this->relatedto ); + if( !empty( $this->repeat )) $output['REPEAT'] = 1; + if( !empty( $this->requeststatus )) $output['REQUEST-STATUS'] = count( $this->requeststatus ); + if( !empty( $this->resources )) $output['RESOURCES'] = count( $this->resources ); + if( !empty( $this->sequence )) $output['SEQUENCE'] = 1; + if( !empty( $this->status )) $output['STATUS'] = 1; + if( !empty( $this->transp )) $output['TRANSP'] = 1; + if( !empty( $this->trigger )) $output['TRIGGER'] = 1; + if( !empty( $this->tzid )) $output['TZID'] = 1; + if( !empty( $this->tzname )) $output['TZNAME'] = count( $this->tzname ); + if( !empty( $this->tzoffsetfrom )) $output['TZOFFSETTFROM'] = 1; + if( !empty( $this->tzoffsetto )) $output['TZOFFSETTO'] = 1; + if( !empty( $this->tzurl )) $output['TZURL'] = 1; + if( !empty( $this->url )) $output['URL'] = 1; + if( !empty( $this->xprop )) $output['X-PROP'] = count( $this->xprop ); return $output; break; case 'UNIQUE_ID': if( empty( $this->unique_id )) - $this->unique_id = gethostbyname( $_SERVER['SERVER_NAME'] ); + $this->unique_id = ( isset( $_SERVER['SERVER_NAME'] )) ? gethostbyname( $_SERVER['SERVER_NAME'] ) : 'localhost'; return $this->unique_id; break; } @@ -5765,299 +5627,343 @@ class calendarComponent { * general component config setting * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-25 + * @since 2.4.8 - 2008-10-24 * @param string $config * @param string $value * @return void */ function setConfig( $config, $value ) { + $res = FALSE; switch( strtoupper( $config )) { case 'ALLOWEMPTY': $this->allowEmpty = $value; + $subcfg = array( 'ALLOWEMPTY' => $value ); + $res = TRUE; break; case 'FORMAT': - $value = trim( $value ); + $value = trim( $value ); $this->format = $value; + $this->_createFormat(); + $subcfg = array( 'FORMAT' => $value ); + $res = TRUE; break; case 'LANGUAGE': // set language for calendar component as defined in [RFC 1766] - $value = trim( $value ); + $value = trim( $value ); $this->language = $value; + $subcfg = array( 'LANGUAGE' => $value ); + $res = TRUE; break; case 'NL': + case 'NEWLINECHAR': $this->nl = $value; + $subcfg = array( 'NL' => $value ); + $res = TRUE; break; case 'UNIQUE_ID': - $value = trim( $value ); + $value = trim( $value ); $this->unique_id = $value; + $subcfg = array( 'UNIQUE_ID' => $value ); + $res = TRUE; break; } + if( !$res ) return FALSE; + if( isset( $subcfg ) && !empty( $this->components )) { + foreach( $subcfg as $cfgkey => $cfgvalue ) { + foreach( $this->components as $cix => $component ) { + $res = $component->setConfig( $cfgkey, $cfgvalue ); + if( !$res ) + break 2; + $this->components[$cix] = $component; // PHP4 compliant + } + } + } + return $res; } /*********************************************************************************/ /** * delete component property value * * @author Kjell-Inge Gustafsson - * @since 2.2.15 - 2007-10-29 + * @since 2.5.1 - 2008-11-14 * @param string $propName * @param int @propix, optional, if specific property is wanted in case of multiply occurences * @return bool, if successfull delete TRUE */ function deleteProperty( $propName, $propix=FALSE ) { - $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP'; - if( !$propix ) - $propix = ( isset( $this->propdelix[$propName] )) ? $this->propdelix[$propName] + 2 : 1; - $this->propdelix[$propName] = --$propix; + if( $this->_notExistProp( $propName )) return FALSE; + $propName = strtoupper( $propName ); + if( in_array( $propName, array( 'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'EXDATE', 'EXRULE', + 'FREEBUSY', 'RDATE', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'TZNAME', 'X-PROP' ))) { + if( !$propix ) + $propix = ( isset( $this->propdelix[$propName] )) ? $this->propdelix[$propName] + 2 : 1; + $this->propdelix[$propName] = --$propix; + } $return = FALSE; switch( $propName ) { case 'ACTION': - if(( 0 < $propix ) || !isset( $this->action['value'] )) return FALSE; - $this->action = array(); - return TRUE; + if( !empty( $this->action )) { + $this->action = ''; + $return = TRUE; + } break; case 'ATTACH': - if( count( $this->attach ) <= $propix ) return FALSE; - $this->attach[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->attach, $propix ); break; case 'ATTENDEE': - if( count( $this->attendee ) <= $propix ) return FALSE; - $this->attendee[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->attendee, $propix ); break; case 'CATEGORIES': - if( !isset( $this->categories[$propix])) return FALSE; - $this->categories[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->categories, $propix ); break; case 'CLASS': - if(( 0 < $propix ) || !isset( $this->class['value'] )) return FALSE; - $this->class = array(); - return TRUE; + if( !empty( $this->class )) { + $this->class = ''; + $return = TRUE; + } break; case 'COMMENT': - if( !isset( $this->comment[$propix])) return FALSE; - $this->comment[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->comment, $propix ); break; case 'COMPLETED': - if(( 0 < $propix ) || !isset( $this->completed['value'] )) return FALSE; - $this->completed = array(); - return TRUE; + if( !empty( $this->completed )) { + $this->completed = ''; + $return = TRUE; + } break; case 'CONTACT': - if( !isset( $this->contact[$propix])) return FALSE; - $this->contact[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->contact, $propix ); break; case 'CREATED': - if(( 0 < $propix ) || !isset( $this->created['value'] )) return FALSE; - $this->created = array(); - return TRUE; + if( !empty( $this->created )) { + $this->created = ''; + $return = TRUE; + } break; case 'DESCRIPTION': - if( !isset( $this->description[$propix])) return FALSE; - $this->description[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->description, $propix ); break; case 'DTEND': - if(( 0 < $propix ) || !isset( $this->dtend['value'] )) return FALSE; - $this->dtend = array(); - return TRUE; + if( !empty( $this->dtend )) { + $this->dtend = ''; + $return = TRUE; + } break; case 'DTSTAMP': - if( in_array( $this->objName, array( 'valarm', 'vtimezone' ))) + if( in_array( $this->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) return FALSE; - if(( 0 < $propix ) || !isset( $this->dtstamp['value'] )) return FALSE; - $this->dtstamp = array(); - return TRUE; + if( !empty( $this->dtstamp )) { + $this->dtstamp = ''; + $return = TRUE; + } break; case 'DTSTART': - if(( 0 < $propix ) || !isset( $this->dtstart['value'] )) return FALSE; - $this->dtstart = array(); - return TRUE; + if( !empty( $this->dtstart )) { + $this->dtstart = ''; + $return = TRUE; + } break; case 'DUE': - if(( 0 < $propix ) || !isset( $this->due['value'] )) return FALSE; - $this->due = array(); - return TRUE; + if( !empty( $this->due )) { + $this->due = ''; + $return = TRUE; + } break; case 'DURATION': - if(( 0 < $propix ) || !isset( $this->duration['value'] )) return FALSE; - $this->duration = array(); - return TRUE; + if( !empty( $this->duration )) { + $this->duration = ''; + $return = TRUE; + } break; case 'EXDATE': - if( !isset( $this->exdate[$propix])) return FALSE; - $this->exdate[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->exdate, $propix ); break; case 'EXRULE': - if( !isset( $this->exrule[$propix])) return FALSE; - $this->exrule[$propix]['value']; - return TRUE; + return $this->deletePropertyM( $this->exrule, $propix ); break; case 'FREEBUSY': - if( !isset( $this->freebusy[$propix])) return FALSE; - $this->freebusy[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->freebusy, $propix ); break; case 'GEO': - if(( 0 < $propix ) || !isset( $this->geo['value'] )) return FALSE; - $this->geo = array(); - return TRUE; + if( !empty( $this->geo )) { + $this->geo = ''; + $return = TRUE; + } break; case 'LAST-MODIFIED': - if(( 0 < $propix ) || !isset( $this->lastmodified['value'] )) return FALSE; - $this->lastmodified = array(); - return TRUE; + if( !empty( $this->lastmodified )) { + $this->lastmodified = ''; + $return = TRUE; + } break; case 'LOCATION': - if(( 0 < $propix ) || !isset( $this->location['value'] )) return FALSE; - $this->location = array(); - return TRUE; + if( !empty( $this->location )) { + $this->location = ''; + $return = TRUE; + } break; case 'ORGANIZER': - if(( 0 < $propix ) || !isset( $this->organizer['value'] )) return FALSE; - $this->organizer = array(); - return TRUE; + if( !empty( $this->organizer )) { + $this->organizer = ''; + $return = TRUE; + } break; case 'PERCENT-COMPLETE': - if(( 0 < $propix ) || !isset( $this->percentcomplete['value'] )) return FALSE; - $this->percentcomplete = array(); - return TRUE; + if( !empty( $this->percentcomplete )) { + $this->percentcomplete = ''; + $return = TRUE; + } break; case 'PRIORITY': - if(( 0 < $propix ) || !isset( $this->priority['value'] )) return FALSE; - $this->priority = array(); - return TRUE; + if( !empty( $this->priority )) { + $this->priority = ''; + $return = TRUE; + } break; case 'RDATE': - if( !isset( $this->rdate[$propix])) return FALSE; - $this->rdate[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->rdate, $propix ); break; case 'RECURRENCE-ID': - if(( 0 < $propix ) || !isset( $this->recurrenceid['value'] )) return FALSE; - $this->recurrenceid = array(); - return TRUE; + if( !empty( $this->recurrenceid )) { + $this->recurrenceid = ''; + $return = TRUE; + } break; case 'RELATED-TO': - if( !isset( $this->relatedto[$propix])) return FALSE; - $this->relatedto[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->relatedto, $propix ); break; case 'REPEAT': - if(( 0 < $propix ) || !isset( $this->repeat['value'] )) return FALSE; - $this->repeat = array(); - return TRUE; + if( !empty( $this->repeat )) { + $this->repeat = ''; + $return = TRUE; + } break; case 'REQUEST-STATUS': - if( !isset( $this->requeststatus[$propix])) return FALSE; - $this->requeststatus[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->requeststatus, $propix ); break; case 'RESOURCES': - if( !isset( $this->resources[$propix])) return FALSE; - $this->resources[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->resources, $propix ); break; case 'RRULE': - if( !isset( $this->rrule[$propix])) return FALSE; - $this->rrule[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->rrule, $propix ); break; case 'SEQUENCE': - if(( 0 < $propix ) || !isset( $this->sequence['value'] )) return FALSE; - $this->sequence = array(); - return TRUE; + if( !empty( $this->sequence )) { + $this->sequence = ''; + $return = TRUE; + } break; case 'STATUS': - if(( 0 < $propix ) || !isset( $this->status['value'] )) return FALSE; - $this->status = array(); - return TRUE; + if( !empty( $this->status )) { + $this->status = ''; + $return = TRUE; + } break; case 'SUMMARY': - if(( 0 < $propix ) || !isset( $this->summary['value'] )) return FALSE; - $this->summary = array(); - return TRUE; + if( !empty( $this->summary )) { + $this->summary = ''; + $return = TRUE; + } break; case 'TRANSP': - if(( 0 < $propix ) || !isset( $this->transp['value'] )) return FALSE; - $this->transp = array(); - return TRUE; + if( !empty( $this->transp )) { + $this->transp = ''; + $return = TRUE; + } break; case 'TRIGGER': - if(( 0 < $propix ) || !isset( $this->trigger['value'] )) return FALSE; - $this->trigger = array(); - return TRUE; + if( !empty( $this->trigger )) { + $this->trigger = ''; + $return = TRUE; + } break; case 'TZID': - if(( 0 < $propix ) || !isset( $this->tzid['value'] )) return FALSE; - $this->tzid = array(); - return TRUE; + if( !empty( $this->tzid )) { + $this->tzid = ''; + $return = TRUE; + } break; case 'TZNAME': - if( !isset( $this->tzname[$propix])) return FALSE; - $this->tzname[$propix] = null; - return TRUE; + return $this->deletePropertyM( $this->tzname, $propix ); break; case 'TZOFFSETFROM': - if(( 0 < $propix ) || !isset( $this->tzoffsetfrom['value'] )) return FALSE; - $this->tzoffsetfrom = array(); - return TRUE; + if( !empty( $this->tzoffsetfrom )) { + $this->tzoffsetfrom = ''; + $return = TRUE; + } break; case 'TZOFFSETTO': - if(( 0 < $propix ) || !isset( $this->tzoffsetto['value'] )) return FALSE; - $this->tzoffsetto = array(); - return TRUE; + if( !empty( $this->tzoffsetto )) { + $this->tzoffsetto = ''; + $return = TRUE; + } break; case 'TZURL': - if(( 0 < $propix ) || !isset( $this->tzurl['value'] )) return FALSE; - $this->tzurl = array(); - return TRUE; + if( !empty( $this->tzurl )) { + $this->tzurl = ''; + $return = TRUE; + } break; case 'UID': - if( in_array( $this->objName, array( 'valarm', 'vtimezone' ))) + if( in_array( $this->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) return FALSE; - if(( 0 < $propix ) || !isset( $this->uid['value'] )) return FALSE; - $this->uid = array(); - return TRUE; + if( !empty( $this->uid )) { + $this->uid = ''; + $return = TRUE; + } break; case 'URL': - if(( 0 < $propix ) || !isset( $this->url['value'] )) return FALSE; - $this->url = array(); - return TRUE; + if( !empty( $this->url )) { + $this->url = ''; + $return = TRUE; + } break; default: + $reduced = ''; if( $propName != 'X-PROP' ) { if( !isset( $this->xprop[$propName] )) return FALSE; - unset( $this->xprop[$propName] ); - return TRUE; + foreach( $this->xprop as $k => $a ) { + if(( $k != $propName ) && !empty( $a )) + $reduced[$k] = $a; + } } else { if( count( $this->xprop ) <= $propix ) return FALSE; $xpropno = 0; foreach( $this->xprop as $xpropkey => $xpropvalue ) { - if( $propix == $xpropno ) { - unset( $this->xprop[$xpropkey] ); - $return = TRUE; - break 2; - } - else - $xpropno++; + if( $propix != $xpropno ) + $reduced[$xpropkey] = $xpropvalue; + $xpropno++; } } + $this->xprop = $reduced; + return TRUE; } return $return; } +/*********************************************************************************/ +/** + * delete component property value, fixing components with multiple occurencies + * + * @author Kjell-Inge Gustafsson + * @since 2.4.5 - 2008-11-07 + * @param array $multiprop, reference to a component property + * @param int @propix, default 0 + * @return bool TRUE + */ + function deletePropertyM( & $multiprop, $propix=0 ) { + if( !isset( $multiprop[$propix])) return FALSE; + unset( $multiprop[$propix] ); + if( empty( $multiprop )) $multiprop = ''; + return ( isset( $this->multiprop[$propix] )) ? FALSE : TRUE; + } /** * get component property value/params * * if property has multiply values, consequtive function calls are needed * * @author Kjell-Inge Gustafsson - * @since 2.1.1 - 2007-07-07 + * @since 2.5.1 - 2008-11-02 * @param string $propName, optional * @param int @propix, optional, if specific property is wanted in case of multiply occurences * @param bool $inclParam=FALSE @@ -6065,193 +5971,168 @@ class calendarComponent { * @return mixed */ function getProperty( $propName=FALSE, $propix=FALSE, $inclParam=FALSE, $specform=FALSE ) { + if( $this->_notExistProp( $propName )) return FALSE; $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP'; - if( !$propix ) - $propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1; - $this->propix[$propName] = --$propix; + if( in_array( $propName, array( 'ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'EXDATE', 'EXRULE', + 'FREEBUSY', 'RDATE', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'TZNAME', 'X-PROP' ))) { + if( !$propix ) + $propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1; + $this->propix[$propName] = --$propix; + } switch( $propName ) { case 'ACTION': - if(( 0 < $propix ) || !isset( $this->action['value'] )) return FALSE; - return ( $inclParam ) ? $this->action : $this->action['value']; + if( !empty( $this->action['value'] )) return ( $inclParam ) ? $this->action : $this->action['value']; break; case 'ATTACH': - if( count( $this->attach ) <= $propix ) return FALSE; + if( !isset( $this->attach[$propix] )) return FALSE; return ( $inclParam ) ? $this->attach[$propix] : $this->attach[$propix]['value']; break; case 'ATTENDEE': - if( count( $this->attendee ) <= $propix ) return FALSE; + if( !isset( $this->attendee[$propix] )) return FALSE; return ( $inclParam ) ? $this->attendee[$propix] : $this->attendee[$propix]['value']; break; case 'CATEGORIES': - if( count( $this->categories ) <= $propix ) return FALSE; + if( !isset( $this->categories[$propix] )) return FALSE; return ( $inclParam ) ? $this->categories[$propix] : $this->categories[$propix]['value']; break; case 'CLASS': - if(( 0 < $propix ) || !isset( $this->class['value'] )) return FALSE; - return ( $inclParam ) ? $this->class : $this->class['value']; + if( !empty( $this->class['value'] )) return ( $inclParam ) ? $this->class : $this->class['value']; break; case 'COMMENT': - if( count( $this->comment ) <= $propix ) return FALSE; + if( !isset( $this->comment[$propix] )) return FALSE; return ( $inclParam ) ? $this->comment[$propix] : $this->comment[$propix]['value']; break; case 'COMPLETED': - if(( 0 < $propix ) || !isset( $this->completed['value'] )) return FALSE; - return ( $inclParam ) ? $this->completed : $this->completed['value']; + if( !empty( $this->completed['value'] )) return ( $inclParam ) ? $this->completed : $this->completed['value']; break; case 'CONTACT': - if( count( $this->contact ) <= $propix ) return FALSE; + if( !isset( $this->contact[$propix] )) return FALSE; return ( $inclParam ) ? $this->contact[$propix] : $this->contact[$propix]['value']; break; case 'CREATED': - if(( 0 < $propix ) || !isset( $this->created['value'] )) return FALSE; - return ( $inclParam ) ? $this->created : $this->created['value']; + if( !empty( $this->created['value'] )) return ( $inclParam ) ? $this->created : $this->created['value']; break; case 'DESCRIPTION': - if( count( $this->description ) <= $propix ) return FALSE; + if( !isset( $this->description[$propix] )) return FALSE; return ( $inclParam ) ? $this->description[$propix] : $this->description[$propix]['value']; break; case 'DTEND': - if(( 0 < $propix ) || !isset( $this->dtend['value'] )) return FALSE; - return ( $inclParam ) ? $this->dtend : $this->dtend['value']; + if( !empty( $this->dtend['value'] )) return ( $inclParam ) ? $this->dtend : $this->dtend['value']; break; case 'DTSTAMP': - if( in_array( $this->objName, array( 'valarm', 'vtimezone' ))) + if( in_array( $this->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) return; - if( 0 < $propix ) - return null; if( !isset( $this->dtstamp['value'] )) $this->_makeDtstamp(); return ( $inclParam ) ? $this->dtstamp : $this->dtstamp['value']; break; case 'DTSTART': - if(( 0 < $propix ) || !isset( $this->dtstart['value'] )) return FALSE; - return ( $inclParam ) ? $this->dtstart : $this->dtstart['value']; + if( !empty( $this->dtstart['value'] )) return ( $inclParam ) ? $this->dtstart : $this->dtstart['value']; break; case 'DUE': - if(( 0 < $propix ) || !isset( $this->due['value'] )) return FALSE; - return ( $inclParam ) ? $this->due : $this->due['value']; + if( !empty( $this->due['value'] )) return ( $inclParam ) ? $this->due : $this->due['value']; break; case 'DURATION': - if(( 0 < $propix ) || !isset( $this->duration['value'] )) return FALSE; + if( !isset( $this->duration['value'] )) return FALSE; $value = ( $specform ) ? $this->duration2date() : $this->duration['value']; return ( $inclParam ) ? array( 'value' => $value, 'params' => $this->duration['params'] ) : $value; break; case 'EXDATE': - if( count( $this->exdate ) <= $propix ) return FALSE; + if( !isset( $this->exdate[$propix] )) return FALSE; return ( $inclParam ) ? $this->exdate[$propix] : $this->exdate[$propix]['value']; break; case 'EXRULE': - if( count( $this->exrule ) <= $propix ) return FALSE; + if( !isset( $this->exrule[$propix] )) return FALSE; return ( $inclParam ) ? $this->exrule[$propix] : $this->exrule[$propix]['value']; break; case 'FREEBUSY': - if( count( $this->freebusy ) <= $propix ) return FALSE; + if( !isset( $this->freebusy[$propix] )) return FALSE; return ( $inclParam ) ? $this->freebusy[$propix] : $this->freebusy[$propix]['value']; break; case 'GEO': - if(( 0 < $propix ) || !isset( $this->geo['value'] )) return FALSE; - return ( $inclParam ) ? $this->geo : $this->geo['value']; + if( !empty( $this->geo['value'] )) return ( $inclParam ) ? $this->geo : $this->geo['value']; break; case 'LAST-MODIFIED': - if(( 0 < $propix ) || !isset( $this->lastmodified['value'] )) return FALSE; - return ( $inclParam ) ? $this->lastmodified : $this->lastmodified['value']; + if( !empty( $this->lastmodified['value'] )) return ( $inclParam ) ? $this->lastmodified : $this->lastmodified['value']; break; case 'LOCATION': - if(( 0 < $propix ) || !isset( $this->location['value'] )) return FALSE; - return ( $inclParam ) ? $this->location : $this->location['value']; + if( !empty( $this->location['value'] )) return ( $inclParam ) ? $this->location : $this->location['value']; break; case 'ORGANIZER': - if(( 0 < $propix ) || !isset( $this->organizer['value'] )) return FALSE; - return ( $inclParam ) ? $this->organizer : $this->organizer['value']; + if( !empty( $this->organizer['value'] )) return ( $inclParam ) ? $this->organizer : $this->organizer['value']; break; case 'PERCENT-COMPLETE': - if(( 0 < $propix ) || !isset( $this->percentcomplete['value'] )) return FALSE; - return ( $inclParam ) ? $this->percentcomplete : $this->percentcomplete['value']; + if( !empty( $this->percentcomplete['value'] )) return ( $inclParam ) ? $this->percentcomplete : $this->percentcomplete['value']; break; case 'PRIORITY': - if(( 0 < $propix ) || !isset( $this->priority['value'] )) return FALSE; - return ( $inclParam ) ? $this->priority : $this->priority['value']; + if( !empty( $this->priority['value'] )) return ( $inclParam ) ? $this->priority : $this->priority['value']; break; case 'RDATE': - if( count( $this->rdate ) <= $propix ) return FALSE; + if( !isset( $this->rdate[$propix] )) return FALSE; return ( $inclParam ) ? $this->rdate[$propix] : $this->rdate[$propix]['value']; break; case 'RECURRENCE-ID': - if(( 0 < $propix ) || !isset( $this->recurrenceid['value'] )) return FALSE; - return ( $inclParam ) ? $this->recurrenceid : $this->recurrenceid['value']; + if( !empty( $this->recurrenceid['value'] )) return ( $inclParam ) ? $this->recurrenceid : $this->recurrenceid['value']; break; case 'RELATED-TO': - if( count( $this->relatedto ) <= $propix ) return FALSE; + if( !isset( $this->relatedto[$propix] )) return FALSE; return ( $inclParam ) ? $this->relatedto[$propix] : $this->relatedto[$propix]['value']; break; case 'REPEAT': - if(( 0 < $propix ) || !isset( $this->repeat['value'] )) return FALSE; - return ( $inclParam ) ? $this->repeat : $this->repeat['value']; + if( !empty( $this->repeat['value'] )) return ( $inclParam ) ? $this->repeat : $this->repeat['value']; break; case 'REQUEST-STATUS': - if( count( $this->requeststatus ) <= $propix ) return FALSE; + if( !isset( $this->requeststatus[$propix] )) return FALSE; return ( $inclParam ) ? $this->requeststatus[$propix] : $this->requeststatus[$propix]['value']; break; case 'RESOURCES': - if( count( $this->resources ) <= $propix ) return FALSE; + if( !isset( $this->resources[$propix] )) return FALSE; return ( $inclParam ) ? $this->resources[$propix] : $this->resources[$propix]['value']; break; case 'RRULE': - if( count( $this->rrule ) <= $propix ) return FALSE; + if( !isset( $this->rrule[$propix] )) return FALSE; return ( $inclParam ) ? $this->rrule[$propix] : $this->rrule[$propix]['value']; break; case 'SEQUENCE': - if(( 0 < $propix ) || !isset( $this->sequence['value'] )) return FALSE; - return ( $inclParam ) ? $this->sequence : $this->sequence['value']; + if( !empty( $this->sequence['value'] )) return ( $inclParam ) ? $this->sequence : $this->sequence['value']; break; case 'STATUS': - if(( 0 < $propix ) || !isset( $this->status['value'] )) return FALSE; - return ( $inclParam ) ? $this->status : $this->status['value']; + if( !empty( $this->status['value'] )) return ( $inclParam ) ? $this->status : $this->status['value']; break; case 'SUMMARY': - if(( 0 < $propix ) || !isset( $this->summary['value'] )) return FALSE; - return ( $inclParam ) ? $this->summary : $this->summary['value']; + if( !empty( $this->summary['value'] )) return ( $inclParam ) ? $this->summary : $this->summary['value']; break; case 'TRANSP': - if(( 0 < $propix ) || !isset( $this->transp['value'] )) return FALSE; - return ( $inclParam ) ? $this->transp : $this->transp['value']; + if( !empty( $this->transp['value'] )) return ( $inclParam ) ? $this->transp : $this->transp['value']; break; case 'TRIGGER': - if(( 0 < $propix ) || !isset( $this->trigger['value'] )) return FALSE; - return ( $inclParam ) ? $this->trigger : $this->trigger['value']; + if( !empty( $this->trigger['value'] )) return ( $inclParam ) ? $this->trigger : $this->trigger['value']; break; case 'TZID': - if(( 0 < $propix ) || !isset( $this->tzid['value'] )) return FALSE; - return ( $inclParam ) ? $this->tzid : $this->tzid['value']; + if( !empty( $this->tzid['value'] )) return ( $inclParam ) ? $this->tzid : $this->tzid['value']; break; case 'TZNAME': - if( count( $this->tzname ) <= $propix ) return FALSE; + if( !isset( $this->tzname[$propix] )) return FALSE; return ( $inclParam ) ? $this->tzname[$propix] : $this->tzname[$propix]['value']; break; case 'TZOFFSETFROM': - if(( 0 < $propix ) || !isset( $this->tzoffsetfrom['value'] )) return FALSE; - return ( $inclParam ) ? $this->tzoffsetfrom : $this->tzoffsetfrom['value']; + if( !empty( $this->tzoffsetfrom['value'] )) return ( $inclParam ) ? $this->tzoffsetfrom : $this->tzoffsetfrom['value']; break; case 'TZOFFSETTO': - if(( 0 < $propix ) || !isset( $this->tzoffsetto['value'] )) return FALSE; - return ( $inclParam ) ? $this->tzoffsetto : $this->tzoffsetto['value']; + if( !empty( $this->tzoffsetto['value'] )) return ( $inclParam ) ? $this->tzoffsetto : $this->tzoffsetto['value']; break; case 'TZURL': - if(( 0 < $propix ) || !isset( $this->tzurl['value'] )) return FALSE; - return ( $inclParam ) ? $this->tzurl : $this->tzurl['value']; + if( !empty( $this->tzurl['value'] )) return ( $inclParam ) ? $this->tzurl : $this->tzurl['value']; break; case 'UID': - if( in_array( $this->objName, array( 'valarm', 'vtimezone' ))) - return; - if( 0 < $propix ) - return null; + if( in_array( $this->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) + return FALSE; if( empty( $this->uid['value'] )) $this->_makeuid(); return ( $inclParam ) ? $this->uid : $this->uid['value']; break; case 'URL': - if(( 0 < $propix ) || !isset( $this->url['value'] )) return FALSE; - return ( $inclParam ) ? $this->url : $this->url['value']; + if( !empty( $this->url['value'] )) return ( $inclParam ) ? $this->url : $this->url['value']; break; default: if( $propName != 'X-PROP' ) { @@ -6260,7 +6141,7 @@ class calendarComponent { : array( $propName, $this->xprop[$propName]['value'] ); } else { - if( count( $this->xprop ) <= $propix ) return FALSE; + if( empty( $this->xprop )) return FALSE; $xpropno = 0; foreach( $this->xprop as $xpropkey => $xpropvalue ) { if( $propix == $xpropno ) @@ -6278,7 +6159,7 @@ class calendarComponent { * general component property setting * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-25 + * @since 2.5.1 - 2008-11-05 * @param mixed $args variable number of function arguments, * first argument is ALWAYS component name, * second ALWAYS component value! @@ -6286,11 +6167,11 @@ class calendarComponent { */ function setProperty() { $numargs = func_num_args(); - if( 1 > $numargs ) - return FALSE; + if( 1 > $numargs ) return FALSE; $arglist = func_get_args(); + if( $this->_notExistProp( $arglist[0] )) return FALSE; if( !$this->getConfig( 'allowEmpty' ) && ( !isset( $arglist[1] ) || empty( $arglist[1] ))) - return; + return FALSE; $arglist[0] = strtoupper( $arglist[0] ); for( $argix=$numargs; $argix < 12; $argix++ ) { if( !isset( $arglist[$argix] )) @@ -6298,146 +6179,103 @@ class calendarComponent { } switch( $arglist[0] ) { case 'ACTION': - $this->setAction( $arglist[1], $arglist[2] ); - break; + return $this->setAction( $arglist[1], $arglist[2] ); case 'ATTACH': - $this->setAttach( $arglist[1], $arglist[2] ); - break; + return $this->setAttach( $arglist[1], $arglist[2], $arglist[3] ); case 'ATTENDEE': - $this->setAttendee( $arglist[1], $arglist[2] ); - break; + return $this->setAttendee( $arglist[1], $arglist[2], $arglist[3] ); case 'CATEGORIES': - $this->setCategories( $arglist[1], $arglist[2] ); - break; + return $this->setCategories( $arglist[1], $arglist[2], $arglist[3] ); case 'CLASS': - $this->setClass( $arglist[1], $arglist[2] ); - break; + return $this->setClass( $arglist[1], $arglist[2] ); case 'COMMENT': - $this->setComment( $arglist[1], $arglist[2] ); - break; + return $this->setComment( $arglist[1], $arglist[2], $arglist[3] ); case 'COMPLETED': - $this->setCompleted( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); - break; + return $this->setCompleted( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); case 'CONTACT': - $this->setContact( $arglist[1], $arglist[2] ); - break; + return $this->setContact( $arglist[1], $arglist[2], $arglist[3] ); case 'CREATED': - $this->setCreated( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); - break; + return $this->setCreated( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); case 'DESCRIPTION': - $this->setDescription( $arglist[1], $arglist[2] ); - break; + return $this->setDescription( $arglist[1], $arglist[2], $arglist[3] ); case 'DTEND': - $this->setDtend( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); - break; + return $this->setDtend( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); case 'DTSTAMP': - $this->setDtstamp( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); - break; + return $this->setDtstamp( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); case 'DTSTART': - $this->setDtstart( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); - break; + return $this->setDtstart( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); case 'DUE': - $this->setDue( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); - break; + return $this->setDue( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); case 'DURATION': - $this->setDuration( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6] ); - break; + return $this->setDuration( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6] ); case 'EXDATE': - $this->setExdate( $arglist[1], $arglist[2] ); - break; + return $this->setExdate( $arglist[1], $arglist[2], $arglist[3] ); case 'EXRULE': - $this->setExrule( $arglist[1], $arglist[2] ); - break; + return $this->setExrule( $arglist[1], $arglist[2], $arglist[3] ); case 'FREEBUSY': - $this->setFreebusy( $arglist[1], $arglist[2], $arglist[3] ); - break; + return $this->setFreebusy( $arglist[1], $arglist[2], $arglist[3], $arglist[4] ); case 'GEO': - $this->setGeo( $arglist[1], $arglist[2], $arglist[3] ); - break; + return $this->setGeo( $arglist[1], $arglist[2], $arglist[3] ); case 'LAST-MODIFIED': - $this->setLastModified( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); - break; + return $this->setLastModified( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7] ); case 'LOCATION': - $this->setLocation( $arglist[1], $arglist[2] ); - break; + return $this->setLocation( $arglist[1], $arglist[2] ); case 'ORGANIZER': - $this->setOrganizer( $arglist[1], $arglist[2] ); - break; + return $this->setOrganizer( $arglist[1], $arglist[2] ); case 'PERCENT-COMPLETE': - $this->setPercentComplete( $arglist[1], $arglist[2] ); - break; + return $this->setPercentComplete( $arglist[1], $arglist[2] ); case 'PRIORITY': - $this->setPriority( $arglist[1], $arglist[2] ); - break; + return $this->setPriority( $arglist[1], $arglist[2] ); case 'RDATE': - $this->setRdate( $arglist[1], $arglist[2] ); - break; + return $this->setRdate( $arglist[1], $arglist[2], $arglist[3] ); case 'RECURRENCE-ID': - $this->setRecurrenceid( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); - break; + return $this->setRecurrenceid( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8] ); case 'RELATED-TO': - $this->setRelatedTo( $arglist[1], $arglist[2] ); - break; + return $this->setRelatedTo( $arglist[1], $arglist[2], $arglist[3] ); case 'REPEAT': - $this->setRepeat( $arglist[1], $arglist[2] ); - break; + return $this->setRepeat( $arglist[1], $arglist[2] ); case 'REQUEST-STATUS': - $this->setRequestStatus( $arglist[1], $arglist[2], $arglist[3], $arglist[4] ); - break; + return $this->setRequestStatus( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5] ); case 'RESOURCES': - $this->setResources( $arglist[1], $arglist[2] ); - break; + return $this->setResources( $arglist[1], $arglist[2], $arglist[3] ); case 'RRULE': - $this->setRrule( $arglist[1], $arglist[2] ); - break; + return $this->setRrule( $arglist[1], $arglist[2], $arglist[3] ); case 'SEQUENCE': - $this->setSequence( $arglist[1], $arglist[2] ); - break; + return $this->setSequence( $arglist[1], $arglist[2] ); case 'STATUS': - $this->setStatus( $arglist[1], $arglist[2] ); - break; + return $this->setStatus( $arglist[1], $arglist[2] ); case 'SUMMARY': - $this->setSummary( $arglist[1], $arglist[2] ); - break; + return $this->setSummary( $arglist[1], $arglist[2] ); case 'TRANSP': - $this->setTransp( $arglist[1], $arglist[2] ); - break; + return $this->setTransp( $arglist[1], $arglist[2] ); case 'TRIGGER': - $this->setTrigger( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8], $arglist[9], $arglist[10], $arglist[11] ); - break; + return $this->setTrigger( $arglist[1], $arglist[2], $arglist[3], $arglist[4], $arglist[5], $arglist[6], $arglist[7], $arglist[8], $arglist[9], $arglist[10], $arglist[11] ); case 'TZID': - $this->setTzid( $arglist[1], $arglist[2] ); - break; + return $this->setTzid( $arglist[1], $arglist[2] ); case 'TZNAME': - $this->setTzname( $arglist[1], $arglist[2] ); - break; + return $this->setTzname( $arglist[1], $arglist[2], $arglist[3] ); case 'TZOFFSETFROM': - $this->setTzoffsetfrom( $arglist[1], $arglist[2] ); - break; + return $this->setTzoffsetfrom( $arglist[1], $arglist[2] ); case 'TZOFFSETTO': - $this->setTzoffsetto( $arglist[1], $arglist[2] ); - break; + return $this->setTzoffsetto( $arglist[1], $arglist[2] ); case 'TZURL': - $this->setTzurl( $arglist[1], $arglist[2] ); - break; + return $this->setTzurl( $arglist[1], $arglist[2] ); case 'UID': - $this->setUid( $arglist[1], $arglist[2] ); - break; + return $this->setUid( $arglist[1], $arglist[2] ); case 'URL': - $this->setUrl( $arglist[1], $arglist[2] ); - break; + return $this->setUrl( $arglist[1], $arglist[2] ); default: - $this->setXprop( $arglist[0], $arglist[1], $arglist[2] ); - break; + return $this->setXprop( $arglist[0], $arglist[1], $arglist[2] ); } + return FALSE; } /*********************************************************************************/ /** * parse component unparsed data into properties * * @author Kjell-Inge Gustafsson - * @since 2.4.2 - 2008-02-07 - * @param mixed $unparsedtext, strict rfc2445 formatted, single property string or array of property strings + * @since 2.5.2 - 2008-10-23 + * @param mixed $unparsedtext, optional, strict rfc2445 formatted, single property string or array of property strings * @return bool FALSE if error occurs during parsing * */ @@ -6461,16 +6299,10 @@ class calendarComponent { } } else - $this->unparsed = array( $unparsedtext ); + $this->unparsed = array( trim( $unparsedtext )); } elseif( !isset( $this->unparsed )) $this->unparsed = array(); -/* - elseif( !isset( $this->unparsed ) || !is_array( $this->unparsed ) || ( 0 >= count( $this->unparsed ))) { - unset( $this->unparsed ); - return FALSE; - } -*/ /* concatenate property values spread over several lines */ $lastix = -1; $propnames = array( 'action', 'attach', 'attendee', 'categories', 'comment', 'completed' @@ -6585,6 +6417,7 @@ class calendarComponent { } } if( 1 < count( $content )) { + $content = array_values( $content ); foreach( $content as $cix => $contentPart ) $content[$cix] = $this->_strunrep( $contentPart ); $this->setProperty( $propname, $content, $propattr ); @@ -6600,17 +6433,19 @@ class calendarComponent { case 'DESCRIPTION': case 'LOCATION': case 'SUMMARY': + if( empty( $line )) + $propattr = null; $this->setProperty( $propname, $this->_strunrep( $line ), $propattr ); unset( $propname2 ); break; case 'REQUEST-STATUS': - $values = explode( ';', $line ); - if( !isset( $values[2] )) - $values[2] = FALSE; + $values = explode( ';', $line, 3 ); + $values[1] = ( !isset( $values[1] )) ? null : $this->_strunrep( $values[1] ); + $values[2] = ( !isset( $values[2] )) ? null : $this->_strunrep( $values[2] ); $this->setProperty( $propname - , $values[0] // statcode - , $this->_strunrep( $values[1] ) // statdesc - , $this->_strunrep( $values[2] ) // extdata + , $values[0] // statcode + , $values[1] // statdesc + , $values[2] // extdata , $propattr ); break; case 'FREEBUSY': @@ -6625,14 +6460,20 @@ class calendarComponent { $this->setProperty( $propname, $fbtype, $values, $propattr ); break; case 'GEO': - $value= explode( ';', $line, 2 ); + $value = explode( ';', $line, 2 ); + if( 2 > count( $value )) + $value[1] = null; $this->setProperty( $propname, $value[0], $value[1], $propattr ); break; case 'EXDATE': - $values= explode( ',', $line ); + $values = ( !empty( $line )) ? explode( ',', $line ) : null; $this->setProperty( $propname, $values, $propattr ); break; case 'RDATE': + if( empty( $line )) { + $this->setProperty( $propname, $line, $propattr ); + break; + } $values = explode( ',', $line ); foreach( $values as $vix => $value ) { $value2 = explode( '/', $value ); @@ -6706,7 +6547,7 @@ class calendarComponent { } // end switch( $propname.. . } // end - foreach( $proprows.. . unset( $this->unparsed, $proprows ); - if( is_array( $this->components ) && ( 0 < count( $this->components ))) { + if( isset( $this->components ) && is_array( $this->components ) && ( 0 < count( $this->components ))) { for( $six = 0; $six < count( $this->components ); $six++ ) { if( !empty( $this->components[$six]->unparsed )) $this->components[$six]->parse(); @@ -6734,12 +6575,13 @@ class calendarComponent { * delete calendar subcomponent from component container * * @author Kjell-Inge Gustafsson - * @since 2.0.4 - 2007-06-20 + * @since 2.5.1 - 2008-10-15 * @param mixed $arg1 ordno / component type / component uid * @param mixed $arg2 optional, ordno if arg1 = component type * @return void */ function deleteComponent( $arg1, $arg2=FALSE ) { + if( !isset( $this->components )) return FALSE; $argType = $index = null; if ( ctype_digit( (string) $arg1 )) { $argType = 'INDEX'; @@ -6747,10 +6589,11 @@ class calendarComponent { } elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) { $argType = strtolower( $arg1 ); - $index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 1; + $index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0; } $cix2dC = 0; foreach ( $this->components as $cix => $component) { + if( empty( $component )) continue; unset( $component->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) { unset( $this->components[$cix] ); @@ -6774,12 +6617,13 @@ class calendarComponent { * get calendar component subcomponent from component container * * @author Kjell-Inge Gustafsson - * @since 2.2.16 - 2007-11-11 + * @since 2.5.1 - 2008-10-15 * @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 ) { + if( !isset( $this->components )) return FALSE; $index = $argType = null; if ( !$arg1 ) { $argType = 'INDEX'; @@ -6805,7 +6649,8 @@ class calendarComponent { if( !empty( $index) && ( $index > end( $ckeys ))) return FALSE; $cix2gC = 0; - foreach ( $this->components as $cix => $component ) { + foreach( $this->components as $cix => $component ) { + if( empty( $component )) continue; unset( $component->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) return $component->copy(); @@ -6838,20 +6683,21 @@ class calendarComponent { * add calendar component as subcomponent to container for subcomponents * * @author Kjell-Inge Gustafsson - * @since 2.2.16 - 2007-11-11 + * @since 2.4.13 - 2008-09-24 * @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 + * @return bool */ function setComponent( $component, $arg1=FALSE, $arg2=FALSE ) { + if( !isset( $this->components )) return 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' ))) { + if( !in_array( $component->objName, array( 'valarm', 'vtimezone', 'standard', 'daylight' ))) { unset( $component->propix ); /* make sure dtstamp and uid is set */ $dummy = $component->getProperty( 'dtstamp' ); @@ -6872,6 +6718,7 @@ class calendarComponent { } $cix2sC = 0; foreach ( $this->components as $cix => $component2 ) { + if( empty( $component2 )) continue; unset( $component2->propix ); if(( 'INDEX' == $argType ) && ( $index == $cix )) { $this->components[$cix] = $component->copy(); @@ -6891,17 +6738,19 @@ class calendarComponent { } /* not found.. . insert anyway.. .*/ $this->components[] = $component->copy(); + return TRUE; } /** * creates formatted output for subcomponents * * @author Kjell-Inge Gustafsson - * @since 2.2.13 - 2007-10-25 + * @since 2.4.10 - 2008-08-06 * @return string */ function createSubComponent() { $output = null; foreach( $this->components as $component ) { + if( empty( $component )) continue; if( '' >= $component->getConfig( 'language')) $component->setConfig( 'language', $this->getConfig( 'language' )); $component->setConfig( 'allowEmpty', $this->getConfig( 'allowEmpty' )); @@ -7019,24 +6868,90 @@ class calendarComponent { * class for calendar component VEVENT * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-12 */ class vevent extends calendarComponent { + var $attach; + var $attendee; + var $categories; + var $comment; + var $contact; + var $class; + var $created; + var $description; + var $dtend; + var $dtstart; + var $duration; + var $exdate; + var $exrule; + var $geo; + var $lastmodified; + var $location; + var $organizer; + var $priority; + var $rdate; + var $recurrenceid; + var $relatedto; + var $requeststatus; + var $resources; + var $rrule; + var $sequence; + var $status; + var $summary; + var $transp; + var $url; + var $xprop; + // component subcomponents container + var $components; /** * constructor for calendar component VEVENT object * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-31 * @return void */ function vevent() { $this->calendarComponent(); + + $this->attach = ''; + $this->attendee = ''; + $this->categories = ''; + $this->class = ''; + $this->comment = ''; + $this->contact = ''; + $this->created = ''; + $this->description = ''; + $this->dtstart = ''; + $this->dtend = ''; + $this->duration = ''; + $this->exdate = ''; + $this->exrule = ''; + $this->geo = ''; + $this->lastmodified = ''; + $this->location = ''; + $this->organizer = ''; + $this->priority = ''; + $this->rdate = ''; + $this->recurrenceid = ''; + $this->relatedto = ''; + $this->requeststatus = ''; + $this->resources = ''; + $this->rrule = ''; + $this->sequence = ''; + $this->status = ''; + $this->summary = ''; + $this->transp = ''; + $this->url = ''; + $this->xprop = ''; + + $this->components = array(); + } /** * create formatted output for calendar component VEVENT object instance * * @author Kjell-Inge Gustafsson - * @since 2.3.1 - 2007-11-19 + * @since 2.5.1 - 2008-11-07 * @param array $xcaldecl * @return string */ @@ -7053,8 +6968,8 @@ class vevent extends calendarComponent { $component .= $this->createClass(); $component .= $this->createCreated(); $component .= $this->createDescription(); - $component .= $this->createDtend(); $component .= $this->createDtstart(); + $component .= $this->createDtend(); $component .= $this->createDuration(); $component .= $this->createExdate(); $component .= $this->createExrule(); @@ -7064,19 +6979,17 @@ class vevent extends calendarComponent { $component .= $this->createOrganizer(); $component .= $this->createPriority(); $component .= $this->createRdate(); + $component .= $this->createRrule(); $component .= $this->createRelatedTo(); $component .= $this->createRequestStatus(); $component .= $this->createRecurrenceid(); $component .= $this->createResources(); - $component .= $this->createRrule(); $component .= $this->createSequence(); $component .= $this->createStatus(); $component .= $this->createSummary(); $component .= $this->createTransp(); $component .= $this->createUrl(); $component .= $this->createXprop(); - if( $this->nl != substr( $component, ( 0 - strlen( $this->nl )))) - $component .= $this->nl; $component .= $this->createSubComponent(); $component .= $this->componentEnd1.$objectname.$this->componentEnd2; if( is_array( $this->xcaldecl ) && ( 0 < count( $this->xcaldecl ))) { @@ -7092,24 +7005,91 @@ class vevent extends calendarComponent { * class for calendar component VTODO * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-12 */ class vtodo extends calendarComponent { + var $attach; + var $attendee; + var $categories; + var $comment; + var $completed; + var $contact; + var $class; + var $created; + var $description; + var $dtstart; + var $due; + var $duration; + var $exdate; + var $exrule; + var $geo; + var $lastmodified; + var $location; + var $organizer; + var $percentcomplete; + var $priority; + var $rdate; + var $recurrenceid; + var $relatedto; + var $requeststatus; + var $resources; + var $rrule; + var $sequence; + var $status; + var $summary; + var $url; + var $xprop; + // component subcomponents container + var $components; /** * constructor for calendar component VTODO object * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-31 * @return void */ function vtodo() { $this->calendarComponent(); + + $this->attach = ''; + $this->attendee = ''; + $this->categories = ''; + $this->class = ''; + $this->comment = ''; + $this->completed = ''; + $this->contact = ''; + $this->created = ''; + $this->description = ''; + $this->dtstart = ''; + $this->due = ''; + $this->duration = ''; + $this->exdate = ''; + $this->exrule = ''; + $this->geo = ''; + $this->lastmodified = ''; + $this->location = ''; + $this->organizer = ''; + $this->percentcomplete = ''; + $this->priority = ''; + $this->rdate = ''; + $this->recurrenceid = ''; + $this->relatedto = ''; + $this->requeststatus = ''; + $this->resources = ''; + $this->rrule = ''; + $this->sequence = ''; + $this->status = ''; + $this->summary = ''; + $this->url = ''; + $this->xprop = ''; + + $this->components = array(); } /** * create formatted output for calendar component VTODO object instance * * @author Kjell-Inge Gustafsson - * @since 2.3.1 - 2007-11-19 + * @since 2.5.1 - 2008-11-07 * @param array $xcaldecl * @return string */ @@ -7149,8 +7129,6 @@ class vtodo extends calendarComponent { $component .= $this->createSummary(); $component .= $this->createUrl(); $component .= $this->createXprop(); - if( $this->nl != substr( $component, ( 0 - strlen( $this->nl )))) - $component .= $this->nl; $component .= $this->createSubComponent(); $component .= $this->componentEnd1.$objectname.$this->componentEnd2; if( is_array( $this->xcaldecl ) && ( 0 < count( $this->xcaldecl ))) { @@ -7166,24 +7144,71 @@ class vtodo extends calendarComponent { * class for calendar component VJOURNAL * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-12 */ class vjournal extends calendarComponent { + var $attach; + var $attendee; + var $categories; + var $comment; + var $contact; + var $class; + var $created; + var $description; + var $dtstart; + var $exdate; + var $exrule; + var $lastmodified; + var $organizer; + var $rdate; + var $recurrenceid; + var $relatedto; + var $requeststatus; + var $rrule; + var $sequence; + var $status; + var $summary; + var $url; + var $xprop; /** * constructor for calendar component VJOURNAL object * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-31 * @return void */ function vjournal() { $this->calendarComponent(); + + $this->attach = ''; + $this->attendee = ''; + $this->categories = ''; + $this->class = ''; + $this->comment = ''; + $this->contact = ''; + $this->created = ''; + $this->description = ''; + $this->dtstart = ''; + $this->exdate = ''; + $this->exrule = ''; + $this->lastmodified = ''; + $this->organizer = ''; + $this->rdate = ''; + $this->recurrenceid = ''; + $this->relatedto = ''; + $this->requeststatus = ''; + $this->rrule = ''; + $this->sequence = ''; + $this->status = ''; + $this->summary = ''; + $this->url = ''; + $this->xprop = ''; } /** * create formatted output for calendar component VJOURNAL object instance * * @author Kjell-Inge Gustafsson - * @since 2.3.1 - 2007-11-19 + * @since 2.5.1 - 2008-10-12 * @param array $xcaldecl * @return string */ @@ -7229,18 +7254,43 @@ class vjournal extends calendarComponent { * class for calendar component VFREEBUSY * * @author Kjell-Inge Gustafsson - * @since 0.7.3 - 2006-09-09 + * @since 2.5.1 - 2008-10-12 */ class vfreebusy extends calendarComponent { + var $attendee; + var $comment; + var $contact; + var $dtend; + var $dtstart; + var $duration; + var $freebusy; + var $organizer; + var $requeststatus; + var $url; + var $xprop; + // component subcomponents container + var $components; /** * constructor for calendar component VFREEBUSY object * * @author Kjell-Inge Gustafsson - * @since 0.7.3 - 2006-09-09 + * @since 2.5.1 - 2008-10-31 * @return void */ function vfreebusy() { $this->calendarComponent(); + + $this->attendee = ''; + $this->comment = ''; + $this->contact = ''; + $this->dtend = ''; + $this->dtstart = ''; + $this->duration = ''; + $this->freebusy = ''; + $this->organizer = ''; + $this->requeststatus = ''; + $this->url = ''; + $this->xprop = ''; } /** * create formatted output for calendar component VFREEBUSY object instance @@ -7258,8 +7308,8 @@ class vfreebusy extends calendarComponent { $component .= $this->createAttendee(); $component .= $this->createComment(); $component .= $this->createContact(); - $component .= $this->createDtend(); $component .= $this->createDtstart(); + $component .= $this->createDtend(); $component .= $this->createDuration(); $component .= $this->createFreebusy(); $component .= $this->createOrganizer(); @@ -7280,24 +7330,43 @@ class vfreebusy extends calendarComponent { * class for calendar component VALARM * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-12 */ class valarm extends calendarComponent { + var $action; + var $attach; + var $attendee; + var $description; + var $duration; + var $repeat; + var $summary; + var $trigger; + var $xprop; /** * constructor for calendar component VALARM object * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-10 + * @since 2.5.1 - 2008-10-31 * @return void */ function valarm() { $this->calendarComponent(); + + $this->action = ''; + $this->attach = ''; + $this->attendee = ''; + $this->description = ''; + $this->duration = ''; + $this->repeat = ''; + $this->summary = ''; + $this->trigger = ''; + $this->xprop = ''; } /** * create formatted output for calendar component VALARM object instance * * @author Kjell-Inge Gustafsson - * @since 2.0.6 - 2007-06-20 + * @since 2.5.1 - 2008-10-22 * @param array $xcaldecl * @return string */ @@ -7314,10 +7383,6 @@ class valarm extends calendarComponent { $component .= $this->createTrigger(); $component .= $this->createXprop(); $component .= $this->componentEnd1.$objectname.$this->componentEnd2; - if( is_array( $this->xcaldecl ) && ( 0 < count( $this->xcaldecl ))) { - foreach( $this->xcaldecl as $localxcaldecl ) - $xcaldecl[] = $localxcaldecl; - } return $component; } } @@ -7327,15 +7392,29 @@ class valarm extends calendarComponent { * class for calendar component VTIMEZONE * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-13 + * @since 2.5.1 - 2008-10-12 */ class vtimezone extends calendarComponent { var $timezonetype; + + var $comment; + var $dtstart; + var $lastmodified; + var $rdate; + var $rrule; + var $tzid; + var $tzname; + var $tzoffsetfrom; + var $tzoffsetto; + var $tzurl; + var $xprop; + // component subcomponents container + var $components; /** * constructor for calendar component VTIMEZONE object * * @author Kjell-Inge Gustafsson - * @since 0.3.0 - 2006-08-13 + * @since 2.5.1 - 2008-10-31 * @param string $timezonetype optional, default FALSE ( STANDARD / DAYLIGHT ) * @return void */ @@ -7345,12 +7424,26 @@ class vtimezone extends calendarComponent { else $this->timezonetype = strtoupper( $timezonetype ); $this->calendarComponent(); + + $this->comment = ''; + $this->dtstart = ''; + $this->lastmodified = ''; + $this->rdate = ''; + $this->rrule = ''; + $this->tzid = ''; + $this->tzname = ''; + $this->tzoffsetfrom = ''; + $this->tzoffsetto = ''; + $this->tzurl = ''; + $this->xprop = ''; + + $this->components = array(); } /** * create formatted output for calendar component VTIMEZONE object instance * * @author Kjell-Inge Gustafsson - * @since 2.0.6 - 2007-06-20 + * @since 2.5.1 - 2008-10-25 * @param array $xcaldecl * @return string */ @@ -7360,16 +7453,14 @@ class vtimezone extends calendarComponent { $component .= $this->createTzid(); $component .= $this->createLastModified(); $component .= $this->createTzurl(); - $component .= $this->createDtstart( TRUE ); + $component .= $this->createDtstart(); $component .= $this->createTzoffsetfrom(); $component .= $this->createTzoffsetto(); $component .= $this->createComment(); - $component .= $this->createRdate( TRUE ); + $component .= $this->createRdate(); $component .= $this->createRrule(); $component .= $this->createTzname(); $component .= $this->createXprop(); - if( $this->nl != substr( $component, ( 0 - strlen( $this->nl )))) - $component .= $this->nl; $component .= $this->createSubComponent(); $component .= $this->componentEnd1.$objectname.$this->componentEnd2; if( is_array( $this->xcaldecl ) && ( 0 < count( $this->xcaldecl ))) {