Completed
Push — master ( 3f0046...b1c777 )
by Gino
06:41 queued 03:19
created

UserXoopsVersion::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * tdmcreate module.
14
 *
15
 * @copyright       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 $phpcode = null;
34
35
    /*
36
    * @var mixed
37
    */
38
    private $xoopscode = null;
39
40
    /*
41
    * @var mixed
42
    */
43
    private $usercode = null;
44
45
    /*
46
    * @var array
47
    */
48
    private $keywords = array();
49
50
    /*
51
    *  @public function constructor
52
    *  @param null
53
    */
54
    /**
55
     *
56
     */
57
    public function __construct()
58
    {
59
        parent::__construct();
60
        $this->phpcode = TDMCreatePhpCode::getInstance();
61
        $this->xoopscode = TDMCreateXoopsCode::getInstance();
62
        $this->usercode = UserXoopsCode::getInstance();
63
    }
64
65
    /*
66
    *  @static function &getInstance
67
    *  @param null
68
    */
69
    /**
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
    /**
90
     * @param $module
91
     * @param $table
92
     * @param $tables
93
     * @param $filename
94
     */
95
    public function write($module, $table, $tables, $filename)
96
    {
97
        $this->setModule($module);
98
        $this->setTable($table);
99
        $this->setTables($tables);
100
        $this->setFileName($filename);
101
        foreach (array_keys($tables) as $t) {
102
            $tableName = $tables[$t]->getVar('table_name');
103
            $this->setKeywords($tableName);
104
        }
105
    }
106
107
    /*
108
    *  @public function setKeywords
109
    *  @param mixed $keywords
110
    */
111
    /**
112
     * @param $keywords
113
     */
114
    public function setKeywords($keywords)
115
    {
116
        if (is_array($keywords)) {
117
            $this->keywords = $keywords;
118
        } else {
119
            $this->keywords[] = $keywords;
120
        }
121
    }
122
123
    /*
124
    *  @public function getKeywords
125
    *  @param null
126
    */
127
    /**
128
     * @return array
129
     */
130
    public function getKeywords()
131
    {
132
        return $this->keywords;
133
    }
134
135
    /*
136
     * @private function getXoopsVersionHeader
137
     * @param $module
138
     * @param $language
139
     *
140
     * @return string
141
     */
142
    private function getXoopsVersionHeader($module, $language)
143
    {
144
        $date = date(_DBDATESTRING);
145
        $ret = $this->getSimpleString('');
146
        $ret .= $this->getCommentLine();
147
        $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$dirname ', 'basename(__DIR__)');
148
        $ret .= $this->getHeaderComment('Informations');
149
        $ha = (1 == $module->getVar('mod_admin')) ? 1 : 0;
150
        $hm = (1 == $module->getVar('mod_user')) ? 1 : 0;
151
152
        $descriptions = array('name' => "{$language}NAME", 'version' => "{$module->getVar('mod_version')}", 'description' => "{$language}DESC",
153
                            'author' => "'{$module->getVar('mod_author')}'", 'author_mail' => "'{$module->getVar('mod_author_mail')}'", 'author_website_url' => "'{$module->getVar('mod_author_website_url')}'",
154
                            'author_website_name' => "'{$module->getVar('mod_author_website_name')}'",'credits' => "'{$module->getVar('mod_credits')}'",'license' => "'{$module->getVar('mod_license')}'",
155
                            'license_url' => "'www.gnu.org/licenses/gpl-2.0.html/'", 'help' => "'page=help'", 'release_info' => "'{$module->getVar('mod_release_info')}'",
156
                            'release_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_release_file')}'", 'release_date' => "'{$date}'",
157
                            'manual' => "'{$module->getVar('mod_manual')}'", 'manual_file' => "XOOPS_URL . '/modules/{$module->getVar('mod_dirname')}/docs/{$module->getVar('mod_manual_file')}'",
158
                            'min_php' => "'{$module->getVar('mod_min_php')}'", 'min_xoops' => "'{$module->getVar('mod_min_xoops')}'", 'min_admin' => "'{$module->getVar('mod_min_admin')}'",
159
                            'min_db' => "array('mysql' => '{$module->getVar('mod_min_mysql')}', 'mysqli' => '{$module->getVar('mod_min_mysql')}')", 'image' => "'assets/images/{$module->getVar('mod_image')}'",
160
                            'dirname' => 'basename(__DIR__)', 'dirmoduleadmin' => "'Frameworks/moduleclasses/moduleadmin'", 'sysicons16' => "'../../Frameworks/moduleclasses/icons/16'",
161
                            'sysicons32' => "'../../Frameworks/moduleclasses/icons/32'", 'modicons16' => "'assets/icons/16'", 'modicons32' => "'assets/icons/32'",
162
                            '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')}'",
163
                            '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')}'",
164
                            'system_menu' => '1', 'hasAdmin' => $ha, 'hasMain' => $hm, 'adminindex' => "'admin/index.php'", 'adminmenu' => "'admin/menu.php'",
165
                            'onInstall' => "'include/install.php'", 'onUpdate' => "'include/update.php'", );
166
167
        $ret .= $this->usercode->getUserModVersion(1, $descriptions);
168
169
        return $ret;
170
    }
171
172
    /*
173
    *  @private function getXoopsVersionMySQL
174
    *  @param $moduleDirname
175
    *  @param $table
176
    */
177
    /**
178
     * @param $moduleDirname
179
     * @param $table
180
     *
181
     * @return string
182
     */
183
    private function getXoopsVersionMySQL($moduleDirname, $table, $tables)
184
    {
185
        $tableName = $table->getVar('table_name');
186
        $n = 1;
187
        $ret = '';
188
        if (!empty($tableName)) {
189
            $ret .= $this->getHeaderComment('Mysql');
190
            $ret .= $this->usercode->getUserModVersion(2, "'sql/mysql.sql'", 'sqlfile', "'mysql'");
191
            $ret .= $this->getCommentLine('Tables');
192
193
            foreach (array_keys($tables) as $t) {
194
                $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'", 'tables', $n);
195
                ++$n;
196
            }
197
            unset($n);
198
        }
199
200
        return $ret;
201
    }
202
203
    /*
204
    *  @private function getXoopsVersionSearch
205
    *  @param $moduleDirname
206
    */
207
    /**
208
     * @param $moduleDirname
209
     *
210
     * @return string
211
     */
212
    private function getXoopsVersionSearch($moduleDirname)
213
    {
214
        $ret = $this->getHeaderComment('Search');
215
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasSearch');
216
        $ret .= $this->usercode->getUserModVersion(2, "'include/search.inc.php'", 'search', "'file'");
217
        $ret .= $this->usercode->getUserModVersion(2, "'{$moduleDirname}_search'", 'search', "'func'");
218
219
        return $ret;
220
    }
221
222
    /*
223
    *  @private function getXoopsVersionComments
224
    *  @param $moduleDirname
225
    */
226
    /**
227
     * @param $moduleDirname
228
     *
229
     * @return string
230
     */
231
    private function getXoopsVersionComments($moduleDirname)
232
    {
233
        $ret = $this->getHeaderComment('Comments');
234
        $ret .= $this->usercode->getUserModVersion(2, "'comments.php'", 'comments', "'pageName'");
235
        $ret .= $this->usercode->getUserModVersion(2, "'com_id'", 'comments', "'itemName'");
236
        $ret .= $this->getCommentLine('Comment callback functions');
237
        $ret .= $this->usercode->getUserModVersion(2, "'include/comment_functions.php'", 'comments', "'callbackFile'");
238
        $descriptions = array('approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'");
239
        $ret .= $this->usercode->getUserModVersion(3, $descriptions, 'comments', "'callback'");
240
241
        return $ret;
242
    }
243
244
    /*
245
    *  @private function getXoopsVersionTemplatesAdmin
246
    *  @param $moduleDirname
247
    */
248
    /**
249
     * @param $moduleDirname
250
     * @param $tables
251
     *
252
     * @return string
253
     */
254
    private function getXoopsVersionTemplatesAdmin($moduleDirname, $tables)
255
    {
256
        $ret = $this->getHeaderComment('Templates');
257
        $ret .= $this->getCommentLine('Admin');
258
259
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', '', true);
260
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '', true);
261
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '', true);
262
        $tablePermissions = array();
263
        foreach (array_keys($tables) as $t) {
264
            $tableName = $tables[$t]->getVar('table_name');
265
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
266
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '', true);
267
        }
268
        if (in_array(1, $tablePermissions)) {
269
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', '', true);
270
        }
271
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '', true);
272
273
        return $ret;
274
    }
275
276
    /*
277
    *  @private function getXoopsVersionTemplatesLine
278
    *  @param $moduleDirname
279
    */
280
    /**
281
     * @param $moduleDirname
282
     *
283
     * @return string
284
     */
285
    private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = '', $isAdmin = false)
286
    {
287
        $ret = '';
288
        $desc = "'description' => ''";
289
        $arrayFile = "array('file' =>";
290
        if ($isAdmin) {
291
            $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin')", 'templates', '');
292
        } else {
293
            if ($extra !== '') {
294
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc})", 'templates', '');
295
            } else {
296
                $ret .= $this->usercode->getUserModVersion(2, "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc})", 'templates', '');
297
            }
298
        }
299
300
        return $ret;
301
    }
302
303
    /*
304
    *  @private function getXoopsVersionTemplatesUser
305
    *  @param $moduleDirname
306
    */
307
    /**
308
     * @param $moduleDirname
309
     *
310
     * @return string
311
     */
312
    private function getXoopsVersionTemplatesUser($moduleDirname, $tables)
313
    {
314
        $ret = $this->getCommentLine('User');
315
316
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '');
317
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '');
318
        $tableBroken = array();
