Trackback XML syntax error + get Trackback to WP working

Found a bug? Tell us!!
Slim
Posts: 3
Joined: Mon Jul 02, 2007 10:28 pm

Trackback XML syntax error + get Trackback to WP working

Post by Slim »

Hi,

first post, and starting off with a bug. Not a nice way to start into a forum, I guess. ;)

I'm pretty sure, I found a bug yesterday. I'll start off with the current trackback function XML.

Code: Select all

<?xml version=\"1.0\"?>
<methodCall>
  <methodName>pingback.ping</methodName>
  <params>
    <param>
      <name>sourceURI</name>
      <value><string>{$serendipity['baseURL']}</string></value>
    </param>
      <name>targetURI</name>
      <value><string>$loc</string></value>
    </param>
  </params>
</methodCall>
This is taken out of includes/functions_trackback.inc.php. As you can easily see, this XML is not valid. There is an opening param tag missing before the targetURI.

I actually stumbled upon this error while searching for the reason, why trackbacks to WordPress don't work. I fixed this little error myself and then ran into the next problem.

Now I traced a bit on my host with a WP and a S9y running and got an idea, why trackbacks to WP don't work. Whenever I save an entry, the trackback is sent. Immediately the WP blog connects to my server and requests a page. Then I get an error, saying that the source URI does not contain a link to the destination and therefore cannot be used as a source. And I do agree with WP in this point. Trackbacks from S9y do look like this:

Code: Select all

<?xml version="1.0"?>
<methodCall>
  <methodName>pingback.ping</methodName>
  <params>
    <param>
      <name>sourceURI</name>
      <value><string>http://example.com/s9y/</string></value>
    </param>
    <param>
      <name>targetURI</name>
      <value><string>http://example.com/wp/archives/48/trackback</string></value>
    </param>
  </params>
</methodCall>
So the WP blog fetches the front page of the s9y blog. And if I have the link "hidden" in the extended view, it can't find a link to itself and therefore rejects the trackback.

The other way round does look better:

Code: Select all

<?xml version="1.0"?>
<methodCall>
<methodName>pingback.ping</methodName>
<params>
<param><value><string>http://example.com/wp/archives/48</string></value></param>
<param><value><string>http://example.com/s9y/2007/06/04/4.html</string></value></param>
</params></methodCall>
So to me the solution should be to include the URI of the just saved entry in the source of the trackback XML. Then WP would find the link and would not reject it anymore. Is that somehow possible? I think it should be only a small smarty variable, but I'm not really into that.

Comments? Sorry for the long post, but it took some lines to explain. ;)

Best regards,
Sebastian

BTW: WP declares the content-type of the trackback request as "text/xml", as opposed to "application/x-www-form-urlencoded" in S9y, which makes it nicer to read in wireshark. ;)
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

Well.. I patched the missing <param> tag into the file you mentioned (using s9y 1.1.3). But it still doesn't work for me, adding trackbacks to WP blogs, even if the link is not located in the extended part of the entry.

But if I add the trackback url manualy using the Trackback Plugin, the trackback is set correctly.

So I assume, the functionality is there, but the WP blog is missing the rdf meta tag? Perhaps there should be implemented a fallback for these blogs, by building the trackback link manualy. For WP the trackback link seems to be <article_link>/trackback/. So if the rdf tag is missing on the page, it could be wise to try this link as fallback? Perhaps an event plugin could do this job, too? Just thinking..
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

First off, thanks for sending that patch. The good news: It fixes a XML oddity.

The bad news: Serendipity doesn't really support pingbacks, the code there is NOT used for sending a TRACKBACK. Trackbacks are sent using the function serendipity_trackback_autodiscover().

This function already submits the extended article view to a WordPress blog.

The problem is this: Serendipity opens the URL you specified in your body/extended entry and tries to detect the trackback location. The trackback location to send a trackback to MUST be contained within <RDF>-metadata elements. Some WP blogs do NOT have this, as you've properly recognized. So serendipity properly thinks, there's no trackback to send to.

If you use the trackback plugin, this will send a trackback to an URL even if no RDF-metadata is present.

So to properly fix it, you must tell the foreign WordPress blogs to properly implement the trackback specification by including the RDF-metadata in their templates. Or you need to use the trackback-plugin like you currently do...

