getXoopsVersionTemplatesAdminUser()   F
last analyzed

Complexity

Conditions 18
Paths 325

Size

Total Lines 91
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 69
nc 325
nop 4
dl 0
loc 91
rs 2.4708
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace XoopsModules\Modulebuilder\Files\User;
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
 * modulebuilder 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 UserXoopsVersion.
32
 */
33
class UserXoopsVersion extends Files\CreateFile
34
{
35
    /**
36
     * @var array
37
     */
38
    private $kw = [];
39
40
    /**
41
     * @var mixed
42
     */
43
    private $uxc = null;
44
45
    /**
46
     * @var mixed
47
     */
48
    private $xc = null;
49
50
    /**
51
     * @var mixed
52
     */
53
    private $pc = null;
54
55
    /**
56
     * @public function constructor
57
     * @param null
58
     */
59
    public function __construct()
60
    {
61
        parent::__construct();
62
        $this->xc  = Modulebuilder\Files\CreateXoopsCode::getInstance();
63
        $this->pc  = Modulebuilder\Files\CreatePhpCode::getInstance();
64
        $this->uxc = Modulebuilder\Files\User\UserXoopsCode::getInstance();
65
    }
66
67
    /**
68
     * @static function getInstance
69
     * @param null
70
     * @return UserXoopsVersion
71
     */
72
    public static function getInstance()
73
    {
74
        static $instance = false;
75
        if (!$instance) {
76
            $instance = new self();
77
        }
78
79
        return $instance;
80
    }
81
82
    /**
83
     * @public function write
84
     * @param       $module
85
     * @param mixed $table
86
     * @param mixed $tables
87
     * @param       $filename
88
     */
89
    public function write($module, $table, $tables, $filename)
90
    {
91
        $this->setModule($module);
92
        $this->setTable($table);
93
        $this->setTables($tables);
94
        $this->setFileName($filename);
95
        foreach (\array_keys($tables) as $t) {
96
            $tableName = $tables[$t]->getVar('table_name');
97
            $this->setKeywords($tableName);
98
        }
99
    }
100
101
    /**
102
     * @public function setKeywords
103
     * @param mixed $keywords
104
     */
105
    public function setKeywords($keywords)
106
    {
107
        if (\is_array($keywords)) {
108
            $this->kw = $keywords;
109
        } else {
110
            $this->kw[] = $keywords;
111
        }
112
    }
113
114
    /**
115
     * @public function getKeywords
116
     * @param null
117
     * @return array
118
     */
119
    public function getKeywords()
120
    {
121
        return $this->kw;
122
    }
123
124
    /**
125
     * @private function getXoopsVersionHeader
126
     * @param $module
127
     * @param $language
128
     *
129
     * @return string
130
     */
131
    private function getXoopsVersionHeader($module, $language)
132
    {
133
        $date = date('Y/m/d');
134
        $ret  = $this->getSimpleString('');
135
        $ret  .= Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine();
136
        $ret  .= $this->xc->getXcEqualsOperator('$moduleDirName     ', '\basename(__DIR__)');
137
        $ret  .= $this->xc->getXcEqualsOperator('$moduleDirNameUpper', '\mb_strtoupper($moduleDirName)');
138
        $ret  .= $this->getDashComment('Informations');
139
        $ha   = (1 == $module->getVar('mod_admin')) ? 1 : 0;
140
        $hm   = (1 == $module->getVar('mod_user')) ? 1 : 0;
141
142
        $descriptions = [
143
            'name'                => "{$language}NAME",
144
            'version'             => "'" . (string)$module->getVar('mod_version') . "'",
145
            'description'         => "{$language}DESC",
146
            'author'              => "'{$module->getVar('mod_author')}'",
147
            'author_mail'         => "'{$module->getVar('mod_author_mail')}'",
148
            'author_website_url'  => "'{$module->getVar('mod_author_website_url')}'",
149
            'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",
150
            'credits'             => "'{$module->getVar('mod_credits')}'",
151
            'license'             => "'{$module->getVar('mod_license')}'",
152
            'license_url'         => "'https://www.gnu.org/licenses/gpl-3.0.en.html'",
153
            'help'                => "'page=help'",
154
            'release_info'        => "'{$module->getVar('mod_release_info')}'",
155
            'release_file'        => "\XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'",
156
            'release_date'        => "'{$date}'",
157
            'manual'              => "'{$module->getVar('mod_manual')}'",
158
            'manual_file'         => "\XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'",
159
            'min_php'             => "'{$module->getVar('mod_min_php')}'",
160
            'min_xoops'           => "'{$module->getVar('mod_min_xoops')}'",
161
            'min_admin'           => "'{$module->getVar('mod_min_admin')}'",
162
            'min_db'              => "['mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}']",
163
            'image'               => "'assets/images/logoModule.png'",
164
            'dirname'             => '\basename(__DIR__)',
165
            'dirmoduleadmin'      => "'Frameworks/moduleclasses/moduleadmin'",
166
            'sysicons16'          => "'../../Frameworks/moduleclasses/icons/16'",
167
            'sysicons32'          => "'../../Frameworks/moduleclasses/icons/32'",
168
            'modicons16'          => "'assets/icons/16'",
169
            'modicons32'          => "'assets/icons/32'",
170
            'demo_site_url'       => "'{$module->getVar('mod_demo_site_url')}'",
171
            'demo_site_name'      => "'{$module->getVar('mod_demo_site_name')}'",
172
            'support_url'         => "'{$module->getVar('mod_support_url')}'",
173
            'support_name'        => "'{$module->getVar('mod_support_name')}'",
174
            'module_website_url'  => "'{$module->getVar('mod_website_url')}'",
175
            'module_website_name' => "'{$module->getVar('mod_website_name')}'",
176
            'release'             => "'{$module->getVar('mod_release')}'",
177
            'module_status'       => "'{$module->getVar('mod_status')}'",
178
            'system_menu'         => '1',
179
            'hasAdmin'            => $ha,
180
            'hasMain'             => $hm,
181
            'adminindex'          => "'admin/index.php'",
182
            'adminmenu'           => "'admin/menu.php'",
183
            'onInstall'           => "'include/install.php'",
184
            'onUninstall'         => "'include/uninstall.php'",
185
            'onUpdate'            => "'include/update.php'",
186
        ];
187
188
        $ret .= $this->uxc->getUserModVersionArray(0, $descriptions);
189
190
        return $ret;
191
    }
192
193
    /**
194
     * @private function getXoopsVersionMySQL
195
     * @param $moduleDirname
196
     * @param $table
197
     * @param $tables
198
     * @return string
199
     */
200
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
201
    {
202
        $tableName = $table->getVar('table_name');
203
        $n         = 1;
204
        $ret       = '';
205
        $items     = [];
206
        $tableRate = 0;
207
        if (!empty($tableName)) {
208
            $ret         .= $this->getDashComment('Mysql');
209
            $description = "'sql/mysql.sql'";
210
            $ret         .= $this->uxc->getUserModVersionText(2, $description, 'sqlfile', "'mysql'");
211
            $ret         .= Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Tables');
212
213
            foreach (\array_keys($tables) as $t) {
214
                $items[] = "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'";
215
                if (1 === (int)$tables[$t]->getVar('table_rate')) {
216
                    $tableRate = 1;
217
                }
218
                ++$n;
219
            }
220
            if (1 === $tableRate) {
221
                $items[] = "'{$moduleDirname}_ratings'";
222
                ++$n;
223
            }
224
            $ret .= $this->uxc->getUserModVersionArray(11, $items, 'tables', $n);
225
            unset($n);
226
        }
227
228
        return $ret;
229
    }
230
231
    /**
232
     * @private function getXoopsVersionSearch
233
     * @param $moduleDirname
234
     *
235
     * @return string
236
     */
237
    private function getXoopsVersionSearch($moduleDirname)
238
    {
239
        $ret   = $this->getDashComment('Search');
240
        $ret   .= $this->uxc->getUserModVersionText(1, 1, 'hasSearch');
241
        $items = ['file' => "'include/search.inc.php'", 'func' => "'{$moduleDirname}_search'"];
242
        $ret   .= $this->uxc->getUserModVersionArray(1, $items, 'search');
243
244
        return $ret;
245
    }
246
247
    /**
248
     * @private function getXoopsVersionComments
249
     * @param $moduleDirname
250
     *
251
     * @param $tables
252
     * @return string
253
     */
254
    private function getXoopsVersionComments($moduleDirname, $tables)
255
    {
256
        $tableName = '';
257
        $fieldId = '';
258
        foreach (\array_keys($tables) as $t) {
259
            if (1 == $tables[$t]->getVar('table_comments')) {
260
                $tableName = $tables[$t]->getVar('table_name');
261
                $fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id'));
262
                foreach (\array_keys($fields) as $f) {
263
                    $fieldName = $fields[$f]->getVar('field_name');
264
                    if (0 == $f) {
265
                        $fieldId = $fieldName;
266
                    }
267
                }
268
            }
269
        }
270
        $ret          = $this->getDashComment('Comments');
271
        $ret          .= $this->uxc->getUserModVersionText(1, "1", 'hasComments');
272
        $ret          .= $this->uxc->getUserModVersionText(2, "'{$tableName}.php'", 'comments', "'pageName'");
273
        $ret          .= $this->uxc->getUserModVersionText(2, "'{$fieldId}'", 'comments', "'itemName'");
274
        $ret          .= Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Comment callback functions');
275
        $ret          .= $this->uxc->getUserModVersionText(2, "'include/comment_functions.php'", 'comments', "'callbackFile'");
276
        $descriptions = ['approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'"];
277
        $ret          .= $this->uxc->getUserModVersionArray(2, $descriptions, 'comments', "'callback'");
278
279
        return $ret;
280
    }
281
282
    /**
283
     * @private function getXoopsVersionTemplatesAdminUser
284
     * @param $moduleDirname
285
     * @param $tables
286
     *
287
     * @param $admin
288
     * @param $user
289
     * @return string
290
     */
291
    private function getXoopsVersionTemplatesAdminUser($moduleDirname, $tables, $admin, $user)
292
    {
293
        $ret  = $this->getDashComment('Templates');
294
        $item = [];
295
        if ($admin) {
296
            $item[] = $this->pc->getPhpCodeCommentLine('Admin templates');
297
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', '', true);
298
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '', true);
299
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '', true);
300
            $tablePermissions = [];
301
            $tableBroken      = [];
302
            foreach (\array_keys($tables) as $t) {
303
                $tableName          = $tables[$t]->getVar('table_name');
304
                $tablePermissions[] = $tables[$t]->getVar('table_permissions');
305
                $tableBroken[]      = $tables[$t]->getVar('table_broken');
306
                $item[]             .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '', true);
307
            }
308
            if (\in_array(1, $tableBroken)) {
309
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken', '', true);
310
            }
311
            if (\in_array(1, $tablePermissions)) {
312
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', '', true);
313
            }
314
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'clone', '', true);
315
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '', true);
316
        }
317
318
        if ($user) {
319
            $item[]      = $this->pc->getPhpCodeCommentLine('User templates');
320
            $item[]      = $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '');
321
            $item[]      = $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '');
322
            $tableBroken = [];
323
            $tablePdf    = [];
324
            $tablePrint  = [];
325
            $tableRate   = [];
326
            $tableRss    = [];
327
            $tableSearch = [];
328
            $tableSingle = [];
329
            $tableSubmit = [];
330
            foreach (\array_keys($tables) as $t) {
331
                if (1 == $tables[$t]->getVar('table_user')) {
332
                    $tableName     = $tables[$t]->getVar('table_name');
333
                    $tableBroken[] = $tables[$t]->getVar('table_broken');
334
                    $tablePdf[]    = $tables[$t]->getVar('table_pdf');
335
                    $tablePrint[]  = $tables[$t]->getVar('table_print');
336
                    $tableRate[]   = $tables[$t]->getVar('table_rate');
337
                    $tableRss[]    = $tables[$t]->getVar('table_rss');
338
                    $tableSearch[] = $tables[$t]->getVar('table_search');
339
                    $tableSingle[] = $tables[$t]->getVar('table_single');
340
                    $tableSubmit[] = $tables[$t]->getVar('table_submit');
341
                    $tableRate[]   = $tables[$t]->getVar('table_rate');
342
                    $item[]        = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '');
343
                    $item[]        = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'list');
344
                    $item[]        = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'item');
345
                }
346
            }
347
            $item[]  = $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs', '');
348
            if (\in_array(1, $tablePdf)) {
349
                foreach (\array_keys($tables) as $t) {
350
                    if ($tables[$t]->getVar('table_pdf')) {
351
                        $tableName = $tables[$t]->getVar('table_name');
352
                        $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName . '_pdf', '');
353
                    }
354
                }
355
            }
356
            if (\in_array(1, $tablePrint)) {
357
                foreach (\array_keys($tables) as $t) {
358
                    if ($tables[$t]->getVar('table_print')) {
359
                        $tableName = $tables[$t]->getVar('table_name');
360
                        $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName . '_print', '');
361
                    }
362
                }
363
            }
364
            if (\in_array(1, $tableRate)) {
365
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate', '');
366
            }
367
            if (\in_array(1, $tableRss)) {
368
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss', '');
369
            }
370
            if (\in_array(1, $tableSearch)) {
371
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'search', '');
372
            }
373
            if (\in_array(1, $tableSingle)) {
374
                $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'single', '');
375
            }
376
            $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '');
377
        }
378
379
        $ret .= $this->uxc->getUserModVersionArray(11, $item, "templates");
380
381
        return $ret;
382
    }
383
384
    /**
385
     * @private function getXoopsVersionTemplatesLine
386
     * @param        $moduleDirname
387
     * @param        $type
388
     * @param string $extra
389
     * @param bool   $isAdmin
390
     * @return string
391
     */
392
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = '', $isAdmin = false)
393
    {
394
        $ret         = '';
395
        $desc        = "'description' => ''";
396
        $arrayFile   = "['file' =>";
397
        if ($isAdmin) {
398
            $ret .= "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin']";
399
        } else {
400
            if ('' !== $extra) {
401
                $ret .= "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc}]";
402
            } else {
403
                $ret .= "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc}]";
404
            }
405
        }
406
407
        return $ret;
408
    }
409
410
    /**
411
     * @private function getXoopsVersionSubmenu
412
     * @param $language
413
     * @param $tables
414
     * @return string
415
     */
416
    private function getXoopsVersionSubmenu($language, $tables)
417
    {
418
        $ret     = $this->getDashComment('Menu');
419
        $xModule = $this->pc->getPhpCodeGlobals('xoopsModule');
420
        $cond    = 'isset(' . $xModule . ') && \is_object(' . $xModule . ')';
421
        $one     =  $this->pc->getPhpCodeGlobals('xoopsModule') . "->getVar('dirname')";
422
        $ret     .= $this->pc->getPhpCodeTernaryOperator('currdirname ', $cond, $one, "'system'");
423
424
        $i          = 1;
425
        $descriptions = [
426
            'name' => "{$language}SMNAME{$i}",
427
            'url'  => "'index.php'",
428
        ];
429
        $contentIf  = $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t");
430
        ++$i;
431
432
        $tableSearch = [];
433
        foreach (\array_keys($tables) as $t) {
434
            $tableName     = $tables[$t]->getVar('table_name');
435
            $tableSearch[] = $tables[$t]->getVar('table_search');
436
            if (1 == $tables[$t]->getVar('table_submenu')) {
437
                $contentIf .= $this->pc->getPhpCodeCommentLine('Sub', $tableName, "\t");
438
                $descriptions = [
439
                    'name' => "{$language}SMNAME{$i}",
440
                    'url'  => "'{$tableName}.php'",
441
                ];
442
                $contentIf  .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t");
443
                unset($item);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $item seems to be never defined.
Loading history...
444
            }
445
            ++$i;
446
            if (1 == $tables[$t]->getVar('table_submit')) {
447
                $contentIf .= $this->pc->getPhpCodeCommentLine('Sub', 'Submit', "\t");
448
                $descriptions = [
449
                    'name' => "{$language}SMNAME{$i}",
450
                    'url'  => "'{$tableName}.php?op=new'",
451
                ];
452
                $contentIf  .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t");
453
                ++$i;
454
            }
455
        }
456
457
        //TODO: after finalizing creation of search.php by User/UserSearch.php this sub menu item can be activated
458
        /*
459
        if (\in_array(1, $tableSearch)) {
460
            $contentIf .= $cpc->getPhpCodeCommentLine('Sub', 'Search', "\t");
461
            $descriptions = [
462
                'name' => "{$language}SMNAME{$i}",
463
                'url'  => "'search.php'",
464
            ];
465
            $contentIf  .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t");
466
        }
467
        */
468
        unset($i);
469
470
        $ret .= $this->pc->getPhpCodeConditions('$moduleDirName', ' == ', '$currdirname', $contentIf);
471
472
        return $ret;
473
    }
474
475
    /**
476
     * @private function getXoopsVersionBlocks
477
     * @param $moduleDirname
478
     * @param $tables
479
     * @param $language
480
     * @return string
481
     */
482
    private function getXoopsVersionBlocks($moduleDirname, $tables, $language)
483
    {
484
        $ret = $this->getDashComment('Default Blocks');
485
        foreach (\array_keys($tables) as $i) {
486
            $tableName        = $tables[$i]->getVar('table_name');
487
            if (0 == $tables[$i]->getVar('table_category') && 1 == $tables[$i]->getVar('table_blocks')) {
488
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'LAST', $language, 'last');
489
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'NEW', $language, 'new');
490
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'HITS', $language, 'hits');
491
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'TOP', $language, 'top');
492
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'RANDOM', $language, 'random');
493
            }
494
        }
495
        $ret .= $this->getDashComment('Spotlight Blocks');
496
        foreach (\array_keys($tables) as $i) {
497
            $tableName        = $tables[$i]->getVar('table_name');
498
            if (0 == $tables[$i]->getVar('table_category') && 1 == $tables[$i]->getVar('table_blocks')) {
499
                $ret .= $this->getXoopsVersionSpotlightBlocks($moduleDirname, $tableName, '', $language, 'spotlight');
500
            }
501
        }
502
503
        return $ret;
504
    }
505
506
    /**
507
     * @private function getXoopsVersionTypeBlocks
508
     * @param $moduleDirname
509
     * @param $tableName
510
     * @param $stuTableSoleName
511
     * @param $language
512
     * @param $type
513
     * @return string
514
     */
515
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type)
516
    {
517
        $stuTableName    = \mb_strtoupper($tableName);
518
        $ucfTableName    = \ucfirst($tableName);
519
        $ret             = $this->pc->getPhpCodeCommentLine($ucfTableName . ' ' . $type);
520
        $blocks          = [
521
            'file'        => "'{$tableName}.php'",
522
            'name'        => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}",
523
            'description' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC",
524
            'show_func'   => "'b_{$moduleDirname}_{$tableName}_show'",
525
            'edit_func'   => "'b_{$moduleDirname}_{$tableName}_edit'",
526
            'template'    => "'{$moduleDirname}_block_{$tableName}.tpl'",
527
            'options'     => "'{$type}|5|25|0'",
528
        ];
529
        $ret             .= $this->uxc->getUserModVersionArray(2, $blocks, 'blocks');
530
531
        return $ret;
532
    }
533
534
    /**
535
     * @private function getXoopsVersionTypeBlocks
536
     * @param $moduleDirname
537
     * @param $tableName
538
     * @param $stuTableSoleName
539
     * @param $language
540
     * @param $type
541
     * @return string
542
     */
543
    private function getXoopsVersionSpotlightBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type)
0 ignored issues
show
Unused Code introduced by
The parameter $stuTableSoleName is not used and could be removed. ( Ignorable by Annotation )

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

543
    private function getXoopsVersionSpotlightBlocks($moduleDirname, $tableName, /** @scrutinizer ignore-unused */ $stuTableSoleName, $language, $type)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
544
    {
545
        $stuTableName    = \mb_strtoupper($tableName);
546
        $ucfTableName    = \ucfirst($tableName);
547
        $ret             = $this->pc->getPhpCodeCommentLine($ucfTableName . ' ' . $type);
548
        $blocks          = [
549
            'file'        => "'{$tableName}_spotlight.php'",
550
            'name'        => "{$language}{$stuTableName}_BLOCK_SPOTLIGHT",
551
            'description' => "{$language}{$stuTableName}_BLOCK_SPOTLIGHT_DESC",
552
            'show_func'   => "'b_{$moduleDirname}_{$tableName}_spotlight_show'",
553
            'edit_func'   => "'b_{$moduleDirname}_{$tableName}_spotlight_edit'",
554
            'template'    => "'{$moduleDirname}_block_{$tableName}_spotlight.tpl'",
555
            'options'     => "'{$type}|5|25|0'",
556
        ];
557
        $ret             .= $this->uxc->getUserModVersionArray(2, $blocks, 'blocks');
558
559
        return $ret;
560
    }
561
562
    /**
563
     * @private function getXoopsVersionConfig
564
     * @param $module
565
     * @param $tables
566
     * @param $language
567
     *
568
     * @return string
569
     */
570
    private function getXoopsVersionConfig($module, $tables, $language)
