mirror of
https://github.com/moodle/moodle.git
synced 2025-05-07 08:45:43 +02:00
Incoming: Bennu library to be used for iCal imports/exports.
This commit is contained in:
parent
5eedb21ee1
commit
f3b6ac1539
1
lib/bennu/CHANGELOG.txt
Normal file
1
lib/bennu/CHANGELOG.txt
Normal file
@ -0,0 +1 @@
|
||||
No changelog yet, sorry.
|
22
lib/bennu/COPYRIGHT.txt
Normal file
22
lib/bennu/COPYRIGHT.txt
Normal file
@ -0,0 +1,22 @@
|
||||
Bennu - An object-oriented iCalendar (RFC2445) implementation in PHP
|
||||
http://bennu.sourceforge.net
|
||||
|
||||
Bennu is copyright (C) 2005 by Ioannis Papaioannou (pj@moodle.org).
|
||||
|
||||
The full text of the LGLP license is included in LICENSE.txt
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to:
|
||||
The Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor
|
||||
Boston, MA 02110-1301 USA
|
504
lib/bennu/LICENSE.txt
Normal file
504
lib/bennu/LICENSE.txt
Normal file
@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
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 this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey 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 library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
148
lib/bennu/README.txt
Normal file
148
lib/bennu/README.txt
Normal file
@ -0,0 +1,148 @@
|
||||
Bennu - An object-oriented iCalendar (RFC2445) implementation in PHP
|
||||
http://bennu.sourceforge.net
|
||||
|
||||
Bennu is copyright (C) 2005 by Ioannis Papaioannou (pj@moodle.org).
|
||||
|
||||
=======================================================================
|
||||
TABLE OF CONTENTS
|
||||
=======================================================================
|
||||
|
||||
1. About Bennu
|
||||
1.1. What is Bennu?
|
||||
1.2. What is iCalendar?
|
||||
1.3. Bennu license
|
||||
|
||||
2. Using Bennu
|
||||
2.1. Integrating Bennu in your application
|
||||
2.2. Usage examples
|
||||
|
||||
3. Bugs and limitations
|
||||
3.1. Known limitations
|
||||
|
||||
4. Contact information
|
||||
|
||||
=======================================================================
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
1. About Bennu
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
1.1. What is Bennu?
|
||||
|
||||
Bennu is a software library written in PHP that implements the
|
||||
functionality of the IETF iCalendar 2.0 specification (RFC 2445).
|
||||
Its purpose is to enable applications which have an interest in
|
||||
this format (e.g. calendaring, scheduler and organizer programs)
|
||||
to support iCalendar in an easy, powerful, and extensible way.
|
||||
|
||||
In other words, Bennu exists so that developers working on such
|
||||
applications don't have to waste painful hours going through the
|
||||
standard and writing the code to implement it. Instead, they can
|
||||
include this library in their application and get to the fun part
|
||||
already: coding THEIR program.
|
||||
|
||||
1.2. What is iCalendar?
|
||||
|
||||
The iCalendar specification is a result of the work of the IETF
|
||||
(Internet Engineering Task Force), Calendaring and Scheduling
|
||||
Working Group. It was authored by Frank Dawson of Lotus
|
||||
Development Corporation and Derik Stenerson of Microsoft
|
||||
Corporation. iCalendar is heavily based on the earlier vCalendar
|
||||
industry specification by the Internet Mail Consortium (IMC),
|
||||
which it extends and seeks to replace.
|
||||
|
||||
In practical terms, iCalendar is the number one format used today
|
||||
by calendaring and scheduler applications to import and export
|
||||
data. Applications which provide support for iCalendar include:
|
||||
|
||||
* Microsoft Outlook
|
||||
* Apple iCal
|
||||
* Mozilla Calendar (and Mozilla Sunbird)
|
||||
* Mulberry
|
||||
* Korganizer
|
||||
* Ximian Evolution
|
||||
|
||||
Effectively, this means that iCalendar is akin to a "common
|
||||
language" which all these applications speak. If you are writing
|
||||
an application which includes scheduling or calendaring elements,
|
||||
and you want it to be able to synchronize with other such
|
||||
programs, you need to support iCalendar. Bennu is an easy way to
|
||||
do exactly that, as long as you are coding in PHP.
|
||||
|
||||
1.3. Bennu license
|
||||
|
||||
Bennu is released under the GNU Lesser General Public License
|
||||
(LGPL). In short, this means that:
|
||||
|
||||
* You are allowed to distribute and/or modify the source code of
|
||||
Bennu
|
||||
* You are allowed to use Bennu or any modified version of it in a
|
||||
commercial application
|
||||
* You do not have to pay any fees to use, modify, or distribute
|
||||
Bennu
|
||||
* You can charge others for distributing Bennu or derived versions
|
||||
* However, in ALL OF THE ABOVE CASES, you MUST provide the source
|
||||
code for Bennu (or any modified version you may have produced),
|
||||
and that source code MUST be provided under the GNU GPL -or- the
|
||||
GNU LGPL license. Furthermore, you MUST include the original
|
||||
copyright notices and credits that you received the source code
|
||||
with when you distribute it INTACT.
|
||||
* In any case, the copyright to Bennu is retained by me,
|
||||
Ioannis Papaioannou.
|
||||
|
||||
##################
|
||||
## DISCLAIMER ##
|
||||
##################
|
||||
|
||||
Please be advised that the above is a very short and to the point
|
||||
explanation of the GNU LGPL terms, as I understand it, and it is
|
||||
only my personal opinion. IT IS NOT THE ACTUAL LICENSE UNDER WHICH
|
||||
BENNU IS RELEASED. It is STRONGLY RECOMMENDED that you read the
|
||||
full text of the LGPL in order to avoid any misunderstandings
|
||||
which may be caused by reading my interpretation of it. You can
|
||||
find the full text of the LGPL in the file LICENSE.TXT, which you
|
||||
must have received as part of the Bennu distribution. If you have
|
||||
not received such a file, please email me mentioning where you
|
||||
obtained your copy of Bennu.
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
2. Using Bennu
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
2.1. Integrating Bennu in your application
|
||||
|
||||
To include Bennu in your application, you only need to include one
|
||||
PHP file, like this:
|
||||
|
||||
<?php
|
||||
include($path_to_bennu.'/library/lib/bennu.inc.php');
|
||||
|
||||
// the rest of your code goes here
|
||||
?>
|
||||
|
||||
2.2. Usage examples
|
||||
|
||||
Please look at the /examples/ directory for ready-to-run examples
|
||||
illustrating how Bennu is to be used. This section will be
|
||||
revisited and properly written when the source code reaches an
|
||||
acceptable level of features and meturity (no, I don't know when
|
||||
that will be).
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
3. Bugs and limitations
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
3.1. Known limitations
|
||||
|
||||
* LANGUAGE property parameters aren't semantically checked.
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
4. Contact information
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
You can contact me at the email address pj@moodle.org for any
|
||||
suggestions, ideas, or bug reports regarding Bennu.
|
||||
|
||||
At some point there will also be a site which you can use to do
|
||||
anything related to Bennu, but sadly not today. If you want to
|
||||
volunteer and give a hand, I 'll be happy to collaborate.
|
2
lib/bennu/TODO.txt
Normal file
2
lib/bennu/TODO.txt
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
* Take a look at all those text values. Control chars shouldn't be allowed.
|
59
lib/bennu/bennu.class.php
Normal file
59
lib/bennu/bennu.class.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* BENNU - PHP iCalendar library
|
||||
* (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
|
||||
*
|
||||
* Released under the LGPL.
|
||||
*
|
||||
* See http://bennu.sourceforge.net/ for more information and downloads.
|
||||
*
|
||||
* @author Ioannis Papaioannou
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
class Bennu {
|
||||
function timestamp_to_datetime($t = NULL) {
|
||||
if($t === NULL) {
|
||||
$t = time();
|
||||
}
|
||||
return gmstrftime('%Y%m%dT%H%M%SZ', $t);
|
||||
}
|
||||
|
||||
function generate_guid() {
|
||||
// Implemented as per the Network Working Group draft on UUIDs and GUIDs
|
||||
|
||||
// These two octets get special treatment
|
||||
$time_hi_and_version = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
|
||||
$clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
|
||||
|
||||
// Need another 14 random octects
|
||||
$pool = '';
|
||||
for($i = 0; $i < 7; ++$i) {
|
||||
$pool .= sprintf('%04x', mt_rand(0, 65535));
|
||||
}
|
||||
|
||||
// time_low = 4 octets
|
||||
$random = substr($pool, 0, 8).'-';
|
||||
|
||||
// time_mid = 2 octets
|
||||
$random .= substr($pool, 8, 4).'-';
|
||||
|
||||
// time_high_and_version = 2 octets
|
||||
$random .= $time_hi_and_version.substr($pool, 12, 2).'-';
|
||||
|
||||
// clock_seq_high_and_reserved = 1 octet
|
||||
$random .= $clock_seq_hi_and_reserved;
|
||||
|
||||
// clock_seq_low = 1 octet
|
||||
$random .= substr($pool, 13, 2).'-';
|
||||
|
||||
// node = 6 octets
|
||||
$random .= substr($pool, 14, 12);
|
||||
|
||||
return $random;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
25
lib/bennu/bennu.inc.php
Normal file
25
lib/bennu/bennu.inc.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* BENNU - PHP iCalendar library
|
||||
* (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
|
||||
*
|
||||
* Released under the LGPL.
|
||||
*
|
||||
* See http://bennu.sourceforge.net/ for more information and downloads.
|
||||
*
|
||||
* @author Ioannis Papaioannou
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
if(!defined('_BENNU_VERSION')) {
|
||||
define('_BENNU_VERSION', '0.1');
|
||||
include('bennu.class.php');
|
||||
include('iCalendar_rfc2445.php');
|
||||
include('iCalendar_components.php');
|
||||
include('iCalendar_properties.php');
|
||||
include('iCalendar_parameters.php');
|
||||
}
|
||||
|
||||
?>
|
410
lib/bennu/iCalendar_components.php
Normal file
410
lib/bennu/iCalendar_components.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* BENNU - PHP iCalendar library
|
||||
* (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
|
||||
*
|
||||
* Released under the LGPL.
|
||||
*
|
||||
* See http://bennu.sourceforge.net/ for more information and downloads.
|
||||
*
|
||||
* @author Ioannis Papaioannou
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
class iCalendar_component {
|
||||
var $name = NULL;
|
||||
var $properties = NULL;
|
||||
var $components = NULL;
|
||||
var $valid_properties = NULL;
|
||||
var $valid_components = NULL;
|
||||
|
||||
function iCalendar_component() {
|
||||
$this->construct();
|
||||
}
|
||||
|
||||
function construct() {
|
||||
// Initialize the components array
|
||||
if(empty($this->components)) {
|
||||
$this->components = array();
|
||||
foreach($this->valid_components as $name) {
|
||||
$this->components[$name] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
function add_property($name, $value = NULL, $parameters = NULL) {
|
||||
|
||||
// Uppercase first of all
|
||||
$name = strtoupper($name);
|
||||
|
||||
// Are we trying to add a valid property?
|
||||
$xname = false;
|
||||
if(!isset($this->valid_properties[$name])) {
|
||||
// If not, is it an x-name as per RFC 2445?
|
||||
if(!rfc2445_is_xname($name)) {
|
||||
return false;
|
||||
}
|
||||
// Since this is an xname, all components are supposed to allow this property
|
||||
$xname = true;
|
||||
}
|
||||
|
||||
// Create a property object of the correct class
|
||||
if($xname) {
|
||||
$property = new iCalendar_property_x;
|
||||
$property->set_name($name);
|
||||
}
|
||||
else {
|
||||
$classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $name));
|
||||
$property = new $classname;
|
||||
}
|
||||
|
||||
// If $value is NULL, then this property must define a default value.
|
||||
if($value === NULL) {
|
||||
$value = $property->default_value();
|
||||
if($value === NULL) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Set this property's parent component to ourselves, because some
|
||||
// properties behave differently according to what component they apply to.
|
||||
$property->set_parent_component($this->name);
|
||||
|
||||
// Set parameters before value; this helps with some properties which
|
||||
// accept a VALUE parameter, and thus change their default value type.
|
||||
|
||||
// The parameters must be valid according to property specifications
|
||||
if(!empty($parameters)) {
|
||||
foreach($parameters as $paramname => $paramvalue) {
|
||||
if(!$property->set_parameter($paramname, $paramvalue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Some parameters interact among themselves (e.g. ENCODING and VALUE)
|
||||
// so make sure that after the dust settles, these invariants hold true
|
||||
if(!$property->invariant_holds()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// $value MUST be valid according to the property data type
|
||||
if(!$property->set_value($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If this property is restricted to only once, blindly overwrite value
|
||||
if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) {
|
||||
$this->properties[$name] = array($property);
|
||||
}
|
||||
|
||||
// Otherwise add it to the instance array for this property
|
||||
else {
|
||||
$this->properties[$name][] = $property;
|
||||
}
|
||||
|
||||
// Finally: after all these, does the component invariant hold?
|
||||
if(!$this->invariant_holds()) {
|
||||
// If not, completely undo the property addition
|
||||
array_pop($this->properties[$name]);
|
||||
if(empty($this->properties[$name])) {
|
||||
unset($this->properties[$name]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function add_component($component) {
|
||||
|
||||
// With the detailed interface, you can add only components with this function
|
||||
if(!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = $component->get_name();
|
||||
|
||||
// Only valid components as specified by this component are allowed
|
||||
if(!in_array($name, $this->valid_components)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add it
|
||||
$this->components[$name][] = $component;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_property_list($name) {
|
||||
}
|
||||
|
||||
function invariant_holds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function is_valid() {
|
||||
// If we have any child components, check that they are all valid
|
||||
if(!empty($this->components)) {
|
||||
foreach($this->components as $component => $instances) {
|
||||
foreach($instances as $number => $instance) {
|
||||
if(!$instance->is_valid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, check the valid property list for any mandatory properties
|
||||
// that have not been set and do not have a default value
|
||||
foreach($this->valid_properties as $property => $propdata) {
|
||||
if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
|
||||
$classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $property));
|
||||
$object = new $classname;
|
||||
if($object->default_value() === NULL) {
|
||||
return false;
|
||||
}
|
||||
unset($object);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function serialize() {
|
||||
// Check for validity of the object
|
||||
if(!$this->is_valid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Maybe the object is valid, but there are some required properties that
|
||||
// have not been given explicit values. In that case, set them to defaults.
|
||||
foreach($this->valid_properties as $property => $propdata) {
|
||||
if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) {
|
||||
$this->add_property($property);
|
||||
}
|
||||
}
|
||||
|
||||
// Start tag
|
||||
$string = rfc2445_fold('BEGIN:'.$this->name) . RFC2445_CRLF;
|
||||
|
||||
// List of properties
|
||||
if(!empty($this->properties)) {
|
||||
foreach($this->properties as $name => $properties) {
|
||||
foreach($properties as $property) {
|
||||
$string .= $property->serialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// List of components
|
||||
if(!empty($this->components)) {
|
||||
foreach($this->components as $name => $components) {
|
||||
foreach($components as $component) {
|
||||
$string .= $component->serialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End tag
|
||||
$string .= rfc2445_fold('END:'.$this->name) . RFC2445_CRLF;
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class iCalendar extends iCalendar_component {
|
||||
var $name = 'VCALENDAR';
|
||||
|
||||
function construct() {
|
||||
$this->valid_properties = array(
|
||||
'CALSCALE' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'METHOD' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'PRODID' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
'VERSION' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
RFC2445_XNAME => RFC2445_OPTIONAL
|
||||
);
|
||||
|
||||
$this->valid_components = array(
|
||||
'VEVENT'
|
||||
// TODO: add support for the other component types
|
||||
//, 'VTODO', 'VJOURNAL', 'VFREEBUSY', 'VTIMEZONE', 'VALARM'
|
||||
);
|
||||
parent::construct();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class iCalendar_event extends iCalendar_component {
|
||||
|
||||
var $name = 'VEVENT';
|
||||
var $properties;
|
||||
|
||||
function construct() {
|
||||
|
||||
$this->valid_components = array('VALARM');
|
||||
|
||||
$this->valid_properties = array(
|
||||
'CLASS' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'CREATED' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'DESCRIPTION' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
// Standard ambiguous here: in 4.6.1 it says that DTSTAMP in optional,
|
||||
// while in 4.8.7.2 it says it's REQUIRED. Go with REQUIRED.
|
||||
'DTSTAMP' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
// Standard ambiguous here: in 4.6.1 it says that DTSTART in optional,
|
||||
// while in 4.8.2.4 it says it's REQUIRED. Go with REQUIRED.
|
||||
'DTSTART' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
'GEO' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'LAST-MODIFIED' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'LOCATION' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'ORGANIZER' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'PRIORITY' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'SEQUENCE' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'STATUS' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'SUMMARY' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'TRANSP' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
// Standard ambiguous here: in 4.6.1 it says that UID in optional,
|
||||
// while in 4.8.4.7 it says it's REQUIRED. Go with REQUIRED.
|
||||
'UID' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
'URL' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'RECURRENCE-ID' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'DTEND' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'DURATION' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'ATTACH' => RFC2445_OPTIONAL,
|
||||
'ATTENDEE' => RFC2445_OPTIONAL,
|
||||
'CATEGORIES' => RFC2445_OPTIONAL,
|
||||
'COMMENT' => RFC2445_OPTIONAL,
|
||||
'CONTACT' => RFC2445_OPTIONAL,
|
||||
'EXDATE' => RFC2445_OPTIONAL,
|
||||
'EXRULE' => RFC2445_OPTIONAL,
|
||||
'REQUEST-STATUS' => RFC2445_OPTIONAL,
|
||||
'RELATED-TO' => RFC2445_OPTIONAL,
|
||||
'RESOURCES' => RFC2445_OPTIONAL,
|
||||
'RDATE' => RFC2445_OPTIONAL,
|
||||
'RRULE' => RFC2445_OPTIONAL,
|
||||
RFC2445_XNAME => RFC2445_OPTIONAL
|
||||
);
|
||||
|
||||
parent::construct();
|
||||
}
|
||||
|
||||
function invariant_holds() {
|
||||
// DTEND and DURATION must not appear together
|
||||
if(isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) {
|
||||
// DTEND must be later than DTSTART
|
||||
// The standard is not clear on how to hande different value types though
|
||||
// TODO: handle this correctly even if the value types are different
|
||||
if($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// DTEND and DTSTART must have the same value type
|
||||
if($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class iCalendar_todo extends iCalendar_component {
|
||||
var $name = 'VTODO';
|
||||
var $properties;
|
||||
|
||||
function construct() {
|
||||
|
||||
$this->properties = array(
|
||||
'class' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'completed' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'created' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'description' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'dtstamp' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'dtstart' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'geo' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'last-modified' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'location' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'organizer' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'percent' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'priority' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'recurid' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'sequence' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'status' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'summary' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'uid' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'url' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'due' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'duration' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'attach' => RFC2445_OPTIONAL,
|
||||
'attendee' => RFC2445_OPTIONAL,
|
||||
'categories' => RFC2445_OPTIONAL,
|
||||
'comment' => RFC2445_OPTIONAL,
|
||||
'contact' => RFC2445_OPTIONAL,
|
||||
'exdate' => RFC2445_OPTIONAL,
|
||||
'exrule' => RFC2445_OPTIONAL,
|
||||
'rstatus' => RFC2445_OPTIONAL,
|
||||
'related' => RFC2445_OPTIONAL,
|
||||
'resources' => RFC2445_OPTIONAL,
|
||||
'rdate' => RFC2445_OPTIONAL,
|
||||
'rrule' => RFC2445_OPTIONAL,
|
||||
'xprop' => RFC2445_OPTIONAL
|
||||
);
|
||||
|
||||
parent::construct();
|
||||
// TODO:
|
||||
// either 'due' or 'duration' may appear in a 'eventprop', but 'due'
|
||||
// and 'duration' MUST NOT occur in the same 'eventprop'
|
||||
}
|
||||
}
|
||||
|
||||
class iCalendar_journal extends iCalendar_component {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
class iCalendar_freebusy extends iCalendar_component {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
class iCalendar_alarm extends iCalendar_component {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
class iCalendar_timezone extends iCalendar_component {
|
||||
var $name = 'VTIMEZONE';
|
||||
var $properties;
|
||||
|
||||
function construct() {
|
||||
|
||||
$this->properties = array(
|
||||
'tzid' => RFC2445_REQUIRED | RFC2445_ONCE,
|
||||
'last-modified' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
'tzurl' => RFC2445_OPTIONAL | RFC2445_ONCE,
|
||||
// TODO: the next two are components of their own!
|
||||
'standardc' => RFC2445_REQUIRED,
|
||||
'daylightc' => RFC2445_REQUIRED,
|
||||
'x-prop' => RFC2445_OPTIONAL
|
||||
);
|
||||
|
||||
parent::construct();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// REMINDER: DTEND must be later than DTSTART for all components which support both
|
||||
// REMINDER: DUE must be later than DTSTART for all components which support both
|
||||
|
||||
?>
|
240
lib/bennu/iCalendar_parameters.php
Normal file
240
lib/bennu/iCalendar_parameters.php
Normal file
@ -0,0 +1,240 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* BENNU - PHP iCalendar library
|
||||
* (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
|
||||
*
|
||||
* Released under the LGPL.
|
||||
*
|
||||
* See http://bennu.sourceforge.net/ for more information and downloads.
|
||||
*
|
||||
* @author Ioannis Papaioannou
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
class iCalendar_parameter {
|
||||
function multiple_values_allowed($parameter) {
|
||||
switch($parameter) {
|
||||
case 'DELEGATED-FROM':
|
||||
case 'DELEGATED-TO':
|
||||
case 'MEMBER':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function default_value($parameter) {
|
||||
switch($parameter) {
|
||||
case 'CUTYPE': return 'INDIVIDUAL';
|
||||
case 'FBTYPE': return 'BUSY';
|
||||
case 'PARTSTAT': return 'NEEDS-ACTION';
|
||||
case 'RELATED': return 'START';
|
||||
case 'RELTYPE': return 'PARENT';
|
||||
case 'ROLE': return 'REQ-PARTICIPANT';
|
||||
case 'RSVP': return 'FALSE';
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function is_valid_value(&$parent_property, $parameter, $value) {
|
||||
switch($parameter) {
|
||||
// These must all be a URI
|
||||
case 'ALTREP':
|
||||
case 'DIR':
|
||||
return rfc2445_is_valid_value($value, RFC2445_TYPE_URI);
|
||||
break;
|
||||
|
||||
// These must be CAL-ADDRESS, which is equivalent to URI
|
||||
case 'DELEGATED-FROM':
|
||||
case 'DELEGATED-TO':
|
||||
case 'MEMBER':
|
||||
case 'SENT-BY':
|
||||
return rfc2445_is_valid_value($value, RFC2445_TYPE_CAL_ADDRESS);
|
||||
break;
|
||||
|
||||
// These are textual parameters, so the MUST NOT contain double quotes
|
||||
case 'CN':
|
||||
return (strpos($value, '"') === false);
|
||||
break;
|
||||
|
||||
// These have enumerated legal values
|
||||
case 'CUTYPE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'INDIVIDUAL' || $value == 'GROUP' || $value == 'RESOURCE' || $value == 'ROOM' || $value == 'UNKNOWN' || rfc2445_is_xname($value));
|
||||
break;
|
||||
|
||||
case 'ENCODING':
|
||||
$value = strtoupper($value);
|
||||
return ($value == '8BIT' || $value == 'BASE64' || rfc2445_is_xname($value));
|
||||
break;
|
||||
|
||||
case 'FBTYPE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'FREE' || $value == 'BUSY' || $value == 'BUSY-UNAVAILABLE' || $value == 'BUSY-TENTATIVE' || rfc2445_is_xname($value));
|
||||
break;
|
||||
|
||||
case 'FMTTYPE':
|
||||
$fmttypes = array(
|
||||
'TEXT' => array('PLAIN', 'RICHTEXT', 'ENRICHED', 'TAB-SEPARATED-VALUES', 'HTML', 'SGML',
|
||||
'VND.LATEX-Z', 'VND.FMI.FLEXSTOR'),
|
||||
'MULTIPART' => array('MIXED', 'ALTERNATIVE', 'DIGEST', 'PARALLEL', 'APPLEDOUBLE', 'HEADER-SET',
|
||||
'FORM-DATA', 'RELATED', 'REPORT', 'VOICE-MESSAGE', 'SIGNED', 'ENCRYPTED',
|
||||
'BYTERANGES'),
|
||||
'MESSAGE' => array('RFC822', 'PARTIAL', 'EXTERNAL-BODY', 'NEWS', 'HTTP'),
|
||||
'APPLICATION' => array('OCTET-STREAM', 'POSTSCRIPT', 'ODA', 'ATOMICMAIL', 'ANDREW-INSET', 'SLATE',
|
||||
'WITA', 'DEC-DX', 'DCA-RFT', 'ACTIVEMESSAGE', 'RTF', 'APPLEFILE',
|
||||
'MAC-BINHEX40', 'NEWS-MESSAGE-ID', 'NEWS-TRANSMISSION', 'WORDPERFECT5.1',
|
||||
'PDF', 'ZIP', 'MACWRITEII', 'MSWORD', 'REMOTE-PRINTING', 'MATHEMATICA',
|
||||
'CYBERCASH', 'COMMONGROUND', 'IGES', 'RISCOS', 'ESHOP', 'X400-BP', 'SGML',
|
||||
'CALS-1840', 'PGP-ENCRYPTED', 'PGP-SIGNATURE', 'PGP-KEYS', 'VND.FRAMEMAKER',
|
||||
'VND.MIF', 'VND.MS-EXCEL', 'VND.MS-POWERPOINT', 'VND.MS-PROJECT',
|
||||
'VND.MS-WORKS', 'VND.MS-TNEF', 'VND.SVD', 'VND.MUSIC-NIFF', 'VND.MS-ARTGALRY',
|
||||
'VND.TRUEDOC', 'VND.KOAN', 'VND.STREET-STREAM', 'VND.FDF',
|
||||
'SET-PAYMENT-INITIATION', 'SET-PAYMENT', 'SET-REGISTRATION-INITIATION',
|
||||
'SET-REGISTRATION', 'VND.SEEMAIL', 'VND.BUSINESSOBJECTS',
|
||||
'VND.MERIDIAN-SLINGSHOT', 'VND.XARA', 'SGML-OPEN-CATALOG', 'VND.RAPID',
|
||||
'VND.ENLIVEN', 'VND.JAPANNET-REGISTRATION-WAKEUP',
|
||||
'VND.JAPANNET-VERIFICATION-WAKEUP', 'VND.JAPANNET-PAYMENT-WAKEUP',
|
||||
'VND.JAPANNET-DIRECTORY-SERVICE', 'VND.INTERTRUST.DIGIBOX', 'VND.INTERTRUST.NNCP'),
|
||||
'IMAGE' => array('JPEG', 'GIF', 'IEF', 'G3FAX', 'TIFF', 'CGM', 'NAPLPS', 'VND.DWG', 'VND.SVF',
|
||||
'VND.DXF', 'PNG', 'VND.FPX', 'VND.NET-FPX'),
|
||||
'AUDIO' => array('BASIC', '32KADPCM', 'VND.QCELP'),
|
||||
'VIDEO' => array('MPEG', 'QUICKTIME', 'VND.VIVO', 'VND.MOTOROLA.VIDEO', 'VND.MOTOROLA.VIDEOP')
|
||||
);
|
||||
$value = strtoupper($value);
|
||||
if(rfc2445_is_xname($value)) {
|
||||
return true;
|
||||
}
|
||||
@list($type, $subtype) = explode('/', $value);
|
||||
if(empty($type) || empty($subtype)) {
|
||||
return false;
|
||||
}
|
||||
if(!isset($fmttypes[$type]) || !in_array($subtype, $fmttypes[$type])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'LANGUAGE':
|
||||
$value = strtoupper($value);
|
||||
$parts = explode('-', $value);
|
||||
foreach($parts as $part) {
|
||||
if(empty($part)) {
|
||||
return false;
|
||||
}
|
||||
if(strspn($part, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') != strlen($part)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'PARTSTAT':
|
||||
$value = strtoupper($value);
|
||||
switch($parent_property->parent_component) {
|
||||
case 'VEVENT':
|
||||
return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE'
|
||||
|| $value == 'DELEGATED' || rfc2445_is_xname($value));
|
||||
break;
|
||||
case 'VTODO':
|
||||
return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE'
|
||||
|| $value == 'DELEGATED' || $value == 'COMPLETED' || $value == 'IN-PROCESS' || rfc2445_is_xname($value));
|
||||
break;
|
||||
case 'VJOURNAL':
|
||||
return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || rfc2445_is_xname($value));
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 'RANGE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'THISANDPRIOR' || $value == 'THISANDFUTURE');
|
||||
break;
|
||||
|
||||
case 'RELATED':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'START' || $value == 'END');
|
||||
break;
|
||||
|
||||
case 'RELTYPE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'PARENT' || $value == 'CHILD' || $value == 'SIBLING' || rfc2445_is_xname($value));
|
||||
break;
|
||||
|
||||
case 'ROLE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'CHAIR' || $value == 'REQ-PARTICIPANT' || $value == 'OPT-PARTICIPANT' || $value == 'NON-PARTICIPANT' || rfc2445_is_xname($value));
|
||||
break;
|
||||
|
||||
case 'RSVP':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'TRUE' || $value == 'FALSE');
|
||||
break;
|
||||
|
||||
case 'TZID':
|
||||
if(empty($value)) {
|
||||
return false;
|
||||
}
|
||||
return (strcspn($value, '";:,') == strlen($value));
|
||||
break;
|
||||
|
||||
case 'VALUE':
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'BINARY' || $value == 'BOOLEAN' || $value == 'CAL-ADDRESS' || $value == 'DATE' ||
|
||||
$value == 'DATE-TIME' || $value == 'DURATION' || $value == 'FLOAT' || $value == 'INTEGER' ||
|
||||
$value == 'PERIOD' || $value == 'RECUR' || $value == 'TEXT' || $value == 'TIME' ||
|
||||
$value == 'URI' || $value == 'UTC-OFFSET' || rfc2445_is_xname($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function do_value_formatting($parameter, $value) {
|
||||
switch($parameter) {
|
||||
// Parameters of type CAL-ADDRESS or URI MUST be double-quoted
|
||||
case 'ALTREP':
|
||||
case 'DIR':
|
||||
case 'DELEGATED-FROM':
|
||||
case 'DELEGATED-TO':
|
||||
case 'MEMBER':
|
||||
case 'SENT-BY':
|
||||
return '"'.$value.'"';
|
||||
break;
|
||||
|
||||
// Textual parameter types must be double quoted if they contain COLON, SEMICOLON
|
||||
// or COMMA. Quoting always sounds easier and standards-conformant though.
|
||||
case 'CN':
|
||||
return '"'.$value.'"';
|
||||
break;
|
||||
|
||||
// Parameters with enumerated legal values, just make them all caps
|
||||
case 'CUTYPE':
|
||||
case 'ENCODING':
|
||||
case 'FBTYPE':
|
||||
case 'FMTTYPE':
|
||||
case 'LANGUAGE':
|
||||
case 'PARTSTAT':
|
||||
case 'RANGE':
|
||||
case 'RELATED':
|
||||
case 'RELTYPE':
|
||||
case 'ROLE':
|
||||
case 'RSVP':
|
||||
case 'VALUE':
|
||||
return strtoupper($value);
|
||||
break;
|
||||
|
||||
// Parameters we shouldn't be messing with
|
||||
case 'TZID':
|
||||
return $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function undo_value_formatting($parameter, $value) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
1299
lib/bennu/iCalendar_properties.php
Normal file
1299
lib/bennu/iCalendar_properties.php
Normal file
File diff suppressed because it is too large
Load Diff
785
lib/bennu/iCalendar_rfc2445.php
Normal file
785
lib/bennu/iCalendar_rfc2445.php
Normal file
@ -0,0 +1,785 @@
|
||||
<?php // $Id$
|
||||
|
||||
/**
|
||||
* BENNU - PHP iCalendar library
|
||||
* (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
|
||||
*
|
||||
* Released under the LGPL.
|
||||
*
|
||||
* See http://bennu.sourceforge.net/ for more information and downloads.
|
||||
*
|
||||
* @author Ioannis Papaioannou
|
||||
* @version $Id$
|
||||
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
All names of properties, property parameters, enumerated property
|
||||
values and property parameter values are case-insensitive. However,
|
||||
all other property values are case-sensitive, unless otherwise
|
||||
stated.
|
||||
|
||||
*/
|
||||
|
||||
define('RFC2445_CRLF', "\r\n");
|
||||
define('RFC2445_WSP', "\t ");
|
||||
define('RFC2445_WEEKDAYS', 'MO,TU,WE,TH,FR,SA,SU');
|
||||
define('RFC2445_FOLDED_LINE_LENGTH', 75);
|
||||
|
||||
define('RFC2445_REQUIRED', 0x01);
|
||||
define('RFC2445_OPTIONAL', 0x02);
|
||||
define('RFC2445_ONCE', 0x04);
|
||||
|
||||
define('RFC2445_PROP_FLAGS', 0);
|
||||
define('RFC2445_PROP_TYPE', 1);
|
||||
define('RFC2445_PROP_DEFAULT', 2);
|
||||
|
||||
define('RFC2445_XNAME', 'X-');
|
||||
|
||||
define('RFC2445_TYPE_BINARY', 0);
|
||||
define('RFC2445_TYPE_BOOLEAN', 1);
|
||||
define('RFC2445_TYPE_CAL_ADDRESS', 2);
|
||||
define('RFC2445_TYPE_DATE', 3);
|
||||
define('RFC2445_TYPE_DATE_TIME', 4);
|
||||
define('RFC2445_TYPE_DURATION', 5);
|
||||
define('RFC2445_TYPE_FLOAT', 6);
|
||||
define('RFC2445_TYPE_INTEGER', 7);
|
||||
define('RFC2445_TYPE_PERIOD', 8);
|
||||
define('RFC2445_TYPE_RECUR', 9);
|
||||
define('RFC2445_TYPE_TEXT', 10);
|
||||
define('RFC2445_TYPE_TIME', 11);
|
||||
define('RFC2445_TYPE_URI', 12); // CAL_ADDRESS === URI
|
||||
define('RFC2445_TYPE_UTC_OFFSET', 13);
|
||||
|
||||
|
||||
function rfc2445_fold($string) {
|
||||
if(strlen($string) <= RFC2445_FOLDED_LINE_LENGTH) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
$retval = '';
|
||||
|
||||
while(strlen($string) > RFC2445_FOLDED_LINE_LENGTH) {
|
||||
$retval .= substr($string, 0, RFC2445_FOLDED_LINE_LENGTH - 1) . RFC2445_CRLF . ' ';
|
||||
$string = substr($string, RFC2445_FOLDED_LINE_LENGTH - 1);
|
||||
}
|
||||
|
||||
$retval .= $string;
|
||||
|
||||
return $retval;
|
||||
|
||||
}
|
||||
|
||||
function rfc2445_unfold($string) {
|
||||
for($i = 0; $i < strlen(RFC2445_WSP); ++$i) {
|
||||
$string = str_replace(RFC2445_CRLF.substr(RFC2445_WSP, $i, 1), '', $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function rfc2445_is_xname($name) {
|
||||
|
||||
// If it's less than 3 chars, it cannot be legal
|
||||
if(strlen($name) < 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If it contains an illegal char anywhere, reject it
|
||||
if(strspn($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-') != strlen($name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// To be legal, it must still start with "X-"
|
||||
return substr($name, 0, 2) === 'X-';
|
||||
}
|
||||
|
||||
function rfc2445_is_valid_value($value, $type) {
|
||||
|
||||
// This branch should only be taken with xname values
|
||||
if($type === NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch($type) {
|
||||
case RFC2445_TYPE_CAL_ADDRESS:
|
||||
case RFC2445_TYPE_URI:
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$valid_schemes = array('ftp', 'http', 'ldap', 'gopher', 'mailto', 'news', 'nntp', 'telnet', 'wais', 'file', 'prospero');
|
||||
|
||||
$pos = strpos($value, ':');
|
||||
if(!$pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$scheme = strtolower(substr($value, 0, $pos));
|
||||
$remain = substr($value, $pos + 1);
|
||||
|
||||
if(!in_array($scheme, $valid_schemes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($scheme === 'mailto') {
|
||||
$regexp = '^[a-zA-Z0-9]+[_a-zA-Z0-9\-]*(\.[_a-z0-9\-]+)*@(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})$';
|
||||
}
|
||||
else {
|
||||
$regexp = '^//(.+(:.*)?@)?(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]{1,5})?(/.*)?$';
|
||||
}
|
||||
|
||||
return ereg($regexp, $remain);
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_BINARY:
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$len = strlen($value);
|
||||
|
||||
if($len % 4 != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for($i = 0; $i < $len; ++$i) {
|
||||
$ch = $value{$i};
|
||||
if(!($ch >= 'a' && $ch <= 'z' || $ch >= 'A' && $ch <= 'Z' || $ch >= '0' && $ch <= '9' || $ch == '-' || $ch == '+')) {
|
||||
if($ch == '=' && $len - $i <= 2) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_BOOLEAN:
|
||||
if(is_bool($value)) {
|
||||
return true;
|
||||
}
|
||||
if(is_string($value)) {
|
||||
$value = strtoupper($value);
|
||||
return ($value == 'TRUE' || $value == 'FALSE');
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_DATE:
|
||||
if(is_int($value)) {
|
||||
if($value < 0) {
|
||||
return false;
|
||||
}
|
||||
$value = "$value";
|
||||
}
|
||||
else if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($value) != 8) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$y = intval(substr($value, 0, 4));
|
||||
$m = intval(substr($value, 4, 2));
|
||||
$d = intval(substr($value, 6, 2));
|
||||
|
||||
return checkdate($m, $d, $y);
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_DATE_TIME:
|
||||
if(!is_string($value) || strlen($value) < 15) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return($value{8} == 'T' &&
|
||||
rfc2445_is_valid_value(substr($value, 0, 8), RFC2445_TYPE_DATE) &&
|
||||
rfc2445_is_valid_value(substr($value, 9), RFC2445_TYPE_TIME));
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_DURATION:
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$len = strlen($value);
|
||||
|
||||
if($len < 3) {
|
||||
// Minimum conformant length: "P1W"
|
||||
return false;
|
||||
}
|
||||
|
||||
if($value{0} == '+' || $value{0} == '-') {
|
||||
$value = substr($value, 1);
|
||||
--$len; // Don't forget to update this!
|
||||
}
|
||||
|
||||
if($value{0} != 'P') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// OK, now break it up
|
||||
$num = '';
|
||||
$allowed = 'WDT';
|
||||
|
||||
for($i = 1; $i < $len; ++$i) {
|
||||
$ch = $value{$i};
|
||||
if($ch >= '0' && $ch <= '9') {
|
||||
$num .= $ch;
|
||||
continue;
|
||||
}
|
||||
if(strpos($allowed, $ch) === false) {
|
||||
// Non-numeric character which shouldn't be here
|
||||
return false;
|
||||
}
|
||||
if($num === '' && $ch != 'T') {
|
||||
// Allowed non-numeric character, but no digits came before it
|
||||
return false;
|
||||
}
|
||||
|
||||
// OK, $ch now holds a character which tells us what $num is
|
||||
switch($ch) {
|
||||
case 'W':
|
||||
// If duration in weeks is specified, this must end the string
|
||||
return ($i == $len - 1);
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
// Days specified, now if anything comes after it must be a 'T'
|
||||
$allowed = 'T';
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
// Starting to specify time, H M S are now valid delimiters
|
||||
$allowed = 'HMS';
|
||||
break;
|
||||
|
||||
case 'H':
|
||||
$allowed = 'M';
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
$allowed = 'S';
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
return ($i == $len - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we 're going to continue, reset $num
|
||||
$num = '';
|
||||
|
||||
}
|
||||
|
||||
// $num is kept for this reason: if we 're here, we ran out of chars
|
||||
// therefore $num must be empty for the period to be legal
|
||||
return ($num === '' && $ch != 'T');
|
||||
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_FLOAT:
|
||||
if(is_float($value)) {
|
||||
return true;
|
||||
}
|
||||
if(!is_string($value) || $value === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dot = false;
|
||||
$int = false;
|
||||
$len = strlen($value);
|
||||
for($i = 0; $i < $len; ++$i) {
|
||||
switch($value{$i}) {
|
||||
case '-': case '+':
|
||||
// A sign can only be seen at position 0 and cannot be the only char
|
||||
if($i != 0 || $len == 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
// A second dot is an error
|
||||
// Make sure we had at least one int before the dot
|
||||
if($dot || !$int) {
|
||||
return false;
|
||||
}
|
||||
$dot = true;
|
||||
// Make also sure that the float doesn't end with a dot
|
||||
if($i == $len - 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
$int = true;
|
||||
break;
|
||||
default:
|
||||
// Any other char is a no-no
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_INTEGER:
|
||||
if(is_int($value)) {
|
||||
return true;
|
||||
}
|
||||
if(!is_string($value) || $value === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($value{0} == '+' || $value{0} == '-') {
|
||||
if(strlen($value) == 1) {
|
||||
return false;
|
||||
}
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
if(strspn($value, '0123456789') != strlen($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ($value >= -2147483648 && $value <= 2147483647);
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_PERIOD:
|
||||
if(!is_string($value) || empty($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode('/', $value);
|
||||
if(count($parts) != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!rfc2445_is_valid_value($parts[0], RFC2445_TYPE_DATE_TIME)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Two legal cases for the second part:
|
||||
if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DATE_TIME)) {
|
||||
// It has to be after the start time, so
|
||||
return ($parts[1] > $parts[0]);
|
||||
}
|
||||
else if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DURATION)) {
|
||||
// The period MUST NOT be negative
|
||||
return ($parts[1]{0} != '-');
|
||||
}
|
||||
|
||||
// It seems to be illegal
|
||||
return false;
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_RECUR:
|
||||
if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode(';', strtoupper($value));
|
||||
|
||||
// First of all, we need at least a FREQ and a UNTIL or COUNT part, so...
|
||||
if(count($parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Let's get that into a more easily comprehensible format
|
||||
$vars = array();
|
||||
foreach($parts as $part) {
|
||||
|
||||
$pieces = explode('=', $part);
|
||||
// There must be exactly 2 pieces, e.g. FREQ=WEEKLY
|
||||
if(count($pieces) != 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// It's illegal for a variable to appear twice
|
||||
if(isset($vars[$pieces[0]])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sounds good
|
||||
$vars[$pieces[0]] = $pieces[1];
|
||||
}
|
||||
|
||||
// OK... now to test everything else
|
||||
|
||||
// FREQ must be the first thing appearing
|
||||
reset($vars);
|
||||
if(key($vars) != 'FREQ') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// It's illegal to have both UNTIL and COUNT appear
|
||||
if(isset($vars['UNTIL']) && isset($vars['COUNT'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Special case: BYWEEKNO is only valid for FREQ=YEARLY
|
||||
if(isset($vars['BYWEEKNO']) && $vars['FREQ'] != 'YEARLY') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Special case: BYSETPOS is only valid if another BY option is specified
|
||||
if(isset($vars['BYSETPOS'])) {
|
||||
$options = array('BYSECOND', 'BYMINUTE', 'BYHOUR', 'BYDAY', 'BYMONTHDAY', 'BYYEARDAY', 'BYWEEKNO', 'BYMONTH');
|
||||
$defined = array_keys($vars);
|
||||
$common = array_intersect($options, $defined);
|
||||
if(empty($common)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// OK, now simply check if each element has a valid value,
|
||||
// unsetting them on the way. If at the end the array still
|
||||
// has some elements, they are illegal.
|
||||
|
||||
if($vars['FREQ'] != 'SECONDLY' && $vars['FREQ'] != 'MINUTELY' && $vars['FREQ'] != 'HOURLY' &&
|
||||
$vars['FREQ'] != 'DAILY' && $vars['FREQ'] != 'WEEKLY' &&
|
||||
$vars['FREQ'] != 'MONTHLY' && $vars['FREQ'] != 'YEARLY') {
|
||||
return false;
|
||||
}
|
||||
unset($vars['FREQ']);
|
||||
|
||||
// Set this, we may need it later
|
||||
$weekdays = explode(',', RFC2445_WEEKDAYS);
|
||||
|
||||
if(isset($vars['UNTIL'])) {
|
||||
if(rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) {
|
||||
// The time MUST be in UTC format
|
||||
if(!(substr($vars['UNTIL'], -1) == 'Z')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(!rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($vars['UNTIL']);
|
||||
|
||||
|
||||
if(isset($vars['COUNT'])) {
|
||||
if(empty($vars['COUNT'])) {
|
||||
// This also catches the string '0', which makes no sense
|
||||
return false;
|
||||
}
|
||||
if(strspn($vars['COUNT'], '0123456789') != strlen($vars['COUNT'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($vars['COUNT']);
|
||||
|
||||
|
||||
if(isset($vars['INTERVAL'])) {
|
||||
if(empty($vars['INTERVAL'])) {
|
||||
// This also catches the string '0', which makes no sense
|
||||
return false;
|
||||
}
|
||||
if(strspn($vars['INTERVAL'], '0123456789') != strlen($vars['INTERVAL'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($vars['INTERVAL']);
|
||||
|
||||
|
||||
if(isset($vars['BYSECOND'])) {
|
||||
if($vars['BYSECOND'] == '') {
|
||||
return false;
|
||||
}
|
||||
// Comma also allowed
|
||||
if(strspn($vars['BYSECOND'], '0123456789,') != strlen($vars['BYSECOND'])) {
|
||||
return false;
|
||||
}
|
||||
$secs = explode(',', $vars['BYSECOND']);
|
||||
foreach($secs as $sec) {
|
||||
if($sec == '' || $sec < 0 || $sec > 59) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYSECOND']);
|
||||
|
||||
|
||||
if(isset($vars['BYMINUTE'])) {
|
||||
if($vars['BYMINUTE'] == '') {
|
||||
return false;
|
||||
}
|
||||
// Comma also allowed
|
||||
if(strspn($vars['BYMINUTE'], '0123456789,') != strlen($vars['BYMINUTE'])) {
|
||||
return false;
|
||||
}
|
||||
$mins = explode(',', $vars['BYMINUTE']);
|
||||
foreach($mins as $min) {
|
||||
if($min == '' || $min < 0 || $min > 59) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYMINUTE']);
|
||||
|
||||
|
||||
if(isset($vars['BYHOUR'])) {
|
||||
if($vars['BYHOUR'] == '') {
|
||||
return false;
|
||||
}
|
||||
// Comma also allowed
|
||||
if(strspn($vars['BYHOUR'], '0123456789,') != strlen($vars['BYHOUR'])) {
|
||||
return false;
|
||||
}
|
||||
$hours = explode(',', $vars['BYHOUR']);
|
||||
foreach($hours as $hour) {
|
||||
if($hour == '' || $hour < 0 || $hour > 23) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYHOUR']);
|
||||
|
||||
|
||||
if(isset($vars['BYDAY'])) {
|
||||
if(empty($vars['BYDAY'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First off, split up all values we may have
|
||||
$days = explode(',', $vars['BYDAY']);
|
||||
|
||||
foreach($days as $day) {
|
||||
$daypart = substr($day, -2);
|
||||
if(!in_array($daypart, $weekdays)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($day) > 2) {
|
||||
$intpart = substr($day, 0, strlen($day) - 2);
|
||||
if(!rfc2445_is_valid_value($intpart, RFC2445_TYPE_INTEGER)) {
|
||||
return false;
|
||||
}
|
||||
if(intval($intpart) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYDAY']);
|
||||
|
||||
|
||||
if(isset($vars['BYMONTHDAY'])) {
|
||||
if(empty($vars['BYMONTHDAY'])) {
|
||||
return false;
|
||||
}
|
||||
$mdays = explode(',', $vars['BYMONTHDAY']);
|
||||
foreach($mdays as $mday) {
|
||||
if(!rfc2445_is_valid_value($mday, RFC2445_TYPE_INTEGER)) {
|
||||
return false;
|
||||
}
|
||||
$mday = abs(intval($mday));
|
||||
if($mday == 0 || $mday > 31) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYMONTHDAY']);
|
||||
|
||||
|
||||
if(isset($vars['BYYEARDAY'])) {
|
||||
if(empty($vars['BYYEARDAY'])) {
|
||||
return false;
|
||||
}
|
||||
$ydays = explode(',', $vars['BYYEARDAY']);
|
||||
foreach($ydays as $yday) {
|
||||
if(!rfc2445_is_valid_value($yday, RFC2445_TYPE_INTEGER)) {
|
||||
return false;
|
||||
}
|
||||
$yday = abs(intval($yday));
|
||||
if($yday == 0 || $yday > 366) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYYEARDAY']);
|
||||
|
||||
|
||||
if(isset($vars['BYWEEKNO'])) {
|
||||
if(empty($vars['BYWEEKNO'])) {
|
||||
return false;
|
||||
}
|
||||
$weeknos = explode(',', $vars['BYWEEKNO']);
|
||||
foreach($weeknos as $weekno) {
|
||||
if(!rfc2445_is_valid_value($weekno, RFC2445_TYPE_INTEGER)) {
|
||||
return false;
|
||||
}
|
||||
$weekno = abs(intval($weekno));
|
||||
if($weekno == 0 || $weekno > 53) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYWEEKNO']);
|
||||
|
||||
|
||||
if(isset($vars['BYMONTH'])) {
|
||||
if(empty($vars['BYMONTH'])) {
|
||||
return false;
|
||||
}
|
||||
// Comma also allowed
|
||||
if(strspn($vars['BYMONTH'], '0123456789,') != strlen($vars['BYMONTH'])) {
|
||||
return false;
|
||||
}
|
||||
$months = explode(',', $vars['BYMONTH']);
|
||||
foreach($months as $month) {
|
||||
if($month == '' || $month < 1 || $month > 12) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYMONTH']);
|
||||
|
||||
|
||||
if(isset($vars['BYSETPOS'])) {
|
||||
if(empty($vars['BYSETPOS'])) {
|
||||
return false;
|
||||
}
|
||||
$sets = explode(',', $vars['BYSETPOS']);
|
||||
foreach($sets as $set) {
|
||||
if(!rfc2445_is_valid_value($set, RFC2445_TYPE_INTEGER)) {
|
||||
return false;
|
||||
}
|
||||
$set = abs(intval($set));
|
||||
if($set == 0 || $set > 366) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($vars['BYSETPOS']);
|
||||
|
||||
|
||||
if(isset($vars['WKST'])) {
|
||||
if(!in_array($vars['WKST'], $weekdays)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unset($vars['WKST']);
|
||||
|
||||
|
||||
// Any remaining vars must be x-names
|
||||
if(empty($vars)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach($vars as $name => $var) {
|
||||
if(!rfc2445_is_xname($name)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// At last, all is OK!
|
||||
return true;
|
||||
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_TEXT:
|
||||
return true;
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_TIME:
|
||||
if(is_int($value)) {
|
||||
if($value < 0) {
|
||||
return false;
|
||||
}
|
||||
$value = "$value";
|
||||
}
|
||||
else if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($value) == 7) {
|
||||
if(strtoupper(substr($value, -1)) != 'Z') {
|
||||
return false;
|
||||
}
|
||||
$value = substr($value, 0, 6);
|
||||
}
|
||||
if(strlen($value) != 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$h = intval(substr($value, 0, 2));
|
||||
$m = intval(substr($value, 2, 2));
|
||||
$s = intval(substr($value, 4, 2));
|
||||
|
||||
return ($h <= 23 && $m <= 59 && $s <= 60);
|
||||
break;
|
||||
|
||||
case RFC2445_TYPE_UTC_OFFSET:
|
||||
if(is_int($value)) {
|
||||
if($value >= 0) {
|
||||
$value = "+$value";
|
||||
}
|
||||
else {
|
||||
$value = "$value";
|
||||
}
|
||||
}
|
||||
else if(!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($value) == 7) {
|
||||
$s = intval(substr($value, 5, 2));
|
||||
$value = substr($value, 0, 5);
|
||||
}
|
||||
if(strlen($value) != 5 || $value == "-0000") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($value{0} != '+' && $value{0} != '-') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$h = intval(substr($value, 1, 2));
|
||||
$m = intval(substr($value, 3, 2));
|
||||
|
||||
return ($h <= 23 && $m <= 59 && $s <= 59);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: remove this assertion
|
||||
trigger_error('bad code path', E_USER_WARNING);
|
||||
var_dump($type);
|
||||
return false;
|
||||
}
|
||||
|
||||
function rfc2445_do_value_formatting($value, $type) {
|
||||
// Note: this does not only do formatting; it also does conversion to string!
|
||||
switch($type) {
|
||||
case RFC2445_TYPE_CAL_ADDRESS:
|
||||
case RFC2445_TYPE_URI:
|
||||
// Enclose in double quotes
|
||||
$value = '"'.$value.'"';
|
||||
break;
|
||||
case RFC2445_TYPE_TEXT:
|
||||
// Escape entities
|
||||
$value = strtr($value, array("\n" => '\\n', '\\' => '\\\\', ',' => '\\,', ';' => '\\;'));
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function rfc2445_undo_value_formatting($value, $type) {
|
||||
switch($type) {
|
||||
case RFC2445_TYPE_CAL_ADDRESS:
|
||||
case RFC2445_TYPE_URI:
|
||||
// Trim beginning and end double quote
|
||||
$value = substr($value, 1, strlen($value) - 2);
|
||||
break;
|
||||
case RFC2445_TYPE_TEXT:
|
||||
// Unescape entities
|
||||
$value = strtr($value, array('\\n' => "\n", '\\N' => "\n", '\\\\' => '\\', '\\,' => ',', '\\;' => ';'));
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user