iCalcreator v2.26.8

iCalcreator v2.26.8
Copyright © 2007-2019 Kjell-Inge Gustafsson, kigkonsult, All rights reserved.
kigkonsult.se iCalcreator
Contact : iCal_at_kigkonsult_dot_se

Preface

This document describes usage of iCalcreator, the PHP software implementation of standards rfc5545/ rfc5546 (rfc2445/rfc2446) to manage iCal formatted files.

This document is provided by kigkonsult for informational purposes and is provided on an "as is" basis without any warranties expressed or implied.

Information in this document is subject to change without notice and does not represent a commitment on the part of kigkonsult. The software described in this document is provided under a license agreement. The software may be used only in accordance with the terms of that license agreement. It is against the law to copy or use the software except as specifically allowed in the license agreement.

It is the users responsibility to ensure the suitability of the software before using it. In no circumstances will kigkonsult be responsible for the use of the software's outcomes or results or any loss or damage of data or programs as a result of using the software.

The use of the software implies acceptance of these terms and the license.

This document makes previous versions obsolete.

The software

iCalcreator is a PHP class package managing iCal files, supporting (non-)calendar systems and applications to process and communicate calendar information like events, agendas, tasks, reports, totos and journaling information.

For iCalcreator 2.26.8 version (and later), PHP version 5.6+ is required.

iCal

A short iCal description is found at Wikipedia. If You are not familiar with iCal, read this first!

The iCalendar format, iCal, are described in

rfc5545
"Internet Calendaring and Scheduling Core Object Specification (iCalendar)"
rfc5546
"iCalendar Transport-Independent Interoperability Protocol (iTIP)"
Scheduling Events, BusyTime, To-dos and Journal Entries

. ..allows for the capture and exchange of information normally stored within a calendaring and scheduling application.

and

. ..is an exchange format between applications or systems.

rfc5545 and rfc5546 obsoletes, respectively, rfc2445 and rfc2446.

Any references to rfc2445, below, corresponds to rfc5545.

xCal

iCalcreator also supports xCal (iCal xml), rfc6321, The XML Format for iCalendar.

A short xCal description is found at Wikipedia.

Support

For previous iCalcreator releases support upon (paid) request only.

Use the issues page for queries, improvement/development issues or professional support and development. Please note that paid support or consulting service has the highest priority.

kigkonsult offer professional services for software support, design and new/re-development, customizations and adaptations of PHP/MySQL solutions with focus on software lifecycle management, including long term utility, reliability and maintainability.

Donate

You can show your appreciation for our free software, and can support future development by making a donation to the kigkonsult GPL/LGPL projects.

Make a donation of any size by clicking here. Thanks in advance!

Contact

Use the github issues for queries, improvement/development issues or professional support and development. Please note that paid support or consulting service has the highest priority.

Downloads and usage examples

At kigkonsult.se you can download a more complete manual and review and explore iCalcreator usage.

Install

