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