Passed
Push — master ( edcc70...e1cde6 )
by Goffy
05:15
created

CreateXoopsCode::getUploadImageGetVar()   A

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

611
                $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, /** @scrutinizer ignore-type */ '', '', $countUploader);
Loading history...
612
                $countUploader++;
613
            } elseif (15 == $fieldElement) {
614
                $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName);
615
            } else {
616
                $ret .= $this->getXcSetVarObj($tableName, $fieldName, "\$_POST['{$fieldName}']");
617
            }
618
        }
619
620
        return $ret;
621
    }
622
623
    /**
624
     * @public function getXcXoopsRequest
625
     * @param string $left
626
     * @param string $var1
627
     * @param string $var2
628
     * @param string $type
629
     * @param bool   $method
630
     * @param string $t
631
     * @return string
632
     */
633
    public function getXcXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $method = false, $t = '')
634
    {
635
        $ret     = '';
636
        $intVars = ('' != $var2) ? "'{$var1}', {$var2}" : "'{$var1}'";
637
        if ('String' === $type) {
638
            $ret .= "{$t}\${$left} = Request::getString('{$var1}', '{$var2}');\n";
639
        } elseif ('Int' === $type) {
640
            $ret .= "{$t}\${$left} = Request::getInt({$intVars});\n";
641
        } elseif ('Int' === $type && false !== $method) {
642
            $ret .= "{$t}\${$left} = Request::getInt({$intVars}, '{$method}');\n";
643
        } else {
644
            $ret .= "{$t}\${$left} = Request::get{$type}('{$var1}', '{$var2}');\n";
645
        }
646
647
        return $ret;
648
    }
649
650
    /**
651
     * @public function getXcAddRight
652
     *
653
     * @param        $anchor
654
     * @param string $permString
655
     * @param string $var
656
     * @param string $groups
657
     * @param string $mid
658
     * @param bool   $isParam
659
     *
660
     * @param string $t
661
     * @return string
662
     */
663
    public function getXcAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
664
    {
665
        if (!$isParam) {
666
            $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n";
667
        } else {
668
            $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})";
669
        }
670
671
        return $ret;
672
    }
673
674
    /**
675
     * @public function getXcCheckRight
676
     *
677
     * @param        $anchor
678
     * @param string $permString
679
     * @param string $var
680
     * @param string $groups
681
     * @param string $mid
682
     * @param bool   $isParam
683
     *
684
     * @param string $t
685
     * @return string
686
     */
687
    public function getXcCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '')
688
    {
689
        if (!$isParam) {
690
            $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n";
691
        } else {
692
            $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})";
693
        }
694
695
        return $ret;
696
    }
697
698
    /**
699
     * @public function getXcAddRight
700
     *
701
     * @param        $anchor
702
     * @param string $permString
703
     * @param string $mid
704
     * @param string $var
705
     * @param bool $isParam
706
     *
707
     * @param string $t
708
     * @return string
709
     */
710
    public function getXcDeleteRight($anchor, $permString = '', $mid = '', $var = '', $isParam = false, $t = '')
711
    {
712
        if (!$isParam) {
713
            $ret = "{$t}\${$anchor}->deleteByModule({$mid}, '{$permString}', {$var});\n";
714
        } else {
715
            $ret = "\${$anchor}->deleteByModule({$mid}, '{$permString}', {$var})";
716
        }
717
        return $ret;
718
    }
719
720
    /**
721
     * @public function getXcHandlerLine
722
     * @param $tableName
723
     * @param string $t
724
     * @return string
725
     */
726
    public function getXcHandlerLine($tableName, $t = '')
727
    {
728
        $ucfTableName = ucfirst($tableName);
729
        return "{$t}\${$tableName}Handler = \$helper->getHandler('{$ucfTableName}');\n";
730
    }
731
732
    /**
733
     * @public function getXcHandlerCreateObj
734
     *
735
     * @param        $tableName
736
     *
737
     * @param string $t
738
     * @return string
739
     */
740
    public function getXcHandlerCreateObj($tableName, $t = '')
741
    {
742
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->create();\n";
743
    }
744
745
    /**
746
     * @public function getXcHandlerGetObj
747
     *
748
     * @param        $tableName
749
     * @param        $ccFieldId
750
     * @param string $t
751
     * @return string
752
     */
753
    public function getXcHandlerGetObj($tableName, $ccFieldId, $t = '')
754
    {
755
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->get(\${$ccFieldId});\n";
756
    }
757
758
    /**
759
     * @public function getXcHandlerCountObj
760
     *
761
     * @param        $tableName
762
     *
763
     * @param string $t
764
     * @return string
765
     */
766
    public function getXcHandlerCountObj($tableName, $t = '')
767
    {
768
        $ucfTableName = ucfirst($tableName);
769
        $ret          = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n";
770
771
        return $ret;
772
    }
773
774
    /**
775
     * @public function getXcClearCount
776
     * @param  $left
777
     * @param  $anchor
778
     * @param  $params
779
     * @param  $t
780
     *
781
     * @return string
782
     */
