Passed
Branch master (38ab27)
by Michael
03:06
created

TDMCreateModules::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 2
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
/*
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
/**
14
 * modules class.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.7
20
 *
21
 * @author          Txmod Xoops <[email protected]> - <http://www.txmodxoops.org/>
22
 *
23
 * @version         $Id: 1.91 modules.php 13040 2015-04-25 15:12:12Z timgno $
24
 */
25
include __DIR__.'/autoload.php';
26
27
/**
28
 * Class TDMCreateModules.
29
 */
30
class TDMCreateModules extends XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
{
32
    /**
33
     * Options.
34
     */
35
    public $options = [
36
        'admin',
37
        'user',
38
        'blocks',
39
        'search',
40
        'comments',
41
        'notifications',
42
        'permissions',
43
        'inroot_copy',
44
    ];
45
46
    /**
47
    *  @public function constructor class
48
    *  @param null
49
    */
50
51
    public function __construct()
52
    {
53
        $tdmcreate = TDMCreateHelper::getInstance();
54
        $setId = XoopsRequest::getInt('set_id');
0 ignored issues
show
Bug introduced by
The type XoopsRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
        $settings = $tdmcreate->getHandler('settings')->get($setId);
56
57
        $this->initVar('mod_id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
        $this->initVar('mod_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_name'));
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
59
        $this->initVar('mod_dirname', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_dirname'));
60
        $this->initVar('mod_version', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_version'));
61
        $this->initVar('mod_since', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_since'));
62
        $this->initVar('mod_min_php', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_php'));
63
        $this->initVar('mod_min_xoops', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_xoops'));
64
        $this->initVar('mod_min_admin', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_admin'));
65
        $this->initVar('mod_min_mysql', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_mysql'));
66
        $this->initVar('mod_description', XOBJ_DTYPE_TXTAREA, $settings->getVar('set_description'));
0 ignored issues
show
Bug introduced by
The constant XOBJ_DTYPE_TXTAREA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
67
        $this->initVar('mod_author', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author'));
68
        $this->initVar('mod_author_mail', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_mail'));
69
        $this->initVar('mod_author_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_url'));
70
        $this->initVar('mod_author_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_name'));
71
        $this->initVar('mod_credits', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_credits'));
72
        $this->initVar('mod_license', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_license'));
73
        $this->initVar('mod_release_info', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_info'));
74
        $this->initVar('mod_release_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_file'));
75
        $this->initVar('mod_manual', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual'));
76
        $this->initVar('mod_manual_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual_file'));
77
        $this->initVar('mod_image', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_image'));
78
        $this->initVar('mod_demo_site_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_url'));
79
        $this->initVar('mod_demo_site_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_name'));
80
        $this->initVar('mod_support_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_url'));
81
        $this->initVar('mod_support_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_name'));
82
        $this->initVar('mod_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_url'));
83
        $this->initVar('mod_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_name'));
84
        $this->initVar('mod_release', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release'));
85
        $this->initVar('mod_status', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_status'));
86
        $this->initVar('mod_admin', XOBJ_DTYPE_INT, $settings->getVar('set_admin'));
87
        $this->initVar('mod_user', XOBJ_DTYPE_INT, $settings->getVar('set_user'));
88
        $this->initVar('mod_blocks', XOBJ_DTYPE_INT, $settings->getVar('set_blocks'));
89
        $this->initVar('mod_search', XOBJ_DTYPE_INT, $settings->getVar('set_search'));
90
        $this->initVar('mod_comments', XOBJ_DTYPE_INT, $settings->getVar('set_comments'));
91
        $this->initVar('mod_notifications', XOBJ_DTYPE_INT, $settings->getVar('set_notifications'));
92
        $this->initVar('mod_permissions', XOBJ_DTYPE_INT, $settings->getVar('set_permissions'));
93
        $this->initVar('mod_inroot_copy', XOBJ_DTYPE_INT, $settings->getVar('set_inroot_copy'));
94
        $this->initVar('mod_donations', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_donations'));
95
        $this->initVar('mod_subversion', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_subversion'));
96
    }
97
98
    /**
99
     * @param string $method
100
     * @param array  $args
101
     *
102
     * @return mixed
103
     */
104
    public function __call($method, $args)
105
    {
106
        $arg = isset($args[0]) ? $args[0] : null;
107
108
        return $this->getVar($method, $arg);
109
    }
110
111
    /**
112
    *  @static function getInstance
113
    *  @param null
114
     * @return TDMCreateModules
115
     */
116
    public static function getInstance()
117
    {
118
        static $instance = false;
119
        if (!$instance) {
120
            $instance = new self();
121
        }
122
123
        return $instance;
124
    }
125
126
    /**
127
    *  @public function getFormModules
128
    *  @param mixed $action
129
     *
130
     * @return XoopsThemeForm
131
     */
132
    public function getFormModules($action = false)
133
    {
134
        $tdmcreate = TDMCreateHelper::getInstance();
135
        if (false === $action) {
136
            $action = $_SERVER['REQUEST_URI'];
137
        }
138
        $set = [];
139
        $settings = $tdmcreate->getHandler('settings')->getAllSettings(0, 0, 'set_type');
140
        foreach ($settings as $setting) {
141
            $set['name'] = $setting->getVar('set_name');
142
            $set['dirname'] = $setting->getVar('set_dirname');
143
            $set['version'] = $setting->getVar('set_version');
144
            $set['since'] = $setting->getVar('set_since');
145
            $set['min_php'] = $setting->getVar('set_min_php');
146
            $set['min_xoops'] = $setting->getVar('set_min_xoops');
147
            $set['min_admin'] = $setting->getVar('set_min_admin');
148
            $set['min_mysql'] = $setting->getVar('set_min_mysql');
149
            $set['description'] = $setting->getVar('set_description');
150
            $set['author'] = $setting->getVar('set_author');
151
            $set['license'] = $setting->getVar('set_license');
152
            $set['admin'] = $setting->getVar('set_admin');
153
            $set['user'] = $setting->getVar('set_user');
154
            $set['blocks'] = $setting->getVar('set_blocks');
155
            $set['search'] = $setting->getVar('set_search');
156
            $set['comments'] = $setting->getVar('set_comments');
157
            $set['notifications'] = $setting->getVar('set_notifications');
158
            $set['permissions'] = $setting->getVar('set_permissions');
159
            $set['inroot'] = $setting->getVar('set_inroot_copy');
160
            $set['image'] = $setting->getVar('set_image');
161
            $set['author_mail'] = $setting->getVar('set_author_mail');
162
            $set['author_website_url'] = $setting->getVar('set_author_website_url');
163
            $set['author_website_name'] = $setting->getVar('set_author_website_name');
164
            $set['credits'] = $setting->getVar('set_credits');
165
            $set['release_info'] = $setting->getVar('set_release_info');
166
            $set['release_file'] = $setting->getVar('set_release_file');
167
            $set['manual'] = $setting->getVar('set_manual');
168
            $set['manual_file'] = $setting->getVar('set_manual_file');
169
            $set['demo_site_url'] = $setting->getVar('set_demo_site_url');
170
            $set['demo_site_name'] = $setting->getVar('set_demo_site_name');
171
            $set['support_url'] = $setting->getVar('set_support_url');
172
            $set['support_name'] = $setting->getVar('set_support_name');
173
            $set['website_url'] = $setting->getVar('set_website_url');
174
            $set['website_name'] = $setting->getVar('set_website_name');
175
            $set['release'] = $setting->getVar('set_release');
176
            $set['status'] = $setting->getVar('set_status');
177
            $set['donations'] = $setting->getVar('set_donations');
178
            $set['subversion'] = $setting->getVar('set_subversion');
179
        }
180
181
        $isNew = $this->isNew();
182
        $title = $isNew ? sprintf(_AM_TDMCREATE_MODULE_NEW) : sprintf(_AM_TDMCREATE_MODULE_EDIT);
183
184
        include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
185
186
        $form = new XoopsThemeForm($title, 'moduleform', $action, 'post', true);
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
187
        $form->setExtra('enctype="multipart/form-data"');
188
189
        $modName = $isNew ? $set['name'] : $this->getVar('mod_name');
190
        $modName = new XoopsFormText(_AM_TDMCREATE_MODULE_NAME, 'mod_name', 50, 255, $modName);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
191
        $modName->setDescription(_AM_TDMCREATE_MODULE_NAME_DESC);
192
        $form->addElement($modName, true);
193
194
        $modDirname = $isNew ? $set['dirname'] : $this->getVar('mod_dirname');
195
        $modDirname = new XoopsFormText(_AM_TDMCREATE_MODULE_DIRNAME, 'mod_dirname', 25, 255, $modDirname);
196
        $modDirname->setDescription(_AM_TDMCREATE_MODULE_DIRNAME_DESC);
197
        $form->addElement($modDirname, true);
198
199
        $modVersion = $isNew ? $set['version'] : $this->getVar('mod_version');
200
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_VERSION, 'mod_version', 10, 25, $modVersion), true);
201
202
        $modSince = $isNew ? $set['since'] : $this->getVar('mod_since');
203
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SINCE, 'mod_since', 10, 25, $modSince), true);
204
205
        $modMinPhp = $isNew ? $set['min_php'] : $this->getVar('mod_min_php');
206
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_PHP, 'mod_min_php', 10, 25, $modMinPhp), true);
207
208
        $modMinXoops = $isNew ? $set['min_xoops'] : $this->getVar('mod_min_xoops');
209
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_XOOPS, 'mod_min_xoops', 10, 25, $modMinXoops), true);
210
211
        $modMinAdmin = $isNew ? $set['min_admin'] : $this->getVar('mod_min_admin');
212
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_ADMIN, 'mod_min_admin', 10, 25, $modMinAdmin), true);
213
214
        $modMinMysql = $isNew ? $set['min_mysql'] : $this->getVar('mod_min_mysql');
