|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
|
6
|
|
|
|
|
7
|
|
|
/* |
|
8
|
|
|
You may not change or alter any portion of this comment or credits |
|
9
|
|
|
of supporting developers from this source code or any supporting source code |
|
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
11
|
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
|
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
15
|
|
|
*/ |
|
16
|
|
|
/** |
|
17
|
|
|
* modulebuilder module. |
|
18
|
|
|
* |
|
19
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
20
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
21
|
|
|
* |
|
22
|
|
|
* @since 2.5.0 |
|
23
|
|
|
* |
|
24
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
//include \dirname(__DIR__) . '/autoload.php'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class CheckData. |
|
32
|
|
|
*/ |
|
33
|
|
|
class CheckData |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var mixed |
|
37
|
|
|
*/ |
|
38
|
|
|
private $cf = null; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
private $modId = null; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var mixed |
|
47
|
|
|
*/ |
|
48
|
|
|
private $tables = null; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var mixed |
|
52
|
|
|
*/ |
|
53
|
|
|
private $infos = []; |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @public function constructor |
|
59
|
|
|
* @param null |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->cf = Modulebuilder\Files\CreateFile::getInstance(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @static function getInstance |
|
68
|
|
|
* |
|
69
|
|
|
* @param null |
|
70
|
|
|
* |
|
71
|
|
|
* @return Modulebuilder\Files\CheckData |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function getInstance() |
|
74
|
|
|
{ |
|
75
|
|
|
static $instance = false; |
|
76
|
|
|
if (!$instance) { |
|
77
|
|
|
$instance = new self(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $instance; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @public function getCheckResult |
|
85
|
|
|
* |
|
86
|
|
|
* @param $module |
|
87
|
|
|
* @return array |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getCheckPreBuilding($module) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->modId = $module->getVar('mod_id'); |
|
92
|
|
|
$this->tables = $this->cf->getTableTables($this->modId); |
|
93
|
|
|
$this->infos = []; |
|
94
|
|
|
|
|
95
|
|
|
$this->getCheckBlock(); |
|
96
|
|
|
$this->getCheckBroken(); |
|
97
|
|
|
$this->getCheckComments(); |
|
98
|
|
|
$this->getCheckUserpage(); |
|
99
|
|
|
$this->getCheckRating(); |
|
100
|
|
|
$this->getCheckSQL(); |
|
101
|
|
|
|
|
102
|
|
|
return $this->infos; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @public function getCheckBroken |
|
107
|
|
|
* |
|
108
|
|
|
* @return array|bool |
|
109
|
|
|
*/ |
|
110
|
|
|
private function getCheckBroken() |
|
111
|
|
|
{ |
|
112
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
113
|
|
|
if (1 == $this->tables[$t]->getVar('table_broken')) { |
|
114
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
115
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
116
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
117
|
|
|
$fieldSatus = ''; |
|
118
|
|
|
|
|
119
|
|
|
foreach (\array_keys($fields) as $f) { |
|
120
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
121
|
|
|
if (16 == $fields[$f]->getVar('field_element')) { |
|
122
|
|
|
$fieldSatus = $fieldName; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
// check whether each table with handling "broken" has also a field "status" |
|
126
|
|
|
if ('' == $fieldSatus) { |
|
127
|
|
|
$info = \str_replace('%t', $tableName, _AM_MODULEBUILDER_BUILDING_CHECK_BROKEN1); |
|
128
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return true; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @private function getCheckUserpage |
|
138
|
|
|
* |
|
139
|
|
|
* @return array|bool |
|
140
|
|
|
*/ |
|
141
|
|
|
private function getCheckUserpage() |
|
142
|
|
|
{ |
|
143
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
144
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
145
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
146
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
147
|
|
|
|
|
148
|
|
|
foreach (\array_keys($fields) as $f) { |
|
149
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
150
|
|
|
// check fields for parameters |
|
151
|
|
|
if ($f > 0) { |
|
152
|
|
|
$fieldParams = (int)$fields[$f]->getVar('field_parent') + (int)$fields[$f]->getVar('field_admin') + (int)$fields[$f]->getVar('field_inlist') + (int)$fields[$f]->getVar('field_inform') |
|
153
|
|
|
+ (int)$fields[$f]->getVar('field_user') + (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
|
154
|
|
|
+ (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot') + (int)$fields[$f]->getVar('field_block') |
|
155
|
|
|
+ (int)$fields[$f]->getVar('field_main') + (int)$fields[$f]->getVar('field_search') + (int)$fields[$f]->getVar('field_required'); |
|
156
|
|
|
if (0 == $fieldParams) { |
|
157
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_FIELDS1); |
|
158
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
//check user file no usage in index or item |
|
165
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
166
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
167
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
168
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
169
|
|
|
|
|
170
|
|
|
foreach (\array_keys($fields) as $f) { |
|
171
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
172
|
|
|
if (1 == $fields[$f]->getVar('field_user')) { |
|
173
|
|
|
// check fields for parameters |
|
174
|
|
|
if ($f > 0) { |
|
175
|
|
|
$fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
|
176
|
|
|
+ (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
|
177
|
|
|
if (0 == $fieldParams) { |
|
178
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_FIELDS2); |
|
179
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
//check user file index multiple usage |
|
186
|
|
|
//check user file item multiple usage |
|
187
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
188
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
189
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
190
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
191
|
|
|
|
|
192
|
|
|
foreach (\array_keys($fields) as $f) { |
|
193
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
194
|
|
|
if (1 == $fields[$f]->getVar('field_user')) { |
|
195
|
|
|
// check fields for parameters |
|
196
|
|
|
if ($f > 0) { |
|
197
|
|
|
$fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot'); |
|
198
|
|
|
if ($fieldParams > 1) { |
|
199
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_FIELDS3); |
|
200
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
201
|
|
|
} |
|
202
|
|
|
$fieldParams = (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
|
203
|
|
|
if ($fieldParams > 1) { |
|
204
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_FIELDS3); |
|
205
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
//check user submit or rate or broken, but table not for user side |
|
213
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
214
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
215
|
|
|
if ((0 == $this->tables[$t]->getVar('table_user')) && (1 == $this->tables[$t]->getVar('table_submit') || 1 == $this->tables[$t]->getVar('table_broken') || 1 == $this->tables[$t]->getVar('table_rate'))) { |
|
216
|
|
|
$info = \str_replace(['%t'], [$tableName], _AM_MODULEBUILDER_BUILDING_CHECK_USERPAGE1); |
|
217
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
return true; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @private function getCheckBlock |
|
225
|
|
|
* |
|
226
|
|
|
* @return array|bool |
|
227
|
|
|
*/ |
|
228
|
|
|
private function getCheckBlock() |
|
229
|
|
|
{ |
|
230
|
|
|
//use in block but no field selected |
|
231
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
232
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
233
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
234
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
235
|
|
|
$count = 0; |
|
236
|
|
|
if (1 == $this->tables[$t]->getVar('table_blocks')) { |
|
237
|
|
|
foreach (\array_keys($fields) as $f) { |
|
238
|
|
|
if (1 == $fields[$f]->getVar('field_block')) { |
|
239
|
|
|
$count++; |
|
240
|
|
|
} |
|
241
|
|
|
} |
|
242
|
|
|
if (0 == $count) { |
|
243
|
|
|
$info = \str_replace(['%t'], [$tableName], _AM_MODULEBUILDER_BUILDING_CHECK_BLOCK1); |
|
244
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
} |
|
248
|
|
|
//use in block but no field date |
|
249
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
250
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
251
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
252
|
|
|
|
|
253
|
|
|
$count = 0; |
|
254
|
|
|
if (1 == $this->tables[$t]->getVar('table_blocks')) { |
|
255
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
256
|
|
|
foreach (\array_keys($fields) as $f) { |
|
257
|
|
|
if (15 == $fields[$f]->getVar('field_element') || 21 == $fields[$f]->getVar('field_element')) { |
|
258
|
|
|
$count++; |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
if (0 == $count) { |
|
262
|
|
|
$info = \str_replace(['%t'], [$tableName], _AM_MODULEBUILDER_BUILDING_CHECK_BLOCK2); |
|
263
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
return true; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/** |
|
271
|
|
|
* @private function getCheckComments |
|
272
|
|
|
* |
|
273
|
|
|
* @return array|bool |
|
274
|
|
|
*/ |
|
275
|
|
|
private function getCheckComments() |
|
276
|
|
|
{ |
|
277
|
|
|
//use comments in multiple tables |
|
278
|
|
|
$count = 0; |
|
279
|
|
|
$tableComments = []; |
|
280
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
281
|
|
|
if (1 == $this->tables[$t]->getVar('table_comments')) { |
|
282
|
|
|
$count++; |
|
283
|
|
|
$tableComments[] = $this->tables[$t]->getVar('table_name'); |
|
284
|
|
|
} |
|
285
|
|
|
} |
|
286
|
|
|
if ($count > 1) { |
|
287
|
|
|
$tablesComments = \implode(', ', $tableComments); |
|
288
|
|
|
$info = \str_replace('%t', $tablesComments, _AM_MODULEBUILDER_BUILDING_CHECK_COMMENTS1); |
|
289
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
293
|
|
|
if (1 == $this->tables[$t]->getVar('table_comments')) { |
|
294
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
295
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
296
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
297
|
|
|
$fieldComments = ''; |
|
298
|
|
|
|
|
299
|
|
|
foreach (\array_keys($fields) as $f) { |
|
300
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
301
|
|
|
if ($fieldName == $this->tables[$t]->getVar('table_fieldname') . '_comments') { |
|
302
|
|
|
$fieldComments = $fieldName; |
|
303
|
|
|
} |
|
304
|
|
|
} |
|
305
|
|
|
// check whether each table with handling "comments" has also a field "comments" |
|
306
|
|
|
if ('' == $fieldComments) { |
|
307
|
|
|
$info = \str_replace(['%f', '%t'], [$this->tables[$t]->getVar('table_fieldname') . '_comments', $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_COMMENTS2); |
|
308
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
return true; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @private function getCheckComments |
|
318
|
|
|
* |
|
319
|
|
|
* @return array|bool |
|
320
|
|
|
*/ |
|
321
|
|
|
private function getCheckRating() |
|
322
|
|
|
{ |
|
323
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
324
|
|
|
if (1 == $this->tables[$t]->getVar('table_rate')) { |
|
325
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
326
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
327
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
328
|
|
|
$fieldRatings = ''; |
|
329
|
|
|
|
|
330
|
|
|
foreach (\array_keys($fields) as $f) { |
|
331
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
332
|
|
|
if ($fieldName == $this->tables[$t]->getVar('table_fieldname') . '_ratings') { |
|
333
|
|
|
$fieldRatings = $fieldName; |
|
334
|
|
|
} |
|
335
|
|
|
} |
|
336
|
|
|
// check whether each table with handling "rating" has also a field "rating" |
|
337
|
|
|
if ('' == $fieldRatings) { |
|
338
|
|
|
$info = \str_replace(['%f', '%t'], [$this->tables[$t]->getVar('table_fieldname') . '_ratings', $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_RATINGS1); |
|
339
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
344
|
|
|
if (1 == $this->tables[$t]->getVar('table_rate')) { |
|
345
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
346
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
347
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
348
|
|
|
$fieldVotes = ''; |
|
349
|
|
|
|
|
350
|
|
|
foreach (\array_keys($fields) as $f) { |
|
351
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
352
|
|
|
if ($fieldName == $this->tables[$t]->getVar('table_fieldname') . '_votes') { |
|
353
|
|
|
$fieldVotes = $fieldName; |
|
354
|
|
|
} |
|
355
|
|
|
} |
|
356
|
|
|
// check whether each table with handling "rating" has also a field "votes" |
|
357
|
|
|
if ('' == $fieldVotes) { |
|
358
|
|
|
$info = \str_replace(['%f', '%t'], [$this->tables[$t]->getVar('table_fieldname') . '_votes', $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_RATINGS1); |
|
359
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
return true; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* @private function getCheckSql |
|
369
|
|
|
* |
|
370
|
|
|
* @return array|bool |
|
371
|
|
|
*/ |
|
372
|
|
|
private function getCheckSql() |
|
373
|
|
|
{ |
|
374
|
|
|
foreach (\array_keys($this->tables) as $t) { |
|
375
|
|
|
$tableId = $this->tables[$t]->getVar('table_id'); |
|
376
|
|
|
$tableName = $this->tables[$t]->getVar('table_name'); |
|
377
|
|
|
$fields = $this->cf->getTableFields($this->modId, $tableId); |
|
378
|
|
|
foreach (\array_keys($fields) as $f) { |
|
379
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
380
|
|
|
$fieldType = $fields[$f]->getVar('field_type'); |
|
381
|
|
|
if (6 == $fieldType || 7 == $fieldType || 8 == $fieldType) { |
|
382
|
|
|
$fieldValue = $fields[$f]->getVar('field_value'); |
|
383
|
|
|
if (0 == \strpos($fieldValue,',')) { |
|
384
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_SQL1); |
|
385
|
|
|
$this->infos[] = ['icon' => 'error', 'info' => $info]; |
|
386
|
|
|
} |
|
387
|
|
|
$fieldDefault = $fields[$f]->getVar('field_default'); |
|
388
|
|
|
if (0 == \strpos($fieldDefault,'.')) { |
|
389
|
|
|
$info = \str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_BUILDING_CHECK_SQL2); |
|
390
|
|
|
$this->infos[] = ['icon' => 'warning', 'info' => $info]; |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
|
} |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
return true; |
|
397
|
|
|
} |
|
398
|
|
|
} |
|
399
|
|
|
|