Completed
Pull Request — master (#144)
by Michael
04:31
created

Modules   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 428
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 274
dl 0
loc 428
rs 5.04
c 1
b 0
f 0
wmc 57

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 45 1
A getValuesModules() 0 19 1
A getOptionsModules() 0 10 3
A getDefinedLanguage() 0 7 2
A __call() 0 5 2
A getInstance() 0 8 2
B createLogo() 0 31 7
F getFormModules() 0 224 39

How to fix   Complexity   

Complex Class

Complex classes like Modules often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Modules, and based on these observations, apply Extract Interface, too.

1
<?php namespace XoopsModules\Tdmcreate;
2
3
use XoopsModules\Tdmcreate;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * modules class.
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.7
22
 *
23
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
24
 *
25
 * @version         $Id: 1.91 modules.php 13040 2015-04-25 15:12:12Z timgno $
26
 */
27
// include __DIR__ . '/autoload.php';
28
29
/**
30
 * Class Modules.
31
 */
32
class Modules extends \XoopsObject
33
{
34
    /**
35
     * Options.
36
     */
37
    public $options = [
38
        'admin',
39
        'user',
40
        'blocks',
41
        'search',
42
        'comments',
43
        'notifications',
44
        'permissions',
45
        'inroot_copy',
46
    ];
47
48
    /**
49
     *  @public function constructor class
50
     *  @param null
51
     */
52
    public function __construct()
53
    {
54
        $helper = Tdmcreate\Helper::getInstance();
55
        $setId = \Xmf\Request::getInt('set_id');
56
        $settings = $helper->getHandler('Settings')->get($setId);
57
58
        $this->initVar('mod_id', XOBJ_DTYPE_INT);
59
        $this->initVar('mod_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_name'));
60
        $this->initVar('mod_dirname', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_dirname'));
61
        $this->initVar('mod_version', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_version'));
62
        $this->initVar('mod_since', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_since'));
63
        $this->initVar('mod_min_php', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_php'));
64
        $this->initVar('mod_min_xoops', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_xoops'));
65
        $this->initVar('mod_min_admin', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_admin'));
66
        $this->initVar('mod_min_mysql', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_mysql'));
67
        $this->initVar('mod_description', XOBJ_DTYPE_TXTAREA, $settings->getVar('set_description'));
68
        $this->initVar('mod_author', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author'));
69
        $this->initVar('mod_author_mail', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_mail'));
70
        $this->initVar('mod_author_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_url'));
71
        $this->initVar('mod_author_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_name'));
72
        $this->initVar('mod_credits', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_credits'));
73
        $this->initVar('mod_license', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_license'));
74
        $this->initVar('mod_release_info', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_info'));
75
        $this->initVar('mod_release_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_file'));
76
        $this->initVar('mod_manual', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual'));
77
        $this->initVar('mod_manual_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual_file'));
78
        $this->initVar('mod_image', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_image'));
79
        $this->initVar('mod_demo_site_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_url'));
80
        $this->initVar('mod_demo_site_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_name'));
81
        $this->initVar('mod_support_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_url'));
82
        $this->initVar('mod_support_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_name'));
83
        $this->initVar('mod_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_url'));
84
        $this->initVar('mod_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_name'));
85
        $this->initVar('mod_release', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release'));
86
        $this->initVar('mod_status', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_status'));
87
        $this->initVar('mod_admin', XOBJ_DTYPE_INT, $settings->getVar('set_admin'));
88
        $this->initVar('mod_user', XOBJ_DTYPE_INT, $settings->getVar('set_user'));
89
        $this->initVar('mod_blocks', XOBJ_DTYPE_INT, $settings->getVar('set_blocks'));
90
        $this->initVar('mod_search', XOBJ_DTYPE_INT, $settings->getVar('set_search'));
91
        $this->initVar('mod_comments', XOBJ_DTYPE_INT, $settings->getVar('set_comments'));
92
        $this->initVar('mod_notifications', XOBJ_DTYPE_INT, $settings->getVar('set_notifications'));
93
        $this->initVar('mod_permissions', XOBJ_DTYPE_INT, $settings->getVar('set_permissions'));
94
        $this->initVar('mod_inroot_copy', XOBJ_DTYPE_INT, $settings->getVar('set_inroot_copy'));
95
        $this->initVar('mod_donations', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_donations'));
96
        $this->initVar('mod_subversion', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_subversion'));
97
    }
98
99
    /**
100
     * @param string $method
101
     * @param array  $args
102
     *
103
     * @return mixed
104
     */
105
    public function __call($method, $args)
106
    {
107
        $arg = isset($args[0]) ? $args[0] : null;
108
109
        return $this->getVar($method, $arg);
110
    }
111
112
    /**
113
     *  @static function getInstance
114
     *  @param null
115
     * @return Modules
116
     */
117
    public static function getInstance()
118
    {
119
        static $instance = false;
120
        if (!$instance) {
121
            $instance = new self();
122
        }
123
124
        return $instance;
125
    }
126
127
    /**
128
     *  @public function getFormModules
129
     *  @param mixed $action
130
     *
131
     * @return \XoopsThemeForm
132
     */
133
    public function getFormModules($action = false)
134
    {
135
        $helper = Tdmcreate\Helper::getInstance();
136
        if (false === $action) {
137
            $action = $_SERVER['REQUEST_URI'];
138
        }
139
        $set = [];
140
        $settings = $helper->getHandler('Settings')->getAllSettings(0, 0, 'set_type');
0 ignored issues
show
Bug introduced by
The method getAllSettings() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

140
        $settings = $helper->getHandler('Settings')->/** @scrutinizer ignore-call */ getAllSettings(0, 0, 'set_type');
Loading history...
141
        foreach ($settings as $setting) {
142
            $set['name'] = $setting->getVar('set_name');
143
            $set['dirname'] = $setting->getVar('set_dirname');
144
            $set['version'] = $setting->getVar('set_version');
145
            $set['since'] = $setting->getVar('set_since');
146
            $set['min_php'] = $setting->getVar('set_min_php');
147
            $set['min_xoops'] = $setting->getVar('set_min_xoops');
148
            $set['min_admin'] = $setting->getVar('set_min_admin');
149
            $set['min_mysql'] = $setting->getVar('set_min_mysql');
150
            $set['description'] = $setting->getVar('set_description');
151
            $set['author'] = $setting->getVar('set_author');
152
            $set['license'] = $setting->getVar('set_license');
153
            $set['admin'] = $setting->getVar('set_admin');
154
            $set['user'] = $setting->getVar('set_user');
155
            $set['blocks'] = $setting->getVar('set_blocks');
156
            $set['search'] = $setting->getVar('set_search');
157
            $set['comments'] = $setting->getVar('set_comments');
158
            $set['notifications'] = $setting->getVar('set_notifications');
159
            $set['permissions'] = $setting->getVar('set_permissions');
160
            $set['inroot'] = $setting->getVar('set_inroot_copy');
161
            $set['image'] = $setting->getVar('set_image');
162
            $set['author_mail'] = $setting->getVar('set_author_mail');
163
            $set['author_website_url'] = $setting->getVar('set_author_website_url');
164
            $set['author_website_name'] = $setting->getVar('set_author_website_name');
165
            $set['credits'] = $setting->getVar('set_credits');
166
            $set['release_info'] = $setting->getVar('set_release_info');
167
            $set['release_file'] = $setting->getVar('set_release_file');
168
            $set['manual'] = $setting->getVar('set_manual');
169
            $set['manual_file'] = $setting->getVar('set_manual_file');
170
            $set['demo_site_url'] = $setting->getVar('set_demo_site_url');
171
            $set['demo_site_name'] = $setting->getVar('set_demo_site_name');
172
            $set['support_url'] = $setting->getVar('set_support_url');
173
            $set['support_name'] = $setting->getVar('set_support_name');
174
            $set['website_url'] = $setting->getVar('set_website_url');
175
            $set['website_name'] = $setting->getVar('set_website_name');
176
            $set['release'] = $setting->getVar('set_release');
177
            $set['status'] = $setting->getVar('set_status');
178
            $set['donations'] = $setting->getVar('set_donations');
179
            $set['subversion'] = $setting->getVar('set_subversion');
180
        }
181
182
        $isNew = $this->isNew();
183
        $title = $isNew ? sprintf(_AM_TDMCREATE_MODULE_NEW) : sprintf(_AM_TDMCREATE_MODULE_EDIT);
184
185
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
186
187
        $form = new \XoopsThemeForm($title, 'moduleform', $action, 'post', true);
188
        $form->setExtra('enctype="multipart/form-data"');
189
190
        $modName = $isNew ? $set['name'] : $this->getVar('mod_name');
191
        $modName = new \XoopsFormText(_AM_TDMCREATE_MODULE_NAME, 'mod_name', 50, 255, $modName);
0 ignored issues
show
Bug introduced by
It seems like $modName can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

191
        $modName = new \XoopsFormText(_AM_TDMCREATE_MODULE_NAME, 'mod_name', 50, 255, /** @scrutinizer ignore-type */ $modName);
Loading history...
192
        $modName->setDescription(_AM_TDMCREATE_MODULE_NAME_DESC);
193
        $form->addElement($modName, true);
194
195
        $modDirname = $isNew ? $set['dirname'] : $this->getVar('mod_dirname');
196
        $modDirname = new \XoopsFormText(_AM_TDMCREATE_MODULE_DIRNAME, 'mod_dirname', 25, 255, $modDirname);
197
        $modDirname->setDescription(_AM_TDMCREATE_MODULE_DIRNAME_DESC);
198
        $form->addElement($modDirname, true);
199
200
        $modVersion = $isNew ? $set['version'] : $this->getVar('mod_version');
201
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_VERSION, 'mod_version', 10, 25, $modVersion), true);
202
203
        $modSince = $isNew ? $set['since'] : $this->getVar('mod_since');
204
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_SINCE, 'mod_since', 10, 25, $modSince), true);
205
206
        $modMinPhp = $isNew ? $set['min_php'] : $this->getVar('mod_min_php');
207
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MIN_PHP, 'mod_min_php', 10, 25, $modMinPhp), true);
208
209
        $modMinXoops = $isNew ? $set['min_xoops'] : $this->getVar('mod_min_xoops');
210
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MIN_XOOPS, 'mod_min_xoops', 10, 25, $modMinXoops), true);
211
212
        $modMinAdmin = $isNew ? $set['min_admin'] : $this->getVar('mod_min_admin');
213
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MIN_ADMIN, 'mod_min_admin', 10, 25, $modMinAdmin), true);
214
215
        $modMinMysql = $isNew ? $set['min_mysql'] : $this->getVar('mod_min_mysql');
216
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MIN_MYSQL, 'mod_min_mysql', 10, 25, $modMinMysql), true);
217
        // Name description
218
        $editorConfigs = [];
219
        $editorConfigs['name'] = 'mod_description';
220
        $editorConfigs['value'] = $isNew ? $set['description'] : $this->getVar('mod_description', 'e');
221
        $editorConfigs['rows'] = 5;
222
        $editorConfigs['cols'] = 100;
223
        $editorConfigs['width'] = '50%';
224
        $editorConfigs['height'] = '100px';
225
        $editorConfigs['editor'] = $helper->getConfig('tdmcreate_editor');
226
        $form->addElement(new \XoopsFormEditor(_AM_TDMCREATE_MODULE_DESCRIPTION, 'mod_description', $editorConfigs), true);
227
        // Author
228
        $modAuthor = $isNew ? $set['author'] : $this->getVar('mod_author');
229
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR, 'mod_author', 50, 255, $modAuthor), true);
230
        $modLicense = $isNew ? $set['license'] : $this->getVar('mod_license');
231
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_LICENSE, 'mod_license', 50, 255, $modLicense), true);
232
233
        $optionsTray = new \XoopsFormElementTray(_OPTIONS, '<br>');
234
        $optionsTray->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
235
        // Check All Modules Options
