Location: PHPKode > projects > OpenWolf Guidelines Validator > openWolf 0.9.9/index.php
<?php

/*************************************************

openWolf - an HTML accessibility guidelines validator
Author: Geoff Munn (hide@address.com)
Version: 0.9.9

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

You may contact the author of openWolf by e-mail at: hide@address.com

The latest version of openWolf can be obtained from:
http://openwolf.sourceforge.net/

*************************************************/
//ini_set('display_errors', true);
//	error_reporting(E_ALL);
$type=@$_REQUEST['type'];
if($type=='')	$type='nz';

//The default scan type is ajax=t
$ajax=@$_REQUEST['ajax'];
if($ajax=='')	$ajax='t';

//Getting a job id implies that we're after an ajax update:
$job_id=@$_REQUEST['job_id'];

define('DEFAULT_THEME', 'accessware');
include_once(DEFAULT_THEME . '/footer.php');
include_once(DEFAULT_THEME . '/header.php');

define('DEFAULT_FOOTER', $default_footer);
define('DEFAULT_HEADER', $default_header);
$default_theme=DEFAULT_THEME;

session_start();
$finished=@$_SESSION['finished'];

if($finished==true){
	//ok, apparently everything is done and we can retrieve the serialized object:
	
	if($_SESSION['success']==true){
			$type=$_SESSION['type'];
			include_once('./parse.core.class.php');
			include_once($type . '/html_output.php');
			include_once($type . '/parse.class.php');
			
			$filepath='./files/results_' . $_SESSION['job_id'] . '.txt';
			$fh2=fopen($filepath, 'r');
			$contents=fread($fh2, filesize($filepath));
			$rows=explode("---linebreak---\n", $contents);
				
			$output_options=unserialize($rows[2]);
			$parse=unserialize($rows[1]);
			$results=unserialize($rows[3]);
			
			if($_REQUEST['snippit']!='' || $_SESSION['snippit']!='')
				$is_snippit=true;
			else
				$is_snippit=false;
				
			session_destroy();
			header('Content-Type: text/html; charset=utf-8');
			output_results($results, $parse, $output_options, $is_snippit);
	} else {
		//a 404 for instance...
		$output_options=$_SESSION['output_options'];
		
		$url=$output_options['url'];
		
		include_once('default/no_file.php');
		
		$output_options['no_file']=$no_file;
		
		session_destroy();
		
		output_404($output_options);
	}
	
	exit;
}
//If this is an ajax loading screen, then we will set up some special variables;
//This should only be triggered by the initial submission:
if($ajax=='t' && (@$_REQUEST['url']!='' || @$_REQUEST['snippit']!='')){
	//Wipe any old session stuff that might still be here:
	//session_start();
	session_destroy();
	session_start();
	
	//$is_finished=@$_SESSION['finished'];
	$is_loading=true;
	$job_id=time();
	//?url=$url&type=nz&&check_links=&department_name=&style=ajax&is_loading=true');
	$_SESSION['url']=$_REQUEST['url'];
	$_SESSION['snippit']=$_REQUEST['snippit'];
	$_SESSION['type']=$type;
	$_SESSION['check_links']=@$_REQUEST['check_links'];
	$_SESSION['department_name']=$_REQUEST['department_name'];
	$_SESSION['ajax']='t';
	
	$_SESSION['job_id']=$job_id;
	//session_write_close();
	
	//run tests=false because these are called separately by an ajax call
	$run_tests=false;
	
} else {
	$run_tests=true;
	$is_loading=false;
}

//Kick off an ajax job:
if($job_id!='' && $run_tests==true){
	$url=$_SESSION['url'];
	$type=$_SESSION['type'];
	$ajax=$_SESSION['ajax'];
	$snippit=$_SESSION['snippit'];
	
	include_once('parse.php');
	exit;
}

if($ajax=='f'){
	//This is a non-ajax job, 
	$url=$_REQUEST['url'];
	$snippit=$_REQUEST['snippit'];
	
	$check_links=@$_REQUEST['check_links'];
	$department_name=$_REQUEST['department_name'];
	
	include_once('parse.php');
	exit;
}

