Skip to content

Commit 2cf739b

Browse files
authored
Merge pull request #894 from pupi1985/patch-141
Fix many issues regarding $errors variable and @ character
2 parents 947a970 + 64725d8 commit 2cf739b

18 files changed

Lines changed: 88 additions & 77 deletions

qa-include/app/captcha.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,22 @@ function qa_set_up_captcha_field(&$qa_content, &$fields, $errors, $note = null)
8282
// workaround for reCAPTCHA, to load multiple instances via JS
8383
$count = @++$qa_content['qa_captcha_count'];
8484

85+
$hasCapatchaError = array_key_exists('captcha', $errors);
86+
8587
if ($count > 1) {
8688
// use blank captcha in order to load via JS
8789
$html = '';
8890
} else {
8991
// first captcha is always loaded explicitly
9092
$qa_content['script_var']['qa_captcha_in'] = 'qa_captcha_div_1';
91-
$html = $captcha->form_html($qa_content, @$errors['captcha']);
93+
$html = $captcha->form_html($qa_content, $hasCapatchaError ? $errors['captcha'] : null);
9294
}
9395

9496
$fields['captcha'] = array(
9597
'type' => 'custom',
9698
'label' => qa_lang_html('misc/captcha_label'),
9799
'html' => '<div id="qa_captcha_div_' . $count . '">' . $html . '</div>',
98-
'error' => @array_key_exists('captcha', $errors) ? qa_lang_html('misc/captcha_error') : null,
100+
'error' => $hasCapatchaError ? qa_lang_html('misc/captcha_error') : null,
99101
'note' => $note,
100102
);
101103

qa-include/pages/account.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070

7171
// Process profile if saved
7272

73+
$errors = array();
74+
7375
// If the post_max_size is exceeded then the $_POST array is empty so no field processing can be done
7476
if (qa_post_limit_exceeded())
7577
$errors['avatar'] = qa_lang('main/file_upload_limit_exceeded');
@@ -247,7 +249,7 @@
247249
$qa_content = qa_content_prepare();
248250

249251
$qa_content['title'] = qa_lang_html('profile/my_account_title');
250-
$qa_content['error'] = @$errors['page'];
252+
$qa_content['error'] = isset($errors['page']) ? $errors['page'] : null;
251253

252254
$qa_content['form_profile'] = array(
253255
'tags' => 'enctype="multipart/form-data" method="post" action="' . qa_self_html() . '"',
@@ -272,7 +274,7 @@
272274
'label' => qa_lang_html('users/handle_label'),
273275
'tags' => 'name="handle"',
274276
'value' => qa_html(isset($inhandle) ? $inhandle : $useraccount['handle']),
275-
'error' => qa_html(@$errors['handle']),
277+
'error' => qa_html(isset($errors['handle']) ? $errors['handle'] : null),
276278
'type' => ($changehandle && !$isblocked) ? 'text' : 'static',
277279
),
278280

@@ -391,7 +393,7 @@
391393
'tags' => 'name="avatar"',
392394
'options' => $avataroptions,
393395
'value' => $avatarvalue,
394-
'error' => qa_html(@$errors['avatar']),
396+
'error' => qa_html(isset($errors['avatar']) ? $errors['avatar'] : null),
395397
);
396398

397399
} else {
@@ -414,7 +416,7 @@
414416
'label' => qa_html($label),
415417
'tags' => 'name="field_' . $userfield['fieldid'] . '"',
416418
'value' => qa_html($value),
417-
'error' => qa_html(@$errors[$userfield['fieldid']]),
419+
'error' => qa_html(isset($errors[$userfield['fieldid']]) ? $errors[$userfield['fieldid']] : null),
418420
'rows' => ($userfield['flags'] & QA_FIELD_FLAGS_MULTI_LINE) ? 8 : null,
419421
'type' => $isblocked ? 'static' : 'text',
420422
);
@@ -443,21 +445,21 @@
443445
'tags' => 'name="oldpassword"',
444446
'value' => qa_html(@$inoldpassword),
445447
'type' => 'password',
446-
'error' => qa_html(@$errors['oldpassword']),
448+
'error' => qa_html(isset($errors['oldpassword']) ? $errors['oldpassword'] : null),
447449
),
448450

