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

18
vendor/kigkonsult/icalcreator/README.md vendored Normal file
View File

@@ -0,0 +1,18 @@
# iCalcreator
is the PHP class package managing
> iCal (rfc2445/rfc5445) information
operating on calendar and
calendar events, reports, todos and journaling data.
iCalcreator supports systems like
* calendars
* CMS
* project management systems
* other applications...
Builds
- stable 2.24 *(master)*
- old 2.22.5 *(tag)* - unsupported

View File

@@ -0,0 +1,71 @@
<?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/>.
*/
/**
* autoload.php
*
* iCalcreator package autoloader
*
* @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
* @since 2.23.16 - 2017-05-27
*/
/**
* Do NOT alter or remove the constant!!
*/
define( 'ICALCREATOR_VERSION', 'iCalcreator 2.24' );
/**
* load iCalcreator src and support classes and traits
*/
spl_autoload_register(
function( $class ) {
static $SRC = 'src';
static $BS = '\\';
static $PHP = '.php';
static $PREFIX = 'kigkonsult\\iCalcreator\\';
static $BASEDIR = null;
if( is_null( $BASEDIR ))
$BASEDIR = __DIR__ . DIRECTORY_SEPARATOR . $SRC . DIRECTORY_SEPARATOR;
if( 0 != strncmp( $PREFIX, $class, 23 ))
return false;
$class = substr( $class, 23 );
if( false !== strpos( $class, $BS ))
$class = str_replace( $BS, DIRECTORY_SEPARATOR, $class );
$file = $BASEDIR . $class . $PHP;
if( file_exists( $file )) {
require $file;
return true;
}
return false;
}
);
/**
* iCalcreator timezones add-on functionality functions, IF required?
*/
// include __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'iCal.tz.inc.php';

View File

@@ -0,0 +1,41 @@
{
"name": "kigkonsult/icalcreator",
"type": "library",
"description": "iCalcreator is the PHP implementation of rfc2445/rfc5545, management of iCal formatted files",
"keywords": [ "rfc2445",
"rfc5545",
"rfc6321",
"management",
"calendar",
"vCalendar",
"vevent",
"vtodo",
"vjournal",
"vfreebusy",
"valarm",
"vtimezone",
"standard",
"daylight",
"file" ],
"time" : "2017-09-04",
"license": "(AGPLv3 or proprietary)",
"description": "iCalcreator is the PHP implementation of rfc2445/rfc5545, management of iCal formatted files",
"keywords": [ "rfc2445", "rfc5545", "calendar", "management", "file", "format" ],
"homepage": "http://kigkonsult.se",
"support": {
"issues": "http://kigkonsult.se/contact/index.php"
},
"authors": [
{
"name": "Kjell-Inge Gustafsson",
"email": "ical@kigkonsult.se"
}
],
"autoload": {
"files": ["autoload.php"],
"psr-4": { "kigkonsult\\iCalcreator\\": ["src/", "src/util/", "src/traits/"] }
},
"require": {
"php": ">=5.4"
}
}

View File

@@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program 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.
This program 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/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.

View File

