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: SafeAnalysisNodeVisitor.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\Expression\BlockReferenceExpression;
[13] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConditionalExpression;
[14] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConstantExpression;
[15] Fix | Delete
use WPML\Core\Twig\Node\Expression\FilterExpression;
[16] Fix | Delete
use WPML\Core\Twig\Node\Expression\FunctionExpression;
[17] Fix | Delete
use WPML\Core\Twig\Node\Expression\GetAttrExpression;
[18] Fix | Delete
use WPML\Core\Twig\Node\Expression\MethodCallExpression;
[19] Fix | Delete
use WPML\Core\Twig\Node\Expression\NameExpression;
[20] Fix | Delete
use WPML\Core\Twig\Node\Expression\ParentExpression;
[21] Fix | Delete
use WPML\Core\Twig\Node\Node;
[22] Fix | Delete
/**
[23] Fix | Delete
* @final
[24] Fix | Delete
*/
[25] Fix | Delete
class SafeAnalysisNodeVisitor extends \WPML\Core\Twig\NodeVisitor\AbstractNodeVisitor
[26] Fix | Delete
{
[27] Fix | Delete
protected $data = [];
[28] Fix | Delete
protected $safeVars = [];
[29] Fix | Delete
public function setSafeVars($safeVars)
[30] Fix | Delete
{
[31] Fix | Delete
$this->safeVars = $safeVars;
[32] Fix | Delete
}
[33] Fix | Delete
public function getSafe(\WPML\Core\Twig_NodeInterface $node)
[34] Fix | Delete
{
[35] Fix | Delete
$hash = \spl_object_hash($node);
[36] Fix | Delete
if (!isset($this->data[$hash])) {
[37] Fix | Delete
return;
[38] Fix | Delete
}
[39] Fix | Delete
foreach ($this->data[$hash] as $bucket) {
[40] Fix | Delete
if ($bucket['key'] !== $node) {
[41] Fix | Delete
continue;
[42] Fix | Delete
}
[43] Fix | Delete
if (\in_array('html_attr', $bucket['value'])) {
[44] Fix | Delete
$bucket['value'][] = 'html';
[45] Fix | Delete
}
[46] Fix | Delete
return $bucket['value'];
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
protected function setSafe(\WPML\Core\Twig_NodeInterface $node, array $safe)
[50] Fix | Delete
{
[51] Fix | Delete
$hash = \spl_object_hash($node);
[52] Fix | Delete
if (isset($this->data[$hash])) {
[53] Fix | Delete
foreach ($this->data[$hash] as &$bucket) {
[54] Fix | Delete
if ($bucket['key'] === $node) {
[55] Fix | Delete
$bucket['value'] = $safe;
[56] Fix | Delete
return;
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
$this->data[$hash][] = ['key' => $node, 'value' => $safe];
[61] Fix | Delete
}
[62] Fix | Delete
protected function doEnterNode(\WPML\Core\Twig\Node\Node $node, \WPML\Core\Twig\Environment $env)
[63] Fix | Delete
{
[64] Fix | Delete
return $node;
[65] Fix | Delete
}
[66] Fix | Delete
protected function doLeaveNode(\WPML\Core\Twig\Node\Node $node, \WPML\Core\Twig\Environment $env)
[67] Fix | Delete
{
[68] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression) {
[69] Fix | Delete
// constants are marked safe for all
[70] Fix | Delete
$this->setSafe($node, ['all']);
[71] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\BlockReferenceExpression) {
[72] Fix | Delete
// blocks are safe by definition
[73] Fix | Delete
$this->setSafe($node, ['all']);
[74] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\ParentExpression) {
[75] Fix | Delete
// parent block is safe by definition
[76] Fix | Delete
$this->setSafe($node, ['all']);
[77] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\ConditionalExpression) {
[78] Fix | Delete
// intersect safeness of both operands
[79] Fix | Delete
$safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3')));
[80] Fix | Delete
$this->setSafe($node, $safe);
[81] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\FilterExpression) {
[82] Fix | Delete
// filter expression is safe when the filter is safe
[83] Fix | Delete
$name = $node->getNode('filter')->getAttribute('value');
[84] Fix | Delete
$args = $node->getNode('arguments');
[85] Fix | Delete
if (\false !== ($filter = $env->getFilter($name))) {
[86] Fix | Delete
$safe = $filter->getSafe($args);
[87] Fix | Delete
if (null === $safe) {
[88] Fix | Delete
$safe = $this->intersectSafe($this->getSafe($node->getNode('node')), $filter->getPreservesSafety());
[89] Fix | Delete
}
[90] Fix | Delete
$this->setSafe($node, $safe);
[91] Fix | Delete
} else {
[92] Fix | Delete
$this->setSafe($node, []);
[93] Fix | Delete
}
[94] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\FunctionExpression) {
[95] Fix | Delete
// function expression is safe when the function is safe
[96] Fix | Delete
$name = $node->getAttribute('name');
[97] Fix | Delete
$args = $node->getNode('arguments');
[98] Fix | Delete
$function = $env->getFunction($name);
[99] Fix | Delete
if (\false !== $function) {
[100] Fix | Delete
$this->setSafe($node, $function->getSafe($args));
[101] Fix | Delete
} else {
[102] Fix | Delete
$this->setSafe($node, []);
[103] Fix | Delete
}
[104] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\MethodCallExpression) {
[105] Fix | Delete
if ($node->getAttribute('safe')) {
[106] Fix | Delete
$this->setSafe($node, ['all']);
[107] Fix | Delete
} else {
[108] Fix | Delete
$this->setSafe($node, []);
[109] Fix | Delete
}
[110] Fix | Delete
} elseif ($node instanceof \WPML\Core\Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \WPML\Core\Twig\Node\Expression\NameExpression) {
[111] Fix | Delete
$name = $node->getNode('node')->getAttribute('name');
[112] Fix | Delete
// attributes on template instances are safe
[113] Fix | Delete
if ('_self' == $name || \in_array($name, $this->safeVars)) {
[114] Fix | Delete
$this->setSafe($node, ['all']);
[115] Fix | Delete
} else {
[116] Fix | Delete
$this->setSafe($node, []);
[117] Fix | Delete
}
[118] Fix | Delete
} else {
[119] Fix | Delete
$this->setSafe($node, []);
[120] Fix | Delete
}
[121] Fix | Delete
return $node;
[122] Fix | Delete
}
[123] Fix | Delete
protected function intersectSafe(array $a = null, array $b = null)
[124] Fix | Delete
{
[125] Fix | Delete
if (null === $a || null === $b) {
[126] Fix | Delete
return [];
[127] Fix | Delete
}
[128] Fix | Delete
if (\in_array('all', $a)) {
[129] Fix | Delete
return $b;
[130] Fix | Delete
}
[131] Fix | Delete
if (\in_array('all', $b)) {
[132] Fix | Delete
return $a;
[133] Fix | Delete
}
[134] Fix | Delete
return \array_intersect($a, $b);
[135] Fix | Delete
}
[136] Fix | Delete
public function getPriority()
[137] Fix | Delete
{
[138] Fix | Delete
return 0;
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
\class_alias('WPML\\Core\\Twig\\NodeVisitor\\SafeAnalysisNodeVisitor', 'WPML\\Core\\Twig_NodeVisitor_SafeAnalysis');
[142] Fix | Delete
[143] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function