1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
|
5
|
|
|
Usage: |
6
|
|
|
|
7
|
|
|
Copy clone.php in <xoops_root> |
8
|
|
|
Change current working directory to <xoops_root> |
9
|
|
|
Update mappings as per new modulename. |
10
|
|
|
|
11
|
|
|
php -q clone.php |
12
|
|
|
|
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
// ########################################################## |
16
|
|
|
// Define your mapping here |
17
|
|
|
// ########################################################## |
18
|
|
|
$patterns = array( |
19
|
|
|
// first one must be module directory name |
20
|
|
|
'smartpartner' => 'smartclient', |
21
|
|
|
'partner' => 'client', |
22
|
|
|
'SMARTPARTNER' => 'SMARTCLIENT', |
23
|
|
|
'SmartPartner' => 'SmartClient', |
24
|
|
|
'Smart Partner' => 'Smart Client', |
25
|
|
|
'SPARTNER' => 'SCLIENT', |
26
|
|
|
'Smartpartner' => 'Smartclient', |
27
|
|
|
'Partner' => 'Client', |
28
|
|
|
'Partenaire' => 'Client', |
29
|
|
|
'partenaire' => 'client' |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$patKeys = array_keys($patterns); |
33
|
|
|
$patValues = array_values($patterns); |
34
|
|
|
|
35
|
|
|
// work around for PHP < 5.0.x |
36
|
|
|
if (!function_exists('file_put_contents')) { |
37
|
|
|
/** |
38
|
|
|
* @param $filename |
39
|
|
|
* @param $data |
40
|
|
|
* @param bool $file_append |
41
|
|
|
*/ |
42
|
|
|
function file_put_contents($filename, $data, $file_append = false) |
43
|
|
|
{ |
44
|
|
|
$fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); |
45
|
|
|
if (!$fp) { |
46
|
|
|
trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); |
47
|
|
|
|
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
fwrite($fp, $data); |
51
|
|
|
fclose($fp); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// recursive clonning script |
56
|
|
|
/** |
57
|
|
|
* @param $path |
58
|
|
|
* @throws |
59
|
|
|
*/ |
60
|
|
|
function cloneFileFolder($path) |
61
|
|
|
{ |
62
|
|
|
global $patKeys; |
63
|
|
|
global $patValues; |
64
|
|
|
|
65
|
|
|
$newPath = str_replace($patKeys[0], $patValues[0], $path); |
66
|
|
|
$newPath = str_replace($patKeys[1], $patValues[1], $path); |
67
|
|
|
|
68
|
|
|
if (is_dir($path)) { |
69
|
|
|
// create new dir |
70
|
|
|
// mkdir($newPath); |
|
|
|
|
71
|
|
View Code Duplication |
if (!@mkdir($newPath) && !is_dir($newPath)) { |
72
|
|
|
throw Exception("Couldn't create this directory: " . $newPath); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// check all files in dir, and process it |
76
|
|
|
if ($handle = opendir($path)) { |
77
|
|
|
while ($file = readdir($handle)) { |
78
|
|
|
if ($file !== '.' && $file !== '..') { |
79
|
|
|
cloneFileFolder("$path/$file"); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
closedir($handle); |
83
|
|
|
} |
84
|
|
|
} else { |
85
|
|
|
if (preg_match('/(.jpg|.gif|.png|.zip)$/i', $path)) { |
86
|
|
|
copy($path, $newPath); |
87
|
|
|
} else { |
88
|
|
|
// file, read it |
89
|
|
|
$content = file_get_contents($path); |
90
|
|
|
$content = str_replace($patKeys, $patValues, $content); |
91
|
|
|
file_put_contents($newPath, $content); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
cloneFileFolder('modules/smartpartner'); |
97
|
|
|
|
98
|
|
|
echo "Happy cloning...\n"; |
99
|
|
|
echo 'check directory modules/' . $patterns['smartpartner'] . " for cloned module \n"; |
100
|
|
|
echo "Consider modifying new module by editing language/english/modinfo.php and assets/images/logo_module.png manually (if you care)\n"; |
101
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.