@@ -0,0 +1,755 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<!--
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/>.
-->
<html>
<head>
<title>iCalcreator 2.24 summary</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="author" content="Kjell-Inge Gustafsson, kigkonsult, All rights reserved">
<meta name="copyright" content="2017-2017 Kjell-Inge Gustafsson, kigkonsult">
<meta name="keywords" content="ical, calendar, calender, xcal, xml, icalender, rfc2445, rfc5545, vcalender, php, create">
<meta name="description" content="iCalcreator 2.24 summary" />
<style type="text/css">
* {
FONT-FAMILY : "Bitstream Vera Sans", Helvetica, "Lucida Grande","Lucida Sans Unicode", Lucida, Arial, Geneva, sans-serif;
BACKGROUND-COLOR: white;
COLOR : black;
FONT-SIZE : small;
}
body {
MARGIN-LEFT : 10px;
WIDTH : 750px;
}
a {
BACKGROUND-COLOR: inherit;
}
a.ref {
BACKGROUND-COLOR: inherit;
FONT-SIZE : 8pt;
LETTER-SPACING : 0.1em;
}
h1 {
BACKGROUND-COLOR: silver;
BORDER : thin solid black;
FONT-SIZE : x-large;
FONT-WEIGHT : bold;
DISPLAY : block;
}
h2 {
FONT-SIZE : large;
}
h3 {
FONT-SIZE : medium;
}
h4 {
FONT-SIZE : small;
FONT-WEIGHT : bold;
}
h5 {
FONT-SIZE : small;
FONT-WEIGHT : normal;
TEXT-DECORATION : underline;
}
table {
border-collapse : collapse;
width : 100%;
}
.bb {
BORDER-BOTTOM : gray dotted thin;
}
.blb {
BORDER-LEFT : gray dotted thin;
BORDER-BOTTOM : gray dotted thin;
TEXT-ALIGN : center;
}
.bl {
BORDER-LEFT : gray dotted thin;
}
.center {
TEXT-ALIGN : center;
}
p.comment {
FONT-FAMILY : monospace;
FONT-SIZE : 9pt;
FONT-WEIGHT : 500;
WHITE-SPACE : pre-wrap; /* css-3 */
WHITE-SPACE : -moz-pre-wrap; /* Mozilla, since 1999 */
WHITE-SPACE : -pre-wrap; /* Opera 4-6 */
WHITE-SPACE : -o-pre-wrap; /* Opera 7 */
WORD-WRAP : break-word; /* Internet Explorer 5.5+ */
}
span.comment {
BACKGROUND-COLOR: inherit;
FONT-FAMILY : Areal;
FONT-SIZE : 8pt;
LETTER-SPACING : 0.2em;
}
p.example {
BACKGROUND-COLOR: #DCDCDC;
font-family : monospace;
FONT-SIZE : 9pt;
LETTER-SPACING : 0.1em;
LINE-HEIGHT : 1.5em;
WHITE-SPACE : pre-wrap; /* css-3 */
WHITE-SPACE : -moz-pre-wrap; /* Mozilla, since 1999 */
WHITE-SPACE : -pre-wrap; /* Opera 4-6 */
WHITE-SPACE : -o-pre-wrap; /* Opera 7 */
WORD-WRAP : break-word; /* Internet Explorer 5.5+ */
}
p.format, span.format {
BORDER : gray dotted thin;
FONT-FAMILY : Helvetica;
FONT-SIZE : 9pt;
LETTER-SPACING : 0.2em;
LINE-HEIGHT : 2em;
WHITE-SPACE : pre-wrap; /* css-3 */
WHITE-SPACE : -moz-pre-wrap; /* Mozilla, since 1999 */
WHITE-SPACE : -pre-wrap; /* Opera 4-6 */
WHITE-SPACE : -o-pre-wrap; /* Opera 7 */
WORD-WRAP : break-word; /* Internet Explorer 5.5+ */
}
.header {
BACKGROUND-COLOR: silver;
BORDER : thin solid black;
FONT-SIZE : xx-large;
}
p.label {
FONT-FAMILY : Arial;
FONT-WEIGHT : bold;
LETTER-SPACING : 0.1em;
}
p.quotes {
BACKGROUND-COLOR: #F5F5F5;
FONT-FAMILY : Arial;
FONT-STYLE : italic;
LETTER-SPACING : 0.1em;
}
sup {
BACKGROUND-COLOR: transparent;
FONT-SIZE : x-small;
FONT-WEIGHT : bold;
VERTICAL-ALIGN : super;
}
.ref {
BACKGROUND-COLOR: transparent;
FONT-SIZE : 8pt;
LETTER-SPACING : 0.1em;
}
.top {
VERTICAL-ALIGN : top;
}
</style>
</head>
<body>
<h1>iCalcreator v2.24</h1>
<p>
iCalcreator v2.24<br>
Copyright (c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved.<br>
<a href="http://kigkonsult.se/iCalcreator/index.php" title="kigkonsult.se/iCalcreator" target="_blank">kigkonsult.se iCalcreator</a><br>
<a href="http://kigkonsult.se/contact/index.php" title="kigkonsult.se contact" target="_blank">kigkonsult.se contact</a>
</p>
<h4>Preface</h2>
<p>
This document describes a <b>short summary</b> usage of iCalcreator, a <em>PHP</em> software implementation of standards rfc5545/rfc5546 (rfc2445/rfc2446) to manage iCal formatted files.
</p>
<p>
This document is provided by kigkonsult for informational purposes
and is provided on an &quot;as is&quot; basis without any warranties expressed or implied.
</p>
<p>
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 <a href="#Copyright_and_Licence">license agreement</a>.
The software may be used only in accordance with the terms of that <a href="#Copyright_and_Licence">license agreement</a>.
It is against the law to copy or use the software except as specifically allowed in the <a href="#Copyright_and_Licence">license agreement</a>.
</p>
<p>
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.
</p>
<p>
The use of the software implies acceptance of these terms and the <a href="#Copyright_and_Licence">license agreement</a>.
</p>
<p>
This document makes previous versions obsolete.
</p>
<h4>The software</h2>
<p>
iCalcreator is a <em>PHP</em> 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.
</p>
<p>
For iCalcreator 2.24 version (and later), <em>PHP</em> version &gt;= 5.4 is required.
</p>
<h4>iCal</h4>
<p>
A short iCal description is found at <a href="http://en.wikipedia.org/wiki/ICalendar#Core_object" title="iCalendar From Wikipedia, the free encyclopedia" target="_blank">Wikipedia</a>.
If You are not familiar with iCal, read this first!
</p>
<p>
The <strong>iCalendar</strong> format, <strong>iCal</strong>, are described in
</p>
<dl>
<dt><a href="http://kigkonsult.se/downloads/dl.php?f=rfc5545" title="Download RFC5545 in text format" target="_blank">rfc5545</a>
<dd>&quot;Internet Calendaring and Scheduling Core Object Specification (<strong>iCalendar</strong>)&quot;
<dt><a href="http://kigkonsult.se/downloads/dl.php?f=rfc5546" title="Download RFC5546 in text format" target="_blank">rfc5546</a>
<dd>&quot;iCalendar Transport-Independent Interoperability Protocol (iTIP)&quot;<br>Scheduling Events, BusyTime, To-dos and Journal Entries
<p class="quotes">. ..allows for the capture and exchange of information normally stored
within a calendaring and scheduling application.</p>
and
<p class="quotes">. ..is an exchange format between applications or systems.</p>
</dl>
<p><a href="http://kigkonsult.se/downloads/dl.php?f=rfc5545" title="Download RFC5545 in text format" target="_blank">rfc5545</a> and
<a href="http://kigkonsult.se/downloads/dl.php?f=rfc5546" title="Download RFC5546 in text format" target="_blank">rfc5546</a>
obsoletes, respectively,
<a href="http://kigkonsult.se/downloads/dl.php?f=rfc2445" title="Download RFC2445 in text format" target="_blank">rfc2445</a> and
<a href="http://kigkonsult.se/downloads/dl.php?f=rfc2446" title="Download RFC2446 in text format" target="_blank">rfc2446</a>.
</p>
<h4>xCal</h4>
<p>
iCalcreator also supports xCal (iCal xml),
<a href="http://kigkonsult.se/downloads/dl.php?f=rfc6321" title="Download RFC6321 in text format" target="_blank">rfc6321</a>,
The XML Format for <strong>iCalendar</strong>.
</p>
<h4>SUPPORT</h4>
<p>
For previous iCalcreator releases support upon (paid) request only.
</p>
<p>
Use the contact <a href="http://kigkonsult.se/contact/index.php" title="kigkonsult.se/contact" target="_blank">page</a>
for queries, improvement/development issues or professional support and development.
Please note that paid support or consulting service has the highest priority.
</p>
<p>
kigkonsult offer professional services for software support, design and new/re-development, customizations and adaptations
of <em>PHP</em>/<em>MySQL</em> solutions with focus on software lifecycle management, including long term utility, reliability and maintainability.
</p>
<h4>DONATE</h4>
<p>
You can show your appreciation for our free software,
and can support future development by making a donation to the kigkonsult GPL/LGPL projects.
</p>
<p>
Make a donation of any size by clicking <a href="http://kigkonsult.se/contact/index.php#Donate" title="Donate" target="_blank">here</a>.
Thanks in advance!
</p>
<h4>Contact</h4>
<p>
Use the <a href="http://kigkonsult.se/contact/index.php" title="kigkonsult.se/contact" target="_blank">contact page</a>
for queries, improvement/development issues or professional support and development.
Please note that paid support or consulting service has the highest priority.
</p>
<h4>Downloads and usage examples</h4>
<p>
At <a href="http://kigkonsult.se/iCalcreator/index.php" title="kigkonsult iCalcreator" target="_blank">kigkonsult.se</a> you can download the
<a href="http://kigkonsult.se/downloads/index.php#iCalcreator" title="iCalcreator complete manual" target="_blank">complete manual</a>
and review and explore iCalcreator usage at the
<a href="http://kigkonsult.se/test/index.php" title="kigkonsult.se iCalcreator implement and test examples" target="_blank">coding and test</a> pages.
</p>
<h4>INSTALL</h4>
<dl>
<dt>Composer (https://getcomposer.org/)
<dd>&nbsp;
<dd>composer require kigkonsult/iCalcreator
<dd>&nbsp;
<dt>or
<dd> include the (download) iCalcreator folder to your include-path<br>
<dd> or unpack to your application-(include)-folder
<dd>Add
<dd><span class="format">require_once &quot;[path/]autoload.php&quot;;</span>
<dd>to your <em>PHP</em>-script.
<dd>The iCalcreator invoker has changed since previous version!
<dd>You may also need to set the default timezone.
</dl>
<h4>Notes</h4>
<p>
When creating a new calendar(/component) object instance, review config settings.
</p>
<p>
You will find a complete iCalcreator function list (ex. getProperty, deleteProperty) in
<a href="http://kigkonsult.se/downloads/index.php#iCalcreator" title="iCalcreator complete manual" target="_blank">iCalcreator manual</a>.
</p>
<p>
Note, to ease up usage, you will find convenient holders for component names,
properties, config keys etc in top of the &quot;util&quot; class file (src/util/util.php).
</p>
<h2>CREATE</h2>
<p class="example">
// <span class="comment">define time zone</span>
$tz = &quot;Europe/Stockholm&quot;;
// <span class="comment">set Your unique id, </span>
// <span class="comment">required if any component UID is missing</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot;,
// <span class="comment">opt. set &quot;calendar&quot; timezone</span>
kigkonsult\iCalcreator\util\util::$TZID =&gt; $tz );
// <span class="comment">create a new calendar object instance</span>
$calendar= new kigkonsult\iCalcreator\vcalendar( $config );
// <span class="comment">required of some calendar software</span>
$calendar-&gt;setProperty( kigkonsult\iCalcreator\util\util::$METHOD,
&quot;PUBLISH&quot; );
$calendar-&gt;setProperty( &quot;x-wr-calname&quot;,
&quot;Calendar Sample&quot; );
$calendar-&gt;setProperty( &quot;X-WR-CALDESC&quot;,
&quot;Calendar Description&quot; );
$calendar-&gt;setProperty( &quot;X-WR-TIMEZONE&quot;,
$tz );
// <span class="comment">create an calendar event component</span>
$vevent = $calendar-&gt;newVevent();
// <span class="comment">set event start</span>
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DTSTART,
array( &quot;year&quot; =&gt; 2017,
&quot;month&quot; =&gt; 4,
&quot;day&quot; =&gt; 1,
&quot;hour&quot; =&gt; 19,
&quot;min&quot; =&gt; 0,
&quot;sec&quot; =&gt; 0 ));
// <span class="comment">set event end</span>
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DTEND,
array( &quot;year&quot; =&gt; 2017,
&quot;month&quot; =&gt; 4,
&quot;day&quot; =&gt; 1,
&quot;hour&quot; =&gt; 22,
&quot;min&quot; =&gt; 30,
&quot;sec&quot; =&gt; 0 ));
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$LOCATION,
&quot;Central Placa&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$SUMMARY,
&quot;PHP summit&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION,
&quot;This is a description&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$COMMENT,
&quot;This is a comment&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$ATTENDEE,
&quot;attendee1@icaldomain.net&quot; );
// <span class="comment">create an event alarm</span>
$valarm = $vevent-&gt;newValarm();
$valarm-&gt;setProperty( kigkonsult\iCalcreator\util\util::$ACTION,
&quot;DISPLAY&quot; );
// <span class="comment">reuse the event description</span>
$valarm-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION,
$vevent-&gt;getProperty(
kigkonsult\iCalcreator\util\util::$DESCRIPTION
)
);
// <span class="comment">a local date</span>
$d = sprintf( '%04d%02d%02d %02d%02d%02d', 2017, 3, 31, 15, 0, 0 );
// <span class="comment">create alarm trigger (in UTC datetime)</span>
kigkonsult\iCalcreator\timezoneHandler::transformDateTime( $d,
$tz,
&quot;UTC&quot;,
&quot;Ymd\THis\Z&quot; );
$valarm-&gt;setProperty( kigkonsult\iCalcreator\util\util::$TRIGGER,
$d );
// <span class="comment">create another calendar event component</span>
$vevent = $calendar-&gt;newVevent();
// <span class="comment">alt. date format, here for an all-day event</span>
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DTSTART,
&quot;20170401&quot;,
array(&quot;VALUE&quot; =&gt; &quot;DATE&quot;));
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$ORGANIZER,
&quot;boss@icaldomain.com&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$SUMMARY,
&quot;ALL-DAY event&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION,
&quot;This is a description for an all-day event&quot; );
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$RESOURCES,
&quot;Full attension&quot; );
// <span class="comment">weekly, four occasions</span>
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$RRULE,
array( &quot;FREQ&quot; =&gt; &quot;WEEKLY&quot;,
&quot;count&quot; =&gt; 4));
// <span class="comment">supporting parse of strict rfc5545 formatted text</span>
$vevent-&gt;parse( &quot;LOCATION:1CP Conference Room 4350&quot; );
// <span class="comment">all calendar components are described in <a href="http://kigkonsult.se/downloads/dl.php?f=rfc5545" title="RFC5545" target="_blank">rfc5545</a></span>
// <span class="comment">a complete iCalcreator function list (ex. setProperty) in <a href="http://kigkonsult.se/downloads/index.php#iCalcreator" title="iCalcreator complete manual" target="_blank">iCalcreator manual</a></span>
// <span class="comment">create timezone component(-s)</span>
// <span class="comment">based on all start dates in events (i.e. all dtstarts)</span>
// <span class="comment">X-LIC-LOCATION required of some calendar software</span>
$xprops = array( &quot;X-LIC-LOCATION&quot; => $tz );
kigkonsult\iCalcreator\timezoneHandler::createTimezone( $v,
$tz,
$xprops );
</p>
<h2>PARSE</h2>
<h4>iCal, rfc5545 / rfc2445 </h4>
<p>How to create iCalcreator object instance</p>
<p class="example">
// <span class="comment">set Your unique id, </span>
// <span class="comment">required if any component UID is missing</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot; );
// <span class="comment">create a new calendar object instance</span>
$calendar= new kigkonsult\iCalcreator\vcalendar( $config );
</p>
<p>and then parse a local iCal file</p>
<p class="example">
// <span class="comment">set directory and file name</span>
$config = array( kigkonsult\iCalcreator\util\util::$DIRECTORY =&gt; &quot;calendars&quot;,
kigkonsult\iCalcreator\util\util::$FILENAME =&gt; &quot;file.ics&quot; );
$calendar-&gt;setConfig( $config );
$calendar-&gt;parse();
// <span class="comment">continue process (edit, parse, select) $calendar</span>
</p>
<p>or parse a remote iCal file (resource)</p>
<p class="example">
// <span class="comment">support parse of remote files</span>
$calendar-&gt;setConfig( kigkonsult\iCalcreator\util\util::$URL,
&quot;http://www.aDomain.net/file.ics&quot; );
$calendar-&gt;parse();
// <span class="comment">ensure start date order</span>
// <span class="comment">(opt., NOT required after parse)</span>
$calendar-&gt;sort();
// <span class="comment">continue process (edit, parse, select) $calendar</span>
</p>
<dl>
<dt>On error
<dd>the setConfig method returns FALSE (ex. unvalid directory/filename).
<dd>the parse method returns FALSE.
</dl>
<h4>xCal, rfc6321 (XML)</h4>
<p>
How to convert (file) XML resource to an iCalcreator object instance.
</p>
<p class="example">
// <span class="comment">set Your unique id, </span>
// <span class="comment">required if any component UID is missing</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot; );
// <span class="comment">use a local xCal file</span>
$filename = &quot;xmlfile.xml&quot;;
// <span class="comment"> or a remote xCal resource</span>
/* $filename = 'http://kigkonsult.se/xcal.php?a=1&amp;b=2&amp;c=3'; */
if( ! ( $calendar = kigkonsult\iCalcreator\iCalXML::XMLfile2iCal( $filename, $config )))
exit( &quot;Error when parsing $filename&quot; );
// <span class="comment">continue process (edit, parse, select) $calendar</span>
</p>
<h2>EDIT</h2>
<p class="example">
// <span class="comment">create a new calendar object instance</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot; );
$calendar = new kigkonsult\iCalcreator\vcalendar( $config );
// <span class="comment">parse a calendar file</span>
$config = array( kigkonsult\iCalcreator\util\util::$DIRECTORY =&gt; &quot;calendars&quot;,
kigkonsult\iCalcreator\util\util::$FILENAME =&gt; &quot;file.ics&quot; );
$calendar-&gt;setConfig( $config );
$calendar-&gt;parse();
// <span class="comment">required of some calendar software</span>
$calendar-&gt;setProperty( kigkonsult\iCalcreator\util\util::$METHOD,
&quot;PUBLISH&quot; );
$calendar-&gt;setProperty( &quot;x-wr-calname&quot;,
&quot;Calendar Sample&quot; );
$calendar-&gt;setProperty( &quot;X-WR-CALDESC&quot;,
&quot;Calendar Description&quot; );
$calendar-&gt;setProperty( &quot;X-WR-TIMEZONE&quot;,
&quot;Europe/Stockholm&quot; );
// <span class="comment">read events, one by one</span>
while( $vevent = $calendar-&gt;getComponent( kigkonsult\iCalcreator\util\util::$LCVEVENT )) {
// <span class="comment">uid (unique id/key for component), required, one occurrence </span>
$uid = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$UID );
// <span class="comment">dtstart required, one occurrence</span>
$dtstart = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$DTSTART );
// <span class="comment">opt. description</span>
if( $description = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION,
1 )) {
// <span class="comment">edit the description</span>
// <span class="comment">update/replace the description</span>
$vevent-&gt;setProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION, $description, FALSE, 1 );
}
// <span class="comment">optional comments</span>
while( $comment = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$COMMENT )) {
.. .
}
// <span class="comment">remove all ATTENDEE properties .. .</span>
while( $vevent-&gt;deleteProperty( kigkonsult\iCalcreator\util\util::$ATTENDEE ))
continue;
// <span class="comment">update/replace event in calendar</span>
// <span class="comment"> with UID as key</span>
$calendar-&gt;setComponent ( $vevent, $uid );
}
</p>
<br>
<br>
<h2>SELECT</h2>
<p>
(setup)
</p>
<p class="example">
// <span class="comment">create a new calendar object instance</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot; );
$calendar = new kigkonsult\iCalcreator\vcalendar( $config );
// <span class="comment">iCalcreator also support remote files</span>
$calendar-&gt;setConfig( kigkonsult\iCalcreator\util\util::$URL,
&quot;http://www.aDomain.net/file.ics&quot; );
$calendar-&gt;parse();
// <span class="comment">required of some calendar software</span>
$calendar-&gt;setProperty( kigkonsult\iCalcreator\util\util::$METHOD,
&quot;PUBLISH&quot; );
$calendar-&gt;setProperty( &quot;x-wr-calname&quot;,
&quot;Calendar Sample&quot; );
$calendar-&gt;setProperty( &quot;X-WR-CALDESC&quot;,
&quot;Calendar Description&quot; );
$calendar-&gt;setProperty( &quot;X-WR-TIMEZONE&quot;,
&quot;Europe/Stockholm&quot; );
</p>
<h4>Ex. calendar date based select</h4>
<p class="example">
// <span class="comment">select components occurring today</span>
// <span class="comment">(including components with recurrence pattern)</span>
$eventArray = $calendar-&gt;selectComponents();
foreach( $eventArray as $year =&gt; $yearArray) {
foreach( $yearArray as $month =&gt; $monthArray ) {
foreach( $monthArray as $day =&gt; $dailyEventsArray ) {
foreach( $dailyEventsArray as $vevent ) {
// <span class="comment">if event is a member of a recurrence set</span>
// <span class="comment">returns array( </span>
// <span class="comment"> &quot;x-current-dtstart&quot;</span>
// <span class="comment"> , (string) date(</span>
// <span class="comment"> &quot;Y-m-d [H:i:s][timezone/UTC offset]&quot;))</span>
$currddate = $event-&gt;getProperty(
kigkonsult\iCalcreator\util\util::$X_CURRENT_DTSTART
);
// <span class="comment">orig. dtstart</span>
$dtstart = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$DTSTART );
$summary = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$SUMMARY );
$description = $vevent-&gt;getProperty( kigkonsult\iCalcreator\util\util::$DESCRIPTION );
.. .
.. .
}
}
}
}
</p>
<h4>Ex. calendar select specific property values</h4>
<p class="example">
// <span class="comment">fetch specific property from calendar perspective</span>
// <span class="comment">(unique) values and occurrences : </span>
// <span class="comment">ATTENDEE, CATEGORIES, CONTACT,</span>
// <span class="comment">DTSTART, LOCATION, ORGANIZER,</span>
// <span class="comment">PRIORITY, RESOURCES, STATUS,</span>
// <span class="comment">SUMMARY, UID, URL,</span>
// <span class="comment">GEOLOCATION<sup>*</sup></span>
$valueOccur = $calendar-&gt;getProperty( kigkonsult\iCalcreator\util\util::$RESOURCES );
foreach( $valueOccur as $uniqueValue =&gt; $occurCnt ) {
echo &quot;The RESOURCES value &lt;b&gt;$uniqueValue&lt;/b&gt; occurs &lt;b&gt;$occurCnt&lt;/b&gt; times&lt;br /&gt;&quot;;
}
</p>
<p>
<sup>*</sup>) 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).
</p>
<h4>Ex. select calendar components based on specific property value</h4>
<p class="example">
// <span class="comment">selects components</span>
// <span class="comment">based on specific property value(-s)</span>
// <span class="comment">ATTENDEE, CATEGORIES, CONTACT,</span>
// <span class="comment">LOCATION, ORGANIZER,</span>
// <span class="comment">PRIORITY, RESOURCES, STATUS,</span>
// <span class="comment">SUMMARY, URL, UID</span>
$selectSpec = array( kigkonsult\iCalcreator\util\util::$CATEGORIES =&gt; &quot;course1&quot; );
$specComps = $calendar-&gt;selectComponents( $selectSpec );
foreach( $specComps as $comp ) {
.. .
}
</p>
<br>
<br>
<h2>OUTPUT</h2>
<p>(setup)</p>
<p class="example">
// <span class="comment">create a new calendar object instance</span>
$config = array( kigkonsult\iCalcreator\util\util::$UNIQUE_ID =&gt; &quot;kigkonsult.se&quot; );
$calendar= new kigkonsult\iCalcreator\vcalendar( $config );
// <span class="comment">required of some calendar software</span>
$calendar-&gt;setProperty( kigkonsult\iCalcreator\util\util::$METHOD,
&quot;PUBLISH&quot; );
$calendar-&gt;setProperty( &quot;x-wr-calname&quot;,
&quot;Calendar Sample&quot; );
$calendar-&gt;setProperty( &quot;X-WR-CALDESC&quot;,
&quot;Calendar Description&quot; );
$calendar-&gt;setProperty( &quot;X-WR-TIMEZONE&quot;,
&quot;Europe/Stockholm&quot; );
// <span class="comment">continue process (edit, parse, select) $calendar</span>
</p>
<h5>opt 1</h5>
<p>
Redirect calendar file to browser.
</p>
<p class="example">
$calendar-&gt;returnCalendar();
exit;
</p>
<h5>opt 2</h5>
<p>
Save calendar to file.
</p>
<p class="example">
// <span class="comment">set output directory and file name</span>
$config = array( kigkonsult\iCalcreator\util\util::$DIRECTORY =&gt; &quot;depot&quot;,
kigkonsult\iCalcreator\util\util::$FILENAME =&gt; &quot;calendar.ics&quot; );
$calendar-&gt;setConfig( $config );
$calendar-&gt;saveCalendar();
</p>
<h5>opt 3, xCal</h5>
<p>
Create well-formed XML, rfc6321 (as string).
</p>
<p class="example">
$xmlstr = kigkonsult\iCalcreator\iCalXML::iCal2XML( $calendar);
</p>
<h5>opt 4, json</h5>
<p>
Create a json string.
</p>
<p class="example">
$xmlstr = kigkonsult\iCalcreator\iCalXML::iCal2XML( $calendar);
$json = json_encode( simplexml_load_string( $xmlstr ));
</p>
<br>
<br>
<a name="Copyright_and_Licence"></a>
<h2>COPYRIGHT AND LICENSE</h2>
<table>
<tr><td>Copyright<td>(c) 2007-2017 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
<tr><td>Link <td>http://kigkonsult.se/iCalcreator/index.php
<tr><td>Package <td>iCalcreator
<tr><td>Version <td>2.24
<tr><td class="top">License <td>
Subject matter of licence is the software iCalcreator.<br>
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.<br>
iCalcreator can be used either under the terms of
a proprietary license, available at <a href="https://kigkonsult.se/">&lt;https://kigkonsult.se/&gt;</a><br>
or the GNU Affero General Public License, version 3:<br>
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.<br>
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.<br>
You should have received a copy of the GNU Affero General Public
License along with this program.
If not, see <a href="http://www.gnu.org/licenses/">&lt;http://www.gnu.org/licenses/&gt;</a>.
</table>
<br>
<br>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,53 @@
iCalcreator 2.24 releaseNotes
This is a major release!
The release includes (but not limited to)
MAJOR rewrite (but same API)
- require PHP >= 5.4
- namespace 'kigkonsult\iCalcreator'
- all calendar properties implemented as traits
with property declaration, create- and set-methods
- class 'iCalUtilityFunctions' renamed 'util'
- component, property, config key names etc
defined as public static properties in util
- more common operations refactored into util classes
- (component) method copy removed
- all config assembled in an array
config FORMAT and NL removed (always using iCal 'CRLF')
- old xCal (XML) output removed
- new class timezoneHandler (method createTimezone etc)
- new class iCalXML managing (rfc6321) XML
- new class iCalvCard managing vCard export
- new class vcalendarSortHandler managing comparison functions
- updated autoloader and altered folder structure
- improved performance
Bug fixed and updates:
util::size75()
no line break in CRLF
preserve opt. trailing CRLF
vcalendar::selectComponents()
index typo
no 'split' when event end at midnight
iCalXML::XMLgetProps()
X-prop parameter VALUE
PHP 7
substr adapt
vcalendar::sort()
reworked
util::splitContent()
attribute split index
vcalendar::getComponent()
calendarComponent::getComponent()
iCalBase::deleteComponent()
UID/component name spilt
code refresh:
fixed typos and fcn arg. and return types
utilRecur class
timezoneHandler::createTimezone(), timezone mgnt
vcalendar::newComponent() wrappers, ex. vcalendar::newVevent() etc

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 );
}
}