Passed
Pull Request — master (#136)
by Michael
02:47
created

AdminXoopsCode::getAdminAddNavigation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 *
18
 * @since           2.5.0
19
 *
20
 * @author          Txmod Xoops http://www.txmodxoops.org
21
 *
22
 * @version         $Id: Axc.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class Axc.
27
 */
28
class AdminXoopsCode
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    /**
31
    *  @static function getInstance
32
    *  @param null
33
    * @return AdminXoopsCode
34
    */
35
    public static function getInstance()
36
    {
37
        static $instance = false;
38
        if (!$instance) {
39
            $instance = new self();
40
        }
41
42
        return $instance;
43
    }
44
45
    /**
46
     * @public function getAdminTemplateMain
47
     * @param        $moduleDirname
48
     * @param        $tableName
49
     *
50
     * @param string $t
51
     * @return string
52
     */
53
    public function getAdminTemplateMain($moduleDirname, $tableName, $t = '')
54
    {
55
        return "{$t}\$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';\n";
56
    }
57
58
    /**
59
     * @public function getAdminTemplateMain
60
     * @param        $language
61
     * @param        $tableName
62
     * @param        $stuTableSoleName
63
     * @param string $op
64
     * @param string $type
65
     *
66
     * @param string $t
67
     * @return string
68
     */
69
    public function getAdminItemButton($language, $tableName, $stuTableSoleName, $op = '?op=new', $type = 'add', $t = '')
70
    {
71
        $stuType = strtoupper($type);
72
        $aM = $t.'$adminMenu->addItemButton(';
73
        if ('add' === $type) {
74
            $ret = $aM."{$language}ADD_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n";
75
        } else {
76
            $ret = $aM."{$language}{$stuTableSoleName}_{$stuType}, '{$tableName}.php{$op}', '{$type}');\n";
77
        }
78
79
        return $ret;
80
    }
81
82
    /**
83
     * @public function getAdminAddNavigation
84
     *
85
     * @param        $tableName
86
     *
87
     * @param string $t
88
     * @return string
89
     */
90
    public function getAdminDisplayNavigation($tableName, $t = '')
91
    {
92
        return "{$t}\$adminMenu->displayNavigation('{$tableName}.php')";
93
    }
94
95
    /**
96
     * @public function getAxcAddInfoBox
97
     * @param        $language
98
     *
99
     * @param string $t
100
     * @return string
101
     */
102
    public function getAxcAddInfoBox($language, $t = '')
103
    {
104
        return "{$t}\$adminMenu->addInfoBox({$language});\n";
105
    }
106
107
    /**
108
     * @public function getAxcAddInfoBoxLine
109
     * @param        $language
110
     * @param string $label
111
     * @param string $var
112
     *
113
     * @param string $t
114
     * @return string
115
     */
116
    public function getAxcAddInfoBoxLine($language, $label = '', $var = '', $t = '')
117
    {
118
        $aMenu = $t.'$adminMenu->addInfoBoxLine(';
119
        if ('' != $var) {
120
            $ret = $aMenu."{$language}, '<label>'.{$label}.'</label>', {$var});\n";
121
        } else {
122
            $ret = $aMenu."{$language}, '<label>'.{$label}.'</label>');\n";
123
        }
124
125
        return $ret;
126
    }
127
128
    /**
129
     * @public function getAxcAddConfigBoxLine
130
     * @param        $language
131
     * @param string $label
132
     * @param string $var
133
     *
134
     * @param string $t
135
     * @return string
136
     */
137
    public function getAxcAddConfigBoxLine($language, $label = '', $var = '', $t = '')
138
    {
139
        $aMenu = $t.'$adminMenu->addConfigBoxLine(';
140
        if ('' != $var) {
141
            $ret = $aMenu."{$language}, '{$label}', {$var});\n";
142
        } else {
143
            $ret = $aMenu."{$language}, '{$label}');\n";
144
        }
145
146
        return $ret;
147
    }
148
149
    /**
150
     * @public function getAxcImageListSetVar
151
     * @param string $moduleDirname
152
     * @param string $tableName
153
     * @param string $fieldName
154
     * @param string $t
155
     * @return string
156
     */
157
    public function getAxcImageListSetVar($moduleDirname, $tableName, $fieldName, $t = '')
158
    {
159
        $pCodeImageList = TDMCreatePhpCode::getInstance();
160
        $xCodeImageList = TDMCreateXoopsCode::getInstance();
161
        $ret = $pCodeImageList->getPhpCodeCommentLine('Set Var', $fieldName, $t);
162
        $ret .= $pCodeImageList->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
163
        $xRootPath = "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'";
164
        $ret .= $xCodeImageList->getXcMediaUploader('uploader', $xRootPath, $moduleDirname, $t);
165
        $post = $pCodeImageList->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST').'[0]';
166
        $fetchMedia = self::getAxcFetchMedia('uploader', $post);
167
        $ifelse = $t."\t//".self::getAxcSetPrefix('uploader', "{$fieldName}_").";\n";
168
        $ifelse .= $t."\t//{$fetchMedia};\n";
169
        $contentElseInt = $xCodeImageList->getXcSetVar($tableName, $fieldName, '$uploader->getSavedFileName()', $t."\t\t");
170
        $contentIf = $xCodeImageList->getXcEqualsOperator('$errors', '$uploader->getErrors()', null, false, $t."\t\t");
171
        $contentIf .= $xCodeImageList->getXcRedirectHeader('javascript:history.go(-1)', '', '3', '$errors', true, $t."\t\t");
172
        $ifelse .= $pCodeImageList->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt, $t."\t");
173
        $contentElseExt = $xCodeImageList->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']", $t."\t");
174
175
        $ret .= $pCodeImageList->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt, $t);
176
177
        return $ret;
178
    }
179
180
    /**
181
     * @public function getAxcUploadImageSetVar
182
     * @param string $moduleDirname
183
     * @param string $tableName
184
     * @param string $fieldName
185
     * @param        $fieldMain
186
     * @param string $t
187
     * @return string
188
     */
189
    public function getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain, $t = '')
190
    {
191
        $pCodeUploadImage = TDMCreatePhpCode::getInstance();
192
        $xCodeUploadImage = TDMCreateXoopsCode::getInstance();
193
        $stuModuleDirname = strtoupper($moduleDirname);
194
        $ret = $pCodeUploadImage->getPhpCodeCommentLine('Set Var', $fieldName, $t);
195
        $ret .= $pCodeUploadImage->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
196
        $xUploadImage = "{$stuModuleDirname}_UPLOAD_IMAGE_PATH";
197
        $ret .= $xCodeUploadImage->getXcMediaUploader('uploader', $xUploadImage.".'/{$tableName}/'", $moduleDirname, $t);
198
        $post = $pCodeUploadImage->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST').'[0]';
199
        $fetchMedia = self::getAxcFetchMedia('uploader', $post);
200
        $file = $pCodeUploadImage->getPhpCodeGlobalsVariables('attachedfile', 'FILES')."['name']";
201
        $expr = '/^.+\.([^.]+)$/sU';
202
        $ifelse = $pCodeUploadImage->getPhpCodePregFunzions('extension', $expr, '', $file, 'replace', false, $t."\t");
203
204
        $ifelse .= $t."\t\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n";
205
        $ifelse .= self::getAxcSetPrefix('uploader', '$imgName', $t."\t").";\n";
206
        $ifelse .= $t."\t{$fetchMedia};\n";
207
        $contentElseInt = $xCodeUploadImage->getXcSetVar($tableName, $fieldName, '$uploader->getSavedFileName()', $t."\t\t");
208
        $contentIf = $xCodeUploadImage->getXcEqualsOperator('$errors', '$uploader->getErrors()', null, false, $t."\t\t");
209
        $contentIf .= $xCodeUploadImage->getXcRedirectHeader('javascript:history.go(-1)', '', '3', '$errors', true, $t."\t\t");
210
        $ifelse .= $pCodeUploadImage->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt, $t."\t");
211
        $contentElseExt = $xCodeUploadImage->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']", $t."\t");
212
213
        $ret .= $pCodeUploadImage->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt, $t);
214
215
        return $ret;
216
    }
217
218
    /**
219
     * @public function getAxcFileSetVar
220
     * @param        $moduleDirname
221
     * @param        $tableName
222
     * @param        $fieldName
223
     * @param bool   $formatUrl
224
     * @param string $t
225
     * @return string
226
     */
227
    public function getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false, $t = '')
228
    {
229
        $stuModuleDirname = strtoupper($moduleDirname);
230
        $ret = self::getAxcImageFileSetVar($moduleDirname, $stuModuleDirname.'_UPLOAD_FILES_PATH', $tableName, $fieldName, $formatUrl, $t);
231
232
        return $ret;
233
    }
234
235
    /**
236
     * @private function getAxcImageFileSetVar
237
     * @param        $moduleDirname
238
     * @param        $dirname
239
     * @param        $tableName
240
     * @param        $fieldName
241
     * @param bool   $formatUrl
242
     * @param string $t
243
     * @return string
244
     */
245
    private function getAxcImageFileSetVar($moduleDirname, $dirname, $tableName, $fieldName, $formatUrl = false, $t = '')
246
    {
247
        $pCodeFileSetVar = TDMCreatePhpCode::getInstance();
248
        $xCodeFileSetVar = TDMCreateXoopsCode::getInstance();
249
        $ret = '';
250
        $ifelse = '';
251
        $files = '';
252
        $post = $pCodeFileSetVar->getPhpCodeGlobalsVariables('xoops_upload_file', 'POST').'[0]';
253
        $fetchMedia = self::getAxcFetchMedia('uploader', $post);
254
        if ($formatUrl) {
255
            $ret .= $xCodeFileSetVar->getXcSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])", $t);
256
            $ret .= $pCodeFileSetVar->getPhpCodeCommentLine('Set Var', $fieldName, $t);
257
            $ifelse .= $t."\t\t{$fetchMedia};\n";
258
        } else {
259
            $files = '/files';
260
            $ret .= $pCodeFileSetVar->getPhpCodeCommentLine('Set Var', $fieldName, $t);
261
            $ifelse .= $t."\t//".self::getAxcSetPrefix('uploader', "'{$fieldName}_'").";\n";
262
            $ifelse .= $t."\t//{$fetchMedia};\n";
263
        }
264
        $ret .= $pCodeFileSetVar->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true, false, '', $t);
265
        $ret .= $xCodeFileSetVar->getXcMediaUploader('uploader', $dirname.".'/{$tableName}{$files}'", $moduleDirname, $t);
266
        $contentElse = $xCodeFileSetVar->getXcSetVar($tableName, $fieldName, '$uploader->getSavedFileName()', $t."\t\t");
267
        $contentIf = $xCodeFileSetVar->getXcEqualsOperator('$errors', '$uploader->getErrors()', null, false, $t."\t\t");
268
        $contentIf .= $xCodeFileSetVar->getXcRedirectHeader('javascript:history.go(-1)', '', '3', '$errors', true, $t."\t\t");
269
        $ifelse .= $pCodeFileSetVar->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse, $t."\t");
270
271
        $ret .= $pCodeFileSetVar->getPhpCodeConditions($fetchMedia, '', '', $t."\t".$fetchMedia.";\n", $ifelse, $t);
272
273
        return $ret;
274
    }
275
276
    /**
277
     * @public function getAxcSetVarsObjects
278
     *
279
     * @param $moduleDirname
280
     * @param $tableName
281
     * @param $tableSoleName
282
     * @param $fields
283
     * @return string
284
     */
285
    public function getAxcSetVarsObjects($moduleDirname, $tableName, $tableSoleName, $fields)
286
    {
287
        $xCodeSetVars = TDMCreateXoopsCode::getInstance();
288
        $ret = TDMCreatePhpCode::getInstance()->getPhpCodeCommentLine($comment = 'Set Vars', $var = '');
289
        $fieldMain = '';
290
        foreach (array_keys($fields) as $f) {
291
            $fieldName = $fields[$f]->getVar('field_name');
292
            $fieldElement = $fields[$f]->getVar('field_element');
293
            if ($f > 0) { // If we want to hide field id
294
                switch ($fieldElement) {
295
                    case 5:
296
                    case 6:
297
                        $ret .= $xCodeSetVars->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName);
298
                        break;
299
                    case 11:
300
                        $ret .= self::getAxcImageListSetVar($moduleDirname, $tableName, $fieldName);
301
                        break;
302
                    case 12:
303
                        $ret .= $xCodeSetVars->getXcUrlFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXcUrlFileSetVar() does not exist on TDMCreateXoopsCode. Did you maybe mean getXcUrlFileGetVar()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
304
                        break;
305
                    case 13:
306
                        if (1 == $fields[$f]->getVar('field_main')) {
307
                            $fieldMain = $fieldName;
308
                        }
309
                        $ret .= self::getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain);
310
                        break;
311
                    case 14:
312
                        $ret .= $xCodeSetVars->getXcUploadFileSetVar($moduleDirname, $tableName, $fieldName);
0 ignored issues
show
Bug introduced by
The method getXcUploadFileSetVar() does not seem to exist on object<TDMCreateXoopsCode>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
313
                        break;
314
                    case 15:
315
                        $ret .= $xCodeSetVars->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName);
316
                        break;
317
                    default:
318
                        $ret .= $xCodeSetVars->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']");
319
                        break;
320
                }
