Commit af7fb73a by Scott

Coding style (admin controllers)

parent 2076b209
...@@ -18,7 +18,7 @@ notifications: ...@@ -18,7 +18,7 @@ notifications:
before_script: before_script:
# PHP_CodeSniffer # PHP_CodeSniffer
- curl -L -o phpcs.phar https://github.com/squizlabs/PHP_CodeSniffer/releases/download/2.9.1/phpcs.phar - curl -L -o phpcs.phar https://github.com/squizlabs/PHP_CodeSniffer/releases/download/3.4.2/phpcs.phar
# PHPUnit - manually download old version so that it works on PHP 7 # PHPUnit - manually download old version so that it works on PHP 7
- curl -L -o phpunit.phar https://phar.phpunit.de/phpunit-4.8.35.phar - curl -L -o phpunit.phar https://phar.phpunit.de/phpunit-4.8.35.phar
# Basic config required for PHPUnit # Basic config required for PHPUnit
......
...@@ -133,9 +133,9 @@ class Approve extends BaseController ...@@ -133,9 +133,9 @@ class Approve extends BaseController
$qa_content['message_list']['messages'][] = $message; $qa_content['message_list']['messages'][] = $message;
} }
} else {
} else
$qa_content['title'] = qa_lang_html('admin/no_unapproved_found'); $qa_content['title'] = qa_lang_html('admin/no_unapproved_found');
}
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
......
...@@ -66,12 +66,10 @@ class Categories extends BaseController ...@@ -66,12 +66,10 @@ class Categories extends BaseController
$parentid = qa_get('addsub'); $parentid = qa_get('addsub');
if (isset($parentid)) if (isset($parentid))
$editcategory = array('parentid' => $parentid); $editcategory = array('parentid' => $parentid);
} else { } else {
if (qa_clicked('doaddcategory')) if (qa_clicked('doaddcategory')) {
$editcategory = array(); $editcategory = array();
} elseif (qa_clicked('dosavecategory')) {
elseif (qa_clicked('dosavecategory')) {
$parentid = qa_post_text('parent'); $parentid = qa_post_text('parent');
$editcategory = array('parentid' => strlen($parentid) ? $parentid : null); $editcategory = array('parentid' => strlen($parentid) ? $parentid : null);
} }
...@@ -94,10 +92,9 @@ class Categories extends BaseController ...@@ -94,10 +92,9 @@ class Categories extends BaseController
$securityexpired = false; $securityexpired = false;
if (qa_clicked('dosaveoptions')) { if (qa_clicked('dosaveoptions')) {
if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
} else {
else {
qa_set_option('allow_no_category', (int)qa_post_text('option_allow_no_category')); qa_set_option('allow_no_category', (int)qa_post_text('option_allow_no_category'));
qa_set_option('allow_no_sub_category', (int)qa_post_text('option_allow_no_sub_category')); qa_set_option('allow_no_sub_category', (int)qa_post_text('option_allow_no_sub_category'));
$savedoptions = true; $savedoptions = true;
...@@ -114,29 +111,24 @@ class Categories extends BaseController ...@@ -114,29 +111,24 @@ class Categories extends BaseController
qa_redirect(qa_request()); qa_redirect(qa_request());
else else
qa_redirect(qa_request(), array('edit' => @$editcategory['parentid'])); qa_redirect(qa_request(), array('edit' => @$editcategory['parentid']));
} elseif (qa_clicked('dosetmissing')) { } elseif (qa_clicked('dosetmissing')) {
if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
} else {
else {
$inreassign = qa_get_category_field_value('reassign'); $inreassign = qa_get_category_field_value('reassign');
qa_db_category_reassign($editcategory['categoryid'], $inreassign); qa_db_category_reassign($editcategory['categoryid'], $inreassign);
qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['categoryid'])); qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['categoryid']));
} }
} elseif (qa_clicked('dosavecategory')) { } elseif (qa_clicked('dosavecategory')) {
if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) if (!qa_check_form_security_code('admin/categories', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
} elseif (qa_post_text('dodelete')) {
elseif (qa_post_text('dodelete')) {
if (!$hassubcategory) { if (!$hassubcategory) {
$inreassign = qa_get_category_field_value('reassign'); $inreassign = qa_get_category_field_value('reassign');
qa_db_category_reassign($editcategory['categoryid'], $inreassign); qa_db_category_reassign($editcategory['categoryid'], $inreassign);
qa_db_category_delete($editcategory['categoryid']); qa_db_category_delete($editcategory['categoryid']);
qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['parentid'])); qa_redirect(qa_request(), array('recalc' => 1, 'edit' => $editcategory['parentid']));
} }
} else { } else {
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
...@@ -152,11 +144,11 @@ class Categories extends BaseController ...@@ -152,11 +144,11 @@ class Categories extends BaseController
// Verify the name is legitimate for that parent ID // Verify the name is legitimate for that parent ID
if (empty($inname)) if (empty($inname)) {
$errors['name'] = qa_lang('main/field_required'); $errors['name'] = qa_lang('main/field_required');
elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH) } elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH) {
$errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH); $errors['name'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TITLE_LENGTH);
else { } else {
foreach ($incategories as $category) { foreach ($incategories as $category) {
if (!strcmp($category['parentid'], $inparentid) && if (!strcmp($category['parentid'], $inparentid) &&
strcmp($category['categoryid'], @$editcategory['categoryid']) && strcmp($category['categoryid'], @$editcategory['categoryid']) &&
...@@ -240,7 +232,6 @@ class Categories extends BaseController ...@@ -240,7 +232,6 @@ class Categories extends BaseController
)); ));
qa_redirect(qa_request(), array('edit' => $editcategory['categoryid'], 'saved' => true, 'recalc' => (int)$recalc)); qa_redirect(qa_request(), array('edit' => $editcategory['categoryid'], 'saved' => true, 'recalc' => (int)$recalc));
} else { // creating a new one } else { // creating a new one
$categoryid = qa_db_category_create($inparentid, $inname, $inslug); $categoryid = qa_db_category_create($inparentid, $inname, $inslug);
...@@ -307,10 +298,15 @@ class Categories extends BaseController ...@@ -307,10 +298,15 @@ class Categories extends BaseController
), ),
); );
qa_set_up_category_field($qa_content, $qa_content['form']['fields']['reassign'], 'reassign', qa_set_up_category_field(
$categories, @$editcategory['categoryid'], qa_opt('allow_no_category'), qa_opt('allow_no_sub_category')); $qa_content,
$qa_content['form']['fields']['reassign'],
'reassign',
$categories,
@$editcategory['categoryid'],
qa_opt('allow_no_category'),
qa_opt('allow_no_sub_category')
);
} elseif (isset($editcategory)) { } elseif (isset($editcategory)) {
$qa_content['form'] = array( $qa_content['form'] = array(
'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"', 'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',
...@@ -386,20 +382,26 @@ class Categories extends BaseController ...@@ -386,20 +382,26 @@ class Categories extends BaseController
$childdepth = qa_db_category_child_depth($editcategory['categoryid']); $childdepth = qa_db_category_child_depth($editcategory['categoryid']);
qa_set_up_category_field($qa_content, $qa_content['form']['fields']['parent'], 'parent', qa_set_up_category_field(
isset($incategories) ? $incategories : $categories, isset($inparentid) ? $inparentid : @$editcategory['parentid'], $qa_content,
true, true, QA_CATEGORY_DEPTH - 1 - $childdepth, @$editcategory['categoryid']); $qa_content['form']['fields']['parent'],
'parent',
isset($incategories) ? $incategories : $categories,
isset($inparentid) ? $inparentid : @$editcategory['parentid'],
true,
true,
QA_CATEGORY_DEPTH - 1 - $childdepth,
@$editcategory['categoryid']
);
$qa_content['form']['fields']['parent']['options'][''] = qa_lang_html('admin/category_top_level'); $qa_content['form']['fields']['parent']['options'][''] = qa_lang_html('admin/category_top_level');
@$qa_content['form']['fields']['parent']['note'] .= qa_lang_html_sub('admin/category_max_depth_x', QA_CATEGORY_DEPTH); @$qa_content['form']['fields']['parent']['note'] .= qa_lang_html_sub('admin/category_max_depth_x', QA_CATEGORY_DEPTH);
} elseif (isset($editcategory['categoryid'])) { // existing category } elseif (isset($editcategory['categoryid'])) { // existing category
if ($hassubcategory) { if ($hassubcategory) {
$qa_content['form']['fields']['name']['note'] = qa_lang_html('admin/category_no_delete_subs'); $qa_content['form']['fields']['name']['note'] = qa_lang_html('admin/category_no_delete_subs');
unset($qa_content['form']['fields']['delete']); unset($qa_content['form']['fields']['delete']);
unset($qa_content['form']['fields']['reassign']); unset($qa_content['form']['fields']['reassign']);
} else { } else {
$qa_content['form']['fields']['delete'] = array( $qa_content['form']['fields']['delete'] = array(
'tags' => 'name="dodelete" id="dodelete"', 'tags' => 'name="dodelete" id="dodelete"',
...@@ -415,8 +417,17 @@ class Categories extends BaseController ...@@ -415,8 +417,17 @@ class Categories extends BaseController
'tags' => 'name="reassign"', 'tags' => 'name="reassign"',
); );
qa_set_up_category_field($qa_content, $qa_content['form']['fields']['reassign'], 'reassign', qa_set_up_category_field(
$categories, $editcategory['parentid'], true, true, null, $editcategory['categoryid']); $qa_content,
$qa_content['form']['fields']['reassign'],
'reassign',
$categories,
$editcategory['parentid'],
true,
true,
null,
$editcategory['categoryid']
);
} }
$qa_content['form']['fields']['questions'] = array( $qa_content['form']['fields']['questions'] = array(
...@@ -452,7 +463,6 @@ class Categories extends BaseController ...@@ -452,7 +463,6 @@ class Categories extends BaseController
'reassign_shown' => 'dodelete', 'reassign_shown' => 'dodelete',
'reassign_hidden' => '!dodelete', 'reassign_hidden' => '!dodelete',
)); ));
} else { // new category } else { // new category
unset($qa_content['form']['fields']['delete']); unset($qa_content['form']['fields']['delete']);
unset($qa_content['form']['fields']['reassign']); unset($qa_content['form']['fields']['reassign']);
...@@ -505,10 +515,9 @@ class Categories extends BaseController ...@@ -505,10 +515,9 @@ class Categories extends BaseController
} }
} }
if (isset($editcategory['position'])) if (isset($editcategory['position'])) {
$positionvalue = $positionoptions[$editcategory['position']]; $positionvalue = $positionoptions[$editcategory['position']];
} else {
else {
$positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x', qa_html($previous['title'])) : qa_lang_html('admin/first'); $positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x', qa_html($previous['title'])) : qa_lang_html('admin/first');
$positionoptions[1 + @max(array_keys($positionoptions))] = $positionvalue; $positionoptions[1 + @max(array_keys($positionoptions))] = $positionvalue;
} }
...@@ -551,10 +560,8 @@ class Categories extends BaseController ...@@ -551,10 +560,8 @@ class Categories extends BaseController
} else { } else {
$qa_content['form']['fields']['name']['note'] = qa_lang_html_sub('admin/category_no_add_subs_x', QA_CATEGORY_DEPTH); $qa_content['form']['fields']['name']['note'] = qa_lang_html_sub('admin/category_no_add_subs_x', QA_CATEGORY_DEPTH);
} }
} }
} }
} else { } else {
$qa_content['form'] = array( $qa_content['form'] = array(
'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"', 'tags' => 'method="post" action="' . qa_path_html(qa_request()) . '"',
...@@ -637,9 +644,9 @@ class Categories extends BaseController ...@@ -637,9 +644,9 @@ class Categories extends BaseController
'type' => 'checkbox', 'type' => 'checkbox',
'value' => qa_opt('allow_no_sub_category'), 'value' => qa_opt('allow_no_sub_category'),
); );
} else {
} else
unset($qa_content['form']['buttons']['save']); unset($qa_content['form']['buttons']['save']);
}
} }
if (qa_get('recalc')) { if (qa_get('recalc')) {
......
...@@ -134,9 +134,9 @@ class Flagged extends BaseController ...@@ -134,9 +134,9 @@ class Flagged extends BaseController
$qa_content['q_list']['qs'][] = $htmlfields; $qa_content['q_list']['qs'][] = $htmlfields;
} }
} else {
} else
$qa_content['title'] = qa_lang_html('admin/no_flagged_found'); $qa_content['title'] = qa_lang_html('admin/no_flagged_found');
}
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
......
...@@ -168,9 +168,9 @@ class Hidden extends BaseController ...@@ -168,9 +168,9 @@ class Hidden extends BaseController
$qa_content['q_list']['qs'][] = $htmlfields; $qa_content['q_list']['qs'][] = $htmlfields;
} }
} else {
} else
$qa_content['title'] = qa_lang_html('admin/no_hidden_found'); $qa_content['title'] = qa_lang_html('admin/no_hidden_found');
}
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
......
...@@ -156,9 +156,9 @@ class Moderate extends BaseController ...@@ -156,9 +156,9 @@ class Moderate extends BaseController
$qa_content['q_list']['qs'][] = $htmlfields; $qa_content['q_list']['qs'][] = $htmlfields;
} }
} else {
} else
$qa_content['title'] = qa_lang_html('admin/no_approve_found'); $qa_content['title'] = qa_lang_html('admin/no_approve_found');
}
$qa_content['navigation']['sub'] = qa_admin_sub_navigation(); $qa_content['navigation']['sub'] = qa_admin_sub_navigation();
......
...@@ -54,9 +54,9 @@ class Pages extends BaseController ...@@ -54,9 +54,9 @@ class Pages extends BaseController
if ((qa_clicked('doaddpage') || qa_clicked('doaddlink') || qa_get('doaddlink') || qa_clicked('dosavepage')) && !isset($editpage)) { if ((qa_clicked('doaddpage') || qa_clicked('doaddlink') || qa_get('doaddlink') || qa_clicked('dosavepage')) && !isset($editpage)) {
$editpage = array('title' => qa_get('text'), 'tags' => qa_get('url'), 'nav' => qa_get('nav'), 'position' => 1); $editpage = array('title' => qa_get('text'), 'tags' => qa_get('url'), 'nav' => qa_get('nav'), 'position' => 1);
$isexternal = qa_clicked('doaddlink') || qa_get('doaddlink') || qa_post_text('external'); $isexternal = qa_clicked('doaddlink') || qa_get('doaddlink') || qa_post_text('external');
} elseif (isset($editpage)) {
} elseif (isset($editpage))
$isexternal = $editpage['flags'] & QA_PAGE_FLAGS_EXTERNAL; $isexternal = $editpage['flags'] & QA_PAGE_FLAGS_EXTERNAL;
}
// Check admin privileges (do late to allow one DB query) // Check admin privileges (do late to allow one DB query)
...@@ -110,22 +110,20 @@ class Pages extends BaseController ...@@ -110,22 +110,20 @@ class Pages extends BaseController
$securityexpired = false; $securityexpired = false;
if (qa_clicked('docancel')) if (qa_clicked('docancel')) {
$editpage = null; $editpage = null;
} elseif (qa_clicked('dosaveoptions') || qa_clicked('doaddpage') || qa_clicked('doaddlink')) {
elseif (qa_clicked('dosaveoptions') || qa_clicked('doaddpage') || qa_clicked('doaddlink')) {
if (!qa_check_form_security_code('admin/pages', qa_post_text('code'))) if (!qa_check_form_security_code('admin/pages', qa_post_text('code')))
$securityexpired = true; $securityexpired = true;
else foreach ($navoptions as $optionname => $langkey) else foreach ($navoptions as $optionname => $langkey)
qa_set_option($optionname, (int)qa_post_text('option_' . $optionname)); qa_set_option($optionname, (int)qa_post_text('option_' . $optionname));
} elseif (qa_clicked('dosavepage')) { } elseif (qa_clicked('dosavepage')) {
require_once QA_INCLUDE_DIR . 'db/admin.php'; require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if (!qa_check_form_security_code('admin/pages', qa_post_text('code'))) if (!qa_check_form_security_code('admin/pages', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
else { } else {
$reloadpages = false; $reloadpages = false;
if (qa_post_text('dodelete')) { if (qa_post_text('dodelete')) {
...@@ -137,7 +135,6 @@ class Pages extends BaseController ...@@ -137,7 +135,6 @@ class Pages extends BaseController
$editpage = null; $editpage = null;
$reloadpages = true; $reloadpages = true;
} else { } else {
$inname = qa_post_text('name'); $inname = qa_post_text('name');
$inposition = qa_post_text('position'); $inposition = qa_post_text('position');
...@@ -150,7 +147,6 @@ class Pages extends BaseController ...@@ -150,7 +147,6 @@ class Pages extends BaseController
$errors = array(); $errors = array();
// Verify the name (navigation link) is legitimate // Verify the name (navigation link) is legitimate
if (empty($inname)) if (empty($inname))
$errors['name'] = qa_lang('main/field_required'); $errors['name'] = qa_lang('main/field_required');
elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH) elseif (qa_strlen($inname) > QA_DB_MAX_CAT_PAGE_TITLE_LENGTH)
...@@ -158,20 +154,16 @@ class Pages extends BaseController ...@@ -158,20 +154,16 @@ class Pages extends BaseController
if ($isexternal) { if ($isexternal) {
// Verify the url is legitimate (vaguely) // Verify the url is legitimate (vaguely)
if (empty($inurl)) if (empty($inurl))
$errors['url'] = qa_lang('main/field_required'); $errors['url'] = qa_lang('main/field_required');
elseif (qa_strlen($inurl) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH) elseif (qa_strlen($inurl) > QA_DB_MAX_CAT_PAGE_TAGS_LENGTH)
$errors['url'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH); $errors['url'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_CAT_PAGE_TAGS_LENGTH);
} else { } else {
// Verify the heading is legitimate // Verify the heading is legitimate
if (qa_strlen($inheading) > QA_DB_MAX_TITLE_LENGTH) if (qa_strlen($inheading) > QA_DB_MAX_TITLE_LENGTH)
$errors['heading'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_TITLE_LENGTH); $errors['heading'] = qa_lang_sub('main/max_length_x', QA_DB_MAX_TITLE_LENGTH);
// Verify the slug is legitimate (and try some defaults if we're creating a new page, and it's not) // Verify the slug is legitimate (and try some defaults if we're creating a new page, and it's not)
for ($attempt = 0; $attempt < 100; $attempt++) { for ($attempt = 0; $attempt < 100; $attempt++) {
switch ($attempt) { switch ($attempt) {
case 0: case 0:
...@@ -217,22 +209,24 @@ class Pages extends BaseController ...@@ -217,22 +209,24 @@ class Pages extends BaseController
// Perform appropriate database action // Perform appropriate database action
if (isset($editpage['pageid'])) { // changing existing page if (isset($editpage['pageid'])) { // changing existing page
$title = isset($errors['name']) ? $editpage['title'] : $inname;
if ($isexternal) { if ($isexternal) {
qa_db_page_set_fields($editpage['pageid'], qa_db_page_set_fields(
isset($errors['name']) ? $editpage['title'] : $inname, $editpage['pageid'],
$title,
QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0), QA_PAGE_FLAGS_EXTERNAL | ($innewwindow ? QA_PAGE_FLAGS_NEW_WINDOW : 0),
isset($errors['url']) ? $editpage['tags'] : $inurl, isset($errors['url']) ? $editpage['tags'] : $inurl,
null, null, $inpermit); null,
null,
$inpermit
);
} else { } else {
$setheading = isset($errors['heading']) ? $editpage['heading'] : $inheading; $setheading = isset($errors['heading']) ? $editpage['heading'] : $inheading;
$setslug = isset($errors['slug']) ? $editpage['tags'] : $inslug; $setslug = isset($errors['slug']) ? $editpage['tags'] : $inslug;
$setcontent = isset($errors['content']) ? $editpage['content'] : $incontent; $setcontent = isset($errors['content']) ? $editpage['content'] : $incontent;
qa_db_page_set_fields($editpage['pageid'], qa_db_page_set_fields($editpage['pageid'], $title, 0, $setslug, $setheading, $setcontent, $inpermit);
isset($errors['name']) ? $editpage['title'] : $inname,
0,
$setslug, $setheading, $setcontent, $inpermit);
$searchmodules = qa_load_modules_with('search', 'unindex_page'); $searchmodules = qa_load_modules_with('search', 'unindex_page');
foreach ($searchmodules as $searchmodule) foreach ($searchmodules as $searchmodule)
...@@ -253,7 +247,6 @@ class Pages extends BaseController ...@@ -253,7 +247,6 @@ class Pages extends BaseController
$editpage = null; $editpage = null;
else else
$editpage = @$pages[$editpage['pageid']]; $editpage = @$pages[$editpage['pageid']];
} else { // creating a new one } else { // creating a new one
if (empty($errors)) { if (empty($errors)) {
if ($isexternal) { if ($isexternal) {
...@@ -448,7 +441,6 @@ class Pages extends BaseController ...@@ -448,7 +441,6 @@ class Pages extends BaseController
unset($qa_content['form']['fields']['slug']); unset($qa_content['form']['fields']['slug']);
unset($qa_content['form']['fields']['heading']); unset($qa_content['form']['fields']['heading']);
unset($qa_content['form']['fields']['content']); unset($qa_content['form']['fields']['content']);
} else { } else {
unset($qa_content['form']['fields']['url']); unset($qa_content['form']['fields']['url']);
unset($qa_content['form']['fields']['newwindow']); unset($qa_content['form']['fields']['newwindow']);
...@@ -462,7 +454,6 @@ class Pages extends BaseController ...@@ -462,7 +454,6 @@ class Pages extends BaseController
($isexternal ? 'newwindow_display' : 'heading_display') => '!dodelete', ($isexternal ? 'newwindow_display' : 'heading_display') => '!dodelete',
'content_display' => '!dodelete', 'content_display' => '!dodelete',
)); ));
} else { } else {
unset($qa_content['form']['fields']['slug']); unset($qa_content['form']['fields']['slug']);
unset($qa_content['form']['fields']['delete']); unset($qa_content['form']['fields']['delete']);
...@@ -472,7 +463,6 @@ class Pages extends BaseController ...@@ -472,7 +463,6 @@ class Pages extends BaseController
unset($qa_content['form']['buttons']['saveview']); unset($qa_content['form']['buttons']['saveview']);
$qa_content['focusid'] = 'name'; $qa_content['focusid'] = 'name';
} else { } else {
// List of standard navigation links // List of standard navigation links
$qa_content['form'] = array( $qa_content['form'] = array(
......
...@@ -105,10 +105,9 @@ class Plugins extends BaseController ...@@ -105,10 +105,9 @@ class Plugins extends BaseController
$queries = $module->init_queries($tables); $queries = $module->init_queries($tables);
if (!empty($queries)) { if (!empty($queries)) {
if (qa_is_http_post()) if (qa_is_http_post()) {
qa_redirect('install'); qa_redirect('install');
} else {
else {
$qa_content['error'] = strtr(qa_lang_html('admin/module_x_database_init'), array( $qa_content['error'] = strtr(qa_lang_html('admin/module_x_database_init'), array(
'^1' => qa_html($name), '^1' => qa_html($name),
'^2' => qa_html($type), '^2' => qa_html($type),
...@@ -170,7 +169,6 @@ class Plugins extends BaseController ...@@ -170,7 +169,6 @@ class Plugins extends BaseController
$authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>'; $authorhtml = '<a href="' . qa_html($metadata['author_uri']) . '">' . $authorhtml . '</a>';
$authorhtml = qa_lang_html_sub('main/by_x', $authorhtml); $authorhtml = qa_lang_html_sub('main/by_x', $authorhtml);
} else } else
$authorhtml = ''; $authorhtml = '';
...@@ -182,9 +180,9 @@ class Plugins extends BaseController ...@@ -182,9 +180,9 @@ class Plugins extends BaseController
$qa_content['script_onloads'][] = array( $qa_content['script_onloads'][] = array(
"qa_version_check(" . qa_js($metadata['update_uri']) . ", " . qa_js($metadata['version'], true) . ", " . qa_js($elementid) . ", false);" "qa_version_check(" . qa_js($metadata['update_uri']) . ", " . qa_js($metadata['version'], true) . ", " . qa_js($elementid) . ", false);"
); );
} } else {
else
$updatehtml = ''; $updatehtml = '';
}
if (isset($metadata['description'])) if (isset($metadata['description']))
$deschtml = qa_html($metadata['description']); $deschtml = qa_html($metadata['description']);
...@@ -204,13 +202,13 @@ class Plugins extends BaseController ...@@ -204,13 +202,13 @@ class Plugins extends BaseController
$pluginhtml .= $deschtml . (strlen($deschtml) > 0 ? '<br>' : ''); $pluginhtml .= $deschtml . (strlen($deschtml) > 0 ? '<br>' : '');
$pluginhtml .= '<small style="color:#666">' . qa_html($pluginDirectoryPath) . '/</small>'; $pluginhtml .= '<small style="color:#666">' . qa_html($pluginDirectoryPath) . '/</small>';
if (qa_qa_version_below(@$metadata['min_q2a'])) if (qa_qa_version_below(@$metadata['min_q2a'])) {
$pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'. $pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'.
qa_lang_html_sub('admin/requires_q2a_version', qa_html($metadata['min_q2a'])).'</span>'; qa_lang_html_sub('admin/requires_q2a_version', qa_html($metadata['min_q2a'])).'</span>';
} elseif (qa_php_version_below(@$metadata['min_php'])) {
elseif (qa_php_version_below(@$metadata['min_php']))
$pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'. $pluginhtml = '<s style="color:#999">'.$pluginhtml.'</s><br><span style="color:#f00">'.
qa_lang_html_sub('admin/requires_php_version', qa_html($metadata['min_php'])).'</span>'; qa_lang_html_sub('admin/requires_php_version', qa_html($metadata['min_php'])).'</span>';
}
$qa_content['form_plugin_'.$pluginIndex] = array( $qa_content['form_plugin_'.$pluginIndex] = array(
'tags' => 'id="'.qa_html($hash).'"', 'tags' => 'id="'.qa_html($hash).'"',
......
...@@ -64,21 +64,18 @@ class UserFields extends BaseController ...@@ -64,21 +64,18 @@ class UserFields extends BaseController
$securityexpired = false; $securityexpired = false;
if (qa_clicked('docancel')) if (qa_clicked('docancel')) {
qa_redirect('admin/users'); qa_redirect('admin/users');
} elseif (qa_clicked('dosavefield')) {
elseif (qa_clicked('dosavefield')) {
require_once QA_INCLUDE_DIR . 'db/admin.php'; require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if (!qa_check_form_security_code('admin/userfields', qa_post_text('code'))) if (!qa_check_form_security_code('admin/userfields', qa_post_text('code')))
$securityexpired = true; $securityexpired = true;
else { else {
if (qa_post_text('dodelete')) { if (qa_post_text('dodelete')) {
qa_db_userfield_delete($editfield['fieldid']); qa_db_userfield_delete($editfield['fieldid']);
qa_redirect('admin/users'); qa_redirect('admin/users');
} else { } else {
$inname = qa_post_text('name'); $inname = qa_post_text('name');
$intype = qa_post_text('type'); $intype = qa_post_text('type');
...@@ -100,16 +97,15 @@ class UserFields extends BaseController ...@@ -100,16 +97,15 @@ class UserFields extends BaseController
qa_db_userfield_set_fields($editfield['fieldid'], isset($errors['name']) ? $editfield['content'] : $inname, $inflags, $inpermit); qa_db_userfield_set_fields($editfield['fieldid'], isset($errors['name']) ? $editfield['content'] : $inname, $inflags, $inpermit);
qa_db_userfield_move($editfield['fieldid'], $inposition); qa_db_userfield_move($editfield['fieldid'], $inposition);
if (empty($errors)) if (empty($errors)) {
qa_redirect('admin/users'); qa_redirect('admin/users');
} else {
else {
$userfields = qa_db_select_with_pending(qa_db_userfields_selectspec()); // reload after changes $userfields = qa_db_select_with_pending(qa_db_userfields_selectspec()); // reload after changes
foreach ($userfields as $userfield) foreach ($userfields as $userfield) {
if ($userfield['fieldid'] == $editfield['fieldid']) if ($userfield['fieldid'] == $editfield['fieldid'])
$editfield = $userfield; $editfield = $userfield;
}
} }
} elseif (empty($errors)) { // creating a new user field } elseif (empty($errors)) { // creating a new user field
for ($attempt = 0; $attempt < 1000; $attempt++) { for ($attempt = 0; $attempt < 1000; $attempt++) {
$suffix = $attempt ? ('-' . (1 + $attempt)) : ''; $suffix = $attempt ? ('-' . (1 + $attempt)) : '';
...@@ -160,9 +156,9 @@ class UserFields extends BaseController ...@@ -160,9 +156,9 @@ class UserFields extends BaseController
$previous = $userfield; $previous = $userfield;
} }
if (isset($editfield['position'])) if (isset($editfield['position'])) {
$positionvalue = $positionoptions[$editfield['position']]; $positionvalue = $positionoptions[$editfield['position']];
else { } else {
$positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x', qa_html(qa_user_userfield_label($previous))) : qa_lang_html('admin/first'); $positionvalue = isset($previous) ? qa_lang_html_sub('admin/after_x', qa_html(qa_user_userfield_label($previous))) : qa_lang_html('admin/first');
$positionoptions[1 + @max(array_keys($positionoptions))] = $positionvalue; $positionoptions[1 + @max(array_keys($positionoptions))] = $positionvalue;
} }
......
...@@ -58,19 +58,16 @@ class UserTitles extends BaseController ...@@ -58,19 +58,16 @@ class UserTitles extends BaseController
$securityexpired = false; $securityexpired = false;
if (qa_clicked('docancel')) if (qa_clicked('docancel')) {
qa_redirect('admin/users'); qa_redirect('admin/users');
} elseif (qa_clicked('dosavetitle')) {
elseif (qa_clicked('dosavetitle')) {
require_once QA_INCLUDE_DIR . 'util/string.php'; require_once QA_INCLUDE_DIR . 'util/string.php';
if (!qa_check_form_security_code('admin/usertitles', qa_post_text('code'))) if (!qa_check_form_security_code('admin/usertitles', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
} else {
else {
if (qa_post_text('dodelete')) { if (qa_post_text('dodelete')) {
unset($pointstitle[$oldpoints]); unset($pointstitle[$oldpoints]);
} else { } else {
$intitle = qa_post_text('title'); $intitle = qa_post_text('title');
$inpoints = qa_post_text('points'); $inpoints = qa_post_text('points');
...@@ -82,9 +79,9 @@ class UserTitles extends BaseController ...@@ -82,9 +79,9 @@ class UserTitles extends BaseController
if (!strlen($intitle)) if (!strlen($intitle))
$errors['title'] = qa_lang('main/field_required'); $errors['title'] = qa_lang('main/field_required');
if (!is_numeric($inpoints)) if (!is_numeric($inpoints)) {
$errors['points'] = qa_lang('main/field_required'); $errors['points'] = qa_lang('main/field_required');
else { } else {
$inpoints = (int)$inpoints; $inpoints = (int)$inpoints;
if (isset($pointstitle[$inpoints]) && ((!strlen(@$oldpoints)) || ($inpoints != $oldpoints))) if (isset($pointstitle[$inpoints]) && ((!strlen(@$oldpoints)) || ($inpoints != $oldpoints)))
...@@ -99,9 +96,9 @@ class UserTitles extends BaseController ...@@ -99,9 +96,9 @@ class UserTitles extends BaseController
unset($pointstitle[$oldpoints]); unset($pointstitle[$oldpoints]);
$pointstitle[$newpoints] = $newtitle; $pointstitle[$newpoints] = $newtitle;
} elseif (empty($errors)) { // creating a new user title
} elseif (empty($errors)) // creating a new user title
$pointstitle[$inpoints] = $intitle; $pointstitle[$inpoints] = $intitle;
}
} }
// Save the new option value // Save the new option value
......
...@@ -56,7 +56,6 @@ class Widgets extends BaseController ...@@ -56,7 +56,6 @@ class Widgets extends BaseController
if ($widget['widgetid'] == $widgetid) if ($widget['widgetid'] == $widgetid)
$editwidget = $widget; $editwidget = $widget;
} }
} else { } else {
$editwidget = array('title' => qa_post_text('title')); $editwidget = array('title' => qa_post_text('title'));
if (!isset($editwidget['title'])) if (!isset($editwidget['title']))
...@@ -129,7 +128,6 @@ class Widgets extends BaseController ...@@ -129,7 +128,6 @@ class Widgets extends BaseController
if ($isPagePlugin || !($page['flags'] & QA_PAGE_FLAGS_EXTERNAL)) if ($isPagePlugin || !($page['flags'] & QA_PAGE_FLAGS_EXTERNAL))
$templateoptions['custom-' . $page['pageid']] = qa_html($page['title']); $templateoptions['custom-' . $page['pageid']] = qa_html($page['title']);
} }
} }
} }
...@@ -138,20 +136,17 @@ class Widgets extends BaseController ...@@ -138,20 +136,17 @@ class Widgets extends BaseController
$securityexpired = false; $securityexpired = false;
if (qa_clicked('docancel')) if (qa_clicked('docancel')) {
qa_redirect('admin/layout'); qa_redirect('admin/layout');
} elseif (qa_clicked('dosavewidget')) {
elseif (qa_clicked('dosavewidget')) {
require_once QA_INCLUDE_DIR . 'db/admin.php'; require_once QA_INCLUDE_DIR . 'db/admin.php';
if (!qa_check_form_security_code('admin/widgets', qa_post_text('code'))) if (!qa_check_form_security_code('admin/widgets', qa_post_text('code'))) {
$securityexpired = true; $securityexpired = true;
} else {
else {
if (qa_post_text('dodelete')) { if (qa_post_text('dodelete')) {
qa_db_widget_delete($editwidget['widgetid']); qa_db_widget_delete($editwidget['widgetid']);
qa_redirect('admin/layout'); qa_redirect('admin/layout');
} else { } else {
if ($widgetfound) { if ($widgetfound) {
$intitle = qa_post_text('title'); $intitle = qa_post_text('title');
...@@ -173,7 +168,6 @@ class Widgets extends BaseController ...@@ -173,7 +168,6 @@ class Widgets extends BaseController
if (isset($editwidget['widgetid'])) { // changing existing widget if (isset($editwidget['widgetid'])) { // changing existing widget
$widgetid = $editwidget['widgetid']; $widgetid = $editwidget['widgetid'];
qa_db_widget_set_fields($widgetid, $intags); qa_db_widget_set_fields($widgetid, $intags);
} else } else
$widgetid = qa_db_widget_create($intitle, $intags); $widgetid = qa_db_widget_create($intitle, $intags);
...@@ -325,7 +319,6 @@ class Widgets extends BaseController ...@@ -325,7 +319,6 @@ class Widgets extends BaseController
'templates_display' => '!(dodelete||template_all)', 'templates_display' => '!(dodelete||template_all)',
'all_display' => '!dodelete', 'all_display' => '!dodelete',
)); ));
} else { } else {
unset($qa_content['form']['fields']['delete']); unset($qa_content['form']['fields']['delete']);
qa_set_display_rules($qa_content, array( qa_set_display_rules($qa_content, array(
...@@ -341,7 +334,6 @@ class Widgets extends BaseController ...@@ -341,7 +334,6 @@ class Widgets extends BaseController
unset($qa_content['form']['fields']['templates']); unset($qa_content['form']['fields']['templates']);
if (!isset($editwidget['widgetid'])) if (!isset($editwidget['widgetid']))
unset($qa_content['form']['buttons']['save']); unset($qa_content['form']['buttons']['save']);
} elseif (!count($positionoptions)) { } elseif (!count($positionoptions)) {
unset($qa_content['form']['fields']['title']['tight']); unset($qa_content['form']['fields']['title']['tight']);
$qa_content['form']['fields']['title']['error'] = qa_lang_html('admin/widget_no_positions'); $qa_content['form']['fields']['title']['error'] = qa_lang_html('admin/widget_no_positions');
......
...@@ -394,5 +394,4 @@ class DbSelect ...@@ -394,5 +394,4 @@ class DbSelect
$outresult = count($outresult) ? reset($outresult) : null; $outresult = count($outresult) ? reset($outresult) : null;
} }
} }
}
}
\ No newline at end of file
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
<rule ref="PSR2"> <rule ref="PSR2">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/> <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
<exclude name="Generic.Files.LineLength.TooLong"/> <exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="Generic.ControlStructures.InlineControlStructure"/>
<exclude name="Squiz.ControlStructures.ControlSignature"/> <!-- doesn't work without above rule -->
</rule> </rule>
<arg name="tab-width" value="4"/> <arg name="tab-width" value="4"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment