Need help with adding a foreach into admin &$areas hook array?

Started by Pipke, January 22, 2015, 08:12:41 AM

Previous topic - Next topic

Pipke

ok, got this function script wich is loaded with 'integrate_admin_areas' => 'rft_mod_admin',
see attachment rft_admin_hook.jpg

function rft_mod_admin(&$areas)

{
    global $txt;

    loadLanguage('RecentForumTopics');
   
    $areas['config']['areas']['modsettings']['subsections']['recentforumtopics'] = array($txt['rft_name']);
}

function rft_mod_settings(&$sub_actions)
{
    global $context;
    $sub_actions['recentforumtopics'] = 'rft_blockSettings';
   
}

function rft_blockSettings($return_config = false)
{
    global $context, $scripturl, $txt, $modSettings;
   
    $config_vars = array(
        array('desc', 'rft_topic_solvednote'),
        array('desc', 'rft_portalnote'),       
        array('permissions', rft_test_permissions')                   
        array('check', 'rft_enable', 'subtext' => $txt['rft_enable_sub'],),       
        array('select', 'rft_numbertopics', array('3' => $txt['rft_3'],'4' => $txt['rft_4'],'5' => $txt['rft_5'],'6' => $txt['rft_6'],'7' => $txt['rft_7'],'8' => $txt['rft_8'],'9' => $txt['rft_9'],'10' => $txt['rft_10'],)),
        array('check', 'rft_disable_smfrecentposts', array('desc', 'rft_topic_solvednote')),
        array('select', 'rft_subject_topics', 'subtext' => $txt['rft_subject_topics_sub'], array('last' => $txt['rft_last'],'first' => $txt['rft_first'],)),
        array('select', 'rft_link_topics', 'subtext' => $txt['rft_link_topics_sub'], array('last' => $txt['rft_last'],'first' => $txt['rft_first'],)),       
        array('check', 'rft_linktree'),
        array('check', 'rft_counter_viewnumbers'),
        array('int', 'rft_color_viewnumbers', 'subtext' => $txt['rft_color_viewnumbers_sub'], 'preinput' => '#', 'size' => 7),
        array('check', 'rft_firstpostlinkicon'),
        array('check', 'rft_lastpostlinkicon'),
        array('check', 'rft_menubuttons'),
        array('check', 'rft_postingicons'),
        array('check', 'rft_topic_solved', 'subtext' => $txt['rft_topic_solved_sub']),
        array('check', 'rft_portal', 'subtext' => $txt['rft_portal_sub']),
        '',
        array('select', 'rft_set_areas', 'subtext' => $txt['rft_test'], array('stop' => $txt['rft_stop'],'start' => $txt['rft_start'],)),           
    );
   
    if ($return_config)
        return $config_vars;

    $context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=recentforumtopics';

    $context['settings_title'] = $txt['rft_settings_title'];

    if (empty($config_vars))
    {
        $context['settings_save_dont_show'] = false;

        $context['settings_message'] = '<div align="center">' . $txt['modification_no_misc_settings'] . '</div>';

        return prepareDBSettingContext($config_vars);
    }

    if (isset($_GET['save']))
    {
        checkSession();
        if ((!empty($_POST['rft_color_viewnumbers'])) && (ctype_alnum($_POST['rft_color_viewnumbers']) === false))
            fatal_lang_error('rft_error_color', false);
           
        $save_vars = $config_vars;

        saveDBSettings($save_vars);

        redirectexit('action=admin;area=modsettings;sa=recentforumtopics');
    }
   
    prepareDBSettingContext($config_vars);
}


How To add this script:
see attachment rft_admin_boards_want_in_hook.jpg

$request = $smcFunc['db_query']('','
            SELECT id_board, name, redirect
            FROM {db_prefix}boards
            ORDER BY name ASC'
        );
        $context['display_boards'] = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) //{
            if (empty($row['redirect']))  // Ignore the redirected boards
                $context['display_boards']['b' . $row['id_board']] = $row['name'];
        $smcFunc['db_free_result']($request);

