Plugin Settings
#1
I was thinking. How do I add more settings to this.

Like a, is this plugin enabled or not.

//All the activation processes go here
function tospopup_activate()
{
    global $db;

     $group = array(
        "gid"            => "NULL",
        "title"          => "Terms of Service Popup",
        "name"           => "tospopup",
        "description"    => "Settings for Terms of Service Popup.",
        "disporder"      => "1",
        "isdefault"      => "no",
    );
    
    $db->insert_query(TABLE_PREFIX."settinggroups", $group);
    $gid = $db->insert_id(); //This will get the id of the just added record in the db
    
    
    $setting_1 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Terms of Service Version",
        "description"    => "What is your current Terms of Service Version. Change this version number to another number whenever you want to force your users to accept the new Terms of Service.",
        "optionscode"    => "text",
        "value"          => '1.0.0',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $setting_1);
    rebuildsettings();
}

//All deactivation processes go here
function tospopup_deactivate()
{
    global $db;

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tospopup'");
    rebuildsettings();
} 
Reply
#2
I'm not really sure what you mean. Would you care to elaborate?
Reply
#3
Well, you alredy have the info there Toungue

Just add:
   $setting_2 = array(
        "sid"            => "NULL",
        "name"           => "yoursecondsetting",
        "title"          => "setting title for setting 2",
        "description"    => "Setting desc for setting 2",
        "optionscode"    => "text",
        "value"          => '1.0.0',
        "disporder"      => '2',
        "gid"            => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $setting_2);
Between:
$db->insert_query(TABLE_PREFIX."settings", $setting_1);
and:
RebuildSettings()
You only need to RebuildSettings() after adding all of your settings to the db.

Also, you need to remove all the settigns in the unninstall process like so:

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('tospopup_setting','yoursecondsetting')");
rebuildsettings();
Reply
#4
you really should be using the _install and _uninstall functions for most of that code and leave _activate and _deactivate empty or for template changes.

the _is_installed function if you set it up properly would tell you if it is installed.

You can create a settings that is a "main switch" which is a simple on/off setting that you can test in whatever function you hook into. say you hook into global_start with myplugin_do_force_tos()

function myplugin_do_force_tos()
{
    global $mybb;

    if($mybb->settings['myplugin_main_switch'] == 1)
    {
        if(VERSION CHECK GOES HERE)
        {
            //do work
        }
    }
}
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#5
Also note, its rebuild_settings(); and not rebuildsettings();
Reply
#6
So this is what I have for now? Does this look fine?

//All the activation processes go here
function tospopup_activate()
{
    global $db;

     $group = array(
        "gid"            => "NULL",
        "title"          => "Terms of Service Popup",
        "name"           => "tospopup",
        "description"    => "Settings for Terms of Service Popup.",
        "disporder"      => "1",
        "isdefault"      => "no",
    );
    
    $db->insert_query(TABLE_PREFIX."settinggroups", $group);
    $gid = $db->insert_id(); //This will get the id of the just added record in the db
    
    
    $setting_1 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Is Terms of Service Popup Enabled",
        "description"    => "To use Terms of Service Popup you have to enable it. Check Yes to enable it.",
        "optionscode"    => "yesno",
        "value"          => 'no',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $setting_1);

    $setting_2 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Terms of Service Version",
        "description"    => "What is your current Terms of Service Version. Change this version number to another number whenever you want to force your users to accept the new Terms of Service.",
        "optionscode"    => "text",
        "value"          => '1.0.0',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $setting_2);

    $setting_3 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Terms of Service In Text",
        "description"    => "Here you have to write your Terms of Service in text.",
        "optionscode"    => "textarea",
        "value"          => 'Please Write Your Terms of Service Here',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query(TABLE_PREFIX."settings", $setting_3);
    rebuildsettings();
}

//All deactivation processes go here
function tospopup_deactivate()
{
    global $db;

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tospopup'");
    rebuild_settings();
} 
Reply
#7
First of all, do not use this: TABLE_PREFIX. in queries like: --> $db->insert_query(TABLE_PREFIX."settinggroups", $group);

In MyBB 1.4.x and above, It should be like this: $db->insert_query("settinggroups", $group);
Reply
#8
(2011-11-10, 12:54 PM)Yaldaram Wrote: First of all, do not use this: TABLE_PREFIX. in queries like: --> $db->insert_query(TABLE_PREFIX."settinggroups", $group);

In MyBB 1.4.x and above, It should be like this: $db->insert_query("settinggroups", $group);

Is this right then?
//All the activation processes go here
function tospopup_activate()
{
    global $db;

     $group = array(
        "gid"            => "NULL",
        "title"          => "Terms of Service Popup",
        "name"           => "tospopup",
        "description"    => "Settings for Terms of Service Popup.",
        "disporder"      => "1",
        "isdefault"      => "no",
    );
    
    $db->insert_query("settinggroups", $group);
    $gid = $db->insert_id(); //This will get the id of the just added record in the db
    
    
    $setting_1 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Is Terms of Service Popup Enabled",
        "description"    => "To use Terms of Service Popup you have to enable it. Check Yes to enable it.",
        "optionscode"    => "yesno",
        "value"          => 'no',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query("settings", $setting_1);

    $setting_2 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Terms of Service Version",
        "description"    => "What is your current Terms of Service Version. Change this version number to another number whenever you want to force your users to accept the new Terms of Service.",
        "optionscode"    => "text",
        "value"          => '1.0.0',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query("settings", $setting_2);

    $setting_3 = array(
        "sid"            => "NULL",
        "name"           => "tospopup_setting",
        "title"          => "Terms of Service In Text",
        "description"    => "Here you have to write your Terms of Service in text.",
        "optionscode"    => "textarea",
        "value"          => 'Please Write Your Terms of Service Here',
        "disporder"      => '1',
        "gid"            => intval($gid),
    );

    $db->insert_query("settings", $setting_3);
    rebuildsettings();
}

//All deactivation processes go here
function tospopup_deactivate()
{
    global $db;

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tospopup'");
    rebuild_settings();
} 

NOTE: I didn't removed it from here, cause I wasn't sure if it had to be removed here too.

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tospopup'");
    rebuild_settings();
Reply
#9
Its fine, just for the future reference, TABLE_PREFIX at the start of the query is now not needed in 1.4.x and above. So starting right through the table name is fine, like this: $db->insert_query("table_name", $group); etc.
Reply
#10
(2011-11-10, 01:16 PM)Yaldaram Wrote: Its fine, just for the future reference, TABLE_PREFIX at the start of the query is now not needed in 1.4.x and above. So starting right through the table name is fine, like this: $db->insert_query("table_name", $group); etc.

But what about this?

Do I also have to remove it from here:
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tospopup'");
    rebuild_settings(); 

So it will look like this:
$db->query("DELETE FROM settings WHERE name='tospopup_setting'");
    $db->query("DELETE FROM settinggroups WHERE name='tospopup'");
    rebuild_settings(); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)