My Markup Validator

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by nonsensep, Oct 24, 2007.

  1. Slothie

    Slothie New Member

    Messages:
    1,430
    Likes Received:
    0
    Trophy Points:
    0
    $_ENV['http_referrer'] or something similar to that. I don't use it all that often.
     
  2. engel

    engel New Member

    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Close, $_SERVER['HTTP_REFERRER']
     
  3. Slothie

    Slothie New Member

    Messages:
    1,430
    Likes Received:
    0
    Trophy Points:
    0
    $_ENV contains $_SERVER so bleah.
     
  4. galaxyAbstractor

    galaxyAbstractor Community Advocate Community Support

    Messages:
    5,508
    Likes Received:
    35
    Trophy Points:
    48
    Last edited: Oct 29, 2007
  5. nonsensep

    nonsensep New Member

    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0
    I released version 1.2. It's under the same URI. Instead of it saying, for example:

    It would say this:

    It also replaces badly written code. And it's more efficient.

    Another change is that version 1.2 supports using "?uri=referer". But it doesn't give "referer" to W3C. It replaces it with $_SERVER["HTTP_REFERER"] then gives it to W3C. That way, there won't be a problem with the cache if more than one site uses "?uri=referer".

    EDIT: Also, I forgot to mention that I don't have cache working fully yet. But I'm working on it. I'll also be working on a CSS validator like this.
     
    Last edited: Oct 30, 2007
  6. engel

    engel New Member

    Messages:
    54
    Likes Received:
    0
    Trophy Points:
    0
    Any chance that the source for this will be released?
     
  7. arsonistx

    arsonistx New Member

    Messages:
    308
    Likes Received:
    0
    Trophy Points:
    0
    It would either be waiting a few seconds for the image to load or an hour for it to cache, lol. I wouldn't really mind if the image took a little while to load.
     
  8. Slothie

    Slothie New Member

    Messages:
    1,430
    Likes Received:
    0
    Trophy Points:
    0
    Ah, I guessed as much, sending curl requests to W3C's validator. I was wondering how someone with enough knowledge to write a validator was having trouble with basic PHP concepts .. heh...

    A really basic version of this script would be as follows

    1. Curl a request to http://validator.w3.org/ with the site name
    2. Get the results and parse it.
    3. Use GD Lib to generate an image.


    It would have been awesome if you wrote your own validator, in this case you're leeching off another's service. Its only a matter of time before they ban an IP from accessing their validator. If they wanted to do a service like this, they could have but it just puts to much stress on their server so they didn't.
     
  9. eminemix

    eminemix Member

    Messages:
    350
    Likes Received:
    0
    Trophy Points:
    16
    I think the W3 Validator is an Open Source. Look here, http://validator.w3.org/source/ !

    You can get it here.
    Now, you don't need to validate it at w3, you will do that here. ;)

    Keep up the good work !
     
    Last edited: Nov 2, 2007
  10. nonsensep

    nonsensep New Member

    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0
    I don't use curl. I use fsockopen. Here's the source:

    Code:
    <?php
    
    $uri = $_GET["uri"];
    $charset = $_GET["charset"];
    $doctype = $_GET["doctype"];
    
    if (trim(strtolower($uri)) == "referer") $uri = $_SERVER["HTTP_REFERER"];
    
    $fp = fsockopen("validator.w3.org", 80, $errno, $errstr, 30);
    if ($fp)
    {
        $send  = "GET /check?uri=" . $uri;
        if (trim($charset) !== "") $send .= "&charset=" . $charset;
        if (trim($doctype) !== "") $send .= "&doctype=" . $doctype;
        $send .= " HTTP/1.1\r\n";
        $send .= "Host: validator.w3.org\r\n";
        $send .= "Accept: text/html;\r\n";
        $send .= "Accept-Language: en-us, en;\r\n";
        $send .= "Connection: Close\r\n\r\n";
    
        fwrite($fp, $send);
        $out = "";
        while (!feof($fp))
        {
            $out .= fgets($fp, 128);
        }
        fclose($fp);
    
        $im = imagecreatetruecolor(176, 31);
    
        $body = substr($out, strpos($out, "<body"), strpos($out, ">", strpos($out, "</body")) - strpos($out, "<body"));
    
        $h2 = trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<h2")) + 1, strpos($body, "</h2>", strpos($body, ">", strpos($body, "<h2"))) - strpos($body, ">", strpos($body, "<h2")) - 1)));
    
        $result = str_replace(" validation", "", trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<td", strpos($body, "Result"))) + 1, strpos($body, "</td>", strpos($body, ">", strpos($body, "<td", strpos($body, "Result")))) - strpos($body, ">", strpos($body, "<td", strpos($body, "Result"))) - 1))));
        
        if (stripos($h2, "valid") != FALSE)
        {
            $doctype = trim(strip_tags(substr($body, strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"'))) + 1, strpos($body, "<select", strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"')))) - strpos($body, ">", strpos($body, "<td", strpos($body, 'for="doctype"'))) - 1)));
    
            if (stripos($h2, "not") != FALSE)
            {
                $error = trim(substr($result, strpos($result, ",") + 1));
                $warning = "0 Warnings";
                $back = imagecolorallocate($im, 210, 61, 36);
            }
            else if (stripos($h2, "tentatively") != FALSE)
            {
                $error = "0 Errors";
                $warning = str_replace("w", "W", trim(substr($result, strpos($result, ",") + 1)));
                $back = imagecolorallocate($im, 85, 176, 90);
            }
            else
            {
                $error = "0 Errors"; 
                $warning = "0 Warnings";
                $back = imagecolorallocate($im, 85, 176, 90);
            }
    
            if (substr($warning, 0, 1) == "1") $warning = str_replace("(s)", "", $warning);
            else $warning = str_replace("(s)", "s", $warning);
    
        
            $string = $doctype . "\n" . $error . ", " . $warning;
            $font = "VeraBd.ttf";
    
        }
        else
        {
            $doctype = $h2;
            $back = imagecolorallocate($im, 210, 61, 36);
    
            $string = wordwrap($h2, 28);
            $font = "VeraMoBd.ttf";
        }
    
        imagefill($im, 0, 0, $back);
    
        $fore = imagecolorallocate($im, 255, 255, 255);
    
        imagettftext($im, 7, 0, 4, 13, $fore, $font, $string);
    
        header("Content-type: image/png");
        imagepng($im);
        imagedestroy($im);
    
    }
    
    ?>
    About the source code, I'll look into that; It'd be much more efficient that way. Except for it being CGI, which I don't prefer.

    The problem with using my own code is that people might not trust that it works as well as say the W3C validator. Even if I use their source, it's not guaranteed to work exactly as their validator
     
    Last edited: Nov 4, 2007
  11. eminemix

    eminemix Member

    Messages:
    350
    Likes Received:
    0
    Trophy Points:
    16
    I think the real problem is that people don't care to have valid html/xhtml on their site.
    When microsoft or google doesn't have it valid, they can't be a good example to others.
     
  12. nonsensep

    nonsensep New Member

    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0
    Some people care to have valid code so that all of their viewers with different OS's, browser's, etc. can share the same viewing experience. Some people think that you don't need 100% perfect code for all your viewers to view the same thing. Others believe that you can't do certain things when trying to use valid code (not true). And finally some are just lazy and write awful markup.
     
  13. Slothie

    Slothie New Member

    Messages:
    1,430
    Likes Received:
    0
    Trophy Points:
    0
    Curl, fsockopen.

    No real difference except that curl would give you better performance.
     
  14. nonsensep

    nonsensep New Member

    Messages:
    39
    Likes Received:
    0
    Trophy Points:
    0

    well for now i'm going to put my project on hold. maybe forever. that is, once i find the time to interpret the perl code from the W3C's validator or write my own, i'll continue it.
     

Share This Page