//This is the AJAX loader.  It only gets displayed with the following condition(s):
//if(isset($_REQUEST['url']) && $is_loading==true){
if($is_loading==true){
	//This loads the status page
	
	$url=$_REQUEST['url'];
	$snippit=$_REQUEST['snippit'];
	
	//okay, so here we take the url, and load an ajax instance with this url to go to the parse.php file
	$ajax_header=<<<EOT
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
	<html>
		<head>
			<title>Loading results...</title>
			<link rel="stylesheet" href="nz/html/styles.css">
			<link rel="stylesheet" href="$default_theme/html/styles.css">
			<script type="text/javascript" src="default/html/janola.js"></script>
			<script type="text/javascript">
				
				function show_results(xml){
					//reload the page, the session should identify that we have finished
					//and will display the results
					
					window.location=window.location;
					
				}
				var janola=new janola_object();
	
				janola.finished_function(show_results);
				janola.load('/?job_id=$job_id');
				
				var loadingInterval=window.setInterval('get_status()', 5000);				
				var is_loading=false;
				
				function get_status(){
					
					if(!is_loading){
						var status=new janola_object();
						status.finished_function(update_status);
						
						status.load('/ajax.php');
						is_loading=true;
					}	
				}
				
				function update_status(xml){
				
					is_loading=false;
					
					var list=document.getElementById('result_list');
					
					var percentage=xml.getElementsByTagName('messages')[0].getAttribute('percent');
					
					var msg=xml.getElementsByTagName('message');
					
					var p=document.getElementById('percentage').getElementsByTagName('span')[0];
					p.style.width=percentage + 'px';
					p.firstChild.nodeValue=percentage + '%';
					
					for(var i=0; i<msg.length; i++){
						is_rule=msg[i].getAttribute('is_rule');
						li_class=msg[i].getAttribute('class');
						li_id=msg[i].getAttribute('id');
						type=msg[i].getAttribute('type');
						
						if(type=='update'){
							li=document.getElementById(li_id);
							
							//update the total:
							
							el=document.getElementById(li_class.substr(3) + '_total');
						
							current=el.firstChild.nodeValue;
							current++;
							el.firstChild.nodeValue=current;
														
						} else {
							li=null;
						}
						
						rule=msg[i].getElementsByTagName('rule')[0].firstChild.nodeValue;
						if(!li){
							text_node=msg[i].getElementsByTagName('text')[0];
							
							if(text_node.childNodes.length>0)
								msg_text=text_node.firstChild.nodeValue;
							else msg_text='';
							
							temp=list.getElementsByTagName('li');
							if(temp)
								li=add_element(list, 'li', {className: li_class, id: li_id}, {}, 'before', temp[0]);
							else
								li=add_element(list, 'li', {className: li_class, id: li_id});
							
							add_element(li, 'p', {text: rule});
							add_element(li, 'p', {text: msg_text, className: 'desc'});
						} else {
							li.getElementsByTagName('p')[0].firstChild.nodeValue=rule;
							li.className=li_class;
														
						}
					}
					
				}
				
			</script>
		</head>
		<body class="loading">	
EOT;

	$ajax_results=<<<EOT
			<div id="main">
				<h2>Please wait while the page is checked</h1>
				<h3>Progress so far:</h3>
				<div class="ajax" id="view_options">
					<ul>
						<li class="progress" id="percentage"><span>0%</span></li>
						<li class="rl_pass"><span>Passes: <strong id="pass_total">0</strong></li>
						<li class="rl_warning"><span>Warnings: <strong id="warning_total">0</strong></li>
						<li class="rl_fail"><span>Failures: <strong id="fail_total">0</strong></li>
						<li class="rl_check"><span>Could not be checked: <strong id="check_total">0</strong></li>
						<li class="rl_user"><span>User check required: <strong id="user_total">0</strong></li>
					</ul>
					<div class="clear">&nbsp;</div>
				</div>
				<div id="container">
					<ul id="result_list" class="ajax">
					
					</ul>
				</div>
EOT;

	print $ajax_header;
	print DEFAULT_HEADER;
	print $ajax_results;
	print DEFAULT_FOOTER;
	print '</body></html>';
	exit;
}

