Mercurial > SimpleWebPresenter
diff Validator.inc @ 88:7a9c45b53866
Add possibility to validate using validator.w3.org
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 17 Oct 2012 20:43:07 +0200 |
| parents | |
| children | 8aadd7a23b68 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Validator.inc Wed Oct 17 20:43:07 2012 +0200 @@ -0,0 +1,48 @@ +<?php +include_once 'ScriptIncludeCache.inc'; + +/// @cond +$baseDir = dirname(__FILE__); +$cache = ScriptIncludeCache::instance(__FILE__); +$cache->includeOnce('common-functions.inc', $baseDir); +/// @endcond + + +class Validator { + + private $uri; + private $validator_url = 'http://validator.w3.org/check'; + + static function get_url_contents($url){ + $crl = curl_init(); + $timeout = 5; + + curl_setopt ($crl, CURLOPT_URL, $url); + curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); + $ret = curl_exec($crl); + curl_close($crl); + return $ret; + } + + function __construct($uri) + { + $this->uri = $uri; + } + + function check() + { + $request = urlencode($this->uri); + $query= '?uri=' . $request; + + $headers = getHeaders($this->validator_url . $query, 2); + return $headers['X-W3C-Validator-Status'] === "Valid"; + } + + function getUri() + { + return $this->uri; + } + +} +?> \ No newline at end of file
