Issues (314)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/Files/Classes/ClassFiles.php (1 issue)

Severity
1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\Classes;
4
5
use XoopsModules\Modulebuilder;
6
use XoopsModules\Modulebuilder\Files;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 */
17
/**
18
 * tc module.
19
 *
20
 * @copyright       XOOPS Project (https://xoops.org)
21
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
22
 *
23
 * @since           2.5.0
24
 *
25
 * @author          Txmod Xoops https://xoops.org 
26
 *                  Goffy https://myxoops.org
27
 *
28
 */
29
30
/**
31
 * Class ClassFiles.
32
 */
33
class ClassFiles extends Files\CreateFile
34
{
35
36
    /**
37
     * @var mixed
38
     */
39
    private $cxc = null;
40
41
    /**
42
     * @var mixed
43
     */
44
    private $xc = null;
45
46
    /**
47
     * @var mixed
48
     */
49
    private $pc = null;
50
51
    /**
52
     * @var mixed
53
     */
54
    private $helper = null;
55
56
    /**
57
     * @public function constructor
58
     * @param null
59
     */
60
    public function __construct()
61
    {
62
        parent::__construct();
63
        $this->xc     = Modulebuilder\Files\CreateXoopsCode::getInstance();
64
        $this->pc     = Modulebuilder\Files\CreatePhpCode::getInstance();
65
        $this->cxc    = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance();
66
        $this->helper = Modulebuilder\Helper::getInstance();
67
    }
68
69
    /**
70
     * @static function getInstance
71
     *
72
     * @param null
73
     *
74
     * @return ClassFiles
75
     */
76
    public static function getInstance()
77
    {
78
        static $instance = false;
79
        if (!$instance) {
80
            $instance = new self();
81
        }
82
83
        return $instance;
84
    }
85
86
    /**
87
     * @public function write
88
     *
89
     * @param string $module
90
     * @param string $table
91
     * @param mixed  $tables
92
     * @param        $filename
93
     */
94
    public function write($module, $table, $tables, $filename)
95
    {
96
        $this->setModule($module);
97
        $this->setTable($table);
98
        $this->setTables($tables);
99
        $this->setFileName($filename);
100
    }
101
102
    /**
103
     * @private function getInitVar
104
     *
105
     * @param string $fieldName
106
     * @param string $type
107
     *
108
     * @return string
109
     */
110
    private function getInitVar($fieldName, $type = 'INT')
111
    {
112
113
        return $this->cxc->getClassInitVar($fieldName, $type);
114
115
    }
116
117
    /**
118
     * @private function getInitVars
119
     *
120
     * @param array $fields
121
     *
122
     * @return string
123
     */
124
    private function getInitVars($fields)
125
    {
126
        $ret = '';
127
        // Creation of the initVar functions list
128
        foreach (\array_keys($fields) as $f) {
129
            $fieldName = $fields[$f]->getVar('field_name');
130
            $fieldType = $fields[$f]->getVar('field_type');
131
            switch ($fieldType) {
132
                case 2:
133
                case 3:
134
                case 4:
135
                case 5:
136
                    $ret .= $this->getInitVar($fieldName, 'INT');
137
                    break;
138
                case 6:
139
                    $ret .= $this->getInitVar($fieldName, 'FLOAT');
140
                    break;
141
                case 7:
142
                case 8:
143
                    $ret .= $this->getInitVar($fieldName, 'DECIMAL');
144
                    break;
145
                case 10:
146
                    $ret .= $this->getInitVar($fieldName, 'ENUM');
147
                    break;
148
                case 11:
149
                    $ret .= $this->getInitVar($fieldName, 'EMAIL');
150
                    break;
151
                case 12:
152
                    $ret .= $this->getInitVar($fieldName, 'URL');
153
                    break;
154
                case 13:
155
                case 14:
156
                    $ret .= $this->getInitVar($fieldName, 'TXTBOX');
157
                    break;
158
                case 15:
159
                case 16:
160
                case 17:
161
                case 18:
162
                    if ((int)$fields[$f]->getVar('field_element') == 4) {
163
                        $ret .= $this->getInitVar($fieldName, 'OTHER');
164
                    } else {
165
                        $ret .= $this->getInitVar($fieldName, 'TXTAREA');
166
                    }
167
                    break;
168
                case 19:
169
                case 20:
170
                case 21:
171
                case 22:
172
                case 23:
173
                    $ret .= $this->getInitVar($fieldName, 'LTIME');
174
                    break;
175
            }
176
        }
177
178
        return $ret;
179
    }
180
181
    /**
182
     * @private  function getClassObject
183
     * @param $module
184
     * @param $table
185
     * @param $fields
186
     * @return string
187
     */
188
    private function getClassObject($module, $table, $fields)
189
    {
190
        $moduleDirname    = $module->getVar('mod_dirname');
191
        $tableName        = $table->getVar('table_name');
192
        $ucfTableName     = \ucfirst($tableName);
193
        $ret              = $this->pc->getPhpCodeDefined();
194
        $ret              .= $this->pc->getPhpCodeCommentMultiLine(['Class Object' => $ucfTableName]);
195
        $cCl              = '';
196
197
        $fieldInForm      = [];
198
        $fieldElementId   = [];
199
        $optionsFieldName = [];
200
        $fieldUpload      = false;
201
        $fieldId          = null;
202
        foreach (\array_keys($fields) as $f) {
203
            $fieldName        = $fields[$f]->getVar('field_name');
204
            $fieldElement     = $fields[$f]->getVar('field_element');
205
            $fieldInForm[]    = $fields[$f]->getVar('field_inform');
206
            $fieldElements    = $this->helper->getHandler('Fieldelements')->get($fieldElement);
207
            $fieldElementId[] = $fieldElements->getVar('fieldelement_id');
208
            if (13 == $fieldElements->getVar('fieldelement_id') || 14 == $fieldElements->getVar('fieldelement_id')) {
209
                //13: UploadImage, 14: UploadFile
210
                $fieldUpload = true;
211
            }
212
            $rpFieldName      = $this->getRightString($fieldName);
213
            if (\in_array(5, $fieldElementId)) {
214
                //if (\count($rpFieldName) % 5) {
215
                    //$optionsFieldName[] = "'" . $rpFieldName . "'";
216
                //} else {
217
                    $optionsFieldName[] = "'" . $rpFieldName . "'\n";
218
                //}
219
            }
220
            if ((0 == $f) && (1 == $table->getVar('table_autoincrement'))) {
221
                $fieldId = $fieldName;
222
            }
223
        }
224
        if (\in_array(5, $fieldElementId) > 1) {
225
            $cCl             .= $this->pc->getPhpCodeCommentMultiLine(['Options' => '']);
226
            $options         = $this->pc->getPhpCodeArray('', $optionsFieldName, true);
227
            $cCl             .= $this->pc->getPhpCodeVariableClass('private', 'options', $options);
228
        }
229
        unset($optionsFieldName);
230
        $cCl              .= $this->pc->getPhpCodeCommentMultiLine(['@var' => 'int'], "\t");
231
        $cCl              .= $this->pc->getPhpCodeVariableClass('public', 'start', '0', "\t");
232
        $cCl              .= $this->pc->getPhpCodeCommentMultiLine(['@var' => 'int'], "\t");
233
        $cCl              .= $this->pc->getPhpCodeVariableClass('public', 'limit', '0', "\t");
234
        $cCl              .= $this->pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t");
235
        $constr           = $this->getInitVars($fields);
236
        $cCl              .= $this->pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t");
237
        $arrayGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null'];
238
        $cCl              .= $this->pc->getPhpCodeCommentMultiLine($arrayGetInstance, "\t");
239
        $getInstance      = $this->pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t");
240
        $instance         = $this->xc->getXcEqualsOperator('$instance', 'new self()', null, "\t\t\t");
241
        $getInstance      .= $this->pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t");
242
        $cCl              .= $this->pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t");
243
244
        $cCl .= $this->getNewInsertId($table);
245
        $cCl .= $this->getFunctionForm($module, $table, $fieldId, $fieldInForm, $fieldUpload);
246
        $cCl .= $this->getValuesInObject($moduleDirname, $table, $fields);
247
        $cCl .= $this->getToArrayInObject($table);
248
249
        if (\in_array(5, $fieldElementId) > 1) {
250
            $cCl .= $this->getOptionsCheck($table);
251
        }
252
        unset($fieldElementId);
253
254
        $ret .= $this->pc->getPhpCodeClass($ucfTableName, $cCl, '\XoopsObject');
255
256
        return $ret;
257
    }
258
259
    /**
260
     * @private function getNewInsertId
261
     *
262
     * @param $table
263
     *
264
     * @return string
265
     */
266
    private function getNewInsertId($table)
267
    {
268
        $tableName     = $table->getVar('table_name');
269
        $ucfTableName  = \ucfirst($tableName);
270
        $ret           = $this->pc->getPhpCodeCommentMultiLine(['The new inserted' => '$Id', '@return' => 'inserted id'], "\t");
271
        $getInsertedId = $this->xc->getXcEqualsOperator('$newInsertedId', "\$GLOBALS['xoopsDB']->getInsertId()", null, "\t\t");
272
        $getInsertedId .= $this->getSimpleString('return $newInsertedId;', "\t\t");
273
274
        $ret .= $this->pc->getPhpCodeFunction('getNewInsertedId' . $ucfTableName, '', $getInsertedId, 'public ', false, "\t");
275
276
        return $ret;
277
    }
278
279
    /**
280
     * @private function getFunctionForm
281
     *
282
     * @param string $module
283
     * @param string $table
284
     * @param        $fieldId
285
     * @param        $fieldInForm
286
     * @param        $fieldUpload
287
     * @return string
288
     */
289
    private function getFunctionForm($module, $table, $fieldId, $fieldInForm, $fieldUpload)
290
    {
291
        $fe               = ClassFormElements::getInstance();
292
        $moduleDirname    = $module->getVar('mod_dirname');
293
        $tableName        = $table->getVar('table_name');
294
        $tableSoleName    = $table->getVar('table_solename');
295
        $tableCategory    = $table->getVar('table_category');
0 ignored issues
show
The assignment to $tableCategory is dead and can be removed.
Loading history...
296
        $ucfTableName     = \ucfirst($tableName);
297
        $stuTableSoleName = \mb_strtoupper($tableSoleName);
298
        $language         = $this->getLanguage($moduleDirname, 'AM');
299
        $fe->initForm($module, $table);
300
        $ret              = $this->pc->getPhpCodeCommentMultiLine(['@public function' => 'getForm', '@param bool' => '$action', '@return' => '\XoopsThemeForm'], "\t");
301
        $action           = $this->xc->getXcEqualsOperator('$action', "\$_SERVER['REQUEST_URI']", null, "\t\t\t");
302
        $ucfModuleDirname = \ucfirst($moduleDirname);
303
        $getForm          = $this->xc->getXcGetInstance('helper', "\XoopsModules\\{$ucfModuleDirname}\Helper", "\t\t");
304
        $getForm          .= $this->pc->getPhpCodeConditions('!', '', '$action', $action, false, "\t\t");
305
        $xUser            = $this->pc->getPhpCodeGlobals('xoopsUser');
306
        $xModule          = $this->pc->getPhpCodeGlobals('xoopsModule');
307
        $getForm          .= $this->xc->getXcEqualsOperator('$isAdmin', $xUser . '->isAdmin(' . $xModule . '->mid())', null, "\t\t");
308
        if ($fieldUpload) {
309
            $permString = 'upload_groups';
310
            $getForm          .= $this->pc->getPhpCodeCommentLine('Permissions for', 'uploader', "\t\t");
311
            $getForm          .= $this->xc->getXcXoopsHandler('groupperm', "\t\t");
312
            $getForm          .= $this->pc->getPhpCodeTernaryOperator('groups', '\is_object(' . $xUser . ')', $xUser . '->getGroups()', '\XOOPS_GROUP_ANONYMOUS', "\t\t");
313
            $checkRight       = $this->xc->getXcCheckRight('$grouppermHandler', $permString, 32, '$groups', $xModule . '->getVar(\'mid\')', true);
314
            $getForm  .= $this->pc->getPhpCodeTernaryOperator('permissionUpload', $checkRight, 'true', 'false', "\t\t");
315
        }
316
        $getForm .= $this->pc->getPhpCodeCommentLine('Title', '', "\t\t");
317
        $getForm .= $this->pc->getPhpCodeTernaryOperator('title', '$this->isNew()', "\sprintf({$language}{$stuTableSoleName}_ADD)", "\sprintf({$language}{$stuTableSoleName}_EDIT)", "\t\t");
318
        $getForm .= $this->pc->getPhpCodeCommentLine('Get Theme', 'Form', "\t\t");
319
        $getForm .= $this->xc->getXcXoopsLoad('XoopsFormLoader', "\t\t");
320
        $getForm .= $this->cxc->getClassXoopsThemeForm('form', 'title', 'form', 'action', 'post');
321
        $getForm .= $this->cxc->getClassSetExtra('form', "'enctype=\"multipart/form-data\"'");
322
        $getForm .= $fe->renderElements();
323
324
        if (\in_array(1, $fieldInForm)) {
325
            if (1 == $table->getVar('table_permissions')) {
326
                $getForm .= $this->getPermissionsInForm($moduleDirname, $fieldId, $tableName);
327
            }
328
        }
329
        $getForm .= $this->pc->getPhpCodeCommentLine('To Save', '', "\t\t");
330
        //$hiddenSave = $cc->getClassXoopsFormHidden('', "'op'", "'save'", true, false);
331
        $getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormHidden('op', 'save')");
332
        $getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormHidden('start', \$this->start)");
333
        $getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormHidden('limit', \$this->limit)");
334
        $getForm .= $this->cxc->getClassAddElement('form', "new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false)");
335
        $getForm .= $this->getSimpleString('return $form;', "\t\t");
336
337
        $ret .= $this->pc->getPhpCodeFunction('getForm' . $ucfTableName, '$action = false', $getForm, 'public ', false, "\t");
338
339
        return $ret;
340
    }
341
342
    /**
343
     * @private function getPermissionsInForm
344
     *
345
     * @param string $moduleDirname
346
     * @param string $fieldId
347
     *
348
     * @param $tableName
349
     * @return string
350
     */
351
    private function getPermissionsInForm($moduleDirname, $fieldId, $tableName)
352
    {
353
        $permissionApprove = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_APPROVE');
354
        $permissionSubmit  = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_SUBMIT');
355
        $permissionView    = $this->getLanguage($moduleDirname, 'AM', 'PERMISSIONS_VIEW');
356
        $ret               = $this->pc->getPhpCodeCommentLine('Permissions', '', "\t\t");
357
        $ret               .= $this->xc->getXcXoopsHandler('member', "\t\t");
358
        $ret               .= $this->xc->getXcEqualsOperator('$groupList', '$memberHandler->getGroupList()', null, "\t\t");
359
        $ret               .= $this->xc->getXcXoopsHandler('groupperm',  "\t\t");
360
        $ret               .= $this->pc->getPhpCodeArrayType('fullList', 'keys', 'groupList', null, false, "\t\t");
361
        $fId               = $this->xc->getXcGetVar('', 'this', $fieldId, true);
362
        $mId               = $this->xc->getXcGetVar('', "GLOBALS['xoopsModule']", 'mid', true);
363
        $contElse          = $this->xc->getXcGetGroupIds('groupsIdsApprove', 'grouppermHandler', "'{$moduleDirname}_approve_{$tableName}'", $fId, $mId, "\t\t\t");
364
        $contElse          .= $this->pc->getPhpCodeArrayType('groupsIdsApprove', 'values', 'groupsIdsApprove', null, false, "\t\t\t");
365
        $contElse          .= $this->cxc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, "groups_approve_{$tableName}[]", '$groupsIdsApprove', false, "\t\t\t");
366
        $contElse          .= $this->xc->getXcGetGroupIds('groupsIdsSubmit', 'grouppermHandler', "'{$moduleDirname}_submit_{$tableName}'", $fId, $mId, "\t\t\t");
367
        $contElse          .= $this->pc->getPhpCodeArrayType('groupsIdsSubmit', 'values', 'groupsIdsSubmit', null, false, "\t\t\t");
368
        $contElse          .= $this->cxc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, "groups_submit_{$tableName}[]", '$groupsIdsSubmit', false, "\t\t\t");
