This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,325 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Additional functions to use with vtimezone components
*
* Before calling the functions, set time zone 'GMT' ('date_default_timezone_set')!
* @author Yitzchok Lavi <icalcreator@onebigsystem.com>
* adjusted for iCalcreator Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @version 1.0.2 - 2011-02-24
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* Returns array with the offset information
*
* From UTC for a (UTC) datetime/timestamp in the
* timezone, according to the VTIMEZONE information in the input array.
* @param array $timezonesarray output from function getTimezonesAsDateArrays (below)
* @param string $tzid time zone identifier
* @param mixed $timestamp timestamp or a UTC datetime (in array format)
* @return array time zone data with keys for $OFFSETHIS, $OFFSETSEC and $TZNAME
*/
function getTzOffsetForDate( $timezonesarray, $tzid, $timestamp ) {
static $OFFSETHIS = 'offsetHis';
static $OFFSETSEC = 'offsetSec';
static $TZBEFORE = 'tzbefore';
static $TZAFTER = 'tzafter';
static $TZNAME = 'tzname';
if( is_array( $timestamp )) {
$timestamp = gmmktime(
$timestamp[util::$LCHOUR],
$timestamp[util::$LCMIN],
$timestamp[util::$LCSEC],
$timestamp[util::$LCMONTH],
$timestamp[util::$LCDAY],
$timestamp[util::$LCYEAR]
) ;
}
$tzoffset = [];
// something to return if all goes wrong (such as if $tzid doesn't find us an array of dates)
$tzoffset[$OFFSETHIS] = '+0000';
$tzoffset[$OFFSETSEC] = 0;
$tzoffset[$TZNAME] = '?';
if( !isset( $timezonesarray[$tzid] ))
return $tzoffset;
$tzdatearray = $timezonesarray[$tzid];
if ( is_array($tzdatearray) ) {
sort($tzdatearray); // just in case
if ( $timestamp < $tzdatearray[0][util::$LCTIMESTAMP] ) {
// our date is before the first change
$tzoffset[$OFFSETHIS] = $tzdatearray[0][$TZBEFORE][$OFFSETHIS] ;
$tzoffset[$OFFSETSEC] = $tzdatearray[0][$TZBEFORE][$OFFSETSEC] ;
$tzoffset[$TZNAME] = $tzdatearray[0][$TZBEFORE][$OFFSETHIS] ; // we don't know the tzname in this case
} elseif ( $timestamp >= $tzdatearray[count($tzdatearray)-1][util::$LCTIMESTAMP] ) {
// our date is after the last change (we do this so our scan can stop at the last record but one)
$tzoffset[$OFFSETHIS] = $tzdatearray[count($tzdatearray)-1][$TZAFTER][$OFFSETHIS] ;
$tzoffset[$OFFSETSEC] = $tzdatearray[count($tzdatearray)-1][$TZAFTER][$OFFSETSEC] ;
$tzoffset[$TZNAME] = $tzdatearray[count($tzdatearray)-1][$TZAFTER][$TZNAME] ;
} else {
// our date somewhere in between
// loop through the list of dates and stop at the one where the timestamp is before our date and the next one is after it
// we don't include the last date in our loop as there isn't one after it to check
for ( $i = 0 ; $i <= count($tzdatearray)-2 ; $i++ ) {
if(( $timestamp >= $tzdatearray[$i][util::$LCTIMESTAMP] ) &&
( $timestamp < $tzdatearray[$i+1][util::$LCTIMESTAMP] )) {
$tzoffset[$OFFSETHIS] = $tzdatearray[$i][$TZAFTER][$OFFSETHIS] ;
$tzoffset[$OFFSETSEC] = $tzdatearray[$i][$TZAFTER][$OFFSETSEC] ;
$tzoffset[$TZNAME] = $tzdatearray[$i][$TZAFTER][$TZNAME] ;
break;
}
}
}
}
return $tzoffset;
}
/**
* Return an array containing all the timezone data in the vcalendar object
*
* @param vcalendar $vcalendar iCalcreator calendar instance
* @return array time zone transition timestamp,
array before(offsetHis, offsetSec),
array after(offsetHis, offsetSec, tzname)
based on the timezone data in the vcalendar object
*/
function getTimezonesAsDateArrays( $vcalendar ) {
$timezonedata = [];
while( $vtz = $vcalendar->getComponent( util::$LCVTIMEZONE )) {
$tzid = $vtz->getProperty('tzid');
$alltzdates = [];
while ( $vtzc = $vtz->getComponent( util::$LCSTANDARD )) {
$newtzdates = expandTimezoneDates($vtzc);
$alltzdates = array_merge($alltzdates, $newtzdates);
}
while ( $vtzc = $vtz->getComponent( util::$LCDAYLIGHT )) {
$newtzdates = expandTimezoneDates($vtzc);
$alltzdates = array_merge($alltzdates, $newtzdates);
}
sort($alltzdates);
$timezonedata[$tzid] = $alltzdates;
}
return $timezonedata;
}
/**
* Returns an array containing time zone data from vtimezone standard/daylight instances
*
* @param object $vtzc an iCalcreator calendar standard/daylight instance
* @return array time zone data;
* array before(offsetHis, offsetSec),
* array after(offsetHis, offsetSec, tzname)
* @todo fix quickfix...
*/
function expandTimezoneDates($vtzc) {
static $OFFSETHIS = 'offsetHis';
static $OFFSETSEC = 'offsetSec';
static $TZBEFORE = 'tzbefore';
static $TZAFTER = 'tzafter';
static $TZNAME = 'tzname';
static $YEARLY = 'YEARLY';
static $FMTDATE = '%04d%02d%02dT%02d%02d%02d';
static $DAYNAMES = ['SU' => 'Sunday',
'MO' => 'Monday',
'TU' => 'Tuesday',
'WE' => 'Wednesday',
'TH' => 'Thursday',
'FR' => 'Friday',
'SA' => 'Saturday'];
static $MON = 'mon';
static $MDAY = 'mday';
static $HOURS = 'hours';
static $MINUTES = 'minutes';
static $SECONDS = 'seconds';
static $MINUS1WEEK = '-1 week';
static $PLUS1MONTH = '+1 month';
static $SP1WEEK = ' week';
static $SP1YEAR = ' year';
static $PLUS10YEAR = '+10 year';
$tzdates = [];
// prepare time zone "description" to attach to each change
$tzbefore = [];
$tzbefore[$OFFSETHIS] = $vtzc->getProperty(util::$TZOFFSETFROM) ;
$tzbefore[$OFFSETSEC] = util::tz2offset($tzbefore[$OFFSETHIS]);
if(( util::$MINUS != substr( (string) $tzbefore[$OFFSETSEC], 0, 1 )) &&
( util::$PLUS != substr( (string) $tzbefore[$OFFSETSEC], 0, 1 )))
$tzbefore[$OFFSETSEC] = util::$PLUS . $tzbefore[$OFFSETSEC];
$tzafter = [];
$tzafter[$OFFSETHIS] = $vtzc->getProperty(util::$TZOFFSETTO) ;
$tzafter[$OFFSETSEC] = util::tz2offset($tzafter[$OFFSETHIS]);
if(( util::$MINUS != substr( (string) $tzafter[$OFFSETSEC], 0, 1 )) &&
( util::$PLUS != substr( (string) $tzafter[$OFFSETSEC], 0, 1 )))
$tzafter[$OFFSETSEC] = util::$PLUS . $tzafter[$OFFSETSEC];
if( false === ( $tzafter[$TZNAME] = $vtzc->getProperty(util::$TZNAME)))
$tzafter[$TZNAME] = $tzafter[$OFFSETHIS];
// find out where to start from
$dtstart = $vtzc->getProperty(util::$DTSTART);
$dtstarttimestamp = mktime( $dtstart[util::$LCHOUR],
$dtstart[util::$LCMIN],
$dtstart[util::$LCSEC],
$dtstart[util::$LCMONTH],
$dtstart[util::$LCDAY],
$dtstart[util::$LCYEAR] ) ;
if( !isset( $dtstart[util::$UNPARSEDTEXT] )) // ??
$dtstart[util::$UNPARSEDTEXT] = sprintf( $FMTDATE, $dtstart[util::$LCYEAR],
$dtstart[util::$LCMONTH],
$dtstart[util::$LCDAY],
$dtstart[util::$LCHOUR],
$dtstart[util::$LCMIN],
$dtstart[util::$LCSEC] );
if ( $dtstarttimestamp == 0 ) {
// it seems that the dtstart string may not have parsed correctly
// let's set a timestamp starting from 1902, using the time part of the original string
// so that the time will change at the right time of day
// at worst we'll get midnight again
$origdtstartsplit = explode('T',$dtstart[util::$UNPARSEDTEXT]) ;
$dtstarttimestamp = strtotime('19020101',0);
$dtstarttimestamp = strtotime($origdtstartsplit[1],$dtstarttimestamp);
}
// the date (in dtstart and opt RDATE/RRULE) is ALWAYS LOCAL (not utc!!), adjust from 'utc' to 'local' timestamp
$diff = -1 * $tzbefore[$OFFSETSEC];
$dtstarttimestamp += $diff;
// add this (start) change to the array of changes
$tzdates[] = [util::$LCTIMESTAMP => $dtstarttimestamp,
$TZBEFORE => $tzbefore,
$TZAFTER => $tzafter];
$datearray = getdate($dtstarttimestamp);
// save original array to use time parts, because strtotime (used below) apparently loses the time
$changetime = $datearray ;
// generate dates according to an RRULE line
$rrule = $vtzc->getProperty(util::$RRULE) ;
if ( is_array($rrule) ) {
if ( $rrule[util::$FREQ] == $YEARLY ) {
// calculate transition dates starting from DTSTART
$offsetchangetimestamp = $dtstarttimestamp;
// calculate transition dates until 10 years in the future
$stoptimestamp = strtotime($PLUS10YEAR,time());
// if UNTIL is set, calculate until then (however far ahead)
if ( isset( $rrule[util::$UNTIL] ) && ( $rrule[util::$UNTIL] != '' )) {
$stoptimestamp = mktime(
$rrule[util::$UNTIL][util::$LCHOUR],
$rrule[util::$UNTIL][util::$LCMIN],
$rrule[util::$UNTIL][util::$LCSEC],
$rrule[util::$UNTIL][util::$LCMONTH],
$rrule[util::$UNTIL][util::$LCDAY],
$rrule[util::$UNTIL][util::$LCYEAR]
) ;
}
$count = 0 ;
$stopcount = isset( $rrule[util::$COUNT] ) ? $rrule[util::$COUNT] : 0 ;
// repeat so long as we're between DTSTART and UNTIL, or we haven't prepared COUNT dates
while( $offsetchangetimestamp < $stoptimestamp &&
( $stopcount == 0 || $count < $stopcount ) ) {
// break up the timestamp into its parts
$datearray = getdate($offsetchangetimestamp);
if ( isset( $rrule[util::$BYMONTH] ) && ( $rrule[util::$BYMONTH] != 0 )) {
// set the month
$datearray[$MON] = $rrule[util::$BYMONTH] ;
}
if ( isset( $rrule[util::$BYMONTHDAY] )) { // start quickfix...
// set first found/specific day of month
$datearray[$MDAY] = ( is_array( $rrule[util::$BYMONTHDAY] ))
? reset( $rrule[util::$BYMONTHDAY] )
: $rrule[util::$BYMONTHDAY]; // end quickfix
} elseif ( isset($rrule[util::$BYDAY]) && is_array($rrule[util::$BYDAY]) ) { // update: 'isset...'
// find the Xth WKDAY in the month
// the starting point for this process is the first of the month set above
$datearray[$MDAY] = 1 ;
// turn $datearray as it is now back into a timestamp
$offsetchangetimestamp = mktime(
$datearray[$HOURS],
$datearray[$MINUTES],
$datearray[$SECONDS],
$datearray[$MON],
$datearray[$MDAY],
$datearray[util::$LCYEAR]
);
if ($rrule[util::$BYDAY][0] > 0) {
// to find Xth WKDAY in month, we find last WKDAY in month before
// we do that by finding first WKDAY in this month and going back one week
// then we add X weeks (below)
$offsetchangetimestamp = strtotime($DAYNAMES[$rrule[util::$BYDAY][util::$DAY]],$offsetchangetimestamp);
$offsetchangetimestamp = strtotime($MINUS1WEEK,$offsetchangetimestamp);
} else {
// to find Xth WKDAY before the end of the month, we find the first WKDAY in the following month
// we do that by going forward one month and going to WKDAY there
// then we subtract X weeks (below)
$offsetchangetimestamp = strtotime($PLUS1MONTH,$offsetchangetimestamp);
$offsetchangetimestamp = strtotime($DAYNAMES[$rrule[util::$BYDAY][util::$DAY]],$offsetchangetimestamp);
}
// now move forward or back the appropriate number of weeks, into the month we want
$offsetchangetimestamp = strtotime($rrule[util::$BYDAY][0] . $SP1WEEK,$offsetchangetimestamp);
$datearray = getdate($offsetchangetimestamp);
}
// convert the date parts back into a timestamp, setting the time parts according to the
// original time data which we stored
$offsetchangetimestamp = mktime(
$changetime[$HOURS],
$changetime[$MINUTES],
$changetime[$SECONDS] + $diff,
$datearray[$MON],
$datearray[$MDAY],
$datearray[util::$LCYEAR]
);
// add this change to the array of changes
$tzdates[] = [util::$LCTIMESTAMP => $offsetchangetimestamp,
$TZBEFORE => $tzbefore,
$TZAFTER => $tzafter];
// update counters (timestamp and count)
$offsetchangetimestamp = strtotime(util::$PLUS
. (( isset( $rrule[util::$INTERVAL] ) && ( $rrule[util::$INTERVAL] != 0 ))
? $rrule[util::$INTERVAL] : 1 )
. $SP1YEAR,$offsetchangetimestamp);
$count += 1 ;
}
}
}
// generate dates according to RDATE lines
while ($rdates = $vtzc->getProperty(util::$RDATE)) {
if ( is_array($rdates) ) {
foreach ( $rdates as $rdate ) {
// convert the explicit change date to a timestamp
$offsetchangetimestamp = mktime(
$rdate[util::$LCHOUR],
$rdate[util::$LCMIN],
$rdate[util::$LCSEC] + $diff,
$rdate[util::$LCMONTH],
$rdate[util::$LCDAY],
$rdate[util::$LCYEAR]
) ;
// add this change to the array of changes
$tzdates[] = [util::$LCTIMESTAMP => $offsetchangetimestamp,
$TZBEFORE => $tzbefore,
$TZAFTER => $tzafter];
}
}
}
return $tzdates;
}

View File

