Passed
Push — master ( 0cff9c...dfbbd0 )
by Goffy
14:51
created

CreateXoopsCode::getXcHandlerGetObj()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
/**
29
 * Class CreateXoopsCode.
30
 */
31
class CreateXoopsCode
32
{
33
    /**
34
     * @static function getInstance
35
     * @param null
36
     */
37
38
    /**
39
     * @return Modulebuilder\Files\CreateXoopsCode
40
     */
41
    public static function getInstance()
42
    {
43
        static $instance = false;
44
        if (!$instance) {
45
            $instance = new self();
46
        }
47
48
        return $instance;
49
    }
50
51
    /**
52
     * @public function getXcSwitch
53
     * @param $op
54
     * @param $cases
55
     * @param $defaultAfterCase
56
     * @param $default
57
     * @param $t - Indentation
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
58
     *
59
     * @return string
60
     */
61
    public function getXcSwitch($op = '', $cases = [], $defaultAfterCase = false, $default = false, $t = '')
62
    {
63
        $pc            = Modulebuilder\Files\CreatePhpCode::getInstance();
64
        $contentSwitch = $pc->getPhpCodeCaseSwitch($cases, $defaultAfterCase, $default, $t . "\t");
65
66
        return $pc->getPhpCodeSwitch($op, $contentSwitch, $t);
67
    }
68
69
    /**
70
     * @public function getXcEqualsOperator
71
     * @param $var
72
     * @param $value
73
     * @param $interlock
74
     * @param $t - Indentation
0 ignored issues
show
Documentation Bug introduced by
The doc comment - at position 0 could not be parsed: Unknown type name '-' at position 0 in -.
Loading history...
75
     *
76
     * @return string
77
     */
78
    public function getXcEqualsOperator($var, $value, $interlock = null, $t = '')
79
    {
80
        return "{$t}{$var} {$interlock}= {$value};\n";
81
    }
82
83
    /**
84
     * @public function getXcAnchorFunction
85
     * @param $anchor
86
     * @param $name
87
     * @param $vars
88
     * @param $close
89
     *
90
     * @return string
91
     */
92
    public function getXcAnchorFunction($anchor, $name, $vars, $close = false)
93
    {
94
        $semicolon = false !== $close ? ';' : '';
95
96
        return "\${$anchor}->{$name}({$vars}){$semicolon}";
97
    }
98
99
    /**
100
     * @public function getXcSetVarObj
101
     * @param $tableName
102
     * @param $fieldName
103
     * @param $var
104
     * @param $t
105
     * @return string
106
     */
107
    public function getXcSetVarObj($tableName, $fieldName, $var, $t = '')
108
    {
109
        return "{$t}\${$tableName}Obj->setVar('{$fieldName}', {$var});\n";
110
    }
111
112
    /**
113
     * @public function getXcGetVar
114
     * @param string $varLeft
115
     * @param string $handle
116
     * @param string $var
117
     * @param bool $isParam
118
     * @param string $t
119
     *
120
     * @param string $format
121
     * @return string
122
     */
123
    public function getXcGetVar($varLeft = '', $handle = '', $var = '', $isParam = false, $t = '', $format = '')
124
    {
125
        if (!$isParam) {
126
            $ret = "{$t}\${$varLeft} = \${$handle}->getVar('{$var}'{$format});\n";
127
        } else {
128
            $ret = "\${$handle}->getVar('{$var}'{$format})";
129
        }
130
131
        return $ret;
132
    }
133
134
    /**
135
     * @public function getXcAddItem
136
     * @param $varLeft
137
     * @param $paramLeft
138
     * @param $paramRight
139
     * @param $t
140
     *
141
     * @return string
142
     */
143
    public function getXcAddItem($varLeft = '', $paramLeft = '', $paramRight = '', $t = '')
144
    {
145
        return "{$t}\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n";
146
    }
147
148
    /**
149
     * @public function getXcGetGroupIds
150
     * @param string $var
151
     * @param string $anchor
152
     * @param        $param1
153
     * @param        $param2
154
     * @param        $param3
155
     * @param string $t
156
     * @return string
157
     */
158
    public function getXcGetGroupIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
159
    {
160
        return "{$t}\${$var} = \${$anchor}->getGroupIds({$param1}, {$param2}, {$param3});\n";
161
    }
162
163
    /**
164
     * @public function getXcGetItemIds
165
     * @param string $var
166
     * @param string $anchor
167
     * @param        $param1
168
     * @param        $param2
169
     * @param        $param3
170
     * @param string $t
171
     * @return string
172
     */
173
    public function getXcGetItemIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '')
174
    {
175
        return "{$t}\${$var} = \${$anchor}->getItemIds({$param1}, {$param2}, {$param3});\n";
176
    }
177
178
    /**
179
     * @public function getXcSetVarTextDateSelect
180
     * @param        $tableName
181
     * @param        $tableSoleName
182
     * @param        $fieldName
183
     * @param string $t
184
     * @return string
185
     */
186
    public function getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName, $t = '')
187
    {
188
        $tf            = Modulebuilder\Files\CreateFile::getInstance();
189
        $rightField    = $tf->getRightString($fieldName);
190
        $ucfRightField = ucfirst($rightField);
191
        $value         = "date_create_from_format(_SHORTDATESTRING, Request::getString('{$fieldName}'))";
192
        $ret           = $this->getXcEqualsOperator("\${$tableSoleName}{$ucfRightField}", $value, null, $t);
193
        $ret           .= $this->getXcSetVarObj($tableName, $fieldName, "\${$tableSoleName}{$ucfRightField}->getTimestamp()", $t);
194
195
        return $ret;
196
    }
197
198
    /**
199
     * @public function getXcSetVarDateTime
200
     * @param        $tableName
201
     * @param        $tableSoleName
202
     * @param        $fieldName
203
     * @param string $t
204
     * @return string
205
     */
206
    public function getXcSetVarDateTime($tableName, $tableSoleName, $fieldName, $t = '')
207
    {
208
        $tf            = Modulebuilder\Files\CreateFile::getInstance();
209
        $rightField    = $tf->getRightString($fieldName);
210
        $ucfRightField = ucfirst($rightField);
211
        $request       = "Request::getArray('{$fieldName}')";
212
        $var           = "\${$tableSoleName}{$ucfRightField}";
213
        $varArr        = "\${$tableSoleName}{$ucfRightField}Arr";
214
        $ret           = $this->getXcEqualsOperator($varArr, $request, null, $t);
215
        $value         = "strtotime({$varArr}['date']) + (int){$varArr}['time']";
216
        $ret           .= $this->getXcEqualsOperator($var, $value, null, $t);
217
        $ret           .= $this->getXcSetVarObj($tableName, $fieldName, $var, $t);
218
219
        return $ret;
220
    }
221
222
    /**
223
     * @public function getXcSetVarCheckBoxOrRadioYN
224
     * @param $tableName
225
     * @param $fieldName
226
     * @param $t
227
     * @return string
228
     */
229
    public function getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName, $t = '')
230
    {
231
        return $this->getXcSetVarObj($tableName, $fieldName, "Request::getInt('{$fieldName}', 0)", $t);
232
    }