369
        $contElse          .= $this->xc->getXcGetGroupIds('groupsIdsView', 'grouppermHandler', "'{$moduleDirname}_view_{$tableName}'", $fId, $mId, "\t\t\t");
370
        $contElse          .= $this->pc->getPhpCodeArrayType('groupsIdsView', 'values', 'groupsIdsView', null, false, "\t\t\t");
371
        $contElse          .= $this->cxc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, "groups_view_{$tableName}[]", '$groupsIdsView', false, "\t\t\t");
372
373
        $contIf = $this->cxc->getClassXoopsFormCheckBox('groupsCanApproveCheckbox', $permissionApprove, "groups_approve_{$tableName}[]", '$fullList', false, "\t\t\t");
374
        $contIf .= $this->cxc->getClassXoopsFormCheckBox('groupsCanSubmitCheckbox', $permissionSubmit, "groups_submit_{$tableName}[]", '$fullList', false, "\t\t\t");
375
        $contIf .= $this->cxc->getClassXoopsFormCheckBox('groupsCanViewCheckbox', $permissionView, "groups_view_{$tableName}[]", '$fullList', false, "\t\t\t");
376
377
        $ret .= $this->pc->getPhpCodeConditions('$this->isNew()', null, null, $contIf, $contElse, "\t\t");
