From 7a63c9a3a8c0fbda3572d08064e71e97e49208b2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:19:46 +0100 Subject: [PATCH 01/15] [ticket/469] Make sure to not define constants more than once B3P-469 --- acp/portal_module.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/acp/portal_module.php b/acp/portal_module.php index eb0a6b87..1d8d9a2f 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -55,8 +55,12 @@ class portal_module $this->portal_columns = $this->phpbb_container->get('board3.portal.columns'); $this->modules_manager = $this->phpbb_container->get('board3.portal.modules.manager'); $this->modules_constraints = $this->phpbb_container->get('board3.portal.modules.constraints_handler'); - define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.portal.modules.table')); - define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.portal.config.table')); + + if (!defined('PORTAL_MODULES_TABLE')) + { + define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.portal.modules.table')); + define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.portal.config.table')); + } if(!function_exists('obtain_portal_config')) { From e4861caed8ecd919adba2f5c1fa30f686899d941 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:20:54 +0100 Subject: [PATCH 02/15] [ticket/469] Add settings for displaying portal on all pages B3P-469 --- acp/portal_module.php | 5 +++++ migrations/v210_rc3.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 migrations/v210_rc3.php diff --git a/acp/portal_module.php b/acp/portal_module.php index 1d8d9a2f..9bfe4586 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -101,6 +101,11 @@ class portal_module 'legend2' => 'ACP_PORTAL_COLUMN_WIDTH_SETTINGS', 'board3_left_column_width' => array('lang' => 'PORTAL_LEFT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), 'board3_right_column_width' => array('lang' => 'PORTAL_RIGHT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), + + 'legend3' => 'ACP_PORTAL_SHOW_ALL', + 'board3_show_all_pages' => array('lang' => 'ACP_PORTAL_SHOW_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_show_all_left' => array('lang' => 'PORTAL_SHOW_ALL_LEFT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_show_all_right' => array('lang' => 'PORTAL_SHOW_ALL_RIGHT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), ) ); diff --git a/migrations/v210_rc3.php b/migrations/v210_rc3.php new file mode 100644 index 00000000..b357acec --- /dev/null +++ b/migrations/v210_rc3.php @@ -0,0 +1,28 @@ + Date: Thu, 12 Feb 2015 22:24:36 +0100 Subject: [PATCH 03/15] [ticket/469] Make listener display portal if settings are set to true B3P-469 --- config/services.yml | 1 + event/listener.php | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/config/services.yml b/config/services.yml index 593fb918..df0d08a4 100644 --- a/config/services.yml +++ b/config/services.yml @@ -87,6 +87,7 @@ services: board3.portal.listener: class: board3\portal\event\listener arguments: + - @board3.portal.main - @auth - @config - @controller.helper diff --git a/event/listener.php b/event/listener.php index e31415e8..a529253e 100644 --- a/event/listener.php +++ b/event/listener.php @@ -13,6 +13,9 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; class listener implements EventSubscriberInterface { + /** @var \board3\portal\controller\main */ + protected $board3_controller; + /** @var \phpbb\auth\auth */ protected $auth; @@ -37,6 +40,7 @@ class listener implements EventSubscriberInterface /** * Constructor of Board3 Portal event listener * + * @param \board3\portal\controller\main $board3_controller Board3 Portal controller * @param \phpbb\auth\auth $auth phpBB auth object * @param \phpbb\config\config $config phpBB config * @param \phpbb\controller\helper $controller_helper Controller helper object @@ -45,8 +49,9 @@ class listener implements EventSubscriberInterface * @param \phpbb\user $user User object * @param string $php_ext phpEx */ - public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext) + public function __construct(\board3\portal\controller\main $board3_controller, \phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\controller\helper $controller_helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\user $user, $php_ext) { + $this->board3_controller = $board3_controller; $this->auth = $auth; $this->config = $config; $this->controller_helper = $controller_helper; @@ -116,6 +121,7 @@ class listener implements EventSubscriberInterface if (strpos($this->user->data['session_page'], '/portal') === false) { $portal_link = $this->controller_helper->route('board3_portal_controller'); + $this->display_portal(); } else { @@ -136,4 +142,19 @@ class listener implements EventSubscriberInterface { return $this->auth->acl_get('u_view_portal') && $this->config['board3_enable']; } + + /** + * Display portal columns on all pages if specified in portal settings + */ + protected function display_portal() + { + // Check if we should show the portal + if (isset($this->config['board3_show_all_pages']) && ($this->config['board3_show_all_left'] || $this->config['board3_show_all_right']) && !defined('ADMIN_START')) + { + $this->board3_controller->handle(array( + 'left' => $this->config['board3_show_all_left'], + 'right' => $this->config['board3_show_all_right'], + )); + } + } } From f2b002c49bde5449c6e07b3d9610fa7e10990a0c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:25:15 +0100 Subject: [PATCH 04/15] [ticket/469] Check current page with get_current_url() The current session page seems to be wrong on the first page access. B3P-469 --- event/listener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event/listener.php b/event/listener.php index a529253e..07e56502 100644 --- a/event/listener.php +++ b/event/listener.php @@ -118,7 +118,7 @@ class listener implements EventSubscriberInterface return; } - if (strpos($this->user->data['session_page'], '/portal') === false) + if (strpos($this->controller_helper->get_current_url(), '/portal') === false) { $portal_link = $this->controller_helper->route('board3_portal_controller'); $this->display_portal(); From ee096bf60dfeba16dfc56fd9bcf8fdaabc4927fd Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:32:09 +0100 Subject: [PATCH 05/15] [ticket/469] Allow restricting portal columns based on parameter in handle B3P-469 --- controller/main.php | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/controller/main.php b/controller/main.php index f814de54..33fde5ea 100644 --- a/controller/main.php +++ b/controller/main.php @@ -80,6 +80,9 @@ class main */ protected $portal_modules; + /** @var string Allowed columns */ + protected $allowed_columns; + /** * Constructor * NOTE: The parameters of this method must match in order and type with @@ -123,12 +126,18 @@ class main /** * Extension front handler method. This is called automatically when your extension is accessed * through index.php?ext=example/foobar + * + * @param array $columns Columns to display + * * @return null */ - public function handle() + public function handle($columns = array()) { $this->controller_helper->run_initial_tasks(); + // Check if we should limit the columns to display + $this->set_allowed_columns($columns); + // Set default data $this->portal_modules = obtain_portal_modules(); $display_online = false; @@ -181,6 +190,14 @@ class main // Assign specific vars $this->assign_template_vars(); + // Return if columns were specified. Columns are only specified if + // portal columns are displayed on pages other than the portal itself. + if ($this->allowed_columns !== 0) + { + $this->template->assign_var('S_PORTAL_ALL', true); + return; + } + // And now to output the page. page_header($this->user->lang('PORTAL'), $display_online); @@ -206,8 +223,15 @@ class main public function get_module_template($row, $module) { $template_module = false; + $column = $this->portal_columns->number_to_string($row['module_column']); + // Make sure we should actually load this module + if (!$this->display_module_allowed($this->portal_columns->string_to_constant($column))) + { + return false; + } + if (in_array($column, array('left', 'right')) && $this->config['board3_' . $column . '_column']) { ++$this->module_count[$column]; @@ -282,4 +306,36 @@ class main make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum{$this->php_ext}")); } } + + /** + * Check whether displaying the module is allowed + * + * @param int $module_column The column of the module + * + * @return bool True if module can be displayed, false if not + */ + protected function display_module_allowed($module_column) + { + return ($this->allowed_columns > 0) ? (bool) ($this->allowed_columns & $module_column) : true; + } + + /** + * Set allowed columns based on supplied columns array + * + * @param array $columns Allowed columns + */ + protected function set_allowed_columns($columns) + { + if (!empty($columns)) + { + foreach ($columns as $column => $show) + { + $this->allowed_columns |= ($show) ? $this->portal_columns->string_to_constant($column) : 0; + } + } + else + { + $this->allowed_columns = 0; + } + } } From bc3b43056994362f5777ca18c1c6ffbe77cadcd5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:32:42 +0100 Subject: [PATCH 06/15] [ticket/469] Add new language entries for displaying portal on all pages B3P-469 --- language/en/portal_acp.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/language/en/portal_acp.php b/language/en/portal_acp.php index 485ff84e..f8f4accd 100644 --- a/language/en/portal_acp.php +++ b/language/en/portal_acp.php @@ -80,6 +80,8 @@ $lang = array_merge($lang, array( 'ACP_PORTAL_CONFIG_INFO' => 'General settings', 'ACP_PORTAL_GENERAL_TITLE' => 'Portal Administration', 'ACP_PORTAL_GENERAL_TITLE_EXP' => 'Thank you for choosing Board3 Portal! This is where you can manage your portal page. The options below let you customize the various general settings.', + 'ACP_PORTAL_SHOW_ALL' => 'Show portal on all pages', + 'ACP_PORTAL_SHOW_ALL_EXP' => 'Display the portal on all pages', 'PORTAL_ENABLE' => 'Enable Portal', 'PORTAL_ENABLE_EXP' => 'Turns the whole portal on or off', 'PORTAL_LEFT_COLUMN' => 'Enable left column', @@ -94,6 +96,10 @@ $lang = array_merge($lang, array( 'PORTAL_LEFT_COLUMN_WIDTH_EXP' => 'Change the width of the left column in pixels; recommended value is 180', 'PORTAL_RIGHT_COLUMN_WIDTH' => 'Width of the right column', 'PORTAL_RIGHT_COLUMN_WIDTH_EXP' => 'Change the width of the right column in pixels; recommended value is 180', + 'PORTAL_SHOW_ALL_LEFT' => 'Show left column on all pages', + 'PORTAL_SHOW_ALL_LEFT_EXP' => 'Display the left column on all pages', + 'PORTAL_SHOW_ALL_RIGHT' => 'Show right column on all pages', + 'PORTAL_SHOW_ALL_RIGHT_EXP' => 'Display the right column on all pages', 'LINK_ADDED' => 'The link has been successfully added', 'LINK_UPDATED' => 'The link has been successfully updated', From 70efdf099e3e8265d4ccc78889e18e127dc43b99 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:33:24 +0100 Subject: [PATCH 07/15] [ticket/469] Add CSS if portal is displayed on all pages B3P-469 --- .../event/overall_header_head_append.html | 3 +++ styles/prosilver/theme/portal_all.css | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 styles/prosilver/theme/portal_all.css diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html index 12a4f8ff..4c222476 100644 --- a/styles/prosilver/template/event/overall_header_head_append.html +++ b/styles/prosilver/template/event/overall_header_head_append.html @@ -1,4 +1,7 @@ + + + diff --git a/styles/prosilver/theme/portal_all.css b/styles/prosilver/theme/portal_all.css new file mode 100644 index 00000000..5772abea --- /dev/null +++ b/styles/prosilver/theme/portal_all.css @@ -0,0 +1,15 @@ +.portal-body-wrapper { + width: 100%; + float: left; + display: block; +} + +#portal-page-body { + clear: both; + margin: 4px 0; +} + +#page-body { + float: left; + width: 100%; +} From 0ea8d11360abf6f85da7176a897aa26f589ac0c2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:33:49 +0100 Subject: [PATCH 08/15] [ticket/469] Remove unused template variable B3P-469 --- styles/prosilver/template/portal/portal_body.html | 1 - styles/subsilver2/template/portal/portal_body.html | 1 - 2 files changed, 2 deletions(-) diff --git a/styles/prosilver/template/portal/portal_body.html b/styles/prosilver/template/portal/portal_body.html index c16cbcb0..386edeaa 100644 --- a/styles/prosilver/template/portal/portal_body.html +++ b/styles/prosilver/template/portal/portal_body.html @@ -1,4 +1,3 @@ - diff --git a/styles/subsilver2/template/portal/portal_body.html b/styles/subsilver2/template/portal/portal_body.html index fb7ed515..ee5d5d1d 100644 --- a/styles/subsilver2/template/portal/portal_body.html +++ b/styles/subsilver2/template/portal/portal_body.html @@ -1,4 +1,3 @@ - From f75dd6660166ef6421eca363bec602efab374b67 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 12 Feb 2015 22:34:15 +0100 Subject: [PATCH 09/15] [ticket/469] Add prosilver events required for portal on all pages B3P-469 --- .../event/overall_footer_page_body_after.html | 40 +++++++++++++++++++ .../overall_header_page_body_before.html | 7 ++++ 2 files changed, 47 insertions(+) create mode 100644 styles/prosilver/template/event/overall_footer_page_body_after.html create mode 100644 styles/prosilver/template/event/overall_header_page_body_before.html diff --git a/styles/prosilver/template/event/overall_footer_page_body_after.html b/styles/prosilver/template/event/overall_footer_page_body_after.html new file mode 100644 index 00000000..d3a70d8b --- /dev/null +++ b/styles/prosilver/template/event/overall_footer_page_body_after.html @@ -0,0 +1,40 @@ + + + + + +
+ + + + + + + + + + +
+ + + + + +
+ + + + + + + + + + +
+ + +
+ + + diff --git a/styles/prosilver/template/event/overall_header_page_body_before.html b/styles/prosilver/template/event/overall_header_page_body_before.html new file mode 100644 index 00000000..8f19066b --- /dev/null +++ b/styles/prosilver/template/event/overall_header_page_body_before.html @@ -0,0 +1,7 @@ + +
+
+
+ +
+ From 311c7cb97f788514c57ee364b8aa3402d221aa5d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 13 Feb 2015 16:33:06 +0100 Subject: [PATCH 10/15] [ticket/469] Only allow showing left or right module on all pages B3P-469 --- acp/portal_module.php | 3 +-- event/listener.php | 6 +++--- includes/modules_helper.php | 15 +++++++++++++++ language/en/portal_acp.php | 8 ++++---- migrations/v210_rc3.php | 3 +-- .../event/overall_header_head_append.html | 4 +++- styles/prosilver/theme/portal_all_responsive.css | 14 ++++++++++++++ 7 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 styles/prosilver/theme/portal_all_responsive.css diff --git a/acp/portal_module.php b/acp/portal_module.php index 9bfe4586..e9313e3b 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -104,8 +104,7 @@ class portal_module 'legend3' => 'ACP_PORTAL_SHOW_ALL', 'board3_show_all_pages' => array('lang' => 'ACP_PORTAL_SHOW_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_show_all_left' => array('lang' => 'PORTAL_SHOW_ALL_LEFT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_show_all_right' => array('lang' => 'PORTAL_SHOW_ALL_RIGHT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), + 'board3_show_all_side' => array('lang' => 'PORTAL_SHOW_ALL_SIDE', 'validate' => 'bool', 'type' => 'custom', 'method' => array('board3.portal.modules_helper', 'display_left_right'), 'explain' => true), ) ); diff --git a/event/listener.php b/event/listener.php index 07e56502..4e92d9f6 100644 --- a/event/listener.php +++ b/event/listener.php @@ -149,11 +149,11 @@ class listener implements EventSubscriberInterface protected function display_portal() { // Check if we should show the portal - if (isset($this->config['board3_show_all_pages']) && ($this->config['board3_show_all_left'] || $this->config['board3_show_all_right']) && !defined('ADMIN_START')) + if (isset($this->config['board3_show_all_pages'])) { $this->board3_controller->handle(array( - 'left' => $this->config['board3_show_all_left'], - 'right' => $this->config['board3_show_all_right'], + 'left' => $this->config['board3_show_all_side'] == false, + 'right' => $this->config['board3_show_all_side'] == true, )); } } diff --git a/includes/modules_helper.php b/includes/modules_helper.php index a8f7858f..f46ce29e 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -158,4 +158,19 @@ class modules_helper { return $this->controller_helper->route($route, $params, $is_amp, $session_id, $reference_type); } + + /** + * Display radio buttons for left/right choice + * + * @param int $value Selected value + * @param string $key Key of config variable + * + * @return string + */ + public function display_left_right($value, $key) + { + $radio_ary = array(0 => 'PORTAL_SHOW_ALL_LEFT', 1 => 'PORTAL_SHOW_ALL_RIGHT'); + + return h_radio($key, $radio_ary, $value, $key); + } } diff --git a/language/en/portal_acp.php b/language/en/portal_acp.php index f8f4accd..35575c26 100644 --- a/language/en/portal_acp.php +++ b/language/en/portal_acp.php @@ -96,10 +96,10 @@ $lang = array_merge($lang, array( 'PORTAL_LEFT_COLUMN_WIDTH_EXP' => 'Change the width of the left column in pixels; recommended value is 180', 'PORTAL_RIGHT_COLUMN_WIDTH' => 'Width of the right column', 'PORTAL_RIGHT_COLUMN_WIDTH_EXP' => 'Change the width of the right column in pixels; recommended value is 180', - 'PORTAL_SHOW_ALL_LEFT' => 'Show left column on all pages', - 'PORTAL_SHOW_ALL_LEFT_EXP' => 'Display the left column on all pages', - 'PORTAL_SHOW_ALL_RIGHT' => 'Show right column on all pages', - 'PORTAL_SHOW_ALL_RIGHT_EXP' => 'Display the right column on all pages', + 'PORTAL_SHOW_ALL_SIDE' => 'Column to display on all pages', + 'PORTAL_SHOW_ALL_SIDE_EXP' => 'Choose which column should be shown on all pages.', + 'PORTAL_SHOW_ALL_LEFT' => 'Left', + 'PORTAL_SHOW_ALL_RIGHT' => 'Right', 'LINK_ADDED' => 'The link has been successfully added', 'LINK_UPDATED' => 'The link has been successfully updated', diff --git a/migrations/v210_rc3.php b/migrations/v210_rc3.php index b357acec..ef519e58 100644 --- a/migrations/v210_rc3.php +++ b/migrations/v210_rc3.php @@ -21,8 +21,7 @@ class v210_rc3 extends \phpbb\db\migration\migration return array( array('config.update', array('board3_portal_version', '2.1.0-rc3')), array('config.add', array('board3_show_all_pages', false)), - array('config.add', array('board3_show_all_left', false)), - array('config.add', array('board3_show_all_right', false)), + array('config.add', array('board3_show_all_side', false)), ); } } diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html index 4c222476..990b1733 100644 --- a/styles/prosilver/template/event/overall_header_head_append.html +++ b/styles/prosilver/template/event/overall_header_head_append.html @@ -1,7 +1,9 @@ - + + + diff --git a/styles/prosilver/theme/portal_all_responsive.css b/styles/prosilver/theme/portal_all_responsive.css new file mode 100644 index 00000000..b20ba095 --- /dev/null +++ b/styles/prosilver/theme/portal_all_responsive.css @@ -0,0 +1,14 @@ +@media only screen and (max-width: 870px), only screen and (max-device-width: 870px) { + .portal-body-center dd.posts, .portal-body-center dd.views { + display: none !important; + } + .portal-body-center dt { width: 130% !important; } +} + +@media only screen and (max-width: 740px), only screen and (max-device-width: 740px) { + .portal-body-center dt { width: 140% !important; } + #portal-left ul.topiclist dd, #portal-right ul.topiclist dd { display: block !important; } + + #portal-right > .portal-clear, #portal-body > .portal-clear, #portal-left > .portal-clear, + #portal-center > .portal-clear, #portal-login-box .portal-clear { display: none !important; } +} \ No newline at end of file From 30bd67f3d88489217c47c1162a04069473651706 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 13 Feb 2015 19:52:00 +0100 Subject: [PATCH 11/15] [ticket/469] Fix tests with new settings B3P-469 --- acp/portal_module.php | 6 +++--- includes/modules_helper.php | 13 +++++++++++++ tests/unit/event/listener_test.php | 8 ++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/acp/portal_module.php b/acp/portal_module.php index e9313e3b..84e63870 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -104,7 +104,7 @@ class portal_module 'legend3' => 'ACP_PORTAL_SHOW_ALL', 'board3_show_all_pages' => array('lang' => 'ACP_PORTAL_SHOW_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'board3_show_all_side' => array('lang' => 'PORTAL_SHOW_ALL_SIDE', 'validate' => 'bool', 'type' => 'custom', 'method' => array('board3.portal.modules_helper', 'display_left_right'), 'explain' => true), + 'board3_show_all_side' => array('lang' => 'PORTAL_SHOW_ALL_SIDE', 'validate' => 'bool', 'type' => 'custom', 'method' => array('board3.portal.modules_helper', 'display_left_right'), 'submit' => array('board3.portal.modules_helper', 'store_left_right'), 'explain' => true), ) ); @@ -223,11 +223,11 @@ class portal_module if ($null['submit'][0] == 'board3.portal.modules_helper') { $func = array($this->modules_helper, $null['submit'][1]); - $args = ($module_id != 0) ? array($config_name, $module_id) : $config_name; + $args = ($module_id != 0) ? array($config_name, $module_id) : array($config_name); } else { - $args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : $config_name; + $args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : array($config_name); $func = $null['submit']; } } diff --git a/includes/modules_helper.php b/includes/modules_helper.php index f46ce29e..04667f83 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -173,4 +173,17 @@ class modules_helper return h_radio($key, $radio_ary, $value, $key); } + + /** + * Store left right choice + * + * @param string $key Config key + */ + public function store_left_right($key) + { + // Get selected side + $value = $this->request->variable($key, false); + + $this->config->set($key, $value); + } } diff --git a/tests/unit/event/listener_test.php b/tests/unit/event/listener_test.php index 323fd620..21d87988 100644 --- a/tests/unit/event/listener_test.php +++ b/tests/unit/event/listener_test.php @@ -17,6 +17,9 @@ class listener_test extends \phpbb_template_template_test_case protected $listener; protected $auth; + /** @var \board3\portal\controller\main */ + protected $controller; + static public $hidden_fields = array(); public function setup() @@ -91,7 +94,12 @@ class listener_test extends \phpbb_template_template_test_case $this->auth->acl_options['global']['u_view_portal'] = 0; $this->auth->acl[0][0] = true; + $this->controller = $this->getMockBuilder('\board3\portal\controller\main') + ->disableOriginalConstructor() + ->getMock(); + $this->listener = new \board3\portal\event\listener( + $this->controller, $this->auth, $this->config, $this->controller_helper, From 1e7dc9b576f84308b4a04e52972270a03773875c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 13 Feb 2015 22:23:23 +0100 Subject: [PATCH 12/15] [ticket/469] Add tests for displaying all pages using main controller B3P-469 --- tests/mock/template.php | 15 +++++ tests/mock/user.php | 5 ++ tests/unit/controller/main_test.php | 94 +++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 tests/unit/controller/main_test.php diff --git a/tests/mock/template.php b/tests/mock/template.php index 539de39f..8806962f 100644 --- a/tests/mock/template.php +++ b/tests/mock/template.php @@ -36,6 +36,16 @@ class template } } + public function assign_vars($vars) + { + $this->data = array_merge($this->data, $vars); + } + + public function assign_var($key, $var) + { + $this->data[$key] = $var; + } + public function assert_equals($data, $row) { foreach ($data as $key => $value) @@ -43,4 +53,9 @@ class template $this->test_case->assertEquals($value, $this->data[$row][$key]); } } + + public function assert_same($expected, $row) + { + $this->test_case->assertSame($expected, $this->data[$row]); + } } diff --git a/tests/mock/user.php b/tests/mock/user.php index eb603e89..b0ca4c45 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -53,4 +53,9 @@ class user extends \PHPUnit_Framework_TestCase $this->markTestIncomplete('Unable to include language file ' . $file); } } + + public function lang($var) + { + return $this->lang[$var]; + } } diff --git a/tests/unit/controller/main_test.php b/tests/unit/controller/main_test.php new file mode 100644 index 00000000..6eb1109f --- /dev/null +++ b/tests/unit/controller/main_test.php @@ -0,0 +1,94 @@ +createXMLDataSet(dirname(__FILE__) . '/../acp/fixtures/modules.xml'); + } + + public function setUp() + { + global $phpbb_root_path, $phpEx, $table_prefix, $cache; + + parent::setUp(); + + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new \phpbb_mock_request() + ), + new \phpbb\filesystem(), + new \phpbb_mock_request(), + $phpbb_root_path, + $phpEx + ); + + $cache = new \phpbb\cache\driver\null(); + + $user = new \board3\portal\tests\mock\user(); + + $config_table = $table_prefix . 'portal_config'; + $modules_table = $table_prefix . 'portal_modules'; + $this->template = new \board3\portal\tests\mock\template($this); + $portal_columns = new \board3\portal\portal\columns(); + $this->config = new \phpbb\config\config(array('board3_enable' => true)); + $modules = array( + '\board3\portal\modules\clock' => new \board3\portal\modules\clock($this->config, $this->template), + ); + $portal_helper = new \board3\portal\includes\helper($modules); + $auth = $this->getMock('\phpbb\auth\auth', array('acl_get')); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->anything()) + ->will($this->returnValue(true)); + + $controller_helper = new \board3\portal\controller\helper( + $auth, + $portal_columns, + $this->config, + $this->template, + $user, + $path_helper, + $portal_helper, + $phpbb_root_path, + '.' . $phpEx + ); + + $this->controller_main = new \board3\portal\controller\main( + $portal_columns, + $this->config, + $controller_helper, + $this->template, + $user, + $path_helper, + $phpbb_root_path, + '.' . $phpEx, + $config_table, + $modules_table + ); + } + + public function test_display_all_pages() + { + $this->assertNull($this->controller_main->handle(array('left' => 1))); + $this->template->assert_same(true, 'S_PORTAL_ALL'); + } +} From 9899d4fd3c926a670d13228cd118fd45527167a9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 13 Feb 2015 22:23:49 +0100 Subject: [PATCH 13/15] [ticket/469] Fix incorrect doc block B3P-469 --- controller/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/main.php b/controller/main.php index 33fde5ea..729b17d3 100644 --- a/controller/main.php +++ b/controller/main.php @@ -80,7 +80,7 @@ class main */ protected $portal_modules; - /** @var string Allowed columns */ + /** @var int Allowed columns */ protected $allowed_columns; /** From 8e85752c6574567ba3f47914c6b242e558555cb4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 14 Feb 2015 22:21:10 +0100 Subject: [PATCH 14/15] [ticket/469] Enable portal on all pages in subsilver2 & add tests B3P-469 --- event/listener.php | 2 +- includes/modules_helper.php | 2 +- migrations/v210_rc3.php | 4 +- .../event/overall_footer_content_after.html | 21 +++++++ .../event/overall_header_content_before.html | 22 ++++++++ tests/functional/portal_no_error_test.php | 55 +++++++++++++++++++ 6 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 styles/subsilver2/template/event/overall_footer_content_after.html create mode 100644 styles/subsilver2/template/event/overall_header_content_before.html diff --git a/event/listener.php b/event/listener.php index 4e92d9f6..1e596995 100644 --- a/event/listener.php +++ b/event/listener.php @@ -149,7 +149,7 @@ class listener implements EventSubscriberInterface protected function display_portal() { // Check if we should show the portal - if (isset($this->config['board3_show_all_pages'])) + if (isset($this->config['board3_show_all_pages']) && $this->config['board3_show_all_pages']) { $this->board3_controller->handle(array( 'left' => $this->config['board3_show_all_side'] == false, diff --git a/includes/modules_helper.php b/includes/modules_helper.php index 04667f83..cc9b1956 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -182,7 +182,7 @@ class modules_helper public function store_left_right($key) { // Get selected side - $value = $this->request->variable($key, false); + $value = $this->request->variable($key, 0); $this->config->set($key, $value); } diff --git a/migrations/v210_rc3.php b/migrations/v210_rc3.php index ef519e58..7af56093 100644 --- a/migrations/v210_rc3.php +++ b/migrations/v210_rc3.php @@ -20,8 +20,8 @@ class v210_rc3 extends \phpbb\db\migration\migration { return array( array('config.update', array('board3_portal_version', '2.1.0-rc3')), - array('config.add', array('board3_show_all_pages', false)), - array('config.add', array('board3_show_all_side', false)), + array('config.add', array('board3_show_all_pages', 0)), + array('config.add', array('board3_show_all_side', 0)), ); } } diff --git a/styles/subsilver2/template/event/overall_footer_content_after.html b/styles/subsilver2/template/event/overall_footer_content_after.html new file mode 100644 index 00000000..8a605a3f --- /dev/null +++ b/styles/subsilver2/template/event/overall_footer_content_after.html @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/styles/subsilver2/template/event/overall_header_content_before.html b/styles/subsilver2/template/event/overall_header_content_before.html new file mode 100644 index 00000000..9e92cb07 --- /dev/null +++ b/styles/subsilver2/template/event/overall_header_content_before.html @@ -0,0 +1,22 @@ + + + + + + + + + +
+ + + + + + + + + + + + diff --git a/tests/functional/portal_no_error_test.php b/tests/functional/portal_no_error_test.php index 481c0fcc..d226a395 100644 --- a/tests/functional/portal_no_error_test.php +++ b/tests/functional/portal_no_error_test.php @@ -53,4 +53,59 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra $this->assertContains('subsilver', $crawler->text()); self::request('GET', 'app.php/portal?style=2'); } + + public function data_portal_all_pages() + { + return array( + array(1), + array(2), + ); + } + + /** + * @dataProvider data_portal_all_pages + * @dependsOn test_enable_subsilver + */ + public function test_portal_all_pages($style_id) + { + $crawler = self::request('GET', 'index.php?style=' . $style_id); + $this->assertNotContains('Menu', $crawler->text()); + + $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); + + $form = $crawler->selectButton('submit')->form(array( + 'config[board3_show_all_pages]' => 1, + 'board3_show_all_side' => 0, + )); + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); + + $crawler = self::request('GET', 'index.php?style=' . $style_id); + $this->assertContains('Menu', $crawler->text()); + + $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); + + $form = $crawler->selectButton('submit')->form(array( + 'config[board3_show_all_pages]' => 1, + 'board3_show_all_side' => 1, + )); + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); + + $crawler = self::request('GET', 'index.php?style=' . $style_id); + $this->assertNotContains('Board Style', $crawler->text()); + $this->assertContains('User menu', $crawler->text()); + + $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); + + $form = $crawler->selectButton('submit')->form(array( + 'config[board3_show_all_pages]' => 0, + 'board3_show_all_side' => 0, + )); + $crawler = self::submit($form); + $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); + + $crawler = self::request('GET', 'index.php?style=' . $style_id); + $this->assertNotContains('Menu', $crawler->text()); + } } From cfa2657da4de716585b4d371f300eba392aeecb4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 14 Feb 2015 22:30:57 +0100 Subject: [PATCH 15/15] [ticket/469] Correctly create path to images on pages outside root B3P-469 --- controller/helper.php | 4 ++-- controller/main.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controller/helper.php b/controller/helper.php index 00925498..ce7d892f 100644 --- a/controller/helper.php +++ b/controller/helper.php @@ -227,7 +227,7 @@ class helper { $this->template->assign_block_vars('modules_' . $this->portal_columns->number_to_string($row['module_column']), array( 'TEMPLATE_FILE' => 'portal/modules/' . $template_module['template'], - 'IMAGE_SRC' => $this->path_helper->get_web_root_path() . $this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $template_module['image_src'], + 'IMAGE_SRC' => $this->path_helper->get_web_root_path() . ltrim($this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $template_module['image_src'], './'), 'TITLE' => $template_module['title'], 'CODE' => $template_module['code'], 'MODULE_ID' => $row['module_id'], @@ -239,7 +239,7 @@ class helper { $this->template->assign_block_vars('modules_' . $this->portal_columns->number_to_string($row['module_column']), array( 'TEMPLATE_FILE' => 'portal/modules/' . $template_module, - 'IMAGE_SRC' => $this->path_helper->get_web_root_path() . $this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $row['module_image_src'], + 'IMAGE_SRC' => $this->path_helper->get_web_root_path() . ltrim($this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/images/portal/' . $row['module_image_src'], './'), 'IMAGE_WIDTH' => $row['module_image_width'], 'IMAGE_HEIGHT' => $row['module_image_height'], 'MODULE_ID' => $row['module_id'], diff --git a/controller/main.php b/controller/main.php index 729b17d3..2d61fba6 100644 --- a/controller/main.php +++ b/controller/main.php @@ -276,7 +276,7 @@ class main 'S_BOTTOM_COLUMN' => $this->check_module_count('bottom'), 'S_DISPLAY_PHPBB_MENU' => $this->config['board3_phpbb_menu'], 'B3P_DISPLAY_JUMPBOX' => $this->config['board3_display_jumpbox'], - 'T_EXT_THEME_PATH' => $this->path_helper->get_web_root_path() . $this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/', + 'T_EXT_THEME_PATH' => $this->path_helper->get_web_root_path() . ltrim($this->root_path . 'styles/' . $this->user->style['style_path'] . '/theme/', './'), )); }