aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/controller/helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/controller/helper.php')
-rw-r--r--phpBB/phpbb/controller/helper.php77
1 files changed, 43 insertions, 34 deletions
diff --git a/phpBB/phpbb/controller/helper.php b/phpBB/phpbb/controller/helper.php
index 4d240f9380..54c30c93fc 100644
--- a/phpBB/phpbb/controller/helper.php
+++ b/phpBB/phpbb/controller/helper.php
@@ -7,39 +7,35 @@
*
*/
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
+namespace phpbb\controller;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\Generator\UrlGenerator;
+use Symfony\Component\Routing\RequestContext;
/**
* Controller helper class, contains methods that do things for controllers
* @package phpBB3
*/
-class phpbb_controller_helper
+class helper
{
/**
* Template object
- * @var phpbb_template
+ * @var \phpbb\template\template
*/
protected $template;
/**
* User object
- * @var phpbb_user
+ * @var \phpbb\user
*/
protected $user;
/**
- * Request object
- * @var phpbb_request
+ * config object
+ * @var \phpbb\config\config
*/
- protected $request;
+ protected $config;
/**
* phpBB root path
@@ -56,18 +52,21 @@ class phpbb_controller_helper
/**
* Constructor
*
- * @param phpbb_template $template Template object
- * @param phpbb_user $user User object
+ * @param \phpbb\template\template $template Template object
+ * @param \phpbb\user $user User object
+ * @param \phpbb\config\config $config Config object
+ * @param \phpbb\controller\provider $provider Path provider
* @param string $phpbb_root_path phpBB root path
* @param string $php_ext PHP extension
*/
- public function __construct(phpbb_template $template, phpbb_user $user, phpbb_request_interface $request, $phpbb_root_path, $php_ext)
+ public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, $phpbb_root_path, $php_ext)
{
$this->template = $template;
$this->user = $user;
- $this->request = $request;
+ $this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
+ $this->route_collection = $provider->get_routes();
}
/**
@@ -78,9 +77,9 @@ class phpbb_controller_helper
* @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)
+ public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false)
{
- page_header($page_title);
+ page_header($page_title, $display_online_list);
$this->template->set_filenames(array(
'body' => $template_file,
@@ -92,33 +91,43 @@ class phpbb_controller_helper
}
/**
- * Generate a URL
+ * Generate a URL to a route
*
- * @param string $route The route to travel
- * @param mixed $params String or array of additional url parameters
+ * @param string $route Name of the route to travel
+ * @param array $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
* @return string The URL already passed through append_sid()
*/
- public function url($route, $params = false, $is_amp = true, $session_id = false)
+ public function route($route, array $params = array(), $is_amp = true, $session_id = false)
{
- $route_params = '';
- if (($route_delim = strpos($route, '?')) !== false)
+ $anchor = '';
+ if (isset($params['#']))
{
- $route_params = substr($route, $route_delim);
- $route = substr($route, 0, $route_delim);
+ $anchor = '#' . $params['#'];
+ unset($params['#']);
}
+ $url_generator = new UrlGenerator($this->route_collection, new RequestContext());
+ $route_url = $url_generator->generate($route, $params);
- $request_uri = $this->request->variable('REQUEST_URI', '', false, phpbb_request::SERVER);
- $script_name = $this->request->variable('SCRIPT_NAME', '', false, phpbb_request::SERVER);
+ if (strpos($route_url, '/') === 0)
+ {
+ $route_url = substr($route_url, 1);
+ }
- // If the app.php file is being used (no rewrite) keep it in the URL.
- // Otherwise, don't include it.
+ if ($is_amp)
+ {
+ $route_url = str_replace(array('&', '&'), array('&', '&'), $route_url);
+ }
+
+ // If enable_mod_rewrite is false, we need to include app.php
$route_prefix = $this->phpbb_root_path;
- $parts = explode('/', $script_name);
- $route_prefix .= strpos($request_uri, $script_name) === 0 ? array_pop($parts) . '/' : '';
+ if (empty($this->config['enable_mod_rewrite']))
+ {
+ $route_prefix .= 'app.' . $this->php_ext . '/';
+ }
- return append_sid($route_prefix . "$route" . $route_params, $params, $is_amp, $session_id);
+ return append_sid($route_prefix . $route_url . $anchor, false, $is_amp, $session_id);
}
/**