449451
'new_1' => array(
450452
'label' => qa_lang_html('users/new_password_1'),
451453
'tags' => 'name="newpassword1"',
452454
'type' => 'password',
453-
'error' => qa_html(@$errors['password']),
455+
'error' => qa_html(isset($errors['password']) ? $errors['password'] : null),
454456
),
455457

456458
'new_2' => array(
457459
'label' => qa_lang_html('users/new_password_2'),
458460
'tags' => 'name="newpassword2"',
459461
'type' => 'password',
460-
'error' => qa_html(@$errors['newpassword2']),
462+
'error' => qa_html(isset($errors['newpassword2']) ? $errors['newpassword2'] : null),
461463
),
462464
),
463465

qa-include/pages/admin/admin-categories.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
}
9494
}
9595

96+
$errors = array();
9697

9798
// Process saving an old or new category
9899

@@ -133,7 +134,6 @@
133134
$incontent = qa_post_text('content');
134135
$inparentid = $setparent ? qa_get_category_field_value('parent') : $editcategory['parentid'];
135136
$inposition = qa_post_text('position');
136-
$errors = array();
137137

138138
// Check the parent ID
139139

@@ -295,7 +295,7 @@
295295
'tags' => 'name="name" id="name"',
296296
'label' => qa_lang_html(count($categories) ? 'admin/category_name' : 'admin/category_name_first'),
297297
'value' => qa_html(isset($inname) ? $inname : @$editcategory['title']),
298-
'error' => qa_html(@$errors['name']),
298+
'error' => qa_html(isset($errors['name']) ? $errors['name'] : null),
299299
),
300300

301301
'questions' => array(),
@@ -309,15 +309,15 @@
309309
'tags' => 'name="slug"',
310310
'label' => qa_lang_html('admin/category_slug'),
311311
'value' => qa_html(isset($inslug) ? $inslug : @$editcategory['tags']),
312-
'error' => qa_html(@$errors['slug']),
312+
'error' => qa_html(isset($errors['slug']) ? $errors['slug'] : null),
313313
),
314314

315315
'content' => array(
316316
'id' => 'content_display',
317317
'tags' => 'name="content"',
318318
'label' => qa_lang_html('admin/category_description'),
319319
'value' => qa_html(isset($incontent) ? $incontent : @$editcategory['content']),
320-
'error' => qa_html(@$errors['content']),
320+
'error' => qa_html(isset($errors['content']) ? $errors['content'] : null),
321321
'rows' => 2,
322322
),
323323
),

qa-include/pages/admin/admin-default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ function qa_optionfield_make_select(&$optionfield, $options, $value, $default)
976976
'tags' => 'name="option_' . $optionname . '" id="option_' . $optionname . '"',
977977
'value' => qa_html($value),
978978
'type' => $type,
979-
'error' => qa_html(@$errors[$optionname]),
979+
'error' => qa_html(isset($errors[$optionname]) ? $errors[$optionname] : null),
980980
);
981981

982982
if (isset($optionmaximum[$optionname]))

qa-include/pages/admin/admin-pages.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999

100100
$securityexpired = false;
101101

102+
$errors = array();
103+
102104
if (qa_clicked('docancel'))
103105
$editpage = null;
104106

@@ -136,8 +138,6 @@
136138
$inheading = qa_post_text('heading');
137139
$incontent = qa_post_text('content');
138140

139-
$errors = array();
140-
141141
// Verify the name (navigation link) is legitimate
142142

143143
if (empty($inname))
@@ -339,7 +339,7 @@
339339
'tags' => 'name="name" id="name"',
340340
'label' => qa_lang_html($isexternal ? 'admin/link_name' : 'admin/page_name'),
341341
'value' => qa_html(isset($inname) ? $inname : @$editpage['title']),
342-
'error' => qa_html(@$errors['name']),
342+
'error' => qa_html(isset($errors['name']) ? $errors['name'] : null),
343343
),
344344

345345
'delete' => array(
@@ -372,15 +372,15 @@
372372
'tags' => 'name="slug"',
373373
'label' => qa_lang_html('admin/page_slug'),
374374
'value' => qa_html(isset($inslug) ? $inslug : @$editpage['tags']),
375-
'error' => qa_html(@$errors['slug']),
375+
'error' => qa_html(isset($errors['slug']) ? $errors['slug'] : null),
376376
),
377377

