discuz! Forum How to add configuration options

Source: Internet
Author: User

discuz! The forum has many configuration options in the background that can be implemented with many features. During the two development sessions of the discuz! forum, we also have to add a few configurations, and then do different things according to the configuration. Let me introduce you to the discuz! Add configuration options to the forum.

Let's take discuz!6.0 as an example. First, let's take a look at discuz!. Forum background Configuration Interface, as an administrator login forum background, select ' Basic Settings '-> ' Basic Settings ' will appear after the following interface:

Figure 1



This page uses the frame, we in the lower right side of the page to select ' Properties ', in the pop-up window, we found that the URL of this page is "/admincp.php?action=settings&do=basic", This page uses the program is admincp.php, first analyzes this file.
The 第172-290 line of this file is roughly as follows:

The code is as follows:
$cpscript = "";
if ($adminid = = 1) {
if ($action = = "Home") {
$cpscript = "Home";
} elseif ($action = = "Runwizard" && Isfounder ()) {
$cpscript = "Runwizard";
} ElseIf ...
} elseif ($adminid = = 2 $adminid = = 3) {
if ($action = = "Home") {
$cpscript = "Home";
ElseIf (($allowedituser $allowbanuser) && ($action = = "Editmember" $action = = "Banmember")) ($ALLOWBA Nip && $action = = "Ipban")) {
$cpscript = "Members";
} ElseIf ...
}
if ($cpscript) {
} ElseIf ...
}
if ($cpscript) {
Require_once discuz_root. ". /admin/". $cpscript.". Inc.php ";
} ......

This program is mainly based on the $action variable to assign the $cpscript, and then according to the value of the $cpscript to introduce the program files in the Admin directory. We look at the $action value on the left of the 179 line, and find that its $cpscript value is "settings," which means that the 283-line program file is "admin/settings.inc.php."
Then open settings.inc.php file, will find the contents of the inside is very long ah, do not be frightened by this, careful analysis of the good.

Line 14th:
The code is as follows:
$operation = $operation? $operation: (!empty ($do) $do: "");
This gives the $operation a value based on the $do value from the GET, in this case the value is "basic".
Line 17th:
The code is as follows:
$query = $db->query ("select * FROM {$tablepre}settings");
while ($setting = $db->fetch_array ($query)) {
$settings [$setting ["variable"]] = $setting ["Value"];
}
These program segments are read from the database and stored in the array $settings so that they can be invoked below.
The following program structure is as follows:
The code is as follows:
if (!submitcheck ("Settingsubmit")) {
if ($operation = = "Access") {
......
} elseif ($operation = = "Styles") {
......
} ElseIf ...
} else {
Data processing after a form is submitted
......
}

The Submitcheck function in the program is to check whether a form is submitted, and if the form is not committed, display the form based on the $operation that was previously processed. The value $operation here is basic, which executes the following paragraph:

The code is as follows:
$operation = "Basic";
ShowType ("Settings_general", "top");
Showsetting ("Settings_bbname", "Settingsnew[bbname]", $settings ["Bbname"], "text");
Showsetting ("Settings_sitename", "Settingsnew[sitename]", $settings ["SiteName"], "text");
Showsetting ("Settings_siteurl", "Settingsnew[siteurl]", $settings ["SiteURL"], "text");
Showsetting ("Settings_index_name", "Settingsnew[indexname]", $settings ["IndexName"], "text");
Showsetting ("SETTINGS_ICP", "SETTINGSNEW[ICP]", $settings ["ICP"], "text");
Showsetting ("settings_boardlicensed", "settingsnew[boardlicensed]", $settings ["boardlicensed"], "Radio");
Showsetting ("settings_bbclosed", "settingsnew[bbclosed]", $settings ["bbclosed"], "Radio");
Showsetting ("Settings_closedreason", "Settingsnew[closedreason]", $settings ["Closedreason"], "textarea");

A custom function showsetting is used here, and its first argument is the name of the configuration option, the second is the name value of the input when the HTML is displayed, and the third parameter is the value of the current configuration option, which is the array from the database above $settings A value in, and the fourth parameter is the type of input. We add a mytest of our own configuration options. Add the following code at the end of the above code:

