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.
Completed
Push — 2.9 ( 9a1a51...6c05fc )
by Thorsten
14:18
created

ajax.config_list.php ➔ renderInputForm()   D

Complexity

Conditions 49
Paths 38

Size

Total Lines 198
Code Lines 147

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 49
eloc 147
nc 38
nop 2
dl 0
loc 198
rs 4.1818

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