@@ -0,0 +1,444 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* Do NOT alter or remove the constant!!
*/
if( ! defined( 'ICALCREATOR_VERSION' ))
define( 'ICALCREATOR_VERSION', 'iCalcreator 2.24' );
/**
* iCalcreator base class
*
* Properties and methods shared by vcalendar and calendarComponents
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-01-30
*/
abstract class iCalBase {
use traits\X_PROPtrait;
/**
* @var array container for sub-components
* @access protected
*/
protected $components = [];
/**
* @var array $unparsed calendar/components in 'raw' text...
* @access protected
*/
protected $unparsed = null;
/**
* @var array $config configuration
* @access protected
*/
protected $config = [];
/**
* @var int component index
* @access protected
*/
protected $compix = 0;
/**
* @var array get multi property index
* @access protected
*/
protected $propix = [];
/**
* @var array delete multi property index
* @access protected
*/
protected $propdelix = [];
/**
* __clone method
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.12 - 2017-04-20
*/
public function __clone() {
foreach( $this->components as $cix => $component )
$this->components[$cix] = clone $component;
if( isset( $this->compix ))
$this->compix = [];
if( isset( $this->propix ))
$this->propix = [];
if( isset( $this->propdelix ))
$this->propdelix = [];
}
/**
* Return config value or info about subcomponents, false on not found
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
* @param mixed $config
* @return mixed
*/
public function getConfig( $config = false) {
static $LCORDNO = 'ordno';
static $LCTYPE = 'type';
static $LCUID = 'uid';
static $LCPROPS = 'props';
static $LCSUB = 'sub';
if( empty( $config )) {
$return = [];
$return[util::$ALLOWEMPTY] = $this->getConfig( util::$ALLOWEMPTY );
if( false !== ( $lang = $this->getConfig( util::$LANGUAGE )))
$return[util::$LANGUAGE] = $lang;
$return[util::$TZID] = $this->getConfig( util::$TZID );
$return[util::$UNIQUE_ID] = $this->getConfig( util::$UNIQUE_ID );
return $return;
}
switch( strtoupper( $config )) {
case util::$ALLOWEMPTY:
if( isset( $this->config[util::$ALLOWEMPTY] ))
return $this->config[util::$ALLOWEMPTY];
break;
case util::$COMPSINFO:
unset( $this->compix );
$info = [];
if( ! empty( $this->components )) {
foreach( $this->components as $cix => $component ) {
if( empty( $component ))
continue;
$info[$cix][$LCORDNO] = $cix + 1;
$info[$cix][$LCTYPE] = $component->objName;
$info[$cix][$LCUID] = $component->getProperty( util::$UID );
$info[$cix][$LCPROPS] = $component->getConfig( util::$PROPINFO );
$info[$cix][$LCSUB] = $component->getConfig( util::$COMPSINFO );
}
}
return $info;
break;
case util::$LANGUAGE: // get language for calendar component as defined in [RFC 1766]
if( isset( $this->config[util::$LANGUAGE] ))
return $this->config[util::$LANGUAGE];
break;
case util::$PROPINFO:
$output = [];
if( ! in_array( $this->objName, util::$LCSUBCOMPS )) {
if( empty( $this->uid ))
$this->uid = util::makeUid( $this->getConfig( util::$UNIQUE_ID ));
$output[util::$UID] = 1;
if( empty( $this->dtstamp ))
$this->dtstamp = util::makeDtstamp();
$output[util::$DTSTAMP] = 1;
}
if( ! empty( $this->summary )) $output[util::$SUMMARY] = 1;
if( ! empty( $this->description )) $output[util::$DESCRIPTION] = count( $this->description );
if( ! empty( $this->dtstart )) $output[util::$DTSTART] = 1;
if( ! empty( $this->dtend )) $output[util::$DTEND] = 1;
if( ! empty( $this->due )) $output[util::$DUE] = 1;
if( ! empty( $this->duration )) $output[util::$DURATION] = 1;
if( ! empty( $this->rrule )) $output[util::$RRULE] = count( $this->rrule );
if( ! empty( $this->rdate )) $output[util::$RDATE] = count( $this->rdate );
if( ! empty( $this->exdate )) $output[util::$EXDATE] = count( $this->exdate );
if( ! empty( $this->exrule )) $output[util::$EXRULE] = count( $this->exrule );
if( ! empty( $this->action )) $output[util::$ACTION] = 1;
if( ! empty( $this->attach )) $output[util::$ATTACH] = count( $this->attach );
if( ! empty( $this->attendee )) $output[util::$ATTENDEE] = count( $this->attendee );
if( ! empty( $this->categories )) $output[util::$CATEGORIES] = count( $this->categories );
if( ! empty( $this->class )) $output[util::$CLASS] = 1;
if( ! empty( $this->comment )) $output[util::$COMMENT] = count( $this->comment );
if( ! empty( $this->completed )) $output[util::$COMPLETED] = 1;
if( ! empty( $this->contact )) $output[util::$CONTACT] = count( $this->contact );
if( ! empty( $this->created )) $output[util::$CREATED] = 1;
if( ! empty( $this->freebusy )) $output[util::$FREEBUSY] = count( $this->freebusy );
if( ! empty( $this->geo )) $output[util::$GEO] = 1;
if( ! empty( $this->lastmodified )) $output[util::$LAST_MODIFIED] = 1;
if( ! empty( $this->location )) $output[util::$LOCATION] = 1;
if( ! empty( $this->organizer )) $output[util::$ORGANIZER] = 1;
if( ! empty( $this->percentcomplete )) $output[util::$PERCENT_COMPLETE] = 1;
if( ! empty( $this->priority )) $output[util::$PRIORITY] = 1;
if( ! empty( $this->recurrenceid )) $output[util::$RECURRENCE_ID] = 1;
if( ! empty( $this->relatedto )) $output[util::$RELATED_TO] = count( $this->relatedto );
if( ! empty( $this->repeat )) $output[util::$REPEAT] = 1;
if( ! empty( $this->requeststatus )) $output[util::$REQUEST_STATUS] = count( $this->requeststatus );
if( ! empty( $this->resources )) $output[util::$RESOURCES] = count( $this->resources );
if( ! empty( $this->sequence )) $output[util::$SEQUENCE] = 1;
if( ! empty( $this->status )) $output[util::$STATUS] = 1;
if( ! empty( $this->transp )) $output[util::$TRANSP] = 1;
if( ! empty( $this->trigger )) $output[util::$TRIGGER] = 1;
if( ! empty( $this->tzid )) $output[util::$TZID] = 1;
if( ! empty( $this->tzname )) $output[util::$TZNAME] = count( $this->tzname );
if( ! empty( $this->tzoffsetfrom )) $output[util::$TZOFFSETFROM] = 1;
if( ! empty( $this->tzoffsetto )) $output[util::$TZOFFSETTO] = 1;
if( ! empty( $this->tzurl )) $output[util::$TZURL] = 1;
if( ! empty( $this->url )) $output[util::$URL] = 1;
if( ! empty( $this->xprop )) $output[util::$X_PROP] = count( $this->xprop );
return $output;
break;
case util::$SETPROPERTYNAMES:
return array_keys( $this->getConfig( util::$PROPINFO ));
break;
case util::$TZID:
if( isset( $this->config[util::$TZID] ))
return $this->config[util::$TZID];
break;
case util::$UNIQUE_ID:
if( empty( $this->config[util::$UNIQUE_ID] ))
$this->config[util::$UNIQUE_ID] = ( isset( $_SERVER[util::$SERVER_NAME] ))
? gethostbyname( $_SERVER[util::$SERVER_NAME] )
: util::$LOCALHOST;
return $this->config[util::$UNIQUE_ID];
break;
}
return false;
}
/**
* General component config setting
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.12 - 2017-04-22
* @param mixed $config
* @param string $value
* @param bool $softUpdate
* @return bool true on success
*/
public function setConfig( $config, $value=null, $softUpdate=null ) {
if( is_null( $softUpdate ))
$softUpdate = false;
if( is_array( $config )) {
$config = array_change_key_case( $config, CASE_UPPER );
foreach( $config as $cKey => $cValue ) {
if( false === $this->setConfig( $cKey, $cValue, $softUpdate ))
return false;
}
return true;
}
$res = false;
switch( strtoupper( $config )) {
case util::$ALLOWEMPTY:
$this->config[util::$ALLOWEMPTY] = $value;
$subcfg = [util::$ALLOWEMPTY => $value];
$res = true;
break;
case util::$LANGUAGE: // set language for component as defined in [RFC 1766]
$value = trim( $value );
if( empty( $this->config[util::$LANGUAGE] ) || ! $softUpdate )
$this->config[util::$LANGUAGE] = $value;
$subcfg = [util::$LANGUAGE => $value];
$res = true;
break;
case util::$TZID:
$this->config[util::$TZID] = trim( $value );
$subcfg = [util::$TZID => trim( $value )];
$res = true;
break;
case util::$UNIQUE_ID:
$value = trim( $value );
$this->config[util::$UNIQUE_ID] = $value;
$subcfg = [util::$UNIQUE_ID => $value];
$res = 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 = $this->components[$cix]->setConfig( $cfgkey, $cfgvalue, $softUpdate );
if( ! $res )
break 2;
}
}
}
return $res;
}
/**
* Return number of components
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.5 - 2017-04-13
* @return int
*/
public function countComponents() {
return ( empty( $this->components )) ? 0 : count( $this->components );
}
/**
* Return new calendar component, included in calendar or component
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-04-13
* @param string $compType component type
* @return calendarComponent
*/
public function newComponent( $compType ) {
$config = $this->getConfig();
$ix = ( empty( $this->components ))
? 0
: key( array_slice( $this->components, -1, 1, TRUE )) + 1;
switch( strtolower( $compType )) {
case util::$LCVALARM :
$this->components[$ix] = new valarm( $config );
break;
case util::$LCVEVENT :
$this->components[$ix] = new vevent( $config );
break;
case util::$LCVTODO :
$this->components[$ix] = new vtodo( $config );
break;
case util::$LCVJOURNAL :
$this->components[$ix] = new vjournal( $config );
break;
case util::$LCVFREEBUSY :
$this->components[$ix] = new vfreebusy( $config );
break;
case util::$LCVTIMEZONE :
array_unshift( $this->components, new vtimezone( $config ));
$ix = 0;
break;
case util::$LCSTANDARD :
array_unshift( $this->components, new vtimezone( util::$LCSTANDARD, $config ));
$ix = 0;
break;
case util::$LCDAYLIGHT :
$this->components[$ix] = new vtimezone( util::$LCDAYLIGHT, $config );
break;
default:
return false;
}
return $this->components[$ix];
}
/**
* Delete calendar subcomponent from component container
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.12 - 2017-05-06
* @param mixed $arg1 ordno / component type / component uid
* @param mixed $arg2 ordno if arg1 = component type
* @return bool true on success
*/
public function deleteComponent( $arg1, $arg2=false ) {
static $INDEX = 'INDEX';
if( ! isset( $this->components ))
return false;
$argType = $index = null;
if ( ctype_digit( (string) $arg1 )) {
$argType = $INDEX;
$index = (int) $arg1 - 1;
}
elseif( in_array( strtolower( $arg1 ), util::$ALLCOMPS )) {
$argType = strtolower( $arg1 );
$index = ( ! empty( $arg2 ) && ctype_digit( (string) $arg2 )) ? (( int ) $arg2 - 1 ) : 0;
}
$cix2dC = 0;
$remove = false;
foreach( $this->components as $cix => $component ) {
if(( $INDEX == $argType ) && ( $index == $cix )) {
unset( $this->components[$cix] );
$remove = true;
break;
}
elseif( $argType == $component->objName ) {
if( $index == $cix2dC ) {
unset( $this->components[$cix] );
$remove = true;
break;
}
$cix2dC++;
}
elseif( ! $argType &&
( $arg1 == $component->getProperty( util::$UID ))) {
unset( $this->components[$cix] );
$remove = true;
break;
}
} // end foreach( $this->components as $cix => $component )
if( $remove ) {
$this->components = array_filter( $this->components );
return true;
}
return false;
}
/**
* Add calendar component as subcomponent to container for subcomponents
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.2 - 2015-03-18
* @param object $component calendarComponent
* @param mixed $arg1 ordno/component type/ component uid
* @param mixed $arg2 ordno if arg1 = component type
* @return bool
*/
public function setComponent( $component, $arg1=false, $arg2=false ) {
static $INDEX = 'INDEX';
if( ! isset( $this->components ))
return false;
$component->setConfig( $this->getConfig(), false, true );
if( ! in_array( strtolower( $component->objName ), util::$LCSUBCOMPS )) {
/* make sure dtstamp and uid is set */
$component->getProperty( util::$DTSTAMP );
$component->getProperty( util::$UID );
}
if( ! $arg1 ) { // plain insert, last in chain
$this->components[] = clone $component;
return true;
}
$argType = $index = null;
if ( ctype_digit( (string) $arg1 )) { // index insert/replace
$argType = $INDEX;
$index = (int) $arg1 - 1;
}
elseif( in_array( strtolower( $arg1 ), util::$MCOMPS )) {
$argType = strtolower( $arg1 );
$index = ( ctype_digit( (string) $arg2 )) ? ((int) $arg2) - 1 : 0;
}
// else if arg1 is set, arg1 must be an UID
$cix2sC = 0;
foreach( $this->components as $cix => $component2 ) {
if( empty( $component2 ))
continue;
if(( $INDEX == $argType ) && ( $index == $cix )) { // index insert/replace
$this->components[$cix] = clone $component;
return true;
}
elseif( $argType == $component2->objName ) { // component Type index insert/replace
if( $index == $cix2sC ) {
$this->components[$cix] = clone $component;
return true;
}
$cix2sC++;
}
elseif( ! $argType && ( $arg1 == $component2->getProperty( util::$UID ))) {
$this->components[$cix] = clone $component; // UID insert/replace
return true;
}
}
/* arg1=index and not found.. . insert at index .. .*/
if( $INDEX == $argType ) {
$this->components[$index] = clone $component;
ksort( $this->components, SORT_NUMERIC );
}
else /* not found.. . insert last in chain anyway .. .*/
$this->components[] = clone $component;
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,142 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator::selectComponent dateTime support class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-02-07
*/
class iCaldateTime extends \DateTime {
/**
* @var string default date[-time] format
*/
public $dateFormat = 'Y-m-d H:i:s e';
/**
* @var string default object instance date[-time] 'key'
*/
public $key = null;
/**
* @var array date[-time] origin
*/
public $SCbools = [];
/**
* Return time (His) array
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-02-07
* @return array
*/
public function getTime() {
static $H_I_S = 'H:i:s';
return explode( util::$COLON, $this->format( $H_I_S ));
}
/**
* Return the timezone name
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.21.7 - 2015-03-07
* @return string
*/
public function getTimezoneName() {
$tz = $this->getTimezone();
return $tz->getName();
}
/**
* Return formatted date
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.21.7 - 2015-03-07
* @param string $format
* @return string
*/
public function format( $format=null ) {
if( empty( $format ) && isset( $this->dateFormat ))
$format = $this->dateFormat;
return parent::format( $format );
}
/**
* Return iCaldateTime object instance based on date array and timezone(s)
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-03-04
* @param array $date
* @param array $params
* @param array $tz
* @param string $dtstartTz
* @return object
* @static
*/
public static function factory( array $date, $params=null, $tz=null, $dtstartTz=null ) {
static $YMDHIS = 'YmdHis';
static $YMD = 'Ymd';
static $Y_M_D = 'Y-m-d';
if( isset( $params[util::$TZID] ) && ! empty( $params[util::$TZID] ))
$tz = ( util::$Z == $params[util::$TZID] ) ? util::$UTC : $params[util::$TZID];
elseif( isset( $tz[util::$LCtz] ) && ! empty( $tz[util::$LCtz] ))
$tz = ( util::$Z == $tz[util::$LCtz] ) ? util::$UTC : $tz[util::$LCtz];
else
$tz = date_default_timezone_get();
$strdate = sprintf( util::$YMD, (int) $date[util::$LCYEAR],
(int) $date[util::$LCMONTH],
(int) $date[util::$LCDAY] );
if( isset( $date[util::$LCHOUR] ))
$strdate .= util::$T . sprintf( util::$HIS, (int) $date[util::$LCHOUR],
(int) $date[util::$LCMIN],
(int) $date[util::$LCSEC] );
try {
$timezone = new \DateTimeZone( $tz );
$iCaldateTime = new iCaldateTime( $strdate, $timezone );
}
catch( \Exception $e ) {
$iCaldateTime = new iCaldateTime( $strdate );
}
if( ! empty( $dtstartTz )) {
if( util::$Z == $dtstartTz )
$dtstartTz = util::$UTC;
if( $dtstartTz != $iCaldateTime->getTimezoneName()) { // set the same timezone as dtstart
try {
$timezone = new \DateTimeZone( $dtstartTz );
$iCaldateTime->setTimezone( $timezone );
}
catch( \Exception $e ) {} // ??
}
}
if( util::isParamsValueSet( [util::$LCparams => $params], util::$DATE )) {
$iCaldateTime->dateFormat = $Y_M_D;
$iCaldateTime->key = $iCaldateTime->format( $YMD );
}
else
$iCaldateTime->key = $iCaldateTime->format( $YMDHIS );
return $iCaldateTime;
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator vCard support class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-01-30
*/
class iCalvCard {
/**
* Convert single ATTENDEE, CONTACT or ORGANIZER (in email format) to vCard
*
* Returns vCard/true or if directory (if set) or file write is unvalid, false
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.8 - 2017-04-17
* @param string $email
* @param string $version vCard version (default 2.1)
* @param string $directory where to save vCards (default false)
* @param string $ext vCard file extension (default 'vcf')
* @return mixed bool true (if directory set and save ok), string (if not), false on error
* @static
*/
public static function iCal2vCard( $email, $version=null, $directory=null, $ext=null ) {
static $UCMAILTOCOLON = 'MAILTO:';
static $CRLF = "\r\n";
static $FMTFN = "FN:%s\r\n";
static $FMTN = 'N:%s';
static $V2_1 = '2.1';
static $AT = '@';
static $V4_0 = '4.0';
static $FMTEMAIL = "EMAIL:%s\r\n";
static $BEGINVCARD = "BEGIN:VCARD\r\n";
static $FMTVERSION = "VERSION:%s\r\n";
static $FMTPRODID = "PRODID:-//kigkonsult.se %s\r\n";
static $FMTREV = "REV:%s\r\n";
static $YMDTHISZ = 'Ymd\THis\Z';
static $ENDVCARD = "END:VCARD\r\n";
static $EXPR = '/[^a-z0-9.]/i';
static $FMTFNAME = '%s%s%s.%s';
static $EXTVCF = 'vcf';
if( empty( $version ))
$version = $V2_1;
if( false === ( $pos = strpos( $email, $AT )))
return false;
if( $directory ) {
if( DIRECTORY_SEPARATOR != substr( $directory, ( 0 - strlen( DIRECTORY_SEPARATOR ))))
$directory .= DIRECTORY_SEPARATOR;
if( ! is_dir( $directory ) || ! is_writable( $directory ))
return false;
}
/* prepare vCard */
$email = str_replace( $UCMAILTOCOLON, null, $email );
$name = $person = substr( $email, 0, $pos );
if( ctype_upper( $name ) || ctype_lower( $name ))
$name = [$name];
else {
if( false !== ( $pos = strpos( $name, util::$DOT ))) {
$name = explode( util::$DOT, $name );
foreach( $name as $k => $part )
$name[$k] = ucfirst( $part );
}
else { // split camelCase
$chars = $name;
$name = [$chars[0]];
$k = 0;
$len = strlen( $chars );
$x = 1;
while( $x < $len ) {
if( ctype_upper( $chars[$x] )) {
$k += 1;
$name[$k] = null;
}
$name[$k] .= $chars[$x];
$x++;
}
}
}
$FN = sprintf( $FMTFN, implode( utiL::$SP1, $name ));
$name = array_reverse( $name );
$N = sprintf( $FMTN, array_shift( $name ));
$scCnt = 0;
while( NULL != ( $part = array_shift( $name ))) {
if(( $V4_0 != $version ) || ( 4 > $scCnt ))
$scCnt += 1;
$N .= util::$SEMIC . $part;
}
while(( $V4_0 == $version ) && ( 4 > $scCnt )) {
$N .= util::$SEMIC;
$scCnt += 1;
}
$N .= $CRLF;
$EMAIL = sprintf( $FMTEMAIL, $email );
/* create vCard */
$vCard = $BEGINVCARD;
$vCard .= sprintf( $FMTVERSION, $version );
$vCard .= sprintf( $FMTPRODID, ICALCREATOR_VERSION );
$vCard .= $N;
$vCard .= $FN;
$vCard .= $EMAIL;
$vCard .= sprintf( $FMTREV, gmdate( $YMDTHISZ ));
$vCard .= $ENDVCARD;
/* save each vCard as (unique) single file */
if( ! empty( $directory )) {
if( empty( $ext ))
$ext = $EXTVCF;
$fprfx = $directory.preg_replace( $EXPR, null, $email );
$cnt = 1;
$dbl = null;
$fName = sprintf( $FMTFNAME, $fprfx, $dbl, $ext );
while( is_file ( $fName )) {
$cnt += 1;
$dbl = $cnt;
$fName = sprintf( $FMTFNAME, $fprfx, $dbl, $ext );
}
if( false === file_put_contents( $fName, $vCard ))
return false;
return true;
}
/* return vCard */
else
return $vCard;
}
/**
* Convert ATTENDEEs, CONTACTs and ORGANIZERs (in email format) to vCards
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-02-20
* @param vcalendar $calendar iCalcreator vcalendar instance
* @param string $version vCard version (default 2.1)
* @param string $directory where to save vCards (default false)
* @param string $ext vCard file extension (default 'vcf')
* @return mixed bool true (if directory set and save ok), string (if not), false on error
* @static
*/
public static function iCal2vCards( vcalendar $calendar, $version=null, $directory=null, $ext=null ) {
static $vCardP = ['ATTENDEE', 'CONTACT', 'ORGANIZER'];
static $AT = '@';
static $UCMAILTOCOLON = 'MAILTO:';
$hits = [];
foreach( $vCardP as $prop ) {
$hits2 = $calendar->getProperty( $prop );
foreach( $hits2 as $propValue => $occCnt ) {
if( false === ( $pos = strpos( $propValue, $AT )))
continue;
$propValue = str_replace( $UCMAILTOCOLON, null, $propValue );
if( isset( $hits[$propValue] ))
$hits[$propValue] += $occCnt;
else
$hits[$propValue] = $occCnt;
}
}
if( empty( $hits ))
return false;
ksort( $hits );
$output = null;
foreach( $hits as $email => $skip ) {
$res = self::iCal2vCard( $email, $version, $directory, $ext );
if( ! empty( $directory ) && ! $res )
return false;
elseif( ! $res )
return $res;
else
$output .= $res;
}
if( $directory )
return true;
return ( empty( $output )) ? false : $output;
}
}

View File

@@ -0,0 +1,438 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator timezone management class
*
* Manages loosely coupled iCalcreator vcalendar (timezone) functions
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-04-07
*/
class timezoneHandler {
private static $FMTTIMESTAMP = '@%s';
private static $OFFSET = 'offset';
private static $TIME = 'time';
/**
* Create a calendar timezone and standard/daylight components
*
* Result when 'Europe/Stockholm' and no from/to arguments is used as timezone:
* BEGIN:VTIMEZONE
* TZID:Europe/Stockholm
* BEGIN:STANDARD
* DTSTART:20101031T020000
* TZOFFSETFROM:+0200
* TZOFFSETTO:+0100
* TZNAME:CET
* END:STANDARD
* BEGIN:DAYLIGHT
* DTSTART:20100328T030000
* TZOFFSETFROM:+0100
* TZOFFSETTO:+0200
* TZNAME:CEST
* END:DAYLIGHT
* END:VTIMEZONE
*
* Generates components for all transitions in a date range,
* based on contribution by Yitzchok Lavi <icalcreator@onebigsystem.com>
* Additional changes jpirkey
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-06-26
* @param vcalendar $calendar iCalcreator calendar instance
* @param string $timezone valid timezone avveptable by PHP5 DateTimeZone
* @param array $xProp *[x-propName => x-propValue]
* @param int $from unix timestamp
* @param int $to unix timestamp
* @return bool
* @static
*/
public static function createTimezone( vcalendar $calendar, $timezone, $xProp=[], $from=null, $to=null ) {
static $Y = 'Y ';
static $YMD = 'Ymd';
static $T000000 = 'T000000';
static $MINUS7MONTH = '-7 month';
static $YMD2 = 'Y-m-d';
static $T235959 = 'T235959';
static $PLUS18MONTH = '+18 month';
static $TS = 'ts';
static $YMDHIS3 = 'Y-m-d-H-i-s';
static $SECONDS = 'seconds';
static $ABBR = 'abbr';
static $ISDST = 'isdst';
static $NOW = 'now';
static $YMDTHISO = 'Y-m-d\TH:i:s O';
if( empty( $timezone ))
return false;
if( ! empty( $from ) && ! is_int( $from ))
return false;
if( ! empty( $to ) && ! is_int( $to ))
return false;
try {
$newTz = new \DateTimeZone( $timezone );
$utcTz = new \DateTimeZone( util::$UTC );
}
catch( \Exception $e ) {
return false;
}
if( empty( $from ) || empty( $to )) {
$dates = array_keys( $calendar->getProperty( util::$DTSTART ));
if( empty( $dates ))
$dates = [date( $YMD )];
}
if( ! empty( $from )) {
try {
$timestamp = sprintf( self::$FMTTIMESTAMP, $from );
$dateFrom = new \DateTime( $timestamp ); // set lowest date (UTC)
}
catch( \Exception $e ) {
return false;
}
}
else {
try {
$from = reset( $dates ); // set lowest date to the lowest dtstart date
$dateFrom = new \DateTime( $from . $T000000, $newTz );
$dateFrom->modify( $MINUS7MONTH ); // set $dateFrom to seven month before the lowest date
$dateFrom->setTimezone( $utcTz ); // convert local date to UTC
}
catch( \Exception $e ) {
return false;
}
}
$dateFromYmd = $dateFrom->format( $YMD2 );
if( ! empty( $to )) {
try {
$timestamp = sprintf( self::$FMTTIMESTAMP, $to );
$dateTo = new \DateTime( $timestamp ); // set end date (UTC)
}
catch( \Exception $e ) {
return false;
}
}
else {
try {
$to = end( $dates ); // set highest date to the highest dtstart date
$dateTo = new \DateTime( $to . $T235959, $newTz );
}
catch( \Exception $e ) {
return false;
}
$dateTo->modify( $PLUS18MONTH ); // set $dateTo to 18 month after the highest date
$dateTo->setTimezone( $utcTz ); // convert local date to UTC
}
$dateToYmd = $dateTo->format( $YMD2 );
$transTemp = [];
$prevOffsetfrom = 0;
$stdIx = $dlghtIx = null;
$prevTrans = false;
$transitions = $newTz->getTransitions();
foreach( $transitions as $tix => $trans ) { // all transitions in date-time order!!
if( 0 > (int) date( $Y, $trans[$TS] )) { // skip negative year... but save offset
$prevOffsetfrom = $trans[self::$OFFSET]; // previous trans offset will be 'next' trans offsetFrom
continue;
}
try {
$timestamp = sprintf( self::$FMTTIMESTAMP, $trans[$TS] );
$date = new \DateTime( $timestamp ); // set transition date (UTC)
}
catch( \Exception $e ) {
return false;
}
$transDateYmd = $date->format( $YMD2 );
if( $transDateYmd < $dateFromYmd ) {
$prevOffsetfrom = $trans[self::$OFFSET]; // previous trans offset will be 'next' trans offsetFrom
$prevTrans = $trans; // we save it in case we don't find any that match
$prevTrans[util::$TZOFFSETFROM] = ( 0 < $tix ) ? $transitions[$tix-1][self::$OFFSET] : 0;
continue;
}
if( $transDateYmd > $dateToYmd )
break; // loop always (?) breaks here
if( ! empty( $prevOffsetfrom ) || ( 0 == $prevOffsetfrom )) {
$trans[util::$TZOFFSETFROM] = $prevOffsetfrom; // i.e. set previous offsetto as offsetFrom
$date->modify( $trans[util::$TZOFFSETFROM] . $SECONDS ); // convert utc date to local date
$d = explode( util::$MINUS, $date->format( $YMDHIS3 ));
$trans[self::$TIME] = [util::$LCYEAR => (int) $d[0], // set date to array
util::$LCMONTH => (int) $d[1], // to ease up dtstart and (opt) rdate setting
util::$LCDAY => (int) $d[2],
util::$LCHOUR => (int) $d[3],
util::$LCMIN => (int) $d[4],
util::$LCSEC => (int) $d[5]];
}
$prevOffsetfrom = $trans[self::$OFFSET];
if( true !== $trans[$ISDST] ) { // standard timezone
if( ! empty( $stdIx ) && isset( $transTemp[$stdIx][util::$TZOFFSETFROM] ) &&
( $transTemp[$stdIx][$ABBR] == $trans[$ABBR] ) &&
( $transTemp[$stdIx][util::$TZOFFSETFROM] == $trans[util::$TZOFFSETFROM] ) &&
( $transTemp[$stdIx][self::$OFFSET] == $trans[self::$OFFSET] )) {
$transTemp[$stdIx][util::$RDATE][] = $trans[self::$TIME];
continue; // check for any repeating rdate's (in order)
}
$stdIx = $tix;
} // end standard timezone
else { // daylight timezone
if( ! empty( $dlghtIx ) && isset( $transTemp[$dlghtIx][util::$TZOFFSETFROM] ) &&
( $transTemp[$dlghtIx][$ABBR] == $trans[$ABBR] ) &&
( $transTemp[$dlghtIx][util::$TZOFFSETFROM] == $trans[util::$TZOFFSETFROM] ) &&
( $transTemp[$dlghtIx][self::$OFFSET] == $trans[self::$OFFSET] )) {
$transTemp[$dlghtIx][util::$RDATE][] = $trans[self::$TIME];
continue; // check for any repeating rdate's (in order)
}
$dlghtIx = $tix;
} // end daylight timezone
$transTemp[$tix] = $trans;
} // end foreach( $transitions as $tix => $trans )
$timezoneComp = $calendar->newVtimezone();
$timezoneComp->setproperty( util::$TZID, $timezone );
if( ! empty( $xProp )) {
foreach( $xProp as $xPropName => $xPropValue )
if( util::isXprefixed( $xPropName ))
$timezoneComp->setproperty( $xPropName, $xPropValue );
}
if( empty( $transTemp )) { // if no match is found
if( $prevTrans ) { // we use the last transition (before startdate) for the tz info
try {
$timestamp = sprintf( self::$FMTTIMESTAMP, $prevTrans[$TS] );
$date = new \DateTime( $timestamp ); // set transition date (UTC)
}
catch( \Exception $e ) {
return false;
}
$date->modify( $prevTrans[util::$TZOFFSETFROM] . $SECONDS );// convert utc date to local date
$d = explode( util::$MINUS, $date->format( $YMDHIS3 )); // set arr-date to ease up dtstart setting
$prevTrans[self::$TIME] = [util::$LCYEAR => (int) $d[0],
util::$LCMONTH => (int) $d[1],
util::$LCDAY => (int) $d[2],
util::$LCHOUR => (int) $d[3],
util::$LCMIN => (int) $d[4],
util::$LCSEC => (int) $d[5]];
$transTemp[0] = $prevTrans;
} // end if( $prevTrans )
else { // or we use the timezone identifier to BUILD the standard tz info (?)
try {
$date = new \DateTime( $NOW, $newTz );
}
catch( \Exception $e ) {
return false;
}
$transTemp[0] = [self::$TIME => $date->format( $YMDTHISO ),
self::$OFFSET => $date->format( util::$Z ),
util::$TZOFFSETFROM => $date->format( util::$Z ),
$ISDST => false];
}
} // end if( empty( $transTemp ))
foreach( $transTemp as $tix => $trans ) { // create standard/daylight subcomponents
$subComp = ( true !== $trans[$ISDST] )
? $timezoneComp->newStandard()
: $timezoneComp->newDaylight();
$subComp->setProperty( util::$DTSTART, $trans[self::$TIME] );
// $subComp->setProperty( 'x-utc-timestamp', $tix.' : '.$trans[$TS] ); // test ###
if( ! empty( $trans[$ABBR] ))
$subComp->setProperty( util::$TZNAME, $trans[$ABBR] );
if( isset( $trans[util::$TZOFFSETFROM] ))
$subComp->setProperty( util::$TZOFFSETFROM, self::offsetSec2His( $trans[util::$TZOFFSETFROM] ));
$subComp->setProperty( util::$TZOFFSETTO, self::offsetSec2His( $trans[self::$OFFSET] ));
if( isset( $trans[util::$RDATE] ))
$subComp->setProperty( util::$RDATE, $trans[util::$RDATE] );
}
return true;
}
/**
* Return iCal offset [-/+]hhmm[ss] (string) from UTC offset seconds
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
* @param string $seconds
* @return string
* @static
*/
public static function offsetSec2His( $seconds ) {
static $FMT = '%02d';
switch( substr( $seconds, 0, 1 )) {
case util::$MINUS :
$output = util::$MINUS;
$seconds = substr( $seconds, 1 );
break;
case util::$PLUS :
$output = util::$PLUS;
$seconds = substr( $seconds, 1 );
break;
default :
$output = util::$PLUS;
break;
}
$output .= sprintf( $FMT, ((int) floor( $seconds / 3600 ))); // hour
$seconds = $seconds % 3600;
$output .= sprintf( $FMT, ((int) floor( $seconds / 60 ))); // min
$seconds = $seconds % 60;
if( 0 < $seconds )
$output .= sprintf( $FMT, $seconds ); // sec
return $output;
}
/**
* Very basic conversion of a MS timezone to a PHP5 valid (Date-)timezone
* matching (MS) UCT offset and time zone descriptors
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.8 - 2017-04-17
* @param string $timezone to convert
* @return bool
* @static
*/
public static function ms2phpTZ( & $timezone ) {
static $REPL1 = ['GMT', 'gmt', 'utc'];
static $REPL2 = ['(', ')', '&', ',', ' '];
static $PUTC = '(UTC';
static $ENDP = ')';
static $TIMEZONE_ID = 'timezone_id';
if( empty( $timezone ))
return false;
$search = str_replace( util::$QQ, null, $timezone );
$search = str_replace( $REPL1, util::$UTC, $search );
if( $PUTC != substr( $search, 0, 4 ))
return false;
if( false === ( $pos = strpos( $search, $ENDP )))
return false;
$searchOffset = substr( $search, 4, ( $pos - 4 ));
$searchOffset = util::tz2offset( str_replace( util::$COLON,
null,
$searchOffset ));
while( util::$SP1 == $search[($pos+1)] )
$pos += 1;
$searchText = trim( str_replace( $REPL2,
util::$SP1,
substr( $search, ( $pos + 1 ))));
$searchWords = explode( util::$SP1, $searchText );
try {
$timezoneAbbreviations = \DateTimeZone::listAbbreviations();
}
catch( \Exception $e ) {
return false;
}
$hits = [];
foreach( $timezoneAbbreviations as $name => $transitions ) {
foreach( $transitions as $cnt => $transition ) {
if( empty( $transition[self::$OFFSET] ) ||
empty( $transition[$TIMEZONE_ID] ) ||
( $transition[self::$OFFSET] != $searchOffset ))
continue;
$cWords = explode( util::$L, $transition[$TIMEZONE_ID] );
$cPrio = $hitCnt = $rank = 0;
foreach( $cWords as $cWord ) {
if( empty( $cWord ))
continue;
$cPrio += 1;
$sPrio = 0;
foreach( $searchWords as $sWord ) {
if( empty( $sWord ) || ( self::$TIME == strtolower( $sWord )))
continue;
$sPrio += 1;
if( strtolower( $cWord ) == strtolower( $sWord )) {
$hitCnt += 1;
$rank += ( $cPrio + $sPrio );
}
else
$rank += 10;
}
}
if( 0 < $hitCnt ) {
$hits[$rank][] = $transition[$TIMEZONE_ID];
}
} // end foreach( $transitions as $cnt => $transition )
} // end foreach( $timezoneAbbreviations as $name => $transitions )
if( empty( $hits ))
return false;
ksort( $hits );
foreach( $hits as $rank => $tzs ) {
if( ! empty( $tzs )) {
$timezone = reset( $tzs );
return true;
}
}
return false;
}
/**
* Transforms a dateTime from a timezone to another
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-04
* @param mixed $date date to alter
* @param string $tzFrom PHP valid 'from' timezone
* @param string $tzTo PHP valid 'to' timezone, default util::$UTC
* @param string $format date output format, default 'Ymd\THis'
* @return bool true on success, false on error
* @static
*/
public static function transformDateTime( & $date, $tzFrom, $tzTo=null, $format=null ) {
static $YMDTHIS = 'Ymd\THis';
if( is_null( $tzTo ))
$tzTo = util::$UTC;
elseif( util::$Z == $tzTo )
$tzTo = util::$UTC;
if( is_null( $format ))
$format = $YMDTHIS;
if( is_array( $date ) && isset( $date[util::$LCTIMESTAMP] )) {
try {
$timestamp = sprintf( self::$FMTTIMESTAMP, $date[util::$LCTIMESTAMP] );
$d = new \DateTime( $timestamp ); // set UTC date
$newTz = new \DateTimeZone( $tzFrom );
$d->setTimezone( $newTz ); // convert to 'from' date
}
catch( \Exception $e ) {
return false;
}
}
else {
if( util::isArrayDate( $date )) {
if( isset( $date[util::$LCtz] ))
unset( $date[util::$LCtz] );
$date = util::date2strdate( util::chkDateArr( $date ));
}
if( util::$Z == substr( $date, -1 ))
$date = substr( $date, 0, ( strlen( $date ) - 2 ));
try {
$newTz = new \DateTimeZone( $tzFrom );
$d = new \DateTime( $date, $newTz );
}
catch( \Exception $e ) {
return false;
}
}
try {
$newTz = new \DateTimeZone( $tzTo );
$d->setTimezone( $newTz );
}
catch( \Exception $e ) {
return false;
}
$date = $d->format( $format );
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* ACTION property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait ACTIONtrait {
/**
* @var array component property ACTION value
* @access protected
*/
protected $action = null;
/**
* Return formatted output for calendar component property action
*
* @return string
*/
public function createAction() {
if( empty( $this->action ))
return null;
if( empty( $this->action[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$ACTION ) : null;
return util::createElement( util::$ACTION,
util::createParams( $this->action[util::$LCparams] ),
$this->action[util::$LCvalue] );
}
/**
* Set calendar component property action
*
* @param string $value "AUDIO" / "DISPLAY" / "EMAIL" / "PROCEDURE" / iana-token / x-name
* @param mixed $params
* @return bool
*/
public function setAction( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->action = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* ATTACH property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait ATTACHtrait {
/**
* @var array component property ATTACH value
* @access protected
*/
protected $attach = null;
/**
* Return formatted output for calendar component property attach
*
* @return string
*/
public function createAttach() {
if( empty( $this->attach ))
return null;
$output = null;
foreach( $this->attach as $aix => $attachPart ) {
if( ! empty( $attachPart[util::$LCvalue] )) {
$output .= util::createElement( util::$ATTACH,
util::createParams( $attachPart[util::$LCparams] ),
$attachPart[util::$LCvalue] );
}
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$ATTACH );
}
return $output;
}
/**
* Set calendar component property attach
*
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setAttach( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->attach,
$value,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilAttendee;
/**
* ATTENDEE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait ATTENDEEtrait {
/**
* @var array component property ATTENDEE value
* @access protected
*/
protected $attendee = null;
/**
* Return formatted output for calendar component property attendee
*
* @return string
*/
public function createAttendee() {
if( empty( $this->attendee ))
return null;
return utilAttendee::formatAttendee( $this->attendee,
$this->getConfig( util::$ALLOWEMPTY ));
}
/**
* Set calendar component property attach
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setAttendee( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->attendee,
utilAttendee::calAddressCheck( $value, false ),
utilAttendee::prepAttendeeParams( $params,
$this->objName,
$this->getConfig( util::$LANGUAGE )),
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* CALSCALE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait CALSCALEtrait {
/**
* @var string calendar property CALSCALE
* @access protected
*/
protected $calscale = null;
/**
* Return formatted output for calendar property calscale
*
* @return string
*/
public function createCalscale() {
return ( empty( $this->calscale ))
? null
: sprintf( self::$FMTICAL, util::$CALSCALE,
$this->calscale );
}
/**
* Set calendar property calscale
*
* @param string $value
*/
public function setCalscale( $value ) {
if( empty( $value ))
return false;
$this->calscale = $value;
return true;
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* CATEGORIES property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait CATEGORIEStrait {
/**
* @var array component property CATEGORIES value
* @access protected
*/
protected $categories = null;
/**
* Return formatted output for calendar component property categories
*
* @return string
*/
public function createCategories() {
if( empty( $this->categories ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->categories as $cx => $category ) {
if( empty( $category[util::$LCvalue] )) {
if ( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$CATEGORIES );
continue;
}
if( is_array( $category[util::$LCvalue] )) {
foreach( $category[util::$LCvalue] as $cix => $cValue )
$category[util::$LCvalue][$cix] = util::strrep( $cValue );
$content = implode( util::$COMMA, $category[util::$LCvalue] );
}
else
$content = util::strrep( $category[util::$LCvalue] );
$output .= util::createElement( util::$CATEGORIES,
util::createParams( $category[util::$LCparams],
[util::$LANGUAGE],
$lang ),
$content );
}
return $output;
}
/**
* Set calendar component property categories
*
* @param mixed $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setCategories( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->categories,
$value,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* CLASS property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait CLASStrait {
/**
* @var string component property CLASS value
* @access protected
*/
protected $class = null;
/**
* Return formatted output for calendar component property class
*
* @return string
*/
public function createClass() {
if( empty( $this->class ))
return null;
if( empty( $this->class[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$CLASS ) : null;
return util::createElement( util::$CLASS,
util::createParams( $this->class[util::$LCparams] ),
$this->class[util::$LCvalue] );
}
/**
* Set calendar component property class
*
* @param string $value "PUBLIC" / "PRIVATE" / "CONFIDENTIAL" / iana-token / x-name
* @param array $params
* @return bool
*/
public function setClass( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->class = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* COMMENT property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait COMMENTtrait {
/**
* @var array component property COMMENT value
* @access protected
*/
protected $comment = null;
/**
* Return formatted output for calendar component property comment
*
* @return string
*/
public function createComment() {
if( empty( $this->comment ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->comment as $cx => $commentPart ) {
if( empty( $commentPart[util::$LCvalue] )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$COMMENT );
continue;
}
$output .= util::createElement( util::$COMMENT,
util::createParams( $commentPart[util::$LCparams],
util::$ALTRPLANGARR,
$lang ),
util::strrep( $commentPart[util::$LCvalue] ));
}
return $output;
}
/**
* Set calendar component property comment
*
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setComment( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->comment,
$value,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* COMPLETED property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-19
*/
trait COMPLETEDtrait {
/**
* @var array component property COMPLETED value
* @access protected
*/
protected $completed = null;
/**
* Return formatted output for calendar component property completed
*
* @return string
*/
public function createCompleted( ) {
if( empty( $this->completed ))
return null;
if( util::hasNodate( $this->completed ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$COMPLETED ) : null;
return util::createElement( util::$COMPLETED,
util::createParams( $this->completed[util::$LCparams] ),
util::date2strdate( $this->completed[util::$LCvalue], 7 ));
}
/**
* Set calendar component property completed
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param array $params
* @return bool
*/
public function setCompleted( $year, $month=null, $day=null, $hour=null, $min=null, $sec=null, $params=null ) {
if( empty( $year )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->completed = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $params )];
return true;
}
else
return false;
}
$this->completed = util::setDate2( $year, $month, $day, $hour, $min, $sec, $params );
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* CONTACT property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait CONTACTtrait {
/**
* @var array component property CONTACT value
* @access protected
*/
protected $contact = null;
/**
* Return formatted output for calendar component property contact
*
* @return string
*/
public function createContact() {
if( empty( $this->contact ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->contact as $cx => $contact ) {
if( ! empty( $contact[util::$LCvalue] ))
$output .= util::createElement( util::$CONTACT,
util::createParams( $contact[util::$LCparams],
util::$ALTRPLANGARR,
$lang ),
util::strrep( $contact[util::$LCvalue] ));
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$CONTACT );
}
return $output;
}
/**
* Set calendar component property contact
*
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setContact( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->contact,
util::trimTrailNL( $value ),
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* CREATED property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait CREATEDtrait {
/**
* @var array component property CREATED value
* @access protected
*/
protected $created = null;
/**
* Return formatted output for calendar component property created
*
* @return string
*/
public function createCreated() {
if( empty( $this->created ))
return null;
return util::createElement( util::$CREATED,
util::createParams( $this->created[util::$LCparams] ),
util::date2strdate( $this->created[util::$LCvalue], 7 ));
}
/**
* Set calendar component property created
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param mixed $params
* @return bool
*/
public function setCreated( $year=null, $month=null, $day=null, $hour=null, $min=null, $sec=null, $params=null ) {
static $YMDTHIS = 'Ymd\THis';
if( empty( $year ))
$year = gmdate( $YMDTHIS );
$this->created = util::setDate2( $year, $month, $day, $hour, $min, $sec, $params );
return true;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DESCRIPTION property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait DESCRIPTIONtrait {
/**
* @var array component property DESCRIPTION value
* @access protected
*/
protected $description = null;
/**
* Return formatted output for calendar component property description
*
* @return string
*/
public function createDescription() {
if( empty( $this->description ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->description as $dx => $description ) {
if( ! empty( $description[util::$LCvalue] ))
$output .= util::createElement( util::$DESCRIPTION,
util::createParams( $description[util::$LCparams],
util::$ALTRPLANGARR,
$lang ),
util::strrep( $description[util::$LCvalue] ));
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$DESCRIPTION );
}
return $output;
}
/**
* Set calendar component property description
*
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setDescription( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
if( util::$LCVJOURNAL != $this->objName )
$index = 1;
util::setMval( $this->description,
$value,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DTEND property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait DTENDtrait {
/**
* @var array component property DTEND value
* @access protected
*/
protected $dtend = null;
/**
* Return formatted output for calendar component property dtend
*
* @return string
*/
public function createDtend() {
if( empty( $this->dtend ))
return null;
if( util::hasNodate( $this->dtend ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$DTEND ) : null;
return util::createElement( util::$DTEND,
util::createParams( $this->dtend[util::$LCparams] ),
util::date2strdate( $this->dtend[util::$LCvalue],
util::isParamsValueSet( $this->dtend, util::$DATE ) ? 3 : null ));
}
/**
* Set calendar component property dtend
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param string $tz
* @param array $params
* @return bool
*/
public function setDtend( $year, $month=null, $day=null, $hour=null, $min=null, $sec=null, $tz=null, $params=null ) {
if( empty( $year )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->dtend = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $params )];
return true;
}
else
return false;
}
if( false === ( $tzid = $this->getConfig( util::$TZID )))
$tzid = null;
$this->dtend = util::setDate( $year, $month, $day, $hour, $min, $sec, $tz,
$params, null, null, $tzid );
return true;
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DTSTAMP property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait DTSTAMPtrait {
/**
* @var array component property DTSTAMP value
* @access protected
*/
protected $dtstamp = null;
/**
* Return formatted output for calendar component property dtstamp
*
* @return string
*/
public function createDtstamp() {
if( util::hasNodate( $this->dtstamp ))
$this->dtstamp = util::makeDtstamp();
return util::createElement( util::$DTSTAMP,
util::createParams( $this->dtstamp[util::$LCparams] ),
util::date2strdate( $this->dtstamp[util::$LCvalue], 7 ));
}
/**
* Set calendar component property dtstamp
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param array $params
* @return bool
*/
public function setDtstamp( $year, $month=null, $day=null, $hour=null, $min=null, $sec=null, $params=null ) {
$this->dtstamp = ( empty( $year )) ? util::makeDtstamp()
: util::setDate2( $year, $month, $day, $hour, $min, $sec, $params );
return true;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DTSTART property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait DTSTARTtrait {
/**
* @var array component property DTSTART value
* @access protected
*/
protected $dtstart = null;
/**
* Return formatted output for calendar component property dtstart
*
* @return string
*/
public function createDtstart() {
if( empty( $this->dtstart ))
return null;
if( util::hasNodate( $this->dtstart ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$DTSTART ): null;
if( in_array( $this->objName, util::$TZCOMPS ))
unset( $this->dtstart[util::$LCvalue][util::$LCtz], $this->dtstart[util::$LCparams][util::$TZID] );
return util::createElement( util::$DTSTART,
util::createParams( $this->dtstart[util::$LCparams] ),
util::date2strdate( $this->dtstart[util::$LCvalue],
util::isParamsValueSet( $this->dtstart, util::$DATE ) ? 3 : null ));
}
/**
* Set calendar component property dtstart
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param string $tz
* @param array $params
* @return bool
*/
public function setDtstart( $year, $month=null, $day=null, $hour=null, $min=null, $sec=null, $tz=null, $params=null ) {
if( empty( $year )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->dtstart = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $params )];
return true;
}
else
return false;
}
if( false === ( $tzid = $this->getConfig( util::$TZID )))
$tzid = null;
$this->dtstart = util::setDate( $year, $month, $day, $hour, $min, $sec, $tz,
$params, util::$DTSTART, $this->objName, $tzid);
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DUE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait DUEtrait {
/**
* @var array component property DUE value
* @access protected
*/
protected $due = null;
/**
* Return formatted output for calendar component property due
*
* @return string
*/
public function createDue() {
if( empty( $this->due ))
return null;
if( util::hasNodate( $this->due ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$DUE ) : null;
return util::createElement( util::$DUE,
util::createParams( $this->due[util::$LCparams] ),
util::date2strdate( $this->due[util::$LCvalue],
util::isParamsValueSet( $this->due, util::$DATE ) ? 3 : null ));
}
/**
* Set calendar component property due
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param string $tz
* @param array $params
* @return bool
*/
public function setDue( $year, $month=null, $day=null, $hour=null, $min=null, $sec=null, $tz=null, $params=null ) {
if( empty( $year )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->due = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $params )];
return true;
}
else
return false;
}
if( false === ( $tzid = $this->getConfig( util::$TZID )))
$tzid = null;
$this->due = util::setDate( $year, $month, $day, $hour, $min, $sec, $tz,
$params, null, null, $tzid );
return true;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* DURATION property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait DURATIONtrait {
/**
* @var array component property DURATION value
* @access protected
*/
protected $duration = null;
/**
* Return formatted output for calendar component property duration
*
* @return string
*/
public function createDuration() {
if( empty( $this->duration ))
return null;
if( ! isset( $this->duration[util::$LCvalue][util::$LCWEEK] ) &&
! isset( $this->duration[util::$LCvalue][util::$LCDAY] ) &&
! isset( $this->duration[util::$LCvalue][util::$LCHOUR] ) &&
! isset( $this->duration[util::$LCvalue][util::$LCMIN] ) &&
! isset( $this->duration[util::$LCvalue][util::$LCSEC] )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
return util::createElement( util::$DURATION );
else
return null;
}
return util::createElement( util::$DURATION,
util::createParams( $this->duration[util::$LCparams] ),
util::duration2str( $this->duration[util::$LCvalue] ));
}
/**
* Set calendar component property duration
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.8 - 2017-04-17
* @param mixed $week
* @param mixed $day
* @param int $hour
* @param int $min
* @param int $sec
* @param array $params
* @return bool
*/
public function setDuration( $week, $day=null, $hour=null, $min=null, $sec=null, $params=null ) {
static $PLUSMINUSARR = ['+', '-'];
if( empty( $week ) && empty( $day ) && empty( $hour ) && empty( $min ) && empty( $sec )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$week = $day = null;
else
return false;
}
if( is_array( $week ) && ( 1 <= count( $week )))
$this->duration = [util::$LCvalue => util::duration2arr( $week ),
util::$LCparams => util::setParams( $day )];
elseif( is_string( $week ) && ( 3 <= strlen( trim( $week )))) {
$week = util::trimTrailNL( trim( $week ));
if( in_array( $week[0], $PLUSMINUSARR ))
$week = substr( $week, 1 );
$this->duration = [util::$LCvalue => util::durationStr2arr( $week ),
util::$LCparams => util::setParams( $day )];
}
else
$this->duration = [util::$LCvalue => util::duration2arr( [util::$LCWEEK => $week,
util::$LCDAY => $day,
util::$LCHOUR => $hour,
util::$LCMIN => $min,
util::$LCSEC => $sec] ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilRexdate;
/**
* EXDATE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait EXDATEtrait {
/**
* @var array component property EXDATE value
* @access protected
*/
protected $exdate = null;
/**
* Return formatted output for calendar component property exdate
*
* @return string
*/
public function createExdate() {
if( empty( $this->exdate ))
return null;
return utilRexdate::formatExdate( $this->exdate,
$this->getConfig( util::$ALLOWEMPTY ));
}
/**
* Set calendar component property exdate
*
* @param array $exdates
* @param array $params
* @param integer $index
* @return bool
*/
public function setExdate( $exdates, $params=null, $index=null ) {
if( empty( $exdates )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
util::setMval( $this->exdate,
util::$EMPTYPROPERTY,
$params,
false,
$index );
return true;
}
else
return false;
}
$input = utilRexdate::prepInputExdate( $exdates, $params );
util::setMval( $this->exdate,
$input[util::$LCvalue],
$input[util::$LCparams],
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilRecur;
/**
* EXRULE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-04-03
*/
trait EXRULEtrait {
/**
* @var array component property EXRULE value
* @access protected
*/
protected $exrule = null;
/**
* Return formatted output for calendar component property exrule
*
* @return string
*/
public function createExrule() {
return utilRecur::formatRecur( util::$EXRULE,
$this->exrule,
$this->getConfig( util::$ALLOWEMPTY ));
}
/**
* Set calendar component property exdate
*
* @param array $exruleset
* @param array $params
* @param integer $index
* @return bool
*/
public function setExrule( $exruleset, $params=null, $index=null ) {
if( empty( $exruleset )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$exruleset = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->exrule,
utilRecur::setRexrule( $exruleset ),
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,188 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* FREEBUSY property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait FREEBUSYtrait {
/**
* @var array component property FREEBUSY value
* @access protected
*/
protected $freebusy = null;
/**
* @var FREEBUSY param keywords
* @access protected
* @static
*/
protected static $LCFBTYPE = 'fbtype';
protected static $UCFBTYPE = 'FBTYPE';
protected static $FREEBUSYKEYS = ['FREE', 'BUSY', 'BUSY-UNAVAILABLE', 'BUSY-TENTATIVE'];
protected static $FREE = 'FREE';
protected static $BUSY = 'BUSY';
/*
protected static $BUSY_UNAVAILABLE = 'BUSY-UNAVAILABLE';
protected static $BUSY_TENTATIVE = 'BUSY-TENTATIVE';
*/
/**
* Return formatted output for calendar component property freebusy
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.16.27 - 2013-07-05
* @return string
*/
public function createFreebusy() {
static $FMT = ';FBTYPE=%s';
static $SORTER = ['kigkonsult\iCalcreator\vcalendarSortHandler', 'sortRdate1'];
if( empty( $this->freebusy ))
return null;
$output = null;
foreach( $this->freebusy as $fx => $freebusyPart ) {
if( empty( $freebusyPart[util::$LCvalue] ) ||
(( 1 == count( $freebusyPart[util::$LCvalue] )) &&
isset( $freebusyPart[util::$LCvalue][self::$LCFBTYPE] ))) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$FREEBUSY );
continue;
}
$attributes = $content = null;
if( isset( $freebusyPart[util::$LCvalue][self::$LCFBTYPE] )) {
$attributes .= sprintf( $FMT, $freebusyPart[util::$LCvalue][self::$LCFBTYPE] );
unset( $freebusyPart[util::$LCvalue][self::$LCFBTYPE] );
$freebusyPart[util::$LCvalue] = array_values( $freebusyPart[util::$LCvalue] );
}
else
$attributes .= sprintf( $FMT, self::$BUSY );
$attributes .= util::createParams( $freebusyPart[util::$LCparams] );
$fno = 1;
$cnt = count( $freebusyPart[util::$LCvalue]);
if( 1 < $cnt )
usort( $freebusyPart[util::$LCvalue], $SORTER );
foreach( $freebusyPart[util::$LCvalue] as $periodix => $freebusyPeriod ) {
$formatted = util::date2strdate( $freebusyPeriod[0] );
$content .= $formatted;
$content .= util::$L;
$cnt2 = count( $freebusyPeriod[1]);
if( array_key_exists( util::$LCYEAR, $freebusyPeriod[1] )) // date-time
$cnt2 = 7;
elseif( array_key_exists( util::$LCWEEK, $freebusyPeriod[1] )) // duration
$cnt2 = 5;
if(( 7 == $cnt2 ) && // period= -> date-time
isset( $freebusyPeriod[1][util::$LCYEAR] ) &&
isset( $freebusyPeriod[1][util::$LCMONTH] ) &&
isset( $freebusyPeriod[1][util::$LCDAY] )) {
$content .= util::date2strdate( $freebusyPeriod[1] );
}
else { // period= -> dur-time
$content .= util::duration2str( $freebusyPeriod[1] );
}
if( $fno < $cnt )
$content .= util::$COMMA;
$fno++;
} // end foreach( $freebusyPart[util::$LCvalue] as $periodix => $freebusyPeriod )
$output .= util::createElement( util::$FREEBUSY,
$attributes,
$content );
} // end foreach( $this->freebusy as $fx => $freebusyPart )
return $output;
}
/**
* Set calendar component property freebusy
*
* @param string $fbType
* @param array $fbValues
* @param array $params
* @param integer $index
* @return bool
*/
public function setFreebusy( $fbType, $fbValues, $params=null, $index=null ) {
static $PREFIXARR = ['P', '+', '-'];
if( empty( $fbValues )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
util::setMval( $this->freebusy,
util::$EMPTYPROPERTY,
$params,
false,
$index );
return true;
}
else
return false;
}
$fbType = strtoupper( $fbType );
if( ! in_array( $fbType, self::$FREEBUSYKEYS ) &&
! util::isXprefixed( $fbType ))
$fbType = self::$BUSY;
$input = [self::$LCFBTYPE => $fbType];
foreach( $fbValues as $fbPeriod ) { // periods => period
if( empty( $fbPeriod ))
continue;
$freebusyPeriod = [];
foreach( $fbPeriod as $fbMember ) { // pairs => singlepart
$freebusyPairMember = [];
if( is_array( $fbMember )) {
if( util::isArrayDate( $fbMember )) { // date-time value
$freebusyPairMember = util::chkDateArr( $fbMember, 7 );
$freebusyPairMember[util::$LCtz] = util::$Z;
}
elseif( util::isArrayTimestampDate( $fbMember )) { // timestamp value
$freebusyPairMember = util::timestamp2date( $fbMember[util::$LCTIMESTAMP], 7 );
$freebusyPairMember[util::$LCtz] = util::$Z;
}
else { // array format duration
$freebusyPairMember = util::duration2arr( $fbMember );
}
}
elseif(( 3 <= strlen( trim( $fbMember ))) && // string format duration
( in_array( $fbMember{0}, $PREFIXARR ))) {
$freebusyPairMember = util::durationStr2arr( $fbMember );
}
elseif( 8 <= strlen( trim( $fbMember ))) { // text date ex. 2006-08-03 10:12:18
$freebusyPairMember = util::strDate2ArrayDate( $fbMember, 7 );
unset( $freebusyPairMember[util::$UNPARSEDTEXT] );
$freebusyPairMember[util::$LCtz] = util::$Z;
}
$freebusyPeriod[] = $freebusyPairMember;
}
$input[] = $freebusyPeriod;
}
util::setMval( $this->freebusy,
$input,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilGeo;
/**
* GEO property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait GEOtrait {
/**
* @var array component property GEO value
* @access protected
*/
protected $geo = null;
/**
* Return formatted output for calendar component property geo
*
* @return string
*/
public function createGeo() {
if( empty( $this->geo ))
return null;
if( empty( $this->geo[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$GEO ) : null;
return util::createElement( util::$GEO,
util::createParams( $this->geo[util::$LCparams] ),
utilGeo::geo2str2( $this->geo[util::$LCvalue][utilGeo::$LATITUDE], utilGeo::$geoLatFmt ) .
util::$SEMIC .
utilGeo::geo2str2( $this->geo[util::$LCvalue][utilGeo::$LONGITUDE], utilGeo::$geoLongFmt ));
}
/**
* Set calendar component property geo
*
* @param mixed $latitude
* @param mixed $longitude
* @param array $params
* @return bool
*/
public function setGeo( $latitude, $longitude, $params=null ) {
if( isset( $latitude ) && isset( $longitude )) {
if( ! is_array( $this->geo ))
$this->geo = [];
$this->geo[util::$LCvalue][utilGeo::$LATITUDE] = floatval( $latitude );
$this->geo[util::$LCvalue][utilGeo::$LONGITUDE] = floatval( $longitude );
$this->geo[util::$LCparams] = util::setParams( $params );
}
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$this->geo = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $params )];
else
return false;
return true;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* LAST-MODIFIED property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait LAST_MODIFIEDtrait {
/**
* @var array component property LAST-MODIFIED value
* @access protected
*/
protected $lastmodified = null;
/**
* Return formatted output for calendar component property last-modified
*
* @return string
*/
public function createLastModified() {
if( empty( $this->lastmodified ))
return null;
return util::createElement( util::$LAST_MODIFIED,
util::createParams( $this->lastmodified[util::$LCparams] ),
util::date2strdate( $this->lastmodified[util::$LCvalue], 7 ));
}
/**
* Set calendar component property completed
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param array $params
* @return bool
*/
public function setLastModified( $year=null, $month=null, $day=null, $hour=null, $min=null, $sec=null, $params=null ) {
static $TMDTHIS = 'Ymd\THis';
if( empty( $year ))
$year = gmdate( $TMDTHIS );
$this->lastmodified = util::setDate2( $year, $month, $day, $hour, $min, $sec, $params );
return true;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* LOCATION property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait LOCATIONtrait {
/**
* @var array component property LOCATION value
* @access protected
*/
protected $location = null;
/**
* Return formatted output for calendar component property location
*
* @return string
*/
public function createLocation() {
if( empty( $this->location ))
return null;
if( empty( $this->location[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$LOCATION ) : null;
return util::createElement( util::$LOCATION,
util::createParams( $this->location[util::$LCparams],
util::$ALTRPLANGARR,
$this->getConfig( util::$LANGUAGE )),
util::strrep( $this->location[util::$LCvalue] ));
}
/**
* Set calendar component property location
*
* @param string $value
* @param array $params
* @return bool
*/
public function setLocation( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->location = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* METHOD property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait METHODtrait {
/**
* @var string calendar property METHOD
* @access protected
*/
protected $method = null;
/**
* Return formatted output for calendar property method
*
* @return string
*/
public function createMethod() {
return ( empty( $this->method ))
? null
: sprintf( self::$FMTICAL, util::$METHOD,
$this->method );
}
/**
* Set calendar property method
*
* @param string $value
* @return bool
*/
public function setMethod( $value ) {
if( empty( $value ))
return false;
$this->method = $value;
return true;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilAttendee;
/**
* ORGANIZER property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-04-03
*/
trait ORGANIZERtrait {
/**
* @var array component property ORGANIZER value
* @access protected
*/
protected $organizer = null;
/**
* Return formatted output for calendar component property organizer
*
* @return string
*/
public function createOrganizer() {
if( empty( $this->organizer ))
return null;
if( empty( $this->organizer[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$ORGANIZER ) : null;
return util::createElement( util::$ORGANIZER,
util::createParams( $this->organizer[util::$LCparams],
[util::$CN,
util::$DIR,
util::$SENT_BY,
util::$LANGUAGE],
$this->getConfig( util::$LANGUAGE )),
$this->organizer[util::$LCvalue] );
}
/**
* Set calendar component property organizer
*
* @param string $value
* @param array $params
* @return bool
*/
public function setOrganizer( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$value = utilAttendee::calAddressCheck( $value, false );
$this->organizer = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
if( isset( $this->organizer[util::$LCparams][util::$SENT_BY] ))
$this->organizer[util::$LCparams][util::$SENT_BY] =
utilAttendee::calAddressCheck( $this->organizer[util::$LCparams][util::$SENT_BY],
false );
return true;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* PERCENT-COMPLETE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait PERCENT_COMPLETEtrait {
/**
* @var array component property PERCENT_COMPLETE value
* @access protected
*/
protected $percentcomplete = null;
/**
* Return formatted output for calendar component property percent-complete
*
* @return string
*/
public function createPercentComplete() {
if( ! isset( $this->percentcomplete ) ||
( empty( $this->percentcomplete ) && ! is_numeric( $this->percentcomplete )))
return null;
if( ! isset( $this->percentcomplete[util::$LCvalue] ) ||
( empty( $this->percentcomplete[util::$LCvalue] ) &&
! is_numeric( $this->percentcomplete[util::$LCvalue] )))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$PERCENT_COMPLETE ) : null;
return util::createElement( util::$PERCENT_COMPLETE,
util::createParams( $this->percentcomplete[util::$LCparams] ),
$this->percentcomplete[util::$LCvalue] );
}
/**
* Set calendar component property percent-complete
*
* @param int $value
* @param array $params
* @return bool
*/
public function setPercentComplete( $value, $params=null ) {
if( empty( $value ) && ! is_numeric( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->percentcomplete = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* PRIORITY property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait PRIORITYtrait {
/**
* @var array component property PRIORITY value
* @access protected
*/
protected $priority = null;
/**
* Return formatted output for calendar component property priority
*
* @return string
*/
public function createPriority() {
if( ! isset( $this->priority ) ||
( empty( $this->priority ) && ! is_numeric( $this->priority )))
return null;
if( ! isset( $this->priority[util::$LCvalue] ) ||
( empty( $this->priority[util::$LCvalue] ) && !is_numeric( $this->priority[util::$LCvalue] )))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$PRIORITY ) : null;
return util::createElement( util::$PRIORITY,
util::createParams( $this->priority[util::$LCparams] ),
$this->priority[util::$LCvalue] );
}
/**
* Set calendar component property priority
*
* @param int $value
* @param array $params
* @return bool
*/
public function setPriority( $value, $params=null ) {
if( empty( $value ) && ! is_numeric( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->priority = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* PRODID property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-15
*/
trait PRODIDtrait {
/**
* @var string calendar property PRODID
* @access protected
*/
protected $prodid = null;
/**
* Return formatted output for calendar property prodid
*
* @return string
*/
public function createProdid() {
if( ! isset( $this->prodid ))
$this->makeProdid();
return util::createElement( util::$PRODID,
null,
$this->prodid );
}
/**
* Create default value for calendar prodid,
* Do NOT alter or remove this method or the invoke of this method,
* a licence violation.
*
* [rfc5545]
* "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]."
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-01-29
*/
public function makeProdid() {
static $FMT = '-//%s//NONSGML kigkonsult.se %s//%s';
if( false !== ( $lang = $this->getConfig( util::$LANGUAGE )))
$lang = strtoupper( $lang );
else
$lang = null;
$this->prodid = sprintf( $FMT, $this->getConfig( util::$UNIQUE_ID ),
ICALCREATOR_VERSION,
$lang );
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilRexdate;
/**
* RDATE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-26
*/
trait RDATEtrait {
/**
* @var array component property RDATE value
* @access protected
*/
protected $rdate = null;
/**
* Return formatted output for calendar component property rdate
*
* @return string
*/
public function createRdate() {
if( empty( $this->rdate ))
return null;
return utilRexdate::formatRdate( $this->rdate,
$this->getConfig( util::$ALLOWEMPTY ),
$this->objName );
}
/**
* Set calendar component property rdate
*
* @param array $rdates
* @param array $params
* @param integer $index
* @return bool
*/
public function setRdate( $rdates, $params=null, $index=null ) {
if( empty( $rdates )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
util::setMval( $this->rdate,
util::$EMPTYPROPERTY,
$params,
false,
$index );
return true;
}
else
return false;
}
$input = utilRexdate::prepInputRdate( $rdates,
$params,
$this->objName );
util::setMval( $this->rdate,
$input[util::$LCvalue],
$input[util::$LCparams],
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* RECURRENCE-ID property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait RECURRENCE_IDtrait {
/**
* @var array component property RECURRENCE_ID value
* @access protected
*/
protected $recurrenceid = null;
/**
* Return formatted output for calendar component property recurrence-id
*
* @return string
*/
public function createRecurrenceid() {
if( empty( $this->recurrenceid ))
return null;
if( empty( $this->recurrenceid[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$RECURRENCE_ID ) : null;
return util::createElement( util::$RECURRENCE_ID,
util::createParams( $this->recurrenceid[util::$LCparams] ),
util::date2strdate( $this->recurrenceid[util::$LCvalue],
util::isParamsValueSet( $this->recurrenceid, util::$DATE ) ? 3 : null ));
}
/**
* Set calendar component property recurrence-id
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $hour
* @param int $min
* @param int $sec
* @param string $tz
* @param array $params
* @return bool
*/
public function setRecurrenceid( $year, $month=null, $day=null,
$hour=null, $min=null, $sec=null,
$tz=null, $params=null ) {
if( empty( $year )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->recurrenceid = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => null];
return true;
}
else
return false;
}
$this->recurrenceid = util::setDate( $year, $month, $day, $hour, $min, $sec, $tz,
$params,
null,
null,
$this->getConfig( util::$TZID ));
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* RELATED-TO property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait RELATED_TOtrait {
/**
* @var array component property RELATED_TO value
* @access protected
*/
protected $relatedto = null;
/**
* Return formatted output for calendar component property related-to
*
* @return string
*/
public function createRelatedTo() {
if( empty( $this->relatedto ))
return null;
$output = null;
foreach( $this->relatedto as $rx => $relation ) {
if( ! empty( $relation[util::$LCvalue] ))
$output .= util::createElement( util::$RELATED_TO,
util::createParams( $relation[util::$LCparams] ),
util::strrep( $relation[util::$LCvalue] ));
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$RELATED_TO );
}
return $output;
}
/**
* Set calendar component property related-to
*
* @param string $value
* @param array $params
* @param int $index
* @return bool
*/
public function setRelatedTo( $value, $params=null, $index=null ) {
static $RELTYPE = 'RELTYPE';
static $PARENT = 'PARENT';
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::existRem( $params, $RELTYPE, $PARENT, true ); // remove default
util::setMval( $this->relatedto,
util::trimTrailNL( $value ),
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* REPEAT property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait REPEATtrait {
/**
* @var array component property REPEAT value
* @access protected
*/
protected $repeat = null;
/**
* Return formatted output for calendar component property repeat
*
* @return string
*/
public function createRepeat() {
if( ! isset( $this->repeat ) ||
( empty( $this->repeat ) && ! is_numeric( $this->repeat )))
return null;
if( ! isset( $this->repeat[util::$LCvalue]) ||
( empty( $this->repeat[util::$LCvalue] ) && ! is_numeric( $this->repeat[util::$LCvalue] )))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$REPEAT ) : null;
return util::createElement( util::$REPEAT,
util::createParams( $this->repeat[util::$LCparams] ),
$this->repeat[util::$LCvalue] );
}
/**
* Set calendar component property repeat
*
* @param string $value
* @param array $params
*/
public function setRepeat( $value, $params=null ) {
if( empty( $value ) && !is_numeric( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->repeat = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* REQUEST-STATUS property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-19
*/
trait REQUEST_STATUStrait {
/**
* @var array component property REQUEST-STATUS value
* @access protected
*/
protected $requeststatus = null;
/**
* Return formatted output for calendar component property request-status
*
* @return string
*/
public function createRequestStatus() {
static $STATCODE = 'statcode';
static $TEXT = 'text';
static $EXTDATA = 'extdata';
if( empty( $this->requeststatus ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->requeststatus as $rx => $rStat ) {
if( empty( $rStat[util::$LCvalue][$STATCODE] )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$REQUEST_STATUS );
continue;
}
$content = number_format( (float) $rStat[util::$LCvalue][$STATCODE], 2, util::$DOT, null );
$content .= util::$SEMIC . util::strrep( $rStat[util::$LCvalue][$TEXT] );
if( isset( $rStat[util::$LCvalue][$EXTDATA] ))
$content .= util::$SEMIC . util::strrep( $rStat[util::$LCvalue][$EXTDATA] );
$output .= util::createElement( util::$REQUEST_STATUS,
util::createParams( $rStat[util::$LCparams],
[util::$LANGUAGE],
$lang ),
$content );
}
return $output;
}
/**
* Set calendar component property request-status
*
* @param float $statcode
* @param string $text
* @param string $extdata
* @param array $params
* @param integer $index
* @return bool
*/
public function setRequestStatus( $statcode, $text, $extdata=null, $params=null, $index=null ) {
static $STATCODE = 'statcode';
static $TEXT = 'text';
static $EXTDATA = 'extdata';
if( empty( $statcode ) || empty( $text )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$statcode = $text = util::$EMPTYPROPERTY;
else
return false;
}
$input = [$STATCODE => $statcode,
$TEXT => util::trimTrailNL( $text )];
if( $extdata )
$input[$EXTDATA] = util::trimTrailNL( $extdata );
util::setMval( $this->requeststatus,
$input,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* RESOURCES property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait RESOURCEStrait {
/**
* @var array component property RESOURCES value
* @access protected
*/
protected $resources = null;
/**
* Return formatted output for calendar component property resources
*
* @return string
*/
public function createResources() {
if( empty( $this->resources ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->resources as $rx => $resource ) {
if( empty( $resource[util::$LCvalue] )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$RESOURCES );
continue;
}
if( is_array( $resource[util::$LCvalue] )) {
foreach( $resource[util::$LCvalue] as $rix => $rValue )
$resource[util::$LCvalue][$rix] = util::strrep( $rValue );
$content = implode( util::$COMMA, $resource[util::$LCvalue] );
}
else
$content = util::strrep( $resource[util::$LCvalue] );
$output .= util::createElement( util::$RESOURCES,
util::createParams( $resource[util::$LCparams],
util::$ALTRPLANGARR,
$lang ),
$content );
}
return $output;
}
/**
* Set calendar component property recources
*
* @param mixed $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setResources( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
if( is_array( $value ))
foreach( $value as & $valuePart )
$valuePart = util::trimTrailNL( $valuePart );
else
$value = util::trimTrailNL( $value );
util::setMval( $this->resources,
$value,
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
use kigkonsult\iCalcreator\util\utilRecur;
/**
* RRULE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-04-03
*/
trait RRULEtrait {
/**
* @var array component property RRULE value
* @access protected
*/
protected $rrule = null;
/**
* Return formatted output for calendar component property rrule
*
* @return string
*/
public function createRrule() {
return utilRecur::formatRecur( util::$RRULE,
$this->rrule,
$this->getConfig( util::$ALLOWEMPTY ));
}
/**
* Set calendar component property rrule
*
* @param array $rruleset
* @param array $params
* @param integer $index
*/
public function setRrule( $rruleset, $params=null, $index=null ) {
if( empty( $rruleset )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$rruleset = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->rrule,
utilRecur::setRexrule( $rruleset ),
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* SEQUENCE property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-24
*/
trait SEQUENCEtrait {
/**
* @var array component property SEQUENCE value
* @access protected
*/
protected $sequence = null;
/**
* Return formatted output for calendar component property sequence
*
* @return string
*/
public function createSequence() {
if( ! isset( $this->sequence ) ||
( empty( $this->sequence ) && ! is_numeric( $this->sequence )))
return null;
if(( ! isset( $this->sequence[util::$LCvalue] ) ||
( empty( $this->sequence[util::$LCvalue] ) && ! is_numeric( $this->sequence[util::$LCvalue] ))) &&
( util::$ZERO != $this->sequence[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$SEQUENCE ) : null;
return util::createElement( util::$SEQUENCE,
util::createParams( $this->sequence[util::$LCparams] ),
$this->sequence[util::$LCvalue] );
}
/**
* Set calendar component property sequence
*
* @param int $value
* @param array $params
*/
public function setSequence( $value=null, $params=null ) {
if(( empty( $value ) && ! is_numeric( $value )) && ( util::$ZERO != $value ))
$value = ( isset( $this->sequence[util::$LCvalue] ) &&
( -1 < $this->sequence[util::$LCvalue] ))
? $this->sequence[util::$LCvalue] + 1
: util::$ZERO;
$this->sequence = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* STATUS property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait STATUStrait {
/**
* @var array component property STATUS value
* @access protected
*/
protected $status = null;
/**
* Return formatted output for calendar component property status
*
* @return string
*/
public function createStatus() {
if( empty( $this->status ))
return null;
if( empty( $this->status[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$STATUS ) : null;
return util::createElement( util::$STATUS,
util::createParams( $this->status[util::$LCparams] ),
$this->status[util::$LCvalue] );
}
/**
* Set calendar component property status
*
* @param string $value
* @param array $params
*/
public function setStatus( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->status = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* SUMMARY property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait SUMMARYtrait {
/**
* @var array component property SUMMARY value
* @access protected
*/
protected $summary = null;
/**
* Return formatted output for calendar component property summary
*
* @return string
*/
public function createSummary() {
if( empty( $this->summary ))
return null;
if( empty( $this->summary[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$SUMMARY ) : null;
return util::createElement( util::$SUMMARY,
util::createParams( $this->summary[util::$LCparams],
util::$ALTRPLANGARR,
$this->getConfig( util::$LANGUAGE )),
util::strrep( $this->summary[util::$LCvalue] ));
}
/**
* Set calendar component property summary
*
* @param string $value
* @param array $params
*/
public function setSummary( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->summary = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TRANSP property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait TRANSPtrait {
/**
* @var array component property TRANSP value
* @access protected
*/
protected $transp = null;
/**
* Return formatted output for calendar component property transp
*
* @return string
*/
public function createTransp() {
if( empty( $this->transp ))
return null;
if( empty( $this->transp[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TRANSP ) : null;
return util::createElement( util::$TRANSP,
util::createParams( $this->transp[util::$LCparams] ),
$this->transp[util::$LCvalue] );
}
/**
* Set calendar component property transp
*
* @param string $value
* @param array $params
* @return bool
*/
public function setTransp( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->transp = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,213 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TRIGGER property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait TRIGGERtrait {
/**
* @var array component property TRIGGER value
* @access protected
*/
protected $trigger = null;
/**
* Return formatted output for calendar component property trigger
*
* @return string
*/
public function createTrigger() {
static $RELATEDSTART = 'relatedStart';
static $BEFORE = 'before';
static $RELATED_END = 'RELATED=END';
if( empty( $this->trigger ))
return null;
if( empty( $this->trigger[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TRIGGER ) : null;
$content = $attributes = null;
if( isset( $this->trigger[util::$LCvalue][util::$LCYEAR] ) &&
isset( $this->trigger[util::$LCvalue][util::$LCMONTH] ) &&
isset( $this->trigger[util::$LCvalue][util::$LCDAY] ))
$content .= util::date2strdate( $this->trigger[util::$LCvalue] );
else {
if( true !== $this->trigger[util::$LCvalue][$RELATEDSTART] )
$attributes .= util::$SEMIC . $RELATED_END;
if( $this->trigger[util::$LCvalue][$BEFORE] )
$content .= util::$MINUS;
$content .= util::duration2str( $this->trigger[util::$LCvalue] );
}
$attributes .= util::createParams( $this->trigger[util::$LCparams] );
return util::createElement( util::$TRIGGER,
$attributes,
$content );
}
/**
* Set calendar component property trigger
*
* @param mixed $year
* @param mixed $month
* @param int $day
* @param int $week
* @param int $hour
* @param int $min
* @param int $sec
* @param bool $relatedStart
* @param bool $before
* @param array $params
* @return bool
*/
public function setTrigger( $year=null, $month=null, $day=null, $week=null, $hour=null, $min=null, $sec=null,
$relatedStart=null, $before=null, $params=null ) {
static $PREFIXARR = ['P', '+', '-'];
static $P = 'P';
static $RELATEDSTART = 'relatedStart';
static $BEFORE = 'before';
static $RELATED = 'RELATED';
static $END = 'END';
if( empty( $year ) &&
( empty( $month ) || is_array( $month )) &&
empty( $day ) && empty( $week ) && empty( $hour ) && empty( $min ) && empty( $sec )) {
if( $this->getConfig( util::$ALLOWEMPTY )) {
$this->trigger = [util::$LCvalue => util::$EMPTYPROPERTY,
util::$LCparams => util::setParams( $month )];
return true;
}
else
return false;
}
if( is_null( $relatedStart ))
$relatedStart = true;
if( is_null( $before ))
$before = true;
switch( true ) {
case( util::isArrayTimestampDate( $year )) : // timestamp UTC
$params = util::setParams( $month );
$date = util::timestamp2date( $year, 7 );
foreach( $date as $k => $v )
$$k = $v;
break;
case( is_array( $year ) && ( is_array( $month ) || empty( $month ))) :
$params = util::setParams( $month );
if( ! ( array_key_exists( util::$LCYEAR, $year ) && // exclude date-time
array_key_exists( util::$LCMONTH, $year ) &&
array_key_exists( util::$LCDAY, $year ))) { // when this must be a duration
if( isset( $params[$RELATED] ) && ( 0 == strcasecmp( $END, $params[$RELATED] )))
$relatedStart = false;
else
$relatedStart = ( array_key_exists( $RELATEDSTART, $year ) &&
( true !== $year[$RELATEDSTART] )) ? false : true;
$before = ( array_key_exists( $BEFORE, $year ) &&
( true !== $year[$BEFORE] )) ? false : true;
}
$SSYY = ( array_key_exists( util::$LCYEAR, $year )) ? $year[util::$LCYEAR] : null;
$month = ( array_key_exists( util::$LCMONTH, $year )) ? $year[util::$LCMONTH] : null;
$day = ( array_key_exists( util::$LCDAY, $year )) ? $year[util::$LCDAY] : null;
$week = ( array_key_exists( util::$LCWEEK, $year )) ? $year[util::$LCWEEK] : null;
$hour = ( array_key_exists( util::$LCHOUR, $year )) ? $year[util::$LCHOUR] : 0; //null;
$min = ( array_key_exists( util::$LCMIN, $year )) ? $year[util::$LCMIN] : 0; //null;
$sec = ( array_key_exists( util::$LCSEC, $year )) ? $year[util::$LCSEC] : 0; //null;
$year = $SSYY;
break;
case( is_string( $year ) && ( is_array( $month ) || empty( $month ))) : // duration or date in a string
$params = util::setParams( $month );
if( in_array( $year{0}, $PREFIXARR )) { // duration
$relatedStart = ( isset( $params[$RELATED] ) && ( 0 == strcasecmp( $END, $params[$RELATED] ))) ? false : true;
$before = ( util::$MINUS == $year[0] ) ? true : false;
if( $P != $year[0] )
$year = substr( $year, 1 );
$date = util::durationStr2arr( $year);
}
else // date
$date = util::strDate2ArrayDate( $year, 7 );
unset( $year, $month, $day, $date[util::$UNPARSEDTEXT] );
if( empty( $date ))
$sec = 0;
else
foreach( $date as $k => $v )
$$k = $v;
break;
default : // single values in function input parameters
$params = util::setParams( $params );
break;
} // end switch( true )
if( ! empty( $year ) && ! empty( $month ) && ! empty( $day )) { // date
$params[util::$VALUE] = util::$DATE_TIME;
$hour = ( $hour ) ? $hour : 0;
$min = ( $min ) ? $min : 0;
$sec = ( $sec ) ? $sec : 0;
$this->trigger = [util::$LCparams => $params];
$this->trigger[util::$LCvalue] = [util::$LCYEAR => $year,
util::$LCMONTH => $month,
util::$LCDAY => $day,
util::$LCHOUR => $hour,
util::$LCMIN => $min,
util::$LCSEC => $sec,
util::$LCtz => util::$Z];
return true;
}
elseif(( empty( $year ) && empty( $month )) && // duration
(( ! empty( $week ) || ( 0 == $week )) ||
( ! empty( $day ) || ( 0 == $day )) ||
( ! empty( $hour ) || ( 0 == $hour )) ||
( ! empty( $min ) || ( 0 == $min )) ||
( ! empty( $sec ) || ( 0 == $sec )))) {
unset( $params[$RELATED] ); // set at output creation (END only)
unset( $params[util::$VALUE] ); // util::$DURATION default
$this->trigger = [util::$LCparams => $params];
$this->trigger[util::$LCvalue] = [];
if( ! empty( $week ))
$this->trigger[util::$LCvalue][util::$LCWEEK] = $week;
if( ! empty( $day ))
$this->trigger[util::$LCvalue][util::$LCDAY] = $day;
if( ! empty( $hour ))
$this->trigger[util::$LCvalue][util::$LCHOUR] = $hour;
if( ! empty( $min ))
$this->trigger[util::$LCvalue][util::$LCMIN] = $min;
if( ! empty( $sec ))
$this->trigger[util::$LCvalue][util::$LCSEC] = $sec;
if( empty( $this->trigger[util::$LCvalue] )) {
$this->trigger[util::$LCvalue][util::$LCSEC] = 0;
$before = false;
}
else
$this->trigger[util::$LCvalue] = util::duration2arr( $this->trigger[util::$LCvalue] );
$relatedStart = ( false !== $relatedStart ) ? true : false;
$before = ( false !== $before ) ? true : false;
$this->trigger[util::$LCvalue][$RELATEDSTART] = $relatedStart;
$this->trigger[util::$LCvalue][$BEFORE] = $before;
return true;
}
return false;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TZID property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait TZIDtrait {
/**
* @var array component property TZID value
* @access protected
*/
protected $tzid = null;
/**
* Return formatted output for calendar component property tzid
*
* @return string
*/
public function createTzid() {
if( empty( $this->tzid ))
return null;
if( empty( $this->tzid[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TZID ) : null;
return util::createElement( util::$TZID,
util::createParams( $this->tzid[util::$LCparams] ),
util::strrep( $this->tzid[util::$LCvalue] ));
}
/**
* Set calendar component property tzid
*
* @since 2.23.12 - 2017-04-22
* @param string $value
* @param array $params
* @return bool
*/
public function setTzid( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->tzid = [util::$LCvalue => trim( util::trimTrailNL( $value )),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TZNAME property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-17
*/
trait TZNAMEtrait {
/**
* @var array component property TZNAME value
* @access protected
*/
protected $tzname = null;
/**
* Return formatted output for calendar component property tzname
*
* @return string
*/
public function createTzname() {
if( empty( $this->tzname ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->tzname as $tzx => $theName ) {
if( ! empty( $theName[util::$LCvalue] ))
$output .= util::createElement( util::$TZNAME,
util::createParams( $theName[util::$LCparams],
[util::$LANGUAGE],
$lang ),
util::strrep( $theName[util::$LCvalue] ));
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( util::$TZNAME );
}
return $output;
}
/**
* Set calendar component property tzname
*
* @param string $value
* @param array $params
* @param integer $index
* @return bool
*/
public function setTzname( $value, $params=null, $index=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
util::setMval( $this->tzname,
util::trimTrailNL( $value ),
$params,
false,
$index );
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TZOFFSETFROM property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait TZOFFSETFROMtrait {
/**
* @var array component property TZOFFSETFROM value
* @access protected
*/
protected $tzoffsetfrom = null;
/**
* Return formatted output for calendar component property tzoffsetfrom
*
* @return string
*/
public function createTzoffsetfrom() {
if( empty( $this->tzoffsetfrom ))
return null;
if( empty( $this->tzoffsetfrom[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TZOFFSETFROM ) : null;
return util::createElement( util::$TZOFFSETFROM,
util::createParams( $this->tzoffsetfrom[util::$LCparams] ),
$this->tzoffsetfrom[util::$LCvalue] );
}
/**
* Set calendar component property tzoffsetfrom
*
* @param string $value
* @param array $params
* @return bool
*/
public function setTzoffsetfrom( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->tzoffsetfrom = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TZOFFSETTO property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait TZOFFSETTOtrait {
/**
* @var array component property TZOFFSETTO value
* @access protected
*/
protected $tzoffsetto = null;
/**
* Return formatted output for calendar component property tzoffsetto
*
* @return string
*/
public function createTzoffsetto() {
if( empty( $this->tzoffsetto ))
return null;
if( empty( $this->tzoffsetto[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TZOFFSETTO ) : null;
return util::createElement( util::$TZOFFSETTO,
util::createParams( $this->tzoffsetto[util::$LCparams] ),
$this->tzoffsetto[util::$LCvalue] );
}
/**
* Set calendar component property tzoffsetto
*
* @param string $value
* @param array $params
* @return bool
*/
public function setTzoffsetto( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->tzoffsetto = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* TZURL property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait TZURLtrait {
/**
* @var array component property TZURL value
* @access protected
*/
protected $tzurl = null;
/**
* Return formatted output for calendar component property tzurl
*
* @return string
*/
public function createTzurl() {
if( empty( $this->tzurl ))
return null;
if( empty( $this->tzurl[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$TZURL ) : null;
return util::createElement( util::$TZURL,
util::createParams( $this->tzurl[util::$LCparams] ),
$this->tzurl[util::$LCvalue] );
}
/**
* Set calendar component property tzurl
*
* @param string $value
* @param array $params
* @return bool
*/
public function setTzurl( $value, $params=null ) {
if( empty( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$this->tzurl = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* UID property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-02-17
*/
trait UIDtrait {
/**
* @var array component property UID value
* @access protected
*/
protected $uid = null;
/**
* Return formatted output for calendar component property uid
*
* If uid is missing, uid is created
*
* @return string
*/
public function createUid() {
if( empty( $this->uid ))
$this->uid = util::makeUid( $this->getConfig( util::$UNIQUE_ID ));
return util::createElement( util::$UID,
util::createParams( $this->uid[util::$LCparams] ),
$this->uid[util::$LCvalue] );
}
/**
* Set calendar component property uid
*
* @param string $value
* @param array $params
* @return bool
*/
public function setUid( $value, $params=null ) {
if( empty( $value ) && ( util::$ZERO != $value ))
return false; // no allowEmpty check here !!!!
$this->uid = [util::$LCvalue => util::trimTrailNL( $value ),
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* URL property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-05
*/
trait URLtrait {
/**
* @var array component property URL value
* @access protected
*/
protected $url = null;
/**
* Return formatted output for calendar component property url
*
* @return string
*/
public function createUrl() {
if( empty( $this->url ))
return null;
if( empty( $this->url[util::$LCvalue] ))
return ( $this->getConfig( util::$ALLOWEMPTY )) ? util::createElement( util::$URL ) : null;
return util::createElement( util::$URL,
util::createParams( $this->url[util::$LCparams] ),
$this->url[util::$LCvalue] );
}
/**
* Set calendar component property url
*
* @param string $value
* @param array $params
* @return bool
*/
public function setUrl( $value, $params=null ) {
static $URN = 'urn';
if( ! empty( $value )) {
if( ! filter_var( $value, FILTER_VALIDATE_URL ) &&
( 0 != strcasecmp( $URN, substr( $value, 0, 3 ))))
return false;
}
elseif( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
$this->url = [util::$LCvalue => $value,
util::$LCparams => util::setParams( $params )];
return true;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* VERSION property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-18
*/
trait VERSIONtrait {
/**
* Property Name: VERSION
*
* Description: A value of "2.0" corresponds to this memo.
*
* @var string calendar property VERSION
* @access protected
*/
protected $version = '2.0';
/**
* Return formatted output for calendar property version
*
* If version is missing, version is set
*
* @return string
*/
public function createVersion() {
return sprintf( self::$FMTICAL, util::$VERSION,
$this->version );
}
/**
* Set (another?) calendar version
*
* @param string $value
* @return bool
*/
public function setVersion( $value ) {
if( empty( $value ))
return false;
$this->version = $value;
return true;
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\traits;
use kigkonsult\iCalcreator\util\util;
/**
* X-property functions
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
trait X_PROPtrait {
/**
* @var array component property X-property value
* @access protected
*/
protected $xprop = null;
/**
* Return formatted output for calendar/component property x-prop
*
* @return string
*/
public function createXprop() {
if( empty( $this->xprop ) || !is_array( $this->xprop ))
return null;
$output = null;
$lang = $this->getConfig( util::$LANGUAGE );
foreach( $this->xprop as $label => $xpropPart ) {
if( ! isset( $xpropPart[util::$LCvalue]) ||
( empty( $xpropPart[util::$LCvalue] ) && ! is_numeric( $xpropPart[util::$LCvalue] ))) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$output .= util::createElement( $label );
continue;
}
if( is_array( $xpropPart[util::$LCvalue] )) {
foreach( $xpropPart[util::$LCvalue] as $pix => $theXpart )
$xpropPart[util::$LCvalue][$pix] = util::strrep( $theXpart );
$xpropPart[util::$LCvalue] = implode( util::$COMMA, $xpropPart[util::$LCvalue] );
}
else
$xpropPart[util::$LCvalue] = util::strrep( $xpropPart[util::$LCvalue] );
$output .= util::createElement( $label,
util::createParams( $xpropPart[util::$LCparams],
[util::$LANGUAGE],
$lang ),
util::trimTrailNL( $xpropPart[util::$LCvalue] ));
}
return $output;
}
/**
* Set calendar property x-prop
*
* @param string $label
* @param string $value
* @param array $params optional
* @return bool
*/
public function setXprop( $label, $value, $params=false ) {
if( empty( $label ) || ! util::isXprefixed( $label ))
return false;
if( empty( $value ) && ! is_numeric( $value )) {
if( $this->getConfig( util::$ALLOWEMPTY ))
$value = util::$EMPTYPROPERTY;
else
return false;
}
$xprop = [util::$LCvalue => $value];
$xprop[util::$LCparams] = util::setParams( $params );
if( ! is_array( $this->xprop ))
$this->xprop = [];
$this->xprop[strtoupper( $label )] = $xprop;
return true;
}
/**
* Delete component property X-prop value
*
* @param string $propName
* @param array $xProp component X-property
* @param int $propix removal counter
* @param array $propdelix
* @access protected
* @static
*/
protected static function deleteXproperty( $propName=null, & $xProp, & $propix, & $propdelix ) {
$reduced = [];
if( $propName != util::$X_PROP ) {
if( ! isset( $xProp[$propName] )) {
unset( $propdelix[$propName] );
return false;
}
foreach( $xProp as $k => $xValue ) {
if(( $k != $propName ) && ! empty( $xValue ))
$reduced[$k] = $xValue;
}
}
else {
if( count( $xProp ) <= $propix ) {
unset( $propdelix[$propName] );
return false;
}
$xpropno = 0;
foreach( $xProp as $xPropKey => $xPropValue ) {
if( $propix != $xpropno )
$reduced[$xPropKey] = $xPropValue;
$xpropno++;
}
}
$xProp = $reduced;
if( empty( $xProp )) {
$xProp = null;
unset( $propdelix[$propName] );
return false;
}
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,254 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
/**
* iCalcreator attendee support class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
class utilAttendee {
/**
* Return string after a cal-address check, prefix mail address with MAILTO
*
* Acceps other prefix ftp://, http://, file://, gopher://, news:, nntp://, telnet://, wais://, prospero:// etc
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-06
* @param string $value
* @param bool $trimQuotes
* @return string
* @static
* @TODO fix in util::splitContent() ??
*/
public static function calAddressCheck( $value, $trimQuotes=true ) {
static $MAILTOCOLON = 'MAILTO:';
$value = trim( $value );
if( $trimQuotes )
$value = trim( $value, util::$QQ );
switch( true ) {
case( empty( $value )) :
break;
case( 0 == strcasecmp( $MAILTOCOLON, substr( $value, 0, 7 ))) :
$value = $MAILTOCOLON . substr( $value, 7 ); // accept mailto:
break;
case( false !== ( $pos = strpos( substr( $value, 0, 9 ), util::$COLON ))) :
break; // accept (as is) from list above
case( filter_var( $value, FILTER_VALIDATE_EMAIL )) :
$value = $MAILTOCOLON . $value; // accept mail address
break;
default : // accept as is...
break;
}
return $value;
}
/**
* Return formatted output for calendar component property attendee
*
* @param array $attendeeData
* @param bool $allowEmpty
* @return string
* @static
*/
public static function formatAttendee( array $attendeeData, $allowEmpty ) {
static $FMTQVALUE = '"%s"';
static $FMTKEYVALUE = ';%s=%s';
static $FMTKEYEQ = ';%s=';
static $FMTDIREQ = ';%s=%s%s%s';
$output = null;
foreach( $attendeeData as $ax => $attendeePart ) {
if( empty( $attendeePart[util::$LCvalue] )) {
if( $allowEmpty )
$output .= util::createElement( util::$ATTENDEE );
continue;
}
$attributes = $content = null;
foreach( $attendeePart as $pLabel => $pValue ) {
if( util::$LCvalue == $pLabel ) {
$content .= $pValue;
continue;
}
if(( util::$LCparams != $pLabel ) ||
( ! is_array( $pValue )))
continue;
foreach( $pValue as $pLabel2 => $pValue2 ) { // fix (opt) quotes
if( is_array( $pValue2 ) ||
in_array( $pLabel2, util::$ATTENDEEPARKEYS ))
continue; // DELEGATED-FROM, DELEGATED-TO, MEMBER
if(( false !== strpos( $pValue2, util::$COLON )) ||
( false !== strpos( $pValue2, util::$SEMIC )) ||
( false !== strpos( $pValue2, util::$COMMA )))
$pValue[$pLabel2] = sprintf( $FMTQVALUE, $pValue2 );
}
/* set attenddee parameters in rfc2445 order */
if( isset( $pValue[util::$CUTYPE] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$CUTYPE,
$pValue[util::$CUTYPE] );
if( isset( $pValue[util::$MEMBER] ))
$attributes .= sprintf( $FMTKEYEQ,
util::$MEMBER ) .
self::getQuotedListItems( $pValue[util::$MEMBER] );
if( isset( $pValue[util::$ROLE] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$ROLE,
$pValue[util::$ROLE] );
if( isset( $pValue[util::$PARTSTAT] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$PARTSTAT,
$pValue[util::$PARTSTAT] );
if( isset( $pValue[util::$RSVP] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$RSVP,
$pValue[util::$RSVP] );
if( isset( $pValue[util::$DELEGATED_TO] ))
$attributes .= sprintf( $FMTKEYEQ,
util::$DELEGATED_TO ) .
self::getQuotedListItems( $pValue[util::$DELEGATED_TO] );
if( isset( $pValue[util::$DELEGATED_FROM] ))
$attributes .= sprintf( $FMTKEYEQ,
util::$DELEGATED_FROM ) .
self::getQuotedListItems( $pValue[util::$DELEGATED_FROM] );
if( isset( $pValue[util::$SENT_BY] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$SENT_BY,
$pValue[util::$SENT_BY] );
if( isset( $pValue[util::$CN] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$CN,
$pValue[util::$CN] );
if( isset( $pValue[util::$DIR] )) {
$delim = ( false === strpos( $pValue[util::$DIR], util::$QQ )) ? util::$QQ : null;
$attributes .= sprintf( $FMTDIREQ, util::$DIR,
$delim,
$pValue[util::$DIR],
$delim );
}
if( isset( $pValue[util::$LANGUAGE] ))
$attributes .= sprintf( $FMTKEYVALUE,
util::$LANGUAGE,
$pValue[util::$LANGUAGE] );
$xparams = [];
foreach( $pValue as $pLabel2 => $pValue2 ) {
if( ctype_digit( (string) $pLabel2 ))
$xparams[] = $pValue2;
elseif( ! in_array( $pLabel2, util::$ATTENDEEPARALLKEYS ))
$xparams[$pLabel2] = $pValue2;
}
if( empty( $xparams ))
continue;
ksort( $xparams, SORT_STRING );
foreach( $xparams as $pLabel2 => $pValue2 ) {
if( ctype_digit( (string) $pLabel2 ))
$attributes .= util::$SEMIC . $pValue2; // ??
else
$attributes .= sprintf( $FMTKEYVALUE, $pLabel2,
$pValue2 );
}
} // end foreach( $attendeePart )) as $pLabel => $pValue )
$output .= util::createElement( util::$ATTENDEE,
$attributes,
$content );
} // end foreach( $attendeeData as $ax => $attendeePart )
return $output;
}
/**
* Return string of comma-separated quoted array members
*
* @param array $list
* @return string
* @access private
* @static
*/
private static function getQuotedListItems( array $list ) {
static $FMTQVALUE = '"%s"';
static $FMTCOMMAQVALUE = ',"%s"';
$strList = null;
foreach( $list as $x => $v )
$strList .= ( 0 < $x )
? sprintf( $FMTCOMMAQVALUE, $v )
: sprintf( $FMTQVALUE, $v );
return $strList;
}
/**
* Return formatted output for calendar component property attendee
*
* @param array $params
* @param string $objName
* @param string $lang
* @return array
* @static
*/
public static function prepAttendeeParams( $params, $objName, $lang ) {
static $NONXPROPCOMPS = null;
if( is_null( $NONXPROPCOMPS ))
$NONXPROPCOMPS = [util::$LCVFREEBUSY, util::$LCVALARM];
$params2 = [];
if( is_array( $params )) {
$optArr = [];
$params = array_change_key_case( $params, CASE_UPPER );
foreach( $params as $pLabel => $optParamValue ) {
if( ! util::isXprefixed( $pLabel ) &&
in_array( $objName, $NONXPROPCOMPS ))
continue;
switch( $pLabel ) {
case util::$MEMBER:
case util::$DELEGATED_TO:
case util::$DELEGATED_FROM:
if( ! is_array( $optParamValue ))
$optParamValue = [$optParamValue];
foreach(( array_keys( $optParamValue )) as $px )
$optArr[$pLabel][] = self::calAddressCheck( $optParamValue[$px] );
break;
default:
if( util::$SENT_BY == $pLabel )
$optParamValue = self::calAddressCheck( $optParamValue );
else
$optParamValue = trim( $optParamValue, util::$QQ );
$params2[$pLabel] = $optParamValue;
break;
} // end switch( $pLabel.. .
} // end foreach( $params as $pLabel => $optParamValue )
foreach( $optArr as $pLabel => $pValue )
$params2[$pLabel] = $pValue;
} // end if( is_array($params ))
// remove defaults
util::existRem( $params2, util::$CUTYPE, util::$INDIVIDUAL );
util::existRem( $params2, util::$PARTSTAT, util::$NEEDS_ACTION );
util::existRem( $params2, util::$ROLE, util::$REQ_PARTICIPANT );
util::existRem( $params2, util::$RSVP, util::$false );
// check language setting
if( isset( $params2[util::$CN ] ) &&
! isset( $params2[util::$LANGUAGE ] ) &&
! empty( $lang ))
$params2[util::$LANGUAGE ] = $lang;
return $params2;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
/**
* iCalcreator geo support class
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
class utilGeo {
/**
* @var string GEO vars: output format for geo latitude and longitude (before rtrim) etc
* @access public
* @static
*/
public static $geoLatFmt = '%09.6f';
public static $geoLongFmt = '%8.6f';
public static $LATITUDE = 'latitude';
public static $LONGITUDE = 'longitude';
/**
* Return formatted geo output
*
* @param float $ll
* @param string $format
* @return string
* @access public
* @static
*/
public static function geo2str2( $ll, $format ) {
if( 0.0 < $ll )
$sign = util::$PLUS;
else
$sign = ( 0.0 > $ll ) ? util::$MINUS : null;
return rtrim( rtrim( $sign . sprintf( $format, abs( $ll )),
util::$ZERO ),
util::$DOT );
}
}

View File

@@ -0,0 +1,873 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
/**
* iCalcreator recur support class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.18 - 2017-06-14
*/
class utilRecur {
/**
* Static values for recurrence FREQuence
* @access private
* @static
*/
private static $DAILY = 'DAILY';
private static $WEEKLY = 'WEEKLY';
private static $MONTHLY = 'MONTHLY';
private static $YEARLY = 'YEARLY';
//private static $SECONDLY = 'SECONDLY';
//private static $MINUTELY = 'MINUTELY';
//private static $HOURLY = 'HOURLY';
private static $DAYNAMES = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
private static $YEARCNT_UP = 'yearcnt_up';
private static $YEARCNT_DOWN = 'yearcnt_down';
private static $MONTHDAYNO_UP = 'monthdayno_up';
private static $MONTHDAYNO_DOWN = 'monthdayno_down';
private static $MONTHCNT_DOWN = 'monthcnt_down';
private static $YEARDAYNO_UP = 'yeardayno_up';
private static $YEARDAYNO_DOWN = 'yeardayno_down';
private static $WEEKNO_UP = 'weekno_up';
private static $WEEKNO_DOWN = 'weekno_down';
private static $W = 'W';
/**
* Sort recur dates
* @param array $byDayA
* @param array $byDayB
* @return int
* @access private
* @static
*/
private static function recurBydaySort( $byDayA, $byDayB ) {
static $days = ['SU' => 0,
'MO' => 1,
'TU' => 2,
'WE' => 3,
'TH' => 4,
'FR' => 5,
'SA' => 6];
return ( $days[substr( $byDayA, -2 )] < $days[substr( $byDayB, -2 )] ) ? -1 : 1;
}
/**
* Return formatted output for calendar component property data value type recur
*
* @param string $recurlabel
* @param array $recurData
* @param bool $allowEmpty
* @return string
* @static
*/
public static function formatRecur( $recurlabel, $recurData, $allowEmpty ) {
static $FMTFREQEQ = 'FREQ=%s';
static $FMTDEFAULTEQ = ';%s=%s';
static $FMTOTHEREQ = ';%s=';
static $RECURBYDAYSORTER = null;
static $SP0 = '';
if( is_null( $RECURBYDAYSORTER ))
$RECURBYDAYSORTER = [get_class(), 'recurBydaySort'];
if( empty( $recurData ))
return null;
$output = null;
foreach( $recurData as $rx => $theRule ) {
if( empty( $theRule[util::$LCvalue] )) {
if( $allowEmpty )
$output .= util::createElement( $recurlabel );
continue;
}
$attributes = ( isset( $theRule[util::$LCparams] ))
? util::createParams( $theRule[util::$LCparams] )
: null;
$content1 = $content2 = null;
foreach( $theRule[util::$LCvalue] as $ruleLabel => $ruleValue ) {
$ruleLabel = strtoupper( $ruleLabel );
switch( $ruleLabel ) {
case util::$FREQ :
$content1 .= sprintf( $FMTFREQEQ, $ruleValue );
break;
case util::$UNTIL :
$parno = ( isset( $ruleValue[util::$LCHOUR] )) ? 7 : 3;
$content2 .= sprintf( $FMTDEFAULTEQ, util::$UNTIL,
util::date2strdate( $ruleValue,
$parno ));
break;
case util::$COUNT :
case util::$INTERVAL :
case util::$WKST :
$content2 .= sprintf( $FMTDEFAULTEQ, $ruleLabel, $ruleValue );
break;
case util::$BYDAY :
$byday = [$SP0];
$bx = 0;
foreach( $ruleValue as $bix => $bydayPart ) {
if( ! empty( $byday[$bx] ) && // new day
! ctype_digit( substr( $byday[$bx], -1 )))
$byday[++$bx] = $SP0;
if( ! is_array( $bydayPart )) // day without order number
$byday[$bx] .= (string) $bydayPart;
else { // day with order number
foreach( $bydayPart as $bix2 => $bydayPart2 )
$byday[$bx] .= (string) $bydayPart2;
}
} // end foreach( $ruleValue as $bix => $bydayPart )
if( 1 < count( $byday ))
usort( $byday, $RECURBYDAYSORTER );
$content2 .= sprintf( $FMTDEFAULTEQ, util::$BYDAY,
implode( util::$COMMA,
$byday ));
break;
default : // BYSECOND/BYMINUTE/BYHOUR/BYMONTHDAY/BYYEARDAY/BYWEEKNO/BYMONTH/BYSETPOS...
if( is_array( $ruleValue )) {
$content2 .= sprintf( $FMTOTHEREQ, $ruleLabel );
$content2 .= implode( util::$COMMA, $ruleValue );
}
else
$content2 .= sprintf( $FMTDEFAULTEQ, $ruleLabel, $ruleValue );
break;
} // end switch( $ruleLabel )
} // end foreach( $theRule[util::$LCvalue] )) as $ruleLabel => $ruleValue )
$output .= util::createElement( $recurlabel,
$attributes,
$content1 . $content2 );
} // end foreach( $recurData as $rx => $theRule )
return $output;
}
/**
* Convert input format for EXRULE and RRULE to internal format
*
* @param array $rexrule
* @return array
* @static
*/
public static function setRexrule( $rexrule ) {
static $BYSECOND = 'BYSECOND';
static $BYMINUTE = 'BYMINUTE';
static $BYHOUR = 'BYHOUR';
$input = [];
if( empty( $rexrule ))
return $input;
$rexrule = array_change_key_case( $rexrule, CASE_UPPER );
foreach( $rexrule as $rexruleLabel => $rexruleValue ) {
if( util::$UNTIL != $rexruleLabel )
$input[$rexruleLabel] = $rexruleValue;
else {
util::strDate2arr( $rexruleValue );
if( util::isArrayTimestampDate( $rexruleValue )) // timestamp, always date-time UTC
$input[$rexruleLabel] = util::timestamp2date( $rexruleValue, 7, util::$UTC );
elseif( util::isArrayDate( $rexruleValue )) { // date or UTC date-time
$parno = ( isset( $rexruleValue[util::$LCHOUR] ) ||
isset( $rexruleValue[4] )) ? 7 : 3;
$d = util::chkDateArr( $rexruleValue, $parno );
if(( 3 < $parno ) &&
isset( $d[util::$LCtz] ) &&
( util::$Z != $d[util::$LCtz] ) &&
util::isOffset( $d[util::$LCtz] )) {
$input[$rexruleLabel] = util::strDate2ArrayDate( sprintf( util::$YMDHISE,
(int) $d[util::$LCYEAR],
(int) $d[util::$LCMONTH],
(int) $d[util::$LCDAY],
(int) $d[util::$LCHOUR],
(int) $d[util::$LCMIN],
(int) $d[util::$LCSEC],
$d[util::$LCtz] ),
7 );
unset( $input[$rexruleLabel][util::$UNPARSEDTEXT] );
}
else
$input[$rexruleLabel] = $d;
}
elseif( 8 <= strlen( trim( $rexruleValue ))) { // ex. textual date-time 2006-08-03 10:12:18 => UTC
$input[$rexruleLabel] = util::strDate2ArrayDate( $rexruleValue );
unset( $input[$rexruleLabel][util::$UNPARSEDTEXT] );
}
if(( 3 < count( $input[$rexruleLabel] )) &&
! isset( $input[$rexruleLabel][util::$LCtz] ))
$input[$rexruleLabel][util::$LCtz] = util::$Z;
}
} // end foreach( $rexrule as $rexruleLabel => $rexruleValue )
/* set recurrence rule specification in rfc2445 order */
$input2 = [];
if( isset( $input[util::$FREQ] ))
$input2[util::$FREQ] = $input[util::$FREQ];
if( isset( $input[util::$UNTIL] ))
$input2[util::$UNTIL] = $input[util::$UNTIL];
elseif( isset( $input[util::$COUNT] ))
$input2[util::$COUNT] = $input[util::$COUNT];
if( isset( $input[util::$INTERVAL] ))
$input2[util::$INTERVAL] = $input[util::$INTERVAL];
if( isset( $input[$BYSECOND] ))
$input2[$BYSECOND] = $input[$BYSECOND];
if( isset( $input[$BYMINUTE] ))
$input2[$BYMINUTE] = $input[$BYMINUTE];
if( isset( $input[$BYHOUR] ))
$input2[$BYHOUR] = $input[$BYHOUR];
if( isset( $input[util::$BYDAY] )) {
if( ! is_array( $input[util::$BYDAY] )) // ensure upper case.. .
$input2[util::$BYDAY] = strtoupper( $input[util::$BYDAY] );
else {
foreach( $input[util::$BYDAY] as $BYDAYx => $BYDAYv ) {
if( 0 == strcasecmp( util::$DAY, $BYDAYx ))
$input2[util::$BYDAY][util::$DAY] = strtoupper( $BYDAYv );
elseif( ! is_array( $BYDAYv ))
$input2[util::$BYDAY][$BYDAYx] = $BYDAYv;
else {
foreach( $BYDAYv as $BYDAYx2 => $BYDAYv2 ) {
if( 0 == strcasecmp( util::$DAY, $BYDAYx2 ))
$input2[util::$BYDAY][$BYDAYx][util::$DAY] = strtoupper( $BYDAYv2 );
else
$input2[util::$BYDAY][$BYDAYx][$BYDAYx2] = $BYDAYv2;
}
}
}
}
} // end if( isset( $input[util::$BYDAY] ))
if( isset( $input[util::$BYMONTHDAY] ))
$input2[util::$BYMONTHDAY] = $input[util::$BYMONTHDAY];
if( isset( $input[util::$BYYEARDAY] ))
$input2[util::$BYYEARDAY] = $input[util::$BYYEARDAY];
if( isset( $input[util::$BYWEEKNO] ))
$input2[util::$BYWEEKNO] = $input[util::$BYWEEKNO];
if( isset( $input[util::$BYMONTH] ))
$input2[util::$BYMONTH] = $input[util::$BYMONTH];
if( isset( $input[util::$BYSETPOS] ))
$input2[util::$BYSETPOS] = $input[util::$BYSETPOS];
if( isset( $input[util::$WKST] ))
$input2[util::$WKST] = $input[util::$WKST];
return $input2;
}
/**
* Update array $result with dates based on a recur pattern
*
* If missing, UNTIL is set 1 year from startdate (emergency break)
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.21.11 - 2015-03-10
* @param array $result array to update, array([Y-m-d] => bool)
* @param array $recur pattern for recurrency (only value part, params ignored)
* @param mixed $wdate component start date, string / array / (datetime) obj
* @param mixed $fcnStart start date, string / array / (datetime) obj
* @param mixed $fcnEnd end date, string / array / (datetime) obj
* @static
* @todo BYHOUR, BYMINUTE, BYSECOND, WEEKLY at year end/start OR not at all
*/
public static function recur2date( & $result,
$recur,
$wdate,
$fcnStart,
$fcnEnd=false ) {
static $YEAR2DAYARR = ['YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY'];
static $SU = 'SU';
self::reFormatDate( $wdate );
$wdateYMD = sprintf( util::$YMD, $wdate[util::$LCYEAR],
$wdate[util::$LCMONTH],
$wdate[util::$LCDAY] );
$wdateHis = sprintf( util::$HIS, $wdate[util::$LCHOUR],
$wdate[util::$LCMIN],
$wdate[util::$LCSEC] );
$untilHis = $wdateHis;
self::reFormatDate( $fcnStart );
$fcnStartYMD = sprintf( util::$YMD, $fcnStart[util::$LCYEAR],
$fcnStart[util::$LCMONTH],
$fcnStart[util::$LCDAY] );
if( ! empty( $fcnEnd ))
self::reFormatDate( $fcnEnd );
else {
$fcnEnd = $fcnStart;
$fcnEnd[util::$LCYEAR] += 1;
}
$fcnEndYMD = sprintf( util::$YMD, $fcnEnd[util::$LCYEAR],
$fcnEnd[util::$LCMONTH],
$fcnEnd[util::$LCDAY] );
// echo "<b>recur _in_ comp</b> start ".implode('-',$wdate)." period start ".implode('-',$fcnStart)." period end ".implode('-',$fcnEnd)."<br>\n";
// echo 'recur='.str_replace( [PHP_EOL, ' '], null, var_export( $recur, true ))."<br> \n"; // test ###
if( ! isset( $recur[util::$COUNT] ) &&
! isset( $recur[util::$UNTIL] ))
$recur[util::$UNTIL] = $fcnEnd; // create break
if( isset( $recur[util::$UNTIL] )) {
foreach( $recur[util::$UNTIL] as $k => $v ) {
if( ctype_digit( $v ))
$recur[util::$UNTIL][$k] = (int) $v;
}
unset( $recur[util::$UNTIL][util::$LCtz] );
if( $fcnEnd > $recur[util::$UNTIL] ) {
$fcnEnd = $recur[util::$UNTIL]; // emergency break
$fcnEndYMD = sprintf( util::$YMD, $fcnEnd[util::$LCYEAR],
$fcnEnd[util::$LCMONTH],
$fcnEnd[util::$LCDAY] );
}
if( isset( $recur[util::$UNTIL][util::$LCHOUR] ))
$untilHis = sprintf( util::$HIS, $recur[util::$UNTIL][util::$LCHOUR],
$recur[util::$UNTIL][util::$LCMIN],
$recur[util::$UNTIL][util::$LCSEC] );
else
$untilHis = sprintf( util::$HIS, 23, 59, 59 );
// echo 'recurUNTIL='.str_replace( [PHP_EOL, ' '], '', var_export( $recur['UNTIL'], true )).", untilHis={$untilHis}<br> \n"; // test ###
} // end if( isset( $recur[util::$UNTIL] ))
// echo 'fcnEnd:'.$fcnEndYMD.$untilHis."<br>\n"; // test ###
if( $wdateYMD > $fcnEndYMD ) {
// echo 'recur out of date, '.implode('-',$wdate).', end='.implode('-',$fcnEnd)."<br>\n"; // test ###
return []; // nothing to do.. .
}
if( ! isset( $recur[util::$FREQ] )) // "MUST be specified.. ."
$recur[util::$FREQ] = self::$DAILY; // ??
$wkst = ( isset( $recur[util::$WKST] ) &&
( $SU == $recur[util::$WKST] )) ? 24*60*60 : 0; // ??
if( ! isset( $recur[util::$INTERVAL] ))
$recur[util::$INTERVAL] = 1;
$recurCount = ( ! isset( $recur[util::$BYSETPOS] )) ? 1 : 0; // DTSTART counts as the first occurrence
/* find out how to step up dates and set index for interval count */
$step = [];
if( self::$YEARLY == $recur[util::$FREQ] )
$step[util::$LCYEAR] = 1;
elseif( self::$MONTHLY == $recur[util::$FREQ] )
$step[util::$LCMONTH] = 1;
elseif( self::$WEEKLY == $recur[util::$FREQ] )
$step[util::$LCDAY] = 7;
else
$step[util::$LCDAY] = 1;
if( isset( $step[util::$LCYEAR] ) && isset( $recur[util::$BYMONTH] ))
$step = [util::$LCMONTH => 1];
if( empty( $step ) && isset( $recur[util::$BYWEEKNO] )) // ??
$step = [util::$LCDAY => 7];
if( isset( $recur[util::$BYYEARDAY] ) ||
isset( $recur[util::$BYMONTHDAY] ) ||
isset( $recur[util::$BYDAY] ))
$step = [util::$LCDAY => 1];
$intervalarr = [];
if( 1 < $recur[util::$INTERVAL] ) {
$intervalix = self::recurIntervalIx( $recur[util::$FREQ],
$wdate,
$wkst );
$intervalarr = [$intervalix => 0];
}
if( isset( $recur[util::$BYSETPOS] )) { // save start date + weekno
$bysetposymd1 = $bysetposymd2 = $bysetposw1 = $bysetposw2 = [];
if( is_array( $recur[util::$BYSETPOS] )) {
foreach( $recur[util::$BYSETPOS] as $bix => $bval )
$recur[util::$BYSETPOS][$bix] = (int) $bval;
}
else
$recur[util::$BYSETPOS] = [(int) $recur[util::$BYSETPOS]];
if( self::$YEARLY == $recur[util::$FREQ] ) {
$wdate[util::$LCMONTH] = $wdate[util::$LCDAY] = 1; // start from beginning of year
$wdateYMD = sprintf( util::$YMD, $wdate[util::$LCYEAR],
$wdate[util::$LCMONTH],
$wdate[util::$LCDAY] );
self::stepdate( $fcnEnd, $fcnEndYMD, [util::$LCYEAR => 1] ); // make sure to count last year
}
elseif( self::$MONTHLY == $recur[util::$FREQ] ) {
$wdate[util::$LCDAY] = 1; // start from beginning of month
$wdateYMD = sprintf( util::$YMD, $wdate[util::$LCYEAR],
$wdate[util::$LCMONTH],
$wdate[util::$LCDAY] );
self::stepdate( $fcnEnd, $fcnEndYMD, [util::$LCMONTH => 1] ); // make sure to count last month
}
else
self::stepdate( $fcnEnd, $fcnEndYMD, $step); // make sure to count whole last period
// echo "BYSETPOS endDat =".implode('-',$fcnEnd).' step='.var_export($step,true)."<br>\n"; // test ######
$bysetposWold = (int) date( self::$W,
mktime( 0,
0,
$wkst,
$wdate[util::$LCMONTH],
$wdate[util::$LCDAY],
$wdate[util::$LCYEAR] ));
$bysetposYold = $wdate[util::$LCYEAR];
$bysetposMold = $wdate[util::$LCMONTH];
$bysetposDold = $wdate[util::$LCDAY];
} // end if( isset( $recur[util::$BYSETPOS] ))
else
self::stepdate( $wdate, $wdateYMD, $step);
$year_old = null;
/* MAIN LOOP */
while( true ) {
// $txt = ( isset( $recur[util::$COUNT] )) ? '. recurCount : ' . $recurCount . ', COUNT : ' . $recur[util::$COUNT] : null; // test ###
// echo "recur start while:<b>{$wdateYMD}</b>, end:{$fcnEndYMD}{$txt}<br>\n"; // test ###
if( $wdateYMD.$wdateHis > $fcnEndYMD.$untilHis )
break;
if( isset( $recur[util::$COUNT] ) &&
( $recurCount >= $recur[util::$COUNT] ))
break;
if( $year_old != $wdate[util::$LCYEAR] ) { // $year_old=null 1:st time
$year_old = $wdate[util::$LCYEAR];
$daycnts = self::initDayCnts( $wdate, $recur, $wkst );
}
/* check interval */
if( 1 < $recur[util::$INTERVAL] ) {
/* create interval index */
$intervalix = self::recurIntervalIx( $recur[util::$FREQ],
$wdate,
$wkst );
/* check interval */
$currentKey = array_keys( $intervalarr );
$currentKey = end( $currentKey ); // get last index
if( $currentKey != $intervalix )
$intervalarr = [$intervalix => ( $intervalarr[$currentKey] + 1 )];
if(( $recur[util::$INTERVAL] != $intervalarr[$intervalix] ) &&
( 0 != $intervalarr[$intervalix] )) {
/* step up date */
// echo "skip: ".implode('-',$wdate)." ix=$intervalix old=$currentKey interval=".$intervalarr[$intervalix]."<br>\n"; // test ###
self::stepdate( $wdate, $wdateYMD, $step);
continue;
}
else // continue within the selected interval
$intervalarr[$intervalix] = 0;
// echo "cont: ".implode('-',$wdate)." ix=$intervalix old=$currentKey interval=".$intervalarr[$intervalix]."<br>\n"; // test ###
} // endif( 1 < $recur['INTERVAL'] )
$updateOK = true;
if( $updateOK && isset( $recur[util::$BYMONTH] ))
$updateOK = self::recurBYcntcheck( $recur[util::$BYMONTH],
$wdate[util::$LCMONTH],
( $wdate[util::$LCMONTH] - 13 ));
if( $updateOK && isset( $recur[util::$BYWEEKNO] ))
$updateOK = self::recurBYcntcheck( $recur[util::$BYWEEKNO],
$daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$WEEKNO_UP],
$daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$WEEKNO_DOWN] );
if( $updateOK && isset( $recur[util::$BYYEARDAY] ))
$updateOK = self::recurBYcntcheck( $recur[util::$BYYEARDAY],
$daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$YEARCNT_UP],
$daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$YEARCNT_DOWN] );
if( $updateOK && isset( $recur[util::$BYMONTHDAY] ))
$updateOK = self::recurBYcntcheck( $recur[util::$BYMONTHDAY],
$wdate[util::$LCDAY],
$daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$MONTHCNT_DOWN] );
// echo "efter BYMONTHDAY: ".implode('-',$wdate).' status: '; echo ($updateOK) ? 'true' : 'false'; echo "<br>\n"; // test ######
if( $updateOK && isset( $recur[util::$BYDAY] )) {
$updateOK = false;
$m = $wdate[util::$LCMONTH];
$d = $wdate[util::$LCDAY];
if( isset( $recur[util::$BYDAY][util::$DAY] )) { // single day, opt with year/month day order no
$daynoexists = $daynosw = $daynamesw = false;
if( $recur[util::$BYDAY][util::$DAY] == $daycnts[$m][$d][util::$DAY] )
$daynamesw = true;
if( isset( $recur[util::$BYDAY][0] )) {
$daynoexists = true;
if(( isset( $recur[util::$FREQ] ) &&
( $recur[util::$FREQ] == self::$MONTHLY )) ||
isset( $recur[util::$BYMONTH] ))
$daynosw = self::recurBYcntcheck( $recur[util::$BYDAY][0],
$daycnts[$m][$d][self::$MONTHDAYNO_UP],
$daycnts[$m][$d][self::$MONTHDAYNO_DOWN] );
elseif( isset( $recur[util::$FREQ] ) &&
( $recur[util::$FREQ] == self::$YEARLY ))
$daynosw = self::recurBYcntcheck( $recur[util::$BYDAY][0],
$daycnts[$m][$d][self::$YEARDAYNO_UP],
$daycnts[$m][$d][self::$YEARDAYNO_DOWN] );
}
if(( $daynoexists && $daynosw && $daynamesw ) ||
( ! $daynoexists && ! $daynosw && $daynamesw )) {
$updateOK = true;
// echo "m=$m d=$d day=".$daycnts[$m][$d][util::$DAY]." yeardayno_up=".$daycnts[$m][$d][self::$YEARDAYNO_UP]." daynoexists:$daynoexists daynosw:$daynosw daynamesw:$daynamesw updateOK:$updateOK<br>\n"; // test ###
}
// echo "m=$m d=$d day=".$daycnts[$m][$d][util::$DAY]." yeardayno_up=".$daycnts[$m][$d][self::$YEARDAYNO_UP]." daynoexists:$daynoexists daynosw:$daynosw daynamesw:$daynamesw updateOK:$updateOK<br>\n"; // test ###
}
else {
foreach( $recur[util::$BYDAY] as $bydayvalue ) {
$daynoexists = $daynosw = $daynamesw = false;
if( isset( $bydayvalue[util::$DAY] ) &&
( $bydayvalue[util::$DAY] == $daycnts[$m][$d][util::$DAY] ))
$daynamesw = true;
if( isset( $bydayvalue[0] )) {
$daynoexists = true;
if(( isset( $recur[util::$FREQ] ) &&
( $recur[util::$FREQ] == self::$MONTHLY )) ||
isset( $recur[util::$BYMONTH] ))
$daynosw = self::recurBYcntcheck( $bydayvalue['0'],
$daycnts[$m][$d][self::$MONTHDAYNO_UP],
$daycnts[$m][$d][self::$MONTHDAYNO_DOWN] );
elseif( isset( $recur[util::$FREQ] ) &&
( $recur[util::$FREQ] == self::$YEARLY ))
$daynosw = self::recurBYcntcheck( $bydayvalue['0'],
$daycnts[$m][$d][self::$YEARDAYNO_UP],
$daycnts[$m][$d][self::$YEARDAYNO_DOWN] );
}
// echo "daynoexists:$daynoexists daynosw:$daynosw daynamesw:$daynamesw<br>\n"; // test ###
if(( $daynoexists && $daynosw && $daynamesw ) ||
( ! $daynoexists && ! $daynosw && $daynamesw )) {
$updateOK = true;
break;
}
}
}
}
// echo "efter BYDAY: ".implode('-',$wdate).' status: '; echo ($updateOK) ? 'true' : 'false'; echo "<br>\n"; // test ###
/* check BYSETPOS */
if( $updateOK ) {
if( isset( $recur[util::$BYSETPOS] ) &&
( in_array( $recur[util::$FREQ], $YEAR2DAYARR))) {
if( isset( $recur[self::$WEEKLY] )) {
if( $bysetposWold == $daycnts[$wdate[util::$LCMONTH]][$wdate[util::$LCDAY]][self::$WEEKNO_UP] )
$bysetposw1[] = $wdateYMD;
else
$bysetposw2[] = $wdateYMD;
}
else {
if(( isset( $recur[util::$FREQ] ) &&
( self::$YEARLY == $recur[util::$FREQ] ) &&
( $bysetposYold == $wdate[util::$LCYEAR] )) ||
( isset( $recur[util::$FREQ] ) &&
( self::$MONTHLY == $recur[util::$FREQ] ) &&
(( $bysetposYold == $wdate[util::$LCYEAR] ) &&
( $bysetposMold == $wdate[util::$LCMONTH] ))) ||
( isset( $recur[util::$FREQ] ) &&
( self::$DAILY == $recur[util::$FREQ] ) &&
(( $bysetposYold == $wdate[util::$LCYEAR] ) &&
( $bysetposMold == $wdate[util::$LCMONTH]) &&
( $bysetposDold == $wdate[util::$LCDAY] )))) {
// echo "bysetposymd1[]=".date('Y-m-d H:i:s',$wdatets)."<br>\n"; // test ###
$bysetposymd1[] = $wdateYMD;
}
else {
// echo "bysetposymd2[]=".date('Y-m-d H:i:s',$wdatets)."<br>\n"; // test ###
$bysetposymd2[] = $wdateYMD;
}
} // end else
}
else {
if( checkdate((int) $wdate[util::$LCMONTH],
(int) $wdate[util::$LCDAY],
(int) $wdate[util::$LCYEAR] )) {
/* update result array if BYSETPOS is not set */
$recurCount++;
if( $fcnStartYMD <= $wdateYMD ) { // only output within period
$result[$wdateYMD] = true;
// echo "recur $wdateYMD, recurCount:{$recurCount}<br>\n"; // test ###
}
}
// else echo "recur, no date $wdateYMD<br>\n"; // test ###
$updateOK = false;
}
}
/* step up date */
self::stepdate( $wdate, $wdateYMD, $step);
/* check if BYSETPOS is set for updating result array */
if( $updateOK && isset( $recur[util::$BYSETPOS] )) {
$bysetpos = false;
if( isset( $recur[util::$FREQ] ) &&
( self::$YEARLY == $recur[util::$FREQ] ) &&
( $bysetposYold != $wdate[util::$LCYEAR] )) {
$bysetpos = true;
$bysetposYold = $wdate[util::$LCYEAR];
}
elseif( isset( $recur[util::$FREQ] ) &&
( self::$MONTHLY == $recur[util::$FREQ] &&
(( $bysetposYold != $wdate[util::$LCYEAR] ) ||
( $bysetposMold != $wdate[util::$LCMONTH] )))) {
$bysetpos = true;
$bysetposYold = $wdate[util::$LCYEAR];
$bysetposMold = $wdate[util::$LCMONTH];
}
elseif( isset( $recur[util::$FREQ] ) &&
( self::$WEEKLY == $recur[util::$FREQ] )) {
$weekno = (int) date( self::$W,
mktime( 0,
0,
$wkst,
$wdate[util::$LCMONTH],
$wdate[util::$LCDAY],
$wdate[util::$LCYEAR] ));
if( $bysetposWold != $weekno ) {
$bysetposWold = $weekno;
$bysetpos = true;
}
}
elseif( isset( $recur[util::$FREQ] ) &&
( self::$DAILY == $recur[util::$FREQ] ) &&
(( $bysetposYold != $wdate[util::$LCYEAR] ) ||
( $bysetposMold != $wdate[util::$LCMONTH] ) ||
( $bysetposDold != $wdate[util::$LCDAY] ))) {
$bysetpos = true;
$bysetposYold = $wdate[util::$LCYEAR];
$bysetposMold = $wdate[util::$LCMONTH];
$bysetposDold = $wdate[util::$LCDAY];
}
if( $bysetpos ) {
if( isset( $recur[util::$BYWEEKNO] )) {
$bysetposarr1 = & $bysetposw1;
$bysetposarr2 = & $bysetposw2;
}
else {
$bysetposarr1 = & $bysetposymd1;
$bysetposarr2 = & $bysetposymd2;
}
foreach( $recur[util::$BYSETPOS] as $ix ) {
if( 0 > $ix ) // both positive and negative BYSETPOS allowed
$ix = ( count( $bysetposarr1 ) + $ix + 1);
$ix--;
if( isset( $bysetposarr1[$ix] )) {
if( $fcnStartYMD <= $bysetposarr1[$ix] ) { // only output within period
// $testweekno = (int) date( $W, mktime( 0, 0, $wkst, (int) substr( $bysetposarr1[$ix], 4, 2 ), (int) substr( $bysetposarr1[$ix], 6, 2 ), (int) substr( $bysetposarr1[$ix], 0, 3 ))); // test ###
// echo " testYMD (weekno)=$bysetposarr1[$ix] ($testweekno)"; // test ###
$result[$bysetposarr1[$ix]] = true;
}
$recurCount++;
}
if( isset( $recur[util::$COUNT] ) && ( $recurCount >= $recur[util::$COUNT] ))
break;
}
// echo "<br>\n"; // test ###
$bysetposarr1 = $bysetposarr2;
$bysetposarr2 = [];
} // end if( $bysetpos )
} // end if( $updateOK && isset( $recur['BYSETPOS'] ))
} // end while( true )
// echo 'output='.str_replace( [PHP_EOL, ' '], '', var_export( $result, true ))."<br> \n"; // test ###
}
/**
* Checking BYDAY (etc) hits, recur2date help function
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.6.12 - 2011-01-03
* @param array $BYvalue
* @param int $upValue
* @param int $downValue
* @return bool
* @access private
* @static
*/
private static function recurBYcntcheck( $BYvalue, $upValue, $downValue ) {
if( is_array( $BYvalue ) &&
( in_array( $upValue, $BYvalue ) || in_array( $downValue, $BYvalue )))
return true;
elseif(( $BYvalue == $upValue ) || ( $BYvalue == $downValue ))
return true;
else
return false;
}
/**
* (re-)Calculate internal index, recur2date help function
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.6.12 - 2011-01-03
* @param string $freq
* @param array $date
* @param int $wkst
* @return bool
* @access private
* @static
*/
private static function recurIntervalIx( $freq, $date, $wkst ) {
/* create interval index */
switch( $freq ) {
case self::$YEARLY :
$intervalix = $date[util::$LCYEAR];
break;
case self::$MONTHLY :
$intervalix = $date[util::$LCYEAR] . util::$MINUS . $date[util::$LCMONTH];
break;
case self::$WEEKLY :
$intervalix = (int) date( self::$W,
mktime( 0,
0,
$wkst,
(int) $date[util::$LCMONTH],
(int) $date[util::$LCDAY],
(int) $date[util::$LCYEAR] ));
break;
case self::$DAILY :
default:
$intervalix = $date[util::$LCYEAR] .
util::$MINUS .
$date[util::$LCMONTH] .
util::$MINUS .
$date[util::$LCDAY];
break;
}
return $intervalix;
}
/**
* Return updated date, array and timpstamp
*
* @param array $date date to step
* @param string $dateYMD date YMD
* @param array $step default array( util::$LCDAY => 1 )
* @return void
* @access private
* @static
*/
private static function stepdate( & $date, & $dateYMD, $step=null ) {
static $t = 't';
if( is_null( $step ))
$step = [util::$LCDAY => 1];
if( ! isset( $date[util::$LCHOUR] ))
$date[util::$LCHOUR] = 0;
if( ! isset( $date[util::$LCMIN] ))
$date[util::$LCMIN] = 0;
if( ! isset( $date[util::$LCSEC] ))
$date[util::$LCSEC] = 0;
if( isset( $step[util::$LCDAY] ))
$mcnt = date( $t,
mktime( (int) $date[util::$LCHOUR],
(int) $date[util::$LCMIN],
(int) $date[util::$LCSEC],
(int) $date[util::$LCMONTH],
(int) $date[util::$LCDAY],
(int) $date[util::$LCYEAR] ));
foreach( $step as $stepix => $stepvalue )
$date[$stepix] += $stepvalue;
if( isset( $step[util::$LCMONTH] )) {
if( 12 < $date[util::$LCMONTH] ) {
$date[util::$LCYEAR] += 1;
$date[util::$LCMONTH] -= 12;
}
}
elseif( isset( $step[util::$LCDAY] )) {
if( $mcnt < $date[util::$LCDAY] ) {
$date[util::$LCDAY] -= $mcnt;
$date[util::$LCMONTH] += 1;
if( 12 < $date[util::$LCMONTH] ) {
$date[util::$LCYEAR] += 1;
$date[util::$LCMONTH] -= 12;
}
}
}
$dateYMD = sprintf( util::$YMD, (int) $date[util::$LCYEAR],
(int) $date[util::$LCMONTH],
(int) $date[util::$LCDAY] );
}
/**
* Return initiated $daycnts
*
* @param array $wdate
* @param array $recur
* @param int $wkst
* @return array
* @access private
* @static
*/
private static function initDayCnts( array $wdate, array $recur, $wkst ) {
$daycnts = [];
$yeardaycnt = [];
$yeardays = 0;
foreach( self::$DAYNAMES as $dn )
$yeardaycnt[$dn] = 0;
for( $m = 1; $m <= 12; $m++ ) { // count up and update up-counters
$daycnts[$m] = [];
$weekdaycnt = [];
foreach( self::$DAYNAMES as $dn )
$weekdaycnt[$dn] = 0;
$mcnt = date( 't', mktime( 0, 0, 0, $m, 1, $wdate[util::$LCYEAR] ));
for( $d = 1; $d <= $mcnt; $d++ ) {
$daycnts[$m][$d] = [];
if( isset( $recur[util::$BYYEARDAY] )) {
$yeardays++;
$daycnts[$m][$d][self::$YEARCNT_UP] = $yeardays;
}
if( isset( $recur[util::$BYDAY] )) {
$day = date( 'w', mktime( 0, 0, 0, $m, $d, $wdate[util::$LCYEAR] ));
$day = self::$DAYNAMES[$day];
$daycnts[$m][$d][util::$DAY] = $day;
$weekdaycnt[$day]++;
$daycnts[$m][$d][self::$MONTHDAYNO_UP] = $weekdaycnt[$day];
$yeardaycnt[$day]++;
$daycnts[$m][$d][self::$YEARDAYNO_UP] = $yeardaycnt[$day];
}
if( isset( $recur[util::$BYWEEKNO] ) ||
( $recur[util::$FREQ] == self::$WEEKLY ))
$daycnts[$m][$d][self::$WEEKNO_UP] = (int) date( self::$W,
mktime( 0,
0,
$wkst,
$m,
$d,
$wdate[util::$LCYEAR] ));
} // end for( $d = 1; $d <= $mcnt; $d++ )
} // end for( $m = 1; $m <= 12; $m++ )
$daycnt = 0;
$yeardaycnt = [];
if( isset( $recur[util::$BYWEEKNO] ) ||
( $recur[util::$FREQ] == self::$WEEKLY )) {
$weekno = null;
for( $d=31; $d > 25; $d-- ) { // get last weekno for year
if( ! $weekno )
$weekno = $daycnts[12][$d][self::$WEEKNO_UP];
elseif( $weekno < $daycnts[12][$d][self::$WEEKNO_UP] ) {
$weekno = $daycnts[12][$d][self::$WEEKNO_UP];
break;
}
}
}
for( $m = 12; $m > 0; $m-- ) { // count down and update down-counters
$weekdaycnt = [];
foreach( self::$DAYNAMES as $dn )
$yeardaycnt[$dn] = $weekdaycnt[$dn] = 0;
$monthcnt = 0;
$mcnt = date( 't', mktime( 0, 0, 0, $m, 1, $wdate[util::$LCYEAR] ));
for( $d = $mcnt; $d > 0; $d-- ) {
if( isset( $recur[util::$BYYEARDAY] )) {
$daycnt -= 1;
$daycnts[$m][$d][self::$YEARCNT_DOWN] = $daycnt;
}
if( isset( $recur[util::$BYMONTHDAY] )) {
$monthcnt -= 1;
$daycnts[$m][$d][self::$MONTHCNT_DOWN] = $monthcnt;
}
if( isset( $recur[util::$BYDAY] )) {
$day = $daycnts[$m][$d][util::$DAY];
$weekdaycnt[$day] -= 1;
$daycnts[$m][$d][self::$MONTHDAYNO_DOWN] = $weekdaycnt[$day];
$yeardaycnt[$day] -= 1;
$daycnts[$m][$d][self::$YEARDAYNO_DOWN] = $yeardaycnt[$day];
}
if( isset( $recur[util::$BYWEEKNO] ) ||
( $recur[util::$FREQ] == self::$WEEKLY ))
$daycnts[$m][$d][self::$WEEKNO_DOWN] = ( $daycnts[$m][$d][self::$WEEKNO_UP] - $weekno - 1 );
}
} // end for( $m = 12; $m > 0; $m-- )
return $daycnts;
}
/**
* Return a reformatted input date
*
* @param mixed $aDate
* @access private
* @static
*/
private static function reFormatDate( & $aDate ) {
static $YMDHIS2 = 'Y-m-d H:i:s';
switch( true ) {
case ( is_string( $aDate )) :
util::strDate2arr( $aDate );
break;
case ( util::isDateTimeClass( $aDate )) :
$aDate = $aDate->format( $YMDHIS2 );
util::strDate2arr( $aDate );
break;
default :
break;
}
foreach( $aDate as $k => $v ) {
if( ctype_digit( $v ))
$aDate[$k] = (int) $v;
}
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
use kigkonsult\iCalcreator\vcalendar;
/**
* iCalcreator redirect support class
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.6 - 2017-04-13
*/
class utilRedirect {
/**
* HTTP headers
*
* @var array $headers
* @access private
* @static
*/
private static $headers = ['Content-Encoding: gzip',
'Vary: *',
'Content-Length: %s',
'Content-Type: text/calendar; charset=utf-8',
'Content-Disposition: attachment; filename="%s"',
'Content-Disposition: inline; filename="%s"',
'Cache-Control: max-age=10'];
/**
* Return created, updated and/or parsed calendar, sending a HTTP redirect header.
*
* @param vcalendar $calendar
* @param bool $utf8Encode
* @param bool $gzip
* @param bool $cdType true : Content-Disposition: attachment... (default), false : ...inline...
* @return bool true on success, false on error
* @static
*/
public static function returnCalendar( vcalendar $calendar,
$utf8Encode=false,
$gzip=false,
$cdType=true ) {
static $ICR = 'iCr';
$filename = $calendar->getConfig( util::$FILENAME );
$output = $calendar->createCalendar();
if( $utf8Encode )
$output = utf8_encode( $output );
$fsize = null;
if( $gzip ) {
$output = gzencode( $output, 9 );
$fsize = strlen( $output );
header( self::$headers[0] );
header( self::$headers[1] );
}
else {
if( false !== ( $temp = tempnam( sys_get_temp_dir(), $ICR ))) {
if( false !== file_put_contents( $temp, $output ))
$fsize = @filesize( $temp );
unlink( $temp );
}
}
if( ! empty( $fsize ))
header( sprintf( self::$headers[2], $fsize ));
header( self::$headers[3] );
$cdType = ( $cdType ) ? 4 : 5;
header( sprintf( self::$headers[$cdType], $filename ));
header( self::$headers[6] );
echo $output;
return true;
}
/**
* If recent version of calendar file exists (default one hour), an HTTP redirect header is sent
*
* @param vcalendar $calendar
* @param int $timeout default 3600 sec
* @param bool $cdType true : Content-Disposition: attachment... (default), false : ...inline...
* @return bool true on success, false on error
* @static
*/
public static function useCachedCalendar( vcalendar $calendar,
$timeout=3600,
$cdType=true ) {
static $R = 'r';
if( false === ( $dirfile = $calendar->getConfig( util::$URL )))
$dirfile = $calendar->getConfig( util::$DIRFILE );
if( ! is_file( $dirfile ) || ! is_readable( $dirfile ))
return false;
if( time() - filemtime( $dirfile ) > $timeout )
return false;
clearstatcache();
$fsize = @filesize( $dirfile );
$filename = $calendar->getConfig( util::$FILENAME );
header( self::$headers[3] );
if( ! empty( $fsize ))
header( sprintf( self::$headers[2], $fsize ));
$cdType = ( $cdType ) ? 4 : 5;
header( sprintf( self::$headers[$cdType], $filename ));
header( self::$headers[6] );
if( false === ( $fp = @fopen( $dirfile, $R )))
return false;
fpassthru( $fp );
fclose( $fp );
return true;
}
}

View File

@@ -0,0 +1,533 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
/**
* iCalcreator EXDATE/RDATE support class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-04-04
*/
class utilRexdate {
/**
* Check (EXDATE/RDATE) date(-time) and params arrays for an opt. timezone
*
* If it is a DATE-TIME or DATE, updates $parno and (opt) $params)
* @param array $theDate date to check
* @param int $parno no of date parts (i.e. year, month.. .)
* @param array $params property parameters
* @access private
* @static
*/
private static function chkDateCfg( $theDate, & $parno, & $params ) {
$paramsValueIsDATE = util::isParamsValueSet( [util::$LCparams => $params],
util::$DATE );
switch( true ) {
case ( isset( $params[util::$TZID] )) :
$parno = 6;
break;
case ( $paramsValueIsDATE ) :
$params[util::$VALUE] = util::$DATE;
$parno = 3;
break;
default:
if( util::isParamsValueSet( [util::$LCparams => $params],
util::$PERIOD )) {
$params[util::$VALUE] = util::$PERIOD;
$parno = 7;
}
switch( true ) {
case ( is_array( $theDate )) :
if( isset( $theDate[util::$LCTIMESTAMP] ))
$tzid = ( isset( $theDate[util::$LCtz] ))
? $theDate[util::$LCtz] : null;
else
$tzid = ( isset( $theDate[util::$LCtz] ))
? $theDate[util::$LCtz] : ( 7 == count( $theDate )) ? end( $theDate ) : null;
if( ! empty( $tzid )) {
$parno = 7;
if( ! util::isOffset( $tzid ))
$params[util::$TZID] = $tzid; // save only timezone
}
elseif( ! $parno &&
( 3 == count( $theDate )) &&
$paramsValueIsDATE )
$parno = 3;
else
$parno = 6;
break;
default : // i.e. string
$date = trim((string) $theDate );
if( util::$Z == substr( $date, -1 ))
$parno = 7; // UTC DATE-TIME
elseif((( 8 == strlen( $date ) && ctype_digit( $date )) ||
( 11 >= strlen( $date )))
&& $paramsValueIsDATE )
$parno = 3;
$date = util::strDate2ArrayDate( $date, $parno );
unset( $date[util::$UNPARSEDTEXT] );
if( ! empty( $date[util::$LCtz] )) {
$parno = 7;
if( ! util::isOffset( $date[util::$LCtz] ))
$params[util::$TZID] = $date[util::$LCtz]; // save only timezone
}
elseif( empty( $parno ))
$parno = 6;
} // end switch( true )
if( isset( $params[util::$TZID] ))
$parno = 6;
break;
} // end switch( true )
return true;
}
/**
* Return formatted output for calendar component property data value type recur
*
* @param array $exdateData
* @param bool $allowEmpty
* @return string
* @static
*/
public static function formatExdate( $exdateData, $allowEmpty ) {
static $SORTER1 = ['kigkonsult\iCalcreator\vcalendarSortHandler',
'sortExdate1'];
static $SORTER2 = ['kigkonsult\iCalcreator\vcalendarSortHandler',
'sortExdate2'];
$output = null;
$exdates = [];
foreach(( array_keys( $exdateData )) as $ex ) {
$theExdate = $exdateData[$ex];
if( empty( $theExdate[util::$LCvalue] )) {
if( $allowEmpty )
$output .= util::createElement( util::$EXDATE );
continue;
}
if( 1 < count( $theExdate[util::$LCvalue] ))
usort( $theExdate[util::$LCvalue], $SORTER1 );
$exdates[] = $theExdate;
}
if( 1 < count( $exdates ))
usort( $exdates, $SORTER2 );
foreach(( array_keys( $exdates )) as $ex ) {
$theExdate = $exdates[$ex];
$content = $attributes = null;
foreach(( array_keys( $theExdate[util::$LCvalue] )) as $eix ) {
$exdatePart = $theExdate[util::$LCvalue][$eix];
$parno = count( $exdatePart );
$formatted = util::date2strdate( $exdatePart, $parno );
if( isset( $theExdate[util::$LCparams][util::$TZID] ))
$formatted = str_replace( util::$Z, null, $formatted);
if( 0 < $eix ) {
if( isset( $theExdate[util::$LCvalue][0][util::$LCtz] )) {
if( ctype_digit( substr( $theExdate[util::$LCvalue][0][util::$LCtz], -4 )) ||
( util::$Z == $theExdate[util::$LCvalue][0][util::$LCtz] )) {
if( util::$Z != substr( $formatted, -1 ))
$formatted .= util::$Z;
}
else
$formatted = str_replace( util::$Z, null, $formatted );
}
else
$formatted = str_replace( util::$Z, null, $formatted );
} // end if( 0 < $eix )
$content .= ( 0 < $eix ) ? util::$COMMA . $formatted : $formatted;
} // end foreach(( array_keys( $theExdate[util::$LCvalue]...
$output .= util::createElement( util::$EXDATE,
util::createParams( $theExdate[util::$LCparams] ),
$content );
} // end foreach(( array_keys( $exdates...
return $output;
}
/**
* Return prepared calendar component property exdate input
*
* @param array $exdates
* @param array $params
* @return array
* @static
*/
public static function prepInputExdate( $exdates, $params=null ) {
static $GMTUTCZARR = ['GMT', 'UTC', 'Z'];
$input = [util::$LCparams => util::setParams( $params,
util::$DEFAULTVALUEDATETIME )];
$toZ = ( isset( $input[util::$LCparams][util::$TZID] ) &&
in_array( strtoupper( $input[util::$LCparams][util::$TZID] ),
$GMTUTCZARR ))
? true : false;
/* ev. check 1:st date and save ev. timezone **/
self::chkDateCfg( reset( $exdates ), $parno, $input[util::$LCparams] );
util::existRem( $input[util::$LCparams],
util::$VALUE,
util::$DATE_TIME ); // remove default parameter
foreach(( array_keys( $exdates )) as $eix ) {
$theExdate = $exdates[$eix];
util::strDate2arr( $theExdate );
if( util::isArrayTimestampDate( $theExdate )) {
if( isset( $theExdate[util::$LCtz] ) &&
! util::isOffset( $theExdate[util::$LCtz] )) {
if( isset( $input[util::$LCparams][util::$TZID] ))
$theExdate[util::$LCtz] = $input[util::$LCparams][util::$TZID];
else
$input[util::$LCparams][util::$TZID] = $theExdate[util::$LCtz];
}
$exdatea = util::timestamp2date( $theExdate, $parno );
}
elseif( is_array( $theExdate )) {
$d = util::chkDateArr( $theExdate, $parno );
if( isset( $d[util::$LCtz] ) &&
( util::$Z != $d[util::$LCtz] ) &&
util::isOffset( $d[util::$LCtz] )) {
$strdate = sprintf( util::$YMDHISE, (int) $d[util::$LCYEAR],
(int) $d[util::$LCMONTH],
(int) $d[util::$LCDAY],
(int) $d[util::$LCHOUR],
(int) $d[util::$LCMIN],
(int) $d[util::$LCSEC],
$d[util::$LCtz] );
$exdatea = util::strDate2ArrayDate( $strdate, 7 );
unset( $exdatea[util::$UNPARSEDTEXT] );
}
else
$exdatea = $d;
}
elseif( 8 <= strlen( trim( $theExdate ))) { // ex. 2006-08-03 10:12:18
$exdatea = util::strDate2ArrayDate( $theExdate, $parno );
unset( $exdatea[util::$UNPARSEDTEXT] );
}
if( 3 == $parno )
unset( $exdatea[util::$LCHOUR],
$exdatea[util::$LCMIN],
$exdatea[util::$LCSEC],
$exdatea[util::$LCtz] );
elseif( isset( $exdatea[util::$LCtz] ))
$exdatea[util::$LCtz] = (string) $exdatea[util::$LCtz];
if( isset( $input[util::$LCparams][util::$TZID] ) ||
( isset( $exdatea[util::$LCtz] ) &&
! util::isOffset( $exdatea[util::$LCtz] )) ||
( isset( $input[util::$LCvalue][0] ) &&
( ! isset( $input[util::$LCvalue][0][util::$LCtz] ))) ||
( isset( $input[util::$LCvalue][0][util::$LCtz] ) &&
! util::isOffset( $input[util::$LCvalue][0][util::$LCtz] )))
unset( $exdatea[util::$LCtz] );
if( $toZ ) // time zone Z
$exdatea[util::$LCtz] = util::$Z;
$input[util::$LCvalue][] = $exdatea;
} // end foreach(( array_keys( $exdates...
if( 0 >= count( $input[util::$LCvalue] ))
return false;
if( 3 == $parno ) {
$input[util::$LCparams][util::$VALUE] = util::$DATE;
unset( $input[util::$LCparams][util::$TZID] );
}
if( $toZ ) // time zone Z
unset( $input[util::$LCparams][util::$TZID] );
return $input;
}
/**
* Return formatted output for calendar component property rdate
*
* @param array $rdateData
* @param bool $allowEmpty
* @param string $objName
* @return string
* @static
*/
public static function formatRdate( $rdateData, $allowEmpty, $objName ) {
static $SORTER1 = ['kigkonsult\iCalcreator\vcalendarSortHandler',
'sortRdate1'];
static $SORTER2 = ['kigkonsult\iCalcreator\vcalendarSortHandler',
'sortRdate2'];
$utcTime = ( in_array( $objName, util::$TZCOMPS )) ? true : false;
$output = null;
$rdates = [];
foreach(( array_keys( $rdateData )) as $rpix ) {
$theRdate = $rdateData[$rpix];
if( empty( $theRdate[util::$LCvalue] )) {
if( $allowEmpty )
$output .= util::createElement( util::$RDATE );
continue;
}
if( $utcTime )
unset( $theRdate[util::$LCparams][util::$TZID] );
if( 1 < count( $theRdate[util::$LCvalue] ))
usort( $theRdate[util::$LCvalue], $SORTER1 );
$rdates[] = $theRdate;
}
if( 1 < count( $rdates ))
usort( $rdates, $SORTER2 );
foreach(( array_keys( $rdates )) as $rpix ) {
$theRdate = $rdates[$rpix];
$attributes = util::createParams( $theRdate[util::$LCparams] );
$cnt = count( $theRdate[util::$LCvalue] );
$content = null;
$rno = 1;
foreach(( array_keys( $theRdate[util::$LCvalue] )) as $rix ) {
$rdatePart = $theRdate[util::$LCvalue][$rix];
$contentPart = null;
if( is_array( $rdatePart ) &&
util::isParamsValueSet( $theRdate, util::$PERIOD )) { // PERIOD
if( $utcTime )
unset( $rdatePart[0][util::$LCtz] );
$formatted = util::date2strdate( $rdatePart[0] ); // PERIOD part 1
if( $utcTime || !empty( $theRdate[util::$LCparams][util::$TZID] ))
$formatted = str_replace( util::$Z, null, $formatted);
$contentPart .= $formatted;
$contentPart .= '/';
$cnt2 = count( $rdatePart[1]);
if( array_key_exists( util::$LCYEAR, $rdatePart[1] )) {
if( array_key_exists( util::$LCHOUR, $rdatePart[1] ))
$cnt2 = 7; // date-time
else
$cnt2 = 3; // date
}
elseif( array_key_exists( util::$LCWEEK, $rdatePart[1] )) // duration
$cnt2 = 5;
if(( 7 == $cnt2 ) && // period= -> date-time
isset( $rdatePart[1][util::$LCYEAR] ) &&
isset( $rdatePart[1][util::$LCMONTH] ) &&
isset( $rdatePart[1][util::$LCDAY] )) {
if( $utcTime )
unset( $rdatePart[1][util::$LCtz] );
$formatted = util::date2strdate( $rdatePart[1] ); // PERIOD part 2
if( $utcTime || !empty( $theRdate[util::$LCparams][util::$TZID] ))
$formatted = str_replace( util::$Z, null, $formatted );
$contentPart .= $formatted;
}
else { // period= -> dur-time
$contentPart .= util::duration2str( $rdatePart[1] );
}
} // PERIOD end
else { // SINGLE date start
if( $utcTime )
unset( $rdatePart[util::$LCtz] );
$parno = ( util::isParamsValueSet( $theRdate, util::$DATE )) ? 3 : null;
$formatted = util::date2strdate( $rdatePart, $parno );
if( $utcTime || !empty( $theRdate[util::$LCparams][util::$TZID] ))
$formatted = str_replace( util::$Z, null, $formatted);
$contentPart .= $formatted;
}
$content .= $contentPart;
if( $rno < $cnt )
$content .= util::$COMMA;
$rno++;
} // end foreach(( array_keys( $theRdate[util::$LCvalue]...
$output .= util::createElement( util::$RDATE,
$attributes,
$content );
} // foreach(( array_keys( $rdates...
return $output;
}
/**
* Return prepared calendar component property rdate input
*
* @param array $rdates
* @param array $params
* @param string $objName
* @return array
* @static
*/
public static function prepInputRdate( $rdates, $params, $objName ) {
static $PREFIXARR = ['P', '+', '-'];
static $GMTUTCZARR = ['GMT', 'UTC', 'Z'];
$input = [util::$LCparams => util::setParams( $params,
util::$DEFAULTVALUEDATETIME )];
if( in_array( $objName, util::$TZCOMPS )) {
unset( $input[util::$LCparams][util::$TZID] );
$input[util::$LCparams][util::$VALUE] = util::$DATE_TIME;
}
$toZ = ( isset( $params[util::$TZID] ) &&
in_array( strtoupper( $params[util::$TZID] ),
$GMTUTCZARR ))
? true : false;
/* check if PERIOD, if not set */
if(( ! isset( $input[util::$LCparams][util::$VALUE] ) ||
( ! util::isParamsValueSet( $input, util::$DATE ) &&
! util::isParamsValueSet( $input, util::$PERIOD ))) &&
isset( $rdates[0] ) && is_array( $rdates[0] ) && ( 2 == count( $rdates[0] )) &&
isset( $rdates[0][0] ) && isset( $rdates[0][1] ) && ! isset( $rdates[0][util::$LCTIMESTAMP] ) &&
(( is_array( $rdates[0][0] ) && ( isset( $rdates[0][0][util::$LCTIMESTAMP] ) ||
util::isArrayDate( $rdates[0][0] ))) ||
( is_string( $rdates[0][0] ) && ( 8 <= strlen( trim( $rdates[0][0] ))))) &&
( is_array( $rdates[0][1] ) || ( is_string( $rdates[0][1] ) && ( 3 <= strlen( trim( $rdates[0][1] ))))))
$input[util::$LCparams][util::$VALUE] = util::$PERIOD;
/* check 1:st date, upd. $parno (opt) and save opt. timezone **/
$date = reset( $rdates );
if( isset( $input[util::$LCparams][util::$VALUE] ) &&
( util::$PERIOD == $input[util::$LCparams][util::$VALUE] )) // PERIOD
$date = reset( $date );
self::chkDateCfg( $date, $parno, $input[util::$LCparams] );
util::existRem( $input[util::$LCparams],
util::$VALUE,
util::$DATE_TIME ); // remove default
foreach( $rdates as $rpix => $theRdate ) {
$inputa = null;
util::strDate2arr( $theRdate );
if( is_array( $theRdate )) {
if( isset( $input[util::$LCparams][util::$VALUE] ) &&
( util::$PERIOD == $input[util::$LCparams][util::$VALUE] )) { // PERIOD
foreach( $theRdate as $rix => $rPeriod ) {
util::strDate2arr( $theRdate );
if( is_array( $rPeriod )) {
if( util::isArrayTimestampDate( $rPeriod )) { // timestamp
if( isset( $rPeriod[util::$LCtz] ) &&
! util::isOffset( $rPeriod[util::$LCtz] )) {
if( isset( $input[util::$LCparams][util::$TZID] ))
$rPeriod[util::$LCtz] = $input[util::$LCparams][util::$TZID];
else
$input[util::$LCparams][util::$TZID] = $rPeriod[util::$LCtz];
}
$inputab = util::timestamp2date( $rPeriod, $parno );
} // end if( util::isArrayTimestampDate( $rPeriod ))
elseif( util::isArrayDate( $rPeriod )) {
$d = ( 3 < count ( $rPeriod ))
? util::chkDateArr( $rPeriod, $parno )
: util::chkDateArr( $rPeriod, 6 );
if( isset( $d[util::$LCtz] ) &&
( util::$Z != $d[util::$LCtz] ) &&
util::isOffset( $d[util::$LCtz] )) {
$inputab = util::strDate2ArrayDate( sprintf( util::$YMDHISE,
(int) $d[util::$LCYEAR],
(int) $d[util::$LCMONTH],
(int) $d[util::$LCDAY],
(int) $d[util::$LCHOUR],
(int) $d[util::$LCMIN],
(int) $d[util::$LCSEC],
$d[util::$LCtz] ),
7 );
unset( $inputab[util::$UNPARSEDTEXT] );
}
else
$inputab = $d;
} // end elseif( util::isArrayDate( $rPeriod ))
elseif(( 1 == count( $rPeriod )) &&
( 8 <= strlen( reset( $rPeriod )))) { // text-date
$inputab = util::strDate2ArrayDate( reset( $rPeriod ), $parno );
unset( $inputab[util::$UNPARSEDTEXT] );
}
else // array format duration
$inputab = util::duration2arr( $rPeriod );
} // end if( is_array( $rPeriod ))
elseif(( 3 <= strlen( trim( $rPeriod ))) && // string format duration
( in_array( $rPeriod[0], $PREFIXARR ))) {
if( 'P' != $rPeriod[0] )
$rPeriod = substr( $rPeriod, 1 );
$inputab = util::durationStr2arr( $rPeriod );
}
elseif( 8 <= strlen( trim( $rPeriod ))) { // text date ex. 2006-08-03 10:12:18
$inputab = util::strDate2ArrayDate( $rPeriod, $parno );
unset( $inputab[util::$UNPARSEDTEXT] );
}
if(( 0 == $rpix ) && ( 0 == $rix )) {
if( isset( $inputab[util::$LCtz] ) &&
in_array( strtoupper( $inputab[util::$LCtz] ),
$GMTUTCZARR )) {
$inputab[util::$LCtz] = util::$Z;
$toZ = true;
}
}
else {
if( isset( $inputa[0][util::$LCtz] ) &&
( util::$Z == $inputa[0][util::$LCtz] ) &&
isset( $inputab[util::$LCYEAR] ))
$inputab[util::$LCtz] = util::$Z;
else
unset( $inputab[util::$LCtz] );
}
if( $toZ && isset( $inputab[util::$LCYEAR] ) )
$inputab[util::$LCtz] = util::$Z;
$inputa[] = $inputab;
} // end foreach( $theRdate as $rix => $rPeriod )
} // PERIOD end
elseif ( util::isArrayTimestampDate( $theRdate )) { // timestamp
if( isset( $theRdate[util::$LCtz] ) &&
! util::isOffset( $theRdate[util::$LCtz] )) {
if( isset( $input[util::$LCparams][util::$TZID] ))
$theRdate[util::$LCtz] = $input[util::$LCparams][util::$TZID];
else
$input[util::$LCparams][util::$TZID] = $theRdate[util::$LCtz];
}
$inputa = util::timestamp2date( $theRdate, $parno );
}
else { // date[-time]
$inputa = util::chkDateArr( $theRdate, $parno );
if( isset( $inputa[util::$LCtz] ) &&
( util::$Z != $inputa[util::$LCtz] ) &&
util::isOffset( $inputa[util::$LCtz] )) {
$inputa = util::strDate2ArrayDate( sprintf( util::$YMDHISE,
(int) $inputa[util::$LCYEAR],
(int) $inputa[util::$LCMONTH],
(int) $inputa[util::$LCDAY],
(int) $inputa[util::$LCHOUR],
(int) $inputa[util::$LCMIN],
(int) $inputa[util::$LCSEC],
$inputa[util::$LCtz] ),
7 );
unset( $inputa[util::$UNPARSEDTEXT] );
}
}
} // end if( is_array( $theRdate ))
elseif( 8 <= strlen( trim( $theRdate ))) { // text date ex. 2006-08-03 10:12:18
$inputa = util::strDate2ArrayDate( $theRdate, $parno );
unset( $inputa[util::$UNPARSEDTEXT] );
if( $toZ )
$inputa[util::$LCtz] = util::$Z;
}
if( ! isset( $input[util::$LCparams][util::$VALUE] ) ||
( util::$PERIOD != $input[util::$LCparams][util::$VALUE] )) { // no PERIOD
if(( 0 == $rpix ) && !$toZ )
$toZ = ( isset( $inputa[util::$LCtz] ) &&
in_array( strtoupper( $inputa[util::$LCtz] ), $GMTUTCZARR ))
? true : false;
if( $toZ )
$inputa[util::$LCtz] = util::$Z;
if( 3 == $parno )
unset( $inputa[util::$LCHOUR],
$inputa[util::$LCMIN],
$inputa[util::$LCSEC],
$inputa[util::$LCtz] );
elseif( isset( $inputa[util::$LCtz] ))
$inputa[util::$LCtz] = (string) $inputa[util::$LCtz];
if( isset( $input[util::$LCparams][util::$TZID] ) ||
( isset( $input[util::$LCvalue][0] ) &&
( ! isset( $input[util::$LCvalue][0][util::$LCtz] ))))
if( !$toZ )
unset( $inputa[util::$LCtz] );
}
$input[util::$LCvalue][] = $inputa;
}
if( 3 == $parno ) {
$input[util::$LCparams][util::$VALUE] = util::$DATE;
unset( $input[util::$LCparams][util::$TZID] );
}
if( $toZ )
unset( $input[util::$LCparams][util::$TZID] );
return $input;
}
}

View File

@@ -0,0 +1,822 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator\util;
use kigkonsult\iCalcreator\vcalendar;
use kigkonsult\iCalcreator\calendarComponent;
use kigkonsult\iCalcreator\vcalendarSortHandler;
use kigkonsult\iCalcreator\iCaldateTime;
/**
* iCalcreator geo support class
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.6 - 2017-04-14
*/
class utilSelect {
/**
* Return selected components from calendar on date or selectOption basis
*
* DTSTART MUST be set for every component.
* No check of date.
* @param object $calendar
* @param mixed $startY (int) start Year, default current Year
* ALT. (obj) start date (datetime)
* ALT. array selecOptions ( *[ <propName> => <uniqueValue> ] )
* @param mixed $startM (int) start Month, default current Month
* ALT. (obj) end date (datetime)
* @param int $startD start Day, default current Day
* @param int $endY end Year, default $startY
* @param int $endM end Month, default $startM
* @param int $endD end Day, default $startD
* @param mixed $cType calendar component type(-s), default false=all else string/array type(-s)
* @param bool $flat false (default) => output : array[Year][Month][Day][]
* true => output : array[] (ignores split)
* @param bool $any true (default) - select component(-s) that occurs within period
* false - only component(-s) that starts within period
* @param bool $split 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 mixed array on success, bool false on error
* @static
*/
public static function selectComponents( vcalendar $calendar,
$startY=null,
$startM=null,
$startD=null,
$endY=null,
$endM=null,
$endD=null,
$cType=null,
$flat=null,
$any=null,
$split=null ) {
static $Y = 'Y';
static $M = 'm';
static $D = 'd';
static $STRTOLOWER = 'strtolower';
static $P1D = 'P1D';
static $DTENDEXIST = 'dtendExist';
static $DUEEXIST = 'dueExist';
static $DURATIONEXIST = 'durationExist';
static $ENDALLDAYEVENT = 'endAllDayEvent';
static $MINUS1DAY = '-1 day';
static $RANGE = 'RANGE';
static $THISANDFUTURE = 'THISANDFUTURE';
static $YMDHIS2 = 'Y-m-d H:i:s';
static $PRA = '%a';
static $YMD2 = 'Y-m-d';
static $DAYOFDAYS = 'day %d of %d';
static $SORTER = ['kigkonsult\iCalcreator\vcalendarSortHandler',
'cmpfcn'];
/* check if empty calendar */
if( 1 > $calendar->countComponents())
return false;
if( is_array( $startY ))
return self::selectComponents2( $calendar, $startY );
/* check default dates */
if( util::isDateTimeClass( $startY ) &&
util::isDateTimeClass( $startM )) {
$endY = $startM->format( $Y );
$endM = $startM->format( $M );
$endD = $startM->format( $D );
$startD = $startY->format( $D );
$startM = $startY->format( $M );
$startY = $startY->format( $Y );
}
else {
if( empty( $startY )) $startY = date( $Y );
if( empty( $startM )) $startM = date( $M );
if( empty( $startD )) $startD = date( $D );
if( empty( $endY )) $endY = $startY;
if( empty( $endM )) $endM = $startM;
if( empty( $endD )) $endD = $startD;
}
/* check component types */
if( empty( $cType ))
$cType = util::$VCOMPS;
else {
if( ! is_array( $cType ))
$cType = [$cType];
$cType = array_map( $STRTOLOWER, $cType );
foreach( $cType as $cix => $theType ) {
if( ! in_array( $theType, util::$VCOMPS ))
$cType[$cix] = util::$LCVEVENT;
}
$cType = array_unique( $cType );
}
$flat = ( is_null( $flat )) ? false : (bool) $flat; // defaults
$any = ( is_null( $any )) ? true : (bool) $any;
$split = ( is_null( $split )) ? true : (bool) $split;
if(( false === $flat ) && ( false === $any )) // invalid combination
$split = false;
if(( true === $flat ) && ( true === $split )) // invalid combination
$split = false;
// echo " args={$startY}-{$startM}-{$startD} - {$endY}-{$endM}-{$endD}, flat={$flat}, any={$any}, split={$split}<br>\n"; $tcnt = 0;// test ###
/* iterate components */
$result = [];
$calendar->sort( util::$UID );
$compUIDcmp = null;
$exdatelist = $recurrIdList = [];
$INTERVAL_P1D = new \DateInterval( $P1D );
// echo ' comp ix : ' . implode( ',', ( array_keys( $calendar->components ))) . "<br>\n"; // test ###
$cix = -1;
while( $component = $calendar->getComponent()) {
$cix += 1;
if( empty( $component ))
continue;
/* deselect unvalid type components */
if( ! in_array( $component->objName, $cType ))
continue;
unset( $compStart, $compEnd );
/* select start from dtstart or due if dtstart is missing */
$prop = $component->getProperty( util::$DTSTART,
false,
true );
if( empty( $prop ) &&
( $component->objName == util::$LCVTODO ) &&
( false === ( $prop = $component->getProperty( util::$DUE,
false,
true ))))
continue;
if( empty( $prop ))
continue;
/* get UID */
$compUID = $component->getProperty( util::$UID );
// echo 'START comp(' . $cix . ') ' . $component->objName . ', UID:' . $compUID . "<br>\n"; // test ###
if( $compUIDcmp != $compUID ) {
$compUIDcmp = $compUID;
$exdatelist = $recurrIdList = [];
}
// echo "#$cix".PHP_EOL.var_export( $component, true ) . "\n"; // test ###
$compStart = iCaldateTime::factory( $prop[util::$LCvalue],
$prop[util::$LCparams],
$prop[util::$LCvalue] );
$dtstartTz = $compStart->getTimezoneName();
if( util::isParamsValueSet( $prop, util::$DATE ))
$compStartHis = null;
else {
$his = $compStart->getTime();
$compStartHis = sprintf( util::$HIS, (int) $his[0],
(int) $his[1],
(int) $his[2] );
}
/* get end date from dtend/due/duration properties */
if( false !== ( $prop = $component->getProperty( util::$DTEND,
false,
true ))) {
$compEnd = iCaldateTime::factory( $prop[util::$LCvalue],
$prop[util::$LCparams],
$prop[util::$LCvalue],
$dtstartTz );
$compEnd->SCbools[$DTENDEXIST] = true;
}
if( empty( $prop ) &&
( $component->objName == util::$LCVTODO ) &&
( false !== ( $prop = $component->getProperty( util::$DUE,
false,
true )))) {
$compEnd = iCaldateTime::factory( $prop[util::$LCvalue],
$prop[util::$LCparams],
$prop[util::$LCvalue],
$dtstartTz );
$compEnd->SCbools[$DUEEXIST] = true;
}
if( empty( $prop ) &&
( false !== ( $prop = $component->getProperty( util::$DURATION,
false,
true,
true )))) {
$compEnd = iCaldateTime::factory( $prop[util::$LCvalue], // in dtend (array) format
$prop[util::$LCparams],
$prop[util::$LCvalue],
$dtstartTz );
$compEnd->SCbools[$DURATIONEXIST] = true;
}
if( ! empty( $prop ) && ! isset( $prop[util::$LCvalue][util::$LCHOUR] )) {
/* a DTEND without time part denotes an end of an event that actually ends the day before,
for an all-day event DTSTART=20071201 DTEND=20071202, taking place 20071201!!! */
$compEnd->SCbools[$ENDALLDAYEVENT] = true;
$compEnd->modify( $MINUS1DAY );
$compEnd->setTime( 23, 59, 59 );
}
unset( $prop );
if( empty( $compEnd )) {
$compDuration = false;
$compEnd = clone $compStart;
$compEnd->setTime( 23, 59, 59 ); // 23:59:59 the same day as start
}
else {
if( $compEnd->format( $YMD2 ) < $compStart->format( $YMD2 )) { // MUST be after start date!!
$compEnd = clone $compStart;
$compEnd->setTime( 23, 59, 59 ); // 23:59:59 the same day as start or ???
}
$compDuration = $compStart->diff( $compEnd ); // DateInterval
}
/* check recurrence-id (note, a missing sequence is the same as sequence=0
so don't test for sequence), to alter when hit in dtstart/recurlist */
$recurrid = null;
if( false !== ( $prop = $component->getProperty( util::$RECURRENCE_ID,
false,
true ))) {
$recurrid = iCaldateTime::factory( $prop[util::$LCvalue],
$prop[util::$LCparams],
$prop[util::$LCvalue],
$dtstartTz );
$rangeSet = ( isset( $prop[util::$LCparams][$RANGE] ) &&
( $THISANDFUTURE == $prop[util::$LCparams][$RANGE] ))
? true : false;
$recurrIdList[$recurrid->key] = [clone $compStart,
clone $compEnd,
$compDuration,
$rangeSet]; // change recur this day to new YmdHis/duration/range
// echo "adding comp no:$cix with date=".$compStart->format('Y-m-d H:i:s e')." to recurrIdList id={$recurrid->key}, newDate={$compStart->key}<br>\n"; // test ###
unset( $prop );
continue; // ignore any other props in the component
} // end recurrence-id/sequence test
// else echo "comp no:$cix with date=".$compStart->format().", NO recurrence-id<br>\n"; // test ###
ksort( $recurrIdList, SORT_STRING );
// echo 'recurrIdList='.implode(', ', array_keys( $recurrIdList ))."<br>\n"; // test ###
$fcnStart = clone $compStart;
$fcnStart->setDate((int) $startY, (int) $startM, (int) $startD );
$fcnStart->setTime( 0, 0, 0 );
$fcnEnd = clone $compEnd;
$fcnEnd->setDate((int) $endY, (int) $endM, (int) $endD );
$fcnEnd->setTime( 23, 59, 59 );
/* make a list of optional exclude dates for component occurence
from exrule and exdate */
$workStart = clone $compStart;
$workStart->sub( $compDuration ? $compDuration : $INTERVAL_P1D );
$workEnd = clone $fcnEnd;
$workEnd->add( $compDuration ? $compDuration : $INTERVAL_P1D );
// echo 'compStart/end:'.$compStart->format( 'YmdHis e' ).' - ' . $compEnd->format( 'YmdHis e' )."<br>\n"; // test ###
// echo '.fcnStart/end:' .$fcnStart->format( 'YmdHis e' ).' - ' . $fcnEnd->format( 'YmdHis e' )."<br>\n"; // test ###
// echo 'workStart/end:'.$workStart->format( 'YmdHis e' ).' - ' . $workEnd->format( 'YmdHis e' )."<br>\n"; // test ###
self::getAllEXRULEdates( $component, $exdatelist,
$dtstartTz, $compStart, $workStart, $workEnd,
$compStartHis );
self::getAllEXDATEdates( $component, $exdatelist, $dtstartTz );
// echo 'exdatelist=' . implode(', ', array_keys( $exdatelist )) ."<br>\n"; // test ###
/* select only components within.. . */
$xRecurrence = 1;
if(( ! $any && self::inScope( $compStart, $fcnStart,
$compStart, $fcnEnd, $compStart->dateFormat )) || // (dt)start within the period
( $any && self::inScope( $fcnEnd, $compStart,
$fcnStart, $compEnd, $compStart->dateFormat ))) { // occurs within the period
/* add the selected component (WITHIN valid dates) to output array */
if( $flat ) { // any=true/false, ignores split
if( empty( $recurrid ))
$result[$compUID] = clone $component; // copy original to output (but not anyone with recurrence-id)
}
elseif( $split ) { // split the original component
// echo 'split comp:' . $compStart->format( 'Ymd His e' ) . ', fcn:'.$fcnStart->format( 'Ymd His e' )."<br>\n"; // test ###
if( $compStart->format( $YMDHIS2 ) < $fcnStart->format( $YMDHIS2 ))
$rstart = clone $fcnStart;
else
$rstart = clone $compStart;
if( $compEnd->format( $YMDHIS2 ) > $fcnEnd->format( $YMDHIS2 ))
$rend = clone $fcnEnd;
else
$rend = clone $compEnd;
// echo "going to test comp no:$cix, rstart=".$rstart->format( 'YmdHis e' )." (key={$rstart->key}), end=".$rend->format( 'YmdHis e' )."<br>\n"; // test ###
if( ! isset( $exdatelist[$rstart->key] )) { // not excluded in exrule/exdate
if( isset( $recurrIdList[$rstart->key] )) { // change start day to new YmdHis/duration
$k = $rstart->key;
// echo "recurrIdList HIT, key={$k}, recur Date=".$recurrIdList[$k][0]->key."<br>\n"; // test ###
$rstart = clone $recurrIdList[$k][0];
$startHis = $rstart->getTime();
$rend = clone $rstart;
if( false !== $recurrIdList[$k][2] )
$rend->add( $recurrIdList[$k][2] );
elseif( false !== $compDuration )
$rend->add( $compDuration );
$endHis = $rend->getTime();
unset( $recurrIdList[$k] );
}
else {
$startHis = $compStart->getTime();
$endHis = $compEnd->getTime();
}
//echo "_____testing comp no:$cix, rstart=".$rstart->format( 'YmdHis e' )." (key={$rstart->key}), end=".$rend->format( 'YmdHis e' )."<br>\n"; // test ###
$cnt = 0; // exclude any recurrence START date, found in exdatelist or recurrIdList but accept the reccurence-id comp itself
$occurenceDays = 1 + (int) $rstart->diff( $rend )->format( $PRA ); // count the days (incl start day)
while( $rstart->format( $YMD2 ) <= $rend->format( $YMD2 )) {
$cnt += 1;
if( 1 < $occurenceDays )
$component->setProperty( util::$X_OCCURENCE,
sprintf( $DAYOFDAYS, $cnt,
$occurenceDays ));
if( 1 < $cnt )
$rstart->setTime( 0, 0, 0 );
else {
$rstart->setTime( $startHis[0], $startHis[1], $startHis[2] );
$exdatelist[$rstart->key] = $compDuration; // make sure to exclude start day from the recurrence pattern
}
$component->setProperty( util::$X_CURRENT_DTSTART,
$rstart->format( $compStart->dateFormat ));
$xY = (int) $rstart->format( $Y );
$xM = (int) $rstart->format( $M );
$xD = (int) $rstart->format( $D );
if( false !== $compDuration ) {
$propName = ( isset( $compEnd->SCbools[$DUEEXIST] ))
? util::$X_CURRENT_DUE : util::$X_CURRENT_DTEND;
if( $cnt < $occurenceDays )
$rstart->setTime( 23, 59, 59 );
elseif(( $rstart->format( $YMD2 ) < $rend->format( $YMD2 )) &&
( '00' == $endHis[0] ) &&
( '00' == $endHis[1] ) &&
( '00' == $endHis[2] )) // end exactly at midnight
$rstart->setTime( 24, 0, 0 );
else
$rstart->setTime( $endHis[0], $endHis[1], $endHis[2] );
$component->setProperty( $propName,
$rstart->format( $compEnd->dateFormat ));
}
$result[$xY][$xM][$xD][$compUID] = clone $component; // copy to output
$rstart->add( $INTERVAL_P1D );
} // end while(( $rstart->format( 'Ymd' ) < $rend->format( 'Ymd' ))
unset( $cnt, $occurenceDays );
} // end if( ! isset( $exdatelist[$rstart->key] ))
// else echo "skip no:$cix with date=".$compStart->format()."<br>\n"; // test ###
unset( $rstart, $rend );
} // end elseif( $split ) - else use component date
else { // !$flat && !$split, i.e. no flat array and DTSTART within period
$tstart = ( isset( $recurrIdList[$compStart->key] ))
? clone $recurrIdList[$compStart->key][0] : clone $compStart;
// echo "going to test comp no:$cix with checkDate={$compStart->key} with recurrIdList=".implode(',',array_keys($recurrIdList)); // test ###
if( ! $any || ! isset( $exdatelist[$tstart->key] )) { // exclude any recurrence date, found in exdatelist
// echo " and copied to output<br>\n"; // test ###
$xY = (int) $tstart->format( $Y );
$xM = (int) $tstart->format( $M );
$xD = (int) $tstart->format( $D );
$result[$xY][$xM][$xD][$compUID] = clone $component; // copy to output
}
unset( $tstart );
}
} // end (dt)start within the period OR occurs within the period
/* *************************************************************
if 'any' components, check components with reccurrence rules, removing all excluding dates
*********************************************************** */
if( true === $any ) {
$recurlist = [];
/* make a list of optional repeating dates for component occurence, rrule, rdate */
self::getAllRRULEdates( $component, $recurlist,
$dtstartTz, $compStart, $workStart, $workEnd,
$compStartHis, $exdatelist, $compDuration );
// echo 'recurlist rrule=' .implode(', ', array_keys( $recurlist )) ."<br>\n"; // test ###
$workStart = clone $fcnStart;
$workStart->sub( $compDuration ? $compDuration : $INTERVAL_P1D );
self::getAllRDATEdates( $component, $recurlist,
$dtstartTz, $workStart, $fcnEnd, $compStart->dateFormat,
$exdatelist, $compStartHis, $compDuration );
unset( $workStart, $rend );
foreach( $recurrIdList as $rKey => $rVal ) { // check for recurrence-id, i.e. alter recur Ymd[His] and duration
if( isset( $recurlist[$rKey] )) {
unset( $recurlist[$rKey] );
$recurlist[$rVal[0]->key] = ( false !== $rVal[2] )
? $rVal[2] : $compDuration;
// echo "alter recurfrom {$rKey} to {$rVal[0]->key} ";if(false!==$dur)echo " ({$dur->format( '%a days, %h-%i-%s' )})";echo "<br>\n"; // test ###
}
}
ksort( $recurlist, SORT_STRING );
// echo 'recurlist rrule/rdate=' .implode(', ', array_keys( $recurlist )) ."<br>\n"; // test ###
// echo 'recurrIdList=' .implode(', ', array_keys( $recurrIdList )) ."<br>\n"; // test ###
/* output all remaining components in recurlist */
if( 0 < count( $recurlist )) {
$component2 = clone $component;
$compUID = $component2->getProperty( util::$UID );
$workStart = clone $fcnStart;
$workStart->sub( $compDuration ? $compDuration : $INTERVAL_P1D );
$YmdOld = null;
foreach( $recurlist as $recurkey => $durvalue ) {
if( $YmdOld == substr( $recurkey, 0, 8 )) // skip overlapping recur the same day, i.e. RDATE before RRULE
continue;
$YmdOld = substr( $recurkey, 0, 8 );
$rstart = clone $compStart;
$rstart->setDate((int) substr( $recurkey, 0, 4 ),
(int) substr( $recurkey, 4, 2 ),
(int) substr( $recurkey, 6, 2 ));
$rstart->setTime((int) substr( $recurkey, 8, 2 ),
(int) substr( $recurkey, 10, 2 ),
(int) substr( $recurkey, 12, 2 ));
// echo "recur start=".$rstart->format( 'Y-m-d H:i:s e' )."<br>\n"; // test ###;
/* add recurring components within valid dates to output array, only start date set */
if( $flat ) {
if( ! isset( $result[$compUID] )) // only one comp
$result[$compUID] = clone $component2; // copy to output
}
/* add recurring components within valid dates to output array, split for each day */
elseif( $split ) {
$rend = clone $rstart;
if( false !== $durvalue )
$rend->add( $durvalue );
if( $rend->format( $YMD2 ) > $fcnEnd->format( $YMD2 ))
$rend = clone $fcnEnd;
$endHis = $rend->getTime();
// echo "recur 1={$recurkey}, start=".$rstart->format( 'YmdHis e' ).", end=".$rend->format( util::$YMDHISE );if($durvalue) echo ", duration=".$durvalue->format( '%a days, %h hours, %i min, %s sec' );echo "<br>\n"; // test ###
$xRecurrence += 1;
$cnt = 0;
$occurenceDays = 1 + (int) $rstart->diff( $rend )->format( $PRA ); // count the days (incl start day)
while( $rstart->format( $YMD2 ) <= $rend->format( $YMD2 )) { // iterate.. .
$cnt += 1;
if( $rstart->format( $YMD2 ) < $fcnStart->format( $YMD2 )) { // date before dtstart
// echo "recur 3, start=".$rstart->format( 'YmdHis e' )." &gt;= fcnStart=".$fcnStart->format( 'YmdHis e' )."<br>\n"; // test ###
$rstart->add( $INTERVAL_P1D ); // cycle rstart to dtstart
$rstart->setTime( 0, 0, 0 );
continue;
}
elseif( 2 == $cnt )
$rstart->setTime( 0, 0, 0 );
$component2->setProperty( util::$X_RECURRENCE,
$xRecurrence );
if( 1 < $occurenceDays )
$component2->setProperty( util::$X_OCCURENCE,
sprintf( $DAYOFDAYS, $cnt, $occurenceDays ));
else
$component2->deleteProperty( util::$X_OCCURENCE );
$component2->setProperty( util::$X_CURRENT_DTSTART,
$rstart->format( $compStart->dateFormat ));
$xY = (int) $rstart->format( $Y );
$xM = (int) $rstart->format( $M );
$xD = (int) $rstart->format( $D );
$propName = ( isset( $compEnd->SCbools[$DUEEXIST] ))
? util::$X_CURRENT_DUE : util::$X_CURRENT_DTEND;
if( false !== $durvalue ) {
if( $cnt < $occurenceDays )
$rstart->setTime( 23, 59, 59 );
elseif(( $rstart->format( $YMD2 ) < $rend->format( $YMD2 )) &&
( '00' == $endHis[0] ) && ( '00' == $endHis[1] ) && ( '00' == $endHis[2] )) // end exactly at midnight
$rstart->setTime( 24, 0, 0 );
else
$rstart->setTime( $endHis[0], $endHis[1], $endHis[2] );
$component2->setProperty( $propName,
$rstart->format( $compEnd->dateFormat ));
// echo "checking date, (day {$cnt} of {$occurenceDays}), _end_=".$rstart->format( 'YmdHis e' )."<br>"; // test ###;
}
else
$component2->deleteProperty( $propName );
$result[$xY][$xM][$xD][$compUID] = clone $component2; // copy to output
$rstart->add( $INTERVAL_P1D );
} // end while( $rstart->format( 'Ymd' ) <= $rend->format( 'Ymd' ))
unset( $rstart, $rend );
} // end elseif( $split )
elseif( $rstart->format( $YMD2 ) >= $fcnStart->format( $YMD2 )) {
$xRecurrence += 1; // date within period, flat=false && split=false => one comp every recur startdate
$component2->setProperty( util::$X_RECURRENCE,
$xRecurrence );
$component2->setProperty( util::$X_CURRENT_DTSTART,
$rstart->format( $compStart->dateFormat ));
$propName = ( isset( $compEnd->SCbools[$DUEEXIST] ))
? util::$X_CURRENT_DUE : util::$X_CURRENT_DTEND;
if( false !== $durvalue ) {
$rstart->add( $durvalue );
$component2->setProperty( $propName,
$rstart->format( $compEnd->dateFormat ));
}
else
$component2->deleteProperty( $propName );
$xY = (int) $rstart->format( $Y );
$xM = (int) $rstart->format( $M );
$xD = (int) $rstart->format( $D );
$result[$xY][$xM][$xD][$compUID] = clone $component2; // copy to output
} // end elseif( $rstart >= $fcnStart )
unset( $rstart );
} // end foreach( $recurlist as $recurkey => $durvalue )
unset( $component2, $xRecurrence, $compUID, $workStart, $rstart );
} // end if( 0 < count( $recurlist ))
} // end if( true === $any )
unset( $component );
} // end while( $component = $calendar->getComponent())
if( 0 >= count( $result ))
return false;
elseif( ! $flat ) {
foreach( $result as $y => $yList ) {
foreach( $yList as $m => $mList ) {
foreach( $mList as $d => $dList ) {
if( empty( $dList ))
unset( $result[$y][$m][$d] );
else {
$result[$y][$m][$d] = array_values( $dList ); // skip tricky UID-index
if( 1 < count( $result[$y][$m][$d] )) {
foreach( $result[$y][$m][$d] as $cix => $d2List ) // sort
vcalendarSortHandler::setSortArgs( $result[$y][$m][$d][$cix] );
usort( $result[$y][$m][$d], $SORTER );
}
}
} // end foreach( $mList as $d => $dList )
if( empty( $result[$y][$m] ))
unset( $result[$y][$m] );
else
ksort( $result[$y][$m] );
} // end foreach( $yList as $m => $mList )
if( empty( $result[$y] ))
unset( $result[$y] );
else
ksort( $result[$y] );
} // end foreach( $result as $y => $yList )
if( empty( $result ))
unset( $result );
else
ksort( $result );
} // end elseif( !$flat )
if( 0 >= count( $result ))
return false;
return $result;
}
/**
* Return bool true if dates are in scope
*
* @param iCaldateTime $start
* @param iCaldateTime $scopeStart
* @param iCaldateTime $end
* @param iCaldateTime $scopeEnd
* @param string $format
* @return bool
* @access private
* @static
*/
private static function inScope( iCaldateTime $start,
iCaldateTime $scopeStart,
iCaldateTime $end,
iCaldateTime $scopeEnd,
$format ) {
return (( $start->format( $format ) >= $scopeStart->format( $format )) &&
( $end->format( $format ) <= $scopeEnd->format( $format )));
}
/**
* Get all EXRULE dates (multiple values allowed)
*
* @param calendarComponent $component
* @param array $exdatelist
* @param string $dtstartTz
* @param iCaldateTime $compStart
* @param iCaldateTime $workStart
* @param iCaldateTime $workEnd
* @param string $compStartHis
*/
private static function getAllEXRULEdates( calendarComponent $component,
array & $exdatelist,
$dtstartTz,
iCaldateTime $compStart,
iCaldateTime $workStart,
iCaldateTime $workEnd,
$compStartHis ) {
while( false !== ( $prop = $component->getProperty( util::$EXRULE ))) {
$exdatelist2 = [];
if( isset( $prop[util::$UNTIL][util::$LCHOUR] )) { // convert UNTIL date to DTSTART timezone
$until = iCaldateTime::factory( $prop[util::$UNTIL],
[util::$TZID => util::$UTC],
null,
$dtstartTz );
$until = $until->format();
util::strDate2arr( $until );
$prop[util::$UNTIL] = $until;
}
utilRecur::recur2date( $exdatelist2,
$prop,
$compStart,
$workStart,
$workEnd );
foreach( $exdatelist2 as $k => $v ) // point out exact every excluded ocurrence (incl. opt. His)
$exdatelist[$k.$compStartHis] = $v;
unset( $until, $exdatelist2 );
}
return true;
}
/**
* Get all EXDATE dates (multiple values allowed)
*
* @param calendarComponent $component
* @param array $exdatelist
* @param string $dtstartTz
*/
private static function getAllEXDATEdates( calendarComponent $component,
array & $exdatelist,
$dtstartTz ) {
while( false !== ( $prop = $component->getProperty( util::$EXDATE,
false,
true ))) {
foreach( $prop[util::$LCvalue] as $exdate ) {
$exdate = iCaldateTime::factory( $exdate,
$prop[util::$LCparams],
$exdate,
$dtstartTz );
$exdatelist[$exdate->key] = true;
} // end - foreach( $exdate as $exdate )
}
return true;
}
/**
* Update $recurlist all RRULE dates (multiple values allowed)
*
* @param calendarComponent $component
* @param array $recurlist
* @param string $dtstartTz
* @param iCaldateTime $compStart
* @param iCaldateTime $workStart
* @param iCaldateTime $workEnd
* @param string $compStartHis
* @param array $exdatelist
* @param object $compDuration
*/
private static function getAllRRULEdates( calendarComponent $component,
array & $recurlist,
$dtstartTz,
iCaldateTime $compStart,
iCaldateTime$workStart,
iCaldateTime $workEnd,
$compStartHis,
array $exdatelist,
$compDuration ) {
while( false !== ( $prop = $component->getProperty( util::$RRULE ))) {
$recurlist2 = [];
if( isset( $prop[util::$UNTIL][util::$LCHOUR] )) { // convert RRULE['UNTIL'] to the same timezone as DTSTART !!
$until = iCaldateTime::factory( $prop[util::$UNTIL],
[util::$TZID => util::$UTC],
null,
$dtstartTz );
$until = $until->format();
util::strDate2arr( $until );
$prop[util::$UNTIL] = $until;
}
utilRecur::recur2date( $recurlist2,
$prop,
$compStart,
$workStart,
$workEnd );
foreach( $recurlist2 as $recurkey => $recurvalue ) { // recurkey=Ymd
$recurkey .= $compStartHis; // add opt His
if( ! isset( $exdatelist[$recurkey] ))
$recurlist[$recurkey] = $compDuration; // DateInterval or false
}
unset( $prop, $until, $recurlist2 );
}
return true;
}
/**
* Update $recurlist with RDATE dates (multiple values allowed)
*
* @param calendarComponent $component
* @param array $recurlist
* @param string $dtstartTz
* @param iCaldateTime $workStart
* @param iCaldateTime $fcnEnd
* @param string $format
* @param array $exdatelist
* @param string $compStartHis
* @param object $compDuration
*/
private static function getAllRDATEdates( calendarComponent $component,
array & $recurlist,
$dtstartTz,
iCaldateTime $workStart,
iCaldateTime $fcnEnd,
$format,
array $exdatelist,
$compStartHis,
$compDuration ) {
while( false !== ( $prop = $component->getProperty( util::$RDATE,
false,
true ))) {
$rdateFmt = ( isset( $prop[util::$LCparams][util::$VALUE] ))
? $prop[util::$LCparams][util::$VALUE]
: util::$DATE_TIME;
$params = $prop[util::$LCparams];
$prop = $prop[util::$LCvalue];
foreach( $prop as $rix => $theRdate ) {
if( util::$PERIOD == $rdateFmt ) { // all days within PERIOD
$rdate = iCaldateTime::factory( $theRdate[0],
$params,
$theRdate[0],
$dtstartTz );
if( ! self::inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) ||
isset( $exdatelist[$rdate->key] ))
continue;
if( isset( $theRdate[1][util::$LCYEAR] )) // date-date period end
$recurlist[$rdate->key] = $rdate->diff( iCaldateTime::factory( $theRdate[1],
$params,
$theRdate[1],
$dtstartTz ));
else // period duration
$recurlist[$rdate->key] = new \DateInterval( util::duration2str( $theRdate[1] ));
} // end if( util::$PERIOD == $rdateFmt )
elseif( util::$DATE == $rdateFmt ) { // single recurrence, DATE
$rdate = iCaldateTime::factory( $theRdate,
array_merge( $params,
[util::$TZID => $dtstartTz] ),
null,
$dtstartTz );
if( self::inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) &&
! isset( $exdatelist[$rdate->key] )) // set start date for recurrence + DateInterval/false (+opt His)
$recurlist[$rdate->key.$compStartHis] = $compDuration;
} // end DATE
else { // start DATETIME
$rdate = iCaldateTime::factory( $theRdate,
$params,
$theRdate,
$dtstartTz );
if( self::inScope( $rdate, $workStart, $rdate, $fcnEnd, $format ) &&
! isset( $exdatelist[$rdate->key] ))
$recurlist[$rdate->key] = $compDuration; // set start datetime for recurrence DateInterval/false
} // end DATETIME
} // end foreach( $prop as $rix => $theRdate )
} // end while( false !== ( $prop = $component->getProperty( util::$RDATE, false, true )))
return true;
}
/**
* Return array with selected components values from calendar based on specific property value(-s)
*
* @param vcalendar $calendar
* @param array $selectOptions (string) key => (mixed) value, (key=propertyName)
* @return array
* @access private
* @static
*/
private static function selectComponents2( vcalendar $calendar,
array $selectOptions ) {
$output = [];
$selectOptions = array_change_key_case( $selectOptions, CASE_UPPER );
while( $component3 = $calendar->getComponent()) {
if( empty( $component3 ))
continue;
if( ! in_array( $component3->objName, util::$VCOMPS ))
continue;
$uid = $component3->getProperty( util::$UID );
foreach( $selectOptions as $propName => $pValue ) {
if( ! in_array( $propName, util::$OTHERPROPS ))
continue;
if( ! is_array( $pValue ))
$pValue = [$pValue];
if(( util::$UID == $propName ) && in_array( $uid, $pValue )) {
$output[$uid][] = $component3;
continue;
}
elseif( in_array( $propName, util::$MPROPS1 )) {
$propValues = [];
$component3->getProperties( $propName, $propValues );
$propValues = array_keys( $propValues );
foreach( $pValue as $theValue ) {
if( in_array( $theValue, $propValues )) { // && ! isset( $output[$uid] )) {
$output[$uid][] = $component3;
break;
}
}
continue;
} // end elseif( // multiple occurrence?
elseif( false === ( $d = $component3->getProperty( $propName ))) // single occurrence
continue;
if( is_array( $d )) {
foreach( $d as $part ) {
if( in_array( $part, $pValue ) && ! isset( $output[$uid] ))
$output[$uid][] = $component3;
}
}
elseif(( util::$SUMMARY == $propName ) && ! isset( $output[$uid] )) {
foreach( $pValue as $pval ) {
if( false !== stripos( $d, $pval )) {
$output[$uid][] = $component3;
break;
}
}
}
elseif( in_array( $d, $pValue ) && ! isset( $output[$uid] ))
$output[$uid][] = $component3;
} // end foreach( $selectOptions as $propName => $pValue )
} // end while( $component3 = $calendar->getComponent()) {
if( ! empty( $output )) {
ksort( $output ); // uid order
$output2 = [];
foreach( $output as $uid => $uList ) {
foreach( $uList as $cx => $uValue )
$output2[] = $uValue;
}
$output = $output2;
}
return $output;
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VALARM component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
class valarm extends calendarComponent {
use traits\ACTIONtrait,
traits\ATTACHtrait,
traits\ATTENDEEtrait,
traits\DESCRIPTIONtrait,
traits\DURATIONtrait,
traits\REPEATtrait,
traits\SUMMARYtrait,
traits\TRIGGERtrait;
/**
* Constructor for calendar component VALARM object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-02-01
* @param array $config
*/
public function __construct( $config = []) {
static $A = 'a';
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$this->cno = $A . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-18
*/
public function __destruct() {
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->propix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->action,
$this->attach,
$this->attendee,
$this->description,
$this->duration,
$this->repeat,
$this->summary,
$this->trigger );
}
/**
* Return formatted output for calendar component VALARM object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.5.1 - 2008-10-22
* @return string
*/
public function createComponent() {
$objectname = strtoupper( $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createAction();
$component .= $this->createAttach();
$component .= $this->createAttendee();
$component .= $this->createDescription();
$component .= $this->createDuration();
$component .= $this->createRepeat();
$component .= $this->createSummary();
$component .= $this->createTrigger();
$component .= $this->createXprop();
return $component . sprintf( util::$FMTEND, $objectname );
}
/**
* Return valarm component property value/params,
*
* If arg $inclParam, return array with keys VALUE/PARAMS.
* @param string $propName
* @param int $propix specific property in case of multiply occurences
* @param bool $inclParam
* @param bool $specform
* @return mixed
*/
public function getProperty( $propName=false,
$propix=false,
$inclParam=false,
$specform=false ) {
switch( strtoupper( $propName )) {
case util::$ACTION:
if( isset( $this->action[util::$LCvalue] ))
return ( $inclParam ) ? $this->action
: $this->action[util::$LCvalue];
break;
case util::$REPEAT:
if( isset( $this->repeat[util::$LCvalue] ))
return ( $inclParam ) ? $this->repeat
: $this->repeat[util::$LCvalue];
break;
case util::$TRIGGER:
if( isset( $this->trigger[util::$LCvalue] ))
return ( $inclParam ) ? $this->trigger
: $this->trigger[util::$LCvalue];
break;
default:
return parent::getProperty( $propName,
$propix,
$inclParam,
$specform );
break;
}
return false;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,299 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator vcalendarSortHandler class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.9 - 2017-04-22
*/
class vcalendarSortHandler {
/**
* vcalendar sort callback function
*
* @since 2.23.9 - 2017-04-20
* @param calendarComponent $a
* @param calendarComponent $b
* @return int
* @static
*/
public static function cmpfcn( calendarComponent $a, calendarComponent $b ) {
if( empty( $a )) return -1;
if( empty( $b )) return 1;
if( util::$LCVTIMEZONE == $a->objName ) {
if( util::$LCVTIMEZONE != $b->objName ) return -1;
elseif( $a->srtk[0] <= $b->srtk[0] ) return -1;
else return 1;
}
elseif( util::$LCVTIMEZONE == $b->objName ) return 1;
for( $k = 0; $k < 4 ; $k++ ) {
if( empty( $a->srtk[$k] )) return -1;
elseif( empty( $b->srtk[$k] )) return 1;
$sortStat = strcmp( $a->srtk[$k], $b->srtk[$k] );
if( 0 == $sortStat )
continue;
return ( 0 < $sortStat ) ? 1 : -1;
}
return 0;
}
/**
* Set sort arguments/parameters in component
*
* @since 2.23.19 - 2017-04-22
* @param calendarComponent $c valendar component
* @param string $sortArg
* @static
*/
public static function setSortArgs( calendarComponent $c, $sortArg=null ) {
static $INITARR = ['0', '0', '0', '0'];
$c->srtk = $INITARR;
if( util::$LCVTIMEZONE == $c->objName ) {
if( false === ( $c->srtk[0] = $c->getProperty( util::$TZID )))
$c->srtk[0] = 0;
return;
}
elseif( ! is_null( $sortArg )) {
if( in_array( $sortArg, util::$MPROPS1 )) { // all string
$propValues = [];
$c->getProperties( $sortArg, $propValues );
if( ! empty( $propValues )) {
$c->srtk[0] = key( array_slice( $propValues, 0, 1, TRUE ));
if( util::$RELATED_TO == $sortArg )
$c->srtk[0] .= $c->getProperty( util::$UID );
}
elseif( util::$RELATED_TO == $sortArg )
$c->srtk[0] = $c->getProperty( util::$UID );
} // end if( in_array( $sortArg, util::$MPROPS1 ))
elseif( false !== ( $d = $c->getProperty( $sortArg ))) {
$c->srtk[0] = ( util::isArrayDate( $d )) ? self::arrDate2str( $d ) : $d;
if( util::$UID == $sortArg ) {
if( false !== ( $d = $c->getProperty( util::$RECURRENCE_ID ))) {
$c->srtk[1] = self::arrDate2str( $d );
if( false === ( $c->srtk[2] = $c->getProperty( util::$SEQUENCE )))
$c->srtk[2] = PHP_INT_MAX;
}
else
$c->srtk[1] = $c->srtk[2] = PHP_INT_MAX;
} // end if( util::$UID == $sortArg )
} // end elseif( false !== ( $d = $c->getProperty( $sortArg )))
return;
} // end elseif( $sortArg )
switch( true ) { // sortkey 0 : dtstart
case ( false !== ( $d = $c->getProperty( util::$X_CURRENT_DTSTART ))) :
$c->srtk[0] = self::arrDate2str( util::strDate2ArrayDate( $d[1] ));
break;
case ( false !== ( $d = $c->getProperty( util::$DTSTART ))) :
$c->srtk[0] = self::arrDate2str( $d );
break;
}
switch( true ) { // sortkey 1 : dtend/due(/duration)
case ( false !== ( $d = $c->getProperty( util::$X_CURRENT_DTEND ))) :
$c->srtk[1] = self::arrDate2str( util::strDate2ArrayDate( $d[1] ));
break;
case ( false !== ( $d = $c->getProperty( util::$DTEND ))) :
$c->srtk[1] = self::arrDate2str( $d );
break;
case ( false !== ( $d = $c->getProperty( util::$X_CURRENT_DUE ))) :
$c->srtk[1] = self::arrDate2str( util::strDate2ArrayDate( $d[1] ));
break;
case ( false !== ( $d = $c->getProperty( util::$DUE ))) :
$c->srtk[1] = self::arrDate2str( $d );
break;
case ( false !== ( $d = $c->getProperty( util::$DURATION, false, false, true ))) :
$c->srtk[1] = self::arrDate2str( $d );
break;
}
switch( true ) { // sortkey 2 : created/dtstamp
case ( false !== ( $d = $c->getProperty( util::$CREATED ))) :
$c->srtk[2] = self::arrDate2str( $d );
break;
case ( false !== ( $d = $c->getProperty( util::$DTSTAMP ))) :
$c->srtk[2] = self::arrDate2str( $d );
break;
}
// sortkey 3 : uid
if( false === ( $c->srtk[3] = $c->getProperty( util::$UID )))
$c->srtk[3] = 0;
}
/**
* Return formatted string from (array) date/datetime
*
* @param array $aDate
* @return string
* @access private
* @static
*/
private static function arrDate2str( array $aDate ) {
$str = sprintf( util::$YMD,
$aDate[util::$LCYEAR],
$aDate[util::$LCMONTH],
$aDate[util::$LCDAY] );
if( isset( $aDate[util::$LCHOUR] ))
$str .= sprintf( util::$HIS,
$aDate[util::$LCHOUR],
$aDate[util::$LCMIN],
$aDate[util::$LCSEC] );
if( isset( $aDate[util::$LCtz] ) && ! empty( $aDate[util::$LCtz] ))
$str .= $aDate[util::$LCtz];
return $str;
}
/**
* Sort callback function for exdate
*
* @param array $a
* @param array $b
* @return int
* @static
*/
public static function sortExdate1( array $a, array $b ) {
$as = sprintf( util::$YMD, (int) $a[util::$LCYEAR],
(int) $a[util::$LCMONTH],
(int) $a[util::$LCDAY] );
$as .= ( isset( $a[util::$LCHOUR] )) ? sprintf( util::$HIS, (int) $a[util::$LCHOUR],
(int) $a[util::$LCMIN],
(int) $a[util::$LCSEC] )
: null;
$bs = sprintf( util::$YMD, (int) $b[util::$LCYEAR],
(int) $b[util::$LCMONTH],
(int) $b[util::$LCDAY] );
$bs .= ( isset( $b[util::$LCHOUR] )) ? sprintf( util::$HIS, (int) $b[util::$LCHOUR],
(int) $b[util::$LCMIN],
(int) $b[util::$LCSEC] )
: null;
return strcmp( $as, $bs );
}
/**
* Sort callback function for exdate
*
* @param array $a
* @param array $b
* @return int
* @static
*/
public static function sortExdate2( array $a, array $b ) {
$val = reset( $a[util::$LCvalue] );
$as = sprintf( util::$YMD, (int) $val[util::$LCYEAR],
(int) $val[util::$LCMONTH],
(int) $val[util::$LCDAY] );
$as .= ( isset( $val[util::$LCHOUR] )) ? sprintf( util::$HIS, (int) $val[util::$LCHOUR],
(int) $val[util::$LCMIN],
(int) $val[util::$LCSEC] )
: null;
$val = reset( $b[util::$LCvalue] );
$bs = sprintf( util::$YMD, (int) $val[util::$LCYEAR],
(int) $val[util::$LCMONTH],
(int) $val[util::$LCDAY] );
$bs .= ( isset( $val[util::$LCHOUR] )) ? sprintf( util::$HIS, (int) $val[util::$LCHOUR],
(int) $val[util::$LCMIN],
(int) $val[util::$LCSEC] )
: null;
return strcmp( $as, $bs );
}
/**
* Sort callback function for freebusy and rdate, sort single property (inside values)
*
* @param array $a
* @param array $b
* @return int
* @static
*/
public static function sortRdate1( array $a, array $b ) {
$as = null;
if( isset( $a[util::$LCYEAR] ))
$as = self::formatdatePart( $a );
elseif( isset( $a[0][util::$LCYEAR] )) {
$as = self::formatdatePart( $a[0] );
$as .= self::formatdatePart( $a[1] );
}
else
return 1;
$bs = null;
if( isset( $b[util::$LCYEAR] ))
$bs = self::formatdatePart( $b );
elseif( isset( $b[0][util::$LCYEAR] )) {
$bs = self::formatdatePart( $b[0] );
$bs .= self::formatdatePart( $b[1] );
}
else
return -1;
return strcmp( $as, $bs );
}
/**
* Sort callback function for rdate, sort multiple RDATEs in order (after 1st datetime/date/period)
*
* @param array $a
* @param array $b
* @return int
* @static
*/
public static function sortRdate2( array $a, array $b ) {
$as = null;
if( isset( $a[util::$LCvalue][0][util::$LCYEAR] ))
$as = self::formatdatePart( $a[util::$LCvalue][0] );
elseif( isset( $a[util::$LCvalue][0][0][util::$LCYEAR] )) {
$as = self::formatdatePart( $a[util::$LCvalue][0][0] );
$as .= self::formatdatePart( $a[util::$LCvalue][0][1] );
}
else
return 1;
$bs = null;
if( isset( $b[util::$LCvalue][0][util::$LCYEAR] ))
$bs = self::formatdatePart( $b[util::$LCvalue][0] );
elseif( isset( $a[util::$LCvalue][0][0][util::$LCYEAR] )) {
$bs = self::formatdatePart( $b[util::$LCvalue][0][0] );
$bs .= self::formatdatePart( $b[util::$LCvalue][0][1] );
}
else
return -1;
return strcmp( $as, $bs );
}
/**
* Format date
*
* @param array $part
* @return string
*/
private static function formatdatePart( array $part ) {
if( isset( $part[util::$LCYEAR] )) {
$str = sprintf( util::$YMD, (int) $part[util::$LCYEAR],
(int) $part[util::$LCMONTH],
(int) $part[util::$LCDAY] );
$str .= ( isset( $part[util::$LCHOUR] )) ? sprintf( util::$HIS, (int) $part[util::$LCHOUR],
(int) $part[util::$LCMIN],
(int) $part[util::$LCSEC] )
: null;
}
else
$str = util::duration2str( $part );
return $str;
}
}

View File

@@ -0,0 +1,190 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VEVENT component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
class vevent extends calendarComponent {
use traits\ATTACHtrait,
traits\ATTENDEEtrait,
traits\CATEGORIEStrait,
traits\CLASStrait,
traits\COMMENTtrait,
traits\CONTACTtrait,
traits\CREATEDtrait,
traits\DESCRIPTIONtrait,
traits\DTENDtrait,
traits\DTSTAMPtrait,
traits\DTSTARTtrait,
traits\DURATIONtrait,
traits\EXDATEtrait,
traits\EXRULEtrait,
traits\GEOtrait,
traits\LAST_MODIFIEDtrait,
traits\LOCATIONtrait,
traits\ORGANIZERtrait,
traits\PRIORITYtrait,
traits\RDATEtrait,
traits\RECURRENCE_IDtrait,
traits\RELATED_TOtrait,
traits\REQUEST_STATUStrait,
traits\RESOURCEStrait,
traits\RRULEtrait,
traits\SEQUENCEtrait,
traits\STATUStrait,
traits\SUMMARYtrait,
traits\TRANSPtrait,
traits\UIDtrait,
traits\URLtrait;
/**
* Constructor for calendar component VEVENT object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-02-01
* @param array $config
*/
public function __construct( $config = []) {
static $E = 'e';
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$this->cno = $E . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-18
*/
public function __destruct() {
if( ! empty( $this->components ))
foreach( $this->components as $cix => $component )
$this->components[$cix]->__destruct();
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->compix,
$this->propix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->attach,
$this->attendee,
$this->categories,
$this->class,
$this->comment,
$this->contact,
$this->created,
$this->description,
$this->dtend,
$this->dtstamp,
$this->dtstart,
$this->duration,
$this->exdate,
$this->exrule,
$this->geo,
$this->lastmodified,
$this->location,
$this->organizer,
$this->priority,
$this->rdate,
$this->recurrenceid,
$this->relatedto,
$this->requeststatus,
$this->resources,
$this->rrule,
$this->sequence,
$this->status,
$this->summary,
$this->transp,
$this->uid,
$this->url );
}
/**
* Return formatted output for calendar component VEVENT object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.10.16 - 2011-10-28
* @return string
*/
public function createComponent() {
$objectname = strtoupper( $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createUid();
$component .= $this->createDtstamp();
$component .= $this->createAttach();
$component .= $this->createAttendee();
$component .= $this->createCategories();
$component .= $this->createComment();
$component .= $this->createContact();
$component .= $this->createClass();
$component .= $this->createCreated();
$component .= $this->createDescription();
$component .= $this->createDtstart();
$component .= $this->createDtend();
$component .= $this->createDuration();
$component .= $this->createExdate();
$component .= $this->createExrule();
$component .= $this->createGeo();
$component .= $this->createLastModified();
$component .= $this->createLocation();
$component .= $this->createOrganizer();
$component .= $this->createPriority();
$component .= $this->createRdate();
$component .= $this->createRrule();
$component .= $this->createRelatedTo();
$component .= $this->createRequestStatus();
$component .= $this->createRecurrenceid();
$component .= $this->createResources();
$component .= $this->createSequence();
$component .= $this->createStatus();
$component .= $this->createSummary();
$component .= $this->createTransp();
$component .= $this->createUrl();
$component .= $this->createXprop();
$component .= $this->createSubComponent();
return $component . sprintf( util::$FMTEND, $objectname );
}
/**
* Return valarm object instance, calendarComponent::newComponent() wrapper
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-06-26
* @return object
*/
public function newValarm() {
return $this->newComponent( util::$LCVALARM );
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VFREEBUSY component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-02
*/
class vfreebusy extends calendarComponent {
use traits\ATTENDEEtrait,
traits\COMMENTtrait,
traits\CONTACTtrait,
traits\DTENDtrait,
traits\DTSTAMPtrait,
traits\DTSTARTtrait,
traits\DURATIONtrait,
traits\FREEBUSYtrait,
traits\ORGANIZERtrait,
traits\REQUEST_STATUStrait,
traits\UIDtrait,
traits\URLtrait;
/**
* Constructor for calendar component VFREEBUSY object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-02-01
* @param array $config
*/
public function __construct( $config = []) {
static $F = 'f';
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$this->cno = $F . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-18
*/
public function __destruct() {
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->propix,
$this->compix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->attendee,
$this->comment,
$this->contact,
$this->dtend,
$this->dtstamp,
$this->dtstart,
$this->duration,
$this->freebusy,
$this->organizer,
$this->requeststatus,
$this->uid,
$this->url );
}
/**
* Return formatted output for calendar component VFREEBUSY object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.3.1 - 2007-11-19
* @return string
*/
public function createComponent() {
$objectname = strtoupper( $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createUid();
$component .= $this->createDtstamp();
$component .= $this->createAttendee();
$component .= $this->createComment();
$component .= $this->createContact();
$component .= $this->createDtstart();
$component .= $this->createDtend();
$component .= $this->createDuration();
$component .= $this->createFreebusy();
$component .= $this->createOrganizer();
$component .= $this->createRequestStatus();
$component .= $this->createUrl();
$component .= $this->createXprop();
return $component . sprintf( util::$FMTEND, $objectname );
}
}

View File

@@ -0,0 +1,155 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VJOURNAL component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-01
*/
class vjournal extends calendarComponent {
use traits\ATTACHtrait,
traits\ATTENDEEtrait,
traits\CATEGORIEStrait,
traits\CLASStrait,
traits\COMMENTtrait,
traits\CONTACTtrait,
traits\CREATEDtrait,
traits\DESCRIPTIONtrait,
traits\DTSTAMPtrait,
traits\DTSTARTtrait,
traits\EXDATEtrait,
traits\EXRULEtrait,
traits\LAST_MODIFIEDtrait,
traits\ORGANIZERtrait,
traits\RDATEtrait,
traits\RECURRENCE_IDtrait,
traits\RELATED_TOtrait,
traits\REQUEST_STATUStrait,
traits\RRULEtrait,
traits\SEQUENCEtrait,
traits\STATUStrait,
traits\SUMMARYtrait,
traits\UIDtrait,
traits\URLtrait;
/**
* Constructor for calendar component VJOURNAL object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.20 - 2017-02-01
* @param array $config
*/
public function __construct( $config = []) {
static $J = 'j';
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$this->cno = $J . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-18
*/
public function __destruct() {
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->compix,
$this->propix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->attach,
$this->attendee,
$this->categories,
$this->class,
$this->comment,
$this->contact,
$this->created,
$this->description,
$this->dtstamp,
$this->dtstart,
$this->exdate,
$this->exrule,
$this->lastmodified,
$this->organizer,
$this->rdate,
$this->recurrenceid,
$this->relatedto,
$this->requeststatus,
$this->rrule,
$this->sequence,
$this->status,
$this->summary,
$this->uid,
$this->url );
}
/**
* Return formatted output for calendar component VJOURNAL object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.5.1 - 2008-10-12
* @return string
*/
public function createComponent() {
$objectname = strtoupper( $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createUid();
$component .= $this->createDtstamp();
$component .= $this->createAttach();
$component .= $this->createAttendee();
$component .= $this->createCategories();
$component .= $this->createClass();
$component .= $this->createComment();
$component .= $this->createContact();
$component .= $this->createCreated();
$component .= $this->createDescription();
$component .= $this->createDtstart();
$component .= $this->createExdate();
$component .= $this->createExrule();
$component .= $this->createLastModified();
$component .= $this->createOrganizer();
$component .= $this->createRdate();
$component .= $this->createRequestStatus();
$component .= $this->createRecurrenceid();
$component .= $this->createRelatedTo();
$component .= $this->createRrule();
$component .= $this->createSequence();
$component .= $this->createStatus();
$component .= $this->createSummary();
$component .= $this->createUrl();
$component .= $this->createXprop();
return $component . sprintf( util::$FMTEND, $objectname );
}
}

View File

@@ -0,0 +1,195 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VTIMEZONE component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-01
*/
class vtimezone extends calendarComponent {
use traits\COMMENTtrait,
traits\DTSTARTtrait,
traits\LAST_MODIFIEDtrait,
traits\RDATEtrait,
traits\RRULEtrait,
traits\TZIDtrait,
traits\TZNAMEtrait,
traits\TZOFFSETFROMtrait,
traits\TZOFFSETTOtrait,
traits\TZURLtrait;
/**
* @var string $timezonetype vtimezone type value
* @access protected
*/
protected $timezonetype;
/**
* Constructor for calendar component VTIMEZONE object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-01
* @param mixed $timezonetype default false ( STANDARD / DAYLIGHT )
* @param array $config
*/
public function __construct( $timezonetype=null, $config = []) {
static $TZ = 'tz';
if( is_array( $timezonetype )) {
$config = $timezonetype;
$timezonetype = null;
}
$this->timezonetype = ( empty( $timezonetype ))
? util::$LCVTIMEZONE : strtolower( $timezonetype );
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$prf = ( empty( $timezonetype )) ? $TZ : substr( $timezonetype, 0, 1 );
$this->cno = $prf . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-17
*/
public function __destruct() {
if( ! empty( $this->components ))
foreach( $this->components as $cix => $component )
$this->components[$cix]->__destruct();
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->propix,
$this->compix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->comment,
$this->dtstart,
$this->lastmodified,
$this->rdate,
$this->rrule,
$this->tzid,
$this->tzname,
$this->tzoffsetfrom,
$this->tzoffsetto,
$this->tzurl,
$this->timezonetype );
}
/**
* Return formatted output for calendar component VTIMEZONE object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.5.1 - 2008-10-25
* @return string
*/
public function createComponent() {
$objectname = strtoupper(( isset( $this->timezonetype )) ? $this->timezonetype : $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createTzid();
$component .= $this->createLastModified();
$component .= $this->createTzurl();
$component .= $this->createDtstart();
$component .= $this->createTzoffsetfrom();
$component .= $this->createTzoffsetto();
$component .= $this->createComment();
$component .= $this->createRdate();
$component .= $this->createRrule();
$component .= $this->createTzname();
$component .= $this->createXprop();
$component .= $this->createSubComponent();
return $component . sprintf( util::$FMTEND, $objectname );
}
/**
* Return vtimezone component property value/params
*
* If arg $inclParam, return array with keys VALUE/PARAMS
* @param string $propName
* @param int $propix specific property in case of multiply occurences
* @param bool $inclParam
* @param bool $specform
* @return mixed
*/
public function getProperty( $propName=null,
$propix=null,
$inclParam=false,
$specform=false ) {
switch( strtoupper( $propName )) {
case util::$TZID:
if( isset( $this->tzid[util::$LCvalue] ))
return ( $inclParam ) ? $this->tzid
: $this->tzid[util::$LCvalue];
break;
case util::$TZOFFSETFROM:
if( isset( $this->tzoffsetfrom[util::$LCvalue] ))
return ( $inclParam ) ? $this->tzoffsetfrom
: $this->tzoffsetfrom[util::$LCvalue];
break;
case util::$TZOFFSETTO:
if( isset( $this->tzoffsetto[util::$LCvalue] ))
return ( $inclParam ) ? $this->tzoffsetto
: $this->tzoffsetto[util::$LCvalue];
break;
case util::$TZURL:
if( isset( $this->tzurl[util::$LCvalue] ))
return ( $inclParam ) ? $this->tzurl
: $this->tzurl[util::$LCvalue];
break;
default:
return parent::getProperty( $propName,
$propix,
$inclParam,
$specform );
break;
}
return false;
}
/**
* Return timezone standard object instance, vtimezone::newComponent() wrapper
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-06-26
* @return object
*/
public function newStandard() {
return $this->newComponent( util::$LCSTANDARD );
}
/**
* Return timezone daylight object instance, vtimezone::newComponent() wrapper
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-06-26
* @return object
*/
public function newDaylight() {
return $this->newComponent( util::$LCDAYLIGHT );
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* iCalcreator, a PHP rfc2445/rfc5545 solution.
*
* This file is a part of iCalcreator.
*
* Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
* Link http://kigkonsult.se/iCalcreator/index.php
* Package iCalcreator
* Version 2.24
* License Subject matter of licence is the software iCalcreator.
* The above copyright, link, package and version notices,
* this licence notice and the [rfc5545] PRODID as implemented and
* invoked in iCalcreator shall be included in all copies or
* substantial portions of the iCalcreator.
* iCalcreator can be used either under the terms of
* a proprietary license, available at <https://kigkonsult.se/>
* or the GNU Affero General Public License, version 3:
* iCalcreator is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* iCalcreator 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 Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
* License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
namespace kigkonsult\iCalcreator;
use kigkonsult\iCalcreator\util\util;
/**
* iCalcreator VTODO component class
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-01
*/
class vtodo extends calendarComponent {
use traits\ATTACHtrait,
traits\ATTENDEEtrait,
traits\CATEGORIEStrait,
traits\CLASStrait,
traits\COMMENTtrait,
traits\COMPLETEDtrait,
traits\CONTACTtrait,
traits\CREATEDtrait,
traits\DESCRIPTIONtrait,
traits\DTSTAMPtrait,
traits\DTSTARTtrait,
traits\DUEtrait,
traits\DURATIONtrait,
traits\EXDATEtrait,
traits\EXRULEtrait,
traits\GEOtrait,
traits\LAST_MODIFIEDtrait,
traits\LOCATIONtrait,
traits\ORGANIZERtrait,
traits\PERCENT_COMPLETEtrait,
traits\PRIORITYtrait,
traits\RDATEtrait,
traits\RECURRENCE_IDtrait,
traits\RELATED_TOtrait,
traits\REQUEST_STATUStrait,
traits\RESOURCEStrait,
traits\RRULEtrait,
traits\SEQUENCEtrait,
traits\STATUStrait,
traits\SUMMARYtrait,
traits\UIDtrait,
traits\URLtrait;
/**
* Constructor for calendar component VTODO object
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-02-01
* @param array $config
*/
public function __construct( $config = []) {
static $T = 't';
parent::__construct();
$this->setConfig( util::initConfig( $config ));
$this->cno = $T . parent::getObjectNo();
}
/**
* Destructor
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.22.23 - 2017-03-17
*/
public function __destruct() {
if( ! empty( $this->components ))
foreach( $this->components as $cix => $component )
$this->components[$cix]->__destruct();
unset( $this->xprop,
$this->components,
$this->unparsed,
$this->config,
$this->propix,
$this->compix,
$this->propdelix );
unset( $this->objName,
$this->cno );
unset( $this->attach,
$this->attendee,
$this->categories,
$this->class,
$this->comment,
$this->completed,
$this->contact,
$this->created,
$this->description,
$this->dtstamp,
$this->dtstart,
$this->due,
$this->duration,
$this->exdate,
$this->exrule,
$this->geo,
$this->lastmodified,
$this->location,
$this->organizer,
$this->percentcomplete,
$this->priority,
$this->rdate,
$this->recurrenceid,
$this->relatedto,
$this->requeststatus,
$this->resources,
$this->rrule,
$this->sequence,
$this->status,
$this->summary,
$this->uid,
$this->url );
}
/**
* Return formatted output for calendar component VTODO object instance
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.5.1 - 2008-11-07
* @return string
*/
public function createComponent() {
$objectname = strtoupper( $this->objName );
$component = sprintf( util::$FMTBEGIN, $objectname );
$component .= $this->createUid();
$component .= $this->createDtstamp();
$component .= $this->createAttach();
$component .= $this->createAttendee();
$component .= $this->createCategories();
$component .= $this->createClass();
$component .= $this->createComment();
$component .= $this->createCompleted();
$component .= $this->createContact();
$component .= $this->createCreated();
$component .= $this->createDescription();
$component .= $this->createDtstart();
$component .= $this->createDue();
$component .= $this->createDuration();
$component .= $this->createExdate();
$component .= $this->createExrule();
$component .= $this->createGeo();
$component .= $this->createLastModified();
$component .= $this->createLocation();
$component .= $this->createOrganizer();
$component .= $this->createPercentComplete();
$component .= $this->createPriority();
$component .= $this->createRdate();
$component .= $this->createRelatedTo();
$component .= $this->createRequestStatus();
$component .= $this->createRecurrenceid();
$component .= $this->createResources();
$component .= $this->createRrule();
$component .= $this->createSequence();
$component .= $this->createStatus();
$component .= $this->createSummary();
$component .= $this->createUrl();
$component .= $this->createXprop();
$component .= $this->createSubComponent();
return $component . sprintf( util::$FMTEND, $objectname );
}
/**
* Return valarm object instance, calendarComponent::newComponent() wrapper
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.20 - 2017-06-26
* @return object
*/
public function newValarm() {
return $this->newComponent( util::$LCVALARM );
}
}