Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

extension.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 7.57 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\template\twig;
015   
016  use Twig\Error\RuntimeError;
017   
018  class extension extends \Twig\Extension\AbstractExtension
019  {
020      /** @var \phpbb\template\context */
021      protected $context;
022   
023      /** @var \phpbb\template\twig\environment */
024      protected $environment;
025   
026      /** @var \phpbb\language\language */
027      protected $language;
028   
029      /**
030      * Constructor
031      *
032      * @param \phpbb\template\context $context
033      * @param \phpbb\template\twig\environment $environment
034      * @param \phpbb\language\language $language
035      */
036      public function __construct(\phpbb\template\context $context, \phpbb\template\twig\environment $environment, $language)
037      {
038          $this->context = $context;
039          $this->environment = $environment;
040          $this->language = $language;
041      }
042   
043      /**
044      * Get the name of this extension
045      *
046      * @return string
047      */
048      public function getName()
049      {
050          return 'phpbb';
051      }
052   
053      /**
054      * Returns the token parser instance to add to the existing list.
055      *
056      * @return array An array of \Twig\TokenParser\AbstractTokenParser instances
057      */
058      public function getTokenParsers()
059      {
060          return array(
061              new \phpbb\template\twig\tokenparser\defineparser,
062              new \phpbb\template\twig\tokenparser\includeparser,
063              new \phpbb\template\twig\tokenparser\includejs,
064              new \phpbb\template\twig\tokenparser\includecss,
065              new \phpbb\template\twig\tokenparser\event($this->environment),
066              new \phpbb\template\twig\tokenparser\includephp($this->environment),
067              new \phpbb\template\twig\tokenparser\php($this->environment),
068          );
069      }
070   
071      /**
072      * Returns a list of filters to add to the existing list.
073      *
074      * @return array An array of filters
075      */
076      public function getFilters()
077      {
078          return array(
079              new \Twig\TwigFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
080              // @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
081              new \Twig\TwigFilter('addslashes', 'addslashes'),
082              new \Twig\TwigFilter('int', 'intval'),
083              new \Twig\TwigFilter('float', 'floatval'),
084          );
085      }
086   
087      /**
088      * Returns a list of global functions to add to the existing list.
089      *
090      * @return array An array of global functions
091      */
092      public function getFunctions()
093      {
094          return array(
095              new \Twig\TwigFunction('lang', array($this, 'lang')),
096              new \Twig\TwigFunction('lang_defined', array($this, 'lang_defined')),
097              new \Twig\TwigFunction('lang_js', [$this, 'lang_js']),
098              new \Twig\TwigFunction('get_class', 'get_class'),
099          );
100      }
101   
102      /**
103      * Returns a list of operators to add to the existing list.
104      *
105      * @return array An array of operators
106      */
107      public function getOperators()
108      {
109          return array(
110              array(
111                  '!' => array('precedence' => 50, 'class' => '\Twig\Node\Expression\Unary\NotUnary'),
112              ),
113              array(
114                  // precedence settings are copied from similar operators in Twig core extension
115                  '||' => array('precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
116                  '&&' => array('precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
117   
118                  'eq' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
119   
120                  'ne' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
121                  'neq' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
122                  '<>' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
123   
124                  '===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
125                  '!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
126   
127                  'gt' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
128                  'gte' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
129                  'ge' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
130                  'lt' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
131                  'lte' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
132                  'le' => array('precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
133   
134                  'mod' => array('precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT),
135              ),
136          );
137      }
138   
139      /**
140      * Grabs a subset of a loop
141      *
142      * @param \Twig\Environment $env          A Twig\Environment instance
143      * @param mixed            $item         A variable
144      * @param integer          $start        Start of the subset
145      * @param integer          $end            End of the subset
146      * @param boolean          $preserveKeys Whether to preserve key or not (when the input is an array)
147      *
148      * @return mixed The sliced variable
149      */
150      public function loop_subset(\Twig\Environment $env, $item, $start, $end = null, $preserveKeys = false)
151      {
152          // We do almost the same thing as Twig's slice (array_slice), except when $end is positive
153          if ($end >= 1)
154          {
155              // When end is > 1, subset will end on the last item in an array with the specified $end
156              // This is different from slice in that it is the number we end on rather than the number
157              //  of items to grab (length)
158   
159              // Start must always be the actual starting number for this calculation (not negative)
160              $start = ($start < 0) ? count($item) + $start : $start;
161              $end = $end - $start;
162          }
163   
164          // We always include the last element (this was the past design)
165          $end = ($end == -1 || $end === null) ? null : $end + 1;
166   
167          return twig_slice($env, $item, $start, $end, $preserveKeys);
168      }
169   
170      /**
171      * Get output for a language variable (L_FOO, LA_FOO)
172      *
173      * This function checks to see if the language var was outputted to $context
174      * (e.g. in the ACP, L_TITLE)
175      * If not, we return the result of $user->lang()
176      *
177      * @return string
178      */
179      public function lang()
180      {
181          $args = func_get_args();
182          $key = $args[0];
183   
184          $context_vars = $this->context->get_root_ref();
185   
186          if (is_string($key) && isset($context_vars['L_' . $key]))
187          {
188              return $context_vars['L_' . $key];
189          }
190   
191          // LA_ is transformed into lang(\'$1\')|escape('js'), so we should not
192          // need to check for it
193   
194          return call_user_func_array(array($this->language, 'lang'), $args);
195      }
196   
197      /**
198       * Check if a language variable exists
199       *
200       * @return bool
201       */
202      public function lang_defined($key)
203      {
204          return call_user_func_array([$this->language, 'is_set'], [$key]);
205      }
206   
207      /**
208       * Get output for language variable in JS code
209       *
210       * @throws RuntimeError When data passed to twig_escape_filter is not a UTF8 string
211       */
212      public function lang_js(): string
213      {
214          $args = func_get_args();
215   
216          return twig_escape_filter($this->environment, call_user_func_array([$this, 'lang'], $args), 'js');
217      }
218  }
219