233
234
    /**
235
     * @public function getXcMediaUploader
236
     * @param $var
237
     * @param $dirPath
238
     * @param $mimetype
239
     * @param $maxsize
240
     * @param string $t
241
     * @return string
242
     */
243
    public function getXcMediaUploader($var, $dirPath, $mimetype, $maxsize, $t = '')
244
    {
245
        $mimetypes_file = $this->getXcGetConfig($mimetype);
246
        $maxsize_file   = $this->getXcGetConfig($maxsize);
247
248
        return "{$t}\${$var} = new \XoopsMediaUploader({$dirPath}, 
249
													{$mimetypes_file}, 
250
													{$maxsize_file}, null, null);\n";
251
    }
252
253
    /**
254
     * @public function getXcXoopsCaptcha
255
     * @param $var
256
     * @param $instance
257
     * @param $t
258
     *
259
     * @return string
260
     */
261
    public function getXcGetInstance($var = '', $instance = '', $t = '')
262
    {
263
        return "{$t}\${$var} = {$instance}::getInstance();\n";
264
    }
265
266
    /**
267
     * @public function getXcGetConfig
268
     * @param $name
269
     * @return string
270
     */
271
    public function getXcGetConfig($name)
272
    {
273
        return "\$helper->getConfig('{$name}')";
274
    }
275
276
    /**
277
     * @public function getXcIdGetVar
278
     * @param $lpFieldName
279
     * @param $t
280
     * @return string
281
     */
282
    public function getXcIdGetVar($lpFieldName, $t = '')
283
    {
284
        return "{$t}\${$lpFieldName}['id'] = \$i;\n";
285
    }
286
287
    /**
288
     * @public function getXcGetVarAll
289
     * @param $lpFieldName
290
     * @param $rpFieldName
291
     * @param $tableName
292
     * @param $fieldName
293
     * @param $t
294
     * @return string
295
     */
296
    public function getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
297
    {
298
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n";
299
    }
300
301
    /**
302
     * @public function getXcHelperGetInstance
303
     * @param        $moduleDirname
304
     *
305
     * @param string $t
306
     * @return string
307
     */
308
    public function getXcHelperGetInstance($moduleDirname, $t = '')
309
    {
310
        $ucfModuleDirname = ucfirst($moduleDirname);
311
        $ret              = "{$t}// Get instance of module\n";
312
        $ret              .= "{$t}\$helper = \XoopsModules\\{$ucfModuleDirname}\Helper::getInstance();\n";
313
314
        return $ret;
315
    }
316
317
    /**
318
     * @public function getXcFormatTimeStamp
319
     * @param        $left
320
     * @param        $value
321
     * @param string $format
322
     * @param string $t
323
     * @return string
324
     */
325
    public function getXcFormatTimeStamp($left, $value, $format = 's', $t = '')
326
    {
327
        return "{$t}\${$left} = formatTimeStamp({$value}, '{$format}');\n";
328
    }
329
330
    /**
331
     * @public function getXcTopicGetVar
332
     * @param        $lpFieldName
333
     * @param        $rpFieldName
334
     * @param        $tableName
335
     * @param        $tableNameTopic
336
     * @param        $fieldNameParent
337
     * @param        $fieldNameTopic
338
     * @param string $t
339
     * @return string
340
     */
341
    public function getXcTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
342
    {
343
        $pc          = Modulebuilder\Files\CreatePhpCode::getInstance();
344
        $ret         = $pc->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
345
        $fieldParent = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
346
        $ret         .= $this->getXcHandlerGet($rpFieldName, $fieldParent, '', $tableNameTopic . 'Handler', false, $t);
347
        $ret         .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
348
349
        return $ret;
350
    }
351
352
    /**
353
     * @public function getXcParentTopicGetVar
354
     * @param        $lpFieldName
355
     * @param        $rpFieldName
356
     * @param        $tableName
357
     * @param        $tableSoleNameTopic
358
     * @param        $tableNameTopic
359
     * @param        $fieldNameParent
360
     * @param string $t
361
     * @return string
362
     */
363
    public function getXcParentTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent, $t = '')
364
    {
365
        $pc           = Modulebuilder\Files\CreatePhpCode::getInstance();
366
        $parentTopic  = $pc->getPhpCodeCommentLine('Get', $tableNameTopic . ' Handler', $t . "\t");
367
        $parentTopic  .= $this->getXcHandlerLine($tableNameTopic, $t . "\t");
368
        $elseGroups   = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
369
        $ret          = $pc->getPhpCodeConditions("!isset(\${$tableNameTopic}Handler", '', '', $parentTopic, $elseGroups);
370
        $ret          .= $this->getXcGetVarFromID("\${$lpFieldName}['{$rpFieldName}']", $tableNameTopic, $tableSoleNameTopic, $tableName, $fieldNameParent, $t);
371
372
        return $ret;
373
    }
374
375
    /**
376
     * @public function getXcGetVarFromID
377
     * @param        $left
378
     * @param        $anchor
379
     * @param        $var
380
     * @param        $tableName
381
     * @param        $fieldName
382
     * @param string $t
383
     * @return string
384
     */
385
    public function getXcGetVarFromID($left, $anchor, $var, $tableName, $fieldName, $t = '')
386
    {
387
        $pc           = Modulebuilder\Files\CreatePhpCode::getInstance();
388
        $ret          = $pc->getPhpCodeCommentLine('Get Var', $fieldName, $t);
389
        $getVarFromID = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, '');
390
        $rightGet     = $this->getXcAnchorFunction($anchor . 'Handler', 'get' . $var . 'FromId', $getVarFromID);
391
        $ret          .= $this->getXcEqualsOperator($left, $rightGet, null, $t);
392
393
        return $ret;
394
    }
395
396
    /**
397
     * @public function getXcGetVarUploadImage
398
     * @param        $lpFieldName
399
     * @param        $rpFieldName
400
     * @param        $tableName
401
     * @param        $fieldName
402
     * @param string $t
403
     * @return string
404
     */