$form_section=<<<EOT
			<fieldset id="validator-fieldset">
	    		<legend>Validator</legend>
		      	<div class="form">
					<div class="field-container">
						<ul class="entry-options">
							<li><label for="url">Please enter a website address:</label></li>
							<li><label>OR enter by <a href="#" id="direct_input_link">direct input</a></label></li>
						</ul>
						<input type="text" name="url" id="url" value="http://" />
						<input type="hidden" name="type" id="type" value="$type" />
						<input type="submit" class="submit" value="Go" />
					</div>
		      	</div>
	      	</fieldset>
EOT;

$form_section_direct=<<<EOT
			<fieldset id="validator-fieldset-direct">
	    		<legend>Validator</legend>
		      	<div class="form">
					<div class="field-container">
						<ul class="entry-options">
							<li><label for="url">Please enter a <a href="#" id="direct_url_link">website address</a></label></li>
							<li><label>OR enter by direct input:</label></li>
						</ul>
						<textarea name="snippit" id="snippit" cols="20" rows="10"></textarea>
						<input type="submit" class="submit" value="Go" />
					</div>
		      	</div>
	      	</fieldset>
EOT;

$wai_section=<<<EOT
			<fieldset class="options">
				<legend>WAI Checkpoints</legend>
				<p>This currently uses the WCAG 1.0 guidelines</p>
				<h2>Options</h2>
				<input type="checkbox" name="priority1" id="priority1" value="t" checked="checked" />
				<span><label for="priority1">Priority 1</label></span>
				<input type="checkbox" name="priority2" id="priority2" value="t" checked="checked" />
				<span><label for="priority2">Priority 2</label></span>
				<input type="checkbox" name="priority3" id="priority3" value="t" checked="checked" />
				<span><label for="priority3">Priority 3</label></span>
				<input type="hidden" name="ajax" value="f">
			</fieldset>
EOT;

$nz_section=<<<EOT
			<fieldset class="options">
				<legend>NZ Web Standards &amp; Recommendations</legend>
				<p>At present, only the standards are checked</p>
				<div>
					<h2>Options</h2>
					<div class="field-container">
						<label for="department_name">Department name (Standard 16.2):</label>
						<input type="text" id="department_name" name="department_name" value="" />
						<span>Example: Ministry of Defense</span>
					</div>
					<div class="field-container">
						<label for="check_links">Check links (Standard 8.2)?</label>
						<input type="checkbox" id="check_links" name="check_links" value="t" />
						<span>On a link-heavy site this may cause long delays.</span>
					</div>
					<div class="field-container" style="display: none">
						<label for="no_ajax">Don't use AJAX loading screen?</label>
						<input type="checkbox" id="no_ajax" name="ajax" value="f" checked />
						<span>Tick this box if the loading screen is giving you problems.</span>
					</div>
				</div>
			</fieldset>
EOT;