783
    public function getXcHandlerCountClear($left, $anchor = '', $params = '', $t = '')
784
    {
785
        $ret = "{$t}\${$left} = \${$anchor}Handler->getCount({$params});\n";
786
787
        return $ret;
788
    }
789
790
    /**
791
     * @public function getXcHandlerAllObj
792
     *
793
     * @param        $tableName
794
     * @param string $fieldMain
795
     * @param string $start
796
     * @param string $limit
797
     *
798
     * @param string $t
799
     * @return string
800
     */
801
    public function getXcHandlerAllObj($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '')
802
    {
803
        $ucfTableName = ucfirst($tableName);
804
        $startLimit   = ('0' != $limit) ? "{$start}, {$limit}" : '0';
805
        $params       = ('' != $fieldMain) ? "{$startLimit}, '{$fieldMain}'" : $startLimit;
806
        $ret          = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n";
807
808
        return $ret;
809
    }
810
811
    /**
812
     * @public function getXcHandlerAllClear
813
     * @param        $left
814
     * @param string $anchor
815
     * @param string $params
816
     * @param string $t
817
     * @return string
818
     */
819
    public function getXcHandlerAllClear($left, $anchor = '', $params = '', $t = '')
820
    {
821
        $ret = "{$t}\${$left} = \${$anchor}Handler->getAll({$params});\n";
822
823
        return $ret;
824
    }
825
826
    /**
827
     * @public function getXcHandlerGet
828
     *
829
     * @param        $left
830
     * @param        $var
831
     * @param string $obj
832
     * @param string $handler
833
     * @param bool   $isParam
834
     *
835
     * @param string $t
836
     * @return string
837
     */
838
    public function getXcHandlerGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '')
839
    {
840
        if ($isParam) {
841
            $ret = "\${$left}{$handler}->get(\${$var})";
842
        } else {
843
            $ret = "{$t}\${$left}{$obj} = \${$handler}->get(\${$var});\n";
844
        }
845
846
        return $ret;
847
    }
848
849
    /**
850
     * @public function getXcHandler
851
     *
852
     * @param $left
853
     * @param $var
854
     * @param $obj
855
     * @param $handler
856
     *
857
     * @return string
858
     */
859
    public function getXcHandlerInsert($left, $var, $obj = '', $handler = 'Handler')
860
    {
861
        return "\${$left}{$handler}->insert(\${$var}{$obj})";
862
863
    }
864
865
    /**
866
     * @public   function getXcHandlerDelete
867
     *
868
     * @param        $left
869
     * @param        $var
870
     * @param string $obj
871
     * @param string $handler
872
     * @return string
873
     */
874
    public function getXcHandlerDelete($left, $var, $obj = '', $handler = 'Handler')
875
    {
876
        return "\${$left}{$handler}->delete(\${$var}{$obj})";
877
    }
878
879
    /**
880
     * @public function getXcGetValues
881
     *
882
     * @param        $tableName
883
     * @param        $tableSoleName
884
     *
885
     * @param string $index
886
     * @param bool   $noArray
887
     * @param string $t
888
     * @return string
889
     */
890
    public function getXcGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '')
891
    {
892
        $index        = '' !== $index ? $index : 'i';
893
        $ucfTableName = ucfirst($tableName);
894
        if (!$noArray) {
895
            $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n";
896
        } else {
897
            $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n";
898
        }
899
900
        return $ret;
901
    }
902
903
    /**
904
     * @public function getXcSetVarsObjects
905
     *
906
     * @param $moduleDirname
907
     * @param $tableName
908
     * @param $tableSoleName
909
     * @param $fields
910
     * @return string
911
     */
912
    public function getXcSetVarsObjects($moduleDirname, $tableName, $tableSoleName, $fields)
913
    {
914
        $axc           = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance();
915
        $ret           = '';
916
        $fieldMain     = '';
917
        $countUploader = 0;
918
        foreach (array_keys($fields) as $f) {
919
            $fieldName    = $fields[$f]->getVar('field_name');
920
            $fieldElement = $fields[$f]->getVar('field_element');
921
            if (1 == $fields[$f]->getVar('field_main')) {
922
                $fieldMain = $fieldName;
923
            }
924
            if ($f > 0) { // If we want to hide field id
925
                switch ($fieldElement) {
926
                    case 5:
927
                    case 6:
928
                        $ret .= $this->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName);
929
                        break;
930
                    case 11:
931
                        $ret .= $axc->getAxcSetVarImageList($tableName, $fieldName, '', $countUploader);
932
                        $countUploader++;
933
                        break;
934
                    case 12:
935
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $countUploader, $fieldMain);
936
                        $countUploader++;
937
                        break;
938
                    case 13:
939
                        $ret .= $axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, '', $countUploader);
940
                        $countUploader++;
941
                        break;
942
                    case 14:
943
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $countUploader, $fieldMain);
944
                        $countUploader++;
945
                        break;
946
                    case 15:
947
                        $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName);
948
                        break;
949
                    default:
950
                        $ret .= $this->getXcSetVarObj($tableName, $fieldName, "\$_POST['{$fieldName}']");
951
                        break;
952
                }
953
            }
954
        }
955
956
        return $ret;
957
    }
958
959
    /**
960
     * @public function getXcSecurity
961
     *
962
     * @param        $tableName
963
     *
964
     * @param string $t
965
     * @return string
966
     */
967
    public function getXcSecurity($tableName, $t = '')
968
    {
969
        $pc              = Modulebuilder\Files\CreatePhpCode::getInstance();
970
        $securityError   = $this->getXcXoopsSecurityErrors();
971
        $implode         = $pc->getPhpCodeImplode(',', $securityError);
972
        $content         = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, false, $t);
973
        $securityCheck   = $this->getXcXoopsSecurityCheck();
974
975
        return $pc->getPhpCodeConditions('!' . $securityCheck, '', '', $content, $t);
976
    }
977
978
    /**
979
     * @public function getXcInsertData
980
     * @param        $tableName
981
     * @param        $language
982
     * @param string $t
983
     * @return string
984
     */
985
    public function getXcInsertData($tableName, $language, $t = '')
986
    {
987
        $pc            = Modulebuilder\Files\CreatePhpCode::getInstance();
988
        $content       = "{$t}\t" . $this->getXcRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK");
989
        $handlerInsert = $this->getXcHandlerInsert($tableName, $tableName, 'Obj');
990
991
        return $pc->getPhpCodeConditions($handlerInsert, '', '', $content, $t);
992
    }
993
994
    /**
995
     * @public function getXcRedirectHeader
996
     * @param        $directory
997
     * @param        $options
998
     * @param        $numb
999
     * @param        $var
1000
     * @param bool   $isString
1001
     * @param string $t
1002
     * @return string
1003
     */
1004
    public function getXcRedirectHeader($directory, $options, $numb, $var, $isString = true, $t = '')
1005
    {
1006
        if (!$isString) {
1007
            $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n";
1008
        } else {
1009
            $ret = "{$t}redirect_header('{$directory}.php{$options}', {$numb}, {$var});\n";
1010
        }
1011
1012
        return $ret;
1013
    }
1014
1015
    /**
1016
     * @public function getXcXoopsConfirm
1017
     * @param        $tableName
1018
     * @param        $language
1019
     * @param        $fieldId
1020
     * @param        $fieldMain
1021
     * @param string $options
1022
     *
1023
     * @param string $t
1024
     * @return string
1025
     */
1026
    public function getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '')
1027
    {
1028
        $stuOptions = mb_strtoupper($options);
1029
        $ccFieldId  = Modulebuilder\Files\CreateFile::getInstance()->getCamelCase($fieldId, false, true);
1030
        $pc         = Modulebuilder\Files\CreatePhpCode::getInstance();
1031
        $xc         = Modulebuilder\Files\CreateXoopsCode::getInstance();
1032
1033
        $array   = "['ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}']";
1034
        $server  = $pc->getPhpCodeGlobalsVariables('REQUEST_URI', 'SERVER');
1035
        $getVar  = $this->getXcGetVar('', $tableName . 'Obj', $fieldMain, true, '');
1036
        $sprintf = $pc->getPhpCodeSprintf($language . 'FORM_SURE_' . $stuOptions, $getVar);
1037
        $confirm = 'new Common\XoopsConfirm(' . "\n";
1038
        $confirm .= $t . "\t" . $array . ",\n";
1039
        $confirm .= $t . "\t" . $server . ",\n";
1040
        $confirm .= $t . "\t" . $sprintf . ')';
1041
        $ret     = $xc->getXcEqualsOperator('$xoopsconfirm', $confirm, '', $t);
1042
        $ret     .= $xc->getXcEqualsOperator('$form', '$xoopsconfirm->getFormXoopsConfirm()', '', $t);
1043
        $ret     .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
1044
        return $ret;
1045
    }
1046
1047
    /**
1048
     * @public function getXcHtmlErrors
1049
     *
1050
     * @param        $tableName
1051
     * @param bool   $isParam
1052
     * @param string $obj
1053
     *
1054
     * @param string $t
1055
     * @return string
1056
     */
1057
    public function getXcHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '')
1058
    {
1059
        if ($isParam) {
1060
            $ret = "\${$tableName}{$obj}->getHtmlErrors()";
1061
        } else {
1062
            $ret = "{$t}\${$tableName}{$obj} = \${$tableName}->getHtmlErrors();";
1063
        }
1064
1065
        return $ret;
1066
    }
1067
1068
    /**
1069
     * @public function getXcGetForm
1070
     *
1071
     * @param        $left
1072
     * @param        $tableName
1073
     * @param string $obj
1074
     *
1075
     * @param string $t
1076
     * @return string
1077
     */
1078
    public function getXcGetForm($left, $tableName, $obj = '', $t = '')
1079
    {
1080
        $ucfTableName = ucfirst($tableName);
1081
1082
        return "{$t}\${$left} = \${$tableName}{$obj}->getForm{$ucfTableName}();\n";
1083
    }
