PageRenderTime 664ms CodeModel.GetById 403ms app.highlight 131ms RepoModel.GetById 30ms app.codeStats 6ms

/wp-content/plugins/all-in-one-event-calendar/lib/iCal/iCalcreator-2.20/iCalcreator.class.php

https://github.com/dedavidd/piratenpartij.nl
PHP | 10543 lines | 8068 code | 31 blank | 2444 comment | 2377 complexity | ca019c5514c8c616bf64eacb28151ef2 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/*********************************************************************************/
   3/**
   4 *
   5 * This file is a PHP implementation of rfc2445/rfc5545.
   6 *
   7 * @copyright Copyright (c) 2007-2014 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
   8 * @link      http://kigkonsult.se/iCalcreator/index.php
   9 * @license   http://kigkonsult.se/downloads/dl.php?f=LGPL
  10 * @package   iCalcreator
  11 * @version   v2.20
  12 */
  13/**
  14 * This library is free software; you can redistribute it and/or
  15 * modify it under the terms of the GNU Lesser General Public
  16 * License as published by the Free Software Foundation; either
  17 * version 2.1 of the License, or (at your option) any later version.
  18 *
  19 * This library is distributed in the hope that it will be useful,
  20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22 * Lesser General Public License for more details.
  23 *
  24 * You should have received a copy of the GNU Lesser General Public
  25 * License along with this library; if not, write to the Free Software
  26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  27 */
  28/*********************************************************************************/
  29/**
  30 *         Do NOT remove or change version!!
  31 *
  32 * @copyright Copyright (c) 2007-2014 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
  33 * @license   http://kigkonsult.se/downloads/dl.php?f=LGPL
  34 */
  35define( 'ICALCREATOR_VERSION', 'iCalcreator 2.20' );
  36/*********************************************************************************/
  37/**
  38 * vcalendar class
  39 *
  40 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
  41 * @since 2.9.6 - 2011-05-14
  42 */
  43class vcalendar {
  44            //  calendar property variables
  45  var $calscale;
  46  var $method;
  47  var $prodid;
  48  var $version;
  49  var $xprop;
  50            //  container for calendar components
  51  var $components;
  52            //  component config variables
  53  var $allowEmpty;
  54  var $unique_id;
  55  var $language;
  56  var $directory;
  57  var $filename;
  58  var $url;
  59  var $delimiter;
  60  var $nl;
  61  var $format;
  62  var $dtzid;
  63            //  component internal variables
  64  var $attributeDelimiter;
  65  var $valueInit;
  66            //  component xCal declaration container
  67  var $xcaldecl;
  68/**
  69 * constructor for calendar object
  70 *
  71 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
  72 * @since 2.9.6 - 2011-05-14
  73 * @param array $config
  74 * @return void
  75 */
  76  function vcalendar ( $config = array()) {
  77    $this->_makeVersion();
  78    $this->calscale   = null;
  79    $this->method     = null;
  80    $this->_makeUnique_id();
  81    $this->prodid     = null;
  82    $this->xprop      = array();
  83    $this->language   = null;
  84    $this->directory  = null;
  85    $this->filename   = null;
  86    $this->url        = null;
  87    $this->dtzid      = null;
  88/**
  89 *   language = <Text identifying a language, as defined in [RFC 1766]>
  90 */
  91    if( defined( 'ICAL_LANG' ) && !isset( $config['language'] ))
  92                                          $config['language']   = ICAL_LANG;
  93    if( !isset( $config['allowEmpty'] ))  $config['allowEmpty'] = TRUE;
  94    if( !isset( $config['nl'] ))          $config['nl']         = "\r\n";
  95    if( !isset( $config['format'] ))      $config['format']     = 'iCal';
  96    if( !isset( $config['delimiter'] ))   $config['delimiter']  = DIRECTORY_SEPARATOR;
  97    $this->setConfig( $config );
  98
  99    $this->xcaldecl   = array();
 100    $this->components = array();
 101  }
 102/**
 103 * return iCalcreator version number
 104 *
 105 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 106 * @since 2.18.5 - 2013-08-29
 107 * @uses ICALCREATOR_VERSION
 108 * @return string
 109 */
 110  public static function iCalcreatorVersion() {
 111    return trim( substr( ICALCREATOR_VERSION, strpos( ICALCREATOR_VERSION, ' ' )));
 112  }
 113/*********************************************************************************/
 114/**
 115 * Property Name: CALSCALE
 116 */
 117/**
 118 * creates formatted output for calendar property calscale
 119 *
 120 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 121 * @since 2.10.16 - 2011-10-28
 122 * @return string
 123 */
 124  function createCalscale() {
 125    if( empty( $this->calscale )) return FALSE;
 126    switch( $this->format ) {
 127      case 'xcal':
 128        return $this->nl.' calscale="'.$this->calscale.'"';
 129        break;
 130      default:
 131        return 'CALSCALE:'.$this->calscale.$this->nl;
 132        break;
 133    }
 134  }
 135/**
 136 * set calendar property calscale
 137 *
 138 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 139 * @since 2.4.8 - 2008-10-21
 140 * @param string $value
 141 * @return void
 142 */
 143  function setCalscale( $value ) {
 144    if( empty( $value )) return FALSE;
 145    $this->calscale = $value;
 146  }
 147/*********************************************************************************/
 148/**
 149 * Property Name: METHOD
 150 */
 151/**
 152 * creates formatted output for calendar property method
 153 *
 154 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 155 * @since 2.10.16 - 2011-10-28
 156 * @return string
 157 */
 158  function createMethod() {
 159    if( empty( $this->method )) return FALSE;
 160    switch( $this->format ) {
 161      case 'xcal':
 162        return $this->nl.' method="'.$this->method.'"';
 163        break;
 164      default:
 165        return 'METHOD:'.$this->method.$this->nl;
 166        break;
 167    }
 168  }
 169/**
 170 * set calendar property method
 171 *
 172 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 173 * @since 2.4.8 - 2008-20-23
 174 * @param string $value
 175 * @return bool
 176 */
 177  function setMethod( $value ) {
 178    if( empty( $value )) return FALSE;
 179    $this->method = $value;
 180    return TRUE;
 181  }
 182/*********************************************************************************/
 183/**
 184 * Property Name: PRODID
 185 *
 186 */
 187/**
 188 * creates formatted output for calendar property prodid
 189 *
 190 * @copyright copyright (c) 2007-2013 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
 191 * @license   http://kigkonsult.se/downloads/dl.php?f=LGPL
 192 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 193 * @since 2.12.11 - 2012-05-13
 194 * @return string
 195 */
 196  function createProdid() {
 197    if( !isset( $this->prodid ))
 198      $this->_makeProdid();
 199    switch( $this->format ) {
 200      case 'xcal':
 201        return $this->nl.' prodid="'.$this->prodid.'"';
 202        break;
 203      default:
 204        $toolbox = new calendarComponent();
 205        $toolbox->setConfig( $this->getConfig());
 206        return $toolbox->_createElement( 'PRODID', '', $this->prodid );
 207        break;
 208    }
 209  }
 210/**
 211 * make default value for calendar prodid, do NOT alter or remove this method or invoke of this method
 212 *
 213 * @copyright copyright (c) 2007-2013 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
 214 * @license   http://kigkonsult.se/downloads/dl.php?f=LGPL
 215 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 216 * @since 2.6.8 - 2009-12-30
 217 * @return void
 218 */
 219  function _makeProdid() {
 220    $this->prodid  = '-//'.$this->unique_id.'//NONSGML kigkonsult.se '.ICALCREATOR_VERSION.'//'.strtoupper( $this->language );
 221  }
 222/**
 223 * Conformance: The property MUST be specified once in an iCalendar object.
 224 * Description: The vendor of the implementation SHOULD assure that this
 225 * is a globally unique identifier; using some technique such as an FPI
 226 * value, as defined in [ISO 9070].
 227 */
 228/**
 229 * make default unique_id for calendar prodid
 230 *
 231 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 232 * @since 0.3.0 - 2006-08-10
 233 * @return void
 234 */
 235  function _makeUnique_id() {
 236    $this->unique_id  = ( isset( $_SERVER['SERVER_NAME'] )) ? gethostbyname( $_SERVER['SERVER_NAME'] ) : 'localhost';
 237  }
 238/*********************************************************************************/
 239/**
 240 * Property Name: VERSION
 241 *
 242 * Description: A value of "2.0" corresponds to this memo.
 243 */
 244/**
 245 * creates formatted output for calendar property version
 246
 247 *
 248 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 249 * @since 2.10.16 - 2011-10-28
 250 * @return string
 251 */
 252  function createVersion() {
 253    if( empty( $this->version ))
 254      $this->_makeVersion();
 255    switch( $this->format ) {
 256      case 'xcal':
 257        return $this->nl.' version="'.$this->version.'"';
 258        break;
 259      default:
 260        return 'VERSION:'.$this->version.$this->nl;
 261        break;
 262    }
 263  }
 264/**
 265 * set default calendar version
 266 *
 267 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 268 * @since 0.3.0 - 2006-08-10
 269 * @return void
 270 */
 271  function _makeVersion() {
 272    $this->version = '2.0';
 273  }
 274/**
 275 * set calendar version
 276 *
 277 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 278 * @since 2.4.8 - 2008-10-23
 279 * @param string $value
 280 * @return void
 281 */
 282  function setVersion( $value ) {
 283    if( empty( $value )) return FALSE;
 284    $this->version = $value;
 285    return TRUE;
 286  }
 287/*********************************************************************************/
 288/**
 289 * Property Name: x-prop
 290 */
 291/**
 292 * creates formatted output for calendar property x-prop, iCal format only
 293 *
 294 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 295 * @since 2.16.21 - 2013-05-25
 296 * @return string
 297 */
 298  function createXprop() {
 299    if( empty( $this->xprop ) || !is_array( $this->xprop )) return FALSE;
 300    $output        = null;
 301    $toolbox       = new calendarComponent();
 302    $toolbox->setConfig( $this->getConfig());
 303    foreach( $this->xprop as $label => $xpropPart ) {
 304      if( !isset($xpropPart['value']) || ( empty( $xpropPart['value'] ) && !is_numeric( $xpropPart['value'] ))) {
 305        if( $this->getConfig( 'allowEmpty' ))
 306          $output .= $toolbox->_createElement( $label );
 307        continue;
 308      }
 309      $attributes  = $toolbox->_createParams( $xpropPart['params'], array( 'LANGUAGE' ));
 310      if( is_array( $xpropPart['value'] )) {
 311        foreach( $xpropPart['value'] as $pix => $theXpart )
 312          $xpropPart['value'][$pix] = iCalUtilityFunctions::_strrep( $theXpart, $this->format, $this->nl );
 313        $xpropPart['value']  = implode( ',', $xpropPart['value'] );
 314      }
 315      else
 316        $xpropPart['value'] = iCalUtilityFunctions::_strrep( $xpropPart['value'], $this->format, $this->nl );
 317      $output     .= $toolbox->_createElement( $label, $attributes, $xpropPart['value'] );
 318      if( is_array( $toolbox->xcaldecl ) && ( 0 < count( $toolbox->xcaldecl ))) {
 319        foreach( $toolbox->xcaldecl as $localxcaldecl )
 320          $this->xcaldecl[] = $localxcaldecl;
 321      }
 322    }
 323    return $output;
 324  }
 325/**
 326 * set calendar property x-prop
 327 *
 328 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 329 * @since 2.18.10 - 2013-09-04
 330 * @param string $label
 331 * @param string $value
 332 * @param array $params optional
 333 * @return bool
 334 */
 335  function setXprop( $label, $value, $params=FALSE ) {
 336    if( empty( $label ))
 337      return FALSE;
 338    $label = strtoupper( $label );
 339    if( 'X-' != substr( $label, 0, 2 ))
 340      return FALSE;
 341    if( empty( $value ) && !is_numeric( $value )) if( $this->getConfig( 'allowEmpty' )) $value = ''; else return FALSE;
 342    $xprop           = array( 'value' => $value );
 343    $xprop['params'] = iCalUtilityFunctions::_setParams( $params );
 344    if( !is_array( $this->xprop ))
 345      $this->xprop = array();
 346    $this->xprop[$label] = $xprop;
 347    return TRUE;
 348  }
 349/*********************************************************************************/
 350/**
 351 * delete calendar property value
 352 *
 353 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 354 * @since 2.8.8 - 2011-03-15
 355 * @param mixed $propName, bool FALSE => X-property
 356 * @param int $propix, optional, if specific property is wanted in case of multiply occurences
 357 * @return bool, if successfull delete
 358 */
 359  function deleteProperty( $propName=FALSE, $propix=FALSE ) {
 360    $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
 361    if( !$propix )
 362      $propix = ( isset( $this->propdelix[$propName] ) && ( 'X-PROP' != $propName )) ? $this->propdelix[$propName] + 2 : 1;
 363    $this->propdelix[$propName] = --$propix;
 364    $return = FALSE;
 365    switch( $propName ) {
 366      case 'CALSCALE':
 367        if( isset( $this->calscale )) {
 368          $this->calscale = null;
 369          $return = TRUE;
 370        }
 371        break;
 372      case 'METHOD':
 373        if( isset( $this->method )) {
 374          $this->method   = null;
 375          $return = TRUE;
 376        }
 377        break;
 378      default:
 379        $reduced = array();
 380        if( $propName != 'X-PROP' ) {
 381          if( !isset( $this->xprop[$propName] )) { unset( $this->propdelix[$propName] ); return FALSE; }
 382          foreach( $this->xprop as $k => $a ) {
 383            if(( $k != $propName ) && !empty( $a ))
 384              $reduced[$k] = $a;
 385          }
 386        }
 387        else {
 388          if( count( $this->xprop ) <= $propix )  return FALSE;
 389          $xpropno = 0;
 390          foreach( $this->xprop as $xpropkey => $xpropvalue ) {
 391            if( $propix != $xpropno )
 392              $reduced[$xpropkey] = $xpropvalue;
 393            $xpropno++;
 394          }
 395        }
 396        $this->xprop = $reduced;
 397        if( empty( $this->xprop )) {
 398          unset( $this->propdelix[$propName] );
 399          return FALSE;
 400        }
 401        return TRUE;
 402    }
 403    return $return;
 404  }
 405/**
 406 * get calendar property value/params
 407 *
 408 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 409 * @since 2.18.10 - 2013-09-04
 410 * @param string $propName, optional
 411 * @param int $propix, optional, if specific property is wanted in case of multiply occurences
 412 * @param bool $inclParam=FALSE
 413 * @return mixed
 414 */
 415  function getProperty( $propName=FALSE, $propix=FALSE, $inclParam=FALSE ) {
 416    $propName = ( $propName ) ? strtoupper( $propName ) : 'X-PROP';
 417    if( 'X-PROP' == $propName ) {
 418      if( !$propix )
 419        $propix  = ( isset( $this->propix[$propName] )) ? $this->propix[$propName] + 2 : 1;
 420      $this->propix[$propName] = --$propix;
 421    }
 422    else {
 423      $mProps    = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'RELATED-TO', 'RESOURCES' );
 424      $vComps    = array('vevent', 'vtodo', 'vjournal', 'vfreebusy' );
 425      $dateFmt   = '%04d%02d%02d';
 426    }
 427    switch( $propName ) {
 428      case 'ATTENDEE':
 429      case 'CATEGORIES':
 430      case 'CONTACT':
 431      case 'DTSTART':
 432      case 'GEOLOCATION':
 433      case 'LOCATION':
 434      case 'ORGANIZER':
 435      case 'PRIORITY':
 436      case 'RESOURCES':
 437      case 'STATUS':
 438      case 'SUMMARY':
 439      case 'RECURRENCE-ID-UID':
 440      case 'RELATED-TO':
 441      case 'R-UID':
 442      case 'UID':
 443      case 'URL':
 444        $output  = array();
 445        foreach ( $this->components as $cix => $component) {
 446          if( !in_array( $component->objName, $vComps))
 447            continue;
 448          if( in_array( $propName, $mProps )) {
 449            $component->_getProperties( $propName, $output );
 450            continue;
 451          }
 452          elseif(( 3 < strlen( $propName )) && ( 'UID' == substr( $propName, -3 ))) {
 453            if( FALSE !== ( $content = $component->getProperty( 'RECURRENCE-ID' )))
 454              $content = $component->getProperty( 'UID' );
 455          }
 456          elseif( 'GEOLOCATION' == $propName ) {
 457            $content = ( FALSE === ( $loc = $component->getProperty( 'LOCATION' ))) ? '' : $loc.' ';
 458            if( FALSE === ( $geo = $component->getProperty( 'GEO' )))
 459              continue;
 460            $content .= iCalUtilityFunctions::_geo2str2( $geo['latitude'],  iCalUtilityFunctions::$geoLatFmt ).
 461                        iCalUtilityFunctions::_geo2str2( $geo['longitude'], iCalUtilityFunctions::$geoLongFmt ).'/';
 462          }
 463          elseif( FALSE === ( $content = $component->getProperty( $propName )))
 464            continue;
 465          if(( FALSE === $content ) || empty( $content ))
 466            continue;
 467          elseif( is_array( $content )) {
 468            if( isset( $content['year'] )) {
 469              $key  = sprintf( $dateFmt, $content['year'], $content['month'], $content['day'] );
 470              if( !isset( $output[$key] ))
 471                $output[$key] = 1;
 472              else
 473                $output[$key] += 1;
 474            }
 475            else {
 476              foreach( $content as $partValue => $partCount ) {
 477                if( !isset( $output[$partValue] ))
 478                  $output[$partValue] = $partCount;
 479                else
 480                  $output[$partValue] += $partCount;
 481              }
 482            }
 483          } // end elseif( is_array( $content )) {
 484          elseif( !isset( $output[$content] ))
 485            $output[$content] = 1;
 486          else
 487            $output[$content] += 1;
 488        } // end foreach ( $this->components as $cix => $component)
 489        if( !empty( $output ))
 490          ksort( $output );
 491        return $output;
 492        break;
 493      case 'CALSCALE':
 494        return ( !empty( $this->calscale )) ? $this->calscale : FALSE;
 495        break;
 496      case 'METHOD':
 497        return ( !empty( $this->method )) ? $this->method : FALSE;
 498        break;
 499      case 'PRODID':
 500        if( empty( $this->prodid ))
 501          $this->_makeProdid();
 502        return $this->prodid;
 503        break;
 504      case 'VERSION':
 505        return ( !empty( $this->version )) ? $this->version : FALSE;
 506        break;
 507      default:
 508        if( $propName != 'X-PROP' ) {
 509          if( !isset( $this->xprop[$propName] )) return FALSE;
 510          return ( $inclParam ) ? array( $propName, $this->xprop[$propName] )
 511                                : array( $propName, $this->xprop[$propName]['value'] );
 512        }
 513        else {
 514          if( empty( $this->xprop )) return FALSE;
 515          $xpropno = 0;
 516          foreach( $this->xprop as $xpropkey => $xpropvalue ) {
 517            if( $propix == $xpropno )
 518              return ( $inclParam ) ? array( $xpropkey, $this->xprop[$xpropkey] )
 519                                    : array( $xpropkey, $this->xprop[$xpropkey]['value'] );
 520            else
 521              $xpropno++;
 522          }
 523          unset( $this->propix[$propName] );
 524          return FALSE; // not found ??
 525        }
 526    }
 527    return FALSE;
 528  }
 529/**
 530 * general vcalendar property setting
 531 *
 532 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 533 * @since 2.2.13 - 2007-11-04
 534 * @param mixed $args variable number of function arguments,
 535 *                    first argument is ALWAYS component name,
 536 *                    second ALWAYS component value!
 537 * @return bool
 538 */
 539  function setProperty () {
 540    $numargs    = func_num_args();
 541    if( 1 > $numargs )
 542      return FALSE;
 543    $arglist    = func_get_args();
 544    $arglist[0] = strtoupper( $arglist[0] );
 545    switch( $arglist[0] ) {
 546      case 'CALSCALE':
 547        return $this->setCalscale( $arglist[1] );
 548      case 'METHOD':
 549        return $this->setMethod( $arglist[1] );
 550      case 'VERSION':
 551        return $this->setVersion( $arglist[1] );
 552      default:
 553        if( !isset( $arglist[1] )) $arglist[1] = null;
 554        if( !isset( $arglist[2] )) $arglist[2] = null;
 555        return $this->setXprop( $arglist[0], $arglist[1], $arglist[2] );
 556    }
 557    return FALSE;
 558  }
 559/*********************************************************************************/
 560/**
 561 * get vcalendar config values or * calendar components
 562 *
 563 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 564 * @since 2.11.7 - 2012-01-12
 565 * @param mixed $config
 566 * @return value
 567 */
 568  function getConfig( $config = FALSE ) {
 569    if( !$config ) {
 570      $return = array();
 571      $return['ALLOWEMPTY']  = $this->getConfig( 'ALLOWEMPTY' );
 572      $return['DELIMITER']   = $this->getConfig( 'DELIMITER' );
 573      $return['DIRECTORY']   = $this->getConfig( 'DIRECTORY' );
 574      $return['FILENAME']    = $this->getConfig( 'FILENAME' );
 575      $return['DIRFILE']     = $this->getConfig( 'DIRFILE' );
 576      $return['FILESIZE']    = $this->getConfig( 'FILESIZE' );
 577      $return['FORMAT']      = $this->getConfig( 'FORMAT' );
 578      if( FALSE !== ( $lang  = $this->getConfig( 'LANGUAGE' )))
 579        $return['LANGUAGE']  = $lang;
 580      $return['NEWLINECHAR'] = $this->getConfig( 'NEWLINECHAR' );
 581      $return['UNIQUE_ID']   = $this->getConfig( 'UNIQUE_ID' );
 582      if( FALSE !== ( $url   = $this->getConfig( 'URL' )))
 583        $return['URL']       = $url;
 584      $return['TZID']        = $this->getConfig( 'TZID' );
 585      return $return;
 586    }
 587    switch( strtoupper( $config )) {
 588      case 'ALLOWEMPTY':
 589        return $this->allowEmpty;
 590        break;
 591      case 'COMPSINFO':
 592        unset( $this->compix );
 593        $info = array();
 594        foreach( $this->components as $cix => $component ) {
 595          if( empty( $component )) continue;
 596          $info[$cix]['ordno'] = $cix + 1;
 597          $info[$cix]['type']  = $component->objName;
 598          $info[$cix]['uid']   = $component->getProperty( 'uid' );
 599          $info[$cix]['props'] = $component->getConfig( 'propinfo' );
 600          $info[$cix]['sub']   = $component->getConfig( 'compsinfo' );
 601        }
 602        return $info;
 603        break;
 604      case 'DELIMITER':
 605        return $this->delimiter;
 606        break;
 607      case 'DIRECTORY':
 608        if( empty( $this->directory ) && ( '0' != $this->directory ))
 609          $this->directory = '.';
 610        return $this->directory;
 611        break;
 612      case 'DIRFILE':
 613        return $this->getConfig( 'directory' ).$this->getConfig( 'delimiter' ).$this->getConfig( 'filename' );
 614        break;
 615      case 'FILEINFO':
 616        return array( $this->getConfig( 'directory' )
 617                    , $this->getConfig( 'filename' )
 618                    , $this->getConfig( 'filesize' ));
 619        break;
 620      case 'FILENAME':
 621        if( empty( $this->filename ) && ( '0' != $this->filename )) {
 622          if( 'xcal' == $this->format )
 623            $this->filename = date( 'YmdHis' ).'.xml'; // recommended xcs.. .
 624          else
 625            $this->filename = date( 'YmdHis' ).'.ics';
 626        }
 627        return $this->filename;
 628        break;
 629      case 'FILESIZE':
 630        $size    = 0;
 631        if( empty( $this->url )) {
 632          $dirfile = $this->getConfig( 'dirfile' );
 633          if( !is_file( $dirfile ) || ( FALSE === ( $size = filesize( $dirfile ))))
 634            $size = 0;
 635          clearstatcache();
 636        }
 637        return $size;
 638        break;
 639      case 'FORMAT':
 640        return ( $this->format == 'xcal' ) ? 'xCal' : 'iCal';
 641        break;
 642      case 'LANGUAGE':
 643         /* get language for calendar component as defined in [RFC 1766] */
 644        return $this->language;
 645        break;
 646      case 'NL':
 647      case 'NEWLINECHAR':
 648        return $this->nl;
 649        break;
 650      case 'TZID':
 651        return $this->dtzid;
 652        break;
 653      case 'UNIQUE_ID':
 654        return $this->unique_id;
 655        break;
 656      case 'URL':
 657        if( !empty( $this->url ))
 658          return $this->url;
 659        else
 660          return FALSE;
 661        break;
 662    }
 663  }
 664/**
 665 * general vcalendar config setting
 666 *
 667 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 668 * @since 2.18.12 - 2013-09-12
 669 * @param mixed  $config
 670 * @param string $value
 671 * @return void
 672 */
 673  function setConfig( $config, $value = FALSE) {
 674    if( is_array( $config )) {
 675      $config  = array_change_key_case( $config, CASE_UPPER );
 676      if( isset( $config['DELIMITER'] )) {
 677        if( FALSE === $this->setConfig( 'DELIMITER', $config['DELIMITER'] ))
 678          return FALSE;
 679        unset( $config['DELIMITER'] );
 680      }
 681      if( isset( $config['DIRECTORY'] )) {
 682        if( FALSE === $this->setConfig( 'DIRECTORY', $config['DIRECTORY'] ))
 683          return FALSE;
 684        unset( $config['DIRECTORY'] );
 685      }
 686      foreach( $config as $cKey => $cValue ) {
 687        if( FALSE === $this->setConfig( $cKey, $cValue ))
 688          return FALSE;
 689      }
 690      return TRUE;
 691    }
 692    else
 693    $res = FALSE;
 694      $config = strtoupper( $config );
 695    switch( $config ) {
 696      case 'ALLOWEMPTY':
 697        $this->allowEmpty = $value;
 698        $subcfg  = array( 'ALLOWEMPTY' => $value );
 699        $res = TRUE;
 700        break;
 701      case 'DELIMITER':
 702        $this->delimiter = $value;
 703        return TRUE;
 704        break;
 705      case 'DIRECTORY':
 706        if( FALSE === ( $value = realpath( rtrim( trim( $value ), $this->delimiter ))))
 707          return FALSE;
 708        else {
 709            /* local directory */
 710          $this->directory = $value;
 711          $this->url       = null;
 712          return TRUE;
 713        }
 714        break;
 715      case 'FILENAME':
 716        $value   = trim( $value );
 717        $dirfile = $this->directory.$this->delimiter.$value;
 718        if( file_exists( $dirfile )) {
 719            /* local file exists */
 720          if( is_readable( $dirfile ) || is_writable( $dirfile )) {
 721            clearstatcache();
 722            $this->filename = $value;
 723            return TRUE;
 724          }
 725          else
 726            return FALSE;
 727        }
 728        elseif( is_readable( $this->directory ) || is_writable( $this->directory )) {
 729            /* read- or writable directory */
 730          clearstatcache();
 731          $this->filename = $value;
 732          return TRUE;
 733        }
 734        else
 735          return FALSE;
 736        break;
 737      case 'FORMAT':
 738        $value   = trim( strtolower( $value ));
 739        if( 'xcal' == $value ) {
 740          $this->format             = 'xcal';
 741          $this->attributeDelimiter = $this->nl;
 742          $this->valueInit          = null;
 743        }
 744        else {
 745          $this->format             = null;
 746          $this->attributeDelimiter = ';';
 747          $this->valueInit          = ':';
 748        }
 749        $subcfg  = array( 'FORMAT' => $value );
 750        $res = TRUE;
 751        break;
 752      case 'LANGUAGE': // set language for calendar component as defined in [RFC 1766]
 753        $value   = trim( $value );
 754        $this->language = $value;
 755        $this->_makeProdid();
 756        $subcfg  = array( 'LANGUAGE' => $value );
 757        $res = TRUE;
 758        break;
 759      case 'NL':
 760      case 'NEWLINECHAR':
 761        $this->nl = $value;
 762        if( 'xcal' == $value ) {
 763          $this->attributeDelimiter = $this->nl;
 764          $this->valueInit          = null;
 765        }
 766        else {
 767          $this->attributeDelimiter = ';';
 768          $this->valueInit          = ':';
 769        }
 770        $subcfg  = array( 'NL' => $value );
 771        $res = TRUE;
 772        break;
 773      case 'TZID':
 774        $this->dtzid = $value;
 775        $subcfg  = array( 'TZID' => $value );
 776        $res = TRUE;
 777        break;
 778      case 'UNIQUE_ID':
 779        $value   = trim( $value );
 780        $this->unique_id = $value;
 781        $this->_makeProdid();
 782        $subcfg  = array( 'UNIQUE_ID' => $value );
 783        $res = TRUE;
 784        break;
 785      case 'URL':
 786            /* remote file - URL */
 787        $value     = str_replace( array( 'HTTP://', 'WEBCAL://', 'webcal://' ), 'http://', trim( $value ));
 788        $value     = str_replace( 'HTTPS://', 'https://', trim( $value ));
 789        if(( 'http://' != substr( $value, 0, 7 )) && ( 'https://' != substr( $value, 0, 8 )))
 790          return FALSE;
 791        $this->directory = '.';
 792        $this->url = $value;
 793        if( '.ics' != strtolower( substr( $value, -4 )))
 794          unset( $this->filename );
 795        else
 796          $this->filename = $basename( $value );
 797        return TRUE;
 798        break;
 799      default:  // any unvalid config key.. .
 800        return TRUE;
 801    }
 802    if( !$res ) return FALSE;
 803    if( isset( $subcfg ) && !empty( $this->components )) {
 804      foreach( $subcfg as $cfgkey => $cfgvalue ) {
 805        foreach( $this->components as $cix => $component ) {
 806          $res = $component->setConfig( $cfgkey, $cfgvalue, TRUE );
 807          if( !$res )
 808            break 2;
 809          $this->components[$cix] = $component->copy(); // PHP4 compliant
 810        }
 811      }
 812    }
 813    return $res;
 814  }
 815/*********************************************************************************/
 816/**
 817 * add calendar component to container
 818 *
 819 * alias to setComponent
 820 *
 821 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 822 * @since 1.x.x - 2007-04-24
 823 * @param object $component calendar component
 824 * @return void
 825 */
 826  function addComponent( $component ) {
 827    $this->setComponent( $component );
 828  }
 829/**
 830 * delete calendar component from container
 831 *
 832 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 833 * @since 2.8.8 - 2011-03-15
 834 * @param mixed $arg1 ordno / component type / component uid
 835 * @param mixed $arg2 optional, ordno if arg1 = component type
 836 * @return void
 837 */
 838  function deleteComponent( $arg1, $arg2=FALSE  ) {
 839    $argType = $index = null;
 840    if ( ctype_digit( (string) $arg1 )) {
 841      $argType = 'INDEX';
 842      $index   = (int) $arg1 - 1;
 843    }
 844    elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) {
 845      $argType = strtolower( $arg1 );
 846      $index   = ( !empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0;
 847    }
 848    $cix1dC = 0;
 849    foreach ( $this->components as $cix => $component) {
 850      if( empty( $component )) continue;
 851      if(( 'INDEX' == $argType ) && ( $index == $cix )) {
 852        unset( $this->components[$cix] );
 853        return TRUE;
 854      }
 855      elseif( $argType == $component->objName ) {
 856        if( $index == $cix1dC ) {
 857          unset( $this->components[$cix] );
 858          return TRUE;
 859        }
 860        $cix1dC++;
 861      }
 862      elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) {
 863        unset( $this->components[$cix] );
 864        return TRUE;
 865      }
 866    }
 867    return FALSE;
 868  }
 869/**
 870 * get calendar component from container
 871 *
 872 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 873 * @since 2.18.10 - 2013-09-04
 874 * @param mixed $arg1 optional, ordno/component type/ component uid
 875 * @param mixed $arg2 optional, ordno if arg1 = component type
 876 * @return object
 877 */
 878  function getComponent( $arg1=FALSE, $arg2=FALSE ) {
 879    $index = $argType = null;
 880    if ( !$arg1 ) { // first or next in component chain
 881      $argType = 'INDEX';
 882      $index   = $this->compix['INDEX'] = ( isset( $this->compix['INDEX'] )) ? $this->compix['INDEX'] + 1 : 1;
 883    }
 884    elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
 885      $arg2  = implode( '-', array_keys( $arg1 ));
 886      $index = $this->compix[$arg2] = ( isset( $this->compix[$arg2] )) ? $this->compix[$arg2] + 1 : 1;
 887      $dateProps  = array( 'DTSTART', 'DTEND', 'DUE', 'CREATED', 'COMPLETED', 'DTSTAMP', 'LAST-MODIFIED', 'RECURRENCE-ID' );
 888      $otherProps = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'RELATED-TO', 'RESOURCES', 'STATUS', 'SUMMARY', 'UID', 'URL' );
 889      $mProps     = array( 'ATTENDEE', 'CATEGORIES', 'CONTACT', 'RELATED-TO', 'RESOURCES' );
 890    }
 891    elseif ( ctype_digit( (string) $arg1 )) { // specific component in chain
 892      $argType = 'INDEX';
 893      $index   = (int) $arg1;
 894      unset( $this->compix );
 895    }
 896    elseif(( strlen( $arg1 ) <= strlen( 'vfreebusy' )) && ( FALSE === strpos( $arg1, '@' ))) { // object class name
 897      unset( $this->compix['INDEX'] );
 898      $argType = strtolower( $arg1 );
 899      if( !$arg2 )
 900        $index = $this->compix[$argType] = ( isset( $this->compix[$argType] )) ? $this->compix[$argType] + 1 : 1;
 901      elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
 902        $index = (int) $arg2;
 903    }
 904    elseif(( strlen( $arg1 ) > strlen( 'vfreebusy' )) && ( FALSE !== strpos( $arg1, '@' ))) { // UID as 1st argument
 905      if( !$arg2 )
 906        $index = $this->compix[$arg1] = ( isset( $this->compix[$arg1] )) ? $this->compix[$arg1] + 1 : 1;
 907      elseif( isset( $arg2 ) && ctype_digit( (string) $arg2 ))
 908        $index = (int) $arg2;
 909    }
 910    if( isset( $index ))
 911      $index  -= 1;
 912    $ckeys = array_keys( $this->components );
 913    if( !empty( $index) && ( $index > end(  $ckeys )))
 914      return FALSE;
 915    $cix1gC = 0;
 916    foreach ( $this->components as $cix => $component) {
 917      if( empty( $component )) continue;
 918      if(( 'INDEX' == $argType ) && ( $index == $cix ))
 919        return $component->copy();
 920      elseif( $argType == $component->objName ) {
 921        if( $index == $cix1gC )
 922          return $component->copy();
 923        $cix1gC++;
 924      }
 925      elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
 926        $hit  = array();
 927        $arg1 = array_change_key_case( $arg1, CASE_UPPER );
 928        foreach( $arg1 as $pName => $pValue ) {
 929          if( !in_array( $pName, $dateProps ) && !in_array( $pName, $otherProps ))
 930            continue;
 931          if( in_array( $pName, $mProps )) { // multiple occurrence
 932            $propValues = array();
 933            $component->_getProperties( $pName, $propValues );
 934            $propValues = array_keys( $propValues );
 935            $hit[] = ( in_array( $pValue, $propValues )) ? TRUE : FALSE;
 936            continue;
 937          } // end   if(.. .// multiple occurrence
 938          if( FALSE === ( $value = $component->getProperty( $pName ))) { // single occurrence
 939            $hit[] = FALSE; // missing property
 940            continue;
 941          }
 942          if( 'SUMMARY' == $pName ) { // exists within (any case)
 943            $hit[] = ( FALSE !== stripos( $value, $pValue )) ? TRUE : FALSE;
 944            continue;
 945          }
 946          if( in_array( $pName, $dateProps )) {
 947            $valuedate = sprintf( '%04d%02d%02d', $value['year'], $value['month'], $value['day'] );
 948            if( 8 < strlen( $pValue )) {
 949              if( isset( $value['hour'] )) {
 950                if( 'T' == substr( $pValue, 8, 1 ))
 951                  $pValue = str_replace( 'T', '', $pValue );
 952                $valuedate .= sprintf( '%02d%02d%02d', $value['hour'], $value['min'], $value['sec'] );
 953              }
 954              else
 955                $pValue = substr( $pValue, 0, 8 );
 956            }
 957            $hit[] = ( $pValue == $valuedate ) ? TRUE : FALSE;
 958            continue;
 959          }
 960          elseif( !is_array( $value ))
 961            $value = array( $value );
 962          foreach( $value as $part ) {
 963            $part = ( FALSE !== strpos( $part, ',' )) ? explode( ',', $part ) : array( $part );
 964            foreach( $part as $subPart ) {
 965              if( $pValue == $subPart ) {
 966                $hit[] = TRUE;
 967                continue 3;
 968              }
 969            }
 970          } // end foreach( $value as $part )
 971          $hit[] = FALSE; // no hit in property
 972        } // end  foreach( $arg1 as $pName => $pValue )
 973        if( in_array( TRUE, $hit )) {
 974          if( $index == $cix1gC )
 975            return $component->copy();
 976          $cix1gC++;
 977        }
 978      } // end elseif( is_array( $arg1 )) { // array( *[propertyName => propertyValue] )
 979      elseif( !$argType && ($arg1 == $component->getProperty( 'uid' ))) { // UID
 980        if( $index == $cix1gC )
 981          return $component->copy();
 982        $cix1gC++;
 983      }
 984    } // end foreach ( $this->components.. .
 985            /* not found.. . */
 986    unset( $this->compix );
 987    return FALSE;
 988  }
 989/**
 990 * create new calendar component, already included within calendar
 991 *
 992 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
 993 * @since 2.6.33 - 2011-01-03
 994 * @param string $compType component type
 995 * @return object (reference)
 996 */
 997  function & newComponent( $compType ) {
 998    $config = $this->getConfig();
 999    $keys   = array_keys( $this->components );
1000    $ix     = end( $keys) + 1;
1001    switch( strtoupper( $compType )) {
1002      case 'EVENT':
1003      case 'VEVENT':
1004        $this->components[$ix] = new vevent( $config );
1005        break;
1006      case 'TODO':
1007      case 'VTODO':
1008        $this->components[$ix] = new vtodo( $config );
1009        break;
1010      case 'JOURNAL':
1011      case 'VJOURNAL':
1012        $this->components[$ix] = new vjournal( $config );
1013        break;
1014      case 'FREEBUSY':
1015      case 'VFREEBUSY':
1016        $this->components[$ix] = new vfreebusy( $config );
1017        break;
1018      case 'TIMEZONE':
1019      case 'VTIMEZONE':
1020        array_unshift( $this->components, new vtimezone( $config ));
1021        $ix = 0;
1022        break;
1023      default:
1024        return FALSE;
1025    }
1026    return $this->components[$ix];
1027  }
1028/**
1029 * select components from calendar on date or selectOption basis
1030 *
1031 * Ensure DTSTART is set for every component.
1032 * No date controls occurs.
1033 *
1034 * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
1035 * @since 2.18.19 - 2014-02-01
1036 * @param mixed $startY optional, start Year,  default current Year ALT. array selecOptions ( *[ <propName> => <uniqueValue> ] )
1037 * @param int   $startM optional, start Month, default current Month
1038 * @param int   $startD optional, start Day,   default current Day
1039 * @param int   $endY   optional, end   Year,  default $startY
1040 * @param int   $endY   optional, end   Month, default $startM
1041 * @param int   $endY   optional, end   Day,   default $startD
1042 * @param mixed $cType  optional, calendar component type(-s), default FALSE=all else string/array type(-s)
1043 * @param bool  $flat   optional, FALSE (default) => output : array[Year][Month][Day][]
1044 *                                TRUE            => output : array[] (ignores split)
1045 * @param bool  $any    optional, TRUE (default) - select component(-s) that occurs within period
1046 *                                FALSE          - only component(-s) that starts within period
1047 * @param bool  $split  optional, TRUE (default) - one component copy every DAY it occurs during the
1048 *                                                 period (implies flat=FALSE)
1049 *                                FALSE          - one occurance of component only in output array
1050 * @return array or FALSE
1051 */
1052  function selectComponents( $startY=FALSE, $startM=FALSE, $startD=FALSE, $endY=FALSE, $endM=FALSE, $endD=FALSE, $cType=FALSE, $flat=FALSE, $any=TRUE, $split=TRUE ) {
1053            /* check  if empty calendar */
1054    if( 0 >= count( $this->components )) return FALSE;
1055    if( is_array( $startY ))
1056      return $this->selectComponents2( $startY );
1057            /* check default dates */
1058    if( ! $startY ) $startY = date( 'Y' );
1059    if( ! $startM ) $startM = date( 'm' );
1060    if( ! $startD ) $startD = date( 'd' );
1061    $startDate = mktime( 0, 0, 0, $startM, $startD, $startY );
1062    if( ! $endY )   $endY   = $startY;
1063    if( ! $endM )   $endM   = $startM;
1064    if( ! $endD )   $endD   = $startD;
1065    $endDate   = mktime( 23, 59, 59, $endM, $endD, $endY );
1066// echo 'selectComp arg='.date( 'Y-m-d H:i:s', $startDate).' -- '.date( 'Y-m-d H:i:s', $endDate)."<br>\n"; $tcnt = 0;// test ###
1067            /* check component types */
1068    $validTypes = array('vevent', 'vtodo', 'vjournal', 'vfreebusy' );
1069    if( empty( $cType ))
1070      $cType = $validTypes;
1071    else {
1072      if( ! is_array( $cType ))
1073        $cType = array( $cType );
1074      $cType = array_map( 'strtolower', $cType );
1075      foreach( $cType as $cix => $theType ) {
1076        $cType[$cix] = $theType;
1077        if( !in_array( $theType, $validTypes ))
1078          $cType[$cix] = 'vevent';
1079      }
1080      $cType = array_unique( $cType );
1081    }
1082    if(( FALSE === $flat ) && ( FALSE === $any )) // invalid combination
1083      $split = FALSE;
1084    if(( TRUE === $flat ) && ( TRUE === $split )) // invalid combination
1085      $split = FALSE;
1086            /* iterate components */
1087    $result       = array();
1088    $this->sort( 'UID' );
1089    $compUIDcmp   = null;
1090    $recurridList = array();
1091    foreach ( $this->components as $cix => $component ) {
1092      if( empty( $component )) continue;
1093      unset( $start );
1094            /* deselect unvalid type components */
1095      if( !in_array( $component->objName, $cType ))
1096        continue;
1097      $start = $component->getProperty( 'dtstart', FALSE, TRUE );
1098            /* select due when dtstart is missing */
1099      if( empty( $start ) && ( $component->objName == 'vtodo' ) && ( FALSE === ( $start = $component->getProperty( 'due', FALSE, TRUE ))))
1100        continue;
1101      if( empty( $start ))
1102        continue;
1103      if( ! isset( $start['value']['tz'] ) && isset( $start['params']['TZID'] ))
1104        $start['value']['tz'] = $start['params']['TZID'];
1105      $start = $start['value'];
1106      $compUID      = $component->getProperty( 'UID' );
1107      if( $compUIDcmp != $compUID ) {
1108        $compUIDcmp = $compUID;
1109        unset( $exdatelist, $recurridList );
1110      }
1111      $SCbools    = array( 'dtendExist' => FALSE,  'dueExist' => FALSE,  'durationExist' => FALSE, 'endAllDayEvent' => FALSE );
1112      $recurrid   = FALSE;
1113      $dateFormat = array();
1114      unset( $end, $startWdate, $endWdate, $rdurWsecs, $rdur, $workstart, $workend ); // clean up
1115      $startWdate = iCalUtilityFunctions::_SCsetXCurrentDateZ( iCalUtilityFunctions::_date2timestamp( $start ), $start );
1116      $dateFormat['start'] = ( isset( $start['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
1117            /* get end date from dtend/due/duration properties */
1118      $end = $component->getProperty( 'dtend', FALSE, TRUE );
1119      if( !empty( $end )) {
1120        $SCbools[ 'dtendExist'] = TRUE;
1121        $dateFormat['end'] = ( isset( $end['value']['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
1122      }
1123      if( ! isset( $end['value']['tz'] ) && isset( $end['params']['TZID'] ))
1124        $end['value']['tz'] = $end['params']['TZID'];
1125      $end = $end['value'];
1126      if( empty( $end ) && ( $component->objName == 'vtodo' )) {
1127        $end = $component->getProperty( 'due' );
1128        if( !empty( $end )) {
1129          $SCbools[ 'dueExist'] = TRUE;
1130          $dateFormat['end'] = ( isset( $end['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
1131        }
1132      }
1133      if( !empty( $end ) && !isset( $end['hour'] )) {
1134          /* a DTEND without time part regards an event that ends the day before,
1135             for an all-day event DTSTART=20071201 DTEND=20071202 (taking place 20071201!!! */
1136        $SCbools[ 'endAllDayEvent'] = TRUE;
1137        $endWdate = mktime( 23, 59, 59, $end['month'], ($end['day'] - 1), $end['year'] );
1138        $end['year']  = date( 'Y', $endWdate );
1139        $end['month'] = date( 'm', $endWdate );
1140        $end['day']   = date( 'd', $endWdate );
1141        $end['hour']  = 23;
1142        $end['min']   = $end['sec'] = 59;
1143      }
1144      if( empty( $end )) {
1145        $end = $component->getProperty( 'duration', FALSE, FALSE, TRUE );// in dtend (array) format
1146        if( !empty( $end ))
1147          if( isset( $start['tz'] ))
1148            $end['tz'] = $start['tz'];
1149          $SCbools[ 'durationExist'] = TRUE;
1150          $dateFormat['end'] = ( isset( $start['hour'] )) ? 'Y-m-d H:i:s' : 'Y-m-d';
1151// if( !empty($end))  echo 'selectComp 4 start='.implode('-',$start).' end='.implode('-',$end)."<br>\n"; // test ###
1152      }
1153      if( empty( $end )) { // assume one day duration if missing end date
1154        $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );
1155        if( isset( $start['tz'] ))
1156          $end['tz'] = $start['tz'];
1157      }
1158// if( isset($end))  echo 'selectComp 5 start='.implode('-',$start).' end='.implode('-',$end)."<br>\n"; // test ###
1159      $endWdate = iCalUtilityFunctions::_SCsetXCurrentDateZ( iCalUtilityFunctions::_date2timestamp( $end ), $end );
1160      if( $endWdate < $startWdate ) { // MUST be after start date!!
1161        $end = array( 'year' => $start['year'], 'month' => $start['month'], 'day' => $start['day'], 'hour' => 23, 'min' => 59, 'sec' => 59 );
1162        $endWdate = iCalUtilityFunctions::_date2timestamp( $end );
1163      }
1164      $rdurWsecs  = $endWdate - $startWdate; // compute event (component) duration in seconds
1165            /* make a list of optional exclude dates for component occurence from exrule and exdate */
1166      $exdatelist = array();
1167      $workstart  = iCalUtilityFunctions::_timestamp2date(( $startDate - $rdurWsecs ), 6);
1168      $workend    = iCalUtilityFunctions::_timestamp2date(( $endDate + $rdurWsecs ), 6);
1169      while( FALSE !== ( $exrule = $component->getProperty( 'exrule' )))    // check exrule
1170        iCalUtilityFunctions::_recur2date( $exdatelist, $exrule, $start, $workstart, $workend );
1171      while( FALSE !== ( $exdate = $component->getProperty( 'exdate' ))) {  // check exdate
1172        foreach( $exdate as $theExdate ) {
1173          $exWdate = iCalUtilityFunctions::_date2timestamp( $theExdate );
1174          $exWdate = mktime( 0, 0, 0, date( 'm', $exWdate ), date( 'd', $exWdate ), date( 'Y', $exWdate )); // on a day-basis !!!
1175          if((( $startDate - $rdurWsecs ) <= $exWdate ) && ( $endDate >= $exWdate ))
1176            $exdatelist[$exWdate] = TRUE;
1177        } // end - foreach( $exdate as $theExdate )
1178      }  // end - check exdate
1179            /* 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 */
1180      if( FALSE !== ( $recurrid = $component->getProperty( 'recurrence-id' ))) {
1181        $recurrid = iCalUtilityFunctions::_date2timestamp( $recurrid );
1182        $recurrid = mktime( 0, 0, 0, date( 'm', $recurrid ), date( 'd', $recurrid ), date( 'Y', $recurrid )); // on a day-basis !!!
1183        $recurridList[$recurrid] = TRUE;                                             // no recurring to start this day
1184// echo "adding comp no:$cix with date=".implode($start)." and recurrid=".implode($recurrid)." to recurridList id=$recurrid<br>\n"; // test ###
1185      } // end recurrence-id/sequence test
1186            /* select only components with.. . */
1187      if(( !$any && ( $startWdate >= $startDate ) && ( $startWdate <= $endDate )) || // (dt)start within the period
1188         (  $any && ( $startWdate < $endDate ) && ( $endWdate >= $startDate ))) {    // occurs within the period
1189            /* add the selected component (WITHIN valid dates) to output array */
1190        if( $flat ) { // any=true/false, ignores split
1191          if( !$recurrid )
1192            $result[$compUID] = $component->copy(); // copy original to output (but not anyone with recurrence-id)
1193        }
1194        elseif( $split ) { // split the original component
1195          if( $endWdate > $endDate )
1196            $endWdate = $endDate;     // use period end date
1197          $rstart   = ( $startWdate < $startDate ) ? $startDate : $startWdate; // use period start date
1198          $startYMD = $rstartYMD = date( 'Ymd', $rstart );
1199          $endYMD   = date( 'Ymd', $endWdate );
1200          $checkDate = mktime( 0, 0, 0, date( 'm', $rstart ), date( 'd', $rstart ), date( 'Y', $rstart ) ); // on a day-basis !!!
1201// echo "going to test comp no:$cix with rstartYMD=$rstartYMD, endYMD=$endYMD and checkDate($checkDate) with recurridList=".implode(',',array_keys($recurridList))."<br>\n"; // test ###
1202          if( !isset( $exdatelist[$checkDate] )) { // exclude any recurrence START date, found in exdatelist
1203            while( $rstartYMD <= $endYMD ) { // iterate
1204              if( isset( $exdatelist[$checkDate] ) ||                   // exclude any recurrence date, found in the exdatelist
1205                ( isset( $recurridList[$checkDate] ) && !$recurrid )) { // or in the recurridList, but not itself
1206// echo "skipping comp no:$cix with datestart=$rstartYMD and checkdate=$checkDate<br>\n"; // test ###
1207                $rstart   += ( 24 *3600 ); // step one day
1208                $rstartYMD = date( 'Ymd', $rstart );
1209                continue;
1210              }
1211              iCalUtilityFunctions::_SCsetXCurrentStart( $component, $dateFormat, $checkDate, $rstartYMD, $rstart, $startYMD, $start );
1212              iCalUtilityFunctions::_SCsetXCurrentEnd(   $component, $dateFormat, $rstart, $rstartYMD, $endWdate, $endYMD, $end, $SCbools );
1213              $wd        = getdate( $rstart );
1214              $result[$wd['year']][$wd['mon']][$wd['mday']][$compUID] = $component->copy(); // copy to output
1215              $rstart   += ( 24 *3600 ); // step one day
1216              $rstartYMD = date( 'Ymd', $rstart );
1217              $checkDate = mktime( 0, 0, 0, date( 'm', $rstart ), date( 'd', $rstart ), date( 'Y', $rstart ) ); // on a day-basis !!!
1218            } // end while( $rstart <= $endWdate )
1219          } // end if( !isset( $exdatelist[$checkDate] ))
1220        } // end elseif( $split )   -  else use component date
1221        elseif( $recurrid && !$flat && !$any && !$split )
1222          $continue = TRUE;
1223        else { // !$flat && !$split, i.e. no flat array and DTSTART within period
1224          $checkDate = mktime( 0, 0, 0, date( 'm', $startWdate ), date( 'd', $startWdate ), date( 'Y', $startWdate ) ); // on a day-basis !!!
1225// echo "going to test comp no:$cix with checkDate=$checkDate with recurridList=".implode(',',array_keys($recurridList)); // test ###
1226          if(( !$any || !isset( $exdatelist[$checkDate] )) &&   // exclude any recurrence date, found in exdatelist
1227              ( !isset( $recurridList[$checkDate] ) || $recurrid )) { // or in the recurridList, but not itself
1228// echo " and copied to output<br>\n"; // test ###
1229            $wd = getdate( $startWdate );
1230            $result[$wd['year']][$wd['mon']][$wd['mday']][$compUID] = $component->copy(); // copy to output
1231          }
1232        }
1233      } // end if(( $startWdate >= $startDate ) && ( $startWdate <= $endDate ))
1234            /* if 'any' components, check components with reccurrence rules, removing all excluding dates */
1235      if( TRUE === $any ) {
1236            /* make a list of optional repeating dates for component occurence, rrule, rdate */
1237        $recurlist = array();
1238        while( FALSE !== ( $rrule = $component->getProperty( 'rrule' )))    // check rrule
1239          iCalUtilityFunctions::_recur2date( $recurlist, $rrule, $start, $workstart, $workend );
1240        foreach( $recurlist as $recurkey => $recurvalue )                   // key=match date as timestamp
1241          $recurlist[$recurkey] = $rdurWsecs;                               // add duration in seconds
1242        while( FALSE !== ( $rdate = $component->getProperty( 'rdate' ))) {  // check rdate
1243          foreach( $rdate as $theRdate ) {
1244            if( is_array( $theRdate ) && ( 2 == count( $theRdate )) &&      // all days within PERIOD
1245                   array_key_exists( '0', $theRdate ) &&  array_key_exists( '1', $theRdate )) {
1246              $rstart = iCalUtilityFunctions::_date2timestamp( $theRdate[0] );
1247              if(( $rstart < ( $startDate - $rdurWsecs )) || ( $rstart > $endDate ))
1248                continue;
1249              if( isset( $theRdate[1]['year'] )) // date-date period
1250                $rend = iCalUtilityFunctions::_date2timestamp( $theRdate[1] );
1251              else {                             // date-duration period
1252                $rend = iCalUtilityFunctions::_duration2date( 

Large files files are truncated, but you can click here to view the full file