378
        $ret .= $this->pc->getPhpCodeCommentLine('To Approve', '', "\t\t");
379
        $ret .= $this->cxc->getClassAddOptionArray('groupsCanApproveCheckbox', '$groupList');
380
        $ret .= $this->cxc->getClassAddElement('form', '$groupsCanApproveCheckbox');
381
        $ret .= $this->pc->getPhpCodeCommentLine('To Submit', '', "\t\t");
382
        $ret .= $this->cxc->getClassAddOptionArray('groupsCanSubmitCheckbox', '$groupList');
383
        $ret .= $this->cxc->getClassAddElement('form', '$groupsCanSubmitCheckbox');
384
        $ret .= $this->pc->getPhpCodeCommentLine('To View', '', "\t\t");
385
        $ret .= $this->cxc->getClassAddOptionArray('groupsCanViewCheckbox', '$groupList');
386
        $ret .= $this->cxc->getClassAddElement('form', '$groupsCanViewCheckbox');
387
388
        return $ret;
389
    }
390
391
    /**
392
     * @private  function getValuesInObject
393
     *
394
     * @param $moduleDirname
395
     * @param $table
396
     * @param $fields
397
     * @return string
398
     * @internal param $null
399
     */
400
    private function getValuesInObject($moduleDirname, $table, $fields)
