diff --git a/lib/Ufixit.php b/lib/Ufixit.php index fb891af26..1a5200718 100755 --- a/lib/Ufixit.php +++ b/lib/Ufixit.php @@ -250,6 +250,28 @@ public function fixHeading($error_html, $new_content, $submitting_again = false) return $fixed_heading; } + /** + * Makes stylized p elements into headings + * @param string $error_html - The bad html that needs to be fixed + * @param string|array $new_content - The chosen heading level from the user + * @param bool $submitting_again - If the user is resubmitting their error fix + * @return string $fixed_heading - The html with corrected Heading + */ + public function makeHeading($error_html, $new_content, $submitting_again = false) + { + $fixed_heading = ''; + if ($new_content == '') { + return $fixed_heading; + } + + $fixed_heading = $error_html; + + $fixed_heading = preg_replace('/

(?!.*<\/p>)/', '', $fixed_heading); + + return $fixed_heading; + } + /** * Fixes table headers by changing td elements to th (and adding proper scope, of course) * @param string $error_html - The unmodified table without proper headings diff --git a/public/parseResults.php b/public/parseResults.php index c252714ac..239b50998 100755 --- a/public/parseResults.php +++ b/public/parseResults.php @@ -73,7 +73,7 @@ 'report_groups' => $udoit_report->content, 'post_path' => $post_input['path'], 'fixable_error_types' => ["cssTextHasContrast", "imgNonDecorativeHasAlt", "tableDataShouldHaveTh", "tableThShouldHaveScope", "headersHaveText", "aMustContainText", "imgAltIsDifferent", "imgAltIsTooLong"], - 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize"] + 'fixable_suggestions' => ["aSuspiciousLinkText", "imgHasAlt", "aLinkTextDoesNotBeginWithRedundantWord", "cssTextStyleEmphasize", "pNotUsedAsHeader"] ]; diff --git a/public/process.php b/public/process.php index fba39f45f..c645115c2 100755 --- a/public/process.php +++ b/public/process.php @@ -155,7 +155,12 @@ $remove_attr = preg_replace("/ data-api-endpoint.*$/s", "", $data['error_html']); $data['error_html'] = $remove_attr; break; - + + case 'pNotUsedAsHeader': + $new_content = filter_input(INPUT_POST, 'newcontent', FILTER_SANITIZE_STRING); + $corrected_error = $ufixit->makeHeading($data['error_html'], $new_content); + break; + case 'tableDataShouldHaveTh': // fixing table headers is a special case... $new_content = filter_input(INPUT_POST, 'newcontent', FILTER_SANITIZE_STRING); diff --git a/templates/partials/result_item/make_heading.php b/templates/partials/result_item/make_heading.php new file mode 100644 index 000000000..494328d93 --- /dev/null +++ b/templates/partials/result_item/make_heading.php @@ -0,0 +1,31 @@ +. +* +* Primary Author Contact: Jacob Bates +*/ +?> +

+ + + + + +
diff --git a/templates/partials/results_items.php b/templates/partials/results_items.php index df0f8f4b5..7dafae656 100644 --- a/templates/partials/results_items.php +++ b/templates/partials/results_items.php @@ -131,6 +131,10 @@ $result_template = 'image_alt'; break; + case "pNotUsedAsHeader": + $result_template = 'make_heading'; + break; + case "tableDataShouldHaveTh": $result_template = 'table_header'; break; diff --git a/tests/UfixitTest.php b/tests/UfixitTest.php index 6b4dd81d4..75fc583ef 100644 --- a/tests/UfixitTest.php +++ b/tests/UfixitTest.php @@ -135,6 +135,19 @@ public function testFixHeadingDeleteHeading() { $this->checkOutputBuffer(); } + public function testMakeHeading() { + $error_html = '

Paragraph text.

'; + $new_content = 'h2'; + $expected = '

Paragraph text.

'; + + ob_start(); + $temp = new Ufixit($this->data); + $output = $temp->makeHeading($error_html, $new_content); + + $this->assertEquals($expected, $output); + $this->checkOutputBuffer(); + } + public function testFixTableHeadersRow() { $error_html = '
Header OneHeader Two
1.304.50
'; $sel_header = 'row';