1084
1085
    /**
1086
     * @public function getTopicGetVar
1087
     * @param        $lpFieldName
1088
     * @param        $rpFieldName
1089
     * @param        $tableName
1090
     * @param        $tableNameTopic
1091
     * @param        $fieldNameParent
1092
     * @param        $fieldNameTopic
1093
     * @param string $t
1094
     * @return string
1095
     */
1096
    public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '')
1097
    {
1098
        $ret      = Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t);
1099
        $paramGet = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, '');
1100
        $ret      .= $this->getXcHandlerGet($rpFieldName, $paramGet, '', $tableNameTopic . 'Handler', false, $t);
1101
        $ret      .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t);
1102
1103
        return $ret;
1104
    }
1105
1106
    /**
1107
     * @public function getUploadImageGetVar
1108
     * @param        $lpFieldName
1109
     * @param        $rpFieldName
1110
     * @param        $tableName
1111
     * @param        $fieldName
1112
     * @param string $t
1113
     * @return string
1114
     */
1115
    /*
1116
    public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '')
1117
    {
1118
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1119
        $ret = $pc->getPhpCodeCommentLine('Get Var', $fieldName, $t);
1120
        $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, '');
1121
        $ret .= $pc->getPhpCodeTernaryOperator('uploadImage', "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t);
1122
        $ret .= $this->getXcEqualsOperator("${$lpFieldName}['{$rpFieldName}']", '$uploadImage', null, $t);
1123
1124
        return $ret;
1125
    }
1126
    */
1127
1128
    /**
1129
     * @public function getXcSaveFieldId
1130
     *
1131
     * @param $fields
1132
     *
1133
     * @return string
1134
     */
1135
    public function getXcSaveFieldId($fields)
1136
    {
1137
        $fieldId = '';
1138
        foreach (array_keys($fields) as $f) {
1139
            if (0 == $f) {
1140
                $fieldId = $fields[$f]->getVar('field_name');
1141
            }
1142
        }
1143
1144
        return $fieldId;
1145
    }
1146
1147
    /**
1148
     * @public function getXcSaveFieldMain
1149
     *
1150
     * @param $fields
1151
     *
1152
     * @return string
1153
     */
1154
    public function getXcSaveFieldMain($fields)
1155
    {
1156
        $fieldMain = '';
1157
        foreach (array_keys($fields) as $f) {
1158
            if (1 == $fields[$f]->getVar('field_main')) {
1159
                $fieldMain = $fields[$f]->getVar('field_name');
1160
            }
1161
        }
1162
1163
        return $fieldMain;
1164
    }
1165
1166
    /**
1167
     * @public function getXcSaveElements
1168
     *
1169
     * @param        $moduleDirname
1170
     * @param        $tableName
1171
     * @param        $tableSoleName
1172
     * @param        $fields
1173
     *
1174
     * @param string $t
1175
     * @return string
1176
     */
1177
    public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $fields, $t = '')
1178
    {
1179
        $axc           = Modulebuilder\Files\Admin\AdminXoopsCode::getInstance();
1180
        $ret           = '';
1181
        $fieldMain     = '';
1182
        $countUploader = 0;
1183
        foreach (array_keys($fields) as $f) {
1184
1185
            $fieldName    = $fields[$f]->getVar('field_name');
1186
            $fieldType    = $fields[$f]->getVar('field_type');
1187
            $fieldElement = $fields[$f]->getVar('field_element');
1188
            if (1 == $fields[$f]->getVar('field_main')) {
1189
                $fieldMain = $fieldName;
1190
            }
1191
            if ($f > 0) { // If we want to hide field id
1192
                switch ($fieldElement) {
1193
                    case 5:
1194
                    case 6:
1195
                        $ret .= $this->getXcSetVarCheckBoxOrRadioYN($tableName, $fieldName, $t);
1196
                        break;
1197
                    case 10:
1198
                        $ret .= $axc->getAxcSetVarImageList($tableName, $fieldName, $t, $countUploader);
1199
                        $countUploader++;
1200
                        break;
1201
                    case 11:
1202
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain);
1203
                        $countUploader++;
1204
                        break;
1205
                    case 12:
1206
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, true, $t, $countUploader, $fieldMain);
1207
                        $countUploader++;
1208
                        break;
1209
                    case 13:
1210
                        $ret .= $axc->getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, $t, $countUploader);
1211
                        $countUploader++;
1212
                        break;
1213
                    case 14:
1214
                        $ret .= $axc->getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, false, $t, $countUploader, $fieldMain);
1215
                        $countUploader++;
1216
                        break;
1217
                    case 15:
1218
                        $ret .= $this->getXcSetVarTextDateSelect($tableName, $tableSoleName, $fieldName, $t);
1219
                        break;
1220
                    case 17:
1221
                        $ret .= $axc->getAxcSetVarPassword($tableName, $fieldName, $t);
1222
                        $countUploader++;
1223
                        break;
1224
                    case 21:
1225
                        $ret .= $this->getXcSetVarDateTime($tableName, $tableSoleName, $fieldName, $t);
1226
                        break;
1227
                    default:
