Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:54 - Dateigröße: 6.31 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  class extension extends \Twig_Extension
 017  {
 018      /** @var \phpbb\template\context */
 019      protected $context;
 020   
 021      /** @var \phpbb\user */
 022      protected $user;
 023   
 024      /**
 025      * Constructor
 026      *
 027      * @param \phpbb\template\context $context
 028      * @param \phpbb\user $user
 029      * @return \phpbb\template\twig\extension
 030      */
 031      public function __construct(\phpbb\template\context $context, $user)
 032      {
 033          $this->context = $context;
 034          $this->user = $user;
 035      }
 036   
 037      /**
 038      * Get the name of this extension
 039      *
 040      * @return string
 041      */
 042      public function getName()
 043      {
 044          return 'phpbb';
 045      }
 046   
 047      /**
 048      * Returns the token parser instance to add to the existing list.
 049      *
 050      * @return array An array of Twig_TokenParser instances
 051      */
 052      public function getTokenParsers()
 053      {
 054          return array(
 055              new \phpbb\template\twig\tokenparser\defineparser,
 056              new \phpbb\template\twig\tokenparser\includeparser,
 057              new \phpbb\template\twig\tokenparser\includejs,
 058              new \phpbb\template\twig\tokenparser\includecss,
 059              new \phpbb\template\twig\tokenparser\event,
 060              new \phpbb\template\twig\tokenparser\includephp,
 061              new \phpbb\template\twig\tokenparser\php,
 062          );
 063      }
 064   
 065      /**
 066      * Returns a list of filters to add to the existing list.
 067      *
 068      * @return array An array of filters
 069      */
 070      public function getFilters()
 071      {
 072          return array(
 073              new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)),
 074              new \Twig_SimpleFilter('addslashes', 'addslashes'),
 075          );
 076      }
 077   
 078      /**
 079      * Returns a list of global functions to add to the existing list.
 080      *
 081      * @return array An array of global functions
 082      */
 083      public function getFunctions()
 084      {
 085          return array(
 086              new \Twig_SimpleFunction('lang', array($this, 'lang')),
 087          );
 088      }
 089   
 090      /**
 091      * Returns a list of operators to add to the existing list.
 092      *
 093      * @return array An array of operators
 094      */
 095      public function getOperators()
 096      {
 097          return array(
 098              array(
 099                  '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
 100              ),
 101              array(
 102                  // precedence settings are copied from similar operators in Twig core extension
 103                  '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 104                  '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 105   
 106                  'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 107   
 108                  'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 109                  'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 110                  '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 111   
 112                  '===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 113                  '!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 114   
 115                  'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 116                  'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 117                  'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 118                  'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 119                  'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 120                  'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 121   
 122                  'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
 123              ),
 124          );
 125      }
 126   
 127      /**
 128      * Grabs a subset of a loop
 129      *
 130      * @param \Twig_Environment $env          A Twig_Environment instance
 131      * @param mixed            $item         A variable
 132      * @param integer          $start        Start of the subset
 133      * @param integer          $end            End of the subset
 134      * @param Boolean          $preserveKeys Whether to preserve key or not (when the input is an array)
 135      *
 136      * @return mixed The sliced variable
 137      */
 138      function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
 139      {
 140          // We do almost the same thing as Twig's slice (array_slice), except when $end is positive
 141          if ($end >= 1)
 142          {
 143              // When end is > 1, subset will end on the last item in an array with the specified $end
 144              // This is different from slice in that it is the number we end on rather than the number
 145              //  of items to grab (length)
 146   
 147              // Start must always be the actual starting number for this calculation (not negative)
 148              $start = ($start < 0) ? sizeof($item) + $start : $start;
 149              $end = $end - $start;
 150          }
 151   
 152          // We always include the last element (this was the past design)
 153          $end = ($end == -1 || $end === null) ? null : $end + 1;
 154   
 155          return twig_slice($env, $item, $start, $end, $preserveKeys);
 156      }
 157   
 158      /**
 159      * Get output for a language variable (L_FOO, LA_FOO)
 160      *
 161      * This function checks to see if the language var was outputted to $context
 162      * (e.g. in the ACP, L_TITLE)
 163      * If not, we return the result of $user->lang()
 164      *
 165      * @return string
 166      */
 167      function lang()
 168      {
 169          $args = func_get_args();
 170          $key = $args[0];
 171   
 172          $context = $this->context->get_data_ref();
 173          $context_vars = $context['.'][0];
 174   
 175          if (isset($context_vars['L_' . $key]))
 176          {
 177              return $context_vars['L_' . $key];
 178          }
 179   
 180          // LA_ is transformed into lang(\'$1\')|addslashes, so we should not
 181          // need to check for it
 182   
 183          return call_user_func_array(array($this->user, 'lang'), $args);
 184      }
 185  }
 186