diff --git a/config/services.yml b/config/services.yml index 64e5b52c..1198d358 100644 --- a/config/services.yml +++ b/config/services.yml @@ -51,7 +51,9 @@ services: - '@auth' - '@config' - '@controller.helper' + - '@dbal.conn' - '@request' + - '%tables.styles%' board3.portal.columns: class: board3\portal\portal\columns diff --git a/controller/helper.php b/controller/helper.php index 283f97d4..6c3198ae 100644 --- a/controller/helper.php +++ b/controller/helper.php @@ -230,16 +230,9 @@ class helper */ public function assign_module_vars($row, $template_module) { - $use_fa = 0; - $fa_styles = explode(';', $this->config['board3_portal_fa_styles']); - foreach ($fa_styles as $fa_style) - { - if ($this->user->style['style_name'] == $fa_style) - { - $use_fa = 1; - break; - } - } + $fa_styles = json_decode($this->config['board3_portal_fa_styles']); + $use_fa = !empty($fa_styles) && in_array($this->user->style['style_name'], $fa_styles); + if (is_array($template_module)) { $this->template->assign_block_vars('modules_' . $this->portal_columns->number_to_string($row['module_column']), array( @@ -250,8 +243,8 @@ class helper 'MODULE_ID' => $row['module_id'], 'IMAGE_WIDTH' => $row['module_image_width'], 'IMAGE_HEIGHT' => $row['module_image_height'], - 'FA_ICON' => utf8_htmlspecialchars($row['module_fa_icon']), - 'FA_SIZE' => $row['module_fa_size'], + 'FA_ICON' => isset($row['module_fa_icon']) ? utf8_htmlspecialchars($row['module_fa_icon']) : '', + 'FA_SIZE' => $row['module_fa_size'] ?? '', 'FA_ENABLED' => $use_fa, )); } @@ -264,8 +257,8 @@ class helper 'IMAGE_HEIGHT' => $row['module_image_height'], 'MODULE_ID' => $row['module_id'], 'TITLE' => (isset($this->user->lang[$row['module_name']])) ? $this->user->lang[$row['module_name']] : utf8_normalize_nfc($row['module_name']), - 'FA_ICON' => utf8_htmlspecialchars($row['module_fa_icon']), - 'FA_SIZE' => $row['module_fa_size'], + 'FA_ICON' => isset($row['module_fa_icon']) ? utf8_htmlspecialchars($row['module_fa_icon']) : '', + 'FA_SIZE' => $row['module_fa_size'] ?? '', 'FA_ENABLED' => $use_fa, )); } diff --git a/includes/modules_helper.php b/includes/modules_helper.php index 5b778dc1..96e0f93a 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -25,6 +25,9 @@ class modules_helper */ protected $config; + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + /** @var \phpbb\controller\helper Controller helper */ protected $controller_helper; @@ -34,6 +37,9 @@ class modules_helper */ protected $request; + /** @var string Styles table */ + protected $styles_table; + /** * Constructor * NOTE: The parameters of this method must match in order and type with @@ -41,14 +47,18 @@ class modules_helper * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\config\config $config phpBB config * @param \phpbb\controller\helper $controller_helper Controller helper + * @param \phpbb\db\driver\driver_interface $db Dbal connection * @param \phpbb\request\request $request phpBB request + * @param string $styles_table Styles table */ - public function __construct($auth, $config, $controller_helper, $request) + public function __construct($auth, $config, $controller_helper, $db, $request, string $styles_table) { $this->auth = $auth; $this->config = $config; $this->controller_helper = $controller_helper; + $this->db = $db; $this->request = $request; + $this->styles_table = $styles_table; } /** @@ -194,30 +204,27 @@ class modules_helper * * @return string Select with available styles */ - public function display_fa_styles() + public function display_fa_styles(): string { - global $phpbb_container; - $table_prefix = $phpbb_container->getParameter('core.table_prefix'); - $db = $phpbb_container->get('dbal.conn'); - $selected = explode(';', $this->config['board3_portal_fa_styles']); + $portal_fa_styles = json_decode($this->config->offsetGet('board3_portal_fa_styles')); + if (!$portal_fa_styles) + { + $portal_fa_styles = []; + } $options = ''; $query = 'SELECT style_name - FROM ' . $table_prefix . 'styles'; - $result = $db->sql_query($query); - while ($row = $db->sql_fetchrow($result)) + FROM ' . $this->styles_table; + $result = $this->db->sql_query($query); + while ($row = $this->db->sql_fetchrow($result)) { $options .= '