1 ;; mixi-utils.el --- Utilities for mixi object -*- coding: euc-jp -*-
3 ;; Copyright (C) 2007, 2008 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>.
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 &optional add-comment-count)
82 (with-mixi-class object
83 (cond ((eq class 'mixi-news)
84 (mixi-news-media object))
85 ((and add-comment-count
86 (eq class 'mixi-comment)
87 (mixi-bbs-p (mixi-comment-parent object)))
88 (concat (mixi-comment-count object) " "
89 (mixi-friend-nick (mixi-comment-owner object))))
90 ((eq class 'mixi-release)
93 (let ((owner (if (eq class 'mixi-log)
94 (mixi-log-friend object)
95 (mixi-object-owner object))))
96 (mixi-friend-nick owner))))))
98 (defun mixi-make-date (object)
99 (let* ((time (mixi-object-time object))
100 (cts (current-time-string time))
101 (day-of-week (substring cts 0 3))
102 (month (substring cts 4 7)))
103 (concat day-of-week ", "
104 (format-time-string "%d" time) " "
106 (format-time-string "%Y %H:%M:%S %z" time))))
108 (defun mixi-make-id-1 (object)
109 (with-mixi-class object
111 (format-time-string "%Y%m%d%H%M" (mixi-object-time object)) "."
112 (cond ((eq class 'mixi-comment)
113 (concat (mixi-friend-id (mixi-comment-owner object)) "@"
114 (mixi-object-id (mixi-comment-parent object)) "."
115 (mixi-friend-id (mixi-object-owner
116 (mixi-comment-parent object))) "."))
117 ((eq class 'mixi-log)
118 (concat (mixi-friend-id (mixi-log-friend object)) "@"))
119 ((eq class 'mixi-release)
120 (concat (md5 (mixi-release-title object)) "@"))
122 (concat (mixi-object-id object) "@"
123 (if (eq class 'mixi-news)
124 (mixi-news-media-id object)
125 (mixi-object-id (mixi-object-owner object))) ".")))
126 (mixi-object-name object))))
128 (defun mixi-make-message-id (object)
129 (format "<%s.mixi.jp>" (mixi-make-id-1 object)))
131 (defun mixi-make-tag-uri (object)
132 (format "tag:mixi.jp,%s:%s"
133 (format-time-string "%Y-%m-%d" (mixi-object-time object))
134 (mixi-make-id-1 object)))
136 (defun mixi-make-url (object)
137 (with-mixi-class object
138 (cond ((eq class 'mixi-diary)
139 (mixi-expand-url (mixi-diary-page object)))
140 ((eq class 'mixi-topic)
141 (mixi-expand-url (mixi-topic-page object)))
142 ((eq class 'mixi-event)
143 (mixi-expand-url (mixi-event-page object)))
144 ((eq class 'mixi-comment)
145 (concat (mixi-make-url (mixi-comment-parent object))
147 ((eq class 'mixi-message)
148 (mixi-expand-url (mixi-message-page object)))
149 ((eq class 'mixi-news)
150 (mixi-news-page object))
151 ((eq class 'mixi-release)
152 (let ((url (mixi-release-list-page)))
153 (mixi-expand-url (substring url 0
154 (string-match "?" url)))))
155 ((eq class 'mixi-log)
156 (mixi-expand-url (mixi-friend-page (mixi-log-friend object))))
157 ((eq class 'mixi-friend)
158 (mixi-expand-url (mixi-friend-page object))))))
160 (defun mixi-make-encoded-url (object)
161 (mixi-url-encode-string (mixi-make-url object)))
163 (defun mixi-make-content (object)
164 (with-mixi-class object
165 (cond ((eq class 'mixi-event)
167 "<dt>³«ºÅÆü»þ¡§</dt>"
168 "<dd>" (mixi-event-date object) "</dd>\n"
169 "<dt>³«ºÅ¾ì½ê¡§</dt>"
170 "<dd>" (mixi-event-place object) "</dd>\n"
172 "<dd>" (mixi-event-detail object) "</dd>\n"
173 "<dt>Ê罸´ü¸Â¡§</dt>"
174 "<dd>" (mixi-event-limit object) "</dd>\n"
176 "<dd>" (mixi-event-members object) "</dd>\n"
178 ((eq class 'mixi-friend)
179 (if (mixi-object-realized-p object)
180 (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
181 (age (if (numberp (mixi-friend-age object))
182 (number-to-string (mixi-friend-age object))
184 (birthday (if (mixi-friend-birthday object)
186 (mapconcat (lambda (number)
187 (number-to-string number))
188 (mixi-friend-birthday object)
191 (blood-type (if (mixi-friend-blood-type object)
193 (mixi-friend-blood-type object))
195 (hobby (mapconcat 'identity
196 (mixi-friend-hobby object) ", ")))
199 "<dd>" (mixi-friend-name object) "</dd>\n"
201 "<dd>" sex "À</dd>\n"
203 "<dd>" (mixi-friend-address object) "</dd>\n"
205 "<dd>" age "ºÐ</dd>\n"
207 "<dd>" birthday "</dd>\n"
209 "<dd>" blood-type "·¿</dd>\n"
211 "<dd>" (mixi-friend-birthplace object) "</dd>\n"
213 "<dd>" hobby "</dd>\n"
215 "<dd>" (mixi-friend-job object) "</dd>\n"
217 "<dd>" (mixi-friend-organization object) "</dd>\n"
218 "<dt>¼«¸Ê¾Ò²ð¡§</dt>"
219 "<dd>" (mixi-friend-profile object) "</dd>\n"
221 (concat "<a href=\"" (mixi-make-url object)
222 "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
223 ((eq class 'mixi-log)
224 (mixi-make-content (mixi-log-friend object)))
225 (t (mixi-object-content object)))))
227 (defun mixi-make-reply-to (object)
228 (setq mixi-reply-to "mixi;")
229 (with-mixi-class object
232 (cond ((eq class 'mixi-diary)
233 (concat mixi-reply-to "comment;diary;"
234 (mixi-friend-id (mixi-diary-owner object)) ";"
235 (mixi-diary-id object)))
237 (concat mixi-reply-to "comment;"
238 (mixi-object-name object) ";"
239 (mixi-community-id (mixi-bbs-community object)) ";"
240 (mixi-bbs-id object)))
241 ((eq class 'mixi-community)
242 (concat mixi-reply-to "topic;"
243 (mixi-community-id object)))
244 ((or (eq class 'mixi-news) (eq object (mixi-make-me)))
245 (concat mixi-reply-to "diary"))
246 ((eq class 'mixi-message)
247 (concat mixi-reply-to "message;"
248 (mixi-friend-id (mixi-message-owner object))))
249 ((or (eq class 'mixi-friend) (eq class 'mixi-log))
250 (concat mixi-reply-to "message;"
251 (mixi-friend-id object)))
253 (concat mixi-reply-to "diary")))))))
255 (defconst mixi-to-regexp
256 "^mixi;\\([a-z]+\\);?\\([a-z0-9]+\\)?;?\\([0-9]+\\)?;?\\([0-9]+\\)?")
258 (defun mixi-send-mail (to title content)
259 (when (string-match mixi-to-regexp to)
260 (let ((method (match-string 1 to)))
261 (cond ((string= method "comment")
262 (let ((parent (match-string 2 to))
263 (owner-id (match-string 3 to))
264 (id (match-string 4 to)))
265 (if (string= parent "diary")
267 (mixi-make-diary (mixi-make-friend owner-id) id) content)
269 (concat mixi-object-prefix "make-" parent))))
271 (funcall func (mixi-make-community owner-id) id)
273 ((string= method "topic")
274 (mixi-post-topic (mixi-make-community (match-string 2 to))
276 ((string= method "diary")
277 (mixi-post-diary title content))
278 ((string= method "message")
279 (mixi-post-message (mixi-make-friend (match-string 2 to))
282 (provide 'mixi-utils)
284 ;;; mixi-utils.el ends here