SmartFAQ is developed by The SmartFactory (https://www.smartfactory.ca), a division of InBox Solutions (https://www.inboxsolutions.net)

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.


The comments are owned by the author. We aren't responsible for their content.
user

 Perl script for cloning WF-Channel


You can details about, and a download of, a Perl script that clones WF-Channel at the link below. WF-Channel is a good module for adding regular HTML pages to a site.

https://xoops.org/modules/newbb/viewtopic.php?topic_id=26041

--Julian

 
user

 Further help please.....


Hi - thanks for the instructions on cloning modules above. I followed them exactly and have cloned the News module (calling it News01) and have successfully installed it. I am able to create articles etc in admin mode, but these do not appear on the home page for the new module, or in the block I created to put on the top page. I don't know if it is related, but in PHP debug mode, I get the following messages when opening up the submit form:

Quote:

Notice [PHP]: Undefined variable: published in file modules/news01/admin/storyform.inc.php line 110
Notice [PHP]: Undefined variable: expired in file modules/news01/admin/storyform.inc.php line 229


Also, I don't know if it is relevant, but there seems to be some repetition in parts 8. and 9. of the above advice (the first two lines of each section are the same) - is there something else missing?

Can you help?

Thanks
MM

 
user

 Re: Further help please.....


I am sorry but I cannot understand the instructions. Does anyone have a better tutorial on how to clone a module, cause this was written in really bad english and I am having a hard time following it.

I can't beleive that this is an official faq! wow

 
user

 Re: Further help please.....


i could follow it easy enough.. but please, it's written by a member not by the XOOPS team, at least give that respect.. the original is in french language i believe, so unless you speak french i think whoever translated it did a good job.

official or not, the faq is just that, it isn't a means to officially endorsed questions & answers, but a collection of questions and answers provided on the various support sites forums collected over the years.

in essence what it's saying is to clone a mod you need to change all references to the directory and filenames..

eg if you want to clone news module then change all references to news in all the files, to news01 or whatever you decide to name it as..then rename the folder to news02 remember to use exact same case if it's in lowercase then use lowercase, uppercase then choose uppercase..

you will also have to change physical filenames, especially the templates where they say news_block..... change to news01_block and so on..

if you were cloning newbb then you'd change all references for newbb in the files to newbb2 or whatever name you want..

sometimes it's a quick and easy job, but sometimes it can take a while..

just remember do the testing on a test site and NOT a live production site.

 
user

 Re: Further help please.....


Sorry, but for the life of me I cannot decipher this, maybe its cause I also do not speak PHP. I figured out a work around on another module so I no longer need this.

 
user

 Re: Further help please.....


Very useful FAQ... i just used it to make dms duplicable...

Thanks a lot
PeterPan

 
user

 REVOLUTION: clone all xoops modules, and replace the credits - Re: Php script for cloning modules


Quote:

In andament ( News 1.3 )

The revolution in construction and nice sites


The next step of FoxTotal Webhosting is make a module to clone and remove the credits of all XOOPS Modules. Sorry, developers. Now the credits of you module will be "Giba (first) and topete (that I dont know if know what giba is doing)"

 
user

 Re: REVOLUTION: clone all xoops modules, and replace the ...


I'm not saying this tutorial is bad, but I find it really difficult to understand, especially as I'm quite new to XOOPS. I can follow instructions, but this English, or should I say Frenglish, is too much for me.


Does anyone know of an easier to follow tutorial?
All I want to do is clone MyDownloads.

 
user

 Re: REVOLUTION: clone all xoops modules, and replace the ...


try wf-downloads, it's more advanced than mydownloads and probably does what u are trying to achieve by cloning..

 
user

 Suggested translation (corrected original)


Hi, I came across this article as I was looking for a way to clone one of my modules, and seeing the complaints concerning the translation, as I am a native speaker of both English and French, I thought I'd offer this correction of the original text (in case it can be of any use to anyone).
I hope it stays true to the original's sense, being rather new to XOOPS as well

==================================================
Mod note:

Thank you - this has now replaced the text in the FAQ for the benefit of all. You effort is greatly appreciated

 
user

 English version corrected.


The English Translation is now the text - thanks to Madgull.

 
user

 works?


does anyone tryed it and get thing work without any trouble? news 1.53

 
user

 wow this works!


Thank you very much for this tutorial! I had my doubts searching/replacing so many different variable names but at the end if worked just fine! I used regexxer, free search-replace tool for linux, to work on multiple file. This took a lil bit of time, but at the end very worth it (also the client is paying per hour so :[] )

Thanks again,

oh and the module I clone / duplicate is xdirectory

 


Login

Who's Online

179 user(s) are online (1 user(s) are browsing XOOPS FAQ)


Members: 0


Guests: 179


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Did you know ?

Which folder to upload after unzipping a theme file?

Random question

What is FTP?