How to duplicate the SmartSection Module for XOOPS CMS.
by Gabi SolomonA client gaved me a small task of creating 2 new sections for his website. The website is powered by the well-known CMS XOOPS. After looking at it i decided that the easy way out would be to duplicate one of the websites existing sections, and settled on the smart section. And because that gave a good run-a-round i thought i will post my solution on my blog, maybe others will benefit from it and save some time ( although others might think this is so obvious ).
First start by downloading SmartSection from http://smartfactory.ca/
Decide on a name for the new section. For this example we will consider GSD Section as the name.
Next we must do a few find & replaces in the files. To do that i used ReplaceEm wich you can download from http://www.orbit.org/replace/. This program let’s you do multiple find&replace on multiple files at once, so you’re time alocated to this task should decrease dramaticly. The replacement you must do are :
‘smartsection’ => ‘gsdsection’
‘SMARTSECTION’ => ‘GSDSECTION’
‘SmartSection’ => ‘GsdSection’
‘Smart Section’ => ‘Gsd Section’
‘SSECTION’ => ‘GSECTION’
‘Smartsection’ => ‘Gsdsection’
Now you must also replace the folder name to gsdsection, and also all the template files that have smartsection in there file name. For example smartsection.css will become gsdsection.css.
Also we must replace the names of the mysql tables. So we will open the file /sql/mysql.sql and replace all the of: smartsection_ with the name of your module. In my case I would replace it with gsdsection_.
Once you have completed these steps, upload the duplicated folder (now your cloned module) and install it though the XOOPS Admin panel.
[later_edit]
After completing all this steps i have found an even easyer way ![]()
I found an already made script to duplicate smart section ( a little bit too late for me , but who knows … maybe not for others ).
Make a file named clone.php and put in the root folder of you’re xoops powered website, also make sure there is a folder of the smartsection in the modules folder of the website.
Put the folowing code in the clone.php :
// ##########################################################
// Define your mapping here
// ##########################################################
$patterns = array(
// first one must be module directory name
'smartsection' => 'mysection',
'SMARTSECTION' => 'MYSECTION',
'SmartSection' => 'MySection',
'Smart Section' => 'My Section',
'SSECTION' => 'MSECTION',
'Smartsection' => 'Mysection'
);
$patKeys = array_keys($patterns);
$patValues = array_values($patterns);
// work around for PHP < 5.0.x
if(!function_exists('file_put_contents')) {
function file_put_contents($filename, $data, $file_append = false) {
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));
if(!$fp) {
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);
return;
}
fputs($fp, $data);
fclose($fp);
}
}
// recursive clonning script
function cloneFileFolder($path)
{
global $patKeys;
global $patValues;
$newPath = str_replace($patKeys[0], $patValues[0], $path);
if (is_dir($path))
{
// create new dir
mkdir($newPath);
// check all files in dir, and process it
if ($handle = opendir($path))
{
while ($file = readdir($handle))
{
if ($file != '.' && $file != '..')
{
cloneFileFolder("$path/$file");
}
}
closedir($handle);
}
}
else
{
if(preg_match('/(.jpg|.gif|.png|.zip)$/i', $path))
{
copy($path, $newPath);
}
else
{
// file, read it
$content = file_get_contents($path);
$content = str_replace($patKeys, $patValues, $content);
file_put_contents($newPath, $content);
}
}
}
cloneFileFolder('modules/news');
echo "Happy cloning...\n";
echo "check directory modules/" . $patterns['smartsection'] . " for cloned module \n";
echo "Consider modifying new module by editing language/english/modinfo.php and images/news_slogo.png manually (if you care)\n";
?>
Normaly change mysection with the desired name.
Cheers.
Awayting questions and comments

