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
Pull Request — master (#1139)
by
unknown
12:39
created

ajax.config_list.php ➔ renderInputForm()   D

Complexity

Conditions 43
Paths 32

Size

Total Lines 162
Code Lines 125

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 43
eloc 125
c 1
b 0
f 0
nc 32
nop 2
dl 0
loc 162
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-2014 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 mixed $key
54
 * @param string $type
55
 *
56
 * @return void
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 'select':
93
            printf('<select name="edit[%s]" size="1" class="form-control">', $key);
94
            
95
            switch ($key) {
96
                
97
                case 'main.language':
98
                    $languages = PMF_Language::getAvailableLanguages();
99
                    if (count($languages) > 0) {
100
                        echo PMF_Language::languageOptions(
101
                            str_replace(
102
                                array(
103
                                     'language_',
104
                                     '.php'
105
                                ),
106
                                '',
107
                                $faqConfig->get('main.language')
108
                            ),
109
                            false,
110
                            true
111
                        );
112
                    } else {
113
                        echo '<option value="language_en.php">English</option>';
114
                    }
115
                   break;
116
                
117
                case 'records.orderby':
118
                    echo PMF_Configuration::sortingOptions($faqConfig->get($key));
119
                    break;
120
                    
121
                case 'records.sortby':
122
                    printf('<option value="DESC"%s>%s</option>',
123
                        ('DESC' == $faqConfig->get($key)) ? ' selected' : '',
124
                        $PMF_LANG['ad_conf_desc']);
125
                    printf('<option value="ASC"%s>%s</option>',
126
                        ('ASC' == $faqConfig->get($key)) ? ' selected' : '',
127
                        $PMF_LANG['ad_conf_asc']);
128
                    break;
129
                    
130
                case 'security.permLevel':
131
                    echo PMF_Perm::permOptions($faqConfig->get($key));
132
                    break;
133
                    
134
                case 'main.templateSet':
135
                    $faqSystem = new PMF_System();
136
                    $templates = $faqSystem->getAvailableTemplates();
137
138
                    foreach ($templates as $template => $selected) {
139
                        printf ("<option%s>%s</option>",
140
                            ($selected === true ? ' selected' : ''),
141
                            $template
142
                        );
143
                    }
144
                    break;
145
                    
146
                case "records.attachmentsStorageType":
147
                    foreach($PMF_LANG['att_storage_type'] as $i => $item) {
148
                        $selected = $faqConfig->get($key) == $i
149
                                  ? ' selected'
150
                                  : '';
151
                        printf('<option value="%d"%s>%s</option>',
152
                               $i, $selected, $item);
153
                    }
154
                    break;
155
                    
156
                case "records.orderingPopularFaqs":
157
                    printf('<option value="visits"%s>%s</option>',
158
                        ('visits' == $faqConfig->get($key)) ? ' selected' : '',
159
                        $PMF_LANG['records.orderingPopularFaqs.visits']);
160
                    printf('<option value="voting"%s>%s</option>',
161
                        ('voting' == $faqConfig->get($key)) ? ' selected' : '',
162
                        $PMF_LANG['records.orderingPopularFaqs.voting']);
163
                    break;
164
165
                case "search.relevance":
166
                    printf('<option value="thema,content,keywords"%s>%s</option>',
167
                        ('thema,content,keywords' == $faqConfig->get($key)) ? ' selected' : '',
168
                        $PMF_LANG['search.relevance.thema-content-keywords']);
169
                    printf('<option value="thema,keywords,content"%s>%s</option>',
170
                        ('thema,keywords,content' == $faqConfig->get($key)) ? ' selected' : '',
171
                        $PMF_LANG['search.relevance.thema-keywords-content']);
172
                    printf('<option value="content,thema,keywords"%s>%s</option>',
173
                        ('content,thema,keywords' == $faqConfig->get($key)) ? ' selected' : '',
174
                        $PMF_LANG['search.relevance.content-thema-keywords']);
175
                    printf('<option value="content,keywords,thema"%s>%s</option>',
176
                        ('content,keywords,thema' == $faqConfig->get($key)) ? ' selected' : '',
177
                        $PMF_LANG['search.relevance.content-keywords-thema']);
178
                    printf('<option value="keywords,content,thema"%s>%s</option>',
179
                        ('keywords,content,thema' == $faqConfig->get($key)) ? ' selected' : '',
180
                        $PMF_LANG['search.relevance.keywords-content-thema']);
181
                    printf('<option value="keywords,thema,content"%s>%s</option>',
182
                        ('keywords,thema,content' == $faqConfig->get($key)) ? ' selected' : '',
183
                        $PMF_LANG['search.relevance.keywords-thema-content']);
184
                    break;
185
            }
186
            
187
            echo "</select>\n</div>\n";
188
            break;
189
190
        case 'checkbox':
191
            printf(
192
                '<div class="checkbox"><input type="checkbox" name="edit[%s]" value="true"',
193
                $key
194
            );
195
            if ($faqConfig->get($key)) {
196
                echo ' checked';
197
            }
198
            if ('security.ldapSupport' === $key && !extension_loaded('ldap')) {
199
                echo ' disabled';
200
            }
201
            if ('security.useSslOnly' === $key && empty($_SERVER['HTTPS'])) {
202
                echo ' disabled';
203
            }
204
            if ('security.ssoSupport' === $key && empty($_SERVER['REMOTE_USER'])) {
205
                echo ' disabled';
206
            }
207
            echo ">\n</div></div>\n";
208
            break;
209
            
210
        case 'print':
211
            printf(
212
                '<input type="text" readonly name="edit[%s]" class="form-control" value="%s"></div>',
213
                $key,
214
                str_replace('"', '&quot;', $faqConfig->get($key)),
215
                $faqConfig->get($key)
216
            );
217
            break;
218
    }
