]> git.mjollnir.org Git - s9y.git/commitdiff
Made pingback receiving better working with WordPress Pingbacks
authorbrockhaus <brockhaus>
Mon, 20 Aug 2007 21:00:01 +0000 (21:00 +0000)
committerbrockhaus <brockhaus>
Mon, 20 Aug 2007 21:00:01 +0000 (21:00 +0000)
comment.php

index f849e142f6741ca69d930eca45851513849192f8..192d173a67bdeb459f27421ef26838d3820df676 100644 (file)
@@ -2,8 +2,8 @@
 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
 # All rights reserved.  See LICENSE file for licensing details
 
-include_once('serendipity_config.inc.php');
-include_once S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
+include('serendipity_config.inc.php');
+include S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
 
 header('Content-Type: text/html; charset=' . LANG_CHARSET);
 
@@ -20,11 +20,33 @@ if (isset($serendipity['GET']['switch'], $serendipity['GET']['entry'])) {
 
 serendipity_rememberComment();
 
-if (!($type = @$_REQUEST['type'])) {
-    $type = 'normal';
+// Trackback logging. For developers: can be switched to true!
+$tb_logging = false;
+// Pingback logging. For developers: can be switched to true!
+$pb_logging = false;
+
+if ($pb_logging) {
+    log_pingback('CONTENT_TYPE: ' . $_SERVER['CONTENT_TYPE']);
+    log_pingback('HTTP_RAW_POST_DATA: ' .  $tmp);
 }
 
-$tb_logging = false; // for developers: can be switched to true!
+if (!($type = @$_REQUEST['type'])) {
+    if ($pb_logging) {
+        ob_start();
+        print_r($HTTP_RAW_POST_DATA);
+        $tmp = ob_get_contents();
+        ob_end_clean();
+        log_pingback('NO TYPE HANDED!');
+    }
+    
+    // WordPress pingbacks don't give any parameter. If it is a XML POST asume it's a pigback
+    if ($_SERVER['CONTENT_TYPE'] == 'text/xml' && isset($HTTP_RAW_POST_DATA)) {
+        $type = 'pingback'; 
+    }
+    else {
+        $type = 'normal';
+    }
+}
 
 if ($type == 'trackback') {
     if ($tb_logging) {
@@ -73,9 +95,20 @@ if ($type == 'trackback') {
         fclose($fp);
     }
 } else if ($type == 'pingback') {
+    if ($pb_logging) {
+        log_pingback('RECEIVED PINGBACK');
+        # PHP 4.2.2 way of doing things
+        ob_start();
+        print_r($HTTP_RAW_POST_DATA);
+        $tmp = ob_get_contents();
+        ob_end_clean();
+        log_pingback('HTTP_RAW_POST_DATA: ' .$tmp);
+    }
     if (add_pingback($_REQUEST['entry_id'], $HTTP_RAW_POST_DATA)) {
+        log_pingback('PINGBACK SUCCESS');;
         report_pingback_success();
     } else {
+        log_pingback('PINGBACK FAILURE');;
         report_pingback_failure();
     }
 } else {
@@ -162,5 +195,15 @@ if ($type == 'trackback') {
 
     $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
 }
+
+// Debug logging for pingback receiving
+function log_pingback($message){
+    global $pb_logging;
+    if ($pb_logging) {
+        $fp = fopen('pingback.log', 'a');
+        fwrite($fp, '[' . date('d.m.Y H:i') . '] ' . $message . "\n");
+        fclose($fp);
+    }
+}
 /* vim: set sts=4 ts=4 expandtab : */
 ?>