The code is as follows:
Showsetting ("Settings_mytest", "settingsnew[mytest]", $settings ["MyTest"], "Radio");

Save, refresh the page found one more option at the bottom of the page:
Settings_mytest whether
But found that it is in English, we can modify the language pack on it. In the No. 450 line of the templates/default/admincp.lang.php file, "settings_closedreason_comment" => "the message that appears when the forum closes," Add the following code:

The code is as follows:
"Settings_mytest" => "Test options:",
"Settings_mytest_comment" => "Hints for test options",

Save and then refresh after the Chinese hint.
Now that the display on the interface has been processed, here's how to process the data after the form is submitted. The Else statement portion of the IF (!submitcheck ("Settingsubmit")) {} of the/admin/settings.inc.php file. This part of the code, first of all the data submitted to the processing, and then all put into the $settingsnew array, in fact, that is, POST the data to check. Around 1140 lines of this file have the following code:

The code is as follows:
foreach ($settingsnew as $key => $val) {
if (Isset ($settings [$key]) && $settings [$key]!= $val) {
$ $key = $val;
$updatecache = TRUE;
if (In_array ($key, Array ("Newbiespan", "Topicperpage", "Postperpage", "Memberperpage", "Hottopic",
"Starthreshold", "Delayviewcount", "Visitedforums", "Maxsigrows", "Timeoffset", "Statscachelife",
"Pvfrequence", "Oltimespan", "Seccodestatus", "Maxprice", "Rssttl", "Rewritestatus", "Bdaystatus",
"Maxonlines", "Loadctrl", "Floodctrl", "Regctrl", "Regfloodctrl", "Searchctrl", "Extcredits1", "extcredits2",
"Extcredits3", "Extcredits4", "extcredits5", "extcredits6", "Extcredits7", "Extcredits8",
"Transfermincredits", "Exchangemincredits", "Maxincperthread", "Maxchargespan", "MAXSPM",
"Maxsearchresults", "Maxsmilies", "Threadmaxpages", "Membermaxpages", "Maxpostsize",
"Minpostsize", "Maxavatarsize", "Maxavatarpixel", "Maxpolloptions", "Karmaratelimit", "Losslessdel",
"Edittimelimit", "Smcols", "Watermarktrans", "watermarkquality", "Jscachelife", "WAPTPP", "WAPPPP",
"Wapmps", "maxmodworksmonths", "Frameon", "Maxonlinelist")) {
$val = (float) $val;
}
$db->query ("REPLACE into {$tablepre}settings (variable, value) VALUES (" $key "," $val ")");
}
}

The purpose of this code is to check if there are any options in the $settingsnew array, float when there is a number option, and then replace all into the table settings, and the MyTest option is added to the datasheet, which is not selected in the datasheet. Item, I need to execute the following SQL statement in the database: REPLACE into cdb_settings (variable, value) VALUES ("MyTest", "0"), and note that the table prefix is modified. The mytest option is stored in the database.

The Code updatecache ("Settings") will be executed around 1160 lines to automatically cache the data in the Settingsnew array, and to implement the method interested friends can take a closer look at/include/cache.func.php How the file is implemented.

When the data is cached, there are mytest items in the $_dcache["settings" array in the/forumdata/cache/cache_settings.php file, and then we can do something with this option. The following code is around the 93rd line of the/include/common.inc.php file:

The code is as follows:
$cachelost = (@include discuz_root.) /forumdata/cache/cache_settings.php ")? "": "Settings";
@extract ($_dcache["Settings"]);
Through the above code, directly to the mytest configuration option to store the value of $mytest variables, we can directly judge $mytest to operate. Add the following code to the 17 lines of the index.php file:

The code is as follows:
if ($mytest) {
echo "Hello this is Test";
}

After running, the effect is as follows:


Figure 2

This has been successful for discuz! Forum added an option, the forum of course there are quite a few options, the basic idea is this, can be added according to the specific situation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.