Passed
Push — master ( 0c230a...202965 )
by Michael
02:53
created

TDMCreateModules::getFormModules()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 225

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 39
nc 4294967295
nop 1
dl 0
loc 225
rs 0
c 0
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
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
    public function __construct()
51
    {
52
        $tdmcreate = TDMCreateHelper::getInstance();
53
        $setId = XoopsRequest::getInt('set_id');
54
        $settings = $tdmcreate->getHandler('settings')->get($setId);
0 ignored issues
show
Bug introduced by
The method get cannot be called on $tdmcreate->getHandler('settings') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
55
56
        $this->initVar('mod_id', XOBJ_DTYPE_INT);
57
        $this->initVar('mod_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_name'));
58
        $this->initVar('mod_dirname', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_dirname'));
59
        $this->initVar('mod_version', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_version'));
60
        $this->initVar('mod_since', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_since'));
61
        $this->initVar('mod_min_php', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_php'));
62
        $this->initVar('mod_min_xoops', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_xoops'));
63
        $this->initVar('mod_min_admin', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_admin'));
64
        $this->initVar('mod_min_mysql', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_min_mysql'));
65
        $this->initVar('mod_description', XOBJ_DTYPE_TXTAREA, $settings->getVar('set_description'));
66
        $this->initVar('mod_author', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author'));
67
        $this->initVar('mod_author_mail', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_mail'));
68
        $this->initVar('mod_author_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_url'));
69
        $this->initVar('mod_author_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_author_website_name'));
70
        $this->initVar('mod_credits', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_credits'));
71
        $this->initVar('mod_license', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_license'));
72
        $this->initVar('mod_release_info', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_info'));
73
        $this->initVar('mod_release_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release_file'));
74
        $this->initVar('mod_manual', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual'));
75
        $this->initVar('mod_manual_file', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_manual_file'));
76
        $this->initVar('mod_image', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_image'));
77
        $this->initVar('mod_demo_site_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_url'));
78
        $this->initVar('mod_demo_site_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_demo_site_name'));
79
        $this->initVar('mod_support_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_url'));
80
        $this->initVar('mod_support_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_support_name'));
81
        $this->initVar('mod_website_url', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_url'));
82
        $this->initVar('mod_website_name', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_website_name'));
83
        $this->initVar('mod_release', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_release'));
84
        $this->initVar('mod_status', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_status'));
85
        $this->initVar('mod_admin', XOBJ_DTYPE_INT, $settings->getVar('set_admin'));
86
        $this->initVar('mod_user', XOBJ_DTYPE_INT, $settings->getVar('set_user'));
87
        $this->initVar('mod_blocks', XOBJ_DTYPE_INT, $settings->getVar('set_blocks'));
88
        $this->initVar('mod_search', XOBJ_DTYPE_INT, $settings->getVar('set_search'));
89
        $this->initVar('mod_comments', XOBJ_DTYPE_INT, $settings->getVar('set_comments'));
90
        $this->initVar('mod_notifications', XOBJ_DTYPE_INT, $settings->getVar('set_notifications'));
91
        $this->initVar('mod_permissions', XOBJ_DTYPE_INT, $settings->getVar('set_permissions'));
92
        $this->initVar('mod_inroot_copy', XOBJ_DTYPE_INT, $settings->getVar('set_inroot_copy'));
93
        $this->initVar('mod_donations', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_donations'));
94
        $this->initVar('mod_subversion', XOBJ_DTYPE_TXTBOX, $settings->getVar('set_subversion'));
95
    }
96
97
    /**
98
     * @param string $method
99
     * @param array  $args
100
     *
101
     * @return mixed
102
     */
103
    public function __call($method, $args)
104
    {
105
        $arg = isset($args[0]) ? $args[0] : null;
106
107
        return $this->getVar($method, $arg);
108
    }
109
110
    /**
111
     *  @static function getInstance
112
     *  @param null
113
     * @return TDMCreateModules
114
     */
115
    public static function getInstance()
116
    {
117
        static $instance = false;
118
        if (!$instance) {
119
            $instance = new self();
120
        }
121
122
        return $instance;
123
    }
124
125
    /**
126
     *  @public function getFormModules
127
     *  @param mixed $action
128
     *
129
     * @return XoopsThemeForm
130
     */
131
    public function getFormModules($action = false)
132
    {
133
        $tdmcreate = TDMCreateHelper::getInstance();
134
        if (false === $action) {
135
            $action = $_SERVER['REQUEST_URI'];
136
        }
137
        $set = [];
138
        $settings = $tdmcreate->getHandler('settings')->getAllSettings(0, 0, 'set_type');
0 ignored issues
show
Bug introduced by
The method getAllSettings cannot be called on $tdmcreate->getHandler('settings') (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
139
        foreach ($settings as $setting) {
140
            $set['name'] = $setting->getVar('set_name');
141
            $set['dirname'] = $setting->getVar('set_dirname');
142
            $set['version'] = $setting->getVar('set_version');
143
            $set['since'] = $setting->getVar('set_since');
144
            $set['min_php'] = $setting->getVar('set_min_php');
145
            $set['min_xoops'] = $setting->getVar('set_min_xoops');
146
            $set['min_admin'] = $setting->getVar('set_min_admin');
147
            $set['min_mysql'] = $setting->getVar('set_min_mysql');
148
            $set['description'] = $setting->getVar('set_description');
149
            $set['author'] = $setting->getVar('set_author');
150
            $set['license'] = $setting->getVar('set_license');
151
            $set['admin'] = $setting->getVar('set_admin');
152
            $set['user'] = $setting->getVar('set_user');
153
            $set['blocks'] = $setting->getVar('set_blocks');
154
            $set['search'] = $setting->getVar('set_search');
155
            $set['comments'] = $setting->getVar('set_comments');
156
            $set['notifications'] = $setting->getVar('set_notifications');
157
            $set['permissions'] = $setting->getVar('set_permissions');
158
            $set['inroot'] = $setting->getVar('set_inroot_copy');
159
            $set['image'] = $setting->getVar('set_image');
160
            $set['author_mail'] = $setting->getVar('set_author_mail');
161
            $set['author_website_url'] = $setting->getVar('set_author_website_url');
162
            $set['author_website_name'] = $setting->getVar('set_author_website_name');
163
            $set['credits'] = $setting->getVar('set_credits');
164
            $set['release_info'] = $setting->getVar('set_release_info');
165
            $set['release_file'] = $setting->getVar('set_release_file');
166
            $set['manual'] = $setting->getVar('set_manual');
167
            $set['manual_file'] = $setting->getVar('set_manual_file');
168
            $set['demo_site_url'] = $setting->getVar('set_demo_site_url');
169
            $set['demo_site_name'] = $setting->getVar('set_demo_site_name');
170
            $set['support_url'] = $setting->getVar('set_support_url');
171
            $set['support_name'] = $setting->getVar('set_support_name');
172
            $set['website_url'] = $setting->getVar('set_website_url');
173
            $set['website_name'] = $setting->getVar('set_website_name');
174
            $set['release'] = $setting->getVar('set_release');
175
            $set['status'] = $setting->getVar('set_status');
176
            $set['donations'] = $setting->getVar('set_donations');
177
            $set['subversion'] = $setting->getVar('set_subversion');
178
        }
179
180
        $isNew = $this->isNew();
181
        $title = $isNew ? sprintf(_AM_TDMCREATE_MODULE_NEW) : sprintf(_AM_TDMCREATE_MODULE_EDIT);
182
183
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
184
185
        $form = new XoopsThemeForm($title, 'moduleform', $action, 'post', true);
186
        $form->setExtra('enctype="multipart/form-data"');
187
188
        $modName = $isNew ? $set['name'] : $this->getVar('mod_name');
189
        $modName = new XoopsFormText(_AM_TDMCREATE_MODULE_NAME, 'mod_name', 50, 255, $modName);
190
        $modName->setDescription(_AM_TDMCREATE_MODULE_NAME_DESC);
191
        $form->addElement($modName, true);
192
193
        $modDirname = $isNew ? $set['dirname'] : $this->getVar('mod_dirname');
194
        $modDirname = new XoopsFormText(_AM_TDMCREATE_MODULE_DIRNAME, 'mod_dirname', 25, 255, $modDirname);
195
        $modDirname->setDescription(_AM_TDMCREATE_MODULE_DIRNAME_DESC);
196
        $form->addElement($modDirname, true);
197
198
        $modVersion = $isNew ? $set['version'] : $this->getVar('mod_version');
199
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_VERSION, 'mod_version', 10, 25, $modVersion), true);
200
201
        $modSince = $isNew ? $set['since'] : $this->getVar('mod_since');
202
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SINCE, 'mod_since', 10, 25, $modSince), true);
203
204
        $modMinPhp = $isNew ? $set['min_php'] : $this->getVar('mod_min_php');
205
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_PHP, 'mod_min_php', 10, 25, $modMinPhp), true);
206
207
        $modMinXoops = $isNew ? $set['min_xoops'] : $this->getVar('mod_min_xoops');
208
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_XOOPS, 'mod_min_xoops', 10, 25, $modMinXoops), true);
209
210
        $modMinAdmin = $isNew ? $set['min_admin'] : $this->getVar('mod_min_admin');
211
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_ADMIN, 'mod_min_admin', 10, 25, $modMinAdmin), true);
212
213
        $modMinMysql = $isNew ? $set['min_mysql'] : $this->getVar('mod_min_mysql');
214
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_MYSQL, 'mod_min_mysql', 10, 25, $modMinMysql), true);
215
        // Name description
216
        $editorConfigs = [];
217
        $editorConfigs['name'] = 'mod_description';
218
        $editorConfigs['value'] = $isNew ? $set['description'] : $this->getVar('mod_description', 'e');
219
        $editorConfigs['rows'] = 5;
220
        $editorConfigs['cols'] = 100;
221
        $editorConfigs['width'] = '50%';
222
        $editorConfigs['height'] = '100px';
223
        $editorConfigs['editor'] = $tdmcreate->getConfig('tdmcreate_editor');
224
        $form->addElement(new XoopsFormEditor(_AM_TDMCREATE_MODULE_DESCRIPTION, 'mod_description', $editorConfigs), true);
225
        // Author
226
        $modAuthor = $isNew ? $set['author'] : $this->getVar('mod_author');
227
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR, 'mod_author', 50, 255, $modAuthor), true);
228
        $modLicense = $isNew ? $set['license'] : $this->getVar('mod_license');