319
        $tablePdf = array();
320
        $tablePrint = array();
321
        $tableRate = array();
322
        $tableRss = array();
323
        $tableSearch = array();
324
        $tableSingle = array();
325
        $tableSubmit = array();
326
        foreach (array_keys($tables) as $t) {
327
            $tableName = $tables[$t]->getVar('table_name');
328
            $tableBroken[] = $tables[$t]->getVar('table_broken');
329
            $tablePdf[] = $tables[$t]->getVar('table_pdf');
330
            $tablePrint[] = $tables[$t]->getVar('table_print');
331
            $tableRate[] = $tables[$t]->getVar('table_rate');
332
            $tableRss[] = $tables[$t]->getVar('table_rss');
333
            $tableSearch[] = $tables[$t]->getVar('table_search');
334
            $tableSingle[] = $tables[$t]->getVar('table_single');
335
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
336
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '');
337
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'list');
338
        }
339
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs', '');
340
        if (in_array(1, $tableBroken)) {
341
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken', '');
342
        }
343
        if (in_array(1, $tablePdf)) {
344
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf', '');
345
        }
346
        if (in_array(1, $tablePrint)) {
347
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'print', '');
348
        }
349
        if (in_array(1, $tableRate)) {
350
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate', '');
351
        }
352
        if (in_array(1, $tableRss)) {
353
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss', '');
354
        }
355
        if (in_array(1, $tableSearch)) {
356
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'search', '');
357
        }
358
        if (in_array(1, $tableSingle)) {
359
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'single', '');
360
        }
361
        if (in_array(1, $tableSubmit)) {
362
            $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'submit', '');
363
        }
364
        $ret .= $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '');
365
366
        return $ret;
367
    }
368
369
    /*
370
    *  @private function getXoopsVersionSubmenu
371
    *  @param $language
372
    */
373
    /**
374
     * @param $language
375
     *
376
     * @return string
377
     */
378
    private function getXoopsVersionSubmenu($language, $tables)
379
    {
380
        $ret = $this->getHeaderComment('Submenu');
381
        $i = 1;
382
        $tableSubmit = array();
383
        foreach (array_keys($tables) as $t) {
384
            $tableName = $tables[$t]->getVar('table_name');
385
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
386
            if (1 == $tables[$t]->getVar('table_submenu')) {
387
                $ret .= $this->getCommentLine('Sub', $tableName);
388
                $tname = array('name' => "{$language}SMNAME{$i}", 'url' => "'{$tableName}.php'");
389
                $ret .= $this->usercode->getUserModVersion(3, $tname, 'sub', $i);
390
            }
391
            ++$i;
392
        }
393
        if (in_array(1, $tableSubmit)) {
394
            $ret .= $this->getCommentLine('Sub', 'Submit');
395
            $submit = array('name' => "{$language}SMNAME{$i}", 'url' => "'submit.php'");
396
            $ret .= $this->usercode->getUserModVersion(3, $submit, 'sub', $i);
397
        }
398
        unset($i);
399
400
        return $ret;
401
    }
402
403
    /*
404
    *  @private function getXoopsVersionBlocks
405
    *  @param $moduleDirname
406
    *  @param $language
407
    */
408
    /**
409
     * @param $moduleDirname
410
     * @param $language
411
     *
412
     * @return string
413
     */
414
    private function getXoopsVersionBlocks($moduleDirname, $tables, $language)
415
    {
416
        $ret = $this->getHeaderComment('Blocks');
417
        $ret .= $this->getSimpleString('$b = 1;');
418
        $tableCategory = array();
419
        foreach (array_keys($tables) as $i) {
420
            $tableName = $tables[$i]->getVar('table_name');
421
            $tableFieldName = $tables[$i]->getVar('table_fieldname');
422
            $tableSoleName = $tables[$i]->getVar('table_solename');
423
            $stuTableSoleName = strtoupper($tableSoleName);
424
            $tableCategory[] = $tables[$i]->getVar('table_category');
425
            if (in_array(1, $tableCategory)) {
426
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $tableFieldName);
427
            } else {
428
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'LAST', $language, 'last');
429
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'NEW', $language, 'new');
430
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'HITS', $language, 'hits');
431
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'TOP', $language, 'top');
432
                $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'RANDOM', $language, 'random');
433
            }
434
        }
435
        $ret .= $this->getSimpleString('unset($b);');
436
437
        return $ret;
438
    }
439
440
    /*
441
    *  @private function getXoopsVersionTypeBlocks
442
    *  @param $moduleDirname
443
    *  @param $language
444
    */
445
    /**
446
     * @param $moduleDirname
447
     * @param $language
448
     *
449
     * @return string
450
     */
451
    private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type)
