Server IP : 85.214.239.14 / Your IP : 18.119.112.208 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/wordpress/phpMyAdmin/vendor/phpmyadmin/twig-i18n-extension/src/Node/ |
Upload File : |
<?php /* * This file is part of Twig. * * (c) 2010-2019 Fabien Potencier * (c) 2019 phpMyAdmin contributors * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PhpMyAdmin\Twig\Extensions\Node; use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\TempNameExpression; use Twig\Node\Node; use Twig\Node\PrintNode; use Twig\Node\SetTempNode; /** * Represents a trans node. * * @author Fabien Potencier <fabien.potencier@symfony-project.com> */ class TransNode extends Node { public function __construct(Node $body, Node $plural = null, AbstractExpression $count = null, Node $notes = null, $lineno, $tag = null) { $nodes = array('body' => $body); if (null !== $count) { $nodes['count'] = $count; } if (null !== $plural) { $nodes['plural'] = $plural; } if (null !== $notes) { $nodes['notes'] = $notes; } parent::__construct($nodes, array(), $lineno, $tag); } /** * {@inheritdoc} */ public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); list($msg, $vars) = $this->compileString($this->getNode('body')); if ($this->hasNode('plural')) { list($msg1, $vars1) = $this->compileString($this->getNode('plural')); $vars = array_merge($vars, $vars1); } $function = $this->getTransFunction($this->hasNode('plural')); if ($this->hasNode('notes')) { $message = trim($this->getNode('notes')->getAttribute('data')); // line breaks are not allowed cause we want a single line comment $message = str_replace(array("\n", "\r"), ' ', $message); $compiler->write("// notes: {$message}\n"); } if ($vars) { $compiler ->write('echo strtr('.$function.'(') ->subcompile($msg) ; if ($this->hasNode('plural')) { $compiler ->raw(', ') ->subcompile($msg1) ->raw(', abs(') ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) ->raw(')') ; } $compiler->raw('), array('); foreach ($vars as $var) { if ('count' === $var->getAttribute('name')) { $compiler ->string('%count%') ->raw(' => abs(') ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) ->raw('), ') ; } else { $compiler ->string('%'.$var->getAttribute('name').'%') ->raw(' => ') ->subcompile($var) ->raw(', ') ; } } $compiler->raw("));\n"); } else { $compiler ->write('echo '.$function.'(') ->subcompile($msg) ; if ($this->hasNode('plural')) { $compiler ->raw(', ') ->subcompile($msg1) ->raw(', abs(') ->subcompile($this->hasNode('count') ? $this->getNode('count') : null) ->raw(')') ; } $compiler->raw(");\n"); } } /** * @param Node $body A Node instance * * @return array */ protected function compileString(Node $body) { if ($body instanceof NameExpression || $body instanceof ConstantExpression || $body instanceof TempNameExpression) { return array($body, array()); } $vars = array(); if (count($body)) { $msg = ''; foreach ($body as $node) { if (get_class($node) === Node::class && $node->getNode(0) instanceof SetTempNode) { $node = $node->getNode(1); } if ($node instanceof PrintNode) { $n = $node->getNode('expr'); while ($n instanceof FilterExpression) { $n = $n->getNode('node'); } $msg .= sprintf('%%%s%%', $n->getAttribute('name')); $vars[] = new NameExpression($n->getAttribute('name'), $n->getTemplateLine()); } else { $msg .= $node->getAttribute('data'); } } } else { $msg = $body->getAttribute('data'); } return array(new Node(array(new ConstantExpression(trim($msg), $body->getTemplateLine()))), $vars); } /** * @param bool $plural Return plural or singular function to use * * @return string */ protected function getTransFunction($plural) { return $plural ? 'ngettext' : 'gettext'; } }