I would like to second krobi's request, GIJOE, if you find the time, could you give us newbee-dev's a brief tutorial, on how to make modules duplicatable?

I really love this feature, and would like to implement it, with my own projects.
I love to write PHP code, but I don't love "how to" articles so much

The implementation of DUPLICATABLE V2...
- at first, you have to decide original "dirname"
- the "dirname" can't include character of 0-9
- the most important & essentially code is this:
$mydirname = basename( dirname( __FILE__ ) ) ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
- use $mydirname for physical&virtual paths
- use (your dirname).$mydirnumber for DB tables & templates
- the skelton of xoops_version.php (replace xhld to your "dirname")
if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
$mydirname = basename( dirname( __FILE__ ) ) ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
$modversion['image'] = "images/xhld{$mydirnumber}_slogo.gif";
$modversion['dirname'] = $mydirname;
// Sql file (must contain sql generated by phpMyAdmin or phpPgAdmin)
$modversion['sqlfile']['mysql'] = "sql/mysql{$mydirnumber}.sql";
// Tables created by sql file (without prefix!)
$modversion['tables'][0] = "xhld{$mydirnumber}";
$modversion['tables'][1] = "xhld{$mydirnumber}_cat";
...
// Blocks
$modversion['blocks'][1]['file'] = "...";
$modversion['blocks'][1]['name'] = ...;
$modversion['blocks'][1]['description'] = ...;
$modversion['blocks'][1]['show_func'] = ...;
$modversion['blocks'][1]['edit_func'] = ...;
$modversion['blocks'][1]['template'] = "xhld{$mydirnumber}_block_(...).html";
$modversion['blocks'][1]['options'] = "{$mydirname}|(the other options)";
// Templates
$modversion['templates'][1]['file'] = "xhld{$mydirnumber}_(...).html";
$modversion['templates'][1]['description'] = '';
$modversion['templates'][2]['file'] = "xhld{$mydirnumber}_(...).html";
$modversion['templates'][2]['description'] = '';
...
// Search
$modversion['hasSearch'] = 1;
$modversion['search']['file'] = "include/search.inc.php";
$modversion['search']['func'] = "xhld{$mydirnumber}_search";
// Notification
$modversion['hasNotification'] = 1;
$modversion['notification']['lookup_file'] = 'include/notification.inc.php';
$modversion['notification']['lookup_func'] = "xhld{$mydirnumber}_notify_iteminfo";
- prepare a number of "mysql*.sql"s in sql/ folder.
- contens of mysql.sql
CREATE TABLE xhld (
...
) TYPE=MyISAM;
CREATE TABLE xhld_cat (
...
) TYPE=MyISAM;
- contens of mysql0.sql
CREATE TABLE xhld0 (
...
) TYPE=MyISAM;
CREATE TABLE xhld0_cat (
...
) TYPE=MyISAM;
-prepare a number of template files in templates/ folder
-eg) xhld_index.html, xhld0_index.html, xhld1_index.html ...
-eg) blocks/xhld_block.html, blocks/xhld0_block.html, blocks/xhld1_block.html ...
-edit all of front-end php files like this:
require( '../../mainfile.php' ) ;
// for "Duplicatable"
$mydirname = basename( dirname( __FILE__ ) ) ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
(original part)
-edit all of back-end php files like this:
include_once( '../../../include/cp_header.php' ) ;
// for "Duplicatable"
$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) echo ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
(original part)
-modify all of php files querying to db
$xoopsDB->prefix("xhld")
$xoopsDB->prefix("xhld{$mydirnumber}")
$xoopsDB->prefix("xhld_cat")
$xoopsDB->prefix("xhld{$mydirnumber}_cat")
...
-sample skelton of search.inc.php
<?php
if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) die ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
eval( '
function xhld'.$mydirnumber.'_search( $keywords , $andor , $limit , $offset , $uid )
{
...
$xoopsDB->query( "...".$xoopsDB->prefix("xhld'.$mydirnumber.'")."..." ) ;
...
}
' ) ;
?>
notice: don't use the character of ' inside eval()- the way to modify notification.inc.php is almost same as search.inc.php
- sample skelton of blocks/*.php
<?php
if( ! defined( 'XHLD_BLOCK_FUNC_INCLUDED' ) ) {
define( 'XHLD_BLOCK_FUNC_INCLUDED' , 1 ) ;
function b_xhld_func_show( $options )
{
$mydirname = empty( $options[0] ) ? basename( dirname( dirname( __FILE__ ) ) ) : $options[0] ;
if( ! preg_match( '/^(\D+)(\d*)$/' , $mydirname , $regs ) ) die ( "invalid dirname: " . htmlspecialchars( $mydirname ) ) ;
$mydirnumber = $regs[2] === '' ? '' : intval( $regs[2] ) ;
(original code)
}
function b_xhld_func_edit( $options )
{
$mydirname = empty( $options[0] ) ? basename( dirname( dirname( __FILE__ ) ) ) : $options[0] ;
(original code)
$form .= "<input type='hidden' size='4' name='options[0]' value='$mydirname' />\n" ;
return $form ;
}
}
?>
-sample of language/(language)/admin.php
<?php
if( defined( 'FOR_XOOPS_LANG_CHECKER' ) || ! defined( 'XHLD_AM_LOADED' ) ) {
define( 'XHLD_AM_LOADED' , 1 ) ;
define("_AM_CONFIG","...");
....
....
}
?>
-sample of language/(language)/modinfo.php
<?php
if( defined( 'FOR_XOOPS_LANG_CHECKER' ) || ! defined( 'XHLD_MI_LOADED' ) ) {
define( 'XHLD_MI_LOADED' , 1 ) ;
define("_MI_CONFIG","...");
....
....
}
?>
- another language files are almost same as admin.php.
Don't forget that this article is just a sample.
There are many and difficult hurdles to implement DUPLICATABLE with working modules.
eg1) in myAlbum-P, a problem of the place of photo storing
eg2) in xhld, a problem of XoopsObject
eg3) in TinyD, a problem of sharing many files of SPAW or PEAR
*/
waw thanks for your sample,
so i will start to work on a news modul (based on news 1.2.1) with your duplicatable technic
If you try to make news duplicatable, refer the codes of xhld.
XoopsObject module has a difficult problem about naming the class.
hey gijoe
i have insert your code into the news modul, my actually status is:
i can install the modul, some admin option also works but not all. and the user site dont work

so i made a rar file, uploaded it to our webspace.
maybe you can take a look at the code.
GET IT HERE
I'm sorry that I can't help you.
I'm not interested with "news" at all.
And I'm very very busy.
my TODO is...
modifying piCal, myAlbum-P, protector, TinyD...
and creating two revolutionary modules in my mind.
You can see that there are no time to touch "news" module.
I have to say that it is not so easy to implement "DUPLICATABLE".
Only well-skilled programmers can do that.
oh thats bad

maybe i can get it to run, when not i will simple make a clone
Quote:
I love to write PHP code, but I don't love "how to" articles so much
I understand

, so many thanks for your effort, it is really appreciated! I will try this out soon.
One example of duplicatable module:
Translation by google
XT-ChannelYou can generator module dinamics on-line

Direct link:
Clone on line XT-ChannelCredtis for Wf-Channel is correct