571
    {
572
        $moduleDirname  = $module->getVar('mod_dirname');
573
        $ret            = $this->getDashComment('Config');
574
575
        $table_editors     = 0;
576
        $table_permissions = 0;
577
        $table_admin       = 0;
578
        $table_user        = 0;
579
        $table_tag         = 0;
580
        $table_uploadimage = 0;
581
        $table_uploadfile  = 0;
582
        $table_rate        = 0;
583
        foreach ($tables as $table) {
584
            $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
585
            foreach (\array_keys($fields) as $f) {
586
                $fieldElement = (int)$fields[$f]->getVar('field_element');
587
                switch ($fieldElement) {
588
                    case 3:
589
                        $table_editors = 1;
590
                        break;
591
                    case 4:
592
                        $table_editors = 1;
593
                        break;
594
                    case 10:
595
                    case 11:
596
                    case 12:
597
                    case 13:
598
                        $table_uploadimage = 1;
599
                        break;
600
                    case 14:
601
                        $table_uploadfile = 1;
602
                        break;
603
                    case 'else':
604
                    default:
605
                        break;
606
                }
607
            }
608
            if (1 == $table->getVar('table_permissions')) {
609
                $table_permissions = 1;
610
            }
611
            if (1 == $table->getVar('table_admin')) {
612
                $table_admin = 1;
613
            }
614
            if (1 == $table->getVar('table_user')) {
615
                $table_user = 1;
616
            }
617
            if (1 == $table->getVar('table_tag')) {
618
                $table_tag = 1;
619
            }
620
            if (1 == $table->getVar('table_rate')) {
621
                $table_rate = 1;
622
            }
623
        }
624
        if (1 === $table_editors) {
625
            $ret          .= $this->pc->getPhpCodeCommentLine('Editor Admin', '');
626
            $ret          .= $this->xc->getXcXoopsLoad('xoopseditorhandler');
627
            $ret          .= $this->xc->getXcEqualsOperator('$editorHandler', 'XoopsEditorHandler::getInstance()');
628
            $editor       = [
629
                'name'        => "'editor_admin'",
630
                'title'       => "'{$language}EDITOR_ADMIN'",
631
                'description' => "'{$language}EDITOR_ADMIN_DESC'",
632
                'formtype'    => "'select'",
633
                'valuetype'   => "'text'",
634
                'default'     => "'dhtml'",
635
                'options'     => 'array_flip($editorHandler->getList())',
636
            ];
637
            $ret          .= $this->uxc->getUserModVersionArray(2, $editor, 'config');
638
            $ret          .= $this->pc->getPhpCodeCommentLine('Editor User', '');
639
            $ret          .= $this->xc->getXcXoopsLoad('xoopseditorhandler');
640
            $ret          .= $this->xc->getXcEqualsOperator('$editorHandler', 'XoopsEditorHandler::getInstance()');
641
            $editor       = [
642
                'name'        => "'editor_user'",
643
                'title'       => "'{$language}EDITOR_USER'",
644
                'description' => "'{$language}EDITOR_USER_DESC'",
645
                'formtype'    => "'select'",
646
                'valuetype'   => "'text'",
647
                'default'     => "'dhtml'",
648
                'options'     => 'array_flip($editorHandler->getList())',
649
            ];
650
            $ret          .= $this->uxc->getUserModVersionArray(2, $editor, 'config');
651
            $ret .= $this->pc->getPhpCodeCommentLine('Editor : max characters admin area');
652
            $maxsize_image    = [
653
                'name'        => "'editor_maxchar'",
654
                'title'       => "'{$language}EDITOR_MAXCHAR'",
655
                'description' => "'{$language}EDITOR_MAXCHAR_DESC'",
656
                'formtype'    => "'textbox'",
657
                'valuetype'   => "'int'",
658
                'default'     => '50',
659
            ];
660
            $ret .= $this->uxc->getUserModVersionArray(2, $maxsize_image, 'config');
661
        }
662
        if (1 === $table_permissions) {
663
            $ret    .= $this->pc->getPhpCodeCommentLine('Get groups');
664
            $ret    .= $this->xc->getXcXoopsHandler('member');
665
            $ret    .= $this->xc->getXcEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
666
            $ret    .= $this->xc->getXcEqualsOperator('$groups', '[]');
667
            $group  = $this->xc->getXcEqualsOperator('$groups[$group] ', '$key', null, "\t");
668
            $ret    .= $this->pc->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
669
            $ret    .= $this->pc->getPhpCodeCommentLine('General access groups');
670
            $groups = [
671
                'name'        => "'groups'",
672
                'title'       => "'{$language}GROUPS'",
673
                'description' => "'{$language}GROUPS_DESC'",
674
                'formtype'    => "'select_multi'",
675
                'valuetype'   => "'array'",
676
                'default'     => '$groups',
677
                'options'     => '$groups',
678
            ];
679
            $ret .= $this->uxc->getUserModVersionArray(2, $groups, 'config');
680
            $ret .= $this->pc->getPhpCodeCommentLine('Upload groups');
681
            $uplgroups  = [
682
                'name'        => "'upload_groups'",
683
                'title'       => "'{$language}UPLOAD_GROUPS'",
684
                'description' => "'{$language}UPLOAD_GROUPS_DESC'",
685
                'formtype'    => "'select_multi'",
686
                'valuetype'   => "'array'",
687
                'default'     => '$groups',
688
                'options'     => '$groups',
689
            ];
690
            $ret         .= $this->uxc->getUserModVersionArray(2, $uplgroups, 'config');
691
692
            $ret         .= $this->pc->getPhpCodeCommentLine('Get Admin groups');
693
            $ret         .= $this->xc->getXcCriteriaCompo('crGroups');
694
            $crit        = $this->xc->getXcCriteria('', "'group_type'", "'Admin'", '', true);
695
            $ret         .= $this->xc->getXcCriteriaAdd('crGroups', $crit, '', "\n");
696
            $ret         .= $this->xc->getXcXoopsHandler('member');
697
            $ret         .= $this->xc->getXcEqualsOperator('$adminXoopsGroups ', '$memberHandler->getGroupList($crGroups)');
698
            $ret         .= $this->xc->getXcEqualsOperator('$adminGroups', '[]');
699
            $adminGroup  = $this->xc->getXcEqualsOperator('$adminGroups[$adminGroup] ', '$key', null, "\t");
700
            $ret         .= $this->pc->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
701
            $adminGroups = [
702
                'name'        => "'admin_groups'",
703
                'title'       => "'{$language}ADMIN_GROUPS'",
704
                'description' => "'{$language}ADMIN_GROUPS_DESC'",
705
                'formtype'    => "'select_multi'",
706
                'valuetype'   => "'array'",
707
                'default'     => '$adminGroups',
708
                'options'     => '$adminGroups',
709
            ];
710
            $ret         .= $this->uxc->getUserModVersionArray(2, $adminGroups, 'config');
711
			$ret         .= $this->pc->getPhpCodeUnset('crGroups');
712
        }
713
714
        if (1 === $table_rate) {
715
            $ret    .= $this->pc->getPhpCodeCommentLine('Get groups');
716
            $ret    .= $this->xc->getXcXoopsHandler('member');
717
            $ret    .= $this->xc->getXcEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
718
            $ret    .= $this->xc->getXcEqualsOperator('$ratingbar_groups', '[]');
719
            $group  = $this->xc->getXcEqualsOperator('$ratingbar_groups[$group] ', '$key', null, "\t");
720
            $ret    .= $this->pc->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
721
            $ret    .= $this->pc->getPhpCodeCommentLine('Rating: Groups with rating permissions');
722
            $groups = [
723
                'name'        => "'ratingbar_groups'",
724
                'title'       => "'{$language}RATINGBAR_GROUPS'",
725
                'description' => "'{$language}RATINGBAR_GROUPS_DESC'",
726
                'formtype'    => "'select_multi'",
727
                'valuetype'   => "'array'",
728
                'default'     => '[1]',
729
                'options'     => '$ratingbar_groups',
730
            ];
731
            $ret .= $this->uxc->getUserModVersionArray(2, $groups, 'config');
732
733
            $ret .= $this->pc->getPhpCodeCommentLine('Rating : used ratingbar');
734
            $mimetypes_image  = [
735
                'name'        => "'ratingbars'",
736
                'title'       => "'{$language}RATINGBARS'",
737
                'description' => "'{$language}RATINGBARS_DESC'",
738
                'formtype'    => "'select'",
739
                'valuetype'   => "'int'",
740
                'default'     => "0",
741
                'options'     => "['{$language}RATING_NONE' => 0, '{$language}RATING_5STARS' => 1, '{$language}RATING_10STARS' => 2, '{$language}RATING_LIKES' => 3, '{$language}RATING_10NUM' => 4]",
742
            ];
743
            $ret .= $this->uxc->getUserModVersionArray(2, $mimetypes_image, 'config');
744
        }
745
746
        $keyword      = \implode(', ', $this->getKeywords());
747
        $ret          .= $this->pc->getPhpCodeCommentLine('Keywords');
748
        $arrayKeyword = [
749
            'name'        => "'keywords'",
750
            'title'       => "'{$language}KEYWORDS'",
751
            'description' => "'{$language}KEYWORDS_DESC'",
752
            'formtype'    => "'textbox'",
753
            'valuetype'   => "'text'",
754
            'default'     => "'{$moduleDirname}, {$keyword}'",
755
        ];
756
        $ret .= $this->uxc->getUserModVersionArray(2, $arrayKeyword, 'config');
757
        unset($this->keywords);
0 ignored issues
show
Bug Best Practice introduced by
The property keywords does not exist on XoopsModules\Modulebuild...s\User\UserXoopsVersion. Did you maybe forget to declare it?
Loading history...
758
759
        if (1 === $table_uploadimage || 1 === $table_uploadfile) {
760
            $ret       .= $this->getXoopsVersionSelectSizeMB($moduleDirname);
761
        }
762
        if (1 === $table_uploadimage) {
763
            $ret .= $this->pc->getPhpCodeCommentLine('Uploads : maxsize of image');
764
            $maxsize_image    = [
765
                'name'        => "'maxsize_image'",
766
                'title'       => "'{$language}MAXSIZE_IMAGE'",
767
                'description' => "'{$language}MAXSIZE_IMAGE_DESC'",
768
                'formtype'    => "'select'",
769
                'valuetype'   => "'int'",
770
                'default'     => '3145728',
771
                'options'     => '$optionMaxsize',
772
            ];
773
            $ret .= $this->uxc->getUserModVersionArray(2, $maxsize_image, 'config');
774
            $ret .= $this->pc->getPhpCodeCommentLine('Uploads : mimetypes of image');
775
            $mimetypes_image  = [
776
                'name'        => "'mimetypes_image'",
777
                'title'       => "'{$language}MIMETYPES_IMAGE'",
778
                'description' => "'{$language}MIMETYPES_IMAGE_DESC'",
779
                'formtype'    => "'select_multi'",
780
                'valuetype'   => "'array'",
781
                'default'     => "['image/gif', 'image/jpeg', 'image/png']",
782
                'options'     => "['bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg', 'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe', 'png' => 'image/png']",
783
            ];
784
            $ret .= $this->uxc->getUserModVersionArray(2, $mimetypes_image, 'config');
785
            $maxwidth_image   = [
786
                'name'        => "'maxwidth_image'",
787
                'title'       => "'{$language}MAXWIDTH_IMAGE'",
788
                'description' => "'{$language}MAXWIDTH_IMAGE_DESC'",
789
                'formtype'    => "'textbox'",
790
                'valuetype'   => "'int'",
791
                'default'     => '800',
792
            ];
793
            $ret .= $this->uxc->getUserModVersionArray(2, $maxwidth_image, 'config');
794
            $maxheight_image   = [
795
                'name'        => "'maxheight_image'",
796
                'title'       => "'{$language}MAXHEIGHT_IMAGE'",
797
                'description' => "'{$language}MAXHEIGHT_IMAGE_DESC'",
798
                'formtype'    => "'textbox'",
799
                'valuetype'   => "'int'",
800
                'default'     => '800',
801
            ];
802
            $ret .= $this->uxc->getUserModVersionArray(2, $maxheight_image, 'config');
803
        }
804
        if (1 === $table_uploadfile) {
805
            $ret .= $this->pc->getPhpCodeCommentLine('Uploads : maxsize of file');
806
            $maxsize_file     = [
807
                'name'        => "'maxsize_file'",
808
                'title'       => "'{$language}MAXSIZE_FILE'",
809
                'description' => "'{$language}MAXSIZE_FILE_DESC'",
810
                'formtype'    => "'select'",
811
                'valuetype'   => "'int'",
812
                'default'     => '3145728',
813
                'options'     => '$optionMaxsize',
814
            ];
815
            $ret .= $this->uxc->getUserModVersionArray(2, $maxsize_file, 'config');
816
            $ret .= $this->pc->getPhpCodeCommentLine('Uploads : mimetypes of file');
817
            $mimetypes_file   = [
818
                'name'        => "'mimetypes_file'",
819
                'title'       => "'{$language}MIMETYPES_FILE'",
820
                'description' => "'{$language}MIMETYPES_FILE_DESC'",
821
                'formtype'    => "'select_multi'",
822
                'valuetype'   => "'array'",
823
                'default'     => "['application/pdf', 'application/zip', 'text/comma-separated-values', 'text/plain', 'image/gif', 'image/jpeg', 'image/png']",
824
                'options'     => "['gif' => 'image/gif','pjpeg' => 'image/pjpeg', 'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe', 'png' => 'image/png', 'pdf' => 'application/pdf','zip' => 'application/zip','csv' => 'text/comma-separated-values', 'txt' => 'text/plain', 'xml' => 'application/xml', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']",
825
            ];
826
            $ret .= $this->uxc->getUserModVersionArray(2, $mimetypes_file, 'config');
827
        }
828
        if (1 === $table_admin) {
829
            $ret .= $this->pc->getPhpCodeCommentLine('Admin pager');
830
            $adminPager = [
831
                'name'        => "'adminpager'",
832
                'title'       => "'{$language}ADMIN_PAGER'",
833
                'description' => "'{$language}ADMIN_PAGER_DESC'",
834
                'formtype'    => "'textbox'",
835
                'valuetype'   => "'int'",
836
                'default'     => '10',
837
            ];
838
            $ret .= $this->uxc->getUserModVersionArray(2, $adminPager, 'config');
839
        }
840
        if (1 === $table_user) {
841
            $ret .= $this->pc->getPhpCodeCommentLine('User pager');
842
            $userPager = [
843
                'name'        => "'userpager'",
844
                'title'       => "'{$language}USER_PAGER'",
845
                'description' => "'{$language}USER_PAGER_DESC'",
846
                'formtype'    => "'textbox'",
847
                'valuetype'   => "'int'",
848
                'default'     => '10',
849
            ];
850
            $ret .= $this->uxc->getUserModVersionArray(2, $userPager, 'config');
851
        }
852
        if (1 === $table_tag) {
853
            $ret .= $this->pc->getPhpCodeCommentLine('Use tag');
854
            $useTag = [
855
                'name'        => "'usetag'",
856
                'title'       => "'{$language}USE_TAG'",
857
                'description' => "'{$language}USE_TAG_DESC'",
858
                'formtype'    => "'yesno'",
859
                'valuetype'   => "'int'",
860
                'default'     => '0',
861
            ];
862
            $ret .= $this->uxc->getUserModVersionArray(2, $useTag, 'config');
863
        }
864
        $ret .= $this->pc->getPhpCodeCommentLine('Number column');
865
        $numbCol          = [
866
            'name'        => "'numb_col'",
867
            'title'       => "'{$language}NUMB_COL'",
868
            'description' => "'{$language}NUMB_COL_DESC'",
869
            'formtype'    => "'select'",
870
            'valuetype'   => "'int'",
871
            'default'     => '1',
872
            'options'     => "[1 => '1', 2 => '2', 3 => '3', 4 => '4']",
873
        ];
874
        $ret .= $this->uxc->getUserModVersionArray(2, $numbCol, 'config');
875
876
        $ret .= $this->pc->getPhpCodeCommentLine('Divide by');
877
        $divideby         = [
878
            'name'        => "'divideby'",
879
            'title'       => "'{$language}DIVIDEBY'",
880
            'description' => "'{$language}DIVIDEBY_DESC'",
881
            'formtype'    => "'select'",
882
            'valuetype'   => "'int'",
883
            'default'     => '1',
884
            'options'     => "[1 => '1', 2 => '2', 3 => '3', 4 => '4']",
885
        ];
886
        $ret .= $this->uxc->getUserModVersionArray(2, $divideby, 'config');
887
888
        $ret .= $this->pc->getPhpCodeCommentLine('Table type');
889
        $tableType        = [
890
            'name'        => "'table_type'",
891
            'title'       => "'{$language}TABLE_TYPE'",
892
            'description' => "'{$language}DIVIDEBY_DESC'",
893
            'formtype'    => "'select'",
894
            'valuetype'   => "'int'",
895
            'default'     => "'bordered'",
896
            'options'     => "['bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed']",
897
        ];
898
        $ret              .= $this->uxc->getUserModVersionArray(2, $tableType, 'config');
899
900
        $ret              .= $this->pc->getPhpCodeCommentLine('Panel by');
901
        $panelType        = [
902
            'name'        => "'panel_type'",
903
            'title'       => "'{$language}PANEL_TYPE'",
904
            'description' => "'{$language}PANEL_TYPE_DESC'",
905
            'formtype'    => "'select'",
906
            'valuetype'   => "'text'",
907
            'default'     => "'default'",
908
            'options'     => "['default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger']",
909
        ];
910
        $ret              .= $this->uxc->getUserModVersionArray(2, $panelType, 'config');
911
        $ret              .= $this->pc->getPhpCodeCommentLine('Paypal ID');
912
        $paypal           = [
913
            'name'        => "'donations'",
914
            'title'       => "'{$language}IDPAYPAL'",
915
            'description' => "'{$language}IDPAYPAL_DESC'",
916
            'formtype'    => "'textbox'",
917
            'valuetype'   => "'textbox'",
918
            'default'     => "'XYZ123'",
919
        ];
920
        $ret              .= $this->uxc->getUserModVersionArray(2, $paypal, 'config');
921
        $ret              .= $this->pc->getPhpCodeCommentLine('Show Breadcrumbs');
922
        $breadcrumbs      = [
923
            'name'        => "'show_breadcrumbs'",
924
            'title'       => "'{$language}SHOW_BREADCRUMBS'",
925
            'description' => "'{$language}SHOW_BREADCRUMBS_DESC'",
926
            'formtype'    => "'yesno'",
927
            'valuetype'   => "'int'",
928
            'default'     => '1',
929
        ];
930
        $ret              .= $this->uxc->getUserModVersionArray(2, $breadcrumbs, 'config');
931
        $ret              .= $this->pc->getPhpCodeCommentLine('Advertise');
932
        $advertise        = [
933
            'name'        => "'advertise'",
934
            'title'       => "'{$language}ADVERTISE'",
935
            'description' => "'{$language}ADVERTISE_DESC'",
936
            'formtype'    => "'textarea'",
937
            'valuetype'   => "'text'",
938
            'default'     => "''",
939
        ];
940
        $ret              .= $this->uxc->getUserModVersionArray(2, $advertise, 'config');
941
        $ret              .= $this->pc->getPhpCodeCommentLine('Bookmarks');
942
        $bookmarks        = [
943
            'name'        => "'bookmarks'",
944
            'title'       => "'{$language}BOOKMARKS'",
945
            'description' => "'{$language}BOOKMARKS_DESC'",
946
            'formtype'    => "'yesno'",
947
            'valuetype'   => "'int'",
948
            'default'     => '0',
949
        ];
950
        $ret              .= $this->uxc->getUserModVersionArray(2, $bookmarks, 'config');
951
952
        /*
953
         * removed, as there are no system templates in xoops core for fb or disqus comments
954
         * modulebuilder currently is also not creatings tpl files for this
955
        $ret              .= $this->pc->getPhpCodeCommentLine('Facebook Comments');
956
        $facebookComments = [
957
            'name'        => "'facebook_comments'",
958
            'title'       => "'{$language}FACEBOOK_COMMENTS'",
959
            'description' => "'{$language}FACEBOOK_COMMENTS_DESC'",
960
            'formtype'    => "'yesno'",
961
            'valuetype'   => "'int'",
962
            'default'     => '0',
963
        ];
964
        $ret              .= $this->uxc->getUserModVersion(3, $facebookComments, 'config', '$c');
965
        $ret              .= $this->getSimpleString('++$c;');
966
        $ret              .= $this->pc->getPhpCodeCommentLine('Disqus Comments');
967
        $disqusComments   = [
968
            'name'        => "'disqus_comments'",
969
            'title'       => "'{$language}DISQUS_COMMENTS'",
970
            'description' => "'{$language}DISQUS_COMMENTS_DESC'",
971
            'formtype'    => "'yesno'",
972
            'valuetype'   => "'int'",
973
            'default'     => '0',
974
        ];
975
        $ret              .= $this->uxc->getUserModVersion(3, $disqusComments, 'config', '$c');
976
        $ret              .= $this->getSimpleString('++$c;');
977
        */
978
979
        $ret              .= $this->pc->getPhpCodeCommentLine('Make Sample button visible?');
980
        $maintainedby     = [
981
            'name'        => "'displaySampleButton'",
982
            'title'       => "'CO_' . \$moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON'",
983
            'description' => "'CO_' . \$moduleDirNameUpper . '_' . 'SHOW_SAMPLE_BUTTON_DESC'",
984
            'formtype'    => "'yesno'",
985
            'valuetype'   => "'int'",
986
            'default'     => '1',
987
        ];
988
        $ret              .= $this->uxc->getUserModVersionArray(2, $maintainedby, 'config');
989
990
        $ret              .= $this->pc->getPhpCodeCommentLine('Maintained by');
991
        $maintainedby     = [
992
            'name'        => "'maintainedby'",
993
            'title'       => "'{$language}MAINTAINEDBY'",
994
            'description' => "'{$language}MAINTAINEDBY_DESC'",
995
            'formtype'    => "'textbox'",
996
            'valuetype'   => "'text'",
997
            'default'     => "'{$module->getVar('mod_support_url')}'",
998
        ];
999
        $ret              .= $this->uxc->getUserModVersionArray(2, $maintainedby, 'config');
1000
1001
        return $ret;
1002
    }
