diff --git a/acp/portal_module.php b/acp/portal_module.php index eb0a6b87..84e63870 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')) { @@ -97,6 +101,10 @@ 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_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), ) ); @@ -215,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/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/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 f814de54..2d61fba6 100644 --- a/controller/main.php +++ b/controller/main.php @@ -80,6 +80,9 @@ class main */ protected $portal_modules; + /** @var int 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]; @@ -252,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/', './'), )); } @@ -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; + } + } } diff --git a/event/listener.php b/event/listener.php index e31415e8..1e596995 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; @@ -113,9 +118,10 @@ 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(); } 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_pages']) + { + $this->board3_controller->handle(array( + '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..cc9b1956 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -158,4 +158,32 @@ 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); + } + + /** + * Store left right choice + * + * @param string $key Config key + */ + public function store_left_right($key) + { + // Get selected side + $value = $this->request->variable($key, 0); + + $this->config->set($key, $value); + } } diff --git a/language/en/portal_acp.php b/language/en/portal_acp.php index 485ff84e..35575c26 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_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 new file mode 100644 index 00000000..7af56093 --- /dev/null +++ b/migrations/v210_rc3.php @@ -0,0 +1,27 @@ + + + + + +
| + + + + + + + + + + + | + + ++ 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 @@ - 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()); + } } 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'); + } +} 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, |