378378
'url' => array(
379379
'id' => 'url_display',
380380
'tags' => 'name="url"',
381381
'label' => qa_lang_html('admin/link_url'),
382382
'value' => qa_html(isset($inurl) ? $inurl : @$editpage['tags']),
383-
'error' => qa_html(@$errors['url']),
383+
'error' => qa_html(isset($errors['url']) ? $errors['url'] : null),
384384
),
385385

386386
'newwindow' => array(
@@ -396,15 +396,15 @@
396396
'tags' => 'name="heading"',
397397
'label' => qa_lang_html('admin/page_heading'),
398398
'value' => qa_html(isset($inheading) ? $inheading : @$editpage['heading']),
399-
'error' => qa_html(@$errors['heading']),
399+
'error' => qa_html(isset($errors['heading']) ? $errors['heading'] : null),
400400
),
401401

402402
'content' => array(
403403
'id' => 'content_display',
404404
'tags' => 'name="content"',
405405
'label' => qa_lang_html('admin/page_content_html'),
406406
'value' => qa_html(isset($incontent) ? $incontent : @$editpage['content']),
407-
'error' => qa_html(@$errors['content']),
407+
'error' => qa_html(isset($errors['content']) ? $errors['content'] : null),
408408
'rows' => 16,
409409
),
410410
),

qa-include/pages/admin/admin-userfields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353

5454
$securityexpired = false;
5555

56+
$errors = array();
57+
5658
if (qa_clicked('docancel'))
5759
qa_redirect('admin/users');
5860

@@ -76,8 +78,6 @@
7678
$inposition = qa_post_text('position');
7779
$inpermit = (int)qa_post_text('permit');
7880

79-
$errors = array();
80-
8181
// Verify the name is legitimate
8282

8383
if (qa_strlen($inname) > QA_DB_MAX_PROFILE_TITLE_LENGTH)
@@ -175,7 +175,7 @@
175175
'tags' => 'name="name" id="name"',
176176
'label' => qa_lang_html('admin/field_name'),
177177
'value' => qa_html(isset($inname) ? $inname : qa_user_userfield_label($editfield)),
178-
'error' => qa_html(@$errors['name']),
178+
'error' => qa_html(isset($errors['name']) ? $errors['name'] : null),
179179
),
180180

181181
'delete' => array(

qa-include/pages/admin/admin-usertitles.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
$securityexpired = false;
4949

50+
$errors = array();
51+
5052
if (qa_clicked('docancel'))
5153
qa_redirect('admin/users');
5254

@@ -64,8 +66,6 @@
6466
$intitle = qa_post_text('title');
6567
$inpoints = qa_post_text('points');
6668

67-
$errors = array();
68-
6969
// Verify the title and points are legitimate
7070

7171
if (!strlen($intitle))
@@ -126,7 +126,7 @@
126126
'tags' => 'name="title" id="title"',
127127
'label' => qa_lang_html('admin/user_title'),
128128
'value' => qa_html(isset($intitle) ? $intitle : @$pointstitle[$oldpoints]),
129-
'error' => qa_html(@$errors['title']),
129+
'error' => qa_html(isset($errors['title']) ? $errors['title'] : null),
130130
),
131131

132132
'delete' => array(
@@ -142,7 +142,7 @@
142142
'label' => qa_lang_html('admin/points_required'),
143143
'type' => 'number',
144144
'value' => qa_html(isset($inpoints) ? $inpoints : @$oldpoints),
145-
'error' => qa_html(@$errors['points']),
145+
'error' => qa_html(isset($errors['points']) ? $errors['points'] : null),
146146
),
147147
),
148148

qa-include/pages/ask.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
$in['tags'] = qa_get_tags_field_value('tags');
105105
}
106106