401
    {
402
        $ucfTableName     = \ucfirst($table->getVar('table_name'));
403
        $ret              = $this->pc->getPhpCodeCommentMultiLine(['Get' => 'Values', '@param null $keys' => '', '@param null $format' => '', '@param null $maxDepth' => '', '@return' => 'array'], "\t");
404
        $ucfModuleDirname = \ucfirst($moduleDirname);
405
        $language         = $this->getLanguage($moduleDirname, 'AM');
406
        $getValues        = $this->xc->getXcEqualsOperator('$ret', '$this->getValues($keys, $format, $maxDepth)', null, "\t\t");
407
        $tablePermissions = $table->getVar('table_permissions');
408
        $tableBroken      = $table->getVar('table_broken');
409
        $fieldMainTopic   = null;
410
        $helper           = 0;
411
        $utility          = 0;
412
        $header           = '';
413
        $configMaxchar    = 0;
414
        $lenMaxName       = 0;
415
        foreach (\array_keys($fields) as $f) {
416
            $fieldName = $fields[$f]->getVar('field_name');
417
            $rpFieldName  = $this->getRightString($fieldName);
418
            $len = \strlen($rpFieldName);
419
            if (3 == $fields[$f]->getVar('field_element') || 4 == $fields[$f]->getVar('field_element')) {
420
                $len = $len + \strlen('_short');
421
            }
422
            $lenMaxName = max($len, $lenMaxName);
423
        }
424
        foreach (\array_keys($fields) as $f) {
425
            $fieldName    = $fields[$f]->getVar('field_name');
426
            $fieldElement = $fields[$f]->getVar('field_element');
427
            $rpFieldName  = $this->getRightString($fieldName);
428
            $spacer = str_repeat(' ', $lenMaxName - \strlen($rpFieldName));
429
            switch ($fieldElement) {
430
                case 3:
431
                    $getValues .= $this->pc->getPhpCodeStripTags("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}', 'e')", false, "\t\t");
432
                    if ($configMaxchar == 0) {
433
                        $getValues .= $this->xc->getXcEqualsOperator('$editorMaxchar', $this->xc->getXcGetConfig('editor_maxchar'), false, "\t\t");
434
                        $configMaxchar = 1;
435
                    }
436
                    $truncate  =  "\$utility::truncateHtml(\$ret['{$rpFieldName}'], \$editorMaxchar)";
437
                    $spacer = str_repeat(' ', $lenMaxName - \strlen($rpFieldName) - \strlen('_short'));
438
                    $getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_short']{$spacer}", $truncate, false, "\t\t");
439
                    $helper = 1;
440
                    $utility = 1;
441
                    break;
442
                case 4:
443
                    $getValues .= $this->xc->getXcGetVar("ret['{$rpFieldName}']{$spacer}", 'this', $fieldName, false, "\t\t", ", 'e'");
444
                    if ($configMaxchar == 0) {
445
                        $getValues .= $this->xc->getXcEqualsOperator('$editorMaxchar', $this->xc->getXcGetConfig('editor_maxchar'), false, "\t\t");
446
                        $configMaxchar = 1;
447
                    }
448
                    $truncate  =  "\$utility::truncateHtml(\$ret['{$rpFieldName}'], \$editorMaxchar)";
449
                    $spacer = str_repeat(' ', $lenMaxName - \strlen($rpFieldName) - \strlen('_short'));
450
                    $getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}_short']{$spacer}", $truncate, false, "\t\t");
451
                    $helper = 1;
452
                    $utility = 1;
453
                    break;
454
                case 6:
455
                    $getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}']{$spacer}", "(int)\$this->getVar('{$fieldName}') > 0 ? _YES : _NO", false, "\t\t");
456
                    break;
457
                case 8:
458
                    $getValues .= $this->xc->getXcXoopsUserUnameFromId("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", "\t\t");
459
                    break;
460
                case 15:
461
                    $getValues .= $this->xc->getXcFormatTimeStamp("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", 's', "\t\t");
462
                    break;
463
                case 16:
464
                    $spacer = str_repeat(' ', $lenMaxName - \strlen('status') + 7);
465
                    $getValues .= $this->xc->getXcGetVar("status{$spacer}", 'this', $fieldName, false, "\t\t");
466
                    $spacer = str_repeat(' ', $lenMaxName - \strlen('status'));
467
                    $getValues .= $this->xc->getXcEqualsOperator("\$ret['status']{$spacer}", '$status', false, "\t\t");
468
                    $contCase1  = $this->xc->getXcEqualsOperator('$status_text', $language . 'STATUS_NONE', false, "\t\t\t\t");
469
                    $cases[$this->xc->getXcGetConstants('STATUS_NONE')] = [$contCase1];
470
                    $contCase2  = $this->xc->getXcEqualsOperator('$status_text', $language . 'STATUS_OFFLINE', false, "\t\t\t\t");
471
                    $cases[$this->xc->getXcGetConstants('STATUS_OFFLINE')] = [$contCase2];
472
                    $contCase3  = $this->xc->getXcEqualsOperator('$status_text', $language . 'STATUS_SUBMITTED', false, "\t\t\t\t");
473
                    $cases[$this->xc->getXcGetConstants('STATUS_SUBMITTED')] = [$contCase3];
474
                    if (1 == $tablePermissions) {
475
                        $contCase4 = $this->xc->getXcEqualsOperator('$status_text', $language . 'STATUS_APPROVED', false, "\t\t\t\t");
476
                        $cases[$this->xc->getXcGetConstants('STATUS_APPROVED')] = [$contCase4];
477
                    }
478
                    if (1 == $tableBroken) {
479
                        $contCase5 = $this->xc->getXcEqualsOperator('$status_text', $language . 'STATUS_BROKEN', false, "\t\t\t\t");
480
                        $cases[$this->xc->getXcGetConstants('STATUS_BROKEN')] = [$contCase5];
481
                    }
482
                    $contentSwitch = $this->pc->getPhpCodeCaseSwitch($cases, true, false, "\t\t\t", true);
483
                    $getValues     .= $this->pc->getPhpCodeSwitch('status', $contentSwitch, "\t\t");
484
                    $len           = $lenMaxName - \strlen('status_text');
485
                    $spacer        = $len > 0 ? str_repeat(' ', $len) : '';
486
                    $getValues     .= $this->xc->getXcEqualsOperator("\$ret['status_text']{$spacer}", '$status_text',  false, "\t\t");
487
                    break;
488
                case 21:
489
                    $getValues .= $this->xc->getXcFormatTimeStamp("ret['{$rpFieldName}']{$spacer}", "\$this->getVar('{$fieldName}')", 'm', "\t\t");
490
                    break;
491
                default:
492
                    $fieldElements    = $this->helper->getHandler('Fieldelements')->get($fieldElement);
493
                    $fieldElementTid  = $fieldElements->getVar('fieldelement_tid');
494
                    if ((int)$fieldElementTid > 0 ) {
495
                        $fieldElementMid = $fieldElements->getVar('fieldelement_mid');
496
                        $fieldElementName = (string)$fieldElements->getVar('fieldelement_name');
497
                        $fieldNameDesc = mb_substr($fieldElementName, \mb_strrpos($fieldElementName, ':'), mb_strlen($fieldElementName));
498
                        $topicTableName = \str_replace(': ', '', \mb_strtolower($fieldNameDesc));
499
                        $fieldsTopics = $this->getTableFields($fieldElementMid, $fieldElementTid);
500
                        foreach (\array_keys($fieldsTopics) as $g) {
501
                            $fieldNameTopic = $fieldsTopics[$g]->getVar('field_name');
502
                            if (1 == $fieldsTopics[$g]->getVar('field_main')) {
503
                                $fieldMainTopic = $fieldNameTopic;
504
                            }
505
                        }
506
                        $getValues .= $this->xc->getXcHandlerLine($topicTableName, "\t\t");
507
                        $getTopicTable = "\${$topicTableName}Handler->get(\$this->getVar('{$fieldName}'))";
508
                        $getValues .= $this->xc->getXcEqualsOperator("\${$topicTableName}Obj", $getTopicTable, null, "\t\t");
509
                        $fMainTopic = "\${$topicTableName}Obj->getVar('{$fieldMainTopic}')";
510
                        $getValues .= $this->xc->getXcEqualsOperator("\$ret['{$rpFieldName}']{$spacer}", $fMainTopic, null, "\t\t");
511
                        $helper = 1;
512
                    } else {
513
                        $getValues .= $this->xc->getXcGetVar("ret['{$rpFieldName}']{$spacer}", 'this', $fieldName, false, "\t\t");
514
                    }
515
                    break;
516
            }
