Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
extension.php
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\language\language */
022 protected $language;
023
024 /**
025 * Constructor
026 *
027 * @param \phpbb\template\context $context
028 * @param \phpbb\language\language $language
029 * @return \phpbb\template\twig\extension
030 */
031 public function __construct(\phpbb\template\context $context, $language)
032 {
033 $this->context = $context;
034 $this->language = $language;
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 // @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes
075 new \Twig_SimpleFilter('addslashes', 'addslashes'),
076 );
077 }
078
079 /**
080 * Returns a list of global functions to add to the existing list.
081 *
082 * @return array An array of global functions
083 */
084 public function getFunctions()
085 {
086 return array(
087 new \Twig_SimpleFunction('lang', array($this, 'lang')),
088 );
089 }
090
091 /**
092 * Returns a list of operators to add to the existing list.
093 *
094 * @return array An array of operators
095 */
096 public function getOperators()
097 {
098 return array(
099 array(
100 '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'),
101 ),
102 array(
103 // precedence settings are copied from similar operators in Twig core extension
104 '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
105 '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
106
107 'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
108
109 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
110 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
111 '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
112
113 '===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
114 '!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
115
116 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
117 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
118 'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
119 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
120 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
121 'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
122
123 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT),
124 ),
125 );
126 }
127
128 /**
129 * Grabs a subset of a loop
130 *
131 * @param \Twig_Environment $env A Twig_Environment instance
132 * @param mixed $item A variable
133 * @param integer $start Start of the subset
134 * @param integer $end End of the subset
135 * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array)
136 *
137 * @return mixed The sliced variable
138 */
139 function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false)
140 {
141 // We do almost the same thing as Twig's slice (array_slice), except when $end is positive
142 if ($end >= 1)
143 {
144 // When end is > 1, subset will end on the last item in an array with the specified $end
145 // This is different from slice in that it is the number we end on rather than the number
146 // of items to grab (length)
147
148 // Start must always be the actual starting number for this calculation (not negative)
149 $start = ($start < 0) ? sizeof($item) + $start : $start;
150 $end = $end - $start;
151 }
152
153 // We always include the last element (this was the past design)
154 $end = ($end == -1 || $end === null) ? null : $end + 1;
155
156 return twig_slice($env, $item, $start, $end, $preserveKeys);
157 }
158
159 /**
160 * Get output for a language variable (L_FOO, LA_FOO)
161 *
162 * This function checks to see if the language var was outputted to $context
163 * (e.g. in the ACP, L_TITLE)
164 * If not, we return the result of $user->lang()
165 *
166 * @return string
167 */
168 function lang()
169 {
170 $args = func_get_args();
171 $key = $args[0];
172
173 $context_vars = $this->context->get_root_ref();
174
175 if (isset($context_vars['L_' . $key]))
176 {
177 return $context_vars['L_' . $key];
178 }
179
180 // LA_ is transformed into lang(\'$1\')|escape('js'), so we should not
181 // need to check for it
182
183 return call_user_func_array(array($this->language, 'lang'), $args);
184 }
185 }
186