$about_page=<<<EOT
	<div>
		<h2>About this program</h2>
		<p>This program generates a discussion document based on an URL you provide and your choice of requirements.</p>
		<p>While a great many requirements can be checked and a variety of results can be returned, some requirements cannot be automatically checked and will require a human assessment.</p>
		<p>Also, sometimes a requirement may receive a pass/warning/fail result, but the result may be wrong and there are sometimes good reasons why this is the case.</p>
		<p>That is why these results are intended as a <em>discussion document</em>, to encourage people to look at that their web pages contain.</p>
		
		<p><strong>The results are not a guarantee of accessibility or usability.</strong></p>
		
		<p>This program is open-source and can be freely downloaded and distributed.  Please refer to the <a href="/license.txt">license</a> for details.</p>
		<p>The project is hosted at SourceForge and can be <a href="http://openwolf.sourceforge.net">downloaded here</a></p>
		
		<p>Comments and suggestions are always appreciated.  Please email <a href="mailto:hide@address.com">hide@address.com</a> with feedback you have.</p>
		
		<h3>Credits</h3>
		<p>The vast, vast majority of code here was written by myself, Geoff Munn.  Specifically, the HTML and CSS parsers, plus most of the associated functions.</p>
		<p>Kudos to <a href="http://www.3months.com">3months.com</a> for hosting a <a href="http://validator.3months.com">mirror</a></p>
		<p>Special thanks to Rowan Smith for testing it and uncovering some really 'interesting' issues and suggestions.</p>
		<p>Thanks to the following people and organisations:</p>
			<li><a href="http://www.w3.org">The W3</a>, for their HTML documentation and HTML validator</li>
			<li><a href="http://www.blooberry.com">Blooberry</a>, for an absolutely brilliant CSS reference</li>
			<li><a href="http://www.htmlhelp.com">HTML Help</a> for their HTML reference</a>
			<li><a href="http://smart-pad.blogspot.com/2006/08/resoving-relative-uri-by-andreas.html">This guy</a> for a handy absolute URL converter</li>
			<li><a href="http://juicystudio.com/article/selector-specificity.php">Juicy Studio</a> for info about CSS specificity</li>
			<li><a href="http://msdn.microsoft.com">Microsoft</a>, for their very comprehensive MSDN library</li>
			<li><a href="http://snoopy.sourceforge.net/">Snoopy</a> for the very handy Snoopy project</li>
			<li><a href="http://www.e.govt.nz">E.govt.nz</a> for (eventually) releasing the Web Standards &amp; Recommendations</li>
			<li><a href="http://unfortunatelypaul.com/2005/03/16/tabindex/">Unfortunately Paul</a> for the tabindex article</li>
			<li><a href="http://famfamfam.com">Famfamfam</a> for the icons in the WAI report</li>
			<li><a href="http://www.icon-king.com">Icon King</a> for the Nuvola icon theme</li>
			<li><a href="http://www.silvestre.com.ar/?p=4">Silvestre</a> for the Dropline Neu icon theme</li>
		</ul>
		<p>You probably don't care, but this validator was written on a Powerbook G4 running OS X.</p>
	</div>
EOT;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>openWolf Guidelines Validator</title>
<link rel="stylesheet" type="text/css" href="/<?php echo DEFAULT_THEME ?>/html/styles.css" />
<script type="text/javascript" src="/<?php echo DEFAULT_THEME ?>/html/scripts.js"></script>
</head>
<body>
	 <?php
    	echo DEFAULT_HEADER;
    ?>
  <div id="main">
  	<div id="container">
	    <form id="scan" method="get" action="">
			<div id="nav-level-1">
				<ul>
					<li><a href="?type=nz" id="nz"<?php if($type=='nz') echo " class=\"selected\"" ?>>NZ Web Standards &amp; Recommendations</a></li>
					<li><a href="?type=wai" id="wai"<?php if($type=='wai') echo " class=\"selected\"" ?>>WAI priorities</a></li>
					<li><a href="?type=about" id="about"<?php if($type=='about') echo " class=\"selected\"" ?>>About this program</a></li>
				</ul>
				<div class="dummy">&nbsp;</div>
			</div>
	    	<?php
	    	
	    	if($type!='about'){
	    		echo $form_section;
	    		echo $form_section_direct;
	    	}
	    	?>
			<div>
	<?php
		switch($type){
			case 'wai':
				echo $wai_section;
				break;
			case 'nz':
				echo $nz_section;
				break;
				
			case 'about':
				echo $about_page;
				break;
		}
	?>
			</div>
	    </form>
  </div>
	<?php
		echo DEFAULT_FOOTER;
	?>
</div>
</body>
</html>
Return current item: OpenWolf Guidelines Validator