Passed
Branch master (31be8b)
by Gino
03:04
created

TDMCreateModules   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 455
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 57
lcom 1
cbo 1
dl 0
loc 455
rs 6.433

8 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 46 1
A __call() 0 6 2
A getInstance() 0 9 2
F getFormModules() 0 226 39
A getValuesModules() 0 20 1
A getDefinedLanguage() 0 8 2
C createLogo() 0 32 7
A getOptionsModules() 0 11 3

How to fix   Complexity   

Complex Class

Complex classes like TDMCreateModules often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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

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

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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       The XOOPS Project http://sourceforge.net/projects/xoops/
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
*  @Class TDMCreateModules
28
*  @extends XoopsObject
29
*/
30
31
/**
32
 * Class TDMCreateModules.
33
 */
34
class TDMCreateModules extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
35
{
36
    /**
37
     * Tdmcreate.
38
     *
39
     * @var mixed
40
     */
41
    private $tdmcreate = null;
42
43
    /**
44
     * Settings.
45
     *
46
     * @var mixed
47
     */
48
    private $settings = null;
49
50
    /**
51
     * Options.
52
     */
53
    public $options = array(
54
        'admin',
55
        'user',
56
        'blocks',
57
        'search',
58
        'comments',
59
        'notifications',
60
        'permissions',
61
        'inroot_copy',
62
    );
63
64
    /*
65
    *  @public function constructor class
66
    *  @param null
67
    */
68
    /**
69
     *
70
     */
71
    public function __construct()
72
    {
73
        $this->tdmcreate = TDMCreateHelper::getInstance();
74
        $setId = XoopsRequest::getInt('set_id');
75
        $this->settings = $this->tdmcreate->getHandler('settings')->get($setId);
0 ignored issues
show
Bug introduced by
The method get cannot be called on $this->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...
76
        //
77
        $this->initVar('mod_id', XOBJ_DTYPE_INT);
78
        $this->initVar('mod_name', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_name'));
79
        $this->initVar('mod_dirname', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_dirname'));
80
        $this->initVar('mod_version', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_version'));
81
        $this->initVar('mod_since', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_since'));
82
        $this->initVar('mod_min_php', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_min_php'));
83
        $this->initVar('mod_min_xoops', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_min_xoops'));
84
        $this->initVar('mod_min_admin', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_min_admin'));
85
        $this->initVar('mod_min_mysql', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_min_mysql'));
86
        $this->initVar('mod_description', XOBJ_DTYPE_TXTAREA, $this->settings->getVar('set_description'));
87
        $this->initVar('mod_author', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_author'));
88
        $this->initVar('mod_author_mail', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_author_mail'));
89
        $this->initVar('mod_author_website_url', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_author_website_url'));
90
        $this->initVar('mod_author_website_name', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_author_website_name'));
91
        $this->initVar('mod_credits', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_credits'));
92
        $this->initVar('mod_license', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_license'));
93
        $this->initVar('mod_release_info', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_release_info'));
94
        $this->initVar('mod_release_file', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_release_file'));
95
        $this->initVar('mod_manual', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_manual'));
96
        $this->initVar('mod_manual_file', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_manual_file'));
97
        $this->initVar('mod_image', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_image'));
98
        $this->initVar('mod_demo_site_url', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_demo_site_url'));
99
        $this->initVar('mod_demo_site_name', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_demo_site_name'));
100
        $this->initVar('mod_support_url', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_support_url'));
101
        $this->initVar('mod_support_name', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_support_name'));
102
        $this->initVar('mod_website_url', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_website_url'));
103
        $this->initVar('mod_website_name', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_website_name'));
104
        $this->initVar('mod_release', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_release'));
105
        $this->initVar('mod_status', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_status'));
106
        $this->initVar('mod_admin', XOBJ_DTYPE_INT, $this->settings->getVar('set_admin'));
107
        $this->initVar('mod_user', XOBJ_DTYPE_INT, $this->settings->getVar('set_user'));
108
        $this->initVar('mod_blocks', XOBJ_DTYPE_INT, $this->settings->getVar('set_blocks'));
109
        $this->initVar('mod_search', XOBJ_DTYPE_INT, $this->settings->getVar('set_search'));
110
        $this->initVar('mod_comments', XOBJ_DTYPE_INT, $this->settings->getVar('set_comments'));
111
        $this->initVar('mod_notifications', XOBJ_DTYPE_INT, $this->settings->getVar('set_notifications'));
112
        $this->initVar('mod_permissions', XOBJ_DTYPE_INT, $this->settings->getVar('set_permissions'));
113
        $this->initVar('mod_inroot_copy', XOBJ_DTYPE_INT, $this->settings->getVar('set_inroot_copy'));
114
        $this->initVar('mod_donations', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_donations'));
115
        $this->initVar('mod_subversion', XOBJ_DTYPE_TXTBOX, $this->settings->getVar('set_subversion'));
116
    }
117
118
    /**
119
     * @param string $method
120
     * @param array  $args
121
     *
122
     * @return mixed
123
     */
124
    public function __call($method, $args)
125
    {
126
        $arg = isset($args[0]) ? $args[0] : null;
127
128
        return $this->getVar($method, $arg);
129
    }
130
131
    /*
132
    *  @static function &getInstance
133
    *  @param null
134
    */
135
    /**
136
     * @return TDMCreateModules
137
     */
138
    public static function &getInstance()
139
    {
140
        static $instance = false;
141
        if (!$instance) {
142
            $instance = new self();
143
        }
144
145
        return $instance;
146
    }
147
148
    /*
149
    *  @public function getFormModules
150
    *  @param mixed $action
151
    */
152
    /**
153
     * @param bool $action
154
     *
155
     * @return XoopsThemeForm
156
     */
157
    public function getFormModules($action = false)
158
    {
159
        //
160
        if ($action === false) {
161
            $action = $_SERVER['REQUEST_URI'];
162
        }
163
        $set = array();
164
        $settings = $this->tdmcreate->getHandler('settings')->getAllSettings(0, 0, 'set_type');
165
        foreach ($settings as $setting) {
166
            $set['name'] = $setting->getVar('set_name');
167
            $set['dirname'] = $setting->getVar('set_dirname');
168
            $set['version'] = $setting->getVar('set_version');
169
            $set['since'] = $setting->getVar('set_since');
170
            $set['min_php'] = $setting->getVar('set_min_php');
171
            $set['min_xoops'] = $setting->getVar('set_min_xoops');
172
            $set['min_admin'] = $setting->getVar('set_min_admin');
173
            $set['min_mysql'] = $setting->getVar('set_min_mysql');
174
            $set['description'] = $setting->getVar('set_description');
175
            $set['author'] = $setting->getVar('set_author');
176
            $set['license'] = $setting->getVar('set_license');
177
            $set['admin'] = $setting->getVar('set_admin');
178
            $set['user'] = $setting->getVar('set_user');
179
            $set['blocks'] = $setting->getVar('set_blocks');
180
            $set['search'] = $setting->getVar('set_search');
181
            $set['comments'] = $setting->getVar('set_comments');
182
            $set['notifications'] = $setting->getVar('set_notifications');
183
            $set['permissions'] = $setting->getVar('set_permissions');
184
            $set['inroot'] = $setting->getVar('set_inroot_copy');
185
            $set['image'] = $setting->getVar('set_image');
186
            $set['author_mail'] = $setting->getVar('set_author_mail');
187
            $set['author_website_url'] = $setting->getVar('set_author_website_url');
188
            $set['author_website_name'] = $setting->getVar('set_author_website_name');
189
            $set['credits'] = $setting->getVar('set_credits');
190
            $set['release_info'] = $setting->getVar('set_release_info');
191
            $set['release_file'] = $setting->getVar('set_release_file');
192
            $set['manual'] = $setting->getVar('set_manual');
193
            $set['manual_file'] = $setting->getVar('set_manual_file');
194
            $set['demo_site_url'] = $setting->getVar('set_demo_site_url');
195
            $set['demo_site_name'] = $setting->getVar('set_demo_site_name');
196
            $set['support_url'] = $setting->getVar('set_support_url');
197
            $set['support_name'] = $setting->getVar('set_support_name');
198
            $set['website_url'] = $setting->getVar('set_website_url');
199
            $set['website_name'] = $setting->getVar('set_website_name');
200
            $set['release'] = $setting->getVar('set_release');
201
            $set['status'] = $setting->getVar('set_status');
202
            $set['donations'] = $setting->getVar('set_donations');
203
            $set['subversion'] = $setting->getVar('set_subversion');
204
        }
205
        //
206
        $isNew = $this->isNew();
207
        $title = $isNew ? sprintf(_AM_TDMCREATE_MODULE_NEW) : sprintf(_AM_TDMCREATE_MODULE_EDIT);
208
        //
209
        include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
210
        //
211
        $form = new XoopsThemeForm($title, 'moduleform', $action, 'post', true);
212
        $form->setExtra('enctype="multipart/form-data"');
213
        //
214
        $modName = $isNew ? $set['name'] : $this->getVar('mod_name');
215
        $modName = new XoopsFormText(_AM_TDMCREATE_MODULE_NAME, 'mod_name', 50, 255, $modName);
216
        $modName->setDescription(_AM_TDMCREATE_MODULE_NAME_DESC);
217
        $form->addElement($modName, true);
218
        //
219
        $modDirname = $isNew ? $set['dirname'] : $this->getVar('mod_dirname');
220
        $modDirname = new XoopsFormText(_AM_TDMCREATE_MODULE_DIRNAME, 'mod_dirname', 25, 255, $modDirname);
221
        $modDirname->setDescription(_AM_TDMCREATE_MODULE_DIRNAME_DESC);
222
        $form->addElement($modDirname, true);
223
        //
224
        $modVersion = $isNew ? $set['version'] : $this->getVar('mod_version');
225
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_VERSION, 'mod_version', 10, 25, $modVersion), true);
226
        //
227
        $modSince = $isNew ? $set['since'] : $this->getVar('mod_since');
228
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SINCE, 'mod_since', 10, 25, $modSince), true);
229
        //
230
        $modMinPhp = $isNew ? $set['min_php'] : $this->getVar('mod_min_php');
231
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_PHP, 'mod_min_php', 10, 25, $modMinPhp), true);
232
        //
233
        $modMinXoops = $isNew ? $set['min_xoops'] : $this->getVar('mod_min_xoops');
234
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_XOOPS, 'mod_min_xoops', 10, 25, $modMinXoops), true);
235
        //
236
        $modMinAdmin = $isNew ? $set['min_admin'] : $this->getVar('mod_min_admin');
237
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_ADMIN, 'mod_min_admin', 10, 25, $modMinAdmin), true);
238
        //
239
        $modMinMysql = $isNew ? $set['min_mysql'] : $this->getVar('mod_min_mysql');
240
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MIN_MYSQL, 'mod_min_mysql', 10, 25, $modMinMysql), true);
241
        // Name description
242
        $editorConfigs = array();
243
        $editorConfigs['name'] = 'mod_description';
244
        $editorConfigs['value'] = $isNew ? $set['description'] : $this->getVar('mod_description', 'e');
245
        $editorConfigs['rows'] = 5;
246
        $editorConfigs['cols'] = 100;
247
        $editorConfigs['width'] = '50%';
248
        $editorConfigs['height'] = '100px';
249
        $editorConfigs['editor'] = $this->tdmcreate->getConfig('tdmcreate_editor');
250
        $form->addElement(new XoopsFormEditor(_AM_TDMCREATE_MODULE_DESCRIPTION, 'mod_description', $editorConfigs), true);
251
        // Author
252
        $modAuthor = $isNew ? $set['author'] : $this->getVar('mod_author');
253
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR, 'mod_author', 50, 255, $modAuthor), true);
254
        $modLicense = $isNew ? $set['license'] : $this->getVar('mod_license');
255
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_LICENSE, 'mod_license', 50, 255, $modLicense), true);
256
        //
257
        $optionsTray = new XoopsFormElementTray(_OPTIONS, '<br />');
258
        $optionsTray->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
259
        // Check All Modules Options
260
        $checkAllOptions = new XoopsFormCheckBox('', 'modulebox', 1);
261
        $checkAllOptions->addOption('allbox', _AM_TDMCREATE_MODULE_ALL);
262
        $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'moduleform\', \'modulebox\');" ');
263
        $checkAllOptions->setClass('xo-checkall');
264
        $optionsTray->addElement($checkAllOptions);
265
        // Options
266
        $checkbox = new XoopsFormCheckbox(' ', 'module_option', $this->getOptionsModules(), '<br />');
267
        foreach ($this->options as $option) {
268
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_MODULE_'.strtoupper($option)));
269
        }
270
        $optionsTray->addElement($checkbox);
271
        //
272
        $form->addElement($optionsTray);
273
        //
274
        $modImage = $this->getVar('mod_image');
275
        $modImage = $modImage ? $modImage : $set['image'];
276
        //
277
        $uploadDirectory = 'uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/modules';
278
        $imgtray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_IMAGE, '<br />');
279
        $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './'.strtolower($uploadDirectory).'/');
280
        $imageselect = new XoopsFormSelect($imgpath, 'mod_image', $modImage);
281
        $modImageArray = XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH);
282
        foreach ($modImageArray as $image) {
283
            $imageselect->addOption("{$image}", $image);
284
        }
285
        $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"mod_image\", \"".$uploadDirectory.'", "", "'.XOOPS_URL."\")'");
286
        $imgtray->addElement($imageselect);
287
        $imgtray->addElement(new XoopsFormLabel('', "<br /><img src='".TDMC_UPLOAD_IMGMOD_URL.'/'.$modImage."' name='image3' id='image3' alt='' /><br />"));
288
        //
289
        $fileseltray = new XoopsFormElementTray('', '<br />');
290
        $fileseltray->addElement(new XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $this->tdmcreate->getConfig('maxsize')));
291
        $fileseltray->addElement(new XoopsFormLabel(''));
292
        $imgtray->addElement($fileseltray);
293
        $form->addElement($imgtray);
294
        //---------- START LOGO GENERATOR -----------------
295
        $tables_img = $this->getVar('table_image') ?: 'about.png';
296
        $iconsdir = '/Frameworks/moduleclasses/icons/32';
297
        if (is_dir(XOOPS_ROOT_PATH.$iconsdir)) {
298
            $uploadDirectory = $iconsdir;
299
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, ".{$iconsdir}/");
300
        } else {
301
            $uploadDirectory = '/uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/tables';
302
            $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './uploads/'.$GLOBALS['xoopsModule']->dirname().'/images/tables');
303
        }
304
        $createLogoTray = new XoopsFormElementTray(_AM_TDMCREATE_MODULE_CREATENEWLOGO, '<br />');
305
        $iconSelect = new XoopsFormSelect($imgpath, 'tables_img', $tables_img, 8);
306
        $tablesImagesArray = XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH.$uploadDirectory);
307
        foreach ($tablesImagesArray as $image) {
308
            $iconSelect->addOption("{$image}", $image);
309
        }
310
        $iconSelect->setExtra(" onchange='showImgSelected2(\"image4\", \"tables_img\", \"".$uploadDirectory.'", "", "'.XOOPS_URL."\")' ");
311
        $createLogoTray->addElement($iconSelect);
312
        $createLogoTray->addElement(new XoopsFormLabel('', "<br /><img src='".XOOPS_URL.'/'.$uploadDirectory.'/'.$tables_img."' name='image4' id='image4' alt='' />"));
313
        // Create preview and submit buttons
314
        $buttonLogoGenerator4 = new XoopsFormButton('', 'button4', _AM_TDMCREATE_MODULE_CREATENEWLOGO, 'button');
315
        $buttonLogoGenerator4->setExtra(" onclick='createNewModuleLogo(\"".TDMC_URL."\")' ");
316
        $createLogoTray->addElement($buttonLogoGenerator4);
317
        //
318
        $form->addElement($createLogoTray);
319
        //------------ END LOGO GENERATOR --------------------
320
        //
321
        $modAuthorMail = $isNew ? $set['author_mail'] : $this->getVar('mod_author_mail');
322
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_MAIL, 'mod_author_mail', 50, 255, $modAuthorMail));
323
        //
324
        $modAuthorWebsiteUrl = $isNew ? $set['author_website_url'] : $this->getVar('mod_author_website_url');
325
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_URL, 'mod_author_website_url', 50, 255, $modAuthorWebsiteUrl));
326
        //
327
        $modAuthorWebsiteName = $isNew ? $set['author_website_name'] : $this->getVar('mod_author_website_name');
328
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_AUTHOR_WEBSITE_NAME, 'mod_author_website_name', 50, 255, $modAuthorWebsiteName));
329
        //