1003
1004
    /**
1005
     * @private function getXoopsVersionNotifications
1006
     * @param $module
1007
     * @param $language
1008
     * @return string
1009
     */
1010
    private function getXoopsVersionNotifications($module, $language)
1011
    {
1012
        $moduleDirname = $module->getVar('mod_dirname');
1013
        $ret           = $this->getDashComment('Notifications');
1014
        $ret           .= $this->uxc->getUserModVersionText(1, 1, 'hasNotification');
1015
        $notifications = ['lookup_file' => "'include/notification.inc.php'", 'lookup_func' => "'{$moduleDirname}_notify_iteminfo'"];
1016
        $ret           .= $this->uxc->getUserModVersionArray(1, $notifications, 'notification');
1017
1018
        $notifyFiles       = [];
1019
        $tables            = $this->getTableTables($module->getVar('mod_id'), 'table_order');
1020
        $tableCategory     = [];
1021
        $tableBroken       = [];
1022
        $tableComments     = [];
1023
        $tableSubmit       = [];
1024
        $tableId           = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $tableId is dead and can be removed.
Loading history...
1025
        $tableMid          = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $tableMid is dead and can be removed.
Loading history...
1026
        $notifyCategory    = '';
1027
        $notifyEventGlobal = $this->pc->getPhpCodeCommentLine('Global events notification');
1028
        $notifyEventTable  = $this->pc->getPhpCodeCommentLine('Event notifications for items');
1029
1030
        //global events
1031
        $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_new', 'global', 0, 'global_new', 'global_new_notify');
1032
        $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_modify', 'global', 0, 'global_modify', 'global_modify_notify');
1033
        $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_delete', 'global', 0, 'global_delete', 'global_delete_notify');
1034
        $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_approve', 'global', 1, 'global_approve', 'global_approve_notify');
1035
        foreach (\array_keys($tables) as $t) {
1036
            $tableBroken[]   = $tables[$t]->getVar('table_broken');
1037
            $tableComments[] = $tables[$t]->getVar('table_comments');
1038
        }
1039
        if (\in_array(1, $tableBroken)) {
1040
            $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_broken', 'global', 1, 'global_broken', 'global_broken_notify');
1041
        }
1042
        if (\in_array(1, $tableComments)) {
1043
            $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_comment', 'global', 0, 'global_comment', 'global_comment_notify');
1044
        }
1045
1046
        foreach (\array_keys($tables) as $t) {
1047
            $tableId         = $tables[$t]->getVar('table_id');
1048
            $tableMid        = $tables[$t]->getVar('table_mid');
1049
            $tableName       = $tables[$t]->getVar('table_name');
1050
            $tableSoleName   = $tables[$t]->getVar('table_solename');
1051
            $tableCategory[] = $tables[$t]->getVar('table_category');
1052
            $tableSubmit[]   = $tables[$t]->getVar('table_submit');
1053
            $fields      = $this->getTableFields($tableMid, $tableId);
1054
            $fieldId     = 0;
1055
            foreach (\array_keys($fields) as $f) {
1056
                $fieldName    = $fields[$f]->getVar('field_name');
1057
                if (0 == $f) {
1058
                    $fieldId = $fieldName;
1059
                }
1060
            }
1061
            if (1 == $tables[$t]->getVar('table_notifications')) {
1062
                $notifyFiles[] = $tableName;
1063
                $notifyCategory .= $this->getXoopsVersionNotificationTableName($language, 'category', $tableName, $tableSoleName, $tableName, $fieldId, 1);
1064
                //$notifyEvent .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_new', $tableName, 0, $tableSoleName, $tableSoleName . '_new_notify');
1065
                $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_modify', $tableName, 0, $tableSoleName . '_modify', $tableSoleName . '_modify_notify');
1066
                $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_delete', $tableName, 0, $tableSoleName . '_delete', $tableSoleName . '_delete_notify');
1067
                $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_approve', $tableName, 0, $tableSoleName . '_approve', $tableSoleName . '_approve_notify');
1068
                if (1 == $tables[$t]->getVar('table_broken')) {
1069
                    $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_broken', $tableName, 0, $tableSoleName . '_broken', $tableSoleName . '_broken_notify');
1070
                }
1071
                /*event will be added by xoops
1072
                if (1 == $tables[$t]->getVar('table_comments')) {
1073
                    $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_comment', $tableName, 0, $tableSoleName . '_comment', $tableSoleName . '_comment_notify');
1074
                }*/
1075
            }
1076
        }
1077
        $ret .= $this->pc->getPhpCodeCommentLine('Categories of notification');
1078
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles);
1079
1080
        //$ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1');
