xoops forums

Dylian

Friend of XOOPS
Posted on: 2009/12/22 17:04
Dylian
Dylian (Show more)
Friend of XOOPS
Posts: 237
Since: 2007/7/21
#1

All available preloads in XOOPS 2.4.2

I'm creating a new module (xHacks) to implement XOOPS hacks from within the administration area. And to do this i use preloads, but i couldn't find a list of all available preloads so i created one. These are all the preloads i could find in XOOPS 2.4.2 CORE: class\database\databasefactory.php : $xoopsPreload->triggerEvent('core.class.database.databasefactory.connection', array(&$class)); Before database connection class\smarty\xoops_plugins\function.xoInboxCount.php $xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler)); Before counting the number of new pm's class\theme_blocks.php $xoopsPreload->triggerEvent('core.class.theme_blocks.retrieveBlocks', array(&$this, &$template, &$block_arr)); Before retrieving the blocks class\xoopsform\formdhtmltextarea.php $xoopsPreload->triggerEvent('core.class.xoopsform.formdhtmltextarea.codeicon', array(&$code)); After setting the button toolbar of the DTHML text area edituser.php $xoopsPreload->triggerEvent('core.edituser.start'); At the beginning of edituser.php footer.php $xoopsPreload->triggerEvent('core.footer.start'); At the beginning of footer.php $xoopsPreload->triggerEvent('core.footer.end'); At the end of footer.php header.php $xoopsPreload->triggerEvent('core.header.start'); At the beginning of header.php $xoopsPreload->triggerEvent('core.header.addmeta'); At the loading of the META data $xoopsPreload->triggerEvent('core.header.end'); At the end of header.php include\common.php $xoopsPreload->triggerEvent('core.include.common.start'); At the beginning of common.php $xoopsPreload->triggerEvent('core.include.common.language'); Before loading the language files $xoopsPreload->triggerEvent('core.include.common.end'); At the end of common.php include\functions.php $xoopsPreload->triggerEvent('core.include.functions.redirectheader', array($url, $time, $message, $addredirect, $allowExternalLink)); At the beginning of the redirectheader() function. index.php $xoopsPreload->triggerEvent('core.index.start'); At the beginning of index.php. lostpass.php $xoopsPreload->triggerEvent('core.lostpass.start'); At the beginning of lostpass.php. pmlite.php $xoopsPreload->triggerEvent('core.pmlite.start'); At the beginning of pmlite.php readpmsg.php $xoopsPreload->triggerEvent('core.readpmsg.start'); At the beginning of readpmsg.php register.php $xoopsPreload->triggerEvent('core.register.start'); At the beginning of register.php user.php $xoopsPreload->triggerEvent('core.user.start'); At the beginning of user.php userinfo.php $xoopsPreload->triggerEvent('core.userinfo.start'); At the beginning of userinfo.php viewpmsg.php $xoopsPreload->triggerEvent('core.viewpmsg.start'); At the beginning of viewpmsg.php SYSTEM MODULE: modules\system\admin\users\main.php $xoopsPreload->triggerEvent('system.admin.users.main.start'); At the beginning of main.php. modules\system\blocks\system_blocks.php $xoopsPreload->triggerEvent('system.blocks.system_blocks.usershow', array(&$pm_handler)); At the loading of the XOOPS "User Menu" block. modules\system\class\gui.php $xoopsPreload->triggerEvent('system.class.gui.header'); At the end of the header() function. But i don't know if these are all available preloads in XOOPS 2.4.2 so if you know some more please post. After i created this list i started working out the actual preload files. So for all module developers that want to use preloads but don't know how to use them... This could come in handy: modules/YourModule/preloads/core.php: (All core preloads)
<?php
###############################################################################
##   Copyright (C) 2009  Dylian Melgert                                      ##
##                                                                           ##
##      This program is free software: you can redistribute it and/or modify ##
##      it under the terms of the GNU General Public License as published by ##
##      the Free Software Foundation, either version 3 of the License, or    ##
##      (at your option) any later version.                                  ##
##                                                                           ##
##      This program is distributed in the hope that it will be useful,      ##
##      but WITHOUT ANY WARRANTY; without even the implied warranty of       ##
##      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        ##
##      GNU General Public License for more details.                         ##
##                                                                           ##
##      You should have received a copy of the GNU General Public License    ##
##      along with this program.  If not, see <http://www.gnu.org/licenses/>.##
###############################################################################

defined('XOOPS_ROOT_PATH') or die('Restricted access');

