Suppose you would like to have two FAQ modules. You might of course ask why on earth you would want such a complication in your PHP-Nuke site, but if you recall that PHP-Nuke lets you decide for each module individually whether to all visitors, only registered ones, or only administrators to view it, you will find out that two identical FAQ modules would be a simple way to have two FAQs, one only for administrators and one for all users.
We will now follow the steps outlined above for the purpose of duplicating the FAQ module:
We copy the whole directory modules/FAQ to modules/Admin_FAQ
We also copy:
admin/modules/adminfaq.php to admin/modules/adminfaq2.php,
admin/links/links.faq.php to admin/links/links.faq2.php and
admin/case/case.adminfaq.php to admin/case/case.adminfaq2.php.
Code inspection reveals that the only tables used by the FAQ module are faqAnswer and faqCategories.
The relevant part of nuke.sql that creates and populates faqAnswer and faqCategories is easily located. After we append a “2” at the table names and copy it to nuke2.sql, the latter will have the following content:
# # Table structure for table `nuke_faqAnswer2` # CREATE TABLE nuke_faqAnswer2 ( id tinyint(4) NOT NULL auto_increment, id_cat tinyint(4) NOT NULL default '0', question varchar(255) default ", answer text, PRIMARY KEY (id), KEY id (id), KEY id_cat (id_cat) ) TYPE=MyISAM; # # Dumping data for table `nuke_faqAnswer2` # # -------------------------------------------------------- # # Table structure for table `nuke_faqCategories2` # CREATE TABLE nuke_faqCategories2 ( id_cat tinyint(3) NOT NULL auto_increment, categories varchar(255) default NULL, flanguage varchar(30) NOT NULL default ", PRIMARY KEY (id_cat), KEY id_cat (id_cat) ) TYPE=MyISAM; # # Dumping data for table `nuke_faqCategories2` # # -------------------------------------------------------- |
We run the nuke2.sql file from the MySQL prompt::
mysql -u dbuname -p dbname < nuke2.sql |
This will create the nuke_faqAnswer2 and nuke_faqCategories2 tables in the database dbname (remember to replace dbuname and dbname with their real values from your config.php!). Since the FAQ module does not come with preset categories and answers, the tables are not populated with data.
We edit all files under modules/Admin-FAQ and also the administrative files admin/modules/adminfaq2.php, admin/links/links.faq2.php and admin/case/case.adminfaq2.php: we change all references to faqAnswer or faqCategories to faqAnswer2 and faqCategories2 respectively.
In admin/case/case.adminfaq.php we change
include ("admin/modules/adminfaq.php"); |
to
include ("admin/modules/adminfaq2.php"); |
Finally, we activate the Admin-FAQ module and specify that it can be viewed only by administrators.
Don't forget the "op"s! | |||
---|---|---|---|
If you want your duplicate module to perform slightly different functions than the original one, there is no way around to creating duplicate "op" functions to be called from the "switch($op)" part of the admin file. In our example, this would mean that we would change
in the admin/modules/adminfaq.php file, to:
and then program the new functionality into the new functions (the ones with the 2 suffix in their name). |