From 1cb706d7fc9dfca40b5c795178cf25a201b0153e Mon Sep 17 00:00:00 2001 From: bg66 Date: Fri, 23 Feb 2007 07:38:54 +0000 Subject: [PATCH] * 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. --- ChangeLog | 19 +++++++ Makefile.am | 2 +- configure.ac | 2 +- mixi-atom.el | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mixi-utils.el | 33 +++++++++++-- mixi.el | 15 ++++-- sb-mixi.el | 20 ++------ 7 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 mixi-atom.el diff --git a/ChangeLog b/ChangeLog index 8957192..342bba6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2007-02-23 OHASHI Akira + + * 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 * mixi-utils.el: New file. diff --git a/Makefile.am b/Makefile.am index b9f10a4..ab5d91a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -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 diff --git a/configure.ac b/configure.ac index bcc8308..61ce495 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ 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 diff --git a/mixi-atom.el b/mixi-atom.el new file mode 100644 index 0000000..add935b --- /dev/null +++ b/mixi-atom.el @@ -0,0 +1,153 @@ +;; mixi-atom.el --- Atom Syndication Format + +;; Copyright (C) 2007 OHASHI Akira + +;; Author: OHASHI Akira +;; 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 . + +;;; 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 "\n" + " " (mixi-make-title object) "\n" + " \n" + " " (mixi-make-tag-uri object) "\n" + " " (mixi-atom-make-date (mixi-object-time object)) + "\n" + " " (mixi-remove-markup (mixi-make-content object)) + "\n" + "\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 "\n" + "\n" + "\n" + "" mixi-atom-title "\n" + "\n" + "" (mixi-atom-now) "\n" + "\n" + " " (mixi-friend-nick (mixi-make-me)) "\n" + "\n" + "tag:mixi.jp," (format-time-string "%Y-%m-%d" + (current-time)) + ":" (mixi-friend-nick (mixi-make-me)) "\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" + "\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 diff --git a/mixi-utils.el b/mixi-utils.el index e65c6d9..58f76d7 100644 --- a/mixi-utils.el +++ b/mixi-utils.el @@ -41,6 +41,20 @@ (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) @@ -80,10 +94,10 @@ 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)) "." @@ -96,7 +110,15 @@ (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 @@ -118,6 +140,9 @@ ((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) @@ -176,6 +201,8 @@ "")) (concat "¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë"))) + ((eq class 'mixi-log) + (mixi-make-content (mixi-log-friend object))) (t (mixi-object-content object))))) (defun mixi-make-reply-to (object) diff --git a/mixi.el b/mixi.el index 2f3e31a..c4e5c81 100644 --- a/mixi.el +++ b/mixi.el @@ -509,24 +509,31 @@ Increase this value when unexpected error frequently occurs." (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-") diff --git a/sb-mixi.el b/sb-mixi.el index 3b6af77..f790d37 100644 --- a/sb-mixi.el +++ b/sb-mixi.el @@ -188,21 +188,11 @@ of mixi object." &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)) -- 1.7.10.4