1228
                        $ret .= $axc->getAxcSetVarMisc($tableName, $fieldName, $fieldType, $fieldElement, $t);
1229
                        break;
1230
                }
1231
            }
1232
        }
1233
1234
        return $ret;
1235
    }
1236
1237
    /**
1238
     * @public function getXcPageNav
1239
     * @param        $tableName
1240
     *
1241
     * @param string $t
1242
     * @param string $paramStart
1243
     * @param string $paramOp
1244
     * @return string
1245
     */
1246
    public function getXcPageNav($tableName, $t = '', $paramStart = 'start', $paramOp = "'op=list&limit=' . \$limit")
1247
    {
1248
        $pc        = Modulebuilder\Files\CreatePhpCode::getInstance();
1249
        $cxc       = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance();
1250
        $ret       = $pc->getPhpCodeCommentLine('Display Navigation', null, $t);
1251
        $condition = $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t");
1252
        $condition .= $cxc->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', $paramStart, $paramOp, false, $t . "\t");
1253
        $condition .= $this->getXcXoopsTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t");
1254
        $ret       .= $pc->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t);
1255
1256
        return $ret;
1257
    }
1258
1259
    /* @public function getXcGetGlobal
1260
     * @param        $globals
1261
     *
1262
     * @param string $t
1263
     * @return string
1264
     */
1265
    public function getXcGetGlobal($globals, $t = '')
1266
    {
1267
        $ret    = $t . "global ";
1268
        $detail = '';
1269
        foreach ($globals as $global) {
1270
            if ($detail !== '') {
1271
                $detail .= ', ';
1272
            }
1273
            $detail .= '$' . $global;
1274
        }
1275
       $ret .= $detail . ";\n";
1276
1277
        return $ret;
1278
    }
1279
1280
    /**
1281
     * @public function getXcGetCriteriaCompo
1282
     *
1283
     * @param        $var
1284
     * @param string $t
1285
     *
1286
     * @return string
1287
     */
1288
    public function getXcCriteriaCompo($var, $t = '')
1289
    {
1290
        return "{$t}\${$var} = new \CriteriaCompo();\n";
1291
    }
1292
1293
    /**
1294
     * @public function getXcCriteria
1295
     *
1296
     * @param        $var
1297
     * @param        $param1
1298
     * @param string $param2
1299
     * @param string $param3
1300
     * @param bool   $isParam
1301
     * @param string $t
1302
     *
1303
     * @return string
1304
     */
1305
    public function getXcCriteria($var, $param1, $param2 = '', $param3 = '', $isParam = false, $t = '')
1306
    {
1307
        $params = ('' != $param2) ? ', ' . $param2 : '';
1308
        $params .= ('' != $param3) ? ', ' . $param3 : '';
1309
1310
        if (false === $isParam) {
1311
            $ret = "{$t}\${$var} = new \Criteria({$param1}{$params});\n";
1312
        } else {
1313
            $ret = "new \Criteria({$param1}{$params})";
1314
        }
1315
1316
        return $ret;
1317
    }
1318
1319
    /**
1320
     * @public function getXcCriteriaAdd
1321
     *
1322
     * @param        $var
1323
     * @param        $param
1324
     * @param string $t
1325
     * @param string $n
1326
     * @param string $condition
1327
     * @return string
1328
     */
1329
    public function getXcCriteriaAdd($var, $param, $t = '', $n = "\n", $condition = '')
1330
    {
1331
        if ('' !== $condition) {
1332
            $condition = ", {$condition}";
1333
        }
1334
        return "{$t}\${$var}->add({$param}{$condition});{$n}";
1335
    }
1336
1337
    /**
1338
     * @public function getXcCriteriaSetStart
1339
     *
1340
     * @param        $var
1341
     * @param        $start
1342
     * @param string $t
1343
     *
1344
     * @param string $n
1345
     * @return string
1346
     */
1347
    public function getXcCriteriaSetStart($var, $start, $t = '', $n = "\n")
1348
    {
1349
        return "{$t}\${$var}->setStart({$start});{$n}";
1350
    }
1351
1352
    /**
1353
     * @public function getXcCriteriaSetLimit
1354
     *
1355
     * @param        $var
1356
     * @param        $limit
1357
     * @param string $t
1358
     *
1359
     * @param string $n
1360
     * @return string
1361
     */
1362
    public function getXcCriteriaSetLimit($var, $limit, $t = '', $n = "\n")
1363
    {
1364
        return "{$t}\${$var}->setLimit({$limit});{$n}";
1365
    }
1366
1367
    /**
1368
     * @public function getXcCriteriaSetSort
1369
     *
1370
     * @param        $var
1371
     * @param        $sort
1372
     * @param string $t
1373
     *
1374
     * @param string $n
1375
     * @return string
1376
     */
1377
    public function getXcCriteriaSetSort($var, $sort, $t = '', $n = "\n")
1378
    {
1379
        return "{$t}\${$var}->setSort({$sort});{$n}";
1380
    }