219
}
220
221
header("Content-type: text/html; charset=utf-8");
222
223
foreach ($LANG_CONF as $key => $value) {
224
    if (strpos($key, $configMode) === 0) {
225
226
        if ('socialnetworks.twitterConsumerKey' == $key) {
227
            echo '<div class="form-group"><label class="control-label col-lg-3"></label>';
228
            echo '<div class="col-lg-9">';
229
            if ('' == $faqConfig->get('socialnetworks.twitterConsumerKey') ||
230
                '' == $faqConfig->get('socialnetworks.twitterConsumerSecret')) {
231
232
                echo '<a target="_blank" href="https://dev.twitter.com/apps/new">Create Twitter App for your FAQ</a>';
233
                echo "<br />\n";
234
                echo "Your Callback URL is: " .$faqConfig->get('main.referenceURL') . "/services/twitter/callback.php";
235
            }
236
237
            if (!isset($content)) {
238
                echo '<br><a target="_blank" href="../services/twitter/redirect.php">';
239
                echo '<img src="../assets/img/twitter.signin.png" alt="Sign in with Twitter"/></a>';
240
            } elseif (isset($content)) {
241
                echo $content->screen_name . "<br />\n";
242
                echo "<img src='" . $content->profile_image_url_https . "'><br />\n";
243
                echo "Follower: " . $content->followers_count . "<br />\n";
244
                echo "Status Count: " . $content->statuses_count . "<br />\n";
245
                echo "Status: " . $content->status->text;
246
            }
247
            echo '</div></div>';
248
        }
249
?>
250
            <div class="form-group">
251
                <label class="control-label col-lg-3">
252
<?php
253
        switch ($key) {
254
255
            case 'records.maxAttachmentSize':
256
                printf($value[1], ini_get('upload_max_filesize'));
257
                break;
258
259
            case 'main.dateFormat':
260
                printf(
261
                    '<a target="_blank" href="http://www.php.net/manual/%s/function.date.php">%s</a>',
262
                    $LANGCODE,
263
                    $value[1]
264
                );
265
                break;
266
267
            default:
268
                echo $value[1];
269
                break;
270
        }
271
?>
272
                </label>
273
                <div class="col-lg-6">
274
                    <?php renderInputForm($key, $value[0]); ?>
275
                </div>
276
<?php
277
    }
278
}
279