Location: PHPKode > projects > VaMoLà - Validator > vamola-validator/vamolarest.php
<?php
/************************************************************************/
/* AChecker                                                             */
/************************************************************************/
/* Copyright (c) 2008 by Greg Gay, Cindy Li                             */
/* Adaptive Technology Resource Centre / University of Toronto			    */
/*                                                                      */
/* 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.                        */
/************************************************************************/

/*
 * This is the web service interface to check accessibility on a given URI
 * Expected parameters:
 * id: to identify the user. must be given
 * uri: The URL of the document to validate. must be given
 * guide: The guidelines to validate against. 
 *        can be multiple guides, separated by comma (,)
 * output: html or rest
 * offset: The line offset on the html output from uri where the validation starts.
 */

define('AC_INCLUDE_PATH', 'include/');

include(AC_INCLUDE_PATH.'vitals.inc.php');
//include_once(AC_INCLUDE_PATH. "classes/HTMLRpt.class.php");
include_once(AC_INCLUDE_PATH. "classes/HTMLRptVamola.class.php");
include_once(AC_INCLUDE_PATH. 'classes/Utility.class.php');
include_once(AC_INCLUDE_PATH. 'classes/DAO/UsersDAO.class.php');
include_once(AC_INCLUDE_PATH. 'classes/DAO/GuidelinesDAO.class.php');
include_once(AC_INCLUDE_PATH. 'classes/DAO/UserLinksDAO.class.php');
include_once(AC_INCLUDE_PATH. 'classes/AccessibilityValidator.class.php');
include_once(AC_INCLUDE_PATH. 'classes/HTMLWebServiceOutput.class.php');
include_once(AC_INCLUDE_PATH. 'classes/RESTWebServiceOutputVamola.class.php');

/*
echo("<p>debug</p>");
echo("<p>request</p>");
print_r($_REQUEST);
echo("<p>get</p>");
print_r($_GET);
*/
//ricostruisco l'url corretto del sito da validare escludendo le opzioni passate con la get che sono relative al validatore
$uri = trim(urldecode($_REQUEST['uri']));
$uri2 = trim(urldecode($_GET['uri']));
//aggiungo ad $uri le eventuali opzioni in get che non riguardano il validatore, ma il sito da validatre
foreach($_GET as $id=>$val)
{
	if($id!='uri' && $id!='guide' && $id!='output')
		$uri2.="&".$id."=".$val;
}
$uri=$uri2;
$uri= str_replace(' ','%20',$uri);
//echo("<p>".$uri2."</p>");

//inserisco http:// se non c'è
if(stripos($uri,'http://')!==0 && stripos($uri,'https://')!==0)
	$uri='http://'.$uri;
	
//MB cambio 'id' in 'id_user_vamola'
//$web_service_id = trim($_REQUEST['id']);
$web_service_id = trim($_REQUEST['id_user_vamola']);
if($web_service_id=='')
{
	//MB metto un id di default
	$web_service_id='2f4149673d93b7f37eb27506905f19d63fbdfe2d';
}
//MB uso la guideline STANCA-B
//$guide = trim(strtolower($_REQUEST['guide']));
$guide='STANCA-B';
//MB uso solo l'output rest
//$output = trim(strtolower($_REQUEST['output']));
$output='rest';
$offset = intval($_REQUEST['offset']);

// initialize defaults for the ones not set or not set right but with default values
if ($output <> 'html' && $output <> 'rest') 
	$output = DEFAULT_WEB_SERVICE_OUTPUT;

// end of initialization

// validate parameters
if ($uri == '')
{
	$errors[] = 'AC_ERROR_EMPTY_URI';
}
else
{
	if (Utility::getValidURI($uri) === false) $errors[] = 'AC_ERROR_INVALID_URI';
}

if ($web_service_id == '')
{
		
	$errors[] = 'AC_ERROR_EMPTY_WEB_SERVICE_ID';
	
}
else
{ // validate web service id
	$usersDAO = new UsersDAO();
	$user_row = $usersDAO->getUserByWebServiceID($web_service_id);

	if (!$user_row) $errors[] = 'AC_ERROR_INVALID_WEB_SERVICE_ID';
	
	$user_id = $user_row['user_id'];
}

// return errors
if (is_array($errors))
{
	if ($output == 'rest')
		echo RESTWebServiceOutputVamola::generateErrorRpt($errors);
	/*
	else
		echo HTMLRpt::generateErrorRpt($errors);
	*/
	exit;
}

// generate guidelines
$guides = explode(',',$guide);

$guidelinesDAO = new GuidelinesDAO();
foreach ($guides as $abbr)
{
	if ($abbr == '') continue;

	$row = $guidelinesDAO->getEnabledGuidelinesByAbbr($abbr);

	if ($row[0]['guideline_id'] <> '') $gids[] = $row[0]['guideline_id'];
}

// set to default guideline if no input guidelines
if (!is_array($gids)) $gids[] = DEFAULT_GUIDELINE;

foreach ($gids as $gid)
	$gidStr .= $gid . ",";

$gidStr = substr($gidStr, 0, -1);

// retrieve user link ID
//MB$userLinksDAO = new UserLinksDAO();
//MB$user_link_id = $userLinksDAO->getUserLinkID($user_id, $uri, $gidStr);

// set new session id
//MB$userLinksDAO->setLastSessionID($user_link_id, Utility::getSessionID());

// validating uri content
$validate_content = @file_get_contents($uri);

if (isset($validate_content))
{
	$aValidator = new AccessibilityValidator($validate_content, $gids, $uri);
	$aValidator->setLineOffset($offset);
	$aValidator->validate();
	$errors = $aValidator->getValidationErrorRpt();
	//MB
	$num_success=$aValidator->get_num_success();

	/* //MB Non salvo decisions
	// save errors into user_decisions 
	$userDecisionsDAO = new UserDecisionsDAO();
	$userDecisionsDAO->saveErrors($user_link_id, $errors);
	*/
	/*
	if ($output == 'html')
	{ // generate html output
		$htmlWebServiceOutput = new HTMLWebServiceOutput($aValidator, $user_link_id, $gids);
		echo $htmlWebServiceOutput->getWebServiceOutput();
	}
	*/
	
	if ($output == 'rest')
	{ // generate html output
		$restWebServiceOutputVamola = new RESTWebServiceOutputVamola(str_replace('%20',' ',$uri),$num_success, $errors, /*$user_link_id,*/ $gids);
		echo $restWebServiceOutputVamola->getWebServiceOutput();
		//print_r($errors);
	}
} 

?>
Return current item: VaMoLà - Validator