1381
1382
    /**
1383
     * @public function getXcCriteriaSetOrder
1384
     *
1385
     * @param        $var
1386
     * @param        $order
1387
     * @param string $t
1388
     *
1389
     * @param string $n
1390
     * @return string
1391
     */
1392
    public function getXcCriteriaSetOrder($var, $order, $t = '', $n = "\n")
1393
    {
1394
        return "{$t}\${$var}->setOrder({$order});{$n}";
1395
    }
1396
1397
    /*************************************************************/
1398
    /** Xoops form components */
1399
    /*************************************************************/
1400
1401
    /**
1402
     * @public function getXcXoopsFormGroupPerm
1403
     * @param $varLeft
1404
     * @param $formTitle
1405
     * @param $moduleId
1406
     * @param $permName
1407
     * @param $permDesc
1408
     * @param $filename
1409
     * @param $t
1410
     *
1411
     * @return string
1412
     */
1413
    public function getXcXoopsFormGroupPerm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '')
1414
    {
1415
        return "{$t}\${$varLeft} = new \XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n";
1416
    }
1417
1418
1419
    /**
1420
     * @public function getXoopsFormSelectExtraOptions
1421
     * @param string $varSelect
1422
     * @param string $caption
1423
     * @param string $var
1424
     * @param array  $options
1425
     * @param bool   $setExtra
1426
     *
1427
     * @param string $t
1428
     * @return string
1429
     */
1430
    public function getXoopsFormSelectExtraOptions($varSelect = '', $caption = '', $var = '', $options = [], $setExtra = true, $t = '')
1431
    {
1432
        $ret = "{$t}\${$varSelect} = new \XoopsFormSelect({$caption}, '{$var}', \${$var});\n";
1433
        if (false !== $setExtra) {
1434
            $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n";
1435
        }
1436
        foreach ($options as $key => $value) {
1437
            $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n";
1438
        }
1439
1440
        return $ret;
1441
    }
1442
1443
1444
    /*************************************************************/
1445
    /** special components */
1446
    /*************************************************************/
1447
    /**
1448
     * @public function getXcGetConstants
1449
     * @param null
1450
     * @return string
1451
     */
1452
    public function getXcGetConstants($const)
1453
    {
1454
        $ret = "Constants::{$const}";
1455
        return $ret;
1456
    }
1457
1458
    /*************************************************************/
1459
    /** other Xoops components */
1460
    /*************************************************************/
1461
1462
1463
    /**
1464
     * @public function getXcXoopsCPHeader
1465
     * @param null
1466
     * @return string
1467
     */
1468
    public function getXcXoopsCPHeader()
1469
    {
1470
        return "xoops_cp_header();\n";
1471
    }
1472
1473
    /**
1474
     * @public function getXcXoopsCPFooter
1475
     * @param null
1476
     * @return string
1477
     */
1478
    public function getXcXoopsCPFooter()
1479
    {
1480
        return "xoops_cp_footer();\n";
1481
    }
1482
1483
    /**
1484
     * @public function getXcXoopsLoad
1485
     *
1486
     * @param $var
1487
     * @param $t
1488
     * @return string
1489
     */
1490
    public function getXcXoopsLoad($var = '', $t = '')
1491
    {
1492
        return "{$t}xoops_load('{$var}');\n";
1493
    }
1494
1495
    /**
1496
     * @public function getXcXoopsLoadLanguage
1497
     *
1498
     * @param $lang
1499
     * @param $t
1500
     * @param $domain
1501
     *
1502
     * @return string
1503
     */
1504
    public function getXcXoopsLoadLanguage($lang, $t = '', $domain = '')
1505
    {
1506
        if ('' === $domain) {
1507
            return "{$t}xoops_loadLanguage('{$lang}');\n";
1508
        }
1509
1510
        return "{$t}xoops_loadLanguage('{$lang}', '{$domain}');\n";
1511
    }
1512
1513
    /**
1514
     * @public function getXcXoopsCaptcha
1515
     * @param $t
1516
     * @return string
1517
     */
1518
    public function getXcXoopsCaptcha($t = '')
1519
    {
1520
        return "{$t}\$xoopsCaptcha = \XoopsCaptcha::getInstance();\n";
1521
    }
1522
1523
    /**
1524
     * @public function getXcXoopsListImgListArray
1525
     * @param $return
1526
     * @param $var
1527
     * @param $t
1528
     *
1529
     * @return string
1530
     */
1531
    public function getXcXoopsListImgListArray($return, $var, $t = '')
1532
    {
1533
        return "{$t}\${$return} = \XoopsLists::getImgListAsArray( {$var} );\n";
1534
    }
1535
1536
    /**
1537
     * @public function getXcXoopsListLangList
1538
     * @param $return
1539
     * @param string $t
1540
     *
1541
     * @return string
1542
     */
1543
    public function getXcXoopsListLangList($return, $t = '')
1544
    {
1545
        return "{$t}\${$return} = \XoopsLists::getLangList();\n";
1546
    }
1547
1548
    /**
1549
     * @public function getXcXoopsListCountryList
1550
     * @param $return
1551
     * @param string $t
1552
     *
1553
     * @return string
1554
     */
