* Makefile.am (MODULES_MIXI): Add it.
* mixi-utils.el (mixi-make-content): Support mixi-log object.
* mixi.el (mixi-url-encode-string): New function.
(mixi-url-encode-and-quote-percent-string) Use it.
* mixi-utils.el: (mixi-make-encoded-url): New function.
(mixi-make-objects): Ditto.
* mixi-utils.el: (mixi-make-id-1): New function.
(mixi-make-message-id): Use it.
(mixi-make-tag-uri): New function.
* sb-mixi.el (shimbun-get-headers): Use it.
* configure.ac: Change PACKAGE to mixi-el.
+2007-02-23 OHASHI Akira <bg66@koka-in.org>
+
+ * mixi-atom.el: New file.
+ * Makefile.am (MODULES_MIXI): Add it.
+
+ * mixi-utils.el (mixi-make-content): Support mixi-log object.
+
+ * mixi.el (mixi-url-encode-string): New function.
+ (mixi-url-encode-and-quote-percent-string) Use it.
+ * mixi-utils.el: (mixi-make-encoded-url): New function.
+ (mixi-make-objects): Ditto.
+
+ * mixi-utils.el: (mixi-make-id-1): New function.
+ (mixi-make-message-id): Use it.
+ (mixi-make-tag-uri): New function.
+ * sb-mixi.el (shimbun-get-headers): Use it.
+
+ * configure.ac: Change PACKAGE to mixi-el.
+
2007-02-22 OHASHI Akira <bg66@koka-in.org>
* mixi-utils.el: New file.
-MODULES_MIXI = mixi.el mixi-utils.el
+MODULES_MIXI = mixi.el mixi-utils.el mixi-atom.el
MODULES_ALL = $(MODULES_MIXI) sb-mixi.el mixi-gnus.el mixi-wl.el
EXTRA_DIST = COMPILE ChangeLog $(MODULES_ALL)
CLEANFILES = auto-autoloads.el custom-load.el *.elc
AC_INIT
AC_PREREQ(2.59)
AC_CONFIG_SRCDIR([mixi.el])
-AM_INIT_AUTOMAKE(mixi, 1.0.0)
+AM_INIT_AUTOMAKE(mixi-el, 1.0.0)
AC_CHECK_EMACS
AC_PATH_LISPDIR
--- /dev/null
+;; mixi-atom.el --- Atom Syndication Format
+
+;; Copyright (C) 2007 OHASHI Akira
+
+;; Author: OHASHI Akira <bg66@koka-in.org>
+;; Keywords: hypermedia
+
+;; This file is *NOT* a part of Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, you can either send email to this
+;; program's maintainer or write to: The Free Software Foundation,
+;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; Bug reports:
+;;
+;; If you have bug reports and/or suggestions for improvement, please
+;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
+
+;;; Code:
+
+(require 'mixi)
+(require 'mixi-utils)
+
+(defcustom mixi-atom-coding-system 'utf-8
+ "*Coding system for Atom Syndication Format."
+ :type 'coding-system
+ :group 'mixi)
+
+(defcustom mixi-atom-namespace "http://www.w3.org/2005/Atom"
+ "*Namespace for Atom Syndication Format."
+ :type 'string
+ :group 'mixi)
+
+(defcustom mixi-atom-title "Mixi Feed"
+ "*Title for feed."
+ :type 'string
+ :group 'mixi)
+
+(defcustom mixi-atom-syndication-list
+ '((mixi-get-diaries . 10))
+ "*A list of atom syndication definition.
+Each element looks like (URL . RANGE) or (FUNCTION . RANGE).
+URL is the URL for mixi access point. If URL is friend's, get his/her diaries
+as article. If community's, get its BBSes. If diary's or BBS's, get its
+comments.
+FUNCTION is the function which has one `range' argument and returns the list
+of mixi object.
+RANGE is the range for getting articles. If RANGE is nil, get all articles."
+ :group 'mixi
+ :type '(repeat (cons
+ (radio (string :tag "URL")
+ (const :tag "New diaries" mixi-get-new-diaries)
+ (const :tag "New comments" mixi-get-new-comments)
+ (const :tag "New BBSes" mixi-get-new-bbses)
+ (const :tag "Messages" mixi-get-messages)
+ (const :tag "Logs" mixi-get-logs)
+ (function :tag "Other function"))
+ (radio (integer :tag "Range")
+ (const :tag "All" nil)))))
+
+(defmacro mixi-atom-make-date (time)
+ `(let ((date (format-time-string "%Y-%m-%dT%T%z" ,time)))
+ (if (string-match "[+-][0-9][0-9][0-9][0-9]$" date)
+ (let ((length (length date)))
+ (format "%s:%s"
+ (substring date 0 (- length 2))
+ (substring date (- length 2) length)))
+ date)))
+
+(defmacro mixi-atom-now ()
+ `(mixi-atom-make-date (current-time)))
+
+(defun mixi-make-atom-entry (object)
+ "Make Atom entry."
+ (concat "<entry>\n"
+ " <title>" (mixi-make-title object) "</title>\n"
+ " <link href=\"" (mixi-make-encoded-url object) "\"/>\n"
+ " <id>" (mixi-make-tag-uri object) "</id>\n"
+ " <updated>" (mixi-atom-make-date (mixi-object-time object))
+ "</updated>\n"
+ " <summary>" (mixi-remove-markup (mixi-make-content object))
+ "</summary>\n"
+ "</entry>\n"))
+
+(defun mixi-make-atom-entries (objects &optional range)
+ "Make Atom entries."
+ (let (entries)
+ (mapcar (lambda (object)
+ (setq entries
+ (concat entries (mixi-make-atom-entry object)))
+ (when (mixi-parent-p object)
+ (let ((comments (mixi-get-comments object range)))
+ (mapc (lambda (comment)
+ (setq entries
+ (concat entries
+ (mixi-make-atom-entry comment))))
+ comments))))
+ objects)
+ entries))
+
+;;;###autoload
+(defun mixi-make-atom ()
+ "Make Atom Syndication Format"
+ (insert "<?xml version=\"1.0\" encoding=\""
+ (symbol-name mixi-atom-coding-system) "\"?>\n"
+ "<feed xmlns=\"" mixi-atom-namespace "\">\n"
+ "\n"
+ "<title>" mixi-atom-title "</title>\n"
+ "<link href=\"" mixi-url "\"/>\n"
+ "<updated>" (mixi-atom-now) "</updated>\n"
+ "<author>\n"
+ " <name>" (mixi-friend-nick (mixi-make-me)) "</name>\n"
+ "</author>\n"
+ "<id>tag:mixi.jp," (format-time-string "%Y-%m-%d"
+ (current-time))
+ ":" (mixi-friend-nick (mixi-make-me)) "</id>\n"
+ "\n"
+ (mapconcat 'identity
+ (mapcar (lambda (list)
+ (let ((url-or-function (car list))
+ (range (cdr list)))
+ (mixi-make-atom-entries
+ (mixi-make-objects url-or-function
+ range) range)))
+ mixi-atom-syndication-list)
+ "\n")
+ "\n"
+ "</feed>\n"))
+
+;;;###autoload
+(defun mixi-atom-write-file (file)
+ (with-temp-buffer
+ (mixi-make-atom)
+ (let ((coding-system-for-write mixi-atom-coding-system)
+ (file (expand-file-name file)))
+ (write-region (point-min) (point-max) file))))
+
+(provide 'mixi-atom)
+
+;;; mixi-atom.el ends here
(put 'with-mixi-class 'lisp-indent-function 'defun)
(put 'with-mixi-class 'edebug-form-spec '(body))
+(defun mixi-make-objects (url-or-function &optional range)
+ (if (stringp url-or-function)
+ (let ((object (mixi-make-object-from-url url-or-function)))
+ (with-mixi-class object
+ (cond ((eq class 'mixi-friend)
+ (mixi-get-diaries object range))
+ ((eq class 'mixi-community)
+ (mixi-get-bbses object range))
+ ((mixi-parent-p object)
+ (mixi-get-comments object range))
+ (t (error (concat (symbol-name class)
+ " is not supported yet."))))))
+ (funcall url-or-function range)))
+
(defun mixi-make-title (object &optional add-parent)
(with-mixi-class object
(cond ((eq class 'mixi-comment)
month " "
(format-time-string "%Y %H:%M:%S %z" time))))
-(defun mixi-make-message-id (object)
+(defun mixi-make-id-1 (object)
(with-mixi-class object
(concat
- (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "."
+ (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
(cond ((eq class 'mixi-comment)
(concat (mixi-friend-id (mixi-comment-owner object)) "@"
(mixi-object-id (mixi-comment-parent object)) "."
(if (eq class 'mixi-news)
(mixi-news-media-id object)
(mixi-object-id (mixi-object-owner object))) ".")))
- (mixi-object-name object) ".mixi.jp>")))
+ (mixi-object-name object))))
+
+(defun mixi-make-message-id (object)
+ (format "<%s.mixi.jp>" (mixi-make-id-1 object)))
+
+(defun mixi-make-tag-uri (object)
+ (format "tag:mixi.jp,%s:%s"
+ (format-time-string "%Y-%m-%d" (mixi-object-time object))
+ (mixi-make-id-1 object)))
(defun mixi-make-url (object)
(with-mixi-class object
((eq class 'mixi-friend)
(mixi-expand-url (mixi-friend-page object))))))
+(defun mixi-make-encoded-url (object)
+ (mixi-url-encode-string (mixi-make-url object)))
+
(defun mixi-make-content (object)
(with-mixi-class object
(cond ((eq class 'mixi-event)
"</dl>"))
(concat "<a href=\"" (mixi-make-url object)
"\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
+ ((eq class 'mixi-log)
+ (mixi-make-content (mixi-log-friend object)))
(t (mixi-object-content object)))))
(defun mixi-make-reply-to (object)
(buffer-string)))
;; stolen (and modified) from w3m.el
-;; FIXME: Hmm.
-(defun mixi-url-encode-and-quote-percent-string (string)
+(defun mixi-url-encode-string (string)
(apply (function concat)
(mapcar
(lambda (char)
(cond
((eq char ?\n) ; newline
- "%%0D%%0A")
+ "%0D%0A")
((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
(char-to-string char)) ; printable
((char-equal char ?\x20) ; space
"+")
(t
- (format "%%%%%02x" char)))) ; escape
+ (format "%%%02x" char)))) ; escape
;; Coerce a string into a list of chars.
(append (encode-coding-string (or string "") mixi-coding-system)
nil))))
+(defun mixi-url-encode-and-quote-percent-string (string)
+ (let ((string (mixi-url-encode-string string))
+ (pos 0))
+ (while (string-match "%" string pos)
+ (setq string (replace-match "%%" nil nil string))
+ (setq pos (+ (match-end 0) 1)))
+ string))
+
;; Object.
(defconst mixi-object-prefix "mixi-")
&optional range)
(let ((url-or-function (cdr (assoc (shimbun-current-group-internal shimbun)
shimbun-mixi-group-alist)))
- (range (when (integerp range) (* range shimbun-mixi-page-articles)))
- objects)
- (if (stringp url-or-function)
- (let* ((object (mixi-make-object-from-url url-or-function))
- (class (mixi-object-class object)))
- (cond ((eq class 'mixi-friend)
- (setq objects (mixi-get-diaries object range)))
- ((eq class 'mixi-community)
- (setq objects (mixi-get-bbses object range)))
- ((mixi-parent-p object)
- (setq objects (mixi-get-comments object range)))
- (t (error (concat (symbol-name class)
- " is not supported yet.")))))
- (setq objects (funcall url-or-function range)))
- (shimbun-sort-headers (shimbun-mixi-get-headers shimbun objects range))))
+ (range (when (integerp range) (* range shimbun-mixi-page-articles))))
+ (shimbun-sort-headers
+ (shimbun-mixi-get-headers shimbun
+ (mixi-make-objects url-or-function range)
+ range))))
(defun shimbun-mixi-comment-article (url shimbun header)
(let* ((message-id (shimbun-header-id header))