330
        $modCredits = $isNew ? $set['credits'] : $this->getVar('mod_credits');
331
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_CREDITS, 'mod_credits', 50, 255, $modCredits));
332
        //
333
        $modReleaseInfo = $isNew ? $set['release_info'] : $this->getVar('mod_release_info');
334
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_INFO, 'mod_release_info', 50, 255, $modReleaseInfo));
335
        //
336
        $modReleaseFile = $isNew ? $set['release_file'] : $this->getVar('mod_release_file');
337
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE_FILE, 'mod_release_file', 50, 255, $modReleaseFile));
338
        //
339
        $modManual = $isNew ? $set['manual'] : $this->getVar('mod_manual');
340
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL, 'mod_manual', 50, 255, $modManual));
341
        //
342
        $modManualFile = $isNew ? $set['manual_file'] : $this->getVar('mod_manual_file');
343
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_MANUAL_FILE, 'mod_manual_file', 50, 255, $modManualFile));
344
        //
345
        $modDemoSiteUrl = $isNew ? $set['demo_site_url'] : $this->getVar('mod_demo_site_url');
346
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_URL, 'mod_demo_site_url', 50, 255, $modDemoSiteUrl));
347
        //
348
        $modDemoSiteName = $isNew ? $set['demo_site_name'] : $this->getVar('mod_demo_site_name');
349
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_DEMO_SITE_NAME, 'mod_demo_site_name', 50, 255, $modDemoSiteName));
350
        //
351
        $modSupportUrl = $isNew ? $set['support_url'] : $this->getVar('mod_support_url');
352
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_URL, 'mod_support_url', 50, 255, $modSupportUrl));
353
        //
354
        $modSupportName = $isNew ? $set['support_name'] : $this->getVar('mod_support_name');
355
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUPPORT_NAME, 'mod_support_name', 50, 255, $modSupportName));
356
        //
357
        $modWebsiteUrl = $isNew ? $set['website_url'] : $this->getVar('mod_website_url');
358
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_URL, 'mod_website_url', 50, 255, $modWebsiteUrl));
359
        //
360
        $modWebsiteName = $isNew ? $set['website_name'] : $this->getVar('mod_website_name');
361
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_WEBSITE_NAME, 'mod_website_name', 50, 255, $modWebsiteName));
362
        //
363
        $modRelease = $isNew ? $set['release'] : $this->getVar('mod_release');
364
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_RELEASE, 'mod_release', 50, 255, $modRelease));
365
        //
366
        $modStatus = $isNew ? $set['status'] : $this->getVar('mod_status');
367
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_STATUS, 'mod_status', 50, 255, $modStatus));
368
        //