236
        $checkAllOptions = new \XoopsFormCheckBox('', 'modulebox', 1);
237
        $checkAllOptions->addOption('allbox', _AM_TDMCREATE_MODULE_ALL);
238
        $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'moduleform\', \'modulebox\');" ');
239
        $checkAllOptions->setClass('xo-checkall');
240
        $optionsTray->addElement($checkAllOptions);
241
        // Options
242
        $checkbox = new \XoopsFormCheckbox(' ', 'module_option', $this->getOptionsModules(), '<br>');
243
        foreach ($this->options as $option) {
244
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_MODULE_' . mb_strtoupper($option)));
245
        }
246
        $optionsTray->addElement($checkbox);
247
248
        $form->addElement($optionsTray);
249
250
        $modImage = $this->getVar('mod_image');
251
        $modImage = $modImage ?: $set['image'];
252
253
        $uploadDirectory = 'uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/modules';
254
        $imgtray = new \XoopsFormElementTray(_AM_TDMCREATE_MODULE_IMAGE, '<br>');
255
        $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './' . mb_strtolower($uploadDirectory) . '/');
256
        $imageselect = new \XoopsFormSelect($imgpath, 'mod_image', $modImage);
257
        $modImageArray = \XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH);
258
        foreach ($modImageArray as $image) {
259
            $imageselect->addOption($image, $image);
260
        }
