|
Server : LiteSpeed System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64 User : nandedex ( 1060) PHP Version : 8.1.33 Disable Function : NONE Directory : /home/nandedex/.cagefs/tmp/ |
class-wp-html-attribute-token.php 0000644 00000005327 15121264543 0013101 0 ustar 00 <?php
/**
* HTML API: WP_HTML_Attribute_Token class
*
* @package WordPress
* @subpackage HTML-API
* @since 6.2.0
*/
/**
* Core class used by the HTML tag processor as a data structure for the attribute token,
* allowing to drastically improve performance.
*
* This class is for internal usage of the WP_HTML_Tag_Processor class.
*
* @access private
* @since 6.2.0
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
*
* @see WP_HTML_Tag_Processor
*/
class WP_HTML_Attribute_Token {
/**
* Attribute name.
*
* @since 6.2.0
*
* @var string
*/
public $name;
/**
* Attribute value.
*
* @since 6.2.0
*
* @var int
*/
public $value_starts_at;
/**
* How many bytes the value occupies in the input HTML.
*
* @since 6.2.0
*
* @var int
*/
public $value_length;
/**
* The string offset where the attribute name starts.
*
* @since 6.2.0
*
* @var int
*/
public $start;
/**
* Byte length of text spanning the attribute inside a tag.
*
* This span starts at the first character of the attribute name
* and it ends after one of three cases:
*
* - at the end of the attribute name for boolean attributes.
* - at the end of the value for unquoted attributes.
* - at the final single or double quote for quoted attributes.
*
* Example:
*
* <div class="post">
* ------------ length is 12, including quotes
*
* <input type="checked" checked id="selector">
* ------- length is 6
*
* <a rel=noopener>
* ------------ length is 11
*
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
*
* @var int
*/
public $length;
/**
* Whether the attribute is a boolean attribute with value `true`.
*
* @since 6.2.0
*
* @var bool
*/
public $is_true;
/**
* Constructor.
*
* @since 6.2.0
* @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
*
* @param string $name Attribute name.
* @param int $value_start Attribute value.
* @param int $value_length Number of bytes attribute value spans.
* @param int $start The string offset where the attribute name starts.
* @param int $length Byte length of the entire attribute name or name and value pair expression.
* @param bool $is_true Whether the attribute is a boolean attribute with true value.
*/
public function __construct( $name, $value_start, $value_length, $start, $length, $is_true ) {
$this->name = $name;
$this->value_starts_at = $value_start;
$this->value_length = $value_length;
$this->start = $start;
$this->length = $length;
$this->is_true = $is_true;
}
}
class-wp-html-token.php 0000644 00000006522 15121264543 0011076 0 ustar 00 <?php
/**
* HTML API: WP_HTML_Token class
*
* @package WordPress
* @subpackage HTML-API
* @since 6.4.0
*/
/**
* Core class used by the HTML processor during HTML parsing
* for referring to tokens in the input HTML string.
*
* This class is designed for internal use by the HTML processor.
*
* @since 6.4.0
*
* @access private
*
* @see WP_HTML_Processor
*/
class WP_HTML_Token {
/**
* Name of bookmark corresponding to source of token in input HTML string.
*
* Having a bookmark name does not imply that the token still exists. It
* may be that the source token and underlying bookmark was wiped out by
* some modification to the source HTML.
*
* @since 6.4.0
*
* @var string
*/
public $bookmark_name = null;
/**
* Name of node; lowercase names such as "marker" are not HTML elements.
*
* For HTML elements/tags this value should come from WP_HTML_Processor::get_tag().
*
* @since 6.4.0
*
* @see WP_HTML_Processor::get_tag()
*
* @var string
*/
public $node_name = null;
/**
* Whether node contains the self-closing flag.
*
* A node may have a self-closing flag when it shouldn't. This value
* only reports if the flag is present in the original HTML.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#self-closing-flag
*
* @var bool
*/
public $has_self_closing_flag = false;
/**
* Indicates if the element is an HTML element or if it's inside foreign content.
*
* @since 6.7.0
*
* @var string 'html', 'svg', or 'math'.
*/
public $namespace = 'html';
/**
* Indicates which kind of integration point the element is, if any.
*
* @since 6.7.0
*
* @var string|null 'math', 'html', or null if not an integration point.
*/
public $integration_node_type = null;
/**
* Called when token is garbage-collected or otherwise destroyed.
*
* @var callable|null
*/
public $on_destroy = null;
/**
* Constructor - creates a reference to a token in some external HTML string.
*
* @since 6.4.0
*
* @param string|null $bookmark_name Name of bookmark corresponding to location in HTML where token is found,
* or `null` for markers and nodes without a bookmark.
* @param string $node_name Name of node token represents; if uppercase, an HTML element; if lowercase, a special value like "marker".
* @param bool $has_self_closing_flag Whether the source token contains the self-closing flag, regardless of whether it's valid.
* @param callable|null $on_destroy Optional. Function to call when destroying token, useful for releasing the bookmark.
*/
public function __construct( ?string $bookmark_name, string $node_name, bool $has_self_closing_flag, ?callable $on_destroy = null ) {
$this->bookmark_name = $bookmark_name;
$this->namespace = 'html';
$this->node_name = $node_name;
$this->has_self_closing_flag = $has_self_closing_flag;
$this->on_destroy = $on_destroy;
}
/**
* Destructor.
*
* @since 6.4.0
*/
public function __destruct() {
if ( is_callable( $this->on_destroy ) ) {
call_user_func( $this->on_destroy, $this->bookmark_name );
}
}
/**
* Wakeup magic method.
*
* @since 6.4.2
*/
public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}
class-wp-html-unsupported-exception.php 0000644 00000007026 15121264543 0014342 0 ustar 00 <?php
/**
* HTML API: WP_HTML_Unsupported_Exception class
*
* @package WordPress
* @subpackage HTML-API
* @since 6.4.0
*/
/**
* Core class used by the HTML processor during HTML parsing
* for indicating that a given operation is unsupported.
*
* This class is designed for internal use by the HTML processor.
*
* The HTML API aims to operate in compliance with the HTML5
* specification, but does not implement the full specification.
* In cases where it lacks support it should not cause breakage
* or unexpected behavior. In the cases where it recognizes that
* it cannot proceed, this class is used to abort from any
* operation and signify that the given HTML cannot be processed.
*
* @since 6.4.0
* @since 6.7.0 Gained contextual information for use in debugging parse failures.
*
* @access private
*
* @see WP_HTML_Processor
*/
class WP_HTML_Unsupported_Exception extends Exception {
/**
* Name of the matched token when the exception was raised,
* if matched on a token.
*
* This does not imply that the token itself was unsupported, but it
* may have been the case that the token triggered part of the HTML
* parsing that isn't supported, such as the adoption agency algorithm.
*
* @since 6.7.0
*
* @var string
*/
public $token_name;
/**
* Number of bytes into the input HTML document where the parser was
* parsing when the exception was raised.
*
* Use this to reconstruct context for the failure.
*
* @since 6.7.0
*
* @var int
*/
public $token_at;
/**
* Full raw text of the matched token when the exception was raised,
* if matched on a token.
*
* Whereas the `$token_name` will be normalized, this contains the full
* raw text of the token, including original casing, duplicated attributes,
* and other syntactic variations that are normally abstracted in the HTML API.
*
* @since 6.7.0
*
* @var string
*/
public $token;
/**
* Stack of open elements when the exception was raised.
*
* Use this to trace the parsing circumstances which led to the exception.
*
* @since 6.7.0
*
* @var string[]
*/
public $stack_of_open_elements = array();
/**
* List of active formatting elements when the exception was raised.
*
* Use this to trace the parsing circumstances which led to the exception.
*
* @since 6.7.0
*
* @var string[]
*/
public $active_formatting_elements = array();
/**
* Constructor function.
*
* @since 6.7.0
*
* @param string $message Brief message explaining what is unsupported, the reason this exception was raised.
* @param string $token_name Normalized name of matched token when this exception was raised.
* @param int $token_at Number of bytes into source HTML document where matched token starts.
* @param string $token Full raw text of matched token when this exception was raised.
* @param string[] $stack_of_open_elements Stack of open elements when this exception was raised.
* @param string[] $active_formatting_elements List of active formatting elements when this exception was raised.
*/
public function __construct( string $message, string $token_name, int $token_at, string $token, array $stack_of_open_elements, array $active_formatting_elements ) {
parent::__construct( $message );
$this->token_name = $token_name;
$this->token_at = $token_at;
$this->token = $token;
$this->stack_of_open_elements = $stack_of_open_elements;
$this->active_formatting_elements = $active_formatting_elements;
}
}
class-wp-html-open-elements.php 0000644 00000053716 15121264543 0012540 0 ustar 00 <?php
/**
* HTML API: WP_HTML_Open_Elements class
*
* @package WordPress
* @subpackage HTML-API
* @since 6.4.0
*/
/**
* Core class used by the HTML processor during HTML parsing
* for managing the stack of open elements.
*
* This class is designed for internal use by the HTML processor.
*
* > Initially, the stack of open elements is empty. The stack grows
* > downwards; the topmost node on the stack is the first one added
* > to the stack, and the bottommost node of the stack is the most
* > recently added node in the stack (notwithstanding when the stack
* > is manipulated in a random access fashion as part of the handling
* > for misnested tags).
*
* @since 6.4.0
*
* @access private
*
* @see https://html.spec.whatwg.org/#stack-of-open-elements
* @see WP_HTML_Processor
*/
class WP_HTML_Open_Elements {
/**
* Holds the stack of open element references.
*
* @since 6.4.0
*
* @var WP_HTML_Token[]
*/
public $stack = array();
/**
* Whether a P element is in button scope currently.
*
* This class optimizes scope lookup by pre-calculating
* this value when elements are added and removed to the
* stack of open elements which might change its value.
* This avoids frequent iteration over the stack.
*
* @since 6.4.0
*
* @var bool
*/
private $has_p_in_button_scope = false;
/**
* A function that will be called when an item is popped off the stack of open elements.
*
* The function will be called with the popped item as its argument.
*
* @since 6.6.0
*
* @var Closure|null
*/
private $pop_handler = null;
/**
* A function that will be called when an item is pushed onto the stack of open elements.
*
* The function will be called with the pushed item as its argument.
*
* @since 6.6.0
*
* @var Closure|null
*/
private $push_handler = null;
/**
* Sets a pop handler that will be called when an item is popped off the stack of
* open elements.
*
* The function will be called with the pushed item as its argument.
*
* @since 6.6.0
*
* @param Closure $handler The handler function.
*/
public function set_pop_handler( Closure $handler ): void {
$this->pop_handler = $handler;
}
/**
* Sets a push handler that will be called when an item is pushed onto the stack of
* open elements.
*
* The function will be called with the pushed item as its argument.
*
* @since 6.6.0
*
* @param Closure $handler The handler function.
*/
public function set_push_handler( Closure $handler ): void {
$this->push_handler = $handler;
}
/**
* Returns the name of the node at the nth position on the stack
* of open elements, or `null` if no such position exists.
*
* Note that this uses a 1-based index, which represents the
* "nth item" on the stack, counting from the top, where the
* top-most element is the 1st, the second is the 2nd, etc...
*
* @since 6.7.0
*
* @param int $nth Retrieve the nth item on the stack, with 1 being
* the top element, 2 being the second, etc...
* @return WP_HTML_Token|null Name of the node on the stack at the given location,
* or `null` if the location isn't on the stack.
*/
public function at( int $nth ): ?WP_HTML_Token {
foreach ( $this->walk_down() as $item ) {
if ( 0 === --$nth ) {
return $item;
}
}
return null;
}
/**
* Reports if a node of a given name is in the stack of open elements.
*
* @since 6.7.0
*
* @param string $node_name Name of node for which to check.
* @return bool Whether a node of the given name is in the stack of open elements.
*/
public function contains( string $node_name ): bool {
foreach ( $this->walk_up() as $item ) {
if ( $node_name === $item->node_name ) {
return true;
}
}
return false;
}
/**
* Reports if a specific node is in the stack of open elements.
*
* @since 6.4.0
*
* @param WP_HTML_Token $token Look for this node in the stack.
* @return bool Whether the referenced node is in the stack of open elements.
*/
public function contains_node( WP_HTML_Token $token ): bool {
foreach ( $this->walk_up() as $item ) {
if ( $token === $item ) {
return true;
}
}
return false;
}
/**
* Returns how many nodes are currently in the stack of open elements.
*
* @since 6.4.0
*
* @return int How many node are in the stack of open elements.
*/
public function count(): int {
return count( $this->stack );
}
/**
* Returns the node at the end of the stack of open elements,
* if one exists. If the stack is empty, returns null.
*
* @since 6.4.0
*
* @return WP_HTML_Token|null Last node in the stack of open elements, if one exists, otherwise null.
*/
public function current_node(): ?WP_HTML_Token {
$current_node = end( $this->stack );
return $current_node ? $current_node : null;
}
/**
* Indicates if the current node is of a given type or name.
*
* It's possible to pass either a node type or a node name to this function.
* In the case there is no current element it will always return `false`.
*
* Example:
*
* // Is the current node a text node?
* $stack->current_node_is( '#text' );
*
* // Is the current node a DIV element?
* $stack->current_node_is( 'DIV' );
*
* // Is the current node any element/tag?
* $stack->current_node_is( '#tag' );
*
* @see WP_HTML_Tag_Processor::get_token_type
* @see WP_HTML_Tag_Processor::get_token_name
*
* @since 6.7.0
*
* @access private
*
* @param string $identity Check if the current node has this name or type (depending on what is provided).
* @return bool Whether there is a current element that matches the given identity, whether a token name or type.
*/
public function current_node_is( string $identity ): bool {
$current_node = end( $this->stack );
if ( false === $current_node ) {
return false;
}
$current_node_name = $current_node->node_name;
return (
$current_node_name === $identity ||
( '#doctype' === $identity && 'html' === $current_node_name ) ||
( '#tag' === $identity && ctype_upper( $current_node_name ) )
);
}
/**
* Returns whether an element is in a specific scope.
*
* @since 6.4.0
*
* @see https://html.spec.whatwg.org/#has-an-element-in-the-specific-scope
*
* @param string $tag_name Name of tag check.
* @param string[] $termination_list List of elements that terminate the search.
* @return bool Whether the element was found in a specific scope.
*/
public function has_element_in_specific_scope( string $tag_name, $termination_list ): bool {
foreach ( $this->walk_up() as $node ) {
$namespaced_name = 'html' === $node->namespace
? $node->node_name
: "{$node->namespace} {$node->node_name}";
if ( $namespaced_name === $tag_name ) {
return true;
}
if (
'(internal: H1 through H6 - do not use)' === $tag_name &&
in_array( $namespaced_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
) {
return true;
}
if ( in_array( $namespaced_name, $termination_list, true ) ) {
return false;
}
}
return false;
}
/**
* Returns whether a particular element is in scope.
*
* > The stack of open elements is said to have a particular element in
* > scope when it has that element in the specific scope consisting of
* > the following element types:
* >
* > - applet
* > - caption
* > - html
* > - table
* > - td
* > - th
* > - marquee
* > - object
* > - template
* > - MathML mi
* > - MathML mo
* > - MathML mn
* > - MathML ms
* > - MathML mtext
* > - MathML annotation-xml
* > - SVG foreignObject
* > - SVG desc
* > - SVG title
*
* @since 6.4.0
* @since 6.7.0 Full support.
*
* @see https://html.spec.whatwg.org/#has-an-element-in-scope
*
* @param string $tag_name Name of tag to check.
* @return bool Whether given element is in scope.
*/
public function has_element_in_scope( string $tag_name ): bool {
return $this->has_element_in_specific_scope(
$tag_name,
array(
'APPLET',
'CAPTION',
'HTML',