1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* modulebuilder module. |
15
|
|
|
* |
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
17
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
18
|
|
|
* |
19
|
|
|
* @since 2.5.5 |
20
|
|
|
* |
21
|
|
|
* @author Goffy https://myxoops.org |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xmf\Request; |
26
|
|
|
use XoopsModules\Modulebuilder\Devtools; |
27
|
|
|
|
28
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
29
|
|
|
$moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
30
|
|
|
|
31
|
|
|
// Define main template |
32
|
|
|
$templateMain = $moduleDirName . '_devtools.tpl'; |
33
|
|
|
|
34
|
|
|
require __DIR__ . '/header.php'; |
35
|
|
|
// Recovered value of argument op in the URL $ |
36
|
|
|
$op = Request::getString('op', 'list'); |
37
|
|
|
|
38
|
|
|
switch ($op) { |
39
|
|
|
case 'fq': |
40
|
|
|
$fqModule = Request::getString('fq_module'); |
41
|
|
|
$src_path = \XOOPS_ROOT_PATH . '/modules/' . $fqModule; |
42
|
|
|
$dst_path = TDMC_UPLOAD_PATH . '/devtools/fq/' . $fqModule; |
43
|
|
|
|
44
|
|
|
$patKeys = []; |
45
|
|
|
$patValues = []; |
46
|
|
|
//Devtools::cloneFileFolder($src_path, $dst_path, $patKeys, $patValues); |
47
|
|
|
Devtools::function_qualifier($src_path, $dst_path, $fqModule); |
48
|
|
|
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_FQ_SUCCESS); |
49
|
|
|
break; |
50
|
|
|
case 'check_lang': |
51
|
|
|
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('devtools.php')); |
52
|
|
|
$clModuleName = Request::getString('cl_module'); |
53
|
|
|
$clModuleNameUpper = \mb_strtoupper($clModuleName); |
54
|
|
|
|
55
|
|
|
//scan language files |
56
|
|
|
$src_path = \XOOPS_ROOT_PATH . '/modules/' . $clModuleName . '/language/english/'; |
57
|
|
|
$langfiles = []; |
58
|
|
|
foreach (scandir($src_path) as $scan) { |
59
|
|
|
if (is_file($src_path . $scan) && 'index.html' !== $scan) { |
60
|
|
|
$langfiles[] = $src_path . $scan; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
$moduleConstants = []; |
64
|
|
|
foreach ($langfiles as $langfile) { |
65
|
|
|
//$constantsBeforeInclude = getUserDefinedConstants(); |
66
|
|
|
require_once($langfile); |
67
|
|
|
//$constantsAfterInclude = getUserDefinedConstants(); |
68
|
|
|
//$moduleConstants[$langfile] = array_diff_assoc($constantsAfterInclude, $constantsBeforeInclude); |
69
|
|
|
} |
70
|
|
|
$constantsAfterInclude = getUserDefinedConstants(); |
71
|
|
|
foreach ($constantsAfterInclude as $constKey => $constValue) { |
72
|
|
|
if (strpos($constKey, '_' . $clModuleNameUpper . '_') > 0) { |
73
|
|
|
$moduleConstants[$constKey] = $constKey; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
//get all php and tpl files from module |
78
|
|
|
$check_path = \XOOPS_ROOT_PATH . '/modules/' . $clModuleName; |
79
|
|
|
$Directory = new RecursiveDirectoryIterator($check_path); |
80
|
|
|
$Iterator = new RecursiveIteratorIterator($Directory); |
81
|
|
|
$regexFiles = new RegexIterator($Iterator, '/^.+\.(php|tpl)$/i', RecursiveRegexIterator::GET_MATCH); |
82
|
|
|
//$files = new RegexIterator($flattened, '#^(?:[A-Z]:)?(?:/(?!\.Trash)[^/]+)+/[^/]+\.(?:php|html)$#Di'); |
83
|
|
|
$modfiles = []; |
84
|
|
|
foreach($regexFiles as $regexFiles) { |
85
|
|
|
$file = str_replace('\\', '/', $regexFiles[0]); |
86
|
|
|
if (!\in_array($file, $langfiles)) { |
87
|
|
|
$modfiles[] = $file; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
//check all constants in all files |
92
|
|
|
$resultCheck = []; |
93
|
|
|
foreach ($moduleConstants as $constKey) { |
94
|
|
|
$foundMod = 0; |
95
|
|
|
$first = ''; |
96
|
|
|
$foundLang = 'not defined'; |
97
|
|
|
//search for complete string |
98
|
|
|
foreach($modfiles as $modfile) { |
99
|
|
|
if( strpos(file_get_contents($modfile),$constKey) !== false) { |
100
|
|
|
$foundMod = 1; |
101
|
|
|
$first = $modfile; |
102
|
|
|
break; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
if (0 == $foundMod) { |
106
|
|
|
//search for concatenated string |
107
|
|
|
$needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_", $constKey); |
108
|
|
|
foreach($modfiles as $modfile) { |
109
|
|
|
if( strpos(file_get_contents($modfile),$needle) !== false) { |
110
|
|
|
$foundMod = 1; |
111
|
|
|
$first = $modfile; |
112
|
|
|
break; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
if (0 == $foundMod) { |
117
|
|
|
//search for concatenated string |
118
|
|
|
$needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_' . '", $constKey); |
119
|
|
|
foreach($modfiles as $modfile) { |
120
|
|
|
if( strpos(file_get_contents($modfile),$needle) !== false) { |
121
|
|
|
$foundMod = 1; |
122
|
|
|
$first = $modfile; |
123
|
|
|
break; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
foreach($langfiles as $langfile) { |
128
|
|
|
if( strpos(file_get_contents($langfile),$constKey) !== false) { |
129
|
|
|
$foundLang = $langfile; |
130
|
|
|
break; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
if ('' == $foundLang) { |
134
|
|
|
//search for concatenated string |
135
|
|
|
$needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_", $constKey); |
136
|
|
|
foreach($langfiles as $langfile) { |
137
|
|
|
if( strpos(file_get_contents($langfile),$needle) !== false) { |
138
|
|
|
$foundLang = $langfile; |
139
|
|
|
break; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
if ('' == $foundLang) { |
144
|
|
|
//search for concatenated string |
145
|
|
|
$needle = str_replace('_' . $clModuleNameUpper . '_', "_' . \$moduleDirNameUpper . '_' . '", $constKey); |
146
|
|
|
foreach($langfiles as $langfile) { |
147
|
|
|
if( strpos(file_get_contents($langfile),$needle) !== false) { |
148
|
|
|
$foundLang = $langfile; |
149
|
|
|
break; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
$resultCheck[\basename($foundLang)][] = ['define' => $constKey, 'found' => $foundMod, 'first' => $first]; |
154
|
|
|
} |
155
|
|
|
$GLOBALS['xoopsTpl']->assign('clresults', $resultCheck); |
156
|
|
|
$GLOBALS['xoopsTpl']->assign('modPathIcon16', TDMC_URL . '/' . $modPathIcon16); |
157
|
|
|
|
158
|
|
|
break; |
159
|
|
|
case 'tab_replacer': |
160
|
|
|
$tabModule = Request::getString('tab_module'); |
161
|
|
|
$src_path = \XOOPS_ROOT_PATH . '/modules/' . $tabModule; |
162
|
|
|
$dst_path = TDMC_UPLOAD_PATH . '/devtools/tab/'; |
163
|
|
|
@\mkdir($dst_path); |
|
|
|
|
164
|
|
|
$dst_path = TDMC_UPLOAD_PATH . '/devtools/tab/' . $tabModule; |
165
|
|
|
@\mkdir($dst_path); |
166
|
|
|
|
167
|
|
|
Devtools::function_tabreplacer($src_path, $dst_path); |
168
|
|
|
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_FQ_SUCCESS); |
169
|
|
|
break; |
170
|
|
|
case 'list': |
171
|
|
|
default: |
172
|
|
|
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('devtools.php')); |
173
|
|
|
$dst_path = TDMC_UPLOAD_PATH . '/devtools/fq/'; |
174
|
|
|
$GLOBALS['xoopsTpl']->assign('fq_desc',\str_replace('%s', $dst_path, \_AM_MODULEBUILDER_DEVTOOLS_FQ_DESC)); |
175
|
|
|
$fq_form = Devtools::getFormModulesFq(); |
176
|
|
|
$GLOBALS['xoopsTpl']->assign('fq_form', $fq_form->render()); |
177
|
|
|
$cl_form = Devtools::getFormModulesCl(); |
178
|
|
|
$GLOBALS['xoopsTpl']->assign('cl_form', $cl_form->render()); |
179
|
|
|
$tab_form = Devtools::getFormModulesTab(); |
180
|
|
|
$GLOBALS['xoopsTpl']->assign('tab_form', $tab_form->render()); |
181
|
|
|
$dst_path = TDMC_UPLOAD_PATH . '/devtools/tab/'; |
182
|
|
|
$GLOBALS['xoopsTpl']->assign('tab_desc',\str_replace('%s', $dst_path, \_AM_MODULEBUILDER_DEVTOOLS_TAB_DESC)); |
183
|
|
|
$GLOBALS['xoopsTpl']->assign('devtools_list',true); |
184
|
|
|
|
185
|
|
|
break; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
function getUserDefinedConstants() { |
189
|
|
|
$constants = get_defined_constants(true); |
190
|
|
|
return (isset($constants['user']) ? $constants['user'] : []); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
require __DIR__ . '/footer.php'; |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: