GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ajax.config_list.php ➔ renderInputForm()   F
last analyzed

Complexity

Conditions 51
Paths 54

Size

Total Lines 201

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 51
nc 54
nop 2
dl 0
loc 201
rs 3.3333
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
 * AJAX: lists the complete configuration items as text/html.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public License,
6
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
7
 * obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * @package phpMyFAQ
10
 * @author Thorsten Rinne <[email protected]>
11
 * @author Thomas Zeithaml <[email protected]>
12
 * @copyright 2005-2019 phpMyFAQ Team
13
 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14
 * @link https://www.phpmyfaq.de
15
 * @since 2005-12-26
16
 */
17
18
use Abraham\TwitterOAuth\TwitterOAuth;
19
use phpMyFAQ\Configuration;
20
use phpMyFAQ\Filter;
21
use phpMyFAQ\Helper\Administration;
22
use phpMyFAQ\Language;
23
use phpMyFAQ\Permission\PermissionHelper;
24
use phpMyFAQ\System;
25
use phpMyFAQ\Utils;
26
27 View Code Duplication
if (!defined('IS_VALID_PHPMYFAQ')) {
28
    $protocol = 'http';
29
    if (isset($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) === 'ON') {
30
        $protocol = 'https';
31
    }
32
    header('Location: '.$protocol.'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']));
33
    exit();
34
}
35
36
if (!empty($_SESSION['access_token'])) {
37
    $connection = new TwitterOAuth(
38
        $faqConfig->get('socialnetworks.twitterConsumerKey'),
39
        $faqConfig->get('socialnetworks.twitterConsumerSecret'),
40
        $_SESSION['access_token']['oauth_token'],
41
        $_SESSION['access_token']['oauth_token_secret']
42
    );
43
44
    $content = $connection->get('account/verify_credentials');
45
}
46
47
$configMode = Filter::filterInput(INPUT_GET, 'conf', FILTER_SANITIZE_STRING, 'main');
48
49
/**
50
 * @param mixed  $key
51
 * @param string $type
52
 */
53
function renderInputForm($key, $type)
54
{
55
    global $PMF_LANG, $faqConfig;
56
57
    switch ($type) {
58
59
        case 'area':
60
            printf(
61
                '<textarea name="edit[%s]" rows="4" class="form-control">%s</textarea>',
62
                $key,
63
                str_replace('<', '&lt;', str_replace('>', '&gt;', $faqConfig->get($key)))
64
            );
65
            printf("</div>\n");
66
            break;
67
68
        case 'input':
69
            if ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenKey' == $key &&
70
                isset($_SESSION['access_token'])) {
71
                $value = $_SESSION['access_token']['oauth_token'];
72
            } elseif ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenSecret' == $key &&
73
                isset($_SESSION['access_token'])) {
74
                $value = $_SESSION['access_token']['oauth_token_secret'];
75
            } else {
76
                $value = str_replace('"', '&quot;', $faqConfig->get($key));
77
            }
78
            printf(
79
                '<input class="form-control" type="%s" name="edit[%s]" value="%s" step="1" min="0">',
80
                is_numeric($value) ? 'number' : 'text',
81
                $key,
82
                $value
83
            );
84
            echo "</div>\n";
85
            break;
86
87
        case 'password':
88
            printf(
89
                '<input class="form-control" type="password" name="edit[%s]" value="%s">',
90
                $key,
91
                $faqConfig->get($key)
92
            );
93
            echo "</div>\n";
94
            break;
95
96
        case 'select':
97
            printf('<select name="edit[%s]" class="form-control">', $key);
98
99
            switch ($key) {
100
101
                case 'main.language':
102
                    $languages = Language::getAvailableLanguages();
103
                    if (count($languages) > 0) {
104
                        echo Language::languageOptions(
105
                            str_replace(
106
                                array(
107
                                        'language_',
108
                                        '.php',
109
                                ),
110
                                '',
111
                                $faqConfig->get('main.language')
112
                            ),
113
                            false,
114
                            true
115
                        );
116
                    } else {
117
                        echo '<option value="language_en.php">English</option>';
118
                    }
119
                    break;
120
121
                case 'records.orderby':
122
                    echo Configuration::sortingOptions($faqConfig->get($key));
123
                    break;
124
125
                case 'records.sortby':
126
                    printf(
127
                        '<option value="DESC" %s>%s</option>',
128
                        ('DESC' == $faqConfig->get($key)) ? 'selected' : '',
129
                        $PMF_LANG['ad_conf_desc']
130
                    );
131
                    printf(
132
                        '<option value="ASC" %s>%s</option>',
133
                        ('ASC' == $faqConfig->get($key)) ? 'selected' : '',
134
                        $PMF_LANG['ad_conf_asc']
135
                    );
136
                    break;
137
138
                case 'security.permLevel':
139
                    echo PermissionHelper::permOptions($faqConfig->get($key));
140
                    break;
141
142
                case 'main.templateSet':
143
                    $faqSystem = new System();
144
                    $templates = $faqSystem->getAvailableTemplates();
145
146
                    foreach ($templates as $template => $selected) {
147
                        printf('<option%s>%s</option>',
148
                            ($selected === true ? ' selected' : ''),
149
                            $template
150
                        );
151
                    }
152
                    break;
153
154
                case 'records.attachmentsStorageType':
155
                    foreach ($PMF_LANG['att_storage_type'] as $i => $item) {
156
                        $selected = (int)$faqConfig->get($key) === $i ? ' selected' : '';
157
                        printf('<option value="%d"%s>%s</option>', $i, $selected, $item);
158
                    }
159
                    break;
160
161
                case 'records.orderingPopularFaqs':
162
                    printf(
163
                        '<option value="visits"%s>%s</option>',
164
                        ('visits' === $faqConfig->get($key)) ? ' selected' : '',
165
                        $PMF_LANG['records.orderingPopularFaqs.visits']
166
                    );
167
                    printf(
168
                        '<option value="voting"%s>%s</option>',
169
                        ('voting' === $faqConfig->get($key)) ? ' selected' : '',
170
                        $PMF_LANG['records.orderingPopularFaqs.voting']
171
                    );
172
                    break;
173
174
                case 'search.relevance':
175
                    printf(
176
                        '<option value="thema,content,keywords"%s>%s</option>',
177
                        ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected' : '',
178
                        $PMF_LANG['search.relevance.thema-content-keywords']
179
                    );
180
                    printf(
181
                        '<option value="thema,keywords,content"%s>%s</option>',
182
                        (
183
                            'thema,keywords,content' == $faqConfig->get($key)) ? ' selected' : '',
184
                        $PMF_LANG['search.relevance.thema-keywords-content']
185
                    );
186
                    printf(
187
                        '<option value="content,thema,keywords"%s>%s</option>',
188
                        ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected' : '',
189
                        $PMF_LANG['search.relevance.content-thema-keywords']
190
                    );
191
                    printf(
192
                        '<option value="content,keywords,thema"%s>%s</option>',
193
                        ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected' : '',
194
                        $PMF_LANG['search.relevance.content-keywords-thema']
195
                    );
196
                    printf(
197
                        '<option value="keywords,content,thema"%s>%s</option>',
198
                        ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected' : '',
199
                        $PMF_LANG['search.relevance.keywords-content-thema']
200
                    );
201
                    printf(
202
                        '<option value="keywords,thema,content"%s>%s</option>',
203
                        ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected' : '',
204
                        $PMF_LANG['search.relevance.keywords-thema-content']
205
                    );
206
                    break;
207
208
                case 'seo.metaTagsHome':
209
                case 'seo.metaTagsFaqs':
210
                case 'seo.metaTagsCategories':
211
                case 'seo.metaTagsPages':
212
                case 'seo.metaTagsAdmin':
213
                    $adminHelper = new Administration();
214
                    echo $adminHelper->renderMetaRobotsDropdown($faqConfig->get($key));
215
                    break;
216
            }
217
218
            echo "</select>\n</div>\n";
219
            break;
220
221
        case 'checkbox':
222
            printf(
223
                '<div class="form-check"><input class="form-check-input" type="checkbox" name="edit[%s]" value="true"',
224
                $key
225
            );
226
            if ($faqConfig->get($key)) {
227
                echo ' checked';
228
            }
229
            if ('ldap.ldapSupport' === $key && !extension_loaded('ldap')) {
230
                echo ' disabled';
231
            }
232
            if ('security.useSslForLogins' === $key && empty($_SERVER['HTTPS'])) {
233
                echo ' disabled';
234
            }
235
            if ('security.useSslOnly' === $key && empty($_SERVER['HTTPS'])) {
236
                echo ' disabled';
237
            }
238
            if ('security.ssoSupport' === $key && empty($_SERVER['REMOTE_USER'])) {
239
                echo ' disabled';
240
            }
241
            echo '></div></div>';
242
            break;
243
244
        case 'print':
245
            printf(
246
                '<input type="text" readonly name="edit[%s]" class="form-control-plaintext" value="%s"></div>',
247
                $key,
248
                str_replace('"', '&quot;', $faqConfig->get($key)),
249
                $faqConfig->get($key)
250
            );
251
            break;
252
    }
253
}
254
255
header('Content-type: text/html; charset=utf-8');
256
257
Utils::moveToTop($LANG_CONF, 'main.maintenanceMode');
258
259
foreach ($LANG_CONF as $key => $value) {
260
    if (strpos($key, $configMode) === 0) {
261
        if ('socialnetworks.twitterConsumerKey' == $key) {
262
            echo '<div class="form-group row"><label class="col-form-label col-lg-4"></label>';
263
            echo '<div class="col-lg-8">';
264
            if ('' == $faqConfig->get('socialnetworks.twitterConsumerKey') ||
265
                '' == $faqConfig->get('socialnetworks.twitterConsumerSecret')) {
266
                echo '<a target="_blank" href="https://dev.twitter.com/apps/new">Create Twitter App for your FAQ</a>';
267
                echo "<br />\n";
268
                echo 'Your Callback URL is: '.$faqConfig->getDefaultUrl().'services/twitter/callback.php';
269
            }
270
271
            if (!isset($content)) {
272
                echo '<br><a target="_blank" href="../services/twitter/redirect.php">';
273
                echo '<img src="../assets/img/twitter.signin.png" alt="Sign in with Twitter"/></a>';
274
            } elseif (isset($content)) {
275
                echo $content->screen_name."<br />\n";
276
                echo "<img src='".$content->profile_image_url_https."'><br />\n";
277
                echo 'Follower: '.$content->followers_count."<br />\n";
278
                echo 'Status Count: '.$content->statuses_count."<br />\n";
279
                echo 'Status: '.$content->status->text;
280
            }
281
            echo '</div></div>';
282
        }
283
284
        printf(
285
            '<div class="form-group row"><label class="col-lg-4 col-form-label %s">',
286
            $value[0] === 'checkbox' || $value[0] === 'radio' ? 'pt-0' : ''
287
            );
288
289
        switch ($key) {
290
            case 'records.maxAttachmentSize':
291
                printf($value[1], ini_get('upload_max_filesize'));
292
                break;
293
            case 'main.dateFormat':
294
                printf(
295
                    '<a target="_blank" href="http://www.php.net/manual/%s/function.date.php">%s</a>',
296
                    $LANGCODE,
297
                    $value[1]
298
                );
299
                break;
300
            default:
301
                echo $value[1];
302
                break;
303
        }
304
?>
305
                </label>
306
                <div class="col-lg-8">
307
                    <?php renderInputForm($key, $value[0]) ?>
308
                </div>
309
<?php
310
311
    }
312
}
313