261
        $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"mod_image\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")'");
262
        $imgtray->addElement($imageselect);
263
        $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . TDMC_UPLOAD_IMGMOD_URL . '/' . $modImage . "' name='image3' id='image3' alt='' /><br>"));
264
265
        $fileseltray = new \XoopsFormElementTray('', '<br>');
266
        $fileseltray->addElement(new \XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxsize')));
267
        $fileseltray->addElement(new \XoopsFormLabel(''));
268
        $imgtray->addElement($fileseltray);
269
        $form->addElement($imgtray);
270
        //---------- START LOGO GENERATOR -----------------
271
        $tables_img = $this->getVar('table_image') ?: 'about.png';
272
        $iconsdir = '/Frameworks/moduleclasses/icons/32';
273
        if (is_dir(XOOPS_ROOT_PATH . $iconsdir)) {
274
            $uploadDirectory = $iconsdir;
275
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, ".{$iconsdir}/");
276
        } else {
277
            $uploadDirectory = '/uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/tables';
278
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/tables');
279
        }
280
        $createLogoTray = new \XoopsFormElementTray(_AM_TDMCREATE_MODULE_CREATENEWLOGO, '<br>');
281
        $iconSelect = new \XoopsFormSelect($imgpath, 'tables_img', $tables_img, 8);
282
        $tablesImagesArray = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDirectory);
283
        foreach ($tablesImagesArray as $image) {
284
            $iconSelect->addOption($image, $image);
285
        }
286
        $iconSelect->setExtra(" onchange='showImgSelected2(\"image4\", \"tables_img\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")' ");
287
        $createLogoTray->addElement($iconSelect);
288
        $createLogoTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDirectory . '/' . $tables_img . "' name='image4' id='image4' alt='' />"));
289
        // Create preview and submit buttons
290
        $buttonLogoGenerator4 = new \XoopsFormButton('', 'button4', _AM_TDMCREATE_MODULE_CREATENEWLOGO, 'button');
291
        $buttonLogoGenerator4->setExtra(" onclick='createNewModuleLogo(\"" . TDMC_URL . "\")' ");
292
        $createLogoTray->addElement($buttonLogoGenerator4);
293
294
        $form->addElement($createLogoTray);
295
        //------------ END LOGO GENERATOR --------------------
296
297
        $modAuthorMail = $isNew ? $set['author_mail'] : $this->getVar('mod_author_mail');
298
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_MAIL, 'mod_author_mail', 50, 255, $modAuthorMail));
299
300
        $modAuthorWebsiteUrl = $isNew ? $set['author_website_url'] : $this->getVar('mod_author_website_url');
301
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_URL, 'mod_author_website_url', 50, 255, $modAuthorWebsiteUrl));
302
303
        $modAuthorWebsiteName = $isNew ? $set['author_website_name'] : $this->getVar('mod_author_website_name');
304
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_NAME, 'mod_author_website_name', 50, 255, $modAuthorWebsiteName));
305
306
        $modCredits = $isNew ? $set['credits'] : $this->getVar('mod_credits');
