forked from EqualifyEverything/equalify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
83 lines (57 loc) · 1.79 KB
/
test.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
<?php
// Let's load in Composer.
require_once ('/var/www/html/vendor/autoload.php');
// Let's run Guzzle.
use GuzzleHttp\Client;
// Create a client with a base URI
$client = new GuzzleHttp\Client();
// Send a request
//$response = $client->request('GET', 'https://wave.webaim.org/api/docs?format=json');
$response = $client->request('GET', 'https://axe.equalify.app/index.php?url=decubing.com');
$axe_json = $response->getBody()->getContents();
$axe_json_decoded = json_decode($axe_json);
$page_url = 'test.com';
// START PLUGIN
// Decode JSON.
$axe_json_decoded = json_decode($axe_json);
// Sometimes Axe can't read the json.
if(empty($axe_json_decoded)){
// And add an alert.
$alert = array(
'source' => 'axe-core',
'url' => $page_url,
'message' => 'axe-core cannot reach the page.',
);
array_push($axe_alerts, $alert);
}else{
// We're add a lit of violations.
$axe_violations = array();
// Show axe violations
foreach($axe_json_decoded[0]->violations as $violation){
// Only show violations.
$axe_violations[] = $violation;
}
// Add alerts.
if(!empty($axe_violations)) {
// Setup alert variables.
foreach($axe_violations as $violation){
// Default variables.
$alert = array();
$alert['source'] = 'axe-core';
$alert['url'] = $page_url;
// Setup tags.
$alert['tags'] = $violation->tags;
// Setup message.
$alert['message'] = '"'.$violation->id.'" violation: '.$violation->help;
// Push alert.
$axe_alerts[] = $alert;
}
}
}
// Test to make sure it works
echo '<pre>';
print_r($axe_alerts);
echo '</pre>';
die;
// Return everything
// return $axe_alerts;