package.xml0000644000175000007640000002317412232027021013165 0ustar slusarzslusarz Horde_Css_Parser pear.horde.org Horde CSS Parser This package provides access to the Sabberworm CSS Parser from within the Horde framework. Michael Slusarz slusarz slusarz@horde.org yes 2013-10-23 1.0.3 1.0.0 stable stable LGPL-2.1 * [mms] Merge from upstream - handle keywords/dimensions case-insensitively. 5.3.0 1.7.0 mbstring 1.0.0 1.0.0 stable stable 2013-04-08 LGPL-2.1 * First release for Horde 5. 1.0.1 1.0.0 stable stable 2013-08-22 LGPL-2.1 * [jan] Fix certain sizes reduced by factor ten (Bug #12462). 1.0.2 1.0.0 stable stable 2013-10-15 LGPL-2.1 * [mms] Performance optimizations in the parser. 1.0.3 1.0.0 stable stable 2013-10-23 LGPL-2.1 * [mms] Merge from upstream - handle keywords/dimensions case-insensitively. Horde_Css_Parser-1.0.3/doc/Horde/Css/Parser/COPYING0000644000175000007640000005765612232027021021533 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_Css_Parser-1.0.3/doc/Horde/Css/Parser/EXPAT_LICENSE0000644000175000007640000000231612232027021022425 0ustar slusarzslusarzLicense for the original PHP-CSS-Parser code (Expat License): PHP-CSS-Parser is freely distributable under the terms of an MIT-style license. Copyright (c) 2011 Raphael Schweikert, http://sabberworm.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Horde_Css_Parser-1.0.3/lib/Horde/Css/Parser.php0000644000175000007640000000332612232027021021173 0ustar slusarzslusarz * @category Horde * @copyright 2013 Horde LLC * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1 * @package Css_Parser */ class Horde_Css_Parser { /** * The parsed CSS document object. * * @var Sabberworm\CSS\CSSList\Document */ public $doc; /** * The parser object. * * @var Sabberworm\CSS\Parser */ public $parser; /** * Constructor. * * @param string $css CSS data. * @param Sabberworm\CSS\Settings $charset Parser settings. */ public function __construct($css, Sabberworm\CSS\Settings $settings = null) { if (is_null($settings)) { $settings = Sabberworm\CSS\Settings::create(); $settings->withMultibyteSupport(false); } $this->parser = new Sabberworm\CSS\Parser($css, $settings); $this->doc = $this->parser->parse(); } /** * Returns compressed CSS output. * * @return string Compressed CSS */ public function compress() { return str_replace( array("\n", ' {', ': ', ';}', ', '), array('', '{', ':', '}', ','), strval($this->doc) ); } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/AtRuleBlockList.php0000644000175000007640000000141012232027021025160 0ustar slusarzslusarzsType = $sType; $this->sArgs = $sArgs; } public function atRuleName() { return $this->sType; } public function atRuleArgs() { return $this->sArgs; } public function __toString() { $sResult = "@{$this->sType} {$this->sArgs}{"; $sResult .= parent::__toString(); $sResult .= '}'; return $sResult; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/CSSBlockList.php0000644000175000007640000000605712232027021024430 0ustar slusarzslusarzaContents as $mContent) { if ($mContent instanceof DeclarationBlock) { $aResult[] = $mContent; } else if ($mContent instanceof CSSBlockList) { $mContent->allDeclarationBlocks($aResult); } } } protected function allRuleSets(&$aResult) { foreach ($this->aContents as $mContent) { if ($mContent instanceof RuleSet) { $aResult[] = $mContent; } else if ($mContent instanceof CSSBlockList) { $mContent->allRuleSets($aResult); } } } protected function allValues($oElement, &$aResult, $sSearchString = null, $bSearchInFunctionArguments = false) { if ($oElement instanceof CSSBlockList) { foreach ($oElement->getContents() as $oContent) { $this->allValues($oContent, $aResult, $sSearchString, $bSearchInFunctionArguments); } } else if ($oElement instanceof RuleSet) { foreach ($oElement->getRules($sSearchString) as $oRule) { $this->allValues($oRule, $aResult, $sSearchString, $bSearchInFunctionArguments); } } else if ($oElement instanceof Rule) { $this->allValues($oElement->getValue(), $aResult, $sSearchString, $bSearchInFunctionArguments); } else if ($oElement instanceof ValueList) { if ($bSearchInFunctionArguments || !($oElement instanceof CSSFunction)) { foreach ($oElement->getListComponents() as $mComponent) { $this->allValues($mComponent, $aResult, $sSearchString, $bSearchInFunctionArguments); } } } else { //Non-List Value or String (CSS identifier) $aResult[] = $oElement; } } protected function allSelectors(&$aResult, $sSpecificitySearch = null) { $aDeclarationBlocks = array(); $this->allDeclarationBlocks($aDeclarationBlocks); foreach ($aDeclarationBlocks as $oBlock) { foreach ($oBlock->getSelectors() as $oSelector) { if ($sSpecificitySearch === null) { $aResult[] = $oSelector; } else { $sComparison = "\$bRes = {$oSelector->getSpecificity()} $sSpecificitySearch;"; eval($sComparison); if ($bRes) { $aResult[] = $oSelector; } } } } } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/CSSList.php0000644000175000007640000000427412232027021023454 0ustar slusarzslusarzaContents = array(); } public function append($oItem) { $this->aContents[] = $oItem; } /** * Removes an item from the CSS list. * @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery) */ public function remove($oItemToRemove) { $iKey = array_search($oItemToRemove, $this->aContents, true); if ($iKey !== false) { unset($this->aContents[$iKey]); } } public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false) { if ($mSelector instanceof DeclarationBlock) { $mSelector = $mSelector->getSelectors(); } if (!is_array($mSelector)) { $mSelector = explode(',', $mSelector); } foreach ($mSelector as $iKey => &$mSel) { if (!($mSel instanceof Selector)) { $mSel = new Selector($mSel); } } foreach ($this->aContents as $iKey => $mItem) { if (!($mItem instanceof DeclarationBlock)) { continue; } if ($mItem->getSelectors() == $mSelector) { unset($this->aContents[$iKey]); if (!$bRemoveAll) { return; } } } } public function __toString() { $sResult = ''; foreach ($this->aContents as $oContent) { $sResult .= $oContent->__toString(); } return $sResult; } public function getContents() { return $this->aContents; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/Document.php0000644000175000007640000000563012232027021023743 0ustar slusarzslusarzallDeclarationBlocks($aResult); return $aResult; } /** * @deprecated use getAllDeclarationBlocks() */ public function getAllSelectors() { return $this->getAllDeclarationBlocks(); } /** * Returns all RuleSet objects found recursively in the tree. */ public function getAllRuleSets() { $aResult = array(); $this->allRuleSets($aResult); return $aResult; } /** * Returns all Value objects found recursively in the tree. * @param (object|string) $mElement the CSSList or RuleSet to start the search from (defaults to the whole document). If a string is given, it is used as rule name filter (@see{RuleSet->getRules()}). * @param (bool) $bSearchInFunctionArguments whether to also return Value objects used as Function arguments. */ public function getAllValues($mElement = null, $bSearchInFunctionArguments = false) { $sSearchString = null; if ($mElement === null) { $mElement = $this; } else if (is_string($mElement)) { $sSearchString = $mElement; $mElement = $this; } $aResult = array(); $this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments); return $aResult; } /** * Returns all Selector objects found recursively in the tree. * Note that this does not yield the full DeclarationBlock that the selector belongs to (and, currently, there is no way to get to that). * @param $sSpecificitySearch An optional filter by specificity. May contain a comparison operator and a number or just a number (defaults to "=="). * @example getSelectorsBySpecificity('>= 100') */ public function getSelectorsBySpecificity($sSpecificitySearch = null) { if (is_numeric($sSpecificitySearch) || is_numeric($sSpecificitySearch[0])) { $sSpecificitySearch = "== $sSpecificitySearch"; } $aResult = array(); $this->allSelectors($aResult, $sSpecificitySearch); return $aResult; } /** * Expands all shorthand properties to their long value */ public function expandShorthands() { foreach ($this->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->expandShorthands(); } } /* * Create shorthands properties whenever possible */ public function createShorthands() { foreach ($this->getAllDeclarationBlocks() as $oDeclaration) { $oDeclaration->createShorthands(); } } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/KeyFrame.php0000644000175000007640000000211312232027021023661 0ustar slusarzslusarzvendorKeyFrame = null; $this->animationName = null; } public function setVendorKeyFrame($vendorKeyFrame) { $this->vendorKeyFrame = $vendorKeyFrame; } public function getVendorKeyFrame() { return $this->vendorKeyFrame; } public function setAnimationName($animationName) { $this->animationName = $animationName; } public function getAnimationName() { return $this->animationName; } public function __toString() { $sResult = "@{$this->vendorKeyFrame} {$this->animationName} {"; $sResult .= parent::__toString(); $sResult .= '}'; return $sResult; } public function atRuleName() { return $this->vendorKeyFrame; } public function atRuleArgs() { return $this->animationName; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/CSSList/MediaQuery.php0000644000175000007640000000117212232027021024227 0ustar slusarzslusarzsQuery = null; } public function setQuery($sQuery) { $this->sQuery = $sQuery; } public function getQuery() { return $this->sQuery; } public function __toString() { $sResult = "@media {$this->sQuery} {"; $sResult .= parent::__toString(); $sResult .= '}'; return $sResult; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Parsing/UnexpectedTokenException.php0000644000175000007640000000207312232027021027266 0ustar slusarzslusarzsExpected = $sExpected; $this->sFound = $sFound; $this->sMatchType = $sMatchType; $sMessage = "Token “{$sExpected}” ({$sMatchType}) not found. Got “{$sFound}”."; if($this->sMatchType === 'search') { $sMessage = "Search for “{$sExpected}” returned no results. Context: “{$sFound}”."; } else if($this->sMatchType === 'count') { $sMessage = "Next token was expected to have {$sExpected} chars. Context: “{$sFound}”."; } else if($this->sMatchType === 'identifier') { $sMessage = "Identifier expected. Got “{$sFound}”"; } parent::__construct($sMessage); } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Property/AtRule.php0000644000175000007640000000104112232027021023711 0ustar slusarzslusarzsCharset = $sCharset; } public function setCharset($sCharset) { $this->sCharset = $sCharset; } public function getCharset() { return $this->sCharset; } public function __toString() { return "@charset {$this->sCharset->__toString()};"; } public function atRuleName() { return 'charset'; } public function atRuleArgs() { return $this->sCharset; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Property/CSSNamespace.php0000644000175000007640000000177612232027021025001 0ustar slusarzslusarzmUrl = $mUrl; $this->sPrefix = $sPrefix; } public function __toString() { return '@namespace '.($this->sPrefix === null ? '' : $this->sPrefix.' ').$this->mUrl->__toString().';'; } public function getUrl() { return $this->mUrl; } public function getPrefix() { return $this->sPrefix; } public function setUrl($mUrl) { $this->mUrl = $mUrl; } public function setPrefix($sPrefix) { $this->sPrefix = $sPrefix; } public function atRuleName() { return 'namespace'; } public function atRuleArgs() { $aResult = array($this->mUrl); if($this->sPrefix) { array_unshift($aResult, $this->sPrefix); } return $aResult; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Property/Import.php0000644000175000007640000000171312232027021023775 0ustar slusarzslusarzoLocation = $oLocation; $this->sMediaQuery = $sMediaQuery; } public function setLocation($oLocation) { $this->oLocation = $oLocation; } public function getLocation() { return $this->oLocation; } public function __toString() { return "@import ".$this->oLocation->__toString().($this->sMediaQuery === null ? '' : ' '.$this->sMediaQuery).';'; } public function atRuleName() { return 'import'; } public function atRuleArgs() { $aResult = array($this->oLocation); if($this->sMediaQuery) { array_push($aResult, $this->sMediaQuery); } return $aResult; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Property/Selector.php0000644000175000007640000000451112232027021024302 0ustar slusarzslusarz\~]+)[\w]+ # elements | \:{1,2}( # pseudo-elements after|before |first-letter|first-line |selection ) )/ix'; private $sSelector; private $iSpecificity; public function __construct($sSelector, $bCalculateSpecificity = false) { $this->setSelector($sSelector); if ($bCalculateSpecificity) { $this->getSpecificity(); } } public function getSelector() { return $this->sSelector; } public function setSelector($sSelector) { $this->sSelector = trim($sSelector); $this->iSpecificity = null; } public function __toString() { return $this->getSelector(); } public function getSpecificity() { if ($this->iSpecificity === null) { $a = 0; /// @todo should exclude \# as well as "#" $aMatches; $b = substr_count($this->sSelector, '#'); $c = preg_match_all(self::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX, $this->sSelector, $aMatches); $d = preg_match_all(self::ELEMENTS_AND_PSEUDO_ELEMENTS_RX, $this->sSelector, $aMatches); $this->iSpecificity = ($a * 1000) + ($b * 100) + ($c * 10) + $d; } return $this->iSpecificity; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Rule/Rule.php0000644000175000007640000001115712232027021022520 0ustar slusarzslusarzsRule = $sRule; $this->mValue = null; $this->bIsImportant = false; } public function setRule($sRule) { $this->sRule = $sRule; } public function getRule() { return $this->sRule; } public function getValue() { return $this->mValue; } public function setValue($mValue) { $this->mValue = $mValue; } /** * @deprecated Old-Style 2-dimensional array given. Retained for (some) backwards-compatibility. Use setValue() instead and wrapp the value inside a RuleValueList if necessary. */ public function setValues($aSpaceSeparatedValues) { $oSpaceSeparatedList = null; if (count($aSpaceSeparatedValues) > 1) { $oSpaceSeparatedList = new RuleValueList(' '); } foreach ($aSpaceSeparatedValues as $aCommaSeparatedValues) { $oCommaSeparatedList = null; if (count($aCommaSeparatedValues) > 1) { $oCommaSeparatedList = new RuleValueList(','); } foreach ($aCommaSeparatedValues as $mValue) { if (!$oSpaceSeparatedList && !$oCommaSeparatedList) { $this->mValue = $mValue; return $mValue; } if ($oCommaSeparatedList) { $oCommaSeparatedList->addListComponent($mValue); } else { $oSpaceSeparatedList->addListComponent($mValue); } } if (!$oSpaceSeparatedList) { $this->mValue = $oCommaSeparatedList; return $oCommaSeparatedList; } else { $oSpaceSeparatedList->addListComponent($oCommaSeparatedList); } } $this->mValue = $oSpaceSeparatedList; return $oSpaceSeparatedList; } /** * @deprecated Old-Style 2-dimensional array returned. Retained for (some) backwards-compatibility. Use getValue() instead and check for the existance of a (nested set of) ValueList object(s). */ public function getValues() { if (!$this->mValue instanceof RuleValueList) { return array(array($this->mValue)); } if ($this->mValue->getListSeparator() === ',') { return array($this->mValue->getListComponents()); } $aResult = array(); foreach ($this->mValue->getListComponents() as $mValue) { if (!$mValue instanceof RuleValueList || $mValue->getListSeparator() !== ',') { $aResult[] = array($mValue); continue; } if ($this->mValue->getListSeparator() === ' ' || count($aResult) === 0) { $aResult[] = array(); } foreach ($mValue->getListComponents() as $mValue) { $aResult[count($aResult) - 1][] = $mValue; } } return $aResult; } /** * Adds a value to the existing value. Value will be appended if a RuleValueList exists of the given type. Otherwise, the existing value will be wrapped by one. */ public function addValue($mValue, $sType = ' ') { if (!is_array($mValue)) { $mValue = array($mValue); } if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) { $mCurrentValue = $this->mValue; $this->mValue = new RuleValueList($sType); if ($mCurrentValue) { $this->mValue->addListComponent($mCurrentValue); } } foreach ($mValue as $mValueItem) { $this->mValue->addListComponent($mValueItem); } } public function setIsImportant($bIsImportant) { $this->bIsImportant = $bIsImportant; } public function getIsImportant() { return $this->bIsImportant; } public function __toString() { $sResult = "{$this->sRule}: "; if ($this->mValue instanceof Value) { //Can also be a ValueList $sResult .= $this->mValue->__toString(); } else { $sResult .= $this->mValue; } if ($this->bIsImportant) { $sResult .= ' !important'; } $sResult .= ';'; return $sResult; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/RuleSet/AtRuleSet.php0000644000175000007640000000137512232027021024136 0ustar slusarzslusarzsType = $sType; $this->sArgs = $sArgs; } public function atRuleName() { return $this->sType; } public function atRuleArgs() { return $this->sArgs; } public function __toString() { $sResult = "@{$this->sType} {$this->sArgs}{"; $sResult .= parent::__toString(); $sResult .= '}'; return $sResult; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php0000644000175000007640000005457112232027021025474 0ustar slusarzslusarzaSelectors = array(); } public function setSelectors($mSelector) { if (is_array($mSelector)) { $this->aSelectors = $mSelector; } else { $this->aSelectors = explode(',', $mSelector); } foreach ($this->aSelectors as $iKey => $mSelector) { if (!($mSelector instanceof Selector)) { $this->aSelectors[$iKey] = new Selector($mSelector); } } } /** * @deprecated use getSelectors() */ public function getSelector() { return $this->getSelectors(); } /** * @deprecated use setSelectors() */ public function setSelector($mSelector) { $this->setSelectors($mSelector); } public function getSelectors() { return $this->aSelectors; } /** * Split shorthand declarations (e.g. +margin+ or +font+) into their constituent parts. * */ public function expandShorthands() { // border must be expanded before dimensions $this->expandBorderShorthand(); $this->expandDimensionsShorthand(); $this->expandFontShorthand(); $this->expandBackgroundShorthand(); $this->expandListStyleShorthand(); } /** * Create shorthand declarations (e.g. +margin+ or +font+) whenever possible. * */ public function createShorthands() { $this->createBackgroundShorthand(); $this->createDimensionsShorthand(); // border must be shortened after dimensions $this->createBorderShorthand(); $this->createFontShorthand(); $this->createListStyleShorthand(); } /** * Split shorthand border declarations (e.g. border: 1px red;) * Additional splitting happens in expandDimensionsShorthand * Multiple borders are not yet supported as of 3 * */ public function expandBorderShorthand() { $aBorderRules = array( 'border', 'border-left', 'border-right', 'border-top', 'border-bottom' ); $aBorderSizes = array( 'thin', 'medium', 'thick' ); $aRules = $this->getRulesAssoc(); foreach ($aBorderRules as $sBorderRule) { if (!isset($aRules[$sBorderRule])) continue; $oRule = $aRules[$sBorderRule]; $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } foreach ($aValues as $mValue) { if ($mValue instanceof Value) { $mNewValue = clone $mValue; } else { $mNewValue = $mValue; } if ($mValue instanceof Size) { $sNewRuleName = $sBorderRule . "-width"; } else if ($mValue instanceof Color) { $sNewRuleName = $sBorderRule . "-color"; } else { if (in_array($mValue, $aBorderSizes)) { $sNewRuleName = $sBorderRule . "-width"; } else/* if(in_array($mValue, $aBorderStyles)) */ { $sNewRuleName = $sBorderRule . "-style"; } } $oNewRule = new Rule($sNewRuleName); $oNewRule->setIsImportant($oRule->getIsImportant()); $oNewRule->addValue(array($mNewValue)); $this->addRule($oNewRule); } $this->removeRule($sBorderRule); } } /** * Split shorthand dimensional declarations (e.g. margin: 0px auto;) * into their constituent parts. * Handles margin, padding, border-color, border-style and border-width. * */ public function expandDimensionsShorthand() { $aExpansions = array( 'margin' => 'margin-%s', 'padding' => 'padding-%s', 'border-color' => 'border-%s-color', 'border-style' => 'border-%s-style', 'border-width' => 'border-%s-width' ); $aRules = $this->getRulesAssoc(); foreach ($aExpansions as $sProperty => $sExpanded) { if (!isset($aRules[$sProperty])) continue; $oRule = $aRules[$sProperty]; $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } $top = $right = $bottom = $left = null; switch (count($aValues)) { case 1: $top = $right = $bottom = $left = $aValues[0]; break; case 2: $top = $bottom = $aValues[0]; $left = $right = $aValues[1]; break; case 3: $top = $aValues[0]; $left = $right = $aValues[1]; $bottom = $aValues[2]; break; case 4: $top = $aValues[0]; $right = $aValues[1]; $bottom = $aValues[2]; $left = $aValues[3]; break; } foreach (array('top', 'right', 'bottom', 'left') as $sPosition) { $oNewRule = new Rule(sprintf($sExpanded, $sPosition)); $oNewRule->setIsImportant($oRule->getIsImportant()); $oNewRule->addValue(${$sPosition}); $this->addRule($oNewRule); } $this->removeRule($sProperty); } } /** * Convert shorthand font declarations * (e.g. font: 300 italic 11px/14px verdana, helvetica, sans-serif;) * into their constituent parts. * */ public function expandFontShorthand() { $aRules = $this->getRulesAssoc(); if (!isset($aRules['font'])) return; $oRule = $aRules['font']; // reset properties to 'normal' per http://www.w3.org/TR/21/fonts.html#font-shorthand $aFontProperties = array( 'font-style' => 'normal', 'font-variant' => 'normal', 'font-weight' => 'normal', 'font-size' => 'normal', 'line-height' => 'normal' ); $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } foreach ($aValues as $mValue) { if (!$mValue instanceof Value) { $mValue = mb_strtolower($mValue); } if (in_array($mValue, array('normal', 'inherit'))) { foreach (array('font-style', 'font-weight', 'font-variant') as $sProperty) { if (!isset($aFontProperties[$sProperty])) { $aFontProperties[$sProperty] = $mValue; } } } else if (in_array($mValue, array('italic', 'oblique'))) { $aFontProperties['font-style'] = $mValue; } else if ($mValue == 'small-caps') { $aFontProperties['font-variant'] = $mValue; } else if ( in_array($mValue, array('bold', 'bolder', 'lighter')) || ($mValue instanceof Size && in_array($mValue->getSize(), range(100, 900, 100))) ) { $aFontProperties['font-weight'] = $mValue; } else if ($mValue instanceof RuleValueList && $mValue->getListSeparator() == '/') { list($oSize, $oHeight) = $mValue->getListComponents(); $aFontProperties['font-size'] = $oSize; $aFontProperties['line-height'] = $oHeight; } else if ($mValue instanceof Size && $mValue->getUnit() !== null) { $aFontProperties['font-size'] = $mValue; } else { $aFontProperties['font-family'] = $mValue; } } foreach ($aFontProperties as $sProperty => $mValue) { $oNewRule = new Rule($sProperty); $oNewRule->addValue($mValue); $oNewRule->setIsImportant($oRule->getIsImportant()); $this->addRule($oNewRule); } $this->removeRule('font'); } /* * Convert shorthand background declarations * (e.g. background: url("chess.png") gray 50% repeat fixed;) * into their constituent parts. * @see http://www.w3.org/TR/21/colors.html#propdef-background * */ public function expandBackgroundShorthand() { $aRules = $this->getRulesAssoc(); if (!isset($aRules['background'])) return; $oRule = $aRules['background']; $aBgProperties = array( 'background-color' => array('transparent'), 'background-image' => array('none'), 'background-repeat' => array('repeat'), 'background-attachment' => array('scroll'), 'background-position' => array(new Size(0, '%'), new Size(0, '%')) ); $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } if (count($aValues) == 1 && $aValues[0] == 'inherit') { foreach ($aBgProperties as $sProperty => $mValue) { $oNewRule = new Rule($sProperty); $oNewRule->addValue('inherit'); $oNewRule->setIsImportant($oRule->getIsImportant()); $this->addRule($oNewRule); } $this->removeRule('background'); return; } $iNumBgPos = 0; foreach ($aValues as $mValue) { if (!$mValue instanceof Value) { $mValue = mb_strtolower($mValue); } if ($mValue instanceof URL) { $aBgProperties['background-image'] = $mValue; } else if ($mValue instanceof Color) { $aBgProperties['background-color'] = $mValue; } else if (in_array($mValue, array('scroll', 'fixed'))) { $aBgProperties['background-attachment'] = $mValue; } else if (in_array($mValue, array('repeat', 'no-repeat', 'repeat-x', 'repeat-y'))) { $aBgProperties['background-repeat'] = $mValue; } else if (in_array($mValue, array('left', 'center', 'right', 'top', 'bottom')) || $mValue instanceof Size ) { if ($iNumBgPos == 0) { $aBgProperties['background-position'][0] = $mValue; $aBgProperties['background-position'][1] = 'center'; } else { $aBgProperties['background-position'][$iNumBgPos] = $mValue; } $iNumBgPos++; } } foreach ($aBgProperties as $sProperty => $mValue) { $oNewRule = new Rule($sProperty); $oNewRule->setIsImportant($oRule->getIsImportant()); $oNewRule->addValue($mValue); $this->addRule($oNewRule); } $this->removeRule('background'); } public function expandListStyleShorthand() { $aListProperties = array( 'list-style-type' => 'disc', 'list-style-position' => 'outside', 'list-style-image' => 'none' ); $aListStyleTypes = array( 'none', 'disc', 'circle', 'square', 'decimal-leading-zero', 'decimal', 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'armenian', 'georgian', 'cjk-ideographic', 'hiragana', 'hira-gana-iroha', 'katakana-iroha', 'katakana' ); $aListStylePositions = array( 'inside', 'outside' ); $aRules = $this->getRulesAssoc(); if (!isset($aRules['list-style'])) return; $oRule = $aRules['list-style']; $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } if (count($aValues) == 1 && $aValues[0] == 'inherit') { foreach ($aListProperties as $sProperty => $mValue) { $oNewRule = new Rule($sProperty); $oNewRule->addValue('inherit'); $oNewRule->setIsImportant($oRule->getIsImportant()); $this->addRule($oNewRule); } $this->removeRule('list-style'); return; } foreach ($aValues as $mValue) { if (!$mValue instanceof Value) { $mValue = mb_strtolower($mValue); } if ($mValue instanceof Url) { $aListProperties['list-style-image'] = $mValue; } else if (in_array($mValue, $aListStyleTypes)) { $aListProperties['list-style-types'] = $mValue; } else if (in_array($mValue, $aListStylePositions)) { $aListProperties['list-style-position'] = $mValue; } } foreach ($aListProperties as $sProperty => $mValue) { $oNewRule = new Rule($sProperty); $oNewRule->setIsImportant($oRule->getIsImportant()); $oNewRule->addValue($mValue); $this->addRule($oNewRule); } $this->removeRule('list-style'); } public function createShorthandProperties(array $aProperties, $sShorthand) { $aRules = $this->getRulesAssoc(); $aNewValues = array(); foreach ($aProperties as $sProperty) { if (!isset($aRules[$sProperty])) continue; $oRule = $aRules[$sProperty]; if (!$oRule->getIsImportant()) { $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } foreach ($aValues as $mValue) { $aNewValues[] = $mValue; } $this->removeRule($sProperty); } } if (count($aNewValues)) { $oNewRule = new Rule($sShorthand); foreach ($aNewValues as $mValue) { $oNewRule->addValue($mValue); } $this->addRule($oNewRule); } } public function createBackgroundShorthand() { $aProperties = array( 'background-color', 'background-image', 'background-repeat', 'background-position', 'background-attachment' ); $this->createShorthandProperties($aProperties, 'background'); } public function createListStyleShorthand() { $aProperties = array( 'list-style-type', 'list-style-position', 'list-style-image' ); $this->createShorthandProperties($aProperties, 'list-style'); } /** * Combine border-color, border-style and border-width into border * Should be run after create_dimensions_shorthand! * */ public function createBorderShorthand() { $aProperties = array( 'border-width', 'border-style', 'border-color' ); $this->createShorthandProperties($aProperties, 'border'); } /* * Looks for long format CSS dimensional properties * (margin, padding, border-color, border-style and border-width) * and converts them into shorthand CSS properties. * */ public function createDimensionsShorthand() { $aPositions = array('top', 'right', 'bottom', 'left'); $aExpansions = array( 'margin' => 'margin-%s', 'padding' => 'padding-%s', 'border-color' => 'border-%s-color', 'border-style' => 'border-%s-style', 'border-width' => 'border-%s-width' ); $aRules = $this->getRulesAssoc(); foreach ($aExpansions as $sProperty => $sExpanded) { $aFoldable = array(); foreach ($aRules as $sRuleName => $oRule) { foreach ($aPositions as $sPosition) { if ($sRuleName == sprintf($sExpanded, $sPosition)) { $aFoldable[$sRuleName] = $oRule; } } } // All four dimensions must be present if (count($aFoldable) == 4) { $aValues = array(); foreach ($aPositions as $sPosition) { $oRule = $aRules[sprintf($sExpanded, $sPosition)]; $mRuleValue = $oRule->getValue(); $aRuleValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aRuleValues[] = $mRuleValue; } else { $aRuleValues = $mRuleValue->getListComponents(); } $aValues[$sPosition] = $aRuleValues; } $oNewRule = new Rule($sProperty); if ((string) $aValues['left'][0] == (string) $aValues['right'][0]) { if ((string) $aValues['top'][0] == (string) $aValues['bottom'][0]) { if ((string) $aValues['top'][0] == (string) $aValues['left'][0]) { // All 4 sides are equal $oNewRule->addValue($aValues['top']); } else { // Top and bottom are equal, left and right are equal $oNewRule->addValue($aValues['top']); $oNewRule->addValue($aValues['left']); } } else { // Only left and right are equal $oNewRule->addValue($aValues['top']); $oNewRule->addValue($aValues['left']); $oNewRule->addValue($aValues['bottom']); } } else { // No sides are equal $oNewRule->addValue($aValues['top']); $oNewRule->addValue($aValues['left']); $oNewRule->addValue($aValues['bottom']); $oNewRule->addValue($aValues['right']); } $this->addRule($oNewRule); foreach ($aPositions as $sPosition) { $this->removeRule(sprintf($sExpanded, $sPosition)); } } } } /** * Looks for long format CSS font properties (e.g. font-weight) and * tries to convert them into a shorthand CSS font property. * At least font-size AND font-family must be present in order to create a shorthand declaration. * */ public function createFontShorthand() { $aFontProperties = array( 'font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family' ); $aRules = $this->getRulesAssoc(); if (!isset($aRules['font-size']) || !isset($aRules['font-family'])) { return; } $oNewRule = new Rule('font'); foreach (array('font-style', 'font-variant', 'font-weight') as $sProperty) { if (isset($aRules[$sProperty])) { $oRule = $aRules[$sProperty]; $mRuleValue = $oRule->getValue(); $aValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aValues[] = $mRuleValue; } else { $aValues = $mRuleValue->getListComponents(); } if ($aValues[0] !== 'normal') { $oNewRule->addValue($aValues[0]); } } } // Get the font-size value $oRule = $aRules['font-size']; $mRuleValue = $oRule->getValue(); $aFSValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aFSValues[] = $mRuleValue; } else { $aFSValues = $mRuleValue->getListComponents(); } // But wait to know if we have line-height to add it if (isset($aRules['line-height'])) { $oRule = $aRules['line-height']; $mRuleValue = $oRule->getValue(); $aLHValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aLHValues[] = $mRuleValue; } else { $aLHValues = $mRuleValue->getListComponents(); } if ($aLHValues[0] !== 'normal') { $val = new RuleValueList('/'); $val->addListComponent($aFSValues[0]); $val->addListComponent($aLHValues[0]); $oNewRule->addValue($val); } } else { $oNewRule->addValue($aFSValues[0]); } $oRule = $aRules['font-family']; $mRuleValue = $oRule->getValue(); $aFFValues = array(); if (!$mRuleValue instanceof RuleValueList) { $aFFValues[] = $mRuleValue; } else { $aFFValues = $mRuleValue->getListComponents(); } $oFFValue = new RuleValueList(','); $oFFValue->setListComponents($aFFValues); $oNewRule->addValue($oFFValue); $this->addRule($oNewRule); foreach ($aFontProperties as $sProperty) { $this->removeRule($sProperty); } } public function __toString() { $sResult = implode(', ', $this->aSelectors) . ' {'; $sResult .= parent::__toString(); $sResult .= '}' . "\n"; return $sResult; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/RuleSet/RuleSet.php0000644000175000007640000001146112232027021023646 0ustar slusarzslusarzaRules = array(); } public function addRule(Rule $oRule) { $sRule = $oRule->getRule(); if(!isset($this->aRules[$sRule])) { $this->aRules[$sRule] = array(); } $this->aRules[$sRule][] = $oRule; } /** * Returns all rules matching the given rule name * @param (null|string|Rule) $mRule pattern to search for. If null, returns all rules. if the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. passing a Rule behaves like calling getRules($mRule->getRule()). * @example $oRuleSet->getRules('font-') //returns an array of all rules either beginning with font- or matching font. * @example $oRuleSet->getRules('font') //returns array(0 => $oRule, …) or array(). */ public function getRules($mRule = null) { if ($mRule instanceof Rule) { $mRule = $mRule->getRule(); } $aResult = array(); foreach($this->aRules as $sName => $aRules) { // Either no search rule is given or the search rule matches the found rule exactly or the search rule ends in “-” and the found rule starts with the search rule. if(!$mRule || $sName === $mRule || (strrpos($mRule, '-') === strlen($mRule) - strlen('-') && (strpos($sName, $mRule) === 0 || $sName === substr($mRule, 0, -1)))) { $aResult = array_merge($aResult, $aRules); } } return $aResult; } /** * Returns all rules matching the given pattern and returns them in an associative array with the rule’s name as keys. This method exists mainly for backwards-compatibility and is really only partially useful. * @param (string) $mRule pattern to search for. If null, returns all rules. if the pattern ends with a dash, all rules starting with the pattern are returned as well as one matching the pattern with the dash excluded. passing a Rule behaves like calling getRules($mRule->getRule()). * Note: This method loses some information: Calling this (with an argument of 'background-') on a declaration block like { background-color: green; background-color; rgba(0, 127, 0, 0.7); } will only yield an associative array containing the rgba-valued rule while @link{getRules()} would yield an indexed array containing both. */ public function getRulesAssoc($mRule = null) { $aResult = array(); foreach($this->getRules($mRule) as $oRule) { $aResult[$oRule->getRule()] = $oRule; } return $aResult; } /** * Remove a rule from this RuleSet. This accepts all the possible values that @link{getRules()} accepts. If given a Rule, it will only remove this particular rule (by identity). If given a name, it will remove all rules by that name. Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would remove all rules with the same name. To get the old behvaiour, use removeRule($oRule->getRule()). * @param (null|string|Rule) $mRule pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash, all rules starting with the pattern are removed as well as one matching the pattern with the dash excluded. Passing a Rule behaves matches by identity. */ public function removeRule($mRule) { if($mRule instanceof Rule) { $sRule = $mRule->getRule(); if(!isset($this->aRules[$sRule])) { return; } foreach($this->aRules[$sRule] as $iKey => $oRule) { if($oRule === $mRule) { unset($this->aRules[$sRule][$iKey]); } } } else { foreach($this->aRules as $sName => $aRules) { // Either no search rule is given or the search rule matches the found rule exactly or the search rule ends in “-” and the found rule starts with the search rule or equals it (without the trailing dash). if(!$mRule || $sName === $mRule || (strrpos($mRule, '-') === strlen($mRule) - strlen('-') && (strpos($sName, $mRule) === 0 || $sName === substr($mRule, 0, -1)))) { unset($this->aRules[$sName]); } } } } public function __toString() { $sResult = ''; foreach ($this->aRules as $aRules) { foreach($aRules as $oRule) { $sResult .= $oRule->__toString(); } } return $sResult; } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/Color.php0000644000175000007640000000222412232027021023027 0ustar slusarzslusarzaComponents; } public function setColor($aColor) { $this->setName(implode('', array_keys($aColor))); $this->aComponents = $aColor; } public function getColorDescription() { return $this->getName(); } public function __toString() { // Shorthand RGB color values // TODO: Include in output settings (once they’re done) if(implode('', array_keys($this->aComponents)) === 'rgb') { $sResult = sprintf( '%02x%02x%02x', $this->aComponents['r']->__toString(), $this->aComponents['g']->__toString(), $this->aComponents['b']->__toString() ); return '#'.(($sResult[0] == $sResult[1]) && ($sResult[2] == $sResult[3]) && ($sResult[4] == $sResult[5]) ? "$sResult[0]$sResult[2]$sResult[4]" : $sResult); } return parent::__toString(); } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/CSSFunction.php0000644000175000007640000000144512232027021024113 0ustar slusarzslusarzgetListSeparator(); $aArguments = $aArguments->getListComponents(); } $this->sName = $sName; parent::__construct($aArguments, $sSeparator); } public function getName() { return $this->sName; } public function setName($sName) { $this->sName = $sName; } public function getArguments() { return $this->aComponents; } public function __toString() { $aArguments = parent::__toString(); return "{$this->sName}({$aArguments})"; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/PrimitiveValue.php0000644000175000007640000000013012232027021024710 0ustar slusarzslusarzfSize = floatval($fSize); $this->sUnit = $sUnit; $this->bIsColorComponent = $bIsColorComponent; } public function setUnit($sUnit) { $this->sUnit = $sUnit; } public function getUnit() { return $this->sUnit; } public function setSize($fSize) { $this->fSize = floatval($fSize); } public function getSize() { return $this->fSize; } public function isColorComponent() { return $this->bIsColorComponent; } /** * Returns whether the number stored in this Size really represents a size (as in a length of something on screen). * @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object. */ public function isSize() { if (in_array($this->sUnit, explode('/', self::NON_SIZE_UNITS))) { return false; } return !$this->isColorComponent(); } public function isRelative() { if (in_array($this->sUnit, explode('/', self::RELATIVE_SIZE_UNITS))) { return true; } if ($this->sUnit === null && $this->fSize != 0) { return true; } return false; } public function __toString() { $l = localeconv(); return preg_replace(array('/' . preg_quote($l['decimal_point'], '/') . '/', '/^0\./'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/String.php0000644000175000007640000000101512232027021023214 0ustar slusarzslusarzsString = $sString; } public function setString($sString) { $this->sString = $sString; } public function getString() { return $this->sString; } public function __toString() { $sString = addslashes($this->sString); $sString = str_replace("\n", '\A', $sString); return '"' . $sString . '"'; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/URL.php0000644000175000007640000000064412232027021022417 0ustar slusarzslusarzoURL = $oURL; } public function setURL(String $oURL) { $this->oURL = $oURL; } public function getURL() { return $this->oURL; } public function __toString() { return "url({$this->oURL->__toString()})"; } }Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Value/Value.php0000644000175000007640000000015512232027021023026 0ustar slusarzslusarzaComponents = $aComponents; $this->sSeparator = $sSeparator; } public function addListComponent($mComponent) { $this->aComponents[] = $mComponent; } public function getListComponents() { return $this->aComponents; } public function setListComponents($aComponents) { $this->aComponents = $aComponents; } public function getListSeparator() { return $this->sSeparator; } public function setListSeparator($sSeparator) { $this->sSeparator = $sSeparator; } function __toString() { return implode($this->sSeparator, $this->aComponents); } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Parser.php0000644000175000007640000005333312232027021022140 0ustar slusarzslusarzsText = $sText; $this->iCurrentPosition = 0; if ($oParserSettings === null) { $oParserSettings = Settings::create(); } $this->oParserSettings = $oParserSettings; $this->blockRules = explode('/', AtRule::BLOCK_RULES); } public function setCharset($sCharset) { $this->sCharset = $sCharset; $this->iLength = $this->strlen($this->sText); } public function getCharset() { return $this->sCharset; } public function parse() { $this->setCharset($this->oParserSettings->sDefaultCharset); $this->sizeUnits = array(); foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS.'/'.Size::RELATIVE_SIZE_UNITS.'/'.Size::NON_SIZE_UNITS) as $val) { $val = $this->strtolower($val); $size = strlen($val); if (isset($this->sizeUnits[$size])) { $this->sizeUnits[$size][] = $val; } else { $this->sizeUnits[$size] = array($val); } } ksort($this->sizeUnits, SORT_NUMERIC); $oResult = new Document(); $this->parseDocument($oResult); return $oResult; } private function parseDocument(Document $oDocument) { $this->consumeWhiteSpace(); $this->parseList($oDocument, true); } private function parseList(CSSList $oList, $bIsRoot = false) { while (!$this->isEnd()) { if ($this->comes('@')) { $oList->append($this->parseAtRule()); } else if ($this->comes('}')) { $this->consume('}'); if ($bIsRoot) { throw new \Exception("Unopened {"); } else { return; } } else { $oList->append($this->parseSelector()); } $this->consumeWhiteSpace(); } if (!$bIsRoot) { throw new \Exception("Unexpected end of document"); } } private function parseAtRule() { $this->consume('@'); $sIdentifier = $this->parseIdentifier(); $this->consumeWhiteSpace(); if ($sIdentifier === 'import') { $oLocation = $this->parseURLValue(); $this->consumeWhiteSpace(); $sMediaQuery = null; if (!$this->comes(';')) { $sMediaQuery = $this->consumeUntil(';'); } $this->consume(';'); return new Import($oLocation, $sMediaQuery); } else if ($sIdentifier === 'charset') { $sCharset = $this->parseStringValue(); $this->consumeWhiteSpace(); $this->consume(';'); $this->setCharset($sCharset->getString()); return new Charset($sCharset); } else if ($this->identifierIs($sIdentifier, 'keyframes')) { $oResult = new KeyFrame(); $oResult->setVendorKeyFrame($sIdentifier); $oResult->setAnimationName(trim($this->consumeUntil('{', false, true))); $this->consumeWhiteSpace(); $this->parseList($oResult); return $oResult; } else if ($sIdentifier === 'namespace') { $sPrefix = null; $mUrl = $this->parsePrimitiveValue(); if (!$this->comes(';')) { $sPrefix = $mUrl; $mUrl = $this->parsePrimitiveValue(); } $this->consume(';'); if ($sPrefix !== null && !is_string($sPrefix)) { throw new \Exception('Wrong namespace prefix '.$sPrefix); } if (!($mUrl instanceof String || $mUrl instanceof URL)) { throw new \Exception('Wrong namespace url of invalid type '.$mUrl); } return new CSSNamespace($mUrl, $sPrefix); } else { //Unknown other at rule (font-face or such) $sArgs = $this->consumeUntil('{', false, true); $this->consumeWhiteSpace(); $bUseRuleSet = true; foreach($this->blockRules as $sBlockRuleName) { if($this->identifierIs($sIdentifier, $sBlockRuleName)) { $bUseRuleSet = false; break; } } if($bUseRuleSet) { $oAtRule = new AtRuleSet($sIdentifier, $sArgs); $this->parseRuleSet($oAtRule); } else { $oAtRule = new AtRuleBlockList($sIdentifier, $sArgs); $this->parseList($oAtRule); } return $oAtRule; } } private function parseIdentifier($bAllowFunctions = true, $bIgnoreCase = true) { $sResult = $this->parseCharacter(true); if ($sResult === null) { throw new UnexpectedTokenException($sResult, $this->peek(5), 'identifier'); } $sCharacter = null; while (($sCharacter = $this->parseCharacter(true)) !== null) { $sResult .= $sCharacter; } if ($bIgnoreCase) { $sResult = $this->strtolower($sResult); } if ($bAllowFunctions && $this->comes('(')) { $this->consume('('); $aArguments = $this->parseValue(array('=', ' ', ',')); $sResult = new CSSFunction($sResult, $aArguments); $this->consume(')'); } return $sResult; } private function parseStringValue() { $sBegin = $this->peek(); $sQuote = null; if ($sBegin === "'") { $sQuote = "'"; } else if ($sBegin === '"') { $sQuote = '"'; } if ($sQuote !== null) { $this->consume($sQuote); } $sResult = ""; $sContent = null; if ($sQuote === null) { //Unquoted strings end in whitespace or with braces, brackets, parentheses while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $this->peek())) { $sResult .= $this->parseCharacter(false); } } else { while (!$this->comes($sQuote)) { $sContent = $this->parseCharacter(false); if ($sContent === null) { throw new \Exception("Non-well-formed quoted string {$this->peek(3)}"); } $sResult .= $sContent; } $this->consume($sQuote); } return new String($sResult); } private function parseCharacter($bIsForIdentifier) { if ($this->peek() === '\\') { $this->consume('\\'); if ($this->comes('\n') || $this->comes('\r')) { return ''; } if (preg_match('/[0-9a-fA-F]/Su', $this->peek()) === 0) { return $this->consume(1); } $sUnicode = $this->consumeExpression('/^[0-9a-fA-F]{1,6}/u'); if ($this->strlen($sUnicode) < 6) { //Consume whitespace after incomplete unicode escape if (preg_match('/\\s/isSu', $this->peek())) { if ($this->comes('\r\n')) { $this->consume(2); } else { $this->consume(1); } } } $iUnicode = intval($sUnicode, 16); $sUtf32 = ""; for ($i = 0; $i < 4; ++$i) { $sUtf32 .= chr($iUnicode & 0xff); $iUnicode = $iUnicode >> 8; } return iconv('utf-32le', $this->sCharset, $sUtf32); } if ($bIsForIdentifier) { $peek = ord($this->peek()); // Ranges: a-z A-Z 0-9 - _ if (($peek >= 97 && $peek <= 122) || ($peek >= 65 && $peek <= 90) || ($peek >= 48 && $peek <= 57) || ($peek === 45) || ($peek === 95) || ($peek > 0xa1)) { return $this->consume(1); } } else { return $this->consume(1); } return null; } private function parseSelector() { $oResult = new DeclarationBlock(); $oResult->setSelector($this->consumeUntil('{', false, true)); $this->consumeWhiteSpace(); $this->parseRuleSet($oResult); return $oResult; } private function parseRuleSet($oRuleSet) { while ($this->comes(';')) { $this->consume(';'); $this->consumeWhiteSpace(); } while (!$this->comes('}')) { $oRule = null; if($this->oParserSettings->bLenientParsing) { try { $oRule = $this->parseRule(); } catch (UnexpectedTokenException $e) { try { $sConsume = $this->consumeUntil(array("\n", ";", '}'), true); // We need to “unfind” the matches to the end of the ruleSet as this will be matched later if($this->streql($this->substr($sConsume, $this->strlen($sConsume)-1, 1), '}')) { --$this->iCurrentPosition; $this->peekCache = null; } else { $this->consumeWhiteSpace(); while ($this->comes(';')) { $this->consume(';'); } } } catch (UnexpectedTokenException $e) { // We’ve reached the end of the document. Just close the RuleSet. return; } } } else { $oRule = $this->parseRule(); } if($oRule) { $oRuleSet->addRule($oRule); } $this->consumeWhiteSpace(); } $this->consume('}'); } private function parseRule() { $oRule = new Rule($this->parseIdentifier()); $this->consumeWhiteSpace(); $this->consume(':'); $oValue = $this->parseValue(self::listDelimiterForRule($oRule->getRule())); $oRule->setValue($oValue); if ($this->comes('!')) { $this->consume('!'); $this->consumeWhiteSpace(); $this->consume('important'); $oRule->setIsImportant(true); } while ($this->comes(';')) { $this->consume(';'); $this->consumeWhiteSpace(); } return $oRule; } private function parseValue($aListDelimiters) { $aStack = array(); $this->consumeWhiteSpace(); //Build a list of delimiters and parsed values while (!($this->comes('}') || $this->comes(';') || $this->comes('!') || $this->comes(')'))) { if (count($aStack) > 0) { $bFoundDelimiter = false; foreach ($aListDelimiters as $sDelimiter) { if ($this->comes($sDelimiter)) { array_push($aStack, $this->consume($sDelimiter)); $this->consumeWhiteSpace(); $bFoundDelimiter = true; break; } } if (!$bFoundDelimiter) { //Whitespace was the list delimiter array_push($aStack, ' '); } } array_push($aStack, $this->parsePrimitiveValue()); $this->consumeWhiteSpace(); } //Convert the list to list objects foreach ($aListDelimiters as $sDelimiter) { if (count($aStack) === 1) { return $aStack[0]; } $iStartPosition = null; while (($iStartPosition = array_search($sDelimiter, $aStack, true)) !== false) { $iLength = 2; //Number of elements to be joined for ($i = $iStartPosition + 2; $i < count($aStack); $i+=2, ++$iLength) { if ($sDelimiter !== $aStack[$i]) { break; } } $oList = new RuleValueList($sDelimiter); for ($i = $iStartPosition - 1; $i - $iStartPosition + 1 < $iLength * 2; $i+=2) { $oList->addListComponent($aStack[$i]); } array_splice($aStack, $iStartPosition - 1, $iLength * 2 - 1, array($oList)); } } return $aStack[0]; } private static function listDelimiterForRule($sRule) { if (preg_match('/^font($|-)/', $sRule)) { return array(',', '/', ' '); } return array(',', ' ', '/'); } private function parsePrimitiveValue() { $oValue = null; $this->consumeWhiteSpace(); if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) { $oValue = $this->parseNumericValue(); } else if ($this->comes('#') || $this->comes('rgb', true) || $this->comes('hsl', true)) { $oValue = $this->parseColorValue(); } else if ($this->comes('url', true)) { $oValue = $this->parseURLValue(); } else if ($this->comes("'") || $this->comes('"')) { $oValue = $this->parseStringValue(); } else { $oValue = $this->parseIdentifier(true, false); } $this->consumeWhiteSpace(); return $oValue; } private function parseNumericValue($bForColor = false) { $sSize = ''; if ($this->comes('-')) { $sSize .= $this->consume('-'); } while (is_numeric($this->peek()) || $this->comes('.')) { if ($this->comes('.')) { $sSize .= $this->consume('.'); } else { $sSize .= $this->consume(1); } } $sUnit = null; foreach ($this->sizeUnits as $len => $val) { $peek = $this->peek($len); if (array_search($this->strtolower($peek), $val) !== false) { $sUnit = $peek; $this->consume($len); break; } } return new Size(floatval($sSize), $sUnit, $bForColor); } private function parseColorValue() { $aColor = array(); if ($this->comes('#')) { $this->consume('#'); $sValue = $this->parseIdentifier(false); if ($this->strlen($sValue) === 3) { $sValue = $sValue[0] . $sValue[0] . $sValue[1] . $sValue[1] . $sValue[2] . $sValue[2]; } $aColor = array('r' => new Size(intval($sValue[0] . $sValue[1], 16), null, true), 'g' => new Size(intval($sValue[2] . $sValue[3], 16), null, true), 'b' => new Size(intval($sValue[4] . $sValue[5], 16), null, true)); } else { $sColorMode = $this->parseIdentifier(false); $this->consumeWhiteSpace(); $this->consume('('); $iLength = $this->strlen($sColorMode); for ($i = 0; $i < $iLength; ++$i) { $this->consumeWhiteSpace(); $aColor[$sColorMode[$i]] = $this->parseNumericValue(true); $this->consumeWhiteSpace(); if ($i < ($iLength - 1)) { $this->consume(','); } } $this->consume(')'); } return new Color($aColor); } private function parseURLValue() { $bUseUrl = $this->comes('url', true); if ($bUseUrl) { $this->consume('url'); $this->consumeWhiteSpace(); $this->consume('('); } $this->consumeWhiteSpace(); $oResult = new URL($this->parseStringValue()); if ($bUseUrl) { $this->consumeWhiteSpace(); $this->consume(')'); } return $oResult; } /** * Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed. We need to check for these versions too. */ private function identifierIs($sIdentifier, $sMatch) { return (strcasecmp($sIdentifier, $sMatch) === 0) ?: preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1; } private function comes($sString, $alpha = false) { $sPeek = $this->peek($alpha ? $this->strlen($sString) : strlen($sString)); return ($sPeek == '') ? false : $this->streql($sPeek, $sString, $alpha); } private function peek($iLength = 1, $iOffset = 0) { if (($peek = (!$iOffset && ($iLength === 1))) && !is_null($this->peekCache)) { return $this->peekCache; } $iOffset += $this->iCurrentPosition; if ($iOffset >= $this->iLength) { return ''; } $iLength = min($iLength, $this->iLength-$iOffset); $out = $this->substr($this->sText, $iOffset, $iLength); if ($peek) { $this->peekCache = $out; } return $out; } private function consume($mValue = 1) { if (is_string($mValue)) { $iLength = $this->strlen($mValue); if (!$this->streql($this->substr($this->sText, $this->iCurrentPosition, $iLength), $mValue)) { throw new UnexpectedTokenException($mValue, $this->peek(max($iLength, 5))); } $this->iCurrentPosition += $this->strlen($mValue); $this->peekCache = null; return $mValue; } else { if ($this->iCurrentPosition + $mValue > $this->iLength) { throw new UnexpectedTokenException($mValue, $this->peek(5), 'count'); } $sResult = $this->substr($this->sText, $this->iCurrentPosition, $mValue); $this->iCurrentPosition += $mValue; $this->peekCache = null; return $sResult; } } private function consumeExpression($mExpression) { $aMatches; if (preg_match($mExpression, $this->inputLeft(), $aMatches, PREG_OFFSET_CAPTURE) === 1) { return $this->consume($aMatches[0][0]); } throw new UnexpectedTokenException($mExpression, $this->peek(5), 'expression'); } private function consumeWhiteSpace() { do { while (preg_match('/\\s/isSu', $this->peek()) === 1) { $this->consume(1); } } while ($this->consumeComment()); } private function consumeComment() { if ($this->comes('/*')) { $this->consume(2); while ($this->consumeUntil('*', false, true)) { if ($this->comes('/')) { $this->consume(1); return true; } } } return false; } private function isEnd() { return $this->iCurrentPosition >= $this->iLength; } private function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false) { $aEnd = is_array($aEnd) ? $aEnd : array($aEnd); $out = ''; $start = $this->iCurrentPosition; while (($char = $this->consume(1)) !== '') { if (in_array($char, $aEnd)) { if ($bIncludeEnd) { $out .= $char; } elseif (!$consumeEnd) { $this->iCurrentPosition -= $this->strlen($char); } return $out; } $out .= $char; } $this->iCurrentPosition = $start; throw new UnexpectedTokenException('One of ("'.implode('","', $aEnd).'")', $this->peek(5), 'search'); } private function inputLeft() { return $this->substr($this->sText, $this->iCurrentPosition, -1); } private function substr($sString, $iStart, $iLength) { if ($this->oParserSettings->bMultibyteSupport) { return mb_substr($sString, $iStart, $iLength, $this->sCharset); } else { return substr($sString, $iStart, $iLength); } } private function strlen($sString) { if ($this->oParserSettings->bMultibyteSupport) { return mb_strlen($sString, $this->sCharset); } else { return strlen($sString); } } private function streql($sString1, $sString2, $bCaseInsensitive = true) { if($bCaseInsensitive) { return $this->strtolower($sString1) === $this->strtolower($sString2); } else { return $sString1 === $sString2; } } private function strtolower($sString) { if ($this->oParserSettings->bMultibyteSupport) { return mb_strtolower($sString, $this->sCharset); } else { return strtolower($sString); } } private function strpos($sString, $sNeedle, $iOffset) { if ($this->oParserSettings->bMultibyteSupport) { return mb_strpos($sString, $sNeedle, $iOffset, $this->sCharset); } else { return strpos($sString, $sNeedle, $iOffset); } } } Horde_Css_Parser-1.0.3/lib/Sabberworm/CSS/Settings.php0000644000175000007640000000250112232027021022473 0ustar slusarzslusarzbMultibyteSupport = $bMultibyteSupport; return $this; } public function withDefaultCharset($sDefaultCharset) { $this->sDefaultCharset = $sDefaultCharset; return $this; } public function withLenientParsing($bLenientParsing = true) { $this->bLenientParsing = $bLenientParsing; return $this; } public function beStrict() { return $this->withLenientParsing(false); } }