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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ajax_iohandler.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 9.93 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\install\helper\iohandler;
015   
016  use phpbb\path_helper;
017  use phpbb\routing\router;
018   
019  /**
020   * Input-Output handler for the AJAX frontend
021   */
022  class ajax_iohandler extends iohandler_base
023  {
024      /**
025       * @var path_helper
026       */
027      protected $path_helper;
028   
029      /**
030       * @var \phpbb\request\request_interface
031       */
032      protected $request;
033   
034      /**
035       * @var \phpbb\template\template
036       */
037      protected $template;
038   
039      /**
040       * @var router
041       */
042      protected $router;
043   
044      /**
045       * @var string
046       */
047      protected $phpbb_root_path;
048   
049      /**
050       * @var string
051       */
052      protected $file_status;
053   
054      /**
055       * @var string
056       */
057      protected $form;
058   
059      /**
060       * @var bool
061       */
062      protected $request_client_refresh;
063   
064      /**
065       * @var array
066       */
067      protected $nav_data;
068   
069      /**
070       * @var array
071       */
072      protected $cookies;
073   
074      /**
075       * @var array
076       */
077      protected $download;
078   
079      /**
080       * @var array
081       */
082      protected $redirect_url;
083   
084      /**
085       * @var resource
086       */
087      protected $file_lock_pointer;
088   
089      /**
090       * Constructor
091       *
092       * @param path_helper                        $path_helper
093       * @param \phpbb\request\request_interface    $request    HTTP request interface
094       * @param \phpbb\template\template            $template    Template engine
095       * @param router                             $router        Router
096       * @param string                             $root_path    Path to phpBB's root
097       */
098      public function __construct(path_helper $path_helper, \phpbb\request\request_interface $request, \phpbb\template\template $template, router $router, $root_path)
099      {
100          $this->path_helper = $path_helper;
101          $this->request    = $request;
102          $this->router    = $router;
103          $this->template    = $template;
104          $this->form        = '';
105          $this->nav_data    = array();
106          $this->cookies    = array();
107          $this->download    = array();
108          $this->redirect_url = array();
109          $this->file_status = '';
110          $this->phpbb_root_path = $root_path;
111   
112          parent::__construct();
113      }
114   
115      /**
116       * {@inheritdoc}
117       */
118      public function get_input($name, $default, $multibyte = false)
119      {
120          return $this->request->variable($name, $default, $multibyte);
121      }
122   
123      /**
124       * {@inheritdoc}
125       */
126      public function get_raw_input($name, $default)
127      {
128          return $this->request->raw_variable($name, $default);
129      }
130   
131      /**
132       * {@inheritdoc}
133       */
134      public function get_server_variable($name, $default = '')
135      {
136          return $this->request->server($name, $default);
137      }
138   
139      /**
140       * {@inheritdoc}
141       */
142      public function get_header_variable($name, $default = '')
143      {
144          return $this->request->header($name, $default);
145      }
146   
147      /**
148       * {@inheritdoc}
149       */
150      public function is_secure()
151      {
152          return $this->request->is_secure();
153      }
154   
155      /**
156       * {@inheritdoc}
157       */
158      public function add_user_form_group($title, $form)
159      {
160          $this->form = $this->generate_form_render_data($title, $form);
161      }
162   
163      /**
164       * {@inheritdoc}
165       */
166      public function generate_form_render_data($title, $form)
167      {
168          $this->template->assign_block_vars('options', array(
169              'LEGEND'    => $this->language->lang($title),
170              'S_LEGEND'    => true,
171          ));
172   
173          $not_button_form = false;
174   
175          foreach ($form as $input_name => $input_options)
176          {
177              if (!isset($input_options['type']))
178              {
179                  continue;
180              }
181   
182              $tpl_ary = array();
183              $not_button_form = ($input_options['type'] !== 'submit' || $not_button_form);
184   
185              $tpl_ary['TYPE'] = $input_options['type'];
186              $tpl_ary['TITLE'] = $this->language->lang($input_options['label']);
187              $tpl_ary['KEY'] = $input_name;
188              $tpl_ary['S_EXPLAIN'] = false;
189   
190              if (isset($input_options['default']))
191              {
192                  $default = $input_options['default'];
193                  $default = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', array($this, 'lang_replace_callback'), $default);
194                  $tpl_ary['DEFAULT'] = $default;
195              }
196   
197              if (isset($input_options['description']))
198              {
199                  $tpl_ary['TITLE_EXPLAIN'] = $this->language->lang($input_options['description']);
200                  $tpl_ary['S_EXPLAIN'] = true;
201              }
202   
203              if (in_array($input_options['type'], array('select', 'radio'), true))
204              {
205                  for ($i = 0, $total = sizeof($input_options['options']); $i < $total; $i++)
206                  {
207                      if (isset($input_options['options'][$i]['label']))
208                      {
209                          $input_options['options'][$i]['label'] = $this->language->lang($input_options['options'][$i]['label']);
210                      }
211                  }
212   
213                  $tpl_ary['OPTIONS'] = $input_options['options'];
214              }
215   
216              $block_name = ($input_options['type'] === 'submit') ? 'submit_buttons' : 'options';
217              $this->template->assign_block_vars($block_name, $tpl_ary);
218          }
219   
220          $this->template->assign_var('S_NOT_ONLY_BUTTON_FORM', $not_button_form);
221   
222          $this->template->set_filenames(array(
223              'form_install' => 'installer_form.html',
224          ));
225   
226          return $this->template->assign_display('form_install');
227      }
228   
229      /**
230       * {@inheritdoc}
231       */
232      public function send_response($no_more_output = false)
233      {
234          $json_data_array = $this->prepare_json_array($no_more_output);
235   
236          if (empty($json_data_array))
237          {
238              return;
239          }
240   
241          $json_data = json_encode($json_data_array);
242   
243          // Try to push content to the browser
244          print(str_pad(' ', 4096) . "\n");
245          print($json_data . "\n\n");
246          flush();
247      }
248   
249      /**
250       * Prepares iohandler's data to be sent out to the client.
251       *
252       * @param bool    $no_more_output    Whether or not there will be more output in this response
253       *
254       * @return array
255       */
256      protected function prepare_json_array($no_more_output = false)
257      {
258          $json_array = array();
259   
260          if (!empty($this->errors))
261          {
262              $json_array['errors'] = $this->errors;
263              $this->errors = array();
264          }
265   
266          if (!empty($this->warnings))
267          {
268              $json_array['warnings'] = $this->warnings;
269              $this->warnings = array();
270          }
271   
272          if (!empty($this->logs))
273          {
274              $json_array['logs'] = $this->logs;
275              $this->logs = array();
276          }
277   
278          if (!empty($this->success))
279          {
280              $json_array['success'] = $this->success;
281              $this->success = array();
282          }
283   
284          if (!empty($this->download))
285          {
286              $json_array['download'] = $this->download;
287              $this->download = array();
288          }
289   
290          if (!empty($this->form))
291          {
292              $json_array['form'] = $this->form;
293              $this->form = '';
294          }
295   
296          if (!empty($this->file_status))
297          {
298              $json_array['file_status'] = $this->file_status;
299              $this->file_status = '';
300          }
301   
302          // If current task name is set, we push progress message to the client side
303          if (!empty($this->current_task_name))
304          {
305              $json_array['progress'] = array(
306                  'task_name'        => $this->current_task_name,
307                  'task_num'        => $this->current_task_progress,
308                  'task_count'    => $this->task_progress_count,
309              );
310   
311              if ($this->restart_progress_bar)
312              {
313                  $json_array['progress']['restart'] = 1;
314                  $this->restart_progress_bar = false;
315              }
316          }
317   
318          if (!empty($this->nav_data))
319          {
320              $json_array['nav'] = $this->nav_data;
321              $this->nav_data = array();
322          }
323   
324          if ($this->request_client_refresh)
325          {
326              $json_array['refresh'] = true;
327              $this->request_client_refresh = false;
328          }
329   
330          if (!empty($this->cookies))
331          {
332              $json_array['cookies'] = $this->cookies;
333              $this->cookies = array();
334          }
335   
336          if (!empty($this->redirect_url))
337          {
338              $json_array['redirect'] = $this->redirect_url;
339              $this->redirect_url = array();
340          }
341   
342          if ($no_more_output)
343          {
344              $json_array['over'] = true;
345          }
346   
347          return $json_array;
348      }
349   
350      /**
351       * {@inheritdoc}
352       */
353      public function set_progress($task_lang_key, $task_number)
354      {
355          parent::set_progress($task_lang_key, $task_number);
356          $this->send_response();
357      }
358   
359      /**
360       * {@inheritdoc}
361       */
362      public function request_refresh()
363      {
364          $this->request_client_refresh = true;
365      }
366   
367      /**
368       * {@inheritdoc}
369       */
370      public function set_active_stage_menu($menu_path)
371      {
372          $this->nav_data['active'] = $menu_path[sizeof($menu_path) - 1];
373          $this->send_response();
374      }
375   
376      /**
377       * {@inheritdoc}
378       */
379      public function set_finished_stage_menu($menu_path)
380      {
381          $this->nav_data['finished'][] = $menu_path[sizeof($menu_path) - 1];
382          $this->send_response();
383      }
384   
385      /**
386       * {@inheritdoc}
387       */
388      public function set_cookie($cookie_name, $cookie_value)
389      {
390          $this->cookies[] = array(
391              'name' => $cookie_name,
392              'value' => $cookie_value
393          );
394      }
395   
396      /**
397       * {@inheritdoc}
398       */
399      public function add_download_link($route, $title, $msg = null)
400      {
401          $link_properties = array(
402              'href'    => $this->router->generate($route),
403              'title'    => $this->language->lang($title),
404              'download' => $this->language->lang('DOWNLOAD'),
405          );
406   
407          if ($msg !== null)
408          {
409              $link_properties['msg'] = htmlspecialchars_decode($this->language->lang($msg));
410          }
411   
412          $this->download[] = $link_properties;
413      }
414   
415      /**
416       * {@inheritdoc}
417       */
418      public function render_update_file_status($status_array)
419      {
420          $this->template->assign_vars(array(
421              'T_IMAGE_PATH'    => $this->path_helper->get_web_root_path() . 'adm/images/',
422          ));
423   
424          foreach ($status_array as $block => $list)
425          {
426              foreach ($list as $filename)
427              {
428                  $dirname = dirname($filename);
429   
430                  $this->template->assign_block_vars($block, array(
431                      'STATUS'            => $block,
432                      'FILENAME'            => $filename,
433                      'DIR_PART'            => (!empty($dirname) && $dirname !== '.') ? dirname($filename) . '/' : false,
434                      'FILE_PART'            => basename($filename),
435                  ));
436              }
437          }
438   
439          $this->template->set_filenames(array(
440              'file_status' => 'installer_update_file_status.html',
441          ));
442   
443          $this->file_status = $this->template->assign_display('file_status');
444      }
445   
446      /**
447       * {@inheritdoc}
448       */
449      public function redirect($url, $use_ajax = false)
450      {
451          $this->redirect_url = array('url' => $url, 'use_ajax' => $use_ajax);
452          $this->send_response(true);
453      }
454   
455      /**
456       * Acquires a file lock
457       */
458      public function acquire_lock()
459      {
460          $lock_file = $this->phpbb_root_path . 'store/io_lock.lock';
461          $this->file_lock_pointer = @fopen($lock_file, 'w+');
462   
463          if ($this->file_lock_pointer)
464          {
465              flock($this->file_lock_pointer, LOCK_EX);
466          }
467      }
468   
469      /**
470       * Release file lock
471       */
472      public function release_lock()
473      {
474          if ($this->file_lock_pointer)
475          {
476              fwrite($this->file_lock_pointer, 'ok');
477              flock($this->file_lock_pointer, LOCK_UN);
478              fclose($this->file_lock_pointer);
479          }
480      }
481   
482      /**
483       * Callback function for language replacing
484       *
485       * @param array    $matches
486       * @return string
487       */
488      public function lang_replace_callback($matches)
489      {
490          if (!empty($matches[1]))
491          {
492              return $this->language->lang($matches[1]);
493          }
494   
495          return '';
496      }
497  }
498