package.xml0000644000175000007640000004772412163054615013210 0ustar slusarzslusarz Horde_Util pear.horde.org Util Horde Utility Libraries These classes provide functionality useful for all kind of applications. Chuck Hagenbuch chuck chuck@horde.org yes Jan Schneider jan jan@horde.org yes Michael Slusarz slusarz slusarz@horde.org yes 2013-06-27 2.3.0 2.3.0 stable stable LGPL-2.1 * [mms] SECURITY: '_formvars' form input must now be JSON encoded, not PHP serialized. 5.3.0 1.7.0 dom Horde_Imap_Client pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 ctype filter iconv json mbstring xml 0.0.1 0.0.1 alpha alpha 2003-10-28 LGPL-2.1 Initial release as a PEAR package 0.0.2 0.0.2 alpha alpha 2006-05-08 LGPL-2.1 Converted to package.xml 2.0 for pear.horde.org 0.1.0 0.1.0 beta beta 2008-09-25 LGPL-2.1 * Added magic PHP5 methods to the Variables class. * Added array_merge_recursive_overwrite() to Horde_Array(). * Fixed a bug in Horde_Array::arraySort where auto-detecting the first key failed. * Added sorter functions for array keys. * Removed use of array_unique(). * Cleaned up addParameter() in the Util class. * Implemented a much more efficient, yet safer file wiping algorithm. * Fixed Util::addParameter when it is passed a base URL that contains an urlencoded ampersand. * Added a parameter to Util::nocacheUrl() to not encode url. * Added Util::getPathInfo(). * Signed parameters to go.php with an HMAC based on a new secret key configuration value, to prevent using go.php as an open referrer. * Made logout tokens only valid for a configurable length of time. * Made it possible to use String.php without having any other files available. * Use utf8_decode() in String::length() if possible. * Always use preg_match() in String::regexMatch(). * Workaround for korean messages in a non-standard charset. * Fixed String::substr() length calculations. * Added multibyte-safe String::wordwrap() method. * Added parameter to use wordwrap() for line folding. * Use C as the portable locale (Bug #6194). * Don't use utf8_encode/decode on very large strings if other options are available. (Bug #6660) * Fixed order of checks in String::convertCharset (Bug #6794). 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 LGPL-2.1 * First alpha release for Horde 4. * Added Horde_String::rpos(). * Renamed Horde_Array::array_merge_recursive_overwrite() to Horde_Array::replaceRecursive(). * Added Horde_String::common(). * Added Horde_Domhtml::. * Removed Horde_Util::assertDriverConfig(). * Removed Horde_Util::bufferOutput(). * Removed Horde_Util::uriB64Encode() and Horde_Util::uriB64Decode(). * Removed Horde_Util::strftime2date() and Horde_Util::date2strftime(). * Removed Horde_Util::closeWindowJs() and Horde_Util::nocacheUrl(). * Added Horde_String::convertToUtf8(). * Added Horde_Util::abbreviate(). * Removed Horde_Array::combine() and Horde_Util::hmac(). 1.0.0beta1 1.0.0 beta beta 2011-03-16 LGPL-2.1 * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 LGPL-2.1 * First release candidate for Horde 4. * [mms] Tweak loading HTML documents (encodings) in Horde_Domhtml. * [mms] Added Horde_Domhtml#returnBody(). * [mms] Added Domhtml unit tests. 1.0.0RC2 1.0.0 beta beta 2011-03-29 LGPL-2.1 * Second release candidate for Horde 4. * Fix parsing ISO-8859-15 data with Horde_Domhtml (Bug #9714). 1.0.0 1.0.0 stable stable 2011-04-06 LGPL-2.1 * First stable release for Horde 4. 1.0.1 1.0.0 stable stable 2011-04-20 LGPL-2.1 * [jan] Fix wrapping of several follow-up lines with existing line breaks. * [jan] Fix creating temporary files with open_basedir restrictions. 1.0.2 1.0.0 stable stable 2011-05-03 LGPL-2.1 * [mms] In Horde_Variables, operate on a copy of the $_REQUEST variable. 1.0.3 1.0.0 stable stable 2011-06-01 LGPL-2.1 * [mms] Don't try to use dl() in PHP 5.3+. 1.0.4 1.0.0 stable stable 2011-06-14 LGPL-2.1 * [jan] Unescape escaped quotes when importing CSV data. 1.0.5 1.0.0 stable stable 2011-07-27 LGPL-2.1 * [jan] Fix removing too many backslashes with magic quotes enabled (Bug #10149). * [jan] Fix reading CSV data with PHP < 5.3. 1.0.6 1.0.0 stable stable 2011-10-11 LGPL-2.1 * [jan] Speed up Horde_String::substr() (Evert Pot, Request #8627). 1.1.0 1.1.0 stable stable 2011-12-06 LGPL-2.1 * [mms] Add Horde_String::validUtf8(). 1.2.0 1.2.0 stable stable 2012-01-17 LGPL-2.1 * [mms] Add Horde_Variables#filter(). 1.3.0 1.3.0 stable stable 2012-03-20 LGPL-2.1 * [jan] Implement ArrayAccess in Horde_Variables. 1.3.1 1.3.0 stable stable 2012-05-29 LGPL-2.1 * [mms] Fix Horde_String::validUtf8() to workaround PHP/PCRE bug where segfault will occur on input strings > ~5000 characters 1.4.0 1.4.0 stable stable 2012-06-29 LGPL-2.1 * [mms] Add Horde_String::trimUtf8Bom(). 1.4.1 1.4.0 stable stable 2012-06-29 LGPL-2.1 * 2012-07-06 2.0.0alpha1 2.0.0alpha1 alpha alpha LGPL-2.1 * First alpha release for Horde 5. * [mms] Removed e-mail array manipulation methods (Horde_Mail package now provides this feature). * [mms] Removed Horde_Util::getCsv() (moved to Horde_Data package). * [mms] Add iteration to Horde_Domhtml object. * [jan] Remove Horde_Util::getTempDir(). * [jan] Remove Horde_Array::replaceRecursive(). 2.0.0beta1 2.0.0beta1 beta beta 2012-07-19 LGPL-2.1 * First beta release for Horde 5. 2.0.0beta2 2.0.0beta1 beta beta 2012-10-12 LGPL-2.1 * [mms] Remove Horde_Util::addParameter() and Horde_Util::removeParameter(). * [mms] Remove Horde_Util::cloneObject(). 2.0.0 2.0.0 stable stable 2012-10-30 LGPL-2.1 * First stable release for Horde 5. 2.0.1 2.0.0 stable stable 2012-11-19 LGPL-2.1 * [mms] Use new Horde_Test layout. 2.0.2 2.0.0 stable stable 2012-12-20 LGPL-2.1 * [mms] Convert Horde_String#validUtf8() from a preg-regex to a string iterator to eliminate PCRE issues relating to stack sizes (Bug #11899). 2.0.3 2.0.0 stable stable 2013-01-09 LGPL-2.1 * [mms] Fix validating certain strings of UTF-8 data (Bug #11930). 2.1.0 2.1.0 stable stable 2013-02-11 LGPL-2.1 * [mms] Added 'charset' and 'metacharset' parameters to returnHtml(). * [mms] Added Horde_Domhtml#getCharset() to get best-guess charset of current encoding within the DOM object. * [mms] Fix inserting HEAD into HTML document with Horde_Domhtml#getHead() if it doesn't already exist in the document. 2.2.0 2.2.0 stable stable 2013-02-17 LGPL-2.1 * [mms] Can't add charset directly to HTML document or else DOM will alter document when generating HTML. * [mms] Added Horde_Domhtml#getBody(). 2.2.1 2.2.0 stable stable 2013-03-05 LGPL-2.1 * [mms] Simplify Horde_Variables iterator. 2.2.2 2.2.0 stable stable 2013-05-06 LGPL-2.1 * [mms] Fix Horde_Domhtml#returnBody(). 2.3.0 2.3.0 stable stable 2013-06-27 LGPL-2.1 * [mms] SECURITY: '_formvars' form input must now be JSON encoded, not PHP serialized. Horde_Util-2.3.0/doc/Horde/Util/COPYING0000644000175000007640000005764612163054615017351 0ustar slusarzslusarz 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_Util-2.3.0/doc/Horde/Util/UPGRADING0000644000175000007640000000075412163054615017545 0ustar slusarzslusarz====================== Upgrading Horde_Util ====================== :Contact: dev@lists.horde.org .. contents:: Contents .. section-numbering:: This lists the API changes between releases of the package. Upgrading to 2.0.0 ================== Horde_Array::replaceRecursive() has been removed. Use array_replace_recursive() instead. Horde_Util::cloneObject() has been removed. Use the clone statement instead. Horde_Util::getTempDir() has been removed. Use sys_get_temp_dir() instead. Horde_Util-2.3.0/lib/Horde/Array/Sort/Helper.php0000644000175000007640000000400512163054615021314 0ustar slusarzslusarz * @author Jan Schneider * @author Michael Slusarz * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Util */ class Horde_Array_Sort_Helper { /** * The array key to sort by. * * @var string */ public $key; /** * Compare two associative arrays by the array key defined in self::$key. * * @param array $a * @param array $b */ public function compare($a, $b) { return strcoll(Horde_String::lower($a[$this->key], true, 'UTF-8'), Horde_String::lower($b[$this->key], true, 'UTF-8')); } /** * Compare, in reverse order, two associative arrays by the array key * defined in self::$key. * * @param scalar $a TODO * @param scalar $b TODO * * @return TODO */ public function reverseCompare($a, $b) { return strcoll(Horde_String::lower($b[$this->key], true, 'UTF-8'), Horde_String::lower($a[$this->key], true, 'UTF-8')); } /** * Compare array keys case insensitively for uksort. * * @param scalar $a TODO * @param scalar $b TODO * * @return TODO */ public function compareKeys($a, $b) { return strcoll(Horde_String::lower($a, true, 'UTF-8'), Horde_String::lower($b, true, 'UTF-8')); } /** * Compare, in reverse order, array keys case insensitively for uksort. * * @param scalar $a TODO * @param scalar $b TODO * * @return TODO */ public function reverseCompareKeys($a, $b) { return strcoll(Horde_String::lower($b, true, 'UTF-8'), Horde_String::lower($a, true, 'UTF-8')); } } Horde_Util-2.3.0/lib/Horde/Array.php0000644000175000007640000001147212163054615017154 0ustar slusarzslusarz * @author Marko Djukic * @author Jan Schneider * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Util */ class Horde_Array { /** * Sorts an array on a specified key. If the key does not exist, * defaults to the first key of the array. * * @param array &$array The array to be sorted, passed by reference. * @param string $key The key by which to sort. If not specified then * the first key is used. * @param integer $dir Sort direction: * 0 = ascending (default) * 1 = descending * @param boolean $assoc Keep key value association? */ static public function arraySort(array &$array, $key = null, $dir = 0, $assoc = true) { /* Return if the array is empty. */ if (empty($array)) { return; } /* If no key to sort by is specified, use the first key of the * first element. */ if (is_null($key)) { $keys = array_keys(reset($array)); $key = array_shift($keys); } /* Call the appropriate sort function. */ $helper = new Horde_Array_Sort_Helper(); $helper->key = $key; $function = $dir ? 'reverseCompare' : 'compare'; if ($assoc) { uasort($array, array($helper, $function)); } else { usort($array, array($helper, $function)); } } /** * Given an HTML type array field "example[key1][key2][key3]" breaks up * the keys so that they could be used to reference a regular PHP array. * * @param string $field The field name to be examined. * @param string &$base Will be set to the base element. * @param array &$keys Will be set to the list of keys. * * @return boolean True on sucess, false on error. */ static public function getArrayParts($field, &$base, &$keys) { if (!preg_match('|([^\[]*)((\[[^\[\]]*\])+)|', $field, $matches)) { return false; } $base = $matches[1]; $keys = explode('][', $matches[2]); $keys[0] = substr($keys[0], 1); $keys[count($keys) - 1] = substr($keys[count($keys) - 1], 0, strlen($keys[count($keys) - 1]) - 1); return true; } /** * Using an array of keys iterate through the array following the * keys to find the final key value. If a value is passed then set * that value. * * @param array &$array The array to be used. * @param array &$keys The key path to follow as an array. * @param array $value If set the target element will have this value set * to it. * * @return mixed The final value of the key path. */ static public function getElement(&$array, array &$keys, $value = null) { if (count($keys)) { $key = array_shift($keys); return isset($array[$key]) ? self::getElement($array[$key], $keys, $value) : false; } if (!is_null($value)) { $array = $value; } return $array; } /** * Returns a rectangle of a two-dimensional array. * * @param array $array The array to extract the rectangle from. * @param integer $row The start row of the rectangle. * @param integer $col The start column of the rectangle. * @param integer $height The height of the rectangle. * @param integer $width The width of the rectangle. * * @return array The extracted rectangle. */ static public function getRectangle(array $array, $row, $col, $height, $width) { $rec = array(); for ($y = $row; $y < $row + $height; $y++) { $rec[] = array_slice($array[$y], $col, $width); } return $rec; } /** * Given an array, returns an associative array with each element key * derived from its value. * For example: * array(0 => 'foo', 1 => 'bar') * would become: * array('foo' => 'foo', 'bar' => 'bar') * * @param array $array An array of values. * * @return array An array with keys the same as values. */ static public function valuesToKeys(array $array) { return $array ? array_combine($array, $array) : array(); } } Horde_Util-2.3.0/lib/Horde/Domhtml.php0000644000175000007640000002110412163054615017473 0ustar slusarzslusarz * @category Horde * @copyright 2010-2013 Horde LLC * @package Util * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 */ class Horde_Domhtml implements Iterator { /** * DOM object. * * @var DOMDocument */ public $dom; /** * Iterator status. * * @var array */ protected $_iterator = null; /** * Original charset of data. * * @var string */ protected $_origCharset; /** * Encoding tag added to beginning of output. * * @var string */ protected $_xmlencoding = ''; /** * Constructor. * * @param string $text The text of the HTML document. * @param string $charset The charset of the HTML document. * * @throws Exception */ public function __construct($text, $charset = null) { if (!extension_loaded('dom')) { throw new Exception('DOM extension is not available.'); } // Bug #9616: Make sure we have valid HTML input. if (!strlen($text)) { $text = ''; } $old_error = libxml_use_internal_errors(true); $doc = new DOMDocument(); if (is_null($charset)) { /* If no charset given, charset is whatever libxml tells us the * encoding should be defaulting to 'iso-8859-1'. */ $doc->loadHTML($text); $this->_origCharset = $doc->encoding ? $doc->encoding : 'iso-8859-1'; } else { /* Convert/try with UTF-8 first. */ $this->_origCharset = Horde_String::lower($charset); $this->_xmlencoding = ''; $doc->loadHTML($this->_xmlencoding . Horde_String::convertCharset($text, $charset, 'UTF-8')); if ($doc->encoding && (Horde_String::lower($doc->encoding) != 'utf-8')) { /* Convert charset to what the HTML document says it SHOULD * be. */ $doc->loadHTML(Horde_String::convertCharset($text, $charset, $doc->encoding)); $this->_xmlencoding = ''; } } if ($old_error) { libxml_use_internal_errors(false); } $this->dom = $doc; /* Sanity checking: make sure we have the documentElement object. */ if (!$this->dom->documentElement) { $this->dom->appendChild($this->dom->createElement('html')); } /* Remove old charset information. */ $xpath = new DOMXPath($this->dom); $domlist = $xpath->query('/html/head/meta[@http-equiv="content-type"]'); for ($i = $domlist->length; $i > 0; --$i) { $meta = $domlist->item($i - 1); $meta->parentNode->removeChild($meta); } } /** * Returns the HEAD element, or creates one if it doesn't exist. * * @return DOMElement HEAD element. */ public function getHead() { $head = $this->dom->getElementsByTagName('head'); if ($head->length) { return $head->item(0); } $headelt = $this->dom->createElement('head'); $this->dom->documentElement->insertBefore($headelt, $this->dom->documentElement->firstChild); return $headelt; } /** * Returns the BODY element, or creates one if it doesn't exist. * * @since 2.2.0 * * @return DOMElement BODY element. */ public function getBody() { $body = $this->dom->getElementsByTagName('body'); if ($body->length) { return $body->item(0); } $bodyelt = $this->dom->createElement('body'); $this->dom->documentElement->appendChild($bodyelt); return $bodyelt; } /** * Returns the full HTML text in the original charset. * * @param array $opts Additional options: (since 2.1.0) * - charset: (string) Return using this charset. If set but empty, will * return as currently stored in the DOM object. * - metacharset: (boolean) If true, will add a META tag containing the * charset information. * * @return string HTML text. */ public function returnHtml(array $opts = array()) { $curr_charset = $this->getCharset(); if (strcasecmp($curr_charset, 'US-ASCII') === 0) { $curr_charset = 'UTF-8'; } $charset = array_key_exists('charset', $opts) ? (empty($opts['charset']) ? $curr_charset : $opts['charset']) : $this->_origCharset; if (empty($opts['metacharset'])) { $text = $this->dom->saveHTML(); } else { /* Add placeholder for META tag. Can't add charset yet because DOM * extension will alter output if it exists. */ $meta = $this->dom->createElement('meta'); $meta->setAttribute('http-equiv', 'content-type'); $meta->setAttribute('horde_dom_html_charset', ''); $head = $this->getHead(); $head->insertBefore($meta, $head->firstChild); $text = str_replace( 'horde_dom_html_charset=""', 'content="text/html; charset=' . $charset . '"', $this->dom->saveHTML() ); $head->removeChild($meta); } if (strcasecmp($curr_charset, $charset) !== 0) { $text = Horde_String::convertCharset($text, $curr_charset, $charset); } if (!$this->_xmlencoding || (($pos = strpos($text, $this->_xmlencoding)) === false)) { return $text; } return substr_replace($text, '', $pos, strlen($this->_xmlencoding)); } /** * Returns the body text in the original charset. * * @return string HTML text. */ public function returnBody() { $body = $this->getBody(); $text = ''; if ($body->hasChildNodes()) { foreach ($body->childNodes as $child) { $text .= $this->dom->saveXML($child); } } return Horde_String::convertCharset($text, 'UTF-8', $this->_origCharset); } /** * Get the charset of the DOM data. * * @since 2.1.0 * * @return string Charset of DOM data. */ public function getCharset() { return $this->dom->encoding ? $this->dom->encoding : ($this->_xmlencoding ? 'UTF-8' : $this->_origCharset); } /* Iterator methods. */ /** */ public function current() { if ($this->_iterator instanceof DOMDocument) { return $this->_iterator; } $curr = end($this->_iterator); return $curr['list']->item($curr['i']); } /** */ public function key() { return 0; } /** */ public function next() { /* Iterate in the reverse direction through the node list. This allows * alteration of the original list without breaking things (foreach() * w/removeChild() may exit iteration after removal is complete. */ if ($this->_iterator instanceof DOMDocument) { $this->_iterator = array(); $curr = array(); $node = $this->dom; } elseif (empty($this->_iterator)) { $this->_iterator = null; return; } else { $curr = &$this->_iterator[count($this->_iterator) - 1]; $node = $curr['list']->item($curr['i']); } if (empty($curr['child']) && ($node instanceof DOMNode) && $node->hasChildNodes()) { $curr['child'] = true; $this->_iterator[] = array( 'child' => false, 'i' => $node->childNodes->length - 1, 'list' => $node->childNodes ); } elseif (--$curr['i'] < 0) { array_pop($this->_iterator); $this->next(); } else { $curr['child'] = false; } } /** */ public function rewind() { $this->_iterator = $this->dom; } /** */ public function valid() { return !is_null($this->_iterator); } } Horde_Util-2.3.0/lib/Horde/String.php0000644000175000007640000006575612163054615017362 0ustar slusarzslusarz * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Util */ class Horde_String { /** * lower() cache. * * @var array */ static protected $_lowers = array(); /** * upper() cache. * * @var array */ static protected $_uppers = array(); /** * Converts a string from one charset to another. * * Uses the iconv or the mbstring extensions. * The original string is returned if conversion failed or none * of the extensions were available. * * @param mixed $input The data to be converted. If $input is an an * array, the array's values get converted * recursively. * @param string $from The string's current charset. * @param string $to The charset to convert the string to. * @param boolean $force Force conversion? * * @return mixed The converted input data. */ static public function convertCharset($input, $from, $to, $force = false) { /* Don't bother converting numbers. */ if (is_numeric($input)) { return $input; } /* If the from and to character sets are identical, return now. */ if (!$force && $from == $to) { return $input; } $from = self::lower($from); $to = self::lower($to); if (!$force && $from == $to) { return $input; } if (is_array($input)) { $tmp = array(); reset($input); while (list($key, $val) = each($input)) { $tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force); } return $tmp; } if (is_object($input)) { // PEAR_Error/Exception objects are almost guaranteed to contain // recursion, which will cause a segfault in PHP. We should never // reach this line, but add a check. if (($input instanceof Exception) || ($input instanceof PEAR_Error)) { return ''; } $input = clone $input; $vars = get_object_vars($input); while (list($key, $val) = each($vars)) { $input->$key = self::convertCharset($val, $from, $to, $force); } return $input; } if (!is_string($input)) { return $input; } return self::_convertCharset($input, $from, $to); } /** * Internal function used to do charset conversion. * * @param string $input See self::convertCharset(). * @param string $from See self::convertCharset(). * @param string $to See self::convertCharset(). * * @return string The converted string. */ static protected function _convertCharset($input, $from, $to) { /* Use utf8_[en|de]code() if possible and if the string isn't too * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these * functions use more memory. */ if (Horde_Util::extensionExists('xml') && ((strlen($input) < 16777216) || !Horde_Util::extensionExists('iconv') || !Horde_Util::extensionExists('mbstring'))) { if (($to == 'utf-8') && in_array($from, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_encode($input); } if (($from == 'utf-8') && in_array($to, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_decode($input); } } /* Try UTF7-IMAP conversions. */ if (($from == 'utf7-imap') || ($to == 'utf7-imap')) { try { if ($from == 'utf7-imap') { return self::convertCharset(Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($input), 'UTF-8', $to); } else { if ($from == 'utf-8') { $conv = $input; } else { $conv = self::convertCharset($input, $from, 'UTF-8'); } return Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($conv); } } catch (Horde_Imap_Client_Exception $e) { return $input; } } /* Try iconv with transliteration. */ if (Horde_Util::extensionExists('iconv')) { unset($php_errormsg); ini_set('track_errors', 1); $out = @iconv($from, $to . '//TRANSLIT', $input); $errmsg = isset($php_errormsg); ini_restore('track_errors'); if (!$errmsg && $out !== false) { return $out; } } /* Try mbstring. */ if (Horde_Util::extensionExists('mbstring')) { $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from)); if (!empty($out)) { return $out; } } return $input; } /** * Makes a string lowercase. * * @param string $string The string to be converted. * @param boolean $locale If true the string will be converted based on * a given charset, locale independent else. * @param string $charset If $locale is true, the charset to use when * converting. * * @return string The string with lowercase characters. */ static public function lower($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtolower($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtolower($string); } if (!isset(self::$_lowers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_lowers[$string] = strtolower($string); setlocale(LC_CTYPE, $language); } return self::$_lowers[$string]; } /** * Makes a string uppercase. * * @param string $string The string to be converted. * @param boolean $locale If true the string will be converted based on a * given charset, locale independent else. * @param string $charset If $locale is true, the charset to use when * converting. If not provided the current charset. * * @return string The string with uppercase characters. */ static public function upper($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtoupper($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtoupper($string); } if (!isset(self::$_uppers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_uppers[$string] = strtoupper($string); setlocale(LC_CTYPE, $language); } return self::$_uppers[$string]; } /** * Returns a string with the first letter capitalized if it is * alphabetic. * * @param string $string The string to be capitalized. * @param boolean $locale If true the string will be converted based on a * given charset, locale independent else. * @param string $charset The charset to use, defaults to current charset. * * @return string The capitalized string. */ static public function ucfirst($string, $locale = false, $charset = null) { if ($locale) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $first = self::substr($string, 0, 1, $charset); if (self::isAlpha($first, $charset)) { $string = self::upper($first, true, $charset) . self::substr($string, 1, null, $charset); } } else { $string = self::upper(substr($string, 0, 1), false) . substr($string, 1); } return $string; } /** * Returns a string with the first letter of each word capitalized if it is * alphabetic. * * Sentences are splitted into words at whitestrings. * * @param string $string The string to be capitalized. * @param boolean $locale If true the string will be converted based on a * given charset, locale independent else. * @param string $charset The charset to use, defaults to current charset. * * @return string The capitalized string. */ static public function ucwords($string, $locale = false, $charset = null) { $words = preg_split('/(\s+)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $c = count($words); $i < $c; $i += 2) { $words[$i] = self::ucfirst($words[$i], $locale, $charset); } return implode('', $words); } /** * Returns part of a string. * * @param string $string The string to be converted. * @param integer $start The part's start position, zero based. * @param integer $length The part's length. * @param string $charset The charset to use when calculating the part's * position and length, defaults to current * charset. * * @return string The string's part. */ static public function substr($string, $start, $length = null, $charset = 'UTF-8') { if (is_null($length)) { $length = self::length($string, $charset) - $start; } if ($length == 0) { return ''; } /* Try mbstring. */ if (Horde_Util::extensionExists('mbstring')) { $ret = @mb_substr($string, $start, $length, self::_mbstringCharset($charset)); /* mb_substr() returns empty string on failure. */ if (strlen($ret)) { return $ret; } } /* Try iconv. */ if (Horde_Util::extensionExists('iconv')) { $ret = @iconv_substr($string, $start, $length, $charset); /* iconv_substr() returns false on failure. */ if ($ret !== false) { return $ret; } } return substr($string, $start, $length); } /** * Returns the character (not byte) length of a string. * * @param string $string The string to return the length of. * @param string $charset The charset to use when calculating the string's * length. * * @return integer The string's length. */ static public function length($string, $charset = 'UTF-8') { $charset = self::lower($charset); if ($charset == 'utf-8' || $charset == 'utf8') { return strlen(utf8_decode($string)); } if (Horde_Util::extensionExists('mbstring')) { $ret = @mb_strlen($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strlen($string); } /** * Returns the numeric position of the first occurrence of $needle * in the $haystack string. * * @param string $haystack The string to search through. * @param string $needle The string to search for. * @param integer $offset Allows to specify which character in haystack * to start searching. * @param string $charset The charset to use when searching for the * $needle string. * * @return integer The position of first occurrence. */ static public function pos($haystack, $needle, $offset = 0, $charset = 'UTF-8') { if (Horde_Util::extensionExists('mbstring')) { $track_errors = ini_set('track_errors', 1); $ret = @mb_strpos($haystack, $needle, $offset, self::_mbstringCharset($charset)); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } return strpos($haystack, $needle, $offset); } /** * Returns the numeric position of the last occurrence of $needle * in the $haystack string. * * @param string $haystack The string to search through. * @param string $needle The string to search for. * @param integer $offset Allows to specify which character in haystack * to start searching. * @param string $charset The charset to use when searching for the * $needle string. * * @return integer The position of first occurrence. */ static public function rpos($haystack, $needle, $offset = 0, $charset = 'UTF-8') { if (Horde_Util::extensionExists('mbstring')) { $track_errors = ini_set('track_errors', 1); $ret = @mb_strrpos($haystack, $needle, $offset, self::_mbstringCharset($charset)); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } return strrpos($haystack, $needle, $offset); } /** * Returns a string padded to a certain length with another string. * This method behaves exactly like str_pad() but is multibyte safe. * * @param string $input The string to be padded. * @param integer $length The length of the resulting string. * @param string $pad The string to pad the input string with. Must * be in the same charset like the input string. * @param const $type The padding type. One of STR_PAD_LEFT, * STR_PAD_RIGHT, or STR_PAD_BOTH. * @param string $charset The charset of the input and the padding * strings. * * @return string The padded string. */ static public function pad($input, $length, $pad = ' ', $type = STR_PAD_RIGHT, $charset = 'UTF-8') { $mb_length = self::length($input, $charset); $sb_length = strlen($input); $pad_length = self::length($pad, $charset); /* Return if we already have the length. */ if ($mb_length >= $length) { return $input; } /* Shortcut for single byte strings. */ if ($mb_length == $sb_length && $pad_length == strlen($pad)) { return str_pad($input, $length, $pad, $type); } switch ($type) { case STR_PAD_LEFT: $left = $length - $mb_length; $output = self::substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input; break; case STR_PAD_BOTH: $left = floor(($length - $mb_length) / 2); $right = ceil(($length - $mb_length) / 2); $output = self::substr(str_repeat($pad, ceil($left / $pad_length)), 0, $left, $charset) . $input . self::substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset); break; case STR_PAD_RIGHT: $right = $length - $mb_length; $output = $input . self::substr(str_repeat($pad, ceil($right / $pad_length)), 0, $right, $charset); break; } return $output; } /** * Wraps the text of a message. * * @param string $string String containing the text to wrap. * @param integer $width Wrap the string at this number of * characters. * @param string $break Character(s) to use when breaking lines. * @param boolean $cut Whether to cut inside words if a line * can't be wrapped. * @param boolean $line_folding Whether to apply line folding rules per * RFC 822 or similar. The correct break * characters including leading whitespace * have to be specified too. * * @return string String containing the wrapped text. */ static public function wordwrap($string, $width = 75, $break = "\n", $cut = false, $line_folding = false) { $wrapped = ''; while (self::length($string, 'UTF-8') > $width) { $line = self::substr($string, 0, $width, 'UTF-8'); $string = self::substr($string, self::length($line, 'UTF-8'), null, 'UTF-8'); // Make sure we didn't cut a word, unless we want hard breaks // anyway. if (!$cut && preg_match('/^(.+?)((\s|\r?\n).*)/us', $string, $match)) { $line .= $match[1]; $string = $match[2]; } // Wrap at existing line breaks. if (preg_match('/^(.*?)(\r?\n)(.*)$/su', $line, $match)) { $wrapped .= $match[1] . $match[2]; $string = $match[3] . $string; continue; } // Wrap at the last colon or semicolon followed by a whitespace if // doing line folding. if ($line_folding && preg_match('/^(.*?)(;|:)(\s+.*)$/u', $line, $match)) { $wrapped .= $match[1] . $match[2] . $break; $string = $match[3] . $string; continue; } // Wrap at the last whitespace of $line. $sub = $line_folding ? '(.+[^\s])' : '(.*)'; if (preg_match('/^' . $sub . '(\s+)(.*)$/u', $line, $match)) { $wrapped .= $match[1] . $break; $string = ($line_folding ? $match[2] : '') . $match[3] . $string; continue; } // Hard wrap if necessary. if ($cut) { $wrapped .= $line . $break; continue; } $wrapped .= $line; } return $wrapped . $string; } /** * Wraps the text of a message. * * @param string $text String containing the text to wrap. * @param integer $length Wrap $text at this number of characters. * @param string $break_char Character(s) to use when breaking lines. * @param boolean $quote Ignore lines that are wrapped with the '>' * character (RFC 2646)? If true, we don't * remove any padding whitespace at the end of * the string. * * @return string String containing the wrapped text. */ static public function wrap($text, $length = 80, $break_char = "\n", $quote = false) { $paragraphs = array(); foreach (preg_split('/\r?\n/', $text) as $input) { if ($quote && (strpos($input, '>') === 0)) { $line = $input; } else { /* We need to handle the Usenet-style signature line * separately; since the space after the two dashes is * REQUIRED, we don't want to trim the line. */ if ($input != '-- ') { $input = rtrim($input); } $line = self::wordwrap($input, $length, $break_char); } $paragraphs[] = $line; } return implode($break_char, $paragraphs); } /** * Return a truncated string, suitable for notifications. * * @param string $text The original string. * @param integer $length The maximum length. * * @return string The truncated string, if longer than $length. */ static public function truncate($text, $length = 100) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, $length - 3)) . '...' : $text; } /** * Return an abbreviated string, with characters in the middle of the * excessively long string replaced by '...'. * * @param string $text The original string. * @param integer $length The length at which to abbreviate. * * @return string The abbreviated string, if longer than $length. */ static public function abbreviate($text, $length = 20) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, round(($length - 3) / 2))) . '...' . ltrim(self::substr($text, (($length - 3) / 2) * -1)) : $text; } /** * Returns the common leading part of two strings. * * @param string $str1 A string. * @param string $str2 Another string. * * @return string The start of $str1 and $str2 that is identical in both. */ static public function common($str1, $str2) { for ($result = '', $i = 0; isset($str1[$i]) && isset($str2[$i]) && $str1[$i] == $str2[$i]; $i++) { $result .= $str1[$i]; } return $result; } /** * Returns true if the every character in the parameter is an alphabetic * character. * * @param string $string The string to test. * @param string $charset The charset to use when testing the string. * * @return boolean True if the parameter was alphabetic only. */ static public function isAlpha($string, $charset) { if (!Horde_Util::extensionExists('mbstring')) { return ctype_alpha($string); } $charset = self::_mbstringCharset($charset); $old_charset = mb_regex_encoding(); if ($charset != $old_charset) { @mb_regex_encoding($charset); } $alpha = !@mb_ereg_match('[^[:alpha:]]', $string); if ($charset != $old_charset) { @mb_regex_encoding($old_charset); } return $alpha; } /** * Returns true if ever character in the parameter is a lowercase letter in * the current locale. * * @param string $string The string to test. * @param string $charset The charset to use when testing the string. * * @return boolean True if the parameter was lowercase. */ static public function isLower($string, $charset) { return ((self::lower($string, true, $charset) === $string) && self::isAlpha($string, $charset)); } /** * Returns true if every character in the parameter is an uppercase letter * in the current locale. * * @param string $string The string to test. * @param string $charset The charset to use when testing the string. * * @return boolean True if the parameter was uppercase. */ static public function isUpper($string, $charset) { return ((self::upper($string, true, $charset) === $string) && self::isAlpha($string, $charset)); } /** * Performs a multibyte safe regex match search on the text provided. * * @param string $text The text to search. * @param array $regex The regular expressions to use, without perl * regex delimiters (e.g. '/' or '|'). * @param string $charset The character set of the text. * * @return array The matches array from the first regex that matches. */ static public function regexMatch($text, $regex, $charset = null) { if (!empty($charset)) { $regex = self::convertCharset($regex, $charset, 'utf-8'); $text = self::convertCharset($text, $charset, 'utf-8'); } $matches = array(); foreach ($regex as $val) { if (preg_match('/' . $val . '/u', $text, $matches)) { break; } } if (!empty($charset)) { $matches = self::convertCharset($matches, 'utf-8', $charset); } return $matches; } /** * Check to see if a string is valid UTF-8. * * @param string $text The text to check. * * @return boolean True if valid UTF-8. */ static public function validUtf8($text) { $text = strval($text); for ($i = 0, $len = strlen($text); $i < $len; ++$i) { $c = ord($text[$i]); if ($c > 128) { if ($c > 247) { // STD 63 (RFC 3629) eliminates 5 & 6-byte characters. return false; } elseif ($c > 239) { $j = 3; } elseif ($c > 223) { $j = 2; } elseif ($c > 191) { $j = 1; } else { return false; } if (($i + $j) > $len) { return false; } do { $c = ord($text[++$i]); if (($c < 128) || ($c > 191)) { return false; } } while (--$j); } } return true; } /** * Workaround charsets that don't work with mbstring functions. * * @param string $charset The original charset. * * @return string The charset to use with mbstring functions. */ static protected function _mbstringCharset($charset) { /* mbstring functions do not handle the 'ks_c_5601-1987' & * 'ks_c_5601-1989' charsets. However, these charsets are used, for * example, by various versions of Outlook to send Korean characters. * Use UHC (CP949) encoding instead. See, e.g., * http://lists.w3.org/Archives/Public/ietf-charsets/2001AprJun/0030.html */ return in_array(self::lower($charset), array('ks_c_5601-1987', 'ks_c_5601-1989')) ? 'UHC' : $charset; } /** * Strip UTF-8 byte order mark (BOM) from string data. * * @param string $str Input string (UTF-8). * * @return string Stripped string (UTF-8). */ static public function trimUtf8Bom($str) { return (substr($str, 0, 3) == pack('CCC', 239, 187, 191)) ? substr($str, 3) : $str; } } Horde_Util-2.3.0/lib/Horde/Util.php0000644000175000007640000004476712163054615017030 0ustar slusarzslusarz * @author Jon Parise * @category Horde * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Util */ class Horde_Util { /** * A list of random patterns to use for overwriting purposes. * See http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html. * We save the random overwrites for efficiency reasons. * * @var array */ static public $patterns = array( "\x55", "\xaa", "\x92\x49\x24", "\x49\x24\x92", "\x24\x92\x49", "\x00", "\x11", "\x22", "\x33", "\x44", "\x55", "\x66", "\x77", "\x88", "\x99", "\xaa", "\xbb", "\xcc", "\xdd", "\xee", "\xff", "\x92\x49\x24", "\x49\x24\x92", "\x24\x92\x49", "\x6d\xb6\xdb", "\xb6\xdb\x6d", "\xdb\x6d\xb6" ); /** * Are magic quotes in use? * * @var boolean */ static protected $_magicquotes = null; /** * TODO * * @var array */ static protected $_shutdowndata = array( 'dirs' => array(), 'files' => array(), 'secure' => array() ); /** * Has the shutdown method been registered? * * @var boolean */ static protected $_shutdownreg = false; /** * Cache for extensionExists(). * * @var array */ static protected $_cache = array(); /** * Checks to see if a value has been set by the script and not by GET, * POST, or cookie input. The value being checked MUST be in the global * scope. * * @param string $varname The variable name to check. * @param mixed $default Default value if the variable isn't present * or was specified by the user. Defaults to null. * * @return mixed $default if the var is in user input or not present, * the variable value otherwise. */ static public function nonInputVar($varname, $default = null) { return (isset($_GET[$varname]) || isset($_POST[$varname]) || isset($_COOKIE[$varname])) ? $default : (isset($GLOBALS[$varname]) ? $GLOBALS[$varname] : $default); } /** * Returns a hidden form input containing the session name and id. * * @param boolean $append_session 0 = only if needed, 1 = always. * * @return string The hidden form input, if needed/requested. */ static public function formInput($append_session = 0) { return (($append_session == 1) || !isset($_COOKIE[session_name()])) ? '\n" : ''; } /** * Prints a hidden form input containing the session name and id. * * @param boolean $append_session 0 = only if needed, 1 = always. */ static public function pformInput($append_session = 0) { echo self::formInput($append_session); } /** * If magic_quotes_gpc is in use, run stripslashes() on $var. * * @param mixed $var The string, or an array of strings, to un-quote. * * @return mixed $var, minus any magic quotes. */ static public function dispelMagicQuotes($var) { if (is_null(self::$_magicquotes)) { self::$_magicquotes = get_magic_quotes_gpc(); } if (self::$_magicquotes) { $var = is_array($var) ? array_map(array(__CLASS__, 'dispelMagicQuotes'), $var) : stripslashes($var); } return $var; } /** * Gets a form variable from GET or POST data, stripped of magic quotes if * necessary. If the variable is somehow set in both the GET data and the * POST data, the value from the POST data will be returned and the GET * value will be ignored. * * @param string $var The name of the form variable to look for. * @param string $default The value to return if the variable is not * there. * * @return string The cleaned form variable, or $default. */ static public function getFormData($var, $default = null) { return (($val = self::getPost($var)) !== null) ? $val : self::getGet($var, $default); } /** * Gets a form variable from GET data, stripped of magic quotes if * necessary. This function will NOT return a POST variable. * * @param string $var The name of the form variable to look for. * @param string $default The value to return if the variable is not * there. * * @return string The cleaned form variable, or $default. */ static public function getGet($var, $default = null) { return (isset($_GET[$var])) ? self::dispelMagicQuotes($_GET[$var]) : $default; } /** * Gets a form variable from POST data, stripped of magic quotes if * necessary. This function will NOT return a GET variable. * * @param string $var The name of the form variable to look for. * @param string $default The value to return if the variable is not * there. * * @return string The cleaned form variable, or $default. */ static public function getPost($var, $default = null) { return (isset($_POST[$var])) ? self::dispelMagicQuotes($_POST[$var]) : $default; } /** * Creates a temporary filename for the lifetime of the script, and * (optionally) registers it to be deleted at request shutdown. * * @param string $prefix Prefix to make the temporary name more * recognizable. * @param boolean $delete Delete the file at the end of the request? * @param string $dir Directory to create the temporary file in. * @param boolean $secure If deleting the file, should we securely delete * the file by overwriting it with random data? * * @return string Returns the full path-name to the temporary file. * Returns false if a temp file could not be created. */ static public function getTempFile($prefix = '', $delete = true, $dir = '', $secure = false) { $tempDir = (empty($dir) || !is_dir($dir)) ? sys_get_temp_dir() : $dir; $tempFile = tempnam($tempDir, $prefix); // If the file was created, then register it for deletion and return. if (empty($tempFile)) { return false; } if ($delete) { self::deleteAtShutdown($tempFile, true, $secure); } return $tempFile; } /** * Creates a temporary filename with a specific extension for the lifetime * of the script, and (optionally) registers it to be deleted at request * shutdown. * * @param string $extension The file extension to use. * @param string $prefix Prefix to make the temporary name more * recognizable. * @param boolean $delete Delete the file at the end of the request? * @param string $dir Directory to create the temporary file in. * @param boolean $secure If deleting file, should we securely delete * the file by overwriting it with random data? * * @return string Returns the full path-name to the temporary file. * Returns false if a temporary file could not be created. */ static public function getTempFileWithExtension($extension = '.tmp', $prefix = '', $delete = true, $dir = '', $secure = false) { $tempDir = (empty($dir) || !is_dir($dir)) ? sys_get_temp_dir() : $dir; if (empty($tempDir)) { return false; } $windows = substr(PHP_OS, 0, 3) == 'WIN'; $tries = 1; do { // Get a known, unique temporary file name. $sysFileName = tempnam($tempDir, $prefix); if ($sysFileName === false) { return false; } // tack on the extension $tmpFileName = $sysFileName . $extension; if ($sysFileName == $tmpFileName) { return $sysFileName; } // Move or point the created temporary file to the full filename // with extension. These calls fail if the new name already // exists. $fileCreated = ($windows ? @rename($sysFileName, $tmpFileName) : @link($sysFileName, $tmpFileName)); if ($fileCreated) { if (!$windows) { unlink($sysFileName); } if ($delete) { self::deleteAtShutdown($tmpFileName, true, $secure); } return $tmpFileName; } unlink($sysFileName); } while (++$tries <= 5); return false; } /** * Creates a temporary directory in the system's temporary directory. * * @param boolean $delete Delete the temporary directory at the end of * the request? * @param string $temp_dir Use this temporary directory as the directory * where the temporary directory will be created. * * @return string The pathname to the new temporary directory. * Returns false if directory not created. */ static public function createTempDir($delete = true, $temp_dir = null) { if (is_null($temp_dir)) { $temp_dir = sys_get_temp_dir(); } if (empty($temp_dir)) { return false; } /* Get the first 8 characters of a random string to use as a temporary directory name. */ do { $new_dir = $temp_dir . '/' . substr(base_convert(uniqid(mt_rand()), 10, 36), 0, 8); } while (file_exists($new_dir)); $old_umask = umask(0000); if (!mkdir($new_dir, 0700)) { $new_dir = false; } elseif ($delete) { self::deleteAtShutdown($new_dir); } umask($old_umask); return $new_dir; } /** * Returns the canonical path of the string. Like PHP's built-in * realpath() except the directory need not exist on the local server. * * Algorithim loosely based on code from the Perl File::Spec::Unix module * (version 1.5). * * @param string $path A file path. * * @return string The canonicalized file path. */ static public function realPath($path) { /* Standardize on UNIX directory separators. */ if (!strncasecmp(PHP_OS, 'WIN', 3)) { $path = str_replace('\\', '/', $path); } /* xx////xx -> xx/xx * xx/././xx -> xx/xx */ $path = preg_replace(array("|/+|", "@(/\.)+(/|\Z(?!\n))@"), array('/', '/'), $path); /* ./xx -> xx */ if ($path != './') { $path = preg_replace("|^(\./)+|", '', $path); } /* /../../xx -> xx */ $path = preg_replace("|^/(\.\./?)+|", '/', $path); /* xx/ -> xx */ if ($path != '/') { $path = preg_replace("|/\Z(?!\n)|", '', $path); } /* /xx/.. -> / */ while (strpos($path, '/..') !== false) { $path = preg_replace("|/[^/]+/\.\.|", '', $path); } return empty($path) ? '/' : $path; } /** * Removes given elements at request shutdown. * * If called with a filename will delete that file at request shutdown; if * called with a directory will remove that directory and all files in that * directory at request shutdown. * * If called with no arguments, return all elements to be deleted (this * should only be done by Horde_Util::_deleteAtShutdown()). * * The first time it is called, it initializes the array and registers * Horde_Util::_deleteAtShutdown() as a shutdown function - no need to do * so manually. * * The second parameter allows the unregistering of previously registered * elements. * * @param string $filename The filename to be deleted at the end of the * request. * @param boolean $register If true, then register the element for * deletion, otherwise, unregister it. * @param boolean $secure If deleting file, should we securely delete * the file? */ static public function deleteAtShutdown($filename, $register = true, $secure = false) { /* Initialization of variables and shutdown functions. */ if (!self::$_shutdownreg) { register_shutdown_function(array(__CLASS__, 'shutdown')); self::$_shutdownreg = true; } $ptr = &self::$_shutdowndata; if ($register) { if (@is_dir($filename)) { $ptr['dirs'][$filename] = true; } else { $ptr['files'][$filename] = true; } if ($secure) { $ptr['secure'][$filename] = true; } } else { unset($ptr['dirs'][$filename], $ptr['files'][$filename], $ptr['secure'][$filename]); } } /** * Deletes registered files at request shutdown. * * This function should never be called manually; it is registered as a * shutdown function by Horde_Util::deleteAtShutdown() and called * automatically at the end of the request. * * Contains code from gpg_functions.php. * Copyright 2002-2003 Braverock Ventures */ static public function shutdown() { $ptr = &self::$_shutdowndata; foreach ($ptr['files'] as $file => $val) { /* Delete files */ if ($val && file_exists($file)) { /* Should we securely delete the file by overwriting the data with a random string? */ if (isset($ptr['secure'][$file])) { $filesize = filesize($file); $fp = fopen($file, 'r+'); foreach (self::$patterns as $pattern) { $pattern = substr(str_repeat($pattern, floor($filesize / strlen($pattern)) + 1), 0, $filesize); fwrite($fp, $pattern); fseek($fp, 0); } fclose($fp); } @unlink($file); } } foreach ($ptr['dirs'] as $dir => $val) { /* Delete directories */ if ($val && file_exists($dir)) { /* Make sure directory is empty. */ $dir_class = dir($dir); while (false !== ($entry = $dir_class->read())) { if ($entry != '.' && $entry != '..') { @unlink($dir . '/' . $entry); } } $dir_class->close(); @rmdir($dir); } } } /** * Caches the result of extension_loaded() calls. * * @param string $ext The extension name. * * @return boolean Is the extension loaded? */ static public function extensionExists($ext) { if (!isset(self::$_cache[$ext])) { self::$_cache[$ext] = extension_loaded($ext); } return self::$_cache[$ext]; } /** * Tries to load a PHP extension, behaving correctly for all operating * systems. * * @param string $ext The extension to load. * * @return boolean True if the extension is now loaded, false if not. * True can mean that the extension was already loaded, * OR was loaded dynamically. */ static public function loadExtension($ext) { /* If $ext is already loaded, our work is done. */ if (self::extensionExists($ext)) { return true; } /* See if we can call dl() at all, by the current ini settings. * dl() has been removed in some PHP 5.3 SAPIs. */ if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1) || !function_exists('dl')) { return false; } if (!strncasecmp(PHP_OS, 'WIN', 3)) { $suffix = 'dll'; } else { switch (PHP_OS) { case 'HP-UX': $suffix = 'sl'; break; case 'AIX': $suffix = 'a'; break; case 'OSX': $suffix = 'bundle'; break; default: $suffix = 'so'; } } return dl($ext . '.' . $suffix) || dl('php_' . $ext . '.' . $suffix); } /** * Utility function to obtain PATH_INFO information. * * @return string The PATH_INFO string. */ static public function getPathInfo() { if (isset($_SERVER['PATH_INFO']) && (strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false)) { return $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['REQUEST_URI']) && isset($_SERVER['SCRIPT_NAME'])) { $search = Horde_String::common($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']); if (substr($search, -1) == '/') { $search = substr($search, 0, -1); } $search = array($search); if (!empty($_SERVER['QUERY_STRING'])) { // We can't use QUERY_STRING directly because URL rewriting // might add more parameters to the query string than those // from the request URI. $url = parse_url($_SERVER['REQUEST_URI']); if (!empty($url['query'])) { $search[] = '?' . $url['query']; } } $path = str_replace($search, '', $_SERVER['REQUEST_URI']); if ($path == '/') { $path = ''; } return $path; } return ''; } } Horde_Util-2.3.0/lib/Horde/Variables.php0000644000175000007640000002357412163054615020014 0ustar slusarzslusarz * @author Chuck Hagenbuch * @author Michael Slusarz * @category Horde * @copyright 2009-2013 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Util */ class Horde_Variables implements ArrayAccess, Countable, IteratorAggregate { /** * The list of expected variables. * * @var array */ protected $_expected = array(); /** * Has the input been sanitized? * * @var boolean */ protected $_sanitized = false; /** * Array of form variables. * * @var array */ protected $_vars; /** * Returns a Horde_Variables object populated with the form input. * * @param string $sanitize Sanitize the input variables? * * @return Horde_Variables Variables object. */ static public function getDefaultVariables($sanitize = false) { return new self(null, $sanitize); } /** * Constructor. * * @param array $vars The list of form variables (if null, defaults * to PHP's $_REQUEST value). If '_formvars' * exists, it must be a JSON encoded array that * contains the list of allowed form variables. * @param string $sanitize Sanitize the input variables? */ public function __construct($vars = array(), $sanitize = false) { if (is_null($vars)) { $request_copy = $_REQUEST; $vars = Horde_Util::dispelMagicQuotes($request_copy); } if (isset($vars['_formvars'])) { $this->_expected = @json_decode($vars['_formvars'], true); unset($vars['_formvars']); } $this->_vars = $vars; if ($sanitize) { $this->sanitize(); } } /** * Sanitize the form input. */ public function sanitize() { if (!$this->_sanitized) { foreach (array_keys($this->_vars) as $key) { $this->$key = $this->filter($key); } $this->_sanitized = true; } } /** * Alias of isset(). * * @see __isset() */ public function exists($varname) { return isset($this->$varname); } /** * isset() implementation. * * @param string $varname The form variable name. * * @return boolean Does $varname form variable exist? */ public function __isset($varname) { return count($this->_expected) ? $this->_getExists($this->_expected, $varname, $value) : $this->_getExists($this->_vars, $varname, $value); } /** * Implements isset() for ArrayAccess interface. * * @see __isset() */ public function offsetExists($field) { return $this->__isset($field); } /** * Returns the value of a given form variable. * * @param string $varname The form variable name. * @param string $default The default form variable value. * * @return mixed The form variable, or $default if it doesn't exist. */ public function get($varname, $default = null) { return $this->_getExists($this->_vars, $varname, $value) ? $value : $default; } /** * Returns the value of a given form variable. * * @param string $varname The form variable name. * * @return mixed The form variable, or null if it doesn't exist. */ public function __get($varname) { $this->_getExists($this->_vars, $varname, $value); return $value; } /** * Implements getter for ArrayAccess interface. * * @see __get() */ public function offsetGet($field) { return $this->__get($field); } /** * Given a variable name, returns the value and sets a variable indicating * whether the value exists in the form data. * * @param string $varname The form variable name. * @param boolean &$exists Reference to variable that will indicate * whether $varname existed in form data. * * @return mixed The form variable, or null if it doesn't exist. */ public function getExists($varname, &$exists) { $exists = $this->_getExists($this->_vars, $varname, $value); return $value; } /** * Sets the value of a given form variable. * * @see __set() */ public function set($varname, $value) { $this->$varname = $value; } /** * Sets the value of a given form variable. * * @param string $varname The form variable name. * @param mixed $value The value to set. */ public function __set($varname, $value) { $keys = array(); if (Horde_Array::getArrayParts($varname, $base, $keys)) { array_unshift($keys, $base); $place = &$this->_vars; $i = count($keys); while ($i--) { $key = array_shift($keys); if (!isset($place[$key])) { $place[$key] = array(); } $place = &$place[$key]; } $place = $value; } else { $this->_vars[$varname] = $value; } } /** * Implements setter for ArrayAccess interface. * * @see __set() */ public function offsetSet($field, $value) { $this->__set($field, $value); } /** * Deletes a given form variable. * * @see __unset() */ public function remove($varname) { unset($this->$varname); } /** * Deletes a given form variable. * * @param string $varname The form variable name. */ public function __unset($varname) { Horde_Array::getArrayParts($varname, $base, $keys); if (is_null($base)) { unset($this->_vars[$varname]); } else { $ptr = &$this->_vars[$base]; $end = count($keys) - 1; foreach ($keys as $key => $val) { if (!isset($ptr[$val])) { break; } if ($end == $key) { array_splice($ptr, array_search($val, array_keys($ptr)), 1); } else { $ptr = &$ptr[$val]; } } } } /** * Implements unset() for ArrayAccess interface. * * @see __unset() */ public function offsetUnset($field) { $this->__unset($field); } /** * Merges a list of variables into the current form variable list. * * @param array $vars Form variables. */ public function merge($vars) { foreach ($vars as $varname => $value) { $this->$varname = $value; } } /** * Set $varname to $value ONLY if it's not already present. * * @param string $varname The form variable name. * @param mixed $value The value to set. * * @return boolean True if the value was altered. */ public function add($varname, $value) { if ($this->exists($varname)) { return false; } $this->_vars[$varname] = $value; return true; } /** * Filters a form value so that it can be used in HTML output. * * @param string $varname The form variable name. * * @return mixed The filtered variable, or null if it doesn't exist. */ public function filter($varname) { $val = $this->$varname; if (is_null($val) || $this->_sanitized) { return $val; } return is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING); } /* Protected methods. */ /** * Fetch the requested variable ($varname) into $value, and return * whether or not the variable was set in $array. * * @param array $array The array to search in (usually either * $this->_vars or $this->_expected). * @param string $varname The name of the variable to look for. * @param mixed &$value $varname's value gets assigned to this variable. * * @return boolean Whether or not the variable was set (or, if we've * checked $this->_expected, should have been set). */ protected function _getExists($array, $varname, &$value) { if (Horde_Array::getArrayParts($varname, $base, $keys)) { if (!isset($array[$base])) { $value = null; return false; } $searchspace = &$array[$base]; $i = count($keys); while ($i--) { $key = array_shift($keys); if (!isset($searchspace[$key])) { $value = null; return false; } $searchspace = &$searchspace[$key]; } $value = $searchspace; return true; } $value = isset($array[$varname]) ? $array[$varname] : null; return !is_null($value); } /* Countable methods. */ /** */ public function count() { return count($this->_vars); } /* IteratorAggregate method. */ public function getIterator() { return new ArrayIterator($this->_vars); } } Horde_Util-2.3.0/test/Horde/Util/fixtures/domhtml_test.html0000644000175000007640000000015712163054615023753 0ustar slusarzslusarz Foo
Bar
Horde_Util-2.3.0/test/Horde/Util/AllTests.php0000644000175000007640000000013212163054615020746 0ustar slusarzslusarzrun(); Horde_Util-2.3.0/test/Horde/Util/ArrayTest.php0000644000175000007640000000346212163054615021142 0ustar slusarzslusarz * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @category Horde * @package Util * @subpackage UnitTests */ class Horde_Util_ArrayTest extends PHPUnit_Framework_TestCase { public function setUp() { $this->array = array( array('name' => 'foo', 'desc' => 'foo long desc'), array('name' => 'aaaa', 'desc' => 'aaa foo long desc'), array('name' => 'baby', 'desc' => 'The test data was boring'), array('name' => 'zebra', 'desc' => 'Striped armadillos'), array('name' => 'umbrage', 'desc' => 'resentment'), ); } public function testArraySort() { Horde_Array::arraySort($this->array); $this->assertEquals( array( 1 => array('name' => 'aaaa', 'desc' => 'aaa foo long desc'), 2 => array('name' => 'baby', 'desc' => 'The test data was boring'), 0 => array('name' => 'foo', 'desc' => 'foo long desc'), 4 => array('name' => 'umbrage', 'desc' => 'resentment'), 3 => array('name' => 'zebra', 'desc' => 'Striped armadillos'), ), $this->array ); } public function testArraySortKey() { Horde_Array::arraySort($this->array, 'desc'); $this->assertEquals( array( 1 => array('name' => 'aaaa', 'desc' => 'aaa foo long desc'), 0 => array('name' => 'foo', 'desc' => 'foo long desc'), 4 => array('name' => 'umbrage', 'desc' => 'resentment'), 3 => array('name' => 'zebra', 'desc' => 'Striped armadillos'), 2 => array('name' => 'baby', 'desc' => 'The test data was boring'), ), $this->array ); } } Horde_Util-2.3.0/test/Horde/Util/bootstrap.php0000644000175000007640000000014312163054615021232 0ustar slusarzslusarz * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @category Horde * @package Util * @subpackage UnitTests */ class Horde_Util_DomhtmlTest extends PHPUnit_Framework_TestCase { public function testBug9567() { $text = << pr=E9parer =E0 vendre d’ao=FBt ; EOT; $expected = "préparer à vendre d’août ;"; $dom = new Horde_Domhtml(quoted_printable_decode($text), 'iso-8859-1'); $this->assertEquals( Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-1'), trim($dom->returnBody()) ); $this->assertEquals( 'iso-8859-1', $dom->getCharset() ); /* Test auto-detect. */ $dom = new Horde_Domhtml(quoted_printable_decode($text)); $this->assertEquals( Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-1'), trim($dom->returnBody()) ); $this->assertEquals( 'iso-8859-1', $dom->getCharset() ); } public function testBug9714() { $text = "J'ai r=E9ussi J ai r=E9ussi"; $expected = "J'ai réussi J ai réussi"; $dom = new Horde_Domhtml(quoted_printable_decode($text), 'iso-8859-15'); $this->assertEquals( Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-15'), trim($dom->returnBody()) ); /* iso-8859-15 is not recognized, so UTF-8 is used internally. */ $this->assertEquals( 'UTF-8', $dom->getCharset() ); /* Test auto-detect. */ $dom = new Horde_Domhtml(quoted_printable_decode($text)); $this->assertEquals( Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-15'), trim($dom->returnBody()) ); /* iso-8859-1 is used for auto-detection. */ $this->assertEquals( 'iso-8859-1', $dom->getCharset() ); } public function testBug9992() { $text = base64_decode('dGVzdDogtbno6bvtu+nt/eHpu7797Txicj4K'); $expected = '

test: ľščéťíťéíýáéťžýí

'; $dom = new Horde_Domhtml($text, 'iso-8859-2'); $this->assertEquals( Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-2'), trim($dom->returnBody()) ); $this->assertEquals( 'UTF-8', $dom->getCharset() ); } public function testIterator() { $text = file_get_contents(__DIR__ . '/fixtures/domhtml_test.html'); $dom = new Horde_Domhtml($text); $tags = array( 'html', 'body', 'div', 'head', 'title' ); foreach ($dom as $node) { if ($node instanceof DOMElement) { if ($node->tagName != reset($tags)) { $this->fail('Wrong tag name.'); } array_shift($tags); } } } public function testHrefSpaces() { $text = << Foo EOT; $dom = new Horde_Domhtml($text, 'UTF-8'); foreach ($dom as $val) { if (($val instanceof DOMElement) && ($val->tagName == 'a')) { $this->assertEquals( ' http://foo.example.com/', $val->getAttribute('href') ); } } $this->assertEquals( 'UTF-8', $dom->getCharset() ); } public function testHeadGeneration() { $dom = new Horde_Domhtml('
foo
'); $head = $dom->getHead(); $this->assertNull($head->previousSibling); $this->assertEquals( 'iso-8859-1', $dom->getCharset() ); } public function testBodyGeneration() { $dom = new Horde_Domhtml('
foo
'); $body = $dom->getBody(); $this->assertEquals( 1, $body->childNodes->length ); $this->assertEquals( 'div', $body->childNodes->item(0)->tagName ); } public function testReturnHtmlCharset() { $dom = new Horde_DomHtml('
préparer à vendre d’août
', 'UTF-8'); $this->assertEquals( $dom->returnHtml(), $dom->returnHtml(array('charset' => 'iso-8859-1')) ); } public function testReturnHtmlMetaCharset() { $dom = new Horde_Domhtml('
foo
', 'UTF-8'); $this->assertRegExp( '/"text\/html; charset=utf-8"/', $dom->returnHtml(array('metacharset' => true)) ); } } Horde_Util-2.3.0/test/Horde/Util/phpunit.xml0000644000175000007640000000005612163054615020720 0ustar slusarzslusarz Horde_Util-2.3.0/test/Horde/Util/StringTest.php0000644000175000007640000004256112163054615021335 0ustar slusarzslusarz * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @category Horde * @package Util * @subpackage UnitTests */ class Horde_Util_StringTest extends PHPUnit_Framework_TestCase { public function tearDown() { setlocale(LC_ALL, ''); } public function testUpper() { $this->assertEquals( 'ABCDEFGHII', Horde_String::upper('abCDefGHiI', true, 'us-ascii') ); $this->assertEquals( 'ABCDEFGHII', Horde_String::upper('abCDefGHiI', true, 'Big5') ); $this->assertEquals( 'ABCDEFGHİI', Horde_String::convertCharset( Horde_String::upper('abCDefGHiI', true, 'iso-8859-9'), 'iso-8859-9', 'utf-8') ); } public function testUpperTurkish() { if (!setlocale(LC_ALL, 'tr_TR')) { $this->markTestSkipped('No Turkish locale installed.'); } $one = Horde_String::convertCharset(strtoupper('abCDefGHiI'), 'iso-8859-9', 'utf-8'); $two = Horde_String::upper('abCDefGHiI'); setlocale(LC_ALL, 'C'); $this->assertEquals('ABCDEFGHİI', $one); $this->assertEquals('ABCDEFGHII', $two); } public function testLower() { $this->assertEquals( 'abcdefghii', Horde_String::lower('abCDefGHiI', true, 'us-ascii') ); $this->assertEquals( 'abcdefghii', Horde_String::lower('abCDefGHiI', true, 'Big5') ); $this->assertEquals( 'abcdefghiı', Horde_String::convertCharset( Horde_String::lower('abCDefGHiI', true, 'iso-8859-9'), 'iso-8859-9', 'utf-8') ); } public function testLowerTurkish() { if (!setlocale(LC_ALL, 'tr_TR')) { $this->markTestSkipped('No Turkish locale installed.'); } $one = Horde_String::convertCharset(strtolower('abCDefGHiI'), 'iso-8859-9', 'utf-8'); $two = Horde_String::lower('abCDefGHiI'); setlocale(LC_ALL, 'C'); $this->assertEquals('abcdefghiı', $one); $this->assertEquals('abcdefghii', $two); } public function testUcfirst() { $this->assertEquals( 'Integer', Horde_String::ucfirst('integer', true, 'us-ascii') ); $this->assertEquals( 'Integer', Horde_String::ucfirst('integer', true, 'Big5') ); $this->assertEquals( 'İnteger', Horde_String::convertCharset( Horde_String::ucfirst('integer', true, 'iso-8859-9'), 'iso-8859-9', 'utf-8') ); } public function testUcwords() { $this->assertEquals( 'Integer Inside', Horde_String::ucwords('integer inside', true, 'us-ascii') ); $this->assertEquals( 'Integer Inside', Horde_String::ucwords('integer inside', true, 'Big5') ); $this->assertEquals( 'İnteger İnside', Horde_String::convertCharset( Horde_String::ucwords('integer inside', true, 'iso-8859-9'), 'iso-8859-9', 'utf-8') ); } public function testUcfirstTurkish() { if (!setlocale(LC_ALL, 'tr_TR')) { $this->markTestSkipped('No Turkish locale installed.'); } $one = Horde_String::convertCharset(ucfirst('integer'), 'iso-8859-9', 'utf-8'); $two = Horde_String::ucfirst('integer'); setlocale(LC_ALL, 'C'); $this->assertEquals('İnteger', $one); $this->assertEquals('Integer', $two); } public function testLength() { $this->assertEquals(7, Horde_String::length('Welcome', 'Big5')); $this->assertEquals(7, Horde_String::length('Welcome', 'Big5')); $this->assertEquals( 2, Horde_String::length( Horde_String::convertCharset('歡迎', 'utf-8', 'Big5'), 'Big5')); $this->assertEquals(2, Horde_String::length('歡迎', 'utf-8')); /* The following strings were taken with permission from the UTF-8 * sampler by Frank da Cruz and the Kermit Project * (http://www.columbia.edu/kermit/). The original page is located at * http://www.columbia.edu/kermit/utf8.html */ // French 50 $this->assertEquals( 50, Horde_String::length('Je peux manger du verre, ça ne me fait pas de mal.', 'utf-8')); // Spanish 36 $this->assertEquals( 36, Horde_String::length('Puedo comer vidrio, no me hace daño.', 'utf-8')); // Portuguese 34 $this->assertEquals( 34, Horde_String::length('Posso comer vidro, não me faz mal.', 'utf-8')); // Brazilian Portuguese 34 $this->assertEquals( 34, Horde_String::length('Posso comer vidro, não me machuca.', 'utf-8')); // Italian 41 $this->assertEquals( 41, Horde_String::length('Posso mangiare il vetro e non mi fa male.', 'utf-8')); // English 39 $this->assertEquals( 39, Horde_String::length('I can eat glass and it doesn\'t hurt me.', 'utf-8')); // Norsk/Norwegian/Nynorsk 33 $this->assertEquals( 33, Horde_String::length('Eg kan eta glas utan å skada meg.', 'utf-8')); // Svensk/Swedish 36 $this->assertEquals( 36, Horde_String::length('Jag kan äta glas utan att skada mig.', 'utf-8')); // Dansk/Danish 45 $this->assertEquals( 45, Horde_String::length('Jeg kan spise glas, det gør ikke ondt på mig.', 'utf-8')); // Deutsch/German 41 $this->assertEquals( 41, Horde_String::length('Ich kann Glas essen, ohne mir weh zu tun.', 'utf-8')); // Russian 38 $this->assertEquals( 38, Horde_String::length('Я могу есть стекло, оно мне не вредит.', 'utf-8')); } public function testPos() { $this->assertEquals(3, Horde_String::pos('Schöne Neue Welt', 'ö')); $this->assertEquals(7, Horde_String::pos('Schöne Neue Welt', 'N')); $this->assertEquals(6, Horde_String::pos('Schöne Neue Welt', ' ')); $this->assertEquals(3, Horde_String::rpos('Schöne Neue Welt', 'ö')); $this->assertEquals(7, Horde_String::rpos('Schöne Neue Welt', 'N')); $this->assertEquals(11, Horde_String::rpos('Schöne Neue Welt', ' ')); } public function testPad() { /* Simple single byte tests. */ $this->assertEquals( 'abc', Horde_String::pad('abc', 2)); $this->assertEquals( 'abc', Horde_String::pad('abc', 3)); $this->assertEquals( 'abc ', Horde_String::pad('abc', 4)); $this->assertEquals( ' abc', Horde_String::pad('abc', 4, ' ', STR_PAD_LEFT)); $this->assertEquals( 'abc ', Horde_String::pad('abc', 4, ' ', STR_PAD_RIGHT)); $this->assertEquals( 'abc ', Horde_String::pad('abc', 4, ' ', STR_PAD_BOTH)); $this->assertEquals( ' abc', Horde_String::pad('abc', 5, ' ', STR_PAD_LEFT)); $this->assertEquals( 'abc ', Horde_String::pad('abc', 5, ' ', STR_PAD_RIGHT)); $this->assertEquals( ' abc ', Horde_String::pad('abc', 5, ' ', STR_PAD_BOTH)); /* Long padding tests. */ $this->assertEquals( '=-+=-+=abc', Horde_String::pad('abc', 10, '=-+', STR_PAD_LEFT)); $this->assertEquals( 'abc=-+=-+=', Horde_String::pad('abc', 10, '=-+', STR_PAD_RIGHT)); $this->assertEquals( '=-+abc=-+=', Horde_String::pad('abc', 10, '=-+', STR_PAD_BOTH)); /* Multibyte tests. */ $this->assertEquals( ' äöü', Horde_String::pad('äöü', 4, ' ', STR_PAD_LEFT, 'utf-8')); $this->assertEquals( 'äöü ', Horde_String::pad('äöü', 4, ' ', STR_PAD_RIGHT, 'utf-8')); $this->assertEquals( 'äöü ', Horde_String::pad('äöü', 4, ' ', STR_PAD_BOTH, 'utf-8')); $this->assertEquals( 'äöüäöüäabc', Horde_String::pad('abc', 10, 'äöü', STR_PAD_LEFT, 'utf-8')); $this->assertEquals( 'abcäöüäöüä', Horde_String::pad('abc', 10, 'äöü', STR_PAD_RIGHT, 'utf-8')); $this->assertEquals( 'äöüabcäöüä', Horde_String::pad('abc', 10, 'äöü', STR_PAD_BOTH, 'utf-8')); /* Special cases. */ $this->assertEquals( 'abc ', Horde_String::pad('abc', 4, ' ', STR_PAD_RIGHT, 'utf-8')); } public function testSubstr() { $string = "Lörem ipsüm dölör sit ämet"; $this->assertEquals( 't ämet', Horde_String::substr($string, 20, null, 'utf-8')); $this->assertEquals( 't ämet', Horde_String::substr($string, -6, null, 'utf-8')); $this->assertEquals( 'Lörem', Horde_String::substr($string, 0, 5, 'utf-8')); $this->assertEquals( 'Lörem', Horde_String::substr($string, 0, -21, 'utf-8')); $this->assertEquals( 'ipsüm', Horde_String::substr($string, 6, 5, 'utf-8')); } public function testWordwrap() { // Test default parameters and break character. $string = "Lörem ipsüm dölör sit ämet, cönsectetüer ädipiscing elit. Aliqüäm söllicitüdin fäücibüs mäüris ämet."; $this->assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals( <<assertEquals('', Horde_String::common('foo', 'bar')); $this->assertEquals('foo', Horde_String::common('foobar', 'fooxyx')); $this->assertEquals('foo', Horde_String::common('foo', 'foobar')); } public function testBug9528() { $this->assertEquals( "", Horde_String::convertCharset("", 'UTF-8', 'Windows-1258') ); } public function testLongStringsBreakUtf8DetectionRegex() { $string = str_repeat('1 A B', 10000); /* Failing test will cause a PHP segfault here. */ Horde_String::validUtf8($string); } public function testValidUtf8() { // Examples from: // http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php#54805 $valid = array( 'Valid ASCII' => "a", 'Valid 2 Octet Sequence' => "\xc3\xb1", 'Valid 3 Octet Sequence' => "\xe2\x82\xa1", 'Valid 4 Octet Sequence' => "\xf0\x90\x8c\xbc", 'Bug #11930' => 'ö ä ü ß\n\nMit freundlichen Grüßen', 'Bug #11930-2' => 'öäüß' ); $invalid = array( 'Invalid 2 Octet Sequence' => "\xc3\x28", 'Invalid Sequence Identifier' => "\xa0\xa1", 'Invalid 3 Octet Sequence (in 2nd Octet)' => "\xe2\x28\xa1", 'Invalid 3 Octet Sequence (in 3rd Octet)' => "\xe2\x82\x28", 'Invalid 4 Octet Sequence (in 2nd Octet)' => "\xf0\x28\x8c\xbc", 'Invalid 4 Octet Sequence (in 3rd Octet)' => "\xf0\x90\x28\xbc", 'Invalid 4 Octet Sequence (in 4th Octet)' => "\xf0\x28\x8c\x28", 'Valid 5 Octet Sequence (but not Unicode!)' => "\xf8\xa1\xa1\xa1\xa1", 'Valid 6 Octet Sequence (but not Unicode!)' => "\xfc\xa1\xa1\xa1\xa1\xa1" ); foreach ($valid as $val) { $this->assertEquals( true, Horde_String::validUtf8($val) ); } foreach ($invalid as $val) { $this->assertEquals( false, Horde_String::validUtf8($val) ); } } } Horde_Util-2.3.0/test/Horde/Util/UtilTest.php0000644000175000007640000001025712163054615021001 0ustar slusarzslusarz * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @category Horde * @package Util * @subpackage UnitTests */ class Horde_Util_UtilTest extends PHPUnit_Framework_TestCase { public function testGetPathInfo() { $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['SERVER_SOFTWARE'] = ''; $_SERVER['PATH_INFO'] = ''; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['PATH_INFO'] = '/foo/bar'; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['SERVER_SOFTWARE'] = 'lighttpd/1.4.26'; $_SERVER['PATH_INFO'] = ''; $_SERVER['REQUEST_URI'] = '/horde/path.php'; $_SERVER['SCRIPT_NAME'] = '/horde/path.php'; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/path.php?baz'; $_SERVER['QUERY_STRING'] = 'baz'; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/path.php/foo/bar'; $_SERVER['SCRIPT_NAME'] = '/horde/path.php'; $_SERVER['QUERY_STRING'] = ''; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/path.php/foo/bar?baz'; $_SERVER['QUERY_STRING'] = 'baz'; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/foo/bar?baz'; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/'; $_SERVER['SCRIPT_NAME'] = '/horde/index.php'; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/index.php'; $_SERVER['SCRIPT_NAME'] = '/horde/index.php'; $_SERVER['QUERY_STRING'] = ''; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/index.php?baz'; $_SERVER['QUERY_STRING'] = 'baz'; $this->assertEquals('', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/index.php/foo/bar'; $_SERVER['SCRIPT_NAME'] = '/horde/index.php'; $_SERVER['QUERY_STRING'] = ''; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/horde/index.php/foo/bar?baz'; $_SERVER['QUERY_STRING'] = 'baz'; $this->assertEquals('/foo/bar', Horde_Util::getPathInfo()); $_SERVER['REQUEST_URI'] = '/test/42?id=42'; $_SERVER['SCRIPT_NAME'] = '/test/index.php'; $_SERVER['QUERY_STRING'] = 'id=42&id=42'; $this->assertEquals('/42', Horde_Util::getPathInfo()); } public function testDispelMagicQuotes() { Horde_Util_Test::setMagicQuotes(false); $vars = $expected = array('foobar', 'foo\bar', 'foo\\bar', 'foo\"bar'); foreach ($vars as $key => $var) { $this->assertEquals($expected[$key], Horde_Util_Test::dispelMagicQuotes($var)); $this->assertEquals($expected[$key], Horde_Util_Test::dispelMagicQuotes($var)); } foreach ($vars as $key => $var) { $var = array($var); $this->assertEquals(array($expected[$key]), Horde_Util_Test::dispelMagicQuotes($var)); $this->assertEquals(array($expected[$key]), Horde_Util_Test::dispelMagicQuotes($var)); } Horde_Util_Test::setMagicQuotes(true); $vars = array('foobar', 'foo\bar', 'foo\\\\bar', 'foo\"bar'); $expected = array('foobar', 'foobar', 'foo\bar', 'foo"bar'); foreach ($vars as $key => $var) { $this->assertEquals($expected[$key], Horde_Util_Test::dispelMagicQuotes($var)); $this->assertEquals($expected[$key], Horde_Util_Test::dispelMagicQuotes($var)); } foreach ($vars as $key => $var) { $var = array($var); $this->assertEquals(array($expected[$key]), Horde_Util_Test::dispelMagicQuotes($var)); $this->assertEquals(array($expected[$key]), Horde_Util_Test::dispelMagicQuotes($var)); } } } /** * @internal */ class Horde_Util_Test extends Horde_Util { static public function setMagicQuotes($set) { self::$_magicquotes = $set; } } Horde_Util-2.3.0/test/Horde/Util/VariablesTest.php0000644000175000007640000000166112163054615021773 0ustar slusarzslusarz * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @category Horde * @package Util * @subpackage UnitTests */ class Horde_Util_VariablesTest extends PHPUnit_Framework_TestCase { public function testRemove() { $vars = new Horde_Variables(array( 'a' => 'a', 'b' => 'b', 'c' => array(1, 2, 3), 'd' => array( 'z' => 'z', 'y' => array( 'f' => 'f', 'g' => 'g' ) ) )); $vars->remove('a'); $vars->remove('d[y][g]'); $this->assertNull($vars->a); $this->assertEquals('b', $vars->b); $this->assertEquals(array(1, 2, 3), $vars->c); $this->assertEquals( array('z' => 'z', 'y' => array('f' => 'f')), $vars->d ); } }