215
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_MYSQL, 'mod_min_mysql', 10, 25, $modMinMysql), true);
216
        // Name description
217
        $editorConfigs = [];
218
        $editorConfigs['name'] = 'mod_description';
219
        $editorConfigs['value'] = $isNew ? $set['description'] : $this->getVar('mod_description', 'e');
220
        $editorConfigs['rows'] = 5;
221
        $editorConfigs['cols'] = 100;
222
        $editorConfigs['width'] = '50%';
223
        $editorConfigs['height'] = '100px';
224
        $editorConfigs['editor'] = $tdmcreate->getConfig('tdmcreate_editor');
225
        $form->addElement(new XoopsFormEditor(_AM_TDMCREATE_MODULE_DESCRIPTION, 'mod_description', $editorConfigs), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormEditor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
226
        // Author
227
        $modAuthor = $isNew ? $set['author'] : $this->getVar('mod_author');
228
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR, 'mod_author', 50, 255, $modAuthor), true);
229
        $modLicense = $isNew ? $set['license'] : $this->getVar('mod_license');
230
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_LICENSE, 'mod_license', 50, 255, $modLicense), true);
231
232
        $optionsTray = new XoopsFormElementTray(_OPTIONS, '<br>');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The constant _OPTIONS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
233
        $optionsTray->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