We cannot use a fallback, because without RDF metadata there's no way to check if a URL really accepts a trackbakc. S9y would then spam sites with Trackback requests even if they do not accept this. That's not really acceptable to me. I think using the trackback plugin for these kind of problems should be the better way to go?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

Hi Garvin.

Yes, you are right, I didn't noticed, that my "fallback idea" could be noticed as SPAM. And of course: Letting the author know about missing RDF tags would be the cleanest way to solve this.

My problem is: Not *some* WP blogs are missing the RDF tag for automated detection but *most* I think. It would be hard work to email all of them, and I guess most of them don't have the PHP capabilities to change this. How do wordpress users do a trackback? Do they all manualy add the trackback url? (I've only seen Serendipity yet, as I am a blog-starter)

Perhaps a "not so spamy way" to fallback is, to check the HTML code of the page, if there is <a href="[articleUrl]/trackback/">. This must be a WP blog without implemented RDF tags in 99% of the cases. Most of the WP blogs I've seen not having the RDF tag are showing the trackback URL below the article text for manualy adding.

Could this be a way to go?
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

I noticed that WP blogs without traceback RDF in many cases have a pingback link tag inside the code. Does s9y support pingback? If yes, how do I enable this?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I believe the RDF-tags are contained in the default WP template! So it's the repsonsibility of template creators to properly implement them. One of the reasons why s9y is a bit cleaner, hehe. ;-)

Bending the rules on s9y site to match the shortcomings of WP in this regard is IMHO not the proper way to go. On the other hand, trackback spam has virtually killed trackbacks, so I don't really know how to proceed with this.

When I personally trackback a WP blog, I usually add their URL with a /trackback/ at the end manually in the trackback plugin, yes.
Perhaps a "not so spamy way" to fallback is, to check the HTML code of the page, if there is <a href="[articleUrl]/trackback/">. This must be a WP blog without implemented RDF tags in 99% of the cases. Most of the WP blogs I've seen not having the RDF tag are showing the trackback URL below the article text for manualy adding.
This is a good suggestion, yes. I could add this for an upcoming serendipity 1.3 release, as it's too late to add this in the 1.2 release cycle (it could possibly and easily break trackbacks).

Maybe you'd like to try this patch - replace the function serendipity_trackback_autodiscover with this one:

Code: Select all

function serendipity_trackback_autodiscover($res, $loc, $url, $author, $title, $text, $loc2 = '') {
    $is_wp    = false;
    $wp_check = false;

    if (preg_match('@((' . preg_quote($loc, '@') . '|' . preg_quote($loc2, '@') . ')/?trackback/)@i', $res, $wp_loc)) {
        // We found a WP-blog that may not advertise RDF-Tags!
        $is_wp = true;
    }

    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])) {
            if ($is_wp) {
                $wp_check = true;
            } else {
                echo '<div>• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_NOT_FOUND) . '</div>';
                return false;
            }
        }
    }

    $trackURI = trim($matches[2]);

    if (preg_match('@dc:identifier\s*=\s*["\'](https?:[^\'"]+)["\']@i', $res, $test)) {
        if ($loc != $test[1] && $loc2 != $test[1]) {
            if ($is_wp) {
                $wp_check = true;
            } else {
                echo '<div>• ' . sprintf(TRACKBACK_FAILED, TRACKBACK_URI_MISMATCH) . '</div>';
                return false;
            }
        }
    }

    // If $wp_check is set it means no RDF metadata was found, and we simply try the /trackback/ url.
    if ($wp_check) {
        $trackURI = $wp_loc[0];
    }

    $data = 'url='        . rawurlencode($url)
          . '&title='     . rawurlencode($title)
          . '&blog_name=' . rawurlencode($author)
          . '&excerpt='   . rawurlencode(strip_tags($text));

    printf(TRACKBACK_SENDING, htmlspecialchars($trackURI));
    flush();

    $response = serendipity_trackback_is_success(_serendipity_send($trackURI, $data));

    if ($response === true) {
        echo '<div>• ' . TRACKBACK_SENT .'</div>';
    } else {
        echo '<div>• ' . sprintf(TRACKBACK_FAILED, $response) . '</div>';
    }

    return $response;
}
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

Thanks for the patch! Is this working with the s9y 1.1.3 version, I have installed?
Btw: Would you suggest me to switch to the beta version of s9y?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