class 
YourModuleCorePreload extends XoopsPreloadItem{

    function 
eventCoreClassDatabaseDatabasefactoryConnection($args){
        
// $args[0] Contains the classname of the Database connection class
        
        // Something to do at the event...
    
}
    
    function 
eventCoreClassSmartyXoops_pluginsXoinboxcount($args){
        
// $args[0] Contains the pm handler
        
        // Something to do at the event...
    
}
    
    function 
eventCoreClassTheme_blocksRetrieveBlocks($args){
        
// $args[0] Contains the current object
        // $args[1] Contains XoopsTpl() object
        // $args[2] Contains an array of XoopsBlock() objects
        
        // Something to do at the event...
    
}
    
    function 
eventCoreClassXoopsformFormdhtmltextareaCodeicon($args){
        
// $args[0] Contains the code variable (DHTML icon bar)
        
        // Something to do at the event...
    
}
    
    function 
eventCoreEdituserStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreFooterStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreFooterEnd(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreHeaderStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreHeaderAddmeta(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreHeaderEnd(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreIncludeCommonStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreIncludeCommonLanguage(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreIncludeCommonEnd(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreIncludeFunctionsRedirectheader($args){
        
// $args[0] Contains the url variable (The URL to redirect to)
        // $args[1] Contains the time variable (How long to wait before redirecting)
        // $args[2] Contains the addredirect variable (If you want to add [[?/&]]xoops_redirect=[[current_url]] to the redirect url.)
        // $args[3] Contains the message variable (The message to show to the user)
        // $args[4] Contains the allowExternalLink variable (If you want to allow redirects to external url's)
        
        // Something to do at the event...
    
}
    
    function 
eventCoreIndexStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreLostpassStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCorePmliteStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreReadpmsgStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreRegisterStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreUserStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreUserinfoStart(){
        
// Something to do at the event...
    
}
    
    function 
eventCoreViewpmsgStart(){
        
// Something to do at the event...
    
}
    
}
?>
modules/YourModule/preloads/systemModule.php: (All sytem module preloads)
<?php
###############################################################################
##   Copyright (C) 2009  Dylian Melgert                                      ##
##                                                                           ##
##      This program is free software: you can redistribute it and/or modify ##
##      it under the terms of the GNU General Public License as published by ##
##      the Free Software Foundation, either version 3 of the License, or    ##
##      (at your option) any later version.                                  ##
##                                                                           ##
##      This program is distributed in the hope that it will be useful,      ##
##      but WITHOUT ANY WARRANTY; without even the implied warranty of       ##
##      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        ##
##      GNU General Public License for more details.                         ##
##                                                                           ##
##      You should have received a copy of the GNU General Public License    ##
##      along with this program.  If not, see <http://www.gnu.org/licenses/>.##
###############################################################################

defined('XOOPS_ROOT_PATH') or die('Restricted access');

class 
YourModuleSystemModulePreload extends XoopsPreloadItem{

    function 
eventSystemAdminUsersMainStart(){
        
// Something to do at the event...
    
}
    
    function 
eventSystemBlocksSystem_blocksUsershow($args){
        
// $args[0] Contains the pm handler
        
        // Something to do at the event...
    
}
    
    function 
eventSystemClassGuiHeader(){
        
// Something to do at the event...
    
}
    
}
?>
I hope this helped and that someone will check whether the information is correct. Greets Dylian.

trabis

Core Developer
Posted on: 2009/12/22 19:54
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#2

Re: All available preloads in XOOPS 2.4.2

Thanks Dylian, this is useful info!
Just have to say that it does not matter the name of the file, the important is that it matches the class name.

modules/YourModule/preloads/systemModule.php
goes with
class YourModuleSystemModulePreload
(there is a typo in your code)

modules/YourModule/preloads/system.php
goes with
class YourModuleSystemPreload

And it does not matter if you have core preloads along with system preloads in the same file, this is just for organization.

One more thing, on XOOPS 2.4.3 the preloads will be executed only for installed and active modules. There will be no need for the preload to do that check.

Many thanks!

Dylian

Friend of XOOPS
Posted on: 2009/12/22 20:21
Dylian
Dylian (Show more)
Friend of XOOPS
Posts: 237
Since: 2007/7/21
#3

Re: All available preloads in XOOPS 2.4.2

Could one of the moderators put a space after class in the second code block? [edit]Whoops, didn't see it was possible to edit your post after a new post has been added...[/edit]

And thanks for the reaction trabis, do you know if these are all the available preloads in XOOPS 2.4.2?

And could new preloads be notified in the changelog or in an other way?

Greets Dylian.

sailjapan

Moderator
Posted on: 2009/12/23 4:46
sailjapan
sailjapan (Show more)
Moderator
Posts: 1672
Since: 2005/11/16
#4

Re: All available preloads in XOOPS 2.4.2

This should definitely be added to the documentation area.

phppp

XOOPS Contributor
Posted on: 2009/12/23 6:04
phppp
phppp (Show more)
XOOPS Contributor
Posts: 2857
Since: 2004/1/25
#5

Re: All available preloads in XOOPS 2.4.2

Please be careful with 'xoopsPreload', it is not officially supported in XOOPS 3 although there might be some compatible solutions.

Before the new API list for X3 is released, please build your new functionality at module level, not rely too much on new classes or APIs introduced in after X2.3.

But anyway, all modules for 2.4+ will be supported with some compromising way.