LanguageModinfo   A
last analyzed

Complexity

Total Complexity 37

Size/Duplication

Total Lines 370
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 176
dl 0
loc 370
rs 9.44
c 0
b 0
f 0
wmc 37

14 Methods

Rating   Name   Duplication   Size   Complexity  
B render() 0 50 7
A getLanguageSubmenu() 0 20 4
A getInstance() 0 8 2
B getLanguageConfig() 0 55 9
A getLanguageMenu() 0 22 3
A getLanguageMain() 0 8 1
A write() 0 5 1
A getLanguageNotifications() 0 15 2
A getLanguagePermissionsGroups() 0 10 1
A getLanguageAdmin() 0 8 1
A getLanguageBlocks() 0 34 3
A getLanguageFooter() 0 6 1
A __construct() 0 3 1
A getLanguageUser() 0 8 1
1
<?php namespace XoopsModules\Tdmcreate\Files\Language;
2
3
use XoopsModules\Tdmcreate;
4
use XoopsModules\Tdmcreate\Files;
5
6
/*
7
 You may not change or alter any portion of this comment or credits
8
 of supporting developers from this source code or any supporting source code
9
 which is considered copyrighted (c) material of the original comment or credit authors.
10
11
 This program is distributed in the hope that it will be useful,
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 */
15
/**
16
 * tdmcreate module.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.0
22
 *
23
 * @author          Txmod Xoops http://www.txmodxoops.org
24
 *
25
 * @version         $Id: LanguageModinfo.php 12258 2014-01-02 09:33:29Z timgno $
26
 */
27
28
/**
29
 * Class LanguageModinfo.
30
 */
31
class LanguageModinfo extends Files\CreateFile
32
{
33
    /**
34
     *  @public function constructor
35
     *  @param null
36
     */
37
    public function __construct()
38
    {
39
        parent::__construct();
40
    }
41
42
    /**
43
     *  @static function getInstance
44
     *  @param null
45
     * @return LanguageModinfo
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance = false;
50
        if (!$instance) {
51
            $instance = new self();
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     *  @public function write
59
     *
60
     * @param $module
61
     * @param $table
62
     * @param $filename
63
     *
64
     * @return string
65
     */
66
    public function write($module, $table, $filename)
67
    {
68
        $this->setModule($module);
69
        $this->setTable($table);
70
        $this->setFileName($filename);
71
    }
72
73
    /**
74
     * @private function getLanguageMain
75
     *
76
     * @param $language
77
     * @param $module
78
     *
79
     * @return string
80
     */
81
    private function getLanguageMain($language, $module)
82
    {
83
        $df = LanguageDefines::getInstance();
84
        $ret = $df->getAboveHeadDefines('Admin Main');
85
        $ret .= $df->getDefine($language, 'NAME', (string)$module->getVar('mod_name'));
86
        $ret .= $df->getDefine($language, 'DESC', (string)$module->getVar('mod_description'));
87
88
        return $ret;
89
    }
90
91
    /**
92
     * @private function getLanguageMenu
93
     *
94
     * @param $module
95
     * @param $language
96
     *
97
     * @return string
98
     */
99
    private function getLanguageMenu($module, $language)
100
    {
101
        $df = Tdmcreate\Files\Language\LanguageDefines::getInstance();
102
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
103
        $menu = 1;
104
        $ret = $df->getAboveHeadDefines('Admin Menu');
105
        $ret .= $df->getDefine($language, "ADMENU{$menu}", 'Dashboard');
106
        $tablePermissions = [];
107
        foreach (array_keys($tables) as $i) {
108
            ++$menu;
109
            $tablePermissions[] = $tables[$i]->getVar('table_permissions');
110
            $ucfTableName = ucfirst($tables[$i]->getVar('table_name'));
111
            $ret .= $df->getDefine($language, "ADMENU{$menu}", $ucfTableName);
112
        }
113
        if (in_array(1, $tablePermissions)) {
114
            ++$menu;
115
            $ret .= $df->getDefine($language, "ADMENU{$menu}", 'Permissions');
116
        }
117
        $ret .= $df->getDefine($language, 'ABOUT', 'About');
118
        unset($menu, $tablePermissions);
119
120
        return $ret;
121
    }
122
123
    /**
124
     *  @private function getLanguageAdmin
125
     *  @param $language
126
     *
127
     * @return string
128
     */
129
    private function getLanguageAdmin($language)
130
    {
131
        $df = LanguageDefines::getInstance();
132
        $ret = $df->getAboveHeadDefines('Admin Nav');
133
        $ret .= $df->getDefine($language, 'ADMIN_PAGER', 'Admin pager');
134
        $ret .= $df->getDefine($language, 'ADMIN_PAGER_DESC', 'Admin per page list');
135
136
        return $ret;
137
    }
138
139
    /**
140
     *  @private function getLanguageSubmenu
141
     *  @param $language
142
     *  @param array $tables
143
     *
144
     * @return string
145
     */
146
    private function getLanguageSubmenu($language, $tables)
147
    {
148
        $df = LanguageDefines::getInstance();
149
        $ret = $df->getAboveDefines('Submenu');
150
        $i = 1;
151
        $tableSubmit = [];
152
        foreach (array_keys($tables) as $t) {
153
            $tableName = $tables[$t]->getVar('table_name');
154
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
155
            if (1 == $tables[$t]->getVar('table_submenu')) {
156
                $ret .= $df->getDefine($language, "SMNAME{$i}", (string)$tableName);
157
            }
158
            ++$i;
159
        }
160
        if (in_array(1, $tableSubmit)) {
161
            $ret .= $df->getDefine($language, "SMNAME{$i}", 'Submit');
162
        }
163
        unset($i, $tableSubmit);
164
165
        return $ret;
166
    }
167
168
    /**
169
     *  @private function getLanguageBlocks
170
     *  @param $language
171
     *  @param array $tables
172
     *
173
     * @return string
174
     */
175
    private function getLanguageBlocks($tables, $language)
176
    {
177
        $df = LanguageDefines::getInstance();
178
        $ret = $df->getAboveDefines('Blocks');
179
        foreach (array_keys($tables) as $i) {
180
            $tableName = $tables[$i]->getVar('table_name');
181
            $stuTableName = mb_strtoupper($tableName);
182
            $tableSoleName = $tables[$i]->getVar('table_solename');
183
            $stuTableSoleName = mb_strtoupper($tableSoleName);
184
            $ucfTableName = ucfirst($tableName);
185
            $ucfTableSoleName = ucfirst($stuTableSoleName);
186
187
            $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK", "{$ucfTableName} block");
188
            $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_DESC", "{$ucfTableName} block description");
189
            if (1 == $tables[$i]->getVar('table_category')) {
190
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block {$ucfTableSoleName}");
191
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block {$ucfTableSoleName} description");
192
            } else {
193
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block  {$ucfTableSoleName}");
194
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block  {$ucfTableSoleName} description");
195
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_LAST", "{$ucfTableName} block last");
196
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_LAST_DESC", "{$ucfTableName} block last description");
197
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_NEW", "{$ucfTableName} block new");
198
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_NEW_DESC", "{$ucfTableName} block new description");
199
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_HITS", "{$ucfTableName} block hits");
200
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_HITS_DESC", "{$ucfTableName} block hits description");
201
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_TOP", "{$ucfTableName} block top");
202
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_TOP_DESC", "{$ucfTableName} block top description");
203
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM", "{$ucfTableName} block random");
204
                $ret .= $df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM_DESC", "{$ucfTableName} block random description");
205
            }
206
        }
207
208
        return $ret;
209
    }
210
211
    /**
212
     *  @private function getLanguageUser
213
     *  @param $language
214
     *
215
     * @return string
216
     */
217
    private function getLanguageUser($language)
218
    {
219
        $df = LanguageDefines::getInstance();
220
        $ret = $df->getAboveDefines('User');
221
        $ret .= $df->getDefine($language, 'USER_PAGER', 'User pager');
222
        $ret .= $df->getDefine($language, 'USER_PAGER_DESC', 'User per page list');
223
224
        return $ret;
225
    }
226
227
    /**
228
     *  @private function getLanguageConfig
229
     *  @param $language
230
     *  @param $tables
231
     *
232
     * @return string
233
     */
234
    private function getLanguageConfig($language, $tables)
235
    {
236
        $df = LanguageDefines::getInstance();
237
        $ret = $df->getAboveDefines('Config');
238
        $fieldImage = false;
239
        $useTag = false;
240
        // $usePermissions = false;
241
        foreach (array_keys($tables) as $i) {
242
            $fields = $this->getTableFields($tables[$i]->getVar('table_mid'), $tables[$i]->getVar('table_id'));
243
            foreach (array_keys($fields) as $f) {
244
                $fieldElement = $fields[$f]->getVar('field_element');
245
                if (4 == $fieldElement) {
246
                    $fieldName = $fields[$f]->getVar('field_name');
247
                    $rpFieldName = $this->getRightString($fieldName);
248
                    $ucfFieldName = ucfirst($rpFieldName);
249
                    $stuFieldName = mb_strtoupper($rpFieldName);
250
                    $ret .= $df->getDefine($language, 'EDITOR_' . $stuFieldName, 'Editor');
251
                    $ret .= $df->getDefine($language, 'EDITOR_' . $stuFieldName . '_DESC', 'Select the Editor ' . $ucfFieldName . ' to use');
252
                }
253
                if (13 == $fieldElement) {
254
                    $fieldImage = true;
255
                }
256
            }
257
            if (0 != $tables[$i]->getVar('table_tag')) {
258
                $useTag = true;
259
            }
260
            // if (0 != $tables[$i]->getVar('table_permissions')) {$usePermissions = true;}
261
        }
262
        $ret .= $df->getDefine($language, 'KEYWORDS', 'Keywords');
263
        $ret .= $df->getDefine($language, 'KEYWORDS_DESC', 'Insert here the keywords (separate by comma)');
264
        /*if (usePermissions) {
265
            $ret .= $df->getDefine($language, "GROUPS", "Groups");
266
            $ret .= $df->getDefine($language, "GROUPS_DESC", "Groups to have permissions");
267
            $ret .= $df->getDefine($language, "ADMIN_GROUPS", "Admin Groups");
268
            $ret .= $df->getDefine($language, "ADMIN_GROUPS_DESC", "Admin Groups to have permissions access");
269
        }*/
270
        if ($fieldImage) {
271
            $ret .= $df->getDefine($language, 'MAXSIZE', 'Max size');
272
            $ret .= $df->getDefine($language, 'MAXSIZE_DESC', 'Set a number of max size uploads files in byte');
273
            $ret .= $df->getDefine($language, 'MIMETYPES', 'Mime Types');
274
            $ret .= $df->getDefine($language, 'MIMETYPES_DESC', 'Set the mime types selected');
275
        }
276
        if ($useTag) {
277
            $ret .= $df->getDefine($language, 'USE_TAG', 'Use TAG');
278
            $ret .= $df->getDefine($language, 'USE_TAG_DESC', 'If you use tag module, check this option to yes');
279
        }
280
        $getDefinesConf = [
281
            'NUMB_COL' => 'Number Columns', 'NUMB_COL_DESC' => 'Number Columns to View.', 'DIVIDEBY' => 'Divide By', 'DIVIDEBY_DESC' => 'Divide by columns number.',
282
            'TABLE_TYPE' => 'Table Type', 'TABLE_TYPE_DESC' => 'Table Type is the bootstrap html table.', 'PANEL_TYPE' => 'Panel Type', 'PANEL_TYPE_DESC' => 'Panel Type is the bootstrap html div.', 'IDPAYPAL' => 'Paypal ID', 'IDPAYPAL_DESC' => 'Insert here your PayPal ID for donactions.', 'ADVERTISE' => 'Advertisement Code', 'ADVERTISE_DESC' => 'Insert here the advertisement code', 'MAINTAINEDBY' => 'Maintained By', 'MAINTAINEDBY_DESC' => 'Allow url of support site or community', 'BOOKMARKS' => 'Social Bookmarks', 'BOOKMARKS_DESC' => 'Show Social Bookmarks in the single page', 'FACEBOOK_COMMENTS' => 'Facebook comments', 'FACEBOOK_COMMENTS_DESC' => 'Allow Facebook comments in the single page', 'DISQUS_COMMENTS' => 'Disqus comments', 'DISQUS_COMMENTS_DESC' => 'Allow Disqus comments in the single page',
283
        ];
284
        foreach ($getDefinesConf as $defc => $descc) {
285
            $ret .= $df->getDefine($language, $defc, $descc);
286
        }
287
288
        return $ret;
289
    }
290
291
    /**
292
     *  @private function getLanguageNotifications
293
     *  @param $language
294
     *  @param mixed $tableSoleName
295
     *
296
     * @return string
297
     */
298
    private function getLanguageNotifications($language, $tableSoleName)
299
    {
300
        $df = LanguageDefines::getInstance();
301
        $ret = $df->getAboveDefines('Notifications');
302
        $stuTableSoleName = mb_strtoupper($tableSoleName);
303
        $ucfTableSoleName = ucfirst($tableSoleName);
304
        $getDefinesNotif = [
305
            'GLOBAL_NOTIFY' => 'Global notify', 'GLOBAL_NOTIFY_DESC' => 'Global notify desc', 'CATEGORY_NOTIFY' => 'Category notify',
306
            'CATEGORY_NOTIFY_DESC' => 'Category notify desc', $stuTableSoleName . '_NOTIFY' => $ucfTableSoleName . ' notify', $stuTableSoleName . '_NOTIFY_DESC' => $ucfTableSoleName . ' notify desc', 'GLOBAL_NEWCATEGORY_NOTIFY' => 'Global newcategory notify', 'GLOBAL_NEWCATEGORY_NOTIFY_CAPTION' => 'Global newcategory notify caption', 'GLOBAL_NEWCATEGORY_NOTIFY_DESC' => 'Global newcategory notify desc', 'GLOBAL_NEWCATEGORY_NOTIFY_SUBJECT' => 'Global newcategory notify subject', 'GLOBAL_' . $stuTableSoleName . 'MODIFY_NOTIFY' => 'Global ' . $tableSoleName . 'modify notify', 'GLOBAL_' . $stuTableSoleName . 'MODIFY_NOTIFY_CAPTION' => 'Global ' . $tableSoleName . ' modify notify caption', 'GLOBAL_' . $stuTableSoleName . 'MODIFY_NOTIFY_DESC' => 'Global ' . $tableSoleName . 'modify notify desc', 'GLOBAL_' . $stuTableSoleName . 'MODIFY_NOTIFY_SUBJECT' => 'Global ' . $tableSoleName . ' modify notify subject', 'GLOBAL_' . $stuTableSoleName . 'BROKEN_NOTIFY' => 'Global ' . $tableSoleName . ' broken notify', 'GLOBAL_' . $stuTableSoleName . 'BROKEN_NOTIFY_CAPTION' => 'Global ' . $tableSoleName . 'broken notify caption', 'GLOBAL_' . $stuTableSoleName . 'BROKEN_NOTIFY_DESC' => 'Global ' . $tableSoleName . 'broken notify desc', 'GLOBAL_' . $stuTableSoleName . 'BROKEN_NOTIFY_SUBJECT' => 'Global ' . $tableSoleName . 'broken notify subject', 'GLOBAL_' . $stuTableSoleName . 'SUBMIT_NOTIFY' => 'Global ' . $tableSoleName . ' submit notify', 'GLOBAL_' . $stuTableSoleName . 'SUBMIT_NOTIFY_CAPTION' => 'Global ' . $tableSoleName . ' submit notify caption', 'GLOBAL_' . $stuTableSoleName . 'SUBMIT_NOTIFY_DESC' => 'Global ' . $tableSoleName . 'submit notify desc', 'GLOBAL_' . $stuTableSoleName . 'SUBMIT_NOTIFY_SUBJECT' => 'Global ' . $tableSoleName . 'submit notify subject', 'GLOBAL_NEW' . $stuTableSoleName . '_NOTIFY' => 'Global new' . $tableSoleName . ' notify', 'GLOBAL_NEW' . $stuTableSoleName . '_NOTIFY_CAPTION' => 'Global new' . $tableSoleName . ' notify caption', 'GLOBAL_NEW' . $stuTableSoleName . '_NOTIFY_DESC' => 'Global new' . $tableSoleName . ' notify desc', 'GLOBAL_NEW' . $stuTableSoleName . '_NOTIFY_SUBJECT' => 'Global new' . $tableSoleName . ' notify subject', 'CATEGORY_' . $stuTableSoleName . 'SUBMIT_NOTIFY' => 'Category ' . $tableSoleName . 'submit notify', 'CATEGORY_' . $stuTableSoleName . 'SUBMIT_NOTIFY_CAPTION' => 'Category ' . $tableSoleName . ' submit notify caption', 'CATEGORY_' . $stuTableSoleName . 'SUBMIT_NOTIFY_DESC' => 'Category ' . $tableSoleName . ' submit notify desc', 'CATEGORY_' . $stuTableSoleName . 'SUBMIT_NOTIFY_SUBJECT' => 'Category ' . $tableSoleName . ' submit notify subject', 'CATEGORY_NEW' . $stuTableSoleName . '_NOTIFY' => 'Category new' . $tableSoleName . ' notify', 'CATEGORY_NEW' . $stuTableSoleName . '_NOTIFY_CAPTION' => 'Category new' . $tableSoleName . ' notify caption', 'CATEGORY_NEW' . $stuTableSoleName . '_NOTIFY_DESC' => 'Category new' . $tableSoleName . ' notify desc', 'CATEGORY_NEW' . $stuTableSoleName . '_NOTIFY_SUBJECT' => 'Category new' . $tableSoleName . ' notify subject', $stuTableSoleName . '_APPROVE_NOTIFY' => $ucfTableSoleName . ' approve notify', $stuTableSoleName . '_APPROVE_NOTIFY_CAPTION' => $ucfTableSoleName . ' approve notify caption', $stuTableSoleName . '_APPROVE_NOTIFY_DESC' => $ucfTableSoleName . ' approve notify desc', $stuTableSoleName . '_APPROVE_NOTIFY_SUBJECT' => $ucfTableSoleName . ' approve notify subject',
307
        ];
308
        foreach ($getDefinesNotif as $defn => $descn) {
309
            $ret .= $df->getDefine($language, $defn, $descn);
310
        }
311
312
        return $ret;
313
    }
314
315
    /**
316
     *  @private function getLanguagePermissionsGroups
317
     *  @param $language
318
     *
319
     * @return string
320
     */
321
    private function getLanguagePermissionsGroups($language)
322
    {
323
        $df = LanguageDefines::getInstance();
324
        $ret = $df->getAboveDefines('Permissions Groups');
325
        $ret .= $df->getDefine($language, 'GROUPS', 'Groups access');
326
        $ret .= $df->getDefine($language, 'GROUPS_DESC', 'Select general access permission for groups.');
327
        $ret .= $df->getDefine($language, 'ADMIN_GROUPS', 'Admin Group Permissions');
328
        $ret .= $df->getDefine($language, 'ADMIN_GROUPS_DESC', 'Which groups have access to tools and permissions page');
329
330
        return $ret;
331
    }
332
333
    /**
334
     *  @private function getFooter
335
     *  @param null
336
     * @return string
337
     */
338
    private function getLanguageFooter()
339
    {
340
        $df = LanguageDefines::getInstance();
341
        $ret = $df->getBelowDefines('End');
342
343
        return $ret;
344
    }
345
346
    /**
347
     *  @public function render
348
     *  @param null
349
     * @return bool|string
350
     */
351
    public function render()
352
    {
353
        $module = $this->getModule();
354
        $table = $this->getTable();
0 ignored issues
show
Unused Code introduced by
The assignment to $table is dead and can be removed.
Loading history...
355
        $tables = $this->getTableTables($module->getVar('mod_id'));
356
        $tableAdmin = [];
357
        $tableUser = [];
358
        $tableSubmenu = [];
359
        $tableBlocks = [];
360
        $tableNotifications = [];
361
        $tablePermissions = [];
362
        foreach (array_keys($tables) as $t) {
363
            $tableSoleName = $tables[$t]->getVar('table_solename');
364
            $tableAdmin[] = $tables[$t]->getVar('table_admin');
365
            $tableUser[] = $tables[$t]->getVar('table_user');
366
            $tableSubmenu[] = $tables[$t]->getVar('table_submenu');
367
            $tableBlocks[] = $tables[$t]->getVar('table_blocks');
368
            $tableNotifications[] = $tables[$t]->getVar('table_notifications');
369
            $tablePermissions[] = $tables[$t]->getVar('table_permissions');
370
        }
371
        $filename = $this->getFileName();
372
        $moduleDirname = $module->getVar('mod_dirname');
373
        $language = $this->getLanguage($moduleDirname, 'MI');
374
        $content = $this->getHeaderFilesComments($module, $filename);
375
        $content .= $this->getLanguageMain($language, $module);
376
        $content .= $this->getLanguageMenu($module, $language);
377
        if (in_array(1, $tableAdmin)) {
378
            $content .= $this->getLanguageAdmin($language);
379
        }
380
        if (in_array(1, $tableUser)) {
381
            $content .= $this->getLanguageUser($language);
382
        }
383
        if (in_array(1, $tableSubmenu)) {
384
            $content .= $this->getLanguageSubmenu($language, $tables);
385
        }
386
        //if (in_array(1, $tableBlocks)) {
387
        $content .= $this->getLanguageBlocks($tables, $language);
388
        //}
389
        $content .= $this->getLanguageConfig($language, $tables);
390
        if (in_array(1, $tableNotifications)) {
391
            $content .= $this->getLanguageNotifications($language, $tableSoleName);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tableSoleName seems to be defined by a foreach iteration on line 362. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
392
        }
393
        if (in_array(1, $tablePermissions)) {
394
            $content .= $this->getLanguagePermissionsGroups($language);
395
        }
396
        $content .= $this->getLanguageFooter();
397
398
        $this->create($moduleDirname, 'language/' . $GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
399
400
        return $this->renderFile();
401
    }
402
}
403