Trackback implementation for Emacs

| emacs

From, posted by Mark A. Hershberger:

This will be put into nnrss.el or weblogger.el, but, for now, here
is an implementation of trackback.

(defun tb-find-tb-url (url &optional local)
  "Find the track-back URL for a resource."
    (let* (xmlform htmlform)
      ;; bit o' work necessary for w3 pre-cvs and post-cvs
      (if local
	  (let ((coding-system-for-read 'binary))
	    (insert-file-contents url))
	(mm-url-insert url)))
    (when (re-search-forward "" nil t)
	  (let ((rdf-end (match-end 0)))
	    (goto-char rdf-start)
	    (re-search-forward "trackback:ping=\"\\([^\"]+\\)" rdf-end)
	    (match-string-no-properties 1)))))))

(defun tb-get-trackback (url)
  "Get who's tb-ed an entry."
  (let ((tb-url (tb-find-tb-url url)))
    (when (not tb-url)
      (error "No trackback URL found at %s" url))
    (w3-fetch (concat tb-url "?__mode=rss"))))

(defun tb-send-trackback (url data &optional no-seek)
  "Send a trackback."
  (let ((tb-url (tb-find-tb-url url)))
    (when (and (not no-seek)
	       (not tb-url))
      (error "No trackback URL found at %s" url))
    (let* ((enctype "multipart/form-data")
	   (query (w3-encode-multipart/form-data data))
	   (url-request-method "POST")
	   (url-request-data (cdr query))
	    (cons (cons "Content-type" (concat enctype "; boundary=\""
					       (substring (car query) 2 nil)
      (w3-fetch (or tb-url url)))))

(defun w3-encode-multipart/form-data (items)
  ;; Create a multipart form submission.
  ;; Returns a cons of two strings.  Car is the separator used.
  ;; cdr is the body of the MIME message."
  (let ((separator (format-time-string
    (cons separator
	     (lambda (item)
		(car item) (cdr item) separator)))
	    items "\r\n")
	   "\r\n" separator "--\r\n"))))

Example Code:

 '(("title"     . "Emacs Trackback Implementation")
   ("excerpt" . "An implementation of trackback for emacs webloggers.")
   ("url"       . "")
   ("blog_name" . "")) t)

Now all we need is a way to receive trackback pings…

You can comment with Disqus or you can e-mail me at