echo '<pre>';
print_r($context['display_boards']);
echo '</pre>';   
foreach ($context['display_boards'] as $rft_boards)       
{
echo'
    <dl class="settings">
        <dt>
            <label for="rft_boards">', $rft_boards, ':</label>
        </dt>
        <dd>
            <input type="checkbox" name="rft_boards" value="1" id="rft_boards"', empty($modSettings['rft_boards']) ? '' : ' checked="checked"', ' class="input_check" />
        </dd>
    </dl>';
}   


Between this array?: (function rft_blockSettings)
see attachment rft_result.jpg

$config_vars = array(
        array('desc', 'rft_topic_solvednote'),
        array('desc', 'rft_portalnote'),       
        array('permissions', 'rft_test_permissions')                   
        array('check', 'rft_enable', 'subtext' => $txt['rft_enable_sub'],),       
        array('select', 'rft_numbertopics', array('3' => $txt['rft_3'],'4' => $txt['rft_4'],'5' => $txt['rft_5'],'6' => $txt['rft_6'],'7' => $txt['rft_7'],'8' => $txt['rft_8'],'9' => $txt['rft_9'],'10' => $txt['rft_10'],)),
        array('check', 'rft_disable_smfrecentposts', array('desc', 'rft_topic_solvednote')),
        array('select', 'rft_subject_topics', 'subtext' => $txt['rft_subject_topics_sub'], array('last' => $txt['rft_last'],'first' => $txt['rft_first'],)),
        array('select', 'rft_link_topics', 'subtext' => $txt['rft_link_topics_sub'], array('last' => $txt['rft_last'],'first' => $txt['rft_first'],)),       
        array('check', 'rft_linktree'),
        array('check', 'rft_counter_viewnumbers'),
        array('int', 'rft_color_viewnumbers', 'subtext' => $txt['rft_color_viewnumbers_sub'], 'preinput' => '#', 'size' => 7),
        array('check', 'rft_firstpostlinkicon'),
        array('check', 'rft_lastpostlinkicon'),
        array('check', 'rft_menubuttons'),
        array('check', 'rft_postingicons'),
        array('check', 'rft_topic_solved', 'subtext' => $txt['rft_topic_solved_sub']),
        array('check', 'rft_portal', 'subtext' => $txt['rft_portal_sub']),
        '',
        array('select', 'rft_set_areas', 'subtext' => $txt['rft_test'], array('stop' => $txt['rft_stop'],'start' => $txt['rft_start'],)),           
    );


What the actualy result needs to be is that admin can select wich boards to exclude to show on the recent forum topics with checkboxes.
Anyone know how to do this?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Pipke

ok almost 200 views, then the question is, is this even possible, to call a function+template within the array and print it out within the admin hook of maybe after it? I know smf can call/load the usergroup permissions and print that out in that hook section but not grabbing boards? If i get answer it cannot be done, ok fair to me then i build it another way, with just a textfield to enter the board id's in it?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Arantor

There is no ready made way to do this, there are a variety of ways of doing it but given that last time I poured time into explaining how to do something the proper way I found my time wasted, I'm not in any hurry to repeat that.

Suki

$config_vars is a manipulative array, this means you can do whatever you want with it, including defining it separately.

you ca split $config_vars right in the exact place where you want to add your query result:


$config_vars = array(
        array('desc', 'rft_topic_solvednote'),
        array('desc', 'rft_portalnote'),                   
    );



Then simply append your query result using either

$config_vars[]

or array_merge or even $config_vars += $query_result;

Then print the rest of your settings with another array:

$config_vars += array(settings here); or with another array_merge()  or add each one separately via $config_vars[]
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Thx Suki for pointing me out where to start, pfff looks hard for me, ill try with my knowledge to get this working, ill let you know the outcome.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

It really isn't that difficult. Check out what I did on one of my mods:

https://github.com/MissAllSunday/emailInactiveUsers/blob/master/Sources/emailInactiveUsers.php#L76

