From: garvinhicking Date: Thu, 15 Dec 2005 11:22:37 +0000 (+0000) Subject: Use PEAR HTTP::Request to send trackbacks. Allows header redirection. X-Git-Tag: 1.0~227 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=23457e56c25fe46ef6b0d70b4683a37c80f03dfc;p=s9y.git Use PEAR HTTP::Request to send trackbacks. Allows header redirection. --- diff --git a/docs/NEWS b/docs/NEWS index cb8bc92..3ea3faa 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,10 @@ Version 1.0 () ------------------------------------------------------------------------ + * Trackback now uses PEAR HTTP::Request class to send trackbacks. + This allows to use HTTP redirects of trackbacks, which seem to + get more common nowadays (garvinhicking) + * Fix Bug #1377095 - Not counting correct number of entries on the /archives page. The page was counting entries belonging to more then one categories multiple times. (garvinhicking) diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index d0b96ea..82c0123 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -82,29 +82,18 @@ function _serendipity_send($loc, $data) { $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; } /** @@ -118,14 +107,14 @@ function _serendipity_send($loc, $data) { * @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 '
• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '
'; @@ -200,32 +189,20 @@ global $serendipity; $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 '
• ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'
'; 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 '
• ' . sprintf(TRACKBACK_SIZE, $serendipity['trackback_filelimit']) .'
'; - 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 '
• ' . TRACKBACK_NO_DATA . '
'; }