452
    {
453
        $stuTableName = strtoupper($tableName);
454
        $ucfTableName = ucfirst($tableName);
455
        $ret = $this->getCommentLine("{$ucfTableName}");
456
        $blocks = array('file' => "'{$tableName}.php'", 'name' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}", 'description' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC",
457
                        'show_func' => "'b_{$moduleDirname}_{$tableName}_show'", 'edit_func' => "'b_{$moduleDirname}_{$tableName}_edit'",
458
                        'template' => "'{$moduleDirname}_block_{$tableName}.tpl'", 'options' => "'{$type}|5|25|0'", );
459
        $ret .= $this->usercode->getUserModVersion(3, $blocks, 'blocks', '$b');
460
        $ret .= $this->getSimpleString('++$b;');
461
462
        return $ret;
463
    }
464
465
    /*
466
    *  @private function getXoopsVersionConfig
467
    *  @param $moduleDirname
468
    *  @param $language
469
    */
470
    /**
471
     * @param $module
472
     * @param $table
473
     * @param $language
474
     *
475
     * @return string
476
     */
477
    private function getXoopsVersionConfig($module, $table, $language)
478
    {
479
        $moduleDirname = $module->getVar('mod_dirname');
480
        $ret = $this->getHeaderComment('Config');
481
        $ret .= $this->getSimpleString('$c = 1;');
482
        $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
483
        $fieldName = array();
484
        $fieldElement = array();
485
        foreach (array_keys($fields) as $f) {
486
            $fieldName[] = $fields[$f]->getVar('field_name');
487
            $fieldElement[] = $fields[$f]->getVar('field_element');
488
        }
489
        if (in_array(4, $fieldElement)) {
490
            $rpFieldName = $this->getRightString($fieldName);
491
            $ucfFieldName = ucfirst($rpFieldName);
492
            $ret .= $this->getCommentLine('Editor', $rpFieldName);
493
            $ret .= $this->xoopscode->getXoopsCodeLoad('xoopseditorhandler');
494
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$editorHandler ', 'XoopsEditorHandler::getInstance()');
495
            $editor = array('name' => "'{$moduleDirname}_editor_{$rpFieldName}'", 'title' => "'{$language}EDITOR_{$ucfFieldName}'", 'description' => "'{$language}EDITOR_{$ucfFieldName}_DESC'",
496
                    'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'dhtml'", 'options' => 'array_flip($editorHandler->getList())', );
497
            $ret .= $this->usercode->getUserModVersion(3, $editor, 'config', '$c');
498
            $ret .= $this->getSimpleString('++$c;');
499
        }
500
        if (1 == $table->getVar('table_permissions')) {
501
            $ret .= $this->getCommentLine('Get groups');
502
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
503
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$xoopsGroups ', '$memberHandler->getGroupList()');
504
            $group = $this->xoopscode->getXoopsCodeEqualsOperator('$groups[$group] ', '$key');
505
            $ret .= $this->phpcode->getPhpCodeForeach('xoopsGroups', false, 'key', 'group', $group);
506
            $groups = array('name' => "'groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
507
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$groups', 'options' => '$groups', );
508
            $ret .= $this->usercode->getUserModVersion(3, $groups, 'config', '$c');
509
            $ret .= $this->getSimpleString('++$c;');
510
            $ret .= $this->getCommentLine('Get Admin groups');
511
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$criteria ', 'new CriteriaCompo()');
512
            $ret .= $this->getSimpleString("\$criteria->add( new Criteria( 'group_type', 'Admin' ) );");
513
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$memberHandler ', "xoops_gethandler('member')", true);
514
            $ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$adminXoopsGroups ', '$memberHandler->getGroupList($criteria)');
515
            $adminGroup = $this->xoopscode->getXoopsCodeEqualsOperator('$adminGroups[$adminGroup] ', '$key');
516
            $ret .= $this->phpcode->getPhpCodeForeach('adminXoopsGroups', false, 'key', 'adminGroup', $adminGroup);
517
            $adminGroups = array('name' => "'admin_groups'", 'title' => "'{$language}GROUPS'", 'description' => "'{$language}GROUPS_DESC'",
518
                        'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => '$adminGroups', 'options' => '$adminGroups', );
519
            $ret .= $this->usercode->getUserModVersion(3, $adminGroups, 'config', '$c');
520
            $ret .= $this->getSimpleString('++$c;');
521
        }
522
        $keyword = implode(', ', $this->getKeywords());
523
        $ret .= $this->getCommentLine('Keywords');
524
        $arrayKeyword = array('name' => "'keywords'", 'title' => "'{$language}KEYWORDS'", 'description' => "'{$language}KEYWORDS_DESC'",
525
                        'formtype' => "'textbox'", 'valuetype' => "'text'", 'default' => "'{$moduleDirname}, {$keyword}'", );
526
        $ret .= $this->usercode->getUserModVersion(3, $arrayKeyword, 'config', '$c');
527
        $ret .= $this->getSimpleString('++$c;');
528
        unset($this->keywords);
529
        if (is_object($table)) {
530
            if (in_array(array(10, 11, 12, 13, 14), $fieldElement)) {
531
                $ret .= $this->getCommentLine('Uploads : maxsize of image');
532
                $maxsize = array('name' => "'maxsize'", 'title' => "'{$language}MAXSIZE'", 'description' => "'{$language}MAXSIZE_DESC'",
533
                    'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '5000000', );
534
                $ret .= $this->usercode->getUserModVersion(3, $maxsize, 'config', '$c');
535
                $ret .= $this->getCommentLine('Uploads : mimetypes of image');
536
                $ret .= $this->getSimpleString('++$c;');
537
                $mimetypes = array('name' => "'mimetypes'", 'title' => "'{$language}MIMETYPES'", 'description' => "'{$language}MIMETYPES_DESC'",
538
                    'formtype' => "'select_multi'", 'valuetype' => "'array'", 'default' => "array('image/gif', 'image/jpeg', 'image/png')", 'options' => "array('bmp' => 'image/bmp','gif' => 'image/gif','pjpeg' => 'image/pjpeg',
539
				   'jpeg' => 'image/jpeg','jpg' => 'image/jpg','jpe' => 'image/jpe',
540
				   'png' => 'image/png')", );
541
                $ret .= $this->usercode->getUserModVersion(3, $mimetypes, 'config', '$c');
542
                $ret .= $this->getSimpleString('++$c;');
543
            }
544
            if (1 == $table->getVar('table_admin')) {
545
                $ret .= $this->getCommentLine('Admin pager');
546
                $adminPager = array('name' => "'adminpager'", 'title' => "'{$language}ADMIN_PAGER'", 'description' => "'{$language}ADMIN_PAGER_DESC'",
547
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
548
                $ret .= $this->usercode->getUserModVersion(3, $adminPager, 'config', '$c');
549
                $ret .= $this->getSimpleString('++$c;');
550
            }
551
            if (1 == $table->getVar('table_user')) {
552
                $ret .= $this->getCommentLine('User pager');
553
                $userPager = array('name' => "'userpager'", 'title' => "'{$language}USER_PAGER'", 'description' => "'{$language}USER_PAGER_DESC'",
554
                        'formtype' => "'textbox'", 'valuetype' => "'int'", 'default' => '10', );
555
                $ret .= $this->usercode->getUserModVersion(3, $userPager, 'config', '$c');
556
                $ret .= $this->getSimpleString('++$c;');
557
            }
558
            if (1 == $table->getVar('table_tag')) {
559
                $ret .= $this->getCommentLine('Use tag');
560
                $useTag = array('name' => "'usetag'", 'title' => "'{$language}USE_TAG'", 'description' => "'{$language}USE_TAG_DESC'",
561
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
562
                $ret .= $this->usercode->getUserModVersion(3, $useTag, 'config', '$c');
563
                $ret .= $this->getSimpleString('++$c;');
564
            }
565
        }
566
        $ret .= $this->getCommentLine('Number column');
567
        $numbCol = array('name' => "'numb_col'", 'title' => "'{$language}NUMB_COL'", 'description' => "'{$language}NUMB_COL_DESC'",
568
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
569
        $ret .= $this->usercode->getUserModVersion(3, $numbCol, 'config', '$c');
570
        $ret .= $this->getSimpleString('++$c;');
571
        $ret .= $this->getCommentLine('Divide by');
572
        $divideby = array('name' => "'divideby'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
573
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => '1', 'options' => "array(1 => '1', 2 => '2', 3 => '3', 4 => '4')", );
574
        $ret .= $this->usercode->getUserModVersion(3, $divideby, 'config', '$c');
575
        $ret .= $this->getSimpleString('++$c;');
576
        $ret .= $this->getCommentLine('Table type');
577
        $tableType = array('name' => "'table_type'", 'title' => "'{$language}DIVIDEBY'", 'description' => "'{$language}DIVIDEBY_DESC'",
578
                        'formtype' => "'select'", 'valuetype' => "'int'", 'default' => "'bordered'", 'options' => "array('bordered' => 'bordered', 'striped' => 'striped', 'hover' => 'hover', 'condensed' => 'condensed')", );
579
        $ret .= $this->usercode->getUserModVersion(3, $tableType, 'config', '$c');
580
        $ret .= $this->getSimpleString('++$c;');
581
        $ret .= $this->getCommentLine('Panel by');
582
        $panelType = array('name' => "'panel_type'", 'title' => "'{$language}PANEL_TYPE'", 'description' => "'{$language}PANEL_TYPE_DESC'",
583
                        'formtype' => "'select'", 'valuetype' => "'text'", 'default' => "'default'", 'options' => "array('default' => 'default', 'primary' => 'primary', 'success' => 'success', 'info' => 'info', 'warning' => 'warning', 'danger' => 'danger')", );
584
        $ret .= $this->usercode->getUserModVersion(3, $panelType, 'config', '$c');
585
        $ret .= $this->getSimpleString('++$c;');
586
        $ret .= $this->getCommentLine('Panel by');
587
        $advertise = array('name' => "'advertise'", 'title' => "'{$language}ADVERTISE'", 'description' => "'{$language}ADVERTISE_DESC'",
588
                        'formtype' => "'textarea'", 'valuetype' => "'text'", 'default' => "''", );
589
        $ret .= $this->usercode->getUserModVersion(3, $advertise, 'config', '$c');
590
        $ret .= $this->getSimpleString('++$c;');
591
        $ret .= $this->getCommentLine('Panel by');
592
        $bookmarks = array('name' => "'bookmarks'", 'title' => "'{$language}BOOKMARKS'", 'description' => "'{$language}BOOKMARKS_DESC'",
593
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
594
        $ret .= $this->usercode->getUserModVersion(3, $bookmarks, 'config', '$c');
595
        $ret .= $this->getSimpleString('++$c;');
596
        $ret .= $this->getCommentLine('Facebook Comments');
597
        $facebookComments = array('name' => "'facebook_comments'", 'title' => "'{$language}FACEBOOK_COMMENTS'", 'description' => "'{$language}FACEBOOK_COMMENTS_DESC'",
598
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
599
        $ret .= $this->usercode->getUserModVersion(3, $facebookComments, 'config', '$c');
600
        $ret .= $this->getSimpleString('++$c;');
601
        $ret .= $this->getCommentLine('Disqus Comments');
602
        $disqusComments = array('name' => "'disqus_comments'", 'title' => "'{$language}DISQUS_COMMENTS'", 'description' => "'{$language}DISQUS_COMMENTS_DESC'",
603
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => '0', );
604
        $ret .= $this->usercode->getUserModVersion(3, $disqusComments, 'config', '$c');
605
        $ret .= $this->getSimpleString('++$c;');
606
        $ret .= $this->getCommentLine('Maintained by');
607
        $maintainedby = array('name' => "'maintainedby'", 'title' => "'{$language}MAINTAINEDBY'", 'description' => "'{$language}MAINTAINEDBY_DESC'",
608
                        'formtype' => "'yesno'", 'valuetype' => "'int'", 'default' => "'{$module->getVar('mod_support_url')}'", );
609
        $ret .= $this->usercode->getUserModVersion(3, $maintainedby, 'config', '$c');
610
        $ret .= $this->getSimpleString('unset($c);');
611
612
        return $ret;
613
    }
614
615
    /*
616
    *  @private function getNotificationsType
617
    *  @param $language
618
    *  @param $type
619
    *  @param $tableName
620
    *  @param $item
621
    *  @param $typeOfNotify
622
    */
623
    /**
624
     * @param $language
625
     * @param $type
626
     * @param $tableName
627
     * @param $notifyFile
628
     * @param $item
629
     * @param $typeOfNotify
630
     *
631
     * @return string
632
     */
633
    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...
634
    {
635
        $stuTableName = strtoupper($tableName);
636
        $stuTypeOfNotify = strtoupper($typeOfNotify);
637
        $notifyFile = explode(', ', $notifyFile);
638
        $notifyFile = implode(', ', $notifyFile);
639
        $ret = '';
640
        switch ($type) {
641
            case 'category':
642
                $ret .= $this->getCommentLine('Category Notify');
643
                $category = array('name' => "'category'", 'title' => "'{$language}{$stuTableName}_NOTIFY'", 'description' => "'{$language}{$stuTableName}_NOTIFY_DESC'",
644
                                    'subscribe_from' => "array('index.php',{$notifyFile})", 'item_name' => "'{$item}'", "'allow_bookmark'" => '1', );
645
                $ret .= $this->usercode->getUserModVersion(3, $category, 'notification', "'{$type}'");
646
                break;
647
            case 'event':
648
                $ret .= $this->getCommentLine('Event Notify');
649
                $event = array('name' => "'{$typeOfNotify}'", 'category' => "'{$tableName}'", 'admin_only' => '1', "'title'" => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY'",
650
                                'caption' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_CAPTION'", 'description' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_DESC'",
651
                                'mail_template' => "'{$tableName}_{$typeOfNotify}_notify'", 'mail_subject' => "'{$language}{$stuTableName}_{$stuTypeOfNotify}_NOTIFY_SUBJECT'", );
652
                $ret .= $this->usercode->getUserModVersion(3, $event, 'notification', "'{$type}'");
653
                break;
654
        }
655
656
        return $ret;
657
    }
658
659
    /*
660
    *  @private function getXoopsVersionNotifications
661
    *  @param $moduleDirname
662
    *  @param $language
663
    */
664
    /**
665
     * @param $moduleDirname
666
     * @param $language
667
     *
668
     * @return string
669
     */
670
    private function getXoopsVersionNotifications($module, $language)
671
    {
672
        $moduleDirname = $module->getVar('mod_dirname');
673
        $ret = $this->getHeaderComment('Notifications');
674
        $ret .= $this->usercode->getUserModVersion(1, 1, 'hasNotification');
675
        $notifications = array("'lookup_file'" => "'include/notification.inc.php'", "'lookup_func'" => "'{$moduleDirname}_notify_iteminfo'");
676
        $ret .= $this->usercode->getUserModVersion(2, $notifications, 'notification');
677
678
        $notifyFiles = array();
679
        $single = 'single';
680
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
681
        $tableCategory = array();
682
        $tableBroken = array();
683
        $tableSubmit = array();
684
        $tableId = null;
685
        $tableMid = null;
686
        foreach (array_keys($tables) as $t) {
687
            $tableId = $tables[$t]->getVar('table_id');
688
            $tableMid = $tables[$t]->getVar('table_mid');
689
            $tableName = $tables[$t]->getVar('table_name');
690
            $tableCategory[] = $tables[$t]->getVar('table_category');
691
            $tableBroken[] = $tables[$t]->getVar('table_broken');
692
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
693
            if (1 == $tables[$t]->getVar('table_notifications')) {
694
                if ($t <= count($tableName)) {
695
                    $notifyFiles[] = $tables[$t]->getVar('table_name');
696
                }
697
            }
698
            if (1 == $tables[$t]->getVar('table_single')) {
699
                $single = $tableName;
700
            }
701
        }
702
        $fields = $this->getTableFields($tableMid, $tableId);
703
        $fieldId = null;
704
        $fieldParent = null;
705
        foreach (array_keys($fields) as $f) {
706
            $fieldName = $fields[$f]->getVar('field_name');
707
            $fieldElement = $fields[$f]->getVar('field_element');
708
            if (0 == $f) {
709
                $fieldId = $fieldName;
710
            }
711
            if ($fieldElement > 15) {
712
                $fieldParent = $fieldName;
713
            }
714
        }
715
716
        $num = 1;
717
        $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles, $num);
718
        ++$num;
719
        $ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1', $num);
720
        ++$num;
721
        $ret .= $this->getXoopsVersionNotificationTableName($language, 'category', 'file', 'file', $single, $fieldId, 1, $num);
722
        unset($num);
723
        $num = 1;
724
        if (in_array(1, $tableCategory)) {
725
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_category', 'global', 0, 'global', 'newcategory', 'global_newcategory_notify', $num);
726
            ++$num;
727
        }
728
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_modify', 'global', 1, 'global', 'filemodify', 'global_filemodify_notify', $num);
729
        if (in_array(1, $tableBroken)) {
730
            ++$num;
731
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_broken', 'global', 1, 'global', 'filebroken', 'global_filebroken_notify', $num);
732
        }
733
        if (in_array(1, $tableSubmit)) {
734
            ++$num;
735
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'global', 1, 'global', 'filesubmit', 'global_filesubmit_notify', $num);
736
        }
737
        ++$num;
738
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'global', 0, 'global', 'newfile', 'global_newfile_notify', $num);
739
        if (in_array(1, $tableCategory)) {
740
            ++$num;
741
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'file_submit', 'category', 1, 'category', 'filesubmit', 'category_filesubmit_notify', $num);
742
            ++$num;
743
            $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'new_file', 'category', 0, 'category', 'newfile', 'category_newfile_notify', $num);
744
        }
745
        ++$num;
746
        $ret .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'approve', 'file', 1, 'file', 'approve', 'file_approve_notify', $num);
747
        unset($num);
748
749
        return $ret;
750
    }
751
752
    /*
753
    *  @private function getXoopsVersionNotificationGlobal
754
    */
755
    /**
756
     * @param $language
757
     * @param $type
758
     * @param $name
759
     * @param $title
760
     * @param $from
761
     *
762
     * @return string
763
     */
764
    private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from, $num)
765
    {
766
        $title = strtoupper($title);
767
        $implodeFrom = implode(".php', '", $from);
768
        $ret = $this->getCommentLine('Global Notify');
769
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
770
                        'subscribe_from' => "array('index.php', '{$implodeFrom}.php')", );
771
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
772
773
        return $ret;
774
    }
775
776
    /*
777
    *  @private function getXoopsVersionNotificationCategory
778
    */
779
    /**
780
     * @param $language
781
     * @param $type
782
     * @param $name
783
     * @param $title
784
     * @param $from
785
     *
786
     * @return string
787
     */
788
    private function getXoopsVersionNotificationCategory($language, $type, $name, $title, $file, $item, $allow, $num)
789
    {
790
        $title = strtoupper($title);
791
        $impFile = implode(".php', '", $file);
792
        $ret = $this->getCommentLine('Category Notify');
793
        $global = array('name' => "'{$name}'", 'title' => "{$language}{$title}_NOTIFY", 'description' => "{$language}{$title}_NOTIFY_DESC",
794
                        'subscribe_from' => "array('{$impFile}.php')", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
795
        $ret .= $this->usercode->getUserModVersion(4, $global, 'notification', "'{$type}'", $num);
796
797
        return $ret;
798
    }
799
800
    /*
801
    *  @private function getXoopsVersionNotificationTableName
802
    */
803
    /**
804
     * @param $language
805
     * @param $type
806
     * @param $name
807
     * @param $title
808
     * @param $file
809
     * @param $item
810
     * @param $allow
811
     *
812
     * @return string
813
     */
814
    private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $file, $item = 'cid', $allow = 1, $num)
815
    {
816
        $stuTitle = strtoupper($title);
817
        $ucfTitle = ucfirst($title);
818
        $ret = $this->getCommentLine($ucfTitle.' Notify');
819
        $table = array('name' => "'{$name}'", 'title' => "{$language}{$stuTitle}_NOTIFY", 'description' => "{$language}{$stuTitle}_NOTIFY_DESC",
820
                        'subscribe_from' => "'{$file}.php'", 'item_name' => "'{$item}'", 'allow_bookmark' => "{$allow}", );
821
        $ret .= $this->usercode->getUserModVersion(4, $table, 'notification', "'{$type}'", $num);
822
823
        return $ret;
824
    }
825
826
    /*
827
    *  @private function getXoopsVersionNotifications
828
    */
829
    /**
830
     * @param $language
831
     * @param $type
832
     * @param $name
833
     * @param $title
834
     * @param $from
835
     * @param $item
836
     * @param $mail
837
     *
838
     * @return string
839
     */
840
    private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin = 1, $title, $table, $mail, $num)
