Update of /cvsroot/php-blog/jBlog
In directory sc8-pr-cvs1:/tmp/cvs-serv604
Modified Files:
comment.php jBlog_functions.inc.php
Log Message:
improved trackback autodiscovery
Index: comment.php
===================================================================
RCS file: /cvsroot/php-blog/jBlog/comment.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- comment.php 6 Mar 2003 17:07:15 -0000 1.5
+++ comment.php 7 Mar 2003 04:07:37 -0000 1.6
@@ -6,44 +6,6 @@
$type = 'normal';
}
-function
-add_trackback ($id, $title, $url, $name, $excerpt)
-{
- global $jBlog;
-
- $comment['title'] = $title;
- $comment['url'] = $url;
- $comment['name'] = $name;
- $comment['comment'] = $excerpt;
-
- jBlog_saveComment($id, $comment, 'TRACKBACK');
-
- return 1;
-}
-
-function
-report_trackback_success ()
-{
-print <<<SUCCESS
-<?xml version="1.0" encoding="iso-8859-1"?>
-<response>
-<error>0</error>
-</response>
-SUCCESS;
-}
-
-function
-report_trackback_failure ()
-{
-print <<<FAILURE
-<?xml version="1.0" encoding="iso-8859-1"?>
-<response>
-<error>1</error>
-<message>Danger Will Robinson, trackback failed.</message>
-</response>
-FAILURE;
-}
-
if ($type == 'trackback') {
$uri = $_SERVER['REQUEST_URI'];
if (preg_match('@\/(\d+)$@', $uri, $matches)) {
Index: jBlog_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/jBlog/jBlog_functions.inc.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- jBlog_functions.inc.php 6 Mar 2003 21:11:39 -0000 1.28
+++ jBlog_functions.inc.php 7 Mar 2003 04:07:37 -0000 1.29
@@ -561,7 +561,7 @@
* validate trackback response
*/
function
-jBlog_trackback_is_success($resp)
+jBlog_trackback_is_success($resp, $final=0)
{
if (preg_match('@<error>(\d)+</error>@', $resp, $matches)) {
if ((int) $matches[1]) {
@@ -575,7 +575,11 @@
}
}
}
-
+ else if($final) {
+ if(preg_match('@trackback:ping(\s*rdf:resource)?\s*=\s*"(http:[^"]+)"@', $resp, $matches)) {
+ return jBlog_trackback_is_success(_jBlog_send(parse_url($matches[2], $data)), 1);
+ }
+ }
return 1;
}
@@ -584,6 +588,22 @@
/**
* Send a trackback ping
*/
+
+function _jBlog_send($target, $data) {
+ fwrite($sock, "POST {$target['path']}{$target['query']} HTTP/1.1\r\n");
+ fwrite($sock, "Host: {$target['host']}\r\n");
+ fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
+ fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
+ fwrite($sock, "Connection: close\r\n\r\n");
+ fwrite($sock, $data);
+
+
+ while (!feof($sock)) {
+ $res .= fgets($sock, 1024);
+ }
+ return $res;
+}
+
function
jBlog_trackback_send($loc, $url, $author, $title, $text)
{
@@ -605,31 +625,59 @@
$data = "url=".rawurlencode($url)."&title=".rawurlencode($title).
"&blog_name=".rawurlencode($author)."&excerpt=".rawurlencode($text);
- fwrite($sock, "POST {$target['path']}{$target['query']} HTTP/1.1\r\n");
- fwrite($sock, "Host: {$target['host']}\r\n");
- fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
- fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
- fwrite($sock, "Connection: close\r\n\r\n");
- fwrite($sock, $data);
-
-
- while (!feof($sock)) {
- $res .= fgets($sock, 1024);
- }
-
- $res = jBlog_trackback_is_success($res);
+ $res = _jBlog_send($target, $data);
+ $res = jBlog_trackback_is_success($res, $data);
fclose($sock);
return $res;
}
/**
+ *
+ */
+function
+add_trackback ($id, $title, $url, $name, $excerpt)
+{
+ global $jBlog;
+
+ $comment['title'] = $title;
+ $comment['url'] = $url;
+ $comment['name'] = $name;
+ $comment['comment'] = $excerpt;
+
+ jBlog_saveComment($id, $comment, 'TRACKBACK');
+
+ return 1;
+}
+
+/**
* Cut text
*/
function
jBlog_trackback_excerpt($text)
{
return substr($text, 0, 255);
+}
+
+function report_trackback_success ()
+{
+print <<<SUCCESS
+<?xml version="1.0" encoding="iso-8859-1"?>
+<response>
+<error>0</error>
+</response>
+SUCCESS;
+}
+
+function report_trackback_failure ()
+{
+print <<<FAILURE
+<?xml version="1.0" encoding="iso-8859-1"?>
+<response>
+<error>1</error>
+<message>Danger Will Robinson, trackback failed.</message>
+</response>
+FAILURE;
}
|