[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/controller/ -> helper.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\controller;
  15  
  16  use Symfony\Component\HttpFoundation\JsonResponse;
  17  use Symfony\Component\HttpFoundation\Response;
  18  use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19  
  20  /**
  21  * Controller helper class, contains methods that do things for controllers
  22  */
  23  class helper
  24  {
  25      /**
  26      * Template object
  27      * @var \phpbb\template\template
  28      */
  29      protected $template;
  30  
  31      /**
  32      * User object
  33      * @var \phpbb\user
  34      */
  35      protected $user;
  36  
  37      /**
  38      * config object
  39      * @var \phpbb\config\config
  40      */
  41      protected $config;
  42  
  43      /* @var \phpbb\symfony_request */
  44      protected $symfony_request;
  45  
  46      /* @var \phpbb\request\request_interface */
  47      protected $request;
  48  
  49      /**
  50       * @var \phpbb\routing\helper
  51       */
  52      protected $routing_helper;
  53  
  54      /**
  55       * Constructor
  56       *
  57       * @param \phpbb\template\template $template Template object
  58       * @param \phpbb\user $user User object
  59       * @param \phpbb\config\config $config Config object
  60       * @param \phpbb\symfony_request $symfony_request Symfony Request object
  61       * @param \phpbb\request\request_interface $request phpBB request object
  62       * @param \phpbb\routing\helper $routing_helper Helper to generate the routes
  63       */
  64  	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\routing\helper $routing_helper)
  65      {
  66          $this->template = $template;
  67          $this->user = $user;
  68          $this->config = $config;
  69          $this->symfony_request = $symfony_request;
  70          $this->request = $request;
  71          $this->routing_helper = $routing_helper;
  72      }
  73  
  74      /**
  75      * Automate setting up the page and creating the response object.
  76      *
  77      * @param string $template_file The template handle to render
  78      * @param string $page_title The title of the page to output
  79      * @param int $status_code The status code to be sent to the page header
  80      * @param bool $display_online_list Do we display online users list
  81      * @param int $item_id Restrict online users to item id
  82      * @param string $item Restrict online users to a certain session item, e.g. forum for session_forum_id
  83      * @param bool $send_headers Whether headers should be sent by page_header(). Defaults to false for controllers.
  84      *
  85      * @return Response object containing rendered page
  86      */
  87  	public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false, $item_id = 0, $item = 'forum', $send_headers = false)
  88      {
  89          page_header($page_title, $display_online_list, $item_id, $item, $send_headers);
  90  
  91          $this->template->set_filenames(array(
  92              'body'    => $template_file,
  93          ));
  94  
  95          page_footer(true, false, false);
  96  
  97          $headers = !empty($this->user->data['is_bot']) ? array('X-PHPBB-IS-BOT' => 'yes') : array();
  98  
  99          return new Response($this->template->assign_display('body'), $status_code, $headers);
 100      }
 101  
 102      /**
 103      * Generate a URL to a route
 104      *
 105      * @param string    $route        Name of the route to travel
 106      * @param array    $params        String or array of additional url parameters
 107      * @param bool    $is_amp        Is url using &amp; (true) or & (false)
 108      * @param string|bool        $session_id    Possibility to use a custom session id instead of the global one
 109      * @param bool|string        $reference_type The type of reference to be generated (one of the constants)
 110      * @return string The URL already passed through append_sid()
 111      */
 112  	public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
 113      {
 114          return $this->routing_helper->route($route, $params, $is_amp, $session_id, $reference_type);
 115      }
 116  
 117      /**
 118      * Output an error, effectively the same thing as trigger_error
 119      *
 120      * @param string $message The error message
 121      * @param int $code The error code (e.g. 404, 500, 503, etc.)
 122      * @return Response A Response instance
 123      *
 124      * @deprecated 3.1.3 (To be removed: 3.3.0) Use exceptions instead.
 125      */
 126  	public function error($message, $code = 500)
 127      {
 128          return $this->message($message, array(), 'INFORMATION', $code);
 129      }
 130  
 131      /**
 132       * Output a message
 133       *
 134       * In case of an error, please throw an exception instead
 135       *
 136       * @param string $message The message to display (must be a language variable)
 137       * @param array $parameters The parameters to use with the language var
 138       * @param string $title Title for the message (must be a language variable)
 139       * @param int $code The HTTP status code (e.g. 404, 500, 503, etc.)
 140       * @return Response A Response instance
 141       */
 142  	public function message($message, array $parameters = array(), $title = 'INFORMATION', $code = 200)
 143      {
 144          array_unshift($parameters, $message);
 145          $message_text = call_user_func_array(array($this->user, 'lang'), $parameters);
 146          $message_title = $this->user->lang($title);
 147  
 148          if ($this->request->is_ajax())
 149          {
 150              global $refresh_data;
 151  
 152              return new JsonResponse(
 153                  array(
 154                      'MESSAGE_TITLE'        => $message_title,
 155                      'MESSAGE_TEXT'        => $message_text,
 156                      'S_USER_WARNING'    => false,
 157                      'S_USER_NOTICE'        => false,
 158                      'REFRESH_DATA'        => (!empty($refresh_data)) ? $refresh_data : null
 159                  ),
 160                  $code
 161              );
 162          }
 163  
 164          $this->template->assign_vars(array(
 165              'MESSAGE_TEXT'    => $message_text,
 166              'MESSAGE_TITLE'    => $message_title,
 167          ));
 168  
 169          return $this->render('message_body.html', $message_title, $code);
 170      }
 171  
 172      /**
 173       * Assigns automatic refresh time meta tag in template
 174       *
 175       * @param    int        $time    time in seconds, when redirection should occur
 176       * @param    string    $url    the URL where the user should be redirected
 177       * @return    null
 178       */
 179  	public function assign_meta_refresh_var($time, $url)
 180      {
 181          $this->template->assign_vars(array(
 182              'META' => '<meta http-equiv="refresh" content="' . $time . '; url=' . $url . '" />',
 183          ));
 184      }
 185  
 186      /**
 187      * Return the current url
 188      *
 189      * @return string
 190      */
 191  	public function get_current_url()
 192      {
 193          return generate_board_url(true) . $this->request->escape($this->symfony_request->getRequestUri(), true);
 194      }
 195  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1