[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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\UrlGenerator; 19 use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 20 use Symfony\Component\Routing\RequestContext; 21 22 /** 23 * Controller helper class, contains methods that do things for controllers 24 */ 25 class helper 26 { 27 /** 28 * Template object 29 * @var \phpbb\template\template 30 */ 31 protected $template; 32 33 /** 34 * User object 35 * @var \phpbb\user 36 */ 37 protected $user; 38 39 /** 40 * config object 41 * @var \phpbb\config\config 42 */ 43 protected $config; 44 45 /* @var \phpbb\symfony_request */ 46 protected $symfony_request; 47 48 /* @var \phpbb\request\request_interface */ 49 protected $request; 50 51 /** 52 * @var \phpbb\filesystem The filesystem object 53 */ 54 protected $filesystem; 55 56 /** 57 * phpBB root path 58 * @var string 59 */ 60 protected $phpbb_root_path; 61 62 /** 63 * PHP file extension 64 * @var string 65 */ 66 protected $php_ext; 67 68 /** 69 * Constructor 70 * 71 * @param \phpbb\template\template $template Template object 72 * @param \phpbb\user $user User object 73 * @param \phpbb\config\config $config Config object 74 * 75 * @param \phpbb\controller\provider $provider Path provider 76 * @param \phpbb\extension\manager $manager Extension manager object 77 * @param \phpbb\symfony_request $symfony_request Symfony Request object 78 * @param \phpbb\request\request_interface $request phpBB request object 79 * @param \phpbb\filesystem $filesystem The filesystem object 80 * @param string $phpbb_root_path phpBB root path 81 * @param string $php_ext PHP file extension 82 */ 83 public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext) 84 { 85 $this->template = $template; 86 $this->user = $user; 87 $this->config = $config; 88 $this->symfony_request = $symfony_request; 89 $this->request = $request; 90 $this->filesystem = $filesystem; 91 $this->phpbb_root_path = $phpbb_root_path; 92 $this->php_ext = $php_ext; 93 $provider->find_routing_files($manager->get_finder()); 94 $this->route_collection = $provider->find($phpbb_root_path)->get_routes(); 95 } 96 97 /** 98 * Automate setting up the page and creating the response object. 99 * 100 * @param string $template_file The template handle to render 101 * @param string $page_title The title of the page to output 102 * @param int $status_code The status code to be sent to the page header 103 * @param bool $display_online_list Do we display online users list 104 * @param int $item_id Restrict online users to item id 105 * @param string $item Restrict online users to a certain session item, e.g. forum for session_forum_id 106 * @param bool $send_headers Whether headers should be sent by page_header(). Defaults to false for controllers. 107 * 108 * @return Response object containing rendered page 109 */ 110 public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false, $item_id = 0, $item = 'forum', $send_headers = false) 111 { 112 page_header($page_title, $display_online_list, $item_id, $item, $send_headers); 113 114 $this->template->set_filenames(array( 115 'body' => $template_file, 116 )); 117 118 page_footer(true, false, false); 119 120 $headers = !empty($this->user->data['is_bot']) ? array('X-PHPBB-IS-BOT' => 'yes') : array(); 121 122 return new Response($this->template->assign_display('body'), $status_code, $headers); 123 } 124 125 /** 126 * Generate a URL to a route 127 * 128 * @param string $route Name of the route to travel 129 * @param array $params String or array of additional url parameters 130 * @param bool $is_amp Is url using & (true) or & (false) 131 * @param string|bool $session_id Possibility to use a custom session id instead of the global one 132 * @param bool|string $reference_type The type of reference to be generated (one of the constants) 133 * @return string The URL already passed through append_sid() 134 */ 135 public function route($route, array $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) 136 { 137 $anchor = ''; 138 if (isset($params['#'])) 139 { 140 $anchor = '#' . $params['#']; 141 unset($params['#']); 142 } 143 144 $context = new RequestContext(); 145 $context->fromRequest($this->symfony_request); 146 147 if ($this->config['force_server_vars']) 148 { 149 $context->setHost($this->config['server_name']); 150 $context->setScheme(substr($this->config['server_protocol'], 0, -3)); 151 $context->setHttpPort($this->config['server_port']); 152 $context->setHttpsPort($this->config['server_port']); 153 $context->setBaseUrl(rtrim($this->config['script_path'], '/')); 154 } 155 156 $script_name = $this->symfony_request->getScriptName(); 157 $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); 158 159 $base_url = $context->getBaseUrl(); 160 161 // Append page name if base URL does not contain it 162 if (!empty($page_name) && strpos($base_url, '/' . $page_name) === false) 163 { 164 $base_url .= '/' . $page_name; 165 } 166 167 // If enable_mod_rewrite is false we need to replace the current front-end by app.php, otherwise we need to remove it. 168 $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); 169 170 // We need to update the base url to move to the directory of the app.php file if the current script is not app.php 171 if ($page_name !== 'app.php' && !$this->config['force_server_vars']) 172 { 173 if (empty($this->config['enable_mod_rewrite'])) 174 { 175 $base_url = str_replace('/app.' . $this->php_ext, '/' . $this->phpbb_root_path . 'app.' . $this->php_ext, $base_url); 176 } 177 else 178 { 179 $base_url .= preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), '$2', $this->phpbb_root_path); 180 } 181 } 182 183 $base_url = $this->request->escape($this->filesystem->clean_path($base_url), true); 184 185 $context->setBaseUrl($base_url); 186 187 $url_generator = new UrlGenerator($this->route_collection, $context); 188 $route_url = $url_generator->generate($route, $params, $reference_type); 189 190 if ($is_amp) 191 { 192 $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url); 193 } 194 195 if ($reference_type === UrlGeneratorInterface::RELATIVE_PATH && empty($this->config['enable_mod_rewrite'])) 196 { 197 $route_url = 'app.' . $this->php_ext . '/' . $route_url; 198 } 199 200 return append_sid($route_url . $anchor, false, $is_amp, $session_id, true); 201 } 202 203 /** 204 * Output an error, effectively the same thing as trigger_error 205 * 206 * @param string $message The error message 207 * @param int $code The error code (e.g. 404, 500, 503, etc.) 208 * @return Response A Response instance 209 * 210 * @deprecated 3.1.3 (To be removed: 3.3.0) Use exceptions instead. 211 */ 212 public function error($message, $code = 500) 213 { 214 return $this->message($message, array(), 'INFORMATION', $code); 215 } 216 217 /** 218 * Output a message 219 * 220 * In case of an error, please throw an exception instead 221 * 222 * @param string $message The message to display (must be a language variable) 223 * @param array $parameters The parameters to use with the language var 224 * @param string $title Title for the message (must be a language variable) 225 * @param int $code The HTTP status code (e.g. 404, 500, 503, etc.) 226 * @return Response A Response instance 227 */ 228 public function message($message, array $parameters = array(), $title = 'INFORMATION', $code = 200) 229 { 230 array_unshift($parameters, $message); 231 $message_text = call_user_func_array(array($this->user, 'lang'), $parameters); 232 $message_title = $this->user->lang($title); 233 234 if ($this->request->is_ajax()) 235 { 236 global $refresh_data; 237 238 return new JsonResponse( 239 array( 240 'MESSAGE_TITLE' => $message_title, 241 'MESSAGE_TEXT' => $message_text, 242 'S_USER_WARNING' => false, 243 'S_USER_NOTICE' => false, 244 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null 245 ), 246 $code 247 ); 248 } 249 250 $this->template->assign_vars(array( 251 'MESSAGE_TEXT' => $message_text, 252 'MESSAGE_TITLE' => $message_title, 253 )); 254 255 return $this->render('message_body.html', $message_title, $code); 256 } 257 258 /** 259 * Return the current url 260 * 261 * @return string 262 */ 263 public function get_current_url() 264 { 265 return generate_board_url(true) . $this->request->escape($this->symfony_request->getRequestUri(), true); 266 } 267 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |