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.8 ( b9ed1f...cd67fa )
by Thorsten
15:59
created

ajax.config_list.php ➔ renderInputForm()   D

Complexity

Conditions 44
Paths 32

Size

Total Lines 158
Code Lines 123

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 44
eloc 123
nc 32
nop 2
dl 0
loc 158
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 5.2
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
 * @package   Administration
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
 * @link      http://www.phpmyfaq.de
18
 * @since     2005-12-26
19
 */
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 = array(
45
        'main'    => 1,
46
        'records' => 1,
47
        'spam'    => 1,
48
        'search'  => 1,
49
        'social'  => 1
50
);
51
52
/**
53
 * @param  $key
54
 * @param  $type
55
 * @return void
56
 */
57
function renderInputForm($key, $type)
58
{
59
    global $PMF_LANG, $faqConfig;
60
61
    switch ($type) {
62
63
        case 'area':
64
            printf('<textarea name="edit[%s]" cols="60" rows="6" class="input-xxlarge">%s</textarea>',
65
                    $key,
66
                    str_replace('<', '&lt;', str_replace('>', '&gt;', $faqConfig->get($key))));
67
            printf("</div>\n");
68
            break;
69
70
        case 'input':
71
            if ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenKey' == $key &&
72
                isset($_SESSION['access_token'])) {
73
                $value = $_SESSION['access_token']['oauth_token'];
74
            } elseif ('' == $faqConfig->get($key) && 'socialnetworks.twitterAccessTokenSecret' == $key &&
75
                isset($_SESSION['access_token'])) {
76
                $value = $_SESSION['access_token']['oauth_token_secret'];
77
            } else {
78
                $value = str_replace('"', '&quot;', $faqConfig->get($key));
79
            }
80
            printf(
81
                '<input class="%s" type="%s" name="edit[%s]" size="75" value="%s" />',
82
                is_numeric($value) ? 'input-small' : 'input-xxlarge',
83
                is_numeric($value) ? 'number' : 'text',
84
                $key,
85
                $value
86
            );
87
            echo "</div>\n";
88
            break;
89
90
        case 'select':
91
            printf('<select name="edit[%s]" size="1" class="input-xlarge">', $key);
92
            
93
            switch ($key) {
94
                
95
                case 'main.language':
96
                    $languages = PMF_Language::getAvailableLanguages();
97
                    if (count($languages) > 0) {
98
                        echo PMF_Language::languageOptions(
99
                            str_replace(
100
                                array(
101
                                     'language_',
102
                                     '.php'
103
                                ),
104
                                '',
105
                                $faqConfig->get('main.language')
106
                            ),
107
                            false,
108
                            true
109
                        );
110
                    } else {
111
                        echo '<option value="language_en.php">English</option>';
112
                    }
113
                   break;
114
                
115
                case 'records.orderby':
116
                    echo PMF_Configuration::sortingOptions($faqConfig->get($key));
117
                    break;
118
                    
119
                case 'records.sortby':
120
                    printf('<option value="DESC"%s>%s</option>',
121
                        ('DESC' == $faqConfig->get($key)) ? ' selected="selected"' : '',
122
                        $PMF_LANG['ad_conf_desc']);
123
                    printf('<option value="ASC"%s>%s</option>',
124
                        ('ASC' == $faqConfig->get($key)) ? ' selected="selected"' : '',
125
                        $PMF_LANG['ad_conf_asc']);
126
                    break;
127
                    
128
                case 'security.permLevel':
129
                    echo PMF_Perm::permOptions($faqConfig->get($key));
130
                    break;
131
                    
132
                case 'main.templateSet':
133
                    $faqSystem = new PMF_System();
134
                    $templates = $faqSystem->getAvailableTemplates();
135
136
                    foreach ($templates as $template => $selected) {
137
                        printf ("<option%s>%s</option>",
138
                            ($selected === true ? ' selected="selected"' : ''),
139
                            $template
140
                        );
141
                    }
142
                    break;
143
                    
144
                case "records.attachmentsStorageType":
145
                    foreach($PMF_LANG['att_storage_type'] as $i => $item) {
146
                        $selected = $faqConfig->get($key) == $i
147
                                  ? ' selected="selected"'
148
                                  : '';
149
                        printf('<option value="%d"%s>%s</option>',
150
                               $i, $selected, $item);
151
                    }
152
                    break;
153
                    
154
                case "records.orderingPopularFaqs":
155
                    printf('<option value="visits"%s>%s</option>',
156
                        ('visits' == $faqConfig->get($key)) ? ' selected="selected"' : '',
157
                        $PMF_LANG['records.orderingPopularFaqs.visits']);
158
                    printf('<option value="voting"%s>%s</option>',
159
                        ('voting' == $faqConfig->get($key)) ? ' selected="selected"' : '',
160
                        $PMF_LANG['records.orderingPopularFaqs.voting']);
161
                    break;
162
163
                case "search.relevance":
164
                    printf('<option value="thema,content,keywords"%s>%s</option>',
165
                        ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected="selected"' : '',
166
                        $PMF_LANG['search.relevance.thema-content-keywords']);
167
                    printf('<option value="thema,keywords,content"%s>%s</option>',
168
                        ('thema,keywords,content' == $faqConfig->get($key)) ? ' selected="selected"' : '',
169
                        $PMF_LANG['search.relevance.thema-keywords-content']);
170
                    printf('<option value="content,thema,keywords"%s>%s</option>',
171
                        ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected="selected"' : '',
172
                        $PMF_LANG['search.relevance.content-thema-keywords']);
173
                    printf('<option value="content,keywords,thema"%s>%s</option>',
174
                        ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected="selected"' : '',
175
                        $PMF_LANG['search.relevance.content-keywords-thema']);
176
                    printf('<option value="keywords,content,thema"%s>%s</option>',
177
                        ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected="selected"' : '',
178
                        $PMF_LANG['search.relevance.keywords-content-thema']);
179
                    printf('<option value="keywords,thema,content"%s>%s</option>',
180
                        ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected="selected"' : '',
181
                        $PMF_LANG['search.relevance.keywords-thema-content']);
182
                    break;
183
            }
184
            
185
            echo "</select>\n</div>\n";
186
            break;
187
188
        case 'checkbox':
189
            printf('<input type="checkbox" name="edit[%s]" value="true"', $key);
190
            if ($faqConfig->get($key)) {
191
                echo ' checked';
192
            }
193
            if ('security.ldapSupport' === $key && !extension_loaded('ldap')) {
194
                echo ' disabled';
195
            }
196
            if ('security.useSslOnly' === $key && empty($_SERVER['HTTPS'])) {
197
                echo ' disabled';
198
            }
199
            if ('security.ssoSupport' === $key && empty($_SERVER['REMOTE_USER'])) {
200
                echo ' disabled';
201
            }
202
            echo " /></div>\n";
203
            break;
204
            
205
        case 'print':
206
            printf(
207
                '<input type="text" readonly name="edit[%s]" class="input-mini uneditable-input" value="%s" /></div>',
208
                $key,
209
                str_replace('"', '&quot;', $faqConfig->get($key)),
210
                $faqConfig->get($key)
211
            );
212
            break;
213
    }
214
}
215
216
header("Content-type: text/html; charset=utf-8");
217
218
foreach ($LANG_CONF as $key => $value) {
219
    if (strpos($key, $configMode) === 0) {
220
221
        if ('socialnetworks.twitterConsumerKey' == $key) {
222
            echo '<div class="control-group"><label class="control-label admin-config-label"></label>';
223
            echo '<div class="controls admin-config-control">';
224
            if ('' == $faqConfig->get('socialnetworks.twitterConsumerKey') ||
225
                '' == $faqConfig->get('socialnetworks.twitterConsumerSecret')) {
226
227
                echo '<a target="_blank" href="https://dev.twitter.com/apps/new">Create Twitter App for your FAQ</a>';
228
                echo "<br />\n";
229
                echo "Your Callback URL is: " .$faqConfig->get('main.referenceURL') . "/services/twitter/callback.php";
230
            }
231
232
            if (!isset($content)) {
233
                echo '<a target="_blank" href="../services/twitter/redirect.php">';
234
                echo '<img src="../assets/img/twitter.signin.png" alt="Sign in with Twitter"/></a>';
235
            } elseif (isset($content)) {
236
                echo $content->screen_name . "<br />\n";
237
                echo "<img src='" . $content->profile_image_url_https . "'><br />\n";
238
                echo "Follower: " . $content->followers_count . "<br />\n";
239
                echo "Status Count: " . $content->statuses_count . "<br />\n";
240
                echo "Status: " . $content->status->text;
241
            }
242
            echo '</div>';
243
            echo '</div>';
244
        }
245
?>
246
            <div class="control-group">
247
                <label class="control-label admin-config-label">
248
<?php
249
        switch ($key) {
250
251
            case 'records.maxAttachmentSize':
252
                printf($value[1], ini_get('upload_max_filesize'));
253
                break;
254
255
            case 'main.dateFormat':
256
                printf(
257
                    '<a target="_blank" href="http://www.php.net/manual/%s/function.date.php">%s</a>',
258
                    $LANGCODE,
259
                    $value[1]
260
                );
261
                break;
262
263
            default:
264
                echo $value[1];
265
                break;
266
        }
267
?>
268
                </label>
269
                <div class="controls admin-config-control">
270
                    <?php renderInputForm($key, $value[0]); ?>
271
                </div>
272
<?php
273
    }
274
}
275