234
        // Check All Modules Options
235
        $checkAllOptions = new XoopsFormCheckBox('', 'modulebox', 1);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
236
        $checkAllOptions->addOption('allbox', _AM_TDMCREATE_MODULE_ALL);
237
        $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'moduleform\', \'modulebox\');" ');
238
        $checkAllOptions->setClass('xo-checkall');
239
        $optionsTray->addElement($checkAllOptions);
240
        // Options
241
        $checkbox = new XoopsFormCheckbox(' ', 'module_option', $this->getOptionsModules(), '<br>');
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckbox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
242
        foreach ($this->options as $option) {
243
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_MODULE_'.strtoupper($option)));
244
        }
245
        $optionsTray->addElement($checkbox);
246
247
        $form->addElement($optionsTray);
248
249
        $modImage = $this->getVar('mod_image');
250
        $modImage = $modImage ?: $set['image'];
251
252
        $uploadDirectory = 'uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/modules';
253
        $imgtray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_IMAGE, '<br>');
254
        $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './'.strtolower($uploadDirectory).'/');
255
        $imageselect = new XoopsFormSelect($imgpath, 'mod_image', $modImage);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
256
        $modImageArray = XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH);
0 ignored issues
show
Bug introduced by
The type XoopsLists was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
257
        foreach ($modImageArray as $image) {
258
            $imageselect->addOption("{$image}", $image);
259
        }
260
        $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"mod_image\", \"".$uploadDirectory.'", "", "'.XOOPS_URL."\")'");
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
261
        $imgtray->addElement($imageselect);
