public static function checkColorContrastForNotVisitedLinkWCAG2AAA()
 {
     return BasicChecks::checkLinkContrastWcag2AAA("link", "link");
 }
 public static function checkLinkContrastWcag2AAA($cssPropriety, $bodyAttribute)
 {
     global $background, $foreground;
     global $global_e, $global_content_dom;
     global $stringa_testo_prova;
     $e = $global_e;
     $content_dom = $global_content_dom;
     BasicChecks::setCssSelectors($content_dom);
     if (!BasicChecks::isElementVisible($e)) {
         return true;
     }
     $background = '';
     $foreground = '';
     if (trim(BasicChecks::remove_children($e)) == "" || trim(BasicChecks::remove_children($e)) == " ") {
         //l'elemento non contiene testo "visibile": non eseguo il controllo del contrasto
         // the element has no text "visible": Do not run the contrast control
         return true;
     }
     $foreground = BasicChecks::getForegroundA($e, $cssPropriety);
     if ($foreground == "undetermined") {
         return true;
     }
     if (($foreground == "" || $foreground == null) && $bodyAttribute != null) {
         $app = $e->parent();
         while ($app->tag != "body" && $app->tag != "html" && $app->tag != null) {
             $app = $app->parent();
         }
         if ($app != null && isset($app->attr[$bodyAttribute])) {
             $foreground = $app->attr[$bodyAttribute];
         }
     }
     if ($foreground == "undetermined") {
         return true;
     }
     if ($foreground == "" || $foreground == null) {
         return true;
     }
     $background = BasicChecks::getBackgroundA($e, $cssPropriety);
     if ($background == "undetermined") {
         return true;
     }
     if ($background == "" || $background == null) {
         $background = BasicChecks::getBackground($e);
     }
     if ($background == "" || $background == null || $background == "-1") {
         return true;
     }
     if ($background == "undetermined") {
         return true;
     }
     $background = BasicChecks::convert_color_to_hex($background);
     $foreground = BasicChecks::convert_color_to_hex($foreground);
     $ris = '';
     $ris = BasicChecks::ContrastRatio(strtolower($background), strtolower($foreground));
     //echo "tag->"; echo $e->tag; echo " bg->"; echo $background; echo " fr->"; echo $foreground; echo " ris="; echo $ris; echo "<br>";
     $size = BasicChecks::fontSizeToPt($e);
     $bold = BasicChecks::get_p_css($e, "font-weight");
     if ($size < 0) {
         //formato non supportato
         return true;
     } elseif ($size >= 18 || $bold == "bold" && $size >= 14) {
         $threashold = 4.5;
     } else {
         $threashold = 7;
     }
     $stringa_testo_prova = '';
     $stringa_testo_prova = "<p>ris: " . $ris . " threashold: " . $threashold . "</p>";
     if ($ris < $threashold) {
         return false;
     } else {
         return true;
     }
     return true;
 }
 /**
  * private
  * check given html dom node for given check_id, save result into $this->result
  * parameters:
  * $e: simple html dom node
  * $check_id: check id
  *
  * return "success" or "fail"
  */
 private function check($e, $check_id)
 {
     global $msg, $base_href, $tag_size;
     // don't check the lines before $line_offset
     if ($e->linenumber <= $this->line_offset) {
         return;
     }
     if ($e->linenumber == 1 && $this->col_offset > 0) {
         $col_number = $e->colnumber - $this->col_offset;
     } else {
         $col_number = $e->colnumber;
     }
     $line_number = $e->linenumber - $this->line_offset;
     $result = $this->get_check_result($line_number, $col_number, $check_id);
     // has not been checked
     if (!$result) {
         $check_result = eval($this->check_func_array[$check_id]);
         //CSS code variable
         $css_code = BasicChecks::getCssOutput();
         $checksDAO = new ChecksDAO();
         $row = $checksDAO->getCheckByID($check_id);
         if (is_null($check_result)) {
             // when $check_result is not true/false, must be something wrong with the check function.
             // show warning message and skip this check
             $msg->addError(array('CHECK_FUNC', $row['html_tag'] . ': ' . _AC($row['name'])));
             // skip this check
             $check_result = true;
         }
         if ($check_result === true) {
             $result = SUCCESS_RESULT;
             //MB
             // number of success checks
             if (isset($this->num_success[$check_id])) {
                 $this->num_success[$check_id]++;
             } else {
                 $this->num_success[$check_id] = 1;
             }
         } else {
             $result = FAIL_RESULT;
         }
         if ($result == FAIL_RESULT) {
             $preview_html = $e->outertext;
             if (strlen($preview_html) > DISPLAY_PREVIEW_HTML_LENGTH) {
                 $html_code = substr($preview_html, 0, DISPLAY_PREVIEW_HTML_LENGTH) . " ...";
             } else {
                 $html_code = $preview_html;
             }
             // find out preview images for validation on <img>
             if (strtolower(trim($row['html_tag'])) == 'img') {
                 $image = BasicChecks::getFile($e->attr['src'], $base_href, $this->uri);
                 // The lines below to check the existence of the image slows down the validation process.
                 // So commented out.
                 //$handle = @fopen($image, 'r');
                 //if (!$handle) $image = '';
                 //else @fclose($handle);
                 // find out image alt text for preview image
                 if (!isset($e->attr['alt'])) {
                     $image_alt = '_NOT_DEFINED';
                 } else {
                     if ($e->attr['alt'] == '') {
                         $image_alt = '_EMPTY';
                     } else {
                         $image_alt = $e->attr['alt'];
                     }
                 }
             }
             // If its a duplicate ID, switch the line number from the element line (body)
             // to the line where the duplicate ID appears.
             global $has_duplicate_attribute;
             if (is_array($has_duplicate_attribute)) {
                 $line_number = $has_duplicate_attribute[0];
                 $html_code .= "(" . $has_duplicate_attribute[1] . ")";
             }
             $this->save_result($line_number, $col_number, $html_code, $check_id, $result, $image, $image_alt, $css_code);
         }
     }
     return $result;
 }