1555
    public function getXcXoopsListCountryList($return, $t = '')
1556
    {
1557
        return "{$t}\${$return} = \XoopsLists::getCountryList();\n";
1558
    }
1559
1560
    /**
1561
     * @public function getXcXoopsUserUnameFromId
1562
     * @param        $left
1563
     * @param        $value
1564
     * @param string $t
1565
     *
1566
     * @return string
1567
     */
1568
    public function getXcXoopsUserUnameFromId($left, $value, $t = '')
1569
    {
1570
        return "{$t}\${$left} = \XoopsUser::getUnameFromId({$value});\n";
1571
    }
1572
1573
    /**
1574
     * @public function getXcXoopsTplAssign
1575
     *
1576
     * @param        $tplString
1577
     * @param        $phpRender
1578
     * @param bool   $leftIsString
1579
     *
1580
     * @param string $t
1581
     * @return string
1582
     */
1583
    public function getXcXoopsTplAssign($tplString, $phpRender, $leftIsString = true, $t = '')
1584
    {
1585
        $assign = "{$t}\$GLOBALS['xoopsTpl']->assign(";
1586
        if (false === $leftIsString) {
1587
            $ret = $assign . "{$tplString}, {$phpRender});\n";
1588
        } else {
1589
            $ret = $assign . "'{$tplString}', {$phpRender});\n";
1590
        }
1591
1592
        return $ret;
1593
    }
1594
1595
    /**
1596
     * @public function getXcXoopsTplAppend
1597
     *
1598
     * @param        $tplString
1599
     * @param        $phpRender
1600
     *
1601
     * @param string $t
1602
     * @return string
1603
     */
1604
    public function getXcXoopsTplAppend($tplString, $phpRender, $t = '')
1605
    {
1606
        return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n";
1607
    }
1608
1609
    /**
1610
     * @public function getXcXoopsTplAppendByRef
1611
     *
1612
     * @param        $tplString
1613
     * @param        $phpRender
1614
     *
1615
     * @param string $t
1616
     * @return string
1617
     */
1618
    public function getXcXoopsTplAppendByRef($tplString, $phpRender, $t = '')
1619
    {
1620
        return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n";
1621
    }
1622
1623
    /**
1624
     * @public function getXcXoopsTplDisplay
1625
     *
1626
     * @param string $displayTpl
1627
     * @param string $t
1628
     * @param bool   $usedoublequotes
1629
     * @return string
1630
     */
1631
    public function getXcXoopsTplDisplay($displayTpl = '{$templateMain}', $t = '', $usedoublequotes = true)
1632
    {
1633
        if ($usedoublequotes) {
1634
            return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n";
1635
        }
1636
1637
        return "{$t}\$GLOBALS['xoopsTpl']->display('db:" . $displayTpl . "');\n";
1638
    }
1639
1640
    /**
1641
     * @public function getXcXoopsPath
1642
     *
1643
     * @param        $directory
1644
     * @param        $filename
1645
     * @param bool   $isParam
1646
     *
1647
     * @param string $t
1648
     * @return string
1649
     */
1650
    public function getXcXoopsPath($directory, $filename, $isParam = false, $t = '')
1651
    {
1652
        if (!$isParam) {
1653
            $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n";
1654
        } else {
1655
            $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')";
1656
        }
1657
1658
        return $ret;
1659
    }
1660
1661
    /**
1662
     * @public function getXcXoopsModuleGetInfo
1663
     *
1664
     * @param        $left
1665
     * @param        $string
1666
     * @param bool   $isParam
1667
     *
1668
     * @param string $t
1669
     * @return string
1670
     */
1671
    public function getXcXoopsModuleGetInfo($left, $string, $isParam = false, $t = '')
1672
    {
1673
        if (!$isParam) {
1674
            $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n";
1675
        } else {
1676
            $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')";
1677
        }
1678
1679
        return $ret;
1680
    }
1681
1682
1683
    /**
1684
     * @public function getXcXoThemeAddStylesheet
1685
     * @param string $style
1686
     *
1687
     * @param string $t
1688
     * @param bool $isString
1689
     * @return string
1690
     */
1691
    public function getXcXoThemeAddStylesheet($style = 'style', $t = '', $isString = true)
1692
    {
1693
        $ret = "{$t}\$GLOBALS['xoTheme']->addStylesheet(";
1694
        if ($isString) {
1695
            $ret .= '$';
1696
        }
1697
        $ret .= "{$style}, null);\n";
1698
        return $ret;
1699
    }
1700
1701
    /**
1702
     * @public function getXcXoopsSecurityCheck
1703
     * @param $denial
1704
     * @return bool
1705
     */
1706
    public function getXcXoopsSecurityCheck($denial = '')
1707
    {
1708
        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...
1709
    }
1710
1711
    /**
1712
     * @public function getXcXoopsSecurityErrors
1713
     * @param null
1714
     * @return string
1715
     */
1716
    public function getXcXoopsSecurityErrors()
1717
    {
1718
        return "\$GLOBALS['xoopsSecurity']->getErrors()";
1719
    }
