AdminXoopsCode::getAdminDisplayNavigation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files\Admin;
4
5
use XoopsModules\Tdmcreate;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * tdmcreate module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
/**
29
 * Class Axc.
30
 */
31
class AdminXoopsCode
32
{
33
    /**
34
     * @static function getInstance
35
     * @param null
36
     * @return AdminXoopsCode
37
     */
38
    public static function getInstance()
39
    {
40
        static $instance = false;
41
        if (!$instance) {
42
            $instance = new self();
43
        }
44
45
        return $instance;
46
    }
47
48
    /**
49
     * @public function getAdminTemplateMain
50
     * @param        $moduleDirname
51
     * @param        $tableName
52
     *
53
     * @param string $t
54
     * @return string
55
     */
56
    public function getAdminTemplateMain($moduleDirname, $tableName, $t = '')
57
    {
58
        return "{$t}\$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';\n";
59
    }
60
61
    /**
62
     * @public function getAdminTemplateMain
63
     * @param        $language
64
     * @param        $tableName
65
     * @param        $stuTableSoleName
66
     * @param string $op
67
     * @param string $type
68
     *
69
     * @param string $t
70
     * @return string
71
     */
72
    public function getAdminItemButton($language, $tableName, $stuTableSoleName, $op = '?op=new', $type = 'add', $t = '')
73
    {
74
        $stuType = mb_strtoupper($type);
75
        $aM      = $t . '$adminObject->addItemButton(';
76
        switch ($type) {
77
            case 'add';
78
                $ret = $aM . "{$language}ADD_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
79
            break;
80
            case 'samplebutton';
81
                $ret = $aM . "{$language}, '{$op}', 'add');\n";
82
                break;
83
            case 'default':
84
            default:
85
                $ret = $aM . "{$language}{$stuTableSoleName}_{$stuType}, '{$tableName}.php{$op}', '{$type}');\n";
86
            break;
87
        }
88
89
        return $ret;
90
    }
91
92
    /**
93
     * @public function getAdminAddNavigation
94
     *
95
     * @param $type
96
     * @param string $t
97
     * @return string
98
     */
99
    public function getAdminDisplayButton($type, $t = '')
100
    {
101
        return "{$t}\$adminObject->displayButton('{$type}');\n";
102
    }
103
104
    /**
105
     * @public function getAdminAddNavigation
106
     *
107
     * @param        $tableName
108
     *
109
     * @param string $t
110
     * @return string
111
     */
112
    public function getAdminDisplayNavigation($tableName, $t = '')
113
    {
114
        return "{$t}\$adminObject->displayNavigation('{$tableName}.php')";
115
    }
116
117
    /**
118
     * @public function getAxcAddInfoBox
119
     * @param        $language
120
     *
121
     * @param string $t
122
     * @return string
123
     */
124
    public function getAxcAddInfoBox($language, $t = '')
125
    {
126
        return "{$t}\$adminObject->addInfoBox({$language});\n";
127
    }
128
129
    /**
130
     * @public function getAxcAddInfoBoxLine
131
     * @param string $label
132
     * @param string $var
133
     *
134
     * @param string $t
135
     * @return string
136
     */
137
    public function getAxcAddInfoBoxLine($label = '', $var = '', $t = '')
138
    {
139
        $aMenu = $t . '$adminObject->addInfoBoxLine(sprintf(';
140
        if ('' != $var) {
141
            $ret = $aMenu . " '<label>'.{$label}.'</label>', {$var}));\n";
142
        } else {
143
            $ret = $aMenu . " '<label>'.{$label}.'</label>'));\n";
144
        }
145
146
        return $ret;
147
    }
148
149
    /**
150
     * @public function getAxcAddConfigBoxLine
151
     * @param        $language
152
     * @param string $label
153
     * @param string $var
154
     *
155
     * @param string $t
156
     * @return string
157
     */
158
    public function getAxcAddConfigBoxLine($language, $label = '', $var = '', $t = '')
159
    {
160
        $aMenu = $t . '$adminObject->addConfigBoxLine(';
161
        if ('' != $var) {
162
            $ret = $aMenu . "{$language}, '{$label}', {$var});\n";
163
        } else {
164
            $ret = $aMenu . "{$language}, '{$label}');\n";
165
        }
166
167
        return $ret;
168
    }
169
170
    /**
171
     * @public function getAxcSetVarImageList
172
     * @param string $tableName
173
     * @param string $fieldName
174
     * @param string $t
175
     * @param int $countUploader
176
     * @return string
177
     */
178
    public function getAxcSetVarImageList($tableName, $fieldName, $t = '', $countUploader = 0)
179
    {
180
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
181
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
182
        $ret         = $pc->getPhpCodeCommentLine('Set Var', $fieldName, $t);
183
        $ret         .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
184
        $xRootPath   = "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'";
185
        $ret         .= $xc->getXcMediaUploader('uploader', $xRootPath, 'mimetypes_image', 'maxsize_image', $t);
186
        $post        = $pc->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST') . '[' . $countUploader . ']';
187
        $fetchMedia  = $this->getAxcFetchMedia('uploader', $post);
188
        $ifelse      = $t . "\t//" . $this->getAxcSetPrefix('uploader', "{$fieldName}_") . ";\n";
189
        $ifelse      .= $t . "\t//{$fetchMedia};\n";
190
        $contElseInt = $xc->getXcSetVarObj($tableName, $fieldName, '$uploader->getSavedFileName()', $t . "\t\t");
191
        $contIf      = $xc->getXcEqualsOperator('$errors', '$uploader->getErrors()', null, $t . "\t\t");
192
        $contIf      .= $xc->getXcRedirectHeader('javascript:history.go(-1)', '', '3', '$errors', true, $t . "\t\t");
193
        $ifelse      .= $pc->getPhpCodeConditions('!$uploader->upload()', '', '', $contIf, $contElseInt, $t . "\t");
194
        $contElseExt = $xc->getXcSetVarObj($tableName, $fieldName, "Request::getString('{$fieldName}')", $t . "\t");
195
196
        $ret         .= $pc->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contElseExt, $t);
197
198
        return $ret;
199
    }
200
201
    /**
202
     * @public function getAxcSetVarUploadImage
203
     * @param string $moduleDirname
204
     * @param string $tableName
205
     * @param string $fieldName
206
     * @param        $fieldMain
207
     * @param string $t
208
     * @param int    $countUploader
209
     * @return string
210
     */
211
    public function getAxcSetVarUploadImage($moduleDirname, $tableName, $fieldName, $fieldMain, $t = '', $countUploader = 0)
212
    {
213
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
214
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
215
        $stuModuleDirname = mb_strtoupper($moduleDirname);
216
        $ucfModuleDirname = ucfirst($moduleDirname);
217
        $ret          = $pc->getPhpCodeCommentLine('Set Var', $fieldName, $t);
218
        $ret          .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
219
        $file         = $pc->getPhpCodeGlobalsVariables($fieldName, 'FILES') . "['name']";
220
        $ret          .= $xc->getXcEqualsOperator('$filename      ', $file, null, $t);
221
        $mimetype     = $pc->getPhpCodeGlobalsVariables($fieldName, 'FILES') . "['type']";
222
        $ret          .= $xc->getXcEqualsOperator('$imgMimetype   ', $mimetype, null, $t);
223
        $ret          .= $xc->getXcEqualsOperator('$imgNameDef    ', "Request::getString('{$fieldMain}')", null, $t);
224
        $ret          .= $xc->getXcEqualsOperator('$uploaderErrors', "''", null, $t);
225
        $xUploadImage = "{$stuModuleDirname}_UPLOAD_IMAGE_PATH";
226
        $ret          .= $xc->getXcMediaUploader('uploader', $xUploadImage . " . '/{$tableName}/'", 'mimetypes_image', 'maxsize_image', $t);
227
        $post         = $pc->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST') . '[' . $countUploader . ']';
228
        $fetchMedia   = $this->getAxcFetchMedia('uploader', $post);
229
        $expr         = '/^.+\.([^.]+)$/sU';
230
        $ifelse       = $pc->getPhpCodePregFunzions('extension', $expr, '', "\$filename", 'replace', false, $t . "\t");
231
        $ifelse       .= $t . "\t\$imgName = str_replace(' ', '', \$imgNameDef) . '.' . \$extension;\n";
232
        $ifelse       .= $this->getAxcSetPrefix('uploader', '$imgName', $t . "\t") . ";\n";
233
        $ifelse       .= $t . "\t{$fetchMedia};\n";
234
        $contElseInt  = $xc->getXcEqualsOperator('$savedFilename', '$uploader->getSavedFileName()', null, $t . "\t\t");
235
        $config       = $xc->getXcGetConfig('maxwidth_image');
236
        $contElseInt  .= $xc->getXcEqualsOperator('$maxwidth ', "(int){$config}", null, $t . "\t\t");
237
        $config       = $xc->getXcGetConfig('maxheight_image');
238
        $contElseInt  .= $xc->getXcEqualsOperator('$maxheight', "(int){$config}", null, $t . "\t\t");
239
        $resizer      = $pc->getPhpCodeCommentLine('Resize image', '', $t . "\t\t\t");
240
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler               ', "new {$ucfModuleDirname}\Common\Resizer()", null, $t . "\t\t\t");
241
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler->sourceFile   ', $xUploadImage . " . '/{$tableName}/' . \$savedFilename", null, $t . "\t\t\t");
242
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler->endFile      ', $xUploadImage . " . '/{$tableName}/' . \$savedFilename", null, $t . "\t\t\t");
243
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler->imageMimetype', '$imgMimetype', null, $t . "\t\t\t");
244
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler->maxWidth     ', '$maxwidth', null, $t . "\t\t\t");
245
        $resizer      .= $xc->getXcEqualsOperator('$imgHandler->maxHeight    ', '$maxheight', null, $t . "\t\t\t");
246
        $resizer      .= $xc->getXcEqualsOperator('$result                   ', '$imgHandler->resizeImage()', null, $t . "\t\t\t");
247
        $contElseInt  .= $pc->getPhpCodeConditions('$maxwidth > 0 && $maxheight > 0', '', '', $resizer, false, $t . "\t\t");
248
        $contElseInt  .= $xc->getXcSetVarObj($tableName, $fieldName, '$savedFilename', $t . "\t\t");
249
        $contIf       = $xc->getXcEqualsOperator('$uploaderErrors', '$uploader->getErrors()', null, $t . "\t\t");
250
        $ifelse       .= $pc->getPhpCodeConditions('!$uploader->upload()', '', '', $contIf, $contElseInt, $t . "\t");
251
        $ifelseExt    = $xc->getXcEqualsOperator('$uploaderErrors', '$uploader->getErrors()', null, $t . "\t\t");
252
        $contElseExt  = $pc->getPhpCodeConditions("\$filename", ' > ', "''", $ifelseExt, false, $t . "\t");
253
        $contElseExt  .= $xc->getXcSetVarObj($tableName, $fieldName, "Request::getString('{$fieldName}')", $t . "\t");
254
255
        $ret          .= $pc->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contElseExt, $t);
256
257
        return $ret;
258
    }
259
260
    /**
261
     * @public function getAxcFileSetVar
262
     * @param        $moduleDirname
263
     * @param        $tableName
264
     * @param        $fieldName
265
     * @param bool   $formatUrl
266
     * @param string $t
267
     * @param int    $countUploader
268
     * @param string $fieldMain
269
     * @return string
270
     */
271
    public function getAxcSetVarUploadFile($moduleDirname, $tableName, $fieldName, $formatUrl = false, $t = '', $countUploader = 0, $fieldMain = '')
272
    {
273
        $stuModuleDirname = mb_strtoupper($moduleDirname);
274
        $ret              = $this->getAxcSetVarImageFile($stuModuleDirname . '_UPLOAD_FILES_PATH', $tableName, $fieldName, $formatUrl, $t, $countUploader, $fieldMain, 'mimetypes_file', 'maxsize_file');
275
276
        return $ret;
277
    }
278
279
    /**
280
     * @private function getAxcSetVarImageFile
281
     * @param        $dirname
282
     * @param        $tableName
283
     * @param        $fieldName
284
     * @param bool $formatUrl
285
     * @param string $t
286
     * @param int $countUploader
287
     * @param string $fieldMain
288
     * @param string $mimetype
289
     * @param string $maxsize
290
     * @return string
291
     */
292
    private function getAxcSetVarImageFile($dirname, $tableName, $fieldName, $formatUrl = false, $t = '', $countUploader = 0, $fieldMain = '', $mimetype = 'mimetypes_image', $maxsize = 'maxsize_image')
