How do I clone a module?
Author: thecat (Claude)
Author's URL: http://thecat.ouvaton.org/
Original Article: The cloning of a module
[b]Article: Corrected English version by Madgull. Thankyou!
This guide is written for the users who want to install the same module twice. It will be necessary for them to clone the original module in order to be able to install it twice.
1) Preliminary
The cloning of a module is not an extremely complicated operation, but can appear tiresome.
The difficulty will be very variable from one module to another:
- certain modules will be more difficult to clone, in particular if they do not respect coding conventions, are not homogeneous in this coding, do not use the xoops functions for access to the database, etc. It is not certain that they are worth being cloned!
- other modules, well-coded, will be rather easy to clone.
It’s better to have a good editor allowing to make the replacements on a whole directory: the risk of error is more significant, but in the event of success, it is definitely faster. Make these replacements step by step and activate the option of respect of (upper/lower) case.
If you choose this solution, think of the contents and the order of your replacements, in order not to cumulate them (example: ' news' transformed into ' news0202 ' instead of ' news02 ').
This tutorial explains the cloning procedure while being based on xoops’ news module.
In theory all the modifications are described, omitting those which one could to believe necessary, but which are not!
Now it's up to you to adapt it to your module!
Wait until you have finished before installing and testing your clone.
2) The directory
* Copy/paste the directory of the module and to rename it to news02
* in xoops_version change the value of the ' dirname':
$$modversion['dirname ' ] = "news02";
* find and replace the references to the directory in all the files:
replace /modules/news/ by /modules/news02/
NB: For certain modules systematically using $$xoopsModule->getvar('dirname ') this last operation will not be necessary.
3) Tables
* publish the mysql.sql file from the sql directory and rename the tables for each sql command:
CREATE COUNTS STORIES02 (
CREATE COUNTS TOPICS02 (
INSERT INTO TOPICS02
* in xoops_version modify the references to the tables:
$$modversion['sqlfile']['mysql ' ] = "sql/mysql.sql";
$$modversion['tables'][0 ] = "stories02";
$$modversion['tables'][1 ] = "topics02";
* find and replace the references to the tables in all the files.
If you make a total replacement, do it with prefix('nameofthetable') rather than the name of the table alone; you would be likely to unnecessarily have to change values of variables which would bear the same name.
In this case, search several times: with simple and doubles quotes, with and without space:
replace prefix(' stories ') , prefix("stories") , prefix(' stories') ... by prefix(' stories02 ')
replace prefix(' topics ') , prefix("topics") , prefix(' topics') ... by prefix(' topics02 ')
NB: certain modules have a include\read_config.php file (or equivalent) in which the names of the tables are assigned with variables.
In this case, only this file needs to be modified.
4) Language definitions (modinfo.php)
You will have to rename all the language definitions of the modinfo.php file, to especially prevent that they be declared 2 times and generate of Warning in php debug mode.
In theory, the other languages files do not need to be modified, but you can do it for consistency.
Not very easy to describe a method, all will depend on the module.
If all the variables are prefixed (ex) _ MI_NEWS _ make a total replacement of _ MI_NEWS _ by _ MI_NEWS02 _
The same goes if they all are prefixed _ SEMI _ make a total replacement of _ SEMI _ by _ MI_NEWS02 _ for example.
If it is mixed one, be careful not to find yourself with _ MI_NEWS02_NEWS02 _ for example.
NB: if you do not carry out this part entirely, at the end of the cloning, install and launch the module in php debug mode: correct the defines generating a warning.
5) Search function
* in xoops_version only modify the name of the function
$$modversion['search']['func ' ] = "news02_search";
* publish the include\search.inc.php file and modify the name of the function
function news02_search($queryarray, $$andor, $$limit, $$offset, $$userid)
6) Blocks
* in xoops_version modify for each block the name of the show and edit functions.
$$modversion['blocks'][3]['show_func ' ] = "b_news02_top_show";
$$modversion['blocks'][3]['edit_func ' ] = "b_news02_top_edit";
* publish each file of the directory blocks referred by $$modversion['blocks'][]['file ' ] = and modify the name of the functions.
For example with the news_top.php file
function b_news02_top_show($options) {
function b_news02_top_edit($options) {
* Nonessential, but preferable, also change the names of the files in xoops_version, without forgetting to rename those in the blocks directory correctly
$$modversion['blocks'][3]['file ' ] = "news02_block_top.html";
7) Comments
* in xoops_version modify the name of the approve and update functions:
$$modversion['comments']['callbackFile ' ] = ' include/comment_functions.php ';
$$modversion['comments']['callback']['approve ' ] = ' news02_com_approve ';
$$modversion['comments']['callback']['update ' ] = ' news02_com_update ';
8) Notification
* in xoops_version modify the name of the look_up function:
$$modversion['notification']['lookup_func ' ] = ' news02_notify_iteminfo ';
9) Templates
* in xoops_version modify the name of the look_up function:
$$modversion['notification']['lookup_func ' ] = ' news02_notify_iteminfo ';
* Nonessential, but preferable, also change the names of the files in xoops_version, without forgetting to rename those in the templates directory correctly
$$modversion['templates'][1]['file ' ] = "news02_archive.html";
10) The logo
* It is not useless to modify the logo so it can be found more easily in the modules’ administration.
Once modified, think of renaming it and of changing the name indicated in xoops_version.
$$modversion['image ' ] = "images/news02_slogo.png";
11) To finish
Go in the modules’ administration: your clone should appear without error message. If it is the case, useless to go further!
Install your clone. If you have error messages at the installation, note them for correction.
Launch your clone. Activate the php debug mode to correct the errors.
Test all the configurations of blocks and functionalities (search, comments, notification).
These tests must be carried out in both scenarios:
- with the original version installed, to detect conflicts or interactions
- without the original version installed (removed, or temporarily famous repertory) to check that your clone is autonomous, and that certain files do not point on those of origin.
12) Current Problems
- Check that the data of the original are not posted in your clone, or that the insertion of data of the clone is not done in the original. You would have in this case forgotten to rename certain references to the tables.
- Fatal error: cannot redeclare... This case was encountered with WFSection at the time of the access to userinfo: the original and its clone each do an ' include' of groupaccess.php, and the functions of this file bearing the same name, Php refuses to redeclare it.
It is possible, either to make the clone point to the original groupacces.php file, or to rename all the functions of this file, as well as the calls to these functions. This second solution is preferable, because it makes your clone autonomous, and avoids a problem in the event of uninstallation and suppression of the original.
This Q&A was found on XOOPS Web Application System : https://xoops.org/modules/smartfaq/faq.php?faqid=274