The mentioned function should work with 1.1.3, but I didn't have the time to test it yet.
Btw: Would you suggest me to switch to the beta version of s9y?
Yes, the 1.2 version has many smaller bugs fixed. There are no open issues in the beta-version, so it'll become the final release soon.

If possible, you should even run the daily snapshots. Some other minor issues have been resolved since beta2 was released.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

1.) I patched my s9y 1.1.3 installation with the new function. Trackbacks to this "buggy" WP blogs are working perfectly now! I think, this is realy a nice feature enhancement for s9y!

2.) Okay, I will update to the newest beta version, soon. Is it just a matter of exchanging the php files, or do I have to run a kind of update skript on the database? Is documentation available describing briefly the update process?

Thanks Garvin for this extremely fast support! I read much about this when reading about the s9y advantages, and I have to say: Yes, it's true! :-)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Great to hear that. I'll definitely implement this functionality in the 1.3 version tree of serendipity as soon as we open it :)
2.) Okay, I will update to the newest beta version, soon. Is it just a matter of exchanging the php files, or do I have to run a kind of update skript on the database? Is documentation available describing briefly the update process?
Yes, only upload the files and the rest is done via the admin interface automatically. Check out the FAQ on www.s9y.org how to perform an update.
Thanks Garvin for this extremely fast support! I read much about this when reading about the s9y advantages, and I have to say: Yes, it's true! :-)
:-) Thanks a lot for that, much appreciated.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Slim
Posts: 3
Joined: Mon Jul 02, 2007 10:28 pm

Post by Slim »

Sorry, could not get back to you sooner. I've mailed with someone with a WP blog and sent him the description, how to insert RDF code. He did and now trackbacks to his blog do work. If someone needs that link to send it to WP blog owners: http://codex.wordpress.org/Template_Tags/trackback_rdf

When I tried to trackback to WP on Sunday, I tried it with and without the /trackback/ appended, it did not work. And I clearly saw the xml code mentioned in my original post. And I don't see any other XML code in the function_trackback.inc.php file. Also, my fix for that XML error worked - at least it got me a different error from WP.

So I think I haven't really understood, how s9y does backtracking. It searches for the RDF part in the linked URI. If it finds it, it sends out a correct trackback. Where is the XML code for those trackbacks? But what if not? To me it looks like it still sends something out to the linked site, like a fallback function. I saw it in my trace, that something was sent out. And it was this very xml code which had an error in it. What's the purpose of this? What does s9y do at this moment?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi Slim!
So I think I haven't really understood, how s9y does backtracking. It searches for the RDF part in the linked URI. If it finds it, it sends out a correct trackback. Where is the XML code for those trackbacks?
Trackbacks are NOT send with XML! They are only a simple HTTP-GET or HTTP-POST request using http://trackbackurl/blabla?url=XX&user=XX&entry=YY...

The workflow is this:

1. You enter a URL in your entry
2. You save the entry
3. s9y greps for all URLs
4. s9y opens each URL
5. s9y searches the returned HTML for a trackback RDF
6a. IF trackback RDF is found, s9y sends a HTTP request to the mentioned URL.
6b. If no trackback RDF is found, s9y aborts that trackback.

So there's no XML pingback functionality or anything like it involved. The function you mentioned in first instance is actually dead code that should not be called anywhere (yet, because I didn'T ever dive into pingbacks, only trackbacks).

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

Btw: Actualy I'm thinking about implementing pingback functionality into s9y, because the WP books w/o rdf trackback metainfo I've seen in most cases had a pingback link attribute (that could be fetched by the dead code you've mentioned).

But I will open a new topic for this. I guess, it should be a plugin like your trackback plugin, so I will open a thread in the plugin forum to fetch brainstormings. :-)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

To not create too much plugins for this, I'd suggest to incorporate the functionality into the Trackback plugin - that would be most helpful for users, I think.

Regards
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
blog.brockha.us
Regular
Posts: 695
Joined: Tue Jul 03, 2007 3:34 am
Location: Berlin, Germany
Contact:

Post by blog.brockha.us »

You want to see it incoporated into the trackback plugin because of performance reasons or why?

Is the trackback plugin in a stable state or are you implemnting new stuff? If I add functionalty into this plugin, I don't want to merge code to often.. This was the main reason, why I was thinking about a seperate plugin.
Post Reply