107+
$errors = array();
108+
107109
if (qa_clicked('doask')) {
108110
require_once QA_INCLUDE_DIR.'app/post-create.php';
109111
require_once QA_INCLUDE_DIR.'util/string.php';
@@ -118,7 +120,6 @@
118120

119121
qa_get_post_content('editor', 'content', $in['editor'], $in['content'], $in['format'], $in['text']);
120122

121-
$errors = array();
122123

123124
if (!qa_check_form_security_code('ask', qa_post_text('code'))) {
124125
$errors['page'] = qa_lang_html('misc/form_security_again');
@@ -181,14 +182,14 @@
181182
$qa_content = qa_content_prepare(false, array_keys(qa_category_path($categories, @$in['categoryid'])));
182183

183184
$qa_content['title'] = qa_lang_html(isset($followanswer) ? 'question/ask_follow_title' : 'question/ask_title');
184-
$qa_content['error'] = @$errors['page'];
185+
$qa_content['error'] = isset($errors['page']) ? $errors['page'] : null;
185186

186187
$editorname = isset($in['editor']) ? $in['editor'] : qa_opt('editor_for_qs');
187188
$editor = qa_load_editor(@$in['content'], @$in['format'], $editorname);
188189

189190
$field = qa_editor_load_field($editor, $qa_content, @$in['content'], @$in['format'], 'content', 12, false);
190191
$field['label'] = qa_lang_html('question/q_content_label');
191-
$field['error'] = qa_html(@$errors['content']);
192+
$field['error'] = qa_html(isset($errors['content']) ? $errors['content'] : null);
192193

193194
$custom = qa_opt('show_custom_ask') ? trim(qa_opt('custom_ask')) : '';
194195

@@ -207,7 +208,7 @@
207208
'label' => qa_lang_html('question/q_title_label'),
208209
'tags' => 'name="title" id="title" autocomplete="off"',
209210
'value' => qa_html(@$in['title']),
210-
'error' => qa_html(@$errors['title']),
211+
'error' => qa_html(isset($errors['title']) ? $errors['title'] : null),
211212
),
212213

213214
'similar' => array(
@@ -260,7 +261,7 @@
260261
if (qa_using_categories() && count($categories)) {
261262
$field = array(
262263
'label' => qa_lang_html('question/q_category_label'),
263-
'error' => qa_html(@$errors['categoryid']),
264+
'error' => qa_html(isset($errors['categoryid']) ? $errors['categoryid'] : null),
264265
);
265266

266267
qa_set_up_category_field($qa_content, $field, 'category', $categories, $in['categoryid'], true, qa_opt('allow_no_sub_category'));
@@ -276,15 +277,15 @@
276277
'label' => qa_html(qa_opt('extra_field_prompt')),
277278
'tags' => 'name="extra"',
278279
'value' => qa_html(@$in['extra']),
279-
'error' => qa_html(@$errors['extra']),
280+
'error' => qa_html(isset($errors['extra']) ? $errors['extra'] : null),
280281
);
281282

282283
qa_array_insert($qa_content['form']['fields'], null, array('extra' => $field));
283284
}
284285

285286
if (qa_using_tags()) {
286287
$field = array(
287-
'error' => qa_html(@$errors['tags']),
288+
'error' => qa_html(isset($errors['tags']) ? $errors['tags'] : null),
288289
);
289290

290291
qa_set_up_tag_field($qa_content, $field, 'tags', isset($in['tags']) ? $in['tags'] : array(), array(),
@@ -298,11 +299,11 @@
298299
}
299300

300301
qa_set_up_notify_fields($qa_content, $qa_content['form']['fields'], 'Q', qa_get_logged_in_email(),
301-
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), @$in['email'], @$errors['email']);
302+
isset($in['notify']) ? $in['notify'] : qa_opt('notify_users_default'), @$in['email'], isset($errors['email']) ? $errors['email'] : null);
302303

303304
if ($captchareason) {
304305
require_once QA_INCLUDE_DIR.'app/captcha.php';
305-
qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors, qa_captcha_reason_note($captchareason));
306+
qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], $errors, qa_captcha_reason_note($captchareason));
306307
}
307308

308309
$qa_content['focusid'] = 'title';

qa-include/pages/feedback.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959

6060
$feedbacksent = false;
6161

62+
$errors = array();
63+
6264
if (qa_clicked('dofeedback')) {
6365
require_once QA_INCLUDE_DIR . 'app/emails.php';
6466
require_once QA_INCLUDE_DIR . 'util/string.php';
@@ -137,7 +139,7 @@
137139
'tags' => 'name="message" id="message"',
138140
'value' => qa_html(@$inmessage),
139141
'rows' => 8,
140-
'error' => qa_html(@$errors['message']),
142+
'error' => qa_html(isset($errors['message']) ? $errors['message'] : null),
141143
),
142144

143145
'name' => array(
@@ -170,7 +172,7 @@
170172
);
171173

172174
if ($usecaptcha && !$feedbacksent)
173-
qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], @$errors);
175+
qa_set_up_captcha_field($qa_content, $qa_content['form']['fields'], $errors);
174176

175177

176178
$qa_content['focusid'] = 'message';

0 commit comments

Comments
 (0)