Quote:
zyspec wrote:
The 'eval' method is much cleaner than SmartClone but given the potential security risks of 'eval' I think we're better of recommending SmartClone - thus I've removed 'eval' from all the modules I've been working on.
What security risks do you mean?
I agree that eval is better than SmartClone way (replacing all instances)
But regarding eval we should note:
- Eval should be used when there is no way. eg: here in the core 2.5.6 all Oninstall/Onupdate and OnUninstall are hard-coded.
so we can use eval like this:
in include/module.php for manipulating xoops_module_pre_install_{$dirname} function we can use this:
 eval( ' function xoops_module_pre_install_'.$dirname.'( $module ) { return onpreinstall_base( $module , "'.$dirname.'" ) ; } ' ) ; 
 
function onpreinstall_base( $module , $dirname ) 
{ 
    // TABLES (loading mysql.sql and change all $dirname) 
    // CLASSES  
    // FUNCTIONS  
}  
What do you think?
===================================
In 2.6 we have better functionality. 
In 2.6 all install/update/uninstall functions has been turned to a preload but we 
need more regarding clone issue.(So 2.6 is a step forward!!!)
In 2.6 still 
pre functions in Oninstall/Onupdate and OnUninstall events are hard-coded.
I think in 2.6 we should turn SmartClone into a 
plugin so pre install should be turned to a preload function like this:
 In XOOPS26/modules/system/class/module.php:
 "onModulePreInstall" event must be triggered before module installation. (before sql file runs)
 so around line 173, I suggest adding following right before 
the legacy (2.5.6 way) onInstall script: 
 // START irmtfan to add a pre install preload event trigger 
 XoopsPreload::getInstance()->triggerEvent('onModulePreInstall', array(&$module, &$this)); 
 // END irmtfan to add a pre install preload event trigger 
 $install_script = $module->getInfo('onInstall'); // irmtfan - remained for legacy modules  
 Then we just need a Clone module(now call it extension!!!) and plugin.
 In Clone module (or you can name it extenstion) we will have this in Xoops26/modules/clone/preloads/core.php 
 class CloneCorePreload extends XoopsPreloadItem 
{ 
    // To do anything before install the module 
    static function eventOnModulePreInstall($args) 
    { 
        $module = $args[0]; 
        if ($plugin = Xoops_Module_Plugin::getPlugin($module->getVar('dirname'), 'clone', true)) { 
            Clone::getInstance()->createClone($module); 
        }    
    } 
}  
I think in createClone function it should change all instances of dirname ??? (but it can be customized in any module plugin.)
any module want to be clonable should have a plugin like this:
in modules/MODULE/class/plugin/clone.php
 class {$Moduledirname}ClonePlugin extends Xoops_Module_Plugin_Abstract implements ClonePluginInterface 
{ 
    public function clonable() 
    { 
        return true; 
    } 
    public function customClone() 
    { 
        $custom = array(); 
        $i=0; 
        $custom[$i]["key"] = "BLABLA"; 
        $custom[$i]["replace"] = "REPLACE_CONSTANT"; 
         
        return $custom;         
    } 
}