Mercurial > SimpleWebPresenter
comparison Validator.inc @ 93:8aadd7a23b68
Moved some functionality from common-functions into Http class.
Reorganized Validator into a class hierarchy.
Added functionality for validating with a buffer in addition to URLs.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 18 Oct 2012 16:44:48 +0200 |
| parents | 7a9c45b53866 |
| children | 2370f4450983 |
comparison
equal
deleted
inserted
replaced
| 92:f468365813c9 | 93:8aadd7a23b68 |
|---|---|
| 2 include_once 'ScriptIncludeCache.inc'; | 2 include_once 'ScriptIncludeCache.inc'; |
| 3 | 3 |
| 4 /// @cond | 4 /// @cond |
| 5 $baseDir = dirname(__FILE__); | 5 $baseDir = dirname(__FILE__); |
| 6 $cache = ScriptIncludeCache::instance(__FILE__); | 6 $cache = ScriptIncludeCache::instance(__FILE__); |
| 7 $cache->includeOnce('common-functions.inc', $baseDir); | |
| 8 /// @endcond | 7 /// @endcond |
| 9 | 8 |
| 10 | 9 |
| 11 class Validator { | 10 abstract class Validator { |
| 12 | 11 abstract function check(); |
| 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 } | 12 } |
| 48 ?> | 13 ?> |
