Passed
Branch master (31be8b)
by Gino
03:04
created

UserXoopsVersion::getXoopsVersionNotifications()   F

Complexity

Conditions 12
Paths 560

Size

Total Lines 81
Code Lines 65

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 81
rs 2.7264
cc 12
eloc 65
nc 560
nop 2

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
/*
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       The XOOPS Project http://sourceforge.net/projects/xoops/
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: UserXoopsVersion.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class UserXoopsVersion.
27
 */
28
class UserXoopsVersion extends TDMCreateFile
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
    * @var mixed
32
    */
33
    private $xoopscode = null;
34
35
    /*
36
    * @var mixed
37
    */
38
    private $usercode = null;
39
40
    /*
41
    * @var array
42
    */
43
    private $keywords = array();
44
45
    /*
46
    *  @public function constructor
47
    *  @param null
48
    */
49
    /**
50
     *
51
     */
52
    public function __construct()
53
    {
54
        parent::__construct();
55
        $this->phpcode = TDMCreatePhpCode::getInstance();
0 ignored issues
show
Documentation Bug introduced by
It seems like \TDMCreatePhpCode::getInstance() of type object<TDMCreatePhpCode> is incompatible with the declared type string of property $phpcode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
57
        $this->usercode = UserXoopsCode::getInstance();
58
    }
59
60
    /*
61
    *  @static function &getInstance
62
    *  @param null
63
    */
64
    /**
65
     * @return UserXoopsVersion
66
     */
67
    public static function &getInstance()
68
    {
69
        static $instance = false;
70
        if (!$instance) {
71
            $instance = new self();
72
        }
73
74
        return $instance;
75
    }
76
77
    /*
78
    *  @public function write
79
    *  @param $module
80
    *  @param mixed $table
81
    *  @param mixed $tables
82
    *  @param $filename
83
    */
84
    /**
85
     * @param $module
86
     * @param $table
87
     * @param $tables
88
     * @param $filename
89
     */
90
    public function write($module, $table, $tables, $filename)
91
    {
92
        $this->setModule($module);
93
        $this->setTable($table);
94
        $this->setTables($tables);
95
        $this->setFileName($filename);
96
        foreach (array_keys($tables) as $t) {
97
            $tableName = $tables[$t]->getVar('table_name');
98
            $this->setKeywords($tableName);
99
        }
100
    }
101
102
    /*
103
    *  @public function setKeywords
104
    *  @param mixed $keywords
105
    */
106
    /**
107
     * @param $keywords
108
     */
109
    public function setKeywords($keywords)
110
    {
111
        if (is_array($keywords)) {
112
            $this->keywords = $keywords;
113
        } else {
114
            $this->keywords[] = $keywords;
115
        }
116
    }
117
118
    /*
119
    *  @public function getKeywords
120
    *  @param null
121
    */
122
    /**
123
     * @return array
124
     */
125
    public function getKeywords()
126
    {
127
        return $this->keywords;
128
    }
129
130
    /*
131
     * @private function getXoopsVersionHeader
132
     * @param $module
133
     * @param $language
134
     *
135
     * @return string
136
     */
137
    private function getXoopsVersionHeader($module, $language)
138
    {
139
        $date = date(_DBDATESTRING);
140
        $ret = $this->getSimpleString('');
141
        $ret .= $this->getCommentLine();
142
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$dirname ', 'basename(__DIR__)');
143
        $ret .= $this->getHeaderComment('Informations');
144
        $ha = (1 == $module->getVar('mod_admin')) ? 1 : 0;
145
        $hm = (1 == $module->getVar('mod_user')) ? 1 : 0;
146
147
        $descriptions = array('name' => "{$language}NAME", 'version' => "{$module->getVar('mod_version')}", 'description' => "{$language}DESC",
148
                            'author' => "'{$module->getVar('mod_author')}'", 'author_mail' => "'{$module->getVar('mod_author_mail')}'", 'author_website_url' => "'{$module->getVar('mod_author_website_url')}'",
149
                            'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",'credits' => "'{$module->getVar('mod_credits')}'",'license' => "'{$module->getVar('mod_license')}'",
150
                            'license_url' => "'www.gnu.org/licenses/gpl-2.0.html/'", 'help' => "'page=help'", 'release_info' => "'{$module->getVar('mod_release_info')}'",
151
                            'release_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'", 'release_date' => "'{$date}'",
152
                            'manual' => "'{$module->getVar('mod_manual')}'", 'manual_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'",
153
                            'min_php' => "'{$module->getVar('mod_min_php')}'", 'min_xoops' => "'{$module->getVar('mod_min_xoops')}'", 'min_admin' => "'{$module->getVar('mod_min_admin')}'",
154
                            'min_db' => "array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}')", 'image' => "'assets/images/{$module->getVar('mod_image')}'",
155
                            'dirname' => 'basename(__DIR__)', 'dirmoduleadmin' => "'Frameworks/moduleclasses/moduleadmin'", 'sysicons16' => "'../../Frameworks/moduleclasses/icons/16'",
156
                            'sysicons32' => "'../../Frameworks/moduleclasses/icons/32'", 'modicons16' => "'assets/icons/16'", 'modicons32' => "'assets/icons/32'",
157
                            'demo_site_url' => "'{$module->getVar('mod_demo_site_url')}'", 'demo_site_name' => "'{$module->getVar('mod_demo_site_name')}'", 'support_url' => "'{$module->getVar('mod_support_url')}'",
158
                            'support_name' => "'{$module->getVar('mod_support_name')}'", 'module_website_url' => "'{$module->getVar('mod_website_url')}'", 'module_website_name' => "'{$module->getVar('mod_website_name')}'", 'release' => "'{$module->getVar('mod_release')}'", 'module_status' => "'{$module->getVar('mod_status')}'",
159
                            'system_menu' => '1', 'hasAdmin' => $ha, 'hasMain' => $hm, 'adminindex' => "'admin/index.php'", 'adminmenu' => "'admin/menu.php'",
160
                            'onInstall' => "'include/install.php'", 'onUpdate' => "'include/update.php'", );
161
162
        $ret .= $this->usercode->getUserModVersion(1, $descriptions);
163
164
        return $ret;
165
    }
