6200 comments
2357 subscribers
Follow me on Twitter (@sachac)
Subscribe! Feed reader E-mail

Trackback implementation for Emacs

From http://elisp.info/archive/80614224, 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."
  (with-temp-buffer
    (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))
	   (url-request-extra-headers
	    (cons (cons "Content-type" (concat enctype "; boundary=\""
					       (substring (car query) 2 nil)
					       "\""))
		  url-request-extra-headers)))
      (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
		    "--separator-%Y%j%H%M%S-for-www-form-data")))
    (cons separator
	  (concat
	   (mapconcat
	    (function
	     (lambda (item)
	       (w3-form-encode-make-mime-part
		(car item) (cdr item) separator)))
	    items "\r\n")
	   "\r\n" separator "--\r\n"))))

Example Code:

(tb-send-trackback
 "http://www.movabletype.org/mt/trackback/3"
 '(("title"     . "Emacs Trackback Implementation")
   ("excerpt" . "An implementation of trackback for emacs webloggers.")
   ("url"       . "http://elisp.info/archive/80614224")
   ("blog_name" . "elisp.info")) t)

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

http://elisp.info/archive/80614224

Short URL: http://sachachua.com/blog/p/2311

On This Day...

  • 2012: Weekly review: Week ending October 19, 2012 — The Small Business Forum was fun to sketchnote. Did lots of good stuff at my consulting gig. Biked through the [...]
  • 2011: Figuring out how to plan for a month — I’ve been doing weekly reviews since October 2006 (210 weekly reviews over ~260 weeks, or about 80% coverage), so I’ve [...]
  • 2010: Saving development time through virtual appliances — Photo (c) 2008 JakesDad – Creative Commons Attribution Licence 2.0 I’m beginning to be a big [...]
  • 2009: Almost a permanent resident! Decisions, decisions… — It’s a good thing I checked the status of my permanent residency application online, as the request for my passport [...]
  • 2007: Eshell redirection — Mike Mattie has this awesome Emacs tip for Eshell: redirecting to buffers and Lisp symbols! To overwrite buffer “foo”: ls > #<buffer foo> To [...]
  • 2007: Weekly review — This week, I focused on getting on board at IBM. I’m happy to say that the process was very smooth, and [...]
  • 2004: ARGH! Drying clothes! — I refuse to be held hostage by laundry tags. I’ll hang the suits up to dry, but darn if I’ll let [...]
  • 2004: Tentative Osaka plans — - Work tomorrow - Leave MSI at 5:40 and arrive at TKC by 7:30. - Shower and change into casual clothes. Pick [...]
  • 2004: First day — Think technical challenge. Think fun. Don’t think about classrooms and a dorm five minutes away from school. Delphi is fun, although I [...]
  • 2004: Training so far — Software installation in a foreign language is difficult. The first time around, I selected “repair” instead of “reinstall”. I realized my mistake [...]