forked from inclusive-design/AChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkacc.php
136 lines (112 loc) · 4.44 KB
/
checkacc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/************************************************************************/
/* AChecker */
/************************************************************************/
/* Copyright (c) 2008 - 2011 */
/* Inclusive Design Institute */
/* */
/* 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. */
/************************************************************************/
// $Id$
/*
* 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/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/RESTWebServiceOutput.class.php');
$uri = trim(urldecode($_REQUEST['uri']));
$web_service_id = trim($_REQUEST['id']);
$guide = trim(strtolower($_REQUEST['guide']));
$output = trim(strtolower($_REQUEST['output']));
$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') {
header('Content-type: text/xml');
echo RESTWebServiceOutput::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;
// retrieve user link ID
$userLinksDAO = new UserLinksDAO();
$user_link_id = $userLinksDAO->getUserLinkID($user_id, $uri, $gids);
// set new session id
$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();
// 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
$restWebServiceOutput = new RESTWebServiceOutput($errors, $user_link_id, $gids);
header('Content-type: text/xml');
echo $restWebServiceOutput->getWebServiceOutput();
}
}
?>