166
167
    /*
168
    *  @private function getXoopsVersionMySQL
169
    *  @param $moduleDirname
170
    *  @param $table
171
    */
172
    /**
173
     * @param $moduleDirname
174
     * @param $table
175
     *
176
     * @return string
177
     */
178
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
179
    {
180
        $tableName = $table->getVar('table_name');
181
        $n = 1;
182
        $ret = '';
183
        if (!empty($tableName)) {
184
            $ret .= $this->getHeaderComment('Mysql');
185
            $ret .= $this->usercode->getUserModVersion(2, "'sql/mysql.sql'", 'sqlfile', "'mysql'");
186
            $ret .= $this->getCommentLine('Tables');
187
188
            foreach (array_keys($tables) as $t) {
189
                $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'", 'tables', $n);
190
                ++$n;
191
            }
192
            unset($n);
193
        }
194
195
        return $ret;
196
    }
197
198
    /*
199
    *  @private function getXoopsVersionSearch
200
    *  @param $moduleDirname
201
    */
202
    /**
203
     * @param $moduleDirname
204
     *
205
     * @return string
206
     */
207
    private function getXoopsVersionSearch($moduleDirname)
208
    {
209
        $ret = $this->getHeaderComment('Search');
210
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasSearch');
211
        $ret .= $this->usercode->getUserModVersion(2, "'include/search.inc.php'", 'search', "'file'");
212
        $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_search'", 'search', "'func'");
213
214
        return $ret;
215
    }
216
217
    /*
218
    *  @private function getXoopsVersionComments
219
    *  @param $moduleDirname
220
    */
221
    /**
222
     * @param $moduleDirname
223
     *
224
     * @return string
225
     */
226
    private function getXoopsVersionComments($moduleDirname)
227
    {
228
        $ret = $this->getHeaderComment('Comments');
229
        $ret .= $this->usercode->getUserModVersion(2, "'comments.php'", 'comments', "'pageName'");
230
        $ret .= $this->usercode->getUserModVersion(2, "'com_id'", 'comments', "'itemName'");
231
        $ret .= $this->getCommentLine('Comment callback functions');
232
        $ret .= $this->usercode->getUserModVersion(2, "'include/comment_functions.php'", 'comments', "'callbackFile'");
233
        $descriptions = array('approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'");
234
        $ret .= $this->usercode->getUserModVersion(3, $descriptions, 'comments', "'callback'");
235
236
        return $ret;
237
    }
238
239
    /*
240
    *  @private function getXoopsVersionTemplatesAdmin
241
    *  @param $moduleDirname
242
    */
243
    /**
244
     * @param $moduleDirname
245
     * @param $tables
246
     *
247
     * @return string
248
     */
249
    private function getXoopsVersionTemplatesAdmin($moduleDirname, $tables)
250
    {
251
        $ret = $this->getHeaderComment('Templates');
252
        $ret .= $this->getCommentLine('Admin');
253
254
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', '', true);
255
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '', true);
256
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '', true);
257
        $tablePermissions = array();
258
        foreach (array_keys($tables) as $t) {
259
            $tableName = $tables[$t]->getVar('table_name');
260
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
261
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '', true);
262
        }
263
        if (in_array(1, $tablePermissions)) {
264
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', '', true);
265
        }
266
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '', true);
267
268
        return $ret;
269
    }
270
271
    /*
272
    *  @private function getXoopsVersionTemplatesLine
273
    *  @param $moduleDirname
274
    */
275
    /**
276
     * @param $moduleDirname
277
     *
278
     * @return string
279
     */
280
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = '', $isAdmin = false)
281
    {
282
        $ret = '';
283
        $desc = "'description' => ''";
284
        $arrayFile = "array('file' =>";
285
        if ($isAdmin) {
286
            $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin')", 'templates', '');
287
        } else {
288
            if ($extra !== '') {
289
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc})", 'templates', '');
290
            } else {
291
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc})", 'templates', '');
292
            }
293
        }
294
295
        return $ret;
296
    }
297
298
    /*
299
    *  @private function getXoopsVersionTemplatesUser
300
    *  @param $moduleDirname
301
    */
302
    /**
303
     * @param $moduleDirname
304
     *
305
     * @return string
306
     */
307
    private function getXoopsVersionTemplatesUser($moduleDirname, $tables)
308
    {
309
        $ret = $this->getCommentLine('User');
310
311
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '');
312
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '');
313
        $tableBroken = array();
314
        $tablePdf = array();
315
        $tablePrint = array();
316
        $tableRate = array();
317
        $tableRss = array();
318
        $tableSearch = array();
319
        $tableSingle = array();
320
        $tableSubmit = array();
321
        foreach (array_keys($tables) as $t) {
322
            $tableName = $tables[$t]->getVar('table_name');
323
            $tableBroken[] = $tables[$t]->getVar('table_broken');
324
            $tablePdf[] = $tables[$t]->getVar('table_pdf');
325
            $tablePrint[] = $tables[$t]->getVar('table_print');
326
            $tableRate[] = $tables[$t]->getVar('table_rate');
327
            $tableRss[] = $tables[$t]->getVar('table_rss');
328
            $tableSearch[] = $tables[$t]->getVar('table_search');
329
            $tableSingle[] = $tables[$t]->getVar('table_single');
330
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
331
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '');
332
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'list');
333
        }
334
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs', '');
335
        if (in_array(1, $tableBroken)) {
336
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken', '');
337
        }
338
        if (in_array(1, $tablePdf)) {
339
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf', '');
340
        }
341
        if (in_array(1, $tablePrint)) {
342
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'print', '');
343
        }
344
        if (in_array(1, $tableRate)) {
345
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate', '');
346
        }
347
        if (in_array(1, $tableRss)) {
348
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss', '');
349
        }
350
        if (in_array(1, $tableSearch)) {
351
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'search', '');
352
        }
353
        if (in_array(1, $tableSingle)) {
354
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'single', '');
355
        }
356
        if (in_array(1, $tableSubmit)) {
357
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'submit', '');
358
        }
359
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '');
360
361
        return $ret;
362
    }
363
364
    /*
365
    *  @private function getXoopsVersionSubmenu
366
    *  @param $language
367
    */
368
    /**
369
     * @param $language
370
     *
371
     * @return string
372
     */
373
    private function getXoopsVersionSubmenu($language, $tables)
374
    {
375
        $ret = $this->getHeaderComment('Submenu');
376
        $i = 1;
377
        $tableSubmit = array();
378
        foreach (array_keys($tables) as $t) {
379
            $tableName = $tables[$t]->getVar('table_name');
380
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
381
            if (1 == $tables[$t]->getVar('table_submenu')) {
382
                $ret .= $this->getCommentLine('Sub', $tableName);
383
                $tname = array('name' => "{$language}SMNAME{$i}", 'url' => "'{$tableName}.php'");
384
                $ret .= $this->usercode->getUserModVersion(3, $tname, 'sub', $i);
385
            }
386
            ++$i;
387
        }
388
        if (in_array(1, $tableSubmit)) {
389
            $ret .= $this->getCommentLine('Sub', 'Submit');
390
            $submit = array('name' => "{$language}SMNAME{$i}", 'url' => "'submit.php'");
391
            $ret .= $this->usercode->getUserModVersion(3, $submit, 'sub', $i);
392
        }
393
        unset($i);
394
395
        return $ret;
396
    }
397
398
    /*
399
    *  @private function getXoopsVersionBlocks
400
    *  @param $moduleDirname
401
    *  @param $language
402
    */
403
    /**
404
     * @param $moduleDirname
405
     * @param $language
406
     *
407
     * @return string
408
     */
409
    private function getXoopsVersionBlocks($moduleDirname, $tables, $language)