1720
1721
    /**
1722
     * @public function getXcXoopsHandler
1723
     * @param        $left
1724
     * @param string $t
1725
     * @param string $n
1726
     * @return string
1727
     */
1728
    public function getXcXoopsHandler($left, $t = '', $n = "\n")
1729
    {
1730
        return "{$t}\${$left}Handler = xoops_getHandler('{$left}');{$n}";
1731
    }
1732
1733
1734
    /*************************************************************/
1735
    /** common components for user and admin pages */
1736
    /*************************************************************/
1737
1738
    /**
1739
     * @public  function getXcCommonPagesEdit
1740
     * @param        $tableName
1741
     * @param        $ccFieldId
1742
     * @param string $t
1743
     * @return string
1744
     */
1745
    public function getXcCommonPagesEdit($tableName, $ccFieldId, $t = '')
1746
    {
1747
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1748
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
1749
1750
        $ret = $pc->getPhpCodeCommentLine('Get Form', null, "\t\t");
1751
        $ret .= $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', false, $t);
1752
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
1753
        $ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
1754
1755
        return $ret;
1756
    }
1757
1758
    /**
1759
     * @public  function getXcCommonPagesNew
1760
     * @param        $tableName
1761
     * @param string $t
1762
     * @return string
1763
     */
1764
    public function getXcCommonPagesNew($tableName, $t = '')
1765
    {
1766
        $pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
1767
        $xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
1768
1769
        $ret = $pc->getPhpCodeCommentLine('Form Create', null, $t);
1770
        $ret .= $xc->getXcHandlerCreateObj($tableName, $t);
1771
        $ret .= $xc->getXcGetForm('form', $tableName, 'Obj', $t);
1772
        $ret .= $xc->getXcXoopsTplAssign('form', '$form->render()', true, $t);
1773
1774
        return $ret;
1775
    }
1776
1777
    /**
1778
     * @public function getXcCommonPagesDelete
1779
     * @param        $language
1780
     * @param        $tableName
1781
     * @param $tableSoleName
1782
     * @param        $fieldId
1783
     * @param        $fieldMain
1784
     * @param $tableNotifications
1785
     * @param string $t
1786
     * @param bool $admin
1787
     * @return string
1788
     */
1789
    public function getXcCommonPagesDelete($language, $tableName, $tableSoleName, $fieldId, $fieldMain, $tableNotifications, $t = '', $admin = false)
1790
    {
1791
        $pc = Modulebuilder\Files\CreatePhpCode::getInstance();
1792
        $xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
1793
        $cf = Modulebuilder\Files\CreateFile::getInstance();
1794
1795
        $ccFieldId    = $cf->getCamelCase($fieldId, false, true);
1796
        $ccFieldMain  = $cf->getCamelCase($fieldMain, false, true);
1797
1798
        $ret                  = $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', false, $t);
1799
        $ret                  .= $xc->getXcGetVar($ccFieldMain, "{$tableName}Obj", $fieldMain, false, $t);
1800
        $reqOk                = "_REQUEST['ok']";
1801
        $isset                = $pc->getPhpCodeIsset($reqOk);
1802
        $xoopsSecurityCheck   = $xc->getXcXoopsSecurityCheck();
1803
        $xoopsSecurityErrors  = $xc->getXcXoopsSecurityErrors();
1804
        $implode              = $pc->getPhpCodeImplode(', ', $xoopsSecurityErrors);
1805
        $redirectHeaderErrors = $xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t\t");
1806
        $delete               = $xc->getXcHandlerDelete($tableName, $tableName, 'Obj', 'Handler');
1807
        $condition            = $pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectHeaderErrors, false, $t . "\t");
1808
        $contInsert = '';
1809
        if (!$admin && 1 == $tableNotifications) {
1810
            $contInsert .= $pc->getPhpCodeCommentLine('Event delete notification', null, $t . "\t\t");
1811
            $contInsert .= $pc->getPhpCodeArray('tags', [], false, $t . "\t\t");
1812
            $contInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t\t");
1813
            $contInsert .= $xc->getXcXoopsHandler('notification', $t . "\t\t");
1814
            $contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_delete', \$tags);", $t . "\t\t");
1815
            $contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \${$ccFieldId}, '{$tableSoleName}_delete', \$tags);", $t . "\t\t");
1816
        }
1817
        $contInsert   .= $xc->getXcRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK", true, $t . "\t\t");
1818
        $htmlErrors   = $xc->getXcHtmlErrors($tableName, true);
1819
        $internalElse = $xc->getXcXoopsTplAssign('error', $htmlErrors, true, $t . "\t\t");
1820
        $condition    .= $pc->getPhpCodeConditions($delete, '', '', $contInsert, $internalElse, $t . "\t");
1821
        $mainElse     = $xc->getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, 'delete', $t . "\t");
1822
        $ret          .= $pc->getPhpCodeConditions($isset, ' && ', "1 == \${$reqOk}", $condition, $mainElse, $t);
1823
1824
        return $ret;
1825
    }
1826
}
1827