Monday, November 08, 2010 at 12:01 AM.


on discoverPingInfo (adrurl) {
		<<7/21/03; 9:46:41 PM by JES
			<<Fix a bug where the auto-discovery bits could not be found if the page also contained RDF which was not for TrackBack auto-discovery.
		<<7/15/03; 12:20:13 AM by JES
			<<We were finding the first set of RDF info on the page, but this assumes that the post we're pinging is the first post on the page, so sometimes the trackback would show up in the wrong place on the target site. Now we find the RDF info with the permalink that corresponds to the post we want to ping.
		<<7/14/03; 12:12:35 PM by JES
			<<Pop off the anchor part of the URL if it exists before making the discovery request. Some servers don't handle this properly, and return a 404 page.
		<<4/25/03; 12:38:43 PM by DW
			<<Per Ringnalda's suggestion, note how we got the pingUrl. If it came through the "about" element, we'll do a GET, if it came through trackback:ping, we'll do a POST.
		<<4/25/03; 8:17:09 AM by DW
			<<If "trackback:ping" is not present, try to get the ping url from "about".
			<<Dave Sifry's site has an improperly formatted date. This is not encouraging. There's no really good workaround for this. If the date is mangled, I'll use Maybe the users won't notice. :-(
		<<4/23/03; 8:55:57 PM by DW
			<<Created. The name of the adrurl table is the URL that has been pointed to by the post. Read the page and look for a <RDF> element. If it can be ping'd record the information about the endpoint in the url table and set adrurl^.flSupportsTrackback = true, otherwise set it false.
	local (url = nameof (adrurl^));
	local (htmltext = tcp.httpreadurl (string.nthField (url, "#", 1)));
	<<wp.newtextobject (htmltext, @adrurl^.htmltext)
	<<local (htmltext = string (adrurl^.htmltext)) //debugging
	local (xtext);
	loop { //find the corresponding RDF snippet
		local (ixrdf = string.patternmatch ("<rdf:RDF", htmltext));
		if ixrdf == 0 { //no RDF element, return
			adrurl^.flChecked = true;
			adrurl^.flSupportsTrackback = false;
		htmltext = string.delete (htmltext, 1, ixrdf-1);
		<<wp.newtextobject (htmltext, @adrurl^.partialhtmltext)
		local (endpattern = "</rdf:RDF>");
		ixrdf = string.patternmatch (endpattern, htmltext);
		if ixrdf == 0 { //no RDF element, return
			adrurl^.flSupportsTrackback = false;
		xtext = string.mid (htmltext, 1, ixrdf + sizeof (endpattern) - 1);
		try {
			<<wp.newtextobject (htmltext, @adrurl^.partialhtmltext)
			local (xstruct);
			xml.compile (xtext, @xstruct);
			local (adrrdf = xml.getaddress (@xstruct, "RDF"));
			local (adrdescription = xml.getaddress (adrrdf, "Description"));
			local (adratts = @adrdescription^.["/atts"]);
			bundle { //JES 7/15/03: skip RDF snippets whose dc:identifier doesn't match the URL
				local (flFound = false);
				if defined (adratts^.["dc:identifier"]) {
					if string.lower (adratts^.["dc:identifier"]) == string.lower (url) {
						flFound = true}};
				if not flFound {
					htmltext = string.delete (htmltext, 1, sizeOf (xtext));
			adrurl^.xDiscoveryInfo = xstruct;
			bundle { //get pingUrl, 4/25/03 by DW
				if defined (adratts^.["trackback:ping"]) {
					adrurl^.pingUrl = adratts^.["trackback:ping"];
					adrurl^.flGotUrlFromAbout = false}
				else {
					adrurl^.pingUrl = adratts^.about;
					adrurl^.flGotUrlFromAbout = true}};
			adrurl^.postTitle = adratts^.["dc:title"];
			bundle { //get description, 4/25/03 by DW
				if defined (adratts^.["dc:description"]) {
					adrurl^.postDescription = adratts^.["dc:description"]}
				else {
					adrurl^.postDescription = ""}};
			bundle { //get postDate, 4/25/03 by DW
				try {
					adrurl^.postDate = date.iso8601StringToDate (adratts^.["dc:date"])}
				else {
					adrurl^.postDate = ()}};
			break} //JES 7/15/03: if we've gotten this far, we're done
		else { // found some RDF, but not the auto-discovery bits
			htmltext = string.delete (htmltext, 1, sizeOf (xtext));
	adrurl^.flSupportsTrackback = true}
<<bundle //test code
	<<discoverPingInfo (@tbtestManilaWebsite.["#discussionGroup"].messages.["0000005"].trackback.outbound.urls.[""])
<<bundle //more test code
	<<local (url = "")
	<<local (adrurl = @scratchpad.aPost.trackback.outbound.urls.[url])
	<<if not defined (adrurl^) {new (tableType, adrurl)}
	<<trackback.discoverPingInfo (adrurl)

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.