[ticket/16904] Fix regression in MCP for topics selection

Regression introduced in #5760

PHPBB3-16904
This commit is contained in:
rxu 2021-11-02 13:55:39 +07:00
parent 8246023e0f
commit 337d876df7
No known key found for this signature in database
GPG key ID: 955F0567380E586A
2 changed files with 29 additions and 41 deletions

View file

@ -35,7 +35,7 @@ function phpbb_module_notes_url($mode, $module_row)
} }
global $user_id; global $user_id;
return ($user_id) ? "&u=$user_id" : ''; return phpbb_extra_url();
} }
function phpbb_module_warn_url($mode, $module_row) 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') if ($mode == 'front' || $mode == 'list')
{ {
global $forum_id; global $forum_id;
return phpbb_extra_url();
return ($forum_id) ? "&f=$forum_id" : '';
} }
if ($mode == 'warn_post') if ($mode == 'warn_post')
{ {
global $forum_id, $post_id; global $forum_id, $post_id;
return phpbb_extra_url();
if ($post_id)
{
$url_extra = "&p=$post_id";
}
else if ($forum_id)
{
$url_extra = "&f=$forum_id";
}
else
{
$url_extra = '';
}
return $url_extra;
} }
else else
{ {
global $user_id; global $user_id;
return phpbb_extra_url();
return ($user_id) ? "&u=$user_id" : '';
} }
} }
@ -99,30 +83,34 @@ function phpbb_module_reports_url($mode, $module_row)
return phpbb_extra_url(); 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);
} }
/** /**

View file

@ -662,7 +662,7 @@ class p_master
// Add url_extra parameter to u_action url // 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']) 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 // Assign the module path for re-usage
@ -920,7 +920,7 @@ class p_master
} }
// Was not allowed in categories before - /*!$item_ary['cat'] && */ // 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 // 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))) if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent)))