;; * mixi-get-new-comments
;; * mixi-get-messages
;; * mixi-get-introductions
+;;
+;; API for posting:
+;;
+;; * mixi-post-diary
+;; * mixi-post-topic
+;; * mixi-post-comment
+;; * mixi-post-message
;;
;; Utilities:
;;
:type 'file
:group 'mixi)
-(defcustom mixi-curl-cookie-file (expand-file-name "~/.mixi-cookies.txt")
+(defcustom mixi-curl-cookie-file (expand-file-name "cookies.txt"
+ mixi-directory)
"*The location of cookie file created by `curl'."
:type 'file
:group 'mixi)
(defmacro mixi-message (&rest strings)
`(concat "[mixi] " ,@strings))
+(put 'mixi-realization-error
+ 'error-message (mixi-message "Cannot realize object"))
+(put 'mixi-realization-error
+ 'error-conditions '(mixi-realization-error error))
+
+(put 'mixi-post-error
+ 'error-message (mixi-message "Cannot post"))
+(put 'mixi-post-error
+ 'error-conditions '(mixi-post-error error))
+
+(defmacro mixi-realization-error (type object)
+ `(let ((data (if (and (boundp 'buffer) debug-on-error)
+ (list ,type ,object buffer)
+ (list ,type ,object))))
+ (signal 'mixi-realization-error data)))
+
+(defmacro mixi-post-error (type &optional object)
+ `(let ((data (when (and (boundp 'buffer) debug-on-error)
+ (list buffer))))
+ (if ,object
+ (setq data (cons ,type (cons ,object data)))
+ (setq data (cons ,type data)))
+ (signal 'mixi-post-error data)))
+
(defconst mixi-message-adult-contents
"¤³¤Î¥Ú¡¼¥¸¤«¤éÀè¤Ï¥¢¥À¥ë¥È¡ÊÀ®¿Í¸þ¤±¡Ë¥³¥ó¥Æ¥ó¥Ä¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£<br>
±ÜÍ÷¤ËƱ°Õ¤µ¤ì¤¿Êý¤Î¤ß¡¢Àè¤Ø¤ª¿Ê¤ß¤¯¤À¤µ¤¤¡£")
(defmacro mixi-retrieve (url &optional post-data)
`(funcall mixi-retrieve-function ,url ,post-data))
+;; FIXME: Change `mixi-retrieve-function' to `mixi-backend'.
+(defmacro mixi-post-form (url fields)
+ `(let ((name (symbol-name mixi-retrieve-function)))
+ (when (string-match "-\\([a-z]+\\)-" name)
+ (let ((func (intern (concat "mixi-" (match-string 1 name)
+ "-post-form"))))
+ (funcall func ,url ,fields)))))
+
(defun mixi-parse-buffer (url buffer &optional post-data)
(when (string-match mixi-message-adult-contents buffer)
(if mixi-accept-adult-contents
(if (not (string-match mixi-message-continuously-accessing buffer))
buffer
(message (mixi-message "Waiting for continuously accessing..."))
- (sit-for mixi-continuously-access-interval)
+ (sleep-for mixi-continuously-access-interval)
(mixi-retrieve url post-data)))
(defmacro mixi-expand-url (url)
,url
(concat mixi-url ,url)))
-(defun mixi-url-retrieve (url &optional post-data)
+;; FIXME: Support file, checkbox and so on.
+(defun mixi-make-form-data (fields)
+ "Make form data and return (CONTENT-TYPE . FORM-DATA)."
+ (let* ((boundary (apply 'format "--_%d_%d_%d" (current-time)))
+ (content-type (concat "multipart/form-data; boundary=" boundary))
+ (form-data
+ (mapconcat
+ (lambda (field)
+ (concat "--" boundary "\r\n"
+ "Content-Disposition: form-data; name=\""
+ (car field) "\"\r\n"
+ "\r\n"
+ (encode-coding-string (cdr field) mixi-coding-system)))
+ fields "\r\n")))
+ (cons content-type (concat form-data "\r\n--" boundary "--"))))
+
+(defun mixi-url-retrieve (url &optional post-data extra-headers)
"Retrieve the URL and return gotten strings."
- (if post-data
- (progn
- (setq url-request-method "POST")
- (setq url-request-data post-data))
- (setq url-request-method "GET")
- (setq url-request-data nil))
- (let* ((url (mixi-expand-url url))
+ (let* ((url-request-method (if post-data "POST" "GET"))
+ (url-request-data post-data)
+ (url-request-extra-headers extra-headers)
+ (url (mixi-expand-url url))
(buffer (url-retrieve-synchronously url))
ret)
(unless (bufferp buffer)
(kill-buffer buffer)
(mixi-parse-buffer url ret post-data))))
+(defun mixi-url-post-form (url fields)
+ (let* ((form-data (mixi-make-form-data fields))
+ (extra-headers `(("Content-Type" . ,(car form-data)))))
+ (mixi-url-retrieve url (cdr form-data) extra-headers)))
+
(defun mixi-w3m-retrieve (url &optional post-data)
"Retrieve the URL and return gotten strings."
(let ((url (mixi-expand-url url)))
(let ((ret (buffer-substring-no-properties (point-min) (point-max))))
(mixi-parse-buffer url ret post-data))))))
+(defun mixi-w3m-post-form (url fields)
+ (let ((form-data (mixi-make-form-data fields)))
+ (mixi-w3m-retrieve url form-data)))
+
(defun mixi-curl-retrieve (url &optional post-data)
"Retrieve the URL and return gotten strings."
(with-temp-buffer
`(let (buffer)
(when ,url
(setq buffer (mixi-retrieve ,url))
- (when (string-match "login.pl" buffer)
+ (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
+ buffer)
(mixi-login)
(setq buffer (mixi-retrieve ,url))))
,@body))
(put 'with-mixi-retrieve 'lisp-indent-function 'defun)
(put 'with-mixi-retrieve 'edebug-form-spec '(form body))
+(defmacro with-mixi-post-form (url fields &rest body)
+ `(let (buffer)
+ (when ,url
+ (setq buffer (mixi-post-form ,url ,fields))
+ (when (string-match "<form action=\"login\\.pl\" method=\"post\">"
+ buffer)
+ (mixi-login)
+ (setq buffer (mixi-post-form ,url ,fields))))
+ ,@body))
+(put 'with-mixi-post-form 'lisp-indent-function 'defun)
+(put 'with-mixi-post-form 'edebug-form-spec '(form body))
+
(defun mixi-get-matched-items (url regexp &optional range)
"Get matched items to REGEXP in URL."
(let ((page 1)
(unless (mixi-object-p object)
(signal 'wrong-type-argument (list 'mixi-object-p object)))
(aref (cdr object) 0))
-(defalias 'mixi-object-realize-p 'mixi-object-timestamp)
+(defalias 'mixi-object-realized-p 'mixi-object-timestamp)
(defun mixi-object-owner (object)
"Return the owner of OBJECT."
mixi-cache-file-regexp))
(defun mixi-save-cache ()
- (unless (file-directory-p mixi-directory)
- (make-directory mixi-directory t))
- (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
- (mapc (lambda (symbol)
- (with-temp-file (expand-file-name
- (substring (symbol-name symbol)
- (length mixi-object-prefix))
- mixi-directory)
- (let ((coding-system-for-write mixi-coding-system)
- (cache (symbol-value symbol)))
- (insert "#s(hash-table size "
- (number-to-string (hash-table-count cache))
- " test equal data (\n")
- (maphash
- (lambda (key value)
- (let (print-level print-length)
- (insert (prin1-to-string key) " "
- (prin1-to-string value) "\n")))
- cache))
- (insert "))")))
- caches)))
+ (let ((cache-directory (expand-file-name "cache" mixi-directory)))
+ (unless (file-directory-p cache-directory)
+ (make-directory cache-directory t))
+ (let ((caches (apropos-internal mixi-cache-regexp 'boundp)))
+ (mapc (lambda (symbol)
+ (with-temp-file (expand-file-name
+ (substring (symbol-name symbol)
+ (length mixi-object-prefix))
+ cache-directory)
+ (let ((coding-system-for-write mixi-coding-system)
+ (cache (symbol-value symbol)))
+ (insert "#s(hash-table size "
+ (number-to-string (hash-table-count cache))
+ " test equal data (\n")
+ (maphash
+ (lambda (key value)
+ (let (print-level print-length)
+ (insert (prin1-to-string key) " "
+ (prin1-to-string value) "\n")))
+ cache))
+ (insert "))")))
+ caches))))
;; stolen (and modified) from lsdb.el
(defun mixi-read-cache (&optional marker)
(read marker))))
(defun mixi-load-cache ()
- (when (file-directory-p mixi-directory)
- ;; FIXME: Load friend and community first.
- (let ((files (directory-files mixi-directory t mixi-cache-file-regexp)))
- (mapc (lambda (file)
- (let ((buffer (find-file-noselect file)))
- (unwind-protect
- (save-excursion
- (set-buffer buffer)
- (goto-char (point-min))
- (re-search-forward "^#s(")
- (goto-char (match-beginning 0))
- (mixi-read-cache (point-marker)))
- (kill-buffer buffer))))
- files))))
+ (let ((cache-directory (expand-file-name "cache" mixi-directory)))
+ (when (file-directory-p cache-directory)
+ ;; FIXME: Load friend and community first.
+ (let ((files (directory-files cache-directory t
+ mixi-cache-file-regexp)))
+ (mapc (lambda (file)
+ (let ((buffer (find-file-noselect file)))
+ (unwind-protect
+ (save-excursion
+ (set-buffer buffer)
+ (goto-char (point-min))
+ (re-search-forward "^#s(")
+ (goto-char (match-beginning 0))
+ (mixi-read-cache (point-marker)))
+ (kill-buffer buffer))))
+ files)))))
;; Friend object.
(defvar mixi-friend-cache (make-hash-table :test 'equal))
`(concat "/show_friend.pl?id=" (mixi-friend-id ,friend)))
(defconst mixi-friend-nick-regexp
- "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>\r?\n\\(.*\\)¤µ¤ó([0-9]+)")
-(defconst mixi-friend-name-sex-regexp
- "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\( \\| \\)Á°</font></td>\n+<td WIDTH=345>\\([^<]+\\) (\\([Ã˽÷]\\)À)</td>")
+ "<img alt=\"\\*\" src=\"http://img\\.mixi\\.jp/img/dot0\\.gif\" width=\"1\" height=\"5\"><br>\r?
+\\(.*\\)¤µ¤ó([0-9]+)")
+(defconst mixi-friend-name-regexp
+ "<td BGCOLOR=#F2DDB7 WIDTH=80 NOWRAP><font COLOR=#996600>̾\\( \\| \\)Á°</font></td>
+
+?<td WIDTH=345>\\(.+?\\)\\(</td>\\|<img\\)")
+(defconst mixi-friend-sex-regexp
+ "<td BGCOLOR=#F2DDB7\\( WIDTH=80 NOWRAP\\)?><font COLOR=#996600>À\\( \\| \\)ÊÌ</font></td>
+
+?<td WIDTH=345>\\([Ã˽÷]\\)À\\(</td>\\|<img\\)")
(defconst mixi-friend-address-regexp
"<td BGCOLOR=#F2DDB7><font COLOR=#996600>¸½½»½ê</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
(defconst mixi-friend-age-regexp
(defconst mixi-friend-birthplace-regexp
"<td BGCOLOR=#F2DDB7><font COLOR=#996600>½Ð¿ÈÃÏ</font>\n?</td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
(defconst mixi-friend-hobby-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+\\)</td></tr>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼ñ\\( \\| \\)Ì£</font></td>\n<td>\\(.+?\\)\\(</td>\\|<img\\)")
(defconst mixi-friend-job-regexp
"<td BGCOLOR=#F2DDB7><font COLOR=#996600>¿¦\\( \\| \\)¶È</font></td>\n<td>\\(.+\\)\\(\n.+\n\\)?</td></tr>")
(defconst mixi-friend-organization-regexp
(defconst mixi-friend-profile-regexp
"<td BGCOLOR=#F2DDB7><font COLOR=#996600>¼«¸Ê¾Ò²ð</font></td>\n<td CLASS=h120>\\(.+\\)</td></tr>")
-(defun mixi-friend-realize (friend)
+(defun mixi-realize-friend (friend)
"Realize a FRIEND."
;; FIXME: Check a expiration of cache?
- (unless (mixi-object-realize-p friend)
+ (unless (mixi-object-realized-p friend)
(let (buf)
(with-mixi-retrieve (mixi-friend-page friend)
(setq buf buffer))
(if (string-match mixi-friend-nick-regexp buf)
(mixi-friend-set-nick friend (match-string 1 buf))
- (signal 'error (list 'cannot-find-nick friend)))
+ (mixi-realization-error 'cannot-find-nick friend))
;; For getting my profile.
- (unless (string-match mixi-friend-name-sex-regexp buf)
+ (unless (string-match mixi-friend-name-regexp buf)
(with-mixi-retrieve (concat "/show_profile.pl?id="
(mixi-friend-id friend))
(setq buf buffer)))
- (if (string-match mixi-friend-name-sex-regexp buf)
- (progn
+ (if (string-match mixi-friend-name-regexp buf)
(mixi-friend-set-name friend (match-string 2 buf))
- (mixi-friend-set-sex friend
- (if (string= (match-string 3 buf) "ÃË")
- 'male 'female)))
- (signal 'error (list 'cannot-find-name-or-sex friend)))
+ (mixi-realization-error 'cannot-find-name friend))
+ (if (string-match mixi-friend-sex-regexp buf)
+ (mixi-friend-set-sex friend
+ (if (string= (match-string 3 buf) "ÃË")
+ 'male 'female))
+ (mixi-realization-error 'cannot-find-sex friend))
(when (string-match mixi-friend-address-regexp buf)
(mixi-friend-set-address friend (match-string 1 buf)))
(when (string-match mixi-friend-age-regexp buf)
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(unless (aref (cdr friend) 2)
- (mixi-friend-realize friend))
+ (mixi-realize-friend friend))
(aref (cdr friend) 2))
(defun mixi-friend-name (friend)
"Return the name of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 3))
(defun mixi-friend-sex (friend)
"Return the sex of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 4))
(defun mixi-friend-address (friend)
"Return the address of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 5))
(defun mixi-friend-age (friend)
"Return the age of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 6))
(defun mixi-friend-birthday (friend)
"Return the birthday of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 7))
(defun mixi-friend-blood-type (friend)
"Return the blood type of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 8))
(defun mixi-friend-birthplace (friend)
"Return the birthplace of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 9))
(defun mixi-friend-hobby (friend)
"Return the hobby of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 10))
(defun mixi-friend-job (friend)
"Return the job of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 11))
(defun mixi-friend-organization (friend)
"Return the organization of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 12))
(defun mixi-friend-profile (friend)
"Return the pforile of FRIEND."
(unless (mixi-friend-p friend)
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
- (mixi-friend-realize friend)
+ (mixi-realize-friend friend)
(aref (cdr friend) 13))
(defun mixi-friend-set-nick (friend nick)
(defconst mixi-friend-list-nick-regexp
"<td valign=middle>\\(.+\\)¤µ¤ó([0-9]+)<br />")
-(defun mixi-get-friends (&rest args)
+(defun mixi-get-friends (&rest friend-or-range)
"Get friends of FRIEND."
- (when (> (length args) 2)
- (signal 'wrong-number-of-arguments (list 'mixi-get-friends (length args))))
- (let ((friend (nth 0 args))
- (range (nth 1 args)))
+ (when (> (length friend-or-range) 2)
+ (signal 'wrong-number-of-arguments (list 'mixi-get-friends
+ (length friend-or-range))))
+ (let ((friend (nth 0 friend-or-range))
+ (range (nth 1 friend-or-range)))
(when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
- (setq friend (nth 1 args))
- (setq range (nth 0 args)))
+ (setq friend (nth 1 friend-or-range))
+ (setq range (nth 0 friend-or-range)))
(unless (or (null friend) (mixi-friend-p friend))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(let ((ids (mixi-get-matched-items (mixi-friend-list-page friend)
(defconst mixi-diary-content-regexp
"<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
-(defun mixi-diary-realize (diary)
+(defun mixi-realize-diary (diary)
"Realize a DIARY."
;; FIXME: Check a expiration of cache?
- (unless (mixi-object-realize-p diary)
+ (unless (mixi-object-realized-p diary)
(with-mixi-retrieve (mixi-diary-page diary)
(unless (string-match mixi-diary-closed-regexp buffer)
(if (string-match mixi-diary-owner-nick-regexp buffer)
(mixi-friend-set-nick (mixi-diary-owner diary)
(match-string 1 buffer))
- (signal 'error (list 'cannot-find-owner-nick diary)))
+ (mixi-realization-error 'cannot-find-owner-nick diary))
(if (string-match mixi-diary-time-regexp buffer)
(mixi-diary-set-time
diary (encode-time 0 (string-to-number (match-string 10 buffer))
(string-to-number (match-string 7 buffer))
(string-to-number (match-string 6 buffer))
(string-to-number (match-string 5 buffer))))
- (signal 'error (list 'cannot-find-time diary)))
+ (mixi-realization-error 'cannot-find-time diary))
(if (string-match mixi-diary-title-regexp buffer)
(mixi-diary-set-title diary (match-string 2 buffer))
- (signal 'error (list 'cannot-find-title diary)))
+ (mixi-realization-error 'cannot-find-title diary))
(if (string-match mixi-diary-content-regexp buffer)
(mixi-diary-set-content diary (match-string 2 buffer))
- (signal 'error (list 'cannot-find-content diary)))))
+ (mixi-realization-error 'cannot-find-content diary))))
(mixi-object-touch diary)))
(defun mixi-diary-owner (diary)
"Return the time of DIARY."
(unless (mixi-diary-p diary)
(signal 'wrong-type-argument (list 'mixi-diary-p diary)))
- (mixi-diary-realize diary)
+ (mixi-realize-diary diary)
(aref (cdr diary) 3))
(defun mixi-diary-title (diary)
"Return the title of DIARY."
(unless (mixi-diary-p diary)
(signal 'wrong-type-argument (list 'mixi-diary-p diary)))
- (mixi-diary-realize diary)
+ (mixi-realize-diary diary)
(aref (cdr diary) 4))
(defun mixi-diary-content (diary)
"Return the content of DIARY."
(unless (mixi-diary-p diary)
(signal 'wrong-type-argument (list 'mixi-diary-p diary)))
- (mixi-diary-realize diary)
+ (mixi-realize-diary diary)
(aref (cdr diary) 5))
(defun mixi-diary-set-time (diary time)
(defconst mixi-diary-list-regexp
"<a href=\"view_diary\\.pl\\?id=\\([0-9]+\\)&owner_id=[0-9]+\">")
-(defun mixi-get-diaries (&rest args)
+(defun mixi-get-diaries (&rest friend-or-range)
"Get diaries of FRIEND."
- (when (> (length args) 2)
+ (when (> (length friend-or-range) 2)
(signal 'wrong-number-of-arguments
- (list 'mixi-get-diaries (length args))))
- (let ((friend (nth 0 args))
- (range (nth 1 args)))
+ (list 'mixi-get-diaries (length friend-or-range))))
+ (let ((friend (nth 0 friend-or-range))
+ (range (nth 1 friend-or-range)))
(when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
- (setq friend (nth 1 args))
- (setq range (nth 0 args)))
+ (setq friend (nth 1 friend-or-range))
+ (setq range (nth 0 friend-or-range)))
(unless (or (null friend) (mixi-friend-p friend))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(let ((items (mixi-get-matched-items (mixi-diary-list-page friend)
(mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
items)))
+(defmacro mixi-post-diary-page ()
+ `(concat "/add_diary.pl"))
+
+(defconst mixi-post-key-regexp
+ "<input type=\"?hidden\"? name=\"?post_key\"? value=\"\\([a-z0-9]+\\)\">")
+(defconst mixi-post-succeed-regexp
+ "<b>\\(ºîÀ®\\|½ñ¤¹þ¤ß\\)¤¬´°Î»¤·¤Þ¤·¤¿¡£È¿±Ç¤Ë»þ´Ö¤¬¤«¤«¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢É½¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¾¯¡¹¤ªÂÔ¤Á¤¯¤À¤µ¤¤¡£</b>")
+
+;; FIXME: Support photos.
+(defun mixi-post-diary (title content)
+ "Post a diary."
+ (unless (stringp title)
+ (signal 'wrong-type-argument (list 'stringp title)))
+ (unless (stringp content)
+ (signal 'wrong-type-argument (list 'stringp content)))
+ (let ((fields `(("id" . ,(mixi-friend-id (mixi-make-me)))
+ ("diary_title" . ,title)
+ ("diary_body" . ,content)
+ ("submit" . "main")))
+ post-key)
+ (with-mixi-post-form (mixi-post-diary-page) fields
+ (if (string-match mixi-post-key-regexp buffer)
+ (setq post-key (match-string 1 buffer))
+ (mixi-post-error 'cannot-find-key)))
+ (setq fields `(("post_key" . ,post-key)
+ ("id" . ,(mixi-friend-id (mixi-make-me)))
+ ("diary_title" . ,title)
+ ("diary_body" . ,content)
+ ("submit" . "confirm")))
+ (with-mixi-post-form (mixi-post-diary-page) fields
+ (unless (string-match mixi-post-succeed-regexp buffer)
+ (mixi-post-error 'cannot-find-succeed)))))
+
;; Community object.
(defvar mixi-community-cache (make-hash-table :test 'equal))
(defun mixi-make-community (id &optional name birthday owner category members
(defconst mixi-community-name-regexp
"<td WIDTH=345>\\(.*\\)</td></tr>")
(defconst mixi-community-birthday-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>³«ÀßÆü</font></td>\n<td>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>³«ÀßÆü</font></td>\r
+<td>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
;; FIXME: Care when the owner has seceded.
(defconst mixi-community-owner-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>´ÉÍý¿Í</font></td>\n<td>\n\n<a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\n\\(.*\\)</a>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>´ÉÍý¿Í</font></td>\r
+<td>\r
+\r
+<a href=\"\\(home\\.pl\\|show_friend\\.pl\\?id=\\([0-9]+\\)\\)\">\r
+\\(.*\\)</a>")
(defconst mixi-community-category-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>\n<td>\\([^<]+\\)</td>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥«¥Æ¥´¥ê</font></td>\r
+<td>\\([^<]+\\)</td>")
(defconst mixi-community-members-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>\n<td>\\([0-9]+\\)¿Í</td></tr>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥á¥ó¥Ð¡¼¿ô</font></td>\r
+<td>\\([0-9]+\\)¿Í</td></tr>")
(defconst mixi-community-open-level-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>»²²Ã¾ò·ï¤È<br>¸ø³«¥ì¥Ù¥ë</font></td>\r
<td>\\(.+\\)</td></tr>")
(defconst mixi-community-authority-regexp
- "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>\n<td>\\(.+\\)</td></tr>")
+ "<td BGCOLOR=#F2DDB7><font COLOR=#996600>¥È¥Ô¥Ã¥¯ºîÀ®¤Î¸¢¸Â</font></td>\r
+<td>\\(.+\\)</td></tr>")
(defconst mixi-community-description-regexp
"<td CLASS=h120>\\(.+\\)</td>")
-(defun mixi-community-realize (community)
+(defun mixi-realize-community (community)
"Realize a COMMUNITY."
;; FIXME: Check a expiration of cache?
- (unless (mixi-object-realize-p community)
+ (unless (mixi-object-realized-p community)
(with-mixi-retrieve (mixi-community-page community)
(if (string-match mixi-community-nodata-regexp buffer)
;; FIXME: Set all members?
(mixi-community-set-name community "¥Ç¡¼¥¿¤¬¤¢¤ê¤Þ¤»¤ó")
(if (string-match mixi-community-name-regexp buffer)
(mixi-community-set-name community (match-string 1 buffer))
- (signal 'error (list 'cannot-find-name community)))
+ (mixi-realization-error 'cannot-find-name community))
(if (string-match mixi-community-birthday-regexp buffer)
(mixi-community-set-birthday
community
(encode-time 0 0 0 (string-to-number (match-string 3 buffer))
(string-to-number (match-string 2 buffer))
(string-to-number (match-string 1 buffer))))
- (signal 'error (list 'cannot-find-birthday community)))
+ (mixi-realization-error 'cannot-find-birthday community))
(if (string-match mixi-community-owner-regexp buffer)
(if (string= (match-string 1 buffer) "home.pl")
(mixi-community-set-owner community (mixi-make-me))
(mixi-community-set-owner
community (mixi-make-friend (match-string 2 buffer)
(match-string 3 buffer))))
- (signal 'error (list 'cannot-find-owner community)))
+ (mixi-realization-error 'cannot-find-owner community))
(if (string-match mixi-community-category-regexp buffer)
(mixi-community-set-category community (match-string 1 buffer))
- (signal 'error (list 'cannot-find-category community)))
+ (mixi-realization-error 'cannot-find-category community))
(if (string-match mixi-community-members-regexp buffer)
(mixi-community-set-members
community (string-to-number (match-string 1 buffer)))
- (signal 'error (list 'cannot-find-members community)))
+ (mixi-realization-error 'cannot-find-members community))
(if (string-match mixi-community-open-level-regexp buffer)
(mixi-community-set-open-level community (match-string 1 buffer))
- (signal 'error (list 'cannot-find-open-level community)))
+ (mixi-realization-error 'cannot-find-open-level community))
(if (string-match mixi-community-authority-regexp buffer)
(mixi-community-set-authority community (match-string 1 buffer))
- (signal 'error (list 'cannot-find-authority community)))
+ (mixi-realization-error 'cannot-find-authority community))
(if (string-match mixi-community-description-regexp buffer)
(mixi-community-set-description community (match-string 1 buffer))
- (signal 'error (list 'cannot-find-description community)))))
+ (mixi-realization-error 'cannot-find-description community))))
(mixi-object-touch community)))
(defun mixi-community-id (community)
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
(unless (aref (cdr community) 2)
- (mixi-community-realize community))
+ (mixi-realize-community community))
(aref (cdr community) 2))
(defun mixi-community-birthday (community)
"Return the birthday of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 3))
(defun mixi-community-owner (community)
"Return the owner of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 4))
(defun mixi-community-category (community)
"Return the category of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 5))
(defun mixi-community-members (community)
"Return the members of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 6))
(defun mixi-community-open-level (community)
"Return the open-level of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 7))
(defun mixi-community-authority (community)
"Return the authority of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 8))
(defun mixi-community-description (community)
"Return the description of COMMUNITY."
(unless (mixi-community-p community)
(signal 'wrong-type-argument (list 'mixi-community-p community)))
- (mixi-community-realize community)
+ (mixi-realize-community community)
(aref (cdr community) 9))
(defun mixi-community-set-name (community name)
(defconst mixi-community-list-name-regexp
"<td valign=middle>\\(.+\\)([0-9]+)</td>")
-(defun mixi-get-communities (&rest args)
+(defun mixi-get-communities (&rest friend-or-range)
"Get communities of FRIEND."
- (when (> (length args) 2)
+ (when (> (length friend-or-range) 2)
(signal 'wrong-number-of-arguments
- (list 'mixi-get-communities (length args))))
- (let ((friend (nth 0 args))
- (range (nth 1 args)))
+ (list 'mixi-get-communities (length friend-or-range))))
+ (let ((friend (nth 0 friend-or-range))
+ (range (nth 1 friend-or-range)))
(when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
- (setq friend (nth 1 args))
- (setq range (nth 0 args)))
+ (setq friend (nth 1 friend-or-range))
+ (setq range (nth 0 friend-or-range)))
(unless (or (null friend) (mixi-friend-p friend))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(let ((ids (mixi-get-matched-items (mixi-community-list-page friend)
`(concat "/view_bbs.pl?id=" (mixi-topic-id ,topic)
"&comm_id=" (mixi-community-id (mixi-topic-community ,topic))))
+(defconst mixi-topic-community-regexp
+ "<td width=\"595\" background=\"http://img\\.mixi\\.jp/img/bg_w\\.gif\"><b>\\[\\(.+\\)\\] ¥È¥Ô¥Ã¥¯</b></td>")
(defconst mixi-topic-time-regexp
"<td rowspan=\"3\" width=\"110\" bgcolor=\"#ffd8b0\" align=\"center\" valign=\"top\" nowrap>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>\\([0-9]+\\):\\([0-9]+\\)</td>")
(defconst mixi-topic-title-regexp
(defconst mixi-topic-content-regexp
"<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>")
-(defun mixi-topic-realize (topic)
+(defun mixi-realize-topic (topic)
"Realize a TOPIC."
;; FIXME: Check a expiration of cache?
- (unless (mixi-object-realize-p topic)
+ (unless (mixi-object-realized-p topic)
(with-mixi-retrieve (mixi-topic-page topic)
+ (if (string-match mixi-topic-community-regexp buffer)
+ (mixi-community-set-name (mixi-topic-community topic)
+ (match-string 1 buffer))
+ (mixi-realization-error 'cannot-find-community topic))
(if (string-match mixi-topic-time-regexp buffer)
(mixi-topic-set-time
topic (encode-time 0 (string-to-number (match-string 5 buffer))
(string-to-number (match-string 3 buffer))
(string-to-number (match-string 2 buffer))
(string-to-number (match-string 1 buffer))))
- (signal 'error (list 'cannot-find-time topic)))
+ (mixi-realization-error 'cannot-find-time topic))
(if (string-match mixi-topic-title-regexp buffer)
(mixi-topic-set-title topic (match-string 1 buffer))
- (signal 'error (list 'cannot-find-title topic)))
+ (mixi-realization-error 'cannot-find-title topic))
(if (string-match mixi-topic-owner-regexp buffer)
(mixi-topic-set-owner topic
(mixi-make-friend (match-string 1 buffer)
(match-string 2 buffer)))
- (signal 'error (list 'cannot-find-owner topic)))
+ (mixi-realization-error 'cannot-find-owner topic))
(if (string-match mixi-topic-content-regexp buffer)
(mixi-topic-set-content topic (match-string 2 buffer))
- (signal 'error (list 'cannot-find-content topic))))
+ (mixi-realization-error 'cannot-find-content topic)))
(mixi-object-touch topic)))
(defun mixi-topic-community (topic)
"Return the time of TOPIC."
(unless (mixi-topic-p topic)
(signal 'wrong-type-argument (list 'mixi-topic-p topic)))
- (mixi-topic-realize topic)
+ (mixi-realize-topic topic)
(aref (cdr topic) 3))
(defun mixi-topic-title (topic)
"Return the title of TOPIC."
(unless (mixi-topic-p topic)
(signal 'wrong-type-argument (list 'mixi-topic-p topic)))
- (mixi-topic-realize topic)
+ (mixi-realize-topic topic)
(aref (cdr topic) 4))
(defun mixi-topic-owner (topic)
"Return the owner of TOPIC."
(unless (mixi-topic-p topic)
(signal 'wrong-type-argument (list 'mixi-topic-p topic)))
- (mixi-topic-realize topic)
+ (mixi-realize-topic topic)
(aref (cdr topic) 5))
(defun mixi-topic-content (topic)
"Return the content of TOPIC."
(unless (mixi-topic-p topic)
(signal 'wrong-type-argument (list 'mixi-topic-p topic)))
- (mixi-topic-realize topic)
+ (mixi-realize-topic topic)
(aref (cdr topic) 6))
(defun mixi-topic-set-time (topic time)
(signal 'wrong-type-argument (list 'mixi-topic-p topic)))
(aset (cdr topic) 6 content))
+(defmacro mixi-post-topic-page (community)
+ `(concat "/add_bbs.pl?id=" (mixi-community-id community)))
+
+;; FIXME: Support photos.
+(defun mixi-post-topic (community title content)
+ "Post a topic to COMMUNITY."
+ (unless (mixi-community-p community)
+ (signal 'wrong-type-argument (list 'mixi-community-p community)))
+ (unless (stringp title)
+ (signal 'wrong-type-argument (list 'stringp title)))
+ (unless (stringp content)
+ (signal 'wrong-type-argument (list 'stringp content)))
+ (let ((fields `(("bbs_title" . ,title)
+ ("bbs_body" . ,content)
+ ("submit" . "main")))
+ post-key)
+ (with-mixi-post-form (mixi-post-topic-page community) fields
+ (if (string-match mixi-post-key-regexp buffer)
+ (setq post-key (match-string 1 buffer))
+ (mixi-post-error 'cannot-find-key community)))
+ (setq fields `(("post_key" . ,post-key)
+ ("bbs_title" . ,title)
+ ("bbs_body" . ,content)
+ ("submit" . "confirm")))
+ (with-mixi-post-form (mixi-post-topic-page community) fields
+ (unless (string-match mixi-post-succeed-regexp buffer)
+ (mixi-post-error 'cannot-find-succeed community)))))
+
;; Event object.
(defvar mixi-event-cache (make-hash-table :test 'equal))
(defun mixi-make-event (community id &optional time title owner date place
`(concat "/view_event.pl?id=" (mixi-event-id ,event)
"&comm_id=" (mixi-community-id (mixi-event-community ,event))))
+(defconst mixi-event-community-regexp
+ "<td WIDTH=595 background=http://img\\.mixi\\.jp/img/bg_w\\.gif><b>\\[\\(.+\\)\\] ¥¤¥Ù¥ó¥È</b></td>")
(defconst mixi-event-time-regexp
- "<td ROWSPAN=11 BGCOLOR=#FFD8B0 ALIGN=center VALIGN=top WIDTH=110>
-\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
-\\([0-9]+\\):\\([0-9]+\\)</td>")
+ "<td ROWSPAN=11 \\(BGCOLOR\\|bgcolor\\)=#FFD8B0 \\(ALIGN\\|align\\)=center \\(VALIGN\\|Valign\\)=top WIDTH=110>
+?\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü<br>
+?\\([0-9]+\\):\\([0-9]+\\)</td>")
(defconst mixi-event-title-regexp
- "<td bgcolor=#FFF4E0 width=410> \\([^<]+\\)</td>")
+ "<td bgcolor=#FFF4E0\\( width=410\\)?> \\([^<]+\\)</td>")
(defconst mixi-event-owner-regexp
- "<td BGCOLOR=#FDF9F2> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
+ "<td \\(BGCOLOR\\|bgcolor\\)=#FDF9F2> <a href=\"show_friend\\.pl\\?id=\\([0-9]+\\)\">\\(.*\\)</a>")
(defconst mixi-event-date-regexp
- "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>³«ºÅÆü»þ</td>
-<td BGCOLOR=#FFFFFF>
+ "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅÆü»þ</td>
+<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
\\(.+\\)
</td>")
(defconst mixi-event-place-regexp
- "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>³«ºÅ¾ì½ê</td>
-<td BGCOLOR=#FFFFFF>
+ "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>³«ºÅ¾ì½ê</td>
+<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
\\(.+\\)
</td>")
(defconst mixi-event-detail-regexp
- "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>¾ÜºÙ</td>
-<td BGCOLOR=#FFFFFF><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
+ "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>¾ÜºÙ</td>
+<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)><table BORDER=0 CELLSPACING=0 CELLPADDING=5><tr><td CLASS=h120>\\(.+\\)</td></tr></table></td>")
(defconst mixi-event-limit-regexp
- "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>Ê罸´ü¸Â</td>
-<td BGCOLOR=#FFFFFF> \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
+ "<td \\(BGCOLOR\\|bgcolor\\)=\"?#\\(FFFFFF\\|ffffff\\)\"? \\(ALIGN\\|align\\)=\"?center\"? NOWRAP>Ê罸´ü¸Â</td>
+?<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)> \\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
(defconst mixi-event-members-regexp
- "<td BGCOLOR=#FFFFFF ALIGN=center NOWRAP>»²²Ã¼Ô</td>
-<td BGCOLOR=#FFFFFF>
-<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
+ "<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\) \\(ALIGN\\|align\\)=center NOWRAP>»²²Ã¼Ô</td>
+<td \\(BGCOLOR\\|bgcolor\\)=#\\(FFFFFF\\|ffffff\\)>
+
+?
+?<table BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
<tr>
-<td> \\(.+\\)</td>")
-(defun mixi-event-realize (event)
+?<td> \\(.+\\)</td>")
+
+(defun mixi-realize-event (event)
"Realize a EVENT."
;; FIXME: Check a expiration of cache?
- (unless (mixi-object-realize-p event)
+ (unless (mixi-object-realized-p event)
(with-mixi-retrieve (mixi-event-page event)
+ (if (string-match mixi-event-community-regexp buffer)
+ (mixi-community-set-name (mixi-event-community event)
+ (match-string 1 buffer))
+ (mixi-realization-error 'cannot-find-community event))
(if (string-match mixi-event-time-regexp buffer)
(mixi-event-set-time
- event (encode-time 0 (string-to-number (match-string 5 buffer))
- (string-to-number (match-string 4 buffer))
- (string-to-number (match-string 3 buffer))
- (string-to-number (match-string 2 buffer))
- (string-to-number (match-string 1 buffer))))
- (signal 'error (list 'cannot-find-time event)))
+ event (encode-time 0 (string-to-number (match-string 8 buffer))
+ (string-to-number (match-string 7 buffer))
+ (string-to-number (match-string 6 buffer))
+ (string-to-number (match-string 5 buffer))
+ (string-to-number (match-string 4 buffer))))
+ (mixi-realization-error 'cannot-find-time event))
(if (string-match mixi-event-title-regexp buffer)
- (mixi-event-set-title event (match-string 1 buffer))
- (signal 'error (list 'cannot-find-title event)))
+ (mixi-event-set-title event (match-string 2 buffer))
+ (mixi-realization-error 'cannot-find-title event))
(if (string-match mixi-event-owner-regexp buffer)
(mixi-event-set-owner event
- (mixi-make-friend (match-string 1 buffer)
- (match-string 2 buffer)))
- (signal 'error (list 'cannot-find-owner event)))
+ (mixi-make-friend (match-string 2 buffer)
+ (match-string 3 buffer)))
+ (mixi-realization-error 'cannot-find-owner event))
(if (string-match mixi-event-date-regexp buffer)
- (mixi-event-set-date event (match-string 1 buffer))
- (signal 'error (list 'cannot-find-date event)))
+ (mixi-event-set-date event (match-string 6 buffer))
+ (mixi-realization-error 'cannot-find-date event))
(if (string-match mixi-event-place-regexp buffer)
- (mixi-event-set-place event (match-string 1 buffer))
- (signal 'error (list 'cannot-find-place event)))
+ (mixi-event-set-place event (match-string 6 buffer))
+ (mixi-realization-error 'cannot-find-place event))
(if (string-match mixi-event-detail-regexp buffer)
- (mixi-event-set-detail event (match-string 1 buffer))
- (signal 'error (list 'cannot-find-detail event)))
+ (mixi-event-set-detail event (match-string 6 buffer))
+ (mixi-realization-error 'cannot-find-detail event))
(when (string-match mixi-event-limit-regexp buffer)
(mixi-event-set-limit
- event (encode-time 0 0 0 (string-to-number (match-string 3 buffer))
- (string-to-number (match-string 2 buffer))
- (string-to-number (match-string 1 buffer)))))
+ event (encode-time 0 0 0 (string-to-number (match-string 8 buffer))
+ (string-to-number (match-string 7 buffer))
+ (string-to-number (match-string 6 buffer)))))
(if (string-match mixi-event-members-regexp buffer)
- (mixi-event-set-members event (match-string 1 buffer))
- (signal 'error (list 'cannot-find-members event))))
+ (mixi-event-set-members event (match-string 6 buffer))
+ (mixi-realization-error 'cannot-find-members event)))
(mixi-object-touch event)))
(defun mixi-event-community (event)
"Return the time of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 3))
(defun mixi-event-title (event)
"Return the title of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 4))
(defun mixi-event-owner (event)
"Return the owner of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 5))
(defun mixi-event-date (event)
"Return the date of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 6))
(defun mixi-event-place (event)
"Return the place of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 7))
(defun mixi-event-detail (event)
"Return the detail of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 8))
(defun mixi-event-limit (event)
"Return the limit of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 9))
(defun mixi-event-members (event)
"Return the members of EVENT."
(unless (mixi-event-p event)
(signal 'wrong-type-argument (list 'mixi-event-p event)))
- (mixi-event-realize event)
+ (mixi-realize-event event)
(aref (cdr event) 10))
(defun mixi-event-set-time (event time)
(aset (cdr event) 10 members))
;; Bbs object.
-(defalias 'mixi-bbs-owner 'mixi-object-owner)
+(defconst mixi-bbs-list '(mixi-topic mixi-event))
+
+(defmacro mixi-bbs-p (object)
+ `(when (memq (mixi-object-class ,object) mixi-bbs-list)
+ t))
+
+(defun mixi-bbs-community (object)
+ "Return the community of OBJECT."
+ (unless (mixi-bbs-p object)
+ (signal 'wrong-type-argument (list 'mixi-bbs-p object)))
+ (let ((func (intern (concat mixi-object-prefix
+ (mixi-object-name object) "-community"))))
+ (funcall func object)))
+
(defalias 'mixi-bbs-id 'mixi-object-id)
(defalias 'mixi-bbs-time 'mixi-object-time)
(defalias 'mixi-bbs-title 'mixi-object-title)
+(defalias 'mixi-bbs-owner 'mixi-object-owner)
(defalias 'mixi-bbs-content 'mixi-object-content)
(defmacro mixi-bbs-list-page (community)
</table>
</td>
</tr>
-<!-- ËÜʸ : start -->
+<!-- [^ ]+ : start -->
<tr>
<td bgcolor=\"#ffffff\">
<table BORDER=0 CELLSPACING=0 CELLPADDING=[35] WIDTH=410>
(mixi-make-diary (mixi-make-friend (nth 1 item)) (nth 0 item)))
items)))
+(defun mixi-post-diary-comment-page (diary)
+ (concat "/add_comment.pl?&diary_id=" (mixi-diary-id diary)))
+
+(defun mixi-post-topic-comment-page (topic)
+ (concat "/add_bbs_comment.pl?id=" (mixi-topic-id topic)
+ "&comm_id=" (mixi-community-id (mixi-topic-community topic))))
+
+(defun mixi-post-event-comment-page (event)
+ (concat "/add_event_comment.pl?id=" (mixi-event-id event)
+ "&comm_id=" (mixi-community-id (mixi-event-community event))))
+
+;; FIXME: Support photos.
+(defun mixi-post-comment (parent content)
+ "Post a comment to PARENT."
+ (unless (mixi-object-p parent)
+ (signal 'wrong-type-argument (list 'mixi-object-p parent)))
+ (unless (stringp content)
+ (signal 'wrong-type-argument (list 'stringp content)))
+ (let* ((name (mixi-object-name bbs))
+ (page (intern (concat mixi-object-prefix "-post" name
+ "-comment-page")))
+ fields post-key)
+ (if (mixi-diary-p parent)
+ (setq fields
+ `(("owner_id" . ,(mixi-friend-id (mixi-diary-owner diary)))
+ ("comment_body" . ,content)))
+ (setq fields `(("comment" . ,content))))
+ (with-mixi-post-form (funcall page parent) fields
+ (if (string-match mixi-post-key-regexp buffer)
+ (setq post-key (match-string 1 buffer))
+ (mixi-post-error 'cannot-find-key bbs)))
+ (if (mixi-diary-p parent)
+ (setq fields
+ `(("post_key" . ,post-key)
+ ("owner_id" . ,(mixi-friend-id (mixi-diary-owner diary)))
+ ("comment_body" . ,content)
+ ("submit" . "confirm")))
+ (setq fields `(("post_key" . ,post-key)
+ ("comment" . ,content)
+ ("submit" . "confirm"))))
+ (with-mixi-post-form (funcall page parent) fields
+ (unless (string-match mixi-post-succeed-regexp buffer)
+ (mixi-post-error 'cannot-find-succeed bbs)))))
+
;; Message object.
(defconst mixi-message-box-list '(inbox outbox savebox thrash)) ; thrash?
(defconst mixi-message-content-regexp
"<tr><td CLASS=h120>\\(.+\\)</td></tr>")
-(defun mixi-message-realize (message)
+(defun mixi-realize-message (message)
"Realize a MESSAGE."
- (unless (mixi-object-realize-p message)
+ (unless (mixi-object-realized-p message)
(with-mixi-retrieve (mixi-message-page message)
(if (string-match mixi-message-owner-regexp buffer)
(mixi-message-set-owner message
(mixi-make-friend (match-string 2 buffer)
(match-string 3 buffer)))
- (signal 'error (list 'cannot-find-owner message)))
+ (mixi-realization-error 'cannot-find-owner message))
(if (string-match mixi-message-title-regexp buffer)
(mixi-message-set-title message (match-string 2 buffer))
- (signal 'error (list 'cannot-find-title message)))
+ (mixi-realization-error 'cannot-find-title message))
(if (string-match mixi-message-time-regexp buffer)
(mixi-message-set-time
message (encode-time 0 (string-to-number (match-string 6 buffer))
(string-to-number (match-string 4 buffer))
(string-to-number (match-string 3 buffer))
(string-to-number (match-string 2 buffer))))
- (signal 'error (list 'cannot-find-time message)))
+ (mixi-realization-error 'cannot-find-time message))
(if (string-match mixi-message-content-regexp buffer)
(mixi-message-set-content message (match-string 1 buffer))
- (signal 'error (list 'cannot-find-content message))))
+ (mixi-realization-error 'cannot-find-content message)))
(mixi-object-touch message)))
(defun mixi-message-id (message)
"Return the owner of MESSAGE."
(unless (mixi-message-p message)
(signal 'wrong-type-argument (list 'mixi-message-p message)))
- (mixi-message-realize message)
+ (mixi-realize-message message)
(aref (cdr message) 3))
(defun mixi-message-title (message)
"Return the title of MESSAGE."
(unless (mixi-message-p message)
(signal 'wrong-type-argument (list 'mixi-message-p message)))
- (mixi-message-realize message)
+ (mixi-realize-message message)
(aref (cdr message) 4))
(defun mixi-message-time (message)
"Return the date of MESSAGE."
(unless (mixi-message-p message)
(signal 'wrong-type-argument (list 'mixi-message-p message)))
- (mixi-message-realize message)
+ (mixi-realize-message message)
(aref (cdr message) 5))
(defun mixi-message-content (message)
"Return the content of MESSAGE."
(unless (mixi-message-p message)
(signal 'wrong-type-argument (list 'mixi-message-p message)))
- (mixi-message-realize message)
+ (mixi-realize-message message)
(aref (cdr message) 6))
(defun mixi-message-set-owner (message owner)
(defconst mixi-message-list-regexp
"<td><a HREF=\"view_message\\.pl\\?id=\\(.+\\)&box=\\(.+\\)\">")
-(defun mixi-get-messages (&rest args)
- "Get messages."
- (when (> (length args) 2)
+(defun mixi-get-messages (&rest box-or-range)
+ "Get messages of BOX."
+ (when (> (length box-or-range) 2)
(signal 'wrong-number-of-arguments
- (list 'mixi-get-messages (length args))))
- (let ((box (nth 0 args))
- (range (nth 1 args)))
+ (list 'mixi-get-messages (length box-or-range))))
+ (let ((box (nth 0 box-or-range))
+ (range (nth 1 box-or-range)))
(when (or (not (mixi-message-box-p box))
(mixi-message-box-p range))
- (setq box (nth 1 args))
- (setq range (nth 0 args)))
+ (setq box (nth 1 box-or-range))
+ (setq range (nth 0 box-or-range)))
(let ((items (mixi-get-matched-items
(mixi-message-list-page
(when box (mixi-message-box-name box)))
(mixi-make-message (nth 0 item) (nth 1 item)))
items))))
+(defmacro mixi-post-message-page (friend)
+ `(concat "/send_message.pl?id=" (mixi-friend-id friend)))
+
+(defconst mixi-post-message-key-regexp
+ "<input name=post_key type=hidden value=\\([a-z0-9]+\\)>")
+
+(defconst mixi-post-message-succeed-regexp
+ "<b>Á÷¿®´°Î»</b>¤·¤Þ¤·¤¿¡£")
+
+(defun mixi-post-message (friend title content)
+ "Post a message to FRIEND."
+ (unless (mixi-friend-p friend)
+ (signal 'wrong-type-argument (list 'mixi-friend-p friend)))
+ (unless (stringp title)
+ (signal 'wrong-type-argument (list 'stringp title)))
+ (unless (stringp content)
+ (signal 'wrong-type-argument (list 'stringp content)))
+ (let ((fields `(("subject" . ,title)
+ ("body" . ,content)
+ ("submit" . "main")))
+ post-key)
+ (with-mixi-post-form (mixi-post-message-page friend) fields
+ (if (string-match mixi-post-message-key-regexp buffer)
+ (setq post-key (match-string 1 buffer))
+ (mixi-post-error 'cannot-find-key friend)))
+ (setq fields `(("post_key" . ,post-key)
+ ("subject" . ,title)
+ ("body" . ,content)
+ ("yes" . "¡¡Á÷¡¡¿®¡¡")
+ ("submit" . "confirm")))
+ (with-mixi-post-form (mixi-post-message-page friend) fields
+ (unless (string-match mixi-post-message-succeed-regexp buffer)
+ (mixi-post-error 'cannot-find-succeed friend)))))
+
;; Introduction object.
(defun mixi-make-introduction (parent owner content)
"Return a introduction object."
</td>
</tr>")
-(defun mixi-get-introductions (&rest args)
- "Get introductions."
- (when (> (length args) 2)
+(defun mixi-get-introductions (&rest friend-or-range)
+ "Get introductions of FRIEND."
+ (when (> (length friend-or-range) 2)
(signal 'wrong-number-of-arguments
- (list 'mixi-get-introduction (length args))))
- (let ((friend (nth 0 args))
- (range (nth 1 args)))
+ (list 'mixi-get-introduction (length friend-or-range))))
+ (let ((friend (nth 0 friend-or-range))
+ (range (nth 1 friend-or-range)))
(when (or (not (mixi-friend-p friend)) (mixi-friend-p range))
- (setq friend (nth 1 args))
- (setq range (nth 0 args)))
+ (setq friend (nth 1 friend-or-range))
+ (setq range (nth 0 friend-or-range)))
(unless (or (null friend) (mixi-friend-p friend))
(signal 'wrong-type-argument (list 'mixi-friend-p friend)))
(let* ((regexp (if friend mixi-introduction-list-regexp