229
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_LICENSE, 'mod_license', 50, 255, $modLicense), true);
230
231
        $optionsTray = new XoopsFormElementTray(_OPTIONS, '<br>');
232
        $optionsTray->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
233
        // Check All Modules Options
234
        $checkAllOptions = new XoopsFormCheckBox('', 'modulebox', 1);
235
        $checkAllOptions->addOption('allbox', _AM_TDMCREATE_MODULE_ALL);
236
        $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'moduleform\', \'modulebox\');" ');
237
        $checkAllOptions->setClass('xo-checkall');
238
        $optionsTray->addElement($checkAllOptions);
239
        // Options
240
        $checkbox = new XoopsFormCheckbox(' ', 'module_option', $this->getOptionsModules(), '<br>');
241
        foreach ($this->options as $option) {
242
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_MODULE_' . mb_strtoupper($option)));
243
        }
244
        $optionsTray->addElement($checkbox);
245
246
        $form->addElement($optionsTray);
247
248
        $modImage = $this->getVar('mod_image');
249
        $modImage = $modImage ?: $set['image'];
250
251
        $uploadDirectory = 'uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/modules';
252
        $imgtray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_IMAGE, '<br>');
253
        $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './' . mb_strtolower($uploadDirectory) . '/');
254
        $imageselect = new XoopsFormSelect($imgpath, 'mod_image', $modImage);
