Titre du sujet : Re: A votre avis ? Trop de Bug !!! Mauvaise utilisation ??? par Kris sur 27/06/2008 22:59:56
Citation : Burning a écrit: Clôner News ?... je crois que même son auteur n'a pas tenté l'aventure
grrrrrrrr !! j'ai laisser un bout de code pour cloner facilement news
@++
code de ce genre :
<?php
/*
Usage:
Copy clone_news.php in <xoops_root>
Change current working directory to <xoops_root>
Update mappings as per new modulename.
php -q clone_news.php
*/
// ##########################################################
// Define your mapping here
// ##########################################################
$patterns = array(
// first one must be module directory name
'news' => 'memo',
'NEWS' => 'memo',
'News' => 'Memo',
'stories' => 'memo_stories',
'topics' => 'memo_topics',
'getmoduleoption' => 'memogetmoduleoption',
'MygetItemIds' => 'memoMygetItemIds',
'CreateSiteNavBar' => 'memoCreateSiteNavBar',
'updateCache' => 'memoupdateCache',
'TableExists' => 'memoTableExists',
'FieldExists' => 'memoFieldExists',
'AddField' => 'memoAddField',
'is_admin_group' => 'memois_admin_group',
'make_infotips' => 'memomake_infotips',
);
$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['news'] . " for cloned module n";
echo "Consider modifying new module by editing language/english/modinfo.php and images/" . $patterns['news'] . "_slogo.png manually (if you care)n";
?>
|