diff --git a/src/UNL/WDN/Assessment.php b/src/UNL/WDN/Assessment.php index 2e13c745570e40b3dd0d98be2e7b8c4e284a9653..5d13295b20312c31a55e73b68601429be41a8113 100644 --- a/src/UNL/WDN/Assessment.php +++ b/src/UNL/WDN/Assessment.php @@ -45,18 +45,18 @@ class UNL_WDN_Assessment $this->removeEntries(); $vlogger = new UNL_WDN_Assessment_ValidationLogger($this); - $slogger = new UNL_WDN_Assessment_ValidityStatusLogger($this); + //$slogger = new UNL_WDN_Assessment_ValidityStatusLogger($this); $spider = $this->getSpider(); $spider->addLogger($vlogger); - $spider->addLogger($slogger); + //$spider->addLogger($slogger); $spider->spider($this->baseUri); } function logPages() { - $slogger = new UNL_WDN_Assessment_ValidityStatusLogger($this); + //$slogger = new UNL_WDN_Assessment_ValidityStatusLogger($this); $spider = $this->getSpider(); - $spider->addLogger($slogger); + //$spider->addLogger($slogger); $spider->spider($this->baseUri); } diff --git a/src/UNL/WDN/Assessment/PageLogger.php b/src/UNL/WDN/Assessment/PageLogger.php index f0c1c029c01fb772d312d8b59077281c264933a2..e8ac99be3e057e69558b911d743c1e3a3e9de260 100644 --- a/src/UNL/WDN/Assessment/PageLogger.php +++ b/src/UNL/WDN/Assessment/PageLogger.php @@ -15,7 +15,9 @@ class UNL_WDN_Assessment_PageLogger extends Spider_LoggerAbstract function log($uri, $depth, DOMXPath $xpath) { - echo PHP_EOL.'|'.str_repeat('-', $depth).$uri; $this->assessment->addUri($uri); + echo PHP_EOL.'<div id="uri_'.md5($uri).'" class="depth_'.$depth.' '.$this->assessment->getValidityStatus($uri).'"> + <span class="uri">'.$uri.'</span> + </div>'.PHP_EOL; } } diff --git a/src/UNL/WDN/Assessment/ValidityStatusLogger.php b/src/UNL/WDN/Assessment/ValidityStatusLogger.php index d063a7d6509872cc0e06be7b8845fa511f371c7b..94f920f4763f2b8d2c90427c92697709989e58b0 100644 --- a/src/UNL/WDN/Assessment/ValidityStatusLogger.php +++ b/src/UNL/WDN/Assessment/ValidityStatusLogger.php @@ -15,6 +15,7 @@ class UNL_WDN_Assessment_ValidityStatusLogger extends Spider_LoggerAbstract function log($uri, $depth, DOMXPath $xpath) { - echo ' '.$this->assessment->getValidityStatus($uri); + $status = $this->assessment->getValidityStatus($uri); + echo '<span id="validity_'.md5($uri).'" class=" validity '.$status.'">'.$status.'</span>'.PHP_EOL; } } \ No newline at end of file diff --git a/www/batchval.css b/www/batchval.css new file mode 100644 index 0000000000000000000000000000000000000000..6785732817ba345f2bafe607443cbb855ddf140a --- /dev/null +++ b/www/batchval.css @@ -0,0 +1,7 @@ +@CHARSET "UTF-8"; +.true { + background-color:green; +} +.false { + background-color:red; +} \ No newline at end of file diff --git a/www/batchval.js b/www/batchval.js new file mode 100644 index 0000000000000000000000000000000000000000..4d07ae48672130117074d62d3fe00f7c438a5e3b --- /dev/null +++ b/www/batchval.js @@ -0,0 +1,51 @@ +function validateAll() +{ + WDN.jQuery('.uri').each(function(){ + // Grab the URI + var uri = WDN.jQuery(this).html(); + + var uriDiv = WDN.jQuery(this).parent(); + + checkValidity(uri, uriDiv); + }); +} + +function validateInvalid() +{ + WDN.jQuery('.uri:not(.true)').each(function(){ + // Grab the URI + var uri = WDN.jQuery(this).html(); + + var uriDiv = WDN.jQuery(this).parent(); + + checkValidity(uri, uriDiv); + }); +} + +function checkValidity(uri, uriDiv) +{ + + uriDiv.removeClass('true false') + + // Tell the user we're loading the result + uriDiv.append('<img class="loading" src="/wdn/templates_3.0/css/header/images/colorbox/loading.gif" />'); + + // Fetch the validator results in JSON format. + WDN.get('validator.php?u='+escape(uri), null, function(result) { + handleJSONResult(result, uriDiv); + }, 'json'); +} + +function handleJSONResult(result, uriDiv) +{ + uriDiv.children('.loading').remove(); + + if (result.validity) { + // It is valid, say no more! + uriDiv.addClass('true'); + return; + } + + uriDiv.addClass('false'); + +} diff --git a/www/index.php b/www/index.php index 99f783ac8e4a901b3eccbcacf40bb5bb519abcf0..a9a2452aff767b4331b9f0a03d13adf5dedba338 100644 --- a/www/index.php +++ b/www/index.php @@ -47,6 +47,8 @@ if (isset($_GET['uri']) <title>UNL | WDN | Batch Validator</title> <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --> <link rel="stylesheet" type="text/css" href="/wdn/templates_3.0/css/content/forms.css" /> +<link rel="stylesheet" type="text/css" href="batchval.css" /> +<script type="text/javascript" src="batchval.js"></script> <!-- InstanceEndEditable --> </head> <body class="fixed"> @@ -80,6 +82,7 @@ if (isset($_GET['uri']) <div id="maincontent"> <!--THIS IS THE MAIN CONTENT AREA; WDN: see glossary item 'main content area' --> <!-- InstanceBeginEditable name="maincontentarea" --> + <div class="three_col left"> <form method="get" action="" class="cool"> <fieldset> <legend>Batch Validator</legend> @@ -106,8 +109,12 @@ if (isset($_GET['uri']) </fieldset> <p class="submit"><input type="submit" id="submit" name="submit" value="Submit" /></p> </form> + </div> + <div class="col right"> + <p class="submit"><a href="#" onclick="validateInvalid(); return false;">Validate Invalid</a></p> + <p class="submit"><a href="#" onclick="validateAll(); return false;">Validate All</a></p> + </div> <div class="clear"> - <pre> <?php if (!empty($uri)) { @@ -143,18 +150,7 @@ if (isset($_GET['uri']) $assessment->logPages(); } } - - //if (isset($assessment)) { - // if ($subPages = $assessment->getSubPages()) { - // echo '<ul>'; - // foreach ($subPages as $page) { - // echo '<li class="'.$page['valid'].'">'.$page['url']. ' valid = '.$page['valid'].'</li>'; - // } - // echo '</ul>'; - // } - //} ?> - </pre> </div> <!-- InstanceEndEditable --> <div class="clear"></div> diff --git a/www/validator.php b/www/validator.php new file mode 100644 index 0000000000000000000000000000000000000000..4debd8f6d1b712f02357276730801d40441e632a --- /dev/null +++ b/www/validator.php @@ -0,0 +1,10 @@ +<?php +require_once 'config.inc.php'; +if (!isset($_GET['u'])) { + throw new Exception('You must pass a uri to validate.'); +} + +$v = new Services_W3C_HTMLValidator(); +$result = $v->validate($_GET['u']); + +echo json_encode($result);