405
    public function getXcGetVarUploadImage($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
406
    {
407
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
408
        $ret = $pc->getPhpCodeCommentLine('Get Var', $fieldName, $t);
409
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
410
        $ret .= $pc->getPhpCodeTernaryOperator("{$lpFieldName}['{$rpFieldName}']", "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
411
412
        return $ret;
413
    }
414
415
    /**
416
     * @public function getXcGetVarUrlFile
417
     * @param $lpFieldName
418
     * @param $rpFieldName
419
     * @param $tableName
420
     * @param $fieldName
421
     * @return string
422
     */
423
    public function getXcGetVarUrlFile($lpFieldName, $rpFieldName, $tableName, $fieldName)
424
    {
425
        return $this->getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName);
426
    }
427
428
    /**
429
     * @public function getXcGetVarTextArea
430
     * @param        $lpFieldName
431
     * @param        $rpFieldName
432
     * @param        $tableName
433
     * @param        $fieldName
434
     * @param string $t
435
     * @return string
436
     */
437
    public function getXcGetVarTextArea($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
438
    {
439
        $pc     = Modulebuilder\Files\CreatePhpCode::getInstance();
440
        $getVar = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, '');
441
442
        return $t . $pc->getPhpCodeStripTags("{$lpFieldName}['{$rpFieldName}']", $getVar, false, $t);
443
    }
444
445
    /**
446
     * @public function getXcGetVarSelectUser
447
     * @param        $lpFieldName
448
     * @param        $rpFieldName
449
     * @param        $tableName
450
     * @param        $fieldName
451
     * @param string $t
452
     * @return string
453
     */
454
    public function getXcGetVarSelectUser($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
455
    {
456
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
457
    }
458
459
    /**
460
     * @public function getXcGetVarTextDateSelect
461
     * @param        $lpFieldName
462
     * @param        $rpFieldName
463
     * @param        $tableName
464
     * @param        $fieldName
465
     * @param string $t
466
     * @return string
467
     */
468
    public function getXcGetVarTextDateSelect($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
469
    {
470
        return "{$t}\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n";
471
    }
472
473
    /**
474
     * @public function getXcUserHeader
475
     * @param        $moduleDirname
476
     * @param        $tableName
477
     * @param string $t
478
     * @return string
479
     */
480
    public function getXcXoopsOptionTemplateMain($moduleDirname, $tableName, $t = '')
481
    {
482
        return "{$t}\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n";
483
    }
484
485
    /**
486
     * @public function getXcUserHeader
487
     * @param $moduleDirname
488
     * @param $tableName
489
     * @return string
490
     */
491
    public function getXcUserHeader($moduleDirname, $tableName)
492
    {
493
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
494
        $ret = $pc->getPhpCodeIncludeDir('__DIR__', 'header');
495
        $ret .= $this->getXcXoopsOptionTemplateMain($moduleDirname, $tableName);
496
        $ret .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true);
497
498
        return $ret;
499
    }
500
501
    /**
502
     * @public function getXcPermissionsHeader
503
     * @param null
504
     * @return string
505
     */
506
    public function getXcPermissionsHeader()
507
    {
508
        $pc         = Modulebuilder\Files\CreatePhpCode::getInstance();
509
        $ret        = $pc->getPhpCodeCommentLine('Permission');
510
        $ret        .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true);
511
        $ret        .= $this->getXcXoopsHandler('groupperm');
512
        $groups     = $this->getXcEqualsOperator('$groups', '$xoopsUser->getGroups()');
513
        $elseGroups = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS');
514
        $ret        .= $pc->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups);
515
516
        return $ret;
517
    }
518
519
    /**
520
     * @public function getXcGetFieldId
521
     *
522
     * @param $fields
523
     *
524
     * @return string
525
     */
526
    public function getXcGetFieldId($fields)
527
    {
528
        $fieldId = 'id';
529
        foreach (array_keys($fields) as $f) {
530
            $fieldName = $fields[$f]->getVar('field_name');
531
            if (0 == $f) {
532
                $fieldId = $fieldName;
533
            }
534
        }
535
536
        return $fieldId;
537
    }
538
539
    /**
540
     * @public function getXcGetFieldName
541
     *
542
     * @param $fields
543
     *
544
     * @return string
545
     */
546
    public function getXcGetFieldName($fields)
547
    {
548
        $fieldName = '';
549
        foreach (array_keys($fields) as $f) {
550
            $fieldName = $fields[$f]->getVar('field_name');
551
        }
552
553
        return $fieldName;
554
    }
555
556
    /**
557
     * @public function getXcGetFieldParentId
558
     *
559
     * @param $fields
560
     *
561
     * @return string
562
     */
563
    public function getXcGetFieldParentId($fields)
564
    {
565
        $fieldPid = 'pid';
566
        foreach (array_keys($fields) as $f) {
567
            $fieldName = $fields[$f]->getVar('field_name');
568
            if (1 == $fields[$f]->getVar('field_parent')) {
569
                $fieldPid = $fieldName;
570
            }
571
        }
572
573
        return $fieldPid;
574
    }
575
576
    /**
577
     * @public function getXcUserSaveElements
578
     *
579
     * @param $moduleDirname
580
     * @param $tableName
581
     * @param $tableSoleName
582
     * @param $fields
583
     * @return string
584
     */
585
    public function getXcUserSaveElements($moduleDirname, $tableName, $tableSoleName, $fields)
586
    {
587
        $axc            = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance();
588
        $ret            = '';
589
        $fieldMain      = '';
590
        $countUploader  = 0;
591
        foreach (array_keys($fields) as $f) {
592
            $fieldName    = $fields[$f]->getVar('field_name');
593
            $fieldElement = $fields[$f]->getVar('field_element');
594
            if (1 == $fields[$f]->getVar('field_main')) {
595
                $fieldMain = $fieldName;
596
            }
597
            if ((5 == $fieldElement) || (6 == $fieldElement)) {
598
                $ret .= $this->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName);
599
            } elseif (13 == $fieldElement) {
600
                $ret .= $axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, '', $countUploader);
601
                $countUploader++;
602
            } elseif (14 == $fieldElement) {
603
                $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, '', '', $countUploader);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type boolean expected by parameter $formatUrl of XoopsModules\Modulebuild...etAxcSetVarUploadFile(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

603
                $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, /** @scrutinizer ignore-type */ '', '', $countUploader);
Loading history...
604
                $countUploader++;
605
            } elseif (15 == $fieldElement) {
606
                $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName);
607
            } else {
608
                $ret .= $this->getXcSetVarObj($tableName, $fieldName, "\$_POST['{$fieldName}']");
609
            }
610
        }
611
612
        return $ret;
613
    }
614
615
    /**
616
     * @public function getXcXoopsRequest
617
     * @param string $left
618
     * @param string $var1
619
     * @param string $var2
620
     * @param string $type
621
     * @param bool   $method
622
     * @param string $t
623
     * @return string
624
     */
625
    public function getXcXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $method = false, $t = '')
626
    {
627
        $ret     = '';
628
        $intVars = ('' != $var2) ? "'{$var1}', {$var2}" : "'{$var1}'";
629
        if ('String' === $type) {
630
            $ret .= "{$t}\${$left} = Request::getString('{$var1}', '{$var2}');\n";
631
        } elseif ('Int' === $type) {
632
            $ret .= "{$t}\${$left} = Request::getInt({$intVars});\n";
633
        } elseif ('Int' === $type && false !== $method) {
634
            $ret .= "{$t}\${$left} = Request::getInt({$intVars}, '{$method}');\n";
635
        } else {
636
            $ret .= "{$t}\${$left} = Request::get{$type}('{$var1}', '{$var2}');\n";
637
        }
638
639
        return $ret;
640
    }
641
642
    /**
643
     * @public function getXcAddRight
644
     *
645
     * @param        $anchor
646
     * @param string $permString
647
     * @param string $var
648
     * @param string $groups
649
     * @param string $mid
650
     * @param bool   $isParam
651
     *
652
     * @param string $t
653
     * @return string
654
     */
655
    public function getXcAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
656
    {
657
        if (!$isParam) {
658
            $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n";
659
        } else {
660
            $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})";
661
        }
662
663
        return $ret;
664
    }
665
666
    /**
667
     * @public function getXcCheckRight
668
     *
669
     * @param        $anchor
670
     * @param string $permString
671
     * @param string $var
672
     * @param string $groups
673
     * @param string $mid
674
     * @param bool   $isParam
675
     *
676
     * @param string $t
677
     * @return string
678
     */
679
    public function getXcCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
680
    {
681
        if (!$isParam) {
682
            $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n";
683
        } else {
684
            $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})";
