Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Validate Direct Input instead of URL #25

Open
BarisW opened this issue Feb 24, 2013 · 12 comments
Open

Validate Direct Input instead of URL #25

BarisW opened this issue Feb 24, 2013 · 12 comments

Comments

@BarisW
Copy link

BarisW commented Feb 24, 2013

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
Copy link

atutor commented Feb 24, 2013

It already does do direct input.

@BarisW
Copy link
Author

BarisW commented Feb 24, 2013

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
Copy link

atutor commented Feb 24, 2013

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
Copy link
Author

BarisW commented Feb 24, 2013

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
Copy link

atutor commented Feb 24, 2013

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
Copy link
Author

BarisW commented Feb 24, 2013

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
Copy link

atutor commented Feb 25, 2013

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
Copy link
Contributor

cindyli commented Feb 25, 2013

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
Copy link
Author

BarisW commented Feb 25, 2013

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
Copy link
Contributor

cindyli commented Feb 25, 2013

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
Copy link

cbiggins commented May 9, 2013

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
Copy link

cbiggins commented May 9, 2013

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants