1 ;; mixi-utils.el --- Utilities for mixi object -*- coding: euc-jp -*-
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>.
36 (defvar mixi-reply-to nil)
38 (defmacro with-mixi-class (object &rest body)
39 `(let ((class (mixi-object-class ,object)))
41 (put 'with-mixi-class 'lisp-indent-function 'defun)
42 (put 'with-mixi-class 'edebug-form-spec '(body))
44 (defun mixi-make-objects (url-or-function &optional range)
45 (if (stringp url-or-function)
46 (let ((object (mixi-make-object-from-url url-or-function)))
47 (with-mixi-class object
48 (cond ((eq class 'mixi-friend)
49 (mixi-get-diaries object range))
50 ((eq class 'mixi-community)
51 (mixi-get-bbses object range))
52 ((mixi-parent-p object)
53 (mixi-get-comments object range))
54 (t (error (concat (symbol-name class)
55 " is not supported yet."))))))
56 (funcall url-or-function range)))
58 (defun mixi-make-title (object &optional add-parent)
59 (with-mixi-class object
60 (cond ((eq class 'mixi-comment)
61 (concat "Re: " (mixi-make-title
62 (mixi-comment-parent object) add-parent)))
64 (mixi-friend-nick (mixi-log-friend object)))
66 (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
67 (subject (mixi-object-title object))
68 (suffix (when add-parent
70 (cond ((eq class 'mixi-diary)
72 (mixi-diary-owner object)))
73 ((eq class 'mixi-news)
74 (mixi-news-media object))
77 (mixi-bbs-community object))))
79 (concat prefix subject suffix))))))
81 (defun mixi-make-author (object)
82 (with-mixi-class object
83 (if (eq class 'mixi-news)
84 (mixi-news-media object)
85 (let ((owner (if (eq class 'mixi-log)
86 (mixi-log-friend object)
87 (mixi-object-owner object))))
88 (mixi-friend-nick owner)))))
90 (defun mixi-make-date (object)
91 (let* ((time (mixi-object-time object))
92 (cts (current-time-string time))
93 (day-of-week (substring cts 0 3))
94 (month (substring cts 4 7)))
95 (concat day-of-week ", "
96 (format-time-string "%d" time) " "
98 (format-time-string "%Y %H:%M:%S %z" time))))
100 (defun mixi-make-id-1 (object)
101 (with-mixi-class object
103 (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
104 (cond ((eq class 'mixi-comment)
105 (concat (mixi-friend-id (mixi-comment-owner object)) "@"
106 (mixi-object-id (mixi-comment-parent object)) "."
107 (mixi-friend-id (mixi-object-owner
108 (mixi-comment-parent object))) "."))
109 ((eq class 'mixi-log)
110 (concat (mixi-friend-id (mixi-log-friend object)) "@"))
112 (concat (mixi-object-id object) "@"
113 (if (eq class 'mixi-news)
114 (mixi-news-media-id object)
115 (mixi-object-id (mixi-object-owner object))) ".")))
116 (mixi-object-name object))))
118 (defun mixi-make-message-id (object)
119 (format "<%s.mixi.jp>" (mixi-make-id-1 object)))
121 (defun mixi-make-tag-uri (object)
122 (format "tag:mixi.jp,%s:%s"
123 (format-time-string "%Y-%m-%d" (mixi-object-time object))
124 (mixi-make-id-1 object)))
126 (defun mixi-make-url (object)
127 (with-mixi-class object
128 (cond ((eq class 'mixi-diary)
129 (mixi-expand-url (mixi-diary-page object)))
130 ((eq class 'mixi-topic)
131 (mixi-expand-url (mixi-topic-page object)))
132 ((eq class 'mixi-event)
133 (mixi-expand-url (mixi-event-page object)))
134 ((eq class 'mixi-comment)
135 (concat (mixi-make-url (mixi-comment-parent object))
137 ((eq class 'mixi-message)
138 (mixi-expand-url (mixi-message-page object)))
139 ((eq class 'mixi-news)
140 (mixi-news-page object))
141 ((eq class 'mixi-log)
142 (mixi-expand-url (mixi-friend-page (mixi-log-friend object))))
143 ((eq class 'mixi-friend)
144 (mixi-expand-url (mixi-friend-page object))))))
146 (defun mixi-make-encoded-url (object)
147 (mixi-url-encode-string (mixi-make-url object)))
149 (defun mixi-make-content (object)
150 (with-mixi-class object
151 (cond ((eq class 'mixi-event)
152 (let ((limit (mixi-event-limit object)))
153 (setq limit (if limit
154 (format-time-string "%Yǯ%m·î%dÆü" limit)
157 "<dt>³«ºÅÆü»þ¡§</dt>"
158 "<dd>" (mixi-event-date object) "</dd>\n"
159 "<dt>³«ºÅ¾ì½ê¡§</dt>"
160 "<dd>" (mixi-event-place object) "</dd>\n"
162 "<dd>" (mixi-event-detail object) "</dd>\n"
163 "<dt>Ê罸´ü¸Â¡§</dt>"
164 "<dd>" limit "</dd>\n"
166 "<dd>" (mixi-event-members object) "</dd>\n"
168 ((eq class 'mixi-friend)
169 (if (mixi-object-realized-p object)
170 (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
171 (age (if (numberp (mixi-friend-age object))
172 (number-to-string (mixi-friend-age object))
174 (birthday (if (mixi-friend-birthday object)
176 (mapconcat (lambda (number)
177 (number-to-string number))
178 (mixi-friend-birthday object)
181 (blood-type (if (mixi-friend-blood-type object)
183 (mixi-friend-blood-type object))
185 (hobby (mapconcat 'identity
186 (mixi-friend-hobby object) ", ")))
189 "<dd>" (mixi-friend-name object) "</dd>\n"
191 "<dd>" sex "À</dd>\n"
193 "<dd>" (mixi-friend-address object) "</dd>\n"
195 "<dd>" age "ºÐ</dd>\n"
197 "<dd>" birthday "</dd>\n"
199 "<dd>" blood-type "·¿</dd>\n"
201 "<dd>" (mixi-friend-birthplace object) "</dd>\n"
203 "<dd>" hobby "</dd>\n"
205 "<dd>" (mixi-friend-job object) "</dd>\n"
207 "<dd>" (mixi-friend-organization object) "</dd>\n"
208 "<dt>¼«¸Ê¾Ò²ð¡§</dt>"
209 "<dd>" (mixi-friend-profile object) "</dd>\n"
211 (concat "<a href=\"" (mixi-make-url object)
212 "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
213 ((eq class 'mixi-log)
214 (mixi-make-content (mixi-log-friend object)))
215 (t (mixi-object-content object)))))
217 (defun mixi-make-reply-to (object)
218 (setq mixi-reply-to "mixi;")
219 (with-mixi-class object
222 (cond ((eq class 'mixi-diary)
223 (concat mixi-reply-to "comment;diary;"
224 (mixi-friend-id (mixi-diary-owner object)) ";"
225 (mixi-diary-id object)))
227 (concat mixi-reply-to "comment;"
228 (mixi-object-name object) ";"
229 (mixi-community-id (mixi-bbs-community object)) ";"
230 (mixi-bbs-id object)))
231 ((eq class 'mixi-community)
232 (concat mixi-reply-to "topic;"
233 (mixi-community-id object)))
234 ((or (eq class 'mixi-news) (eq object (mixi-make-me)))
235 (concat mixi-reply-to "diary"))
236 ((eq class 'mixi-message)
237 (concat mixi-reply-to "message;"
238 (mixi-friend-id (mixi-message-owner object))))
239 ((or (eq class 'mixi-friend) (eq class 'mixi-log))
240 (concat mixi-reply-to "message;"
241 (mixi-friend-id object))))))))
243 (defconst mixi-to-regexp
244 "^mixi;\\([a-z]+\\);?\\([a-z0-9]+\\)?;?\\([0-9]+\\)?;?\\([0-9]+\\)?")
246 (defun mixi-send-mail (to title content)
247 (when (string-match mixi-to-regexp to)
248 (let ((method (match-string 1 to)))
249 (cond ((string= method "comment")
250 (let ((parent (match-string 2 to))
251 (owner-id (match-string 3 to))
252 (id (match-string 4 to)))
253 (if (string= parent "diary")
255 (mixi-make-diary (mixi-make-friend owner-id) id) content)
257 (concat mixi-object-prefix "make-" parent))))
259 (funcall func (mixi-make-community owner-id) id)
261 ((string= method "topic")
262 (mixi-post-topic (mixi-make-community (match-string 2 to))
264 ((string= method "diary")
265 (mixi-post-diary title content))
266 ((string= method "message")
267 (mixi-post-message (mixi-make-friend (match-string 2 to))
270 (provide 'mixi-utils)
272 ;;; mixi-utils.el ends here