diff --git a/phpBB/includes/functions_mcp.php b/phpBB/includes/functions_mcp.php index b467d7c2ed..fa3cc3de35 100644 --- a/phpBB/includes/functions_mcp.php +++ b/phpBB/includes/functions_mcp.php @@ -35,7 +35,7 @@ function phpbb_module_notes_url($mode, $module_row) } global $user_id; - return ($user_id) ? "&u=$user_id" : ''; + return phpbb_extra_url(); } function phpbb_module_warn_url($mode, $module_row) @@ -43,34 +43,18 @@ function phpbb_module_warn_url($mode, $module_row) if ($mode == 'front' || $mode == 'list') { global $forum_id; - - return ($forum_id) ? "&f=$forum_id" : ''; + return phpbb_extra_url(); } if ($mode == 'warn_post') { global $forum_id, $post_id; - - if ($post_id) - { - $url_extra = "&p=$post_id"; - } - else if ($forum_id) - { - $url_extra = "&f=$forum_id"; - } - else - { - $url_extra = ''; - } - - return $url_extra; + return phpbb_extra_url(); } else { global $user_id; - - return ($user_id) ? "&u=$user_id" : ''; + return phpbb_extra_url(); } } @@ -99,30 +83,34 @@ function phpbb_module_reports_url($mode, $module_row) return phpbb_extra_url(); } -function phpbb_extra_url() +/** + * Generate URL parameters for MCP modules + * + * @param array $additional_parameters Array with additional parameters in format of ['key' => 'parameter_name'] + * + * @return string String with URL parameters (empty string if not any) + */ +function phpbb_extra_url($additional_parameters = []) { - global $forum_id, $topic_id, $post_id, $report_id, $user_id; + $url_extra = []; + $url_parameters = array_merge([ + 'f' => 'forum_id', + 't' => 'topic_id', + 'p' => 'post_id', + 'r' => 'report_id', + 'u' => 'user_id', + ], $additional_parameters); - if ($post_id) + foreach ($url_parameters as $key => $value) { - $url_extra = "&p=$post_id"; + global $$value; + if (isset($$value) && $parameter = $$value) + { + $url_extra[] = "$key=$parameter"; + } } - else if ($topic_id) - { - $url_extra = "&t=$topic_id"; - } - else if ($forum_id) - { - $url_extra = "&f=$forum_id"; - } - else - { - $url_extra = ''; - } - $url_extra .= ($user_id) ? "&u=$user_id" : ''; - $url_extra .= ($report_id) ? "&r=$report_id" : ''; - return $url_extra; + return implode('&', $url_extra); } /** diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index e90c11f884..5b7c558365 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -662,7 +662,7 @@ class p_master // Add url_extra parameter to u_action url if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) { - $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; + $this->module->u_action .= '&' . $this->module_ary[$this->active_module_row_id]['url_extra']; } // Assign the module path for re-usage @@ -920,7 +920,7 @@ class p_master } // Was not allowed in categories before - /*!$item_ary['cat'] && */ - $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; + $u_title .= (isset($item_ary['url_extra']) && $item_ary['url_extra']) ? '&' . $item_ary['url_extra'] : ''; // Only output a categories items if it's currently selected if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent)))