255
        $modImageArray = XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH);
256
        foreach ($modImageArray as $image) {
257
            $imageselect->addOption("{$image}", $image);
258
        }
259
        $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"mod_image\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")'");
260
        $imgtray->addElement($imageselect);
261
        $imgtray->addElement(new XoopsFormLabel('', "<br><img src='" . TDMC_UPLOAD_IMGMOD_URL . '/' . $modImage . "' name='image3' id='image3' alt='' /><br>"));
262
263
        $fileseltray = new XoopsFormElementTray('', '<br>');
264
        $fileseltray->addElement(new XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $tdmcreate->getConfig('maxsize')));
265
        $fileseltray->addElement(new XoopsFormLabel(''));
266
        $imgtray->addElement($fileseltray);
267
        $form->addElement($imgtray);
268
        //---------- START LOGO GENERATOR -----------------
269
        $tables_img = $this->getVar('table_image') ?: 'about.png';
270
        $iconsdir = '/Frameworks/moduleclasses/icons/32';
271
        if (is_dir(XOOPS_ROOT_PATH . $iconsdir)) {
272
            $uploadDirectory = $iconsdir;
273
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, ".{$iconsdir}/");
274
        } else {
275
            $uploadDirectory = '/uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/tables';
276
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/tables');
277
        }
278
        $createLogoTray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_CREATENEWLOGO, '<br>');
279
        $iconSelect = new XoopsFormSelect($imgpath, 'tables_img', $tables_img, 8);
280
        $tablesImagesArray = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDirectory);
281
        foreach ($tablesImagesArray as $image) {
282
            $iconSelect->addOption("{$image}", $image);
283
        }
284
        $iconSelect->setExtra(" onchange='showImgSelected2(\"image4\", \"tables_img\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")' ");
285
        $createLogoTray->addElement($iconSelect);
286
        $createLogoTray->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDirectory . '/' . $tables_img . "' name='image4' id='image4' alt='' />"));
287
        // Create preview and submit buttons
288
        $buttonLogoGenerator4 = new XoopsFormButton('', 'button4', _AM_TDMCREATE_MODULE_CREATENEWLOGO, 'button');
289
        $buttonLogoGenerator4->setExtra(" onclick='createNewModuleLogo(\"" . TDMC_URL . "\")' ");
290
        $createLogoTray->addElement($buttonLogoGenerator4);
291
292
        $form->addElement($createLogoTray);
293
        //------------ END LOGO GENERATOR --------------------
294
295
        $modAuthorMail = $isNew ? $set['author_mail'] : $this->getVar('mod_author_mail');
296
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_MAIL, 'mod_author_mail', 50, 255, $modAuthorMail));
297
298
        $modAuthorWebsiteUrl = $isNew ? $set['author_website_url'] : $this->getVar('mod_author_website_url');
299
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_URL, 'mod_author_website_url', 50, 255, $modAuthorWebsiteUrl));
300
301
        $modAuthorWebsiteName = $isNew ? $set['author_website_name'] : $this->getVar('mod_author_website_name');
302
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_NAME, 'mod_author_website_name', 50, 255, $modAuthorWebsiteName));
303
304
        $modCredits = $isNew ? $set['credits'] : $this->getVar('mod_credits');
305
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_CREDITS, 'mod_credits', 50, 255, $modCredits));
306
307
        $modReleaseInfo = $isNew ? $set['release_info'] : $this->getVar('mod_release_info');
308
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_INFO, 'mod_release_info', 50, 255, $modReleaseInfo));
309
310
        $modReleaseFile = $isNew ? $set['release_file'] : $this->getVar('mod_release_file');
311
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_FILE, 'mod_release_file', 50, 255, $modReleaseFile));
312
313
        $modManual = $isNew ? $set['manual'] : $this->getVar('mod_manual');
314
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL, 'mod_manual', 50, 255, $modManual));
315
316
        $modManualFile = $isNew ? $set['manual_file'] : $this->getVar('mod_manual_file');
317
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL_FILE, 'mod_manual_file', 50, 255, $modManualFile));
318
319
        $modDemoSiteUrl = $isNew ? $set['demo_site_url'] : $this->getVar('mod_demo_site_url');
320
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_URL, 'mod_demo_site_url', 50, 255, $modDemoSiteUrl));
321
322
        $modDemoSiteName = $isNew ? $set['demo_site_name'] : $this->getVar('mod_demo_site_name');
