package.xml 0000664 0001750 0001750 00000140557 12642740277 011326 0 ustar jan jan
Horde_Prefspear.horde.orgHorde Preferences APIThe Horde_Prefs package provides a common abstracted interface into the various preferences storage mediums. It also includes all of the functions for retrieving, storing, and checking preference values.Michael Slusarzslusarzslusarz@horde.orgyesChuck Hagenbuchchuckchuck@horde.orgyesJan Schneiderjanjan@horde.orgyes2016-01-052.7.52.7.0stablestableLGPL-2.1
* [jan] Improve Oracle compatibility.
5.3.06.0.0alpha16.0.0alpha11.7.0Horde_Exceptionpear.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_Translationpear.horde.org2.2.03.0.0alpha13.0.0alpha1Horde_Utilpear.horde.org2.0.03.0.0alpha13.0.0alpha1jsonHorde_Autoloaderpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Cachepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Dbpear.horde.org2.2.03.0.0alpha13.0.0alpha1Horde_Imagepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Imsppear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Kolab_Storagepear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Ldappear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Mongopear.horde.org1.0.02.0.0alpha12.0.0alpha1Horde_Testpear.horde.org2.1.03.0.0alpha13.0.0alpha10.0.10.0.1alphaalpha2003-07-05LGPL-2.1
Initial release as a PEAR package
0.0.20.0.2alphaalpha2004-01-01LGPL-2.1
* Add failover functionality, if one of the drivers is not available will fall back to session-based preferences.
* Add support for separate read and write DB servers for the sql driver.
2006-05-080.0.30.0.3alphaalphaLGPL-2.1
* Data in postgres must be stored in a BYTEA field, not a TEXT field (Bug #8130).
* Converted to package.xml 2.0 for pear.horde.org
* Added files-based preferences backend (thomas.jarosch@intra2net.com, Request #6653)
1.0.0alpha11.0.0alphaalpha2011-03-08LGPL-2.1
* First alpha release for Horde 4.
* Abstract caching code into Horde_Prefs_Cache.
* Removed Horde_Prefs_Storage_Kolab driver.
* Abstract storage code into Horde_Prefs_Storage.
* Add array access API to Horde_Prefs.
* Remove dependency on horde/Core.
* Use Horde_Db as backend for Sql driver.
* Moved UI code to horde/Core.
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.
* [mjr] Fix IMSP driver.
1.0.0RC21.0.0betabeta2011-03-29LGPL-2.1
* Second release candidate for Horde 4.
1.0.01.0.0stablestable2011-04-06LGPL-2.1
* First stable release for Horde 4.
1.1.01.1.0stablestable2011-06-01LGPL-2.1
* [gwr] Added a script for exporting/importing preferences from/to a backend.
* [gwr] Added support for listing the scopes in some storage backends.
* [gwr] Fixed the driver for the Kolab IMAP backend.
1.1.11.1.0stablestable2011-06-03LGPL-2.1
* [gwr] Revert dependency on Kolab_Storage-1.1.*
1.1.21.1.0stablestable2011-07-05LGPL-2.1
* [jan] Update Lithuanian translation.
* [jan] Update Brazilian Portuguese translation.
* [mms] Null argument to Horde_Prefs#remove() will remove all prefs (Bug #10241).
1.1.31.1.0stablestable2011-07-27LGPL-2.1
* [jan] Update Latvian translation.
1.1.41.1.0stablestable2011-08-30LGPL-2.1
* [mms] Fix identities when default_identity is locked (Bug #10098).
1.1.51.1.0stablestable2011-11-08LGPL-2.1
* [jan] Skip Kolab test if Horde_Kolab_Storage is not installed.
1.1.61.1.0stablestable2011-12-06LGPL-2.1
* [jan] Update Japanese translation (Hiromi Kimura <hiromi@tac.tsukuba.ac.jp>).
1.1.71.1.0stablestable2011-12-13LGPL-2.1
* [jan] Catch exceptions from storage writing during shutdown.
* [jan] Use binary column type for preference values (Bug #10803).
1.1.81.1.0stablestable2012-04-10LGPL-2.1
* [jan] Update translations.
1.1.91.1.0stablestable2012-04-10LGPL-2.1
*
2012-07-052.0.0alpha11.1.0alphastableLGPL-2.1
* First alpha release for Horde 5.
* [mms] Use new Horde_Mail API.
2.0.0beta11.1.0betastable2012-07-19LGPL-2.1
* First beta release for Horde 5.
2.0.01.1.0stablestable2012-10-30LGPL-2.1
* First stable release for Horde 5.
* [jan] Update Polish translation (Krzysztof Kozera <krzysztof113@o2.pl>).
2.0.11.1.0stablestable2012-11-06LGPL-2.1
* [jan] Update Dutch translation (Arjen de Korte <build+horde@de-korte.org>).
2.1.02.1.0stablestable2013-01-09LGPL-2.1
* [mms] When removing a pref, reset its value in the cached scope to the default (Bug #11895).
* [mms] Delete preference from storage backend when calling Horde_Prefs#remove().
* [mms] Add throw parameter to Horde_Prefs#store().
* [jan] Update Basque translation (Ibon Igartua <ibon.igartua@ehu.es>).
* [jan] Fix creating storage folder for Kolab/IMAP backends (Bug #11751).
2.2.02.2.0stablestable2013-01-29LGPL-2.1
* [mms] Horde_Prefs_Identity#getDefaultFromAddress() now returns a Horde_Mail_Rfc822_Address object.
* [jan] Update French translation (Paul De Vlieger <paul.de_vlieger@moniut.univ-bpclermont.fr>).
2.3.02.2.0stablestable2013-02-12LGPL-2.1
* [jan] Add Horde_Prefs_Identity#getFromAddress().
* [jan] Fix LDAP driver and use Horde_Ldap (Heinz Schweiger <heinz@htl-steyr.ac.at>, Request #11697).
2.3.12.2.0stablestable2013-02-13LGPL-2.1
* [mms] Fix regression that broke Horde_Prefs_Identity#getDefaultFromAddress() in 2.3.0.
2.3.22.2.0stablestable2013-03-05LGPL-2.1
* [jan] Improve unit tests.
* [mms] Simplify Horde_Prefs_Scope iterator.
2.4.02.2.0stablestable2013-05-06LGPL-2.1
* [mms] Add MongoDB storage driver.
* [mms] Fix removing preference from backend (Bug #12207).
* [mms] More compact internal/serialized representation of data in Horde_Prefs_Scope.
2.4.12.2.0stablestable2013-05-16LGPL-2.1
* [mms] Fix removing prefs from storage backends (Bug #12208).
* [mms] Fix fatal error in Horde_Prefs_Scope#valid().
2.5.02.5.0stablestable2013-07-16LGPL-2.1
* [mms] Add ability to override locked pref status when setting value via Horde_Prefs#setValue().
2.5.12.5.0stablestable2013-10-28LGPL-2.1
* [mms] Fix iteration of Horde_Prefs_Scope object.
2.5.22.5.0stablestable2013-11-11LGPL-2.1
* [mms] Correct fix for iteration of Horde_Prefs_Scope object.
2.6.02.6.0stablestable2014-05-02LGPL-2.1
* [mms] Add Horde_Prefs#getCache().
* [mms] Add Horde_Cache based cache driver.
* [mms] Pref scopes are now loaded on-demand.
* [mms] Add Horde_Prefs#changeScope().
2.7.02.7.0stablestable2014-08-29LGPL-2.1
* [mms] Add ArrayAccess, Countable, and Iterator functionality to the Horde_Prefs_Identity object.
2.7.12.7.0stablestable2014-12-29LGPL-2.1
* [mms] Fix Horde_Prefs#isDefault() to return true if the given pref name doesn't exist in a scope.
2.7.22.7.0stablestable2015-02-10LGPL-2.1
* [mms] Removed unused 'password' parameter.
2.7.32.7.0stablestable2015-04-28LGPL-2.1
* [jan] Fix issues with certain locales like Turkish.
2.7.42.7.0stablestable2015-07-31LGPL-2.1
* [jan] Updated UK translation.
2.7.52.7.0stablestable2016-01-05LGPL-2.1
* [jan] Improve Oracle compatibility.
Horde_Prefs-2.7.5/bin/horde-prefs 0000775 0001750 0001750 00000012204 12642740277 014757 0 ustar jan jan #!/usr/bin/env php
*
*
* The following example is the necessary setup for a SQL database:
*
*
*
*
* Copyright 2011-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Gunnar Wrobel
*/
if (strpos('@php_dir@', '@php_dir') === 0) {
set_include_path(__DIR__ . '/../../../lib' . PATH_SEPARATOR . get_include_path());
}
@include 'Horde/Autoloader/Default.php';
if (!class_exists('Horde_Autoloader_Default')) {
die('The "Horde_Autoloader" PEAR package is unavailable. Install it with "pear install Horde_Autoloader" first!' . "\n");
}
$args = $_SERVER['argv'];
array_shift($args);
if (empty($args) || empty($args[0])) {
die('You must specify a path to the configuration file as the first argument!' . "\n");
}
@include realpath($args[0]);
if (empty($conf)) {
die(sprintf('%s did not provide the expected "$conf" configuration array!', $args[0]) . "\n");
}
if (!isset($conf['driver'])) {
die(sprintf('%s did not provide the expected driver configuration ($conf[\'driver\'])!', $args[0]) . "\n");
}
$storage_class = 'Horde_Prefs_Storage_' . Horde_String::ucfirst($conf['driver']);
if (empty($args[1])) {
die('You must specify a the id of the user you want to work with as second argument!' . "\n");
}
$storage = new $storage_class($args[1], $conf['params']);
if (empty($args[2])) {
die('You must specify the action to perform as third argument (one of list, print, export, write)!' . "\n");
}
class ScopeExporter
{
public $scope;
public $data;
public function __construct($scope)
{
$this->scope = $scope;
}
public function set($name, $val)
{
$this->data[$name] = $val;
}
}
class ScopeImporter
{
public $scope;
public $data;
public function __construct($scope, $data)
{
$this->scope = $scope;
$this->data = $data;
}
public function getDirty()
{
return array_keys($this->data);
}
public function get($name)
{
return $this->data[$name];
}
}
switch ($args[2]) {
case 'list':
foreach ($storage->listScopes() as $scope) {
print $scope . "\n";
}
break;
case 'print':
if (empty($args[3])) {
die('You must specify the scope to act upon as fourth argument!' . "\n");
}
$scope = new ScopeExporter($args[3]);
$storage->get($scope);
foreach ($scope->data as $name => $val) {
print $name . ": " . $val . "\n";
}
break;
case 'export':
if (empty($args[3])) {
die('You must specify the scope to act upon as fourth argument!' . "\n");
}
$scope = new ScopeExporter($args[3]);
$storage->get($scope);
if (empty($args[4])) {
die('You must specify the file to export to as fifth argument!' . "\n");
}
file_put_contents($args[4], serialize($scope->data));
break;
case 'import':
if (empty($args[3])) {
die('You must specify the scope to act upon as fourth argument!' . "\n");
}
if (empty($args[4])) {
die('You must specify the file to import to as fifth argument!' . "\n");
}
$data = unserialize(file_get_contents($args[4]));
if ($data) {
$scope = new ScopeImporter($args[3], $data);
$storage->store($scope);
} else {
die(sprintf('Failed importing preference data from %s!', $args[4]) . "\n");
}
break;
}
Horde_Prefs-2.7.5/doc/Horde/Prefs/COPYING 0000664 0001750 0001750 00000057646 12642740277 016006 0 ustar jan jan 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_Prefs-2.7.5/lib/Horde/Prefs/Cache/Base.php 0000664 0001750 0001750 00000003412 12642740277 017320 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
abstract class Horde_Prefs_Cache_Base
{
/**
* Configuration parameters.
* 'user' is always available as an entry.
*
* @var string
*/
protected $_params = array();
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Additional configuration parameters.
*/
public function __construct($user, array $params = array())
{
$this->_params = array_merge($this->_params, $params);
$this->_params['user'] = $user;
}
/**
* Retrieves the requested preferences scope from the cache backend.
*
* @param string $scope Scope specifier.
*
* @return mixed Returns false if no data is available, otherwise the
* Horde_Prefs_Scope object.
* @throws Horde_Prefs_Exception
*/
abstract public function get($scope);
/**
* Stores preferences in the cache backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object to store.
*
* @throws Horde_Prefs_Exception
*/
abstract public function store($scope_ob);
/**
* Removes preferences from the cache.
*
* @param string $scope The scope to remove. If null, clears entire
* cache.
*
* @throws Horde_Prefs_Exception
*/
abstract public function remove($scope = null);
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Cache/HordeCache.php 0000664 0001750 0001750 00000004103 12642740277 020431 0 ustar jan jan
* @category Horde
* @copyright 2014-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
* @since 2.6.0
*/
class Horde_Prefs_Cache_HordeCache extends Horde_Prefs_Cache_Base
{
/**
* @param array $params Additional configuration parameters:
* - cache: (Horde_Cache) [REQUIRED] Cache object.
* - prefix: (string) Cache prefix.
*/
public function __construct($user, array $params = array())
{
if (!isset($params['cache'])) {
throw new InvalidArgumentException('Missing cache parameter.');
}
parent::__construct($user, array_merge(array(
'prefix' => ''
), $params));
$this->_params['cprefix'] = implode('|', array(
$this->_params['user'],
$this->_params['prefix']
));
}
/**
*/
public function get($scope)
{
return @unserialize(
$this->_params['cache']->get($this->_cacheId($scope), 0)
);
}
/**
*/
public function store($scope_ob)
{
$this->_params['cache']->set(
$this->_cacheId($scope_ob->scope),
serialize($scope_ob)
);
}
/**
*/
public function remove($scope = null)
{
if (!is_null($scope)) {
$this->_params['cache']->expire($this->_cacheId($scope));
}
}
/**
* Get cache ID.
*
* @param string $scope Scope ID.
*
* @return string Cache ID.
*/
protected function _cacheId($scope)
{
return $this->_params['cprefix'] . '|' . $scope;
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Cache/Null.php 0000664 0001750 0001750 00000001307 12642740277 017361 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Cache_Null extends Horde_Prefs_Cache_Base
{
/**
*/
public function get($scope)
{
return false;
}
/**
*/
public function store($scope_ob)
{
}
/**
*/
public function remove($scope = null)
{
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Cache/Session.php 0000664 0001750 0001750 00000002455 12642740277 020077 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Cache_Session extends Horde_Prefs_Cache_Base
{
/**
* Session key.
*
* @var string
*/
protected $_key;
/**
*/
public function __construct($user, array $params = array())
{
parent::__construct($user, $params);
$this->_key = 'horde_prefs_cache_' . $this->_params['user'];
}
/**
*/
public function get($scope)
{
return isset($_SESSION[$this->_key][$scope])
? $_SESSION[$this->_key][$scope]
: false;
}
/**
*/
public function store($scope_ob)
{
$_SESSION[$this->_key][$scope_ob->getScope()] = $scope_ob;
}
/**
*/
public function remove($scope = null)
{
if (is_null($scope)) {
unset($_SESSION[$this->_key]);
} else {
unset($_SESSION[$this->_key][$scope]);
}
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Base.php 0000664 0001750 0001750 00000004766 12642740277 017736 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
abstract class Horde_Prefs_Storage_Base
{
/**
* Configuration parameters.
* 'user' is always available as an entry.
*
* @var string
*/
protected $_params = array();
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Additional configuration parameters.
*/
public function __construct($user, array $params = array())
{
$this->_params = array_merge($this->_params, $params);
$this->_params['user'] = (string)$user;
}
/**
* Get the list of driver parameters.
*
* @return array Driver parameters.
*/
public function getParams()
{
return $this->_params;
}
/**
* Retrieves the requested preferences scope from the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @return Horde_Prefs_Scope The modified scope object.
* @throws Horde_Prefs_Exception
*/
abstract public function get($scope_ob);
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
abstract public function store($scope_ob);
/**
* Called whenever a preference value is changed.
*
* @param string $scope Scope specifier.
* @param string $pref The preference name.
*/
public function onChange($scope, $pref)
{
}
/**
* Removes preferences from the backend.
*
* @param string $scope The scope of the prefs to clear. If null, clears
* all scopes.
* @param string $pref The pref to clear. If null, clears the entire
* scope.
*
* @throws Horde_Prefs_Exception
*/
abstract public function remove($scope = null, $pref = null);
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
throw new Horde_Prefs_Exception('Not implemented!');
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/File.php 0000664 0001750 0001750 00000013166 12642740277 017735 0 ustar jan jan
* @author Michael Slusarz
* @category Horde
* @package Prefs
*/
class Horde_Prefs_Storage_File extends Horde_Prefs_Storage_Base
{
/* Current version number of the data format */
const VERSION = 2;
/**
* Cached unserialized data of all scopes.
*
* @var array
*/
protected $_fileCache = null;
/**
* Full path to the current preference file.
*
* @var string
*/
protected $_fullpath;
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters:
*
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
// Sanity check for directory
if (empty($params['directory']) || !is_dir($params['directory'])) {
throw new InvalidArgumentException('Preference storage directory is not available.');
}
if (!is_writable($params['directory'])) {
throw new InvalidArgumentException(sprintf('Directory %s is not writeable.', $params['directory']));
}
parent::__construct($user, $params);
$this->_fullpath = $this->_params['directory'] . '/' . basename($this->_params['user']) . '.prefs';
}
/**
* Retrieves the requested preferences scope from the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @return Horde_Prefs_Scope The modified scope object.
* @throws Horde_Prefs_Exception
*/
public function get($scope_ob)
{
if ($this->_loadFileCache() &&
isset($this->_fileCache[$scope_ob->scope])) {
foreach ($this->_fileCache[$scope_ob->scope] as $name => $val) {
$scope_ob->set($name, $val);
}
}
return $scope_ob;
}
/**
* Load the preferences from the files.
*
* @return boolean True on success.
* @throws Horde_Prefs_Exception
*/
protected function _loadFileCache()
{
if (is_null($this->_fileCache)) {
// Try to read
if (!file_exists($this->_fullpath)) {
$this->_fileCache = array(
'__file_version' => self::VERSION
);
return false;
}
$this->_fileCache = @unserialize(file_get_contents($this->_fullpath));
// Check version number. We can call format transformations hooks
// in the future.
if (!is_array($this->_fileCache) ||
!array_key_exists('__file_version', $this->_fileCache) ||
!($this->_fileCache['__file_version'] == self::VERSION)) {
if ($this->_fileCache['__file_version'] == 1) {
$this->updateFileFormat();
} else {
throw new Horde_Prefs_Exception(sprintf('Wrong version number found: %s (should be %d)', $this->_fileCache['__file_version'], self::VERSION));
}
}
}
return true;
}
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
public function store($scope_ob)
{
$this->_loadFileCache();
/* Driver has no support for storing locked status. */
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
unset($this->_fileCache[$scope_ob->scope][$name]);
} else {
$this->_fileCache[$scope_ob->scope][$name] = $value;
}
}
$tmp_file = Horde_Util::getTempFile('PrefsFile', true, $this->_params['directory']);
if ((file_put_contents($tmp_file, serialize($this->_fileCache)) === false) ||
(@rename($tmp_file, $this->_fullpath) === false)) {
throw new Horde_Prefs_Exception(sprintf('Write of preferences to %s failed', $this->_fullpath));
}
}
/**
* Removes preferences from the backend.
*
* @param string $scope The scope of the prefs to clear. If null, clears
* all scopes.
* @param string $pref The pref to clear. If null, clears the entire
* scope.
*
* @throws Horde_Db_Exception
*/
public function remove($scope = null, $pref = null)
{
// TODO
}
/* Helper functions. */
/**
* Updates format of file.
*/
public function updateFileFormat()
{
$new_vers = array('__file_version' => self::VERSION);
unset($this->_fileCache['__file_version']);
foreach ($this->_fileCache as $scope => $prefs) {
foreach ($prefs as $name => $pref) {
$new_vers[$scope][$name] = $pref['v'];
}
}
$this->_fileCache = $new_vers;
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
$this->_loadFileCache();
return array_diff(
array_keys($this->_fileCache), array('__file_version')
);
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Imsp.php 0000664 0001750 0001750 00000003611 12642740277 017760 0 ustar jan jan
* @category Horde
* @package Prefs
*/
class Horde_Prefs_Storage_Imsp extends Horde_Prefs_Storage_Base
{
/**
* Handle for the IMSP server connection.
*
* @var Horde_Imsp_Options
*/
protected $_imsp;
public function __construct($user, array $params = array())
{
if (empty($params['imsp'])) {
throw new InvalidArguementException('Missing required imsp parameter.');
}
$this->_imsp = $params['imsp'];
parent::__construct($user, $params);
}
/**
*/
public function get($scope_ob)
{
try {
$prefs = $this->_imsp->get($scope_ob->scope . '.*');
} catch (Horde_Imsp_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($prefs as $name => $val) {
$name = str_replace($scope_ob->scope . '.', '', $name);
if ($val != '-') {
$scope_ob->set($name, $val);
}
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
/* Driver has no support for storing locked status. */
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
try {
$this->_imsp->set($scope_ob->scope . '.' . $name, $value ? $value : '-');
} catch (Horde_Imsp_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
// TODO
}
/* Helper functions. */
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/KolabImap.php 0000664 0001750 0001750 00000022470 12642740277 020713 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_KolabImap extends Horde_Prefs_Storage_Base
{
/**
* Handle for the current Kolab connection.
*
* @var Horde_Kolab_Storage
*/
protected $_kolab;
/**
* Name of the preferences default folder
*
* @var string
*/
protected $_folder;
/**
* Log handler.
*
* @var Horde_Log_Logger
*/
protected $_logger;
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters.
*
* 'kolab' - (Horde_Kolab_Storage) [REQUIRED] The storage backend.
* 'folder' - (string) The default name of the preferences folder.
* DEFAULT: _('Preferences')
*
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
if (!isset($params['kolab'])) {
throw new InvalidArgumentException('Missing "kolab" parameter.');
}
$this->_kolab = $params['kolab'];
unset($params['kolab']);
if (isset($params['logger'])) {
$this->_logger = $params['logger'];
}
if (isset($params['folder'])) {
$this->_folder = $params['folder'];
} else {
$this->_folder = Horde_Prefs_Translation::t("Preferences");
}
parent::__construct($user, $params);
}
/**
* Retrieves the requested preferences scope from the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @return Horde_Prefs_Scope The modified scope object.
* @throws Horde_Prefs_Exception
*/
public function get($scope_ob)
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return $scope_ob;
}
/** This may not fail (or if it does it is okay to pass the error up */
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope_ob->scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$this->_logMissingScope($e, $scope_ob->scope);
return $scope_ob;
}
foreach ($this->_prefToArray($pref['pref']) as $key => $value) {
$scope_ob->set($key, $value);
}
return $scope_ob;
}
/**
* Stores changed preferences in the storage backend.
*
* @param Horde_Prefs_Scope $scope_ob The scope object.
*
* @throws Horde_Prefs_Exception
*/
public function store($scope_ob)
{
/** This *must* succeed */
$data = $this->_getStorage(true);
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope_ob->scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$pref = array('application' => $scope_ob->scope);
}
if (isset($pref['pref'])) {
$new = $this->_prefToArray($pref['pref']);
} else {
$new = array();
}
foreach ($scope_ob->getDirty() as $name) {
$new[$name] = $scope_ob->get($name);
}
$pref['pref'] = $this->_arrayToPref($new);
try {
if (!isset($pref['uid'])) {
$data->create($pref);
} else {
$data->modify($pref);
}
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Removes preferences from the backend.
*
* @param string $scope The scope of the prefs to clear. If null, clears
* all scopes.
* @param string $pref The pref to clear. If null, clears the entire
* scope.
*
* @throws Horde_Prefs_Exception
*/
public function remove($scope = null, $pref = null)
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return;
}
if ($scope === null) {
$data->deleteAll();
return;
}
$query = $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS);
try {
$pref = $query->getApplicationPreferences($scope);
} catch (Horde_Kolab_Storage_Exception $e) {
$this->_logMissingScope($e, $scope);
return;
}
if ($pref === null) {
$data->delete($pref['uid']);
return;
}
$new = $this->_prefToArray($pref);
unset($new[$pref]);
$pref['pref'] = $this->_arrayToPref($new);
try {
$data->modify($pref);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
try {
$data = $this->_getStorage();
} catch (Horde_Prefs_Exception $e) {
$this->_logMissingStorage($e);
return;
}
return $data->getQuery(Horde_Kolab_Storage_Data::QUERY_PREFS)
->getApplications();
}
/* Helper functions. */
/**
* Opens a connection to the Kolab server.
*
* @param boolean $create_missing Create a preferences folder if it is
* missing.
*
* @return Horde_Kolab_Storage_Data The storage backend.
*
* @throws Horde_Prefs_Exception
*/
protected function _getStorage($create_missing = false)
{
$query = $this->_kolab->getList()->getQuery();
if ($folder = $query->getDefault('h-prefs')) {
return $this->_kolab->getData($folder);
}
$folders = $query->listByType('h-prefs');
if (!empty($folders)) {
return $this->_kolab->getData($folders[0]);
}
if (!$create_missing) {
throw new Horde_Prefs_Exception(
'No Kolab storage backend available.'
);
}
$params = $this->getParams();
$folder = $this->_kolab->getList()
->getNamespace()
->constructFolderName($params['user'], $this->_folder);
$this->_kolab->getList()->getListManipulation()->createFolder($folder, 'h-prefs.default');
if ($this->_logger !== null) {
$this->_logger->info(
sprintf(
__CLASS__ . ': Created default Kolab preferences folder "%s".',
$this->_folder
)
);
}
return $this->_kolab->getData($folder);
}
/**
* Convert Kolab preferences data to an array.
*
* @param array $pref The preferences list.
*
* @return array The preferences data as array.
*/
private function _prefToArray($pref)
{
$result = array();
foreach ($pref as $prefstr) {
/** If the string doesn't contain a colon delimiter, skip it. */
if (strpos($prefstr, ':') !== false) {
/** Split the string into its name:value components. */
list($name, $val) = explode(':', $prefstr, 2);
$result[$name] = base64_decode($val);
}
}
return $result;
}
/**
* Convert a key => value list of preferences to the Kolab preferences.
*
* @param array $pref The preferences.
*
* @return array The preferences data as list.
*/
private function _arrayToPref($pref)
{
$result = array();
foreach ($pref as $name => $value) {
if ($value !== null) {
$result[] = $name . ':' . base64_encode($value);
}
}
return $result;
}
/**
* Log the missing backend.
*
* @param Exception $e The exception that occurred.
*
* @return NULL
*/
private function _logMissingStorage(Exception $e)
{
if ($this->_logger !== null) {
$this->_logger->debug(
sprintf(
__CLASS__ . ': Failed retrieving Kolab preferences data storage (%s)',
$e->getMessage()
)
);
}
}
/**
* Log the missing scope.
*
* @param Exception $e The exception that occurred.
* @param string $scope The scope that was attempted to get.
*
* @return NULL
*/
private function _logMissingScope(Exception $e, $scope)
{
if ($this->_logger !== null) {
$this->_logger->debug(
sprintf(
__CLASS__ . ': No preference information available for scope %s (%s).',
$scope,
$e->getMessage()
)
);
}
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Ldap.php 0000664 0001750 0001750 00000017600 12642740277 017733 0 ustar jan jan
* @author Ben Klang
* @author Michael Slusarz
* @author Heinz Schweiger
* @category Horde
* @package Prefs
*/
class Horde_Prefs_Storage_Ldap extends Horde_Prefs_Storage_Base
{
/**
* Handle for the current LDAP connection.
*
* @var Horde_Ldap
*/
protected $_ldap;
/**
* Current DN holding the preferences.
*
* @var string
*/
protected $_prefsDN;
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters.
* - 'ldap': (Horde_Ldap) [REQUIRED] The DB instance.
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
if (!isset($params['ldap'])) {
throw new InvalidArgumentException('Missing ldap parameter.');
}
$this->_ldap = $params['ldap'];
unset($params['ldap']);
try {
$this->_prefsDN = $this->_ldap->findUserDN($user);
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
try {
// Try do find an existing preference object in an organizational
// unit under the userDN
$search = $this->_ldap->search(
$this->_prefsDN,
Horde_Ldap_Filter::create('objectclass', 'equals', 'hordePerson'),
array('attributes' => array('dn'), 'scope' => 'sub')
);
if ($search->count() == 1) {
$this->_prefsDN = $search->shiftEntry()->currentDN();
}
} catch (Horde_Ldap_Exception $e) {
}
parent::__construct($user, $params);
}
/**
*/
public function get($scope_ob)
{
// Preferences are stored as colon-separated name:value pairs.
// Each pair is stored as its own attribute off of the multi-
// value attribute named in: $scope_ob->scope . 'Prefs'
// getEntry() converts attribute indexes to lowercase.
$field = Horde_String::lower($scope_ob->scope . 'Prefs');
try {
$prefs = $this->_ldap->getEntry($this->_prefsDN, array($field));
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
if ($prefs->exists($field)) {
foreach ($prefs->getValue($field, 'all') as $prefstr) {
// If the string doesn't contain a colon delimiter, skip it.
if (strpos($prefstr, ':') !== false) {
// Split the string into its name:value components.
list($name, $value) = explode(':', $prefstr, 2);
$scope_ob->set($name, base64_decode($value));
}
}
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
// Preferences are stored as colon-separated name:value pairs.
// Each pair is stored as its own attribute off of the multi-
// value attribute named in: $scope_ob->scope . 'Prefs'
// getEntry() converts attribute indexes to lowercase.
$field = Horde_String::lower($scope_ob->scope . 'Prefs');
try {
$prefs = $this->_ldap->getEntry($this->_prefsDN, array($field, 'objectclass'));
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
// Add any missing objectclasses.
// Entries must have the objectclasses 'top' and 'hordePerson'
// to successfully store LDAP prefs. Check for both of them,
// and add them if necessary.
$objectclasses = $prefs->getValue('objectclass', 'all');
foreach (array('top', 'hordePerson') as $oc) {
if (!in_array($oc, $objectclasses)) {
$prefs->add(array('objectClass' => $oc));
}
}
// Delete dirty preferences if they exists in the current LDAP entry.
if ($prefs->exists($field)) {
foreach ($prefs->getValue($field, 'all') as $prefstr) {
// Split the string into its name:value components.
list($name, $val) = explode(':', $prefstr, 2);
// Delete values of dirty preference names
if ($scope_ob->isDirty($name)) {
$prefs->delete(array($field => $prefstr));
}
}
try {
$prefs->update();
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
// Add any dirty values.
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
// Null values were deleted above.
if (!is_null($value)) {
$prefs->add(array($field => $name . ':' . base64_encode($value)));
}
}
try {
$prefs->update();
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
if (is_null($scope)) {
// Clear all scopes.
$scopes = $this->listScopes();
} else {
$scopes = array($scope);
}
foreach ($scopes as $s) {
// getEntry() converts attribute indexes to lowercase.
$field = Horde_String::lower($s . 'Prefs');
try {
$prefs = $this->_ldap->getEntry($this->_prefsDN, array($field));
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
if (is_null($pref)) {
// Clear entire scope.
$prefs->delete(array($field));
} elseif ($prefs->exists($field)) {
// Find preference to clear.
foreach ($prefs->getValue($field, 'all') as $prefstr) {
// Split the string into its name:value components.
list($name, $val) = explode(':', $prefstr, 2);
if ($name == $pref) {
$prefs->delete(array($field => $prefstr));
}
}
}
try {
$prefs->update();
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
$scopes = array();
try {
$prefs = $this->_ldap->search(
$this->_prefsDN,
Horde_Ldap_Filter::create('objectclass', 'equals', 'hordePerson'),
// Attributes associated to objectclass hordePerson.
array('attributes' => array('@hordePerson'),
'scope' => 'base',
'attrsonly' => true)
);
} catch (Horde_Ldap_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
if (!$prefs) {
return $scopes;
}
foreach ($prefs->shiftEntry()->attributes() as $attr) {
// Trim off prefs from attribute name to get scope (e.g. hordePrefs
// -> horde).
$scope = str_ireplace("prefs","",$attr);
// Skip non-prefs attributes like objectclass (no replacement
// occurred above).
if ($attr != $scope) {
$scopes[] = $scope;
}
}
return $scopes;
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Mongo.php 0000664 0001750 0001750 00000010776 12642740277 020141 0 ustar jan jan
* @category Horde
* @copyright 2013-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_Mongo extends Horde_Prefs_Storage_Base implements Horde_Mongo_Collection_Index
{
/* Field names. */
const UID = 'uid';
const SCOPE = 'scope';
const NAME = 'name';
const VALUE = 'value';
/**
* The MongoDB Collection object for the cache data.
*
* @var MongoCollection
*/
protected $_db;
/**
* Indices list.
*
* @var array
*/
protected $_indices = array(
'index_scope' => array(
self::SCOPE => 1
),
'index_uid' => array(
self::UID => 1
)
);
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters.
*
* - collection: (string) The collection name.
* - mongo_db: (Horde_Mongo_Client) [REQUIRED] A MongoDB client object.
*
*/
public function __construct($user, array $params = array())
{
if (!isset($params['mongo_db'])) {
throw new InvalidArgumentException('Missing mongo_db parameter.');
}
parent::__construct($user, array_merge(array(
'collection' => 'horde_prefs'
), $params));
$this->_db = $this->_params['mongo_db']->selectCollection(null, $this->_params['collection']);
}
/**
*/
public function get($scope_ob)
{
try {
$res = $this->_db->find(array(
self::SCOPE => $scope_ob->scope,
self::UID => $this->_params['user']
), array(
self::NAME => 1,
self::VALUE => 1
));
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($res as $val) {
$scope_ob->set($val[self::NAME], $val[self::VALUE]->bin);
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
$this->remove($scope_ob->scope, $name);
} else {
$query = array(
self::NAME => $name,
self::SCOPE => $scope_ob->scope,
self::UID => $this->_params['user']
);
try {
$this->_db->update(
$query,
array_merge($query, array(
self::VALUE => new MongoBinData($value, MongoBinData::BYTE_ARRAY)
)),
array(
'upsert' => true
)
);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
$query = array(
self::UID => $this->_params['user']
);
if (!is_null($scope)) {
$query[self::SCOPE] = $scope;
if (!is_null($pref)) {
$query[self::NAME] = $pref;
}
}
try {
$this->_db->remove($query);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
*/
public function listScopes()
{
try {
return $this->_db->distinct(self::SCOPE);
} catch (MongoException $e) {
throw new Horde_Prefs_Exception($e);
}
}
/* Horde_Mongo_Collection_Index methods. */
/**
*/
public function checkMongoIndices()
{
return $this->_params['mongo_db']->checkIndices($this->_db, $this->_indices);
}
/**
*/
public function createMongoIndices()
{
$this->_params['mongo_db']->createIndices($this->_db, $this->_indices);
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Null.php 0000664 0001750 0001750 00000001332 12642740277 017760 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_Null extends Horde_Prefs_Storage_Base
{
/**
*/
public function get($scope_ob)
{
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
}
/**
*/
public function remove($scope = null, $pref = null)
{
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Storage/Sql.php 0000664 0001750 0001750 00000014225 12642740277 017612 0 ustar jan jan
* @author Michael Slusarz
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Storage_Sql extends Horde_Prefs_Storage_Base
{
/**
* Handle for the current database connection.
*
* @var Horde_Db_Adapter
*/
protected $_db;
/**
* Constructor.
*
* @param string $user The username.
* @param array $params Configuration parameters:
* - db: (Horde_Db_Adapter) [REQUIRED] The DB
* instance.
* - table: (string) The name of the prefs table.
* DEFAULT: 'horde_prefs'
*
* @throws InvalidArgumentException
*/
public function __construct($user, array $params = array())
{
if (!isset($params['db'])) {
throw new InvalidArgumentException('Missing db parameter.');
}
$this->_db = $params['db'];
unset($params['db']);
$params = array_merge(array(
'table' => 'horde_prefs'
), $params);
parent::__construct($user, $params);
}
/**
* Returns the charset of the DB backend.
*
* @return string The connection's charset.
*/
public function getCharset()
{
return $this->_db->getOption('charset');
}
/**
*/
public function get($scope_ob)
{
$charset = $this->_db->getOption('charset');
$query = 'SELECT pref_name, pref_value FROM ' .
$this->_params['table'] . ' ' .
'WHERE pref_uid = ? AND pref_scope = ?';
$values = array($this->_params['user'], $scope_ob->scope);
try {
$result = $this->_db->selectAll($query, $values);
$columns = $this->_db->columns($this->_params['table']);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
foreach ($result as $row) {
$name = trim($row['pref_name']);
$value = $columns['pref_value']->binaryToString($row['pref_value']);
$scope_ob->set($name, Horde_String::convertCharset($value, $charset, 'UTF-8'));
}
return $scope_ob;
}
/**
*/
public function store($scope_ob)
{
if (!$this->_db->isActive()) {
$this->_db->reconnect();
}
$charset = $this->_db->getOption('charset');
// For each preference, check for an existing table row and
// update it if it's there, or create a new one if it's not.
foreach ($scope_ob->getDirty() as $name) {
$value = $scope_ob->get($name);
if (is_null($value)) {
$this->remove($scope_ob->scope, $name);
} else {
$values = array($this->_params['user'], $name, $scope_ob->scope);
// Does a row already exist for this preference?
$query = 'SELECT 1 FROM ' . $this->_params['table'] .
' WHERE pref_uid = ? AND pref_name = ?' .
' AND pref_scope = ?';
try {
$check = $this->_db->selectValue($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
/* Driver has no support for storing locked status. */
$value = Horde_String::convertCharset($value, 'UTF-8', $charset);
$value = new Horde_Db_Value_Binary($value);
if (empty($check)) {
// Insert a new row.
$values = array(
'pref_uid' => $this->_params['user'],
'pref_scope' => $scope_ob->scope,
'pref_name' => $name,
'pref_value' => $value
);
try {
$this->_db->insertBlob($this->_params['table'], $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
} else {
// Update the existing row.
try {
$this->_db->updateBlob(
$this->_params['table'],
array('pref_value' => $value),
array(
'pref_uid = ? AND pref_name = ? AND pref_scope = ?',
array($this->_params['user'], $name, $scope_ob->scope)
)
);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
}
}
/**
*/
public function remove($scope = null, $pref = null)
{
$query = 'DELETE FROM ' . $this->_params['table'] .
' WHERE pref_uid = ?';
$values = array($this->_params['user']);
if (!is_null($scope)) {
$query .= ' AND pref_scope = ?';
$values[] = $scope;
if (!is_null($pref)) {
$query .= ' AND pref_name = ?';
$values[] = $pref;
}
}
try {
$this->_db->delete($query, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
/**
* Lists all available scopes.
*
* @return array The list of scopes stored in the backend.
*/
public function listScopes()
{
$query = 'SELECT ' . $this->_db->distinct('pref_scope') . ' FROM '
. $this->_params['table'];
try {
return $this->_db->selectValues($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Prefs_Exception($e);
}
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/CategoryManager.php 0000664 0001750 0001750 00000015407 12642740277 020522 0 ustar jan jan
* @category Horde
* @package Prefs
*/
class Horde_Prefs_CategoryManager
{
/**
* Get all categories.
*/
public static function get()
{
$string = $GLOBALS['prefs']->getValue('categories');
if (empty($string)) {
return array();
}
$categories = explode('|', $string);
asort($categories);
return $categories;
}
/**
* TODO
*/
public static function getSelect($id, $current = null)
{
$categories = self::get();
$colors = self::colors();
$fgcolors = self::fgColors();
$id_html = htmlspecialchars($id);
$html = '';
}
/**
* TODO
*/
public static function getJavaScript($formname, $elementname)
{
$prompt = addslashes(Horde_Prefs_Translation::t("Please type the new category name:"));
$error = addslashes(Horde_Prefs_Translation::t("You must type a new category name."));
return <<
JAVASCRIPT;
}
/**
* Add a new category.
*
* @param string $category The name of the category to add.
*
* @return mixed False on failure, or the new category's name.
*/
public static function add($category)
{
if ($GLOBALS['prefs']->isLocked('categories') || empty($category)) {
return false;
}
$categories = self::get();
if (in_array($category, $categories)) {
return $category;
}
$categories[] = $category;
$GLOBALS['prefs']->setValue('categories', implode('|', $categories));
return $category;
}
/**
* Delete a category.
*
* @param string $category The category to remove.
*
* @return boolean True on success, false on failure.
*/
public static function remove($category)
{
if ($GLOBALS['prefs']->isLocked('categories')) {
return false;
}
$categories = self::get();
$key = array_search($category, $categories);
if ($key === false) {
return $key;
}
unset($categories[$key]);
$GLOBALS['prefs']->setValue('categories', implode('|', $categories));
// Remove any color preferences for $category.
$colors = self::colors();
unset($colors[$category]);
self::setColors($colors);
return true;
}
/**
* Returns the color for each of the user's categories.
*
* @return array A list of colors, key is the category name, value is the
* HTML color code.
*/
public static function colors()
{
/* Default values that can be overridden but must always be
* present. */
$colors['_default_'] = '#FFFFFF';
$colors['_unfiled_'] = '#DDDDDD';
$pairs = explode('|', $GLOBALS['prefs']->getValue('category_colors'));
foreach ($pairs as $pair) {
if (!empty($pair)) {
list($category, $color) = explode(':', $pair);
$colors[$category] = $color;
}
}
$colors[''] = $colors['_unfiled_'];
return $colors;
}
/**
* Returns the foreground color for each of the user's categories.
*
* @return array A list of colors, key is the category name, value is the
* HTML color code.
*/
public static function fgColors()
{
$colors = self::colors();
$fgcolors = array();
foreach ($colors as $name => $color) {
$fgcolors[$name] = Horde_Image::brightness($color) < 128 ? '#f6f6f6' : '#000';
}
return $fgcolors;
}
/**
* TODO
*/
public static function setColor($category, $color)
{
$colors = self::colors();
$colors[$category] = $color;
self::setColors($colors);
}
/**
* TODO
*/
public static function setColors($colors)
{
$pairs = array();
foreach ($colors as $category => $color) {
if ($color[0] != '#') {
$color = '#' . $color;
}
if (!empty($category)) {
$pairs[] = $category . ':' . $color;
}
}
$GLOBALS['prefs']->setValue('category_colors', implode('|', $pairs));
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Exception.php 0000664 0001750 0001750 00000000736 12642740277 017407 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Exception extends Horde_Exception_Wrapped
{
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Identity.php 0000664 0001750 0001750 00000031562 12642740277 017243 0 ustar jan jan
* @category Horde
* @copyright 2001-2016 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Identity
implements ArrayAccess, Countable, IteratorAggregate
{
/**
* Array containing all the user's identities.
*
* @var array
*/
protected $_identities = array();
/**
* A pointer to the user's standard identity.
* This one is used by the methods returning values if no other one is
* specified.
*
* @var integer
*/
protected $_default = 0;
/**
* The user whose identities these are.
*
* @var string
*/
protected $_user = null;
/**
* Preference names.
*
* @var array
*/
protected $_prefnames = array(
'default_identity' => 'default_identity',
'from_addr' => 'from_addr',
'fullname' => 'fullname',
'id' => 'id',
'identities' => 'identities',
'properties' => array('id', 'fullname', 'from_addr')
);
/**
* The prefs object that this Identity points to.
*
* @var Horde_Prefs
*/
protected $_prefs;
/**
* Constructor.
*
* @param array $params Parameters:
* - default_identity: (string) The preference name for the default
* identity.
* DEFAULT: 'default_identity'
* - from_addr: (string) The preference name for the user's from e-mail
* address.
* DEFAULT: 'from_addr'
* - fullname: (string) The preference name for the user's full name.
* DEFAULT: 'fullname'
* - id: (string) The preference name for the identity name.
* DEFAULT: 'id'
* - identities: (string) The preference name for the identity store.
* DEFAULT: 'identities'
* - prefs: (Horde_Prefs) [REQUIRED] The prefs object to use.
* - properties: (array) The list of properties for the identity.
* DEFAULT: array('from_addr', 'fullname', 'id')
* - user: (string) [REQUIRED] The user whose prefs we are handling.
*/
public function __construct($params = array())
{
foreach (array_keys($this->_prefnames) as $val) {
if (isset($params[$val])) {
$this->_prefnames[$val] = $params[$val];
}
}
$this->_prefs = $params['prefs'];
$this->_user = $params['user'];
if (!($this->_identities = @unserialize($this->_prefs->getValue($this->_prefnames['identities'])))) {
$this->_identities = $this->_prefs->getDefault($this->_prefnames['identities']);
}
$this->setDefault($this->_prefs->getValue($this->_prefnames['default_identity']));
}
/**
* Creates a default identity if none exists yet and sets the preferences
* up if the identities are locked.
*/
public function init()
{
if (!is_array($this->_identities) || (count($this->_identities) <= 0)) {
foreach (array_keys($this->_prefnames) as $key) {
$identity[$key] = $this->_prefs->getValue($key);
}
if (empty($identity['id'])) {
$identity['id'] = Horde_Prefs_Translation::t("Default Identity");
}
$this->_identities = array($identity);
$this->verify(0);
}
}
/**
* Saves all identities in the prefs backend.
*/
public function save()
{
$this->_prefs->setValue($this->_prefnames['identities'], serialize($this->_identities));
$this->_prefs->setValue($this->_prefnames['default_identity'], $this->_default);
}
/**
* Adds a new identity to the array of identities.
*
* @param array $identity An identity hash to add.
*
* @return integer The pointer to the created identity
*/
public function add($identity = array())
{
$this->_identities[] = $identity;
return count($this->_identities) - 1;
}
/**
* Returns a complete identity hash.
*
* @param integer $identity The identity to retrieve.
*
* @return array An identity hash. Returns null if the identity does not
* exist.
*/
public function get($identity = null)
{
if (is_null($identity)) {
$identity = $this->_default;
}
return isset($this->_identities[$identity])
? $this->_identities[$identity]
: null;
}
/**
* Removes an identity from the array of identities.
*
* @param integer $identity The pointer to the identity to be removed
*
* @return array The removed identity.
*/
public function delete($identity)
{
$deleted = array_splice($this->_identities, $identity, 1);
if (!empty($deleted)) {
foreach (array_keys($this->_identities) as $id) {
if ($this->setDefault($id)) {
break;
}
}
$this->save();
}
return reset($deleted);
}
/**
* Returns a pointer to the current default identity.
*
* @return integer The pointer to the current default identity.
*/
public function getDefault()
{
return $this->_default;
}
/**
* Sets the current default identity.
* If the identity doesn't exist, the old default identity stays the same.
*
* @param integer $identity The pointer to the new default identity.
*
* @return boolean True on success, false on failure.
*/
public function setDefault($identity)
{
if (isset($this->_identities[$identity])) {
$this->_default = $identity;
return true;
}
return false;
}
/**
* Returns a property from one of the identities. If this value doesn't
* exist or is locked, the property is retrieved from the prefs backend.
*
* @param string $key The property to retrieve.
* @param integer $identity The identity to retrieve the property from.
*
* @return mixed The value of the property.
*/
public function getValue($key, $identity = null)
{
if (is_null($identity) || !isset($this->_identities[$identity])) {
$identity = $this->_default;
}
return (!isset($this->_identities[$identity][$key]) || $this->_prefs->isLocked($key))
? $this->_prefs->getValue($key)
: $this->_identities[$identity][$key];
}
/**
* Returns an array with the specified property from all existing
* identities.
*
* @param string $key The property to retrieve.
*
* @return array The array with the values from all identities.
*/
public function getAll($key)
{
$list = array();
foreach (array_keys($this->_identities) as $identity) {
$list[$identity] = $this->getValue($key, $identity);
}
return $list;
}
/**
* Sets a property with a specified value.
*
* @param string $key The property to set.
* @param mixed $val The value to which the property should be
* set.
* @param integer $identity The identity to set the property in.
*
* @return boolean True on success, false on failure (property was
* locked).
*/
public function setValue($key, $val, $identity = null)
{
if (is_null($identity)) {
$identity = $this->_default;
}
if (!$this->_prefs->isLocked($key)) {
$this->_identities[$identity][$key] = $val;
return true;
}
return false;
}
/**
* Returns true if all properties are locked and therefore nothing in the
* identities can be changed.
*
* @return boolean True if all properties are locked, false otherwise.
*/
public function isLocked()
{
foreach ($this->_prefnames['properties'] as $key) {
if (!$this->_prefs->isLocked($key)) {
return false;
}
}
return true;
}
/**
* Returns true if the given address belongs to one of the identities.
*
* @param string $key The identity key to search.
* @param string $value The value to search for in $key.
*
* @return boolean True if the $value was found in $key.
*/
public function hasValue($key, $value)
{
$list = $this->getAll($key);
foreach ($list as $valueB) {
if (!empty($valueB) &&
strpos(Horde_String::lower($value), Horde_String::lower($valueB)) !== false) {
return true;
}
}
return false;
}
/**
* Verifies and sanitizes all identity properties.
*
* @param integer $identity The identity to verify.
*
* @throws Horde_Prefs_Exception
*/
public function verify($identity = null)
{
if (is_null($identity)) {
$identity = $this->_default;
}
if (!$this->getValue('id', $identity)) {
$this->setValue('id', Horde_Prefs_Translation::t("Unnamed"), $identity);
}
// To verify e-mail, first parse input, than re-parse in verify mode.
$ob = new Horde_Mail_Rfc822_Address($this->getValue($this->_prefnames['from_addr'], $identity));
try {
$rfc822 = new Horde_Mail_Rfc822();
$rfc822->parseAddressList($ob, array(
'validate' => true
));
} catch (Horde_Mail_Exception $e) {
throw new Horde_Prefs_Exception(sprintf(Horde_Prefs_Translation::t("\"%s\" is not a valid email address."), strval($ob)));
}
$this->setValue('from_addr', strval($ob), $identity);
}
/**
* Returns the user's full name.
*
* @param integer $ident The identity to retrieve the name from.
*
* @return string The user's full name, or the user name if it doesn't
* exist.
*/
public function getName($ident = null)
{
if (isset($this->_names[$ident])) {
return $this->_names[$ident];
}
$this->_names[$ident] = $this->getValue($this->_prefnames['fullname'], $ident);
if (!strlen($this->_names[$ident])) {
$this->_names[$ident] = $this->_user;
}
return $this->_names[$ident];
}
/**
* Returns the from address based on the chosen identity.
*
* If no address can be found it is built from the current user.
*
* @since Horde_Prefs 2.3.0
*
* @param integer $ident The identity to retrieve the address from.
*
* @return Horde_Mail_Rfc822_Address A valid from address.
*/
public function getFromAddress($ident = null)
{
$val = $this->getValue($this->_prefnames['from_addr'], $ident);
if (!strlen($val)) {
$val = $this->_user;
}
return new Horde_Mail_Rfc822_Address($val);
}
/**
* Generates the from address to use for the default identity.
*
* @param boolean $fullname Include the fullname information.
*
* @return Horde_Mail_Rfc822_Address The default from address (object
* returned since 2.2.0).
*/
public function getDefaultFromAddress($fullname = false)
{
$ob = new Horde_Mail_Rfc822_Address($this->getFromAddress());
$ob->personal = $fullname
? $this->getValue($this->_prefnames['fullname'])
: null;
return $ob;
}
/* ArrayAccess methods. */
/**
* @since 2.7.0
*/
public function offsetExists($offset)
{
return isset($this->_identities[$offset]);
}
/**
* @since 2.7.0
*/
public function offsetGet($offset)
{
return $this->get($offset);
}
/**
* @since 2.7.0
*/
public function offsetSet($offset, $value)
{
// $value is ignored.
$this->set($offset);
}
/**
* @since 2.7.0
*/
public function offsetUnset($offset)
{
$this->delete($offset);
}
/* Countable method. */
/**
* @since 2.7.0
*/
public function count()
{
return count($this->_identities);
}
/* IteratorAggregate method. */
/**
* @since 2.7.0
*/
public function getIterator()
{
return new ArrayIterator($this->_identities);
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Scope.php 0000664 0001750 0001750 00000016276 12642740277 016530 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs_Scope implements Iterator, Serializable
{
/**
* Is the object being initialized?
*
* @var boolean
*/
public $init = false;
/**
* The scope name.
*
* @var string
*/
public $scope;
/**
* List of dirty prefs.
*
* @var array
*/
protected $_dirty = array();
/**
* Preferences list. Each preference has the following format:
*
* [pref_name] => array(
* [d] => (string) Default value
* If not present, 'v' is the default value.
* [l] => (boolean) Locked
* If not present, pref is not locked.
* [v] => (string) Current pref value
* )
*
* For internal storage, if 'l' and 'v' are both not available:
* [pref_name] => (string) Current pref value
*
*
* @var array
*/
protected $_prefs = array();
/**
* Constructor.
*
* @param string $scope The scope for this set of preferences.
*/
public function __construct($scope)
{
$this->scope = $scope;
}
/**
* Removes a preference entry.
*
* @param string $pref The name of the preference to remove.
*
* @return boolean True if preference was removed.
*/
public function remove($pref)
{
if (!($p = $this->_fromInternal($pref))) {
return false;
}
if (isset($p['d'])) {
$p['v'] = $p['d'];
unset($p['d']);
$this->_toInternal($pref, $p);
$this->setDirty($pref, false);
}
return true;
}
/**
* Sets the value for a preference.
*
* @param string $pref The preference name.
* @param string $val The preference value.
*/
public function set($pref, $val)
{
if ($p = $this->_fromInternal($pref)) {
if ($val != $p['v']) {
if (isset($p['d']) && ($val == $p['d'])) {
unset($p['d']);
} else {
$p['d'] = $p['v'];
}
$p['v'] = $val;
$this->_toInternal($pref, $p);
}
} else {
$this->_toInternal($pref, array('v' => $val));
}
}
/**
* Does a preference exist in this scope?
*
* @return boolean True if the preference exists.
*/
public function exists($pref)
{
return isset($this->_prefs[$pref]);
}
/**
* Returns the value of a preference.
*
* @param string $pref The preference name to retrieve.
*
* @return string The value of the preference, null if it doesn't exist.
*/
public function get($pref)
{
return ($p = $this->_fromInternal($pref))
? $p['v']
: null;
}
/**
* Mark a preference as locked.
*
* @param string $pref The preference name.
* @param boolean $locked Is the preference locked?
*/
public function setLocked($pref, $locked)
{
if ($p = $this->_fromInternal($pref)) {
if ($locked) {
if (!isset($p['l'])) {
$p['l'] = true;
$this->_toInternal($pref, $p);
}
} elseif (isset($p['l'])) {
unset($p['l']);
$this->_toInternal($pref, $p);
}
}
}
/**
* Is a preference locked?
*
* @param string $pref The preference name.
*
* @return boolean Whether the preference is locked.
*/
public function isLocked($pref)
{
return ($p = $this->_fromInternal($pref))
? !empty($p['l'])
: false;
}
/**
* Is a preference's value the default?
*
* @param string $pref The preference name.
*
* @return boolean True if the preference contains the default value.
*/
public function isDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? !isset($p['d'])
: true;
}
/**
* Returns the default value of a preference.
*
* @param string $pref The preference name.
*
* @return string The preference's default value.
*/
public function getDefault($pref)
{
return ($p = $this->_fromInternal($pref))
? (isset($p['d']) ? $p['d'] : $p['v'])
: null;
}
/**
* Get the list of dirty preferences.
*
* @return array The list of dirty preferences.
*/
public function getDirty()
{
return array_keys($this->_dirty);
}
/**
* Is a preference marked dirty?
*
* @param mixed $pref The preference name. If null, will return true if
* scope contains at least one dirty pref.
*
* @return boolean True if the preference is marked dirty.
*/
public function isDirty($pref = null)
{
return is_null($pref)
? !empty($this->_dirty)
: isset($this->_dirty[$pref]);
}
/**
* Set the dirty flag for a preference
*
* @param string $pref The preference name.
* @param boolean $dirty True to mark the pref as dirty.
*/
public function setDirty($pref, $dirty)
{
if ($dirty) {
$this->_dirty[$pref] = true;
} else {
unset($this->_dirty[$pref]);
}
}
/**
*/
protected function _fromInternal($pref)
{
if (!isset($this->_prefs[$pref])) {
return false;
}
return is_array($this->_prefs[$pref])
? $this->_prefs[$pref]
: array('v' => $this->_prefs[$pref]);
}
/**
*/
protected function _toInternal($pref, array $value)
{
if (!isset($value['d']) && !isset($value['l'])) {
$value = $value['v'];
}
$this->_prefs[$pref] = $value;
if (!$this->init) {
$this->setDirty($pref, true);
}
}
/* Iterator methods. */
/**
*/
public function current()
{
return $this->_fromInternal($this->key());
}
/**
*/
public function key()
{
return key($this->_prefs);
}
/**
*/
public function next()
{
return next($this->_prefs);
}
/**
*/
public function rewind()
{
return reset($this->_prefs);
}
/**
*/
public function valid()
{
return !is_null(key($this->_prefs));
}
/* Serializable methods. */
/**
*/
public function serialize()
{
return json_encode(array(
$this->scope,
$this->_prefs
));
}
/**
*/
public function unserialize($data)
{
list($this->scope, $this->_prefs) = json_decode($data, true);
}
}
Horde_Prefs-2.7.5/lib/Horde/Prefs/Translation.php 0000664 0001750 0001750 00000001340 12642740277 017737 0 ustar jan jan
* @package Prefs
*/
class Horde_Prefs_Translation extends Horde_Translation_Autodetect
{
/**
* The translation domain
*
* @var string
*/
protected static $_domain = 'Horde_Prefs';
/**
* The absolute PEAR path to the translations for the default gettext handler.
*
* @var string
*/
protected static $_pearDirectory = '@data_dir@';
}
Horde_Prefs-2.7.5/lib/Horde/Prefs.php 0000664 0001750 0001750 00000032227 12642740277 015451 0 ustar jan jan
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Prefs
*/
class Horde_Prefs implements ArrayAccess
{
/* The default scope name. */
const DEFAULT_SCOPE = 'horde';
/**
* Caching object.
*
* @var Horde_Prefs_Cache
*/
protected $_cache;
/**
* General library options.
*
* @var array
*/
protected $_opts = array(
'cache' => null,
'logger' => null,
'sizecallback' => null,
'storage' => null,
'user' => ''
);
/**
* String containing the name of the current scope. This is used
* to differentiate between sets of preferences. By default, preferences
* belong to this scope.
*
* @var string
*/
protected $_scope = self::DEFAULT_SCOPE;
/**
* Scope list. Keys are scope names, values are Horde_Prefs_Scope
* objects.
*
* @var array
*/
protected $_scopes = array();
/**
* The storage driver(s).
*
* @var array
*/
protected $_storage;
/**
* Constructor.
*
* @param string $scope The scope for this set of preferences.
* @param mixed $storage The storage object(s) to use. Either a single
* Horde_Prefs_Storage object, or an array of
* objects.
* @param array $opts Additional confguration options:
*
* cache - (Horde_Prefs_Cache) The cache driver to use.
* DEFAULT: No caching.
* logger - (Horde_Log_Logger) Logging object.
* DEFAULT: NONE
* sizecallback - (callback) If set, called when setting a value in the
* backend.
* DEFAULT: NONE
* user - (string) The name of the user who owns this set of preferences.
* DEFAULT: NONE
*
*/
public function __construct($scope, $storage = null, array $opts = array())
{
$this->_opts = array_merge($this->_opts, $opts);
$this->_cache = isset($this->_opts['cache'])
? $this->_opts['cache']
: new Horde_Prefs_Cache_Null($this->getUser());
$this->_scope = $scope;
if (is_null($storage)) {
$storage = array(new Horde_Prefs_Storage_Null($this->getUser()));
} elseif (!is_array($storage)) {
$storage = array($storage);
}
$this->_storage = $storage;
register_shutdown_function(array($this, 'store'), false);
}
/**
* Return the cache object.
*
* @since 2.6.0
*
* @return Horde_Prefs_Cache_Base Cache object.
*/
public function getCache()
{
return $this->_cache;
}
/**
* Return the user who owns these preferences.
*
* @return string The user these preferences are for.
*/
public function getUser()
{
return $this->_opts['user'];
}
/**
* Get the current scope.
*
* @return string The current scope (application).
*/
public function getScope()
{
return $this->_scope;
}
/**
* Returns the storage drivers.
*
* @return array The storage drivers.
*/
public function getStorage()
{
return $this->_storage;
}
/**
* Removes a preference entry from the $prefs hash.
*
* @param string $pref The name of the preference to remove. If null,
* removes all prefs.
*/
public function remove($pref = null)
{
$to_remove = array();
if (is_null($pref)) {
foreach ($this->_scopes as $key => $val) {
$to_remove[$key] = array_keys(iterator_to_array($val));
}
} elseif ($scope = $this->_getScope($pref)) {
$to_remove[$scope] = array($pref);
}
foreach ($to_remove as $key => $val) {
$scope = $this->_scopes[$key];
foreach ($val as $prefname) {
$scope->remove($prefname);
foreach ($this->_storage as $storage) {
try {
$storage->remove($scope->scope, $prefname);
} catch (Exception $e) {}
}
}
}
}
/**
* Sets the given preference to the specified value if the preference is
* modifiable.
*
* @param string $pref The preference name to modify.
* @param string $val The preference value (UTF-8).
* @param array $opts Additional options:
*
* - force: (boolean) If true, will set the value disregarding the
* current locked status of the pref. (@since 2.5.0)
* DEFAULT: false
* - nosave: (boolean) If true, the preference will not be saved to the
* storage backend(s).
* DEFAULT: false
*
*
* @return boolean True if the value was successfully set, false on a
* failure.
* @throws Horde_Prefs_Exception
*/
public function setValue($pref, $val, array $opts = array())
{
/* Exit early if preference doesn't exist or is locked. */
if (!($scope = $this->_getScope($pref)) ||
(empty($opts['force']) &&
$this->_scopes[$scope]->isLocked($pref))) {
return false;
}
// Check to see if the value exceeds the allowable storage limit.
if ($this->_opts['sizecallback'] &&
call_user_func($this->_opts['sizecallback'], $pref, strlen($val))) {
return false;
}
$this->_scopes[$scope]->set($pref, $val);
if (!empty($opts['nosave'])) {
$this->_scopes[$scope]->setDirty($pref, false);
}
foreach ($this->_storage as $storage) {
$storage->onChange($scope, $pref);
}
if ($this->_opts['logger']) {
$this->_opts['logger']->log(__CLASS__ . ': Storing preference value (' . $pref . ')', 'DEBUG');
}
return true;
}
/**
* Shortcut to setValue().
*/
public function __set($name, $value)
{
return $this->setValue($name, $value);
}
/**
* Returns the value of the requested preference.
*
* @param string $pref The preference name.
*
* @return string The value of the preference (UTF-8), null if it doesn't
* exist.
*/
public function getValue($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->get($pref)
: null;
}
/**
* Shortcut to getValue().
*/
public function __get($name)
{
return $this->getValue($name);
}
/**
* Mark a preference as locked.
*
* @param string $pref The preference name.
* @param boolean $locked Is the preference locked?
*/
public function setLocked($pref, $bool)
{
if ($scope = $this->_getScope($pref)) {
$this->_scopes[$scope]->setLocked($pref, $bool);
}
}
/**
* Is a preference locked?
*
* @param string $pref The preference name.
*
* @return boolean Whether the preference is locked.
*/
public function isLocked($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isLocked($pref)
: false;
}
/**
* Is a preference marked dirty?
*
* @param string $pref The preference name.
*
* @return boolean True if the preference is marked dirty.
*/
public function isDirty($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isDirty($pref)
: false;
}
/**
* Returns the default value of the given preference.
*
* @param string $pref The name of the preference to get the default for.
*
* @return string The preference's default value.
*/
public function getDefault($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->getDefault($pref)
: null;
}
/**
* Determines if the current preference value is the default value.
*
* @param string $pref The name of the preference to check.
*
* @return boolean True if the preference is the application default
* value.
*/
public function isDefault($pref)
{
return ($scope = $this->_getScope($pref))
? $this->_scopes[$scope]->isDefault($pref)
: true;
}
/**
* Returns the scope of a preference.
*
* @param string $pref The preference name.
*
* @return mixed The scope of the preference, or null if it doesn't
* exist.
*/
protected function _getScope($pref)
{
$this->_loadScope($this->_scope);
if ($this->_scopes[$this->_scope]->exists($pref)) {
return $this->_scope;
} elseif ($this->_scope != self::DEFAULT_SCOPE) {
$this->_loadScope(self::DEFAULT_SCOPE);
if ($this->_scopes[self::DEFAULT_SCOPE]->exists($pref)) {
return self::DEFAULT_SCOPE;
}
}
return null;
}
/**
* Retrieves preferences for the current scope.
*
* @param string $scope Optional scope specifier - if not present the
* current scope will be used.
*/
public function retrieve($scope = null)
{
if (!is_null($scope)) {
$this->changeScope($scope);
}
$this->_loadScope(self::DEFAULT_SCOPE);
$this->_loadScope($this->getScope());
}
/**
* Changes the current preference scope.
*
* @since 2.6.0
*
* @param string $scope Scope specifier.
*/
public function changeScope($scope)
{
$this->_scope = $scope;
}
/**
* Load a specific preference scope.
*
* @param string $scope The scope to load.
*/
protected function _loadScope($scope)
{
// Return if we've already loaded these prefs.
if (!empty($this->_scopes[$scope])) {
return;
}
// Now check the prefs cache for existing values.
try {
if ((($cached = $this->_cache->get($scope)) !== false) &&
($cached instanceof Horde_Prefs_Scope)) {
$this->_scopes[$scope] = $cached;
return;
}
} catch (Horde_Prefs_Exception $e) {}
$scope_ob = new Horde_Prefs_Scope($scope);
$scope_ob->init = true;
// Need to set object in scopes array now, since the storage object
// might recursively call the prefs object.
$this->_scopes[$scope] = $scope_ob;
foreach ($this->_storage as $storage) {
$scope_ob = $storage->get($scope_ob);
}
$scope_ob->init = false;
$this->_cache->store($scope_ob);
}
/**
* Save all dirty prefs to the storage backend.
*
* @param boolean $throw Throw exception on error? If false, ignores
* errors. (Since 2.1.0)
*/
public function store($throw = true)
{
foreach ($this->_scopes as $scope) {
if ($scope->isDirty()) {
foreach ($this->_storage as $storage) {
try {
$storage->store($scope);
} catch (Exception $e) {
if ($throw) {
throw $e;
}
}
}
try {
$this->_cache->store($scope);
} catch (Exception $e) {
if ($throw) {
throw $e;
}
}
}
}
}
/**
* Cleanup (e.g. remove) scope(s).
*
* @param boolean $all Cleanup all scopes. If false, clean present scope
* only.
*/
public function cleanup($all = false)
{
if ($all) {
/* Destroy all scopes. */
$this->_scopes = array();
$scope = null;
} else {
unset($this->_scopes[$this->_scope]);
$scope = $this->_scope;
}
try {
$this->_cache->remove($scope);
} catch (Horde_Prefs_Exception $e) {}
}
/* ArrayAccess methods. */
public function offsetExists($offset)
{
return !is_null($this->getValue($offset));
}
public function offsetGet($offset)
{
return $this->getValue($offset);
}
public function offsetSet($offset, $value)
{
$this->setValue($offset, $value);
}
public function offsetUnset($offset)
{
$this->remove($offset);
}
}
Horde_Prefs-2.7.5/locale/ar/LC_MESSAGES/Horde_Prefs.mo 0000664 0001750 0001750 00000000705 12642740277 020231 0 ustar jan jan , <