[ticket/436] Generate routes with modules_helper and remove use of app.php

Modules should generate routes with the modules helper instead of directly
creating links to app.php.

B3P-436
This commit is contained in:
Marc Alexander
2015-01-04 16:09:43 +01:00
parent c08f728fe4
commit 2640fea635
8 changed files with 73 additions and 49 deletions

View File

@@ -14,7 +14,6 @@ services:
- %core.root_path%
- @user
- @board3.portal.fetch_posts
- @controller.helper
tags:
- { name: board3.portal.module }
@@ -47,6 +46,7 @@ services:
class: board3\portal\modules\calendar
arguments:
- @config
- @board3.portal.modules_helper
- @template
- @dbal.conn
- @request
@@ -211,6 +211,7 @@ services:
- %core.root_path%
- %core.php_ext%
- @user
- @board3.portal.modules_helper
tags:
- { name: board3.portal.module }
@@ -260,11 +261,10 @@ services:
class: board3\portal\modules\stylechanger
arguments:
- @config
- @board3.portal.modules_helper
- @template
- @dbal.conn
- @request
- %core.php_ext%
- %core.root_path%
- @user
tags:
- { name: board3.portal.module }

View File

@@ -68,6 +68,7 @@ services:
arguments:
- @auth
- @config
- @controller.helper
- @request
board3.portal.columns:

View File

@@ -9,6 +9,8 @@
namespace board3\portal\includes;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class modules_helper
{
/**
@@ -23,6 +25,9 @@ class modules_helper
*/
protected $config;
/** @var \phpbb\controller\helper Controller helper */
protected $controller_helper;
/**
* phpBB request
* @var \phpbb\request\request
@@ -35,12 +40,14 @@ class modules_helper
* the dependencies defined in the services.yml file for this service.
* @param \phpbb\auth\auth $auth Auth object
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\controller\helper $controller_helper Controller helper
* @param \phpbb\request\request $request phpBB request
*/
public function __construct($auth, $config, $request)
public function __construct($auth, $config, $controller_helper, $request)
{
$this->auth = $auth;
$this->config = $config;
$this->controller_helper = $controller_helper;
$this->request = $request;
}
@@ -135,4 +142,20 @@ class modules_helper
$news = implode(',', $values);
$this->config->set($key, $news);
}
/**
* Wrapper method for controller_helper::route()
*
* @param string $route Route name
* @param array $params Route parameters
* @param bool $is_amp
* @param bool $session_id
* @param bool $reference_type
*
* @return string URL for route
*/
public function route($route, $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH)
{
return $this->controller_helper->route($route, $params, $is_amp, $session_id, $reference_type);
}
}

View File

@@ -80,9 +80,6 @@ class announcements extends module_base
/** @var \board3\portal\portal\fetch_posts */
protected $fetch_posts;
/** @var \phpbb\controller\helper */
protected $controller_helper;
/**
* Construct an announcements object
*
@@ -98,9 +95,8 @@ class announcements extends module_base
* @param string $phpbb_root_path phpBB root path
* @param \phpbb\user $user phpBB user object
* @param \board3\portal\portal\fetch_posts $fetch_posts Fetch posts object
* @param \phpbb\controller\helper $controller_helper Controller helper
*/
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts, $controller_helper)
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts)
{
$this->auth = $auth;
$this->cache = $cache;
@@ -114,7 +110,6 @@ class announcements extends module_base
$this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
$this->fetch_posts = $fetch_posts;
$this->controller_helper = $controller_helper;
}
/**
@@ -239,7 +234,7 @@ class announcements extends module_base
if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id])
{
$pagination = generate_portal_pagination($this->controller_helper->route('board3_portal_controller'), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id);
$pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id);
$announcements_row = array_merge($announcements_row, array(
'AP_PAGINATION' => (isset($pagination)) ? $pagination : '',
@@ -345,7 +340,7 @@ class announcements extends module_base
'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id),
'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id . '&view=unread#unread'),
'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id),
'U_READ_FULL' => $this->controller_helper->route('board3_portal_controller') . '?' . $read_full_url,
'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url,
'L_READ_FULL' => $read_full,
'OPEN' => $open_bracket,
'CLOSE' => $close_bracket,
@@ -379,7 +374,7 @@ class announcements extends module_base
*/
if (!isset($fetch_news[$i]))
{
redirect($this->controller_helper->route('board3_portal_controller') . '#top');
redirect($this->modules_helper->route('board3_portal_controller') . '#top');
}
$forum_id = $fetch_news[$i]['forum_id'];
@@ -391,7 +386,7 @@ class announcements extends module_base
$read_full = $this->user->lang['BACK'];
$real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id;
$read_full_url = ($this->request->is_set('ap_' . $module_id)) ? $this->controller_helper->route('board3_portal_controller') . "?ap_{$module_id}=$start#a_{$module_id}_$i" : $this->controller_helper->route('board3_portal_controller') . "#a_{$module_id}_$i";
$read_full_url = ($this->request->is_set('ap_' . $module_id)) ? $this->modules_helper->route('board3_portal_controller') . "?ap_{$module_id}=$start#a_{$module_id}_$i" : $this->modules_helper->route('board3_portal_controller') . "#a_{$module_id}_$i";
$view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id);
$this->template->assign_block_vars('announcements.center_row', array(

View File

@@ -89,13 +89,13 @@ class calendar extends module_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template */
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\request\request */
/** @var \phpbb\request\request_interface */
protected $request;
/** @var string PHP file extension */
@@ -116,22 +116,27 @@ class calendar extends module_base
/** @var \phpbb\log\log phpBB log */
protected $log;
/** @var \board3\portal\includes\modules_helper */
protected $modules_helper;
/**
* Construct a calendar object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver $db Database driver
* @param \phpbb\request\request $request phpBB request
* @param \board3\portal\includes\modules_helper $modules_helper Modules helper
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db Database driver
* @param \phpbb\request\request_interface $request phpBB request
* @param string $phpEx php file extension
* @param string $phpbb_root_path phpBB root path
* @param \phpbb\user $user phpBB user object
* @param \phpbb\path_helper $path_helper phpBB path helper
* @param \phpbb\log\log $log phpBB log object
*/
public function __construct($config, $template, $db, $request, $phpbb_root_path, $phpEx, $user, $path_helper, $log)
public function __construct($config, $modules_helper, $template, $db, $request, $phpbb_root_path, $phpEx, $user, $path_helper, $log)
{
$this->config = $config;
$this->modules_helper = $modules_helper;
$this->template = $template;
$this->db = $db;
$this->request = $request;
@@ -183,8 +188,8 @@ class calendar extends module_base
// output our general calendar bits
$down = $this->mini_cal_month - 1;
$up = $this->mini_cal_month + 1;
$prev_month = '<a href="' . append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "m$module_id=$down#minical$module_id") . '"><img src="' . $this->portal_root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/cal_icon_left_arrow.png' . '" title="' . $this->user->lang['VIEW_PREVIOUS_MONTH'] . '" height="16" width="16" alt="&lt;&lt;" /></a>';
$next_month = '<a href="' . append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "m$module_id=$up#minical$module_id") . '"><img src="' . $this->portal_root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/cal_icon_right_arrow.png' . '" title="' . $this->user->lang['VIEW_NEXT_MONTH'] . '" height="16" width="16" alt="&gt;&gt;" /></a>';
$prev_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$down#minical$module_id" . '"><img src="' . $this->portal_root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/cal_icon_left_arrow.png' . '" title="' . $this->user->lang['VIEW_PREVIOUS_MONTH'] . '" height="16" width="16" alt="&lt;&lt;" /></a>';
$next_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$up#minical$module_id" . '"><img src="' . $this->portal_root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/cal_icon_right_arrow.png' . '" title="' . $this->user->lang['VIEW_NEXT_MONTH'] . '" height="16" width="16" alt="&gt;&gt;" /></a>';
$this->template->assign_block_vars('minical', array(
'S_SUNDAY_FIRST' => ($this->config['board3_sunday_first_' . $module_id]) ? true : false,

View File

@@ -228,7 +228,7 @@ class news extends module_base
// Create pagination if necessary
if ($this->config['board3_news_archive_' . $module_id])
{
$pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $module_id);
$pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $module_id);
}
if ($this->config['board3_number_of_news_' . $module_id] <> 0 && $this->config['board3_news_archive_' . $module_id])
@@ -338,7 +338,7 @@ class news extends module_base
'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']),
'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id'] . '&amp;view=unread#unread'),
'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&amp;f=' . $fetch_news[$i]['forum_id'] . '&amp;t=' . $fetch_news[$i]['topic_id']),
'U_READ_FULL' => append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", $read_full_url),
'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url,
'L_READ_FULL' => $read_full,
'OPEN' => $open_bracket,
'CLOSE' => $close_bracket,
@@ -370,7 +370,7 @@ class news extends module_base
$close_bracket = ' ]';
$read_full = $this->user->lang['BACK'];
$read_full_url = ($this->request->is_set('np_' . $module_id)) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "np_$module_id=$start#n_{$module_id}_$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#n_{$module_id}_$i");
$read_full_url = ($this->request->is_set('np_' . $module_id)) ? $this->modules_helper->route('board3_portal_controller') . "?np_$module_id=$start#n_{$module_id}_$i" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_$i";
$view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&amp;t=' . $topic_id);
$this->template->assign_block_vars('news.news_row', array(

View File

@@ -71,6 +71,9 @@ class poll extends module_base
/** @var \phpbb\user */
protected $user;
/** @var \board3\portal\includes\modules_helper */
protected $modules_helper;
/**
* Construct a poll object
*
@@ -82,8 +85,9 @@ class poll extends module_base
* @param string $phpEx php file extension
* @param string $phpbb_root_path phpBB root path
* @param \phpbb\user $user phpBB user object
* @param \board3\portal\includes\modules_helper $modules_helper Modules helper
*/
public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx, $user)
public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx, $user, $modules_helper)
{
$this->auth = $auth;
$this->config = $config;
@@ -93,6 +97,7 @@ class poll extends module_base
$this->php_ext = $phpEx;
$this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
$this->modules_helper = $modules_helper;
}
/**
@@ -231,7 +236,7 @@ class poll extends module_base
if($s_can_up_vote)
{
$redirect_url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal");
$redirect_url = $this->modules_helper->route('board3_portal_controller');
if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id))
{
@@ -449,8 +454,8 @@ class poll extends module_base
}
$poll_view_str = urlencode(implode(',', $make_poll_view));
$portalpoll_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "polls=$poll_view_str");
$portalvote_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "f=$forum_id&amp;t=$topic_id");
$portalpoll_url= $this->modules_helper->route('board3_portal_controller') . "polls=$poll_view_str";
$portalvote_url= $this->modules_helper->route('board3_portal_controller') . "f=$forum_id&amp;t=$topic_id";
$viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f=$forum_id&amp;t=$topic_id");
$poll_end = $data['poll_length'] + $data['poll_start'];

View File

@@ -44,21 +44,18 @@ class stylechanger extends module_base
/** @var \phpbb\config\config */
protected $config;
/** @var \phpbb\template */
/** @var \board3\portal\includes\modules_helper */
protected $modules_helper;
/** @var \phpbb\template\template */
protected $template;
/** @var \phpbb\db\driver */
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\request\request */
/** @var \phpbb\request\request_interface */
protected $request;
/** @var string PHP file extension */
protected $php_ext;
/** @var string phpBB root path */
protected $phpbb_root_path;
/** @var \phpbb\user */
protected $user;
@@ -66,21 +63,19 @@ class stylechanger extends module_base
* Construct a stylechanger object
*
* @param \phpbb\config\config $config phpBB config
* @param \phpbb\template $template phpBB template
* @param \phpbb\db\driver $db Database driver
* @param \phpbb\request\request $request phpBB request
* @param string $phpEx php file extension
* @param string $phpbb_root_path phpBB root path
* @param \board3\portal\includes\modules_helper $modules_helper Modules helper
* @param \phpbb\template\template $template phpBB template
* @param \phpbb\db\driver\driver_interface $db Database driver
* @param \phpbb\request\request_interface $request phpBB request
* @param \phpbb\user $user phpBB user object
*/
public function __construct($config, $template, $db, $request, $phpEx, $phpbb_root_path, $user)
public function __construct($config, $modules_helper, $template, $db, $request, $user)
{
$this->config = $config;
$this->modules_helper = $modules_helper;
$this->template = $template;
$this->db = $db;
$this->request = $request;
$this->php_ext = $phpEx;
$this->phpbb_root_path = $phpbb_root_path;
$this->user = $user;
}
@@ -101,11 +96,11 @@ class stylechanger extends module_base
$style = $this->request->variable('style', 0);
if (!empty($style))
{
$url = str_replace('style=' . $style, 'style=' . $row['style_id'], append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"));
$url = str_replace('style=' . $style, 'style=' . $row['style_id'], $this->modules_helper->route('board3_portal_controller'));
}
else
{
$url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", 'style=' . $row['style_id']);
$url = $this->modules_helper->route('board3_portal_controller') . '?style=' . $row['style_id'];
}
++$style_count;
$style_select .= '<option value="' . $url . '"' . ($row['style_id'] == $this->user->style['style_id'] ? ' selected="selected"' : '') . '>' . utf8_htmlspecialchars($row['style_name']) . '</option>';