Page 1 of 1

MCP module missing forum id for mode sections

Posted: Thu May 07, 2015 11:18 pm
by docpify
Hello,

To enable my moderators to do some simple administrative tasks on subforums (create/rename), I have made a custom MCP module. The first part I made, to create subforums, worked just fine, but when I started adding another mode for renaming forums, I found that the mode links in the control panel do not include an f value, so the forum id is lost when navigating, making my code inoperable.

My info/mcp_subforum.php: https://ghostbin.com/paste/gwne8
My mcp_subforum.php: https://ghostbin.com/paste/qhx5g

I have cleared the cache multiple times as well, but I am unable to get the f parameter added to these mode links. It works fine for the default modules, and I can not see what they do different..

I have been searching for the answers with no luck, and the code involved is too opaque for me to be able to follow, so I hope someone on here will be able to help!

-- Cheers, Morten

Re: MCP module missing forum id for mode sections

Posted: Fri May 08, 2015 7:40 am
by AmigoJack
The module class checks for _module_* functions and calls them, i.e. /includes/functions_module.php:

Code: Select all

            // Function for building 'url_extra'
            $url_func = '_module_' . $row['module_basename'] . '_url';

            // Function for building the language name
            $lang_func = '_module_' . $row['module_basename'] . '_lang';

            // Custom function for calling parameters on module init (for example assigning template variables)
            $custom_func = '_module_' . $row['module_basename'];
The MCP can append the forum ID to every URI because /mcp.php has:

Code: Select all

function _module_main_url($mode, &$module_row)
{
    return extra_url();
}

function _module_logs_url($mode, &$module_row)
{
    return extra_url();
}

function _module_ban_url($mode, &$module_row)
{
    return extra_url();
}

function _module_queue_url($mode, &$module_row)
{
    return extra_url();
}

function _module_reports_url($mode, &$module_row)
{
    return extra_url();
}

function extra_url()
{
    global $forum_id, $topic_id, $post_id, $report_id, $user_id;

    $url_extra = '';
    $url_extra .= ($forum_id) ? "&f=$forum_id" : '';
    $url_extra .= ($topic_id) ? "&t=$topic_id" : '';
    $url_extra .= ($post_id) ? "&p=$post_id" : '';
    $url_extra .= ($user_id) ? "&u=$user_id" : '';
    $url_extra .= ($report_id) ? "&r=$report_id" : '';

    return $url_extra;
}

You must create your own function in there, i.e.:

Code: Select all

function _module_subforum_url($mode, &$module_row)
{
    return extra_url();
}

Re: MCP module missing forum id for mode sections

Posted: Mon May 11, 2015 12:07 pm
by docpify
Thanks a lot, that fixed it!