369
        $modDonations = $isNew ? $set['donations'] : $this->getVar('mod_donations');
370
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_PAYPAL_BUTTON, 'mod_donations', 50, 255, $modDonations));
371
        //
372
        $modSubversion = $isNew ? $set['subversion'] : $this->getVar('mod_subversion');
373
        $form->addElement(new XoopsFormText(_AM_TDMCREATE_MODULE_SUBVERSION, 'mod_subversion', 50, 255, $modSubversion));
374
        //
375
        $buttonTray = new XoopsFormElementTray(_REQUIRED.' <sup class="red bold">*</sup>', '');
376
        $buttonTray->addElement(new XoopsFormHidden('op', 'save'));
377
        $buttonTray->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
378
        $form->addElement($buttonTray);
379
        $form->addElement($tabTray);
0 ignored issues
show
Bug introduced by
The variable $tabTray does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
380
381
        return $form;
382
    }
383
384
    /*
385
    *  @private static function createLogo
386
    *  @param mixed $logoIcon
387
    *  @param string $moduleDirname
388
    */
389
    /**
390
     * @param $logoIcon
391
     * @param $moduleDirname
392
     *
393
     * @return bool|string
394
     */
395
    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...
396
    {
397
        if (!extension_loaded('gd')) {
398
            return false;
399
        } else {
400
            $requiredFunctions = array('imagecreatefrompng', 'imagefttext', 'imagecopy', 'imagepng', 'imagedestroy', 'imagecolorallocate');
401
            foreach ($requiredFunctions as $func) {
402
                if (!function_exists($func)) {
403
                    return false;
404
                }
405
            }
406
        }
407
        if (!file_exists($imageBase = TDMC_IMAGES_LOGOS_PATH.'/empty.png') ||
408
            !file_exists($font = TDMC_FONTS_PATH.'/VeraBd.ttf') ||
409
            !file_exists($iconFile = XOOPS_ICONS32_PATH.'/'.basename($logoIcon))
410
        ) {
411
            return false;
412
        }
413
        $imageModule = imagecreatefrompng($imageBase);
414
        $imageIcon = imagecreatefrompng($iconFile);
415
        // Write text
416
        $textColor = imagecolorallocate($imageModule, 0, 0, 0);
417
        $spaceBorder = (92 - strlen($moduleDirname) * 7.5) / 2;
418
        imagefttext($imageModule, 8.5, 0, $spaceBorder, 45, $textColor, $font, ucfirst($moduleDirname), array());
419
        imagecopy($imageModule, $imageIcon, 29, 2, 0, 0, 32, 32);
420
        $logoImg = '/'.$moduleDirname.'_logo.png';
421
        imagepng($imageModule, TDMC_UPLOAD_IMGMOD_PATH.$logoImg);
422
        imagedestroy($imageModule);
423
        imagedestroy($imageIcon);
424
425
        return TDMC_UPLOAD_IMGMOD_URL.$logoImg;
426
    }
