+ // Return it
+ return $getUrl;
+}
+
+// Removes http[s]://<hostname> from given url
+function removeHttpHostNameFromUrl ($url) {
+ // Remove http[s]://
+ $remove = explode(':', $url);
+ $remove = explode('/', substr($remove[1], 3));
+
+ // Remove the first element (should be the hostname)
+ unset($remove[0]);
+
+ // implode() back all other elements and prepend a slash
+ $url = '/' . implode('/', $remove);
+
+ // Return prepared URL
+ return $url;
+}
+
+// Sends a HTTP request (GET, POST, HEAD are currently supported)
+function sendHttpRequest ($requestType, $baseUrl, $requestData = array(), $removeHeader = FALSE) {
+ // Init response
+ $response = array();
+
+ // Start "detecting" the request type
+ switch ($requestType) {
+ case 'HEAD': // Send a HTTP/1.1 HEAD request
+ $response = sendHeadRequest($baseUrl, $requestData);
+ break;
+
+ case 'GET': // Send a HTTP/1.1 GET request
+ $response = sendGetRequest($baseUrl, $requestData, $removeHeader);
+ break;
+
+ case 'POST': // Send a HTTP/1.1 POST request
+ $response = sendPostRequest($baseUrl, $requestData, $removeHeader);
+ break;
+
+ default: // Unsupported HTTP request, this is really bad and needs fixing
+ reportBug(__FUNCTION__, __LINE__, 'Unsupported request detected. requestType=' . $requestType . ',baseUrl=' . $baseUrl . ',requestData()=' . count($requestData));
+ break;
+ } // END - switch
+
+ // Return response
+ return $response;
+}
+
+// Sends a HEAD request
+function sendHeadRequest ($baseUrl, $requestData = array()) {
+ // Generate full GET URL
+ $getUrl = generateGetUrlFromBaseUrlData($baseUrl, $requestData);
+
+ // Is there http[s]:// in front of the URL?
+ if (isFullQualifiedUrl($getUrl)) {
+ // Remove http[s]://<hostname> from URL
+ $getUrl = removeHttpHostNameFromUrl($getUrl);
+ } elseif (substr($getUrl, 0, 1) != '/') {
+ // Prepend a slash
+ $getUrl = '/' . $getUrl;
+ }
+
+ // Extract hostname and port from script
+ $host = extractHostnameFromUrl($baseUrl);
+
+ // Generate HEAD request header
+ $request = 'HEAD ' . (isProxyUsed() === TRUE ? $baseUrl : '') . trim($getUrl) . ' HTTP/1.1' . getConfig('HTTP_EOL');
+ $request .= 'Host: ' . $host . getConfig('HTTP_EOL');
+ $request .= 'Referer: ' . getUrl() . '/admin.php' . getConfig('HTTP_EOL');
+ if (isConfigEntrySet('FULL_VERSION')) {
+ $request .= 'User-Agent: ' . getTitle() . '/' . getFullVersion() . getConfig('HTTP_EOL');
+ } else {
+ $request .= 'User-Agent: ' . getTitle() . '/' . getConfig('VERSION') . getConfig('HTTP_EOL');
+ }
+ $request .= 'Accept: image/png,image/*;q=0.8,text/plain,text/html,*/*;q=0.5' . getConfig('HTTP_EOL');
+ $request .= 'Accept-Charset: UTF-8,*' . getConfig('HTTP_EOL');
+ $request .= 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' . getConfig('HTTP_EOL');
+ $request .= 'Connection: close' . getConfig('HTTP_EOL');
+ $request .= getConfig('HTTP_EOL');
+
+ // Send the raw request
+ $response = sendRawRequest($host, $request);
+
+ // Return the result to the caller function
+ return $response;
+}
+
+// Send a GET request
+function sendGetRequest ($baseUrl, $requestData = array(), $removeHeader = FALSE) {
+ // Generate full GET URL
+ $getUrl = generateGetUrlFromBaseUrlData($baseUrl, $requestData);
+
+ // Is there http[s]:// in front of the URL?
+ if (isFullQualifiedUrl($getUrl)) {
+ // Remove http[s]://<hostname> from url
+ $getUrl = removeHttpHostNameFromUrl($getUrl);
+ } elseif (substr($getUrl, 0, 1) != '/') {
+ // Prepend a slash
+ $getUrl = '/' . $getUrl;
+ }
+
+ // Extract hostname and port from script
+ $host = extractHostnameFromUrl($baseUrl);
+