517
        }
518
        if ($helper > 0) {
519
            $header .= $this->xc->getXcGetInstance('helper ', "\XoopsModules\\{$ucfModuleDirname}\Helper", "\t\t");
520
        }
521
        if ($utility > 0) {
522
            $header .= $this->xc->getXcEqualsOperator('$utility', "new \XoopsModules\\{$ucfModuleDirname}\Utility()", '',"\t\t");
523
        }
524
        $getValues .= $this->getSimpleString('return $ret;', "\t\t");
525
526
        $ret .= $this->pc->getPhpCodeFunction('getValues' . $ucfTableName, '$keys = null, $format = null, $maxDepth = null', $header . $getValues, 'public ', false, "\t");
527
528
        return $ret;
529
    }
530
531
    /**
532
     * @private function getToArrayInObject
533
     *
534
     * @param $table
535
     *
536
     * @return string
537
     */
538
    private function getToArrayInObject($table)
539
    {
540
        $tableName    = $table->getVar('table_name');
541
        $ucfTableName = \ucfirst($tableName);
542
        $multiLineCom = ['Returns an array representation' => 'of the object', '' => '', '@return' => 'array'];
543
        $ret          = $this->pc->getPhpCodeCommentMultiLine($multiLineCom, "\t");
544
545
        $getToArray = $this->pc->getPhpCodeArray('ret', [], false, "\t\t");
546
        $getToArray .= $this->xc->getXcEqualsOperator('$vars', '$this->getVars()', null, "\t\t");
547
        $foreach    = $this->xc->getXcEqualsOperator('$ret[$var]', '$this->getVar($var)', null, "\t\t\t");
548
        $getToArray .= $this->pc->getPhpCodeForeach('vars', true, false, 'var', $foreach, "\t\t");
549
        $getToArray .= $this->getSimpleString('return $ret;', "\t\t");
550
551
        $ret .= $this->pc->getPhpCodeFunction('toArray' . $ucfTableName, '', $getToArray, 'public ', false, "\t");
552
553
        return $ret;
554
    }
555
556
    /**
557
     * @private function getOptionsCheck
558
     *
559
     * @param $table
560
     *
561
     * @return string
562
     */
563
    private function getOptionsCheck($table)
564
    {
565
        $tableName    = $table->getVar('table_name');
566
        $ucfTableName = \ucfirst($tableName);
567
        $ret          = $this->pc->getPhpCodeCommentMultiLine(['Get' => 'Options'], "\t");
568
        $getOptions   = $this->pc->getPhpCodeArray('ret', [], false, "\t");
569
570
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
571
        foreach (\array_keys($fields) as $f) {
572
            $fieldName    = $fields[$f]->getVar('field_name');
573
            $fieldElement = $fields[$f]->getVar('field_element');
574
575
            $fieldElements  = $this->helper->getHandler('Fieldelements')->get($fieldElement);
576
            $fieldElementId = $fieldElements->getVar('fieldelement_id');
577
            $rpFieldName    = $this->getRightString($fieldName);
578
            if (5 == $fieldElementId) {
579
                $arrayPush  = $this->pc->getPhpCodeArrayType('ret', 'push', "'{$rpFieldName}'", null, false, "\t\t\t");
580
                $getOptions .= $this->pc->getPhpCodeConditions("\$this->getVar('{$fieldName}')", ' == ', '1', $arrayPush, false, "\t\t");
581
            }
582
        }
583
584
        $getOptions .= $this->getSimpleString('return $ret;', "\t\t");
585
586
        $ret .= $this->pc->getPhpCodeFunction('getOptions' . $ucfTableName, '', $getOptions, 'public ', false, "\t");
587
588
        return $ret;
589
    }
590
591
    /**
592
     * @public function render
593
     * @param null
594
     *
595
     * @return bool|string
596
     */
597
    public function render()
598
    {
599
        $module         = $this->getModule();
600
        $table          = $this->getTable();
601
        $filename       = $this->getFileName();
602
        $moduleDirname  = $module->getVar('mod_dirname');
603
        $fields         = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
604
605
        $namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]);
606
        $content   = $this->getHeaderFilesComments($module, null, $namespace);
607
        $content   .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname]);
608
        $content   .= $this->getClassObject($module, $table, $fields);
609
610
        $this->create($moduleDirname, 'class', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
611
612
        return $this->renderFile();
613
    }
614
}
615