AbstractExtension.php
2 years ago
AttributeMatchingExtension.php
2 years ago
CombinationExtension.php
2 years ago
ExtensionInterface.php
2 years ago
FunctionExtension.php
2 years ago
HtmlExtension.php
2 years ago
NodeExtension.php
2 years ago
PseudoClassExtension.php
2 years ago
index.php
2 years ago
HtmlExtension.php
70 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\CssSelector\XPath\Extension; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\CssSelector\Exception\ExpressionErrorException; |
| 5 | use MailPoetVendor\Symfony\Component\CssSelector\Node\FunctionNode; |
| 6 | use MailPoetVendor\Symfony\Component\CssSelector\XPath\Translator; |
| 7 | use MailPoetVendor\Symfony\Component\CssSelector\XPath\XPathExpr; |
| 8 | class HtmlExtension extends AbstractExtension |
| 9 | { |
| 10 | public function __construct(Translator $translator) |
| 11 | { |
| 12 | $translator->getExtension('node')->setFlag(NodeExtension::ELEMENT_NAME_IN_LOWER_CASE, \true)->setFlag(NodeExtension::ATTRIBUTE_NAME_IN_LOWER_CASE, \true); |
| 13 | } |
| 14 | public function getPseudoClassTranslators() : array |
| 15 | { |
| 16 | return ['checked' => [$this, 'translateChecked'], 'link' => [$this, 'translateLink'], 'disabled' => [$this, 'translateDisabled'], 'enabled' => [$this, 'translateEnabled'], 'selected' => [$this, 'translateSelected'], 'invalid' => [$this, 'translateInvalid'], 'hover' => [$this, 'translateHover'], 'visited' => [$this, 'translateVisited']]; |
| 17 | } |
| 18 | public function getFunctionTranslators() : array |
| 19 | { |
| 20 | return ['lang' => [$this, 'translateLang']]; |
| 21 | } |
| 22 | public function translateChecked(XPathExpr $xpath) : XPathExpr |
| 23 | { |
| 24 | return $xpath->addCondition('(@checked ' . "and (name(.) = 'input' or name(.) = 'command')" . "and (@type = 'checkbox' or @type = 'radio'))"); |
| 25 | } |
| 26 | public function translateLink(XPathExpr $xpath) : XPathExpr |
| 27 | { |
| 28 | return $xpath->addCondition("@href and (name(.) = 'a' or name(.) = 'link' or name(.) = 'area')"); |
| 29 | } |
| 30 | public function translateDisabled(XPathExpr $xpath) : XPathExpr |
| 31 | { |
| 32 | return $xpath->addCondition('(' . '@disabled and' . '(' . "(name(.) = 'input' and @type != 'hidden')" . " or name(.) = 'button'" . " or name(.) = 'select'" . " or name(.) = 'textarea'" . " or name(.) = 'command'" . " or name(.) = 'fieldset'" . " or name(.) = 'optgroup'" . " or name(.) = 'option'" . ')' . ') or (' . "(name(.) = 'input' and @type != 'hidden')" . " or name(.) = 'button'" . " or name(.) = 'select'" . " or name(.) = 'textarea'" . ')' . ' and ancestor::fieldset[@disabled]'); |
| 33 | // todo: in the second half, add "and is not a descendant of that fieldset element's first legend element child, if any." |
| 34 | } |
| 35 | public function translateEnabled(XPathExpr $xpath) : XPathExpr |
| 36 | { |
| 37 | return $xpath->addCondition('(' . '@href and (' . "name(.) = 'a'" . " or name(.) = 'link'" . " or name(.) = 'area'" . ')' . ') or (' . '(' . "name(.) = 'command'" . " or name(.) = 'fieldset'" . " or name(.) = 'optgroup'" . ')' . ' and not(@disabled)' . ') or (' . '(' . "(name(.) = 'input' and @type != 'hidden')" . " or name(.) = 'button'" . " or name(.) = 'select'" . " or name(.) = 'textarea'" . " or name(.) = 'keygen'" . ')' . ' and not (@disabled or ancestor::fieldset[@disabled])' . ') or (' . "name(.) = 'option' and not(" . '@disabled or ancestor::optgroup[@disabled]' . ')' . ')'); |
| 38 | } |
| 39 | public function translateLang(XPathExpr $xpath, FunctionNode $function) : XPathExpr |
| 40 | { |
| 41 | $arguments = $function->getArguments(); |
| 42 | foreach ($arguments as $token) { |
| 43 | if (!($token->isString() || $token->isIdentifier())) { |
| 44 | throw new ExpressionErrorException('Expected a single string or identifier for :lang(), got ' . \implode(', ', $arguments)); |
| 45 | } |
| 46 | } |
| 47 | return $xpath->addCondition(\sprintf('ancestor-or-self::*[@lang][1][starts-with(concat(' . "translate(@%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '-')" . ', %s)]', 'lang', Translator::getXpathLiteral(\strtolower($arguments[0]->getValue()) . '-'))); |
| 48 | } |
| 49 | public function translateSelected(XPathExpr $xpath) : XPathExpr |
| 50 | { |
| 51 | return $xpath->addCondition("(@selected and name(.) = 'option')"); |
| 52 | } |
| 53 | public function translateInvalid(XPathExpr $xpath) : XPathExpr |
| 54 | { |
| 55 | return $xpath->addCondition('0'); |
| 56 | } |
| 57 | public function translateHover(XPathExpr $xpath) : XPathExpr |
| 58 | { |
| 59 | return $xpath->addCondition('0'); |
| 60 | } |
| 61 | public function translateVisited(XPathExpr $xpath) : XPathExpr |
| 62 | { |
| 63 | return $xpath->addCondition('0'); |
| 64 | } |
| 65 | public function getName() : string |
| 66 | { |
| 67 | return 'html'; |
| 68 | } |
| 69 | } |
| 70 |