Completed
Push — master ( f541a6...b68755 )
by Gino
06:36 queued 03:15
created

LanguageModinfo::getLanguageConfig()   C

Complexity

Conditions 9
Paths 20

Size

Total Lines 47
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 47
rs 5.2941
cc 9
eloc 31
nc 20
nop 2
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 $tables	 
71
     * @param $filename
72
     *
73
     * @return string
74
     */
75
    public function write($module, $table, $tables, $filename)
76
    {
77
        $this->setModule($module);
78
        $this->setTable($table);
79
        $this->setTables($tables);
80
        $this->setFileName($filename);
81
    }
82
83
    /**
84
     * @private function getLanguageMain     
85
     *
86
     * @param $language
87
     * @param $module
88
     *
89
     * @return string
90
     */
91
    private function getLanguageMain($language, $module)
92
    {
93
        $ret = $this->df->getAboveHeadDefines('Admin Main');
94
        $ret .= $this->df->getDefine($language, 'NAME', "{$module->getVar('mod_name')}");
95
        $ret .= $this->df->getDefine($language, 'DESC', "{$module->getVar('mod_description')}");
96
97
        return $ret;
98
    }
99
100
    /**
101
     * @private function getLanguageMenu
102
     *
103
     * @param $module
104
     * @param $language     
105
     *
106
     * @return string
107
     */
108
    private function getLanguageMenu($module, $language)
109
    {
110
        $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order');
111
        $menu = 1;
112
        $ret = $this->df->getAboveHeadDefines('Admin Menu');
113
        $ret .= $this->df->getDefine($language, "ADMENU{$menu}", 'Dashboard');
114
        $tablePermissions = array();
115
        foreach (array_keys($tables) as $i) {
116
            ++$menu;
117
            $tablePermissions[] = $tables[$i]->getVar('table_permissions');
118
            $ucfTableName = ucfirst($tables[$i]->getVar('table_name'));
119
            $ret .= $this->df->getDefine($language, "ADMENU{$menu}", "{$ucfTableName}");
120
        }
121
        if (in_array(1, $tablePermissions)) {
122
            ++$menu;
123
            $ret .= $this->df->getDefine($language, "ADMENU{$menu}", 'Permissions');
124
        }
125
        $ret .= $this->df->getDefine($language, 'ABOUT', 'About');
126
        unset($menu, $tablePermissions);
127
128
        return $ret;
129
    }
130
131
    /*
132
    *  @private function getLanguageAdmin
133
    *  @param $language
134
    */
135
    /**
136
     * @param $language
137
     *
138
     * @return string
139
     */
140
    private function getLanguageAdmin($language)
141
    {
142
        $ret = $this->df->getAboveHeadDefines('Admin Nav');
143
        $ret .= $this->df->getDefine($language, 'ADMIN_PAGER', 'Admin pager');
144
        $ret .= $this->df->getDefine($language, 'ADMIN_PAGER_DESC', 'Admin per page list');
145
146
        return $ret;
147
    }
148
149
    /*
150
    *  @private function getLanguageSubmenu
151
    *  @param $language
152
    *  @param array $tables
153
    */
154
    /**
155
     * @param $language
156
     * @param $tables
157
     *
158
     * @return string
159
     */
160
    private function getLanguageSubmenu($language, $tables)
161
    {
162
        $ret = $this->df->getAboveDefines('Submenu');
163
        $i = 1;
164
        $tableSubmit = array();
165
        foreach (array_keys($tables) as $t) {
166
            $tableName = $tables[$t]->getVar('table_name');
167
            $tableSubmit[] = $tables[$t]->getVar('table_submit');
168
            if (1 == $tables[$t]->getVar('table_submenu')) {
169
                $ret .= $this->df->getDefine($language, "SMNAME{$i}", "{$tableName}");
170
            }
171
            ++$i;
172
        }
173
        if (in_array(1, $tableSubmit)) {
174
            $ret .= $this->df->getDefine($language, "SMNAME{$i}", 'Submit');
175
        }
176
        unset($i, $tableSubmit);
177
178
        return $ret;
179
    }
180
181
    /*
182
    *  @private function getLanguageBlocks
183
    *  @param $language
184
    *  @param array $tables
185
    */
186
    /**
187
     * @param $language
188
     * @param $tables
189
     *
190
     * @return string
191
     */
192
    private function getLanguageBlocks($tables, $language)
193
    {
194
        $ret = $this->df->getAboveDefines('Blocks');
195
        foreach (array_keys($tables) as $i) {
196
            $tableName = $tables[$i]->getVar('table_name');
197
            $stuTableName = strtoupper($tableName);
198
            $tableSoleName = $tables[$i]->getVar('table_solename');
199
            $stuTableSoleName = strtoupper($tableSoleName);
200
            $ucfTableName = ucfirst($tableName);
201
            $ucfTableSoleName = ucfirst($stuTableSoleName);
202
            if (1 == $tables[$i]->getVar('table_blocks')) {
203
                $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK", "{$ucfTableName} block");
204
                $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_DESC", "{$ucfTableName} block description");
205
                if ($tables[$i]->getVar('table_category') == 1) {
206
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block {$ucfTableSoleName}");
207
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block {$ucfTableSoleName} description");
208
                } else {
209
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}", "{$ucfTableName} block  {$ucfTableSoleName}");
210
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", "{$ucfTableName} block  {$ucfTableSoleName} description");
211
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_LAST", "{$ucfTableName} block last");
212
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_LAST_DESC", "{$ucfTableName} block last description");
213
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_NEW", "{$ucfTableName} block new");
214
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_NEW_DESC", "{$ucfTableName} block new description");
215
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_HITS", "{$ucfTableName} block hits");
216
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_HITS_DESC", "{$ucfTableName} block hits description");
217
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_TOP", "{$ucfTableName} block top");
218
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_TOP_DESC", "{$ucfTableName} block top description");
219
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM", "{$ucfTableName} block random");
220
                    $ret .= $this->df->getDefine($language, "{$stuTableName}_BLOCK_RANDOM_DESC", "{$ucfTableName} block random description");
221
                }
222
            }
223
        }
224
225
        return $ret;
226
    }
227
228
    /*
229
    *  @private function getLanguageUser
230
    *  @param $language
231
    */
232
    /**
233
     * @param $language
234
     *
235
     * @return string
236
     */
237
    private function getLanguageUser($language)
238
    {
239
        $ret = $this->df->getAboveDefines('User');
240
        $ret .= $this->df->getDefine($language, 'USER_PAGER', 'User pager');
241
        $ret .= $this->df->getDefine($language, 'USER_PAGER_DESC', 'User per page list');
242
243
        return $ret;
244
    }
245
246
    /*
247
    *  @private function getLanguageConfig
248
    *  @param $language
249
    *  @param $table
250
    */
251
    /**
252
     * @param $language
253
     * @param $table
254
     *
255
     * @return string
256
     */
257
    private function getLanguageConfig($language, $table)
258
    {
259
        $ret = $this->df->getAboveDefines('Config');
260
        if (is_object($table) && $table->getVar('table_image') != '') {
261
            $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id'));
262
            $fieldElement = array();
263
            foreach (array_keys($fields) as $f) {
264
                $fieldElement[] = $fields[$f]->getVar('field_element');
265
                if (in_array(4, $fieldElement)) {
266
                    $fieldName = $fields[$f]->getVar('field_name');
267
                    $rpFieldName = $this->getRightString($fieldName);
268
                    $ucfFieldName = ucfirst($rpFieldName);
269
                    $stuFieldName = strtoupper($rpFieldName);
270
                    $ret .= $this->df->getDefine($language, 'EDITOR_'.$stuFieldName, 'Editor');
271
                    $ret .= $this->df->getDefine($language, 'EDITOR_'.$stuFieldName.'_DESC', 'Select the Editor '.$ucfFieldName.' to use');
272
                }
273
            }
274
            unset($fieldElement);
275
        }
276
        $ret .= $this->df->getDefine($language, 'KEYWORDS', 'Keywords');
277
        $ret .= $this->df->getDefine($language, 'KEYWORDS_DESC', 'Insert here the keywords (separate by comma)');
278
        if (is_object($table)) {
279
            /*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...
280
                $ret .= $this->df->getDefine($language, "GROUPS", "Groups");
281
                $ret .= $this->df->getDefine($language, "GROUPS_DESC", "Groups to have permissions");
282
                $ret .= $this->df->getDefine($language, "ADMIN_GROUPS", "Admin Groups");
283
                $ret .= $this->df->getDefine($language, "ADMIN_GROUPS_DESC", "Admin Groups to have permissions access");
284
            }*/
285
            if ($table->getVar('table_image') != '') {
286
                $ret .= $this->df->getDefine($language, 'MAXSIZE', 'Max size');
287
                $ret .= $this->df->getDefine($language, 'MAXSIZE_DESC', 'Set a number of max size uploads file in byte');
288
                $ret .= $this->df->getDefine($language, 'MIMETYPES', 'Mime Types');
289
                $ret .= $this->df->getDefine($language, 'MIMETYPES_DESC', 'Set the mime types selected');
290
            }
291
            if ($table->getVar('table_tag') != 0) {
292
                $ret .= $this->df->getDefine($language, 'USE_TAG', 'Use TAG');
293
                $ret .= $this->df->getDefine($language, 'USE_TAG_DESC', 'If you use tag module, check this option to yes');
294
            }
295
        }
296
        $getDefinesConf = array('NUMB_COL' => 'Number Columns', 'NUMB_COL_DESC' => 'Number Columns to View.', 'DIVIDEBY' => 'Divide By', 'DIVIDEBY_DESC' => 'Divide by columns number.',
297
                                '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', );
298
        foreach ($getDefinesConf as $defc => $descc) {
299
            $ret .= $this->df->getDefine($language, $defc, $descc);
300
        }
301
302
        return $ret;
303
    }
304
305
    /*
306
    *  @private function getLanguageNotifications
307
    *  @param $language
308
    *  @param mixed $table
309
    */
310
    /**
311
     * @param $language
312
     *
313
     * @return string
314
     */
315
    private function getLanguageNotifications($language)
316
    {
317
        $ret = $this->df->getAboveDefines('Notifications');
318
        $getDefinesNotif = array('GLOBAL_NOTIFY' => 'Global notify', 'GLOBAL_NOTIFY_DESC' => 'Global notify desc', 'CATEGORY_NOTIFY' => 'Category notify',
319
                                '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', );
320
        foreach ($getDefinesNotif as $defn => $descn) {
321
            $ret .= $this->df->getDefine($language, $defn, $descn);
322
        }
323
324
        return $ret;
325
    }
326
327
    /*
328
    *  @private function getLanguagePermissionsGroups
329
    *  @param $language
330
    */
331
    /**
332
     * @param $language
333
     *
334
     * @return string
335
     */
336
    private function getLanguagePermissionsGroups($language)
337
    {
338
        $ret = $this->df->getAboveDefines('Permissions Groups');
339
        $ret .= $this->df->getDefine($language, 'GROUPS', 'Groups access');
340
        $ret .= $this->df->getDefine($language, 'GROUPS_DESC', 'Select general access permission for groups.');
341
        $ret .= $this->df->getDefine($language, 'ADMIN_GROUPS', 'Admin Group Permissions');
342
        $ret .= $this->df->getDefine($language, 'ADMIN_GROUPS_DESC', 'Which groups have access to tools and permissions page');
343
344
        return $ret;
345
    }
346
347
    /*
348
    *  @private function getFooter
349
    *  @param null
350
    */
351
    /**
352
     * @return string
353
     */
354
    private function getLanguageFooter()
355
    {
356
        $ret = $this->df->getBelowDefines('End');
357
358
        return $ret;
359
    }
360
361
    /*
362
    *  @public function render
363
    *  @param null
364
    */
365
    /**
366
     * @return bool|string
367
     */
368
    public function render()
369
    {
370
        $module = $this->getModule();
371
        $table = $this->getTable();
372
        $tables = $this->getTables();
373
        $filename = $this->getFileName();
374
        $moduleDirname = $module->getVar('mod_dirname');
375
        $language = $this->getLanguage($moduleDirname, 'MI');
376
        $content = $this->getHeaderFilesComments($module, $filename);
377
        $content .= $this->getLanguageMain($language, $module);
378
        $content .= $this->getLanguageMenu($module, $language);
379
        if (1 == $table->getVar('table_admin')) {
380
            $content .= $this->getLanguageAdmin($language);
381
        }
382
        if (1 == $table->getVar('table_user')) {
383
            $content .= $this->getLanguageUser($language);
384
        }
385
        //if (1 == $table->getVar('table_submenu')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
386
            $content .= $this->getLanguageSubmenu($language, $tables);
387
        //}
388
        if (1 == $table->getVar('table_blocks')) {
389
            $content .= $this->getLanguageBlocks($tables, $language);
390
        }
391
        $content .= $this->getLanguageConfig($language, $table);
392
        if (1 == $table->getVar('table_notifications')) {
393
            $content .= $this->getLanguageNotifications($language);
394
        }
395
        if (1 == $table->getVar('table_permissions')) {
396
            $content .= $this->getLanguagePermissionsGroups($language);
397
        }
398
        $content .= $this->getLanguageFooter();
399
        //
400
        $this->create($moduleDirname, 'language/'.$GLOBALS['xoopsConfig']['language'], $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED);
401
402
        return $this->renderFile();
403
    }
404
}
405