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
*/