function eiu_membergroups(); returns an array of selectable groups and I print them all on my own $config_vars array  then I added some more settings via $config_vars[]
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Quote from: Suki on January 23, 2015, 10:34:41 AM
It really isn't that difficult. Check out what I did on one of my mods:

https://github.com/MissAllSunday/emailInactiveUsers/blob/master/Sources/emailInactiveUsers.php#L76

function eiu_membergroups(); returns an array of selectable groups and I print them all on my own $config_vars array  then I added some more settings via $config_vars[]

::) +1
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Pipke

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Cool, just keep in mind that using the "multi" param in a select field before 2.0.9 will yield an error due to a bug on SMF. 2.0.9 added  a wrong fix for it so it hasn't truly been solved.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

A bug is that it doesnt save it when you unselect the selection, like when unset all the selections in the box and save it, it still returns the selection you saved of the last selection, also tested this with your EmailInactiveUsers , it happens there also. Do you know if there is a fix for it?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Thats the one I'm talking about.  2.0.9 had a fix for it but wasn't properly implemented.

Yes, it will only happen with mods that uses the multi param on a select tag, there aren't that many, I only knew mine and now yours.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Quote from: Suki on January 29, 2015, 10:09:41 AM
Thats the one I'm talking about.  2.0.9 had a fix for it but wasn't properly implemented.


If anyone is intrested how to fix this, i have fixed it with this code:
function rft_view_perm()
{   
    global $smcFunc, $modSettings, $txt;
        $request = $smcFunc['db_query']('', '       
        SELECT id_group, group_name       
        FROM {db_prefix}membergroups       
        WHERE id_group > {int:admin}',       
        array(           
        'admin' => 1,        )   
        );   
    $return = array();   
    while ($row = $smcFunc['db_fetch_assoc']($request))       
        $return[$row['id_group']] = $row['group_name'];   
    $smcFunc['db_free_result']($request);
        $beginning = array(1 => $txt['rft_select_all_groups'], 0 => $txt['guests']);
        $returnresult = $beginning + $return;   
    return $returnresult;
}

function rft_hide_boards()
{
    global $smcFunc, $modSettings, $txt;   
        $request = $smcFunc['db_query']('','           
        SELECT id_board, name, redirect           
        FROM {db_prefix}boards           
        ORDER BY name ASC'       
        );   
    $return = array();   
    while ($row = $smcFunc['db_fetch_assoc']($request))   
        if (empty($row['redirect']))       
        $return[$row['id_board']] = $row['name'];           
    $smcFunc['db_free_result']($request);   
        $beginning = array(0 => $txt['rft_select_all_boards']);
        $returnresult = $beginning + $return;   
    return $returnresult;
}

function rft_hide_cats()
{   
    global $smcFunc, $modSettings, $txt;   
    $request = $smcFunc['db_query']('','           
    SELECT id_cat, name           
    FROM {db_prefix}categories           
    ORDER BY name ASC'       
    );   
    $return = array();   
    while ($row = $smcFunc['db_fetch_assoc']($request))   
        $return[$row['id_cat']] = $row['name'];           
    $smcFunc['db_free_result']($request);       
        $beginning = array(0 => $txt['rft_select_all_cats']);
        $returnresult = $beginning + $return;   
    return $returnresult;
}


wich results to the attchment image.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Well, the actual fix on 2.0.9 will do the trick, you just have to apply it properly.

You really don't need to fix it on your mod as its not a bug on your mod but an SMF bug.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Pipke

Quote from: Suki on January 31, 2015, 12:45:24 PM
Well, the actual fix on 2.0.9 will do the trick, you just have to apply it properly.


Where can i find that fix then?
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Suki

Its included on the 2.0.9 package. But, like I said, it really isn't your duty to fix this :)  Its an SMF bug and should be addressed on the next patch, we are only waiting to gather some more fixes to make the release worth it.

In the mean time, you won't get that much reports, I received 3 or 4 all of them pretty easily to resolve.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: