Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add configuration options for Discuz forums

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to add configuration options to the Discuz forum, which is very detailed and has a certain reference value. Interested friends must finish reading it!

Discuz! The forum has many configuration options in the background, through which many functions can be achieved. In Discuz! In the process of secondary development of the forum, we also often add some configurations, and then carry out different operations according to the configuration. Next I will introduce how to use Discuz! Add configuration options to the forum.

Let's take Discuzations 6.0 as an example. First, let's take a look at Discuz! In the configuration interface of the forum backend, log in to the forum backend as an administrator, and select "basic Settings"-> "basic Settings". The following interface appears:

Figure 1

This page uses a frame. We right-click on the lower right page and select 'Properties'. In the pop-up window, we find that the URL of this page is'/ admincp.php?action=settings&do=basic', and the program used for this page is admincp.php. Let's analyze this file first.

Lines 172-290 of this file are 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')) | | ($allowbanip & & $action = = 'ipban')) {

$cpscript = 'members'

} elseif...

}

If ($cpscript) {

} elseif...

}

If ($cpscript) {

Require_once DISCUZ_ROOT.'./admin/'.$cpscript.'.inc.php'

}.

This program mainly assigns a value to $cpscript according to the $action variable, and then introduces the program files in the admin directory according to the value of $cpscript. If we look at the judgment of the $action value on the left side of line 179, we will find that the value of $cpscript is' settings', which means that the program file introduced on line 283 is' admin/settings.inc.php'.

Then open the settings.inc.php file, you will find that the content is very long ah, do not be frightened by this, carefully analyze it.

Line 14:

The code is as follows:

$operation = $operation? $operation: (! empty ($do)? $do:'')

Here we assign a value to $operation based on the $do value from GET, which in this case is' basic'.

Line 17:

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 out from the database and stored in the array $settings for the following calls.

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 form submission

……

}

The submitcheck function in the program is used to check whether a form is submitted, and if it is not submitted, it is displayed according to the previously processed $operation. Here the value of $operation 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')

Here you use a custom function showsetting, whose first parameter is the name of the configuration option, the second parameter is the name value of the input when the HTML is displayed, the third parameter is the value of the current configuration option, it is a value in the array $settings checked out from the database above, and the fourth parameter is the type of input. Let's add our own configuration option, mytest. 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 and find an extra option at the bottom of the page:

Is settings_mytest right?

But found that it is in English, we can modify the language pack. In line 450 of the templates/default/admincp.lang.php file, 'settings_closedreason_comment' = >' the message that appears when the forum is closed, add the following code:

The code is as follows:

'settings_mytest' = >' Test options:'

'settings_mytest_comment' = >' hints for test options'

Save it and then refresh it and you will be prompted in Chinese.

Now that the display on the interface has been processed, let's talk about how to deal with the data submitted by the form. In the else statement section corresponding to if (! submitcheck ('settingsubmit')) {} in the / admin/settings.inc.php file. In this part of the code, we first process the submitted data, and then put it all into the $settingsnew array, which is actually the data from POST to check. There is the following code on about 1140 lines of this file:

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 whether there is a corresponding option in the $settingsnew array, if there is a numeric option, float conversion, and then all REPLACE INTO to the data table settings, mytest option is we newly added, the data table does not have this option, I need to first execute the following SQL statement in the database: REPLACE INTO cdb_settings (variable, value) VALUES ('mytest',' 0'), pay attention to modify the table prefix. This mytest option will be stored in the database.

The code updatecache ('settings') will be executed around line 1160 to cache the data in the settingsnew array automatically. If you are interested in the implementation method, you can take a closer look at how the / include/cache.func.php file is implemented.

After the data is cached, there is a mytest entry in the $_ DCACHE ['settings'] array in the / forumdata/cache/cache_settings.php file, and then we can do something with this option. There is the following code around line 93 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'])

With the above code, the value of the mytest configuration option is directly stored in the $mytest variable, and we can directly determine the $mytest to operate. Add the following code to line 17 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 so far has been successful for Discuz! The forum added an option, of course, the forum also has considerable options, the basic ideas are like this, can be added according to the specific situation.

The above is all the content of the article "how to add configuration options in Discuz Forum". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report