Passed
Branch master (d5fa10)
by Gino
03:19
created

LanguageModinfo   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 389
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 39
c 3
b 2
f 0
lcom 2
cbo 2
dl 0
loc 389
rs 8.2857

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getInstance() 0 9 2
A write() 0 6 1
A getLanguageMain() 0 8 1
A getLanguageMenu() 0 22 3
A getLanguageAdmin() 0 8 1
A getLanguageSubmenu() 0 20 4
B getLanguageBlocks() 0 35 4
A getLanguageUser() 0 8 1
C getLanguageConfig() 0 47 9
A getLanguageNotifications() 0 11 2
A getLanguagePermissionsGroups() 0 10 1
A getLanguageFooter() 0 6 1
C render() 0 50 8
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: LanguageModinfo.php 12258 2014-01-02 09:33:29Z timgno $
23
 */
24
25
/**
26
 * Class LanguageModinfo.
27
 */
28
class LanguageModinfo 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 $df = null;
34
35
    /*
36
    *  @public function constructor
37
    *  @param null
38
    */
39
    /**
40
     *
41
     */
42
    public function __construct()
43
    {
44
        parent::__construct();
45
        $this->df = LanguageDefines::getInstance();
46
    }
47
48
    /*
49
    *  @static function &getInstance
50
    *  @param null
51
    */
52
    /**
53
     * @return LanguageModinfo
54
     */
55
    public static function &getInstance()
56
    {
57
        static $instance = false;
58
        if (!$instance) {
59
            $instance = new self();
60
        }
61
62
        return $instance;
63
    }
64
65
    /**
66
     *  @public function write    
67
     *
68
     * @param $module
69
     * @param $table
70
     * @param $filename
71
     *
72
     * @return string
73
     */
74
    public function write($module, $table, $filename)
75
    {
76
        $this->setModule($module);
77
        $this->setTable($table);
78
        $this->setFileName($filename);
79
    }
80
81
    /**
82
     * @private function getLanguageMain     
83
     *
84
     * @param $language
85
     * @param $module
86
     *
87
     * @return string
88
     */
89
    private function getLanguageMain($language, $module)
90
    {
91
        $ret = $this->df->getAboveHeadDefines('Admin Main');
92
        $ret .= $this->df->getDefine($language, 'NAME', "{$module->getVar('mod_name')}");
93
        $ret .= $this->df->getDefine($language, 'DESC', "{$module->getVar('mod_description')}");
94
95
        return $ret;
96
    }
97
98
    /**
99
     * @private function getLanguageMenu
100
     *
101
     * @param $module
102
     * @param $language     
103
     *
104
     * @return string
105
     */
106
    private function getLanguageMenu($module, $language)
107
    {
108
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
109
        $menu = 1;
110
        $ret = $this->df->getAboveHeadDefines('Admin Menu');
111
        $ret .= $this->df->getDefine($language, "ADMENU{$menu}", 'Dashboard');
112
        $tablePermissions = array();
113
        foreach (array_keys($tables) as $i) {
114
            ++$menu;
115
            $tablePermissions[] = $tables[$i]->getVar('table_permissions');
116
            $ucfTableName = ucfirst($tables[$i]->getVar('table_name'));
117
            $ret .= $this->df->getDefine($language, "ADMENU{$menu}", "{$ucfTableName}");
118
        }
119
        if (in_array(1, $tablePermissions)) {
120
            ++$menu;
121
            $ret .= $this->df->getDefine($language, "ADMENU{$menu}", 'Permissions');
122
        }
123
        $ret .= $this->df->getDefine($language, 'ABOUT', 'About');
124
        unset($menu, $tablePermissions);
125
126
        return $ret;
127
    }
128
129
    /*
130
    *  @private function getLanguageAdmin
131
    *  @param $language
132
    */
133
    /**
134
     * @param $language
135
     *
136
     * @return string
137
     */
138
    private function getLanguageAdmin($language)
139
    {
140
        $ret = $this->df->getAboveHeadDefines('Admin Nav');
141
        $ret .= $this->df->getDefine($language, 'ADMIN_PAGER', 'Admin pager');
142
        $ret .= $this->df->getDefine($language, 'ADMIN_PAGER_DESC', 'Admin per page list');
143
144
        return $ret;
145
    }
146
147
    /*
148
    *  @private function getLanguageSubmenu
149
    *  @param $language
150
    *  @param array $tables
151
    */
152
    /**
153
     * @param $language
154
     * @param $tables
155
     *
156
     * @return string
157
     */
158
    private function getLanguageSubmenu($language, $tables)
