package.xml 0000664 0000766 0000024 00000106412 12231336712 010120 0 ustar
Horde_Alarmpear.horde.orgHorde Alarm LibrariesAn interface to deal with reminders, alarms and notifications through a standardized API. The following notification methods are currently available: standard Horde notifications, popups, emails.Jan Schneiderjanjan@horde.orgyes2013-10-212.0.51.0.0stablestableLGPL-2.1
* [mjr] Fix initializing Alarms when using PDO_Oci or PDO_PostgreSQL.
5.3.01.7.0Horde_Datepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Exceptionpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Translationpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Dbpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Logpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Mailpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Mimepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Notificationpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Permspear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Prefspear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Testpear.horde.org2.1.03.0.0alpha13.0.0alpha11.0.0alpha11.0.0alphaalpha2011-03-08LGPL-2.1
* First alpha release for Horde 4.
1.0.0beta11.0.0betabeta2011-03-16LGPL-2.1
* First beta release for Horde 4.
1.0.0RC11.0.0betabeta2011-03-22LGPL-2.1
* First release candidate for Horde 4.
1.0.0RC21.0.0betabeta2011-03-29LGPL-2.1
* Second release candidate for Horde 4.
* [jan] Fix fatal error in desktop notifications (Bug #9727).
1.0.01.0.0stablestable2011-04-06LGPL-2.1
* First stable release for Horde 4.
* [jan] Remove last bits of Core dependency.
1.0.11.0.0stablestable2011-05-18LGPL-2.1
* [jan] Updated Spanish translation.
1.0.21.0.0stablestable2011-06-01LGPL-2.1
* [jan] Updated Slovak translation.
1.0.31.0.0stablestable2011-07-05LGPL-2.1
* [jan] Update Lithuanian translation.
* [jan] Update Brazilian Portuguese translation.
1.0.41.0.0stablestable2011-07-27LGPL-2.1
* [jan] Update Latvian translation.
1.0.51.0.0stablestable2011-11-08LGPL-2.1
* [jan] Update Croatian translation.
1.0.61.0.0stablestable2011-11-22LGPL-2.1
* [jan] Update Estonian translation.
1.0.71.0.0stablestable2011-12-06LGPL-2.1
* [jan] Catch exceptions from Horde_Mime when sending alarm messages (Bug #10388).
1.0.81.0.0stablestable2011-12-06LGPL-2.1
* [mjr] Fix issue that prevented Desktop Notifications from displaying.
2.0.0alpha11.0.0alphastable2012-07-05LGPL-2.1
* First alpha release for Horde 5.
2.0.0beta11.0.0betastable2012-07-19LGPL-2.1
* First beta release for Horde 5.
2.0.0beta21.0.0betastable2012-08-29LGPL-2.1
* [jan] Fix Desktop notifications (Bug #10810).
2.0.0RC11.0.0betastable2012-10-26LGPL-2.1
* [mjr] Fix a bug that broke Desktop Notifications.
2.0.01.0.0stablestable2012-10-30LGPL-2.1
* First stable release for Horde 5.
* [jan] Update Polish translation (Krzysztof Kozera <krzysztof113@o2.pl>).
2.0.11.0.0stablestable2012-11-06LGPL-2.1
* [jan] Update Dutch translation (Arjen de Korte <build+horde@de-korte.org>).
2.0.21.0.0stablestable2012-11-19LGPL-2.1
* [mms] Use new Horde_Test layout.
2.0.31.0.0stablestable2013-01-09LGPL-2.1
* [jan] Update Basque translation (Ibon Igartua <ibon.igartua@ehu.es>).
2.0.41.0.0stablestable2013-03-05LGPL-2.1
* [jan] Fix unit tests.
2.0.51.0.0stablestable2013-10-21LGPL-2.1
* [mjr] Fix initializing Alarms when using PDO_Oci or PDO_PostgreSQL.
Horde_Alarm-2.0.5/doc/Horde/Alarm/COPYING 0000664 0000766 0000024 00000057656 12231336711 014533 0 ustar GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, 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
Horde_Alarm-2.0.5/lib/Horde/Alarm/Handler/Desktop.php 0000664 0000766 0000024 00000005157 12231336711 017165 0 ustar
* @package Alarm
*/
class Horde_Alarm_Handler_Desktop extends Horde_Alarm_Handler
{
/**
* A notification callback.
*
* @var callback
*/
protected $_jsNotify;
/**
* An icon URL.
*
* @var string
*/
protected $_icon;
/**
* Constructor.
*
* @param array $params Any parameters that the handler might need.
* Required parameter:
* - js_notify: A Horde_Notification_Handler
* instance.
* Optional parameter:
* - icon: URL of an icon to display.
*/
public function __construct(array $params = null)
{
if (!isset($params['js_notify'])) {
throw new InvalidArgumentException('Parameter \'js_notify\' missing.');
}
if (!is_callable($params['js_notify'])) {
throw new Horde_Alarm_Exception('Parameter \'js_notify\' is not a valid callback.');
}
$this->_jsNotify = $params['js_notify'];
if (isset($params['icon'])) {
$this->_icon = $params['icon'];
}
}
/**
* Notifies about an alarm through javscript.
*
* @param array $alarm An alarm hash.
*/
public function notify(array $alarm)
{
$js = sprintf('if(window.webkitNotifications)(function(){function show(){switch(window.webkitNotifications.checkPermission()){case 0:var notify=window.webkitNotifications.createNotification("%s",%s,%s);notify.show();(function(){notify.cancel()}).delay(5);break;case 1:window.webkitNotifications.requestPermission(function(){});break}}show()})()',
$this->_icon,
Horde_Serialize::serialize($alarm['title'], Horde_Serialize::JSON),
isset($alarm['text']) ? Horde_Serialize::serialize($alarm['text'], Horde_Serialize::JSON) : "''");
call_user_func($this->_jsNotify, $js);
}
/**
* Returns a human readable description of the handler.
*
* @return string
*/
public function getDescription()
{
return Horde_Alarm_Translation::t("Desktop notification (with certain browsers)");
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Handler/Mail.php 0000664 0000766 0000024 00000011070 12231336711 016425 0 ustar
* @package Alarm
*/
class Horde_Alarm_Handler_Mail extends Horde_Alarm_Handler
{
/**
* An identity factory.
*
* @var Horde_Core_Factory_Identity
*/
protected $_identity;
/**
* A Horde_Mail_Transport object.
*
* @var Horde_Mail_Transport
*/
protected $_mail;
/**
* Constructor.
*
* @param array $params Any parameters that the handler might need.
* Required parameter:
* - identity: An identity factory that implements
* create().
* - mail: A Horde_Mail_Transport instance.
*
* @throws Horde_Alarm_Exception
*/
public function __construct(array $params = null)
{
foreach (array('identity', 'mail') as $param) {
if (!isset($params[$param])) {
throw new Horde_Alarm_Exception('Parameter \'' . $param . '\' missing.');
}
}
if (!method_exists($params['identity'], 'create')) {
throw new Horde_Alarm_Exception('Parameter \'identity\' does not have a method create().');
}
if (!($params['mail'] instanceof Horde_Mail_Transport)) {
throw new Horde_Alarm_Exception('Parameter \'mail\' is not a Horde_Mail_Transport object.');
}
$this->_identity = $params['identity'];
$this->_mail = $params['mail'];
}
/**
* Notifies about an alarm by e-mail.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
public function notify(array $alarm)
{
if (!empty($alarm['internal']['mail']['sent'])) {
return;
}
if (empty($alarm['params']['mail']['email'])) {
if (empty($alarm['user'])) {
return;
}
$email = $this->_identity
->create($alarm['user'])
->getDefaultFromAddress(true);
} else {
$email = $alarm['params']['mail']['email'];
}
try {
$mail = new Horde_Mime_Mail(array(
'Subject' => $alarm['title'],
'To' => $email,
'From' => $email,
'Auto-Submitted' => 'auto-generated',
'X-Horde-Alarm' => $alarm['title']));
if (isset($alarm['params']['mail']['mimepart'])) {
$mail->setBasePart($alarm['params']['mail']['mimepart']);
} elseif (empty($alarm['params']['mail']['body'])) {
$mail->setBody($alarm['text']);
} else {
$mail->setBody($alarm['params']['mail']['body']);
}
$mail->send($this->_mail);
} catch (Horde_Mime_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
$alarm['internal']['mail']['sent'] = true;
$this->alarm->internal($alarm['id'], $alarm['user'], $alarm['internal']);
}
/**
* Resets the internal status of the handler, so that alarm notifications
* are sent again.
*
* @param array $alarm An alarm hash.
*/
public function reset(array $alarm)
{
$alarm['internal']['mail']['sent'] = false;
$this->alarm->internal($alarm['id'], $alarm['user'], $alarm['internal']);
}
/**
* Returns a human readable description of the handler.
*
* @return string
*/
public function getDescription()
{
return Horde_Alarm_Translation::t("Email");
}
/**
* Returns a hash of user-configurable parameters for the handler.
*
* The parameters are hashes with parameter names as keys and parameter
* information as values. The parameter information is a hash with the
* following keys:
* - type: the parameter type as a preference type.
* - desc: a parameter description.
* - required: whether this parameter is required.
*
* @return array
*/
public function getParameters()
{
return array(
'email' => array(
'type' => 'text',
'desc' => Horde_Alarm_Translation::t("Email address (optional)"),
'required' => false));
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Handler/Notify.php 0000664 0000766 0000024 00000006103 12231336711 017014 0 ustar
* @package Alarm
*/
class Horde_Alarm_Handler_Notify extends Horde_Alarm_Handler
{
/**
* A notification handler injector.
*
* @var object
*/
protected $_notification;
/**
* Whether a sound already had been played during the page request.
*
* @var boolean
*/
protected $_soundPlayed = false;
/**
* Constructor.
*
* @param array $params Any parameters that the handler might need.
* Required parameter:
* - notification: (object) A factory that implements create() and
* returns a Notification object.
*
* @throws Horde_Alarm_Exception
*/
public function __construct(array $params = null)
{
if (!isset($params['notification'])) {
throw new Horde_Alarm_Exception('Parameter \'notification\' missing.');
}
if (!method_exists($params['notification'], 'create')) {
throw new Horde_Alarm_Exception('Parameter \'notification\' does not have a method create().');
}
$this->_notification = $params['notification'];
}
/**
* Notifies about an alarm through Horde_Notification.
*
* @param array $alarm An alarm hash.
*/
public function notify(array $alarm)
{
$notification = $this->_notification->create();
$notification->push($alarm['title'], 'horde.alarm', array('alarm' => $alarm));
if (!empty($alarm['params']['notify']['sound']) &&
!isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) {
$notification->attach('audio');
$notification->push($alarm['params']['notify']['sound'], 'audio');
$this->_soundPlayed[$alarm['params']['notify']['sound']] = true;
}
}
/**
* Returns a human readable description of the handler.
*
* @return string
*/
public function getDescription()
{
return Horde_Alarm_Translation::t("Inline");
}
/**
* Returns a hash of user-configurable parameters for the handler.
*
* The parameters are hashes with parameter names as keys and parameter
* information as values. The parameter information is a hash with the
* following keys:
* - type: the parameter type as a preference type.
* - desc: a parameter description.
* - required: whether this parameter is required.
*
* @return array
*/
public function getParameters()
{
return array(
'sound' => array(
'type' => 'sound',
'desc' => Horde_Alarm_Translation::t("Play a sound?"),
'required' => false));
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Exception.php 0000664 0000766 0000024 00000000651 12231336711 016127 0 ustar
* @category Horde
* @package Alarm
*/
class Horde_Alarm_Exception extends Horde_Exception_Wrapped
{
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Handler.php 0000664 0000766 0000024 00000003205 12231336711 015544 0 ustar
* @package Alarm
*/
abstract class Horde_Alarm_Handler
{
/**
* The alarm object to that this handler is attached.
*
* Horde_Alarm
*/
public $alarm;
/**
* Notifies about an alarm.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
abstract public function notify(array $alarm);
/**
* Resets the internal status of the handler, so that alarm notifications
* are sent again.
*
* @param array $alarm An alarm hash.
*/
public function reset(array $alarm)
{
}
/**
* Returns a human readable description of the handler.
*
* @return string
*/
abstract public function getDescription();
/**
* Returns a hash of user-configurable parameters for the handler.
*
* The parameters are hashes with parameter names as keys and parameter
* information as values. The parameter information is a hash with the
* following keys:
* - type: the parameter type as a preference type.
* - desc: a parameter description.
* - required: whether this parameter is required.
*
* @return array
*/
public function getParameters()
{
return array();
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Null.php 0000664 0000766 0000024 00000011376 12231336711 015111 0 ustar
* @package Alarm
*/
class Horde_Alarm_Null extends Horde_Alarm
{
/**
* Returns a list of alarms from the backend.
*
* @param Horde_Date $time The time when the alarms should be active.
* @param string $user Return alarms for this user, all users if
* null, or global alarms if empty.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
protected function _list($user, Horde_Date $time)
{
return array();
}
/**
* Returns a list of all global alarms from the backend.
*
* @return array A list of alarm hashes.
*/
protected function _global()
{
return array();
}
/**
* Returns an alarm hash from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return array An alarm hash.
* @throws Horde_Alarm_Exception
*/
protected function _get($id, $user)
{
throw new Horde_Alarm_Exception('Alarm not found');
}
/**
* Adds an alarm hash to the backend.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
protected function _add(array $alarm)
{
}
/**
* Updates an alarm hash in the backend.
*
* @param array $alarm An alarm hash.
* @param boolean $keepsnooze Whether to keep the snooze value unchanged.
*
* @throws Horde_Alarm_Exception
*/
protected function _update(array $alarm, $keepsnooze = false)
{
}
/**
* Updates internal alarm properties, i.e. properties not determined by
* the application setting the alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param array $internal A hash with the internal data.
*
* @throws Horde_Alarm_Exception
*/
public function internal($id, $user, array $internal)
{
}
/**
* Returns whether an alarm with the given id exists already.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return boolean True if the specified alarm exists.
* @throws Horde_Alarm_Exception
*/
protected function _exists($id, $user)
{
return false;
}
/**
* Delays (snoozes) an alarm for a certain period.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $snooze The snooze time.
*
* @throws Horde_Alarm_Exception
*/
protected function _snooze($id, $user, Horde_Date $snooze)
{
}
/**
* Returns whether an alarm is snoozed.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $time The time when the alarm may be snoozed.
*
* @return boolean True if the alarm is snoozed.
* @throws Horde_Alarm_Exception
*/
protected function _isSnoozed($id, $user, Horde_Date $time)
{
return false;
}
/**
* Dismisses an alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @throws Horde_Alarm_Exception
*/
protected function _dismiss($id, $user)
{
}
/**
* Deletes an alarm from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user. All users' alarms if null.
*
* @throws Horde_Alarm_Exception
*/
protected function _delete($id, $user = null)
{
}
/**
* Garbage collects old alarms in the backend.
*
* @throws Horde_Alarm_Exception
*/
protected function _gc()
{
}
/**
* Attempts to initialize the backend.
*
* @throws Horde_Alarm_Exception
*/
public function initialize()
{
}
/**
* Converts a value from the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _fromDriver($value)
{
return $value;
}
/**
* Converts a value to the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _toDriver($value)
{
return $value;
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Object.php 0000664 0000766 0000024 00000017234 12231336711 015404 0 ustar
* @package Alarm
*/
class Horde_Alarm_Object extends Horde_Alarm
{
protected $_alarms = array();
/**
* Returns a certain alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user.
*
* @return array An alarm hash.
*/
protected function &_findAlarm($id, $user)
{
foreach ($this->_alarms as &$alarm) {
if ($alarm['id'] == $id && $alarm['user'] === $user) {
return $alarm;
}
}
$result = null;
return $result;
}
/**
* Sorts a number of alarms in chronological order.
*/
protected function _sortAlarms($a, $b)
{
$cmp = $a['start']->compareDateTime($b['start']);
if ($cmp) {
return $cmp;
}
if (empty($a['end'])) {
return -1;
}
if (empty($b['end'])) {
return 1;
}
return $a['end']->compareDateTime($b['end']);
}
/**
* Returns a list of alarms from the backend.
*
* @param Horde_Date $time The time when the alarms should be active.
* @param string $user Return alarms for this user, all users if
* null, or global alarms if empty.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
protected function _list($user, Horde_Date $time)
{
$alarms = array();
foreach ($this->_alarms as $alarm) {
if (empty($alarm['dismissed']) &&
((empty($alarm['snooze']) && $alarm['start']->compareDateTime($time) <= 0) ||
$alarm['snooze']->compareDateTime($time) <= 0) &&
(empty($alarm['end']) || $alarm['end']->compareDateTime($time) >= 0) &&
(is_null($user) || empty($alarm['uid']) || $alarm['uid'] = $user)) {
$alarms[] = $alarm;
}
}
usort($alarms, array($this, '_sortAlarms'));
return $alarms;
}
/**
* Returns a list of all global alarms from the backend.
*
* @return array A list of alarm hashes.
*/
protected function _global()
{
return array();
}
/**
* Returns an alarm hash from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user.
*
* @return array An alarm hash.
* @throws Horde_Alarm_Exception
*/
protected function _get($id, $user)
{
$alarm = $this->_findAlarm($id, $user);
if (!$alarm) {
throw new Horde_Alarm_Exception('Alarm not found');
}
return $alarm;
}
/**
* Adds an alarm hash to the backend.
*
* @param array $alarm An alarm hash.
*/
protected function _add(array $alarm)
{
$alarm = array_merge(
array('user' => '',
'end' => null,
'text' => null,
'snooze' => null,
'internal' => null),
$alarm);
$this->_alarms[] = $alarm;
}
/**
* Updates an alarm hash in the backend.
*
* @param array $alarm An alarm hash.
* @param boolean $keepsnooze Whether to keep the snooze value unchanged.
*/
protected function _update(array $alarm, $keepsnooze = false)
{
$user = isset($alarm['user']) ? $alarm['user'] : null;
$al = &$this->_findAlarm($alarm['id'], $user);
foreach (array('start', 'end', 'methods', 'params', 'title', 'text') as $property) {
$al[$property] = isset($alarm[$property]) ? $alarm[$property] : null;
}
if (!$keepsnooze) {
$al['snooze'] = null;
}
}
/**
* Updates internal alarm properties, i.e. properties not determined by
* the application setting the alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param array $internal A hash with the internal data.
*
* @throws Horde_Alarm_Exception
*/
public function internal($id, $user, array $internal)
{
$alarm = &$this->_findAlarm($id, $user);
$alarm['internal'] = $internal;
}
/**
* Returns whether an alarm with the given id exists already.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return boolean True if the specified alarm exists.
* @throws Horde_Alarm_Exception
*/
protected function _exists($id, $user)
{
return (bool)$this->_findAlarm($id, $user);
}
/**
* Delays (snoozes) an alarm for a certain period.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $snooze The snooze time.
*
* @throws Horde_Alarm_Exception
*/
protected function _snooze($id, $user, Horde_Date $snooze)
{
$alarm = &$this->_findAlarm($id, $user);
$alarm['snooze'] = $snooze;
}
/**
* Returns whether an alarm is snoozed.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $time The time when the alarm may be snoozed.
*
* @return boolean True if the alarm is snoozed.
* @throws Horde_Alarm_Exception
*/
protected function _isSnoozed($id, $user, Horde_Date $time)
{
$alarm = $this->_findAlarm($id, $user);
return !empty($alarm['dismissed']) ||
(isset($alarm['snooze']) &&
$alarm['snooze']->compareDateTime($time) >= 0);
}
/**
* Dismisses an alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @throws Horde_Alarm_Exception
*/
protected function _dismiss($id, $user)
{
$alarm = &$this->_findAlarm($id, $user);
$alarm['dismissed'] = true;
}
/**
* Deletes an alarm from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user. All users' alarms if null.
*
* @throws Horde_Alarm_Exception
*/
protected function _delete($id, $user = null)
{
$newAlarms = array();
foreach ($this->_alarms as &$alarm) {
if ($alarm['id'] != $id ||
(!is_null($user) && $alarm['user'] != $user)) {
$newAlarms[] = $alarm;
}
}
$this->_alarms = $newAlarms;
}
/**
* Garbage collects old alarms in the backend.
*
* @throws Horde_Alarm_Exception
*/
protected function _gc()
{
}
/**
* Attempts to initialize the backend.
*
* @throws Horde_Alarm_Exception
*/
public function initialize()
{
}
/**
* Converts a value from the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _fromDriver($value)
{
return $value;
}
/**
* Converts a value to the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _toDriver($value)
{
return $value;
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Sql.php 0000664 0000766 0000024 00000034537 12231336711 014742 0 ustar
* @package Alarm
*/
class Horde_Alarm_Sql extends Horde_Alarm
{
/**
* Handle for the current database connection.
*
* @var Horde_Db_Adapter
*/
protected $_db;
/**
* Constructor.
*
* @param array $params Configuration parameters:
*
* 'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance.
* 'table' - (string) The name of the alarm table in 'database'.
* DEFAULT: 'horde_alarms'
*
*
* @throws Horde_Alarm_Exception
*/
public function __construct(array $params = array())
{
if (!isset($params['db'])) {
throw new Horde_Alarm_Exception('Missing db parameter.');
}
$this->_db = $params['db'];
unset($params['db']);
$params = array_merge(array(
'table' => 'horde_alarms'
), $params);
parent::__construct($params);
}
/**
* Returns a list of alarms from the backend.
*
* @param string $user Return alarms for this user, all users if
* null, or global alarms if empty.
* @param Horde_Date $time The time when the alarms should be active.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
protected function _list($user, Horde_Date $time)
{
$query = sprintf('SELECT alarm_id, alarm_uid, alarm_start, alarm_end, alarm_methods, alarm_params, alarm_title, alarm_text, alarm_snooze, alarm_internal FROM %s WHERE alarm_dismissed = 0 AND ((alarm_snooze IS NULL AND alarm_start <= ?) OR alarm_snooze <= ?) AND (alarm_end IS NULL OR alarm_end >= ?)%s ORDER BY alarm_start, alarm_end',
$this->_params['table'],
is_null($user) ? '' : ' AND (alarm_uid IS NULL OR alarm_uid = ? OR alarm_uid = ?)');
$dt = $time->setTimezone('UTC')->format('Y-m-d\TH:i:s');
$values = array($dt, $dt, $dt);
if (!is_null($user)) {
$values[] = '';
$values[] = (string)$user;
}
try {
$result = $this->_db->selectAll($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
$alarms = array();
foreach ($result as $val) {
$alarms[] = $this->_getHash($val);
}
return $alarms;
}
/**
* Returns a list of all global alarms from the backend.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
protected function _global()
{
$query = sprintf('SELECT alarm_id, alarm_uid, alarm_start, alarm_end, alarm_methods, alarm_params, alarm_title, alarm_text, alarm_snooze, alarm_internal FROM %s WHERE alarm_uid IS NULL OR alarm_uid = \'\' ORDER BY alarm_start, alarm_end',
$this->_params['table']);
try {
$result = $this->_db->selectAll($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
$alarms = array();
foreach ($result as $val) {
$alarms[] = $this->_getHash($val);
}
return $alarms;
}
/**
*/
protected function _getHash(array $alarm)
{
$params = base64_decode($alarm['alarm_params']);
if (!strlen($params) && strlen($alarm['alarm_params'])) {
$params = $alarm['alarm_params'];
}
return array(
'id' => $alarm['alarm_id'],
'user' => $alarm['alarm_uid'],
'start' => new Horde_Date($alarm['alarm_start'], 'UTC'),
'end' => empty($alarm['alarm_end']) ? null : new Horde_Date($alarm['alarm_end'], 'UTC'),
'methods' => @unserialize($alarm['alarm_methods']),
'params' => @unserialize($params),
'title' => $this->_fromDriver($alarm['alarm_title']),
'text' => $this->_fromDriver($alarm['alarm_text']),
'snooze' => empty($alarm['alarm_snooze']) ? null : new Horde_Date($alarm['alarm_snooze'], 'UTC'),
'internal' => empty($alarm['alarm_internal']) ? null : @unserialize($alarm['alarm_internal'])
);
}
/**
* Returns an alarm hash from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return array An alarm hash.
* @throws Horde_Alarm_Exception
*/
protected function _get($id, $user)
{
$query = sprintf('SELECT alarm_id, alarm_uid, alarm_start, alarm_end, alarm_methods, alarm_params, alarm_title, alarm_text, alarm_snooze, alarm_internal FROM %s WHERE alarm_id = ? AND %s',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
try {
$alarm = $this->_db->selectOne($query, array($id, $user));
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
if (empty($alarm)) {
throw new Horde_Alarm_Exception('Alarm not found');
}
return $this->_getHash($alarm);
}
/**
* Adds an alarm hash to the backend.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
protected function _add(array $alarm)
{
$query = sprintf('INSERT INTO %s (alarm_id, alarm_uid, alarm_start, alarm_end, alarm_methods, alarm_params, alarm_title, alarm_text, alarm_snooze) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', $this->_params['table']);
$values = array(
$alarm['id'],
isset($alarm['user']) ? $alarm['user'] : '',
(string)$alarm['start']->setTimezone('UTC'),
empty($alarm['end']) ? null : (string)$alarm['end']->setTimezone('UTC'),
serialize($alarm['methods']),
base64_encode(serialize($alarm['params'])),
$this->_toDriver($alarm['title']),
empty($alarm['text']) ? null : $this->_toDriver($alarm['text']),
null
);
try {
$this->_db->insert($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Updates an alarm hash in the backend.
*
* @param array $alarm An alarm hash.
* @param boolean $keepsnooze Whether to keep the snooze value unchanged.
*
* @throws Horde_Alarm_Exception
*/
protected function _update(array $alarm, $keepsnooze = false)
{
$query = sprintf('UPDATE %s set alarm_start = ?, alarm_end = ?, alarm_methods = ?, alarm_params = ?, alarm_title = ?, alarm_text = ?%s WHERE alarm_id = ? AND %s',
$this->_params['table'],
$keepsnooze ? '' : ', alarm_snooze = NULL, alarm_dismissed = 0',
isset($alarm['user']) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array((string)$alarm['start']->setTimezone('UTC'),
empty($alarm['end']) ? null : (string)$alarm['end']->setTimezone('UTC'),
serialize($alarm['methods']),
base64_encode(serialize($alarm['params'])),
$this->_toDriver($alarm['title']),
empty($alarm['text'])
? null
: $this->_toDriver($alarm['text']),
$alarm['id'],
isset($alarm['user']) ? $alarm['user'] : '');
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Updates internal alarm properties, i.e. properties not determined by
* the application setting the alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param array $internal A hash with the internal data.
*
* @throws Horde_Alarm_Exception
*/
public function internal($id, $user, array $internal)
{
$query = sprintf('UPDATE %s set alarm_internal = ? WHERE alarm_id = ? AND %s',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array(serialize($internal), $id, $user);
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Returns whether an alarm with the given id exists already.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return boolean True if the specified alarm exists.
* @throws Horde_Alarm_Exception
*/
protected function _exists($id, $user)
{
$query = sprintf('SELECT 1 FROM %s WHERE alarm_id = ? AND %s',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
try {
return ($this->_db->selectValue($query, array($id, $user)) == 1);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Delays (snoozes) an alarm for a certain period.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $snooze The snooze time.
*
* @throws Horde_Alarm_Exception
*/
protected function _snooze($id, $user, Horde_Date $snooze)
{
$query = sprintf('UPDATE %s set alarm_snooze = ? WHERE alarm_id = ? AND %s',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array((string)$snooze->setTimezone('UTC'), $id, $user);
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Returns whether an alarm is snoozed.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $time The time when the alarm may be snoozed.
*
* @return boolean True if the alarm is snoozed.
* @throws Horde_Alarm_Exception
*/
protected function _isSnoozed($id, $user, Horde_Date $time)
{
$query = sprintf('SELECT 1 FROM %s WHERE alarm_id = ? AND %s AND (alarm_dismissed = 1 OR (alarm_snooze IS NOT NULL AND alarm_snooze >= ?))',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
try {
return $this->_db->selectValue($query, array($id, $user, (string)$time->setTimezone('UTC')));
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Dismisses an alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @throws Horde_Alarm_Exception
*/
protected function _dismiss($id, $user)
{
$query = sprintf('UPDATE %s set alarm_dismissed = 1 WHERE alarm_id = ? AND %s',
$this->_params['table'],
!empty($user) ? 'alarm_uid = ?' : '(alarm_uid = ? OR alarm_uid IS NULL)');
$values = array($id, $user);
try {
$this->_db->update($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Deletes an alarm from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user. All users' alarms if null.
*
* @throws Horde_Alarm_Exception
*/
protected function _delete($id, $user = null)
{
$query = sprintf('DELETE FROM %s WHERE alarm_id = ?', $this->_params['table']);
$values = array($id);
if (!is_null($user)) {
$query .= empty($user)
? ' AND (alarm_uid IS NULL OR alarm_uid = ?)'
: ' AND alarm_uid = ?';
$values[] = $user;
}
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Alarm_Exception($e);
}
}
/**
* Garbage collects old alarms in the backend.
*/
protected function _gc()
{
$query = sprintf('DELETE FROM %s WHERE alarm_end IS NOT NULL AND alarm_end < ?', $this->_params['table']);
$end = new Horde_Date(time());
$this->_db->delete($query, array((string)$end->setTimezone('UTC')));
}
/**
* Initialization tasks.
*
* @throws Horde_Alarm_Exception
*/
public function initialize()
{
/* Handle any database specific initialization code to run. */
switch ($this->_db->adapterName()) {
case 'PDO_Oci':
$query = "ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'";
$this->_db->select($query);
break;
case 'PDO_PostgreSQL':
$query = "SET datestyle TO 'iso'";
$this->_db->select($query);
break;
}
}
/**
* Converts a value from the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _fromDriver($value)
{
return Horde_String::convertCharset($value, $this->_params['charset'], 'UTF-8');
}
/**
* Converts a value to the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
protected function _toDriver($value)
{
return Horde_String::convertCharset($value, 'UTF-8', $this->_params['charset']);
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm/Translation.php 0000664 0000766 0000024 00000003212 12231336711 016463 0 ustar
* @package Alarm
*/
class Horde_Alarm_Translation extends Horde_Translation
{
/**
* Returns the translation of a message.
*
* @var string $message The string to translate.
*
* @return string The string translation, or the original string if no
* translation exists.
*/
static public function t($message)
{
self::$_domain = 'Horde_Alarm';
self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Alarm/locale';
return parent::t($message);
}
/**
* Returns the plural translation of a message.
*
* @param string $singular The singular version to translate.
* @param string $plural The plural version to translate.
* @param integer $number The number that determines singular vs. plural.
*
* @return string The string translation, or the original string if no
* translation exists.
*/
static public function ngettext($singular, $plural, $number)
{
self::$_domain = 'Horde_Alarm';
self::$_directory = '@data_dir@' == '@'.'data_dir'.'@' ? __DIR__ . '/../../../locale' : '@data_dir@/Horde_Alarm/locale';
return parent::ngettext($singular, $plural, $number);
}
}
Horde_Alarm-2.0.5/lib/Horde/Alarm.php 0000664 0000766 0000024 00000036521 12231336711 014176 0 ustar
* @package Alarm
*/
abstract class Horde_Alarm
{
/**
* Logger.
*
* @var Horde_Log_Logger
*/
protected $_logger;
/**
* Alarm loader callback.
*
* @var mixed
*/
protected $_loader;
/**
* Hash containing connection parameters.
*
* @var array
*/
protected $_params = array(
'ttl' => 300
);
/**
* All registered notification handlers.
*
* @var array
*/
protected $_handlers = array();
/**
* Whether handler classes have been dynamically loaded already.
*
* @var boolean
*/
protected $_handlersLoaded = false;
/**
* Constructor.
*
* @param array $params Configuration parameters:
*
* 'logger' - (Horde_Log_Logger) A logger instance.
* 'ttl' - (integer) Time to live value, in seconds.
*
*/
public function __construct(array $params = array())
{
if (isset($params['logger'])) {
$this->_logger = $params['logger'];
unset($params['logger']);
}
if (isset($params['loader'])) {
$this->_loader = $params['loader'];
unset($params['loader']);
}
$this->_params = array_merge($this->_params, $params);
}
/**
* Returns a list of alarms from the backend.
*
* @param string $user Return alarms for this user, all users if
* null, or global alarms if empty.
* @param Horde_Date $time The time when the alarms should be active.
* Defaults to now.
* @param boolean $load Update active alarms from all applications?
* @param boolean $preload Preload alarms that go off within the next
* ttl time span?
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
public function listAlarms($user = null, Horde_Date $time = null,
$load = false, $preload = true)
{
if (empty($time)) {
$time = new Horde_Date(time());
}
if ($load && is_callable($this->_loader)) {
call_user_func($this->_loader, $user, $preload);
}
$alarms = $this->_list($user, $time);
foreach (array_keys($alarms) as $alarm) {
if (isset($alarms[$alarm]['mail']['body'])) {
$alarms[$alarm]['mail']['body'] = $this->_fromDriver($alarms[$alarm]['mail']['body']);
}
}
return $alarms;
}
/**
* Returns a list of alarms from the backend.
*
* @param Horde_Date $time The time when the alarms should be active.
* @param string $user Return alarms for this user, all users if
* null, or global alarms if empty.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
abstract protected function _list($user, Horde_Date $time);
/**
* Returns a list of all global alarms from the backend.
*
* @return array A list of alarm hashes.
* @throws Horde_Alarm_Exception
*/
public function globalAlarms()
{
$alarms = $this->_global();
foreach (array_keys($alarms) as $alarm) {
if (isset($alarms[$alarm]['mail']['body'])) {
$alarms[$alarm]['mail']['body'] = $this->_fromDriver($alarms[$alarm]['mail']['body']);
}
}
return $alarms;
}
/**
* Returns a list of all global alarms from the backend.
*
* @return array A list of alarm hashes.
*/
abstract protected function _global();
/**
* Returns an alarm hash from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return array An alarm hash. Contains the following:
*
* id: Unique alarm id.
* user: The alarm's user. Empty if a global alarm.
* start: The alarm start as a Horde_Date.
* end: The alarm end as a Horde_Date.
* methods: The notification methods for this alarm.
* params: The paramters for the notification methods.
* title: The alarm title.
* text: An optional alarm description.
* snooze: The snooze time (next time) of the alarm as a Horde_Date.
* internal: Holds internally used data.
*
* @throws Horde_Alarm_Exception
*/
public function get($id, $user)
{
$alarm = $this->_get($id, $user);
if (isset($alarm['mail']['body'])) {
$alarm['mail']['body'] = $this->_fromDriver($alarm['mail']['body']);
}
return $alarm;
}
/**
* Returns an alarm hash from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return array An alarm hash.
* @throws Horde_Alarm_Exception
*/
abstract protected function _get($id, $user);
/**
* Stores an alarm hash in the backend.
*
* The alarm will be added if it doesn't exist, and updated otherwise.
*
* @param array $alarm An alarm hash. See self::get() for format.
* @param boolean $keep Whether to keep the snooze value and notification
* status unchanged. If true, the alarm will get
* "un-snoozed", and notifications (like mails) are
* sent again.
*
* @throws Horde_Alarm_Exception
*/
public function set(array $alarm, $keep = false)
{
if (isset($alarm['mail']['body'])) {
$alarm['mail']['body'] = $this->_toDriver($alarm['mail']['body']);
}
if ($this->exists($alarm['id'], isset($alarm['user']) ? $alarm['user'] : '')) {
$this->_update($alarm, $keep);
if (!$keep) {
foreach ($this->_handlers as &$handler) {
$handler->reset($alarm);
}
}
} else {
$this->_add($alarm);
}
}
/**
* Adds an alarm hash to the backend.
*
* @param array $alarm An alarm hash.
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _add(array $alarm);
/**
* Updates an alarm hash in the backend.
*
* @param array $alarm An alarm hash.
* @param boolean $keepsnooze Whether to keep the snooze value unchanged.
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _update(array $alarm, $keepsnooze = false);
/**
* Updates internal alarm properties, i.e. properties not determined by
* the application setting the alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param array $internal A hash with the internal data.
*
* @throws Horde_Alarm_Exception
*/
abstract public function internal($id, $user, array $internal);
/**
* Returns whether an alarm with the given id exists already.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return boolean True if the specified alarm exists.
*/
public function exists($id, $user)
{
try {
return $this->_exists($id, $user);
} catch (Horde_Alarm_Exception $e) {
return false;
}
}
/**
* Returns whether an alarm with the given id exists already.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @return boolean True if the specified alarm exists.
* @throws Horde_Alarm_Exception
*/
abstract protected function _exists($id, $user);
/**
* Delays (snoozes) an alarm for a certain period.
*
* @param string $id The alarm's unique id.
* @param string $user The notified user.
* @param integer $minutes The delay in minutes. A negative value
* dismisses the alarm completely.
*
* @throws Horde_Alarm_Exception
*/
public function snooze($id, $user, $minutes)
{
if (empty($user)) {
throw new Horde_Alarm_Exception('This alarm cannot be snoozed.');
}
$alarm = $this->get($id, $user);
if ($alarm) {
if ($minutes > 0) {
$alarm['snooze'] = new Horde_Date(time());
$alarm['snooze']->min += $minutes;
$this->_snooze($id, $user, $alarm['snooze']);
return;
}
$this->_dismiss($id, $user);
}
}
/**
* Delays (snoozes) an alarm for a certain period.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $snooze The snooze time.
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _snooze($id, $user, Horde_Date $snooze);
/**
* Returns whether an alarm is snoozed.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $time The time when the alarm may be snoozed.
* Defaults to now.
*
* @return boolean True if the alarm is snoozed.
*
* @throws Horde_Alarm_Exception
*/
public function isSnoozed($id, $user, Horde_Date $time = null)
{
if (is_null($time)) {
$time = new Horde_Date(time());
}
return (bool)$this->_isSnoozed($id, $user, $time);
}
/**
* Returns whether an alarm is snoozed.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
* @param Horde_Date $time The time when the alarm may be snoozed.
*
* @return boolean True if the alarm is snoozed.
* @throws Horde_Alarm_Exception
*/
abstract protected function _isSnoozed($id, $user, Horde_Date $time);
/**
* Dismisses an alarm.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _dismiss($id, $user);
/**
* Deletes an alarm from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user. All users' alarms if null.
*
* @throws Horde_Alarm_Exception
*/
function delete($id, $user = null)
{
$this->_delete($id, $user);
}
/**
* Deletes an alarm from the backend.
*
* @param string $id The alarm's unique id.
* @param string $user The alarm's user. All users' alarms if null.
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _delete($id, $user = null);
/**
* Notifies the user about any active alarms.
*
* @param string $user Notify this user, all users if null, or guest
* users if empty.
* @param boolean $load Update active alarms from all applications?
* @param boolean $preload Preload alarms that go off within the next
* ttl time span?
* @param array $exclude Don't notify with these methods.
*
* @throws Horde_Alarm_Exception
*/
public function notify($user = null, $load = true, $preload = true,
array $exclude = array())
{
try {
$alarms = $this->listAlarms($user, null, $load, $preload);
} catch (Horde_Alarm_Exception $e) {
if ($this->_logger) {
$this->_logger->log($e, 'ERR');
}
throw $e;
}
if (empty($alarms)) {
return;
}
$handlers = $this->handlers();
foreach ($alarms as $alarm) {
foreach ($alarm['methods'] as $alarm_method) {
if (isset($handlers[$alarm_method]) &&
!in_array($alarm_method, $exclude)) {
$handlers[$alarm_method]->notify($alarm);
}
}
}
}
/**
* Registers a notification handler.
*
* @param string $name A handler name.
* @param Horde_Alarm_Handler $handler A notification handler.
*/
public function addHandler($name, Horde_Alarm_Handler $handler)
{
$this->_handlers[$name] = $handler;
$handler->alarm = $this;
}
/**
* Returns a list of available notification handlers and parameters.
*
* The returned list is a hash with method names as the keys and
* optionally associated parameters as values. The parameters are hashes
* again with parameter names as keys and parameter information as
* values. The parameter information is hash with the following keys:
* 'desc' contains a parameter description; 'required' specifies whether
* this parameter is required.
*
* @return array List of methods and parameters.
*/
public function handlers()
{
if (!$this->_handlersLoaded) {
foreach (new DirectoryIterator(__DIR__ . '/Alarm/Handler') as $file) {
if (!$file->isFile() || substr($file->getFilename(), -4) != '.php') {
continue;
}
$handler = Horde_String::lower($file->getBasename('.php'));
if (isset($this->_handlers[$handler])) {
continue;
}
require_once $file->getPathname();
$class = 'Horde_Alarm_Handler_' . $file->getBasename('.php');
if (class_exists($class, false)) {
$this->addHandler($handler, new $class());
}
}
$this->_handlerLoaded = true;
}
return $this->_handlers;
}
/**
* Garbage collects old alarms in the backend.
*
* @param boolean $force Force garbace collection? If false, GC happens
* with a 1% chance.
*
* @throws Horde_Alarm_Exception
*/
public function gc($force = false)
{
/* A 1% chance we will run garbage collection during a call. */
if ($force || rand(0, 99) == 0) {
$this->_gc();
}
}
/**
* Garbage collects old alarms in the backend.
*
* @throws Horde_Alarm_Exception
*/
abstract protected function _gc();
/**
* Attempts to initialize the backend.
*
* @throws Horde_Alarm_Exception
*/
abstract public function initialize();
/**
* Converts a value from the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
abstract protected function _fromDriver($value);
/**
* Converts a value to the driver's charset.
*
* @param mixed $value Value to convert.
*
* @return mixed Converted value.
*/
abstract protected function _toDriver($value);
}
Horde_Alarm-2.0.5/locale/ar/LC_MESSAGES/Horde_Alarm.mo 0000664 0000766 0000024 00000000674 12231336711 016762 0 ustar , <