コード例 #1
0
 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;
 }