307
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_CREDITS, 'mod_credits', 50, 255, $modCredits));
308
309
        $modReleaseInfo = $isNew ? $set['release_info'] : $this->getVar('mod_release_info');
310
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_INFO, 'mod_release_info', 50, 255, $modReleaseInfo));
311
312
        $modReleaseFile = $isNew ? $set['release_file'] : $this->getVar('mod_release_file');
313
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_FILE, 'mod_release_file', 50, 255, $modReleaseFile));
314
315
        $modManual = $isNew ? $set['manual'] : $this->getVar('mod_manual');
316
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL, 'mod_manual', 50, 255, $modManual));
317
318
        $modManualFile = $isNew ? $set['manual_file'] : $this->getVar('mod_manual_file');
319
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL_FILE, 'mod_manual_file', 50, 255, $modManualFile));
320
321
        $modDemoSiteUrl = $isNew ? $set['demo_site_url'] : $this->getVar('mod_demo_site_url');
322
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_URL, 'mod_demo_site_url', 50, 255, $modDemoSiteUrl));
323
324
        $modDemoSiteName = $isNew ? $set['demo_site_name'] : $this->getVar('mod_demo_site_name');
325
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_NAME, 'mod_demo_site_name', 50, 255, $modDemoSiteName));
326
327
        $modSupportUrl = $isNew ? $set['support_url'] : $this->getVar('mod_support_url');
328
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_URL, 'mod_support_url', 50, 255, $modSupportUrl));
329
330
        $modSupportName = $isNew ? $set['support_name'] : $this->getVar('mod_support_name');
331
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_NAME, 'mod_support_name', 50, 255, $modSupportName));
332
333
        $modWebsiteUrl = $isNew ? $set['website_url'] : $this->getVar('mod_website_url');
334
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_URL, 'mod_website_url', 50, 255, $modWebsiteUrl));
335
336
        $modWebsiteName = $isNew ? $set['website_name'] : $this->getVar('mod_website_name');
337
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_NAME, 'mod_website_name', 50, 255, $modWebsiteName));
338
339
        $modRelease = $isNew ? $set['release'] : $this->getVar('mod_release');
340
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE, 'mod_release', 50, 255, $modRelease));
341
342
        $modStatus = $isNew ? $set['status'] : $this->getVar('mod_status');
343
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_STATUS, 'mod_status', 50, 255, $modStatus));
344
345
        $modDonations = $isNew ? $set['donations'] : $this->getVar('mod_donations');
346
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_PAYPAL_BUTTON, 'mod_donations', 50, 255, $modDonations));
347
348
        $modSubversion = $isNew ? $set['subversion'] : $this->getVar('mod_subversion');
349
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_MODULE_SUBVERSION, 'mod_subversion', 50, 255, $modSubversion));
350
351
        $buttonTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', '');
352
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save'));
353
        $buttonTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
354
        $form->addElement($buttonTray);
355
356
        return $form;
357
    }
358
359
    /**
360
     *  @private static function createLogo
361
     *  @param mixed $logoIcon
362
     *  @param string $moduleDirname
363
     *
364
     * @return bool|string
365
     */
366
    private static function createLogo($logoIcon, $moduleDirname)