685
        }
686
687
        return $ret;
688
    }
689
690
    /**
691
     * @public function getXcAddRight
692
     *
693
     * @param        $anchor
694
     * @param string $permString
695
     * @param string $mid
696
     * @param string $var
697
     * @param bool $isParam
698
     *
699
     * @param string $t
700
     * @return string
701
     */
702
    public function getXcDeleteRight($anchor, $permString = '', $mid = '', $var = '', $isParam = false, $t = '')
703
    {
704
        if (!$isParam) {
705
            $ret = "{$t}\${$anchor}->deleteByModule({$mid}, '{$permString}', {$var});\n";
706
        } else {
707
            $ret = "\${$anchor}->deleteByModule({$mid}, '{$permString}', {$var})";
708
        }
709
        return $ret;
710
    }
711
712
    /**
713
     * @public function getXcHandlerLine
714
     * @param $tableName
715
     * @param string $t
716
     * @return string
717
     */
718
    public function getXcHandlerLine($tableName, $t = '')
719
    {
720
        return "{$t}\${$tableName}Handler = \$helper->getHandler('{$tableName}');\n";
721
    }
722
723
    /**
724
     * @public function getXcHandlerCreateObj
725
     *
726
     * @param        $tableName
727
     *
728
     * @param string $t
729
     * @return string
730
     */
731
    public function getXcHandlerCreateObj($tableName, $t = '')
732
    {
733
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->create();\n";
734
    }
735
736
    /**
737
     * @public function getXcHandlerGetObj
738
     *
739
     * @param        $tableName
740
     * @param        $ccFieldId
741
     * @param string $t
742
     * @return string
743
     */
744
    public function getXcHandlerGetObj($tableName, $ccFieldId, $t = '')
745
    {
746
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->get(\${$ccFieldId});\n";
747
    }
748
749
    /**
750
     * @public function getXcHandlerCountObj
751
     *
752
     * @param        $tableName
753
     *
754
     * @param string $t
755
     * @return string
756
     */
757
    public function getXcHandlerCountObj($tableName, $t = '')
758
    {
759
        $ucfTableName = ucfirst($tableName);
760
        $ret          = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
761
762
        return $ret;
763
    }
764
765
    /**
766
     * @public function getXcClearCount
767
     * @param  $left
768
     * @param  $anchor
769
     * @param  $params
770
     * @param  $t
771
     *
772
     * @return string
773
     */
774
    public function getXcHandlerCountClear($left, $anchor = '', $params = '', $t = '')
775
    {
776
        $ret = "{$t}\${$left} = \${$anchor}Handler->getCount({$params});\n";
777
778
        return $ret;
779
    }
780
781
    /**
782
     * @public function getXcHandlerAllObj
783
     *
784
     * @param        $tableName
785
     * @param string $fieldMain
786
     * @param string $start
787
     * @param string $limit
788
     *
789
     * @param string $t
790
     * @return string
791
     */
792
    public function getXcHandlerAllObj($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '')
793
    {
794
        $ucfTableName = ucfirst($tableName);
795
        $startLimit   = ('0' != $limit) ? "{$start}, {$limit}" : '0';
796
        $params       = ('' != $fieldMain) ? "{$startLimit}, '{$fieldMain}'" : $startLimit;
797
        $ret          = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n";
798
799
        return $ret;
800
    }
801
802
    /**
803
     * @public function getXcHandlerAllClear
804
     * @param        $left
805
     * @param string $anchor
806
     * @param string $params
807
     * @param string $t
808
     * @return string
809
     */
810
    public function getXcHandlerAllClear($left, $anchor = '', $params = '', $t = '')
811
    {
812
        $ret = "{$t}\${$left} = \${$anchor}Handler->getAll({$params});\n";
813
814
        return $ret;
815
    }
816
817
    /**
818
     * @public function getXcHandlerGet
819
     *
820
     * @param        $left
821
     * @param        $var
822
     * @param string $obj
823
     * @param string $handler
824
     * @param bool   $isParam
825
     *
826
     * @param string $t
827
     * @return string
828
     */
829
    public function getXcHandlerGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '')
830
    {
831
        if ($isParam) {
832
            $ret = "\${$left}{$handler}->get(\${$var})";
833
        } else {
834
            $ret = "{$t}\${$left}{$obj} = \${$handler}->get(\${$var});\n";
835
        }
836
837
        return $ret;
838
    }
839
840
    /**
841
     * @public function getXcHandler
842
     *
843
     * @param $left
844
     * @param $var
845
     * @param $obj
846
     * @param $handler
847
     *
848
     * @return string
849
     */
850
    public function getXcHandlerInsert($left, $var, $obj = '', $handler = 'Handler')
851
    {
852
        return "\${$left}{$handler}->insert(\${$var}{$obj})";
853
854
    }
855
856
    /**
857
     * @public   function getXcHandlerDelete
858
     *
859
     * @param        $left
860
     * @param        $var
861
     * @param string $obj
862
     * @param string $handler
863
     * @return string
864
     */
865
    public function getXcHandlerDelete($left, $var, $obj = '', $handler = 'Handler')
866
    {
867
        return "\${$left}{$handler}->delete(\${$var}{$obj})";
868
    }
869
870
    /**
871
     * @public function getXcGetValues
872
     *
873
     * @param        $tableName
874
     * @param        $tableSoleName
875
     *
876
     * @param string $index
877
     * @param bool   $noArray
878
     * @param string $t
879
     * @return string
880
     */
881
    public function getXcGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '')
882
    {
883
        $index        = '' !== $index ? $index : 'i';
884
        $ucfTableName = ucfirst($tableName);
885
        if (!$noArray) {
886
            $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
887
        } else {
888
            $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
889
        }
890
891
        return $ret;
892
    }
893
894
    /**
895
     * @public function getXcSetVarsObjects
896
     *
897
     * @param $moduleDirname
898
     * @param $tableName
899
     * @param $tableSoleName
900
     * @param $fields
901
     * @return string
902
     */
903
    public function getXcSetVarsObjects($moduleDirname, $tableName, $tableSoleName, $fields)
904
    {
905
        $axc           = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance();
906
        $ret           = '';
907
        $fieldMain     = '';
908
        $countUploader = 0;
909
        foreach (array_keys($fields) as $f) {
910
            $fieldName    = $fields[$f]->getVar('field_name');
911
            $fieldElement = $fields[$f]->getVar('field_element');
912
            if (1 == $fields[$f]->getVar('field_main')) {
913
                $fieldMain = $fieldName;
914
            }
915
            if ($f > 0) { // If we want to hide field id
916
                switch ($fieldElement) {
917
                    case 5:
918
                    case 6:
919
                        $ret .= $this->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName);
920
                        break;
921
                    case 11:
922
                        $ret .= $axc->getAxcSetVarImageList($tableName, $fieldName, '', $countUploader);
923
                        $countUploader++;
924
                        break;
925
                    case 12:
926
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $countUploader, $fieldMain);
927
                        $countUploader++;
928
                        break;
929
                    case 13:
930
                        $ret .= $axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, '', $countUploader);
931
                        $countUploader++;
932
                        break;
933
                    case 14:
934
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $countUploader, $fieldMain);
935
                        $countUploader++;
936
                        break;
