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