321
            }
322
        }
323
324
        return $ret;
325
    }
326
327
    /**
328
     * @public function getAxcFetchMedia
329
     *
330
     * @param        $anchor
331
     * @param        $var
332
     *
333
     * @param string $t
334
     * @return string
335
     */
336
    public function getAxcFetchMedia($anchor, $var, $t = '')
337
    {
338
        return "{$t}\${$anchor}->fetchMedia({$var})";
339
    }
340
341
    /**
342
     * @public function getAxcSetPrefix
343
     *
344
     * @param        $anchor
345
     * @param        $var
346
     *
347
     * @param string $t
348
     * @return string
349
     */
350
    public function getAxcSetPrefix($anchor, $var, $t = '')
351
    {
352
        return "{$t}\${$anchor}->setPrefix({$var})";
353
    }
354
355
    /**
356
     * @public function getAxcGetObjHandlerId
357
     *
358
     * @param string $tableName
359
     * @param string $fieldId
360
     *
361
     * @param string $t
362
     * @return string
363
     */
364
    public function getAxcGetObjHandlerId($tableName, $fieldId, $t = '')
365
    {
366
        return "{$t}\${$tableName}Obj = \${$tableName}Handler->get(\${$fieldId});\n";
367
    }
368
369
    /**
370
     * @public function getAdminCodeCaseDelete
371
     * @param        $language
372
     * @param        $tableName
373
     * @param        $fieldId
374
     * @param        $fieldMain
375
     * @param string $t
376
     * @return string
377
     */
378
    public function getAdminCodeCaseDelete($language, $tableName, $fieldId, $fieldMain, $t = '')
379
    {
380
        $phpCodeCaseDelete = TDMCreatePhpCode::getInstance();
381
        $xCodeCaseDelete = TDMCreateXoopsCode::getInstance();
382
        $ccFieldId = TDMCreateFile::getInstance()->getCamelCase($fieldId, false, true);
383
        $ret = $xCodeCaseDelete->getXcGet($tableName, $ccFieldId, 'Obj', $tableName.'Handler');
384
385
        $reqOk = "_REQUEST['ok']";
386
        $isset = $phpCodeCaseDelete->getPhpCodeIsset($reqOk);
387
        $xoopsSecurityCheck = $xCodeCaseDelete->getXcSecurityCheck();
388
        $xoopsSecurityErrors = $xCodeCaseDelete->getXcSecurityErrors();
389
        $implode = $phpCodeCaseDelete->getPhpCodeImplode(', ', $xoopsSecurityErrors);
390
        $redirectHeaderErrors = $xCodeCaseDelete->getXcRedirectHeader($tableName, '', '3', $implode, true, $t."\t\t");
391
392
        $delete = $xCodeCaseDelete->getXcDelete($tableName, $tableName, 'Obj', 'Handler');
393
        $condition = $phpCodeCaseDelete->getPhpCodeConditions('!'.$xoopsSecurityCheck, '', '', $redirectHeaderErrors, false, $t."\t");
394
395
        $redirectHeaderLanguage = $xCodeCaseDelete->getXcRedirectHeader($tableName, '', '3', "{$language}FORM_DELETE_OK", true, $t."\t\t");
396
        $htmlErrors = $xCodeCaseDelete->getXcHtmlErrors($tableName, true);
397
        $internalElse = $xCodeCaseDelete->getXcTplAssign('error', $htmlErrors, true, $t."\t\t");
398
        $condition .= $phpCodeCaseDelete->getPhpCodeConditions($delete, '', '', $redirectHeaderLanguage, $internalElse, $t."\t");
399
400
        $mainElse = $xCodeCaseDelete->getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, 'delete', $t."\t");
401
        $ret .= $phpCodeCaseDelete->getPhpCodeConditions($isset, ' && ', "1 == \${$reqOk}", $condition, $mainElse, $t);
402
403
        return $ret;
404
    }
405
}
406