Skip to content

Commit b1d59c9

Browse files
committed
Fix PHP error
1 parent 93165d3 commit b1d59c9

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/class.Net.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@
44
* @package i18nChecker
55
*/
66
/*
7-
*
7+
*
88
*/
99
require_once(PATH_SRC.'/class.Utils.php');
1010
/**
1111
* HTTP related functions
12-
*
13-
* This class defines functions to fetch and return the content and important
14-
* information about remote or uploaded documents.
15-
*
12+
*
13+
* This class defines functions to fetch and return the content and important
14+
* information about remote or uploaded documents.
15+
*
1616
* @package i18nChecker
1717
* @author Thomas Gambet <[email protected]>
1818
* @copyright 2011 W3C ® (MIT, ERCIM, Keio)
1919
* @license http://www.w3.org/Consortium/Legal/copyright-software
2020
*/
2121
class Net {
22-
22+
2323
private static $logger;
24-
24+
2525
public static function _init() {
2626
self::$logger = Logger::getLogger('Net');
2727
}
28-
28+
2929
public static function getDocumentByUri($uri) {
3030
self::$logger->info("Check by URI initiated for: ".$uri);
31-
31+
3232
// Check that a uri has been submitted
3333
if ($uri == "") {
3434
Message::addMessage(MSG_LEVEL_ERROR, lang("message_empty_uri"));
3535
self::$logger->info("- Aborted: URI is empty");
3636
return false;
3737
}
38-
38+
3939
// Check the scheme of the uri, must be http or https
4040
$scheme = parse_url($uri, PHP_URL_SCHEME);
4141
if ($scheme == null)
@@ -45,24 +45,24 @@ public static function getDocumentByUri($uri) {
4545
self::$logger->info("- Aborted: ".$scheme." scheme is not allowed");
4646
return false;
4747
}
48-
48+
4949
// Check that the uri is correct (CURLE_URL_MALFORMAT is not enough)
5050
/*if (preg_match('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', $uri) == 0) {
5151
Message::addMessage(MSG_LEVEL_ERROR, lang("message_invalid_url_syntax", $uri));
5252
self::$logger->info("- Aborted: incorrect syntax");
5353
//return false;
5454
}*/
55-
55+
5656
// Get the content and headers of the submitted document
5757
$result = self::fetchDocument($uri);
5858
$uri = $result[0];
5959
$content = $result[1];
6060
$curl_info = $result[2];
6161
$curl_error = $result[3];
62-
63-
self::$logger->debug("Effective URI: ".$uri);
62+
63+
self::$logger->debug("Effective URI: ".$uri);
6464
self::$logger->debug("Curl Info: ".print_r($curl_info, true));
65-
65+
6666
// Report errors to the user. Most common cases should be internationalized.
6767
if ($curl_error != 0) {
6868
if ($curl_error == CURLE_URL_MALFORMAT) {
@@ -80,8 +80,8 @@ public static function getDocumentByUri($uri) {
8080
self::$logger->info("Curl ERROR: ".$result[4]);
8181
return false;
8282
}
83-
84-
// Check the response code.
83+
84+
// Check the response code.
8585
$response_code = $curl_info["http_code"];
8686
if ($response_code == 404) {
8787
Message::addMessage(MSG_LEVEL_ERROR, lang("message_document_not_found"));
@@ -97,37 +97,37 @@ public static function getDocumentByUri($uri) {
9797
self::$logger->info("- Aborted: HTTP response code != 200 (".$response_code.")");
9898
return false;
9999
}
100-
100+
101101
// Check that the document mimetype is either text/html or application/xhtml+xml
102102
$mimetypename = 'Unknown';
103103
if (strpos($curl_info['content_type'], ';')) {
104104
$parts = explode(';', $curl_info['content_type']);
105105
$mimetypename = $parts[0];
106-
} else {
107-
$mimetypename = $curl_info['content_type'];
106+
} else {
107+
$mimetypename = $curl_info['content_type'];
108108
}
109-
109+
110110
if ($mimetypename != 'text/html' && $mimetypename != 'application/xhtml+xml') {
111111
Message::addMessage(MSG_LEVEL_ERROR, lang("message_unsupported_mimetype", $mimetypename));
112112
self::$logger->info("- Aborted: ".$mimetypename." mime-type not supported");
113113
return false;
114114
}
115-
115+
116116
// Returns the headers and the content of the document
117117
return array($uri, $curl_info, $content);
118118
}
119-
119+
120120
public static function getDocumentByFileUpload($file) {
121121
Message::addMessage(MSG_LEVEL_WARNING, lang("message_file_upload_warning"));
122122
//Message::addMessage(MSG_LEVEL_WARNING, "The file upload feature is still experimental and not fully tested. Results should be considered with care.");
123123
$content = file_get_contents($file['tmp_name']);
124-
/* // seems that php deletes temporary file at the end of the request anyway
124+
/* // seems that php deletes temporary file at the end of the request anyway
125125
* if (Conf::get('delete_uploaded_files'))
126126
* unlink($file['tmp_name']);
127127
*/
128128
return array(null, null, $content);
129129
}
130-
130+
131131
public static function fetchDocument($url) {
132132
// Support of IRIs.
133133
$isIRI = false;
@@ -146,7 +146,7 @@ public static function fetchDocument($url) {
146146
self::$logger->error("Error parsing url: ".$url);
147147
}
148148
}
149-
149+
150150
//$url = str_replace("&amp;", "&", urldecode(trim($encodedUrl)));
151151
$ch = curl_init();
152152
curl_setopt($ch, CURLOPT_USERAGENT, Conf::get('curl_user_agent'));
@@ -162,33 +162,33 @@ public static function fetchDocument($url) {
162162
curl_setopt($ch, CURLOPT_TIMEOUT, Conf::get('curl_timeout'));
163163
curl_setopt($ch, CURLOPT_MAXREDIRS, Conf::get('curl_maxredirs'));
164164
// Curl does not parse the Content-Language header so we need a callback function (cf CURLOPT_HEADERFUNCTION)
165-
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $curl_info) use (&$_REQUEST) {
165+
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $curl_info) {
166166
$pattern = '/Content-Language:(.*?)\n/';
167167
if (preg_match($pattern, $curl_info, $result))
168168
$_REQUEST['doc_content_language'] = trim($result[1]);
169169
return strlen($curl_info);
170170
});
171-
171+
172172
self::$logger->debug("CURL Options: ".
173173
"\n\t\t User-Agent: ".Conf::get('curl_user_agent').
174174
"\n\t\t CookieJar: ".Conf::get('curl_cookiejar_path')." - Enabled: ".Conf::get('curl_cookiejar_enabled').
175175
"\n\t\t Connexion Timeout: ".Conf::get('curl_connect_timeout').
176176
"\n\t\t Timeout: ".Conf::get('curl_timeout').
177177
"\n\t\t Max redirections: ".Conf::get('curl_maxredirs'));
178-
178+
179179
$header = array();
180180
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
181181
$header[] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
182182
if (isset($_SERVER['HTTP_ACCEPT_CHARSET']))
183183
$header[] = $_SERVER['HTTP_ACCEPT_CHARSET'];
184-
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
185-
184+
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
185+
186186
$content = curl_exec($ch);
187187
$response = curl_getinfo($ch);
188188
$code = curl_errno($ch);
189189
$error = curl_error($ch);
190190
curl_close($ch);
191-
191+
192192
// Add the content-language header value that we parsed before to $curl_info
193193
if (isset($_REQUEST['doc_content_language']) && $_REQUEST['doc_content_language'] != "") {
194194
$response['content_language'] = $_REQUEST['doc_content_language'];
@@ -208,7 +208,7 @@ public static function fetchDocument($url) {
208208
$response['url'] = http_build_url($parsedURL);
209209
//self::$logger->debug("Final effective URL: ".$response['url']);
210210
}
211-
211+
212212
return array($response['url'], $content, $response, $code, $error);
213213
}
214214
}

0 commit comments

Comments
 (0)