262
        $imgtray->addElement(new XoopsFormLabel('', "<br><img src='".TDMC_UPLOAD_IMGMOD_URL.'/'.$modImage."' name='image3' id='image3' alt='' /><br>"));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
263
264
        $fileseltray = new XoopsFormElementTray('', '<br>');
265
        $fileseltray->addElement(new XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $tdmcreate->getConfig('maxsize')));
0 ignored issues
show
Bug introduced by
The type XoopsFormFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
266
        $fileseltray->addElement(new XoopsFormLabel(''));
267
        $imgtray->addElement($fileseltray);
268
        $form->addElement($imgtray);
269
        //---------- START LOGO GENERATOR -----------------
270
        $tables_img = $this->getVar('table_image') ?: 'about.png';
271
        $iconsdir = '/Frameworks/moduleclasses/icons/32';
272
        if (is_dir(XOOPS_ROOT_PATH.$iconsdir)) {
273
            $uploadDirectory = $iconsdir;
274
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, ".{$iconsdir}/");
275
        } else {
276
            $uploadDirectory = '/uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/tables';
277
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/tables');
278
        }
279
        $createLogoTray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_CREATENEWLOGO, '<br>');
280
        $iconSelect = new XoopsFormSelect($imgpath, 'tables_img', $tables_img, 8);
281
        $tablesImagesArray = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH.$uploadDirectory);
282
        foreach ($tablesImagesArray as $image) {
283
            $iconSelect->addOption("{$image}", $image);
284
        }
285
        $iconSelect->setExtra(" onchange='showImgSelected2(\"image4\", \"tables_img\", \"".$uploadDirectory.'", "", "'.XOOPS_URL."\")' ");
286
        $createLogoTray->addElement($iconSelect);
287
        $createLogoTray->addElement(new XoopsFormLabel('', "<br><img src='".XOOPS_URL.'/'.$uploadDirectory.'/'.$tables_img."' name='image4' id='image4' alt='' />"));
288
        // Create preview and submit buttons
289
        $buttonLogoGenerator4 = new XoopsFormButton('', 'button4', _AM_TDMCREATE_MODULE_CREATENEWLOGO, 'button');
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
290
        $buttonLogoGenerator4->setExtra(" onclick='createNewModuleLogo(\"".TDMC_URL."\")' ");
291
        $createLogoTray->addElement($buttonLogoGenerator4);
292
293
        $form->addElement($createLogoTray);
294
        //------------ END LOGO GENERATOR --------------------
295
296
        $modAuthorMail = $isNew ? $set['author_mail'] : $this->getVar('mod_author_mail');
297
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_MAIL, 'mod_author_mail', 50, 255, $modAuthorMail));
298
299
        $modAuthorWebsiteUrl = $isNew ? $set['author_website_url'] : $this->getVar('mod_author_website_url');
300
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_URL, 'mod_author_website_url', 50, 255, $modAuthorWebsiteUrl));
301
302
        $modAuthorWebsiteName = $isNew ? $set['author_website_name'] : $this->getVar('mod_author_website_name');
303
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_NAME, 'mod_author_website_name', 50, 255, $modAuthorWebsiteName));
304
305
        $modCredits = $isNew ? $set['credits'] : $this->getVar('mod_credits');
306
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_CREDITS, 'mod_credits', 50, 255, $modCredits));
307
308
        $modReleaseInfo = $isNew ? $set['release_info'] : $this->getVar('mod_release_info');
309
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_INFO, 'mod_release_info', 50, 255, $modReleaseInfo));
310
311
        $modReleaseFile = $isNew ? $set['release_file'] : $this->getVar('mod_release_file');
312
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_FILE, 'mod_release_file', 50, 255, $modReleaseFile));
313
314
        $modManual = $isNew ? $set['manual'] : $this->getVar('mod_manual');
315
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL, 'mod_manual', 50, 255, $modManual));
316
317
        $modManualFile = $isNew ? $set['manual_file'] : $this->getVar('mod_manual_file');
318
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL_FILE, 'mod_manual_file', 50, 255, $modManualFile));
319
320
        $modDemoSiteUrl = $isNew ? $set['demo_site_url'] : $this->getVar('mod_demo_site_url');
321
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_URL, 'mod_demo_site_url', 50, 255, $modDemoSiteUrl));
322
323
        $modDemoSiteName = $isNew ? $set['demo_site_name'] : $this->getVar('mod_demo_site_name');
