actually they are simpler than you can expect.
the concept of having preloads is "Loading some functions prior to loading the module itself"
These functions can be load in some defined places in Core.
The most current defined places are:
/xoops255/class/database/databasefactory.php (1 hit)
Line 60: $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class));
/xoops255/class/smarty/xoops_plugins/function.xoInboxCount.php (1 hit)
Line 17: $xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler));
/xoops255/class/theme_blocks.php (1 hit)
Line 119: $xoopsPreload->triggerEvent('core.class.theme_blocks.retrieveBlocks', array(&$this, &$template, &$block_arr));
/xoops255/class/xoopsform/formdhtmltextarea.php (1 hit)
Line 202: $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code));
/xoops255/edituser.php (1 hit)
Line 22: $xoopsPreload->triggerEvent('core.edituser.start');
/xoops255/footer.php (2 hits)
Line 22: $xoopsPreload->triggerEvent('core.footer.start');
Line 72: $xoopsPreload->triggerEvent('core.footer.end');
/xoops255/header.php (5 hits)
Line 25: $xoopsPreload->triggerEvent('core.header.start');
Line 62: $xoopsPreload->triggerEvent('core.header.addmeta');
Line 91: $xoopsPreload->triggerEvent('core.header.checkcache');
Line 93: $xoopsPreload->triggerEvent('core.header.cacheend');
Line 109: $xoopsPreload->triggerEvent('core.header.end');
/xoops255/include/common.php (3 hits)
Line 51: $xoopsPreload->triggerEvent('core.include.common.start');
Line 167: $xoopsPreload->triggerEvent('core.include.common.language');
Line 337: $xoopsPreload->triggerEvent('core.include.common.end');
/xoops255/include/functions.php (1 hit)
Line 563: $xoopsPreload->triggerEvent('core.include.functions.redirectheader', array($url, $time, $message, $addredirect, $allowExternalLink));
/xoops255/index.php (1 hit)
Line 25: $xoopsPreload->triggerEvent('core.index.start');
/xoops255/lostpass.php (1 hit)
Line 22: $xoopsPreload->triggerEvent('core.lostpass.start');
/xoops255/modules/system/blocks/system_blocks.php (1 hit)
Line 185: $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', array(&$pm_handler));
/xoops255/modules/system/class/gui.php (1 hit)
Line 90: $xoopsPreload->triggerEvent('system.class.gui.header');
/xoops255/pmlite.php (1 hit)
Line 21: $xoopsPreload->triggerEvent('core.pmlite.start');
/xoops255/readpmsg.php (1 hit)
Line 21: $xoopsPreload->triggerEvent('core.readpmsg.start');
/xoops255/register.php (1 hit)
Line 27: $xoopsPreload->triggerEvent('core.register.start');
/xoops255/user.php (1 hit)
Line 27: $xoopsPreload->triggerEvent('core.user.start');
/xoops255/userinfo.php (1 hit)
Line 27: $xoopsPreload->triggerEvent('core.userinfo.start');
/xoops255/viewpmsg.php (1 hit)
Line 21: $xoopsPreload->triggerEvent('core.viewpmsg.start');
to use a defined preload in your module you just need to do this:
1- create YOUR_MODULE/preloads/core.php file
2- add the name of preload by removing all dots, add a "event" and uppercase of the first letters for all.
eg: core.footer.start => eventCoreFooterStart
// to log main part of modules
function eventCoreFooterStart($args)
{
include dirname(dirname(__FILE__)) . '/include/log.php';
}
You can define preloads in some places of Core without hardcoding.
one of the amazing places is defining a new xoops_smarty function for your module.
for an example please look at:
xoops255\class\smarty\xoops_plugins\function.xoInboxCount.php:
function smarty_function_xoInboxCount($params, &$smarty)
{
global $xoopsUser;
if (!isset($xoopsUser) || !is_object($xoopsUser)) {
return;
}
$time = time();
if (isset($_SESSION['xoops_inbox_count']) && @$_SESSION['xoops_inbox_count_expire'] > $time) {
$count = intval($_SESSION['xoops_inbox_count']);
} else {
$pm_handler =& xoops_gethandler('privmessage');
$xoopsPreload =& XoopsPreload::getInstance();
$xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler));
$criteria = new CriteriaCompo(new Criteria('read_msg', 0));
$criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
$count = intval($pm_handler->getCount($criteria));
$_SESSION['xoops_inbox_count'] = $count;
$_SESSION['xoops_inbox_count_expire'] = $time + 60;
}
if (!@empty( $params['assign'])) {
$smarty->assign( $params['assign'], $count );
} else {
echo $count;
}
}
?>
IMO the above is all you should know as a module developer.