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.../httpdocs/wp-conte.../plugins/sitepres.../lib/twig/src/NodeVisi...
File: EscaperNodeVisitor.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Twig.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier
[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 WPML\Core\Twig\NodeVisitor;
[10] Fix | Delete
[11] Fix | Delete
use WPML\Core\Twig\Environment;
[12] Fix | Delete
use WPML\Core\Twig\Node\AutoEscapeNode;
[13] Fix | Delete
use WPML\Core\Twig\Node\BlockNode;
[14] Fix | Delete
use WPML\Core\Twig\Node\BlockReferenceNode;
[15] Fix | Delete
use WPML\Core\Twig\Node\DoNode;
[16] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConditionalExpression;
[17] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConstantExpression;
[18] Fix | Delete
use WPML\Core\Twig\Node\Expression\FilterExpression;
[19] Fix | Delete
use WPML\Core\Twig\Node\Expression\InlinePrint;
[20] Fix | Delete
use WPML\Core\Twig\Node\ImportNode;
[21] Fix | Delete
use WPML\Core\Twig\Node\ModuleNode;
[22] Fix | Delete
use WPML\Core\Twig\Node\Node;
[23] Fix | Delete
use WPML\Core\Twig\Node\PrintNode;
[24] Fix | Delete
use WPML\Core\Twig\NodeTraverser;
[25] Fix | Delete
/**
[26] Fix | Delete
* @final
[27] Fix | Delete
*
[28] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[29] Fix | Delete
*/
[30] Fix | Delete
class EscaperNodeVisitor extends \WPML\Core\Twig\NodeVisitor\AbstractNodeVisitor
[31] Fix | Delete
{
[32] Fix | Delete
protected $statusStack = [];
[33] Fix | Delete
protected $blocks = [];
[34] Fix | Delete
protected $safeAnalysis;
[35] Fix | Delete
protected $traverser;
[36] Fix | Delete
protected $defaultStrategy = \false;
[37] Fix | Delete
protected $safeVars = [];
[38] Fix | Delete
public function __construct()
[39] Fix | Delete
{
[40] Fix | Delete
$this->safeAnalysis = new \WPML\Core\Twig\NodeVisitor\SafeAnalysisNodeVisitor();
[41] Fix | Delete
}
[42] Fix | Delete
protected function doEnterNode(\WPML\Core\Twig\Node\Node $node, \WPML\Core\Twig\Environment $env)
[43] Fix | Delete
{
[44] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\ModuleNode) {
[45] Fix | Delete
if ($env->hasExtension('WPML\\Core\\Twig\\Extension\\EscaperExtension') && ($defaultStrategy = $env->getExtension('WPML\\Core\\Twig\\Extension\\EscaperExtension')->getDefaultStrategy($node->getTemplateName()))) {
[46] Fix | Delete
$this->defaultStrategy = $defaultStrategy;
[47] Fix | Delete
}
[48] Fix | Delete
$this->safeVars = [];
[49] Fix | Delete
$this->blocks = [];
[50] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\AutoEscapeNode) {
[51] Fix | Delete
$this->statusStack[] = $node->getAttribute('value');
[52] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\BlockNode) {
[53] Fix | Delete
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
[54] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\ImportNode) {
[55] Fix | Delete
$this->safeVars[] = $node->getNode('var')->getAttribute('name');
[56] Fix | Delete
}
[57] Fix | Delete
return $node;
[58] Fix | Delete
}
[59] Fix | Delete
protected function doLeaveNode(\WPML\Core\Twig\Node\Node $node, \WPML\Core\Twig\Environment $env)
[60] Fix | Delete
{
[61] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\ModuleNode) {
[62] Fix | Delete
$this->defaultStrategy = \false;
[63] Fix | Delete
$this->safeVars = [];
[64] Fix | Delete
$this->blocks = [];
[65] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\FilterExpression) {
[66] Fix | Delete
return $this->preEscapeFilterNode($node, $env);
[67] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\PrintNode && \false !== ($type = $this->needEscaping($env))) {
[68] Fix | Delete
$expression = $node->getNode('expr');
[69] Fix | Delete
if ($expression instanceof \WPML\Core\Twig\Node\Expression\ConditionalExpression && $this->shouldUnwrapConditional($expression, $env, $type)) {
[70] Fix | Delete
return new \WPML\Core\Twig\Node\DoNode($this->unwrapConditional($expression, $env, $type), $expression->getTemplateLine());
[71] Fix | Delete
}
[72] Fix | Delete
return $this->escapePrintNode($node, $env, $type);
[73] Fix | Delete
}
[74] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\AutoEscapeNode || $node instanceof \WPML\Core\Twig\Node\BlockNode) {
[75] Fix | Delete
\array_pop($this->statusStack);
[76] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\BlockReferenceNode) {
[77] Fix | Delete
$this->blocks[$node->getAttribute('name')] = $this->needEscaping($env);
[78] Fix | Delete
}
[79] Fix | Delete
return $node;
[80] Fix | Delete
}
[81] Fix | Delete
private function shouldUnwrapConditional(\WPML\Core\Twig\Node\Expression\ConditionalExpression $expression, \WPML\Core\Twig\Environment $env, $type)
[82] Fix | Delete
{
[83] Fix | Delete
$expr2Safe = $this->isSafeFor($type, $expression->getNode('expr2'), $env);
[84] Fix | Delete
$expr3Safe = $this->isSafeFor($type, $expression->getNode('expr3'), $env);
[85] Fix | Delete
return $expr2Safe !== $expr3Safe;
[86] Fix | Delete
}
[87] Fix | Delete
private function unwrapConditional(\WPML\Core\Twig\Node\Expression\ConditionalExpression $expression, \WPML\Core\Twig\Environment $env, $type)
[88] Fix | Delete
{
[89] Fix | Delete
// convert "echo a ? b : c" to "a ? echo b : echo c" recursively
[90] Fix | Delete
$expr2 = $expression->getNode('expr2');
[91] Fix | Delete
if ($expr2 instanceof \WPML\Core\Twig\Node\Expression\ConditionalExpression && $this->shouldUnwrapConditional($expr2, $env, $type)) {
[92] Fix | Delete
$expr2 = $this->unwrapConditional($expr2, $env, $type);
[93] Fix | Delete
} else {
[94] Fix | Delete
$expr2 = $this->escapeInlinePrintNode(new \WPML\Core\Twig\Node\Expression\InlinePrint($expr2, $expr2->getTemplateLine()), $env, $type);
[95] Fix | Delete
}
[96] Fix | Delete
$expr3 = $expression->getNode('expr3');
[97] Fix | Delete
if ($expr3 instanceof \WPML\Core\Twig\Node\Expression\ConditionalExpression && $this->shouldUnwrapConditional($expr3, $env, $type)) {
[98] Fix | Delete
$expr3 = $this->unwrapConditional($expr3, $env, $type);
[99] Fix | Delete
} else {
[100] Fix | Delete
$expr3 = $this->escapeInlinePrintNode(new \WPML\Core\Twig\Node\Expression\InlinePrint($expr3, $expr3->getTemplateLine()), $env, $type);
[101] Fix | Delete
}
[102] Fix | Delete
return new \WPML\Core\Twig\Node\Expression\ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine());
[103] Fix | Delete
}
[104] Fix | Delete
private function escapeInlinePrintNode(\WPML\Core\Twig\Node\Expression\InlinePrint $node, \WPML\Core\Twig\Environment $env, $type)
[105] Fix | Delete
{
[106] Fix | Delete
$expression = $node->getNode('node');
[107] Fix | Delete
if ($this->isSafeFor($type, $expression, $env)) {
[108] Fix | Delete
return $node;
[109] Fix | Delete
}
[110] Fix | Delete
return new \WPML\Core\Twig\Node\Expression\InlinePrint($this->getEscaperFilter($type, $expression), $node->getTemplateLine());
[111] Fix | Delete
}
[112] Fix | Delete
protected function escapePrintNode(\WPML\Core\Twig\Node\PrintNode $node, \WPML\Core\Twig\Environment $env, $type)
[113] Fix | Delete
{
[114] Fix | Delete
if (\false === $type) {
[115] Fix | Delete
return $node;
[116] Fix | Delete
}
[117] Fix | Delete
$expression = $node->getNode('expr');
[118] Fix | Delete
if ($this->isSafeFor($type, $expression, $env)) {
[119] Fix | Delete
return $node;
[120] Fix | Delete
}
[121] Fix | Delete
$class = \get_class($node);
[122] Fix | Delete
return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine());
[123] Fix | Delete
}
[124] Fix | Delete
protected function preEscapeFilterNode(\WPML\Core\Twig\Node\Expression\FilterExpression $filter, \WPML\Core\Twig\Environment $env)
[125] Fix | Delete
{
[126] Fix | Delete
$name = $filter->getNode('filter')->getAttribute('value');
[127] Fix | Delete
$type = $env->getFilter($name)->getPreEscape();
[128] Fix | Delete
if (null === $type) {
[129] Fix | Delete
return $filter;
[130] Fix | Delete
}
[131] Fix | Delete
$node = $filter->getNode('node');
[132] Fix | Delete
if ($this->isSafeFor($type, $node, $env)) {
[133] Fix | Delete
return $filter;
[134] Fix | Delete
}
[135] Fix | Delete
$filter->setNode('node', $this->getEscaperFilter($type, $node));
[136] Fix | Delete
return $filter;
[137] Fix | Delete
}
[138] Fix | Delete
protected function isSafeFor($type, \WPML\Core\Twig_NodeInterface $expression, $env)
[139] Fix | Delete
{
[140] Fix | Delete
$safe = $this->safeAnalysis->getSafe($expression);
[141] Fix | Delete
if (null === $safe) {
[142] Fix | Delete
if (null === $this->traverser) {
[143] Fix | Delete
$this->traverser = new \WPML\Core\Twig\NodeTraverser($env, [$this->safeAnalysis]);
[144] Fix | Delete
}
[145] Fix | Delete
$this->safeAnalysis->setSafeVars($this->safeVars);
[146] Fix | Delete
$this->traverser->traverse($expression);
[147] Fix | Delete
$safe = $this->safeAnalysis->getSafe($expression);
[148] Fix | Delete
}
[149] Fix | Delete
return \in_array($type, $safe) || \in_array('all', $safe);
[150] Fix | Delete
}
[151] Fix | Delete
protected function needEscaping(\WPML\Core\Twig\Environment $env)
[152] Fix | Delete
{
[153] Fix | Delete
if (\count($this->statusStack)) {
[154] Fix | Delete
return $this->statusStack[\count($this->statusStack) - 1];
[155] Fix | Delete
}
[156] Fix | Delete
return $this->defaultStrategy ? $this->defaultStrategy : \false;
[157] Fix | Delete
}
[158] Fix | Delete
protected function getEscaperFilter($type, \WPML\Core\Twig_NodeInterface $node)
[159] Fix | Delete
{
[160] Fix | Delete
$line = $node->getTemplateLine();
[161] Fix | Delete
$name = new \WPML\Core\Twig\Node\Expression\ConstantExpression('escape', $line);
[162] Fix | Delete
$args = new \WPML\Core\Twig\Node\Node([new \WPML\Core\Twig\Node\Expression\ConstantExpression((string) $type, $line), new \WPML\Core\Twig\Node\Expression\ConstantExpression(null, $line), new \WPML\Core\Twig\Node\Expression\ConstantExpression(\true, $line)]);
[163] Fix | Delete
return new \WPML\Core\Twig\Node\Expression\FilterExpression($node, $name, $args, $line);
[164] Fix | Delete
}
[165] Fix | Delete
public function getPriority()
[166] Fix | Delete
{
[167] Fix | Delete
return 0;
[168] Fix | Delete
}
[169] Fix | Delete
}
[170] Fix | Delete
\class_alias('WPML\\Core\\Twig\\NodeVisitor\\EscaperNodeVisitor', 'WPML\\Core\\Twig_NodeVisitor_Escaper');
[171] Fix | Delete
[172] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function