324
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_NAME, 'mod_demo_site_name', 50, 255, $modDemoSiteName));
325
326
        $modSupportUrl = $isNew ? $set['support_url'] : $this->getVar('mod_support_url');
327
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_URL, 'mod_support_url', 50, 255, $modSupportUrl));
328
329
        $modSupportName = $isNew ? $set['support_name'] : $this->getVar('mod_support_name');
330
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_NAME, 'mod_support_name', 50, 255, $modSupportName));
331
332
        $modWebsiteUrl = $isNew ? $set['website_url'] : $this->getVar('mod_website_url');
333
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_URL, 'mod_website_url', 50, 255, $modWebsiteUrl));
334
335
        $modWebsiteName = $isNew ? $set['website_name'] : $this->getVar('mod_website_name');
336
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_NAME, 'mod_website_name', 50, 255, $modWebsiteName));
337
338
        $modRelease = $isNew ? $set['release'] : $this->getVar('mod_release');
339
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE, 'mod_release', 50, 255, $modRelease));
340
341
        $modStatus = $isNew ? $set['status'] : $this->getVar('mod_status');
342
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_STATUS, 'mod_status', 50, 255, $modStatus));
343
344
        $modDonations = $isNew ? $set['donations'] : $this->getVar('mod_donations');
345
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_PAYPAL_BUTTON, 'mod_donations', 50, 255, $modDonations));
346
347
        $modSubversion = $isNew ? $set['subversion'] : $this->getVar('mod_subversion');
348
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUBVERSION, 'mod_subversion', 50, 255, $modSubversion));
349
350
        $buttonTray = new XoopsFormElementTray(_REQUIRED.' <sup class="red bold">*</sup>', '');