159
    {
160
        $ret = $this->df->getAboveDefines('Submenu');
161
        $i = 1;
162
        $tableSubmit = array();
163
        foreach (array_keys($tables) as $t) {
164
            $tableName = $tables[$t]->getVar('table_name');
165
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
166
            if (1 == $tables[$t]->getVar('table_submenu')) {
167
                $ret .= $this->df->getDefine($language, "SMNAME{$i}", "{$tableName}");
168
            }
169
            ++$i;
170
        }
171
        if (in_array(1, $tableSubmit)) {
172
            $ret .= $this->df->getDefine($language, "SMNAME{$i}", 'Submit');
173
        }
174
        unset($i, $tableSubmit);
175
176
        return $ret;
177
    }
178
179
    /*
180
    *  @private function getLanguageBlocks
181
    *  @param $language
182
    *  @param array $tables
183
    */
184
    /**
185
     * @param $language
186
     * @param $tables
187
     *
188
     * @return string
189
     */
190
    private function getLanguageBlocks($tables, $language)
191
    {
192
        $ret = $this->df->getAboveDefines('Blocks');
193
        foreach (array_keys($tables) as $i) {
194
            $tableName = $tables[$i]->getVar('table_name');
195
            $stuTableName = strtoupper($tableName);
196
            $tableSoleName = $tables[$i]->getVar('table_solename');
197
            $stuTableSoleName = strtoupper($tableSoleName);
198
            $ucfTableName = ucfirst($tableName);
199
            $ucfTableSoleName = ucfirst($stuTableSoleName);
200
            if (1 == $tables[$i]->getVar('table_blocks')) {
201
                $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK", "{$ucfTableName} block");
202
                $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_DESC", "{$ucfTableName} block description");
203
                if ($tables[$i]->getVar('table_category') == 1) {
204
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block {$ucfTableSoleName}");
205
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block {$ucfTableSoleName} description");
206
                } else {
207
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block  {$ucfTableSoleName}");
208
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block  {$ucfTableSoleName} description");
209
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_LAST", "{$ucfTableName} block last");
210
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_LAST_DESC", "{$ucfTableName} block last description");
211
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_NEW", "{$ucfTableName} block new");
212
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_NEW_DESC", "{$ucfTableName} block new description");
213
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_HITS", "{$ucfTableName} block hits");
214
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_HITS_DESC", "{$ucfTableName} block hits description");
215
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_TOP", "{$ucfTableName} block top");
216
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_TOP_DESC", "{$ucfTableName} block top description");
217
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM", "{$ucfTableName} block random");
218
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM_DESC", "{$ucfTableName} block random description");
219
                }
220
            }
221
        }
222
223
        return $ret;
224
    }
225
226
    /*
227
    *  @private function getLanguageUser
228
    *  @param $language
229
    */
230
    /**
231
     * @param $language
232
     *
233
     * @return string
234
     */
235
    private function getLanguageUser($language)
236
    {
237
        $ret = $this->df->getAboveDefines('User');
238
        $ret .= $this->df->getDefine($language, 'USER_PAGER', 'User pager');
239
        $ret .= $this->df->getDefine($language, 'USER_PAGER_DESC', 'User per page list');
240
241
        return $ret;
242
    }
243
244
    /*
245
    *  @private function getLanguageConfig
246
    *  @param $language
247
    *  @param $table
248
    */
249
    /**
250
     * @param $language
251
     * @param $table
252
     *
253
     * @return string
254
     */
255
    private function getLanguageConfig($language, $table)