427
428
    /**
429
     * Get Values.
430
     */
431
    public function getValuesModules($keys = null, $format = null, $maxDepth = null)
432
    {
433
        $ret = parent::getValues($keys, $format, $maxDepth);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getValues() instead of getValuesModules()). Are you sure this is correct? If so, you might want to change this to $this->getValues().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
434
        // Values
435
        $ret['id'] = $this->getVar('mod_id');
436
        $ret['name'] = $this->getVar('mod_name');
437
        $ret['version'] = $this->getVar('mod_version');
438
        $ret['image'] = $this->getVar('mod_image');
439
        $ret['release'] = $this->getVar('mod_release');
440
        $ret['status'] = $this->getVar('mod_status');
441
        $ret['admin'] = $this->getVar('mod_admin');
442
        $ret['user'] = $this->getVar('mod_user');
443
        $ret['blocks'] = $this->getVar('mod_blocks');
444
        $ret['search'] = $this->getVar('mod_search');
445
        $ret['comments'] = $this->getVar('mod_comments');
446
        $ret['notifications'] = $this->getVar('mod_notifications');
447
        $ret['permissions'] = $this->getVar('mod_permissions');
448
449
        return $ret;
450
    }
451
452
    /**
453
     * Get Options.
454
     */
455
    /**
456
     * @param $key
457
     *
458
     * @return string
459
     */
