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 GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; 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-self ""
48 "*URI for retrieving Atom Feed Documents representing this Atom feed."
52 (defcustom mixi-atom-title "Mixi Feed"
57 (defcustom mixi-atom-file "~/atom.xml"
58 "*File name for `mixi-make-atom-file'."
62 (defcustom mixi-atom-syndication-list
63 '((mixi-get-diaries . 10))
64 "*A list of atom syndication definition.
65 Each element looks like (URL . RANGE) or (FUNCTION . RANGE).
66 URL is the URL for mixi access point. If URL is friend's, get his/her diaries
67 as article. If community's, get its BBSes. If diary's or BBS's, get its
69 FUNCTION is the function which has one `range' argument and returns the list
71 RANGE is the range for getting articles. If RANGE is nil, get all articles."
74 (radio (string :tag "URL")
75 (const :tag "New diaries" mixi-get-new-diaries)
76 (const :tag "New comments" mixi-get-new-comments)
77 (const :tag "New BBSes" mixi-get-new-bbses)
78 (const :tag "Messages" mixi-get-messages)
79 (const :tag "Logs" mixi-get-logs)
80 (function :tag "Other function"))
81 (radio (integer :tag "Range")
82 (const :tag "All" nil)))))
84 (defmacro mixi-atom-make-date (time)
85 `(let ((date (format-time-string "%Y-%m-%dT%T%z" ,time)))
86 (if (string-match "[+-][0-9][0-9][0-9][0-9]$" date)
87 (let ((length (length date)))
89 (substring date 0 (- length 2))
90 (substring date (- length 2) length)))
93 (defmacro mixi-atom-now ()
94 `(mixi-atom-make-date (current-time)))
96 (defun mixi-make-atom-entry (object)
99 " <title>" (mixi-make-title object) "</title>\n"
100 " <link href=\"" (mixi-make-encoded-url object) "\"/>\n"
101 " <id>" (mixi-make-tag-uri object) "</id>\n"
102 " <updated>" (mixi-atom-make-date (mixi-object-time object))
104 " <summary>" (mixi-encode-specials-string
105 (mixi-remove-markup (mixi-make-content object)))
109 (defun mixi-make-atom-entries (objects &optional range)
112 (mapcar (lambda (object)
114 (concat entries (mixi-make-atom-entry object)))
115 (when (mixi-parent-p object)
116 (let ((comments (mixi-get-comments object range)))
120 (mixi-make-atom-entry (car comments))))
121 (setq comments (cdr comments))))))
125 (defun mixi-make-atom ()
126 "Make Atom Syndication Format"
127 (concat "<?xml version=\"1.0\" encoding=\""
128 (symbol-name mixi-atom-coding-system) "\"?>\n"
129 "<feed xmlns=\"" mixi-atom-namespace "\">\n"
130 "<link rel=\"self\" href=\"" mixi-atom-self "\"/>\n"
132 "<title>" mixi-atom-title "</title>\n"
133 "<link href=\"" mixi-url "\"/>\n"
134 "<updated>" (mixi-atom-now) "</updated>\n"
136 " <name>" (mixi-friend-nick (mixi-make-me)) "</name>\n"
138 "<id>tag:mixi.jp," (format-time-string "%Y-%m-%d"
140 ":" (mixi-friend-nick (mixi-make-me)) "</id>\n"
143 (mapcar (lambda (list)
144 (let ((url-or-function (car list))
146 (mixi-make-atom-entries
147 (mixi-make-objects url-or-function
149 mixi-atom-syndication-list)
155 (defun mixi-atom-cgi ()
156 (princ (concat "Content-Type: application/atom+xml; charset="
157 (symbol-name mixi-atom-coding-system) "\n"
159 (encode-coding-string (mixi-make-atom)
160 mixi-atom-coding-system))))
163 (defun mixi-atom-file ()
165 (insert (mixi-make-atom))
166 (let ((coding-system-for-write mixi-atom-coding-system)
167 (file (expand-file-name mixi-atom-file)))
168 (write-region (point-min) (point-max) file))))
172 ;;; mixi-atom.el ends here