CreateArchitecture::setBaseFoldersFiles()   F
last analyzed

Complexity

Conditions 17
Paths 4352

Size

Total Lines 115
Code Lines 76

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 76
nc 4352
nop 1
dl 0
loc 115
rs 1.0499
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

1
<?php
2
3
namespace XoopsModules\Tdmcreate\Files;
4
5
use XoopsModules\Tdmcreate;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
/**
17
 * tdmcreate module.
18
 *
19
 * @copyright       XOOPS Project (https://xoops.org)
20
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21
 *
22
 * @since           2.5.0
23
 *
24
 * @author          Txmod Xoops http://www.txmodxoops.org
25
 *
26
 */
27
28
//include dirname(__DIR__) . '/autoload.php';
29
30
/**
31
 * Class Architecture.
32
 */
33
class CreateArchitecture extends CreateStructure
34
{
35
    /**
36
     * @public function constructor class
37
     *
38
     * @param null
39
     */
40
    public function __construct()
41
    {
42
        parent::__construct();
43
        $this->setUploadPath(TDMC_UPLOAD_REPOSITORY_PATH);
44
    }
45
46
    /**
47
     * @static function getInstance
48
     *
49
     * @param null
50
     *
51
     * @return Tdmcreate\Files\CreateArchitecture
52
     */
53
    public static function getInstance()
54
    {
55
        static $instance = false;
56
        if (!$instance) {
57
            $instance = new self();
58
        }
59
60
        return $instance;
61
    }
62
63
    /**
64
     * @public function setBaseFoldersFiles
65
     *
66
     * @param $module
67
     */
68
    public function setBaseFoldersFiles($module)
69
    {
70
        $helper = Tdmcreate\Helper::getInstance();
71
        $tf     = Tdmcreate\Files\CreateFile::getInstance();
72
        // Module
73
        $modId = $module->getVar('mod_id');
74
        // Id of tables
75
        $tables = $tf->getTableTables($modId);
76
77
        $table = null;
78
        foreach (array_keys($tables) as $t) {
79
            $tableId   = $tables[$t]->getVar('table_id');
80
            $tableName = $tables[$t]->getVar('table_name');
81
            $table     = $helper->getHandler('Tables')->get($tableId);
82
        }
83
84
        $indexFile       = XOOPS_UPLOAD_PATH . '/index.html';
85
        $stlModuleAuthor = str_replace(' ', '', mb_strtolower($module->getVar('mod_author')));
86
        $this->setModuleName($module->getVar('mod_dirname'));
87
        $uploadPath = $this->getUploadPath();
88
        // Creation of "module" folder in the Directory repository
89
        $this->makeDir($uploadPath . '/' . $this->getModuleName());
90
        if (1 != $module->getVar('mod_user')) {
91
            // Copied of index.html file in "root module" folder
92
            $this->copyFile('', $indexFile, 'index.html');
93
        }
94
        if (1 == $module->getVar('mod_admin')) {
95
            // Creation of "admin" folder and index.html file
96
            $this->makeDirAndCopyFile('admin', $indexFile, 'index.html');
97
        }
98
        if (1 == $module->getVar('mod_blocks')) {
99
            // Creation of "blocks" folder and index.html file
100
            $this->makeDirAndCopyFile('blocks', $indexFile, 'index.html');
101
        }
102
        $language  = ('english' !== $GLOBALS['xoopsConfig']['language']) ? $GLOBALS['xoopsConfig']['language'] : 'english';
103
        $copyFiles = [
104
            'class'                           => $indexFile,
105
            'include'                         => $indexFile,
106
            'config'                          => $indexFile,
107
            'language'                        => $indexFile,
108
            'assets'                          => $indexFile,
109
            'assets/css'                      => $indexFile,
110
            'assets/css/admin'                => $indexFile,
111
            'assets/icons'                    => $indexFile,
112
            'assets/icons/16'                 => $indexFile,
113
            'assets/icons/32'                 => $indexFile,
114
            'docs'                            => $indexFile,
115
            'assets/images'                   => $indexFile,
116
            'assets/js'                       => $indexFile,
117
            'language/' . $language           => $indexFile,
118
            'language/' . $language . '/help' => $indexFile,
119
            'preloads'                        => $indexFile,
120
        ];
121
        foreach ($copyFiles as $k => $v) {
122
            // Creation of folders and index.html file
123
            $this->makeDirAndCopyFile($k, $v, 'index.html');
124
        }
125
        //Copy the logo of the module
126
        $modImage = str_replace(' ', '', mb_strtolower($module->getVar('mod_image')));
127
        $targetImage = 'logoModule.png';
128
        $this->copyFile('assets/images', TDMC_UPLOAD_IMGMOD_PATH . '/' . $modImage, $targetImage);
129
130
        //Copy blank files
131
        $targetImage = 'blank.gif';
132
        $this->copyFile('assets/images', TDMC_IMAGE_PATH . '/' . $targetImage, $targetImage);
133
        $targetImage = 'blank.png';
134
        $this->copyFile('assets/images', TDMC_IMAGE_PATH . '/' . $targetImage , $targetImage);
135
136
        // Copy of 'module_author_logo.png' file in uploads dir
137
        $logoPng     = $stlModuleAuthor . '_logo.png';
138
        $logoGifFrom = TDMC_UPLOAD_IMGMOD_PATH . '/' . $logoPng;
139
        // If file exists
140
        if (!file_exists($logoGifFrom)) {
141
            // Rename file
142
            $copyFile    = TDMC_IMAGES_LOGOS_URL . '/xoopsdevelopmentteam_logo.gif';
143
            $copyNewFile = $logoGifFrom;
144
            copy($copyFile, $copyNewFile);
145
        } else {
146
            // Copy file
147
            $copyFile    = TDMC_IMAGES_LOGOS_URL . '/' . $logoPng;
148
            $copyNewFile = $logoGifFrom;
149
            copy($copyFile, $copyNewFile);
150
        }
151
152
        // Creation of 'module_author_logo.gif' file
153
        $this->copyFile('assets/images', $copyNewFile, $logoPng);
154
        $docs = [
155
            '/credits.txt' => 'credits.txt',
156
            '/install.txt' => 'install.txt',
157
            '/lang.diff'   => 'lang.diff',
158
            '/license.txt' => 'license.txt',
159
            '/readme.txt'  => 'readme.txt',
160
        ];
161
        foreach ($docs as $k => $v) {
162
            // Creation of folder docs and .txt files
163
            $this->makeDirAndCopyFile('docs', TDMC_DOCS_PATH . $k, $v);
164
        }
165
        if (!empty($tableName)) {
166
            if (1 == $module->getVar('mod_admin') || 1 == $module->getVar('mod_user')) {
167
                // Creation of "templates" folder and index.html file
168
                $this->makeDirAndCopyFile('templates', $indexFile, 'index.html');
169
            }
170
            if (1 == $module->getVar('mod_admin')) {
171
                // Creation of "templates/admin" folder and index.html file
172
                $this->makeDirAndCopyFile('templates/admin', $indexFile, 'index.html');
173
            }
174
            if ((1 == $module->getVar('mod_blocks')) && (1 == $table->getVar('table_blocks'))) {
175
                // Creation of "templates/blocks" folder and index.html file
176
                $this->makeDirAndCopyFile('templates/blocks', $indexFile, 'index.html');
177
            }
178
            // Creation of "sql" folder and index.html file
179
            $this->makeDirAndCopyFile('sql', $indexFile, 'index.html');
180
            if ((1 == $module->getVar('mod_notifications')) && (1 == $table->getVar('table_notifications'))) {
181
                // Creation of "language/local_language/mail_template" folder and index.html file
182
                $this->makeDirAndCopyFile('language/' . $language . '/mail_template', $indexFile, 'index.html');
183
            }
184
        }
185
    }
186
187
    /**
188
     * @public function setFilesToBuilding
189
     *
190
     * @param string $module
191
     *
192
     * @return array
193
     */
194
    public function setFilesToBuilding($module)
195
    {
196
        $helper = Tdmcreate\Helper::getInstance();
197
        $tf     = Tdmcreate\Files\CreateFile::getInstance();
198
        // Module
199
        $modId         = $module->getVar('mod_id');
200
        $moduleDirname = $module->getVar('mod_dirname');
201
        $icon32        = 'assets/icons/32';
202
        $tables        = $tf->getTableTables($modId);
203
        $files         = $tf->getTableMoreFiles($modId);
204
        $ret           = [];
205
206
        $table              = null;
207
        $tableCategory      = [];
208
        //$tableName          = [];
209
        $tableAdmin         = [];
210
        $tableUser          = [];
211
        $tableBlocks        = [];
212
        $tableSearch        = [];
213
        $tableComments      = [];
214
        $tableNotifications = [];
215
        $permTables         = [];
216
        $tablePermissions   = [];
217
        $tableBroken        = [];
218
        $tablePdf           = [];
219
        $tablePrint         = [];
220
        $tableRate          = [];
221
        $tableRss           = [];
222
        $tableSingle        = [];
223
        $tableSubmit        = [];
224
        $tableVisit         = [];
225
        $tableTag           = [];
226
        foreach (array_keys($tables) as $t) {
227
            $tableId              = $tables[$t]->getVar('table_id');
228
            $tableName            = $tables[$t]->getVar('table_name');
229
            $tableCategory[]      = $tables[$t]->getVar('table_category');
230
            $tableImage           = $tables[$t]->getVar('table_image');
231
            $tableAdmin[]         = $tables[$t]->getVar('table_admin');
232
            $tableUser[]          = $tables[$t]->getVar('table_user');
233
            $tableBlocks[]        = $tables[$t]->getVar('table_blocks');
234
            $tableSearch[]        = $tables[$t]->getVar('table_search');
235
            $tableComments[]      = $tables[$t]->getVar('table_comments');
236
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
237
            $tablePermissions[]   = $tables[$t]->getVar('table_permissions');
238
            $permTables[]         = $tables[$t]->getVar('table_name');
239
            $tableBroken[]        = $tables[$t]->getVar('table_broken');
240
            $tablePdf[]           = $tables[$t]->getVar('table_pdf');
241
            $tablePrint[]         = $tables[$t]->getVar('table_print');
242
            $tableRate[]          = $tables[$t]->getVar('table_rate');
243
            $tableRss[]           = $tables[$t]->getVar('table_rss');
244
            $tableSingle[]        = $tables[$t]->getVar('table_single');
245
            $tableSubmit[]        = $tables[$t]->getVar('table_submit');
246
            $tableVisit[]         = $tables[$t]->getVar('table_visit');
247
            $tableTag[]           = $tables[$t]->getVar('table_tag');
248
            // Get Table Object
249
            $table = $helper->getHandler('Tables')->get($tableId);
250
            // Copy of tables images file
251
            if (file_exists($uploadTableImage = TDMC_UPLOAD_IMGTAB_PATH . '/' . $tableImage)) {
252
                $this->copyFile($icon32, $uploadTableImage, $tableImage);
253
            } elseif (file_exists($uploadTableImage = XOOPS_ICONS32_PATH . '/' . $tableImage)) {
254
                $this->copyFile($icon32, $uploadTableImage, $tableImage);
255
            }
256
            // Creation of admin files
257
            if (1 === (int)$tables[$t]->getVar('table_admin')) {
258
                // Admin Pages File
259
                $adminPages = Tdmcreate\Files\Admin\AdminPages::getInstance();
260
                $adminPages->write($module, $table, $tableName . '.php');
261
                $ret[] = $adminPages->render();
262
                // Admin Templates File
263
                $adminTemplatesPages = Tdmcreate\Files\Templates\Admin\TemplatesAdminPages::getInstance();
264
                $adminTemplatesPages->write($module, $table, $moduleDirname . '_admin_' . $tableName . '.tpl');
265
                $ret[] = $adminTemplatesPages->render();
266
            }
267
            // Creation of blocks
268
            if (1 === (int)$tables[$t]->getVar('table_blocks')) {
269
                // Blocks Files
270
                $blocksFiles = Tdmcreate\Files\Blocks\BlocksFiles::getInstance();
271
                $blocksFiles->write($module, $table, $tableName . '.php');
272
                $ret[] = $blocksFiles->render();
273
                // Templates Blocks Files
274
                $templatesBlocks = Tdmcreate\Files\Templates\Blocks\TemplatesBlocks::getInstance();
275
                $templatesBlocks->write($module, $table, $moduleDirname . '_block_' . $tableName . '.tpl');
276
                $ret[] = $templatesBlocks->render();
277
            }
278
            // Creation of classes
279
            if (1 === (int)$tables[$t]->getVar('table_admin') || 1 === (int)$tables[$t]->getVar('table_user')) {
280
                // Class Files
281
                $classFiles = Tdmcreate\Files\Classes\ClassFiles::getInstance();
282
                $classFiles->write($module, $table, $tables, ucfirst($tableName) . '.php');
0 ignored issues
show
Bug introduced by
$table of type XoopsObject is incompatible with the type string expected by parameter $table of XoopsModules\Tdmcreate\F...ses\ClassFiles::write(). ( Ignorable by Annotation )

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

282
                $classFiles->write($module, /** @scrutinizer ignore-type */ $table, $tables, ucfirst($tableName) . '.php');
Loading history...
283
                $ret[] = $classFiles->render();
284
            }
285
            // Creation of classhandlers
286
            if (1 === (int)$tables[$t]->getVar('table_admin') || 1 === (int)$tables[$t]->getVar('table_user')) {
287
                // Class Files
288
                $classFiles = Tdmcreate\Files\Classes\ClassHandlerFiles::getInstance();
289
                $classFiles->write($module, $table, $tables, ucfirst($tableName) . 'handler.php');
0 ignored issues
show
Bug introduced by
$table of type XoopsObject is incompatible with the type string expected by parameter $table of XoopsModules\Tdmcreate\F...ssHandlerFiles::write(). ( Ignorable by Annotation )

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

289
                $classFiles->write($module, /** @scrutinizer ignore-type */ $table, $tables, ucfirst($tableName) . 'handler.php');
Loading history...
290
                $ret[] = $classFiles->render();
291
            }
292
            // Creation of user files
293
            if (1 === (int)$tables[$t]->getVar('table_user')) {
294
                // User Pages File
295
                $userPages = Tdmcreate\Files\User\UserPages::getInstance();
296
                $userPages->write($module, $table, $tableName . '.php');
297
                $ret[] = $userPages->render();
298
                // User Templates File
299
                $userTemplatesPages = Tdmcreate\Files\Templates\User\Pages::getInstance();
300
                $userTemplatesPages->write($module, $table, $moduleDirname . '_' . $tableName . '.tpl');
301
                $ret[] = $userTemplatesPages->render();
302
                // User List Templates File
303
                $userTemplatesPagesList = Tdmcreate\Files\Templates\User\PagesList::getInstance();
304
                $userTemplatesPagesList->write($module, $table, $tables, $moduleDirname . '_' . $tableName . '_list' . '.tpl');
305
                $ret[] = $userTemplatesPagesList->render();
306
                if (1 === (int)$tables[$t]->getVar('table_category')) {
307
                    // User List Templates File
308
                    $userTemplatesCategories = Templates\User\Categories::getInstance();
309
                    $userTemplatesCategories->write($module, $table, $moduleDirname . '_' . $tableName . '_cat.tpl');
310
                    $ret[] = $userTemplatesCategories->render();
311
                    // User List Templates File
312
                    $userTemplatesCategoriesList = Templates\User\CategoriesList::getInstance();
313
                    $userTemplatesCategoriesList->write($module, $table, $moduleDirname . '_' . $tableName . '_cat_list' . '.tpl');
314
                    $ret[] = $userTemplatesCategoriesList->render();
315
                }
316
            }
317
        }
318
319
        // Creation of constants
320
        $classSpecialFiles = Tdmcreate\Files\Classes\ClassSpecialFiles::getInstance();
321
        $classSpecialFiles->write($module, '', $tables, ucfirst('constants') . '.php');
322
        $classSpecialFiles->className = 'Constants';
323
        $ret[] = $classSpecialFiles->renderConstants();
324
325
        // Creation of permissions
326
        if (in_array(1, $tablePermissions)) {
327
            // Creation of classes
328
            $classSpecialFiles = Tdmcreate\Files\Classes\ClassSpecialFiles::getInstance();
329
            $classSpecialFiles->write($module, '', null, ucfirst('permissions') . '.php');
330
            $classSpecialFiles->className = 'Permissions';
331
            $ret[] = $classSpecialFiles->renderClass();
332
333
            // Creation of classhandlers
334
            $classSpecialFiles = Tdmcreate\Files\Classes\ClassSpecialFiles::getInstance();
335
            $classSpecialFiles->write($module, '', $permTables, ucfirst('permissionshandler') . '.php');
336
            $classSpecialFiles->className = 'Permissionshandler';
337
            $ret[] = $classSpecialFiles->renderPermissionsHandler();
338
339
        }
340
        foreach (array_keys($files) as $t) {
341
            $fileName      = $files[$t]->getVar('file_name');
342
            $fileExtension = $files[$t]->getVar('file_extension');
343
            $fileInfolder  = $files[$t]->getVar('file_infolder');
344
            // More File
345
            $moreFiles = Tdmcreate\MoreFiles::getInstance();
346
            $moreFiles->write($module, $fileName, $fileInfolder, $fileExtension);
0 ignored issues
show
Bug introduced by
The method write() does not exist on XoopsModules\Tdmcreate\MoreFiles. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

346
            $moreFiles->/** @scrutinizer ignore-call */ 
347
                        write($module, $fileName, $fileInfolder, $fileExtension);
Loading history...
347
            $ret[] = $moreFiles->render();
0 ignored issues
show
Bug introduced by
The method render() does not exist on XoopsModules\Tdmcreate\MoreFiles. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

347
            /** @scrutinizer ignore-call */ 
348
            $ret[] = $moreFiles->render();
Loading history...
348
        }
349
        // Language Modinfo File
350
        $languageModinfo = Tdmcreate\Files\Language\LanguageModinfo::getInstance();
351
        $languageModinfo->write($module, $table, 'modinfo.php');
352
        $ret[] = $languageModinfo->render();
353
        if (1 == $module->getVar('mod_admin')) {
354
            // Admin Header File
355
            $adminHeader = Tdmcreate\Files\Admin\AdminHeader::getInstance();
356
            $adminHeader->write($module, $table, $tables, 'header.php');
357
            $ret[] = $adminHeader->render();
358
            // Admin Index File
359
            $adminIndex = Tdmcreate\Files\Admin\AdminIndex::getInstance();
360
            $adminIndex->write($module, $tables, 'index.php');
361
            $ret[] = $adminIndex->render();
362
            // Admin Menu File
363
            $adminObject = Tdmcreate\Files\Admin\AdminMenu::getInstance();
364
            $adminObject->write($module, 'menu.php');
365
            $ret[] = $adminObject->render();
366
            // Admin About File
367
            $adminAbout = Tdmcreate\Files\Admin\AdminAbout::getInstance();
368
            $adminAbout->write($module, 'about.php');
369
            $ret[] = $adminAbout->render();
370
            // Admin Footer File
371
            $adminFooter = Tdmcreate\Files\Admin\AdminFooter::getInstance();
372
            $adminFooter->write($module, 'footer.php');
373
            $ret[] = $adminFooter->render();
374
            // Templates Admin About File
375
            $adminTemplatesAbout = Tdmcreate\Files\Templates\Admin\TemplatesAdminAbout::getInstance();
376
            $adminTemplatesAbout->write($module, $moduleDirname . '_admin_about.tpl');
377
            $ret[] = $adminTemplatesAbout->render();
378
            // Templates Admin Index File
379
            $adminTemplatesIndex = Tdmcreate\Files\Templates\Admin\TemplatesAdminIndex::getInstance();
380
            $adminTemplatesIndex->write($module, $moduleDirname . '_admin_index.tpl');
381
            $ret[] = $adminTemplatesIndex->render();
382
            // Templates Admin Footer File
383
            $adminTemplatesFooter = Tdmcreate\Files\Templates\Admin\TemplatesAdminFooter::getInstance();
384
            $adminTemplatesFooter->write($module, $moduleDirname . '_admin_footer.tpl');
385
            $ret[] = $adminTemplatesFooter->render();
386
            // Templates Admin Header File
387
            $adminTemplatesHeader = Tdmcreate\Files\Templates\Admin\TemplatesAdminHeader::getInstance();
388
            $adminTemplatesHeader->write($module, $moduleDirname . '_admin_header.tpl');
389
            $ret[] = $adminTemplatesHeader->render();
390
            // Language Admin File
391
            $languageAdmin = Tdmcreate\Files\Language\LanguageAdmin::getInstance();
392
            $languageAdmin->write($module, $table, $tables, 'admin.php');
393
            $ret[] = $languageAdmin->render();
394
        }
395
396
        // Class Helper File ==> setCommonFiles
397
398
        // Include Functions File
399
        $includeFunctions = Tdmcreate\Files\Includes\IncludeFunctions::getInstance();
400
        $includeFunctions->write($module, 'functions.php');
401
        $ret[] = $includeFunctions->render();
402
403
        // Include Install File  ==>  setCommonFiles
404
        // Include Uninstall File  ==>  setCommonFiles
405
        // Include Update File  ==>  setCommonFiles
406
407
        if (in_array(1, $tableBlocks)) {
408
            // Language Blocks File
409
            $languageBlocks = Tdmcreate\Files\Language\LanguageBlocks::getInstance();
410
            $languageBlocks->write($module, $tables, 'blocks.php');
411
            $ret[] = $languageBlocks->render();
412
        }
413
        // Creation of admin permission files
414
        if (in_array(1, $tablePermissions)) {
415
            // Admin Permissions File
416
            $adminPermissions = Tdmcreate\Files\Admin\AdminPermissions::getInstance();
417
            $adminPermissions->write($module, $tables, 'permissions.php');
418
            $ret[] = $adminPermissions->render();
419
            // Templates Admin Permissions File
420
            $adminTemplatesPermissions = Tdmcreate\Files\Templates\Admin\TemplatesAdminPermissions::getInstance();
421
            $adminTemplatesPermissions->write($module, $moduleDirname . '_admin_permissions.tpl');
422
            $ret[] = $adminTemplatesPermissions->render();
423
        }
424
        // Creation of notifications files
425
        if (in_array(1, $tableNotifications)) {
426
            // Include Notifications File
427
            $includeNotifications = Tdmcreate\Files\Includes\IncludeNotifications::getInstance();
428
            $includeNotifications->write($module, $tables, 'notifications.inc.php');
429
            $ret[] = $includeNotifications->render();
430
            // Language Mail Template Category File
431
            $languageMailTpl = Tdmcreate\Files\Language\LanguageMailTpl::getInstance();
432
            $languageMailTpl->write($module, 'category_new_notify.tpl');
433
            $ret[] = $languageMailTpl->render();
434
        }
435
        // Creation of sql file
436
        if (null != $table->getVar('table_name')) {
437
            // Sql File
438
            $sqlFile = Tdmcreate\Files\Sql\SqlFile::getInstance();
439
            $sqlFile->write($module, 'mysql.sql');
440
            $ret[] = $sqlFile->render();
441
        }
442
        // Creation of search file
443
        if (in_array(1, $tableSearch)) {
444
            // Search File
445
            //TODO: UserSearch has to be adapted
446
            /*
447
            $userSearch = Tdmcreate\Files\User\UserSearch::getInstance();
448
            $userSearch->write($module, $table, 'search.php');
449
            $ret[] = $userSearch->render();
450
            */
451
            // Include Search File
452
            $includeSearch = Tdmcreate\Files\Includes\IncludeSearch::getInstance();
453
            $includeSearch->write($module, $tables, 'search.inc.php');
454
            $ret[] = $includeSearch->render();
455
        }
456
        // Creation of comments files
457
        if (in_array(1, $tableComments)) {
458
            /*
459
             * TODO: are this comment files required?
460
            // Include Comments File
461
            $includeComments = Tdmcreate\Files\Includes\IncludeComments::getInstance();
462
            $includeComments->write($module, $table);
463
            $ret[] = $includeComments->renderCommentsIncludes($module, 'comment_edit');
464
            // Include Comments File
465
            $includeComments = Tdmcreate\Files\Includes\IncludeComments::getInstance();
466
            $includeComments->write($module, $table);
467
            $ret[] = $includeComments->renderCommentsIncludes($module, 'comment_delete');
468
            // Include Comments File
469
            $includeComments = Tdmcreate\Files\Includes\IncludeComments::getInstance();
470
            $includeComments->write($module, $table);
471
            $ret[] = $includeComments->renderCommentsIncludes($module, 'comment_post');
472
            // Include Comments File
473
            $includeComments = Tdmcreate\Files\Includes\IncludeComments::getInstance();
474
            $includeComments->write($module, $table);
475
            $ret[] = $includeComments->renderCommentsIncludes($module, 'comment_reply');
476
            // Include Comments File
477
            $includeComments = Tdmcreate\Files\Includes\IncludeComments::getInstance();
478
            $includeComments->write($module, $table);
479
            $ret[] = $includeComments->renderCommentsNew($module, 'comment_new');
480
            */
481
482
            // Include Comment Functions File
483
            $includeCommentFunctions = Tdmcreate\Files\Includes\IncludeCommentFunctions::getInstance();
484
            $includeCommentFunctions->write($module, $table, 'comment_functions.php');
485
            $ret[] = $includeCommentFunctions->render();
486
        }
487
488
        if ((1 == $module->getVar('mod_user')) && in_array(1, $tableUser)) {
489
            // Creation of user template files
490
            // Templates Index File
491
            $userTemplatesIndex = Tdmcreate\Files\Templates\User\Index::getInstance();
492
            $userTemplatesIndex->write($module, $table, $tables, $moduleDirname . '_index.tpl');
493
            $ret[] = $userTemplatesIndex->render();
494
            // Templates Footer File
495
            $userTemplatesFooter = Tdmcreate\Files\Templates\User\Footer::getInstance();
496
            $userTemplatesFooter->write($module, $table, $moduleDirname . '_footer.tpl');
497
            $ret[] = $userTemplatesFooter->render();
498
            // Templates Header File
499
            $userTemplatesHeader = Tdmcreate\Files\Templates\User\Header::getInstance();
500
            $userTemplatesHeader->write($module, $moduleDirname . '_header.tpl');
501
            $ret[] = $userTemplatesHeader->render();
502
503
            // Creation of user files
504
            // User Footer File
505
            $userFooter = Tdmcreate\Files\User\UserFooter::getInstance();
506
            $userFooter->write($module, 'footer.php');
507
            $ret[] = $userFooter->render();
508
            // User Header File
509
            $userHeader = Tdmcreate\Files\User\UserHeader::getInstance();
510
            $userHeader->write($module, $table, $tables, 'header.php');
511
            $ret[] = $userHeader->render();
512
            // User Notification Update File
513
            if ((1 == $module->getVar('mod_notifications')) && in_array(1, $tableNotifications)) {
514
                $userNotificationUpdate = Tdmcreate\Files\User\UserNotificationUpdate::getInstance();
515
                $userNotificationUpdate->write($module, 'notification_update.php');
516
                $ret[] = $userNotificationUpdate->render();
517
            }
518
            // User Broken File
519
            if (in_array(1, $tableBroken)) {
520
                $userBroken = Tdmcreate\Files\User\UserBroken::getInstance();
521
                $userBroken->write($module, $table, 'broken.php');
522
                $ret[] = $userBroken->render();
523
                // User Templates Broken File
524
                $userTemplatesBroken = Templates\User\Broken::getInstance();
525
                $userTemplatesBroken->write($module, $table, $moduleDirname . '_broken.tpl');
526
                $ret[] = $userTemplatesBroken->render();
527
            }
528
            // User Pdf File
529
            if (in_array(1, $tablePdf)) {
530
                $userPdf = Tdmcreate\Files\User\UserPdf::getInstance();
531
                $userPdf->write($module, $table, 'pdf.php');
532
                $ret[] = $userPdf->render();
533
                // User Templates Pdf File
534
                $userTemplatesPdf = Tdmcreate\Files\Templates\User\Pdf::getInstance();
535
                $userTemplatesPdf->write($module, $moduleDirname . '_pdf.tpl');
536
                $ret[] = $userTemplatesPdf->render();
537
            }
538
            // User Print File
539
            if (in_array(1, $tablePrint)) {
540
                $userPrint = Tdmcreate\Files\User\UserPrint::getInstance();
541
                $userPrint->write($module, $table, 'print.php');
542
                $ret[] = $userPrint->render();
543
                // User Templates Print File
544
                $userTemplatesPrint = Tdmcreate\Files\Templates\User\UserPrint::getInstance();
545
                $userTemplatesPrint->write($module, $table, $moduleDirname . '_print.tpl');
546
                $ret[] = $userTemplatesPrint->render();
547
            }
548
            // User Rate File
549
            //TODO: UserSearch has to be adapted
550
            if (in_array(1, $tableRate)) {
551
                $userRate = Tdmcreate\Files\User\UserRate::getInstance();
552
                $userRate->write($module, $table, 'rate.php');
553
                $ret[] = $userRate->render();
554
                // User Templates Rate File
555
                $userTemplatesRate = Tdmcreate\Files\Templates\User\Rate::getInstance();
556
                $userTemplatesRate->write($module, $table, $moduleDirname . '_rate.tpl');
557
                $ret[] = $userTemplatesRate->render();
558
            }
559
560
            // User Rss File
561
            if (in_array(1, $tableRss)) {
562
                $userRss = Tdmcreate\Files\User\UserRss::getInstance();
563
                $userRss->write($module, $table, 'rss.php');
564
                $ret[] = $userRss->render();
565
                // User Templates Rss File
566
                $userTemplatesRss = Tdmcreate\Files\Templates\User\Rss::getInstance();
567
                $userTemplatesRss->write($module, $moduleDirname . '_rss.tpl');
568
                $ret[] = $userTemplatesRss->render();
569
            }
570
            // User Single File
571
            if (in_array(1, $tableSingle)) {
572
                $userSingle = Tdmcreate\Files\User\UserSingle::getInstance();
573
                $userSingle->write($module, $table, 'single.php');
574
                $ret[] = $userSingle->render();
575
                // User Templates Single File
576
                $userTemplatesSingle = Tdmcreate\Files\Templates\User\Single::getInstance();
577
                $userTemplatesSingle->write($module, $table, $moduleDirname . '_single.tpl');
578
                $ret[] = $userTemplatesSingle->render();
579
            }
580
581
            // User Submit File
582
            if (in_array(1, $tableSubmit)) {
583
                $userSubmit = Tdmcreate\Files\User\UserSubmit::getInstance();
584
                $userSubmit->write($module, $table, 'submit.php');
585
                $ret[] = $userSubmit->render();
586
                // User Templates Submit File
587
                $userTemplatesSubmit = Tdmcreate\Files\Templates\User\Submit::getInstance();
588
                $userTemplatesSubmit->write($module, $table, $moduleDirname . '_submit.tpl');
589
                $ret[] = $userTemplatesSubmit->render();
590
            }
591
            // User Visit File
592
            if (in_array(1, $tableVisit)) {
593
                $userVisit = Tdmcreate\Files\User\UserVisit::getInstance();
594
                $userVisit->write($module, $table, 'visit.php');
595
                $ret[] = $userVisit->render();
596
            }
597
598
            // User Tag Files
599
            if (in_array(1, $tableTag)) {
600
                $userListTag = Tdmcreate\Files\User\UserListTag::getInstance();
601
                $userListTag->write($module, 'list.tag.php');
602
                $ret[]       = $userListTag->render();
603
                $userViewTag = Tdmcreate\Files\User\UserViewTag::getInstance();
604
                $userViewTag->write($module, 'view.tag.php');
605
                $ret[] = $userViewTag->render();
606
            }
607
            // User Index File
608
            $userIndex = Tdmcreate\Files\User\UserIndex::getInstance();
609
            $userIndex->write($module, $table, 'index.php');
610
            $ret[] = $userIndex->render();
611
            // Language Main File
612
            $languageMain = Tdmcreate\Files\Language\LanguageMain::getInstance();
613
            $languageMain->write($module, $tables, 'main.php');
614
            $ret[] = $languageMain->render();
615
            // User Templates Submit File
616
            $userTemplatesUserBreadcrumbs = Templates\User\Breadcrumbs::getInstance();
617
            $userTemplatesUserBreadcrumbs->write($module, $moduleDirname . '_breadcrumbs.tpl');
618
            $ret[] = $userTemplatesUserBreadcrumbs->render();
619
        }
620
        // Css Admin Styles File
621
        $cssStyles = Tdmcreate\Files\Assets\Css\Admin\CssAdminStyles::getInstance();
622
        $cssStyles->write($module, 'style.css');
623
        $ret[] = $cssStyles->render();
624
        // Css Styles File
625
        $cssStyles = Tdmcreate\Files\Assets\Css\CssStyles::getInstance();
626
        $cssStyles->write($module, 'style.css');
627
        $ret[] = $cssStyles->render();
628
        // Include Jquery File
629
        $JavascriptJQuery = Tdmcreate\Files\Assets\Js\JavascriptJQuery::getInstance();
630
        $JavascriptJQuery->write($module, 'functions.js');
631
        $ret[] = $JavascriptJQuery->render();
632
        // Include Common File
633
        $includeCommon = Tdmcreate\Files\Includes\IncludeCommon::getInstance();
634
        $includeCommon->write($module, $table, 'common.php');
635
        $ret[] = $includeCommon->render();
636
        // Common Config File
637
        $includeConfig = Tdmcreate\Files\Config\ConfigConfig::getInstance();
638
        $includeConfig->write($module, $tables, 'config.php');
639
        $ret[] = $includeConfig->render();
640
        // Docs Changelog File
641
        $docsChangelog = Tdmcreate\Files\Docs\DocsChangelog::getInstance();
642
        $docsChangelog->write($module, 'changelog.txt');
643
        $ret[] = $docsChangelog->render();
644
        // Language Help File
645
        $languageHelp = Tdmcreate\Files\Language\LanguageHelp::getInstance();
646
        $languageHelp->write($module, 'help.html');
647
        $ret[] = $languageHelp->render();
648
        // User Xoops Version File
649
        $userXoopsVersion = Tdmcreate\Files\User\UserXoopsVersion::getInstance();
650
        $userXoopsVersion->write($module, $table, $tables, 'xoops_version.php');
651
        $ret[] = $userXoopsVersion->render();
652
653
        // Return Array
654
        return $ret;
655
    }
656
657
    /**
658
     * @public function setCommonFiles
659
     *
660
     * @param $module
661
     */
662
    public function setCommonFiles($module)
663
    {
664
665
        $moduleName = $module->getVar('mod_dirname');
666
        //$src_path   = XOOPS_ROOT_PATH . '/modules/tdmcreate/files';
667
        //$tmp_path   = XOOPS_UPLOAD_PATH . '/tdmcreate/temp';
668
        $upl_path   = TDMC_UPLOAD_REPOSITORY_PATH . '/' . mb_strtolower($moduleName);
669
670
        $patterns = [
671
            mb_strtolower('tdmcreate')          => mb_strtolower($moduleName),
672
            mb_strtoupper('tdmcreate')          => mb_strtoupper($moduleName),
673
            ucfirst(mb_strtolower('tdmcreate')) => ucfirst(mb_strtolower($moduleName)),
674
        ];
675
676
        $patKeys   = array_keys($patterns);
677
        $patValues = array_values($patterns);
678
679
        /* clone complete missing folders */
680
        $cloneFolders[] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cloneFolders was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cloneFolders = array(); before regardless.
Loading history...
681
            'src'   => TDMC_PATH . '/commonfiles',
682
            'dst'   => $upl_path,
683
            'rcode' => true
684
        ];
685
        foreach ($cloneFolders as $folder) {
686
            Tdmcreate\Files\CreateClone::cloneFileFolder($folder['src'], $folder['dst'], $folder['rcode'], $patKeys, $patValues);
687
        }
688
        unset($cloneFolders);
689
690
        /* create missing folders for common files */
691
        $createFolders[] = $upl_path . '/testdata/' . $GLOBALS['xoopsConfig']['language'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$createFolders was never initialized. Although not strictly required by PHP, it is generally a good practice to add $createFolders = array(); before regardless.
Loading history...
692
        if ('english' !== $GLOBALS['xoopsConfig']['language']) {
693
            $createFolders[] = $upl_path . '/testdata/english';
694
            $createFolders[] = $upl_path . '/language/english';
695
        }
696
        foreach ($createFolders as $folder) {
697
            @mkdir($folder);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

697
            /** @scrutinizer ignore-unhandled */ @mkdir($folder);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
698
        }
699
        unset($createFolders);
700
701
        if ('english' !== $GLOBALS['xoopsConfig']['language']) {
702
            $cloneFolders[] = [
703
                'src'   => TDMC_PATH . '/commonfiles/language/english',
704
                'dst'   => $upl_path . '/language/' . $GLOBALS['xoopsConfig']['language'],
705
                'rcode' => true
706
            ];
707
            //copy back all language files to english language folder
708
            $cloneFolders[] = [
709
                'src'   => $upl_path . '/language/' . $GLOBALS['xoopsConfig']['language'],
710
                'dst'   => $upl_path . '/language/english',
711
                'rcode' => false
712
            ];
713
            foreach ($cloneFolders as $folder) {
714
                Tdmcreate\Files\CreateClone::cloneFileFolder($folder['src'], $folder['dst'], $folder['rcode'], $patKeys, $patValues);
715
            }
716
            unset($cloneFolders);
717
        }
718
719
        /* clone single missing files*/
720
        $cloneFiles[] = [
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cloneFiles was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cloneFiles = array(); before regardless.
Loading history...
721
            'src'   => TDMC_PATH . '/config/',
722
            'dst'   => $upl_path . '/config/',
723
            'file'  => 'admin.yml',
724
            'rcode' => true
725
        ];
726
        $cloneFiles[] = [
727
            'src'   => TDMC_PATH . '/config/',
728
            'dst'   => $upl_path . '/config/',
729
            'file'  => 'icons.php',
730
            'rcode' => true
731
        ];
732
        $cloneFiles[] = [
733
            'src'   => TDMC_PATH . '/config/',
734
            'dst'   => $upl_path . '/config/',
735
            'file'  => 'paths.php',
736
            'rcode' => true
737
        ];
738
        foreach ($cloneFiles as $file) {
739
            Tdmcreate\Files\CreateClone::cloneFile($file['src'] . $file['file'], $file['dst'] . $file['file'], $file['rcode'], $patKeys, $patValues);
740
        }
741
        unset($cloneFiles);
742
    }
743
}
744