diff OnlineURIValidator.inc.php @ 134:b6b4a58c7625

Using .inc.php rather than just .inc for include files.
author Tom Fredrik Blenning <bfg@bfgconsult.no>
date Sun, 22 Jan 2023 19:22:00 +0100
parents OnlineURIValidator.inc@2370f4450983
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OnlineURIValidator.inc.php	Sun Jan 22 19:22:00 2023 +0100
@@ -0,0 +1,49 @@
+<?php
+include_once 'ScriptIncludeCache.inc.php';
+
+/// @cond
+$baseDir = dirname(__FILE__);
+$cache = ScriptIncludeCache::instance(__FILE__);
+$cache->includeOnce('Http.inc.php', $baseDir);
+$cache->includeOnce('OnlineValidator.inc.php', $baseDir);
+/// @endcond
+
+/**
+ * Defines a validator which uses an online validator and a URI to the
+ * content
+ */
+class OnlineURIValidator extends OnlineValidator
+{
+  private $uri;
+
+  /**
+   * Constructs an OnlineURIValidator
+   *
+   * @param $uri The uri to validate
+   */
+  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";
+  }
+
+  /**
+   * Gets the URI for this validator
+   *
+   * @return string with the URI
+   */
+  function getUri()
+  {
+    return $this->uri;
+  }
+
+}
+?>
\ No newline at end of file