293
    {
294
        $pc     = Tdmcreate\Files\CreatePhpCode::getInstance();
295
        $xc     = Tdmcreate\Files\CreateXoopsCode::getInstance();
296
        $ret    = '';
297
        $files  = '';
298
        $contIf = '';
299
300
        if ($formatUrl) {
301
            $ret .= $xc->getXcSetVarObj($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])", $t);
302
        }
303
        $ret         .= $pc->getPhpCodeCommentLine('Set Var', $fieldName, $t);
304
        $ret         .= $pc->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
305
        $file        = $pc->getPhpCodeGlobalsVariables($fieldName, 'FILES') . "['name']";
306
        $ret         .= $xc->getXcEqualsOperator('$filename      ', $file, null, $t);
307
        $ret         .= $xc->getXcEqualsOperator('$imgNameDef    ', "Request::getString('{$fieldMain}')", null, $t);
308
        $ret         .= $xc->getXcMediaUploader('uploader', $dirname . " . '/{$tableName}{$files}/'", $mimetype, $maxsize, $t);
309
        $post        = $pc->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST') . '[' . $countUploader . ']';
310
        $fetchMedia  = $this->getAxcFetchMedia('uploader', $post);
311
        $expr        = '/^.+\.([^.]+)$/sU';
312
        $ifelse      = $pc->getPhpCodePregFunzions('extension', $expr, '', "\$filename", 'replace', false, $t . "\t");
313
        $ifelse      .= $t . "\t\$imgName = str_replace(' ', '', \$imgNameDef) . '.' . \$extension;\n";
314
        $ifelse      .= $this->getAxcSetPrefix('uploader', '$imgName', $t . "\t") . ";\n";
315
        $ifelse      .= $t . "\t{$fetchMedia};\n";
316
        $contElseInt = $xc->getXcSetVarObj($tableName, $fieldName, '$uploader->getSavedFileName()', $t . "\t\t");
317
        $contIf      .= $xc->getXcEqualsOperator('$errors', '$uploader->getErrors()', null, $t . "\t\t");
318
        $ifelse      .= $pc->getPhpCodeConditions('!$uploader->upload()', '', '', $contIf, $contElseInt, $t . "\t");
319
        $ifelseExt   = $xc->getXcEqualsOperator('$uploaderErrors', '$uploader->getErrors()', null, $t . "\t\t");
320
        $contElseExt = $pc->getPhpCodeConditions("\$filename", ' > ', "''", $ifelseExt, false, $t . "\t");
321
        $contElseExt .= $xc->getXcSetVarObj($tableName, $fieldName, "Request::getString('{$fieldName}')", $t . "\t");
322
323
        $ret         .= $pc->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contElseExt, $t);
324
325
        return $ret;
326
    }
327
328
    /**
329
     * @public function getAxcSetVarPassword
330
     * @param        $tableName
331
     * @param        $fieldName
332
     * @param string $t
333
     * @return string
334
     */
335
    public function getAxcSetVarPassword($tableName, $fieldName, $t = '')
336
    {
337
        $xc  = Tdmcreate\Files\CreateXoopsCode::getInstance();
338
        $pc  = Tdmcreate\Files\CreatePhpCode::getInstance();
339
        $cf  = Tdmcreate\Files\CreateFile::getInstance();
340
        $ccFieldId = $cf->getCamelCase($fieldName, false, true);
341
        $ret       = $xc->getXcEqualsOperator("\${$ccFieldId}", "Request::getString('{$fieldName}', '')", '',$t);
342
        $contIf    = $xc->getXcSetVarObj($tableName, $fieldName, "password_hash(\${$ccFieldId}, PASSWORD_DEFAULT)", $t . "\t");
343
        $ret       .= $pc->getPhpCodeConditions("''", ' !== ', "\${$ccFieldId}",$contIf, false, $t);
344
345
        return $ret;
346
    }
347
348
349
    /**
350
     * @public function getAxcSetVarMisc
351
     * @param        $tableName
352
     * @param        $fieldName
353
     * @param $fieldType
354
     * @param string $t
355
     * @return string
356
     */
357
    public function getAxcSetVarMisc($tableName, $fieldName, $fieldType, $t = '')
