2012-10-19 19:54:19 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @package controller
|
|
|
|
* @copyright (c) 2012 phpBB Group
|
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller helper class, contains methods that do things for controllers
|
|
|
|
* @package phpBB3
|
|
|
|
*/
|
|
|
|
class phpbb_controller_helper
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Template object
|
|
|
|
* @var phpbb_template
|
|
|
|
*/
|
|
|
|
protected $template;
|
|
|
|
|
|
|
|
/**
|
2012-11-13 09:26:31 -05:00
|
|
|
* User object
|
|
|
|
* @var phpbb_user
|
|
|
|
*/
|
|
|
|
protected $user;
|
|
|
|
|
2013-09-02 10:51:46 -07:00
|
|
|
/**
|
|
|
|
* Request object
|
|
|
|
* @var phpbb_request
|
|
|
|
*/
|
|
|
|
protected $request;
|
|
|
|
|
2012-11-13 09:26:31 -05:00
|
|
|
/**
|
|
|
|
* phpBB root path
|
2012-10-19 19:54:19 -04:00
|
|
|
* @var string
|
|
|
|
*/
|
2012-11-16 10:37:07 -05:00
|
|
|
protected $phpbb_root_path;
|
2012-10-19 19:54:19 -04:00
|
|
|
|
|
|
|
/**
|
2012-11-13 09:26:31 -05:00
|
|
|
* PHP extension
|
2012-10-19 19:54:19 -04:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $php_ext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2012-11-13 09:26:31 -05:00
|
|
|
* @param phpbb_template $template Template object
|
|
|
|
* @param phpbb_user $user User object
|
2012-11-16 10:37:07 -05:00
|
|
|
* @param string $phpbb_root_path phpBB root path
|
2012-11-13 09:26:31 -05:00
|
|
|
* @param string $php_ext PHP extension
|
2012-10-19 19:54:19 -04:00
|
|
|
*/
|
2013-09-02 12:53:37 -07:00
|
|
|
public function __construct(phpbb_template $template, phpbb_user $user, phpbb_request_interface $request, $phpbb_root_path, $php_ext)
|
2012-10-19 19:54:19 -04:00
|
|
|
{
|
2012-11-13 09:26:31 -05:00
|
|
|
$this->template = $template;
|
|
|
|
$this->user = $user;
|
2013-09-02 10:51:46 -07:00
|
|
|
$this->request = $request;
|
2012-11-16 10:37:07 -05:00
|
|
|
$this->phpbb_root_path = $phpbb_root_path;
|
2012-11-13 09:26:31 -05:00
|
|
|
$this->php_ext = $php_ext;
|
2012-10-19 19:54:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automate setting up the page and creating the response object.
|
|
|
|
*
|
|
|
|
* @param string $handle The template handle to render
|
|
|
|
* @param string $page_title The title of the page to output
|
|
|
|
* @param int $status_code The status code to be sent to the page header
|
|
|
|
* @return Response object containing rendered page
|
|
|
|
*/
|
|
|
|
public function render($template_file, $page_title = '', $status_code = 200)
|
|
|
|
{
|
|
|
|
page_header($page_title);
|
|
|
|
|
|
|
|
$this->template->set_filenames(array(
|
|
|
|
'body' => $template_file,
|
|
|
|
));
|
|
|
|
|
|
|
|
page_footer(true, false, false);
|
|
|
|
|
2012-11-13 10:42:20 -05:00
|
|
|
return new Response($this->template->assign_display('body'), $status_code);
|
2012-10-19 19:54:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-18 14:00:40 -05:00
|
|
|
* Generate a URL
|
2012-10-19 19:54:19 -04:00
|
|
|
*
|
2013-03-15 13:35:43 +01:00
|
|
|
* @param string $route The route to travel
|
|
|
|
* @param mixed $params String or array of additional url parameters
|
|
|
|
* @param bool $is_amp Is url using & (true) or & (false)
|
|
|
|
* @param string $session_id Possibility to use a custom session id instead of the global one
|
2013-01-18 14:00:40 -05:00
|
|
|
* @return string The URL already passed through append_sid()
|
2012-10-19 19:54:19 -04:00
|
|
|
*/
|
2013-03-15 13:35:43 +01:00
|
|
|
public function url($route, $params = false, $is_amp = true, $session_id = false)
|
2012-10-19 19:54:19 -04:00
|
|
|
{
|
2013-03-15 15:21:15 +01:00
|
|
|
$route_params = '';
|
|
|
|
if (($route_delim = strpos($route, '?')) !== false)
|
|
|
|
{
|
|
|
|
$route_params = substr($route, $route_delim);
|
|
|
|
$route = substr($route, 0, $route_delim);
|
|
|
|
}
|
|
|
|
|
2013-09-02 10:51:46 -07:00
|
|
|
$request_uri = $this->request->variable('REQUEST_URI', '', false, phpbb_request::SERVER);
|
|
|
|
$script_name = $this->request->variable('SCRIPT_NAME', '', false, phpbb_request::SERVER);
|
|
|
|
|
|
|
|
// If the app.php file is being used (no rewrite) keep it in the URL.
|
|
|
|
// Otherwise, don't include it.
|
|
|
|
$route_prefix = $this->phpbb_root_path;
|
|
|
|
$parts = explode('/', $script_name);
|
|
|
|
$route_prefix .= strpos($request_uri, $script_name) === 0 ? array_pop($parts) . '/' : '';
|
2013-03-15 13:35:43 +01:00
|
|
|
|
2013-09-02 10:51:46 -07:00
|
|
|
return append_sid($route_prefix . "$route" . $route_params, $params, $is_amp, $session_id);
|
2012-10-19 19:54:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output an error, effectively the same thing as trigger_error
|
|
|
|
*
|
|
|
|
* @param string $message The error message
|
2012-11-16 10:38:40 -05:00
|
|
|
* @param string $code The error code (e.g. 404, 500, 503, etc.)
|
2012-10-19 19:54:19 -04:00
|
|
|
* @return Response A Reponse instance
|
|
|
|
*/
|
2012-11-16 10:38:40 -05:00
|
|
|
public function error($message, $code = 500)
|
2012-10-19 19:54:19 -04:00
|
|
|
{
|
|
|
|
$this->template->assign_vars(array(
|
|
|
|
'MESSAGE_TEXT' => $message,
|
2012-11-13 09:26:31 -05:00
|
|
|
'MESSAGE_TITLE' => $this->user->lang('INFORMATION'),
|
2012-10-19 19:54:19 -04:00
|
|
|
));
|
|
|
|
|
2012-11-13 09:26:31 -05:00
|
|
|
return $this->render('message_body.html', $this->user->lang('INFORMATION'), $code);
|
2012-10-19 19:54:19 -04:00
|
|
|
}
|
|
|
|
}
|