256
    {
257
        $ret = $this->df->getAboveDefines('Config');
258
        if (is_object($table) && $table->getVar('table_image') != '') {
259
            $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
260
            $fieldElement = array();
261
            foreach (array_keys($fields) as $f) {
262
                $fieldElement[] = $fields[$f]->getVar('field_element');
263
                if (in_array(4, $fieldElement)) {
264
                    $fieldName = $fields[$f]->getVar('field_name');
265
                    $rpFieldName = $this->getRightString($fieldName);
266
                    $ucfFieldName = ucfirst($rpFieldName);
267
                    $stuFieldName = strtoupper($rpFieldName);
268
                    $ret .= $this->df->getDefine($language, 'EDITOR_'.$stuFieldName, 'Editor');
269
                    $ret .= $this->df->getDefine($language, 'EDITOR_'.$stuFieldName.'_DESC', 'Select the Editor '.$ucfFieldName.' to use');
270
                }
271
            }
272
            unset($fieldElement);
273
        }
274
        $ret .= $this->df->getDefine($language, 'KEYWORDS', 'Keywords');
275
        $ret .= $this->df->getDefine($language, 'KEYWORDS_DESC', 'Insert here the keywords (separate by comma)');
276
        if (is_object($table)) {
277
            /*if ($table->getVar('table_permissions') != 0) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
278
                $ret .= $this->df->getDefine($language, "GROUPS", "Groups");
279
                $ret .= $this->df->getDefine($language, "GROUPS_DESC", "Groups to have permissions");
280
                $ret .= $this->df->getDefine($language, "ADMIN_GROUPS", "Admin Groups");
281
                $ret .= $this->df->getDefine($language, "ADMIN_GROUPS_DESC", "Admin Groups to have permissions access");
282
            }*/
283
            if ($table->getVar('table_image') != '') {
284
                $ret .= $this->df->getDefine($language, 'MAXSIZE', 'Max size');
285
                $ret .= $this->df->getDefine($language, 'MAXSIZE_DESC', 'Set a number of max size uploads file in byte');
286
                $ret .= $this->df->getDefine($language, 'MIMETYPES', 'Mime Types');
287
                $ret .= $this->df->getDefine($language, 'MIMETYPES_DESC', 'Set the mime types selected');
288
            }
289
            if ($table->getVar('table_tag') != 0) {
290
                $ret .= $this->df->getDefine($language, 'USE_TAG', 'Use TAG');
291
                $ret .= $this->df->getDefine($language, 'USE_TAG_DESC', 'If you use tag module, check this option to yes');
292
            }
293
        }
294
        $getDefinesConf = array('NUMB_COL' => 'Number Columns', 'NUMB_COL_DESC' => 'Number Columns to View.', 'DIVIDEBY' => 'Divide By', 'DIVIDEBY_DESC' => 'Divide by columns number.',
295
                                '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', );
296
        foreach ($getDefinesConf as $defc => $descc) {
297
            $ret .= $this->df->getDefine($language, $defc, $descc);
298
        }
299
300
        return $ret;
301
    }
302
303
    /*
304
    *  @private function getLanguageNotifications
305
    *  @param $language
306
    *  @param mixed $table
307
    */
308
    /**
309
     * @param $language
310
     *
311
     * @return string
312
     */
313
    private function getLanguageNotifications($language)
314
    {
315
        $ret = $this->df->getAboveDefines('Notifications');
316
        $getDefinesNotif = array('GLOBAL_NOTIFY' => 'Global notify', 'GLOBAL_NOTIFY_DESC' => 'Global notify desc', 'CATEGORY_NOTIFY' => 'Category notify',
317
                                'CATEGORY_NOTIFY_DESC' => 'Category notify desc', 'FILE_NOTIFY' => 'File notify', 'FILE_NOTIFY_DESC' => 'File 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_FILEMODIFY_NOTIFY' => 'Global filemodify notify', 'GLOBAL_FILEMODIFY_NOTIFY_CAPTION' => 'Global filemodify notify caption', 'GLOBAL_FILEMODIFY_NOTIFY_DESC' => 'Global filemodify notify desc', 'GLOBAL_FILEMODIFY_NOTIFY_SUBJECT' => 'Global filemodify notify subject', 'GLOBAL_FILEBROKEN_NOTIFY' => 'Global filebroken notify', 'GLOBAL_FILEBROKEN_NOTIFY_CAPTION' => 'Global filebroken notify caption', 'GLOBAL_FILEBROKEN_NOTIFY_DESC' => 'Global filebroken notify desc', 'GLOBAL_FILEBROKEN_NOTIFY_SUBJECT' => 'Global filebroken notify subject', 'GLOBAL_FILESUBMIT_NOTIFY' => 'Global filesubmit notify', 'GLOBAL_FILESUBMIT_NOTIFY_CAPTION' => 'Global filesubmit notify caption', 'GLOBAL_FILESUBMIT_NOTIFY_DESC' => 'Global filesubmit notify desc', 'GLOBAL_FILESUBMIT_NOTIFY_SUBJECT' => 'Global filesubmit notify subject', 'GLOBAL_NEWFILE_NOTIFY' => 'Global newfile notify', 'GLOBAL_NEWFILE_NOTIFY_CAPTION' => 'Global newfile notify caption', 'GLOBAL_NEWFILE_NOTIFY_DESC' => 'Global newfile notify desc', 'GLOBAL_NEWFILE_NOTIFY_SUBJECT' => 'Global newfile notify subject', 'CATEGORY_FILESUBMIT_NOTIFY' => 'Category filesubmit notify', 'CATEGORY_FILESUBMIT_NOTIFY_CAPTION' => 'Category filesubmit notify caption', 'CATEGORY_FILESUBMIT_NOTIFY_DESC' => 'Category filesubmit notify desc', 'CATEGORY_FILESUBMIT_NOTIFY_SUBJECT' => 'Category filesubmit notify subject', 'CATEGORY_NEWFILE_NOTIFY' => 'Category newfile notify', 'CATEGORY_NEWFILE_NOTIFY_CAPTION' => 'Category newfile notify caption', 'CATEGORY_NEWFILE_NOTIFY_DESC' => 'Category newfile notify desc', 'CATEGORY_NEWFILE_NOTIFY_SUBJECT' => 'Category newfile notify subject', 'FILE_APPROVE_NOTIFY' => 'File approve notify', 'FILE_APPROVE_NOTIFY_CAPTION' => 'File approve notify caption', 'FILE_APPROVE_NOTIFY_DESC' => 'File approve notify desc', 'FILE_APPROVE_NOTIFY_SUBJECT' => 'File approve notify subject', );
318
        foreach ($getDefinesNotif as $defn => $descn) {
319
            $ret .= $this->df->getDefine($language, $defn, $descn);
320
        }
321
322
        return $ret;
323
    }