937
                    case 15:
938
                        $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName);
939
                        break;
940
                    default:
941
                        $ret .= $this->getXcSetVarObj($tableName, $fieldName, "\$_POST['{$fieldName}']");
942
                        break;
943
                }
944
            }
945
        }
946
947
        return $ret;
948
    }
949
950
    /**
951
     * @public function getXcSecurity
952
     *
953
     * @param        $tableName
954
     *
955
     * @param string $t
956
     * @return string
957
     */
958
    public function getXcSecurity($tableName, $t = '')
959
    {
960
        $pc              = Modulebuilder\Files\CreatePhpCode::getInstance();
961
        $securityError   = $this->getXcXoopsSecurityErrors();
962
        $implode         = $pc->getPhpCodeImplode(',', $securityError);
963
        $content         = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, $t);
0 ignored issues
show
Bug introduced by
$t of type string is incompatible with the type boolean expected by parameter $isString of XoopsModules\Modulebuild...::getXcRedirectHeader(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

963
        $content         = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, /** @scrutinizer ignore-type */ $t);
Loading history...
964
        $securityCheck   = $this->getXcXoopsSecurityCheck();
965
966
        return $pc->getPhpCodeConditions('!' . $securityCheck, '', '', $content, $t);
967
    }
968
969
    /**
970
     * @public function getXcInsertData
971
     * @param        $tableName
972
     * @param        $language
973
     * @param string $t
974
     * @return string
975
     */
976
    public function getXcInsertData($tableName, $language, $t = '')
977
    {
978
        $pc            = Modulebuilder\Files\CreatePhpCode::getInstance();
979
        $content       = "{$t}\t" . $this->getXcRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
980
        $handlerInsert = $this->getXcHandlerInsert($tableName, $tableName, 'Obj');
981
982
        return $pc->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
983
    }
984
985
    /**
986
     * @public function getXcRedirectHeader
987
     * @param        $directory
988
     * @param        $options
989
     * @param        $numb
990
     * @param        $var
991
     * @param bool   $isString
992
     *
993
     * @param string $t
994
     * @return string
995
     */
996
    public function getXcRedirectHeader($directory, $options, $numb, $var, $isString = true, $t = '')
997
    {
998
        if (!$isString) {
999
            $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n";
1000
        } else {
1001
            $ret = "{$t}redirect_header('{$directory}.php{$options}', {$numb}, {$var});\n";
1002
        }
1003
1004
        return $ret;
1005
    }
1006
1007
    /**
1008
     * @public function getXcXoopsConfirm
1009
     * @param        $tableName
1010
     * @param        $language
1011
     * @param        $fieldId
1012
     * @param        $fieldMain
1013
     * @param string $options
1014
     *
1015
     * @param string $t
1016
     * @return string
1017
     */
1018
    public function getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1019
    {
1020
        $stuOptions = mb_strtoupper($options);
1021
        $ccFieldId  = Modulebuilder\Files\CreateFile::getInstance()->getCamelCase($fieldId, false, true);
1022
        $pc         = Modulebuilder\Files\CreatePhpCode::getInstance();
1023
        $array      = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')";
1024
        $server     = $pc->getPhpCodeGlobalsVariables('REQUEST_URI', 'SERVER');
1025
        $getVar     = $this->getXcGetVar('', $tableName . 'Obj', $fieldMain, true, '');
1026
        $sprintf    = $pc->getPhpCodeSprintf($language . 'FORM_SURE_' . $stuOptions, $getVar);
1027
        $ret        = "{$t}xoops_confirm({$array}, {$server}, {$sprintf});\n";
1028
1029
        return $ret;
1030
    }
1031
1032
    /**
1033
     * @public function getXcHtmlErrors
1034
     *
1035
     * @param        $tableName
1036
     * @param bool   $isParam
1037
     * @param string $obj
1038
     *
1039
     * @param string $t
1040
     * @return string
1041
     */
1042
    public function getXcHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1043
    {
1044
        if ($isParam) {
1045
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1046
        } else {
1047
            $ret = "{$t}\${$tableName}{$obj} = \${$tableName}->getHtmlErrors();";
1048
        }
1049
1050
        return $ret;
1051
    }
1052
1053
    /**
1054
     * @public function getXcGetForm
1055
     *
1056
     * @param        $left
1057
     * @param        $tableName
1058
     * @param string $obj
1059
     *
1060
     * @param string $t
1061
     * @return string
1062
     */
1063
    public function getXcGetForm($left, $tableName, $obj = '', $t = '')
1064
    {
1065
        $ucfTableName = ucfirst($tableName);
1066
1067
        return "{$t}\${$left} = \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1068
    }
1069
1070
    /**
1071
     * @public function getTopicGetVar
1072
     * @param        $lpFieldName
1073
     * @param        $rpFieldName
1074
     * @param        $tableName
1075
     * @param        $tableNameTopic
1076
     * @param        $fieldNameParent
1077
     * @param        $fieldNameTopic
1078
     * @param string $t
1079
     * @return string
1080
     */
1081
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
1082
    {
1083
        $ret      = Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
1084
        $paramGet = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
1085
        $ret      .= $this->getXcHandlerGet($rpFieldName, $paramGet, '', $tableNameTopic . 'Handler', false, $t);
1086
        $ret      .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
1087
1088
        return $ret;
1089
    }
1090
1091
    /**
1092
     * @public function getUploadImageGetVar
1093
     * @param        $lpFieldName
1094
     * @param        $rpFieldName
1095
     * @param        $tableName
1096
     * @param        $fieldName
1097
     * @param string $t
1098
     * @return string
1099
     */
1100
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
1101
    {
1102
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1103
        $ret = $pc->getPhpCodeCommentLine('Get Var', $fieldName, $t);
1104
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
1105
        $ret .= $pc->getPhpCodeTernaryOperator('uploadImage', "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
1106
        $ret .= $this->getXcEqualsOperator("${$lpFieldName}['{$rpFieldName}']", '$uploadImage', null, $t);
1107
1108
        return $ret;
1109
    }
1110
1111
    /**
1112
     * @public function getXcSaveFieldId
1113
     *
1114
     * @param $fields
1115
     *
1116
     * @return string
1117
     */
1118
    public function getXcSaveFieldId($fields)
1119
    {
1120
        $fieldId = '';
1121
        foreach (array_keys($fields) as $f) {
1122
            if (0 == $f) {
1123
                $fieldId = $fields[$f]->getVar('field_name');
1124
            }
1125
        }
1126
1127
        return $fieldId;
1128
    }
1129
1130
    /**
1131
     * @public function getXcSaveFieldMain
1132
     *
1133
     * @param $fields
1134
     *
1135
     * @return string
1136
     */
1137
    public function getXcSaveFieldMain($fields)
1138
    {
1139
        $fieldMain = '';
1140
        foreach (array_keys($fields) as $f) {
1141
            if (1 == $fields[$f]->getVar('field_main')) {
1142
                $fieldMain = $fields[$f]->getVar('field_name');
1143
            }
1144
        }
1145
1146
        return $fieldMain;
1147
    }
1148
1149
    /**
1150
     * @public function getXcSaveElements
1151
     *
1152
     * @param        $moduleDirname
1153
     * @param        $tableName
1154
     * @param        $tableSoleName
1155
     * @param        $fields
1156
     *
1157
     * @param string $t
1158
     * @return string
1159
     */
1160
    public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $fields, $t = '')
