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-syndication-list
53 '((mixi-get-diaries . 10))
54 "*A list of atom syndication definition.
55 Each element looks like (URL . RANGE) or (FUNCTION . RANGE).
56 URL is the URL for mixi access point. If URL is friend's, get his/her diaries
57 as article. If community's, get its BBSes. If diary's or BBS's, get its
59 FUNCTION is the function which has one `range' argument and returns the list
61 RANGE is the range for getting articles. If RANGE is nil, get all articles."
64 (radio (string :tag "URL")
65 (const :tag "New diaries" mixi-get-new-diaries)
66 (const :tag "New comments" mixi-get-new-comments)
67 (const :tag "New BBSes" mixi-get-new-bbses)
68 (const :tag "Messages" mixi-get-messages)
69 (const :tag "Logs" mixi-get-logs)
70 (function :tag "Other function"))
71 (radio (integer :tag "Range")
72 (const :tag "All" nil)))))
74 (defmacro mixi-atom-make-date (time)
75 `(let ((date (format-time-string "%Y-%m-%dT%T%z" ,time)))
76 (if (string-match "[+-][0-9][0-9][0-9][0-9]$" date)
77 (let ((length (length date)))
79 (substring date 0 (- length 2))
80 (substring date (- length 2) length)))
83 (defmacro mixi-atom-now ()
84 `(mixi-atom-make-date (current-time)))
86 (defun mixi-make-atom-entry (object)
89 " <title>" (mixi-make-title object) "</title>\n"
90 " <link href=\"" (mixi-make-encoded-url object) "\"/>\n"
91 " <id>" (mixi-make-tag-uri object) "</id>\n"
92 " <updated>" (mixi-atom-make-date (mixi-object-time object))
94 " <summary>" (mixi-remove-markup (mixi-make-content object))
98 (defun mixi-make-atom-entries (objects &optional range)
101 (mapcar (lambda (object)
103 (concat entries (mixi-make-atom-entry object)))
104 (when (mixi-parent-p object)
105 (let ((comments (mixi-get-comments object range)))
106 (mapc (lambda (comment)
109 (mixi-make-atom-entry comment))))
115 (defun mixi-make-atom ()
116 "Make Atom Syndication Format"
117 (insert "<?xml version=\"1.0\" encoding=\""
118 (symbol-name mixi-atom-coding-system) "\"?>\n"
119 "<feed xmlns=\"" mixi-atom-namespace "\">\n"
121 "<title>" mixi-atom-title "</title>\n"
122 "<link href=\"" mixi-url "\"/>\n"
123 "<updated>" (mixi-atom-now) "</updated>\n"
125 " <name>" (mixi-friend-nick (mixi-make-me)) "</name>\n"
127 "<id>tag:mixi.jp," (format-time-string "%Y-%m-%d"
129 ":" (mixi-friend-nick (mixi-make-me)) "</id>\n"
132 (mapcar (lambda (list)
133 (let ((url-or-function (car list))
135 (mixi-make-atom-entries
136 (mixi-make-objects url-or-function
138 mixi-atom-syndication-list)
144 (defun mixi-atom-write-file (file)
147 (let ((coding-system-for-write mixi-atom-coding-system)
148 (file (expand-file-name file)))
149 (write-region (point-min) (point-max) file))))
153 ;;; mixi-atom.el ends here