410
    {
411
        $ret = $this->getHeaderComment('Blocks');
412
        $ret .= $this->getSimpleString('$b = 1;');
413
        $tableCategory = array();
414
        foreach (array_keys($tables) as $i) {
415
            $tableName = $tables[$i]->getVar('table_name');
416
            $tableFieldName = $tables[$i]->getVar('table_fieldname');
417
            $tableSoleName = $tables[$i]->getVar('table_solename');
418
            $stuTableSoleName = strtoupper($tableSoleName);
419
            $tableCategory[] = $tables[$i]->getVar('table_category');
420
            if (in_array(1, $tableCategory)) {
421
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $tableFieldName);
422
            } else {
423
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'LAST', $language, 'last');
424
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'NEW', $language, 'new');
425
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'HITS', $language, 'hits');
426
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'TOP', $language, 'top');
427
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'RANDOM', $language, 'random');
428
            }
429
        }
430
        $ret .= $this->getSimpleString('unset($b);');
431
432
        return $ret;
433
    }
434
435
    /*
436
    *  @private function getXoopsVersionTypeBlocks
437
    *  @param $moduleDirname
438
    *  @param $language
439
    */
440
    /**
441
     * @param $moduleDirname
442
     * @param $language
443
     *
444
     * @return string
445
     */
446
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type)
447
    {
448
        $stuTableName = strtoupper($tableName);
449
        $ucfTableName = ucfirst($tableName);
450
        $ret = $this->getCommentLine("{$ucfTableName}");
451
        $blocks = array('file' => "'{$tableName}.php'", 'name' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}", 'description' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC",
452
                        'show_func' => "'b_{$moduleDirname}_{$tableName}_show'", 'edit_func' => "'b_{$moduleDirname}_{$tableName}_edit'",
453
                        'template' => "'{$moduleDirname}_block_{$tableName}.tpl'", 'options' => "'{$type}|5|25|0'", );
454
        $ret .= $this->usercode->getUserModVersion(3, $blocks, 'blocks', '$b');
455
        $ret .= $this->getSimpleString('++$b;');
456
457
        return $ret;
458
    }
459
460
    /*
461
    *  @private function getXoopsVersionConfig
462
    *  @param $moduleDirname
463
    *  @param $language
464
    */
465
    /**
466
     * @param $module
467
     * @param $table
468
     * @param $language
469
     *
470
     * @return string
471
     */
472
    private function getXoopsVersionConfig($module, $table, $language)