1161
    {
1162
        $axc           = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance();
1163
        $ret           = '';
1164
        $fieldMain     = '';
1165
        $countUploader = 0;
1166
        foreach (array_keys($fields) as $f) {
1167
1168
            $fieldName    = $fields[$f]->getVar('field_name');
1169
            $fieldType    = $fields[$f]->getVar('field_type');
1170
            $fieldElement = $fields[$f]->getVar('field_element');
1171
            if (1 == $fields[$f]->getVar('field_main')) {
1172
                $fieldMain = $fieldName;
1173
            }
1174
            if ($f > 0) { // If we want to hide field id
1175
                switch ($fieldElement) {
1176
                    case 5:
1177
                    case 6:
1178
                        $ret .= $this->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName, $t);
1179
                        break;
1180
                    case 10:
1181
                        $ret .= $axc->getAxcSetVarImageList($tableName, $fieldName, $t, $countUploader);
1182
                        $countUploader++;
1183
                        break;
1184
                    case 11:
1185
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain);
1186
                        $countUploader++;
1187
                        break;
1188
                    case 12:
1189
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $t, $countUploader, $fieldMain);
1190
                        $countUploader++;
1191
                        break;
1192
                    case 13:
1193
                        $ret .= $axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, $t, $countUploader);
1194
                        $countUploader++;
1195
                        break;
1196
                    case 14:
1197
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain);
1198
                        $countUploader++;
1199
                        break;
1200
                    case 15:
1201
                        $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName, $t);
1202
                        break;
1203
                    case 17:
1204
                        $ret .= $axc->getAxcSetVarPassword($tableName, $fieldName, $t);
1205
                        $countUploader++;
1206
                        break;
1207
                    case 21:
1208
                        $ret .= $this->getXcSetVarDateTime($tableName, $tableSoleName, $fieldName, $t);
1209
                        break;
1210
                    default:
1211
                        $ret .= $axc->getAxcSetVarMisc($tableName, $fieldName, $fieldType, $fieldElement, $t);
1212
                        break;
1213
                }
1214
            }
1215
        }
1216
1217
        return $ret;
1218
    }
1219
1220
    /**
1221
     * @public function getXcPageNav
1222
     * @param        $tableName
1223
     *
1224
     * @param string $t
1225
     * @param string $paramStart
1226
     * @param string $paramOp
1227
     * @return string
1228
     */
1229
    public function getXcPageNav($tableName, $t = '', $paramStart = 'start', $paramOp = "'op=list&limit=' . \$limit")
1230
    {
1231
        $pc        = Modulebuilder\Files\CreatePhpCode::getInstance();
1232
        $cxc       = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance();
1233
        $ret       = $pc->getPhpCodeCommentLine('Display Navigation', null, $t);
1234
        $condition = $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t");
1235
        $condition .= $cxc->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', $paramStart, $paramOp, false, $t . "\t");
1236
        $condition .= $this->getXcXoopsTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t");
1237
        $ret       .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1238
1239
        return $ret;
1240
    }
1241
1242
    /* @public function getXcGetGlobal
1243
     * @param        $globals
1244
     *
1245
     * @param string $t
1246
     * @return string
1247
     */
1248
    public function getXcGetGlobal($globals, $t = '')
1249
    {
1250
        $ret    = $t . "global ";
1251
        $detail = '';
1252
        foreach ($globals as $global) {
1253
            if ($detail !== '') {
1254
                $detail .= ', ';
1255
            }
1256
            $detail .= '$' . $global;
1257
        }
1258
       $ret .= $detail . ";\n";
1259
1260
        return $ret;
1261
    }
1262
1263
    /**
1264
     * @public function getXcGetCriteriaCompo
1265
     *
1266
     * @param        $var
1267
     * @param string $t
1268
     *
1269
     * @return string
1270
     */
1271
    public function getXcCriteriaCompo($var, $t = '')
1272
    {
1273
        return "{$t}\${$var} = new \CriteriaCompo();\n";
1274
    }
1275
1276
    /**
1277
     * @public function getXcCriteria
1278
     *
1279
     * @param        $var
1280
     * @param        $param1
1281
     * @param string $param2
1282
     * @param string $param3
1283
     * @param bool   $isParam
1284
     * @param string $t
1285
     *
1286
     * @return string
1287
     */
1288
    public function getXcCriteria($var, $param1, $param2 = '', $param3 = '', $isParam = false, $t = '')
1289
    {
1290
        $params = ('' != $param2) ? ', ' . $param2 : '';
1291
        $params .= ('' != $param3) ? ', ' . $param3 : '';
1292
1293
        if (false === $isParam) {
1294
            $ret = "{$t}\${$var} = new \Criteria( {$param1}{$params} );\n";
1295
        } else {
1296
            $ret = "new \Criteria( {$param1}{$params} )";
1297
        }
1298
1299
        return $ret;
1300
    }
1301
1302
    /**
1303
     * @public function getXcCriteriaAdd
1304
     *
1305
     * @param        $var
1306
     * @param        $param
1307
     * @param string $t
1308
     * @param string $n
1309
     * @param string $condition
1310
     * @return string
1311
     */
1312
    public function getXcCriteriaAdd($var, $param, $t = '', $n = "\n", $condition = '')
1313
    {
1314
        if ('' !== $condition) {
1315
            $condition = ", {$condition}";
1316
        }
1317
        return "{$t}\${$var}->add( {$param}{$condition} );{$n}";
1318
    }
1319
1320
    /**
1321
     * @public function getXcCriteriaSetStart
1322
     *
1323
     * @param        $var
1324
     * @param        $start
1325
     * @param string $t
1326
     *
1327
     * @param string $n
1328
     * @return string
1329
     */
1330
    public function getXcCriteriaSetStart($var, $start, $t = '', $n = "\n")
1331
    {
1332
        return "{$t}\${$var}->setStart( {$start} );{$n}";
1333
    }
1334
1335
    /**
1336
     * @public function getXcCriteriaSetLimit
1337
     *
1338
     * @param        $var
1339
     * @param        $limit
1340
     * @param string $t
1341
     *
1342
     * @param string $n
1343
     * @return string
1344
     */
1345
    public function getXcCriteriaSetLimit($var, $limit, $t = '', $n = "\n")
1346
    {
1347
        return "{$t}\${$var}->setLimit( {$limit} );{$n}";
1348
    }
1349
1350
    /**
1351
     * @public function getXcCriteriaSetSort
1352
     *
1353
     * @param        $var
1354
     * @param        $sort
1355
     * @param string $t
1356
     *
1357
     * @param string $n
1358
     * @return string
1359
     */
1360
    public function getXcCriteriaSetSort($var, $sort, $t = '', $n = "\n")
1361
    {
1362
        return "{$t}\${$var}->setSort( {$sort} );{$n}";
1363
    }
1364
1365
    /**
1366
     * @public function getXcCriteriaSetOrder
1367
     *
1368
     * @param        $var
1369
     * @param        $order
1370
     * @param string $t
1371
     *
1372
     * @param string $n
1373
     * @return string
1374
     */
