Fix the last change.
[elisp/mixi.git] / mixi-utils.el
1 ;; mixi-utils.el --- Utilities for mixi object
2
3 ;; Copyright (C) 2007 OHASHI Akira
4
5 ;; Author: OHASHI Akira <bg66@koka-in.org>
6 ;; Keywords: hypermedia
7
8 ;; This file is *NOT* a part of Emacs.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;; Bug reports:
28 ;;
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>.
31
32 ;;; Code:
33
34 (require 'mixi)
35
36 (defvar mixi-reply-to nil)
37
38 (defmacro with-mixi-class (object &rest body)
39   `(let ((class (mixi-object-class ,object)))
40      ,@body))
41 (put 'with-mixi-class 'lisp-indent-function 'defun)
42 (put 'with-mixi-class 'edebug-form-spec '(body))
43
44 (defun mixi-make-title (object &optional add-parent)
45   (with-mixi-class object
46     (cond ((eq class 'mixi-comment)
47            (concat "Re: " (mixi-make-title
48                            (mixi-comment-parent object) add-parent)))
49           ((eq class 'mixi-log)
50            (mixi-friend-nick (mixi-log-friend object)))
51           (t
52            (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
53                  (subject (mixi-object-title object))
54                  (suffix (when add-parent
55                            (concat " ("
56                                    (if (eq class 'mixi-diary)
57                                        (mixi-friend-nick
58                                         (mixi-diary-owner object))
59                                      (mixi-community-name
60                                       (mixi-bbs-community object)))
61                                    ")"))))
62              (concat prefix subject suffix))))))
63
64 (defun mixi-make-author (object)
65   (with-mixi-class object
66     (if (eq class 'mixi-news)
67         (mixi-news-media object)
68       (let ((owner (if (eq class 'mixi-log)
69                        (mixi-log-friend object)
70                      (mixi-object-owner object))))
71         (mixi-friend-nick owner)))))
72
73 (defun mixi-make-date (object)
74   (let* ((time (mixi-object-time object))
75          (cts (current-time-string time))
76          (day-of-week (substring cts 0 3))
77          (month (substring cts 4 7)))
78     (concat day-of-week ", "
79             (format-time-string "%d" time) " "
80             month " "
81             (format-time-string "%Y %H:%M:%S %z" time))))
82
83 (defun mixi-make-message-id (object)
84   (with-mixi-class object
85     (concat
86      (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "."
87      (cond ((eq class 'mixi-comment)
88             (concat (mixi-friend-id (mixi-comment-owner object)) "@"
89                     (mixi-object-id (mixi-comment-parent object)) "."
90                     (mixi-friend-id (mixi-object-owner
91                                      (mixi-comment-parent object))) "."))
92            ((eq class 'mixi-log)
93             (concat (mixi-friend-id (mixi-log-friend object)) "@"))
94            (t
95             (concat (mixi-object-id object) "@"
96                     (if (eq class 'mixi-news)
97                         (mixi-news-media-id object)
98                       (mixi-object-id (mixi-object-owner object))) ".")))
99      (mixi-object-name object) ".mixi.jp>")))
100
101 (defun mixi-make-url (object)
102   (with-mixi-class object
103     (cond ((eq class 'mixi-diary)
104            (mixi-expand-url (mixi-diary-page object)))
105           ((eq class 'mixi-topic)
106            (mixi-expand-url (mixi-topic-page object)))
107           ((eq class 'mixi-event)
108            (mixi-expand-url (mixi-event-page object)))
109           ((eq class 'mixi-comment)
110            (concat (mixi-make-url (mixi-comment-parent object))
111                    "#comment"))
112           ((eq class 'mixi-message)
113            (mixi-expand-url (mixi-message-page object)))
114           ((eq class 'mixi-news)
115            (mixi-news-page object))
116           ((eq class 'mixi-log)
117            (mixi-expand-url (mixi-friend-page (mixi-log-friend object))))
118           ((eq class 'mixi-friend)
119            (mixi-expand-url (mixi-friend-page object))))))
120
121 (defun mixi-make-content (object)
122   (with-mixi-class object
123     (cond ((eq class 'mixi-event)
124            (let ((limit (mixi-event-limit object)))
125              (setq limit (if limit
126                              (format-time-string "%Yǯ%m·î%dÆü" limit)
127                            "»ØÄê¤Ê¤·"))
128              (concat "<dl>"
129                      "<dt>³«ºÅÆü»þ¡§</dt>"
130                      "<dd>" (mixi-event-date object) "</dd>\n"
131                      "<dt>³«ºÅ¾ì½ê¡§</dt>"
132                      "<dd>" (mixi-event-place object) "</dd>\n"
133                      "<dt>¾ÜºÙ¡§</dt>"
134                      "<dd>" (mixi-event-detail object) "</dd>\n"
135                      "<dt>Ê罸´ü¸Â¡§</dt>"
136                      "<dd>" limit "</dd>\n"
137                      "<dt>»²²Ã¼Ô¡§</dt>"
138                      "<dd>" (mixi-event-members object) "</dd>\n"
139                      "</dl>")))
140           ((eq class 'mixi-friend)
141            (if (mixi-object-realized-p object)
142                (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
143                      (age (number-to-string (mixi-friend-age object)))
144                      (birthday
145                       (concat (mapconcat (lambda (number)
146                                            (number-to-string number))
147                                          (mixi-friend-birthday object) "·î")
148                               "Æü"))
149                      (blood-type (symbol-name
150                                   (mixi-friend-blood-type object)))
151                      (hobby (mapconcat 'identity
152                                        (mixi-friend-hobby object) ", ")))
153                  (concat "<dl>"
154                          "<dt>̾Á°¡§</dt>"
155                          "<dd>" (mixi-friend-name object) "</dd>\n"
156                          "<dt>À­ÊÌ¡§</dt>"
157                          "<dd>" sex "À­</dd>\n"
158                          "<dt>¸½½»½ê¡§</dt>"
159                          "<dd>" (mixi-friend-address object) "</dd>\n"
160                          "<dt>ǯÎð¡§</dt>"
161                          "<dd>" age "ºÐ</dd>\n"
162                          "<dt>ÃÂÀ¸Æü¡§</dt>"
163                          "<dd>" birthday "</dd>\n"
164                          "<dt>·ì±Õ·¿¡§</dt>"
165                          "<dd>" blood-type "·¿</dd>\n"
166                          "<dt>½Ð¿ÈÃÏ¡§</dt>"
167                          "<dd>" (mixi-friend-birthplace object) "</dd>\n"
168                          "<dt>¼ñÌ£¡§</dt>"
169                          "<dd>" hobby "</dd>\n"
170                          "<dt>¿¦¶È¡§</dt>"
171                          "<dd>" (mixi-friend-job object) "</dd>\n"
172                          "<dt>½ê°¡§</dt>"
173                          "<dd>" (mixi-friend-organization object) "</dd>\n"
174                          "<dt>¼«¸Ê¾Ò²ð¡§</dt>"
175                          "<dd>" (mixi-friend-profile object) "</dd>\n"
176                          "</dl>"))
177              (concat "<a href=\"" (mixi-make-url object)
178                      "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
179           (t (mixi-object-content object)))))
180
181 (defun mixi-make-reply-to (object)
182   (setq mixi-reply-to "mixi;")
183   (with-mixi-class object
184     (setq mixi-reply-to
185           (concat
186            (cond ((eq class 'mixi-diary)
187                   (concat mixi-reply-to "comment;diary;"
188                           (mixi-friend-id (mixi-diary-owner object)) ";"
189                           (mixi-diary-id object)))
190                  ((mixi-bbs-p object)
191                   (concat mixi-reply-to "comment;"
192                           (mixi-object-name object) ";"
193                           (mixi-community-id (mixi-bbs-community object)) ";"
194                           (mixi-bbs-id object)))
195                  ((eq class 'mixi-community)
196                   (concat mixi-reply-to "topic;"
197                           (mixi-community-id object)))
198                  ((or (eq class 'mixi-news) (eq object (mixi-make-me)))
199                   (concat mixi-reply-to "diary"))
200                  ((eq class 'mixi-message)
201                   (concat mixi-reply-to "message;"
202                           (mixi-friend-id (mixi-message-owner object))))
203                  ((or (eq class 'mixi-friend) (eq class 'mixi-log))
204                   (concat mixi-reply-to "message;"
205                           (mixi-friend-id object))))))))
206
207 (provide 'mixi-utils)
208
209 ;;; mixi-utils.el ends here