473
    {
474
        $moduleDirname = $module->getVar('mod_dirname');
475
        $ret = $this->getHeaderComment('Config');
476
        $ret .= $this->getSimpleString('$c = 1;');
477
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
478
        $fieldName = array();
479
        $fieldElement = array();
480
        foreach (array_keys($fields) as $f) {
481
            $fieldName[] = $fields[$f]->getVar('field_name');
482
            $fieldElement[] = $fields[$f]->getVar('field_element');
483
        }
484
        if (in_array(4, $fieldElement)) {
485
            $rpFieldName = $this->getRightString($fieldName);
486
            $ucfFieldName = ucfirst($rpFieldName);
487
            $ret .= $this->getCommentLine('Editor', $rpFieldName);
488
            $ret .= $this->xoopscode->getXoopsCodeLoad('xoopseditorhandler');
489
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$editorHandler ', 'XoopsEditorHandler::getInstance()');
490
            $editor = array('name' => "'{$moduleDirname}_editor_{$rpFieldName}'", 'title' => "'{$language}EDITOR_{$ucfFieldName}'", 'description' => "'{$language}EDITOR_{$ucfFieldName}_DESC'",
491
                    'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'dhtml'", 'options' => 'array_flip($editorHandler->getList())', );
492
            $ret .= $this->usercode->getUserModVersion(3, $editor, 'config', '$c');
493
            $ret .= $this->getSimpleString('++$c;');
494
        }
495
        if (1 == $table->getVar('table_permissions')) {
496
            $ret .= $this->getCommentLine('Get groups');
497
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
498
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
499
            $group = $this->xoopscode->getXoopsCodeEqualsOperator('$groups[$group] ', '$key');
500
            $ret .= $this->phpcode->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
0 ignored issues
show
Bug introduced by
The method getPhpCodeForeach cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
501
            $groups = array('name' => "'groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
502
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$groups', 'options' => '$groups', );
503
            $ret .= $this->usercode->getUserModVersion(3, $groups, 'config', '$c');
504
            $ret .= $this->getSimpleString('++$c;');
505
            $ret .= $this->getCommentLine('Get Admin groups');
506
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$criteria ', 'new CriteriaCompo()');
507
            $ret .= $this->getSimpleString("\$criteria->add( new Criteria( 'group_type', 'Admin' ) );");
508
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
509
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$adminXoopsGroups ', '$memberHandler->getGroupList($criteria)');
510
            $adminGroup = $this->xoopscode->getXoopsCodeEqualsOperator('$adminGroups[$adminGroup] ', '$key');
511
            $ret .= $this->phpcode->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
0 ignored issues
show
Bug introduced by
The method getPhpCodeForeach cannot be called on $this->phpcode (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
512
            $adminGroups = array('name' => "'admin_groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
513
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$adminGroups', 'options' => '$adminGroups', );
514
            $ret .= $this->usercode->getUserModVersion(3, $adminGroups, 'config', '$c');
515
            $ret .= $this->getSimpleString('++$c;');
516
        }
517
        $keyword = implode(', ', $this->getKeywords());
518
        $ret .= $this->getCommentLine('Keywords');
519
        $arrayKeyword = array('name' => "'keywords'", 'title' => "'{$language}KEYWORDS'", 'description' => "'{$language}KEYWORDS_DESC'",
520
                        'formtype' => "'textbox'", 'valuetype' => "'text'", 'default' => "'{$moduleDirname}, {$keyword}'", );
521
        $ret .= $this->usercode->getUserModVersion(3, $arrayKeyword, 'config', '$c');
522
        $ret .= $this->getSimpleString('++$c;');
523
        unset($this->keywords);
524
        if (is_object($table)) {
525
            if (in_array(array(10, 11, 12, 13, 14), $fieldElement)) {
526
                $ret .= $this->getCommentLine('Uploads : maxsize of image');
527
                $maxsize = array('name' => "'maxsize'", 'title' => "'{$language}MAXSIZE'", 'description' => "'{$language}MAXSIZE_DESC'",
528
                    'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '5000000', );
529
                $ret .= $this->usercode->getUserModVersion(3, $maxsize, 'config', '$c');
530
                $ret .= $this->getCommentLine('Uploads : mimetypes of image');
531
                $ret .= $this->getSimpleString('++$c;');
532
                $mimetypes = array('name' => "'mimetypes'", 'title' => "'{$language}MIMETYPES'", 'description' => "'{$language}MIMETYPES_DESC'",
533
                    'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => "array('image/gif', 'image/jpeg', 'image/png')",
534
                    'options' => "array('bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg', 'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe', 'png' => 'image/png')", );
535
                $ret .= $this->usercode->getUserModVersion(3, $mimetypes, 'config', '$c');
536
                $ret .= $this->getSimpleString('++$c;');
537
            }
538
            if (1 == $table->getVar('table_admin')) {
539
                $ret .= $this->getCommentLine('Admin pager');
540
                $adminPager = array('name' => "'adminpager'", 'title' => "'{$language}ADMIN_PAGER'", 'description' => "'{$language}ADMIN_PAGER_DESC'",
541
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
542
                $ret .= $this->usercode->getUserModVersion(3, $adminPager, 'config', '$c');
543
                $ret .= $this->getSimpleString('++$c;');
544
            }
545
            if (1 == $table->getVar('table_user')) {
546
                $ret .= $this->getCommentLine('User pager');
547
                $userPager = array('name' => "'userpager'", 'title' => "'{$language}USER_PAGER'", 'description' => "'{$language}USER_PAGER_DESC'",
548
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
549
                $ret .= $this->usercode->getUserModVersion(3, $userPager, 'config', '$c');
550
                $ret .= $this->getSimpleString('++$c;');
551
            }
552
            if (1 == $table->getVar('table_tag')) {
553
                $ret .= $this->getCommentLine('Use tag');
554
                $useTag = array('name' => "'usetag'", 'title' => "'{$language}USE_TAG'", 'description' => "'{$language}USE_TAG_DESC'",
555
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
556
                $ret .= $this->usercode->getUserModVersion(3, $useTag, 'config', '$c');
557
                $ret .= $this->getSimpleString('++$c;');
558
            }
559
        }
560
        $ret .= $this->getCommentLine('Number column');
561
        $numbCol = array('name' => "'numb_col'", 'title' => "'{$language}NUMB_COL'", 'description' => "'{$language}NUMB_COL_DESC'",
562
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
563
        $ret .= $this->usercode->getUserModVersion(3, $numbCol, 'config', '$c');
564
        $ret .= $this->getSimpleString('++$c;');
565
        $ret .= $this->getCommentLine('Divide by');
566
        $divideby = array('name' => "'divideby'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
567
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
568
        $ret .= $this->usercode->getUserModVersion(3, $divideby, 'config', '$c');
569
        $ret .= $this->getSimpleString('++$c;');
570
        $ret .= $this->getCommentLine('Table type');
571
        $tableType = array('name' => "'table_type'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
572
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => "'bordered'", 'options' => "array('bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed')", );
573
        $ret .= $this->usercode->getUserModVersion(3, $tableType, 'config', '$c');
574
        $ret .= $this->getSimpleString('++$c;');
575
        $ret .= $this->getCommentLine('Panel by');
576
        $panelType = array('name' => "'panel_type'", 'title' => "'{$language}PANEL_TYPE'", 'description' => "'{$language}PANEL_TYPE_DESC'",
577
                        'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'default'", 'options' => "array('default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger')", );
578
        $ret .= $this->usercode->getUserModVersion(3, $panelType, 'config', '$c');
579
        $ret .= $this->getSimpleString('++$c;');
580
        $ret .= $this->getCommentLine('Panel by');
581
        $advertise = array('name' => "'advertise'", 'title' => "'{$language}ADVERTISE'", 'description' => "'{$language}ADVERTISE_DESC'",
582
                        'formtype' => "'textarea'", 'valuetype' => "'text'", 'default' => "''", );
583
        $ret .= $this->usercode->getUserModVersion(3, $advertise, 'config', '$c');
584
        $ret .= $this->getSimpleString('++$c;');
585
        $ret .= $this->getCommentLine('Panel by');
586
        $bookmarks = array('name' => "'bookmarks'", 'title' => "'{$language}BOOKMARKS'", 'description' => "'{$language}BOOKMARKS_DESC'",
587
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
588
        $ret .= $this->usercode->getUserModVersion(3, $bookmarks, 'config', '$c');
589
        $ret .= $this->getSimpleString('++$c;');
590
        $ret .= $this->getCommentLine('Facebook Comments');
591
        $facebookComments = array('name' => "'facebook_comments'", 'title' => "'{$language}FACEBOOK_COMMENTS'", 'description' => "'{$language}FACEBOOK_COMMENTS_DESC'",
592
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
593
        $ret .= $this->usercode->getUserModVersion(3, $facebookComments, 'config', '$c');
594
        $ret .= $this->getSimpleString('++$c;');
595
        $ret .= $this->getCommentLine('Disqus Comments');
596
        $disqusComments = array('name' => "'disqus_comments'", 'title' => "'{$language}DISQUS_COMMENTS'", 'description' => "'{$language}DISQUS_COMMENTS_DESC'",
597
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
598
        $ret .= $this->usercode->getUserModVersion(3, $disqusComments, 'config', '$c');
599
        $ret .= $this->getSimpleString('++$c;');
600
        $ret .= $this->getCommentLine('Maintained by');
601
        $maintainedby = array('name' => "'maintainedby'", 'title' => "'{$language}MAINTAINEDBY'", 'description' => "'{$language}MAINTAINEDBY_DESC'",
602
                        'formtype' => "'textbox'", 'valuetype' => "'text'", 'default' => "'{$module->getVar('mod_support_url')}'", );
603
        $ret .= $this->usercode->getUserModVersion(3, $maintainedby, 'config', '$c');
604
        $ret .= $this->getSimpleString('unset($c);');
605
606
        return $ret;
607
    }
608
609
    /*
610
    *  @private function getNotificationsType
611
    *  @param $language
612
    *  @param $type
613
    *  @param $tableName
614
    *  @param $item
615
    *  @param $typeOfNotify
616
    */
617
    /**
618
     * @param $language
619
     * @param $type
620
     * @param $tableName
621
     * @param $notifyFile
622
     * @param $item
623
     * @param $typeOfNotify
624
     *
625
     * @return string
626
     */
627
    private function getNotificationsType($language, $type = 'category', $tableName, $notifyFile, $item, $typeOfNotify)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
628
    {
629
        $stuTableName = strtoupper($tableName);
630
        $stuTypeOfNotify = strtoupper($typeOfNotify);
631
        $notifyFile = explode(', ', $notifyFile);
632
        $notifyFile = implode(', ', $notifyFile);
633
        $ret = '';
634
        switch ($type) {
635
            case 'category':
636
                $ret .= $this->getCommentLine('Category Notify');
637
                $category = array('name' => "'category'", 'title' => "'{$language}{$stuTableName}_NOTIFY'", 'description' => "'{$language}{$stuTableName}_NOTIFY_DESC'",
638
                                    'subscribe_from' => "array('index.php',{$notifyFile})", 'item_name' => "'{$item}'", "'allow_bookmark'" => '1', );
639
                $ret .= $this->usercode->getUserModVersion(3, $category, 'notification', "'{$type}'");
640
                break;
641
            case 'event':
642
                $ret .= $this->getCommentLine('Event Notify');
643
                $event = array('name' => "'{$typeOfNotify}'", 'category' => "'{$tableName}'", 'admin_only' => '1', "'title'" => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY'",
644
                                'caption' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_CAPTION'", 'description' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_DESC'",
645
                                'mail_template' => "'{$tableName}_{$typeOfNotify}_notify'", 'mail_subject' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_SUBJECT'", );
646
                $ret .= $this->usercode->getUserModVersion(3, $event, 'notification', "'{$type}'");
647
                break;
648
        }
649
650
        return $ret;
651
    }
652
653
    /*
654
    *  @private function getXoopsVersionNotifications
655
    *  @param $moduleDirname
656
    *  @param $language
657
    */
658
    /**
659
     * @param $moduleDirname
660
     * @param $language
661
     *
662
     * @return string
663
     */
664
    private function getXoopsVersionNotifications($module, $language)
665
    {
666
        $moduleDirname = $module->getVar('mod_dirname');
667
        $ret = $this->getHeaderComment('Notifications');
668
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasNotification');
669
        $notifications = array("'lookup_file'" => "'include/notification.inc.php'", "'lookup_func'" => "'{$moduleDirname}_notify_iteminfo'");
670
        $ret .= $this->usercode->getUserModVersion(2, $notifications, 'notification');
671
672
        $notifyFiles = array();
673
        $single = 'single';
674
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
675
        $tableCategory = array();
676
        $tableBroken = array();
677
        $tableSubmit = array();
678
        $tableId = null;
679
        $tableMid = null;
680
        foreach (array_keys($tables) as $t) {
681
            $tableId = $tables[$t]->getVar('table_id');
682
            $tableMid = $tables[$t]->getVar('table_mid');
683
            $tableName = $tables[$t]->getVar('table_name');
684
            $tableCategory[] = $tables[$t]->getVar('table_category');
685
            $tableBroken[] = $tables[$t]->getVar('table_broken');
686
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
687
            if (1 == $tables[$t]->getVar('table_notifications')) {
688
                if ($t <= count($tableName)) {
689
                    $notifyFiles[] = $tables[$t]->getVar('table_name');
690
                }
691
            }
692
            if (1 == $tables[$t]->getVar('table_single')) {
693
                $single = $tableName;
694
            }
695
        }
696
        $fields = $this->getTableFields($tableMid, $tableId);
697
        $fieldId = null;
698
        $fieldParent = null;
699
        foreach (array_keys($fields) as $f) {
700
            $fieldName = $fields[$f]->getVar('field_name');
701
            $fieldElement = $fields[$f]->getVar('field_element');
702
            if (0 == $f) {
703
                $fieldId = $fieldName;
704
            }
705
            if ($fieldElement > 15) {
706
                $fieldParent = $fieldName;
707
            }
708
        }
709
710
        $num = 1;
711
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles, $num);
712
        ++$num;
713
        $ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1', $num);
714
        ++$num;
715
        $ret .= $this->getXoopsVersionNotificationTableName($language, 'category', 'file', 'file', $single, $fieldId, 1, $num);
716
        unset($num);
717
        $num = 1;
718
        if (in_array(1, $tableCategory)) {
719
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_category', 'global', 0, 'global', 'newcategory', 'global_newcategory_notify', $num);
720
            ++$num;
721
        }
722
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_modify', 'global', 1, 'global', 'filemodify', 'global_filemodify_notify', $num);
723
        if (in_array(1, $tableBroken)) {
724
            ++$num;
725
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_broken', 'global', 1, 'global', 'filebroken', 'global_filebroken_notify', $num);
726
        }
727
        if (in_array(1, $tableSubmit)) {
728
            ++$num;
729
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'global', 1, 'global', 'filesubmit', 'global_filesubmit_notify', $num);
730
        }
731
        ++$num;
732
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'global', 0, 'global', 'newfile', 'global_newfile_notify', $num);
733
        if (in_array(1, $tableCategory)) {
734
            ++$num;
735
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'category', 1, 'category', 'filesubmit', 'category_filesubmit_notify', $num);
736
            ++$num;
737
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'category', 0, 'category', 'newfile', 'category_newfile_notify', $num);
738
        }
739
        ++$num;
740
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'approve', 'file', 1, 'file', 'approve', 'file_approve_notify', $num);
741
        unset($num);
742
743
        return $ret;
744
    }
745
746
    /*
747
    *  @private function getXoopsVersionNotificationGlobal
748
    */
749
    /**
750
     * @param $language
751
     * @param $type
752
     * @param $name
753
     * @param $title
754
     * @param $from
755
     *
756
     * @return string
757
     */
758
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from, $num)
759
    {
760
        $title = strtoupper($title);
761
        $implodeFrom = implode(".php', '", $from);
762
        $ret = $this->getCommentLine('Global Notify');
763
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
764
                        'subscribe_from' => "array('index.php', '{$implodeFrom}.php')", );
765
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
766
767
        return $ret;
768
    }
769
770
    /*
771
    *  @private function getXoopsVersionNotificationCategory
772
    */
773
    /**
774
     * @param $language
775
     * @param $type
776
     * @param $name
777
     * @param $title
778
     * @param $from
779
     *
780
     * @return string
781
     */
782
    private function getXoopsVersionNotificationCategory($language, $type, $name, $title, $file, $item, $allow, $num)
783
    {
784
        $title = strtoupper($title);
785
        $impFile = implode(".php', '", $file);
786
        $ret = $this->getCommentLine('Category Notify');
787
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
788
                        'subscribe_from' => "array('{$impFile}.php')", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
789
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
790
791
        return $ret;
792
    }
793
794
    /*
795
    *  @private function getXoopsVersionNotificationTableName
796
    */
797
    /**
798
     * @param $language
799
     * @param $type
800
     * @param $name
801
     * @param $title
802
     * @param $file
803
     * @param $item
804
     * @param $allow
805
     *
806
     * @return string
807
     */
808
    private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $file, $item = 'cid', $allow = 1, $num)
809
    {
810
        $stuTitle = strtoupper($title);
811
        $ucfTitle = ucfirst($title);
812
        $ret = $this->getCommentLine($ucfTitle.' Notify');
813
        $table = array('name' => "'{$name}'", 'title' => "{$language}{$stuTitle}_NOTIFY", 'description' => "{$language}{$stuTitle}_NOTIFY_DESC",
814
                        'subscribe_from' => "'{$file}.php'", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
815
        $ret .= $this->usercode->getUserModVersion(4, $table, 'notification', "'{$type}'", $num);
816
817
        return $ret;
818
    }
819
820
    /*
821
    *  @private function getXoopsVersionNotifications
822
    */
823
    /**
824
     * @param $language
825
     * @param $type
826
     * @param $name
827
     * @param $title
828
     * @param $from
829
     * @param $item
830
     * @param $mail
831
     *
832
     * @return string
833
     */
834
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail, $num)
835
    {
836
        $title = strtoupper($title);
837
        $table = strtoupper($table);
838
        $ucfTitle = ucfirst($title);
839
        $ret = $this->getCommentLine($ucfTitle.' Notify');
840
        $event = array('name' => "'{$name}'", 'category' => "'{$category}'", 'admin_only' => "{$admin}", 'title' => "{$language}{$title}_{$table}_NOTIFY",
841
                        'caption' => "{$language}{$title}_{$table}_NOTIFY_CAPTION", 'description' => "{$language}{$title}_{$table}_NOTIFY_DESC",
842
                        'mail_template' => "'{$mail}'", 'mail_subject' => "{$language}{$title}_{$table}_NOTIFY_SUBJECT", );
843
        $ret .= $this->usercode->getUserModVersion(4, $event, 'notification', "'{$type}'", $num);
844
845
        return $ret;
846
    }
847
848
    /*
849
    *  @public function render
850
    *  @param null
851
    */
852
    /**
853
     * @return bool|string
854
     */
855
    public function render()
856
    {
857
        $module = $this->getModule();
858
        $table = $this->getTable();
859
        $tables = $this->getTables();
860
        $filename = $this->getFileName();
861
        $moduleDirname = $module->getVar('mod_dirname');
862
        $language = $this->getLanguage($moduleDirname, 'MI');
863
        $content = $this->getHeaderFilesComments($module, $filename);
864
        $content .= $this->getXoopsVersionHeader($module, $language);
865
        if (1 == $module->getVar('mod_admin')) {
866
            $content .= $this->getXoopsVersionTemplatesAdmin($moduleDirname, $tables);
867
        }
868
        if (1 == $module->getVar('mod_user')) {
869
            $content .= $this->getXoopsVersionTemplatesUser($moduleDirname, $tables);
870
        }
871
        $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
872
        $tableSearch = array();
873
        $tableComments = array();
874
        $tableSubmenu = array();
875
        $tableBlocks = array();
876
        $tableNotifications = array();
877
        foreach (array_keys($tables) as $t) {
878
            $tableSearch[] = $tables[$t]->getVar('table_search');
879
            $tableComments[] = $tables[$t]->getVar('table_comments');
880
            $tableSubmenu[] = $tables[$t]->getVar('table_submenu');
881
            $tableBlocks[] = $tables[$t]->getVar('table_blocks');
882
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
883
        }
884
        if (in_array(1, $tableSearch)) {
885
            $content .= $this->getXoopsVersionSearch($moduleDirname);
886
        }
887
        if (in_array(1, $tableComments)) {
888
            $content .= $this->getXoopsVersionComments($moduleDirname);
889
        }
890
        if (in_array(1, $tableSubmenu)) {
891
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
892
        }
893
        if (in_array(1, $tableBlocks)) {
894
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $tables, $language);
895
        }
896
        $content .= $this->getXoopsVersionConfig($module, $table, $language);
897
        if (in_array(1, $tableNotifications)) {
898
            $content .= $this->getXoopsVersionNotifications($module, $language);
899
        }
900
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
901
902
        return $this->renderFile();
903
    }
904
}
905