1375
    public function getXcCriteriaSetOrder($var, $order, $t = '', $n = "\n")
1376
    {
1377
        return "{$t}\${$var}->setOrder( {$order} );{$n}";
1378
    }
1379
1380
    /*************************************************************/
1381
    /** Xoops form components */
1382
    /*************************************************************/
1383
1384
    /**
1385
     * @public function getXcXoopsFormGroupPerm
1386
     * @param $varLeft
1387
     * @param $formTitle
1388
     * @param $moduleId
1389
     * @param $permName
1390
     * @param $permDesc
1391
     * @param $filename
1392
     * @param $t
1393
     *
1394
     * @return string
1395
     */
1396
    public function getXcXoopsFormGroupPerm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '')
1397
    {
1398
        return "{$t}\${$varLeft} = new \XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
1399
    }
1400
1401
1402
    /**
1403
     * @public function getXoopsFormSelectExtraOptions
1404
     * @param string $varSelect
1405
     * @param string $caption
1406
     * @param string $var
1407
     * @param array  $options
1408
     * @param bool   $setExtra
1409
     *
1410
     * @param string $t
1411
     * @return string
1412
     */
1413
    public function getXoopsFormSelectExtraOptions($varSelect = '', $caption = '', $var = '', $options = [], $setExtra = true, $t = '')
1414
    {
1415
        $ret = "{$t}\${$varSelect} = new \XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
1416
        if (false !== $setExtra) {
1417
            $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n";
1418
        }
1419
        foreach ($options as $key => $value) {
1420
            $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n";
1421
        }
1422
1423
        return $ret;
1424
    }
1425
1426
1427
    /*************************************************************/
1428
    /** special components */
1429
    /*************************************************************/
1430
    /**
1431
     * @public function getXcGetConstants
1432
     * @param null
1433
     * @return string
1434
     */
1435
    public function getXcGetConstants($const)
1436
    {
1437
        $ret = "Constants::{$const}";
1438
        return $ret;
1439
    }
1440
1441
    /*************************************************************/
1442
    /** other Xoops components */
1443
    /*************************************************************/
1444
1445
1446
    /**
1447
     * @public function getXcXoopsCPHeader
1448
     * @param null
1449
     * @return string
1450
     */
1451
    public function getXcXoopsCPHeader()
1452
    {
1453
        return "xoops_cp_header();\n";
1454
    }
1455
1456
    /**
1457
     * @public function getXcXoopsCPFooter
1458
     * @param null
1459
     * @return string
1460
     */
1461
    public function getXcXoopsCPFooter()
1462
    {
1463
        return "xoops_cp_footer();\n";
1464
    }
1465
1466
    /**
1467
     * @public function getXcXoopsLoad
1468
     *
1469
     * @param $var
1470
     * @param $t
1471
     * @return string
1472
     */
1473
    public function getXcXoopsLoad($var = '', $t = '')
1474
    {
1475
        return "{$t}xoops_load('{$var}');\n";
1476
    }
1477
1478
    /**
1479
     * @public function getXcXoopsLoadLanguage
1480
     *
1481
     * @param $lang
1482
     * @param $t
1483
     * @param $domain
1484
     *
1485
     * @return string
1486
     */
1487
    public function getXcXoopsLoadLanguage($lang, $t = '', $domain = '')
1488
    {
1489
        if ('' === $domain) {
1490
            return "{$t}xoops_loadLanguage('{$lang}');\n";
1491
        }
1492
1493
        return "{$t}xoops_loadLanguage('{$lang}', '{$domain}');\n";
1494
    }
1495
1496
    /**
1497
     * @public function getXcXoopsCaptcha
1498
     * @param $t
1499
     * @return string
1500
     */
1501
    public function getXcXoopsCaptcha($t = '')
1502
    {
1503
        return "{$t}\$xoopsCaptcha = \XoopsCaptcha::getInstance();\n";
1504
    }
1505
1506
    /**
1507
     * @public function getXcXoopsListImgListArray
1508
     * @param $return
1509
     * @param $var
1510
     * @param $t
1511
     *
1512
     * @return string
1513
     */
1514
    public function getXcXoopsListImgListArray($return, $var, $t = '')
1515
    {
1516
        return "{$t}\${$return} = \XoopsLists::getImgListAsArray( {$var} );\n";
1517
    }
1518
1519
    /**
1520
     * @public function getXcXoopsListLangList
1521
     * @param $return
1522
     * @param string $t
1523
     *
1524
     * @return string
1525
     */
1526
    public function getXcXoopsListLangList($return, $t = '')
1527
    {
1528
        return "{$t}\${$return} = \XoopsLists::getLangList();\n";
1529
    }
1530
1531
    /**
1532
     * @public function getXcXoopsListCountryList
1533
     * @param $return
1534
     * @param string $t
1535
     *
1536
     * @return string
1537
     */
1538
    public function getXcXoopsListCountryList($return, $t = '')
1539
    {
1540
        return "{$t}\${$return} = \XoopsLists::getCountryList();\n";
1541
    }
1542
1543
    /**
1544
     * @public function getXcXoopsUserUnameFromId
1545
     * @param        $left
1546
     * @param        $value
1547
     * @param string $t
1548
     *
1549
     * @return string
1550
     */
1551
    public function getXcXoopsUserUnameFromId($left, $value, $t = '')
1552
    {
1553
        return "{$t}\${$left} = \XoopsUser::getUnameFromId({$value});\n";
1554
    }
1555
1556
    /**
1557
     * @public function getXcXoopsTplAssign
1558
     *
1559
     * @param        $tplString
1560
     * @param        $phpRender
1561
     * @param bool   $leftIsString
1562
     *
1563
     * @param string $t
1564
     * @return string
1565
     */
1566
    public function getXcXoopsTplAssign($tplString, $phpRender, $leftIsString = true, $t = '')
1567
    {
1568
        $assign = "{$t}\$GLOBALS['xoopsTpl']->assign(";
1569
        if (false === $leftIsString) {
1570
            $ret = $assign . "{$tplString}, {$phpRender});\n";
1571
        } else {
1572
            $ret = $assign . "'{$tplString}', {$phpRender});\n";
1573
        }
1574
1575
        return $ret;
1576
    }
1577
1578
    /**
1579
     * @public function getXcXoopsTplAppend
1580
     *
1581
     * @param        $tplString
1582
     * @param        $phpRender
1583
     *
1584
     * @param string $t
1585
     * @return string
1586
     */
1587
    public function getXcXoopsTplAppend($tplString, $phpRender, $t = '')
1588
    {
1589
        return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
1590
    }
1591
1592
    /**
1593
     * @public function getXcXoopsTplAppendByRef
1594
     *
1595
     * @param        $tplString
1596
     * @param        $phpRender
1597
     *
1598
     * @param string $t
1599
     * @return string
1600
     */
1601
    public function getXcXoopsTplAppendByRef($tplString, $phpRender, $t = '')
1602
    {
1603
        return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
1604
    }
1605
1606
    /**
1607
     * @public function getXcXoopsTplDisplay
1608
     *
1609
     * @param string $displayTpl
1610
     * @param string $t
1611
     * @param bool   $usedoublequotes
1612
     * @return string
1613
     */
1614
    public function getXcXoopsTplDisplay($displayTpl = '{$templateMain}', $t = '', $usedoublequotes = true)
