Ipb 2.2:Admin CP Integration
From IpbWiki
Admin CP Integration
You've coded your first few mods, but now what? You want to make your mods easier to use and control through the Admin CP. So how would you go about doing that? This tutorial explains how to set up on/off Admin CP settings, forum selection settings, and group selection settings. All the basics compiled into an easy tutorial.
This is the structure of a basic Universal Mod Installer XML file with just a single setting.
<mod_data>
<mod_info>
<title>PZ23-Admin CP Integration</title>
<version>1.0</version>
<author>John</author>
<website>http://www.pznetworks.com/forums/index.php</website>
<ipbver>2.3</ipbver>
</mod_info>
<sections_group>
<section>
<conf_title_title>[PZ23] Admin CP Integration</conf_title_title>
<conf_title_desc><![CDATA[Settings for the PZ23-Admin CP Integration by John of Platinum Zone.]]></conf_title_desc>
<conf_title_keyword>pz_integrate</conf_title_keyword>
<conf_title_noshow>0</conf_title_noshow>
</section>
</sections_group>
<settings_group>
<setting>
<conf_title>System Online?</conf_title>
<conf_description><![CDATA[Turn system online?]]></conf_description>
<conf_group></conf_group>
<conf_type>yes_no</conf_type>
<conf_key>pz_turniton</conf_key>
<conf_default>1</conf_default>
<conf_extra></conf_extra>
<conf_evalphp></conf_evalphp>
<conf_position>1</conf_position>
<conf_start_group></conf_start_group>
<conf_end_group></conf_end_group>
<conf_help_key></conf_help_key>
</setting>
</settings_group>
</mod_data>
Study the structure. The first few fields are simple to understand. Title, version, author, website, and ipbver. However, when filling in ipbver, remember that the version of the IP.Board that your modification works with will only be the first two digits (with a period in between). So for a modification that was made on an IPB 2.2.2, forum, you would only type in 2.2.
Next comes the sections group. The sections group is basically the group of settings that can be accessed from the Tools & Settings tab. Title, description, keyword, and noshow are its attributes. The first three are self-explanatory. The fourth, noshow, is not something you need to worry about right now.
Next is our settings group. Inside you will observe a setting that will control the modification.
Turn system online? It's important to let the user decide if the modification should be running or disabled at any given time. That's why you should include such a setting in your XML settings file which will be read by the Universal Mod Installer.
The attributes of the setting that you need to change are the conf_title, conf_description, and conf_key in order to have an on/off setting.
So you've created your first XML file. But how do you plan to integrate it with your mod?
You need to be able to fetch the current position of the setting (yes/no) to be able to put it into your script. This is done with $this->ipsclass->vars['<conf_keyword>'].
In my XML file, I chose pz_turniton as my conf_keyword. Now I'll have to write an if statement in my PHP script that will use that setting in order to determine if the mod should be executed.
// PZ23: Execution Time
//--------------------------------
if ( $this->ipsclass->vars['pz_turniton'] )
{
//Place the execution code here
}
The if statement verifies that $this->ipsclass->vars['pz_turniton'] is set to 1. So if the user has set the setting to 0 (no, or off in the Admin CP), then the if statement would not be executed. When the setting is turned to Yes, then the execution code will be executed next time the script is run.
Congratulations, you've made your first setting. But let's step it up a notch.
Forum Permissions You want your members to be able to select forum(s) from the list of all of their forums/subforums that will integrate with your script. So here's how you do it.
<conf_title>Group Permissions</conf_title>
<conf_description><![CDATA[Simply specify which forum(s) will be affected by this mod. ]]></conf_description>
<conf_group></conf_group>
<conf_type>multi</conf_type>
<conf_key>pz_ilbg</conf_key>
<conf_default>null</conf_default>
<conf_extra>#show_forums#</conf_extra>
<conf_evalphp><![CDATA[if ( $save == 1)
{
if ( is_array($_POST['pz_ilbg']) )
{
$_POST['pz_ilbg'] = implode(\\",\\",$_POST['pz_ilbg']);
}
else
{
$_POST['pz_ilbg'] = \\"\\";
}
$key = 'pz_ilbg';
}
if ( $show == 1 )
{
$key = 'pz_ilbg[]';
}]]></conf_evalphp>
<conf_position></conf_position>
<conf_start_group></conf_start_group>
<conf_end_group></conf_end_group>
<conf_help_key></conf_help_key>
</setting>
In bold are the keywords that you MUST replace with your own for this setting to work correctly. So just replace those with your own by running a search and replace on pz_ilbg if you have such a feature on your editor.
Place that in your XML and your mod users will be able to select multiple forums/subforums that will be coordinating with this mod.
[\\"http://images.pznetworks.com/viewer.php?id=39groupis.png\\"
So now let's set up an if statement to check if the user is in a forum that is selected by the user in the Admin CP.
{
//Execution code
}
There you go! Now if a user is in a specific forum, only then will the mod execute.
Group Permissions Next up is the group permissions. To be perfectly honest all you have to do is copy the Forum Permissions setting and replace #show_forums# with #show_groups# as well as the keywords that are highlighted above with your own.
So an example of this would be:
<conf_title>Group Permissions</conf_title>
<conf_description><![CDATA[Simply specify which forum(s) will be affected by this mod. ]]></conf_description>
<conf_group></conf_group>
<conf_type>multi</conf_type>
<conf_key>pz_groupies</conf_key>
<conf_default>null</conf_default>
<conf_extra>#show_groups#</conf_extra>
<conf_evalphp><![CDATA[if ( $save == 1)
{
if ( is_array($_POST['pz_groupies']) )
{
$_POST['pz_groupies'] = implode(\\",\\",$_POST['pz_groupies']);
}
else
{
$_POST['pz_groupies'] = \\"\\";
}
$key = 'pz_groupies';
}
if ( $show == 1 )
{
$key = 'pz_groupies[]';
}]]></conf_evalphp>
<conf_position></conf_position>
<conf_start_group></conf_start_group>
<conf_end_group></conf_end_group>
<conf_help_key></conf_help_key>
</setting>
And now users can choose groups in their scripts like below.
[\"http://images.pznetworks.com/viewer.php?id=97whois.png\"
]
And here is an example of PHP code that will determine if the current browsing user is in a specified member group:
{
//Execution code
}
And in the end this is a possible result after including 3 types of settings in your XML:
[\"http://images.pznetworks.com/viewer.php?id=76makemod.png\"
]
Overall making your mod a lot more user-friendly and more convenient.
Those are the basic settings, but with thought you can put them into very effective use.
© 2007 by John of Platinum Zone
