/wp-content/plugins/all-in-one-event-calendar/lib/iCal/iCalcreator-2.20/iCalcreator.class.php
PHP | 10543 lines | 8068 code | 31 blank | 2444 comment | 2377 complexity | ca019c5514c8c616bf64eacb28151ef2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*********************************************************************************/
- /**
- *
- * This file is a PHP implementation of rfc2445/rfc5545.
- *
- * @copyright Copyright (c) 2007-2014 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
- * @link http://kigkonsult.se/iCalcreator/index.php
- * @license http://kigkonsult.se/downloads/dl.php?f=LGPL
- * @package iCalcreator
- * @version v2.20
- */
- /**
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /*********************************************************************************/
- /**
- * Do NOT remove or change version!!
- *
- * @copyright Copyright (c) 2007-2014 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
- * @license http://kigkonsult.se/downloads/dl.php?f=LGPL
- */
- define( 'ICALCREATOR_VERSION', 'iCalcreator 2.20' );
- /*********************************************************************************/
- /**
- * vcalendar class
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.9.6 - 2011-05-14
- */
- class vcalendar {
- // calendar property variables
- var $calscale;
- var $method;
- var $prodid;
- var $version;
- var $xprop;
- // container for calendar components
- var $components;
- // component config variables
- var $allowEmpty;
- var $unique_id;
- var $language;
- var $directory;
- var $filename;
- var $url;
- var $delimiter;
- var $nl;
- var $format;
- var $dtzid;
- // component internal variables
- var $attributeDelimiter;
- var $valueInit;
- // component xCal declaration container
- var $xcaldecl;
- /**
- * constructor for calendar object
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.9.6 - 2011-05-14
- * @param array $config
- * @return void
- */
- function vcalendar ( $config = array()) {
- $this->_makeVersion();
- $this->calscale = null;
- $this->method = null;
- $this->_makeUnique_id();
- $this->prodid = null;
- $this->xprop = array();
- $this->language = null;
- $this->directory = null;
- $this->filename = null;
- $this->url = null;
- $this->dtzid = null;
- /**
- * language = <Text identifying a language, as defined in [RFC 1766]>
- */
- if( defined( 'ICAL_LANG' ) && !isset( $config['language'] ))
- $config['language'] = ICAL_LANG;
- if( !isset( $config['allowEmpty'] )) $config['allowEmpty'] = TRUE;
- if( !isset( $config['nl'] )) $config['nl'] = "\r\n";
- if( !isset( $config['format'] )) $config['format'] = 'iCal';
- if( !isset( $config['delimiter'] )) $config['delimiter'] = DIRECTORY_SEPARATOR;
- $this->setConfig( $config );
- $this->xcaldecl = array();
- $this->components = array();
- }
- /**
- * return iCalcreator version number
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.5 - 2013-08-29
- * @uses ICALCREATOR_VERSION
- * @return string
- */
- public static function iCalcreatorVersion() {
- return trim( substr( ICALCREATOR_VERSION, strpos( ICALCREATOR_VERSION, ' ' )));
- }
- /*********************************************************************************/
- /**
- * Property Name: CALSCALE
- */
- /**
- * creates formatted output for calendar property calscale
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.10.16 - 2011-10-28
- * @return string
- */
- function createCalscale() {
- if( empty( $this->calscale )) return FALSE;
- switch( $this->format ) {
- case 'xcal':
- return $this->nl.' calscale="'.$this->calscale.'"';
- break;
- default:
- return 'CALSCALE:'.$this->calscale.$this->nl;
- break;
- }
- }
- /**
- * set calendar property calscale
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.4.8 - 2008-10-21
- * @param string $value
- * @return void
- */
- function setCalscale( $value ) {
- if( empty( $value )) return FALSE;
- $this->calscale = $value;
- }
- /*********************************************************************************/
- /**
- * Property Name: METHOD
- */
- /**
- * creates formatted output for calendar property method
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.10.16 - 2011-10-28
- * @return string
- */
- function createMethod() {
- if( empty( $this->method )) return FALSE;
- switch( $this->format ) {
- case 'xcal':
- return $this->nl.' method="'.$this->method.'"';
- break;
- default:
- return 'METHOD:'.$this->method.$this->nl;
- break;
- }
- }
- /**
- * set calendar property method
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.4.8 - 2008-20-23
- * @param string $value
- * @return bool
- */
- function setMethod( $value ) {
- if( empty( $value )) return FALSE;
- $this->method = $value;
- return TRUE;
- }
- /*********************************************************************************/
- /**
- * Property Name: PRODID
- *
- */
- /**
- * creates formatted output for calendar property prodid
- *
- * @copyright copyright (c) 2007-2013 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
- * @license http://kigkonsult.se/downloads/dl.php?f=LGPL
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.12.11 - 2012-05-13
- * @return string
- */
- function createProdid() {
- if( !isset( $this->prodid ))
- $this->_makeProdid();
- switch( $this->format ) {
- case 'xcal':
- return $this->nl.' prodid="'.$this->prodid.'"';
- break;
- default:
- $toolbox = new calendarComponent();
- $toolbox->setConfig( $this->getConfig());
- return $toolbox->_createElement( 'PRODID', '', $this->prodid );
- break;
- }
- }
- /**
- * make default value for calendar prodid, do NOT alter or remove this method or invoke of this method
- *
- * @copyright copyright (c) 2007-2013 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
- * @license http://kigkonsult.se/downloads/dl.php?f=LGPL
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.6.8 - 2009-12-30
- * @return void
- */
- function _makeProdid() {
- $this->prodid = '-//'.$this->unique_id.'//NONSGML kigkonsult.se '.ICALCREATOR_VERSION.'//'.strtoupper( $this->language );
- }
- /**
- * Conformance: The property MUST be specified once in an iCalendar object.
- * Description: The vendor of the implementation SHOULD assure that this
- * is a globally unique identifier; using some technique such as an FPI
- * value, as defined in [ISO 9070].
- */
- /**
- * make default unique_id for calendar prodid
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 0.3.0 - 2006-08-10
- * @return void
- */
- function _makeUnique_id() {
- $this->unique_id = ( isset( $_SERVER['SERVER_NAME'] )) ? gethostbyname( $_SERVER['SERVER_NAME'] ) : 'localhost';
- }
- /*********************************************************************************/
- /**
- * Property Name: VERSION
- *
- * Description: A value of "2.0" corresponds to this memo.
- */
- /**
- * creates formatted output for calendar property version
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.10.16 - 2011-10-28
- * @return string
- */
- function createVersion() {
- if( empty( $this->version ))
- $this->_makeVersion();
- switch( $this->format ) {
- case 'xcal':
- return $this->nl.' version="'.$this->version.'"';
- break;
- default:
- return 'VERSION:'.$this->version.$this->nl;
- break;
- }
- }
- /**
- * set default calendar version
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 0.3.0 - 2006-08-10
- * @return void
- */
- function _makeVersion() {
- $this->version = '2.0';
- }
- /**
- * set calendar version
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.4.8 - 2008-10-23
- * @param string $value
- * @return void
- */
- function setVersion( $value ) {
- if( empty( $value )) return FALSE;
- $this->version = $value;
- return TRUE;
- }
- /*********************************************************************************/
- /**
- * Property Name: x-prop
- */
- /**
- * creates formatted output for calendar property x-prop, iCal format only
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.16.21 - 2013-05-25
- * @return string
- */
- function createXprop() {
- if( empty( $this->xprop ) || !is_array( $this->xprop )) return FALSE;
- $output = null;
- $toolbox = new calendarComponent();
- $toolbox->setConfig( $this->getConfig());
- foreach( $this->xprop as $label => $xpropPart ) {
- if( !isset($xpropPart['value']) || ( empty( $xpropPart['value'] ) && !is_numeric( $xpropPart['value'] ))) {
- if( $this->getConfig( 'allowEmpty' ))
- $output .= $toolbox->_createElement( $label );
- continue;
- }
- $attributes = $toolbox->_createParams( $xpropPart['params'], array( 'LANGUAGE' ));
- if( is_array( $xpropPart['value'] )) {
- foreach( $xpropPart['value'] as $pix => $theXpart )
- $xpropPart['value'][$pix] = iCalUtilityFunctions::_strrep( $theXpart, $this->format, $this->nl );
- $xpropPart['value'] = implode( ',', $xpropPart['value'] );
- }
- else
- $xpropPart['value'] = iCalUtilityFunctions::_strrep( $xpropPart['value'], $this->format, $this->nl );
- $output .= $toolbox->_createElement( $label, $attributes, $xpropPart['value'] );
- if( is_array( $toolbox->xcaldecl ) && ( 0 < count( $toolbox->xcaldecl ))) {
- foreach( $toolbox->xcaldecl as $localxcaldecl )
- $this->xcaldecl[] = $localxcaldecl;
- }
- }
- return $output;
- }
- /**
- * set calendar property x-prop
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.10 - 2013-09-04
- * @param string $label
- * @param string $value
- * @param array $params optional
- * @return bool
- */
- function setXprop( $label, $value, $params=FALSE ) {
- if( empty( $label ))
- return FALSE;
- $label = strtoupper( $label );
- if( 'X-' != substr( $label, 0, 2 ))
- return FALSE;
- if( empty( $value ) && !is_numeric( $value )) if( $this->getConfig( 'allowEmpty' )) $value = ''; else return FALSE;
- $xprop = array( 'value' => $value );
- $xprop['params'] = iCalUtilityFunctions::_setParams( $params );
- if( !is_array( $this->xprop ))
- $this->xprop = array();
- $this->xprop[$label] = $xprop;
- return TRUE;
- }
- /*********************************************************************************/
- /**
- * delete calendar property value
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.8.8 - 2011-03-15
- * @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
- */
- function deleteProperty( $propName=FALSE, $propix=FALSE ) {
- $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
- if( !$propix )
- $propix = ( isset( $this->propdelix[$propName] ) && ( 'X-PROP' != $propName )) ? $this->propdelix[$propName] + 2 : 1;
- $this->propdelix[$propName] = --$propix;
- $return = FALSE;
- switch( $propName ) {
- case 'CALSCALE':
- if( isset( $this->calscale )) {
- $this->calscale = null;
- $return = TRUE;
- }
- break;
- case 'METHOD':
- if( isset( $this->method )) {
- $this->method = null;
- $return = TRUE;
- }
- break;
- default:
- $reduced = array();
- if( $propName != 'X-PROP' ) {
- if( !isset( $this->xprop[$propName] )) { unset( $this->propdelix[$propName] ); return FALSE; }
- 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 )
- $reduced[$xpropkey] = $xpropvalue;
- $xpropno++;
- }
- }
- $this->xprop = $reduced;
- if( empty( $this->xprop )) {
- unset( $this->propdelix[$propName] );
- return FALSE;
- }
- return TRUE;
- }
- return $return;
- }
- /**
- * get calendar property value/params
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.10 - 2013-09-04
- * @param string $propName, optional
- * @param int $propix, optional, if specific property is wanted in case of multiply occurences
- * @param bool $inclParam=FALSE
- * @return mixed
- */
- function getProperty( $propName=FALSE, $propix=FALSE, $inclParam=FALSE ) {
- $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
- if( 'X-PROP' == $propName ) {
- if( !$propix )
- $propix = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1;
- $this->propix[$propName] = --$propix;
- }
- else {
- $mProps = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'RELATED-TO', 'RESOURCES' );
- $vComps = array('vevent', 'vtodo', 'vjournal', 'vfreebusy' );
- $dateFmt = '%04d%02d%02d';
- }
- switch( $propName ) {
- case 'ATTENDEE':
- case 'CATEGORIES':
- case 'CONTACT':
- case 'DTSTART':
- case 'GEOLOCATION':
- case 'LOCATION':
- case 'ORGANIZER':
- case 'PRIORITY':
- case 'RESOURCES':
- case 'STATUS':
- case 'SUMMARY':
- case 'RECURRENCE-ID-UID':
- case 'RELATED-TO':
- case 'R-UID':
- case 'UID':
- case 'URL':
- $output = array();
- foreach ( $this->components as $cix => $component) {
- if( !in_array( $component->objName, $vComps))
- continue;
- if( in_array( $propName, $mProps )) {
- $component->_getProperties( $propName, $output );
- continue;
- }
- elseif(( 3 < strlen( $propName )) && ( 'UID' == substr( $propName, -3 ))) {
- if( FALSE !== ( $content = $component->getProperty( 'RECURRENCE-ID' )))
- $content = $component->getProperty( 'UID' );
- }
- elseif( 'GEOLOCATION' == $propName ) {
- $content = ( FALSE === ( $loc = $component->getProperty( 'LOCATION' ))) ? '' : $loc.' ';
- if( FALSE === ( $geo = $component->getProperty( 'GEO' )))
- continue;
- $content .= iCalUtilityFunctions::_geo2str2( $geo['latitude'], iCalUtilityFunctions::$geoLatFmt ).
- iCalUtilityFunctions::_geo2str2( $geo['longitude'], iCalUtilityFunctions::$geoLongFmt ).'/';
- }
- elseif( FALSE === ( $content = $component->getProperty( $propName )))
- continue;
- if(( FALSE === $content ) || empty( $content ))
- continue;
- elseif( is_array( $content )) {
- if( isset( $content['year'] )) {
- $key = sprintf( $dateFmt, $content['year'], $content['month'], $content['day'] );
- if( !isset( $output[$key] ))
- $output[$key] = 1;
- else
- $output[$key] += 1;
- }
- else {
- foreach( $content as $partValue => $partCount ) {
- if( !isset( $output[$partValue] ))
- $output[$partValue] = $partCount;
- else
- $output[$partValue] += $partCount;
- }
- }
- } // end elseif( is_array( $content )) {
- elseif( !isset( $output[$content] ))
- $output[$content] = 1;
- else
- $output[$content] += 1;
- } // end foreach ( $this->components as $cix => $component)
- if( !empty( $output ))
- ksort( $output );
- return $output;
- break;
- case 'CALSCALE':
- return ( !empty( $this->calscale )) ? $this->calscale : FALSE;
- break;
- case 'METHOD':
- return ( !empty( $this->method )) ? $this->method : FALSE;
- break;
- case 'PRODID':
- if( empty( $this->prodid ))
- $this->_makeProdid();
- return $this->prodid;
- break;
- case 'VERSION':
- return ( !empty( $this->version )) ? $this->version : FALSE;
- break;
- default:
- if( $propName != 'X-PROP' ) {
- if( !isset( $this->xprop[$propName] )) return FALSE;
- return ( $inclParam ) ? array( $propName, $this->xprop[$propName] )
- : array( $propName, $this->xprop[$propName]['value'] );
- }
- else {
- if( empty( $this->xprop )) return FALSE;
- $xpropno = 0;
- foreach( $this->xprop as $xpropkey => $xpropvalue ) {
- if( $propix == $xpropno )
- return ( $inclParam ) ? array( $xpropkey, $this->xprop[$xpropkey] )
- : array( $xpropkey, $this->xprop[$xpropkey]['value'] );
- else
- $xpropno++;
- }
- unset( $this->propix[$propName] );
- return FALSE; // not found ??
- }
- }
- return FALSE;
- }
- /**
- * general vcalendar property setting
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @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 bool
- */
- function setProperty () {
- $numargs = func_num_args();
- if( 1 > $numargs )
- return FALSE;
- $arglist = func_get_args();
- $arglist[0] = strtoupper( $arglist[0] );
- switch( $arglist[0] ) {
- case 'CALSCALE':
- return $this->setCalscale( $arglist[1] );
- case 'METHOD':
- return $this->setMethod( $arglist[1] );
- case 'VERSION':
- return $this->setVersion( $arglist[1] );
- default:
- 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, kigkonsult <ical@kigkonsult.se>
- * @since 2.11.7 - 2012-01-12
- * @param mixed $config
- * @return value
- */
- function getConfig( $config = FALSE ) {
- if( !$config ) {
- $return = array();
- $return['ALLOWEMPTY'] = $this->getConfig( 'ALLOWEMPTY' );
- $return['DELIMITER'] = $this->getConfig( 'DELIMITER' );
- $return['DIRECTORY'] = $this->getConfig( 'DIRECTORY' );
- $return['FILENAME'] = $this->getConfig( 'FILENAME' );
- $return['DIRFILE'] = $this->getConfig( 'DIRFILE' );
- $return['FILESIZE'] = $this->getConfig( 'FILESIZE' );
- $return['FORMAT'] = $this->getConfig( 'FORMAT' );
- if( FALSE !== ( $lang = $this->getConfig( 'LANGUAGE' )))
- $return['LANGUAGE'] = $lang;
- $return['NEWLINECHAR'] = $this->getConfig( 'NEWLINECHAR' );
- $return['UNIQUE_ID'] = $this->getConfig( 'UNIQUE_ID' );
- if( FALSE !== ( $url = $this->getConfig( 'URL' )))
- $return['URL'] = $url;
- $return['TZID'] = $this->getConfig( 'TZID' );
- return $return;
- }
- switch( strtoupper( $config )) {
- case 'ALLOWEMPTY':
- return $this->allowEmpty;
- break;
- case 'COMPSINFO':
- unset( $this->compix );
- $info = array();
- foreach( $this->components as $cix => $component ) {
- if( empty( $component )) continue;
- $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' );
- }
- return $info;
- break;
- case 'DELIMITER':
- return $this->delimiter;
- break;
- case 'DIRECTORY':
- if( empty( $this->directory ) && ( '0' != $this->directory ))
- $this->directory = '.';
- return $this->directory;
- break;
- case 'DIRFILE':
- return $this->getConfig( 'directory' ).$this->getConfig( 'delimiter' ).$this->getConfig( 'filename' );
- break;
- case 'FILEINFO':
- return array( $this->getConfig( 'directory' )
- , $this->getConfig( 'filename' )
- , $this->getConfig( 'filesize' ));
- break;
- case 'FILENAME':
- if( empty( $this->filename ) && ( '0' != $this->filename )) {
- if( 'xcal' == $this->format )
- $this->filename = date( 'YmdHis' ).'.xml'; // recommended xcs.. .
- else
- $this->filename = date( 'YmdHis' ).'.ics';
- }
- return $this->filename;
- break;
- case 'FILESIZE':
- $size = 0;
- if( empty( $this->url )) {
- $dirfile = $this->getConfig( 'dirfile' );
- if( !is_file( $dirfile ) || ( FALSE === ( $size = filesize( $dirfile ))))
- $size = 0;
- clearstatcache();
- }
- return $size;
- break;
- case 'FORMAT':
- return ( $this->format == 'xcal' ) ? 'xCal' : 'iCal';
- break;
- case 'LANGUAGE':
- /* get language for calendar component as defined in [RFC 1766] */
- return $this->language;
- break;
- case 'NL':
- case 'NEWLINECHAR':
- return $this->nl;
- break;
- case 'TZID':
- return $this->dtzid;
- break;
- case 'UNIQUE_ID':
- return $this->unique_id;
- break;
- case 'URL':
- if( !empty( $this->url ))
- return $this->url;
- else
- return FALSE;
- break;
- }
- }
- /**
- * general vcalendar config setting
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.12 - 2013-09-12
- * @param mixed $config
- * @param string $value
- * @return void
- */
- function setConfig( $config, $value = FALSE) {
- if( is_array( $config )) {
- $config = array_change_key_case( $config, CASE_UPPER );
- if( isset( $config['DELIMITER'] )) {
- if( FALSE === $this->setConfig( 'DELIMITER', $config['DELIMITER'] ))
- return FALSE;
- unset( $config['DELIMITER'] );
- }
- if( isset( $config['DIRECTORY'] )) {
- if( FALSE === $this->setConfig( 'DIRECTORY', $config['DIRECTORY'] ))
- return FALSE;
- unset( $config['DIRECTORY'] );
- }
- foreach( $config as $cKey => $cValue ) {
- if( FALSE === $this->setConfig( $cKey, $cValue ))
- return FALSE;
- }
- return TRUE;
- }
- else
- $res = FALSE;
- $config = strtoupper( $config );
- switch( $config ) {
- case 'ALLOWEMPTY':
- $this->allowEmpty = $value;
- $subcfg = array( 'ALLOWEMPTY' => $value );
- $res = TRUE;
- break;
- case 'DELIMITER':
- $this->delimiter = $value;
- return TRUE;
- break;
- case 'DIRECTORY':
- if( FALSE === ( $value = realpath( rtrim( trim( $value ), $this->delimiter ))))
- return FALSE;
- else {
- /* local directory */
- $this->directory = $value;
- $this->url = null;
- return TRUE;
- }
- break;
- case 'FILENAME':
- $value = trim( $value );
- $dirfile = $this->directory.$this->delimiter.$value;
- if( file_exists( $dirfile )) {
- /* local file exists */
- if( is_readable( $dirfile ) || is_writable( $dirfile )) {
- clearstatcache();
- $this->filename = $value;
- return TRUE;
- }
- else
- return FALSE;
- }
- elseif( is_readable( $this->directory ) || is_writable( $this->directory )) {
- /* read- or writable directory */
- clearstatcache();
- $this->filename = $value;
- return TRUE;
- }
- else
- return FALSE;
- break;
- case 'FORMAT':
- $value = trim( strtolower( $value ));
- if( 'xcal' == $value ) {
- $this->format = 'xcal';
- $this->attributeDelimiter = $this->nl;
- $this->valueInit = null;
- }
- else {
- $this->format = null;
- $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;
- $this->_makeProdid();
- $subcfg = array( 'LANGUAGE' => $value );
- $res = TRUE;
- break;
- case 'NL':
- case 'NEWLINECHAR':
- $this->nl = $value;
- if( 'xcal' == $value ) {
- $this->attributeDelimiter = $this->nl;
- $this->valueInit = null;
- }
- else {
- $this->attributeDelimiter = ';';
- $this->valueInit = ':';
- }
- $subcfg = array( 'NL' => $value );
- $res = TRUE;
- break;
- case 'TZID':
- $this->dtzid = $value;
- $subcfg = array( 'TZID' => $value );
- $res = TRUE;
- break;
- case 'UNIQUE_ID':
- $value = trim( $value );
- $this->unique_id = $value;
- $this->_makeProdid();
- $subcfg = array( 'UNIQUE_ID' => $value );
- $res = TRUE;
- break;
- case 'URL':
- /* remote file - URL */
- $value = str_replace( array( 'HTTP://', 'WEBCAL://', 'webcal://' ), 'http://', trim( $value ));
- $value = str_replace( 'HTTPS://', 'https://', trim( $value ));
- if(( 'http://' != substr( $value, 0, 7 )) && ( 'https://' != substr( $value, 0, 8 )))
- return FALSE;
- $this->directory = '.';
- $this->url = $value;
- if( '.ics' != strtolower( substr( $value, -4 )))
- unset( $this->filename );
- else
- $this->filename = $basename( $value );
- return TRUE;
- break;
- default: // any unvalid config key.. .
- return TRUE;
- }
- 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, TRUE );
- if( !$res )
- break 2;
- $this->components[$cix] = $component->copy(); // PHP4 compliant
- }
- }
- }
- return $res;
- }
- /*********************************************************************************/
- /**
- * add calendar component to container
- *
- * alias to setComponent
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 1.x.x - 2007-04-24
- * @param object $component calendar component
- * @return void
- */
- function addComponent( $component ) {
- $this->setComponent( $component );
- }
- /**
- * delete calendar component from container
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.8.8 - 2011-03-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 ) {
- $argType = $index = null;
- if ( ctype_digit( (string) $arg1 )) {
- $argType = 'INDEX';
- $index = (int) $arg1 - 1;
- }
- elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
- $argType = strtolower( $arg1 );
- $index = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0;
- }
- $cix1dC = 0;
- foreach ( $this->components as $cix => $component) {
- if( empty( $component )) continue;
- if(( 'INDEX' == $argType ) && ( $index == $cix )) {
- unset( $this->components[$cix] );
- return TRUE;
- }
- elseif( $argType == $component->objName ) {
- if( $index == $cix1dC ) {
- unset( $this->components[$cix] );
- return TRUE;
- }
- $cix1dC++;
- }
- elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {
- unset( $this->components[$cix] );
- return TRUE;
- }
- }
- return FALSE;
- }
- /**
- * get calendar component from container
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.10 - 2013-09-04
- * @param mixed $arg1 optional, ordno/component type/ component uid
- * @param mixed $arg2 optional, ordno if arg1 = component type
- * @return object
- */
- function getComponent( $arg1=FALSE, $arg2=FALSE ) {
- $index = $argType = null;
- if ( !$arg1 ) { // first or next in component chain
- $argType = 'INDEX';
- $index = $this->compix['INDEX'] = ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;
- }
- elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
- $arg2 = implode( '-', array_keys( $arg1 ));
- $index = $this->compix[$arg2] = ( isset( $this->compix[$arg2] )) ? $this->compix[$arg2] + 1 : 1;
- $dateProps = array( 'DTSTART', 'DTEND', 'DUE', 'CREATED', 'COMPLETED', 'DTSTAMP', 'LAST-MODIFIED', 'RECURRENCE-ID' );
- $otherProps = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'RELATED-TO', 'RESOURCES', 'STATUS', 'SUMMARY', 'UID', 'URL' );
- $mProps = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'RELATED-TO', 'RESOURCES' );
- }
- elseif ( ctype_digit( (string) $arg1 )) { // specific component in chain
- $argType = 'INDEX';
- $index = (int) $arg1;
- unset( $this->compix );
- }
- elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) { // object class name
- unset( $this->compix['INDEX'] );
- $argType = strtolower( $arg1 );
- if( !$arg2 )
- $index = $this->compix[$argType] = ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;
- elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
- $index = (int) $arg2;
- }
- elseif(( strlen( $arg1 ) > strlen( 'vfreebusy' )) && ( FALSE !== strpos( $arg1, '@' ))) { // UID as 1st argument
- if( !$arg2 )
- $index = $this->compix[$arg1] = ( isset( $this->compix[$arg1] )) ? $this->compix[$arg1] + 1 : 1;
- elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
- $index = (int) $arg2;
- }
- if( isset( $index ))
- $index -= 1;
- $ckeys = array_keys( $this->components );
- if( !empty( $index) && ( $index > end( $ckeys )))
- return FALSE;
- $cix1gC = 0;
- foreach ( $this->components as $cix => $component) {
- if( empty( $component )) continue;
- if(( 'INDEX' == $argType ) && ( $index == $cix ))
- return $component->copy();
- elseif( $argType == $component->objName ) {
- if( $index == $cix1gC )
- return $component->copy();
- $cix1gC++;
- }
- elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
- $hit = array();
- $arg1 = array_change_key_case( $arg1, CASE_UPPER );
- foreach( $arg1 as $pName => $pValue ) {
- if( !in_array( $pName, $dateProps ) && !in_array( $pName, $otherProps ))
- continue;
- if( in_array( $pName, $mProps )) { // multiple occurrence
- $propValues = array();
- $component->_getProperties( $pName, $propValues );
- $propValues = array_keys( $propValues );
- $hit[] = ( in_array( $pValue, $propValues )) ? TRUE : FALSE;
- continue;
- } // end if(.. .// multiple occurrence
- if( FALSE === ( $value = $component->getProperty( $pName ))) { // single occurrence
- $hit[] = FALSE; // missing property
- continue;
- }
- if( 'SUMMARY' == $pName ) { // exists within (any case)
- $hit[] = ( FALSE !== stripos( $value, $pValue )) ? TRUE : FALSE;
- continue;
- }
- if( in_array( $pName, $dateProps )) {
- $valuedate = sprintf( '%04d%02d%02d', $value['year'], $value['month'], $value['day'] );
- if( 8 < strlen( $pValue )) {
- if( isset( $value['hour'] )) {
- if( 'T' == substr( $pValue, 8, 1 ))
- $pValue = str_replace( 'T', '', $pValue );
- $valuedate .= sprintf( '%02d%02d%02d', $value['hour'], $value['min'], $value['sec'] );
- }
- else
- $pValue = substr( $pValue, 0, 8 );
- }
- $hit[] = ( $pValue == $valuedate ) ? TRUE : FALSE;
- continue;
- }
- elseif( !is_array( $value ))
- $value = array( $value );
- foreach( $value as $part ) {
- $part = ( FALSE !== strpos( $part, ',' )) ? explode( ',', $part ) : array( $part );
- foreach( $part as $subPart ) {
- if( $pValue == $subPart ) {
- $hit[] = TRUE;
- continue 3;
- }
- }
- } // end foreach( $value as $part )
- $hit[] = FALSE; // no hit in property
- } // end foreach( $arg1 as $pName => $pValue )
- if( in_array( TRUE, $hit )) {
- if( $index == $cix1gC )
- return $component->copy();
- $cix1gC++;
- }
- } // end elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
- elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) { // UID
- if( $index == $cix1gC )
- return $component->copy();
- $cix1gC++;
- }
- } // end foreach ( $this->components.. .
- /* not found.. . */
- unset( $this->compix );
- return FALSE;
- }
- /**
- * create new calendar component, already included within calendar
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.6.33 - 2011-01-03
- * @param string $compType component type
- * @return object (reference)
- */
- function & newComponent( $compType ) {
- $config = $this->getConfig();
- $keys = array_keys( $this->components );
- $ix = end( $keys) + 1;
- switch( strtoupper( $compType )) {
- case 'EVENT':
- case 'VEVENT':
- $this->components[$ix] = new vevent( $config );
- break;
- case 'TODO':
- case 'VTODO':
- $this->components[$ix] = new vtodo( $config );
- break;
- case 'JOURNAL':
- case 'VJOURNAL':
- $this->components[$ix] = new vjournal( $config );
- break;
- case 'FREEBUSY':
- case 'VFREEBUSY':
- $this->components[$ix] = new vfreebusy( $config );
- break;
- case 'TIMEZONE':
- case 'VTIMEZONE':
- array_unshift( $this->components, new vtimezone( $config ));
- $ix = 0;
- break;
- default:
- return FALSE;
- }
- return $this->components[$ix];
- }
- /**
- * select components from calendar on date or selectOption basis
- *
- * Ensure DTSTART is set for every component.
- * No date controls occurs.
- *
- * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
- * @since 2.18.19 - 2014-02-01
- * @param mixed $startY optional, start Year, default current Year ALT. array selecOptions ( *[ <propName> => <uniqueValue> ] )
- * @param int $startM optional, start Month, default current Month
- * @param int $startD optional, start Day, default current Day
- * @param int $endY optional, end Year, default $startY
- * @param int $endY optional, end Month, default $startM
- * @param int $endY optional, end Day, default $startD
- * @param mixed $cType optional, calendar component type(-s), default FALSE=all else string/array type(-s)
- * @param bool $flat optional, FALSE (default) => output : array[Year][Month][Day][]
- * TRUE => output : array[] (ignores split)
- * @param bool $any optional, TRUE (default) - select component(-s) that occurs within period
- * FALSE - only component(-s) that starts within period
- * @param bool $split optional, TRUE (default) - one component copy every DAY it occurs during the
- * period (implies flat=FALSE)
- * FALSE - one occurance of component only in output array
- * @return array or FALSE
- */
- function selectComponents( $startY=FALSE, $startM=FALSE, $startD=FALSE, $endY=FALSE, $endM=FALSE, $endD=FALSE, $cType=FALSE, $flat=FALSE, $any=TRUE, $split=TRUE ) {
- /* check if empty calendar */
- if( 0 >= count( $this->components )) return FALSE;
- if( is_array( $startY ))
- return $this->selectComponents2( $startY );
- /* check default dates */
- if( ! $startY ) $startY = date( 'Y' );
- if( ! $startM ) $startM = date( 'm' );
- if( ! $startD ) $startD = date( 'd' );
- $startDate = mktime( 0, 0, 0, $startM, $startD, $startY );
- if( ! $endY ) $endY = $startY;
- if( ! $endM ) $endM = $startM;
- if( ! $endD ) $endD = $startD;
- $endDate = mktime( 23, 59, 59, $endM, $endD, $endY );
- // echo 'selectComp arg='.date( 'Y-m-d H:i:s', $startDate).' -- '.date( 'Y-m-d H:i:s', $endDate)."<br>\n"; $tcnt = 0;// test ###
- /* check component types */
- $validTypes = array('vevent', 'vtodo', 'vjournal', 'vfreebusy' );
- if( empty( $cType ))
- $cType = $validTypes;
- else {
- if( ! is_array( $cType ))
- $cType = array( $cType );
- $cType = array_map( 'strtolower', $cType );
- foreach( $cType as $cix => $theType ) {
- $cType[$cix] = $theType;
- if( !in_array( $theType, $validTypes ))
- $cType[$cix] = 'vevent';
- }
- $cType = array_unique( $cType );
- }
- if(( FALSE === $flat ) && ( FALSE === $any )) // invalid combination
- $split = FALSE;
- if(( TRUE === $flat ) && ( TRUE === $split )) // invalid combination
- $split = FALSE;
- /* iterate components */
- $result = array();
- $this->sort( 'UID' );
- $compUIDcmp = null;
- $recurridList = array();
- foreach ( $this->components as $cix => $component ) {
- if( empty( $component )) continue;
- unset( $start );
- /* deselect unvalid type components */
- if( !in_array( $component->objName, $cType ))
- continue;
- $start = $component->getProperty( 'dtstart', FALSE, TRUE );
- /* select due when dtstart is missing */
- if( empty( $start ) && ( $component->objName == 'vtodo' ) && ( FALSE === ( $start = $component->getProperty( 'due', FALSE, TRUE ))))
- continue;
- if( empty( $start ))
- continue;
- if( ! isset( $start['value']['tz'] ) && isset( $start['params']['TZID'] ))
- $start['value']['tz'] = $start['params']['TZID'];
- $start = $start['value'];
- $compUID = $component->getProperty( 'UID' );
- if( $compUIDcmp != $compUID ) {
- $compUIDcmp = $compUID;
- unset( $exdatelist, $recurridList );
- }
- $SCbools = array( 'dtendExist' => FALSE, 'dueExist' => FALSE, 'durationExist' => FALSE, 'endAllDayEvent' => FALSE );
- $recurrid = FALSE;
- $dateFormat = array();
- unset( $end, $startWdate, $endWdate, $rdurWsecs, $rdur, $workstart, $workend ); // clean up
- $startWdate = iCalUtilityFunctions::_SCsetXCurrentDateZ( iCalUtilityFunctions::_date2timestamp( $start ), $start );
- $dateFormat['start'] = ( isset( $start['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
- /* get end date from dtend/due/duration properties */
- $end = $component->getProperty( 'dtend', FALSE, TRUE );
- if( !empty( $end )) {
- $SCbools[ 'dtendExist'] = TRUE;
- $dateFormat['end'] = ( isset( $end['value']['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
- }
- if( ! isset( $end['value']['tz'] ) && isset( $end['params']['TZID'] ))
- $end['value']['tz'] = $end['params']['TZID'];
- $end = $end['value'];
- if( empty( $end ) && ( $component->objName == 'vtodo' )) {
- $end = $component->getProperty( 'due' );
- if( !empty( $end )) {
- $SCbools[ 'dueExist'] = TRUE;
- $dateFormat['end'] = ( isset( $end['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
- }
- }
- 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!!! */
- $SCbools[ '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 )) {
- $end = $component->getProperty( 'duration', FALSE, FALSE, TRUE );// in dtend (array) format
- if( !empty( $end ))
- if( isset( $start['tz'] ))
- $end['tz'] = $start['tz'];
- $SCbools[ 'durationExist'] = TRUE;
- $dateFormat['end'] = ( isset( $start['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
- // if( !empty($end)) echo 'selectComp 4 start='.implode('-',$start).' end='.implode('-',$end)."<br>\n"; // test ###
- }
- if( empty( $end )) { // assume one day duration if missing end date
- $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );
- if( isset( $start['tz'] ))
- $end['tz'] = $start['tz'];
- }
- // if( isset($end)) echo 'selectComp 5 start='.implode('-',$start).' end='.implode('-',$end)."<br>\n"; // test ###
- $endWdate = iCalUtilityFunctions::_SCsetXCurrentDateZ( iCalUtilityFunctions::_date2timestamp( $end ), $end );
- if( $endWdate < $startWdate ) { // MUST be after start date!!
- $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );
- $endWdate = iCalUtilityFunctions::_date2timestamp( $end );
- }
- $rdurWsecs = $endWdate - $startWdate; // compute event (component) duration in seconds
- /* make a list of optional exclude dates for component occurence from exrule and exdate */
- $exdatelist = array();
- $workstart = iCalUtilityFunctions::_timestamp2date(( $startDate - $rdurWsecs ), 6);
- $workend = iCalUtilityFunctions::_timestamp2date(( $endDate + $rdurWsecs ), 6);
- while( FALSE !== ( $exrule = $component->getProperty( 'exrule' ))) // check exrule
- iCalUtilityFunctions::_recur2date( $exdatelist, $exrule, $start, $workstart, $workend );
- while( FALSE !== ( $exdate = $component->getProperty( 'exdate' ))) { // check exdate
- foreach( $exdate as $theExdate ) {
- $exWdate = iCalUtilityFunctions::_date2timestamp( $theExdate );
- $exWdate = mktime( 0, 0, 0, date( 'm', $exWdate ), date( 'd', $exWdate ), date( 'Y', $exWdate )); // on a day-basis !!!
- if((( $startDate - $rdurWsecs ) <= $exWdate ) && ( $endDate >= $exWdate ))
- $exdatelist[$exWdate] = TRUE;
- } // end - foreach( $exdate as $theExdate )
- } // end - check exdate
- /* check recurrence-id (note, a missing sequence is the same as sequence=0 so don't test for sequence), remove hit with reccurr-id date */
- if( FALSE !== ( $recurrid = $component->getProperty( 'recurrence-id' ))) {
- $recurrid = iCalUtilityFunctions::_date2timestamp( $recurrid );
- $recurrid = mktime( 0, 0, 0, date( 'm', $recurrid ), date( 'd', $recurrid ), date( 'Y', $recurrid )); // on a day-basis !!!
- $recurridList[$recurrid] = TRUE; // no recurring to start this day
- // echo "adding comp no:$cix with date=".implode($start)." and recurrid=".implode($recurrid)." to recurridList id=$recurrid<br>\n"; // test ###
- } // end recurrence-id/sequence test
- /* select only components with.. . */
- if(( !$any && ( $startWdate >= $startDate ) && ( $startWdate <= $endDate )) || // (dt)start within the period
- ( $any && ( $startWdate < $endDate ) && ( $endWdate >= $startDate ))) { // occurs within the period
- /* add the selected component (WITHIN valid dates) to output array */
- if( $flat ) { // any=true/false, ignores split
- if( !$recurrid )
- $result[$compUID] = $component->copy(); // copy original to output (but not anyone with recurrence-id)
- }
- elseif( $split ) { // split the original component
- if( $endWdate > $endDate )
- $endWdate = $endDate; // use period end date
- $rstart = ( $startWdate < $startDate ) ? $startDate : $startWdate; // use period start date
- $startYMD = $rstartYMD = date( 'Ymd', $rstart );
- $endYMD = date( 'Ymd', $endWdate );
- $checkDate = mktime( 0, 0, 0, date( 'm', $rstart ), date( 'd', $rstart ), date( 'Y', $rstart ) ); // on a day-basis !!!
- // echo "going to test comp no:$cix with rstartYMD=$rstartYMD, endYMD=$endYMD and checkDate($checkDate) with recurridList=".implode(',',array_keys($recurridList))."<br>\n"; // test ###
- if( !isset( $exdatelist[$checkDate] )) { // exclude any recurrence START date, found in exdatelist
- while( $rstartYMD <= $endYMD ) { // iterate
- if( isset( $exdatelist[$checkDate] ) || // exclude any recurrence date, found in the exdatelist
- ( isset( $recurridList[$checkDate] ) && !$recurrid )) { // or in the recurridList, but not itself
- // echo "skipping comp no:$cix with datestart=$rstartYMD and checkdate=$checkDate<br>\n"; // test ###
- $rstart += ( 24 *3600 ); // step one day
- $rstartYMD = date( 'Ymd', $rstart );
- continue;
- }
- iCalUtilityFunctions::_SCsetXCurrentStart( $component, $dateFormat, $checkDate, $rstartYMD, $rstart, $startYMD, $start );
- iCalUtilityFunctions::_SCsetXCurrentEnd( $component, $dateFormat, $rstart, $rstartYMD, $endWdate, $endYMD, $end, $SCbools );
- $wd = getdate( $rstart );
- $result[$wd['year']][$wd['mon']][$wd['mday']][$compUID] = $component->copy(); // copy to output
- $rstart += ( 24 *3600 ); // step one day
- $rstartYMD = date( 'Ymd', $rstart );
- $checkDate = mktime( 0, 0, 0, date( 'm', $rstart ), date( 'd', $rstart ), date( 'Y', $rstart ) ); // on a day-basis !!!
- } // end while( $rstart <= $endWdate )
- } // end if( !isset( $exdatelist[$checkDate] ))
- } // end elseif( $split ) - else use component date
- elseif( $recurrid && !$flat && !$any && !$split )
- $continue = TRUE;
- else { // !$flat && !$split, i.e. no flat array and DTSTART within period
- $checkDate = mktime( 0, 0, 0, date( 'm', $startWdate ), date( 'd', $startWdate ), date( 'Y', $startWdate ) ); // on a day-basis !!!
- // echo "going to test comp no:$cix with checkDate=$checkDate with recurridList=".implode(',',array_keys($recurridList)); // test ###
- if(( !$any || !isset( $exdatelist[$checkDate] )) && // exclude any recurrence date, found in exdatelist
- ( !isset( $recurridList[$checkDate] ) || $recurrid )) { // or in the recurridList, but not itself
- // echo " and copied to output<br>\n"; // test ###
- $wd = getdate( $startWdate );
- $result[$wd['year']][$wd['mon']][$wd['mday']][$compUID] = $component->copy(); // copy to output
- }
- }
- } // end if(( $startWdate >= $startDate ) && ( $startWdate <= $endDate ))
- /* if 'any' components, check components with reccurrence rules, removing all excluding dates */
- if( TRUE === $any ) {
- /* make a list of optional repeating dates for component occurence, rrule, rdate */
- $recurlist = array();
- while( FALSE !== ( $rrule = $component->getProperty( 'rrule' ))) // check rrule
- iCalUtilityFunctions::_recur2date( $recurlist, $rrule, $start, $workstart, $workend );
- foreach( $recurlist as $recurkey => $recurvalue ) // key=match date as timestamp
- $recurlist[$recurkey] = $rdurWsecs; // add duration in seconds
- while( FALSE !== ( $rdate = $component->getProperty( 'rdate' ))) { // check rdate
- foreach( $rdate as $theRdate ) {
- if( is_array( $theRdate ) && ( 2 == count( $theRdate )) && // all days within PERIOD
- array_key_exists( '0', $theRdate ) && array_key_exists( '1', $theRdate )) {
- $rstart = iCalUtilityFunctions::_date2timestamp( $theRdate[0] );
- if(( $rstart < ( $startDate - $rdurWsecs )) || ( $rstart > $endDate ))
- continue;
- if( isset( $theRdate[1]['year'] )) // date-date period
- $rend = iCalUtilityFunctions::_date2timestamp( $theRdate[1] );
- else { // date-duration period
- $rend = iCalUtilityFunctions::_duration2date( …
Large files files are truncated, but you can click here to view the full file