1615
    {
1616
        if ($usedoublequotes) {
1617
            return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n";
1618
        }
1619
1620
        return "{$t}\$GLOBALS['xoopsTpl']->display('db:" . $displayTpl . "');\n";
1621
    }
1622
1623
    /**
1624
     * @public function getXcXoopsPath
1625
     *
1626
     * @param        $directory
1627
     * @param        $filename
1628
     * @param bool   $isParam
1629
     *
1630
     * @param string $t
1631
     * @return string
1632
     */
1633
    public function getXcXoopsPath($directory, $filename, $isParam = false, $t = '')
1634
    {
1635
        if (!$isParam) {
1636
            $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
1637
        } else {
1638
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
1639
        }
1640
1641
        return $ret;
1642
    }
1643
1644
    /**
1645
     * @public function getXcXoopsModuleGetInfo
1646
     *
1647
     * @param        $left
1648
     * @param        $string
1649
     * @param bool   $isParam
1650
     *
1651
     * @param string $t
1652
     * @return string
1653
     */
1654
    public function getXcXoopsModuleGetInfo($left, $string, $isParam = false, $t = '')
1655
    {
1656
        if (!$isParam) {
1657
            $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
1658
        } else {
1659
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
1660
        }
1661
1662
        return $ret;
1663
    }
1664
1665
1666
    /**
1667
     * @public function getXcXoThemeAddStylesheet
1668
     * @param string $style
1669
     *
1670
     * @param string $t
1671
     * @return string
1672
     */
1673
    public function getXcXoThemeAddStylesheet($style = 'style', $t = '')
1674
    {
1675
        return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n";
1676
    }
1677
1678
    /**
1679
     * @public function getXcXoopsSecurityCheck
1680
     * @param $denial
1681
     * @return bool
1682
     */
1683
    public function getXcXoopsSecurityCheck($denial = '')
1684
    {
1685
        return "{$denial}\$GLOBALS['xoopsSecurity']->check()";
0 ignored issues
show
Bug Best Practice introduced by
The expression return $denial.'\$GLOBAL...opsSecurity']->check()' returns the type string which is incompatible with the documented return type boolean.
Loading history...
1686
    }
1687
1688
    /**
1689
     * @public function getXcXoopsSecurityErrors
1690
     * @param null
1691
     * @return string
1692
     */
1693
    public function getXcXoopsSecurityErrors()
1694
    {
1695
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1696
    }
1697
1698
    /**
1699
     * @public function getXcXoopsHandler
1700
     * @param        $left
1701
     * @param string $t
1702
     * @param string $n
1703
     * @return string
1704
     */
1705
    public function getXcXoopsHandler($left, $t = '', $n = "\n")
1706
    {
1707
        return "{$t}\${$left}Handler = xoops_getHandler('{$left}');{$n}";
1708
    }
1709
1710
1711
    /*************************************************************/
1712
    /** common components for user and admin pages */
1713
    /*************************************************************/
1714
1715
    /**
1716
     * @public  function getXcCommonPagesEdit
1717
     * @param        $tableName
1718
     * @param        $ccFieldId
1719
     * @param string $t
1720
     * @return string
1721
     */
1722
    public function getXcCommonPagesEdit($tableName, $ccFieldId, $t = '')
1723
    {
1724
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1725
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
1726
1727
        $ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t");
1728
        $ret .= $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', false, $t);
1729
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
1730
        $ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
1731
1732
        return $ret;
1733
    }
1734
1735
    /**
1736
     * @public  function getXcCommonPagesNew
1737
     * @param        $tableName
1738
     * @param string $t
1739
     * @return string
1740
     */
1741
    public function getXcCommonPagesNew($tableName, $t = '')
1742
    {
1743
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1744
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
1745
1746
        $ret = $pc->getPhpCodeCommentLine('Form Create', null, $t);
1747
        $ret .= $xc->getXcHandlerCreateObj($tableName, $t);
1748
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
1749
        $ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
1750
1751
        return $ret;
1752
    }
1753
1754
    /**
1755
     * @public function getXcCommonPagesDelete
1756
     * @param        $language
1757
     * @param        $tableName
1758
     * @param $tableSoleName
1759
     * @param        $fieldId
1760
     * @param        $fieldMain
1761
     * @param $tableNotifications
1762
     * @param string $t
1763
     * @param bool $admin
1764
     * @return string
1765
     */
1766
    public function getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t = '', $admin = false)
1767
    {
1768
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
1769
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
1770
        $cf = Modulebuilder\Files\CreateFile::getInstance();
1771
1772
        $ccFieldId    = $cf->getCamelCase($fieldId, false, true);
1773
        $stuFieldMain = mb_strtoupper($fieldMain);
1774
        $ccFieldMain  = $cf->getCamelCase($fieldMain, false, true);
1775
1776
        $ret                  = $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', '', $t);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type boolean expected by parameter $isParam of XoopsModules\Modulebuild...Code::getXcHandlerGet(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1776
        $ret                  = $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', /** @scrutinizer ignore-type */ '', $t);
Loading history...
1777
        $ret                  .= $xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t);
1778
        $reqOk                = "_REQUEST['ok']";
1779
        $isset                = $pc->getPhpCodeIsset($reqOk);
1780
        $xoopsSecurityCheck   = $xc->getXcXoopsSecurityCheck();
1781
        $xoopsSecurityErrors  = $xc->getXcXoopsSecurityErrors();
1782
        $implode              = $pc->getPhpCodeImplode(', ', $xoopsSecurityErrors);
1783
        $redirectHeaderErrors = $xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t\t");
1784
        $delete               = $xc->getXcHandlerDelete($tableName, $tableName, 'Obj', 'Handler');
1785
        $condition            = $pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectHeaderErrors, false, $t . "\t");
1786
        $contInsert = '';
1787
        if (!$admin && 1 == $tableNotifications) {
1788
            $contInsert .= $pc->getPhpCodeCommentLine('Event delete notification', null, $t . "\t\t");
1789
            $contInsert .= $pc->getPhpCodeArray('tags', [], false, $t . "\t\t");
1790
            $contInsert .= $xc->getXcEqualsOperator("\$tags['{$stuFieldMain}']", "\${$ccFieldMain}", '', $t . "\t\t");
1791
            $contInsert .= $xc->getXcXoopsHandler('notification', $t . "\t\t");
1792
            $contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_delete', \$tags);", $t . "\t\t");
1793
            $contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \${$ccFieldId}, '{$tableSoleName}_delete', \$tags);", $t . "\t\t");
1794
        }
1795
        $contInsert   .= $xc->getXcRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK", true, $t . "\t\t");
1796
        $htmlErrors   = $xc->getXcHtmlErrors($tableName, true);
1797
        $internalElse = $xc->getXcXoopsTplAssign('error', $htmlErrors, true, $t . "\t\t");
1798
        $condition    .= $pc->getPhpCodeConditions($delete, '', '', $contInsert, $internalElse, $t . "\t");
1799
        $mainElse     = $xc->getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, 'delete', $t . "\t");
1800
        $ret          .= $pc->getPhpCodeConditions($isset, ' && ', "1 == \${$reqOk}", $condition, $mainElse, $t);
1801
1802
        return $ret;
1803
    }
1804
}
1805