1 ;; mixi.el --- API library for accessing to mixi
3 ;; Copyright (C) 2005,2006 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.
27 ;; API for getting contents:
30 ;; * mixi-get-favorites
33 ;; * mixi-get-new-diaries
34 ;; * mixi-search-diaries
35 ;; * mixi-get-communities
36 ;; * mixi-search-communities
38 ;; * mixi-get-new-bbses
39 ;; * mixi-search-bbses
40 ;; * mixi-get-comments
41 ;; * mixi-get-new-comments
42 ;; * mixi-get-messages
43 ;; * mixi-get-introductions
49 ;; * mixi-post-comment
50 ;; * mixi-post-message
54 ;; * mixi-remove-markup
58 ;; Display newest 3 diaries like a mail format.
61 ;; (buffer (get-buffer-create "*temp*"))
62 ;; (format "%Y/%m/%d %H:%M"))
63 ;; (pop-to-buffer buffer)
64 ;; (mapc (lambda (diary)
65 ;; (let ((subject (mixi-diary-title diary))
66 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
67 ;; (date (format-time-string format (mixi-diary-time diary)))
68 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
69 ;; (insert "From: " from "\n"
70 ;; "Subject: " subject "\n"
71 ;; "Date: " date "\n\n"
73 ;; (mixi-get-new-diaries range))
74 ;; (set-buffer-modified-p nil)
75 ;; (setq buffer-read-only t)
76 ;; (goto-char (point-min)))
78 ;; Display newest 3 diaries including newest 3 comments like a mail format.
79 ;; Comments are displayed like a reply mail.
82 ;; (buffer (get-buffer-create "*temp*"))
83 ;; (format "%Y/%m/%d %H:%M"))
84 ;; (pop-to-buffer buffer)
85 ;; (mapc (lambda (diary)
86 ;; (let ((subject (mixi-diary-title diary))
87 ;; (from (mixi-friend-nick (mixi-diary-owner diary)))
88 ;; (date (format-time-string format (mixi-diary-time diary)))
89 ;; (body (mixi-remove-markup (mixi-diary-content diary))))
90 ;; (insert "From: " from "\n"
91 ;; "Subject: " subject "\n"
92 ;; "Date: " date "\n\n"
94 ;; (mapc (lambda (comment)
95 ;; (let ((from (mixi-friend-nick
96 ;; (mixi-comment-owner comment)))
97 ;; (subject (concat "Re: " subject))
98 ;; (date (format-time-string
99 ;; format (mixi-comment-time comment)))
100 ;; (body (mixi-remove-markup
101 ;; (mixi-comment-content comment))))
102 ;; (insert "From: " from "\n"
103 ;; "Subject: " subject "\n"
104 ;; "Date: " date "\n\n"
106 ;; (mixi-get-comments diary range))))
107 ;; (mixi-get-new-diaries range))
108 ;; (set-buffer-modified-p nil)
109 ;; (setq buffer-read-only t)
110 ;; (goto-char (point-min)))
114 ;; If you have bug reports and/or suggestions for improvement, please
115 ;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
119 (eval-when-compile (require 'cl))
122 "API library for accessing to mixi."
125 (defcustom mixi-url "http://mixi.jp"
130 (defcustom mixi-directory (expand-file-name "~/.mixi")
131 "*Where to look for mixi files."
135 (defcustom mixi-coding-system 'euc-jp
136 "*Coding system for mixi."
140 (defcustom mixi-curl-program "curl"
141 "*The program name of `curl'."
145 (defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
147 "*The location of cookie file created by `curl'."
151 (defcustom mixi-backend
152 (or (condition-case nil
160 (if (fboundp 'url-retrieve-synchronously)
163 (if (and (fboundp 'executable-find)
164 (executable-find mixi-curl-program))
166 (error "Cannot set `mixi-backend'."))
167 "*The function for retrieving."
168 :type '(radio (const :tag "Use w3m" w3m)
169 (const :tag "Use url.el" url)
170 (const :tag "Use curl" curl)
171 (symbol :tag "The other backend"))
174 (defcustom mixi-default-email nil
175 "*Default E-mail address that is used to login automatically."
176 :type '(radio (string :tag "E-mail address")
177 (const :tag "Asked when it is necessary" nil))
180 (defcustom mixi-default-password nil
181 "*Default password that is used to login automatically."
182 :type '(radio (string :tag "Password")
183 (const :tag "Asked when it is necessary" nil))
186 (defcustom mixi-accept-adult-contents t
187 "*If non-nil, accept to access to the adult contents."
191 (defcustom mixi-continuously-access-interval 4.0
192 "*Time interval between each mixi access.
193 Increase this value when unexpected error frequently occurs."
197 (defcustom mixi-cache-expires nil
198 "*Seconds for expiration of a cached object."
199 :type '(radio (integer :tag "Expired seconds")
200 (const :tag "Don't expire" nil)
201 (const :tag "Don't cache" t))
204 ;; FIXME: Not implemented.
205 (defcustom mixi-cache-use-file t
206 "*If non-nil, caches are saved to files."
213 (defmacro mixi-message (&rest strings)
214 `(concat "[mixi] " ,@strings))
216 (put 'mixi-realization-error
217 'error-message (mixi-message "Cannot realize object"))
218 (put 'mixi-realization-error
219 'error-conditions '(mixi-realization-error error))
221 (put 'mixi-post-error
222 'error-message (mixi-message "Cannot post"))
223 (put 'mixi-post-error
224 'error-conditions '(mixi-post-error error))
226 (defmacro mixi-realization-error (type object)
227 `(let ((data (if (and (boundp 'buffer) debug-on-error)
228 (list ,type ,object buffer)
229 (list ,type ,object))))
230 (signal 'mixi-realization-error data)))
232 (defmacro mixi-post-error (type &optional object)
233 `(let ((data (when (and (boundp 'buffer) debug-on-error)
236 (setq data (cons ,type (cons ,object data)))
237 (setq data (cons ,type data)))
238 (signal 'mixi-post-error data)))
240 (defconst mixi-message-adult-contents
241 "¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
242 ±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
243 (defconst mixi-message-continuously-accessing
244 "°ÂÄꤷ¤Æ¥µ¥¤¥È¤Î±¿±Ä¤ò¤ª¤³¤Ê¤¦°Ù¡¢´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹<br>
245 ¿·¤ÏÀ©¸Â¤µ¤»¤Æ¤¤¤¿¤À¤¤¤Æ¤ª¤ê¤Þ¤¹¡£¤´ÌÂÏǤò¤ª¤«¤±¤¤¤¿¤·¤Þ¤¹¤¬¡¢¤·¤Ð¤é¤¯¤ª<br>
246 ÂÔ¤Á¤¤¤¿¤À¤¤¤Æ¤«¤éÁàºî¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£")
247 (defconst mixi-warning-continuously-accessing
248 "´Ö³Ö¤ò¶õ¤±¤Ê¤¤Ï¢Â³Åª¤Ê¥Ú¡¼¥¸¤ÎÁ«°Ü¡¦¹¹¿·¤òÉÑÈˤˤª¤³¤Ê¤ï¤ì¤Æ¤¤¤ë¤³¤È¤¬¸«<br>
249 ¼õ¤±¤é¤ì¤Þ¤·¤¿¤Î¤Ç¡¢°ì»þŪ¤ËÁàºî¤òÄä»ß¤µ¤»¤Æ¤¤¤¿¤À¤¤Þ¤¹¡£¿½¤·Ìõ¤´¤¶¤¤¤Þ<br>
250 ¤»¤ó¤¬¡¢¤·¤Ð¤é¤¯¤Î´Ö¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£")
252 (defmacro mixi-retrieve (url &optional post-data)
253 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-retrieve"))
256 (defmacro mixi-post-form (url fields)
257 `(funcall (intern (concat "mixi-" (symbol-name mixi-backend) "-post-form"))
260 (defun mixi-parse-buffer (url buffer &optional post-data)
261 (when (string-match mixi-message-adult-contents buffer)
262 (if mixi-accept-adult-contents
263 (setq buffer (mixi-retrieve url "submit=agree"))
264 (setq buffer (mixi-retrieve (concat url "?")))))
265 (when (string-match mixi-warning-continuously-accessing buffer)
266 (error (mixi-message "Access denied. Please wait a while and increase "
267 "the value of `mixi-continuously-access-interval'.")))
268 (if (not (string-match mixi-message-continuously-accessing buffer))
270 (message (mixi-message "Waiting for continuously accessing..."))
271 (sleep-for mixi-continuously-access-interval)
272 (mixi-retrieve url post-data)))
274 (defmacro mixi-expand-url (url)
275 `(if (string-match (concat "^" mixi-url) ,url)
277 (concat mixi-url ,url)))
279 ;; FIXME: Support file, checkbox and so on.
280 (defun mixi-make-form-data (fields)
281 "Make form data and return (CONTENT-TYPE . FORM-DATA)."
282 (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
283 (content-type (concat "multipart/form-data; boundary=" boundary))
287 (concat "--" boundary "\r\n"
288 "Content-Disposition: form-data; name=\""
291 (encode-coding-string (cdr field) mixi-coding-system)))
293 (cons content-type (concat form-data "\r\n--" boundary "--"))))
295 (defun mixi-url-retrieve (url &optional post-data extra-headers)
296 "Retrieve the URL and return gotten strings."
297 (let* ((url-request-method (if post-data "POST" "GET"))
298 (url-request-data post-data)
299 (url-request-extra-headers extra-headers)
300 (url (mixi-expand-url url))
301 (buffer (url-retrieve-synchronously url))
303 (unless (bufferp buffer)
304 (error (mixi-message "Cannot retrieve")))
305 (with-current-buffer buffer
306 (goto-char (point-min))
307 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
308 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
309 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
310 (error (mixi-message "Cannot retrieve")))
311 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
312 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
314 (mixi-parse-buffer url ret post-data))))
316 (defun mixi-url-post-form (url fields)
317 (let* ((form-data (mixi-make-form-data fields))
318 (extra-headers `(("Content-Type" . ,(car form-data)))))
319 (mixi-url-retrieve url (cdr form-data) extra-headers)))
321 (defun mixi-w3m-retrieve (url &optional post-data)
322 "Retrieve the URL and return gotten strings."
323 (let ((url (mixi-expand-url url)))
325 (if (not (string= (w3m-retrieve url nil nil post-data) "text/html"))
326 (error (mixi-message "Cannot retrieve"))
327 (w3m-decode-buffer url)
328 (let ((ret (buffer-substring-no-properties (point-min) (point-max))))
329 (mixi-parse-buffer url ret post-data))))))
331 (defun mixi-w3m-post-form (url fields)
332 (let ((form-data (mixi-make-form-data fields)))
333 (mixi-w3m-retrieve url form-data)))
335 (defun mixi-curl-retrieve (url &optional post-data)
336 "Retrieve the URL and return gotten strings."
338 (if (fboundp 'set-buffer-multibyte)
339 (set-buffer-multibyte nil))
340 (let ((orig-mode (default-file-modes))
341 (coding-system-for-read 'binary)
342 (coding-system-for-write 'binary)
346 (set-default-file-modes 448)
348 (apply #'start-process "curl" (current-buffer)
350 (append (if post-data '("-d" "@-"))
352 "-b" mixi-curl-cookie-file
353 "-c" mixi-curl-cookie-file
354 (mixi-expand-url url)))))
355 (set-process-sentinel process #'ignore))
356 (set-default-file-modes orig-mode))
358 (process-send-string process (concat post-data "\n"))
359 (process-send-eof process))
360 (while (eq (process-status process) 'run)
361 (accept-process-output process 1))
362 (goto-char (point-min))
363 (while (looking-at "HTTP/[0-9]+\\.[0-9]+ [13][0-9][0-9]")
364 (delete-region (point) (re-search-forward "\r?\n\r?\n")))
365 (unless (looking-at "HTTP/[0-9]+\\.[0-9]+ 200")
366 (error (mixi-message "Cannot retrieve")))
367 (delete-region (point) (re-search-forward "\r?\n\r?\n"))
368 (setq ret (decode-coding-string (buffer-string) mixi-coding-system))
369 (mixi-parse-buffer url ret post-data))))
371 (defconst mixi-my-id-regexp
372 "<a href=\"add_diary\\.pl\\?id=\\([0-9]+\\)")
374 (defun mixi-login (&optional email password)
376 (when (and (eq mixi-backend 'w3m) (not w3m-use-cookies))
377 (error (mixi-message "Require to accept cookies. Please set "
378 "`w3m-use-cookies' to t.")))
379 (let ((email (or email mixi-default-email
380 (read-from-minibuffer (mixi-message "Login Email: "))))
381 (password (or password mixi-default-password
382 (read-passwd (mixi-message "Login Password: ")))))
383 (let ((buffer (mixi-retrieve "/login.pl"
384 (concat "email=" email
385 "&password=" password
388 (unless (string-match "url=/check\\.pl\\?n=" buffer)
389 (error (mixi-message "Cannot login")))
390 (setq buffer (mixi-retrieve "/check.pl?n=home.pl"))
391 (if (string-match mixi-my-id-regexp buffer)
392 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
393 (error (mixi-message "Cannot login"))))))
395 (defun mixi-logout ()
396 (mixi-retrieve "/logout.pl"))
398 (defmacro with-mixi-retrieve (url &rest body)
401 (setq buffer (mixi-retrieve ,url))
402 (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
405 (setq buffer (mixi-retrieve ,url))))
407 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
408 (put 'with-mixi-retrieve 'edebug-form-spec '(form body))
410 (defmacro with-mixi-post-form (url fields &rest body)
413 (setq buffer (mixi-post-form ,url ,fields))
414 (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
417 (setq buffer (mixi-post-form ,url ,fields))))
419 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
420 (put 'with-mixi-post-form 'edebug-form-spec '(form body))
422 (defun mixi-get-matched-items (url regexp &optional range)
423 "Get matched items to REGEXP in URL."
427 (while (or (null range) (< (length ids) range))
428 (with-mixi-retrieve (format url page)
431 (while (and (string-match regexp buffer pos)
432 (or (null range) (< (length ids) range)))
435 (while (match-string num buffer)
436 (setq list (cons (match-string num buffer) list))
438 (when (not (member (reverse list) ids))
440 (setq ids (cons (reverse list) ids)))
441 (setq pos (match-end (1- num)))))
447 ;; stolen (and modified) from shimbun.el
448 (defun mixi-remove-markup (string)
449 "Remove markups from STRING."
451 (insert (or string ""))
453 (goto-char (point-min))
454 (while (search-forward "<!--" nil t)
455 (delete-region (match-beginning 0)
456 (or (search-forward "-->" nil t)
458 (goto-char (point-min))
459 (while (re-search-forward "<[^>]+>" nil t)
460 (replace-match "" t t))
461 (goto-char (point-min))
462 (while (re-search-forward "
\r" nil t)
463 (replace-match "\n" t t)))
464 ;; FIXME: Decode entities.
467 ;; stolen (and modified) from w3m.el
469 (defun mixi-url-encode-and-quote-percent-string (string)
470 (apply (function concat)
474 ((eq char ?\n) ; newline
476 ((string-match "[-a-zA-Z0-9_:/.]" (char-to-string char)) ; xxx?
477 (char-to-string char)) ; printable
478 ((char-equal char ?\x20) ; space
481 (format "%%%%%02x" char)))) ; escape
482 ;; Coerce a string into a list of chars.
483 (append (encode-coding-string (or string "") mixi-coding-system)
487 (defconst mixi-object-prefix "mixi-")
489 (defmacro mixi-object-class (object)
492 (defmacro mixi-object-p (object)
493 `(let ((class (mixi-object-class ,object)))
494 (when (symbolp class)
495 (eq (string-match (concat "^" mixi-object-prefix)
496 (symbol-name class)) 0))))
498 (defun mixi-object-name (object)
499 "Return the name of OBJECT."
500 (unless (mixi-object-p object)
501 (signal 'wrong-type-argument (list 'mixi-object-p object)))
502 (let ((class (mixi-object-class object)))
503 (substring (symbol-name class) (length mixi-object-prefix))))
505 (defun mixi-read-object (exp)
506 "Read one Lisp expression as mixi object."
507 (if (mixi-object-p exp)
508 (let ((func (intern (concat mixi-object-prefix "make-"
509 (mixi-object-name exp))))
510 (args (mapcar (lambda (arg)
511 (mixi-read-object arg))
513 (let ((object (apply func (cdr args))))
515 (mixi-object-set-timestamp object (car args)))
519 (defun mixi-object-timestamp (object)
520 "Return the timestamp of OJBECT."
521 (unless (mixi-object-p object)
522 (signal 'wrong-type-argument (list 'mixi-object-p object)))
523 (aref (cdr object) 0))
524 (defalias 'mixi-object-realized-p 'mixi-object-timestamp)
526 (defun mixi-object-owner (object)
527 "Return the owner of OBJECT."
528 (unless (mixi-object-p object)
529 (signal 'wrong-type-argument (list 'mixi-object-p object)))
530 (let ((func (intern (concat mixi-object-prefix
531 (mixi-object-name object) "-owner"))))
532 (funcall func object)))
534 (defun mixi-object-id (object)
535 "Return the id of OBJECT."
536 (unless (mixi-object-p object)
537 (signal 'wrong-type-argument (list 'mixi-object-p object)))
538 (let ((func (intern (concat mixi-object-prefix
539 (mixi-object-name object) "-id"))))
540 (funcall func object)))
542 (defun mixi-object-time (object)
543 "Return the time of OBJECT."
544 (unless (mixi-object-p object)
545 (signal 'wrong-type-argument (list 'mixi-object-p object)))
546 (let ((func (intern (concat mixi-object-prefix
547 (mixi-object-name object) "-time"))))
548 (funcall func object)))
550 (defun mixi-object-title (object)
551 "Return the title of OBJECT."
552 (unless (mixi-object-p object)
553 (signal 'wrong-type-argument (list 'mixi-object-p object)))
554 (let ((func (intern (concat mixi-object-prefix
555 (mixi-object-name object) "-title"))))
556 (funcall func object)))
558 (defun mixi-object-content (object)
559 "Return the content of OBJECT."
560 (unless (mixi-object-p object)
561 (signal 'wrong-type-argument (list 'mixi-object-p object)))
562 (let ((func (intern (concat mixi-object-prefix
563 (mixi-object-name object) "-content"))))
564 (funcall func object)))
566 (defun mixi-object-set-timestamp (object timestamp)
567 "Set the timestamp of OBJECT."
568 (unless (mixi-object-p object)
569 (signal 'wrong-type-argument (list 'mixi-object-p object)))
570 (aset (cdr object) 0 timestamp))
572 (defmacro mixi-object-touch (object)
573 `(mixi-object-set-timestamp ,object (current-time)))
575 (defconst mixi-object-url-regexp
576 "/\\(show\\|view\\)_\\([a-z]+\\)\\.pl")
578 (defun mixi-make-object-from-url (url)
579 "Return a mixi object from URL."
580 (if (string-match mixi-object-url-regexp url)
581 (let ((name (match-string 2 url)))
582 (when (string= name "bbs")
584 (let ((func (intern (concat mixi-object-prefix "make-" name
587 (when (string-match "/home\\.pl" url)
588 (mixi-make-friend-from-url url))))
591 ;; stolen from time-date.el
592 (defun mixi-time-less-p (t1 t2)
593 "Say whether time value T1 is less than time value T2."
594 (unless (numberp (cdr t1))
595 (setq t1 (cons (car t1) (car (cdr t1)))))
596 (unless (numberp (cdr t2))
597 (setq t2 (cons (car t2) (car (cdr t2)))))
598 (or (< (car t1) (car t2))
599 (and (= (car t1) (car t2))
600 (< (cdr t1) (cdr t2)))))
602 (defun mixi-time-add (t1 t2)
603 "Add two time values. One should represent a time difference."
604 (unless (numberp (cdr t1))
605 (setq t1 (cons (car t1) (car (cdr t1)))))
606 (unless (numberp (cdr t2))
607 (setq t2 (cons (car t2) (car (cdr t2)))))
608 (let ((low (+ (cdr t1) (cdr t2))))
609 (cons (+ (car t1) (car t2) (lsh low -16)) low)))
611 ;; stolen from time-date.el
612 (defun mixi-seconds-to-time (seconds)
613 "Convert SECONDS (a floating point number) to a time value."
614 (cons (floor seconds 65536)
615 (floor (mod seconds 65536))))
617 (defun mixi-cache-expired-p (object)
618 "Whether a cache of OBJECT is expired."
619 (let ((timestamp (mixi-object-timestamp object)))
620 (unless (or (null mixi-cache-expires)
622 (if (numberp mixi-cache-expires)
624 (mixi-time-add timestamp (mixi-seconds-to-time mixi-cache-expires))
628 (defun mixi-make-cache (key value table)
629 "Make a cache object and return it."
630 (let ((cache (gethash key table)))
631 (if (and cache (not (mixi-cache-expired-p cache)))
633 (puthash key value table))))
635 (defconst mixi-cache-file-regexp "[a-z]+-cache$")
636 (defconst mixi-cache-regexp (concat mixi-object-prefix
637 mixi-cache-file-regexp))
639 (defun mixi-save-cache ()
640 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
641 (unless (file-directory-p cache-directory)
642 (make-directory cache-directory t))
643 (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
644 (mapc (lambda (symbol)
645 (with-temp-file (expand-file-name
646 (substring (symbol-name symbol)
647 (length mixi-object-prefix))
649 (let ((coding-system-for-write mixi-coding-system)
650 (cache (symbol-value symbol)))
651 (insert "#s(hash-table size "
652 (number-to-string (hash-table-count cache))
653 " test equal data (\n")
656 (let (print-level print-length)
657 (insert (prin1-to-string key) " "
658 (prin1-to-string value) "\n")))
663 ;; stolen (and modified) from lsdb.el
664 (defun mixi-read-cache (&optional marker)
665 "Read one Lisp expression as text from MARKER, return as Lisp object."
668 (if (looking-at "^#s(")
671 (forward-char 2);skip "#s"
672 (forward-sexp);move to the left paren
675 (buffer-disable-undo)
676 (insert-buffer-substring (marker-buffer marker)
678 (goto-char (point-min))
680 (let ((object (read (current-buffer)))
682 (if (eq 'hash-table (car object))
684 (setq data (plist-get (cdr object) 'data))
686 (pop data);throw it away
687 (mixi-read-object (pop data))))
691 (defun mixi-load-cache ()
692 (let ((cache-directory (expand-file-name "cache" mixi-directory)))
693 (when (file-directory-p cache-directory)
694 ;; FIXME: Load friend and community first.
695 (let ((files (directory-files cache-directory t
696 mixi-cache-file-regexp)))
698 (let ((buffer (find-file-noselect file)))
702 (goto-char (point-min))
703 (re-search-forward "^#s(")
704 (goto-char (match-beginning 0))
705 (mixi-read-cache (point-marker)))
706 (kill-buffer buffer))))
710 (defvar mixi-friend-cache (make-hash-table :test 'equal))
711 (defun mixi-make-friend (id &optional nick name sex address age birthday
712 blood-type birthplace hobby job organization
714 "Return a friend object."
715 (mixi-make-cache id (cons 'mixi-friend (vector nil id nick name sex address
716 age birthday blood-type
718 organization profile))
721 (defun mixi-make-me ()
722 "Return a my object."
724 (with-mixi-retrieve "/home.pl"
725 (if (string-match mixi-my-id-regexp buffer)
726 (setq mixi-me (mixi-make-friend (match-string 1 buffer)))
727 (signal 'error (list 'who-am-i)))))
730 (defconst mixi-friend-url-regexp
731 "/show_friend\\.pl\\?id=\\([0-9]+\\)")
733 (defun mixi-make-friend-from-url (url)
734 "Return a friend object from URL."
735 (if (string-match mixi-friend-url-regexp url)
736 (let ((id (match-string 1 url)))
737 (mixi-make-friend id))
738 (when (string-match "/home\\.pl" url)
741 (defmacro mixi-friend-p (friend)
742 `(eq (mixi-object-class ,friend) 'mixi-friend))
744 (defmacro mixi-friend-page (friend)
745 `(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
747 (defconst mixi-friend-nick-regexp
748 "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>
\r?
749 \\(.*\\)¤µ¤ó([0-9]+)")
750 (defconst mixi-friend-name-regexp
751 "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\( \\| \\)Á°</font></td>
753 ?<td WIDTH=345>\\(.+?\\)\\(</td>\\|<img\\)")
754 (defconst mixi-friend-sex-regexp
755 "<td BGCOLOR=#F2DDB7\\( WIDTH=80 NOWRAP\\)?><font COLOR=#996600>À\\( \\| \\)ÊÌ</font></td>
757 ?<td WIDTH=345>\\([Ã˽÷]\\)À\\(</td>\\|<img\\)")
758 (defconst mixi-friend-address-regexp
759 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¸½½»½ê</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
760 (defconst mixi-friend-age-regexp
761 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ǯ\\( \\| \\)Îð</font></td>\n<td>\\([0-9]+\\)ºÐ\\(\n.+\n\\)?</td></tr>")
762 (defconst mixi-friend-birthday-regexp
763 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>ÃÂÀ¸Æü</font></td>\n<td>\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(\n.+\n\\)?</td></tr>")
764 (defconst mixi-friend-blood-type-regexp
765 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>·ì±Õ·¿</font></td>\n<td>\\([ABO]B?\\)·¿\\(\n\n\\)?</td></tr>")
766 (defconst mixi-friend-birthplace-regexp
767 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
768 (defconst mixi-friend-hobby-regexp
769 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+?\\)\\(</td>\\|<img\\)")
770 (defconst mixi-friend-job-regexp
771 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¿¦\\( \\| \\)¶È</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
772 (defconst mixi-friend-organization-regexp
773 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>½ê\\( \\| \\)°</font></td>\n<td[^>]*>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
774 (defconst mixi-friend-profile-regexp
775 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼«¸Ê¾Ò²ð</font></td>\n<td CLASS=h120>\\(.+\\)</td></tr>")
777 (defun mixi-realize-friend (friend)
779 ;; FIXME: Check a expiration of cache?
780 (unless (mixi-object-realized-p friend)
782 (with-mixi-retrieve (mixi-friend-page friend)
784 (if (string-match mixi-friend-nick-regexp buf)
785 (mixi-friend-set-nick friend (match-string 1 buf))
786 (mixi-realization-error 'cannot-find-nick friend))
787 ;; For getting my profile.
788 (unless (string-match mixi-friend-name-regexp buf)
789 (with-mixi-retrieve (concat "/show_profile.pl?id="
790 (mixi-friend-id friend))
792 (if (string-match mixi-friend-name-regexp buf)
793 (mixi-friend-set-name friend (match-string 2 buf))
794 (mixi-realization-error 'cannot-find-name friend))
795 (if (string-match mixi-friend-sex-regexp buf)
796 (mixi-friend-set-sex friend
797 (if (string= (match-string 3 buf) "ÃË")
799 (mixi-realization-error 'cannot-find-sex friend))
800 (when (string-match mixi-friend-address-regexp buf)
801 (mixi-friend-set-address friend (match-string 1 buf)))
802 (when (string-match mixi-friend-age-regexp buf)
804 friend (string-to-number (match-string 2 buf))))
805 (when (string-match mixi-friend-birthday-regexp buf)
806 (mixi-friend-set-birthday
807 friend (list (string-to-number (match-string 1 buf))
808 (string-to-number (match-string 2 buf)))))
809 (when (string-match mixi-friend-blood-type-regexp buf)
810 (mixi-friend-set-blood-type friend (intern (match-string 1 buf))))
811 (when (string-match mixi-friend-birthplace-regexp buf)
812 (mixi-friend-set-birthplace friend (match-string 1 buf)))
813 (when (string-match mixi-friend-hobby-regexp buf)
814 (mixi-friend-set-hobby
815 friend (split-string (match-string 2 buf) ", ")))
816 (when (string-match mixi-friend-job-regexp buf)
817 (mixi-friend-set-job friend (match-string 2 buf)))
818 (when (string-match mixi-friend-organization-regexp buf)
819 (mixi-friend-set-organization friend (match-string 2 buf)))
820 (when (string-match mixi-friend-profile-regexp buf)
821 (mixi-friend-set-profile friend (match-string 1 buf))))
822 (mixi-object-touch friend)))
824 (defun mixi-friend-id (friend)
825 "Return the id of FRIEND."
826 (unless (mixi-friend-p friend)
827 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
828 (aref (cdr friend) 1))
830 (defun mixi-friend-nick (friend)
831 "Return the nick of FRIEND."
832 (unless (mixi-friend-p friend)
833 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
834 (unless (aref (cdr friend) 2)
835 (mixi-realize-friend friend))
836 (aref (cdr friend) 2))
838 (defun mixi-friend-name (friend)
839 "Return the name of FRIEND."
840 (unless (mixi-friend-p friend)
841 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
842 (mixi-realize-friend friend)
843 (aref (cdr friend) 3))
845 (defun mixi-friend-sex (friend)
846 "Return the sex of FRIEND."
847 (unless (mixi-friend-p friend)
848 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
849 (mixi-realize-friend friend)
850 (aref (cdr friend) 4))
852 (defun mixi-friend-address (friend)
853 "Return the address of FRIEND."
854 (unless (mixi-friend-p friend)
855 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
856 (mixi-realize-friend friend)
857 (aref (cdr friend) 5))
859 (defun mixi-friend-age (friend)
860 "Return the age of FRIEND."
861 (unless (mixi-friend-p friend)
862 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
863 (mixi-realize-friend friend)
864 (aref (cdr friend) 6))
866 (defun mixi-friend-birthday (friend)
867 "Return the birthday of FRIEND."
868 (unless (mixi-friend-p friend)
869 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
870 (mixi-realize-friend friend)
871 (aref (cdr friend) 7))
873 (defun mixi-friend-blood-type (friend)
874 "Return the blood type of FRIEND."
875 (unless (mixi-friend-p friend)
876 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
877 (mixi-realize-friend friend)
878 (aref (cdr friend) 8))
880 (defun mixi-friend-birthplace (friend)
881 "Return the birthplace of FRIEND."
882 (unless (mixi-friend-p friend)
883 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
884 (mixi-realize-friend friend)
885 (aref (cdr friend) 9))
887 (defun mixi-friend-hobby (friend)
888 "Return the hobby of FRIEND."
889 (unless (mixi-friend-p friend)
890 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
891 (mixi-realize-friend friend)
892 (aref (cdr friend) 10))
894 (defun mixi-friend-job (friend)
895 "Return the job of FRIEND."
896 (unless (mixi-friend-p friend)
897 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
898 (mixi-realize-friend friend)
899 (aref (cdr friend) 11))
901 (defun mixi-friend-organization (friend)
902 "Return the organization of FRIEND."
903 (unless (mixi-friend-p friend)
904 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
905 (mixi-realize-friend friend)
906 (aref (cdr friend) 12))
908 (defun mixi-friend-profile (friend)
909 "Return the pforile of FRIEND."
910 (unless (mixi-friend-p friend)
911 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
912 (mixi-realize-friend friend)
913 (aref (cdr friend) 13))
915 (defun mixi-friend-set-nick (friend nick)
916 "Set the nick of FRIEND."
917 (unless (mixi-friend-p friend)
918 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
919 (aset (cdr friend) 2 nick))
921 (defun mixi-friend-set-name (friend name)
922 "Set the name of FRIEND."
923 (unless (mixi-friend-p friend)
924 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
925 (aset (cdr friend) 3 name))
927 (defun mixi-friend-set-sex (friend sex)
928 "Set the sex of FRIEND."
929 (unless (mixi-friend-p friend)
930 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
931 (aset (cdr friend) 4 sex))
933 (defun mixi-friend-set-address (friend address)
934 "Set the address of FRIEND."
935 (unless (mixi-friend-p friend)
936 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
937 (aset (cdr friend) 5 address))
939 (defun mixi-friend-set-age (friend age)
940 "Set the age of FRIEND."
941 (unless (mixi-friend-p friend)
942 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
943 (aset (cdr friend) 6 age))
945 (defun mixi-friend-set-birthday (friend birthday)
946 "Set the birthday of FRIEND."
947 (unless (mixi-friend-p friend)
948 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
949 (aset (cdr friend) 7 birthday))
951 (defun mixi-friend-set-blood-type (friend blood-type)
952 "Set the blood type of FRIEND."
953 (unless (mixi-friend-p friend)
954 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
955 (aset (cdr friend) 8 blood-type))
957 (defun mixi-friend-set-birthplace (friend birthplace)
958 "Set the birthplace of FRIEND."
959 (unless (mixi-friend-p friend)
960 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
961 (aset (cdr friend) 9 birthplace))
963 (defun mixi-friend-set-hobby (friend hobby)
964 "Set the hobby of FRIEND."
965 (unless (mixi-friend-p friend)
966 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
967 (aset (cdr friend) 10 hobby))
969 (defun mixi-friend-set-job (friend job)
970 "Set the job of FRIEND."
971 (unless (mixi-friend-p friend)
972 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
973 (aset (cdr friend) 11 job))
975 (defun mixi-friend-set-organization (friend organization)
976 "Set the organization of FRIEND."
977 (unless (mixi-friend-p friend)
978 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
979 (aset (cdr friend) 12 organization))
981 (defun mixi-friend-set-profile (friend profile)
982 "Set the profile of FRIEND."
983 (unless (mixi-friend-p friend)
984 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
985 (aset (cdr friend) 13 profile))
987 (defmacro mixi-friend-list-page (&optional friend)
988 `(concat "/list_friend.pl?page=%d"
989 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
991 (defconst mixi-friend-list-id-regexp
992 "<a href=show_friend\\.pl\\?id=\\([0-9]+\\)")
993 (defconst mixi-friend-list-nick-regexp
994 "<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
996 (defun mixi-get-friends (&rest friend-or-range)
997 "Get friends of FRIEND."
998 (when (> (length friend-or-range) 2)
999 (signal 'wrong-number-of-arguments (list 'mixi-get-friends
1000 (length friend-or-range))))
1001 (let ((friend (nth 0 friend-or-range))
1002 (range (nth 1 friend-or-range)))
1003 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1004 (setq friend (nth 1 friend-or-range))
1005 (setq range (nth 0 friend-or-range)))
1006 (unless (or (null friend) (mixi-friend-p friend))
1007 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1008 (let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
1009 mixi-friend-list-id-regexp
1011 (nicks (mixi-get-matched-items (mixi-friend-list-page friend)
1012 mixi-friend-list-nick-regexp
1016 (while (< index (length ids))
1017 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1018 (nth 0 (nth index nicks))) ret))
1023 (defmacro mixi-favorite-list-page ()
1024 `(concat "/list_bookmark.pl?page=%d"))
1026 (defconst mixi-favorite-list-id-regexp
1027 "<td ALIGN=center BGCOLOR=#FDF9F2 width=330><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">")
1028 (defconst mixi-favorite-list-nick-regexp
1029 "<td BGCOLOR=#FDF9F2><font COLOR=#996600>̾ Á°</font></td>
1030 <td COLSPAN=2 BGCOLOR=#FFFFFF>\\(.+\\)</td></tr>")
1032 (defun mixi-get-favorites (&optional range)
1034 (let ((ids (mixi-get-matched-items (mixi-favorite-list-page)
1035 mixi-favorite-list-id-regexp
1037 (nicks (mixi-get-matched-items (mixi-favorite-list-page)
1038 mixi-favorite-list-nick-regexp
1042 (while (< index (length ids))
1043 (setq ret (cons (mixi-make-friend (nth 0 (nth index ids))
1044 (nth 0 (nth index nicks))) ret))
1049 (defun mixi-make-log (friend time)
1050 "Return a log object."
1051 (cons 'mixi-log (vector friend time)))
1053 (defmacro mixi-log-p (log)
1054 `(eq (mixi-object-class ,log) 'mixi-log))
1056 (defun mixi-log-friend (log)
1057 "Return the friend of LOG."
1058 (unless (mixi-log-p log)
1059 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1062 (defun mixi-log-time (log)
1063 "Return the time of LOG."
1064 (unless (mixi-log-p log)
1065 (signal 'wrong-type-argument (list 'mixi-log-p log)))
1068 (defmacro mixi-log-list-page ()
1069 `(concat "/show_log.pl"))
1071 (defconst mixi-log-list-regexp
1072 "\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\) <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a></li>")
1074 (defun mixi-get-logs (&optional range)
1076 (let ((items (mixi-get-matched-items (mixi-log-list-page)
1077 mixi-log-list-regexp
1079 (mapcar (lambda (item)
1080 (mixi-make-log (mixi-make-friend (nth 5 item) (nth 6 item))
1082 (string-to-number (nth 4 item))
1083 (string-to-number (nth 3 item))
1084 (string-to-number (nth 2 item))
1085 (string-to-number (nth 1 item))
1086 (string-to-number (nth 0 item)))))
1090 (defvar mixi-diary-cache (make-hash-table :test 'equal))
1091 (defun mixi-make-diary (owner id &optional time title content)
1092 "Return a diary object."
1093 (let ((owner (or owner (mixi-make-me))))
1094 (mixi-make-cache (list (mixi-friend-id owner) id)
1095 (cons 'mixi-diary (vector nil owner id time title
1099 (defconst mixi-diary-url-regexp
1100 "/view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)")
1102 (defun mixi-make-diary-from-url (url)
1103 "Return a diary object from URL."
1104 (when (string-match mixi-diary-url-regexp url)
1105 (let ((id (match-string 1 url))
1106 (owner-id (match-string 2 url)))
1107 (mixi-make-diary (mixi-make-friend owner-id) id))))
1109 (defmacro mixi-diary-p (diary)
1110 `(eq (mixi-object-class ,diary) 'mixi-diary))
1112 (defmacro mixi-diary-page (diary)
1113 `(concat "/view_diary.pl?id=" (mixi-diary-id ,diary)
1114 "&owner_id=" (mixi-friend-id (mixi-diary-owner ,diary))))
1116 (defconst mixi-diary-closed-regexp
1117 "<td>ͧ¿Í\\(¤Îͧ¿Í\\)?¤Þ¤Ç¸ø³«¤Î¤¿¤áÆɤळ¤È¤¬½ÐÍè¤Þ¤»¤ó¡£</td></tr>")
1118 (defconst mixi-diary-owner-nick-regexp
1119 "<td WIDTH=490 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b><font COLOR=#605048>\\(.+?\\)\\(¤µ¤ó\\)?¤ÎÆüµ</font></b></td>")
1120 (defconst mixi-diary-time-regexp
1121 "<td \\(align\\|ALIGN\\)=\"?center\"? \\(rowspan\\|ROWSPAN\\)=\"?[23]\"? \\(nowrap=\"nowrap\"\\|NOWRAP\\) \\(width\\|WIDTH\\)=\"?95\"? bgcolor=\"?#FFD8B0\"?>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü\\(<br />\\|<br>\\)\\([0-9]+\\):\\([0-9]+\\)</td>")
1122 (defconst mixi-diary-title-regexp
1123 "<td \\(bgcolor\\|BGCOLOR\\)=\"?#FFF4E0\"? width=\"?430\"?> \\([^<]+\\)</td>")
1124 (defconst mixi-diary-content-regexp
1125 "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
1127 (defun mixi-realize-diary (diary)
1129 ;; FIXME: Check a expiration of cache?
1130 (unless (mixi-object-realized-p diary)
1131 (with-mixi-retrieve (mixi-diary-page diary)
1132 (unless (string-match mixi-diary-closed-regexp buffer)
1133 (if (string-match mixi-diary-owner-nick-regexp buffer)
1134 (mixi-friend-set-nick (mixi-diary-owner diary)
1135 (match-string 1 buffer))
1136 (mixi-realization-error 'cannot-find-owner-nick diary))
1137 (if (string-match mixi-diary-time-regexp buffer)
1138 (mixi-diary-set-time
1139 diary (encode-time 0 (string-to-number (match-string 10 buffer))
1140 (string-to-number (match-string 9 buffer))
1141 (string-to-number (match-string 7 buffer))
1142 (string-to-number (match-string 6 buffer))
1143 (string-to-number (match-string 5 buffer))))
1144 (mixi-realization-error 'cannot-find-time diary))
1145 (if (string-match mixi-diary-title-regexp buffer)
1146 (mixi-diary-set-title diary (match-string 2 buffer))
1147 (mixi-realization-error 'cannot-find-title diary))
1148 (if (string-match mixi-diary-content-regexp buffer)
1149 (mixi-diary-set-content diary (match-string 2 buffer))
1150 (mixi-realization-error 'cannot-find-content diary))))
1151 (mixi-object-touch diary)))
1153 (defun mixi-diary-owner (diary)
1154 "Return the owner of DIARY."
1155 (unless (mixi-diary-p diary)
1156 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1157 (aref (cdr diary) 1))
1159 (defun mixi-diary-id (diary)
1160 "Return the id of DIARY."
1161 (unless (mixi-diary-p diary)
1162 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1163 (aref (cdr diary) 2))
1165 (defun mixi-diary-time (diary)
1166 "Return the time of DIARY."
1167 (unless (mixi-diary-p diary)
1168 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1169 (mixi-realize-diary diary)
1170 (aref (cdr diary) 3))
1172 (defun mixi-diary-title (diary)
1173 "Return the title of DIARY."
1174 (unless (mixi-diary-p diary)
1175 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1176 (mixi-realize-diary diary)
1177 (aref (cdr diary) 4))
1179 (defun mixi-diary-content (diary)
1180 "Return the content of DIARY."
1181 (unless (mixi-diary-p diary)
1182 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1183 (mixi-realize-diary diary)
1184 (aref (cdr diary) 5))
1186 (defun mixi-diary-set-time (diary time)
1187 "Set the time of DIARY."
1188 (unless (mixi-diary-p diary)
1189 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1190 (aset (cdr diary) 3 time))
1192 (defun mixi-diary-set-title (diary title)
1193 "Set the title of DIARY."
1194 (unless (mixi-diary-p diary)
1195 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1196 (aset (cdr diary) 4 title))
1198 (defun mixi-diary-set-content (diary content)
1199 "Set the content of DIARY."
1200 (unless (mixi-diary-p diary)
1201 (signal 'wrong-type-argument (list 'mixi-diary-p diary)))
1202 (aset (cdr diary) 5 content))
1204 (defmacro mixi-diary-list-page (&optional friend)
1205 `(concat "/list_diary.pl?page=%d"
1206 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1208 (defconst mixi-diary-list-regexp
1209 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">")
1211 (defun mixi-get-diaries (&rest friend-or-range)
1212 "Get diaries of FRIEND."
1213 (when (> (length friend-or-range) 2)
1214 (signal 'wrong-number-of-arguments
1215 (list 'mixi-get-diaries (length friend-or-range))))
1216 (let ((friend (nth 0 friend-or-range))
1217 (range (nth 1 friend-or-range)))
1218 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1219 (setq friend (nth 1 friend-or-range))
1220 (setq range (nth 0 friend-or-range)))
1221 (unless (or (null friend) (mixi-friend-p friend))
1222 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1223 (let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
1224 mixi-diary-list-regexp
1226 (mapcar (lambda (item)
1227 (mixi-make-diary friend (nth 0 item)))
1230 (defmacro mixi-new-diary-list-page ()
1231 `(concat "/new_friend_diary.pl?page=%d"))
1233 (defconst mixi-new-diary-list-regexp
1234 "<a class=\"new_link\" href=view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)>")
1236 (defun mixi-get-new-diaries (&optional range)
1238 (let ((items (mixi-get-matched-items (mixi-new-diary-list-page)
1239 mixi-new-diary-list-regexp
1241 (mapcar (lambda (item)
1242 (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
1245 (defmacro mixi-search-diary-list-page (keyword)
1246 `(concat "/search_diary.pl?page=%d&submit=search&keyword="
1247 (mixi-url-encode-and-quote-percent-string keyword)))
1249 (defconst mixi-search-diary-list-regexp
1250 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)\">")
1252 (defun mixi-search-diaries (keyword &optional range)
1253 (let ((items (mixi-get-matched-items (mixi-search-diary-list-page keyword)
1254 mixi-search-diary-list-regexp
1256 (mapcar (lambda (item)
1257 (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
1260 (defmacro mixi-post-diary-page ()
1261 `(concat "/add_diary.pl"))
1263 (defconst mixi-post-key-regexp
1264 "<input type=\"?hidden\"? name=\"?post_key\"? value=\"\\([a-z0-9]+\\)\">")
1265 (defconst mixi-post-succeed-regexp
1266 "<b>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</b>")
1268 ;; FIXME: Support photos.
1269 (defun mixi-post-diary (title content)
1271 (unless (stringp title)
1272 (signal 'wrong-type-argument (list 'stringp title)))
1273 (unless (stringp content)
1274 (signal 'wrong-type-argument (list 'stringp content)))
1275 (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
1276 ("diary_title" . ,title)
1277 ("diary_body" . ,content)
1278 ("submit" . "main")))
1280 (with-mixi-post-form (mixi-post-diary-page) fields
1281 (if (string-match mixi-post-key-regexp buffer)
1282 (setq post-key (match-string 1 buffer))
1283 (mixi-post-error 'cannot-find-key)))
1284 (setq fields `(("post_key" . ,post-key)
1285 ("id" . ,(mixi-friend-id (mixi-make-me)))
1286 ("diary_title" . ,title)
1287 ("diary_body" . ,content)
1288 ("submit" . "confirm")))
1289 (with-mixi-post-form (mixi-post-diary-page) fields
1290 (unless (string-match mixi-post-succeed-regexp buffer)
1291 (mixi-post-error 'cannot-find-succeed)))))
1293 ;; Community object.
1294 (defvar mixi-community-cache (make-hash-table :test 'equal))
1295 (defun mixi-make-community (id &optional name birthday owner category members
1296 open-level authority description)
1297 "Return a community object."
1298 (mixi-make-cache id (cons 'mixi-community (vector nil id name birthday owner
1300 open-level authority
1302 mixi-community-cache))
1304 (defconst mixi-community-url-regexp
1305 "/view_community\\.pl\\?id=\\([0-9]+\\)")
1307 (defun mixi-make-community-from-url (url)
1308 "Return a community object from URL."
1309 (when (string-match mixi-community-url-regexp url)
1310 (let ((id (match-string 1 url)))
1311 (mixi-make-community id))))
1313 (defmacro mixi-community-p (community)
1314 `(eq (mixi-object-class ,community) 'mixi-community))
1316 (defmacro mixi-community-page (community)
1317 `(concat "/view_community.pl?id=" (mixi-community-id ,community)))
1319 ;; FIXME: Not community specific.
1320 (defconst mixi-community-nodata-regexp
1321 "^¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1322 (defconst mixi-community-name-regexp
1323 "<td WIDTH=345>\\(.*\\)</td></tr>")
1324 (defconst mixi-community-birthday-regexp
1325 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>³«ÀßÆü</font></td>
\r
1326 <td>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
1327 ;; FIXME: Care when the owner has seceded.
1328 (defconst mixi-community-owner-regexp
1329 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>´ÉÍý¿Í</font></td>
\r
1332 <a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">
\r
1334 (defconst mixi-community-category-regexp
1335 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>
\r
1336 <td>\\([^<]+\\)</td>")
1337 (defconst mixi-community-members-regexp
1338 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>
\r
1339 <td>\\([0-9]+\\)¿Í</td></tr>")
1340 (defconst mixi-community-open-level-regexp
1341 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
\r
1342 <td>\\(.+\\)</td></tr>")
1343 (defconst mixi-community-authority-regexp
1344 "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>
\r
1345 <td>\\(.+\\)</td></tr>")
1346 (defconst mixi-community-description-regexp
1347 "<td CLASS=h120>\\(.+\\)</td>")
1349 (defun mixi-realize-community (community)
1350 "Realize a COMMUNITY."
1351 ;; FIXME: Check a expiration of cache?
1352 (unless (mixi-object-realized-p community)
1353 (with-mixi-retrieve (mixi-community-page community)
1354 (if (string-match mixi-community-nodata-regexp buffer)
1355 ;; FIXME: Set all members?
1356 (mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
1357 (if (string-match mixi-community-name-regexp buffer)
1358 (mixi-community-set-name community (match-string 1 buffer))
1359 (mixi-realization-error 'cannot-find-name community))
1360 (if (string-match mixi-community-birthday-regexp buffer)
1361 (mixi-community-set-birthday
1363 (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
1364 (string-to-number (match-string 2 buffer))
1365 (string-to-number (match-string 1 buffer))))
1366 (mixi-realization-error 'cannot-find-birthday community))
1367 (if (string-match mixi-community-owner-regexp buffer)
1368 (if (string= (match-string 1 buffer) "home.pl")
1369 (mixi-community-set-owner community (mixi-make-me))
1370 (mixi-community-set-owner
1371 community (mixi-make-friend (match-string 2 buffer)
1372 (match-string 3 buffer))))
1373 (mixi-realization-error 'cannot-find-owner community))
1374 (if (string-match mixi-community-category-regexp buffer)
1375 (mixi-community-set-category community (match-string 1 buffer))
1376 (mixi-realization-error 'cannot-find-category community))
1377 (if (string-match mixi-community-members-regexp buffer)
1378 (mixi-community-set-members
1379 community (string-to-number (match-string 1 buffer)))
1380 (mixi-realization-error 'cannot-find-members community))
1381 (if (string-match mixi-community-open-level-regexp buffer)
1382 (mixi-community-set-open-level community (match-string 1 buffer))
1383 (mixi-realization-error 'cannot-find-open-level community))
1384 (if (string-match mixi-community-authority-regexp buffer)
1385 (mixi-community-set-authority community (match-string 1 buffer))
1386 (mixi-realization-error 'cannot-find-authority community))
1387 (if (string-match mixi-community-description-regexp buffer)
1388 (mixi-community-set-description community (match-string 1 buffer))
1389 (mixi-realization-error 'cannot-find-description community))))
1390 (mixi-object-touch community)))
1392 (defun mixi-community-id (community)
1393 "Return the id of COMMUNITY."
1394 (unless (mixi-community-p community)
1395 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1396 (aref (cdr community) 1))
1398 (defun mixi-community-name (community)
1399 "Return the name of COMMUNITY."
1400 (unless (mixi-community-p community)
1401 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1402 (unless (aref (cdr community) 2)
1403 (mixi-realize-community community))
1404 (aref (cdr community) 2))
1406 (defun mixi-community-birthday (community)
1407 "Return the birthday of COMMUNITY."
1408 (unless (mixi-community-p community)
1409 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1410 (mixi-realize-community community)
1411 (aref (cdr community) 3))
1413 (defun mixi-community-owner (community)
1414 "Return the owner of COMMUNITY."
1415 (unless (mixi-community-p community)
1416 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1417 (mixi-realize-community community)
1418 (aref (cdr community) 4))
1420 (defun mixi-community-category (community)
1421 "Return the category of COMMUNITY."
1422 (unless (mixi-community-p community)
1423 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1424 (mixi-realize-community community)
1425 (aref (cdr community) 5))
1427 (defun mixi-community-members (community)
1428 "Return the members of COMMUNITY."
1429 (unless (mixi-community-p community)
1430 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1431 (mixi-realize-community community)
1432 (aref (cdr community) 6))
1434 (defun mixi-community-open-level (community)
1435 "Return the open-level of COMMUNITY."
1436 (unless (mixi-community-p community)
1437 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1438 (mixi-realize-community community)
1439 (aref (cdr community) 7))
1441 (defun mixi-community-authority (community)
1442 "Return the authority of COMMUNITY."
1443 (unless (mixi-community-p community)
1444 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1445 (mixi-realize-community community)
1446 (aref (cdr community) 8))
1448 (defun mixi-community-description (community)
1449 "Return the description of COMMUNITY."
1450 (unless (mixi-community-p community)
1451 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1452 (mixi-realize-community community)
1453 (aref (cdr community) 9))
1455 (defun mixi-community-set-name (community name)
1456 "Set the name of COMMUNITY."
1457 (unless (mixi-community-p community)
1458 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1459 (aset (cdr community) 2 name))
1461 (defun mixi-community-set-birthday (community birthday)
1462 "Set the birthday of COMMUNITY."
1463 (unless (mixi-community-p community)
1464 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1465 (aset (cdr community) 3 birthday))
1467 (defun mixi-community-set-owner (community owner)
1468 "Set the owner of COMMUNITY."
1469 (unless (mixi-community-p community)
1470 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1471 (unless (mixi-friend-p owner)
1472 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1473 (aset (cdr community) 4 owner))
1475 (defun mixi-community-set-category (community category)
1476 "Set the category of COMMUNITY."
1477 (unless (mixi-community-p community)
1478 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1479 (aset (cdr community) 5 category))
1481 (defun mixi-community-set-members (community members)
1482 "Set the name of COMMUNITY."
1483 (unless (mixi-community-p community)
1484 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1485 (aset (cdr community) 6 members))
1487 (defun mixi-community-set-open-level (community open-level)
1488 "Set the name of COMMUNITY."
1489 (unless (mixi-community-p community)
1490 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1491 (aset (cdr community) 7 open-level))
1493 (defun mixi-community-set-authority (community authority)
1494 "Set the name of COMMUNITY."
1495 (unless (mixi-community-p community)
1496 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1497 (aset (cdr community) 8 authority))
1499 (defun mixi-community-set-description (community description)
1500 "Set the name of COMMUNITY."
1501 (unless (mixi-community-p community)
1502 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1503 (aset (cdr community) 9 description))
1505 (defmacro mixi-community-list-page (&optional friend)
1506 `(concat "/list_community.pl?page=%d"
1507 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
1509 (defconst mixi-community-list-id-regexp
1510 "<a href=view_community\\.pl\\?id=\\([0-9]+\\)")
1511 (defconst mixi-community-list-name-regexp
1512 "<td valign=middle>\\(.+\\)([0-9]+)</td>")
1514 (defun mixi-get-communities (&rest friend-or-range)
1515 "Get communities of FRIEND."
1516 (when (> (length friend-or-range) 2)
1517 (signal 'wrong-number-of-arguments
1518 (list 'mixi-get-communities (length friend-or-range))))
1519 (let ((friend (nth 0 friend-or-range))
1520 (range (nth 1 friend-or-range)))
1521 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
1522 (setq friend (nth 1 friend-or-range))
1523 (setq range (nth 0 friend-or-range)))
1524 (unless (or (null friend) (mixi-friend-p friend))
1525 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
1526 (let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
1527 mixi-community-list-id-regexp
1529 (names (mixi-get-matched-items (mixi-community-list-page friend)
1530 mixi-community-list-name-regexp
1534 (while (< index (length ids))
1535 (setq ret (cons (mixi-make-community (nth 0 (nth index ids))
1536 (nth 0 (nth index names))) ret))
1540 (defmacro mixi-search-community-list-page (keyword)
1541 `(concat "/search_community.pl?page=%d&&sort=date&type=com&submit=main"
1542 "&keyword=" (mixi-url-encode-and-quote-percent-string keyword)
1545 (defconst mixi-search-community-list-regexp
1546 "<td WIDTH=90 VALIGN=top ROWSPAN=4 ALIGN=center background=http://img\\.mixi\\.jp/img/bg_line\\.gif><a href=\"view_community\\.pl\\?id=\\([0-9]+\\)\"><img SRC=\"http://img-c[0-9]+\\.mixi\\.jp/photo/comm/[^.]+\\.jpg\" VSPACE=3 border=0></a></td>
1547 <td NOWRAP WIDTH=90 BGCOLOR=#FDF9F2><font COLOR=#996600>¥³¥ß¥å¥Ë¥Æ¥£Ì¾</font></td>
1548 <td COLSPAN=2 WIDTH=370 BGCOLOR=#FFFFFF>\\([^<]+\\)</td></tr>")
1550 ;; FIXME: Support category.
1551 (defun mixi-search-communities (keyword &optional range)
1552 (let ((items (mixi-get-matched-items (mixi-search-community-list-page
1554 mixi-search-community-list-regexp
1556 (mapcar (lambda (item)
1557 (mixi-make-community (nth 0 item) (nth 1 item)))
1561 (defvar mixi-topic-cache (make-hash-table :test 'equal))
1562 (defun mixi-make-topic (community id &optional time title owner content)
1563 "Return a topic object."
1564 (mixi-make-cache (list (mixi-community-id community) id)
1565 (cons 'mixi-topic (vector nil community id time title owner
1569 (defconst mixi-topic-url-regexp
1570 "/view_bbs\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
1572 (defun mixi-make-topic-from-url (url)
1573 "Return a topic object from URL."
1574 (when (string-match mixi-topic-url-regexp url)
1575 (let ((id (match-string 1 url))
1576 (community-id (match-string 3 url)))
1577 (mixi-make-topic (mixi-make-community community-id) id))))
1579 (defmacro mixi-topic-p (topic)
1580 `(eq (mixi-object-class ,topic) 'mixi-topic))
1582 (defmacro mixi-topic-page (topic)
1583 `(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
1584 "&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
1586 (defconst mixi-topic-community-regexp
1587 "<td width=\"595\" background=\"http://img\\.mixi\\.jp/img/bg_w\\.gif\"><b>\\[\\(.+\\)\\] ¥È¥Ô¥Ã¥¯</b></td>")
1588 (defconst mixi-topic-time-regexp
1589 "<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
1590 (defconst mixi-topic-title-regexp
1591 "<td bgcolor=\"#fff4e0\"> \\([^<]+\\)</td>")
1592 (defconst mixi-topic-owner-regexp
1593 "<td bgcolor=\"#fdf9f2\"> <font color=\"#dfb479\"></font> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*?\\)\\(¤µ¤ó\\)?</a>")
1594 (defconst mixi-topic-content-regexp
1595 "<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td class=\"h120\"><table><tr>\\(<td width=\"130\" height=\"140\" align=\"center\" valign=\"middle\"><a href=\"javascript:void(0)\" onClick=\"MM_openBrWindow('show_bbs_picture\\.pl\\?id=[0-9]+&number=[0-9]+','pict','width=680,height=660,toolbar=no,scrollbars=yes,left=5,top=5')\"><img src=\"http://ic[0-9]+\\.mixi\\.jp/[^.]+\\.jpg\" border=\"0\"></a></td>\n\\)*</tr></table>\\(.+\\)</td></tr></table>")
1597 (defun mixi-realize-topic (topic)
1599 ;; FIXME: Check a expiration of cache?
1600 (unless (mixi-object-realized-p topic)
1601 (with-mixi-retrieve (mixi-topic-page topic)
1602 (if (string-match mixi-topic-community-regexp buffer)
1603 (mixi-community-set-name (mixi-topic-community topic)
1604 (match-string 1 buffer))
1605 (mixi-realization-error 'cannot-find-community topic))
1606 (if (string-match mixi-topic-time-regexp buffer)
1607 (mixi-topic-set-time
1608 topic (encode-time 0 (string-to-number (match-string 5 buffer))
1609 (string-to-number (match-string 4 buffer))
1610 (string-to-number (match-string 3 buffer))
1611 (string-to-number (match-string 2 buffer))
1612 (string-to-number (match-string 1 buffer))))
1613 (mixi-realization-error 'cannot-find-time topic))
1614 (if (string-match mixi-topic-title-regexp buffer)
1615 (mixi-topic-set-title topic (match-string 1 buffer))
1616 (mixi-realization-error 'cannot-find-title topic))
1617 (if (string-match mixi-topic-owner-regexp buffer)
1618 (mixi-topic-set-owner topic
1619 (mixi-make-friend (match-string 1 buffer)
1620 (match-string 2 buffer)))
1621 (mixi-realization-error 'cannot-find-owner topic))
1622 (if (string-match mixi-topic-content-regexp buffer)
1623 (mixi-topic-set-content topic (match-string 2 buffer))
1624 (mixi-realization-error 'cannot-find-content topic)))
1625 (mixi-object-touch topic)))
1627 (defun mixi-topic-community (topic)
1628 "Return the community of TOPIC."
1629 (unless (mixi-topic-p topic)
1630 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1631 (aref (cdr topic) 1))
1633 (defun mixi-topic-id (topic)
1634 "Return the id of TOPIC."
1635 (unless (mixi-topic-p topic)
1636 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1637 (aref (cdr topic) 2))
1639 (defun mixi-topic-time (topic)
1640 "Return the time of TOPIC."
1641 (unless (mixi-topic-p topic)
1642 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1643 (mixi-realize-topic topic)
1644 (aref (cdr topic) 3))
1646 (defun mixi-topic-title (topic)
1647 "Return the title of TOPIC."
1648 (unless (mixi-topic-p topic)
1649 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1650 (mixi-realize-topic topic)
1651 (aref (cdr topic) 4))
1653 (defun mixi-topic-owner (topic)
1654 "Return the owner of TOPIC."
1655 (unless (mixi-topic-p topic)
1656 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1657 (mixi-realize-topic topic)
1658 (aref (cdr topic) 5))
1660 (defun mixi-topic-content (topic)
1661 "Return the content of TOPIC."
1662 (unless (mixi-topic-p topic)
1663 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1664 (mixi-realize-topic topic)
1665 (aref (cdr topic) 6))
1667 (defun mixi-topic-set-time (topic time)
1668 "Set the time of TOPIC."
1669 (unless (mixi-topic-p topic)
1670 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1671 (aset (cdr topic) 3 time))
1673 (defun mixi-topic-set-title (topic title)
1674 "Set the title of TOPIC."
1675 (unless (mixi-topic-p topic)
1676 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1677 (aset (cdr topic) 4 title))
1679 (defun mixi-topic-set-owner (topic owner)
1680 "Set the owner of TOPIC."
1681 (unless (mixi-topic-p topic)
1682 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1683 (unless (mixi-friend-p owner)
1684 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1685 (aset (cdr topic) 5 owner))
1687 (defun mixi-topic-set-content (topic content)
1688 "Set the content of TOPIC."
1689 (unless (mixi-topic-p topic)
1690 (signal 'wrong-type-argument (list 'mixi-topic-p topic)))
1691 (aset (cdr topic) 6 content))
1693 (defmacro mixi-post-topic-page (community)
1694 `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
1696 ;; FIXME: Support photos.
1697 (defun mixi-post-topic (community title content)
1698 "Post a topic to COMMUNITY."
1699 (unless (mixi-community-p community)
1700 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1701 (unless (stringp title)
1702 (signal 'wrong-type-argument (list 'stringp title)))
1703 (unless (stringp content)
1704 (signal 'wrong-type-argument (list 'stringp content)))
1705 (let ((fields `(("bbs_title" . ,title)
1706 ("bbs_body" . ,content)
1707 ("submit" . "main")))
1709 (with-mixi-post-form (mixi-post-topic-page community) fields
1710 (if (string-match mixi-post-key-regexp buffer)
1711 (setq post-key (match-string 1 buffer))
1712 (mixi-post-error 'cannot-find-key community)))
1713 (setq fields `(("post_key" . ,post-key)
1714 ("bbs_title" . ,title)
1715 ("bbs_body" . ,content)
1716 ("submit" . "confirm")))
1717 (with-mixi-post-form (mixi-post-topic-page community) fields
1718 (unless (string-match mixi-post-succeed-regexp buffer)
1719 (mixi-post-error 'cannot-find-succeed community)))))
1722 (defvar mixi-event-cache (make-hash-table :test 'equal))
1723 (defun mixi-make-event (community id &optional time title owner date place
1724 detail limit members)
1725 "Return a event object."
1726 (mixi-make-cache (list (mixi-community-id community) id)
1727 (cons 'mixi-event (vector nil community id time title owner
1728 date place detail limit members))
1731 (defconst mixi-event-url-regexp
1732 "/view_event\\.pl\\?id=\\([0-9]+\\)\\(&comment_count=[0-9]+\\)?&comm_id=\\([0-9]+\\)")
1734 (defun mixi-make-event-from-url (url)
1735 "Return a event object from URL."
1736 (when (string-match mixi-event-url-regexp url)
1737 (let ((id (match-string 1 url))
1738 (community-id (match-string 3 url)))
1739 (mixi-make-event (mixi-make-community community-id) id))))
1741 (defmacro mixi-event-p (event)
1742 `(eq (mixi-object-class ,event) 'mixi-event))
1744 (defmacro mixi-event-page (event)
1745 `(concat "/view_event.pl?id=" (mixi-event-id ,event)
1746 "&comm_id=" (mixi-community-id (mixi-event-community ,event))))
1748 (defconst mixi-event-community-regexp
1749 "<td WIDTH=595 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b>\\[\\(.+\\)\\] ¥¤¥Ù¥ó¥È</b></td>")
1750 (defconst mixi-event-time-regexp
1751 "<td ROWSPAN=11 \\(BGCOLOR\\|bgcolor\\)=#FFD8B0 \\(ALIGN\\|align\\)=center \\(VALIGN\\|Valign\\)=top WIDTH=110>
1752 ?\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
1753 ?\\([0-9]+\\):\\([0-9]+\\)</td>")
1754 (defconst mixi-event-title-regexp
1755 "<td bgcolor=#FFF4E0\\( width=410\\)?> \\([^<]+\\)</td>")
1756 (defconst mixi-event-owner-regexp
1757 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
1758 (defconst mixi-event-owner-seceded-regexp
1759 "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> \\((mixi Âà²ñºÑ)\\)")
1760 (defconst mixi-event-date-regexp
1761 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅÆü»þ</td>
1762 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1765 (defconst mixi-event-place-regexp
1766 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅ¾ì½ê</td>
1767 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1770 (defconst mixi-event-detail-regexp
1771 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>¾ÜºÙ</td>
1772 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
1773 (defconst mixi-event-limit-regexp
1774 "<td \\(BGCOLOR\\|bgcolor\\)=\"?#\\(FFFFFF\\|ffffff\\)\"? \\(ALIGN\\|align\\)=\"?center\"? NOWRAP>Ê罸´ü¸Â</td>
1775 ?<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)> \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
1776 (defconst mixi-event-members-regexp
1777 "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>»²²Ã¼Ô</td>
1778 <td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
1781 ?<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
1784 ?<td> \\(.+\\)</td>")
1786 (defun mixi-realize-event (event)
1788 ;; FIXME: Check a expiration of cache?
1789 (unless (mixi-object-realized-p event)
1790 (with-mixi-retrieve (mixi-event-page event)
1791 (if (string-match mixi-event-community-regexp buffer)
1792 (mixi-community-set-name (mixi-event-community event)
1793 (match-string 1 buffer))
1794 (mixi-realization-error 'cannot-find-community event))
1795 (if (string-match mixi-event-time-regexp buffer)
1796 (mixi-event-set-time
1797 event (encode-time 0 (string-to-number (match-string 8 buffer))
1798 (string-to-number (match-string 7 buffer))
1799 (string-to-number (match-string 6 buffer))
1800 (string-to-number (match-string 5 buffer))
1801 (string-to-number (match-string 4 buffer))))
1802 (mixi-realization-error 'cannot-find-time event))
1803 (if (string-match mixi-event-title-regexp buffer)
1804 (mixi-event-set-title event (match-string 2 buffer))
1805 (mixi-realization-error 'cannot-find-title event))
1806 (if (string-match mixi-event-owner-regexp buffer)
1807 (mixi-event-set-owner event
1808 (mixi-make-friend (match-string 2 buffer)
1809 (match-string 3 buffer)))
1810 (if (string-match mixi-event-owner-seceded-regexp buffer)
1811 (mixi-event-set-owner event
1812 (mixi-make-friend nil
1813 (match-string 2 buffer)))
1814 (mixi-realization-error 'cannot-find-owner event)))
1815 (if (string-match mixi-event-date-regexp buffer)
1816 (mixi-event-set-date event (match-string 6 buffer))
1817 (mixi-realization-error 'cannot-find-date event))
1818 (if (string-match mixi-event-place-regexp buffer)
1819 (mixi-event-set-place event (match-string 6 buffer))
1820 (mixi-realization-error 'cannot-find-place event))
1821 (if (string-match mixi-event-detail-regexp buffer)
1822 (mixi-event-set-detail event (match-string 6 buffer))
1823 (mixi-realization-error 'cannot-find-detail event))
1824 (when (string-match mixi-event-limit-regexp buffer)
1825 (mixi-event-set-limit
1826 event (encode-time 0 0 0 (string-to-number (match-string 8 buffer))
1827 (string-to-number (match-string 7 buffer))
1828 (string-to-number (match-string 6 buffer)))))
1829 (if (string-match mixi-event-members-regexp buffer)
1830 (mixi-event-set-members event (match-string 6 buffer))
1831 (mixi-realization-error 'cannot-find-members event)))
1832 (mixi-object-touch event)))
1834 (defun mixi-event-community (event)
1835 "Return the community of EVENT."
1836 (unless (mixi-event-p event)
1837 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1838 (aref (cdr event) 1))
1840 (defun mixi-event-id (event)
1841 "Return the id of EVENT."
1842 (unless (mixi-event-p event)
1843 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1844 (aref (cdr event) 2))
1846 (defun mixi-event-time (event)
1847 "Return the time of EVENT."
1848 (unless (mixi-event-p event)
1849 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1850 (mixi-realize-event event)
1851 (aref (cdr event) 3))
1853 (defun mixi-event-title (event)
1854 "Return the title of EVENT."
1855 (unless (mixi-event-p event)
1856 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1857 (mixi-realize-event event)
1858 (aref (cdr event) 4))
1860 (defun mixi-event-owner (event)
1861 "Return the owner of EVENT."
1862 (unless (mixi-event-p event)
1863 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1864 (mixi-realize-event event)
1865 (aref (cdr event) 5))
1867 (defun mixi-event-date (event)
1868 "Return the date of EVENT."
1869 (unless (mixi-event-p event)
1870 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1871 (mixi-realize-event event)
1872 (aref (cdr event) 6))
1874 (defun mixi-event-place (event)
1875 "Return the place of EVENT."
1876 (unless (mixi-event-p event)
1877 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1878 (mixi-realize-event event)
1879 (aref (cdr event) 7))
1881 (defun mixi-event-detail (event)
1882 "Return the detail of EVENT."
1883 (unless (mixi-event-p event)
1884 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1885 (mixi-realize-event event)
1886 (aref (cdr event) 8))
1888 (defun mixi-event-limit (event)
1889 "Return the limit of EVENT."
1890 (unless (mixi-event-p event)
1891 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1892 (mixi-realize-event event)
1893 (aref (cdr event) 9))
1895 (defun mixi-event-members (event)
1896 "Return the members of EVENT."
1897 (unless (mixi-event-p event)
1898 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1899 (mixi-realize-event event)
1900 (aref (cdr event) 10))
1902 (defun mixi-event-set-time (event time)
1903 "Set the time of EVENT."
1904 (unless (mixi-event-p event)
1905 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1906 (aset (cdr event) 3 time))
1908 (defun mixi-event-set-title (event title)
1909 "Set the title of EVENT."
1910 (unless (mixi-event-p event)
1911 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1912 (aset (cdr event) 4 title))
1914 (defun mixi-event-set-owner (event owner)
1915 "Set the owner of EVENT."
1916 (unless (mixi-event-p event)
1917 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1918 (unless (mixi-friend-p owner)
1919 (signal 'wrong-type-argument (list 'mixi-friend-p owner)))
1920 (aset (cdr event) 5 owner))
1922 (defun mixi-event-set-date (event date)
1923 "Set the date of EVENT."
1924 (unless (mixi-event-p event)
1925 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1926 (aset (cdr event) 6 date))
1928 (defun mixi-event-set-place (event place)
1929 "Set the place of EVENT."
1930 (unless (mixi-event-p event)
1931 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1932 (aset (cdr event) 7 place))
1934 (defun mixi-event-set-detail (event detail)
1935 "Set the detail of EVENT."
1936 (unless (mixi-event-p event)
1937 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1938 (aset (cdr event) 8 detail))
1940 (defun mixi-event-set-limit (event limit)
1941 "Set the limit of EVENT."
1942 (unless (mixi-event-p event)
1943 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1944 (aset (cdr event) 9 limit))
1946 (defun mixi-event-set-members (event members)
1947 "Set the members of EVENT."
1948 (unless (mixi-event-p event)
1949 (signal 'wrong-type-argument (list 'mixi-event-p event)))
1950 (aset (cdr event) 10 members))
1953 (defconst mixi-bbs-list '(mixi-topic mixi-event))
1955 (defmacro mixi-bbs-p (object)
1956 `(when (memq (mixi-object-class ,object) mixi-bbs-list)
1959 (defun mixi-bbs-community (object)
1960 "Return the community of OBJECT."
1961 (unless (mixi-bbs-p object)
1962 (signal 'wrong-type-argument (list 'mixi-bbs-p object)))
1963 (let ((func (intern (concat mixi-object-prefix
1964 (mixi-object-name object) "-community"))))
1965 (funcall func object)))
1967 (defalias 'mixi-bbs-id 'mixi-object-id)
1968 (defalias 'mixi-bbs-time 'mixi-object-time)
1969 (defalias 'mixi-bbs-title 'mixi-object-title)
1970 (defalias 'mixi-bbs-owner 'mixi-object-owner)
1971 (defalias 'mixi-bbs-content 'mixi-object-content)
1973 (defmacro mixi-bbs-list-page (community)
1974 `(concat "/list_bbs.pl?page=%d"
1975 "&id=" (mixi-community-id ,community)))
1977 (defconst mixi-bbs-list-regexp
1978 "<a href=view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)")
1980 (defun mixi-get-bbses (community &optional range)
1981 "Get bbese of COMMUNITY."
1982 (unless (mixi-community-p community)
1983 (signal 'wrong-type-argument (list 'mixi-community-p community)))
1984 (let ((items (mixi-get-matched-items (mixi-bbs-list-page community)
1985 mixi-bbs-list-regexp
1987 (mapcar (lambda (item)
1988 (let ((name (nth 0 item)))
1989 (when (string= name "bbs")
1990 (setq name "topic"))
1991 (let ((func (intern (concat "mixi-make-" name))))
1992 (funcall func community (nth 1 item)))))
1995 (defmacro mixi-new-bbs-list-page ()
1996 `(concat "/new_bbs.pl?page=%d"))
1998 (defconst mixi-new-bbs-list-regexp
1999 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comment_count=[0-9]+&comm_id=\\([0-9]+\\)\" class=\"new_link\">")
2001 (defun mixi-get-new-bbses (&optional range)
2003 (let ((items (mixi-get-matched-items (mixi-new-bbs-list-page)
2004 mixi-new-bbs-list-regexp
2006 (mapcar (lambda (item)
2007 (let ((name (nth 0 item)))
2008 (when (string= name "bbs")
2009 (setq name "topic"))
2010 (let ((func (intern (concat "mixi-make-" name))))
2011 (funcall func (mixi-make-community (nth 2 item))
2015 (defmacro mixi-search-bbs-list-page (keyword)
2016 `(concat "/search_topic.pl?page=%d&type=top&submit=search"
2017 "&keyword=" (mixi-url-encode-and-quote-percent-string keyword)
2018 "&community_id=0&category_id=0"))
2020 (defconst mixi-search-bbs-list-regexp
2021 "<a href=\"view_\\(bbs\\|event\\)\\.pl\\?id=\\([0-9]+\\)&comm_id=\\([0-9]+\\)\"><img src=http://img\\.mixi\\.jp/img/shbtn\\.gif ALT=¾ÜºÙ¤ò¸«¤ë BORDER=0 WIDTH=104 HEIGHT=19></a>")
2023 ;; FIXME: Support community and category.
2024 (defun mixi-search-bbses (keyword &optional range)
2025 (let ((items (mixi-get-matched-items (mixi-search-bbs-list-page keyword)
2026 mixi-search-bbs-list-regexp
2028 (mapcar (lambda (item)
2029 (let ((name (nth 0 item)))
2030 (when (string= name "bbs")
2031 (setq name "topic"))
2032 (let ((func (intern (concat "mixi-make-" name))))
2033 (funcall func (mixi-make-community (nth 2 item))
2038 (defun mixi-make-comment (parent owner time content)
2039 "Return a comment object."
2040 (cons 'mixi-comment (vector parent owner time content)))
2042 (defmacro mixi-comment-p (comment)
2043 `(eq (mixi-object-class ,comment) 'mixi-comment))
2045 (defun mixi-comment-parent (comment)
2046 "Return the parent of COMMENT."
2047 (unless (mixi-comment-p comment)
2048 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2049 (aref (cdr comment) 0))
2051 (defun mixi-comment-owner (comment)
2052 "Return the owner of COMMENT."
2053 (unless (mixi-comment-p comment)
2054 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2055 (aref (cdr comment) 1))
2057 (defun mixi-comment-time (comment)
2058 "Return the time of COMMENT."
2059 (unless (mixi-comment-p comment)
2060 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2061 (aref (cdr comment) 2))
2063 (defun mixi-comment-content (comment)
2064 "Return the content of COMMENT."
2065 (unless (mixi-comment-p comment)
2066 (signal 'wrong-type-argument (list 'mixi-comment-p comment)))
2067 (aref (cdr comment) 3))
2069 (defun mixi-diary-comment-list-page (diary)
2070 (concat "/view_diary.pl?full=1"
2071 "&id=" (mixi-diary-id diary)
2072 "&owner_id=" (mixi-friend-id (mixi-diary-owner diary))))
2074 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2075 (defconst mixi-diary-comment-list-regexp
2076 "<td rowspan=\"2\" align=\"center\" width=\"95\" bgcolor=\"#f2ddb7\" nowrap>
2077 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)\\(<br>
2078 <input type=checkbox name=comment_id value=\".+\">
2081 <td ALIGN=center BGCOLOR=#FDF9F2 WIDTH=430>
2082 <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"410\">
2085 <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2087 \\(<font color=\"#f2ddb7\">|</font> <a href=[^>]+>ºï½ü</a>
2094 <!-- [^ ]+ : start -->
2096 <td bgcolor=\"#ffffff\">
2097 <table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
2101 </td></tr></table>")
2103 (defun mixi-topic-comment-list-page (topic)
2104 (concat "/view_bbs.pl?page=all"
2105 "&id=" (mixi-topic-id topic)
2106 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2108 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2109 (defconst mixi-topic-comment-list-regexp
2110 "<tr valign=\"top\">
2111 <td rowspan=\"2\" width=\"110\" bgcolor=\"#f2ddb7\" align=\"center\" nowrap>
2112 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2113 \\([0-9]+\\):\\([0-9]+\\)<br>
2114 \\(<input type=\"checkbox\" name=\"comment_id\" value=\".+\">
2116 <td bgcolor=\"#fdf9f2\"> <font color=\"#f8a448\">
2117 <b>[^<]+</b>:</font>
2119 \\|\\) *<a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2123 \\|<font color=\"#f2ddb7\">| </font><a href=\"delete_bbs_comment\\.pl\\?id=[0-9]+&comm_id=[0-9]+&comment_id=[0-9]+\">ºï½ü</a>
2127 <td bgcolor=\"#ffffff\" align=\"center\">
2128 <table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"500\">
2139 (defun mixi-event-comment-list-page (event)
2140 (concat "/view_event.pl?page=all"
2141 "&id=" (mixi-event-id event)
2142 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2144 ;; FIXME: Split regexp to time, owner(id and nick) and contents.
2145 (defconst mixi-event-comment-list-regexp
2147 <td ROWSPAN=2 ALIGN=center BGCOLOR=#F2DDB7 WIDTH=110>
2148 \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
2149 \\([0-9]+\\):\\([0-9]+\\)<br>
2151 \\(<td BGCOLOR=#FDF9F2>\\)
2152 <font COLOR=#F8A448><b>[^<]+</b> :</font>
2153 <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>
2158 <td ALIGN=center BGCOLOR=#FFFFFF>
2159 <table BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=500>
2160 <tr><td CLASS=h120>\\(.+\\)</td></tr>
2165 (defun mixi-get-comments (parent &optional range)
2166 "Get comments of PARENT."
2167 (unless (mixi-object-p parent)
2168 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2169 (let* ((name (mixi-object-name parent))
2170 (list-page (intern (concat mixi-object-prefix name
2171 "-comment-list-page")))
2172 (regexp (eval (intern (concat mixi-object-prefix name
2173 "-comment-list-regexp")))))
2174 (let ((items (mixi-get-matched-items
2175 (funcall list-page parent) regexp)))
2178 (mapc (lambda (item)
2179 (when (and (numberp range)
2180 (>= (length list) range))
2182 (setq list (cons item list)))
2184 (setq items (reverse list)))
2185 (mapcar (lambda (item)
2186 (mixi-make-comment parent (mixi-make-friend
2187 (nth 7 item) (nth 8 item))
2190 (string-to-number (nth 4 item))
2191 (string-to-number (nth 3 item))
2192 (string-to-number (nth 2 item))
2193 (string-to-number (nth 1 item))
2194 (string-to-number (nth 0 item)))
2198 (defmacro mixi-new-comment-list-page ()
2199 `(concat "/new_comment.pl?page=%d"))
2201 (defconst mixi-new-comment-list-regexp
2202 "<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=\\([0-9]+\\)&comment_count=[0-9]+\" class=\"new_link\">")
2204 (defun mixi-get-new-comments (&optional range)
2206 (let ((items (mixi-get-matched-items (mixi-new-comment-list-page)
2207 mixi-new-comment-list-regexp
2209 (mapcar (lambda (item)
2210 (mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
2213 (defun mixi-post-diary-comment-page (diary)
2214 (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
2216 (defun mixi-post-topic-comment-page (topic)
2217 (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
2218 "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
2220 (defun mixi-post-event-comment-page (event)
2221 (concat "/add_event_comment.pl?id=" (mixi-event-id event)
2222 "&comm_id=" (mixi-community-id (mixi-event-community event))))
2224 ;; FIXME: Support photos.
2225 (defun mixi-post-comment (parent content)
2226 "Post a comment to PARENT."
2227 (unless (mixi-object-p parent)
2228 (signal 'wrong-type-argument (list 'mixi-object-p parent)))
2229 (unless (stringp content)
2230 (signal 'wrong-type-argument (list 'stringp content)))
2231 (let* ((name (mixi-object-name parent))
2232 (page (intern (concat mixi-object-prefix "post-" name
2235 (if (mixi-diary-p parent)
2237 `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2238 ("comment_body" . ,content)))
2239 (setq fields `(("comment" . ,content))))
2240 (with-mixi-post-form (funcall page parent) fields
2241 (if (string-match mixi-post-key-regexp buffer)
2242 (setq post-key (match-string 1 buffer))
2243 (mixi-post-error 'cannot-find-key parent)))
2244 (if (mixi-diary-p parent)
2246 `(("post_key" . ,post-key)
2247 ("owner_id" . ,(mixi-friend-id (mixi-diary-owner parent)))
2248 ("comment_body" . ,content)
2249 ("submit" . "confirm")))
2250 (setq fields `(("post_key" . ,post-key)
2251 ("comment" . ,content)
2252 ("submit" . "confirm"))))
2253 (with-mixi-post-form (funcall page parent) fields
2254 (unless (string-match mixi-post-succeed-regexp buffer)
2255 (mixi-post-error 'cannot-find-succeed parent)))))
2258 (defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
2260 (defmacro mixi-message-box-p (box)
2261 `(when (memq ,box mixi-message-box-list)
2264 (defun mixi-message-box-name (box)
2265 "Return the name of BOX."
2266 (unless (mixi-message-box-p box)
2267 (signal 'wrong-type-argument (list 'mixi-message-box-p box)))
2270 (defvar mixi-message-cache (make-hash-table :test 'equal))
2271 (defun mixi-make-message (id box &optional owner title time content)
2272 "Return a message object."
2273 (mixi-make-cache (list id box)
2274 (cons 'mixi-message (vector nil id box owner title time
2276 mixi-message-cache))
2278 (defconst mixi-message-url-regexp
2279 "/view_message\\.pl\\?id=\\([a-z0-9]+\\)&box=\\([a-z]+\\)")
2281 (defun mixi-make-message-from-url (url)
2282 "Return a message object from URL."
2283 (when (string-match mixi-message-url-regexp url)
2284 (let ((id (match-string 1 url))
2285 (box (match-string 2 url)))
2286 (mixi-make-message id box))))
2288 (defmacro mixi-message-p (message)
2289 `(eq (mixi-object-class ,message) 'mixi-message))
2291 (defmacro mixi-message-page (message)
2292 `(concat "/view_message.pl?id=" (mixi-message-id ,message)
2293 "&box=" (mixi-message-box ,message)))
2295 (defconst mixi-message-owner-regexp
2296 "<font COLOR=#996600>\\(º¹½Ð¿Í\\|°¸ Àè\\)</font> : <a HREF=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)\\(</a>\\|</td>\\)")
2297 (defconst mixi-message-title-regexp
2298 "<font COLOR=#996600>·ï\\(¡¡\\| \\)̾</font> : \\(.+\\)\n?</td>")
2299 (defconst mixi-message-time-regexp
2300 "<font COLOR=#996600>Æü\\(¡¡\\| \\)ÉÕ</font> : \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\)»þ\\([0-9]+\\)ʬ ")
2301 (defconst mixi-message-content-regexp
2302 "<tr><td CLASS=h120>\\(.+\\)</td></tr>")
2304 (defun mixi-realize-message (message)
2305 "Realize a MESSAGE."
2306 (unless (mixi-object-realized-p message)
2307 (with-mixi-retrieve (mixi-message-page message)
2308 (if (string-match mixi-message-owner-regexp buffer)
2309 (mixi-message-set-owner message
2310 (mixi-make-friend (match-string 2 buffer)
2311 (match-string 3 buffer)))
2312 (mixi-realization-error 'cannot-find-owner message))
2313 (if (string-match mixi-message-title-regexp buffer)
2314 (mixi-message-set-title message (match-string 2 buffer))
2315 (mixi-realization-error 'cannot-find-title message))
2316 (if (string-match mixi-message-time-regexp buffer)
2317 (mixi-message-set-time
2318 message (encode-time 0 (string-to-number (match-string 6 buffer))
2319 (string-to-number (match-string 5 buffer))
2320 (string-to-number (match-string 4 buffer))
2321 (string-to-number (match-string 3 buffer))
2322 (string-to-number (match-string 2 buffer))))
2323 (mixi-realization-error 'cannot-find-time message))
2324 (if (string-match mixi-message-content-regexp buffer)
2325 (mixi-message-set-content message (match-string 1 buffer))
2326 (mixi-realization-error 'cannot-find-content message)))
2327 (mixi-object-touch message)))
2329 (defun mixi-message-id (message)
2330 "Return the id of MESSAGE."
2331 (unless (mixi-message-p message)
2332 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2333 (aref (cdr message) 1))
2335 (defun mixi-message-box (message)
2336 "Return the box of MESSAGE."
2337 (unless (mixi-message-p message)
2338 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2339 (aref (cdr message) 2))
2341 (defun mixi-message-owner (message)
2342 "Return the owner of MESSAGE."
2343 (unless (mixi-message-p message)
2344 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2345 (mixi-realize-message message)
2346 (aref (cdr message) 3))
2348 (defun mixi-message-title (message)
2349 "Return the title of MESSAGE."
2350 (unless (mixi-message-p message)
2351 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2352 (mixi-realize-message message)
2353 (aref (cdr message) 4))
2355 (defun mixi-message-time (message)
2356 "Return the date of MESSAGE."
2357 (unless (mixi-message-p message)
2358 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2359 (mixi-realize-message message)
2360 (aref (cdr message) 5))
2362 (defun mixi-message-content (message)
2363 "Return the content of MESSAGE."
2364 (unless (mixi-message-p message)
2365 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2366 (mixi-realize-message message)
2367 (aref (cdr message) 6))
2369 (defun mixi-message-set-owner (message owner)
2370 "Set the owner of MESSAGE."
2371 (unless (mixi-message-p message)
2372 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2373 (aset (cdr message) 3 owner))
2375 (defun mixi-message-set-title (message title)
2376 "Set the title of MESSAGE."
2377 (unless (mixi-message-p message)
2378 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2379 (aset (cdr message) 4 title))
2381 (defun mixi-message-set-time (message time)
2382 "Set the date of MESSAGE."
2383 (unless (mixi-message-p message)
2384 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2385 (aset (cdr message) 5 time))
2387 (defun mixi-message-set-content (message content)
2388 "Set the content of MESSAGE."
2389 (unless (mixi-message-p message)
2390 (signal 'wrong-type-argument (list 'mixi-message-p message)))
2391 (aset (cdr message) 6 content))
2393 (defmacro mixi-message-list-page (&optional box)
2394 `(concat "/list_message.pl?page=%d"
2395 (when ,box (concat "&box=" ,box))))
2397 (defconst mixi-message-list-regexp
2398 "<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
2400 (defun mixi-get-messages (&rest box-or-range)
2401 "Get messages of BOX."
2402 (when (> (length box-or-range) 2)
2403 (signal 'wrong-number-of-arguments
2404 (list 'mixi-get-messages (length box-or-range))))
2405 (let ((box (nth 0 box-or-range))
2406 (range (nth 1 box-or-range)))
2407 (when (or (not (mixi-message-box-p box))
2408 (mixi-message-box-p range))
2409 (setq box (nth 1 box-or-range))
2410 (setq range (nth 0 box-or-range)))
2411 (let ((items (mixi-get-matched-items
2412 (mixi-message-list-page
2413 (when box (mixi-message-box-name box)))
2414 mixi-message-list-regexp
2416 (mapcar (lambda (item)
2417 (mixi-make-message (nth 0 item) (nth 1 item)))
2420 (defmacro mixi-post-message-page (friend)
2421 `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
2423 (defconst mixi-post-message-key-regexp
2424 "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
2426 (defconst mixi-post-message-succeed-regexp
2427 "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
2429 (defun mixi-post-message (friend title content)
2430 "Post a message to FRIEND."
2431 (unless (mixi-friend-p friend)
2432 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2433 (unless (stringp title)
2434 (signal 'wrong-type-argument (list 'stringp title)))
2435 (unless (stringp content)
2436 (signal 'wrong-type-argument (list 'stringp content)))
2437 (let ((fields `(("subject" . ,title)
2439 ("submit" . "main")))
2441 (with-mixi-post-form (mixi-post-message-page friend) fields
2442 (if (string-match mixi-post-message-key-regexp buffer)
2443 (setq post-key (match-string 1 buffer))
2444 (mixi-post-error 'cannot-find-key friend)))
2445 (setq fields `(("post_key" . ,post-key)
2446 ("subject" . ,title)
2448 ("yes" . "¡¡Á÷¡¡¿®¡¡")
2449 ("submit" . "confirm")))
2450 (with-mixi-post-form (mixi-post-message-page friend) fields
2451 (unless (string-match mixi-post-message-succeed-regexp buffer)
2452 (mixi-post-error 'cannot-find-succeed friend)))))
2454 ;; Introduction object.
2455 (defun mixi-make-introduction (parent owner content)
2456 "Return a introduction object."
2457 (cons 'mixi-introduction (vector parent owner content)))
2459 (defmacro mixi-introduction-p (introduction)
2460 `(eq (mixi-object-class ,introduction) 'mixi-introduction))
2462 (defun mixi-introduction-parent (introduction)
2463 "Return the parent of INTRODUCTION."
2464 (unless (mixi-introduction-p introduction)
2465 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2466 (aref (cdr introduction) 0))
2468 (defun mixi-introduction-owner (introduction)
2469 "Return the owner of INTRODUCTION."
2470 (unless (mixi-introduction-p introduction)
2471 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2472 (aref (cdr introduction) 1))
2474 (defun mixi-introduction-content (introduction)
2475 "Return the content of INTRODUCTION."
2476 (unless (mixi-introduction-p introduction)
2477 (signal 'wrong-type-argument (list 'mixi-introduction-p introduction)))
2478 (aref (cdr introduction) 3))
2480 (defmacro mixi-introduction-list-page (&optional friend)
2481 `(concat "/show_intro.pl?page=%d"
2482 (when ,friend (concat "&id=" (mixi-friend-id ,friend)))))
2484 (defconst mixi-introduction-list-regexp
2485 "<tr bgcolor=#FFFFFF>
2486 <td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
2493 \\(\\(.\\|\n<br>\\)+\\)\\|
2494 \\(\\(.\\|\n<br>\\)+\\)\\)
2501 (defconst mixi-my-introduction-list-regexp
2502 "<tr bgcolor=#FFFFFF>
2503 <td WIDTH=150 background=http://img\\.mixi\\.jp/img/bg_line\\.gif align=\"center\"><a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\"><img src=\".+\" border=0><br>
2511 \\(\\(.\\|\n<br>\\)+\\)\\|
2512 \\(\\(.\\|\n<br>\\)+\\)\\)
2516 <a href=\"edit_intro\\.pl\\?id=\\1&type=edit\">¤³¤Îͧ¿Í¤ò¾Ò²ð¤¹¤ë</a>
2520 <a href=\"delete_intro\\.pl\\?id=\\1\">ºï½ü</a>
2525 (defun mixi-get-introductions (&rest friend-or-range)
2526 "Get introductions of FRIEND."
2527 (when (> (length friend-or-range) 2)
2528 (signal 'wrong-number-of-arguments
2529 (list 'mixi-get-introduction (length friend-or-range))))
2530 (let ((friend (nth 0 friend-or-range))
2531 (range (nth 1 friend-or-range)))
2532 (when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
2533 (setq friend (nth 1 friend-or-range))
2534 (setq range (nth 0 friend-or-range)))
2535 (unless (or (null friend) (mixi-friend-p friend))
2536 (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
2537 (let* ((regexp (if friend mixi-introduction-list-regexp
2538 mixi-my-introduction-list-regexp))
2539 (items (mixi-get-matched-items (mixi-introduction-list-page friend)
2542 (mapcar (lambda (item)
2543 (mixi-make-introduction (or friend (mixi-make-me))
2544 (mixi-make-friend (nth 0 item)
2551 ;;; mixi.el ends here