CreateXoopsCode::getXcSecurity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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