323
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_NAME, 'mod_demo_site_name', 50, 255, $modDemoSiteName));
324
325
        $modSupportUrl = $isNew ? $set['support_url'] : $this->getVar('mod_support_url');
326
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_URL, 'mod_support_url', 50, 255, $modSupportUrl));
327
328
        $modSupportName = $isNew ? $set['support_name'] : $this->getVar('mod_support_name');
329
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_NAME, 'mod_support_name', 50, 255, $modSupportName));
330
331
        $modWebsiteUrl = $isNew ? $set['website_url'] : $this->getVar('mod_website_url');
332
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_URL, 'mod_website_url', 50, 255, $modWebsiteUrl));
333
334
        $modWebsiteName = $isNew ? $set['website_name'] : $this->getVar('mod_website_name');
335
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_NAME, 'mod_website_name', 50, 255, $modWebsiteName));
336
337
        $modRelease = $isNew ? $set['release'] : $this->getVar('mod_release');
338
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE, 'mod_release', 50, 255, $modRelease));
339
340
        $modStatus = $isNew ? $set['status'] : $this->getVar('mod_status');
341
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_STATUS, 'mod_status', 50, 255, $modStatus));
342
343
        $modDonations = $isNew ? $set['donations'] : $this->getVar('mod_donations');
344
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_PAYPAL_BUTTON, 'mod_donations', 50, 255, $modDonations));
345
346
        $modSubversion = $isNew ? $set['subversion'] : $this->getVar('mod_subversion');
347
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUBVERSION, 'mod_subversion', 50, 255, $modSubversion));
348
349
        $buttonTray = new XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', '');
350
        $buttonTray->addElement(new XoopsFormHidden('op', 'save'));
351
        $buttonTray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
352
        $form->addElement($buttonTray);
353
354
        return $form;
355
    }
356
357
    /**
358
     *  @private static function createLogo
359
     *  @param mixed $logoIcon
360
     *  @param string $moduleDirname
361
     *
362
     * @return bool|string
363
     */
364
    private static function createLogo($logoIcon, $moduleDirname)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
365
    {
366
        if (!extension_loaded('gd')) {
367
            return false;
368
        }
369
        $requiredFunctions = ['imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate'];
370
        foreach ($requiredFunctions as $func) {
371
            if (!function_exists($func)) {
372
                return false;
373
            }
374
        }
375
376
        if (!file_exists($imageBase = TDMC_IMAGES_LOGOS_PATH . '/empty.png') ||
377
            !file_exists($font = TDMC_FONTS_PATH . '/VeraBd.ttf') ||
378
            !file_exists($iconFile = XOOPS_ICONS32_PATH . '/' . basename($logoIcon))
379
        ) {
380
            return false;
381
        }
382
        $imageModule = imagecreatefrompng($imageBase);
383
        $imageIcon = imagecreatefrompng($iconFile);
384
        // Write text
385
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
386
        $spaceBorder = (92 - mb_strlen($moduleDirname) * 7.5) / 2;
387
        imagefttext($imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), []);
388
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
389
        $logoImg = '/' . $moduleDirname . '_logo.png';
390
        imagepng($imageModule, TDMC_UPLOAD_IMGMOD_PATH . $logoImg);
391
        imagedestroy($imageModule);
392
        imagedestroy($imageIcon);
393
394
        return TDMC_UPLOAD_IMGMOD_URL . $logoImg;
395
    }
396
397
    /**
398
     * Get Values.
399
     *
400
     * @param null $keys
401
     * @param null $format
402
     * @param null $maxDepth
403
     *
404
     * @return array
405
     */
406
    public function getValuesModules($keys = null, $format = null, $maxDepth = null)
