Skip to content

Commit

Permalink
Merge pull request #50 from ucfcdl/UDOIT_issue13
Browse files Browse the repository at this point in the history
Enhancement #13 plus a fix for the base_url issue.
  • Loading branch information
bagofarms committed Dec 7, 2015
2 parents 59f8b37 + c12aa01 commit 9ad12ca
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions core/quail/common/accessibility_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,11 +1189,11 @@ function check()

if ($element->tagName === 'h1' || $element->tagName === 'h2' || $element->tagName === 'h3' || $element->tagName === 'h4' || $element->tagName === 'h5' || $element->tagName === 'h6') {
if ($luminosity < 3) {
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity);
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity . 'type: heading');
}
} else {
if ($luminosity < 4.5) {
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity);
$this->addReport($element, 'background: '. $background .' fore: '. $style['color'] . ' lum: '. $luminosity . 'type: text');
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
// Establish base_url given by canvas API
if( isset($_POST['custom_canvas_api_domain']) ){
$base_url = $_SESSION['base_url'] = 'https://'.$_POST['custom_canvas_api_domain'].'/';
} elseif( isset($_SESSION['base_url']) ){
$base_url = $_SESSION['base_url'];
} else {
echo '
<!DOCTYPE html>
Expand All @@ -94,7 +96,6 @@

// Pull the API key from the database
$dsn = "mysql:dbname=$db_name;host=$db_host";

try {
$dbh = new PDO($dsn, $db_user, $db_password);
} catch (PDOException $e) {
Expand Down
44 changes: 20 additions & 24 deletions lib/Ufixit.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,6 @@ public function fixAltText($error_html, $new_content, $submitting_again = false)
return $fixed_img;
}

/*********/

// public function fixLinkText($error_html, $new_content, $submitting_again = false)
// {
// $this->dom->loadHTML('<?xml encoding="utf-8" >' . $error_html);

// $as = $this->dom->getElementsByTagName('a');

// foreach ($as as $a) {
// var_dump($a);
// $a->setAttribute('nodeValue', $new_content);
// echo($new_content);
// $fixed_link = $this->dom->saveHTML($a);
// echo($fixed_link);
// }

// return $fixed_link;
// }



/**
* Fixes CSS contrast errors
* @param array $error_colors - The color(s) that need to be replaced
Expand All @@ -152,14 +131,31 @@ public function fixAltText($error_html, $new_content, $submitting_again = false)
* @param bool $submitting_again - If the user is resubmitting their error fix
* @return string $fixed_css - The html with corrected CSS
*/
public function fixCss($error_colors, $error_html, $new_content, $submitting_again = false)
public function fixCss($error_colors, $error_html, $new_content, $bold, $italic, $submitting_again = false)
{
preg_match_all('/<(\w+)\s+\w+.*?>/s', $error_html, $matches);

$fixed_css = $error_html;

for ($i = 0; $i < count($error_colors); $i++) {
$fixed_css = str_replace($error_colors[$i], $new_content[$i], $fixed_css);
}

$this->dom->loadHTML('<?xml encoding="utf-8" ?>' . $fixed_css );

$tag = $this->dom->getElementsByTagName( $matches[1][0] )->item(0);

if ($bold == 'bold') {
$tag->setAttribute('style', $tag->getAttribute('style').' font-weight: bold;');

}

if ($italic == 'italic') {
$tag->setAttribute('style', $tag->getAttribute('style').' font-style: italic;');
}

$fixed_css = $this->dom->saveHTML($tag);

return $fixed_css;
}

Expand All @@ -181,7 +177,7 @@ public function fixLink($error_html, $new_content, $submitting_again = false)

$tag = $this->dom->getElementsByTagName('a')->item(0);

$linkText = $this->dom->createTextNode($new_content);
$linkText = $this->dom->createTextNode( htmlspecialchars($new_content) );

$tag->nodeValue = "";
$tag->appendChild($linkText);
Expand Down Expand Up @@ -212,7 +208,7 @@ public function fixHeading($error_html, $new_content, $submitting_again = false)

$tag = $this->dom->getElementsByTagName( $matches[0] )->item(0);

$headingText = $this->dom->createTextNode($new_content);
$headingText = $this->dom->createTextNode( htmlspecialchars($new_content) );

$tag->appendChild($headingText);

Expand Down
1 change: 1 addition & 0 deletions lib/parseResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function isYouTubeVideo($link_url, $regex)
<div class="form-group no-margin margin-bottom">
<label for="newcontent[<?= $i; ?>]">Replacement color for <?= $item->colors[$i]; ?></label>
<input class="color {hash:true,caps:false} form-control" type="text" name="newcontent[<?= $i; ?>]" value="<?= $item->colors[$i]; ?>" placeholder="Replacement for <?= $item->colors[$i]; ?>">
<label><input name="add-bold" type="checkbox" value="bold" />&nbsp;Make this text bold</label>&nbsp;<label><input name="add-italic" type="checkbox" value="italic" />&nbsp;Make this text <span style="font-style: italics;">italicized</span></label><br />
</div>
<?php endfor; ?>
<button class="submit-content btn btn-default" type="submit">Submit</button>
Expand Down
6 changes: 4 additions & 2 deletions lib/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@
'error_html' => htmlspecialchars_decode($_POST['errorhtml']),
'error_colors' => isset($_POST['errorcolor']) ? $_POST['errorcolor'] : '',
'error_type' => $_POST['errortype'],
'new_content' => $_POST['newcontent']
'new_content' => $_POST['newcontent'],
'bold' => isset($_POST['add-bold']) ? $_POST['add-bold'] : '',
'italic' => isset($_POST['add-italic']) ? $_POST['add-italic'] : ''
];

session_start();
Expand Down Expand Up @@ -155,7 +157,7 @@
$corrected_error = $ufixit->fixLink($data['error_html'], $data['new_content'], $submitting_again);
break;
case 'cssTextHasContrast':
$corrected_error = $ufixit->fixCss($data['error_colors'], $data['error_html'], $data['new_content'], $submitting_again);
$corrected_error = $ufixit->fixCss($data['error_colors'], $data['error_html'], $data['new_content'], $data['bold'], $data['italic'], $submitting_again);
break;
case 'headersHaveText':
$corrected_error = $ufixit->fixHeading($data['error_html'], $data['new_content'], $submitting_again);
Expand Down

0 comments on commit 9ad12ca

Please sign in to comment.