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/Node
File: ModuleNode.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\Node;
[11] Fix | Delete
[12] Fix | Delete
use WPML\Core\Twig\Compiler;
[13] Fix | Delete
use WPML\Core\Twig\Node\Expression\AbstractExpression;
[14] Fix | Delete
use WPML\Core\Twig\Node\Expression\ConstantExpression;
[15] Fix | Delete
use WPML\Core\Twig\Source;
[16] Fix | Delete
/**
[17] Fix | Delete
* Represents a module node.
[18] Fix | Delete
*
[19] Fix | Delete
* Consider this class as being final. If you need to customize the behavior of
[20] Fix | Delete
* the generated class, consider adding nodes to the following nodes: display_start,
[21] Fix | Delete
* display_end, constructor_start, constructor_end, and class_end.
[22] Fix | Delete
*
[23] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[24] Fix | Delete
*/
[25] Fix | Delete
class ModuleNode extends \WPML\Core\Twig\Node\Node
[26] Fix | Delete
{
[27] Fix | Delete
public function __construct(\WPML\Core\Twig_NodeInterface $body, \WPML\Core\Twig\Node\Expression\AbstractExpression $parent = null, \WPML\Core\Twig_NodeInterface $blocks, \WPML\Core\Twig_NodeInterface $macros, \WPML\Core\Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '')
[28] Fix | Delete
{
[29] Fix | Delete
if (!$name instanceof \WPML\Core\Twig\Source) {
[30] Fix | Delete
@\trigger_error(\sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a \\Twig\\Source instance instead.', __METHOD__), \E_USER_DEPRECATED);
[31] Fix | Delete
$source = new \WPML\Core\Twig\Source($source, $name);
[32] Fix | Delete
} else {
[33] Fix | Delete
$source = $name;
[34] Fix | Delete
}
[35] Fix | Delete
$nodes = ['body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits, 'display_start' => new \WPML\Core\Twig\Node\Node(), 'display_end' => new \WPML\Core\Twig\Node\Node(), 'constructor_start' => new \WPML\Core\Twig\Node\Node(), 'constructor_end' => new \WPML\Core\Twig\Node\Node(), 'class_end' => new \WPML\Core\Twig\Node\Node()];
[36] Fix | Delete
if (null !== $parent) {
[37] Fix | Delete
$nodes['parent'] = $parent;
[38] Fix | Delete
}
[39] Fix | Delete
// embedded templates are set as attributes so that they are only visited once by the visitors
[40] Fix | Delete
parent::__construct($nodes, [
[41] Fix | Delete
// source to be remove in 2.0
[42] Fix | Delete
'source' => $source->getCode(),
[43] Fix | Delete
// filename to be remove in 2.0 (use getTemplateName() instead)
[44] Fix | Delete
'filename' => $source->getName(),
[45] Fix | Delete
'index' => null,
[46] Fix | Delete
'embedded_templates' => $embeddedTemplates,
[47] Fix | Delete
], 1);
[48] Fix | Delete
// populate the template name of all node children
[49] Fix | Delete
$this->setTemplateName($source->getName());
[50] Fix | Delete
$this->setSourceContext($source);
[51] Fix | Delete
}
[52] Fix | Delete
public function setIndex($index)
[53] Fix | Delete
{
[54] Fix | Delete
$this->setAttribute('index', $index);
[55] Fix | Delete
}
[56] Fix | Delete
public function compile(\WPML\Core\Twig\Compiler $compiler)
[57] Fix | Delete
{
[58] Fix | Delete
$this->compileTemplate($compiler);
[59] Fix | Delete
foreach ($this->getAttribute('embedded_templates') as $template) {
[60] Fix | Delete
$compiler->subcompile($template);
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
protected function compileTemplate(\WPML\Core\Twig\Compiler $compiler)
[64] Fix | Delete
{
[65] Fix | Delete
if (!$this->getAttribute('index')) {
[66] Fix | Delete
$compiler->write('<?php');
[67] Fix | Delete
}
[68] Fix | Delete
$this->compileClassHeader($compiler);
[69] Fix | Delete
if (\count($this->getNode('blocks')) || \count($this->getNode('traits')) || !$this->hasNode('parent') || $this->getNode('parent') instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression || \count($this->getNode('constructor_start')) || \count($this->getNode('constructor_end'))) {
[70] Fix | Delete
$this->compileConstructor($compiler);
[71] Fix | Delete
}
[72] Fix | Delete
$this->compileGetParent($compiler);
[73] Fix | Delete
$this->compileDisplay($compiler);
[74] Fix | Delete
$compiler->subcompile($this->getNode('blocks'));
[75] Fix | Delete
$this->compileMacros($compiler);
[76] Fix | Delete
$this->compileGetTemplateName($compiler);
[77] Fix | Delete
$this->compileIsTraitable($compiler);
[78] Fix | Delete
$this->compileDebugInfo($compiler);
[79] Fix | Delete
$this->compileGetSource($compiler);
[80] Fix | Delete
$this->compileGetSourceContext($compiler);
[81] Fix | Delete
$this->compileClassFooter($compiler);
[82] Fix | Delete
}
[83] Fix | Delete
protected function compileGetParent(\WPML\Core\Twig\Compiler $compiler)
[84] Fix | Delete
{
[85] Fix | Delete
if (!$this->hasNode('parent')) {
[86] Fix | Delete
return;
[87] Fix | Delete
}
[88] Fix | Delete
$parent = $this->getNode('parent');
[89] Fix | Delete
$compiler->write("protected function doGetParent(array \$context)\n", "{\n")->indent()->addDebugInfo($parent)->write('return ');
[90] Fix | Delete
if ($parent instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression) {
[91] Fix | Delete
$compiler->subcompile($parent);
[92] Fix | Delete
} else {
[93] Fix | Delete
$compiler->raw('$this->loadTemplate(')->subcompile($parent)->raw(', ')->repr($this->getSourceContext()->getName())->raw(', ')->repr($parent->getTemplateLine())->raw(')');
[94] Fix | Delete
}
[95] Fix | Delete
$compiler->raw(";\n")->outdent()->write("}\n\n");
[96] Fix | Delete
}
[97] Fix | Delete
protected function compileClassHeader(\WPML\Core\Twig\Compiler $compiler)
[98] Fix | Delete
{
[99] Fix | Delete
$compiler->write("\n\nnamespace WPML\Core;\n\n");
[100] Fix | Delete
if (!$this->getAttribute('index')) {
[101] Fix | Delete
$compiler->write("use \\WPML\\Core\\Twig\\Environment;\n")->write("use \\WPML\\Core\\Twig\\Error\\LoaderError;\n")->write("use \\WPML\\Core\\Twig\\Error\\RuntimeError;\n")->write("use \\WPML\\Core\\Twig\\Markup;\n")->write("use \\WPML\\Core\\Twig\\Sandbox\\SecurityError;\n")->write("use \\WPML\\Core\\Twig\\Sandbox\\SecurityNotAllowedTagError;\n")->write("use \\WPML\\Core\\Twig\\Sandbox\\SecurityNotAllowedFilterError;\n")->write("use \\WPML\\Core\\Twig\\Sandbox\\SecurityNotAllowedFunctionError;\n")->write("use \\WPML\\Core\\Twig\\Source;\n")->write("use \\WPML\\Core\\Twig\\Template;\n\n");
[102] Fix | Delete
}
[103] Fix | Delete
$compiler->write('/* ' . \str_replace('*/', '* /', $this->getSourceContext()->getName()) . " */\n")->write('class ' . \substr( $compiler->getEnvironment()->getTemplateClass($this->getSourceContext()->getName(), $this->getAttribute('index')), 11 ) )->raw(\sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass()))->write("{\n")->indent();
[104] Fix | Delete
}
[105] Fix | Delete
protected function compileConstructor(\WPML\Core\Twig\Compiler $compiler)
[106] Fix | Delete
{
[107] Fix | Delete
$compiler->write("public function __construct(Environment \$env)\n", "{\n")->indent()->subcompile($this->getNode('constructor_start'))->write("parent::__construct(\$env);\n\n");
[108] Fix | Delete
// parent
[109] Fix | Delete
if (!$this->hasNode('parent')) {
[110] Fix | Delete
$compiler->write("\$this->parent = false;\n\n");
[111] Fix | Delete
}
[112] Fix | Delete
$countTraits = \count($this->getNode('traits'));
[113] Fix | Delete
if ($countTraits) {
[114] Fix | Delete
// traits
[115] Fix | Delete
foreach ($this->getNode('traits') as $i => $trait) {
[116] Fix | Delete
$this->compileLoadTemplate($compiler, $trait->getNode('template'), \sprintf('$_trait_%s', $i));
[117] Fix | Delete
$node = $trait->getNode('template');
[118] Fix | Delete
$compiler->addDebugInfo($node)->write(\sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i))->indent()->write("throw new RuntimeError('Template \"'.")->subcompile($trait->getNode('template'))->raw(".'\" cannot be used as a trait.', ")->repr($node->getTemplateLine())->raw(", \$this->getSourceContext());\n")->outdent()->write("}\n")->write(\sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i));
[119] Fix | Delete
foreach ($trait->getNode('targets') as $key => $value) {
[120] Fix | Delete
$compiler->write(\sprintf('if (!isset($_trait_%s_blocks[', $i))->string($key)->raw("])) {\n")->indent()->write("throw new RuntimeError(sprintf('Block ")->string($key)->raw(' is not defined in trait ')->subcompile($trait->getNode('template'))->raw(".'), ")->repr($node->getTemplateLine())->raw(", \$this->getSourceContext());\n")->outdent()->write("}\n\n")->write(\sprintf('$_trait_%s_blocks[', $i))->subcompile($value)->raw(\sprintf('] = $_trait_%s_blocks[', $i))->string($key)->raw(\sprintf(']; unset($_trait_%s_blocks[', $i))->string($key)->raw("]);\n\n");
[121] Fix | Delete
}
[122] Fix | Delete
}
[123] Fix | Delete
if ($countTraits > 1) {
[124] Fix | Delete
$compiler->write("\$this->traits = array_merge(\n")->indent();
[125] Fix | Delete
for ($i = 0; $i < $countTraits; ++$i) {
[126] Fix | Delete
$compiler->write(\sprintf('$_trait_%s_blocks' . ($i == $countTraits - 1 ? '' : ',') . "\n", $i));
[127] Fix | Delete
}
[128] Fix | Delete
$compiler->outdent()->write(");\n\n");
[129] Fix | Delete
} else {
[130] Fix | Delete
$compiler->write("\$this->traits = \$_trait_0_blocks;\n\n");
[131] Fix | Delete
}
[132] Fix | Delete
$compiler->write("\$this->blocks = array_merge(\n")->indent()->write("\$this->traits,\n")->write("[\n");
[133] Fix | Delete
} else {
[134] Fix | Delete
$compiler->write("\$this->blocks = [\n");
[135] Fix | Delete
}
[136] Fix | Delete
// blocks
[137] Fix | Delete
$compiler->indent();
[138] Fix | Delete
foreach ($this->getNode('blocks') as $name => $node) {
[139] Fix | Delete
$compiler->write(\sprintf("'%s' => [\$this, 'block_%s'],\n", $name, $name));
[140] Fix | Delete
}
[141] Fix | Delete
if ($countTraits) {
[142] Fix | Delete
$compiler->outdent()->write("]\n")->outdent()->write(");\n");
[143] Fix | Delete
} else {
[144] Fix | Delete
$compiler->outdent()->write("];\n");
[145] Fix | Delete
}
[146] Fix | Delete
$compiler->subcompile($this->getNode('constructor_end'))->outdent()->write("}\n\n");
[147] Fix | Delete
}
[148] Fix | Delete
protected function compileDisplay(\WPML\Core\Twig\Compiler $compiler)
[149] Fix | Delete
{
[150] Fix | Delete
$compiler->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n")->indent()->subcompile($this->getNode('display_start'))->subcompile($this->getNode('body'));
[151] Fix | Delete
if ($this->hasNode('parent')) {
[152] Fix | Delete
$parent = $this->getNode('parent');
[153] Fix | Delete
$compiler->addDebugInfo($parent);
[154] Fix | Delete
if ($parent instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression) {
[155] Fix | Delete
$compiler->write('$this->parent = $this->loadTemplate(')->subcompile($parent)->raw(', ')->repr($this->getSourceContext()->getName())->raw(', ')->repr($parent->getTemplateLine())->raw(");\n");
[156] Fix | Delete
$compiler->write('$this->parent');
[157] Fix | Delete
} else {
[158] Fix | Delete
$compiler->write('$this->getParent($context)');
[159] Fix | Delete
}
[160] Fix | Delete
$compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
[161] Fix | Delete
}
[162] Fix | Delete
$compiler->subcompile($this->getNode('display_end'))->outdent()->write("}\n\n");
[163] Fix | Delete
}
[164] Fix | Delete
protected function compileClassFooter(\WPML\Core\Twig\Compiler $compiler)
[165] Fix | Delete
{
[166] Fix | Delete
$compiler->subcompile($this->getNode('class_end'))->outdent()->write("}\n");
[167] Fix | Delete
}
[168] Fix | Delete
protected function compileMacros(\WPML\Core\Twig\Compiler $compiler)
[169] Fix | Delete
{
[170] Fix | Delete
$compiler->subcompile($this->getNode('macros'));
[171] Fix | Delete
}
[172] Fix | Delete
protected function compileGetTemplateName(\WPML\Core\Twig\Compiler $compiler)
[173] Fix | Delete
{
[174] Fix | Delete
$compiler->write("public function getTemplateName()\n", "{\n")->indent()->write('return ')->repr($this->getSourceContext()->getName())->raw(";\n")->outdent()->write("}\n\n");
[175] Fix | Delete
}
[176] Fix | Delete
protected function compileIsTraitable(\WPML\Core\Twig\Compiler $compiler)
[177] Fix | Delete
{
[178] Fix | Delete
// A template can be used as a trait if:
[179] Fix | Delete
// * it has no parent
[180] Fix | Delete
// * it has no macros
[181] Fix | Delete
// * it has no body
[182] Fix | Delete
//
[183] Fix | Delete
// Put another way, a template can be used as a trait if it
[184] Fix | Delete
// only contains blocks and use statements.
[185] Fix | Delete
$traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros'));
[186] Fix | Delete
if ($traitable) {
[187] Fix | Delete
if ($this->getNode('body') instanceof \WPML\Core\Twig\Node\BodyNode) {
[188] Fix | Delete
$nodes = $this->getNode('body')->getNode(0);
[189] Fix | Delete
} else {
[190] Fix | Delete
$nodes = $this->getNode('body');
[191] Fix | Delete
}
[192] Fix | Delete
if (!\count($nodes)) {
[193] Fix | Delete
$nodes = new \WPML\Core\Twig\Node\Node([$nodes]);
[194] Fix | Delete
}
[195] Fix | Delete
foreach ($nodes as $node) {
[196] Fix | Delete
if (!\count($node)) {
[197] Fix | Delete
continue;
[198] Fix | Delete
}
[199] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\TextNode && \ctype_space($node->getAttribute('data'))) {
[200] Fix | Delete
continue;
[201] Fix | Delete
}
[202] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\BlockReferenceNode) {
[203] Fix | Delete
continue;
[204] Fix | Delete
}
[205] Fix | Delete
$traitable = \false;
[206] Fix | Delete
break;
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
if ($traitable) {
[210] Fix | Delete
return;
[211] Fix | Delete
}
[212] Fix | Delete
$compiler->write("public function isTraitable()\n", "{\n")->indent()->write(\sprintf("return %s;\n", $traitable ? 'true' : 'false'))->outdent()->write("}\n\n");
[213] Fix | Delete
}
[214] Fix | Delete
protected function compileDebugInfo(\WPML\Core\Twig\Compiler $compiler)
[215] Fix | Delete
{
[216] Fix | Delete
$compiler->write("public function getDebugInfo()\n", "{\n")->indent()->write(\sprintf("return %s;\n", \str_replace("\n", '', \var_export(\array_reverse($compiler->getDebugInfo(), \true), \true))))->outdent()->write("}\n\n");
[217] Fix | Delete
}
[218] Fix | Delete
protected function compileGetSource(\WPML\Core\Twig\Compiler $compiler)
[219] Fix | Delete
{
[220] Fix | Delete
$compiler->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n")->write("public function getSource()\n", "{\n")->indent()->write("@trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);\n\n")->write('return $this->getSourceContext()->getCode();')->raw("\n")->outdent()->write("}\n\n");
[221] Fix | Delete
}
[222] Fix | Delete
protected function compileGetSourceContext(\WPML\Core\Twig\Compiler $compiler)
[223] Fix | Delete
{
[224] Fix | Delete
$compiler->write("public function getSourceContext()\n", "{\n")->indent()->write('return new Source(')->string($compiler->getEnvironment()->isDebug() ? $this->getSourceContext()->getCode() : '')->raw(', ')->string($this->getSourceContext()->getName())->raw(', ')->string($this->getSourceContext()->getPath())->raw(");\n")->outdent()->write("}\n");
[225] Fix | Delete
}
[226] Fix | Delete
protected function compileLoadTemplate(\WPML\Core\Twig\Compiler $compiler, $node, $var)
[227] Fix | Delete
{
[228] Fix | Delete
if ($node instanceof \WPML\Core\Twig\Node\Expression\ConstantExpression) {
[229] Fix | Delete
$compiler->write(\sprintf('%s = $this->loadTemplate(', $var))->subcompile($node)->raw(', ')->repr($node->getTemplateName())->raw(', ')->repr($node->getTemplateLine())->raw(");\n");
[230] Fix | Delete
} else {
[231] Fix | Delete
throw new \LogicException('Trait templates can only be constant nodes.');
[232] Fix | Delete
}
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Node\\ModuleNode', 'WPML\\Core\\Twig_Node_Module');
[236] Fix | Delete
[237] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function