0 ignored issues
show
Bug introduced by
The constant _REQUIRED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
351
        $buttonTray->addElement(new XoopsFormHidden('op', 'save'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
352
        $buttonTray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
0 ignored issues
show
Bug introduced by
The constant _SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
353
        $form->addElement($buttonTray);
354
355
        return $form;
356
    }
357
358
    /**
359
    *  @private static function createLogo
360
    *  @param mixed $logoIcon
361
    *  @param string $moduleDirname
362
     *
363
     * @return bool|string
364
     */
365
    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...
366
    {
367
        if (!extension_loaded('gd')) {
368
            return false;
369
        } else {
370
            $requiredFunctions = ['imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate'];
371
            foreach ($requiredFunctions as $func) {
372
                if (!function_exists($func)) {
373
                    return false;
374
                }
375
            }
376
        }
377
        if (!file_exists($imageBase = TDMC_IMAGES_LOGOS_PATH.'/empty.png') ||
378
            !file_exists($font = TDMC_FONTS_PATH.'/VeraBd.ttf') ||
379
            !file_exists($iconFile = XOOPS_ICONS32_PATH.'/'.basename($logoIcon))
380
        ) {
381
            return false;
382
        }
383
        $imageModule = imagecreatefrompng($imageBase);
384
        $imageIcon = imagecreatefrompng($iconFile);
385
        // Write text
386
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
387
        $spaceBorder = (92 - strlen($moduleDirname) * 7.5) / 2;
388
        imagefttext($imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
0 ignored issues
show
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

388
        imagefttext($imageModule, 8.5, 0, /** @scrutinizer ignore-type */ $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
Loading history...
389
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
390
        $logoImg = '/'.$moduleDirname.'_logo.png';
391
        imagepng($imageModule, TDMC_UPLOAD_IMGMOD_PATH.$logoImg);
392
        imagedestroy($imageModule);
393
        imagedestroy($imageIcon);
394
395
        return TDMC_UPLOAD_IMGMOD_URL.$logoImg;
396
    }
397
398
    /**
399
     * Get Values.
400
     *
401
     * @param null $keys
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...
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...
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...
402
     * @param null $format
403
     * @param null $maxDepth
404
     *
405
     * @return array
406
     */
407
    public function getValuesModules($keys = null, $format = null, $maxDepth = null)
408
    {
409
        $ret = $this->getValues($keys, $format, $maxDepth);
410
        // Values
411
        $ret['id'] = $this->getVar('mod_id');
412
        $ret['name'] = $this->getVar('mod_name');
413
        $ret['version'] = $this->getVar('mod_version');
414
        $ret['image'] = $this->getVar('mod_image');
415
        $ret['release'] = $this->getVar('mod_release');
416
        $ret['status'] = $this->getVar('mod_status');
417
        $ret['admin'] = $this->getVar('mod_admin');
418
        $ret['user'] = $this->getVar('mod_user');
419
        $ret['blocks'] = $this->getVar('mod_blocks');
420
        $ret['search'] = $this->getVar('mod_search');
421
        $ret['comments'] = $this->getVar('mod_comments');
422
        $ret['notifications'] = $this->getVar('mod_notifications');
423
        $ret['permissions'] = $this->getVar('mod_permissions');
424
425
        return $ret;
426
    }
427
428
    /**
429
     * Get getOptionsModules.
430
     *
431
     * @return array
432
     */
433
    private function getOptionsModules()
434
    {
435
        $retModules = [];
436
        foreach ($this->options as $option) {
437
            if (1 == $this->getVar('mod_' . $option)) {
438
                array_push($retModules, $option);
439
            }
440
        }
441
442
        return $retModules;
443
    }
444
445
    /**
446
     * Get Defined Language.
447
     *
448
     * @param $lang
449
     *
450
     * @return string
451
     */
452
    private static function getDefinedLanguage($lang)
453
    {
454
        if (defined($lang)) {
455
            return constant($lang);
456
        }
457
458
        return $lang;
459
    }
460
}
461
462
/**
463
 *  @Class TDMCreateModulesHandler
464
 *  @extends XoopsPersistableObjectHandler
465
 */
466
class TDMCreateModulesHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Bug introduced by
The type XoopsPersistableObjectHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
467
{
468
    /**
469
     *  @public function constructor class
470
     *
471
     * @param null|XoopsDatabase $db
472
     */
473
    public function __construct(XoopsDatabase $db)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
474
    {
475
        parent::__construct($db, 'tdmcreate_modules', 'TDMCreateModules', 'mod_id', 'mod_name');
476
    }
477
478
    /**
479
     * @param bool $isNew
480
     *
481
     * @return XoopsObject
482
     */
483
    public function create($isNew = true)
484
    {
485
        return parent::create($isNew);
486
    }
487
488
    /**
489
     * retrieve a field.
490
     *
491
     * @param int  $i      field id
492
     * @param null $fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
493
     *
494
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
495
     *               object
496
     */
497
    public function get($i = null, $fields = null)
498
    {
499
        return parent::get($i, $fields);
500
    }
501
502
    /**
503
     * get inserted id.
504
     *
505
     * @param null
506
     *
507
     * @return int reference to the {@link TDMCreateTables} object
508
     */
509
    public function getInsertId()
510
    {
511
        return $this->db->getInsertId();
512
    }
513
514
    /**
515
     * Get Count Modules.
516
     *
517
     * @param int    $start
518
     * @param int    $limit
519
     * @param string $sort
520
     * @param string $order
521
     *
522
     * @return int
523
     */
524
    public function getCountModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
525
    {
526
        $crCountModules = new CriteriaCompo();
0 ignored issues
show
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
527
        $crCountModules = $this->getModulesCriteria($crCountModules, $start, $limit, $sort, $order);
528
529
        return $this->getCount($crCountModules);
530
    }
531
532
    /**
533
     * Get All Modules.
534
     *
535
     * @param int    $start
536
     * @param int    $limit
537
     * @param string $sort
538
     * @param string $order
539
     *
540
     * @return array
541
     */
542
    public function getAllModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
543
    {
544
        $crAllModules = new CriteriaCompo();
545
        $crAllModules = $this->getModulesCriteria($crAllModules, $start, $limit, $sort, $order);
546
547
        return $this->getAll($crAllModules);
548
    }
549
550
    /**
551
     * Get Modules Criteria.
552
     *
553
     * @param $crModules
554
     * @param $start
555
     * @param $limit
556
     * @param $sort
557
     * @param $order
558
     *
559
     * @return mixed
560
     */
561
    private function getModulesCriteria($crModules, $start, $limit, $sort, $order)
562
    {
563
        $crModules->setStart($start);
564
        $crModules->setLimit($limit);
565
        $crModules->setSort($sort);
566
        $crModules->setOrder($order);
567
568
        return $crModules;
569
    }
570
}
571