0 ignored issues
show
Unused Code introduced by
The method createLogo() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
367
    {
368
        if (!extension_loaded('gd')) {
369
            return false;
370
        }
371
        $requiredFunctions = ['imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate'];
372
        foreach ($requiredFunctions as $func) {
373
            if (!function_exists($func)) {
374
                return false;
375
            }
376
        }
377
378
        if (!file_exists($imageBase = TDMC_IMAGES_LOGOS_PATH . '/empty.png') ||
379
            !file_exists($font = TDMC_FONTS_PATH . '/VeraBd.ttf') ||
380
            !file_exists($iconFile = XOOPS_ICONS32_PATH . '/' . basename($logoIcon))
381
        ) {
382
            return false;
383
        }
384
        $imageModule = imagecreatefrompng($imageBase);
385
        $imageIcon = imagecreatefrompng($iconFile);
386
        // Write text
387
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
0 ignored issues
show
Bug introduced by
It seems like $imageModule can also be of type false; however, parameter $image of imagecolorallocate() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

387
        $textColor = imagecolorallocate(/** @scrutinizer ignore-type */ $imageModule, 0, 0, 0);
Loading history...
388
        $spaceBorder = (92 - mb_strlen($moduleDirname) * 7.5) / 2;
389
        imagefttext($imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
0 ignored issues
show
Bug introduced by
It seems like $imageModule can also be of type false; however, parameter $image of imagefttext() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

389
        imagefttext(/** @scrutinizer ignore-type */ $imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
Loading history...
Bug introduced by
$spaceBorder of type double is incompatible with the type integer expected by parameter $x of imagefttext(). ( Ignorable by Annotation )

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

389
        imagefttext($imageModule, 8.5, 0, /** @scrutinizer ignore-type */ $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
Loading history...
390
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
0 ignored issues
show
Bug introduced by
It seems like $imageIcon can also be of type false; however, parameter $src_im of imagecopy() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

390
        imagecopy($imageModule, /** @scrutinizer ignore-type */ $imageIcon, 29, 2, 0, 0, 32, 32);
Loading history...
Bug introduced by
It seems like $imageModule can also be of type false; however, parameter $dst_im of imagecopy() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

390
        imagecopy(/** @scrutinizer ignore-type */ $imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
Loading history...
391
        $logoImg = '/' . $moduleDirname . '_logo.png';
392
        imagepng($imageModule, TDMC_UPLOAD_IMGMOD_PATH . $logoImg);
0 ignored issues
show
Bug introduced by
It seems like $imageModule can also be of type false; however, parameter $image of imagepng() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

392
        imagepng(/** @scrutinizer ignore-type */ $imageModule, TDMC_UPLOAD_IMGMOD_PATH . $logoImg);
Loading history...
393
        imagedestroy($imageModule);
0 ignored issues
show
Bug introduced by
It seems like $imageModule can also be of type false; however, parameter $image of imagedestroy() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

393
        imagedestroy(/** @scrutinizer ignore-type */ $imageModule);
Loading history...
394
        imagedestroy($imageIcon);
395
396
        return TDMC_UPLOAD_IMGMOD_URL . $logoImg;
397
    }
398
399
    /**
400
     * Get Values.
401
     *
402
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
403
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
404
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
405
     *
406
     * @return array
407
     */
408
    public function getValuesModules($keys = null, $format = null, $maxDepth = null)
409
    {
410
        $ret = $this->getValues($keys, $format, $maxDepth);
411
        // Values
412
        $ret['id'] = $this->getVar('mod_id');
413
        $ret['name'] = $this->getVar('mod_name');
414
        $ret['version'] = $this->getVar('mod_version');
415
        $ret['image'] = $this->getVar('mod_image');
416
        $ret['release'] = $this->getVar('mod_release');
417
        $ret['status'] = $this->getVar('mod_status');
418
        $ret['admin'] = $this->getVar('mod_admin');
419
        $ret['user'] = $this->getVar('mod_user');
420
        $ret['blocks'] = $this->getVar('mod_blocks');
421
        $ret['search'] = $this->getVar('mod_search');
422
        $ret['comments'] = $this->getVar('mod_comments');
423
        $ret['notifications'] = $this->getVar('mod_notifications');
424
        $ret['permissions'] = $this->getVar('mod_permissions');
425
426
        return $ret;
427
    }
428
429
    /**
430
     * Get getOptionsModules.
431
     *
432
     * @return array
433
     */
434
    private function getOptionsModules()
435
    {
436
        $retModules = [];
437
        foreach ($this->options as $option) {
438
            if (1 == $this->getVar('mod_' . $option)) {
439
                $retModules[] = $option;
440
            }
441
        }
442
443
        return $retModules;
444
    }
445
446
    /**
447
     * Get Defined Language.
448
     *
449
     * @param $lang
450
     *
451
     * @return string
452
     */
453
    private static function getDefinedLanguage($lang)
454
    {
455
        if (defined($lang)) {
456
            return constant($lang);
457
        }
458
459
        return $lang;
460
    }
461
}
462