* mixi.el (mixi-news-title-regexp): Follow the change of mixi.
[elisp/mixi.git] / mixi.el
diff --git a/mixi.el b/mixi.el
index 8d52aa3..dac2570 100644 (file)
--- a/mixi.el
+++ b/mixi.el
@@ -224,6 +224,7 @@ Increase this value when unexpected error frequently occurs."
   :type 'boolean
   :group 'mixi)
 
+(defvar mixi-temp-buffer-name " *mixi temp*")
 (defvar mixi-me nil)
 
 ;; Utilities.
@@ -415,32 +416,34 @@ Increase this value when unexpected error frequently occurs."
   (mixi-retrieve "/logout.pl"))
 
 (defmacro with-mixi-retrieve (url &rest body)
-  `(when ,url
-     (with-temp-buffer
+  `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
+     (when ,url
+       (erase-buffer)
        (insert (mixi-retrieve ,url))
        (goto-char (point-min))
        (when (search-forward
              "<form action=\"login.pl\" method=\"post\">" nil t)
         (mixi-login)
         (erase-buffer)
-        (insert (mixi-retrieve ,url))
-        (goto-char (point-min)))
-       ,@body)))
+        (insert (mixi-retrieve ,url))))
+     (goto-char (point-min))
+     ,@body))
 (put 'with-mixi-retrieve 'lisp-indent-function 'defun)
 (put 'with-mixi-retrieve 'edebug-form-spec '(body))
 
 (defmacro with-mixi-post-form (url fields &rest body)
-  `(when ,url
-     (with-temp-buffer
+  `(with-current-buffer (get-buffer-create mixi-temp-buffer-name)
+     (when ,url
+       (erase-buffer)
        (insert (mixi-post-form ,url ,fields))
        (goto-char (point-min))
        (when (search-forward
              "<form action=\"login.pl\" method=\"post\">" nil t)
         (mixi-login)
         (erase-buffer)
-        (insert (mixi-post-form ,url ,fields))
-        (goto-char (point-min)))
-       ,@body)))
+        (insert (mixi-post-form ,url ,fields))))
+     (goto-char (point-min))
+     ,@body))
 (put 'with-mixi-post-form 'lisp-indent-function 'defun)
 (put 'with-mixi-post-form 'edebug-form-spec '(body))
 
@@ -450,7 +453,7 @@ Increase this value when unexpected error frequently occurs."
        ids)
     (catch 'end
       (while (or (null range) (< (length ids) range))
-       (with-mixi-retrieve (format url page)
+       (with-mixi-retrieve (when url (format url page))
          (let ((func (if reverse (progn
                                    (goto-char (point-max))
                                    're-search-backward)
@@ -1139,11 +1142,11 @@ Increase this value when unexpected error frequently occurs."
 (defconst mixi-diary-content-regexp
   "<td \\(class\\|CLASS\\)=\"?h12\"?>\\(.*\\)</td>")
 
-(defun mixi-realize-diary (diary)
+(defun mixi-realize-diary (diary &optional page)
   "Realize a DIARY."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p diary)
-    (with-mixi-retrieve (mixi-diary-page diary)
+    (with-mixi-retrieve (or page (mixi-diary-page diary))
       (unless (re-search-forward mixi-diary-closed-regexp nil t)
        (if (re-search-forward mixi-diary-owner-nick-regexp nil t)
            (mixi-friend-set-nick (mixi-diary-owner diary) (match-string 1))
@@ -1395,7 +1398,7 @@ Increase this value when unexpected error frequently occurs."
   "<td WIDTH=345>\\(.*\\)</td></tr>")
 (defconst mixi-community-birthday-regexp
   "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>³«ÀßÆü</font></td>\r
-<td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü</td>")
+<td WIDTH=345>\\([0-9]+\\)ǯ\\([0-9]+\\)·î\\([0-9]+\\)Æü")
 ;; FIXME: Care when the owner has seceded.
 (defconst mixi-community-owner-regexp
   "<td BGCOLOR=#F2DDB7 WIDTH=80><font COLOR=#996600>´ÉÍý¿Í</font></td>\r
@@ -1664,11 +1667,11 @@ Increase this value when unexpected error frequently occurs."
 (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]+&comm_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-realize-topic (topic)
+(defun mixi-realize-topic (topic &optional page)
   "Realize a TOPIC."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p topic)
-    (with-mixi-retrieve (mixi-topic-page topic)
+    (with-mixi-retrieve (or page (mixi-topic-page topic))
       (if (re-search-forward mixi-topic-community-regexp nil t)
          (mixi-community-set-name (mixi-topic-community topic)
                                   (match-string 1))
@@ -1852,11 +1855,11 @@ Increase this value when unexpected error frequently occurs."
 
 ?<td>&nbsp;\\(.+\\)</td>")
 
-(defun mixi-realize-event (event)
+(defun mixi-realize-event (event &optional page)
   "Realize a EVENT."
   ;; FIXME: Check a expiration of cache?
   (unless (mixi-object-realized-p event)
-    (with-mixi-retrieve (mixi-event-page event)
+    (with-mixi-retrieve (or page (mixi-event-page event))
       (if (re-search-forward mixi-event-community-regexp nil t)
          (mixi-community-set-name (mixi-event-community event)
                                   (match-string 1))
@@ -2100,6 +2103,19 @@ Increase this value when unexpected error frequently occurs."
                           (nth 1 item)))))
            items)))
 
+;; Parent object.
+(defmacro mixi-parent-p (object)
+  `(or (eq (mixi-object-class ,object) 'mixi-diary)
+       (mixi-bbs-p object)))
+
+(defun mixi-realize-parent (parent &optional page)
+  "Realize a PARENT."
+  (unless (mixi-parent-p parent)
+    (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
+  (let ((func (intern (concat mixi-object-prefix "realize-"
+                             (mixi-object-name parent)))))
+    (funcall func parent page)))
+
 ;; Comment object.
 (defun mixi-make-comment (parent owner time content)
   "Return a comment object."
@@ -2233,15 +2249,18 @@ Increase this value when unexpected error frequently occurs."
 
 (defun mixi-get-comments (parent &optional range)
   "Get comments of PARENT."
-  (unless (mixi-object-p parent)
-    (signal 'wrong-type-argument (list 'mixi-object-p parent)))
+  (unless (mixi-parent-p parent)
+    (signal 'wrong-type-argument (list 'mixi-parent-p parent)))
   (let* ((name (mixi-object-name parent))
         (list-page (intern (concat mixi-object-prefix name
                                    "-comment-list-page")))
         (regexp (eval (intern (concat mixi-object-prefix name
-                                      "-comment-list-regexp")))))
-    (let ((items (mixi-get-matched-items
-                 (funcall list-page parent) regexp range t)))
+                                      "-comment-list-regexp"))))
+        (page (funcall list-page parent)))
+    (unless (mixi-object-realized-p parent)
+      (mixi-realize-parent parent page)
+      (setq page nil))
+    (let ((items (mixi-get-matched-items page regexp range t)))
       (mapcar (lambda (item)
                (mixi-make-comment parent (mixi-make-friend
                                           (nth 7 item) (nth 8 item))
@@ -2632,15 +2651,17 @@ Increase this value when unexpected error frequently occurs."
           "&media_id=" (mixi-news-media-id ,news)))
 
 (defconst mixi-news-title-regexp
-  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)</td>")
+  "<td HEIGHT=\"46\" STYLE=\"font-weight: bold;font-size: 14px;\" CLASS=\"h130\">\\(.+\\)\\(\r
+\\)?</td>")
 (defconst mixi-news-media-time-regexp
   "<td COLSPAN=\"2\" ALIGN=\"right\">(\\(.+\\)&nbsp;-&nbsp;\\([0-9]+\\)·î\\([0-9]+\\)Æü \\([0-9]+\\):\\([0-9]+\\))</td></tr>")
 (defconst mixi-news-content-regexp
   "<td CLASS=\"h150\">
 
 \\(.+\\)
-
-?
+<br>
+\\(.*
+\\)?
 
 \\(</td>\\|<br>\\)")