Mercurial > SimpleWebPresenter
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 86:b9654b9c4a66 | 88:7a9c45b53866 |
|---|---|
| 1 <?php | |
| 2 include_once 'ScriptIncludeCache.inc'; | |
| 3 | |
| 4 /// @cond | |
| 5 $baseDir = dirname(__FILE__); | |
| 6 $cache = ScriptIncludeCache::instance(__FILE__); | |
| 7 $cache->includeOnce('common-functions.inc', $baseDir); | |
| 8 /// @endcond | |
| 9 | |
| 10 | |
| 11 class Validator { | |
| 12 | |
| 13 private $uri; | |
| 14 private $validator_url = 'http://validator.w3.org/check'; | |
| 15 | |
| 16 static function get_url_contents($url){ | |
| 17 $crl = curl_init(); | |
| 18 $timeout = 5; | |
| 19 | |
| 20 curl_setopt ($crl, CURLOPT_URL, $url); | |
| 21 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
| 22 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
| 23 $ret = curl_exec($crl); | |
| 24 curl_close($crl); | |
| 25 return $ret; | |
| 26 } | |
| 27 | |
| 28 function __construct($uri) | |
| 29 { | |
| 30 $this->uri = $uri; | |
| 31 } | |
| 32 | |
| 33 function check() | |
| 34 { | |
| 35 $request = urlencode($this->uri); | |
| 36 $query= '?uri=' . $request; | |
| 37 | |
| 38 $headers = getHeaders($this->validator_url . $query, 2); | |
| 39 return $headers['X-W3C-Validator-Status'] === "Valid"; | |
| 40 } | |
| 41 | |
| 42 function getUri() | |
| 43 { | |
| 44 return $this->uri; | |
| 45 } | |
| 46 | |
| 47 } | |
| 48 ?> |
