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. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
environment.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 use phpbb\template\assets_bag;
017
018 class environment extends \Twig\Environment
019 {
020 /** @var \phpbb\config\config */
021 protected $phpbb_config;
022
023 /** @var \phpbb\filesystem\filesystem */
024 protected $filesystem;
025
026 /** @var \phpbb\path_helper */
027 protected $phpbb_path_helper;
028
029 /** @var \Symfony\Component\DependencyInjection\ContainerInterface */
030 protected $container;
031
032 /** @var \phpbb\extension\manager */
033 protected $extension_manager;
034
035 /** @var \phpbb\event\dispatcher_interface */
036 protected $phpbb_dispatcher;
037
038 /** @var string */
039 protected $phpbb_root_path;
040
041 /** @var string */
042 protected $web_root_path;
043
044 /** @var array **/
045 protected $namespace_look_up_order = array('__main__');
046
047 /** @var assets_bag */
048 protected $assets_bag;
049
050 /**
051 * Constructor
052 *
053 * @param \phpbb\config\config $phpbb_config The phpBB configuration
054 * @param \phpbb\filesystem\filesystem $filesystem
055 * @param \phpbb\path_helper $path_helper phpBB path helper
056 * @param string $cache_path The path to the cache directory
057 * @param \phpbb\extension\manager $extension_manager phpBB extension manager
058 * @param \Twig\Loader\LoaderInterface $loader Twig loader interface
059 * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
060 * @param array $options Array of options to pass to Twig
061 */
062 public function __construct(\phpbb\config\config $phpbb_config, \phpbb\filesystem\filesystem $filesystem, \phpbb\path_helper $path_helper, $cache_path, \phpbb\extension\manager $extension_manager = null, \Twig\Loader\LoaderInterface $loader = null, \phpbb\event\dispatcher_interface $phpbb_dispatcher = null, $options = array())
063 {
064 $this->phpbb_config = $phpbb_config;
065
066 $this->filesystem = $filesystem;
067 $this->phpbb_path_helper = $path_helper;
068 $this->extension_manager = $extension_manager;
069 $this->phpbb_dispatcher = $phpbb_dispatcher;
070
071 $this->phpbb_root_path = $this->phpbb_path_helper->get_phpbb_root_path();
072
073 $this->assets_bag = new assets_bag();
074
075 $options = array_merge(array(
076 'cache' => (defined('IN_INSTALL')) ? false : $cache_path,
077 'debug' => false,
078 'auto_reload' => (bool) $this->phpbb_config['load_tplcompile'],
079 'autoescape' => false,
080 ), $options);
081
082 parent::__construct($loader, $options);
083 }
084
085 /**
086 * Get the list of enabled phpBB extensions
087 *
088 * Used in EVENT node
089 *
090 * @return array
091 */
092 public function get_phpbb_extensions()
093 {
094 return ($this->extension_manager) ? $this->extension_manager->all_enabled() : array();
095 }
096
097 /**
098 * Get phpBB config
099 *
100 * @return \phpbb\config\config
101 */
102 public function get_phpbb_config()
103 {
104 return $this->phpbb_config;
105 }
106
107 /**
108 * Get the phpBB root path
109 *
110 * @return string
111 */
112 public function get_phpbb_root_path()
113 {
114 return $this->phpbb_root_path;
115 }
116
117 /**
118 * Get the filesystem object
119 *
120 * @return \phpbb\filesystem\filesystem
121 */
122 public function get_filesystem()
123 {
124 return $this->filesystem;
125 }
126
127 /**
128 * Get the web root path
129 *
130 * @return string
131 */
132 public function get_web_root_path()
133 {
134 return $this->web_root_path ?? $this->web_root_path = $this->phpbb_path_helper->get_web_root_path();
135 }
136
137 /**
138 * Get the phpbb path helper object
139 *
140 * @return \phpbb\path_helper
141 */
142 public function get_path_helper()
143 {
144 return $this->phpbb_path_helper;
145 }
146
147 /**
148 * Gets the assets bag
149 *
150 * @return assets_bag
151 */
152 public function get_assets_bag()
153 {
154 return $this->assets_bag;
155 }
156
157 /**
158 * Get the namespace look up order
159 *
160 * @return array
161 */
162 public function getNamespaceLookUpOrder()
163 {
164 return $this->namespace_look_up_order;
165 }
166
167 /**
168 * Set the namespace look up order to load templates from
169 *
170 * @param array $namespace
171 * @return \Twig\Environment
172 */
173 public function setNamespaceLookUpOrder($namespace)
174 {
175 $this->namespace_look_up_order = $namespace;
176
177 return $this;
178 }
179
180 /**
181 * {@inheritdoc}
182 */
183 public function render($name, array $context = [])
184 {
185 return $this->display_with_assets($name, $context);
186 }
187
188 /**
189 * {@inheritdoc}
190 */
191 public function display($name, array $context = [])
192 {
193 echo $this->display_with_assets($name, $context);
194 }
195
196 /**
197 * {@inheritdoc}
198 */
199 private function display_with_assets($name, array $context = [])
200 {
201 $placeholder_salt = unique_id();
202
203 if (array_key_exists('definition', $context))
204 {
205 $context['definition']->set('SCRIPTS', '__SCRIPTS_' . $placeholder_salt . '__');
206 $context['definition']->set('STYLESHEETS', '__STYLESHEETS_' . $placeholder_salt . '__');
207 }
208
209 /**
210 * Allow changing the template output stream before rendering
211 *
212 * @event core.twig_environment_render_template_before
213 * @var array context Array with template variables
214 * @var string name The template name
215 * @since 3.2.1-RC1
216 */
217 if ($this->phpbb_dispatcher)
218 {
219 $vars = array('context', 'name');
220 extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_before', compact($vars)));
221 }
222
223 $output = parent::render($name, $context);
224
225 /**
226 * Allow changing the template output stream after rendering
227 *
228 * @event core.twig_environment_render_template_after
229 * @var array context Array with template variables
230 * @var string name The template name
231 * @var string output Rendered template output stream
232 * @since 3.2.1-RC1
233 */
234 if ($this->phpbb_dispatcher)
235 {
236 $vars = array('context', 'name', 'output');
237 extract($this->phpbb_dispatcher->trigger_event('core.twig_environment_render_template_after', compact($vars)));
238 }
239
240 return $this->inject_assets($output, $placeholder_salt);
241 }
242
243 /**
244 * Injects the assets (from INCLUDECSS/JS) in the output.
245 *
246 * @param string $output
247 *
248 * @return string
249 */
250 private function inject_assets($output, $placeholder_salt)
251 {
252 $output = str_replace('__STYLESHEETS_' . $placeholder_salt . '__', $this->assets_bag->get_stylesheets_content(), $output);
253 $output = str_replace('__SCRIPTS_' . $placeholder_salt . '__', $this->assets_bag->get_scripts_content(), $output);
254
255 return $output;
256 }
257
258 /**
259 * Loads a template by name.
260 *
261 * @param string $name The template name
262 * @param integer $index The index if it is an embedded template
263 * @return \Twig\Template A template instance representing the given template name
264 * @throws \Twig\Error\LoaderError
265 */
266 public function loadTemplate($name, $index = null)
267 {
268 if (strpos($name, '@') === false)
269 {
270 foreach ($this->getNamespaceLookUpOrder() as $namespace)
271 {
272 try
273 {
274 if ($namespace === '__main__')
275 {
276 return parent::loadTemplate($name, $index);
277 }
278
279 return parent::loadTemplate('@' . $namespace . '/' . $name, $index);
280 }
281 catch (\Twig\Error\LoaderError $e)
282 {
283 }
284 }
285
286 // We were unable to load any templates
287 throw $e;
288 }
289 else
290 {
291 return parent::loadTemplate($name, $index);
292 }
293 }
294
295 /**
296 * Finds a template by name.
297 *
298 * @param string $name The template name
299 * @return string
300 * @throws \Twig\Error\LoaderError
301 */
302 public function findTemplate($name)
303 {
304 if (strpos($name, '@') === false)
305 {
306 foreach ($this->getNamespaceLookUpOrder() as $namespace)
307 {
308 try
309 {
310 if ($namespace === '__main__')
311 {
312 return parent::getLoader()->getCacheKey($name);
313 }
314
315 return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name);
316 }
317 catch (\Twig\Error\LoaderError $e)
318 {
319 }
320 }
321
322 // We were unable to load any templates
323 throw $e;
324 }
325 else
326 {
327 return parent::getLoader()->getCacheKey($name);
328 }
329 }
330 }
331