Discuz plug-in core function Hookscript analysis.

Source: Internet
Author: User

function Hookscript ($script, $hscript, $type = ' Funcs ', $param = Array (), $func = ', $scriptextra = ') {
# This function is the function of the Fang heart of the plugin tick. is extremely important for plug-in development. We analyze each.
# Hookscript ($script, $hscript, $type = ' Funcs ', $param = Array (), $func = ", $scriptextra =")
# Hookscript ($script, $hscript, $type = ' Funcs ', $param = Array (), $func = ", $scriptextra =")
# Hookscript (method name, type (such as global, theme, move, etc...), call type, parameter, can hook up a pair of methods, special parameters);
Global $_g; By introducing the core array, the default is a total of 4KB large arrays,
Static $pluginclasses; Static cargo plug-in class array to calculate whether the execution file has been introduced.
if ($hscript = = ' Home ') {//When $hscript equals home, do some variable conversion, the special parameter is valid here.
if ($script = = ' space ') {
$scriptextra =! $scriptextra? $_get[' do ': $scriptextra;
$script = ' space '. (!empty ($scriptextra)? ' _ '. $scriptextra: ');
} elseif ($script = = ' SPACECP ') {
$scriptextra =! $scriptextra? $_get[' AC ': $scriptextra;
$script. =!empty ($scriptextra)? ' _ '. $scriptextra: ';
}
}

# Determine if the plugin is defined or open. otherwise quit.
if (!isset ($_g[' setting '][hooktype][$hscript] [$script] [$type])) {
Return
}
# Determine if the plugin has a cache, and if not, exit.
if (!isset ($_g[' cache ' [' plugin '])) {
Loadcache (' plugin ');
}

# Loop out the module array, the module array contains the file path.
foreach (array) $_g[' setting '][hooktype][$hscript [$script] [' module '] as $identifier = = $include) {
Pluginrunlist here detects if the method is disabled, or skips it once.
if ($_g[' pluginrunlist ') &&!in_array ($identifier, $_g[' pluginrunlist ']) {
Continue
}
The right to judge.
$hooksadminid [$identifier] =!$_g[' setting '][hooktype][$hscript] [$script] [' Adminid '] [$identifier] | | ($_g[' setting '][hooktype][$hscript] [$script] [' Adminid '] [$identifier] && $_g[' Adminid '] > 0 && $_g [' Setting '] [' Hookscript '] [$hscript] [$script] [' Adminid '] [$identifier] >= $_g[' Adminid ']);
if ($hooksadminid [$identifier]) {////The file will be introduced only if the permission is passed. Personally think the $pluginclasses array should be used.
@include_once discuz_root. " /source/plugin/'. $include. Class.php ';
}
}

# The set of judging methods is an array, (is is_array necessary to suppress errors with @?)
if (@is_array ($_g[' setting '][hooktype][$hscript [$script] [$type])) {
$_g[' inhookscript ') = true; Can only indicate that the call was successful.
The method that handles additional calls is incremented so that it can be used in loops.
$funcs =! $func? $_g[' setting '][hooktype][$hscript] [$script] [$type]: Array ($func = $_g[' setting '][hooktype][$hscript] [$script] [$type] [$func]);
Loop through all the methods. multidimensional arrays, taking into account that a type of hook may have multiple implementations.
foreach ($funcs as $hookkey = = $hookfuncs) {
foreach ($hookfuncs as $hookfunc) {
$hookfunc [0] can also be understood as the name of the class for the type.
$hookfunc [1] for the method of execution
if ($hooksadminid [$hookfunc [0]]) {
# The name of the class needs to be reorganized here.
$classkey = (Hooktype! = ' hookscriptmobile '?) ': ' Mobile '). ' Plugin_ '. ($hookfunc [0]. ($hscript! = ' global '? ' _ '. $hscript: '));

# exit if the class is not loaded. The false parameter is to not check for ingestion.
if (!class_exists ($classkey, false)) {
Continue
}
# If you don't instantiate it, instantiate it once.
if (!isset ($pluginclasses [$classkey])) {
$pluginclasses [$classkey] = new $classkey;
}
# Judgment $hookfunc[1] method does not exist in the instance. Just quit.
if (!method_exists ($pluginclasses [$classkey], $hookfunc [1])) {
Continue
}
# then call the $hookfunc[1] method, and implant the method.
$return = $pluginclasses [$classkey]-> $hookfunc [1] ($param);
$param = Var_export ($param, true);
echo "{$classkey}-> $hookfunc [1] ($param) <br/>"; These two lines can be printed specifically.

# The judgment type has a feature and exists in the Pluginhooks array, and then exits.
if (substr ($hookkey, -7) = = ' _extend ' &&!empty ($_g[' setting ' [' pluginhooks '] [$hookkey])) {
Continue
}

# Enter when the return value is evaluated as an array.
if (Is_array ($return)) {
# $hookkey Determine if there is a plug-in hook. And if the array. It then loops, releasing the return value to a different assignment.
if (!isset ($_g[' setting '] [' pluginhooks '] [$hookkey]) | | Is_array ($_g[' setting ' [' pluginhooks '] [$hookkey])) {
foreach ($return as $k = = $v) {
$_g[' Setting ' [' pluginhooks '] [$hookkey] [$k]. = $v;
}
} else {
foreach ($return as $k = = $v) {
$_g[' Setting ' [' pluginhooks '] [$hookkey] [$k] = $v;
}
}
} else {
#假如返回值不是数组, the return value is released in a different way.
if (!is_array ($_g[' setting ' [' pluginhooks '] [$hookkey])) {
$_g[' Setting ' [' pluginhooks '] [$hookkey]. = $return;
} else {
foreach ($_g[' setting ' [' pluginhooks '] [$hookkey] as $k and $v) {
$_g[' Setting ' [' pluginhooks '] [$hookkey] [$k]. = $return;
}
}
}
}
}
}
}
# What does it mean to change a variable, which defines true above, which defines false here, is the calculation process complete?
$_g[' inhookscript ' = false;
}

Discuz plug-in core function Hookscript analysis.

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.