841
    {
842
        $title = strtoupper($title);
843
        $table = strtoupper($table);
844
        $ucfTitle = ucfirst($title);
845
        $ret = $this->getCommentLine($ucfTitle.' Notify');
846
        $event = array('name' => "'{$name}'", 'category' => "'{$category}'", 'admin_only' => "{$admin}", 'title' => "{$language}{$title}_{$table}_NOTIFY",
847
                        'caption' => "{$language}{$title}_{$table}_NOTIFY_CAPTION", 'description' => "{$language}{$title}_{$table}_NOTIFY_DESC",
848
                        'mail_template' => "'{$mail}'", 'mail_subject' => "{$language}{$title}_{$table}_NOTIFY_SUBJECT", );
849
        $ret .= $this->usercode->getUserModVersion(4, $event, 'notification', "'{$type}'", $num);
850
851
        return $ret;
852
    }
853
854
    /*
855
    *  @public function render
856
    *  @param null
857
    */
858
    /**
859
     * @return bool|string
860
     */
861
    public function render()
862
    {
863
        $module = $this->getModule();
864
        $table = $this->getTable();
865
        $tables = $this->getTables();
866
        $filename = $this->getFileName();
867
        $moduleDirname = $module->getVar('mod_dirname');
868
        $language = $this->getLanguage($moduleDirname, 'MI');
869
        $content = $this->getHeaderFilesComments($module, $filename);
870
        $content .= $this->getXoopsVersionHeader($module, $language);
871
        if (1 == $module->getVar('mod_admin')) {
872
            $content .= $this->getXoopsVersionTemplatesAdmin($moduleDirname, $tables);
873
        }
874
        if (1 == $module->getVar('mod_user')) {
875
            $content .= $this->getXoopsVersionTemplatesUser($moduleDirname, $tables);
876
        }
877
        $content .= $this->getXoopsVersionMySQL($moduleDirname, $table, $tables);
878
        $tableSearch = array();
879
        $tableComments = array();
880
        $tableSubmenu = array();
881
        $tableBlocks = array();
882
        $tableNotifications = array();
883
        foreach (array_keys($tables) as $t) {
884
            $tableSearch[] = $tables[$t]->getVar('table_search');
885
            $tableComments[] = $tables[$t]->getVar('table_comments');
886
            $tableSubmenu[] = $tables[$t]->getVar('table_submenu');
887
            $tableBlocks[] = $tables[$t]->getVar('table_blocks');
888
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
889
        }
890
        if (in_array(1, $tableSearch)) {
891
            $content .= $this->getXoopsVersionSearch($moduleDirname);
892
        }
893
        if (in_array(1, $tableComments)) {
894
            $content .= $this->getXoopsVersionComments($moduleDirname);
895
        }
896
        if (in_array(1, $tableSubmenu)) {
897
            $content .= $this->getXoopsVersionSubmenu($language, $tables);
898
        }
899
        if (in_array(1, $tableBlocks)) {
900
            $content .= $this->getXoopsVersionBlocks($moduleDirname, $tables, $language);
901
        }
902
        $content .= $this->getXoopsVersionConfig($module, $table, $language);
903
        if (in_array(1, $tableNotifications)) {
904
            $content .= $this->getXoopsVersionNotifications($module, $language);
905
        }
906
        $this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
907
908
        return $this->renderFile();
909
    }
910
}
911