460
    private function getOptionsModules()
461
    {
462
        $retModules = array();
463
        foreach ($this->options as $option) {
464
            if ($this->getVar('mod_'.$option) == 1) {
465
                array_push($retModules, $option);
466
            }
467
        }
468
469
        return $retModules;
470
    }
471
472
    /**
473
     * Get Defined Language.
474
     */
475
    /**
476
     * @param $lang
477
     *
478
     * @return string
479
     */
480
    private static function getDefinedLanguage($lang)
481
    {
482
        if (defined($lang)) {
483
            return constant($lang);
484
        }
485
486
        return $lang;
487
    }
488
}
489
490
/*
491
*  @Class TDMCreateModulesHandler
492
*  @extends XoopsPersistableObjectHandler
493
*/
494
495
/**
496
 * Class TDMCreateModulesHandler.
497
 */
498
class TDMCreateModulesHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
499
{
500
    /*
501
    *  @public function constructor class
502
    *  @param mixed $db
503
    */
504
    /**
505
     * @param null|object $db
506
     */
507
    public function __construct(&$db)
508
    {
509
        parent::__construct($db, 'tdmcreate_modules', 'tdmcreatemodules', 'mod_id', 'mod_name');
510
    }
511
512
    /**
513
     * @param bool $isNew
514
     *
515
     * @return object
516
     */
517
    public function &create($isNew = true)
518
    {
519
        return parent::create($isNew);
520
    }
521
522
    /**
523
     * retrieve a field.
524
     *
525
     * @param int  $i      field id
526
     * @param null $fields
527
     *
528
     * @return mixed reference to the <a href='psi_element://TDMCreateFields'>TDMCreateFields</a> object
529
     *               object
530
     */
531
    public function &get($i = null, $fields = null)
532
    {
533
        return parent::get($i, $fields);
534
    }
535
536
    /**
537
     * get inserted id.
538
     *
539
     * @param null
540
     *
541
     * @return int reference to the {@link TDMCreateTables} object
542
     */
543
    public function &getInsertId()
544
    {
545
        return $this->db->getInsertId();
546
    }
547
548
    /**
549
     * insert a new field in the database.
550
     *
551
     * @param object $field reference to the {@link TDMCreateFields} object
552
     * @param bool   $force
553
     *
554
     * @return bool FALSE if failed, TRUE if already present and unchanged or successful
555
     */
556
    public function &insert(&$field, $force = false)
557
    {
558
        if (!parent::insert($field, $force)) {
559
            return false;
560
        }
561
562
        return true;
563
    }
564
565
    /**
566
     * Get Count Modules.
567
     */
568
    public function getCountModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
569
    {
570
        $criteriaCountModules = new CriteriaCompo();
571
        $criteriaCountModules = $this->getModulesCriteria($criteriaCountModules, $start, $limit, $sort, $order);
572
573
        return $this->getCount($criteriaCountModules);
574
    }
575
576
    /**
577
     * Get All Modules.
578
     */
579
    public function getAllModules($start = 0, $limit = 0, $sort = 'mod_id ASC, mod_name', $order = 'ASC')
580
    {
581
        $criteriaAllModules = new CriteriaCompo();
582
        $criteriaAllModules = $this->getModulesCriteria($criteriaAllModules, $start, $limit, $sort, $order);
583
584
        return $this->getAll($criteriaAllModules);
585
    }
586
587
    /**
588
     * Get Modules Criteria.
589
     */
590
    private function getModulesCriteria($criteriaModules, $start, $limit, $sort, $order)
591
    {
592
        $criteriaModules->setStart($start);
593
        $criteriaModules->setLimit($limit);
594
        $criteriaModules->setSort($sort);
595
        $criteriaModules->setOrder($order);
596
597
        return $criteriaModules;
598
    }
599
}
600