diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OnlineURIValidator.inc	Thu Oct 18 16:44:48 2012 +0200
@@ -0,0 +1,49 @@
+<?php
+include_once 'ScriptIncludeCache.inc';
+
+/// @cond
+$baseDir = dirname(__FILE__);
+$cache = ScriptIncludeCache::instance(__FILE__);
+$cache->includeOnce('Http.inc', $baseDir);
+$cache->includeOnce('OnlineValidator.inc', $baseDir);
+/// @endcond
+
+
+class OnlineURIValidator extends OnlineValidator
+{
+  private $uri;
+
+  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 = Http::getHeaders($this->validator_url . $query, 5);
+    return $headers['X-W3C-Validator-Status'] === "Valid";
+  }
+
+  function getUri()
+  {
+    return $this->uri;
+  }
+
+}
+?>
\ No newline at end of file