1 ;; mixi-atom.el --- Atom Syndication Format
3 ;; Copyright (C) 2007 OHASHI Akira
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: hypermedia
8 ;; This file is *NOT* a part of Emacs.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; if not, you can either send email to this
22 ;; program's maintainer or write to: The Free Software Foundation,
23 ;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 ;; If you have bug reports and/or suggestions for improvement, please
30 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
37 (defcustom mixi-atom-coding-system 'utf-8
38 "*Coding system for Atom Syndication Format."
42 (defcustom mixi-atom-namespace "http://www.w3.org/2005/Atom"
43 "*Namespace for Atom Syndication Format."
47 (defcustom mixi-atom-title "Mixi Feed"
52 (defcustom mixi-atom-file "~/atom.xml"
53 "*File name for `mixi-make-atom-file'."
57 (defcustom mixi-atom-syndication-list
58 '((mixi-get-diaries . 10))
59 "*A list of atom syndication definition.
60 Each element looks like (URL . RANGE) or (FUNCTION . RANGE).
61 URL is the URL for mixi access point. If URL is friend's, get his/her diaries
62 as article. If community's, get its BBSes. If diary's or BBS's, get its
64 FUNCTION is the function which has one `range' argument and returns the list
66 RANGE is the range for getting articles. If RANGE is nil, get all articles."
69 (radio (string :tag "URL")
70 (const :tag "New diaries" mixi-get-new-diaries)
71 (const :tag "New comments" mixi-get-new-comments)
72 (const :tag "New BBSes" mixi-get-new-bbses)
73 (const :tag "Messages" mixi-get-messages)
74 (const :tag "Logs" mixi-get-logs)
75 (function :tag "Other function"))
76 (radio (integer :tag "Range")
77 (const :tag "All" nil)))))
79 (defmacro mixi-atom-make-date (time)
80 `(let ((date (format-time-string "%Y-%m-%dT%T%z" ,time)))
81 (if (string-match "[+-][0-9][0-9][0-9][0-9]$" date)
82 (let ((length (length date)))
84 (substring date 0 (- length 2))
85 (substring date (- length 2) length)))
88 (defmacro mixi-atom-now ()
89 `(mixi-atom-make-date (current-time)))
91 (defun mixi-make-atom-entry (object)
94 " <title>" (mixi-make-title object) "</title>\n"
95 " <link href=\"" (mixi-make-encoded-url object) "\"/>\n"
96 " <id>" (mixi-make-tag-uri object) "</id>\n"
97 " <updated>" (mixi-atom-make-date (mixi-object-time object))
99 " <summary>" (mixi-remove-markup (mixi-make-content object))
103 (defun mixi-make-atom-entries (objects &optional range)
106 (mapcar (lambda (object)
108 (concat entries (mixi-make-atom-entry object)))
109 (when (mixi-parent-p object)
110 (let ((comments (mixi-get-comments object range)))
114 (mixi-make-atom-entry (car comments))))
115 (setq comments (cdr comments))))))
119 (defun mixi-make-atom ()
120 "Make Atom Syndication Format"
121 (concat "<?xml version=\"1.0\" encoding=\""
122 (symbol-name mixi-atom-coding-system) "\"?>\n"
123 "<feed xmlns=\"" mixi-atom-namespace "\">\n"
125 "<title>" mixi-atom-title "</title>\n"
126 "<link href=\"" mixi-url "\"/>\n"
127 "<updated>" (mixi-atom-now) "</updated>\n"
129 " <name>" (mixi-friend-nick (mixi-make-me)) "</name>\n"
131 "<id>tag:mixi.jp," (format-time-string "%Y-%m-%d"
133 ":" (mixi-friend-nick (mixi-make-me)) "</id>\n"
136 (mapcar (lambda (list)
137 (let ((url-or-function (car list))
139 (mixi-make-atom-entries
140 (mixi-make-objects url-or-function
142 mixi-atom-syndication-list)
148 (defun mixi-atom-cgi ()
149 (princ (concat "Content-Type: application/atom+xml; charset="
150 (symbol-name mixi-atom-coding-system) "\n"
152 (encode-coding-string (mixi-make-atom)
153 mixi-atom-coding-system))))
156 (defun mixi-atom-file ()
158 (insert (mixi-make-atom))
159 (let ((coding-system-for-write mixi-atom-coding-system)
160 (file (expand-file-name mixi-atom-file)))
161 (write-region (point-min) (point-max) file))))
165 ;;; mixi-atom.el ends here