OSDN Git Service

ぱんださん提供の表示件数指定&リプライ機能付きcomment
authormasui <masui>
Wed, 4 Sep 2002 07:02:49 +0000 (16:02 +0900)
committermasui <masui>
Wed, 4 Sep 2002 07:02:49 +0000 (16:02 +0900)
http://home.arino.jp/index.php?%5B%5Bpcomment.inc.php%5D%5D

plugin/pcomment.inc.php [new file with mode: 0644]

diff --git a/plugin/pcomment.inc.php b/plugin/pcomment.inc.php
new file mode 100644 (file)
index 0000000..e4df61e
--- /dev/null
@@ -0,0 +1,292 @@
+<?
+/*
+Last-Update:2002-09-02 rev.13
+
+*¥×¥é¥°¥¤¥ó pcomment
+»ØÄꤷ¤¿¥Ú¡¼¥¸¤Ë¥³¥á¥ó¥È¤òÁÞÆþ
+
+*Usage
+ #pcomment([¥Ú¡¼¥¸Ì¾][,ɽ¼¨¤¹¤ë¥³¥á¥ó¥È¿ô][,¥ª¥×¥·¥ç¥ó])
+
+*¥Ñ¥é¥á¡¼¥¿
+-¥Ú¡¼¥¸Ì¾~
+ Åê¹Æ¤µ¤ì¤¿¥³¥á¥ó¥È¤òµ­Ï¿¤¹¤ë¥Ú¡¼¥¸¤Î̾Á°
+-ɽ¼¨¤¹¤ë¥³¥á¥ó¥È¿ô~
+ ²áµî¤Î¥³¥á¥ó¥È¤ò²¿·ïɽ¼¨¤¹¤ë¤«(0¤ÇÁ´·ï)
+
+*¥ª¥×¥·¥ç¥ó
+-above~
+ ¥³¥á¥ó¥È¤ò¥Õ¥£¡¼¥ë¥É¤ÎÁ°¤Ëɽ¼¨(¿·¤·¤¤µ­»ö¤¬²¼)
+-below~
+ ¥³¥á¥ó¥È¤ò¥Õ¥£¡¼¥ë¥É¤Î¸å¤Ëɽ¼¨(¿·¤·¤¤µ­»ö¤¬¾å)
+-reply~
+ 2¥ì¥Ù¥ë¤Þ¤Ç¤Î¥³¥á¥ó¥È¤Ë¥ê¥×¥é¥¤¤ò¤Ä¤±¤ëradio¥Ü¥¿¥ó¤òɽ¼¨
+
+*/
+// ¥Ú¡¼¥¸Ì¾¤Î¥Ç¥Õ¥©¥ë¥È(%s¤Ë$vars["page"]¤¬Æþ¤ë)
+define("PCMT_PAGE","[[¥³¥á¥ó¥È/%s]]");
+//
+// É½¼¨¤¹¤ë¥³¥á¥ó¥È¿ô¤Î¥Ç¥Õ¥©¥ë¥È
+define("PCMT_NUM_COMMENTS",10);
+//
+// ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
+define("PCMT_COLS_NAME",15);
+//
+// ¥³¥á¥ó¥È¤Î¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
+define("PCMT_COLS_COMMENT",70);
+//
+// ÁÞÆþ¤¹¤ë°ÌÃÖ 1:ËöÈø 0:ÀèƬ
+define("PCMT_INSERT_INS",1);
+//
+//¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
+define("PCMT_FORMAT_NAME","[[%s]]");
+define("PCMT_FORMAT_MSG","%s");
+define("PCMT_FORMAT_DATE","SIZE(10){%s}");
+// \x08¤Ï¡¢Åê¹Æ¤µ¤ì¤¿Ê¸»úÎóÃæ¤Ë¸½¤ì¤Ê¤¤Ê¸»ú¤Ç¤¢¤ì¤Ð¤Ê¤ó¤Ç¤â¤¤¤¤¡£
+define("PCMT_FORMAT","\x08MSG\x08 -- \x08NAME\x08 \x08DATE\x08");
+
+function plugin_pcomment_init() {
+       $_plugin_pcmt_messages = array(
+               '_pcmt_btn_name' => '¤ªÌ¾Á°: ',
+               '_pcmt_btn_comment' => '¥³¥á¥ó¥È¤ÎÁÞÆþ',
+               '_pcmt_msg_comment' => '¥³¥á¥ó¥È: ',
+               '_pcmt_msg_recent' => 'ºÇ¿·¤Î%d·ï¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹¡£',
+               '_pcmt_msg_all' => '¥³¥á¥ó¥È¥Ú¡¼¥¸¤ò»²¾È',
+               '_pcmt_msg_none' => '¥³¥á¥ó¥È¤Ï¤¢¤ê¤Þ¤»¤ó¡£',
+               '_title_pcmt_collided' => '$1 ¤Ç¡Ú¹¹¿·¤Î¾×ÆÍ¡Û¤¬µ¯¤­¤Þ¤·¤¿',
+               '_msg_pcmt_collided' => '¤¢¤Ê¤¿¤¬¤³¤Î¥Ú¡¼¥¸¤òÊÔ½¸¤·¤Æ¤¤¤ë´Ö¤Ë¡¢Â¾¤Î¿Í¤¬Æ±¤¸¥Ú¡¼¥¸¤ò¹¹¿·¤·¤Æ¤·¤Þ¤Ã¤¿¤è¤¦¤Ç¤¹¡£<br />
+¥³¥á¥ó¥È¤òÄɲä·¤Þ¤·¤¿¤¬¡¢°ã¤¦°ÌÃÖ¤ËÁÞÆþ¤µ¤ì¤Æ¤¤¤ë¤«¤â¤·¤ì¤Þ¤»¤ó¡£<br />',
+       );
+  set_plugin_messages($_plugin_pcmt_messages);
+}
+function plugin_pcomment_action() {
+       global $post;
+
+       $retval = "";
+       if($post["msg"]) { $retval = pcmt_insert(); }
+       return $retval;
+}
+
+function plugin_pcomment_convert() {
+       global $script,$vars;
+       global $_pcmt_btn_name, $_pcmt_btn_comment, $_pcmt_msg_comment, $_pcmt_msg_all, $_pcmt_msg_recent;
+
+       //Ìá¤êÃÍ
+       $ret = "";
+
+       //¥Ñ¥é¥á¡¼¥¿ÊÑ´¹
+       $args = func_get_args();
+       array_walk($args, "pcmt_check_arg", &$params);
+       unset($args);
+
+       //ʸ»úÎó¤ò¼èÆÀ
+       list($page, $count) = $params["arg"];
+       if ($page == "") { $page = sprintf(PCMT_PAGE,strip_bracket($vars["page"])); }
+       if ($count == 0 and $count !== "0") { $count = PCMT_NUM_COMMENTS; }
+
+       //¸þ¤­¤ò·èÄê
+       $dir = PCMT_INSERT_INS;
+       if ($params["above"]) { $dir = 1; }
+       if ($params["below"]) { $dir = 0; } //ξÊý»ØÄꤵ¤ì¤¿¤é²¼¤Ë (^^;
+
+       //¥³¥á¥ó¥È¤ò¼èÆÀ
+       list($comments, $digest) = pcmt_get_comments($page,$count,$dir,$params["reply"]);
+
+       //¥Õ¥©¡¼¥à¤òɽ¼¨
+       if($params["noname"]) {
+               $title = $_pcmt_msg_comment;
+               $name = '';
+       } else {
+               $title = $_pcmt_btn_name;
+               $name = '<input type="text" name="name" size="'.PCMT_COLS_NAME.'" />';
+       }
+
+       $radio = $params["reply"] ? '<input type="radio" name="reply" value="0" checked />' : '';
+       $comment = '<input type="text" name="msg" size="'.PCMT_COLS_COMMENT.'" />';
+
+       //XSSÀȼåÀ­ÌäÂê - ³°Éô¤«¤éÍ褿ÊÑ¿ô¤ò¥¨¥¹¥±¡¼¥×
+       $f_page = htmlspecialchars($page);
+       $f_refer = htmlspecialchars($vars["page"]);
+       $f_nodate = htmlspecialchars($params["nodate"]);
+
+       $form = <<<EOD
+  <div>
+  <input type="hidden" name="digest" value="$digest" />
+  <input type="hidden" name="plugin" value="pcomment" />
+  <input type="hidden" name="refer" value="$f_refer" />
+  <input type="hidden" name="page" value="$f_page" />
+  <input type="hidden" name="nodate" value="$f_nodate" />
+  <input type="hidden" name="dir" value="$dir" />
+  $radio $title $name $comment
+  <input type="submit" value="$_pcmt_btn_comment" />
+  </div>
+EOD;
+
+       $link = $page;
+       if (!is_page($page)) {
+               $recent = $_pcmt_msg_none;
+       } else {
+               if ($_pcmt_msg_all != "") {
+                       $link = preg_replace("/^(\[\[)?/","$1$_pcmt_msg_all&gt;[[","$page]]");
+               }
+               $recent = "";
+               if ($count > 0) {
+                       $recent = sprintf($_pcmt_msg_recent,$count);
+               }
+       }
+       $link = make_link($link);
+       return $dir ?
+               "<div><p>$recent $link</p>\n<form action=\"$script\" method=\"post\">$comments$form</form></div>" :
+               "<div><form action=\"$script\" method=\"post\">$form$comments</form>\n<p>$recent $link</p></div>";
+}
+
+function pcmt_insert($page) {
+       global $post,$vars,$script,$now,$do_backup;
+       global $_title_updated;
+
+       $ret["msg"] = $_title_updated;
+
+       //ʸ»úÎó¤ÎÀ°·Á
+       $msg = user_rules_str($post["msg"]);
+
+       //¥³¥á¥ó¥È¥Õ¥©¡¼¥Þ¥Ã¥È¤òŬÍÑ
+       $msg = sprintf(PCMT_FORMAT_MSG, rtrim($post["msg"]));
+       $name = ($post["name"] == '') ? '' :  sprintf(PCMT_FORMAT_NAME, $post["name"]);
+       $date = ($post["nodate"] == "1") ? '' : sprintf(PCMT_FORMAT_DATE, $now);
+       if ($date != '' or $name != '') { 
+               $msg = str_replace("\x08MSG\x08", $msg,  PCMT_FORMAT);
+               $msg = str_replace("\x08NAME\x08",$name, $msg);
+               $msg = str_replace("\x08DATE\x08",$date, $msg);
+       }
+       if ($post["reply"] or !is_page($post["page"])) {
+               $msg = preg_replace("/^\-+/",'',$msg);
+       }
+       $msg = rtrim($msg);
+
+       if (!is_page($post["page"])) {
+               $new = htmlspecialchars($post["refer"])."\n\n-$msg\n";
+       } else {
+               //¥Ú¡¼¥¸¤òÆɤ߽Ф¹
+               $data = file(get_filename(encode($post["page"])));
+               $old = join("",$data);
+
+               $reply = $post["reply"];
+               // ¹¹¿·¤Î¾×Æͤò¸¡½Ð
+               if (md5($old) != $post["digest"]) {
+                       $ret["msg"] = $_title_paint_collided;
+                       $ret["body"] = $_msg_paint_collided;
+                       $reply = 0; //¥ê¥×¥é¥¤¤Ç¤Ê¤¯¤¹¤ë
+               }
+
+               // ¥Ú¡¼¥¸ËöÈø¤ÎÄ´À°
+               if (substr($data[count($data) - 1],-1,1) != "\n") { $data[] = "\n"; }
+
+               //´ð½àÅÀ¤ò·èÄê
+               $level = 1;
+               if ($post["dir"] == "1") {
+                       $pos = count($data) - 1;
+                       $step = -1;
+               } else {
+                       $pos = -1;
+                       foreach ($data as $line) {
+                               if (preg_match("/^\-/",$line)) break;
+                               $pos++;
+                       }
+                       $step = 1;
+               }
+               //¥ê¥×¥é¥¤Àè¤Î¥³¥á¥ó¥È¤ò¸¡º÷
+               if ($reply > 0) {
+                       while ($pos >= 0 and $pos < count($data)) {
+                               if (preg_match("/^(\-{1,2})(?!\-)/",$data[$pos], $matches) and --$reply == 0) {
+                                       $level = strlen($matches[1]) + 1; //ÁÞÆþ¤¹¤ë¥ì¥Ù¥ë
+                                       break;
+                               }
+                               $pos += $step;
+                       }
+                       while (++$pos < count($data)) {
+                               if (preg_match("/^(\-{1,2})(?!\-)/",$data[$pos], $matches)) {
+                                       if (strlen($matches[1]) < $level) { break; }
+                               }
+                       }
+               } else {
+                       $pos++;
+               }
+               //¹ÔƬʸ»ú
+               $head = str_repeat("-",$level);
+               //¥³¥á¥ó¥È¤òÁÞÆþ
+               array_splice($data,$pos,0,"$head$msg\n");
+               $new = join("",$data);
+
+               // º¹Ê¬¥Õ¥¡¥¤¥ë¤ÎºîÀ®
+               file_write(DIFF_DIR,$post["page"],do_diff($old,$new));
+
+               // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤ÎºîÀ®
+               if ($do_backup) {
+                       $oldtime = filemtime(get_filename(encode($post["page"])));
+                       make_backup(encode($post["page"]).".txt", $old, $oldtime);
+               }
+       }
+
+       // ¥Õ¥¡¥¤¥ë¤Î½ñ¤­¹þ¤ß
+       file_write(DATA_DIR, $post["page"], $new);
+
+       // is_page¤Î¥­¥ã¥Ã¥·¥å¤ò¥¯¥ê¥¢¤¹¤ë¡£
+       is_page($post["page"], true);
+
+       $vars["page"] = $post["page"] = $post["refer"];
+
+       return $ret;
+}
+//¥ª¥×¥·¥ç¥ó¤ò²òÀϤ¹¤ë
+function pcmt_check_arg($val, $key, &$params) {
+       $valid_args = array('noname','nodate','below','above','reply');
+       foreach ($valid_args as $valid) {
+               if (strpos($valid, strtolower($val)) === 0) {
+                       $params[$valid] = 1;
+                       return;
+               }
+       }
+       $params["arg"][] = $val;
+}
+function pcmt_get_comments($page,$count,$dir,$reply) {
+       $data = @file(get_filename(encode($page)));
+
+       if (!is_array($data)) { return array("",0); }
+
+       $digest = md5(join("", $data));
+
+       //¥³¥á¥ó¥È¤ò»ØÄꤵ¤ì¤¿·ï¿ô¤À¤±ÀÚ¤ê¼è¤ë
+       if ($dir) { $data = array_reverse($data); }
+       $num = $cnt = 0;
+       $cmts = array();
+       foreach ($data as $line) {
+               if (preg_match("/^(\-{1,2})(?!\-)(.*)$/", $line, $matches)) {
+                       if ($count > 0 and strlen($matches[1]) == 1 and ++$cnt > $count) { break; }
+                       if ($reply) {
+                               ++$num;
+                               $cmts[] = "$matches[1]\x01$num\x02$matches[2]\n";
+                       } else {
+                               $cmts[] = $line;
+                       }
+               } else {
+                       $cmts[] = $line;
+               }
+       }
+       $data = $cmts;
+       if ($dir) { $data = array_reverse($data); }
+       unset($cmts);
+
+       //¥³¥á¥ó¥È¤è¤êÁ°¤Î¥Ç¡¼¥¿¤ò¼è¤ê½ü¤¯¡£
+       while (count($data) > 0 and substr($data[0],0,1) != '-') { array_shift($data); }
+
+       //htmlÊÑ´¹
+       $comments = convert_html(join("", $data));
+       unset($data);
+
+       //¥³¥á¥ó¥È¤Ë¥é¥¸¥ª¥Ü¥¿¥ó¤Î°õ¤ò¤Ä¤±¤ë
+       if ($reply) {
+               $comments = preg_replace("/\x01(\d+)\x02/",'<input type="radio" name="reply" value="$1" />', $comments);
+       }
+       return array($comments,$digest);
+}
+?>