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

helper.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 11.02 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\controller;
015   
016  use phpbb\auth\auth;
017  use phpbb\cache\driver\driver_interface as cache_interface;
018  use phpbb\config\config;
019  use phpbb\cron\manager;
020  use phpbb\db\driver\driver_interface;
021  use phpbb\event\dispatcher;
022  use phpbb\language\language;
023  use phpbb\request\request_interface;
024  use phpbb\routing\helper as routing_helper;
025  use phpbb\symfony_request;
026  use phpbb\template\template;
027  use phpbb\user;
028  use Symfony\Component\HttpFoundation\JsonResponse;
029  use Symfony\Component\HttpFoundation\Response;
030  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
031   
032  /**
033  * Controller helper class, contains methods that do things for controllers
034  */
035  class helper
036  {
037      /** @var auth */
038      protected $auth;
039   
040      /** @var cache_interface */
041      protected $cache;
042   
043      /** @var config */
044      protected $config;
045   
046      /** @var manager */
047      protected $cron_manager;
048   
049      /** @var driver_interface */
050      protected $db;
051   
052      /** @var dispatcher */
053      protected $dispatcher;
054   
055      /** @var language */
056      protected $language;
057   
058      /* @var request_interface */
059      protected $request;
060   
061      /** @var routing_helper */
062      protected $routing_helper;
063   
064      /* @var symfony_request */
065      protected $symfony_request;
066   
067      /** @var template */
068      protected $template;
069   
070      /** @var user */
071      protected $user;
072   
073      /** @var string */
074      protected $admin_path;
075   
076      /** @var string */
077      protected $php_ext;
078   
079      /** @var bool $sql_explain */
080      protected $sql_explain;
081   
082      /**
083       * Constructor
084       *
085       * @param auth $auth Auth object
086       * @param cache_interface $cache
087       * @param config $config Config object
088       * @param manager $cron_manager
089       * @param driver_interface $db DBAL object
090       * @param dispatcher $dispatcher
091       * @param language $language
092       * @param request_interface $request phpBB request object
093       * @param routing_helper $routing_helper Helper to generate the routes
094       * @param symfony_request $symfony_request Symfony Request object
095       * @param template $template Template object
096       * @param user $user User object
097       * @param string $root_path phpBB root path
098       * @param string $admin_path Admin path
099       * @param string $php_ext PHP extension
100       * @param bool $sql_explain Flag whether to display sql explain
101       */
102      public function __construct(auth $auth, cache_interface $cache, config $config, manager $cron_manager,
103                                  driver_interface $db, dispatcher $dispatcher, language $language,
104                                  request_interface $request, routing_helper $routing_helper,
105                                  symfony_request $symfony_request, template $template, user $user, $root_path,
106                                  $admin_path, $php_ext, $sql_explain = false)
107      {
108          $this->auth = $auth;
109          $this->cache = $cache;
110          $this->cron_manager = $cron_manager;
111          $this->db = $db;
112          $this->dispatcher = $dispatcher;
113          $this->language = $language;
114          $this->template = $template;
115          $this->user = $user;
116          $this->config = $config;
117          $this->symfony_request = $symfony_request;
118          $this->request = $request;
119          $this->routing_helper = $routing_helper;
120          $this->admin_path = $root_path . $admin_path;
121          $this->php_ext = $php_ext;
122          $this->sql_explain = $sql_explain;
123      }
124   
125      /**
126      * Automate setting up the page and creating the response object.
127      *
128      * @param string $template_file The template handle to render
129      * @param string $page_title The title of the page to output
130      * @param int $status_code The status code to be sent to the page header
131      * @param bool $display_online_list Do we display online users list
132      * @param int $item_id Restrict online users to item id
133      * @param string $item Restrict online users to a certain session item, e.g. forum for session_forum_id
134      * @param bool $send_headers Whether headers should be sent by page_header(). Defaults to false for controllers.
135      *
136      * @return Response object containing rendered page
137      */
138      public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false, $item_id = 0, $item = 'forum', $send_headers = false)
139      {
140          page_header($page_title, $display_online_list, $item_id, $item, $send_headers);
141   
142          $this->template->set_filenames(array(
143              'body'    => $template_file,
144          ));
145   
146          $run_cron = true;
147          $page_footer_override = false;
148   
149          /**
150           * Execute code and/or overwrite page_footer()
151           *
152           * @event core.page_footer
153           * @var    bool    run_cron            Shall we run cron tasks
154           * @var    bool    page_footer_override    Shall we skip displaying the page footer
155           * @since 3.1.0-a1
156           * @changed 3.3.1-RC1 Added to controller helper render() method for backwards compatibility
157           */
158          $vars = ['run_cron', 'page_footer_override'];
159          extract($this->dispatcher->trigger_event('core.page_footer', compact($vars)));
160   
161          if (!$page_footer_override)
162          {
163              $this->display_footer($run_cron);
164          }
165   
166          $headers = !empty($this->user->data['is_bot']) ? ['X-PHPBB-IS-BOT' => 'yes'] : [];
167   
168          $display_template = true;
169          $exit_handler = true; // not used
170   
171          /**
172           * Execute code and/or modify output before displaying the template.
173           *
174           * @event core.page_footer_after
175           * @var    bool display_template    Whether or not to display the template
176           * @var    bool exit_handler        Whether or not to run the exit_handler() (no effect on controller pages)
177           *
178           * @since 3.1.0-RC5
179           * @changed 3.3.1-RC1 Added to controller helper render() method for backwards compatibility
180           */
181          $vars = ['display_template', 'exit_handler'];
182          extract($this->dispatcher->trigger_event('core.page_footer_after', compact($vars)));
183   
184          $response = new Response($display_template ? $this->template->assign_display('body') : '', $status_code, $headers);
185   
186          /**
187           * Modify response before output
188           *
189           * @event core.controller_helper_render_response
190           * @var    Response response    Symfony response object
191           *
192           * @since 3.3.1-RC1
193           */
194          $vars = ['response'];
195          extract($this->dispatcher->trigger_event('core.controller_helper_render_response', compact($vars)));
196   
197          return $response;
198      }
199   
200      /**
201      * Generate a URL to a route
202      *
203      * @param string    $route        Name of the route to travel
204      * @param array    $params        String or array of additional url parameters
205      * @param bool    $is_amp        Is url using &amp; (true) or & (false)
206      * @param string|bool        $session_id    Possibility to use a custom session id instead of the global one
207      * @param int    $reference_type    The type of reference to be generated (one of the constants)
208      * @return string The URL already passed through append_sid()
209      */
210      public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
211      {
212          return $this->routing_helper->route($route, $params, $is_amp, $session_id, $reference_type);
213      }
214   
215      /**
216      * Output an error, effectively the same thing as trigger_error
217      *
218      * @param string $message The error message
219      * @param int $code The error code (e.g. 404, 500, 503, etc.)
220      * @return Response A Response instance
221      *
222      * @deprecated 3.1.3 (To be removed: 4.0.0) Use exceptions instead.
223      */
224      public function error($message, $code = 500)
225      {
226          return $this->message($message, array(), 'INFORMATION', $code);
227      }
228   
229      /**
230       * Output a message
231       *
232       * In case of an error, please throw an exception instead
233       *
234       * @param string $message The message to display (must be a language variable)
235       * @param array $parameters The parameters to use with the language var
236       * @param string $title Title for the message (must be a language variable)
237       * @param int $code The HTTP status code (e.g. 404, 500, 503, etc.)
238       * @return Response A Response instance
239       */
240      public function message($message, array $parameters = array(), $title = 'INFORMATION', $code = 200)
241      {
242          array_unshift($parameters, $message);
243          $message_text = call_user_func_array(array($this->language, 'lang'), $parameters);
244          $message_title = $this->language->lang($title);
245   
246          if ($this->request->is_ajax())
247          {
248              global $refresh_data;
249   
250              return new JsonResponse(
251                  array(
252                      'MESSAGE_TITLE'        => $message_title,
253                      'MESSAGE_TEXT'        => $message_text,
254                      'S_USER_WARNING'    => false,
255                      'S_USER_NOTICE'        => false,
256                      'REFRESH_DATA'        => (!empty($refresh_data)) ? $refresh_data : null
257                  ),
258                  $code
259              );
260          }
261   
262          $this->template->assign_vars(array(
263              'MESSAGE_TEXT'    => $message_text,
264              'MESSAGE_TITLE'    => $message_title,
265          ));
266   
267          return $this->render('message_body.html', $message_title, $code);
268      }
269   
270      /**
271       * Assigns automatic refresh time meta tag in template
272       *
273       * @param    int        $time    time in seconds, when redirection should occur
274       * @param    string    $url    the URL where the user should be redirected
275       * @return    void
276       */
277      public function assign_meta_refresh_var($time, $url)
278      {
279          $this->template->assign_vars(array(
280              'META' => '<meta http-equiv="refresh" content="' . $time . '; url=' . $url . '" />',
281          ));
282      }
283   
284      /**
285      * Return the current url
286      *
287      * @return string
288      */
289      public function get_current_url()
290      {
291          return generate_board_url(true) . $this->request->escape($this->symfony_request->getRequestUri(), true);
292      }
293   
294      /**
295       * Handle display actions for footer, e.g. SQL report and credit line
296       *
297       * @param bool $run_cron Flag whether cron should be run
298       *
299       * @return void
300       */
301      public function display_footer($run_cron = true)
302      {
303          $this->display_sql_report();
304   
305          $this->template->assign_vars([
306                  'DEBUG_OUTPUT'            => phpbb_generate_debug_output($this->db, $this->config, $this->auth, $this->user, $this->dispatcher),
307                  'TRANSLATION_INFO'        => $this->language->is_set('TRANSLATION_INFO') ? $this->language->lang('TRANSLATION_INFO') : '',
308                  'CREDIT_LINE'            => $this->language->lang('POWERED_BY', '<a href="https://www.phpbb.com/">phpBB</a>&reg; Forum Software &copy; phpBB Limited'),
309   
310                  'U_ACP'                    => ($this->auth->acl_get('a_') && !empty($this->user->data['is_registered'])) ? append_sid("{$this->admin_path}index.{$this->php_ext}", false, true, $this->user->session_id) : '',
311          ]);
312   
313          if ($run_cron)
314          {
315              $this->set_cron_task();
316          }
317      }
318   
319      /**
320       * Display SQL report
321       *
322       * @return void
323       */
324      public function display_sql_report()
325      {
326          if ($this->sql_explain && $this->request->variable('explain', false) && $this->auth->acl_get('a_'))
327          {
328              $this->db->sql_report('display');
329          }
330      }
331   
332      /**
333       * Set cron task for footer
334       *
335       * @return void
336       */
337      protected function set_cron_task()
338      {
339          // Call cron-type script
340          $call_cron = false;
341          if (!defined('IN_CRON') && !$this->config['use_system_cron'] && !$this->config['board_disable'] && !$this->user->data['is_bot'] && !$this->cache->get('_cron.lock_check'))
342          {
343              $call_cron = true;
344              $time_now = (!empty($this->user->time_now) && is_int($this->user->time_now)) ? $this->user->time_now : time();
345   
346              // Any old lock present?
347              if (!empty($this->config['cron_lock']))
348              {
349                  $cron_time = explode(' ', $this->config['cron_lock']);
350   
351                  // If 1 hour lock is present we do not set a cron task
352                  if ($cron_time[0] + 3600 >= $time_now)
353                  {
354                      $call_cron = false;
355                  }
356              }
357          }
358   
359          // Call cron job?
360          if ($call_cron)
361          {
362              $task = $this->cron_manager->find_one_ready_task();
363   
364              if ($task)
365              {
366                  $cron_task_tag = $task->get_html_tag();
367                  $this->template->assign_var('RUN_CRON_TASK', $cron_task_tag);
368              }
369              else
370              {
371                  $this->cache->put('_cron.lock_check', true, 60);
372              }
373          }
374      }
375  }
376