1081
1082
        $ret .= $notifyCategory . $notifyEventGlobal . $notifyEventTable;
1083
1084
1085
        return $ret;
1086
    }
1087
1088
    /**
1089
     * @private function getXoopsVersionNotificationGlobal
1090
     * @param $language
1091
     * @param $type
1092
     * @param $name
1093
     * @param $title
1094
     * @param $from
1095
     *
1096
     * @return string
1097
     */
1098
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from)
1099
    {
1100
        $title       = \mb_strtoupper($title);
1101
        $implodeFrom = \implode(".php', '", $from);
1102
        $ret         = $this->pc->getPhpCodeCommentLine('Global Notify');
1103
        $global      = [
1104
            'name'           => "'{$name}'",
1105
            'title'          => "{$language}NOTIFY_{$title}",
1106
            'description'    => "''",
1107
            'subscribe_from' => "['index.php', '{$implodeFrom}.php']",
1108
        ];
1109
        $ret         .= $this->uxc->getUserModVersionArray(3, $global, 'notification', "'{$type}'");
1110
1111
        return $ret;
1112
    }
1113
1114
1115
    /**
1116
     * @private function getXoopsVersionNotificationTableName
1117
     * @param $language
1118
     * @param $type
1119
     * @param $name
1120
     * @param $title
1121
     * @param $file
1122
     * @param $item
1123
     * @param $allow
1124
     *
1125
     * @return string
1126
     */
