Completed
Pull Request — master (#144)
by Michael
03:13
created

Modules::getFormModules()   F

Complexity

Conditions 39
Paths 0

Size

Total Lines 224
Code Lines 172

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 39
eloc 172
nc 0
nop 1
dl 0
loc 224
rs 3.3333
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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

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

Commonly applied refactorings include:

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

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

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

388
        $textColor   = imagecolorallocate(/** @scrutinizer ignore-type */ $imageModule, 0, 0, 0);
Loading history...
389
        $spaceBorder = (92 - mb_strlen($moduleDirname) * 7.5) / 2;
390
        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

390
        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

390
        imagefttext($imageModule, 8.5, 0, /** @scrutinizer ignore-type */ $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
Loading history...
391
        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

391
        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

391
        imagecopy(/** @scrutinizer ignore-type */ $imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
Loading history...
392
        $logoImg = '/' . $moduleDirname . '_logo.png';
393
        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

393
        imagepng(/** @scrutinizer ignore-type */ $imageModule, TDMC_UPLOAD_IMGMOD_PATH . $logoImg);
Loading history...
394
        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

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