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/TokenPar...
File: ForTokenParser.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
* (c) Armin Ronacher
[6] Fix | Delete
*
[7] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[8] Fix | Delete
* file that was distributed with this source code.
[9] Fix | Delete
*/
[10] Fix | Delete
namespace WPML\Core\Twig\TokenParser;
[11] Fix | Delete
[12] Fix | Delete
use WPML\Core\Twig\Error\SyntaxError;
[13] Fix | Delete
use WPML\Core\Twig\Node\Expression\AssignNameExpression;
[14] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConstantExpression;
[15] Fix | Delete
use WPML\Core\Twig\Node\Expression\GetAttrExpression;
[16] Fix | Delete
use WPML\Core\Twig\Node\Expression\NameExpression;
[17] Fix | Delete
use WPML\Core\Twig\Node\ForNode;
[18] Fix | Delete
use WPML\Core\Twig\Token;
[19] Fix | Delete
use WPML\Core\Twig\TokenStream;
[20] Fix | Delete
/**
[21] Fix | Delete
* Loops over each item of a sequence.
[22] Fix | Delete
*
[23] Fix | Delete
* <ul>
[24] Fix | Delete
* {% for user in users %}
[25] Fix | Delete
* <li>{{ user.username|e }}</li>
[26] Fix | Delete
* {% endfor %}
[27] Fix | Delete
* </ul>
[28] Fix | Delete
*
[29] Fix | Delete
* @final
[30] Fix | Delete
*/
[31] Fix | Delete
class ForTokenParser extends \WPML\Core\Twig\TokenParser\AbstractTokenParser
[32] Fix | Delete
{
[33] Fix | Delete
public function parse(\WPML\Core\Twig\Token $token)
[34] Fix | Delete
{
[35] Fix | Delete
$lineno = $token->getLine();
[36] Fix | Delete
$stream = $this->parser->getStream();
[37] Fix | Delete
$targets = $this->parser->getExpressionParser()->parseAssignmentExpression();
[38] Fix | Delete
$stream->expect(\WPML\Core\Twig\Token::OPERATOR_TYPE, 'in');
[39] Fix | Delete
$seq = $this->parser->getExpressionParser()->parseExpression();
[40] Fix | Delete
$ifexpr = null;
[41] Fix | Delete
if ($stream->nextIf(\WPML\Core\Twig\Token::NAME_TYPE, 'if')) {
[42] Fix | Delete
$ifexpr = $this->parser->getExpressionParser()->parseExpression();
[43] Fix | Delete
}
[44] Fix | Delete
$stream->expect(\WPML\Core\Twig\Token::BLOCK_END_TYPE);
[45] Fix | Delete
$body = $this->parser->subparse([$this, 'decideForFork']);
[46] Fix | Delete
if ('else' == $stream->next()->getValue()) {
[47] Fix | Delete
$stream->expect(\WPML\Core\Twig\Token::BLOCK_END_TYPE);
[48] Fix | Delete
$else = $this->parser->subparse([$this, 'decideForEnd'], \true);
[49] Fix | Delete
} else {
[50] Fix | Delete
$else = null;
[51] Fix | Delete
}
[52] Fix | Delete
$stream->expect(\WPML\Core\Twig\Token::BLOCK_END_TYPE);
[53] Fix | Delete
if (\count($targets) > 1) {
[54] Fix | Delete
$keyTarget = $targets->getNode(0);
[55] Fix | Delete
$keyTarget = new \WPML\Core\Twig\Node\Expression\AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine());
[56] Fix | Delete
$valueTarget = $targets->getNode(1);
[57] Fix | Delete
$valueTarget = new \WPML\Core\Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
[58] Fix | Delete
} else {
[59] Fix | Delete
$keyTarget = new \WPML\Core\Twig\Node\Expression\AssignNameExpression('_key', $lineno);
[60] Fix | Delete
$valueTarget = $targets->getNode(0);
[61] Fix | Delete
$valueTarget = new \WPML\Core\Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine());
[62] Fix | Delete
}
[63] Fix | Delete
if ($ifexpr) {
[64] Fix | Delete
$this->checkLoopUsageCondition($stream, $ifexpr);
[65] Fix | Delete
$this->checkLoopUsageBody($stream, $body);
[66] Fix | Delete
}
[67] Fix | Delete
return new \WPML\Core\Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag());
[68] Fix | Delete
}
[69] Fix | Delete
public function decideForFork(\WPML\Core\Twig\Token $token)
[70] Fix | Delete
{
[71] Fix | Delete
return $token->test(['else', 'endfor']);
[72] Fix | Delete
}
[73] Fix | Delete
public function decideForEnd(\WPML\Core\Twig\Token $token)
[74] Fix | Delete
{
[75] Fix | Delete
return $token->test('endfor');
[76] Fix | Delete
}
[77] Fix | Delete
// the loop variable cannot be used in the condition
[78] Fix | Delete
protected function checkLoopUsageCondition(\WPML\Core\Twig\TokenStream $stream, \WPML\Core\Twig_NodeInterface $node)
[79] Fix | Delete
{
[80] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \WPML\Core\Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
[81] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext());
[82] Fix | Delete
}
[83] Fix | Delete
foreach ($node as $n) {
[84] Fix | Delete
if (!$n) {
[85] Fix | Delete
continue;
[86] Fix | Delete
}
[87] Fix | Delete
$this->checkLoopUsageCondition($stream, $n);
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
// check usage of non-defined loop-items
[91] Fix | Delete
// it does not catch all problems (for instance when a for is included into another or when the variable is used in an include)
[92] Fix | Delete
protected function checkLoopUsageBody(\WPML\Core\Twig\TokenStream $stream, \WPML\Core\Twig_NodeInterface $node)
[93] Fix | Delete
{
[94] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \WPML\Core\Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) {
[95] Fix | Delete
$attribute = $node->getNode('attribute');
[96] Fix | Delete
if ($attribute instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) {
[97] Fix | Delete
throw new \WPML\Core\Twig\Error\SyntaxError(\sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext());
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
// should check for parent.loop.XXX usage
[101] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\ForNode) {
[102] Fix | Delete
return;
[103] Fix | Delete
}
[104] Fix | Delete
foreach ($node as $n) {
[105] Fix | Delete
if (!$n) {
[106] Fix | Delete
continue;
[107] Fix | Delete
}
[108] Fix | Delete
$this->checkLoopUsageBody($stream, $n);
[109] Fix | Delete
}
[110] Fix | Delete
}
[111] Fix | Delete
public function getTag()
[112] Fix | Delete
{
[113] Fix | Delete
return 'for';
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
\class_alias('WPML\\Core\\Twig\\TokenParser\\ForTokenParser', 'WPML\\Core\\Twig_TokenParser_For');
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function