1127
    private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $file, $item, $allow)
1128
    {
1129
        $stuTitle = \mb_strtoupper($title);
1130
        $ucfTitle = \ucfirst($title);
1131
        $ret      = $this->pc->getPhpCodeCommentLine($ucfTitle . ' Notify');
1132
        $table    = [
1133
            'name'           => "'{$name}'",
1134
            'title'          => "{$language}NOTIFY_{$stuTitle}",
1135
            'description'    => "''",
1136
            'subscribe_from' => "'{$file}.php'",
1137
            'item_name'      => "'{$item}'",
1138
            'allow_bookmark' => (string)$allow,
1139
        ];
1140
        $ret .= $this->uxc->getUserModVersionArray(3, $table, 'notification', "'{$type}'");
1141
1142
        return $ret;
1143
    }
1144
1145
    /**
1146
     * @private function getXoopsVersionNotifications
1147
     * @param $language
1148
     * @param $type
1149
     * @param $name
1150
     * @param $category
1151
     * @param $admin
1152
     * @param $title
1153
     * @param $mail
1154
     *
1155
     * @return string
1156
     */
1157
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin, $title, $mail)
1158
    {
1159
        $title    = \mb_strtoupper($title);
1160
        $ucfTitle = \ucfirst($title);
1161
        $ret      = $this->pc->getPhpCodeCommentLine($ucfTitle . ' Notify');
1162
        $event    = [
1163
            'name'          => "'{$name}'",
1164
            'category'      => "'{$category}'",
1165
            'admin_only'    => (string)$admin,
1166
            'title'         => "{$language}NOTIFY_{$title}",
1167
            'caption'       => "{$language}NOTIFY_{$title}_CAPTION",
1168
            'description'   => "''",
1169
            'mail_template' => "'{$mail}'",
1170
            'mail_subject'  => "{$language}NOTIFY_{$title}_SUBJECT",
1171
        ];
1172
        $ret .= $this->uxc->getUserModVersionArray(3, $event, 'notification', "'{$type}'");
1173
1174
        return $ret;
1175
    }
