Move pquery to 3rd party libs
The project is abandoned so the easiest way for patching it is adding it to the lib-3rd-party. [MAILPOE-3980]
This commit is contained in:
committed by
Veljko V
parent
a96fc01c56
commit
539f518f64
@@ -8,8 +8,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.1",
|
"php": ">=7.1",
|
||||||
"mtdowling/cron-expression": "^1.1",
|
"mtdowling/cron-expression": "^1.1",
|
||||||
"soundasleep/html2text": "dev-master",
|
"soundasleep/html2text": "dev-master"
|
||||||
"tburry/pquery": "^1.1.1"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-gd": "*",
|
"ext-gd": "*",
|
||||||
|
54
composer.lock
generated
54
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "44e6370ee3bd0f45a6ba712d32f54ef9",
|
"content-hash": "a736768274d32a1dbad34e9a59f8565d",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "mtdowling/cron-expression",
|
"name": "mtdowling/cron-expression",
|
||||||
@@ -103,58 +103,6 @@
|
|||||||
"source": "https://github.com/mailpoet/html2text/tree/master"
|
"source": "https://github.com/mailpoet/html2text/tree/master"
|
||||||
},
|
},
|
||||||
"time": "2019-04-24T12:03:33+00:00"
|
"time": "2019-04-24T12:03:33+00:00"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "tburry/pquery",
|
|
||||||
"version": "v1.1.1",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/tburry/pquery.git",
|
|
||||||
"reference": "872339ffd38d261c4417ea1855428b1b4ff9abf1"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/tburry/pquery/zipball/872339ffd38d261c4417ea1855428b1b4ff9abf1",
|
|
||||||
"reference": "872339ffd38d261c4417ea1855428b1b4ff9abf1",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"htmlawed/htmlawed": "dev-master"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"classmap": [
|
|
||||||
"IQuery.php",
|
|
||||||
"gan_formatter.php",
|
|
||||||
"gan_node_html.php",
|
|
||||||
"gan_parser_html.php",
|
|
||||||
"gan_selector_html.php",
|
|
||||||
"gan_tokenizer.php",
|
|
||||||
"gan_xml2array.php",
|
|
||||||
"pQuery.php"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"LGPL-2.1"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Todd Burry",
|
|
||||||
"email": "todd@vanillaforums.com",
|
|
||||||
"role": "developer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "A jQuery like html dom parser written in php.",
|
|
||||||
"keywords": [
|
|
||||||
"dom",
|
|
||||||
"ganon",
|
|
||||||
"php"
|
|
||||||
],
|
|
||||||
"time": "2016-01-14T20:55:00+00:00"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
151
lib-3rd-party/pquery/IQuery.php
vendored
Normal file
151
lib-3rd-party/pquery/IQuery.php
vendored
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
interface IQuery extends \Countable {
|
||||||
|
/// Methods ///
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the specified class(es) to each of the set of matched elements.
|
||||||
|
* @param string $classname The name of the class to add. You can add multiple classes by separating them with spaces.
|
||||||
|
* @return IQuery
|
||||||
|
*/
|
||||||
|
function addClass($classname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content, specified by the parameter, after each element in the set of matched elements.
|
||||||
|
* @param string $content The content to add.
|
||||||
|
* @return IQuery
|
||||||
|
*/
|
||||||
|
function after($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content, specified by the parameter, to the end of each element in the set of matched elements.
|
||||||
|
* @param string $content The content to append.
|
||||||
|
* @return IQuery
|
||||||
|
*/
|
||||||
|
function append($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of an attribute for the first element in the set of matched elements or set one
|
||||||
|
* or more attributes for every matched element.
|
||||||
|
* @param string $name The name of the attribute.
|
||||||
|
* @param null|string $value The value to set or null to get the current attribute value.
|
||||||
|
* @return string|IQuery
|
||||||
|
*/
|
||||||
|
function attr($name, $value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content, specified by the parameter, before each element in the set of matched elements.
|
||||||
|
* @param string $content The content to add.
|
||||||
|
* @return IQuery
|
||||||
|
*/
|
||||||
|
function before($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all child nodes of the set of matched elements from the DOM.
|
||||||
|
* @return IQuery;
|
||||||
|
*/
|
||||||
|
function clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a style property for the first element in the set of matched elements or
|
||||||
|
* set one or more CSS properties for every matched element.
|
||||||
|
*/
|
||||||
|
// function css($name, $value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether any of the matched elements are assigned the given class.
|
||||||
|
* @param string $classname The name of the class to check.
|
||||||
|
*/
|
||||||
|
function hasClass($classname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HTML contents of the first element in the set of matched elements
|
||||||
|
* or set the HTML contents of every matched element.
|
||||||
|
* @param string|null $value The value to set.
|
||||||
|
*/
|
||||||
|
function html($value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
|
||||||
|
* @param string $content The content to add.
|
||||||
|
*/
|
||||||
|
function prepend($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property for the first element in the set of matched elements
|
||||||
|
* or set one or more properties for every matched element.
|
||||||
|
* @param string $name The name of the property.
|
||||||
|
* The currently supported properties are `tagname`, `selected`, and `checked`.
|
||||||
|
* @param null|string $value The value to set or null to get the current property value.
|
||||||
|
*/
|
||||||
|
function prop($name, $value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the set of matched elements from the DOM.
|
||||||
|
* @param null|string $selector A css query to filter the set of removed nodes.
|
||||||
|
*/
|
||||||
|
function remove($selector = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an attribute from each element in the set of matched elements.
|
||||||
|
* @param string $name The name of the attribute to remove.
|
||||||
|
*/
|
||||||
|
function removeAttr($name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
|
||||||
|
* @param string $classname The name of the class to remove.
|
||||||
|
*/
|
||||||
|
function removeClass($classname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.
|
||||||
|
* @param string $content The content that will replace the nodes.
|
||||||
|
*/
|
||||||
|
function replaceWith($content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the element.
|
||||||
|
* @param null|string $tagName A new tag name or null to return the current tag name.
|
||||||
|
*/
|
||||||
|
function tagName($value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the combined text contents of each element in the set of matched elements, including their descendants, or set the text contents of the matched elements.
|
||||||
|
* @param null|string $value A string to set the text or null to return the current text.
|
||||||
|
*/
|
||||||
|
function text($value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or remove one or more classes from each element in the set of matched elements,
|
||||||
|
* depending on either the class’s presence or the value of the switch argument.
|
||||||
|
* @param string $classname
|
||||||
|
* @param bool|null
|
||||||
|
*/
|
||||||
|
function toggleClass($classname, $switch = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place.
|
||||||
|
*/
|
||||||
|
function unwrap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current value of the first element in the set of matched elements or set the value of every matched element.
|
||||||
|
* @param string|null $value The new value of the element or null to return the current value.
|
||||||
|
*/
|
||||||
|
function val($value = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap an HTML structure around each element in the set of matched elements.
|
||||||
|
* @param string A tag name or html string specifying the structure to wrap around the matched elements.
|
||||||
|
*/
|
||||||
|
function wrap($wrapping_element);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap an HTML structure around the content of each element in the set of matched elements.
|
||||||
|
* @param string A tag name or html string specifying the structure to wrap around the content of the matched elements.
|
||||||
|
*/
|
||||||
|
function wrapInner($wrapping_element);
|
||||||
|
}
|
502
lib-3rd-party/pquery/LICENSE
vendored
Normal file
502
lib-3rd-party/pquery/LICENSE
vendored
Normal file
@@ -0,0 +1,502 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Libraries
|
||||||
|
|
||||||
|
If you develop a new library, and you want it to be of the greatest
|
||||||
|
possible use to the public, we recommend making it free software that
|
||||||
|
everyone can redistribute and change. You can do so by permitting
|
||||||
|
redistribution under these terms (or, alternatively, under the terms of the
|
||||||
|
ordinary General Public License).
|
||||||
|
|
||||||
|
To apply these terms, attach the following notices to the library. It is
|
||||||
|
safest to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the library's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||||
|
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||||
|
|
||||||
|
<signature of Ty Coon>, 1 April 1990
|
||||||
|
Ty Coon, President of Vice
|
||||||
|
|
||||||
|
That's all there is to it!
|
381
lib-3rd-party/pquery/gan_formatter.php
vendored
Normal file
381
lib-3rd-party/pquery/gan_formatter.php
vendored
Normal file
@@ -0,0 +1,381 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indents text
|
||||||
|
* @param string $text
|
||||||
|
* @param int $indent
|
||||||
|
* @param string $indent_string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function indent_text($text, $indent, $indent_string = ' ') {
|
||||||
|
if ($indent && $indent_string) {
|
||||||
|
return str_replace("\n", "\n".str_repeat($indent_string, $indent), $text);
|
||||||
|
} else {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used to format/minify HTML nodes
|
||||||
|
*
|
||||||
|
* Used like:
|
||||||
|
* <code>
|
||||||
|
* <?php
|
||||||
|
* $formatter = new HtmlFormatter();
|
||||||
|
* $formatter->format($root);
|
||||||
|
* ?>
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
class HtmlFormatter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which elements start on a new line and which function as block
|
||||||
|
* @var array('element' => array('new_line' => true, 'as_block' => true, 'format_inside' => true))
|
||||||
|
*/
|
||||||
|
var $block_elements = array(
|
||||||
|
'p' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h1' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h2' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h3' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h4' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h5' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'h6' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
|
||||||
|
'form' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'fieldset' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'legend' => array('new_line' => true, 'as_block' => false, 'format_inside' => true),
|
||||||
|
'dl' => array('new_line' => true, 'as_block' => false, 'format_inside' => true),
|
||||||
|
'dt' => array('new_line' => true, 'as_block' => false, 'format_inside' => true),
|
||||||
|
'dd' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'ol' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'ul' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'li' => array('new_line' => true, 'as_block' => false, 'format_inside' => true),
|
||||||
|
|
||||||
|
'table' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'tr' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
|
||||||
|
'dir' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'menu' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'address' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'blockquote' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'center' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'del' => array('new_line' => true, 'as_block' => false, 'format_inside' => true),
|
||||||
|
//'div' => array('new_line' => false, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'hr' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'ins' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'noscript' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'pre' => array('new_line' => true, 'as_block' => true, 'format_inside' => false),
|
||||||
|
'script' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'style' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
|
||||||
|
'html' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'head' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'body' => array('new_line' => true, 'as_block' => true, 'format_inside' => true),
|
||||||
|
'title' => array('new_line' => true, 'as_block' => false, 'format_inside' => false)
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which characters are considered whitespace
|
||||||
|
* @var array("\t" => true) True to recognize as new line
|
||||||
|
*/
|
||||||
|
var $whitespace = array(
|
||||||
|
' ' => false,
|
||||||
|
"\t" => false,
|
||||||
|
"\x0B" => false,
|
||||||
|
"\0" => false,
|
||||||
|
"\n" => true,
|
||||||
|
"\r" => true
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String that is used to generate correct indenting
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $indent_string = ' ';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String that is used to break lines
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $linebreak_string = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Other formatting options
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $options = array(
|
||||||
|
'img_alt' => '',
|
||||||
|
'self_close_str' => null,
|
||||||
|
'attribute_shorttag' => false,
|
||||||
|
'sort_attributes' => false,
|
||||||
|
'attributes_case' => CASE_LOWER,
|
||||||
|
'minify_script' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Errors found during formatting
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $errors = array();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
* @param array $options {@link $options}
|
||||||
|
*/
|
||||||
|
function __construct($options = array()) {
|
||||||
|
$this->options = array_merge($this->options, $options);
|
||||||
|
|
||||||
|
if (isset($options['indent_str']))
|
||||||
|
$this->indent_string = $options['indent_str'];
|
||||||
|
|
||||||
|
if (isset($options['linebreak_str']))
|
||||||
|
$this->linebreak_string = $options['linebreak_str'];
|
||||||
|
}
|
||||||
|
|
||||||
|
#php4 PHP4 class constructor compatibility
|
||||||
|
#function HtmlFormatter($options = array()) {return $this->__construct($options);}
|
||||||
|
#php4e
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class magic invoke method, performs {@link format()}
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __invoke(&$node) {
|
||||||
|
return $this->format($node);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minifies HTML / removes unneeded whitespace
|
||||||
|
* @param DomNode $root
|
||||||
|
* @param bool $strip_comments
|
||||||
|
* @param bool $recursive
|
||||||
|
*/
|
||||||
|
static function minify_html(&$root, $strip_comments = true, $recursive = true) {
|
||||||
|
if ($strip_comments) {
|
||||||
|
foreach($root->select(':comment', false, $recursive, true) as $c) {
|
||||||
|
$prev = $c->getSibling(-1);
|
||||||
|
$next = $c->getSibling(1);
|
||||||
|
$c->delete();
|
||||||
|
if ($prev && $next && ($prev->isText()) && ($next->isText())) {
|
||||||
|
$prev->text .= $next->text;
|
||||||
|
$next->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($root->select('(!pre + !xmp + !style + !script + !"?php" + !"~text~" + !"~comment~"):not-empty > "~text~"', false, $recursive, true) as $c) {
|
||||||
|
$c->text = preg_replace('`\s+`', ' ', $c->text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minifies javascript using JSMin+
|
||||||
|
* @param DomNode $root
|
||||||
|
* @param string $indent_string
|
||||||
|
* @param bool $wrap_comment Wrap javascript in HTML comments (<!-- ~text~ //-->)
|
||||||
|
* @param bool $recursive
|
||||||
|
* @return bool|array Array of errors on failure, true on succes
|
||||||
|
*/
|
||||||
|
static function minify_javascript(&$root, $indent_string = ' ', $wrap_comment = true, $recursive = true) {
|
||||||
|
#php4 JSMin+ doesn't support PHP4
|
||||||
|
#return true;
|
||||||
|
#php4e
|
||||||
|
#php5
|
||||||
|
include_once('third_party/jsminplus.php');
|
||||||
|
|
||||||
|
$errors = array();
|
||||||
|
foreach($root->select('script:not-empty > "~text~"', false, $recursive, true) as $c) {
|
||||||
|
try {
|
||||||
|
$text = $c->text;
|
||||||
|
while ($text) {
|
||||||
|
$text = trim($text);
|
||||||
|
//Remove comment/CDATA tags at begin and end
|
||||||
|
if (substr($text, 0, 4) === '<!--') {
|
||||||
|
$text = substr($text, 5);
|
||||||
|
continue;
|
||||||
|
} elseif (strtolower(substr($text, 0, 9)) === '<![cdata[') {
|
||||||
|
$text = substr($text, 10);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($end = substr($text, -3)) && (($end === '-->') || ($end === ']]>'))) {
|
||||||
|
$text = substr($text, 0, -3);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim($text)) {
|
||||||
|
$text = \JSMinPlus::minify($text);
|
||||||
|
if ($wrap_comment) {
|
||||||
|
$text = "<!--\n".$text."\n//-->";
|
||||||
|
}
|
||||||
|
if ($indent_string && ($wrap_comment || (strpos($text, "\n") !== false))) {
|
||||||
|
$text = indent_text("\n".$text, $c->indent(), $indent_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$c->text = $text;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$errors[] = array($e, $c->parent->dumpLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (($errors) ? $errors : true);
|
||||||
|
#php5e
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats HTML
|
||||||
|
* @param DomNode $root
|
||||||
|
* @param bool $recursive
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function format_html(&$root, $recursive = null) {
|
||||||
|
if ($recursive === null) {
|
||||||
|
$recursive = true;
|
||||||
|
self::minify_html($root);
|
||||||
|
} elseif (is_int($recursive)) {
|
||||||
|
$recursive = (($recursive > 1) ? $recursive - 1 : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$root_tag = strtolower($root->tag);
|
||||||
|
$in_block = isset($this->block_elements[$root_tag]) && $this->block_elements[$root_tag]['as_block'];
|
||||||
|
$child_count = count($root->children);
|
||||||
|
|
||||||
|
if (isset($this->options['attributes_case']) && $this->options['attributes_case']) {
|
||||||
|
$root->attributes = array_change_key_case($root->attributes, $this->options['attributes_case']);
|
||||||
|
$root->attributes_ns = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->options['sort_attributes']) && $this->options['sort_attributes']) {
|
||||||
|
if ($this->options['sort_attributes'] === 'reverse') {
|
||||||
|
krsort($root->attributes);
|
||||||
|
} else {
|
||||||
|
ksort($root->attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($root->select(':element', true, false, true)) {
|
||||||
|
$root->setTag(strtolower($root->tag), true);
|
||||||
|
if (($this->options['img_alt'] !== null) && ($root_tag === 'img') && (!isset($root->alt))) {
|
||||||
|
$root->setAttribute('alt', $this->options['img_alt']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->options['self_close_str'] !== null) {
|
||||||
|
$root->self_close_str = $this->options['self_close_str'];
|
||||||
|
}
|
||||||
|
if ($this->options['attribute_shorttag'] !== null) {
|
||||||
|
$root->attribute_shorttag = $this->options['attribute_shorttag'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = null;
|
||||||
|
$n_tag = '';
|
||||||
|
// $prev_tag = '';
|
||||||
|
$as_block = false;
|
||||||
|
$prev_asblock = false;
|
||||||
|
for($i = 0; $i < $child_count; $i++) {
|
||||||
|
$n =& $root->children[$i];
|
||||||
|
$indent = $n->indent();
|
||||||
|
|
||||||
|
if (!$n->isText()) {
|
||||||
|
$n_tag = strtolower($n->tag);
|
||||||
|
$new_line = isset($this->block_elements[$n_tag]) && $this->block_elements[$n_tag]['new_line'];
|
||||||
|
$as_block = isset($this->block_elements[$n_tag]) && $this->block_elements[$n_tag]['as_block'];
|
||||||
|
$format_inside = ((!isset($this->block_elements[$n_tag])) || $this->block_elements[$n_tag]['format_inside']);
|
||||||
|
|
||||||
|
if ($prev && ($prev->isText()) && $prev->text && ($char = $prev->text[strlen($prev->text) - 1]) && isset($this->whitespace[$char])) {
|
||||||
|
if ($this->whitespace[$char]) {
|
||||||
|
$prev->text .= str_repeat($this->indent_string, $indent);
|
||||||
|
} else {
|
||||||
|
$prev->text = substr_replace($prev->text, $this->linebreak_string.str_repeat($this->indent_string, $indent), -1, 1);
|
||||||
|
}
|
||||||
|
} elseif (($new_line || $prev_asblock || ($in_block && ($i === 0)))){
|
||||||
|
if ($prev && ($prev->isText())) {
|
||||||
|
$prev->text .= $this->linebreak_string.str_repeat($this->indent_string, $indent);
|
||||||
|
} else {
|
||||||
|
$root->addText($this->linebreak_string.str_repeat($this->indent_string, $indent), $i);
|
||||||
|
++$child_count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($format_inside && count($n->children)) {
|
||||||
|
//$last = end($n->children);
|
||||||
|
$last = $n->children[count($n->children) - 1];
|
||||||
|
$last_tag = ($last) ? strtolower($last->tag) : '';
|
||||||
|
$last_asblock = ($last_tag && isset($this->block_elements[$last_tag]) && $this->block_elements[$last_tag]['as_block']);
|
||||||
|
|
||||||
|
if (($n->childCount(true) > 0) || (trim($n->getPlainText()))) {
|
||||||
|
if ($last && ($last->isText()) && $last->text && ($char = $last->text[strlen($last->text) - 1]) && isset($this->whitespace[$char])) {
|
||||||
|
if ($as_block || ($last->index() > 0) || isset($this->whitespace[$last->text[0]])) {
|
||||||
|
if ($this->whitespace[$char]) {
|
||||||
|
$last->text .= str_repeat($this->indent_string, $indent);
|
||||||
|
} else {
|
||||||
|
$last->text = substr_replace($last->text, $this->linebreak_string.str_repeat($this->indent_string, $indent), -1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (($as_block || $last_asblock || ($in_block && ($i === 0))) && $last) {
|
||||||
|
if ($last && ($last->isText())) {
|
||||||
|
$last->text .= $this->linebreak_string.str_repeat($this->indent_string, $indent);
|
||||||
|
} else {
|
||||||
|
$n->addText($this->linebreak_string.str_repeat($this->indent_string, $indent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (!trim($n->getInnerText())) {
|
||||||
|
$n->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($recursive) {
|
||||||
|
$this->format_html($n, $recursive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif (trim($n->text) && ((($i - 1 < $child_count) && ($char = $n->text[0]) && isset($this->whitespace[$char])) || ($in_block && ($i === 0)))) {
|
||||||
|
if (isset($this->whitespace[$char])) {
|
||||||
|
if ($this->whitespace[$char]) {
|
||||||
|
$n->text = str_repeat($this->indent_string, $indent).$n->text;
|
||||||
|
} else {
|
||||||
|
$n->text = substr_replace($n->text, $this->linebreak_string.str_repeat($this->indent_string, $indent), 0, 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$n->text = $this->linebreak_string.str_repeat($this->indent_string, $indent).$n->text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$prev = $n;
|
||||||
|
// $prev_tag = $n_tag;
|
||||||
|
$prev_asblock = $as_block;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats HTML/Javascript
|
||||||
|
* @param DomNode $root
|
||||||
|
* @see format_html()
|
||||||
|
*/
|
||||||
|
function format(&$node) {
|
||||||
|
$this->errors = array();
|
||||||
|
if ($this->options['minify_script']) {
|
||||||
|
$a = self::minify_javascript($node, $this->indent_string, true, true);
|
||||||
|
if (is_array($a)) {
|
||||||
|
foreach($a as $error) {
|
||||||
|
$this->errors[] = $error[0]->getMessage().' >>> '.$error[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->format_html($node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
2855
lib-3rd-party/pquery/gan_node_html.php
vendored
Normal file
2855
lib-3rd-party/pquery/gan_node_html.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
839
lib-3rd-party/pquery/gan_parser_html.php
vendored
Normal file
839
lib-3rd-party/pquery/gan_parser_html.php
vendored
Normal file
@@ -0,0 +1,839 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a HTML document
|
||||||
|
*
|
||||||
|
* Functionality can be extended by overriding functions or adjusting the tag map.
|
||||||
|
* Document may contain small errors, the parser will try to recover and resume parsing.
|
||||||
|
*/
|
||||||
|
class HtmlParserBase extends TokenizerBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag open token, used for "<"
|
||||||
|
*/
|
||||||
|
const TOK_TAG_OPEN = 100;
|
||||||
|
/**
|
||||||
|
* Tag close token, used for ">"
|
||||||
|
*/
|
||||||
|
const TOK_TAG_CLOSE = 101;
|
||||||
|
/**
|
||||||
|
* Forward slash token, used for "/"
|
||||||
|
*/
|
||||||
|
const TOK_SLASH_FORWARD = 103;
|
||||||
|
/**
|
||||||
|
* Backslash token, used for "\"
|
||||||
|
*/
|
||||||
|
const TOK_SLASH_BACKWARD = 104;
|
||||||
|
/**
|
||||||
|
* String token, used for attribute values (" and ')
|
||||||
|
*/
|
||||||
|
const TOK_STRING = 104;
|
||||||
|
/**
|
||||||
|
* Equals token, used for "="
|
||||||
|
*/
|
||||||
|
const TOK_EQUALS = 105;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets HTML identifiers, tags/attributes are considered identifiers
|
||||||
|
* @see TokenizerBase::$identifiers
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $identifiers = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:-_!?%';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status of the parser (tagname, closing tag, etc)
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $status = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map characters to match their tokens
|
||||||
|
* @see TokenizerBase::$custom_char_map
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $custom_char_map = array(
|
||||||
|
'<' => self::TOK_TAG_OPEN,
|
||||||
|
'>' => self::TOK_TAG_CLOSE,
|
||||||
|
"'" => 'parse_string',
|
||||||
|
'"' => 'parse_string',
|
||||||
|
'/' => self::TOK_SLASH_FORWARD,
|
||||||
|
'\\' => self::TOK_SLASH_BACKWARD,
|
||||||
|
'=' => self::TOK_EQUALS
|
||||||
|
);
|
||||||
|
|
||||||
|
function __construct($doc = '', $pos = 0) {
|
||||||
|
parent::__construct($doc, $pos);
|
||||||
|
$this->parse_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
#php4 PHP4 class constructor compatibility
|
||||||
|
#function HtmlParserBase($doc = '', $pos = 0) {return $this->__construct($doc, $pos);}
|
||||||
|
#php4e
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback functions for certain tags
|
||||||
|
@var array (TAG_NAME => FUNCTION_NAME)
|
||||||
|
@internal Function should be a method in the class
|
||||||
|
@internal Tagname should be lowercase and is everything after <, e.g. "?php" or "!doctype"
|
||||||
|
@access private
|
||||||
|
*/
|
||||||
|
var $tag_map = array(
|
||||||
|
'!doctype' => 'parse_doctype',
|
||||||
|
'?' => 'parse_php',
|
||||||
|
'?php' => 'parse_php',
|
||||||
|
'%' => 'parse_asp',
|
||||||
|
'style' => 'parse_style',
|
||||||
|
'script' => 'parse_script'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a HTML string (attributes)
|
||||||
|
* @internal Gets called with ' and "
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_string() {
|
||||||
|
if ($this->next_pos($this->doc[$this->pos], false) !== self::TOK_UNKNOWN) {
|
||||||
|
--$this->pos;
|
||||||
|
}
|
||||||
|
return self::TOK_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse text between tags
|
||||||
|
* @internal Gets called between tags, uses {@link $status}[last_pos]
|
||||||
|
* @internal Stores text in {@link $status}[text]
|
||||||
|
*/
|
||||||
|
function parse_text() {
|
||||||
|
$len = $this->pos - 1 - $this->status['last_pos'];
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $this->status['last_pos'] + 1, $len) : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse comment tags
|
||||||
|
* @internal Gets called with HTML comments ("<!--")
|
||||||
|
* @internal Stores text in {@link $status}[comment]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_comment() {
|
||||||
|
$this->pos += 3;
|
||||||
|
if ($this->next_pos('-->', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->status['comment'] = $this->getTokenString(1, -1);
|
||||||
|
--$this->pos;
|
||||||
|
} else {
|
||||||
|
$this->status['comment'] = $this->getTokenString(1, -1);
|
||||||
|
$this->pos += 2;
|
||||||
|
}
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse doctype tag
|
||||||
|
* @internal Gets called with doctype ("<!doctype")
|
||||||
|
* @internal Stores text in {@link $status}[dtd]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_doctype() {
|
||||||
|
$start = $this->pos;
|
||||||
|
if ($this->next_search('[>', false) === self::TOK_UNKNOWN) {
|
||||||
|
if ($this->doc[$this->pos] === '[') {
|
||||||
|
if (($this->next_pos(']', false) !== self::TOK_UNKNOWN) || ($this->next_pos('>', false) !== self::TOK_UNKNOWN)) {
|
||||||
|
$this->addError('Invalid doctype');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->token_start = $start;
|
||||||
|
$this->status['dtd'] = $this->getTokenString(2, -1);
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->addError('Invalid doctype');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse cdata tag
|
||||||
|
* @internal Gets called with cdata ("<![cdata")
|
||||||
|
* @internal Stores text in {@link $status}[cdata]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_cdata() {
|
||||||
|
if ($this->next_pos(']]>', false) === self::TOK_UNKNOWN) {
|
||||||
|
$this->status['cdata'] = $this->getTokenString(9, -1);
|
||||||
|
$this->status['last_pos'] = $this->pos + 2;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->addError('Invalid cdata tag');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse php tags
|
||||||
|
* @internal Gets called with php tags ("<?php")
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_php() {
|
||||||
|
$start = $this->pos;
|
||||||
|
if ($this->next_pos('?>', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->pos -= 2; //End of file
|
||||||
|
}
|
||||||
|
|
||||||
|
$len = $this->pos - 1 - $start;
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : '');
|
||||||
|
$this->status['last_pos'] = ++$this->pos;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse asp tags
|
||||||
|
* @internal Gets called with asp tags ("<%")
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_asp() {
|
||||||
|
$start = $this->pos;
|
||||||
|
if ($this->next_pos('%>', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->pos -= 2; //End of file
|
||||||
|
}
|
||||||
|
|
||||||
|
$len = $this->pos - 1 - $start;
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : '');
|
||||||
|
$this->status['last_pos'] = ++$this->pos;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse style tags
|
||||||
|
* @internal Gets called with php tags ("<style>")
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_style() {
|
||||||
|
if ($this->parse_attributes() && ($this->token === self::TOK_TAG_CLOSE) && ($start = $this->pos) && ($this->next_pos('</style>', false) === self::TOK_UNKNOWN)) {
|
||||||
|
$len = $this->pos - 1 - $start;
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : '');
|
||||||
|
|
||||||
|
$this->pos += 7;
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->addError('No end for style tag found');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse script tags
|
||||||
|
* @internal Gets called with php tags ("<script>")
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_script() {
|
||||||
|
if ($this->parse_attributes() && ($this->token === self::TOK_TAG_CLOSE) && ($start = $this->pos) && ($this->next_pos('</script>', false) === self::TOK_UNKNOWN)) {
|
||||||
|
$len = $this->pos - 1 - $start;
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $start + 1, $len) : '');
|
||||||
|
|
||||||
|
$this->pos += 8;
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->addError('No end for script tag found');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse conditional tags (+ all conditional tags inside)
|
||||||
|
* @internal Gets called with IE conditionals ("<![if]" and "<!--[if]")
|
||||||
|
* @internal Stores condition in {@link $status}[tag_condition]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_conditional() {
|
||||||
|
if ($this->status['closing_tag']) {
|
||||||
|
$this->pos += 8;
|
||||||
|
} else {
|
||||||
|
$this->pos += (($this->status['comment']) ? 5 : 3);
|
||||||
|
if ($this->next_pos(']', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->addError('"]" not found in conditional tag');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->status['tag_condition'] = $this->getTokenString(0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->next_no_whitespace() !== self::TOK_TAG_CLOSE) {
|
||||||
|
$this->addError('No ">" tag found 2 for conditional tag');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->status['comment']) {
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
if ($this->next_pos('-->', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->addError('No ending tag found for conditional tag');
|
||||||
|
$this->pos = $this->size - 1;
|
||||||
|
|
||||||
|
$len = $this->pos - 1 - $this->status['last_pos'];
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $this->status['last_pos'] + 1, $len) : '');
|
||||||
|
} else {
|
||||||
|
$len = $this->pos - 10 - $this->status['last_pos'];
|
||||||
|
$this->status['text'] = (($len > 0) ? substr($this->doc, $this->status['last_pos'] + 1, $len) : '');
|
||||||
|
$this->pos += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse attributes (names + value)
|
||||||
|
* @internal Stores attributes in {@link $status}[attributes] (array(ATTR => VAL))
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_attributes() {
|
||||||
|
$this->status['attributes'] = array();
|
||||||
|
|
||||||
|
while ($this->next_no_whitespace() === self::TOK_IDENTIFIER) {
|
||||||
|
$attr = $this->getTokenString();
|
||||||
|
if (($attr === '?') || ($attr === '%')) {
|
||||||
|
//Probably closing tags
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->next_no_whitespace() === self::TOK_EQUALS) {
|
||||||
|
if ($this->next_no_whitespace() === self::TOK_STRING) {
|
||||||
|
$val = $this->getTokenString(1, -1);
|
||||||
|
} else {
|
||||||
|
$this->token_start = $this->pos;
|
||||||
|
if (!isset($stop)) {
|
||||||
|
$stop = $this->whitespace;
|
||||||
|
$stop['<'] = true;
|
||||||
|
$stop['>'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((++$this->pos < $this->size) && (!isset($stop[$this->doc[$this->pos]]))) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
--$this->pos;
|
||||||
|
|
||||||
|
$val = $this->getTokenString();
|
||||||
|
|
||||||
|
if (trim($val) === '') {
|
||||||
|
$this->addError('Invalid attribute value');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$val = $attr;
|
||||||
|
$this->pos = (($this->token_start) ? $this->token_start : $this->pos) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->status['attributes'][$attr] = $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default callback for tags
|
||||||
|
* @internal Gets called after the tagname (<html*ENTERS_HERE* attribute="value">)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_tag_default() {
|
||||||
|
if ($this->status['closing_tag']) {
|
||||||
|
$this->status['attributes'] = array();
|
||||||
|
$this->next_no_whitespace();
|
||||||
|
} else {
|
||||||
|
if (!$this->parse_attributes()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->token !== self::TOK_TAG_CLOSE) {
|
||||||
|
if ($this->token === self::TOK_SLASH_FORWARD) {
|
||||||
|
$this->status['self_close'] = true;
|
||||||
|
$this->next();
|
||||||
|
} elseif ((($this->status['tag_name'][0] === '?') && ($this->doc[$this->pos] === '?')) || (($this->status['tag_name'][0] === '%') && ($this->doc[$this->pos] === '%'))) {
|
||||||
|
$this->status['self_close'] = true;
|
||||||
|
$this->pos++;
|
||||||
|
|
||||||
|
if (isset($this->char_map[$this->doc[$this->pos]]) && (!is_string($this->char_map[$this->doc[$this->pos]]))) {
|
||||||
|
$this->token = $this->char_map[$this->doc[$this->pos]];
|
||||||
|
} else {
|
||||||
|
$this->token = self::TOK_UNKNOWN;
|
||||||
|
}
|
||||||
|
}/* else {
|
||||||
|
$this->status['self_close'] = false;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->token !== self::TOK_TAG_CLOSE) {
|
||||||
|
$this->addError('Expected ">", but found "'.$this->getTokenString().'"');
|
||||||
|
if ($this->next_pos('>', false) !== self::TOK_UNKNOWN) {
|
||||||
|
$this->addError('No ">" tag found for "'.$this->status['tag_name'].'" tag');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse tag
|
||||||
|
* @internal Gets called after opening tag (<*ENTERS_HERE*html attribute="value">)
|
||||||
|
* @internal Stores information about the tag in {@link $status} (comment, closing_tag, tag_name)
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_tag() {
|
||||||
|
$start = $this->pos;
|
||||||
|
$this->status['self_close'] = false;
|
||||||
|
$this->parse_text();
|
||||||
|
|
||||||
|
$next = (($this->pos + 1) < $this->size) ? $this->doc[$this->pos + 1] : '';
|
||||||
|
if ($next === '!') {
|
||||||
|
$this->status['closing_tag'] = false;
|
||||||
|
|
||||||
|
if (substr($this->doc, $this->pos + 2, 2) === '--') {
|
||||||
|
$this->status['comment'] = true;
|
||||||
|
|
||||||
|
if (($this->doc[$this->pos + 4] === '[') && (strcasecmp(substr($this->doc, $this->pos + 5, 2), 'if') === 0)) {
|
||||||
|
return $this->parse_conditional();
|
||||||
|
} else {
|
||||||
|
return $this->parse_comment();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->status['comment'] = false;
|
||||||
|
|
||||||
|
if ($this->doc[$this->pos + 2] === '[') {
|
||||||
|
if (strcasecmp(substr($this->doc, $this->pos + 3, 2), 'if') === 0) {
|
||||||
|
return $this->parse_conditional();
|
||||||
|
} elseif (strcasecmp(substr($this->doc, $this->pos + 3, 5), 'endif') === 0) {
|
||||||
|
$this->status['closing_tag'] = true;
|
||||||
|
return $this->parse_conditional();
|
||||||
|
} elseif (strcasecmp(substr($this->doc, $this->pos + 3, 5), 'cdata') === 0) {
|
||||||
|
return $this->parse_cdata();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($next === '/') {
|
||||||
|
$this->status['closing_tag'] = true;
|
||||||
|
++$this->pos;
|
||||||
|
} else {
|
||||||
|
$this->status['closing_tag'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->next() !== self::TOK_IDENTIFIER) {
|
||||||
|
$this->addError('Tagname expected');
|
||||||
|
//if ($this->next_pos('>', false) === self::TOK_UNKNOWN) {
|
||||||
|
$this->status['last_pos'] = $start - 1;
|
||||||
|
return true;
|
||||||
|
//} else {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = $this->getTokenString();
|
||||||
|
$this->status['tag_name'] = $tag;
|
||||||
|
$tag = strtolower($tag);
|
||||||
|
|
||||||
|
if (isset($this->tag_map[$tag])) {
|
||||||
|
$res = $this->{$this->tag_map[$tag]}();
|
||||||
|
} else {
|
||||||
|
$res = $this->parse_tag_default();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->status['last_pos'] = $this->pos;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse full document
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function parse_all() {
|
||||||
|
$this->errors = array();
|
||||||
|
$this->status['last_pos'] = -1;
|
||||||
|
|
||||||
|
if (($this->token === self::TOK_TAG_OPEN) || ($this->next_pos('<', false) === self::TOK_UNKNOWN)) {
|
||||||
|
do {
|
||||||
|
if (!$this->parse_tag()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} while ($this->next_pos('<') !== self::TOK_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pos = $this->size;
|
||||||
|
$this->parse_text();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a HTML document into a HTML DOM
|
||||||
|
*/
|
||||||
|
class HtmlParser extends HtmlParserBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Root object
|
||||||
|
* @internal If string, then it will create a new instance as root
|
||||||
|
* @var DomNode
|
||||||
|
*/
|
||||||
|
var $root = 'pQuery\\DomNode';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current parsing hierarchy
|
||||||
|
* @internal Root is always at index 0, current tag is at the end of the array
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $hierarchy = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags that don't need closing tags
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $tags_selfclose = array(
|
||||||
|
'area' => true,
|
||||||
|
'base' => true,
|
||||||
|
'basefont' => true,
|
||||||
|
'br' => true,
|
||||||
|
'col' => true,
|
||||||
|
'command' => true,
|
||||||
|
'embed' => true,
|
||||||
|
'frame' => true,
|
||||||
|
'hr' => true,
|
||||||
|
'img' => true,
|
||||||
|
'input' => true,
|
||||||
|
'ins' => true,
|
||||||
|
'keygen' => true,
|
||||||
|
'link' => true,
|
||||||
|
'meta' => true,
|
||||||
|
'param' => true,
|
||||||
|
'source' => true,
|
||||||
|
'track' => true,
|
||||||
|
'wbr' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
* @param string $doc Document to be tokenized
|
||||||
|
* @param int $pos Position to start parsing
|
||||||
|
* @param DomNode $root Root node, null to auto create
|
||||||
|
*/
|
||||||
|
function __construct($doc = '', $pos = 0, $root = null) {
|
||||||
|
if ($root === null) {
|
||||||
|
$root = new $this->root('~root~', null);
|
||||||
|
}
|
||||||
|
$this->root =& $root;
|
||||||
|
|
||||||
|
parent::__construct($doc, $pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
#php4 PHP4 class constructor compatibility
|
||||||
|
#function HtmlParser($doc = '', $pos = 0, $root = null) {return $this->__construct($doc, $pos, $root);}
|
||||||
|
#php4e
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class magic invoke method, performs {@link select()}
|
||||||
|
* @return array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __invoke($query = '*') {
|
||||||
|
return $this->select($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class magic toString method, performs {@link DomNode::toString()}
|
||||||
|
* @return string
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __toString() {
|
||||||
|
return $this->root->getInnerText();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a css select query on the root node
|
||||||
|
* @see DomNode::select()
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function select($query = '*', $index = false, $recursive = true, $check_self = false) {
|
||||||
|
return $this->root->select($query, $index, $recursive, $check_self);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current hierarchy status and checks for
|
||||||
|
* correct opening/closing of tags
|
||||||
|
* @param bool $self_close Is current tag self closing? Null to use {@link tags_selfclose}
|
||||||
|
* @internal This is were most of the nodes get added
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_hierarchy($self_close = null) {
|
||||||
|
if ($self_close === null) {
|
||||||
|
$this->status['self_close'] = ($self_close = isset($this->tags_selfclose[strtolower($this->status['tag_name'])]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($self_close) {
|
||||||
|
if ($this->status['closing_tag']) {
|
||||||
|
|
||||||
|
//$c = end($this->hierarchy)->children
|
||||||
|
$c = $this->hierarchy[count($this->hierarchy) - 1]->children;
|
||||||
|
$found = false;
|
||||||
|
for ($count = count($c), $i = $count - 1; $i >= 0; $i--) {
|
||||||
|
if (strcasecmp($c[$i]->tag, $this->status['tag_name']) === 0) {
|
||||||
|
for($ii = $i + 1; $ii < $count; $ii++) {
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$c[$i + 1]->changeParent($c[$i], $index);
|
||||||
|
}
|
||||||
|
$c[$i]->self_close = false;
|
||||||
|
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
|
$this->addError('Closing tag "'.$this->status['tag_name'].'" which is not open');
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($this->status['tag_name'][0] === '?') {
|
||||||
|
//end($this->hierarchy)->addXML($this->status['tag_name'], '', $this->status['attributes']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addXML($this->status['tag_name'], '', $this->status['attributes'], $index);
|
||||||
|
} elseif ($this->status['tag_name'][0] === '%') {
|
||||||
|
//end($this->hierarchy)->addASP($this->status['tag_name'], '', $this->status['attributes']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addASP($this->status['tag_name'], '', $this->status['attributes'], $index);
|
||||||
|
} else {
|
||||||
|
//end($this->hierarchy)->addChild($this->status);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addChild($this->status, $index);
|
||||||
|
}
|
||||||
|
} elseif ($this->status['closing_tag']) {
|
||||||
|
$found = false;
|
||||||
|
for ($count = count($this->hierarchy), $i = $count - 1; $i >= 0; $i--) {
|
||||||
|
if (strcasecmp($this->hierarchy[$i]->tag, $this->status['tag_name']) === 0) {
|
||||||
|
|
||||||
|
for($ii = ($count - $i - 1); $ii >= 0; $ii--) {
|
||||||
|
$e = array_pop($this->hierarchy);
|
||||||
|
if ($ii > 0) {
|
||||||
|
$this->addError('Closing tag "'.$this->status['tag_name'].'" while "'.$e->tag.'" is not closed yet');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
|
$this->addError('Closing tag "'.$this->status['tag_name'].'" which is not open');
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//$this->hierarchy[] = end($this->hierarchy)->addChild($this->status);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[] = $this->hierarchy[count($this->hierarchy) - 1]->addChild($this->status, $index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_cdata() {
|
||||||
|
if (!parent::parse_cdata()) {return false;}
|
||||||
|
|
||||||
|
//end($this->hierarchy)->addCDATA($this->status['cdata']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addCDATA($this->status['cdata'], $index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_comment() {
|
||||||
|
if (!parent::parse_comment()) {return false;}
|
||||||
|
|
||||||
|
//end($this->hierarchy)->addComment($this->status['comment']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addComment($this->status['comment'], $index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_conditional() {
|
||||||
|
if (!parent::parse_conditional()) {return false;}
|
||||||
|
|
||||||
|
if ($this->status['comment']) {
|
||||||
|
//$e = end($this->hierarchy)->addConditional($this->status['tag_condition'], true);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e = $this->hierarchy[count($this->hierarchy) - 1]->addConditional($this->status['tag_condition'], true, $index);
|
||||||
|
if ($this->status['text'] !== '') {
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e->addText($this->status['text'], $index);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($this->status['closing_tag']) {
|
||||||
|
$this->parse_hierarchy(false);
|
||||||
|
} else {
|
||||||
|
//$this->hierarchy[] = end($this->hierarchy)->addConditional($this->status['tag_condition'], false);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[] = $this->hierarchy[count($this->hierarchy) - 1]->addConditional($this->status['tag_condition'], false, $index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_doctype() {
|
||||||
|
if (!parent::parse_doctype()) {return false;}
|
||||||
|
|
||||||
|
//end($this->hierarchy)->addDoctype($this->status['dtd']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addDoctype($this->status['dtd'], $index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_php() {
|
||||||
|
if (!parent::parse_php()) {return false;}
|
||||||
|
|
||||||
|
//end($this->hierarchy)->addXML('php', $this->status['text']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addXML('php', $this->status['text'], $index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_asp() {
|
||||||
|
if (!parent::parse_asp()) {return false;}
|
||||||
|
|
||||||
|
//end($this->hierarchy)->addASP('', $this->status['text']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addASP('', $this->status['text'], $index);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_script() {
|
||||||
|
if (!parent::parse_script()) {return false;}
|
||||||
|
|
||||||
|
//$e = end($this->hierarchy)->addChild($this->status);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e = $this->hierarchy[count($this->hierarchy) - 1]->addChild($this->status, $index);
|
||||||
|
if ($this->status['text'] !== '') {
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e->addText($this->status['text'], $index);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_style() {
|
||||||
|
if (!parent::parse_style()) {return false;}
|
||||||
|
|
||||||
|
//$e = end($this->hierarchy)->addChild($this->status);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e = $this->hierarchy[count($this->hierarchy) - 1]->addChild($this->status, $index);
|
||||||
|
if ($this->status['text'] !== '') {
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$e->addText($this->status['text'], $index);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_tag_default() {
|
||||||
|
if (!parent::parse_tag_default()) {return false;}
|
||||||
|
|
||||||
|
$this->parse_hierarchy(($this->status['self_close']) ? true : null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_text() {
|
||||||
|
parent::parse_text();
|
||||||
|
if ($this->status['text'] !== '') {
|
||||||
|
//end($this->hierarchy)->addText($this->status['text']);
|
||||||
|
$index = null; //Needs to be passed by ref
|
||||||
|
$this->hierarchy[count($this->hierarchy) - 1]->addText($this->status['text'], $index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_all() {
|
||||||
|
$this->hierarchy = array(&$this->root);
|
||||||
|
return ((parent::parse_all()) ? $this->root : false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTML5 specific parser (adds support for omittable closing tags)
|
||||||
|
*/
|
||||||
|
class Html5Parser extends HtmlParser {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags with ommitable closing tags
|
||||||
|
* @var array array('tag2' => 'tag1') will close tag1 if following (not child) tag is tag2
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $tags_optional_close = array(
|
||||||
|
//Current tag => Previous tag
|
||||||
|
'li' => array('li' => true),
|
||||||
|
'dt' => array('dt' => true, 'dd' => true),
|
||||||
|
'dd' => array('dt' => true, 'dd' => true),
|
||||||
|
'address' => array('p' => true),
|
||||||
|
'article' => array('p' => true),
|
||||||
|
'aside' => array('p' => true),
|
||||||
|
'blockquote' => array('p' => true),
|
||||||
|
'dir' => array('p' => true),
|
||||||
|
'div' => array('p' => true),
|
||||||
|
'dl' => array('p' => true),
|
||||||
|
'fieldset' => array('p' => true),
|
||||||
|
'footer' => array('p' => true),
|
||||||
|
'form' => array('p' => true),
|
||||||
|
'h1' => array('p' => true),
|
||||||
|
'h2' => array('p' => true),
|
||||||
|
'h3' => array('p' => true),
|
||||||
|
'h4' => array('p' => true),
|
||||||
|
'h5' => array('p' => true),
|
||||||
|
'h6' => array('p' => true),
|
||||||
|
'header' => array('p' => true),
|
||||||
|
'hgroup' => array('p' => true),
|
||||||
|
'hr' => array('p' => true),
|
||||||
|
'menu' => array('p' => true),
|
||||||
|
'nav' => array('p' => true),
|
||||||
|
'ol' => array('p' => true),
|
||||||
|
'p' => array('p' => true),
|
||||||
|
'pre' => array('p' => true),
|
||||||
|
'section' => array('p' => true),
|
||||||
|
'table' => array('p' => true),
|
||||||
|
'ul' => array('p' => true),
|
||||||
|
'rt' => array('rt' => true, 'rp' => true),
|
||||||
|
'rp' => array('rt' => true, 'rp' => true),
|
||||||
|
'optgroup' => array('optgroup' => true, 'option' => true),
|
||||||
|
'option' => array('option'),
|
||||||
|
'tbody' => array('thread' => true, 'tbody' => true, 'tfoot' => true),
|
||||||
|
'tfoot' => array('thread' => true, 'tbody' => true),
|
||||||
|
'tr' => array('tr' => true),
|
||||||
|
'td' => array('td' => true, 'th' => true),
|
||||||
|
'th' => array('td' => true, 'th' => true),
|
||||||
|
'body' => array('head' => true)
|
||||||
|
);
|
||||||
|
|
||||||
|
protected function parse_hierarchy($self_close = null) {
|
||||||
|
$tag_curr = strtolower($this->status['tag_name']);
|
||||||
|
if ($self_close === null) {
|
||||||
|
$this->status['self_close'] = ($self_close = isset($this->tags_selfclose[$tag_curr]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! ($self_close || $this->status['closing_tag'])) {
|
||||||
|
//$tag_prev = strtolower(end($this->hierarchy)->tag);
|
||||||
|
$tag_prev = strtolower($this->hierarchy[count($this->hierarchy) - 1]->tag);
|
||||||
|
if (isset($this->tags_optional_close[$tag_curr]) && isset($this->tags_optional_close[$tag_curr][$tag_prev])) {
|
||||||
|
array_pop($this->hierarchy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::parse_hierarchy($self_close);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
949
lib-3rd-party/pquery/gan_selector_html.php
vendored
Normal file
949
lib-3rd-party/pquery/gan_selector_html.php
vendored
Normal file
@@ -0,0 +1,949 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tokenizes a css selector query
|
||||||
|
*/
|
||||||
|
class CSSQueryTokenizer extends TokenizerBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opening bracket token, used for "["
|
||||||
|
*/
|
||||||
|
const TOK_BRACKET_OPEN = 100;
|
||||||
|
/**
|
||||||
|
* Closing bracket token, used for "]"
|
||||||
|
*/
|
||||||
|
const TOK_BRACKET_CLOSE = 101;
|
||||||
|
/**
|
||||||
|
* Opening brace token, used for "("
|
||||||
|
*/
|
||||||
|
const TOK_BRACE_OPEN = 102;
|
||||||
|
/**
|
||||||
|
* Closing brace token, used for ")"
|
||||||
|
*/
|
||||||
|
const TOK_BRACE_CLOSE = 103;
|
||||||
|
/**
|
||||||
|
* String token
|
||||||
|
*/
|
||||||
|
const TOK_STRING = 104;
|
||||||
|
/**
|
||||||
|
* Colon token, used for ":"
|
||||||
|
*/
|
||||||
|
const TOK_COLON = 105;
|
||||||
|
/**
|
||||||
|
* Comma token, used for ","
|
||||||
|
*/
|
||||||
|
const TOK_COMMA = 106;
|
||||||
|
/**
|
||||||
|
* "Not" token, used for "!"
|
||||||
|
*/
|
||||||
|
const TOK_NOT = 107;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "All" token, used for "*" in query
|
||||||
|
*/
|
||||||
|
const TOK_ALL = 108;
|
||||||
|
/**
|
||||||
|
* Pipe token, used for "|"
|
||||||
|
*/
|
||||||
|
const TOK_PIPE = 109;
|
||||||
|
/**
|
||||||
|
* Plus token, used for "+"
|
||||||
|
*/
|
||||||
|
const TOK_PLUS = 110;
|
||||||
|
/**
|
||||||
|
* "Sibling" token, used for "~" in query
|
||||||
|
*/
|
||||||
|
const TOK_SIBLING = 111;
|
||||||
|
/**
|
||||||
|
* Class token, used for "." in query
|
||||||
|
*/
|
||||||
|
const TOK_CLASS = 112;
|
||||||
|
/**
|
||||||
|
* ID token, used for "#" in query
|
||||||
|
*/
|
||||||
|
const TOK_ID = 113;
|
||||||
|
/**
|
||||||
|
* Child token, used for ">" in query
|
||||||
|
*/
|
||||||
|
const TOK_CHILD = 114;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attribute compare prefix token, used for "|="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_PREFIX = 115;
|
||||||
|
/**
|
||||||
|
* Attribute contains token, used for "*="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_CONTAINS = 116;
|
||||||
|
/**
|
||||||
|
* Attribute contains word token, used for "~="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_CONTAINS_WORD = 117;
|
||||||
|
/**
|
||||||
|
* Attribute compare end token, used for "$="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_ENDS = 118;
|
||||||
|
/**
|
||||||
|
* Attribute equals token, used for "="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_EQUALS = 119;
|
||||||
|
/**
|
||||||
|
* Attribute not equal token, used for "!="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_NOT_EQUAL = 120;
|
||||||
|
/**
|
||||||
|
* Attribute compare bigger than token, used for ">="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_BIGGER_THAN = 121;
|
||||||
|
/**
|
||||||
|
* Attribute compare smaller than token, used for "<="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_SMALLER_THAN = 122;
|
||||||
|
/**
|
||||||
|
* Attribute compare with regex, used for "%="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_REGEX = 123;
|
||||||
|
/**
|
||||||
|
* Attribute compare start token, used for "^="
|
||||||
|
*/
|
||||||
|
const TOK_COMPARE_STARTS = 124;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets query identifiers
|
||||||
|
* @see TokenizerBase::$identifiers
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $identifiers = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_-?';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map characters to match their tokens
|
||||||
|
* @see TokenizerBase::$custom_char_map
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $custom_char_map = array(
|
||||||
|
'.' => self::TOK_CLASS,
|
||||||
|
'#' => self::TOK_ID,
|
||||||
|
',' => self::TOK_COMMA,
|
||||||
|
'>' => 'parse_gt',//self::TOK_CHILD,
|
||||||
|
|
||||||
|
'+' => self::TOK_PLUS,
|
||||||
|
'~' => 'parse_sibling',
|
||||||
|
|
||||||
|
'|' => 'parse_pipe',
|
||||||
|
'*' => 'parse_star',
|
||||||
|
'$' => 'parse_compare',
|
||||||
|
'=' => self::TOK_COMPARE_EQUALS,
|
||||||
|
'!' => 'parse_not',
|
||||||
|
'%' => 'parse_compare',
|
||||||
|
'^' => 'parse_compare',
|
||||||
|
'<' => 'parse_compare',
|
||||||
|
|
||||||
|
'"' => 'parse_string',
|
||||||
|
"'" => 'parse_string',
|
||||||
|
'(' => self::TOK_BRACE_OPEN,
|
||||||
|
')' => self::TOK_BRACE_CLOSE,
|
||||||
|
'[' => self::TOK_BRACKET_OPEN,
|
||||||
|
']' => self::TOK_BRACKET_CLOSE,
|
||||||
|
':' => self::TOK_COLON
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse ">" character
|
||||||
|
* @internal Could be {@link TOK_CHILD} or {@link TOK_COMPARE_BIGGER_THAN}
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_gt() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
++$this->pos;
|
||||||
|
return ($this->token = self::TOK_COMPARE_BIGGER_THAN);
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_CHILD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse "~" character
|
||||||
|
* @internal Could be {@link TOK_SIBLING} or {@link TOK_COMPARE_CONTAINS_WORD}
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_sibling() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
++$this->pos;
|
||||||
|
return ($this->token = self::TOK_COMPARE_CONTAINS_WORD);
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_SIBLING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse "|" character
|
||||||
|
* @internal Could be {@link TOK_PIPE} or {@link TOK_COMPARE_PREFIX}
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_pipe() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
++$this->pos;
|
||||||
|
return ($this->token = self::TOK_COMPARE_PREFIX);
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_PIPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse "*" character
|
||||||
|
* @internal Could be {@link TOK_ALL} or {@link TOK_COMPARE_CONTAINS}
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_star() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
++$this->pos;
|
||||||
|
return ($this->token = self::TOK_COMPARE_CONTAINS);
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse "!" character
|
||||||
|
* @internal Could be {@link TOK_NOT} or {@link TOK_COMPARE_NOT_EQUAL}
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_not() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
++$this->pos;
|
||||||
|
return ($this->token = self::TOK_COMPARE_NOT_EQUAL);
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_NOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse several compare characters
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_compare() {
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === '=')) {
|
||||||
|
switch($this->doc[$this->pos++]) {
|
||||||
|
case '$':
|
||||||
|
return ($this->token = self::TOK_COMPARE_ENDS);
|
||||||
|
case '%':
|
||||||
|
return ($this->token = self::TOK_COMPARE_REGEX);
|
||||||
|
case '^':
|
||||||
|
return ($this->token = self::TOK_COMPARE_STARTS);
|
||||||
|
case '<':
|
||||||
|
return ($this->token = self::TOK_COMPARE_SMALLER_THAN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse strings (" and ')
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function parse_string() {
|
||||||
|
$char = $this->doc[$this->pos];
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if ($this->next_search($char.'\\', false) !== self::TOK_NULL) {
|
||||||
|
if($this->doc[$this->pos] === $char) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
++$this->pos;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->pos = $this->size - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($this->token = self::TOK_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a css select query on HTML nodes
|
||||||
|
*/
|
||||||
|
class HtmlSelector {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parser object
|
||||||
|
* @internal If string, then it will create a new instance as parser
|
||||||
|
* @var CSSQueryTokenizer
|
||||||
|
*/
|
||||||
|
var $parser = 'pQuery\\CSSQueryTokenizer';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target of queries
|
||||||
|
* @var DomNode
|
||||||
|
*/
|
||||||
|
var $root = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last performed query, result in {@link $result}
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $query = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of matching nodes
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $result = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include root in search, if false the only child nodes are evaluated
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
var $search_root = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search recursively
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
var $search_recursive = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra function map for custom filters
|
||||||
|
* @var array
|
||||||
|
* @internal array('root' => 'filter_root') will cause the
|
||||||
|
* selector to call $this->filter_root at :root
|
||||||
|
* @see DomNode::$filter_map
|
||||||
|
*/
|
||||||
|
var $custom_filter_map = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
* @param DomNode $root {@link $root}
|
||||||
|
* @param string $query
|
||||||
|
* @param bool $search_root {@link $search_root}
|
||||||
|
* @param bool $search_recursive {@link $search_recursive}
|
||||||
|
* @param CSSQueryTokenizer $parser If null, then default class will be used
|
||||||
|
*/
|
||||||
|
function __construct($root, $query = '*', $search_root = false, $search_recursive = true, $parser = null) {
|
||||||
|
if ($parser === null) {
|
||||||
|
$parser = new $this->parser();
|
||||||
|
}
|
||||||
|
$this->parser = $parser;
|
||||||
|
$this->root =& $root;
|
||||||
|
|
||||||
|
$this->search_root = $search_root;
|
||||||
|
$this->search_recursive = $search_recursive;
|
||||||
|
|
||||||
|
$this->select($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
#php4 PHP4 class constructor compatibility
|
||||||
|
#function HtmlSelector($root, $query = '*', $search_root = false, $search_recursive = true, $parser = null) {return $this->__construct($root, $query, $search_root, $search_recursive, $parser);}
|
||||||
|
#php4e
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toString method, returns {@link $query}
|
||||||
|
* @return string
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __toString() {
|
||||||
|
return $this->query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class magic invoke method, performs {@link select()}
|
||||||
|
* @return array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function __invoke($query = '*') {
|
||||||
|
return $this->select($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform query
|
||||||
|
* @param string $query
|
||||||
|
* @return array False on failure
|
||||||
|
*/
|
||||||
|
function select($query = '*') {
|
||||||
|
$this->parser->setDoc($query);
|
||||||
|
$this->query = $query;
|
||||||
|
return (($this->parse()) ? $this->result : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger error
|
||||||
|
* @param string $error
|
||||||
|
* @internal %pos% and %tok% will be replace in string with position and token(string)
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function error($error) {
|
||||||
|
$error = htmlentities(str_replace(
|
||||||
|
array('%tok%', '%pos%'),
|
||||||
|
array($this->parser->getTokenString(), (int) $this->parser->getPos()),
|
||||||
|
$error
|
||||||
|
));
|
||||||
|
|
||||||
|
trigger_error($error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get identifier (parse identifier or string)
|
||||||
|
* @param bool $do_error Error on failure
|
||||||
|
* @return string False on failure
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_getIdentifier($do_error = true) {
|
||||||
|
$p =& $this->parser;
|
||||||
|
$tok = $p->token;
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_IDENTIFIER) {
|
||||||
|
return $p->getTokenString();
|
||||||
|
} elseif($tok === CSSQueryTokenizer::TOK_STRING) {
|
||||||
|
return str_replace(array('\\\'', '\\"', '\\\\'), array('\'', '"', '\\'), $p->getTokenString(1, -1));
|
||||||
|
} elseif ($do_error) {
|
||||||
|
$this->error('Expected identifier at %pos%!');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get query conditions (tag, attribute and filter conditions)
|
||||||
|
* @return array False on failure
|
||||||
|
* @see DomNode::match()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_conditions() {
|
||||||
|
$p =& $this->parser;
|
||||||
|
$tok = $p->token;
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_NULL) {
|
||||||
|
$this->error('Invalid search pattern(1): Empty string!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conditions_all = array();
|
||||||
|
|
||||||
|
//Tags
|
||||||
|
while ($tok !== CSSQueryTokenizer::TOK_NULL) {
|
||||||
|
$conditions = array('tags' => array(), 'attributes' => array());
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if (($tok === CSSQueryTokenizer::TOK_PIPE) && ($tok = $p->next()) && ($tok !== CSSQueryTokenizer::TOK_ALL)) {
|
||||||
|
if (($tag = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'compare' => 'name'
|
||||||
|
);
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
} else {
|
||||||
|
$conditions['tags'][''] = array(
|
||||||
|
'tag' => '',
|
||||||
|
'match' => false
|
||||||
|
);
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => '',
|
||||||
|
'compare' => 'namespace',
|
||||||
|
);
|
||||||
|
} elseif (($tag = $this->parse_getIdentifier()) !== false) {
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'compare' => 'total',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
} elseif ($tok === CSSQueryTokenizer::TOK_BRACE_OPEN) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
$last_mode = 'or';
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$match = true;
|
||||||
|
$compare = 'total';
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_NOT) {
|
||||||
|
$match = false;
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$this->next();
|
||||||
|
$compare = 'name';
|
||||||
|
if (($tag = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$tag = '';
|
||||||
|
$compare = 'namespace';
|
||||||
|
} elseif (($tag = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
} else {
|
||||||
|
if (($tag = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$compare = 'namespace';
|
||||||
|
} elseif (($tag_name = $this->parse_getIdentifier()) !== false) {
|
||||||
|
$tag = $tag.':'.$tag_name;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_WHITESPACE) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'match' => $match,
|
||||||
|
'operator' => $last_mode,
|
||||||
|
'compare' => $compare
|
||||||
|
);
|
||||||
|
switch($tok) {
|
||||||
|
case CSSQueryTokenizer::TOK_COMMA:
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
$last_mode = 'or';
|
||||||
|
continue 2;
|
||||||
|
case CSSQueryTokenizer::TOK_PLUS:
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
$last_mode = 'and';
|
||||||
|
continue 2;
|
||||||
|
case CSSQueryTokenizer::TOK_BRACE_CLOSE:
|
||||||
|
$tok = $p->next();
|
||||||
|
break 2;
|
||||||
|
default:
|
||||||
|
$this->error('Expected closing brace or comma at pos %pos%!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif (($tag = $this->parse_getIdentifier(false)) !== false) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'compare' => 'namespace'
|
||||||
|
);
|
||||||
|
} elseif (($tag_name = $this->parse_getIdentifier()) !== false) {
|
||||||
|
$tag = $tag.':'.$tag_name;
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'match' => true
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tok = $p->next();
|
||||||
|
} elseif ($tag === 'text' && $tok === CSSQueryTokenizer::TOK_BRACE_OPEN) {
|
||||||
|
$pos = $p->getPos();
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_BRACE_CLOSE) {
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => '~text~',
|
||||||
|
'match' => true
|
||||||
|
);
|
||||||
|
$p->next();
|
||||||
|
} else {
|
||||||
|
$p->setPos($pos);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$conditions['tags'][] = array(
|
||||||
|
'tag' => $tag,
|
||||||
|
'match' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unset($conditions['tags']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Class
|
||||||
|
$last_mode = 'or';
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_CLASS) {
|
||||||
|
$p->next();
|
||||||
|
if (($class = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions['attributes'][] = array(
|
||||||
|
'attribute' => 'class',
|
||||||
|
'operator_value' => 'contains_word',
|
||||||
|
'value' => $class,
|
||||||
|
'operator_result' => $last_mode
|
||||||
|
);
|
||||||
|
$last_mode = 'and';
|
||||||
|
$tok = $p->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
//ID
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ID) {
|
||||||
|
$p->next();
|
||||||
|
if (($id = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions['attributes'][] = array(
|
||||||
|
'attribute' => 'id',
|
||||||
|
'operator_value' => 'equals',
|
||||||
|
'value' => $id,
|
||||||
|
'operator_result' => $last_mode
|
||||||
|
);
|
||||||
|
$last_mode = 'and';
|
||||||
|
$tok = $p->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Attributes
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_BRACKET_OPEN) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
$match = true;
|
||||||
|
$compare = 'total';
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_NOT) {
|
||||||
|
$match = false;
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_ALL) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if (($attribute = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$compare = 'name';
|
||||||
|
$tok = $p->next();
|
||||||
|
} else {
|
||||||
|
$this->error('Expected pipe at pos %pos%!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if (($tag = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
} elseif (($attribute = $this->parse_getIdentifier()) !== false) {
|
||||||
|
$tok = $p->next();
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_PIPE) {
|
||||||
|
$tok = $p->next();
|
||||||
|
|
||||||
|
if (($attribute_name = $this->parse_getIdentifier()) !== false) {
|
||||||
|
$attribute = $attribute.':'.$attribute_name;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tok = $p->next();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_WHITESPACE) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
$operator_value = '';
|
||||||
|
$val = '';
|
||||||
|
switch($tok) {
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_PREFIX:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_CONTAINS:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_CONTAINS_WORD:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_ENDS:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_EQUALS:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_NOT_EQUAL:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_REGEX:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_STARTS:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_BIGGER_THAN:
|
||||||
|
case CSSQueryTokenizer::TOK_COMPARE_SMALLER_THAN:
|
||||||
|
$operator_value = $p->getTokenString(($tok === CSSQueryTokenizer::TOK_COMPARE_EQUALS) ? 0 : -1);
|
||||||
|
$p->next_no_whitespace();
|
||||||
|
|
||||||
|
if (($val = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operator_value && $val) {
|
||||||
|
$conditions['attributes'][] = array(
|
||||||
|
'attribute' => $attribute,
|
||||||
|
'operator_value' => $operator_value,
|
||||||
|
'value' => $val,
|
||||||
|
'match' => $match,
|
||||||
|
'operator_result' => $last_mode,
|
||||||
|
'compare' => $compare
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$conditions['attributes'][] = array(
|
||||||
|
'attribute' => $attribute,
|
||||||
|
'value' => $match,
|
||||||
|
'operator_result' => $last_mode,
|
||||||
|
'compare' => $compare
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($tok) {
|
||||||
|
case CSSQueryTokenizer::TOK_COMMA:
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
$last_mode = 'or';
|
||||||
|
continue 2;
|
||||||
|
case CSSQueryTokenizer::TOK_PLUS:
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
$last_mode = 'and';
|
||||||
|
continue 2;
|
||||||
|
case CSSQueryTokenizer::TOK_BRACKET_CLOSE:
|
||||||
|
$tok = $p->next();
|
||||||
|
break 2;
|
||||||
|
default:
|
||||||
|
$this->error('Expected closing bracket or comma at pos %pos%!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($conditions['attributes']) < 1) {
|
||||||
|
unset($conditions['attributes']);
|
||||||
|
}
|
||||||
|
|
||||||
|
while($tok === CSSQueryTokenizer::TOK_COLON) {
|
||||||
|
if (count($conditions) < 1) {
|
||||||
|
$conditions['tags'] = array(array(
|
||||||
|
'tag' => '',
|
||||||
|
'match' => false
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tok = $p->next();
|
||||||
|
if (($filter = $this->parse_getIdentifier()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($tok = $p->next()) === CSSQueryTokenizer::TOK_BRACE_OPEN) {
|
||||||
|
$start = $p->pos;
|
||||||
|
$count = 1;
|
||||||
|
while ((($tok = $p->next()) !== CSSQueryTokenizer::TOK_NULL) && !(($tok === CSSQueryTokenizer::TOK_BRACE_CLOSE) && (--$count === 0))) {
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_BRACE_OPEN) {
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($tok !== CSSQueryTokenizer::TOK_BRACE_CLOSE) {
|
||||||
|
$this->error('Expected closing brace at pos %pos%!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$len = $p->pos - 1 - $start;
|
||||||
|
$params = (($len > 0) ? substr($p->doc, $start + 1, $len) : '');
|
||||||
|
$tok = $p->next();
|
||||||
|
} else {
|
||||||
|
$params = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$conditions['filters'][] = array('filter' => $filter, 'params' => $params);
|
||||||
|
}
|
||||||
|
if (count($conditions) < 1) {
|
||||||
|
$this->error('Invalid search pattern(2): No conditions found!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$conditions_all[] = $conditions;
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_WHITESPACE) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tok === CSSQueryTokenizer::TOK_COMMA) {
|
||||||
|
$tok = $p->next_no_whitespace();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $conditions_all;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate root node using custom callback
|
||||||
|
* @param array $conditions {@link parse_conditions()}
|
||||||
|
* @param bool|int $recursive
|
||||||
|
* @param bool $check_root
|
||||||
|
* @return array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_callback($conditions, $recursive = true, $check_root = false) {
|
||||||
|
return ($this->result = $this->root->getChildrenByMatch(
|
||||||
|
$conditions,
|
||||||
|
$recursive,
|
||||||
|
$check_root,
|
||||||
|
$this->custom_filter_map
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse first bit of query, only root node has to be evaluated now
|
||||||
|
* @param bool|int $recursive
|
||||||
|
* @return bool
|
||||||
|
* @internal Result of query is set in {@link $result}
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_single($recursive = true) {
|
||||||
|
if (($c = $this->parse_conditions()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->parse_callback($c, $recursive, $this->search_root);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate sibling nodes
|
||||||
|
* @return bool
|
||||||
|
* @internal Result of query is set in {@link $result}
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_adjacent() {
|
||||||
|
$tmp = $this->result;
|
||||||
|
$this->result = array();
|
||||||
|
if (($c = $this->parse_conditions()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($tmp as $t) {
|
||||||
|
if (($sibling = $t->getNextSibling()) !== false) {
|
||||||
|
if ($sibling->match($c, true, $this->custom_filter_map)) {
|
||||||
|
$this->result[] = $sibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate {@link $result}
|
||||||
|
* @param bool $parent Evaluate parent nodes
|
||||||
|
* @param bool|int $recursive
|
||||||
|
* @return bool
|
||||||
|
* @internal Result of query is set in {@link $result}
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse_result($parent = false, $recursive = true) {
|
||||||
|
$tmp = $this->result;
|
||||||
|
$tmp_res = array();
|
||||||
|
if (($c = $this->parse_conditions()) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(array_keys($tmp) as $t) {
|
||||||
|
$this->root = (($parent) ? $tmp[$t]->parent : $tmp[$t]);
|
||||||
|
$this->parse_callback($c, $recursive);
|
||||||
|
foreach(array_keys($this->result) as $r) {
|
||||||
|
if (!in_array($this->result[$r], $tmp_res, true)) {
|
||||||
|
$tmp_res[] = $this->result[$r];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->result = $tmp_res;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse full query
|
||||||
|
* @return bool
|
||||||
|
* @internal Result of query is set in {@link $result}
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
protected function parse() {
|
||||||
|
$p =& $this->parser;
|
||||||
|
$p->setPos(0);
|
||||||
|
$this->result = array();
|
||||||
|
|
||||||
|
if (!$this->parse_single()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (count($this->result) > 0) {
|
||||||
|
switch($p->token) {
|
||||||
|
case CSSQueryTokenizer::TOK_CHILD:
|
||||||
|
$this->parser->next_no_whitespace();
|
||||||
|
if (!$this->parse_result(false, 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSSQueryTokenizer::TOK_SIBLING:
|
||||||
|
$this->parser->next_no_whitespace();
|
||||||
|
if (!$this->parse_result(true, 1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSSQueryTokenizer::TOK_PLUS:
|
||||||
|
$this->parser->next_no_whitespace();
|
||||||
|
if (!$this->parse_adjacent()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSSQueryTokenizer::TOK_ALL:
|
||||||
|
case CSSQueryTokenizer::TOK_IDENTIFIER:
|
||||||
|
case CSSQueryTokenizer::TOK_STRING:
|
||||||
|
case CSSQueryTokenizer::TOK_BRACE_OPEN:
|
||||||
|
case CSSQueryTokenizer::TOK_BRACKET_OPEN:
|
||||||
|
case CSSQueryTokenizer::TOK_ID:
|
||||||
|
case CSSQueryTokenizer::TOK_CLASS:
|
||||||
|
case CSSQueryTokenizer::TOK_COLON:
|
||||||
|
if (!$this->parse_result()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CSSQueryTokenizer::TOK_NULL:
|
||||||
|
break 2;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$this->error('Invalid search pattern(3): No result modifier found!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
566
lib-3rd-party/pquery/gan_tokenizer.php
vendored
Normal file
566
lib-3rd-party/pquery/gan_tokenizer.php
vendored
Normal file
@@ -0,0 +1,566 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a document into tokens
|
||||||
|
*
|
||||||
|
* Can convert any string into tokens. The base class only supports
|
||||||
|
* identifier/whitespace tokens. For more tokens, the class can be
|
||||||
|
* easily extended.
|
||||||
|
*
|
||||||
|
* Use like:
|
||||||
|
* <code>
|
||||||
|
* <?php
|
||||||
|
* $a = new TokenizerBase('hello word');
|
||||||
|
* while ($a->next() !== $a::TOK_NULL) {
|
||||||
|
* echo $a->token, ': ',$a->getTokenString(), "<br>\n";
|
||||||
|
* }
|
||||||
|
* ?>
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @internal The tokenizer works with a character map that connects a certain
|
||||||
|
* character to a certain function/token. This class is build with speed in mind.
|
||||||
|
*/
|
||||||
|
class TokenizerBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NULL Token, used at end of document (parsing should stop after this token)
|
||||||
|
*/
|
||||||
|
const TOK_NULL = 0;
|
||||||
|
/**
|
||||||
|
* Unknown token, used at unidentified character
|
||||||
|
*/
|
||||||
|
const TOK_UNKNOWN = 1;
|
||||||
|
/**
|
||||||
|
* Whitespace token, used with whitespace
|
||||||
|
*/
|
||||||
|
const TOK_WHITESPACE = 2;
|
||||||
|
/**
|
||||||
|
* Identifier token, used with identifiers
|
||||||
|
*/
|
||||||
|
const TOK_IDENTIFIER = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The document that is being tokenized
|
||||||
|
* @var string
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see setDoc()
|
||||||
|
* @see getDoc()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $doc = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size of the document (length of string)
|
||||||
|
* @var int
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see $doc
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $size = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current (character) position in the document
|
||||||
|
* @var int
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see setPos()
|
||||||
|
* @see getPos()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $pos = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current (Line/Column) position in document
|
||||||
|
* @var array (Current_Line, Line_Starting_Pos)
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see getLinePos()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $line_pos = array(0, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current token
|
||||||
|
* @var int
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see getToken()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $token = self::TOK_NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start position of token. If NULL, then current position is used.
|
||||||
|
* @var int
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @see getTokenString()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $token_start = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List with all the character that can be considered as whitespace
|
||||||
|
* @var array|string
|
||||||
|
* @internal Variable is public + associated array for faster access!
|
||||||
|
* @internal array(' ' => true) will recognize space (' ') as whitespace
|
||||||
|
* @internal String will be converted to array in constructor
|
||||||
|
* @internal Result token will be {@link self::TOK_WHITESPACE};
|
||||||
|
* @see setWhitespace()
|
||||||
|
* @see getWhitespace()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $whitespace = " \t\n\r\0\x0B";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List with all the character that can be considered as identifier
|
||||||
|
* @var array|string
|
||||||
|
* @internal Variable is public + associated array for faster access!
|
||||||
|
* @internal array('a' => true) will recognize 'a' as identifier
|
||||||
|
* @internal String will be converted to array in constructor
|
||||||
|
* @internal Result token will be {@link self::TOK_IDENTIFIER};
|
||||||
|
* @see setIdentifiers()
|
||||||
|
* @see getIdentifiers()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $identifiers = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All characters that should be mapped to a token/function that cannot be considered as whitespace or identifier
|
||||||
|
* @var array
|
||||||
|
* @internal Variable is public + associated array for faster access!
|
||||||
|
* @internal array('a' => 'parse_a') will call $this->parse_a() if it matches the character 'a'
|
||||||
|
* @internal array('a' => self::TOK_A) will set token to TOK_A if it matches the character 'a'
|
||||||
|
* @see mapChar()
|
||||||
|
* @see unmapChar()
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $custom_char_map = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Automatically built character map. Built using {@link $identifiers}, {@link $whitespace} and {@link $custom_char_map}
|
||||||
|
* @var array
|
||||||
|
* @internal Public for faster access!
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $char_map = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All errors found while parsing the document
|
||||||
|
* @var array
|
||||||
|
* @see addError()
|
||||||
|
*/
|
||||||
|
var $errors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor
|
||||||
|
* @param string $doc Document to be tokenized
|
||||||
|
* @param int $pos Position to start parsing
|
||||||
|
* @see setDoc()
|
||||||
|
* @see setPos()
|
||||||
|
*/
|
||||||
|
function __construct($doc = '', $pos = 0) {
|
||||||
|
$this->setWhitespace($this->whitespace);
|
||||||
|
$this->setIdentifiers($this->identifiers);
|
||||||
|
|
||||||
|
$this->setDoc($doc, $pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
#php4 PHP4 class constructor compatibility
|
||||||
|
#function TokenizerBase($doc = '', $pos = 0) {return $this->__construct($doc, $pos);}
|
||||||
|
#php4e
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets target document
|
||||||
|
* @param string $doc Document to be tokenized
|
||||||
|
* @param int $pos Position to start parsing
|
||||||
|
* @see getDoc()
|
||||||
|
* @see setPos()
|
||||||
|
*/
|
||||||
|
function setDoc($doc, $pos = 0) {
|
||||||
|
$this->doc = $doc;
|
||||||
|
$this->size = strlen($doc);
|
||||||
|
$this->setPos($pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns target document
|
||||||
|
* @return string
|
||||||
|
* @see setDoc()
|
||||||
|
*/
|
||||||
|
function getDoc() {
|
||||||
|
return $this->doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets position in document
|
||||||
|
* @param int $pos
|
||||||
|
* @see getPos()
|
||||||
|
*/
|
||||||
|
function setPos($pos = 0) {
|
||||||
|
$this->pos = $pos - 1;
|
||||||
|
$this->line_pos = array(0, 0);
|
||||||
|
$this->next();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current position in document (Index)
|
||||||
|
* @return int
|
||||||
|
* @see setPos()
|
||||||
|
*/
|
||||||
|
function getPos() {
|
||||||
|
return $this->pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current position in document (Line/Char)
|
||||||
|
* @return array array(Line, Column)
|
||||||
|
*/
|
||||||
|
function getLinePos() {
|
||||||
|
return array($this->line_pos[0], $this->pos - $this->line_pos[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current token
|
||||||
|
* @return int
|
||||||
|
* @see $token
|
||||||
|
*/
|
||||||
|
function getToken() {
|
||||||
|
return $this->token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns current token as string
|
||||||
|
* @param int $start_offset Offset from token start
|
||||||
|
* @param int $end_offset Offset from token end
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getTokenString($start_offset = 0, $end_offset = 0) {
|
||||||
|
$token_start = ((is_int($this->token_start)) ? $this->token_start : $this->pos) + $start_offset;
|
||||||
|
$len = $this->pos - $token_start + 1 + $end_offset;
|
||||||
|
return (($len > 0) ? substr($this->doc, $token_start, $len) : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets characters to be recognized as whitespace
|
||||||
|
*
|
||||||
|
* Used like: setWhitespace('ab') or setWhitespace(array('a' => true, 'b', 'c'));
|
||||||
|
* @param string|array $ws
|
||||||
|
* @see getWhitespace();
|
||||||
|
*/
|
||||||
|
function setWhitespace($ws) {
|
||||||
|
if (is_array($ws)) {
|
||||||
|
$this->whitespace = array_fill_keys(array_values($ws), true);
|
||||||
|
$this->buildCharMap();
|
||||||
|
} else {
|
||||||
|
$this->setWhiteSpace(str_split($ws));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whitespace characters as string/array
|
||||||
|
* @param bool $as_string Should the result be a string or an array?
|
||||||
|
* @return string|array
|
||||||
|
* @see setWhitespace()
|
||||||
|
*/
|
||||||
|
function getWhitespace($as_string = true) {
|
||||||
|
$ws = array_keys($this->whitespace);
|
||||||
|
return (($as_string) ? implode('', $ws) : $ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets characters to be recognized as identifier
|
||||||
|
*
|
||||||
|
* Used like: setIdentifiers('ab') or setIdentifiers(array('a' => true, 'b', 'c'));
|
||||||
|
* @param string|array $ident
|
||||||
|
* @see getIdentifiers();
|
||||||
|
*/
|
||||||
|
function setIdentifiers($ident) {
|
||||||
|
if (is_array($ident)) {
|
||||||
|
$this->identifiers = array_fill_keys(array_values($ident), true);
|
||||||
|
$this->buildCharMap();
|
||||||
|
} else {
|
||||||
|
$this->setIdentifiers(str_split($ident));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns identifier characters as string/array
|
||||||
|
* @param bool $as_string Should the result be a string or an array?
|
||||||
|
* @return string|array
|
||||||
|
* @see setIdentifiers()
|
||||||
|
*/
|
||||||
|
function getIdentifiers($as_string = true) {
|
||||||
|
$ident = array_keys($this->identifiers);
|
||||||
|
return (($as_string) ? implode('', $ident) : $ident);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps a custom character to a token/function
|
||||||
|
*
|
||||||
|
* Used like: mapChar('a', self::{@link TOK_IDENTIFIER}) or mapChar('a', 'parse_identifier');
|
||||||
|
* @param string $char Character that should be mapped. If set, it will be overridden
|
||||||
|
* @param int|string $map If function name, then $this->function will be called, otherwise token is set to $map
|
||||||
|
* @see unmapChar()
|
||||||
|
*/
|
||||||
|
function mapChar($char, $map) {
|
||||||
|
$this->custom_char_map[$char] = $map;
|
||||||
|
$this->buildCharMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a char mapped with {@link mapChar()}
|
||||||
|
* @param string $char Character that should be unmapped
|
||||||
|
* @see mapChar()
|
||||||
|
*/
|
||||||
|
function unmapChar($char) {
|
||||||
|
unset($this->custom_char_map[$char]);
|
||||||
|
$this->buildCharMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the {@link $map_char} array
|
||||||
|
* @internal Builds single array that maps all characters. Gets called if {@link $whitespace}, {@link $identifiers} or {@link $custom_char_map} get modified
|
||||||
|
*/
|
||||||
|
protected function buildCharMap() {
|
||||||
|
$this->char_map = $this->custom_char_map;
|
||||||
|
if (is_array($this->whitespace)) {
|
||||||
|
foreach($this->whitespace as $w => $v) {
|
||||||
|
$this->char_map[$w] = 'parse_whitespace';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_array($this->identifiers)) {
|
||||||
|
foreach($this->identifiers as $i => $v) {
|
||||||
|
$this->char_map[$i] = 'parse_identifier';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add error to the array and appends current position
|
||||||
|
* @param string $error
|
||||||
|
*/
|
||||||
|
function addError($error) {
|
||||||
|
$this->errors[] = htmlentities($error.' at '.($this->line_pos[0] + 1).', '.($this->pos - $this->line_pos[1] + 1).'!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse line breaks and increase line number
|
||||||
|
* @internal Gets called to process line breaks
|
||||||
|
*/
|
||||||
|
protected function parse_linebreak() {
|
||||||
|
if($this->doc[$this->pos] === "\r") {
|
||||||
|
++$this->line_pos[0];
|
||||||
|
if ((($this->pos + 1) < $this->size) && ($this->doc[$this->pos + 1] === "\n")) {
|
||||||
|
++$this->pos;
|
||||||
|
}
|
||||||
|
$this->line_pos[1] = $this->pos;
|
||||||
|
} elseif($this->doc[$this->pos] === "\n") {
|
||||||
|
++$this->line_pos[0];
|
||||||
|
$this->line_pos[1] = $this->pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse whitespace
|
||||||
|
* @return int Token
|
||||||
|
* @internal Gets called with {@link $whitespace} characters
|
||||||
|
*/
|
||||||
|
protected function parse_whitespace() {
|
||||||
|
$this->token_start = $this->pos;
|
||||||
|
|
||||||
|
while(++$this->pos < $this->size) {
|
||||||
|
if (!isset($this->whitespace[$this->doc[$this->pos]])) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$this->parse_linebreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--$this->pos;
|
||||||
|
return self::TOK_WHITESPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse identifiers
|
||||||
|
* @return int Token
|
||||||
|
* @internal Gets called with {@link $identifiers} characters
|
||||||
|
*/
|
||||||
|
protected function parse_identifier() {
|
||||||
|
$this->token_start = $this->pos;
|
||||||
|
|
||||||
|
while((++$this->pos < $this->size) && isset($this->identifiers[$this->doc[$this->pos]])) {}
|
||||||
|
|
||||||
|
--$this->pos;
|
||||||
|
return self::TOK_IDENTIFIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continues to the next token
|
||||||
|
* @return int Next token ({@link TOK_NULL} if none)
|
||||||
|
*/
|
||||||
|
function next() {
|
||||||
|
$this->token_start = null;
|
||||||
|
|
||||||
|
if (++$this->pos < $this->size) {
|
||||||
|
if (isset($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
if (is_string($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}());
|
||||||
|
} else {
|
||||||
|
return ($this->token = $this->char_map[$this->doc[$this->pos]]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_UNKNOWN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the next token, but skips whitespace
|
||||||
|
* @return int Next token ({@link TOK_NULL} if none)
|
||||||
|
*/
|
||||||
|
function next_no_whitespace() {
|
||||||
|
$this->token_start = null;
|
||||||
|
|
||||||
|
while (++$this->pos < $this->size) {
|
||||||
|
if (!isset($this->whitespace[$this->doc[$this->pos]])) {
|
||||||
|
if (isset($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
if (is_string($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}());
|
||||||
|
} else {
|
||||||
|
return ($this->token = $this->char_map[$this->doc[$this->pos]]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_UNKNOWN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->parse_linebreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($this->token = self::TOK_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the next token using stop characters.
|
||||||
|
*
|
||||||
|
* Used like: next_search('abc') or next_search(array('a' => true, 'b' => true, 'c' => true));
|
||||||
|
* @param string|array $characters Characters to search for
|
||||||
|
* @param bool $callback Should the function check the charmap after finding a character?
|
||||||
|
* @return int Next token ({@link TOK_NULL} if none)
|
||||||
|
*/
|
||||||
|
function next_search($characters, $callback = true) {
|
||||||
|
$this->token_start = $this->pos;
|
||||||
|
if (!is_array($characters)) {
|
||||||
|
$characters = array_fill_keys(str_split($characters), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(++$this->pos < $this->size) {
|
||||||
|
if (isset($characters[$this->doc[$this->pos]])) {
|
||||||
|
if ($callback && isset($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
if (is_string($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}());
|
||||||
|
} else {
|
||||||
|
return ($this->token = $this->char_map[$this->doc[$this->pos]]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_UNKNOWN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->parse_linebreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($this->token = self::TOK_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the next token by searching for a string
|
||||||
|
* @param string $needle The needle that's being searched for
|
||||||
|
* @param bool $callback Should the function check the charmap after finding the needle?
|
||||||
|
* @return int Next token ({@link TOK_NULL} if none)
|
||||||
|
*/
|
||||||
|
function next_pos($needle, $callback = true) {
|
||||||
|
$this->token_start = $this->pos;
|
||||||
|
if (($this->pos < $this->size) && (($p = stripos($this->doc, $needle, $this->pos + 1)) !== false)) {
|
||||||
|
|
||||||
|
$len = $p - $this->pos - 1;
|
||||||
|
if ($len > 0) {
|
||||||
|
$str = substr($this->doc, $this->pos + 1, $len);
|
||||||
|
|
||||||
|
if (($l = strrpos($str, "\n")) !== false) {
|
||||||
|
++$this->line_pos[0];
|
||||||
|
$this->line_pos[1] = $l + $this->pos + 1;
|
||||||
|
|
||||||
|
$len -= $l;
|
||||||
|
if ($len > 0) {
|
||||||
|
$str = substr($str, 0, -$len);
|
||||||
|
$this->line_pos[0] += substr_count($str, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pos = $p;
|
||||||
|
if ($callback && isset($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
if (is_string($this->char_map[$this->doc[$this->pos]])) {
|
||||||
|
return ($this->token = $this->{$this->char_map[$this->doc[$this->pos]]}());
|
||||||
|
} else {
|
||||||
|
return ($this->token = $this->char_map[$this->doc[$this->pos]]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ($this->token = self::TOK_UNKNOWN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->pos = $this->size;
|
||||||
|
return ($this->token = self::TOK_NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expect a specific token or character. Adds error if token doesn't match.
|
||||||
|
* @param string|int $token Character or token to expect
|
||||||
|
* @param bool|int $do_next Go to next character before evaluating. 1 for next char, true to ignore whitespace
|
||||||
|
* @param bool|int $try_next Try next character if current doesn't match. 1 for next char, true to ignore whitespace
|
||||||
|
* @param bool|int $next_on_match Go to next character after evaluating. 1 for next char, true to ignore whitespace
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function expect($token, $do_next = true, $try_next = false, $next_on_match = 1) {
|
||||||
|
if ($do_next) {
|
||||||
|
if ($do_next === 1) {
|
||||||
|
$this->next();
|
||||||
|
} else {
|
||||||
|
$this->next_no_whitespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_int($token)) {
|
||||||
|
if (($this->token !== $token) && ((!$try_next) || ((($try_next === 1) && ($this->next() !== $token)) || (($try_next === true) && ($this->next_no_whitespace() !== $token))))) {
|
||||||
|
$this->addError('Unexpected "'.$this->getTokenString().'"');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (($this->doc[$this->pos] !== $token) && ((!$try_next) || (((($try_next === 1) && ($this->next() !== self::TOK_NULL)) || (($try_next === true) && ($this->next_no_whitespace() !== self::TOK_NULL))) && ($this->doc[$this->pos] !== $token)))) {
|
||||||
|
$this->addError('Expected "'.$token.'", but found "'.$this->getTokenString().'"');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($next_on_match) {
|
||||||
|
if ($next_on_match === 1) {
|
||||||
|
$this->next();
|
||||||
|
} else {
|
||||||
|
$this->next_no_whitespace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
101
lib-3rd-party/pquery/gan_xml2array.php
vendored
Normal file
101
lib-3rd-party/pquery/gan_xml2array.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a XML document to an array
|
||||||
|
*/
|
||||||
|
class XML2ArrayParser extends HtmlParserBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the document structure
|
||||||
|
* @var array array('name' => 'tag', 'attrs' => array('attr' => 'val'), 'childen' => array())
|
||||||
|
*/
|
||||||
|
var $root = array(
|
||||||
|
'name' => '',
|
||||||
|
'attrs' => array(),
|
||||||
|
'children' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current parsing hierarchy
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $hierarchy = array();
|
||||||
|
|
||||||
|
protected function parse_hierarchy($self_close) {
|
||||||
|
if ($this->status['closing_tag']) {
|
||||||
|
$found = false;
|
||||||
|
for ($count = count($this->hierarchy), $i = $count - 1; $i >= 0; $i--) {
|
||||||
|
if (strcasecmp($this->hierarchy[$i]['name'], $this->status['tag_name']) === 0) {
|
||||||
|
|
||||||
|
for($ii = ($count - $i - 1); $ii >= 0; $ii--) {
|
||||||
|
$e = array_pop($this->hierarchy);
|
||||||
|
if ($ii > 0) {
|
||||||
|
$this->addError('Closing tag "'.$this->status['tag_name'].'" while "'.$e['name'].'" is not closed yet');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$found) {
|
||||||
|
$this->addError('Closing tag "'.$this->status['tag_name'].'" which is not open');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tag = array(
|
||||||
|
'name' => $this->status['tag_name'],
|
||||||
|
'attrs' => $this->status['attributes'],
|
||||||
|
'children' => array()
|
||||||
|
);
|
||||||
|
if ($this->hierarchy) {
|
||||||
|
$current =& $this->hierarchy[count($this->hierarchy) - 1];
|
||||||
|
$current['children'][] = $tag;
|
||||||
|
$tag =& $current['children'][count($current['children']) - 1];
|
||||||
|
unset($current['tagData']);
|
||||||
|
} else {
|
||||||
|
$this->root = $tag;
|
||||||
|
$tag =& $this->root;
|
||||||
|
$self_close = false;
|
||||||
|
}
|
||||||
|
if (!$self_close) {
|
||||||
|
$this->hierarchy[] =& $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_tag_default() {
|
||||||
|
if (!parent::parse_tag_default()) {return false;}
|
||||||
|
|
||||||
|
if ($this->status['tag_name'][0] !== '?') {
|
||||||
|
$this->parse_hierarchy(($this->status['self_close']) ? true : null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_text() {
|
||||||
|
parent::parse_text();
|
||||||
|
if (($this->status['text'] !== '') && $this->hierarchy) {
|
||||||
|
$current =& $this->hierarchy[count($this->hierarchy) - 1];
|
||||||
|
if (!$current['children']) {
|
||||||
|
$current['tagData'] = $this->status['text'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_all() {
|
||||||
|
return ((parent::parse_all()) ? $this->root : false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
101
lib-3rd-party/pquery/ganon.php
vendored
Normal file
101
lib-3rd-party/pquery/ganon.php
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
use pQuery\Html5Parser;
|
||||||
|
use pQuery\HtmlFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns HTML DOM from string
|
||||||
|
* @param string $str
|
||||||
|
* @param bool $return_root Return root node or return parser object
|
||||||
|
* @return Html5Parser|DomNode
|
||||||
|
*/
|
||||||
|
function str_get_dom($str, $return_root = true) {
|
||||||
|
$a = new Html5Parser($str);
|
||||||
|
return (($return_root) ? $a->root : $a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns HTML DOM from file/website
|
||||||
|
* @param string $str
|
||||||
|
* @param bool $return_root Return root node or return parser object
|
||||||
|
* @param bool $use_include_path Use include path search in file_get_contents
|
||||||
|
* @param resource $context Context resource used in file_get_contents (PHP >= 5.0.0)
|
||||||
|
* @return Html5Parser|DomNode
|
||||||
|
*/
|
||||||
|
function file_get_dom($file, $return_root = true, $use_include_path = false, $context = null) {
|
||||||
|
if (version_compare(PHP_VERSION, '5.0.0', '>='))
|
||||||
|
$f = file_get_contents($file, $use_include_path, $context);
|
||||||
|
else {
|
||||||
|
if ($context !== null)
|
||||||
|
trigger_error('Context parameter not supported in this PHP version');
|
||||||
|
$f = file_get_contents($file, $use_include_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (($f === false) ? false : str_get_dom($f, $return_root));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format/beautify DOM
|
||||||
|
* @param DomNode $root
|
||||||
|
* @param array $options Extra formatting options {@link Formatter::$options}
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function dom_format(&$root, $options = array()) {
|
||||||
|
$formatter = new HtmlFormatter($options);
|
||||||
|
return $formatter->format($root);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
|
||||||
|
/**
|
||||||
|
* PHP alternative to str_split, for backwards compatibility
|
||||||
|
* @param string $string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function str_split($string) {
|
||||||
|
$res = array();
|
||||||
|
$size = strlen($string);
|
||||||
|
for ($i = 0; $i < $size; $i++) {
|
||||||
|
$res[] = $string[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
|
||||||
|
/**
|
||||||
|
* PHP alternative to array_fill_keys, for backwards compatibility
|
||||||
|
* @param array $keys
|
||||||
|
* @param mixed $value
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function array_fill_keys($keys, $value) {
|
||||||
|
$res = array();
|
||||||
|
foreach($keys as $k) {
|
||||||
|
$res[$k] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#!! <- Ignore when converting to single file
|
||||||
|
if (!defined('GANON_NO_INCLUDES')) {
|
||||||
|
define('GANON_NO_INCLUDES', true);
|
||||||
|
include_once('IQuery.php');
|
||||||
|
include_once('gan_tokenizer.php');
|
||||||
|
include_once('gan_parser_html.php');
|
||||||
|
include_once('gan_node_html.php');
|
||||||
|
include_once('gan_selector_html.php');
|
||||||
|
include_once('gan_formatter.php');
|
||||||
|
}
|
||||||
|
#!
|
||||||
|
|
||||||
|
?>
|
279
lib-3rd-party/pquery/pQuery.php
vendored
Normal file
279
lib-3rd-party/pquery/pQuery.php
vendored
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Niels A.D.
|
||||||
|
* @author Todd Burry <todd@vanillaforums.com>
|
||||||
|
* @copyright 2010 Niels A.D., 2014 Todd Burry
|
||||||
|
* @license http://opensource.org/licenses/LGPL-2.1 LGPL-2.1
|
||||||
|
* @package pQuery
|
||||||
|
*/
|
||||||
|
|
||||||
|
use pQuery\IQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A jQuery-like object for php.
|
||||||
|
*/
|
||||||
|
class pQuery implements ArrayAccess, IteratorAggregate, IQuery {
|
||||||
|
/// Properties ///
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var IQuery[]
|
||||||
|
*/
|
||||||
|
protected $nodes = array();
|
||||||
|
|
||||||
|
/// Methods ///
|
||||||
|
|
||||||
|
public function __construct($nodes = array()) {
|
||||||
|
$this->nodes = $nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addClass($classname) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->addClass($classname);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function after($content) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->after($content);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append($content) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->append($content);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attr($name, $value = null) {
|
||||||
|
if (empty($this->nodes) && $value === null)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->attr($name);
|
||||||
|
$node->attr($name, $value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function before($content) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->before($content);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clear() {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->clear();
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the count of matched elements.
|
||||||
|
*
|
||||||
|
* @return int Returns the count of matched elements.
|
||||||
|
*/
|
||||||
|
public function count() {
|
||||||
|
return count($this->nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format/beautify a DOM.
|
||||||
|
*
|
||||||
|
* @param pQuery\DomNode $dom The dom to format.
|
||||||
|
* @param array $options Extra formatting options. See {@link pQuery\HtmlFormatter::$options}.
|
||||||
|
* @return bool Returns `true` on sucess and `false` on failure.
|
||||||
|
*/
|
||||||
|
// public static function format($dom, $options = array()) {
|
||||||
|
// $formatter = new pQuery\HtmlFormatter($options);
|
||||||
|
// return $formatter->format($dom);
|
||||||
|
// }
|
||||||
|
|
||||||
|
public function getIterator() {
|
||||||
|
return new ArrayIterator($this->nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasClass($classname) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($node->hasClass($classname))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function html($value = null) {
|
||||||
|
if (empty($this->nodes) && $value === null)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->html();
|
||||||
|
$node->html($value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetExists($offset) {
|
||||||
|
return isset($this->nodes[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetGet($offset) {
|
||||||
|
return isset($this->nodes[$offset]) ? $this->nodes[$offset] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetSet($offset, $value) {
|
||||||
|
|
||||||
|
if (is_null($offset) || !isset($this->nodes[$offset])) {
|
||||||
|
throw new \BadMethodCallException("You are not allowed to add new nodes to the pQuery object.");
|
||||||
|
} else {
|
||||||
|
$this->nodes[$offset]->replaceWith($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function offsetUnset($offset) {
|
||||||
|
if (isset($this->nodes[$offset])) {
|
||||||
|
$this->nodes[$offset]->remove();
|
||||||
|
unset($this->nodes[$offset]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query a file or url.
|
||||||
|
*
|
||||||
|
* @param string $path The path to the url.
|
||||||
|
* @param resource $context A context suitable to be passed into {@link file_get_contents}
|
||||||
|
* @return pQuery\DomNode Returns the root dom node for the html file.
|
||||||
|
*/
|
||||||
|
public static function parseFile($path, $context = null) {
|
||||||
|
$html_str = file_get_contents($path, false, $context);
|
||||||
|
return static::parseStr($html_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query a string of html.
|
||||||
|
*
|
||||||
|
* @param string $html
|
||||||
|
* @return pQuery\DomNode Returns the root dom node for the html string.
|
||||||
|
*/
|
||||||
|
public static function parseStr($html) {
|
||||||
|
$parser = new pQuery\Html5Parser($html);
|
||||||
|
return $parser->root;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepend($content = null) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->prepend($content);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prop($name, $value = null) {
|
||||||
|
if (empty($this->nodes) && $value === null)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->prop($name);
|
||||||
|
$node->prop($name, $value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove($selector = null) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->remove($selector);
|
||||||
|
}
|
||||||
|
if ($selector === null)
|
||||||
|
$this->nodes = array();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeAttr($name) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->removeAttr($name);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeClass($classname) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->removeClass($classname);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function replaceWith($content) {
|
||||||
|
foreach ($this->nodes as &$node) {
|
||||||
|
$node = $node->replaceWith($content);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tagName($value = null) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->tagName();
|
||||||
|
$node->tagName($value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function text($value = null) {
|
||||||
|
if (empty($this->nodes) && $value === null)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->text();
|
||||||
|
$node->text($value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toggleClass($classname, $switch = null) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->toggleClass($classname, $switch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unwrap() {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->unwrap();
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function val($value = null) {
|
||||||
|
if (empty($this->nodes) && $value === null)
|
||||||
|
return '';
|
||||||
|
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
if ($value === null)
|
||||||
|
return $node->val();
|
||||||
|
$node->val($value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function wrap($wrapping_element) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->wrap($wrapping_element);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function wrapInner($wrapping_element) {
|
||||||
|
foreach ($this->nodes as $node) {
|
||||||
|
$node->wrapInner($wrapping_element);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
2086
lib-3rd-party/pquery/third_party/jsminplus.php
vendored
Normal file
2086
lib-3rd-party/pquery/third_party/jsminplus.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user