407
    {
408
        $ret = $this->getValues($keys, $format, $maxDepth);
409
        // Values
410
        $ret['id'] = $this->getVar('mod_id');
411
        $ret['name'] = $this->getVar('mod_name');
412
        $ret['version'] = $this->getVar('mod_version');
413
        $ret['image'] = $this->getVar('mod_image');
414
        $ret['release'] = $this->getVar('mod_release');
415
        $ret['status'] = $this->getVar('mod_status');
416
        $ret['admin'] = $this->getVar('mod_admin');
417
        $ret['user'] = $this->getVar('mod_user');
418
        $ret['blocks'] = $this->getVar('mod_blocks');
419
        $ret['search'] = $this->getVar('mod_search');
420
        $ret['comments'] = $this->getVar('mod_comments');
421
        $ret['notifications'] = $this->getVar('mod_notifications');
422
        $ret['permissions'] = $this->getVar('mod_permissions');
423
424
        return $ret;
425
    }
426
427
    /**
428
     * Get getOptionsModules.
429
     *
430
     * @return array
431
     */
432
    private function getOptionsModules()
433
    {
434
        $retModules = [];
435
        foreach ($this->options as $option) {
436
            if (1 == $this->getVar('mod_' . $option)) {
437
                $retModules[] = $option;
438
            }
439
        }
440
441
        return $retModules;
442
    }
443
444
    /**
445
     * Get Defined Language.
446
     *
447
     * @param $lang
448
     *
449
     * @return string
450
     */
451
    private static function getDefinedLanguage($lang)
452
    {
453
        if (defined($lang)) {
454
            return constant($lang);
455
        }
456
457
        return $lang;
458
    }
459
}
460
461
/**
462
 *  @Class TDMCreateModulesHandler
463
 *  @extends XoopsPersistableObjectHandler
464
 */
465
class TDMCreateModulesHandler extends XoopsPersistableObjectHandler
466
{
467
    /**
468
     *  @public function constructor class
469
     *
470
     * @param null|XoopsDatabase $db
471
     */
472
    public function __construct(XoopsDatabase $db)
473
    {
474
        parent::__construct($db, 'tdmcreate_modules', 'TDMCreateModules', 'mod_id', 'mod_name');
475
    }
476
477
    /**
478
     * @param bool $isNew
479
     *
480
     * @return XoopsObject
481
     */
482
    public function create($isNew = true)
483
    {
484
        return parent::create($isNew);
485
    }
486
487
    /**
488
     * retrieve a field.
489
     *
490
     * @param int  $i      field id
491
     * @param null $fields
492
     *
493
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
494
     *               object
495
     */
496
    public function get($i = null, $fields = null)
497
    {
498
        return parent::get($i, $fields);
499
    }
500
501
    /**
502
     * get inserted id.
503
     *
504
     * @param null
505
     *
506
     * @return int reference to the {@link TDMCreateTables} object
507
     */
508
    public function getInsertId()
509
    {
510
        return $this->db->getInsertId();
511
    }
512
513
    /**
514
     * Get Count Modules.
515
     *
516
     * @param int    $start
517
     * @param int    $limit
518
     * @param string $sort
519
     * @param string $order
520
     *
521
     * @return int
522
     */
523
    public function getCountModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
524
    {
525
        $crCountModules = new CriteriaCompo();
526
        $crCountModules = $this->getModulesCriteria($crCountModules, $start, $limit, $sort, $order);
527
528
        return $this->getCount($crCountModules);
529
    }
530
531
    /**
532
     * Get All Modules.
533
     *
534
     * @param int    $start
535
     * @param int    $limit
536
     * @param string $sort
537
     * @param string $order
538
     *
539
     * @return array
540
     */
541
    public function getAllModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
542
    {
543
        $crAllModules = new CriteriaCompo();
544
        $crAllModules = $this->getModulesCriteria($crAllModules, $start, $limit, $sort, $order);
545
546
        return $this->getAll($crAllModules);
547
    }
548
549
    /**
550
     * Get Modules Criteria.
551
     *
552
     * @param $crModules
553
     * @param $start
554
     * @param $limit
555
     * @param $sort
556
     * @param $order
557
     *
558
     * @return mixed
559
     */
560
    private function getModulesCriteria($crModules, $start, $limit, $sort, $order)
561
    {
562
        $crModules->setStart($start);
563
        $crModules->setLimit($limit);
564
        $crModules->setSort($sort);
565
        $crModules->setOrder($order);
566
567
        return $crModules;
568
    }
569
}
570