Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../www/wp-conte.../plugins/wpforms-.../vendor_p.../symfony/css-sele.../XPath
File: Translator.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
namespace WPForms\Vendor\Symfony\Component\CssSelector\XPath;
[10] Fix | Delete
[11] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Exception\ExpressionErrorException;
[12] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Node\FunctionNode;
[13] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Node\NodeInterface;
[14] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Node\SelectorNode;
[15] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Parser\Parser;
[16] Fix | Delete
use WPForms\Vendor\Symfony\Component\CssSelector\Parser\ParserInterface;
[17] Fix | Delete
/**
[18] Fix | Delete
* XPath expression translator interface.
[19] Fix | Delete
*
[20] Fix | Delete
* This component is a port of the Python cssselect library,
[21] Fix | Delete
* which is copyright Ian Bicking, @see https://github.com/SimonSapin/cssselect.
[22] Fix | Delete
*
[23] Fix | Delete
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
[24] Fix | Delete
*
[25] Fix | Delete
* @internal
[26] Fix | Delete
*/
[27] Fix | Delete
class Translator implements TranslatorInterface
[28] Fix | Delete
{
[29] Fix | Delete
/**
[30] Fix | Delete
* @var ParserInterface
[31] Fix | Delete
*/
[32] Fix | Delete
private $mainParser;
[33] Fix | Delete
/**
[34] Fix | Delete
* @var ParserInterface[]
[35] Fix | Delete
*/
[36] Fix | Delete
private $shortcutParsers = array();
[37] Fix | Delete
/**
[38] Fix | Delete
* @var Extension\ExtensionInterface
[39] Fix | Delete
*/
[40] Fix | Delete
private $extensions = array();
[41] Fix | Delete
/**
[42] Fix | Delete
* @var array
[43] Fix | Delete
*/
[44] Fix | Delete
private $nodeTranslators = array();
[45] Fix | Delete
/**
[46] Fix | Delete
* @var array
[47] Fix | Delete
*/
[48] Fix | Delete
private $combinationTranslators = array();
[49] Fix | Delete
/**
[50] Fix | Delete
* @var array
[51] Fix | Delete
*/
[52] Fix | Delete
private $functionTranslators = array();
[53] Fix | Delete
/**
[54] Fix | Delete
* @var array
[55] Fix | Delete
*/
[56] Fix | Delete
private $pseudoClassTranslators = array();
[57] Fix | Delete
/**
[58] Fix | Delete
* @var array
[59] Fix | Delete
*/
[60] Fix | Delete
private $attributeMatchingTranslators = array();
[61] Fix | Delete
public function __construct(ParserInterface $parser = null)
[62] Fix | Delete
{
[63] Fix | Delete
$this->mainParser = $parser ?: new Parser();
[64] Fix | Delete
$this->registerExtension(new Extension\NodeExtension())->registerExtension(new Extension\CombinationExtension())->registerExtension(new Extension\FunctionExtension())->registerExtension(new Extension\PseudoClassExtension())->registerExtension(new Extension\AttributeMatchingExtension());
[65] Fix | Delete
}
[66] Fix | Delete
/**
[67] Fix | Delete
* @param string $element
[68] Fix | Delete
*
[69] Fix | Delete
* @return string
[70] Fix | Delete
*/
[71] Fix | Delete
public static function getXpathLiteral($element)
[72] Fix | Delete
{
[73] Fix | Delete
if (\false === \strpos($element, "'")) {
[74] Fix | Delete
return "'" . $element . "'";
[75] Fix | Delete
}
[76] Fix | Delete
if (\false === \strpos($element, '"')) {
[77] Fix | Delete
return '"' . $element . '"';
[78] Fix | Delete
}
[79] Fix | Delete
$string = $element;
[80] Fix | Delete
$parts = array();
[81] Fix | Delete
while (\true) {
[82] Fix | Delete
if (\false !== ($pos = \strpos($string, "'"))) {
[83] Fix | Delete
$parts[] = \sprintf("'%s'", \substr($string, 0, $pos));
[84] Fix | Delete
$parts[] = "\"'\"";
[85] Fix | Delete
$string = \substr($string, $pos + 1);
[86] Fix | Delete
} else {
[87] Fix | Delete
$parts[] = "'{$string}'";
[88] Fix | Delete
break;
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
return \sprintf('concat(%s)', \implode($parts, ', '));
[92] Fix | Delete
}
[93] Fix | Delete
/**
[94] Fix | Delete
* {@inheritdoc}
[95] Fix | Delete
*/
[96] Fix | Delete
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::')
[97] Fix | Delete
{
[98] Fix | Delete
$selectors = $this->parseSelectors($cssExpr);
[99] Fix | Delete
/** @var SelectorNode $selector */
[100] Fix | Delete
foreach ($selectors as $index => $selector) {
[101] Fix | Delete
if (null !== $selector->getPseudoElement()) {
[102] Fix | Delete
throw new ExpressionErrorException('Pseudo-elements are not supported.');
[103] Fix | Delete
}
[104] Fix | Delete
$selectors[$index] = $this->selectorToXPath($selector, $prefix);
[105] Fix | Delete
}
[106] Fix | Delete
return \implode(' | ', $selectors);
[107] Fix | Delete
}
[108] Fix | Delete
/**
[109] Fix | Delete
* {@inheritdoc}
[110] Fix | Delete
*/
[111] Fix | Delete
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::')
[112] Fix | Delete
{
[113] Fix | Delete
return ($prefix ?: '') . $this->nodeToXPath($selector);
[114] Fix | Delete
}
[115] Fix | Delete
/**
[116] Fix | Delete
* Registers an extension.
[117] Fix | Delete
*
[118] Fix | Delete
* @param Extension\ExtensionInterface $extension
[119] Fix | Delete
*
[120] Fix | Delete
* @return $this
[121] Fix | Delete
*/
[122] Fix | Delete
public function registerExtension(Extension\ExtensionInterface $extension)
[123] Fix | Delete
{
[124] Fix | Delete
$this->extensions[$extension->getName()] = $extension;
[125] Fix | Delete
$this->nodeTranslators = \array_merge($this->nodeTranslators, $extension->getNodeTranslators());
[126] Fix | Delete
$this->combinationTranslators = \array_merge($this->combinationTranslators, $extension->getCombinationTranslators());
[127] Fix | Delete
$this->functionTranslators = \array_merge($this->functionTranslators, $extension->getFunctionTranslators());
[128] Fix | Delete
$this->pseudoClassTranslators = \array_merge($this->pseudoClassTranslators, $extension->getPseudoClassTranslators());
[129] Fix | Delete
$this->attributeMatchingTranslators = \array_merge($this->attributeMatchingTranslators, $extension->getAttributeMatchingTranslators());
[130] Fix | Delete
return $this;
[131] Fix | Delete
}
[132] Fix | Delete
/**
[133] Fix | Delete
* @param string $name
[134] Fix | Delete
*
[135] Fix | Delete
* @return Extension\ExtensionInterface
[136] Fix | Delete
*
[137] Fix | Delete
* @throws ExpressionErrorException
[138] Fix | Delete
*/
[139] Fix | Delete
public function getExtension($name)
[140] Fix | Delete
{
[141] Fix | Delete
if (!isset($this->extensions[$name])) {
[142] Fix | Delete
throw new ExpressionErrorException(\sprintf('Extension "%s" not registered.', $name));
[143] Fix | Delete
}
[144] Fix | Delete
return $this->extensions[$name];
[145] Fix | Delete
}
[146] Fix | Delete
/**
[147] Fix | Delete
* Registers a shortcut parser.
[148] Fix | Delete
*
[149] Fix | Delete
* @param ParserInterface $shortcut
[150] Fix | Delete
*
[151] Fix | Delete
* @return $this
[152] Fix | Delete
*/
[153] Fix | Delete
public function registerParserShortcut(ParserInterface $shortcut)
[154] Fix | Delete
{
[155] Fix | Delete
$this->shortcutParsers[] = $shortcut;
[156] Fix | Delete
return $this;
[157] Fix | Delete
}
[158] Fix | Delete
/**
[159] Fix | Delete
* @param NodeInterface $node
[160] Fix | Delete
*
[161] Fix | Delete
* @return XPathExpr
[162] Fix | Delete
*
[163] Fix | Delete
* @throws ExpressionErrorException
[164] Fix | Delete
*/
[165] Fix | Delete
public function nodeToXPath(NodeInterface $node)
[166] Fix | Delete
{
[167] Fix | Delete
if (!isset($this->nodeTranslators[$node->getNodeName()])) {
[168] Fix | Delete
throw new ExpressionErrorException(\sprintf('Node "%s" not supported.', $node->getNodeName()));
[169] Fix | Delete
}
[170] Fix | Delete
return \call_user_func($this->nodeTranslators[$node->getNodeName()], $node, $this);
[171] Fix | Delete
}
[172] Fix | Delete
/**
[173] Fix | Delete
* @param string $combiner
[174] Fix | Delete
* @param NodeInterface $xpath
[175] Fix | Delete
* @param NodeInterface $combinedXpath
[176] Fix | Delete
*
[177] Fix | Delete
* @return XPathExpr
[178] Fix | Delete
*
[179] Fix | Delete
* @throws ExpressionErrorException
[180] Fix | Delete
*/
[181] Fix | Delete
public function addCombination($combiner, NodeInterface $xpath, NodeInterface $combinedXpath)
[182] Fix | Delete
{
[183] Fix | Delete
if (!isset($this->combinationTranslators[$combiner])) {
[184] Fix | Delete
throw new ExpressionErrorException(\sprintf('Combiner "%s" not supported.', $combiner));
[185] Fix | Delete
}
[186] Fix | Delete
return \call_user_func($this->combinationTranslators[$combiner], $this->nodeToXPath($xpath), $this->nodeToXPath($combinedXpath));
[187] Fix | Delete
}
[188] Fix | Delete
/**
[189] Fix | Delete
* @param XPathExpr $xpath
[190] Fix | Delete
* @param FunctionNode $function
[191] Fix | Delete
*
[192] Fix | Delete
* @return XPathExpr
[193] Fix | Delete
*
[194] Fix | Delete
* @throws ExpressionErrorException
[195] Fix | Delete
*/
[196] Fix | Delete
public function addFunction(XPathExpr $xpath, FunctionNode $function)
[197] Fix | Delete
{
[198] Fix | Delete
if (!isset($this->functionTranslators[$function->getName()])) {
[199] Fix | Delete
throw new ExpressionErrorException(\sprintf('Function "%s" not supported.', $function->getName()));
[200] Fix | Delete
}
[201] Fix | Delete
return \call_user_func($this->functionTranslators[$function->getName()], $xpath, $function);
[202] Fix | Delete
}
[203] Fix | Delete
/**
[204] Fix | Delete
* @param XPathExpr $xpath
[205] Fix | Delete
* @param string $pseudoClass
[206] Fix | Delete
*
[207] Fix | Delete
* @return XPathExpr
[208] Fix | Delete
*
[209] Fix | Delete
* @throws ExpressionErrorException
[210] Fix | Delete
*/
[211] Fix | Delete
public function addPseudoClass(XPathExpr $xpath, $pseudoClass)
[212] Fix | Delete
{
[213] Fix | Delete
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
[214] Fix | Delete
throw new ExpressionErrorException(\sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
[215] Fix | Delete
}
[216] Fix | Delete
return \call_user_func($this->pseudoClassTranslators[$pseudoClass], $xpath);
[217] Fix | Delete
}
[218] Fix | Delete
/**
[219] Fix | Delete
* @param XPathExpr $xpath
[220] Fix | Delete
* @param string $operator
[221] Fix | Delete
* @param string $attribute
[222] Fix | Delete
* @param string $value
[223] Fix | Delete
*
[224] Fix | Delete
* @return XPathExpr
[225] Fix | Delete
*
[226] Fix | Delete
* @throws ExpressionErrorException
[227] Fix | Delete
*/
[228] Fix | Delete
public function addAttributeMatching(XPathExpr $xpath, $operator, $attribute, $value)
[229] Fix | Delete
{
[230] Fix | Delete
if (!isset($this->attributeMatchingTranslators[$operator])) {
[231] Fix | Delete
throw new ExpressionErrorException(\sprintf('Attribute matcher operator "%s" not supported.', $operator));
[232] Fix | Delete
}
[233] Fix | Delete
return \call_user_func($this->attributeMatchingTranslators[$operator], $xpath, $attribute, $value);
[234] Fix | Delete
}
[235] Fix | Delete
/**
[236] Fix | Delete
* @param string $css
[237] Fix | Delete
*
[238] Fix | Delete
* @return SelectorNode[]
[239] Fix | Delete
*/
[240] Fix | Delete
private function parseSelectors($css)
[241] Fix | Delete
{
[242] Fix | Delete
foreach ($this->shortcutParsers as $shortcut) {
[243] Fix | Delete
$tokens = $shortcut->parse($css);
[244] Fix | Delete
if (!empty($tokens)) {
[245] Fix | Delete
return $tokens;
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
return $this->mainParser->parse($css);
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function