$target['port'] = 80;
}
- $sock = @fsockopen($target['host'], $target['port']);
- if (!is_resource($sock)) {
- return "Couldn't connect to $loc";
+ $uri = $target['scheme'] . '://' . $target['host'] . ':' . $target['port'] . $target['path'] . $target['query'];
+ require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
+ $req = &new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'POST'));
+ $req->addRawPostData($data, true);
+ $res = $req->sendRequest();
+
+ if (PEAR::isError($res)) {
+ return false;
}
- $headers = "POST {$target['path']}{$target['query']} HTTP/1.1\r\n";
- $headers .= "Host: {$target['host']}\r\n";
- $headers .= "User-Agent: Serendipity/{$serendipity['version']}\r\n";
- $headers .= "Content-Type: application/x-www-form-urlencoded; charset=" . LANG_CHARSET . "\r\n";
- $headers .= "Content-Length: " . strlen($data) . "\r\n";
- $headers .= "Connection: close\r\n";
- $headers .= "\r\n";
- $headers .= $data;
-
- fwrite($sock, $headers);
-
- $res = '';
- while (!feof($sock)) {
- $res .= fgets($sock, 1024);
- }
-
- fclose($sock);
- return $res;
+ $fContent = $req->getResponseBody();
+ return $fContent;
}
/**
* @param string The title of our entry
* @param string The text of our entry
* @param string A comparsion URL
-
+
* @return string Response
*/
function serendipity_trackback_autodiscover($res, $loc, $url, $author, $title, $text, $loc2 = '') {
if (!preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*["\'](https?:[^"\']+)["\']@i', $res, $matches)) {
$matches = array();
serendipity_plugin_api::hook_event('backend_trackback_check', $matches, $loc);
-
+
// Plugins may say that a URI is valid, in situations where a blog has no valid RDF metadata
if (empty($matches[2])) {
echo '<div>• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '</div>';
$parsed_loc = $u['scheme'] . '://' . $u['host'] . $port . $u['path'];
- $res = '';
+ require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
+ $req = &new HTTP_Request($parsed_loc, array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'GET'));
+ $res = $req->sendRequest();
- $fp = @fsockopen($u['host'], $u['port'], $err, $timeout);
- if (!$fp) {
+ if (PEAR::isError($res)) {
echo '<div>• ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'</div>';
return;
- } else {
- fputs($fp, "GET {$u['path']} HTTP/1.0\r\n");
- fputs($fp, "Host: {$u['host']}\r\n");
- fputs($fp, "User-Agent: Serendipity/{$serendipity['version']}\r\n");
- fputs($fp, "Connection: close\r\n\r\n");
-
- while ($fp && !feof($fp) && strlen($res) < $serendipity['trackback_filelimit']) {
- $res .= fgets($fp, 4096);
- }
- fclose($fp);
-
- if (strlen($res) >= $serendipity['trackback_filelimit']) {
- echo '<div>• ' . sprintf(TRACKBACK_SIZE, $serendipity['trackback_filelimit']) .'</div>';
- return;
- }
}
- if (strlen($res) != 0) {
- serendipity_trackback_autodiscover($res, $parsed_loc, $url, $author, $title, $text, $loc);
- serendipity_pingback_autodiscover($loc, $res);
+ $fContent = $req->getResponseBody();
+
+ if (strlen($fContent) != 0) {
+ serendipity_trackback_autodiscover($fContent, $parsed_loc, $url, $author, $title, $text, $loc);
+ serendipity_pingback_autodiscover($loc, $fContent);
} else {
echo '<div>• ' . TRACKBACK_NO_DATA . '</div>';
}