358
    {
359
        $xc  = Tdmcreate\Files\CreateXoopsCode::getInstance();
360
        switch ((int)$fieldType){
361
            case 2:
362
            case 3:
363
            case 4:
364
            case 5:
365
                $ret = $xc->getXcSetVarObj($tableName, $fieldName, "Request::getInt('{$fieldName}', 0)", $t);
366
                break;
367
            case 6:
368
            case 7:
369
            case 8:
370
                $ret = $xc->getXcSetVarObj($tableName, $fieldName, "Request::getFloat('{$fieldName}', 0)", $t);
371
                break;
372
            case 13:
373
            case 14:
374
            case 15:
375
            case 16:
376
            case 17:
377
            case 18:
378
                $ret = $xc->getXcSetVarObj($tableName, $fieldName, "Request::getString('{$fieldName}', '')", $t);
379
                break;
380
            case 0:
381
            default:
382
                //TODO: should be finally
383
                $ret = $xc->getXcSetVarObj($tableName, $fieldName, "\$_POST['{$fieldName}']", $t);
384
                break;
385
        }
386
387
        return $ret;
388
    }
389
390
    /**
391
     * @public function getAxcFetchMedia
392
     *
393
     * @param        $anchor
394
     * @param        $var
395
     *
396
     * @param string $t
397
     * @return string
398
     */
399
    public function getAxcFetchMedia($anchor, $var, $t = '')
400
    {
401
        return "{$t}\${$anchor}->fetchMedia({$var})";
402
    }
403
404
    /**
405
     * @public function getAxcSetPrefix
406
     *
407
     * @param        $anchor
408
     * @param        $var
409
     *
410
     * @param string $t
411
     * @return string
412
     */
413
    public function getAxcSetPrefix($anchor, $var, $t = '')
414
    {
415
        return "{$t}\${$anchor}->setPrefix({$var})";
416
    }
417
418
    /**
419
     * @public function getAdminCodeCaseDelete
420
     * @param        $language
421
     * @param        $tableName
422
     * @param        $fieldId
423
     * @param        $fieldMain
424
     * @param string $t
425
     * @return string
426
     */
427
    public function getAdminCodeCaseDelete($language, $tableName, $fieldId, $fieldMain, $t = '')
428
    {
429
        $pc = Tdmcreate\Files\CreatePhpCode::getInstance();
430
        $xc = Tdmcreate\Files\CreateXoopsCode::getInstance();
431
        $cf = Tdmcreate\Files\CreateFile::getInstance();
432
        $ccFieldId              = $cf->getCamelCase($fieldId, false, true);
433
        $ret                    = $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', '', $t);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type boolean expected by parameter $isParam of XoopsModules\Tdmcreate\F...Code::getXcHandlerGet(). ( Ignorable by Annotation )

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

433
        $ret                    = $xc->getXcHandlerGet($tableName, $ccFieldId, 'Obj', $tableName . 'Handler', /** @scrutinizer ignore-type */ '', $t);
Loading history...
434
        $reqOk                  = "_REQUEST['ok']";
435
        $isset                  = $pc->getPhpCodeIsset($reqOk);
436
        $xoopsSecurityCheck     = $xc->getXcXoopsSecurityCheck();
437
        $xoopsSecurityErrors    = $xc->getXcXoopsSecurityErrors();
438
        $implode                = $pc->getPhpCodeImplode(', ', $xoopsSecurityErrors);
439
        $redirectHeaderErrors   = $xc->getXcRedirectHeader($tableName, '', '3', $implode, true, $t . "\t\t");
440
        $delete                 = $xc->getXcHandlerDelete($tableName, $tableName, 'Obj', 'Handler');
441
        $condition              = $pc->getPhpCodeConditions('!' . $xoopsSecurityCheck, '', '', $redirectHeaderErrors, false, $t . "\t");
442
        $redirectHeaderLanguage = $xc->getXcRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK", true, $t . "\t\t");
443
        $htmlErrors             = $xc->getXcHtmlErrors($tableName, true);
444
        $internalElse           = $xc->getXcXoopsTplAssign('error', $htmlErrors, true, $t . "\t\t");
445
        $condition              .= $pc->getPhpCodeConditions($delete, '', '', $redirectHeaderLanguage, $internalElse, $t . "\t");
446
        $mainElse               = $xc->getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, 'delete', $t . "\t");
447
        $ret                    .= $pc->getPhpCodeConditions($isset, ' && ', "1 == \${$reqOk}", $condition, $mainElse, $t);
448
449
        return $ret;
450
    }
451
}
452