Settings::getDefinedLanguage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php namespace XoopsModules\Tdmcreate;
2
3
use XoopsModules\Tdmcreate;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * settings class.
17
 *
18
 * @copyright       XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
20
 *
21
 * @since           2.5.7
22
 *
23
 * @author          TDM TEAM DEV MODULE
24
 *
25
 * @version         $Id: settings.php 13070 2015-05-19 12:24:20Z timgno $
26
 */
27
// include __DIR__ . '/autoload.php';
28
/*
29
*  @Class Settings
30
*  @extends \XoopsObject
31
*/
32
33
/**
34
 * Class Settings.
35
 */
36
class Settings extends \XoopsObject
37
{
38
    /**
39
     * Options.
40
     */
41
    public $options = [
42
        'admin',
43
        'user',
44
        'blocks',
45
        'search',
46
        'comments',
47
        'notifications',
48
        'permissions',
49
        'inroot_copy',
50
    ];
51
52
    /**
53
     *  @public function constructor class
54
     *
55
     *  @param null
56
     */
57
    public function __construct()
58
    {
59
        $helper = Tdmcreate\Helper::getInstance();
60
        $this->initVar('set_id', XOBJ_DTYPE_INT);
61
        $this->initVar('set_name', XOBJ_DTYPE_TXTBOX, $helper->getConfig('name'));
62
        $this->initVar('set_dirname', XOBJ_DTYPE_TXTBOX, $helper->getConfig('dirname'));
63
        $this->initVar('set_version', XOBJ_DTYPE_TXTBOX, $helper->getConfig('version'));
64
        $this->initVar('set_since', XOBJ_DTYPE_TXTBOX, $helper->getConfig('since'));
65
        $this->initVar('set_min_php', XOBJ_DTYPE_TXTBOX, $helper->getConfig('min_php'));
66
        $this->initVar('set_min_xoops', XOBJ_DTYPE_TXTBOX, $helper->getConfig('min_xoops'));
67
        $this->initVar('set_min_admin', XOBJ_DTYPE_TXTBOX, $helper->getConfig('min_admin'));
68
        $this->initVar('set_min_mysql', XOBJ_DTYPE_TXTBOX, $helper->getConfig('min_mysql'));
69
        $this->initVar('set_description', XOBJ_DTYPE_TXTAREA, $helper->getConfig('description'));
70
        $this->initVar('set_author', XOBJ_DTYPE_TXTBOX, $helper->getConfig('author'));
71
        $this->initVar('set_author_mail', XOBJ_DTYPE_TXTBOX, $helper->getConfig('author_email'));
72
        $this->initVar('set_author_website_url', XOBJ_DTYPE_TXTBOX, $helper->getConfig('author_website_url'));
73
        $this->initVar('set_author_website_name', XOBJ_DTYPE_TXTBOX, $helper->getConfig('author_website_name'));
74
        $this->initVar('set_credits', XOBJ_DTYPE_TXTBOX, $helper->getConfig('credits'));
75
        $this->initVar('set_license', XOBJ_DTYPE_TXTBOX, $helper->getConfig('license'));
76
        $this->initVar('set_release_info', XOBJ_DTYPE_TXTBOX, $helper->getConfig('release_info'));
77
        $this->initVar('set_release_file', XOBJ_DTYPE_TXTBOX, $helper->getConfig('release_file'));
78
        $this->initVar('set_manual', XOBJ_DTYPE_TXTBOX, $helper->getConfig('manual'));
79
        $this->initVar('set_manual_file', XOBJ_DTYPE_TXTBOX, $helper->getConfig('manual_file'));
80
        $this->initVar('set_image', XOBJ_DTYPE_TXTBOX, $helper->getConfig('image'));
81
        $this->initVar('set_demo_site_url', XOBJ_DTYPE_TXTBOX, $helper->getConfig('demo_site_url'));
82
        $this->initVar('set_demo_site_name', XOBJ_DTYPE_TXTBOX, $helper->getConfig('demo_site_name'));
83
        $this->initVar('set_support_url', XOBJ_DTYPE_TXTBOX, $helper->getConfig('support_url'));
84
        $this->initVar('set_support_name', XOBJ_DTYPE_TXTBOX, $helper->getConfig('support_name'));
85
        $this->initVar('set_website_url', XOBJ_DTYPE_TXTBOX, $helper->getConfig('website_url'));
86
        $this->initVar('set_website_name', XOBJ_DTYPE_TXTBOX, $helper->getConfig('website_name'));
87
        $this->initVar('set_release', XOBJ_DTYPE_TXTBOX, $helper->getConfig('release_date'));
88
        $this->initVar('set_status', XOBJ_DTYPE_TXTBOX, $helper->getConfig('status'));
89
        $this->initVar('set_admin', XOBJ_DTYPE_INT, $helper->getConfig('display_admin'));
90
        $this->initVar('set_user', XOBJ_DTYPE_INT, $helper->getConfig('display_user'));
91
        $this->initVar('set_blocks', XOBJ_DTYPE_INT, $helper->getConfig('active_blocks'));
92
        $this->initVar('set_search', XOBJ_DTYPE_INT, $helper->getConfig('active_search'));
93
        $this->initVar('set_comments', XOBJ_DTYPE_INT, $helper->getConfig('active_comments'));
94
        $this->initVar('set_notifications', XOBJ_DTYPE_INT, $helper->getConfig('active_notifications'));
95
        $this->initVar('set_permissions', XOBJ_DTYPE_INT, $helper->getConfig('active_permissions'));
96
        $this->initVar('set_inroot_copy', XOBJ_DTYPE_INT, $helper->getConfig('inroot_copy'));
97
        $this->initVar('set_donations', XOBJ_DTYPE_TXTBOX, $helper->getConfig('donations'));
98
        $this->initVar('set_subversion', XOBJ_DTYPE_TXTBOX, $helper->getConfig('subversion'));
99
        $this->initVar('set_type', XOBJ_DTYPE_TXTBOX);
100
    }
101
102
    /**
103
     * @param string $method
104
     * @param array  $args
105
     *
106
     * @return mixed
107
     */
108
    public function __call($method, $args)
109
    {
110
        $arg = isset($args[0]) ? $args[0] : null;
111
112
        return $this->getVar($method, $arg);
113
    }
114
115
    /**
116
     *  @static function getInstance
117
     *
118
     *  @param null
119
     *
120
     * @return Settings
121
     */
122
    public static function getInstance()
123
    {
124
        static $instance = false;
125
        if (!$instance) {
126
            $instance = new self();
127
        }
128
129
        return $instance;
130
    }
131
132
    /**
133
     * @public function getForm
134
     *
135
     * @param bool|mixed $action
136
     * @return \XoopsThemeForm
137
     */
138
    public function getFormSettings($action = false)
139
    {
140
        $helper = Tdmcreate\Helper::getInstance();
141
        if (false === $action) {
142
            $action = $_SERVER['REQUEST_URI'];
143
        }
144
145
        $isNew = $this->isNew();
146
        $title = $isNew ? sprintf(_AM_TDMCREATE_SETTING_NEW) : sprintf(_AM_TDMCREATE_SETTING_EDIT);
147
148
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
149
150
        $form = new \XoopsThemeForm($title, 'settingform', $action, 'post', true);
151
        $form->setExtra('enctype="multipart/form-data"');
152
153
        $form->addElement(new \XoopsFormHidden('set_id', $this->getVar('set_id')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('set_id') can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

153
        $form->addElement(new \XoopsFormHidden('set_id', /** @scrutinizer ignore-type */ $this->getVar('set_id')));
Loading history...
154
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_NAME, 'set_name', 50, 255, $this->getVar('set_name')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('set_name') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

154
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_NAME, 'set_name', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('set_name')));
Loading history...
155
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DIRNAME, 'set_dirname', 25, 255, $this->getVar('set_dirname')));
156
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_VERSION, 'set_version', 10, 25, $this->getVar('set_version')));
157
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SINCE, 'set_since', 10, 25, $this->getVar('set_since')));
158
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_PHP, 'set_min_php', 10, 25, $this->getVar('set_min_php')));
159
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_XOOPS, 'set_min_xoops', 10, 25, $this->getVar('set_min_xoops')));
160
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_ADMIN, 'set_min_admin', 10, 25, $this->getVar('set_min_admin')));
161
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MIN_MYSQL, 'set_min_mysql', 10, 25, $this->getVar('set_min_mysql')));
162
        $form->addElement(new \XoopsFormTextArea(_AM_TDMCREATE_SETTING_DESCRIPTION, 'set_description', $this->getVar('set_description'), 4, 25));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('set_description') can also be of type array and array; however, parameter $value of XoopsFormTextArea::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

162
        $form->addElement(new \XoopsFormTextArea(_AM_TDMCREATE_SETTING_DESCRIPTION, 'set_description', /** @scrutinizer ignore-type */ $this->getVar('set_description'), 4, 25));
Loading history...
163
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR, 'set_author', 50, 255, $this->getVar('set_author')));
164
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_LICENSE, 'set_license', 50, 255, $this->getVar('set_license')));
165
        // Check All Settings Options
166
        $optionsTray = new \XoopsFormElementTray(_OPTIONS, '<br>');
167
        $checkAllOptions = new \XoopsFormCheckBox('', 'settingbox', 1);
168
        $checkAllOptions->addOption('allbox', _AM_TDMCREATE_SETTING_ALL);
169
        $checkAllOptions->setExtra(' onclick="xoopsCheckAll(\'settingform\', \'settingbox\');" ');
170
        $checkAllOptions->setClass('xo-checkall');
171
        $optionsTray->addElement($checkAllOptions);
172
        // Options
173
        $settingOption = $this->getOptionsSettings();
174
        $checkbox = new \XoopsFormCheckbox(' ', 'setting_option', $settingOption, '<br>');
175
        $checkbox->setDescription(_AM_TDMCREATE_OPTIONS_DESC);
176
        foreach ($this->options as $option) {
177
            $checkbox->addOption($option, self::getDefinedLanguage('_AM_TDMCREATE_SETTING_' . mb_strtoupper($option)));
178
        }
179
        $optionsTray->addElement($checkbox);
180
181
        $form->addElement($optionsTray);
182
183
        $modImage = $this->getVar('set_image');
184
        $modImage = $modImage ?: $set['image'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $set seems to be never defined.
Loading history...
185
186
        $uploadDirectory = 'uploads/' . $GLOBALS['xoopsModule']->dirname() . '/images/modules';
187
        $imgtray = new \XoopsFormElementTray(_AM_TDMCREATE_SETTING_IMAGE, '<br>');
188
        $imgpath = sprintf(_AM_TDMCREATE_FORMIMAGE_PATH, './' . mb_strtolower($uploadDirectory) . '/');
189
        $imageSelect = new \XoopsFormSelect($imgpath, 'set_image', $modImage);
190
        $modImage_array = \XoopsLists::getImgListAsArray(TDMC_UPLOAD_IMGMOD_PATH);
191
        foreach ($modImage_array as $image) {
192
            $imageSelect->addOption($image, $image);
193
        }
194
        $imageSelect->setExtra("onchange='showImgSelected(\"image3\", \"set_image\", \"" . $uploadDirectory . '", "", "' . XOOPS_URL . "\")'");
195
        $imgtray->addElement($imageSelect);
196
        $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . TDMC_UPLOAD_IMGMOD_URL . '/' . $modImage . "' name='image3' id='image3' alt='' /><br>"));
197
198
        $fileseltray = new \XoopsFormElementTray('', '<br>');
199
        $fileseltray->addElement(new \XoopsFormFile(_AM_TDMCREATE_FORMUPLOAD, 'attachedfile', $helper->getConfig('maxsize')));
200
        $fileseltray->addElement(new \XoopsFormLabel(''));
201
        $imgtray->addElement($fileseltray);
202
        $form->addElement($imgtray);
203
204
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_MAIL, 'set_author_mail', 50, 255, $this->getVar('set_author_mail')));
205
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_WEBSITE_URL, 'set_author_website_url', 50, 255, $this->getVar('set_author_website_url')));
206
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_AUTHOR_WEBSITE_NAME, 'set_author_website_name', 50, 255, $this->getVar('set_author_website_name')));
207
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_CREDITS, 'set_credits', 50, 255, $this->getVar('set_credits')));
208
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_RELEASE_INFO, 'set_release_info', 50, 255, $this->getVar('set_release_info')));
209
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_RELEASE_FILE, 'set_release_file', 50, 255, $this->getVar('set_release_file')));
210
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MANUAL, 'set_manual', 50, 255, $this->getVar('set_manual')));
211
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_MANUAL_FILE, 'set_manual_file', 50, 255, $this->getVar('set_manual_file')));
212
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DEMO_SITE_URL, 'set_demo_site_url', 50, 255, $this->getVar('set_demo_site_url')));
213
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_DEMO_SITE_NAME, 'set_demo_site_name', 50, 255, $this->getVar('set_demo_site_name')));
214
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUPPORT_URL, 'set_support_url', 50, 255, $this->getVar('set_support_url')));
215
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUPPORT_NAME, 'set_support_name', 50, 255, $this->getVar('set_support_name')));
216
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_WEBSITE_URL, 'set_website_url', 50, 255, $this->getVar('set_website_url')));
217
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_WEBSITE_NAME, 'set_website_name', 50, 255, $this->getVar('set_website_name')));
218
        // Form Text Date Select
219
        $form->addElement(new \XoopsFormTextDateSelect(_AM_TDMCREATE_SETTING_RELEASE, 'set_release', '', $this->getVar('set_release')));
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

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

219
        $form->addElement(new \XoopsFormTextDateSelect(_AM_TDMCREATE_SETTING_RELEASE, 'set_release', /** @scrutinizer ignore-type */ '', $this->getVar('set_release')));
Loading history...
220
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_STATUS, 'set_status', 50, 255, $this->getVar('set_status')));
221
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_PAYPAL_BUTTON, 'set_donations', 50, 255, $this->getVar('set_donations')));
222
        $form->addElement(new \XoopsFormText(_AM_TDMCREATE_SETTING_SUBVERSION, 'set_subversion', 50, 255, $this->getVar('set_subversion')));
223
224
        $buttonTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', '');
225
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save'));
226
        $buttonTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
227
        $form->addElement($buttonTray);
228
229
        return $form;
230
    }
231
232
    /**
233
     * Get Values.
234
     *
235
     * @param null $keys
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
236
     * @param null $format
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
237
     * @param null $maxDepth
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $maxDepth is correct as it would always require null to be passed?
Loading history...
238
     *
239
     * @return array
240
     */
241
    public function getValuesSettings($keys = null, $format = null, $maxDepth = null)
242
    {
243
        $ret = $this->getValues($keys, $format, $maxDepth);
244
        // Values
245
        $ret['id'] = $this->getVar('set_id');
246
        $ret['name'] = $this->getVar('set_name');
247
        $ret['version'] = $this->getVar('set_version');
248
        $ret['image'] = $this->getVar('set_image');
249
        $ret['release'] = $this->getVar('set_release');
250
        $ret['status'] = $this->getVar('set_status');
251
        $ret['type'] = $this->getVar('set_type');
252
253
        return $ret;
254
    }
255
256
    /**
257
     * Get Options Settings.
258
     * @return array
259
     */
260
    private function getOptionsSettings()
261
    {
262
        $retSet = [];
263
        foreach ($this->options as $option) {
264
            if (1 == $this->getVar('set_' . $option)) {
265
                $retSet[] = $option;
266
            }
267
        }
268
269
        return $retSet;
270
    }
271
272
    /**
273
     * Get Defined Language.
274
     *
275
     * @param $lang
276
     *
277
     * @return string
278
     */
279
    private static function getDefinedLanguage($lang)
280
    {
281
        if (defined($lang)) {
282
            return constant($lang);
283
        }
284
285
        return $lang;
286
    }
287
}
288