Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | <?php |
2 | |||
3 | class w3c_fragment_checker { |
||
4 | |||
5 | public static function perform_external_w3c_check($fragment, $validator_url) { |
||
6 | if ($fragment == '') return true; // Damit es nicht zu einer 302-Endlosschleife kommt, wenn Fragment='' ist! |
||
7 | |||
8 | $w3c_check_conn = new HTTPClass; |
||
9 | |||
10 | $w3c_check_conn->connection_checker = 'inetconn_ok'; |
||
11 | $w3c_check_conn->error_level = HTTPC_ERRLVL_FATAL_ERRORS; |
||
12 | $w3c_check_conn->use_post_method = true; |
||
13 | |||
14 | $w3c_check_conn->user_agent = WBUserAgent(); |
||
15 | |||
16 | $w3c_check_conn->additional_fields['Referer'] = $validator_url; |
||
17 | $w3c_check_conn->additional_fields['Content-type'] = 'application/x-www-form-urlencoded'; |
||
18 | |||
19 | $w3c_check_conn_res = $w3c_check_conn->execute_http_request($validator_url.'check', 'fragment='.urlencode($fragment)); |
||
20 | |||
21 | if ($w3c_check_conn_res->error != HTTPC_NO_ERROR) { |
||
22 | return NULL; // Fehler |
||
23 | } else { |
||
24 | /* $pos = strpos($w3c_check_conn_res->content, '<h2 class="valid">'); |
||
25 | if ($pos !== false) { |
||
26 | $ret_status = 'Valid'; |
||
27 | } else { |
||
28 | $pos = strpos($w3c_check_conn_res->content, '<h2 id="results" class="invalid">'); |
||
29 | if ($pos !== false) { |
||
30 | $ret_status = 'Invalid'; |
||
31 | } else { |
||
32 | $ret_status = 'Abort'; |
||
33 | } |
||
34 | } */ |
||
35 | |||
36 | // Ab Version 0.8.0 wäre x-w3c-validator-status = Abort. |
||
37 | // Darunter ist x-w3c-validator-status gar nicht vorhanden |
||
38 | if (isset($w3c_check_conn_res->header['x-w3c-validator-status'])) { |
||
39 | $ret_status = $w3c_check_conn_res->header['x-w3c-validator-status']; |
||
40 | } else { |
||
41 | $ret_status = 'Abort'; |
||
42 | } |
||
43 | |||
44 | if ($ret_status == 'Valid') { |
||
45 | return true; |
||
46 | } else if ($ret_status == 'Invalid') { |
||
47 | return false; |
||
48 | } else { |
||
49 | return NULL; // Fehler |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | |||
54 | public static function local_w3c_check_possible() { |
||
55 | @include_once 'Services/W3C/HTMLValidator.php'; |
||
56 | return class_exists('Services_W3C_HTMLValidator'); |
||
57 | } |
||
58 | |||
59 | public static function perform_local_w3c_check($fragment) { |
||
60 | if ($fragment == '') return true; // Damit diese Funktion kein anderes Ergebnis als perform_external_w3c_check() liefert. |
||
61 | |||
62 | // Es gibt extrem viele Strict-Fehler im PEAR... Wir dürfen kein E_STRICT hier verwenden |
||
63 | $old_err_rep = ini_get('error_reporting'); |
||
64 | |||
65 | // PEAR hat einen Notice Fehler, wenn ein Nicht-UTF8-Zeichen in der HTML vorhanden ist |
||
66 | // error_reporting(E_NOTICE); |
||
67 | error_reporting(E_ALL ^ E_NOTICE); |
||
68 | |||
69 | require_once 'Services/W3C/HTMLValidator.php'; |
||
70 | $validator = new Services_W3C_HTMLValidator(); |
||
71 | $res = $validator->validateFragment($fragment); |
||
72 | |||
73 | ini_set('error_reporting', $old_err_rep); |
||
74 | |||
75 | if (isset($res->validity)) { |
||
76 | return $res->validity; |
||
77 | } else { |
||
78 | return null; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public static function auto_perform_w3c_check($fragment, $validator_url, $force_external_check = false) { |
||
83 | if ((self::local_w3c_check_possible()) && (!$force_external_check)) { |
||
84 | return self::perform_local_w3c_check($fragment); |
||
85 | } else { |
||
86 | return self::perform_external_w3c_check($fragment, $validator_url); |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | ?> |