Composer (https://getcomposer.org/)
 
composer require kigkonsult/icalcreator
 
Or
include the (download) iCalcreator folder to your include-path
Add
require_once "[path/]iCalcreator-2.26.8/autoload.php";
to your PHP-script.
The iCalcreator invoker has changed since previous version!

iCalcreator 2.26.8 is using namespace "Kigkonsult\Icalcreator".

Notes

When creating a new Vcalendar(/component) instance, review config settings.

You will find a complete iCalcreator function list (ex. getProperty, deleteProperty) in iCalcreator manual.

Note, to ease up usage, you will find convenient holders for component names, properties, config keys etc in top of the "util" class file (src/util/util.php).

CREATE

<?php namespace Kigkonsult\Icalcreator; use Kigkonsult\Icalcreator\Util\Util; // define time zone $tz = "Europe/Stockholm"; // set Your unique id, // required if any component UID is missing $config = [ Util::$UNIQUE_ID => "kigkonsult.se", // opt. set "calendar" timezone Util::$TZID => $tz ]; // create a new Vcalendar instance $calendar= new Vcalendar( $config ); // required of some calendar software $calendar->setProperty( Util::$METHOD, "PUBLISH" ); $calendar->setProperty( Util::$X_WR_CALNAME, "Calendar Sample"); $calendar->setProperty( Util::$X_WR_CALDESC, "Calendar Description" ); $calendar->setProperty( Util::$X_WR_TIMEZONE, $tz ); // create an calendar event component $vevent = $calendar->newVevent(); // set event start $vevent->setProperty( Util::$DTSTART, new DateTime( '2017-04-01 19:00:00') ); // set event end $vevent->setProperty( Util::$DTEND, new DateTime( '2017-04-01 22:30:00') ); $vevent->setProperty( Util::$LOCATION, "Central Placa" ); $vevent->setProperty( Util::$SUMMARY, "PHP summit" ); $vevent->setProperty( Util::$DESCRIPTION, "This is a description" ); $vevent->setProperty( Util::$COMMENT, "This is a comment" ); $vevent->setProperty( Util::$ATTENDEE, "attendee1@icaldomain.net" ); // create an event alarm $valarm = $vevent->newValarm(); $valarm->setProperty( Util::$ACTION, "DISPLAY" ); // reuse the event description $valarm->setProperty( Util::$DESCRIPTION, $vevent->getProperty( Util::$DESCRIPTION )); // create alarm trigger (in UTC datetime) $valarm->setProperty( Util::$TRIGGER, new DateTime( '2017-04-01 08:00:00 UTC') ); // create another calendar event component $vevent = $calendar->newVevent(); // alt. date format, here for an all-day event $vevent->setProperty( Util::$DTSTART, "20170401", [ "VALUE" => "DATE" ] ); $vevent->setProperty( Util::$ORGANIZER, "cio@icaldomain.com" ); $vevent->setProperty( Util::$SUMMARY, "ALL-DAY event" ); $vevent->setProperty( Util::$DESCRIPTION, "This is a description for an all-day event" ); $vevent->setProperty( Util::$RESOURCES, "Full attension" ); // weekly, four occasions $vevent->setProperty( Util::$RRULE, [ "FREQ" => "WEEKLY", "count" => 4 ] ); // supporting parse of strict rfc5545 formatted text $vevent->parse( "LOCATION:1CP Conference Room 4350" ); // all calendar components are described in rfc5545 // a complete iCalcreator function list (ex. setProperty) in the iCalcreator using manual // create timezone component(-s) // based on all start dates in events (i.e. all dtstarts) // X-LIC-LOCATION required of some calendar software $xprops = [ Util::$X_LIC_LOCATION => $tz ]; Kigkonsult\Icalcreator\TimezoneHandler::createTimezone( $v, $tz, $xprops );

PARSE

iCal, rfc5545 / rfc2445

How to parse an iCal (external/file) resource

// set Your unique id, // required if any component UID is missing $vcalendar = new Vcalendar( [ Util::$UNIQUE_ID => "kigkonsult.se", ] ); $iCalContent = file_get_contents( "calendar.ics" ); $vcalendar->parse( $iCalContent );

xCal, rfc6321 (XML)

How to convert (file) XML resource to an Vcalendar instance.

// set Your unique id, // required if any component UID is missing $config = [ Util::$UNIQUE_ID => "kigkonsult.se" ]; // use a local xCal file $filename = "xmlfile.xml"; // or a remote xCal resource /* $filename = 'http://kigkonsult.se/xcal.php?a=1&b=2&c=3'; */ if( ! ( $calendar = Kigkonsult\Icalcreator\IcalXML::XMLfile2iCal( $filename, $config ))) { exit( "Error when parsing $filename" ); } // continue process (edit, parse, select) $calendar

EDIT

// create a new Vcalendar instance $config = [ Util::$UNIQUE_ID => "kigkonsult.se" ]; $calendar = new Vcalendar( $config ); // parse a calendar file $config = [ Util::$DIRECTORY => "calendars", Util::$FILENAME => "file.ics" ]; $calendar->setConfig( $config ); $calendar->parse(); // required of some calendar software $calendar->setProperty( Util::$METHOD, "PUBLISH" ); $calendar->setProperty( Util::$X_WR_CALNAME, "Calendar Sample"); $calendar->setProperty( Util::$X_WR_CALDESC, "Calendar Description" ); $calendar->setProperty( Util::$X_WR_TIMEZONE, "Europe/Stockholm" ); // read events, one by one while( $vevent = $calendar->getComponent( Vcalendar::VEVENT )) { // get uid (unique id/key for component), required, one occurrence $uid = $vevent->getProperty( Util::$UID ); // get dtstart required, one occurrence $dtstart = $vevent->getProperty( Util::$DTSTART ); // opt. description if( $description = $vevent->getProperty( Util::$DESCRIPTION, 1 )) { // edit the description // update/replace the description $vevent->setProperty( Util::$DESCRIPTION, $description, false, 1 ); } // get optional comments while( $comment = $vevent->getProperty( Util::$COMMENT )) { .. . } // remove all ATTENDEE properties .. . while( $vevent->deleteProperty( Util::$ATTENDEE )) { continue; } // update/replace event in calendar // with UID as key $calendar->setComponent ( $vevent, $uid ); } // end while



SELECT

(setup)

// create a new Vcalendar instance $calendar = new Vcalendar( [ Util::$UNIQUE_ID => "kigkonsult.se", ] ); $iCalContent = file_get_contents( "http://www.aDomain.net/file.ics" ); $calendar->parse( $iCalContent ); // required of some calendar software $calendar->setProperty( Util::$METHOD, "PUBLISH" ); $calendar->setProperty( Util::$X_WR_CALNAME, "Calendar Sample"); $calendar->setProperty( Util::$X_WR_CALDESC, "Calendar Description" ); $calendar->setProperty( Util::$X_WR_TIMEZONE, "Europe/Stockholm");

Ex. calendar date based select

// select components occurring today // (including components with recurrence pattern) $eventArray = $calendar->selectComponents(); foreach( $eventArray as $year => $yearArray) { foreach( $yearArray as $month => $monthArray ) { foreach( $monthArray as $day => $dailyEventsArray ) { foreach( $dailyEventsArray as $vevent ) { // if event is a member of a recurrence set // returns [ // "x-current-dtstart", // (string) date( "Y-m-d [H:i:s][timezone/UTC offset]") // ] $currddate = $event->getProperty( Util::$X_CURRENT_DTSTART ); // orig. dtstart $dtstart = $vevent->getProperty( Util::$DTSTART ); $summary = $vevent->getProperty( Util::$SUMMARY ); $description = $vevent->getProperty( Util::$DESCRIPTION ); .. . .. . } // end foreach } // end foreach } // end foreach } // end foreach

Ex. calendar select specific property values

// fetch specific property from calendar perspective // (unique) values and occurrences : // ATTENDEE, CATEGORIES, CONTACT, // DTSTART, LOCATION, ORGANIZER, // PRIORITY, RESOURCES, STATUS, // SUMMARY, UID, URL, // GEOLOCATION* $valueOccur = $calendar->getProperty( Util::$RESOURCES ); foreach( $valueOccur as $uniqueValue => $occurCnt ) { echo "The RESOURCES value <b>$uniqueValue</b> occurs <b>$occurCnt</b> times<br />"; }

*) Using the non-standard directive "GEOLOCATION", iCalcreator returns output supporting ISO6709 "Standard representation of geographic point location by coordinates", by combining the "LOCATION" and "GEO" property values (only if "GEO" is set).

Ex. select calendar components based on specific property value

// selects components // based on specific property value(-s) // ATTENDEE, CATEGORIES, CONTACT, // LOCATION, ORGANIZER, // PRIORITY, RESOURCES, STATUS, // SUMMARY, URL, UID $selectSpec = [ Util::$CATEGORIES => "course1" ]; $specComps = $calendar->selectComponents( $selectSpec ); foreach( $specComps as $comp ) { .. . }



OUTPUT

(setup)

// create a new Vcalendar instance $calendar = new Vcalendar( [ Util::$UNIQUE_ID => "kigkonsult.se", ] ); // required of some calendar software $calendar->setProperty( Util::$METHOD, "PUBLISH" ); $calendar->setProperty( Util::$X_WR_CALNAME, "Calendar Sample"); $calendar->setProperty( Util::$X_WR_CALDESC, "Calendar Description" ); $calendar->setProperty( Util::$X_WR_TIMEZONE, "Europe/Stockholm"); // continue process (edit, parse, select) $calendar

opt 1

Redirect calendar file to browser.

$calendar->returnCalendar(); exit;

opt 2

Save calendar to file.

// set output directory and file name $config = [ Util::$DIRECTORY => "depot", Util::$FILENAME => "calendar.ics" ]; $calendar->setConfig( $config ); $calendar->saveCalendar();

opt 3, xCal

Create well-formed XML, rfc6321 (as string).

$xmlstr = Kigkonsult\Icalcreator\IcalXML::iCal2XML( $calendar);

opt 4, json

Create a json string.

$xmlstr = Kigkonsult\Icalcreator\IcalXML::iCal2XML( $calendar); $json = json_encode( simplexml_load_string( $xmlstr ));



COPYRIGHT AND LICENSE

Copyright(c) 2007-2019 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
Link http://kigkonsult.se/iCalcreator/index.php
Package iCalcreator
Version 2.26.8
License Subject matter of licence is the software iCalcreator.
The above copyright, link, package and version notices,
this licence notice and the invariant [rfc5545] PRODID result use
as implemented and invoked in iCalcreator shall be included in
all copies or substantial portions of the iCalcreator.

iCalcreator is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with iCalcreator. If not, see <https://www.gnu.org/licenses/>.