1176
1177
    /**
1178
     * @private function getXoopsVersionNotifications
1179
     * @param $moduleDirname
1180
     * @param string $t
1181
     * @return string
1182
     */
1183
    private function getXoopsVersionSelectSizeMB($moduleDirname, $t = '')
1184
    {
1185
        $ucModuleDirname       = \mb_strtoupper($moduleDirname);
1186
1187
        $ret  = $this->pc->getPhpCodeCommentLine('create increment steps for file size');
1188
        $ret  .= $this->pc->getPhpCodeIncludeDir("__DIR__ . '/include/xoops_version.inc.php'", '',true,true);
1189
        $ret  .= $this->xc->getXcEqualsOperator('$iniPostMaxSize      ', "{$moduleDirname}ReturnBytes(\ini_get('post_max_size'))");
1190
        $ret  .= $this->xc->getXcEqualsOperator('$iniUploadMaxFileSize', "{$moduleDirname}ReturnBytes(\ini_get('upload_max_filesize'))");
1191
        $ret  .= $this->xc->getXcEqualsOperator('$maxSize             ', "min(\$iniPostMaxSize, \$iniUploadMaxFileSize)");
1192
        $cond = $this->xc->getXcEqualsOperator('$increment', '500', null, $t . "\t");
1193
        $ret  .= $this->pc->getPhpCodeConditions('$maxSize', ' > ', '10000 * 1048576', $cond, false, $t);
1194
        $cond = $this->xc->getXcEqualsOperator('$increment', '200', null, $t . "\t");
1195
        $ret  .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '10000 * 1048576', $cond, false, $t);
1196
        $cond  = $this->xc->getXcEqualsOperator('$increment', '100', null, $t . "\t");
1197
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '5000 * 1048576', $cond, false, $t);
1198
        $cond  = $this->xc->getXcEqualsOperator('$increment', '50', null, $t . "\t");
1199
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '2500 * 1048576', $cond, false, $t);
1200
        $cond  = $this->xc->getXcEqualsOperator('$increment', '10', null, $t . "\t");
1201
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '1000 * 1048576', $cond, false, $t);
1202
        $cond  = $this->xc->getXcEqualsOperator('$increment', '5', null, $t . "\t");
1203
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '500 * 1048576', $cond, false, $t);
1204
        $cond  = $this->xc->getXcEqualsOperator('$increment', '2', null, $t . "\t");
1205
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '100 * 1048576', $cond, false, $t);
1206
        $cond  = $this->xc->getXcEqualsOperator('$increment', '1', null, $t . "\t");
1207
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '50 * 1048576', $cond, false, $t);
1208
        $cond  = $this->xc->getXcEqualsOperator('$increment', '0.5', null, $t . "\t");
1209
        $ret   .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '25 * 1048576', $cond, false, $t);
1210
        $ret   .= $this->xc->getXcEqualsOperator('$optionMaxsize', '[]');
1211
        $ret   .= $this->xc->getXcEqualsOperator('$i', '$increment');
1212
        $while = $this->xc->getXcEqualsOperator("\$optionMaxsize[\$i . ' ' . _MI_{$ucModuleDirname}_SIZE_MB]", '$i * 1048576', null, $t . "\t");
1213
        $while .= $this->xc->getXcEqualsOperator('$i', '$increment', '+',$t . "\t");
1214
        $ret   .= $this->pc->getPhpCodeWhile('i * 1048576', $while, '$maxSize', '<=');
1215
1216
        return $ret;
1217
    }
1218
1219
    /**
1220
     * @public function render
1221
     * @param null
1222
     * @return bool|string
1223
     */
1224
    public function render()
1225
    {
1226
        $module        = $this->getModule();
1227
        $table         = $this->getTable();
1228
        $tables        = $this->getTables();
1229
        $filename      = $this->getFileName();
1230
        $moduleDirname = $module->getVar('mod_dirname');
1231
        $language      = $this->getLanguage($moduleDirname, 'MI');
1232
        $content       = $this->getHeaderFilesComments($module);
1233
        $content       .= $this->getXoopsVersionHeader($module, $language);
1234
        $content       .= $this->getXoopsVersionTemplatesAdminUser($moduleDirname, $tables, $module->getVar('mod_admin'), $module->getVar('mod_user'));
1235
        if (\count($tables) > 0) {
1236
            $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
1237
        }
1238
        $tableSearch        = [];
1239
        $tableComments      = [];
1240
        $tableSubmenu       = [];
1241
        $tableBlocks        = [];
1242
        $tableNotifications = [];
1243
        foreach (\array_keys($tables) as $t) {
1244
            $tableSearch[]        = $tables[$t]->getVar('table_search');
1245
            $tableComments[]      = $tables[$t]->getVar('table_comments');
1246
            $tableSubmenu[]       = $tables[$t]->getVar('table_submenu');
1247
            $tableBlocks[]        = $tables[$t]->getVar('table_blocks');
1248
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
1249
        }
1250
        if (\in_array(1, $tableSearch)) {
1251
            $content .= $this->getXoopsVersionSearch($moduleDirname);
1252
        }
1253
        if (\in_array(1, $tableComments)) {
1254
            $content .= $this->getXoopsVersionComments($moduleDirname, $tables);
1255
        }
1256
        if (\in_array(1, $tableSubmenu)) {
1257
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
1258
        }
1259
        if (\in_array(1, $tableBlocks)) {
1260
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $tables, $language);
1261
        }
1262
        $content .= $this->getXoopsVersionConfig($module, $tables, $language);
1263
        if (\in_array(1, $tableNotifications)) {
1264
            $content .= $this->getXoopsVersionNotifications($module, $language);
1265
        }
1266
        $this->create($moduleDirname, '/', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED);
1267
1268
        return $this->renderFile();
1269
    }
1270
}
1271