inclusive-design / AChecker

Automated interactive Web content accessibility checker.
https://achecker.ca
GNU General Public License v2.0
69 stars 61 forks source link

Validate Direct Input instead of URL #25

Open BarisW opened 11 years ago

BarisW commented 11 years ago

It would awesome if AChecker also supports Direct Input, just like W3C does: http://validator.w3.org/#validate_by_input

I want to validate my content before saving the page, so I need something to validate the content before it's actual a working URL.

Would this be possible?

atutor commented 11 years ago

It already does do direct input.

BarisW commented 11 years ago

I meant the webservice. According to the docs, it needs an URI and I don't see a way to enter just content?

achecker.ca/documentation/web_service_api.php

atutor commented 11 years ago

You might take a look at the TinyMCE plugin, which kind of does that. https://github.com/atutor/acheck_plugin_tmce

There's no plans though, for direct input via Webservices. It might be a good project for a community member to take on ;-)

BarisW commented 11 years ago

Hi, thanks for the info. I've tried implementing the same logics, but I cannot get it to work. I'm using PHP instead of JavaScript. I'm trying to implement the checker in a Drupal module, and I'm using this code:

$url = 'http://achecker.ca/checker/index.php';
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = array(
  'gid[]' => '8',
  'validate_content' => urlencode('<h1>This is a test</h1>'),
);
$response = drupal_http_request($url, $headers, 'POST', http_build_query($data, '', '&'));

Just like here: http://drupal.org/node/221136 I do get a response, but that response just seems to be the HTML of the page, as if it never received input.

Any thoughts on how I could get this to work?

atutor commented 11 years ago

If you want to take this to the atutor.ca forums, I'll pass you on to Cindy Li, who created the Webservices http://atutor.ca/forum/18/1.html

BarisW commented 11 years ago

I'm more that willing to do that. However, I can't create an account on the forums. I've tried 4 different usernames, but all seem to be taken (can't believe that, I've tried some random strings).

I there another way to contact Cindy Li?

atutor commented 11 years ago

We had some problems on the atutor.ca server this weekend. I've made a few adjustments, and hoping things are working now.

You can try again. https://atutor.ca/my/register.php

cindyli commented 11 years ago

Thanks for pumping in ideas and looking into code.

To achieve what you need, AChecker server side needs to be adjusted to accept the direct html content to be validated. With the current web service implementation:

https://github.com/atutor/AChecker/blob/master/checkacc.php#L48-56

The only valid input is URIs. However, extending AChecker to accommodate direct input should not be hard.

BarisW commented 11 years ago

Thanks Cindy for your reply. Implementing this seems rather simple. Is this something you can/will do? Or do you want me to Fork the module and implement it myself?

cindyli commented 11 years ago

Hi BarisW, it might be a while before we do another round of work on achecker. It would get done faster if you wanted to take it on.

cbiggins commented 11 years ago

BarisW, this might get you started. Its a diff of checkacc.php. Theres not much to it.

@@ -35,6 +35,7 @@ include_once(AC_INCLUDE_PATH. 'classes/RESTWebServiceOutput.class.php');

$uri = trim(urldecode($_REQUEST['uri'])); +$validate_content = trim(urldecode($_REQUEST['html'])); $web_service_id = trim($_REQUEST['id']); $guide = trim(strtolower($_REQUEST['guide'])); $output = trim(strtolower($_REQUEST['output'])); @@ -46,11 +47,11 @@ // end of initialization

// validate parameters -if ($uri == '') +if ($uri == '' && $validate_content == '') { $errors[] = 'AC_ERROR_EMPTY_URI'; } -else +else if (empty($validate_content)) { if (Utility::getValidURI($uri) === false) $errors[] = 'AC_ERROR_INVALID_URI'; } @@ -106,7 +107,9 @@ $userLinksDAO->setLastSessionID($user_link_id, Utility::getSessionID());

// validating uri content +if (empty($validate_content)) { $validate_content = @file_get_contents($uri); +}

if (isset($validate_content)) {

cbiggins commented 11 years ago

I've just added a pull request with this functionality also.

https://github.com/atutor/AChecker/pull/30