SettingForm::display()   F
last analyzed

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 364

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 28
nc 50331648
nop 0
dl 0
loc 364
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
 * @author         Pierre-Henry Soria <[email protected]>
4
 * @copyright      (c) 2012-2019, Pierre-Henry Soria. All Rights Reserved.
5
 * @license        GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
6
 * @package        PH7 / App / System / Module / Admin / From
7
 */
8
9
namespace PH7;
10
11
use PH7\Framework\File\File;
12
use PH7\Framework\Ip\Ip;
13
use PH7\Framework\Module\Various as SysMod;
14
use PH7\Framework\Mvc\Model\DbConfig;
15
use PH7\Framework\Mvc\Router\Uri;
16
use PH7\Framework\Security\CSRF\Token as SecurityToken;
17
use PH7\Framework\Security\Spam\Captcha\Captcha;
18
use PH7\Framework\Translate\Lang;
19
use PH7\Framework\Url\Header;
20
21
class SettingForm
22
{
23
    const CHANGE_CHAT_DOC_URL = 'http://ph7cms.com/how-to-change-chat/';
24
    const I18N_DOC_URL = 'http://ph7cms.com/doc/en/how-to-translate-to-another-language';
25
    const GOOGLE_API_KEY_URL = 'https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,places_backend&amp;keyType=CLIENT_SIDE&amp;reusekey=true';
26
27
    public static function display()
0 ignored issues
show
Coding Style introduced by
display uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
    {
29
        if (isset($_POST['submit_setting'])) {
30
            if (\PFBC\Form::isValid($_POST['submit_setting'])) {
31
                new SettingFormProcess;
32
            }
33
34
            Header::redirect();
35
        }
36
37
        $bIsAffiliateEnabled = SysMod::isEnabled('affiliate');
38
        $bIsMailEnabled = SysMod::isEnabled('mail');
39
        $bIsNoteEnabled = SysMod::isEnabled('note');
40
        $bIsForumEnabled = SysMod::isEnabled('forum');
41
        $bIsPictureEnabled = SysMod::isEnabled('picture');
42
        $bIsVideoEnabled = SysMod::isEnabled('video');
43
44
        $oForm = new \PFBC\Form('form_setting');
45
        $oForm->configure(['action' => '']);
46
        $oForm->addElement(new \PFBC\Element\Hidden('submit_setting', 'form_setting'));
47
        $oForm->addElement(new \PFBC\Element\Token('setting'));
48
49
50
        /********** General Settings **********/
51
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="content" id="general"><div class="col-md-10"><h2 class="underline">' . t('Global Settings') . '</h2>'));
52
53
        $oFile = new File;
54
55
        $oForm->addElement(new \PFBC\Element\Textbox(t('Site Name:'), 'site_name', ['value' => DbConfig::getSetting('siteName'), 'validation' => new \PFBC\Validation\Str(2, 50), 'required' => 1]));
56
57
        $oForm->addElement(new \PFBC\Element\Select(t('Default Theme:'), 'default_template', self::getTpls($oFile), ['value' => DbConfig::getSetting('defaultTemplate'), 'required' => 1]));
58
59
        $oForm->addElement(new \PFBC\Element\Select(t('Default Module:'), 'default_sys_module', self::getDefMods(), ['description' => t('The default module is the one running by default on the homepage.'), 'value' => DbConfig::getSetting('defaultSysModule'), 'required' => 1]));
60
61
        $oForm->addElement(new \PFBC\Element\Select(t('Default Language:'), 'default_language', self::getLangs($oFile), ['description' => t('Documentation: <a href="%0%">Translate your site to another language</a>.', self::I18N_DOC_URL), 'value' => DbConfig::getSetting('defaultLanguage'), 'validation' => new \PFBC\Validation\Str(5, 5), 'required' => 1]));
62
63
        $oForm->addElement(new \PFBC\Element\Select(t('Map Type:'), 'map_type', ['roadmap' => t('Roadmap (default)'), 'hybrid' => t('Hybrid'), 'terrain' => t('Terrain'), 'satellite' => t('Satellite')], ['value' => DbConfig::getSetting('mapType'), 'required' => 1]));
64
65
        $oForm->addElement(new \PFBC\Element\Select(t('Profiles with Photo Only:'), 'profile_with_avatars', ['1' => t('Yes'), '0' => t('No')], ['description' => t('Display only the profiles with a profile photo on profile blocks (such as the homepage).'), 'value' => DbConfig::getSetting('profileWithAvatarSet'), 'required' => 1]));
66
67
        $oForm->addElement(new \PFBC\Element\Select(t('Splash Homepage:'), 'splash_page', ['1' => t('Enable (recommended)'), '0' => t('Disable')], ['description' => t('Use the Splash Page for visitors (not logged), otherwise the classic page will be used. <br /><em>Available only if "User" is the Default Module.</em>'), 'value' => DbConfig::getSetting('splashPage'), 'required' => 1]));
68
69
        $oForm->addElement(new \PFBC\Element\Select(t('Background Splash Video:'), 'bg_splash_vid', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('Enable/Disable the "Animated Video" on the Splash Homepage. <br /><em>Available only if "User" is the Default Module.</em>'), 'value' => DbConfig::getSetting('bgSplashVideo'), 'required' => 1]));
70
71
        $oForm->addElement(new \PFBC\Element\Select(t('Display Profiles on Guest Homepage:'), 'users_block', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('Display or not the newest users on the homepage for visitors. <br /><em>Available only if "User" is the Default Module.</em>'), 'value' => DbConfig::getSetting('usersBlock'), 'required' => 1]));
72
73
        $oForm->addElement(new \PFBC\Element\Number(t('Number of Profiles on Splash Page:'), 'number_profile_splash_page', ['description' => t('The number of profile photos to display on the Splash Homepage. <br /><em>Available only if "Profiles on Guest Homepage" is enabled and if "User" is the Default Module.</em>'), 'value' => DbConfig::getSetting('numberProfileSplashPage'), 'validation' => new \PFBC\Validation\Str(1, 2), 'required' => 1]));
74
75
        if ($bIsForumEnabled) {
76
            $oForm->addElement(new \PFBC\Element\Select(t('WYSIWYG editor for Forum:'), 'wysiwyg_editor_forum', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('Enable WYSIWYG editor (CKEditor) for the forum posts. If disabled, the simple textarea field will be used.'), 'value' => DbConfig::getSetting('wysiwygEditorForum'), 'required' => 1]));
77
        }
78
79
        $oForm->addElement(new \PFBC\Element\Select(t('Social Media Widgets:'), 'social_media_widgets', [1 => t('Enable'), 0 => t('Disable')], ['description' => t('Enable the Social Media Sharing such as Like and Sharing buttons.'), 'value' => DbConfig::getSetting('socialMediaWidgets'), 'required' => 1]));
80
81
        $oForm->addElement(new \PFBC\Element\Select(t('Adult Disclaimer:'), 'disclaimer', [1 => t('Enable'), 0 => t('Disable')], ['description' => t('Show an Adult Warning to enter to your website. This is useful for websites with adult content. <br /><strong>WARNING: this disclaimer offered by a third-party provider may sometimes open a new tab promoting third-party adult websites.</strong>'), 'value' => DbConfig::getSetting('disclaimer'), 'required' => 1]));
82
83
        $oForm->addElement(new \PFBC\Element\Select(t('Cookie Consent Bar:'), 'cookie_consent_bar', [1 => t('Enable'), 0 => t('Disable')], ['description' => t('Enable a Cookie Consent Bar to prevent your users that your website uses cookies. This is required by EU Law (if you have visitors from EU countries). The Cookie Bar will only be displayed if the visitor is in the EU.'), 'value' => DbConfig::getSetting('cookieConsentBar'), 'required' => 1]));
84
85
        $oForm->addElement(new \PFBC\Element\Select(t('Ajax Site with AjPH:'), 'full_ajax_site', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t("Be careful! 'Full Ajax Navigation' feature is still in <strong>beta version</strong> and may not be working properly on all pages."), 'value' => DbConfig::getSetting('fullAjaxSite'), 'required' => 1]));
86
87
        $oForm->addElement(new \PFBC\Element\Select(t('Site Status:'), 'site_status', [DbConfig::ENABLED_SITE => t('Online'), DbConfig::MAINTENANCE_SITE => t('Maintenance (offline)')], ['description' => t("Maintenance mode is useful if you are working on your website or update it. Logged admins and admin panel won't be affected by the maintenance page."), 'value' => DbConfig::getSetting('siteStatus'), 'required' => 1]));
88
89
        $oForm->addElement(new \PFBC\Element\Select(t('Show "Powered By" link in footer:'), 'display_powered_by_link', [1 => t('Enable'), 0 => t('Disable (NOT recommended)')], ['description' => t('Are you proud of using <a href="%software_website%">pH7CMS</a> brand? Are you proud to say your dating app has been made by the Leading Dating Software provider?'), 'value' => DbConfig::getSetting('displayPoweredByLink'), 'required' => 1]));
90
91
        $oForm->addElement(new \PFBC\Element\Select(t('Show the News Feed:'), 'is_software_news_feed', [1 => t('Enable'), 0 => t('Disable')], ['description' => t('Show the latest news about the software in the admin dashboard (recommend).'), 'value' => DbConfig::getSetting('isSoftwareNewsFeed'), 'required' => 1]));
92
93
        unset($oFile);
94
95
        /********** Logo Settings **********/
96
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="icon"><div class="col-md-10"><h2 class="underline">' . t('Icon Logo') . '</h2>'));
97
98
        $oForm->addElement(new \PFBC\Element\File('', 'logo', ['description' => t('Add your small logo/icon that represents/distinguishes the best your site/concept/brand.'), 'accept' => 'image/*']));
99
100
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="s_marg"><img src="' . PH7_URL_TPL . PH7_TPL_NAME . PH7_SH . PH7_IMG . 'logo.png?v=' . File::version(PH7_PATH_TPL . PH7_TPL_NAME . PH7_DS . PH7_IMG . 'logo.png') . '" alt="' . t('Icon Logo') . '" title="' . t('The current logo of your website.') . '" /></div>'));
101
102
103
        /********** Registration **********/
104
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="registration"><div class="col-md-10"><h2 class="underline">' . t('Registration') . '</h2>'));
105
106
        $aUserActivationTypes = [
107
            RegistrationCore::NO_ACTIVATION => t('No activation required'),
108
            RegistrationCore::EMAIL_ACTIVATION => t('Self-activation via email'),
109
            RegistrationCore::MANUAL_ACTIVATION => t('Manual activation by administrator')
110
        ];
111
        if (SysMod::isEnabled('sms-verification')) {
112
            $aUserActivationTypes[RegistrationCore::SMS_ACTIVATION] = t('Self-activation via SMS');
113
        }
114
115
        $oForm->addElement(
116
            new \PFBC\Element\Select(
117
                t('Account activation type for Members:'),
118
                'user_activation_type',
119
                $aUserActivationTypes,
120
                [
121
                    'value' => DbConfig::getSetting('userActivationType'),
122
                    'required' => 1
123
                ]
124
            )
125
        );
126
127
        if ($bIsAffiliateEnabled) {
128
            $oForm->addElement(
129
                new \PFBC\Element\Select(
130
                    t('Account activation type for Affiliates:'),
131
                    'aff_activation_type',
132
                    [
133
                        RegistrationCore::NO_ACTIVATION => t('No activation required'),
134
                        RegistrationCore::EMAIL_ACTIVATION => t('Self-activation via email'),
135
                        RegistrationCore::MANUAL_ACTIVATION => t('Manual activation by administrator')
136
                    ],
137
                    [
138
                        'value' => DbConfig::getSetting('affActivationType'),
139
                        'required' => 1
140
                    ]
141
                )
142
            );
143
        }
144
145
        $oForm->addElement(new \PFBC\Element\Number(t('Minimum username length:'), 'min_username_length', ['value' => DbConfig::getSetting('minUsernameLength'), 'max' => DbConfig::getSetting('maxUsernameLength') - 1, 'required' => 1]));
146
147
        $oForm->addElement(new \PFBC\Element\Number(t('Maximum username length:'), 'max_username_length', ['value' => DbConfig::getSetting('maxUsernameLength'), 'min' => DbConfig::getSetting('minUsernameLength') + 1, 'max' => PH7_MAX_USERNAME_LENGTH, 'required' => 1]));
148
149
        $oForm->addElement(new \PFBC\Element\Number(t('Minimum age for registration:'), 'min_age_registration', ['value' => DbConfig::getSetting('minAgeRegistration'), 'max' => DbConfig::getSetting('maxAgeRegistration') - 1, 'validation' => new \PFBC\Validation\Str(1, 2), 'required' => 1]));
150
151
        $oForm->addElement(new \PFBC\Element\Number(t('Maximum age for registration:'), 'max_age_registration', ['value' => DbConfig::getSetting('maxAgeRegistration'), 'min' => DbConfig::getSetting('minAgeRegistration') + 1, 'validation' => new \PFBC\Validation\Str(1, 3), 'required' => 1]));
152
153
        $oForm->addElement(new \PFBC\Element\Select(t('Date of Birth field type:'), 'is_user_age_range_field', ['1' => t('Age Range (without month and day of birth )'), '0' => t('Date-Picker calendar (full date of birth)')], ['value' => DbConfig::getSetting('isUserAgeRangeField'), 'required' => 1]));
154
155
        $oForm->addElement(new \PFBC\Element\Select(t('Require photo to be uploaded:'), 'require_registration_avatar', ['1' => t('Yes'), '0' => t('No')], ['description' => t('Require Members to upload a profile photo during sign up.') . '<br /><small>' . t("Doesn't guarantee that all users will have a profile photo, because users can still close the tab without completely finishing the registration process.") . '</small>', 'value' => DbConfig::getSetting('requireRegistrationAvatar'), 'required' => 1]));
156
157
        $oForm->addElement(new \PFBC\Element\Select(t('Default Membership Group:'), 'default_membership_group_id', self::getMembershipGroups(), ['value' => DbConfig::getSetting('defaultMembershipGroupId'), 'required' => 1]));
158
159
160
        /********** Picture and Video **********/
161
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="pic_vid"><div class="col-md-10"><h2 class="underline">' . t('Picture and Video') . '</h2>'));
162
163
        if ($bIsPictureEnabled || $bIsVideoEnabled) {
164
            $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Image') . '</h3>'));
165
166
            $oForm->addElement(new \PFBC\Element\Textbox(t('Watermark Text:'), 'watermark_text_image', ['description' => t('Leave it blank to disable the watermark text on images.'), 'value' => DbConfig::getSetting('watermarkTextImage', '')]));
167
168
            $oForm->addElement(new \PFBC\Element\Number(t('Watermark Size:'), 'size_watermark_text_image', ['description' => t('Between 0 to 5.'), 'min' => 0, 'max' => 5, 'value' => DbConfig::getSetting('sizeWatermarkTextImage'), 'required' => 1]));
169
        }
170
171
        if ($bIsVideoEnabled) {
172
            $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Video') . '</h3>'));
173
174
            $oForm->addElement(new \PFBC\Element\Url(t('Default Video:'), 'default_video', ['description' => t('Video by default if no video is found.'), 'value' => DbConfig::getSetting('defaultVideo'), 'required' => 1]));
175
176
            $oForm->addElement(new \PFBC\Element\Select(t('Autoplay Video:'), 'autoplay_video', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('autoplayVideo'), 'required' => 1]));
177
        }
178
179
180
        /********** Moderation **********/
181
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="moderation"><div class="col-md-10"><h2 class="underline">' . t('Moderation') . '</h2>'));
182
183
        $oForm->addElement(new \PFBC\Element\Select(t('Nudity Filter:'), 'nudity_filter', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('Photos will be automatically pending approval if there are detected as "Nude/Adult Photos"'), 'value' => DbConfig::getSetting('nudityFilter'), 'required' => 1]));
184
185
        $oForm->addElement(new \PFBC\Element\Select(t('Profile Photo Manual Approval:'), 'avatar_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('avatarManualApproval'), 'required' => 1]));
186
187
        $oForm->addElement(new \PFBC\Element\Select(t('Background Profile Manual Approval:'), 'bg_profile_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('bgProfileManualApproval'), 'required' => 1]));
188
189
        if ($bIsNoteEnabled) {
190
            $oForm->addElement(new \PFBC\Element\Select(t('Note Post Manual Approval:'), 'note_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('noteManualApproval'), 'required' => 1]));
191
        }
192
193
        if ($bIsPictureEnabled) {
194
            $oForm->addElement(new \PFBC\Element\Select(t('Photos Manual Approval:'), 'picture_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('pictureManualApproval'), 'required' => 1]));
195
        }
196
197
        if ($bIsVideoEnabled) {
198
            $oForm->addElement(new \PFBC\Element\Select(t('Videos Manual Approval:'), 'video_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('videoManualApproval'), 'required' => 1]));
199
        }
200
201
        if (SysMod::isEnabled('webcam')) {
202
            $oForm->addElement(new \PFBC\Element\Select(t('Webcam Pictures Manual Approval:'), 'webcam_picture_manual_approval', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('This approval mode is experimental, do not use it on production.'), 'value' => DbConfig::getSetting('webcamPictureManualApproval'), 'required' => 1]));
203
        }
204
205
206
        /********** Email **********/
207
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="email"><div class="col-md-10"><h2 class="underline">' . t('Email Parameters') . '</h2>'));
208
209
        $oForm->addElement(new \PFBC\Element\Textbox(t('Email Name:'), 'email_name', ['value' => DbConfig::getSetting('emailName'), 'required' => 1]));
210
211
        $oForm->addElement(new \PFBC\Element\Email(t('Admin Email:'), 'admin_email', ['value' => DbConfig::getSetting('adminEmail'), 'required' => 1]));
212
213
        $oForm->addElement(new \PFBC\Element\Email(t('Feedback Email:'), 'feedback_email', ['value' => DbConfig::getSetting('feedbackEmail'), 'required' => 1]));
214
215
        $oForm->addElement(new \PFBC\Element\Email(t('Return Email:'), 'return_email', ['description' => 'Usually [email protected]', 'value' => DbConfig::getSetting('returnEmail'), 'required' => 1]));
216
217
218
        /********** Security **********/
219
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="security"><div class="col-md-10"><h2 class="underline">' . t('Security') . '</h2>'));
220
221
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Password') . '</h3>'));
222
223
        $oForm->addElement(new \PFBC\Element\Number(t('Minimum password length:'), 'min_password_length', ['value' => DbConfig::getSetting('minPasswordLength'), 'required' => 1]));
224
225
        $oForm->addElement(new \PFBC\Element\Number(t('Maximum password length:'), 'max_password_length', ['value' => DbConfig::getSetting('maxPasswordLength'), 'required' => 1]));
226
227
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Login Attempt Protection') . '</h3>'));
228
229
        $oForm->addElement(new \PFBC\Element\Select(t('Blocking login attempts exceeded for Users:'), 'is_user_login_attempt', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('isUserLoginAttempt'), 'required' => 1]));
230
231
        if ($bIsAffiliateEnabled) {
232
            $oForm->addElement(new \PFBC\Element\Select(t('Blocking login attempts exceeded for Affiliates:'), 'is_affiliate_login_attempt', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('isAffiliateLoginAttempt'), 'required' => 1]));
233
        }
234
235
        $oForm->addElement(new \PFBC\Element\Select(t('Blocking login attempts exceeded for Admins:'), 'is_admin_login_attempt', ['1' => t('Enable'), '0' => t('Disable')], ['value' => DbConfig::getSetting('isAdminLoginAttempt'), 'required' => 1]));
236
237
        $oForm->addElement(new \PFBC\Element\Number(t('Max number of login attempts before blocking for Users:'), 'max_user_login_attempts', ['value' => DbConfig::getSetting('maxUserLoginAttempts'), 'required' => 1]));
238
239
        if ($bIsAffiliateEnabled) {
240
            $oForm->addElement(new \PFBC\Element\Number(t('Max number of login attempts before blocking for Affiliates:'), 'max_affiliate_login_attempts', ['value' => DbConfig::getSetting('maxAffiliateLoginAttempts'), 'required' => 1]));
241
        }
242
243
        $oForm->addElement(new \PFBC\Element\Number(t('Max number of login attempts before blocking for Admins:'), 'max_admin_login_attempts', ['value' => DbConfig::getSetting('maxAdminLoginAttempts'), 'required' => 1]));
244
245
        $oForm->addElement(new \PFBC\Element\Number(t('Time interval blocking for Users:'), 'login_user_attempt_time', ['description' => t('Time in minutes.'), 'value' => DbConfig::getSetting('loginUserAttemptTime'), 'required' => 1]));
246
247
        if ($bIsAffiliateEnabled) {
248
            $oForm->addElement(new \PFBC\Element\Number(t('Time interval blocking for Affiliates:'), 'login_affiliate_attempt_time', ['description' => t('Time in minutes.'), 'value' => DbConfig::getSetting('loginAffiliateAttemptTime'), 'required' => 1]));
249
        }
250
251
        $oForm->addElement(new \PFBC\Element\Number(t('Time interval blocking for Admins:'), 'login_admin_attempt_time', ['description' => t('Time in minutes.'), 'value' => DbConfig::getSetting('loginAdminAttemptTime'), 'required' => 1]));
252
253
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Various') . '</h3>'));
254
255
        $oForm->addElement(new \PFBC\Element\Select(t('Send Abuse Reports by email:'), 'send_report_mail', ['1' => t('Yes'), '0' => t('No')], ['value' => DbConfig::getSetting('sendReportMail'), 'required' => 1]));
256
257
        $oForm->addElement(new \PFBC\Element\Textbox(t('IP Restriction for Admin Panel Access:'), 'ip_login', ['description' => t('By entering <a href="%0%" title="Get your current IP address">your IP</a>, you will get a higher security and exclude all other people and bots that tried to login with another IP address even if the login is correct! Leave blank to disable this feature. Be careful, for using this feature you need to have a static IP (not a dynamic one). If you are not sure, please contact your ISP.', Ip::api()), 'value' => DbConfig::getSetting('ipLogin', '')]));
258
259
        $oForm->addElement(new \PFBC\Element\Textbox(t('Indicate a word that will replace the banned word in <a href="%0%">the list</a>.', Uri::get(PH7_ADMIN_MOD, 'file', 'protectededit', 'app/configs/bans/word.txt', false)), 'ban_word_replace', ['value' => DbConfig::getSetting('banWordReplace'), 'required' => 1]));
260
261
        $oForm->addElement(new \PFBC\Element\Select(t('Enable/Disable CSRF security tokens in forms:'), 'security_token_forms', ['1' => t('Enable'), '0' => t('Disable')], ['description' => t('Sometimes this protection can be annoying for users if there are not fast enough to fulfill the forms. However, if disabled, your website can be vulnerable on CSRF attacks in forms.'), 'value' => DbConfig::getSetting('securityToken'), 'required' => 1]));
262
263
        $oForm->addElement(new \PFBC\Element\Number(t('CSRF token lifetime:'), 'security_token_lifetime', ['description' => t('Time in seconds.'), 'value' => DbConfig::getSetting('securityTokenLifetime'), 'required' => 1]));
264
265
        $oForm->addElement(new \PFBC\Element\Select(t('Protect for Users against session cookies hijacking:'), 'is_user_session_ip_check', ['1' => t('Yes (recommended for security reasons)'), '0' => t('No')], ['description' => t('This protection can cause problems for logged in users with dynamic IPs. Please disable if their IP changes frequently during the session.'), 'value' => DbConfig::getSetting('isUserSessionIpCheck'), 'required' => 1]));
266
267
        if ($bIsAffiliateEnabled) {
268
            $oForm->addElement(new \PFBC\Element\Select(t('Protect for Affiliates against session cookies hijacking:'), 'is_affiliate_session_ip_check', ['1' => t('Yes (recommended for security reasons)'), '0' => t('No')], ['description' => t('This protection can cause problems for affiliates with dynamic IPs. Please disable if their IP changes frequently during the session.'), 'value' => DbConfig::getSetting('isAffiliateSessionIpCheck'), 'required' => 1]));
269
        }
270
271
        $oForm->addElement(new \PFBC\Element\Select(t('Protect for Admins against session cookies hijacking:'), 'is_admin_session_ip_check', ['1' => t('Yes (highly recommended for security reasons)'), '0' => t('No')], ['description' => t('This protection can cause problems for admins with dynamic IPs. Please disable if their IP changes frequently during the session.'), 'value' => DbConfig::getSetting('isAdminSessionIpCheck'), 'required' => 1]));
272
273
        $oForm->addElement(new \PFBC\Element\Select(t('System against DDoS attacks:'), 'stop_DDoS', ['1' => t('Activate'), '0' => t('Deactivate')], ['description' => t('Enable it ONLY if you think your website has real DDoS attacks or if your server is highly overloaded.'), 'value' => DbConfig::getSetting('DDoS'), 'required' => 1]));
274
275
276
        /********** Spam **********/
277
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="spam"><div class="col-md-10"><h2 class="underline">' . t('Spam') . '</h2>'));
278
279
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Time Delay') . '</h3>'));
280
281
        $oForm->addElement(new \PFBC\Element\Number(t('Registration delay for Users:'), 'time_delay_user_registration', ['description' => t('Number of minutes that has to pass before a user with the same IP address can register again. Enter "0" to disable.'), 'value' => DbConfig::getSetting('timeDelayUserRegistration'), 'required' => 1]));
282
283
        if ($bIsAffiliateEnabled) {
284
            $oForm->addElement(new \PFBC\Element\Number(t('Registration delay for Affiliates:'), 'time_delay_aff_registration', ['description' => t('Number of minutes that has to pass before an affiliate with the same IP address can register again. Enter "0" to disable.'), 'value' => DbConfig::getSetting('timeDelayAffRegistration'), 'required' => 1]));
285
        }
286
287
        if ($bIsNoteEnabled) {
288
            $oForm->addElement(new \PFBC\Element\Number(t('Send Note delay:'), 'time_delay_send_note', ['description' => t('Number of minutes for the same user to post a new note.'), 'value' => DbConfig::getSetting('timeDelaySendNote'), 'required' => 1]));
289
        }
290
291
        if ($bIsMailEnabled) {
292
            $oForm->addElement(new \PFBC\Element\Number(t('Send Mail delay:'), 'time_delay_send_mail', ['description' => t('Number of minutes for the same user can send a new email.'), 'value' => DbConfig::getSetting('timeDelaySendMail'), 'required' => 1]));
293
        }
294
        $oForm->addElement(new \PFBC\Element\Number(t('Send Comment delay:'), 'time_delay_send_comment', ['description' => t('Number of minutes for the same user can send a new comment.'), 'value' => DbConfig::getSetting('timeDelaySendComment'), 'required' => 1]));
295
296
        if ($bIsForumEnabled) {
297
            $oForm->addElement(new \PFBC\Element\Number(t('Send Forum Topic delay:'), 'time_delay_send_forum_topic', ['description' => t('Number of minutes for the same user can send a new topic in the forum.'), 'value' => DbConfig::getSetting('timeDelaySendForumTopic'), 'required' => 1]));
298
299
            $oForm->addElement(new \PFBC\Element\Number(t('Send Forum Message delay:'), 'time_delay_send_forum_msg', ['description' => t('Number of minutes for the same user can send a reply message in the same topic.'), 'value' => DbConfig::getSetting('timeDelaySendForumMsg'), 'required' => 1]));
300
        }
301
302
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Captcha') . '</h3>'));
303
304
        $oForm->addElement(new \PFBC\Element\Select(t('Captcha Complexity:'), 'captcha_complexity', [Captcha::COMPLEXITY_LOW, Captcha::COMPLEXITY_MEDIUM, Captcha::COMPLEXITY_HIGH], ['value' => DbConfig::getSetting('captchaComplexity'), 'required' => 1]));
305
306
        $oForm->addElement(new \PFBC\Element\Select(t('Captcha Case Sensitive:'), 'captcha_case_sensitive', ['1' => t('Yes'), '0' => t('No')], ['value' => DbConfig::getSetting('captchaCaseSensitive'), 'required' => 1]));
307
308
        $oForm->addElement(new \PFBC\Element\Select(t('Captcha for User Signup Form:'), 'is_captcha_user_signup', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaUserSignup'), 'required' => 1]));
309
310
        if ($bIsAffiliateEnabled) {
311
            $oForm->addElement(new \PFBC\Element\Select(t('Captcha for Affiliate Signup Form:'), 'is_captcha_affiliate_signup', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaAffiliateSignup'), 'required' => 1]));
312
        }
313
314
        if ($bIsMailEnabled) {
315
            $oForm->addElement(new \PFBC\Element\Select(t('Captcha for sending Messages between users:'), 'is_captcha_mail', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaMail'), 'required' => 1]));
316
        }
317
318
        $oForm->addElement(new \PFBC\Element\Select(t('Captcha for adding a Comment:'), 'is_captcha_comment', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaComment'), 'required' => 1]));
319
320
        if ($bIsForumEnabled) {
321
            $oForm->addElement(new \PFBC\Element\Select(t('Captcha for adding or reply a message in the Forum:'), 'is_captcha_forum', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaForum'), 'required' => 1]));
322
        }
323
324
        if ($bIsNoteEnabled) {
325
            $oForm->addElement(new \PFBC\Element\Select(t('Captcha for adding a User Post Note:'), 'is_captcha_note', ['1' => t('Activate'), '0' => t('Deactivate')], ['value' => DbConfig::getSetting('isCaptchaNote'), 'required' => 1]));
326
        }
327
328
        $oForm->addElement(new \PFBC\Element\HTMLExternal('<br /><h3 class="underline">' . t('Pruning') . '</h3>'));
329
330
        $oForm->addElement(new \PFBC\Element\Number(t('Delete old Messages:'), 'clean_msg', ['description' => t('Delete messages older than X days. 0 to disable.'), 'value' => DbConfig::getSetting('cleanMsg'), 'required' => 1]));
331
332
        $oForm->addElement(new \PFBC\Element\Number(t('Delete old Comments:'), 'clean_comment', ['description' => t('Delete comments older than X days. 0 to disable.'), 'value' => DbConfig::getSetting('cleanComment'), 'required' => 1]));
333
334
        $oForm->addElement(new \PFBC\Element\Number(t('Delete old IM Messages:'), 'clean_messenger', ['description' => t('Delete IM messages older than X days. 0 to disable.'), 'value' => DbConfig::getSetting('cleanMessenger'), 'required' => 1]));
335
336
337
        /********** Design (Color) **********/
338
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="design"><div class="col-md-10"><h2 class="underline">' . t('Override Website Colors') . '</h2>'));
339
340
        $oForm->addElement(new \PFBC\Element\Color(t('Website Background:'), 'background_color', ['value' => DbConfig::getSetting('backgroundColor')]));
341
342
        $oForm->addElement(new \PFBC\Element\Color(t('Text:'), 'text_color', ['value' => DbConfig::getSetting('textColor')]));
343
344
        $oForm->addElement(new \PFBC\Element\Color(t('Links:'), 'link_color', ['value' => DbConfig::getSetting('linkColor')]));
345
346
        $oForm->addElement(new \PFBC\Element\Color(t('Footer Links:'), 'footer_link_color', ['value' => DbConfig::getSetting('footerLinkColor')]));
347
348
        $oForm->addElement(new \PFBC\Element\Color(t('Links hover:'), 'link_hover_color', ['value' => DbConfig::getSetting('linkHoverColor')]));
349
350
        $oForm->addElement(new \PFBC\Element\HTMLExternal(
351
            '<div class="right"><a href="' . Uri::get(PH7_ADMIN_MOD, 'setting', 'resetcolor', (new SecurityToken)->url(), false) . '">' . t('Reset Colors') . '</a></div>'
352
        ));
353
354
355
        /********** API **********/
356
        $oForm->addElement(
357
            new \PFBC\Element\HTMLExternal(
358
                '</div></div><div class="content" id="api"><div class="col-md-10"><h2 class="underline">' . t('API') . '</h2>'
359
            )
360
        );
361
362
        if (SysMod::isEnabled('map')) {
363
            $sGoogleApiKeyDesc = t('You can get your key <a href="%0%">here</a>. Then, select "<strong>Google Maps JavaScript API</strong>" for "<em>Which API are you using</em>" and "<strong>Web browser (Javascript)</strong>" for "<em>Where will you be calling the API from</em>", then you will get your API key to paste here. ', self::GOOGLE_API_KEY_URL);
364
            $oForm->addElement(new \PFBC\Element\Textbox(t('Google Maps API Key:'), 'google_api_key', ['description' => $sGoogleApiKeyDesc, 'value' => DbConfig::getSetting('googleApiKey', '')]));
365
        }
366
367
        $oForm->addElement(new \PFBC\Element\Url(t('IP API:'), 'ip_api', ['description' => t('The URL must end with a slash.'), 'value' => DbConfig::getSetting('ipApi'), 'required' => 1]));
368
369
        if (SysMod::isEnabled('chat')) {
370
            $oForm->addElement(new \PFBC\Element\Url(t('Chat API:'), 'chat_api', ['description' => t('Documentation: <a href="%0%">Change the default chat service by your real one</a>.<br /> <small>Parsing tags are permitted (e.g. #!http://api.your-service-chat.com/?url=%0%&name=%1%!#).</small>', self::CHANGE_CHAT_DOC_URL, '<strong>%site_url%</strong>', '<strong>%site_name%</strong>'), 'value' => DbConfig::getSetting('chatApi'), 'required' => 1]));
371
        }
372
373
        if (SysMod::isEnabled('chatroulette')) {
374
            $oForm->addElement(new \PFBC\Element\Url(t('Chatroulette API:'), 'chatroulette_api', ['description' => t('Documentation: <a href="%0%">Change the default chatroulette provider by yours</a>.<br /> <small>Parsing tags are permitted (e.g. #!http://api.your-service-chat.com/?url=%0%&name=%1%!#).</small>', self::CHANGE_CHAT_DOC_URL, '<strong>%site_url%</strong>', '<strong>%site_name%</strong>'), 'value' => DbConfig::getSetting('chatrouletteApi'), 'required' => 1]));
375
        }
376
377
378
        /********** Automation **********/
379
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><div class="content" id="automation"><div class="col-md-10"><h2 class="underline">' . t('Automation') . '</h2>'));
380
381
        $oForm->addElement(new \PFBC\Element\Textbox(t('Secret word for the cron URL:'), 'cron_security_hash', ['description' => t('Your very secret word for the cron URL. It will be used for running automated cron jobs.'), 'value' => DbConfig::getSetting('cronSecurityHash'), 'required' => 1, 'validation' => new \PFBC\Validation\Str(1, 64)]));
382
383
        $oForm->addElement(new \PFBC\Element\Number(t('User inactivity timeout:'), 'user_timeout', ['description' => t('The number of minutes that a member becomes inactive (offline).'), 'value' => DbConfig::getSetting('userTimeout'), 'required' => 1]));
384
385
386
        $oForm->addElement(new \PFBC\Element\HTMLExternal('</div></div><script src="' . PH7_URL_STATIC . PH7_JS . 'tabs.js"></script><script>tabs(\'p\', [\'general\',\'icon\',\'registration\',\'pic_vid\',\'moderation\',\'email\',\'security\',\'spam\',\'design\',\'api\',\'automation\']);</script>'));
387
        $oForm->addElement(new \PFBC\Element\Button(t('Save'), 'submit', ['icon' => 'check']));
388
389
        $oForm->render();
390
    }
391
392
    /**
393
     * @param File $oFile
394
     *
395
     * @return array
396
     */
397
    private static function getTpls(File $oFile)
398
    {
399
        $aTpls = [];
400
401
        $aTplIds = $oFile->getDirList(PH7_PATH_TPL);
402
        foreach ($aTplIds as $sTpl) {
403
            $aTpls[$sTpl] = ucfirst($sTpl);
404
        }
405
406
        return $aTpls;
407
    }
408
409
    /**
410
     * @param File $oFile
411
     *
412
     * @return array
413
     */
414
    private static function getLangs(File $oFile)
415
    {
416
        $aLangs = [];
417
418
        $aLangIds = $oFile->getDirList(PH7_PATH_APP_LANG);
419
        foreach ($aLangIds as $sLang) {
420
            $sAbbrLang = Lang::getIsoCode($sLang);
421
            $aLangs[$sLang] = t($sAbbrLang) . ' (' . $sLang . ')';
422
        }
423
424
        return $aLangs;
425
    }
426
427
    /**
428
     * @return array
429
     */
430
    private static function getDefMods()
431
    {
432
        $aMods = [];
433
434
        foreach (self::getActivatableDefMods() as $sMod) {
435
            // Skip the disabled module (would be impossible to set a disabled module as the default one)
436
            if (!SysMod::isEnabled($sMod)) {
437
                continue;
438
            }
439
440
            $aMods[$sMod] = ucfirst($sMod);
441
        }
442
443
        return $aMods;
444
    }
445
446
    /**
447
     * @return array
448
     */
449
    private static function getMembershipGroups()
450
    {
451
        $aGroupNames = [];
452
453
        $oGroupIds = (new AdminCoreModel)->getMemberships();
454
        foreach ($oGroupIds as $iId) {
0 ignored issues
show
Bug introduced by
The expression $oGroupIds of type object<stdClass>|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
455
            $aGroupNames[$iId->groupId] = $iId->name;
456
        }
457
458
        return $aGroupNames;
459
    }
460
461
    /**
462
     * Get the list of modules that are possible to enable as the default system module.
463
     *
464
     * @return array
465
     */
466
    private static function getActivatableDefMods()
467
    {
468
        return [
469
            'user',
470
            'affiliate',
471
            'blog',
472
            'note',
473
            'chat',
474
            'chatroulette',
475
            'forum',
476
            'game',
477
            'hotornot',
478
            'picture',
479
            'video'
480
        ];
481
    }
482
}
483