324
325
    /*
326
    *  @private function getLanguagePermissionsGroups
327
    *  @param $language
328
    */
329
    /**
330
     * @param $language
331
     *
332
     * @return string
333
     */
334
    private function getLanguagePermissionsGroups($language)
335
    {
336
        $ret = $this->df->getAboveDefines('Permissions Groups');
337
        $ret .= $this->df->getDefine($language, 'GROUPS', 'Groups access');
338
        $ret .= $this->df->getDefine($language, 'GROUPS_DESC', 'Select general access permission for groups.');
339
        $ret .= $this->df->getDefine($language, 'ADMIN_GROUPS', 'Admin Group Permissions');
340
        $ret .= $this->df->getDefine($language, 'ADMIN_GROUPS_DESC', 'Which groups have access to tools and permissions page');
341
342
        return $ret;
343
    }
344
345
    /*
346
    *  @private function getFooter
347
    *  @param null
348
    */
349
    /**
350
     * @return string
351
     */
352
    private function getLanguageFooter()
353
    {
354
        $ret = $this->df->getBelowDefines('End');
355
356
        return $ret;
357
    }
358
359
    /*
360
    *  @public function render
361
    *  @param null
362
    */
363
    /**
364
     * @return bool|string
365
     */
366
    public function render()
367
    {
368
        $module = $this->getModule();
369
        $table = $this->getTable();
370
		$tables = $this->getTableTables($module->getVar('mod_id'));
371
        $tableAdmin = array();
372
		$tableUser = array();
373
		$tableSubmenu = array();
374
		$tableBlocks = array();
375
		$tableNotifications = array();
376
		$tablePermissions = array();
377
		foreach (array_keys($tables) as $t) {
378
            $tableAdmin[] = $tables[$t]->getVar('table_admin');
379
			$tableUser[] = $tables[$t]->getVar('table_user');
380
			$tableSubmenu[] = $tables[$t]->getVar('table_submenu');
381
			$tableBlocks[] = $tables[$t]->getVar('table_blocks');
382
			$tableNotifications[] = $tables[$t]->getVar('table_notifications');
383
			$tablePermissions[] = $tables[$t]->getVar('table_permissions');
384
        }
385
        $filename = $this->getFileName();
386
        $moduleDirname = $module->getVar('mod_dirname');
387
        $language = $this->getLanguage($moduleDirname, 'MI');
388
        $content = $this->getHeaderFilesComments($module, $filename);
389
        $content .= $this->getLanguageMain($language, $module);
390
        $content .= $this->getLanguageMenu($module, $language);
391
        if (in_array(1, $tableAdmin)) {
392
            $content .= $this->getLanguageAdmin($language);
393
        }
394
        if (in_array(1, $tableUser)) {
395
            $content .= $this->getLanguageUser($language);
396
        }
397
        if (in_array(1, $tableSubmenu)) {
398
            $content .= $this->getLanguageSubmenu($language, $tables);
399
        }
400
        if (in_array(1, $tableBlocks)) {
401
            $content .= $this->getLanguageBlocks($tables, $language);
402
        }
403
        $content .= $this->getLanguageConfig($language, $table);
404
        if (in_array(1, $tableNotifications)) {
405
            $content .= $this->getLanguageNotifications($language);
406
        }
407
        if (in_array(1, $tablePermissions)) {
408
            $content .= $this->getLanguagePermissionsGroups($language);
409
        }
410
        $content .= $this->getLanguageFooter();
411
        //
412
        $this->create($moduleDirname, 'language/'.$GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
413
414
        return $this->renderFile();
415
    }
416
}
417