[P2-php-svn] [790] expack:

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 17日 (日) 18:10:54 JST


Revision: 790
          http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=790
Author:   rsk
Date:     2010-01-17 18:10:54 +0900 (Sun, 17 Jan 2010)

Log Message:
-----------
expack:
- rev.100117.0000. (移行スクリプトのテスト用の仮バージョン)
- まとめ読みキャッシュをP2KeyValueStoreで管理するようにした。
-- 設定管理でまとめ読みキャッシュのタイトルや含まれるスレッドを
   参照できるようになった。
-- まとめ読みのキャッシュを残す数の定義 ($_conf['matome_cache_max']) を
   conf/conf.inc.php から onf/conf_admin.inc.php に移した。
- URL-safe Base64変換メソッドをP2UtilクラスからUrlSafeBase64クラスに移した。
- ImageCache2インストーラーを修正。
- その他、内部的な変更とバグ修正がいくつか。

Modified Paths:
--------------
    p2ex/trunk/conf/conf.inc.php
    p2ex/trunk/conf/conf_admin.inc.php
    p2ex/trunk/conf/setup_info.php
    p2ex/trunk/doc/ImageCache2/ic2_install.phps
    p2ex/trunk/editpref.php
    p2ex/trunk/ic2_manager.php
    p2ex/trunk/index.php
    p2ex/trunk/iv2.php
    p2ex/trunk/js/motolspopup.js
    p2ex/trunk/js/respopup.js
    p2ex/trunk/lib/P2DataStore/AbstractDataStore.php
    p2ex/trunk/lib/P2DataStore/CookieDataStore.php
    p2ex/trunk/lib/P2DataStore/PostDataStore.php
    p2ex/trunk/lib/P2KeyValueStore.php
    p2ex/trunk/lib/P2Util.php
    p2ex/trunk/lib/UA.php
    p2ex/trunk/lib/bootstrap.php
    p2ex/trunk/lib/expack/ic2/templates/ic2mng.tpl.html
    p2ex/trunk/lib/startup.funcs.php
    p2ex/trunk/read_new.php
    p2ex/trunk/read_new_k.php
    p2ex/trunk/style/editpref_css.inc
    p2ex/trunk/style/iv2_css.inc
    p2ex/trunk/style/style_css.inc

Added Paths:
-----------
    p2ex/trunk/js/editpref.js
    p2ex/trunk/lib/MatomeCache.php
    p2ex/trunk/lib/MatomeCacheList.php
    p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php
    p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php
    p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php
    p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php
    p2ex/trunk/lib/UrlSafeBase64.php
    p2ex/trunk/read_new_cache.php

Removed Paths:
-------------
    p2ex/trunk/lib/read_new.inc.php


-------------- next part --------------
Modified: p2ex/trunk/conf/conf.inc.php
===================================================================
--- p2ex/trunk/conf/conf.inc.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/conf/conf.inc.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -7,7 +7,7 @@
 // ƒo[ƒWƒ‡ƒ“î•ñ
 $_conf = array(
     'p2version' => '1.7.29+1.8.x',  // rep2‚̃o[ƒWƒ‡ƒ“
-    'p2expack'  => '100113.1300',   // Šg’£ƒpƒbƒN‚̃o[ƒWƒ‡ƒ“
+    'p2expack'  => '100117.0000',   // Šg’£ƒpƒbƒN‚̃o[ƒWƒ‡ƒ“
     'p2name'    => 'expack',        // rep2‚Ì–¼‘O
 );
 
@@ -225,6 +225,7 @@
     $_conf['dat_dir']  = p2_realpath($_conf['dat_dir']);
     $_conf['idx_dir']  = p2_realpath($_conf['idx_dir']);
     $_conf['pref_dir'] = p2_realpath($_conf['pref_dir']);
+    $_conf['db_dir']   = p2_realpath($_conf['db_dir']);
 
     // ŠÇ——p•Û‘¶ƒfƒBƒŒƒNƒgƒŠ
     $_conf['admin_dir'] = $_conf['data_dir'] . '/admin';
@@ -282,16 +283,13 @@
         $_conf[$k] = $_conf['pref_dir'] . '/' . $v;
     }
 
-    $_conf['matome_cache_path'] = $_conf['pref_dir'] . '/matome_cache';
-    $_conf['matome_cache_ext']  = '.htm';
-    $_conf['matome_cache_max']  = 3; // —\”õƒLƒƒƒbƒVƒ…‚̐”
-
     $_conf['orig_favita_brd']   = $_conf['favita_brd'];
     $_conf['orig_favlist_idx']  = $_conf['favlist_idx'];
 
     $_conf['cookie_db_path']    = $_conf['db_dir'] . '/p2_cookies.sqlite3';
     $_conf['post_db_path']      = $_conf['db_dir'] . '/p2_post_data.sqlite3';
     $_conf['hostcheck_db_path'] = $_conf['db_dir'] . '/p2_hostcheck_cache.sqlite3';
+    $_conf['matome_db_path']    = $_conf['db_dir'] . '/p2_matome_cache.sqlite3';
     $_conf['iv2_cache_db_path'] = $_conf['db_dir'] . '/iv2_cache.sqlite3';
 
     // •â³

Modified: p2ex/trunk/conf/conf_admin.inc.php
===================================================================
--- p2ex/trunk/conf/conf_admin.inc.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/conf/conf_admin.inc.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -98,6 +98,9 @@
 // ‘O‰ñƒƒOƒCƒ“î•ñ‚ð•\Ž¦i‚·‚é:1, ‚µ‚È‚¢:0j
 $_conf['last_login_log_show'] = 1;  // (1)
 
+// V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ðŽc‚·” (–³Œø:0, –³ŒÀ:-1)
+$_conf['matome_cache_max'] = 5; // (5)
+
 // }}}
 // ----------------------------------------------------------------------
 // {{{ ƒp[ƒ~ƒbƒVƒ‡ƒ“

Modified: p2ex/trunk/conf/setup_info.php
===================================================================
--- p2ex/trunk/conf/setup_info.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/conf/setup_info.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -39,6 +39,7 @@
 // ’l‚Í "yymmdd.hhmm" Œ`Ž®‚цƒj[ƒN‚©‚¸‡‚Ƀ\[ƒg‚³‚ê‚Ä‚¢‚È‚¯‚ê‚΂Ȃç‚È‚¢
 $p2_changed_versions = array(
     '100113.1300',
+    '100117.0000',
 );
 
 /*

Modified: p2ex/trunk/doc/ImageCache2/ic2_install.phps
===================================================================
--- p2ex/trunk/doc/ImageCache2/ic2_install.phps	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/doc/ImageCache2/ic2_install.phps	2010-01-17 09:10:54 UTC (rev 790)
@@ -27,10 +27,7 @@
 require_once 'HTML/Template/Flexy.php';
 require_once 'HTML/Template/Flexy/Element.php';
 require_once 'Validate.php';
-require_once P2EX_LIB_DIR . '/ic2/findexec.inc.php';
-require_once P2EX_LIB_DIR . '/ic2/DataObject/Images.php';
-require_once P2EX_LIB_DIR . '/ic2/Thumbnailer.php';
-require_once P2EX_LIB_DIR . '/ic2/loadconfig.inc.php';
+require_once P2EX_LIB_DIR . '/ic2/bootstrap.php';
 
 // Ý’èƒtƒ@ƒCƒ‹“ǂݍž‚Ý
 $ini = ic2_loadconfig();
@@ -77,12 +74,11 @@
     $table_extra_defs = '';
     break;
 case 'sqlite':
-case 'sqlite3':
     $serial = 'INTEGER PRIMARY KEY';
     $table_extra_defs = '';
     break;
 default:
-    die('MySQL, PostgreSQL, SQLite2, SQLite3ˆÈŠO‚̃f[ƒ^ƒx[ƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB');
+    die('MySQL, PostgreSQL, SQLite2ˆÈŠO‚̃f[ƒ^ƒx[ƒX‚ɂ͑Ήž‚µ‚Ä‚¢‚Ü‚¹‚ñB');
 }
 
 // ƒe[ƒuƒ‹–¼‚͐ݒè‚É‚æ‚Á‚Ä‚ÍDB‚Ì—\–ñŒê‚ªŽg‚í‚ê‚é‚©‚à‚µ‚ê‚È‚¢‚Ì‚ÅDB_xxx::quoteIdentifier()‚Å

Modified: p2ex/trunk/editpref.php
===================================================================
--- p2ex/trunk/editpref.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/editpref.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -30,7 +30,7 @@
         if ($_conf['expack.misc.multi_favs']) {
             $sync_boards[] = $_conf['orig_favita_brd'];
             for ($i = 1; $i <= $_conf['expack.misc.favset_num']; $i++) {
-                $sync_boards[] = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favita%d.brd', $i);
+                $sync_boards[] = sprintf('%s/p2_favita%d.brd', $_conf['pref_dir'], $i);
             }
         } else {
             $sync_boards[] = $_conf['favita_brd'];
@@ -40,7 +40,7 @@
         if ($_conf['expack.misc.multi_favs']) {
             $sync_indexes[] = $_conf['orig_favlist_idx'];
             for ($i = 1; $i <= $_conf['expack.misc.favset_num']; $i++) {
-                $sync_indexes[] = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favlist%d.idx', $i);
+                $sync_indexes[] = sprintf('%s/p2_favlist%d.idx', $_conf['pref_dir'], $i);
             }
         } else {
             $sync_indexes[] = $_conf['favlist_idx'];
@@ -60,8 +60,8 @@
             $sync_boards[] = $_conf['orig_favita_brd'];
             $sync_indexes[] = $_conf['orig_favlist_idx'];
             for ($i = 1; $i <= $_conf['expack.misc.favset_num']; $i++) {
-                $sync_boards[] = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favita%d.brd', $i);
-                $sync_indexes[] = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favlist%d.idx', $i);
+                $sync_boards[] = sprintf('%s/p2_favita%d.brd', $_conf['pref_dir'], $i);
+                $sync_indexes[] = sprintf('%s/p2_favlist%d.idx', $_conf['pref_dir'], $i);
             }
         } else {
             $sync_boards[] = $_conf['favita_brd'];
@@ -133,10 +133,13 @@
 
 if (!$_conf['ktai']) {
     echo <<<EOP
-    <script type="text/javascript" src="js/changeskin.js?{$_conf['p2_version_id']}"></script>
     <link rel="stylesheet" type="text/css" href="css.php?css=style&amp;skin={$skin_en}">
     <link rel="stylesheet" type="text/css" href="css.php?css=editpref&amp;skin={$skin_en}">
     <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">\n
+    <script type="text/javascript" src="js/basic.js?{$_conf['p2_version_id']}"></script>
+    <script type="text/javascript" src="js/changeskin.js?{$_conf['p2_version_id']}"></script>
+    <script type="text/javascript" src="js/respopup.js?{$_conf['p2_version_id']}"></script>
+    <script type="text/javascript" src="js/editpref.js?{$_conf['p2_version_id']}"></script>\n
 EOP;
     $body_at = ' onload="window.top.document.title=window.self.document.title;"';
 } elseif (!$_conf['iphone']) {
@@ -304,13 +307,12 @@
     }
 
     // }}}
-
-    echo "</table>\n";
 }
 
 // Œg‘Ñ—p•\Ž¦
 if ($_conf['ktai']) {
     echo <<<EOP
+<hr>
 <p>±ÎÞÝ/NGÜ°ÄޕҏW</p>
 <form method="GET" action="edit_aborn_word.php">
 {$_conf['k_input_ht']}
@@ -332,6 +334,7 @@
 <input type="hidden" name="file" value="{$aborn_res_txt}">
 <input type="submit" value="±ÎÞÝÚ½•ÒW">
 </form>
+<hr>
 EOP;
     echo "<p>νĂ̓¯Šúi2ch‚̔ˆړ]‚ɑΉž‚µ‚Ü‚·j</p>\n";
     echo getSyncFavoritesFormHt('all', '‚·‚ׂÄ');
@@ -363,39 +366,92 @@
 
 // {{{ V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…•\Ž¦
 
-$max = $_conf['matome_cache_max'];
+$matome_cache_list = MatomeCacheList::getList();
+if ($matome_cache_list) {
+    $ckeyprefixlen = strlen(MatomeCacheList::getKeyPrefix());
+    $i = 0;
 
-if ($_conf['ktai']) {
-    $ext = '.k' . $_conf['matome_cache_ext'];
-} else {
-    $ext = $_conf['matome_cache_ext'];
-}
+    if ($_conf['ktai']) {
+        echo "<hr>\n<p>V’…‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…</p>\n";
+    } else {
+        echo "<tr><td colspan=\"2\">\n";
+        echo "<fieldset>\n<legend>V’…‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…</legend>\n";
+    }
 
-for ($i = 0; $i <= $max; $i++) {
-    $dnum = ($i) ? '.'.$i : '';
-    $ai = '&amp;cnum=' . $i;
-    $file = $_conf['matome_cache_path'] . $dnum . $ext;
-    //echo '<!-- '.$file.' -->';
-    if (file_exists($file)) {
-        $filemtime = filemtime($file);
-        $date = date('Y/m/d G:i:s', $filemtime);
-        $kib = round(filesize($file) / 1024, 0);
-        $url = 'read_new.php?cview=1' . $ai . '&amp;filemtime=' . $filemtime . $_conf['k_at_a'];
-        $links[] = '<a href="' . $url . '" target="read">' . $date . '</a> ' . $kib . 'KiB';
+    echo "<ul id=\"matome_cache\">\n";
+
+    foreach ($matome_cache_list as $cache_key => $cache_info) {
+        echo '<li>';
+
+        $i++;
+        $ckey = substr($cache_key, $ckeyprefixlen);
+        $clink = 'read_new_cache.php?ckey=' . rawurlencode($ckey) . $_conf['k_at_a'];
+        if ($cache_info['title']) {
+            $ctitle = $cache_info['title'];
+        } else {
+            $ctitle = $ckey;
+        }
+        $cnumthreads = count($cache_info['threads']);
+
+        if ($_conf['ktai']) {
+            $cdate = date('y/m/d G:i', $cache_info['time']);
+            echo "{$cdate}<br><a href=\"{$clink}\">{$ctitle}</a>";
+        } else {
+            $cid = 'matome_cache_meta' . $i;
+            $cdate = date('Y/m/d H:i:s', $cache_info['time']);
+            if ($cnumthreads) {
+                $cpopup_at = " onmouseover=\"showCacheMetaData('{$cid}', event)\"";
+                $cpopup_at .= " onmouseout=\"hideCacheMetaData('{$cid}')\"";
+            } else {
+                $cpopup_at = '';
+            }
+            echo "<span class=\"matome_cache_date\">{$cdate}</span> ";
+            echo "[<a href=\"{$clink}\" target=\"read\"{$cpopup_at}>{$ctitle}</a>]";
+            if ($cnumthreads) {
+                echo "<div class=\"popup_element\" id=\"{$cid}\"{$cpopup_at}>";
+            }
+        }
+
+        if ($cnumthreads) {
+            if ($_conf['ktai']) {
+                $ctarget_at = '';
+            } else {
+                $ctarget_at = ' target="read"';
+            }
+
+            echo '<ul>';
+            foreach ($cache_info['threads'] as $cthread) {
+                $cthreadlink = $_conf['read_php']
+                             . '?host=' . rawurlencode($cthread['host'])
+                             . '&amp;bbs=' . rawurlencode($cthread['bbs'])
+                             . '&amp;key=' . rawurlencode($cthread['key'])
+                             . '&amp;ls=' . rawurlencode($cthread['ls'])
+                             . '&amp;offline=true' . $_conf['k_at_a'];
+                echo "<li><a href=\"{$cthreadlink}\"{$ctarget_at}>{$cthread['title']}</a></li>";
+            }
+            echo '</ul>';
+
+            if (!$_conf['ktai']) {
+                echo '</div>';
+            }
+        }
+
+        echo "</li>\n";
     }
-}
-if (!empty($links)) {
-    if ($_conf['ktai']) {
-        echo '<hr>'."\n";
+
+    echo "</ul>\n";
+    if (!$_conf['ktai']) {
+        echo "</fieldset>\n";
+        echo "</td></tr>\n";
     }
-    echo $htm['matome'] = '<p>V’…‚Ü‚Æ‚ß“Ç‚Ý‚Ì‘O‰ñƒLƒƒƒbƒVƒ…‚ð•\Ž¦<br>' . implode('<br>', $links) . '</p>';
 }
 
 // }}}
 
-// Œg‘Ñ—pƒtƒbƒ^
 if ($_conf['ktai']) {
     echo "<hr><div class=\"center\">{$_conf['k_to_index_ht']}</div>";
+} else {
+    echo "</table>\n";
 }
 
 echo '</body></html>';
@@ -418,7 +474,7 @@
 {
     global $_conf;
 
-    $path = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . $filename;
+    $path = $_conf['pref_dir'] . '/' . $filename;
 
     if ((file_exists($path) && is_writable($path)) ||
         (!file_exists($path) && is_writable(dirname($path)))

Modified: p2ex/trunk/ic2_manager.php
===================================================================
--- p2ex/trunk/ic2_manager.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/ic2_manager.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -24,6 +24,11 @@
 
 // Ý’è“ǂݍž‚Ý
 $ini = ic2_loadconfig();
+if ($ini['Viewer']['cache'] && file_exists($_conf['iv2_cache_db_path'])) {
+    $viewer_cache_exists = true;
+} else {
+    $viewer_cache_exists = false;
+}
 
 // ƒf[ƒ^ƒx[ƒX‚ɐڑ±
 $db = DB::connect($ini['General']['dsn']);
@@ -48,11 +53,14 @@
 if (isset($_POST['action'])) {
     switch ($_POST['action']) {
 
+        // ‰æ‘œ‚ðíœ‚·‚é
         case 'dropZero':
         case 'dropAborn':
             if ($_POST['action'] == 'dropZero') {
+                // ƒ‰ƒ“ƒN=0 ‚̉摜‚ðíœ‚·‚é
                 $where = $db->quoteIdentifier('rank') . ' = 0';
                 if (isset($_POST['dropZeroLimit'])) {
+                    // Žæ“¾‚µ‚½ŠúŠÔ‚ðŒÀ’è
                     switch ($_POST['dropZeroSelectTime']) {
                         case '24hours': $expires = 86400; break;
                         case 'aday':    $expires = 86400; break;
@@ -69,8 +77,10 @@
                             time() - $expires);
                     }
                 }
+                // ƒuƒ‰ƒbƒNƒŠƒXƒg‚É“o˜^‚·‚é
                 $to_blacklist = !empty($_POST['dropZeroToBlackList']);
             } else {
+                // ‚ ‚ځ[‚ñ‰æ‘œ‚ðíœ‚µAƒuƒ‰ƒbƒNƒŠƒXƒg‚É“o˜^‚·‚é
                 $where = $db->quoteIdentifier('rank') . ' < 0';
                 $to_blacklist = TRUE;
             }
@@ -89,6 +99,7 @@
             $flexy->setData('toBlackList', $to_blacklist);
             break;
 
+        // PC—pˆÈŠO‚̍쐬Ï‚݃Tƒ€ƒlƒCƒ‹‚ðÁ‹Ž‚·‚é
         case 'clearThumb':
             $thumb_dir2 = $ini['General']['cachedir'] . '/' . $ini['Thumb2']['name'];
             $thumb_dir3 = $ini['General']['cachedir'] . '/' . $ini['Thumb3']['name'];
@@ -104,8 +115,10 @@
             }
             break;
 
+        // ˆê——•\Ž¦—p‚̃f[ƒ^ƒLƒƒƒbƒVƒ…‚ðÁ‹Ž‚·‚é
         case 'clearCache':
-            if (file_exists($_conf['iv2_cache_db_path'])) {
+            // ˆê——•\Ž¦—pƒf[ƒ^ƒLƒƒƒbƒVƒ…‚ðƒNƒŠƒA
+            if ($viewer_cache_exists) {
                 $kvs = P2KeyValueStore::getStore($_conf['iv2_cache_db_path'],
                                                  P2KeyValueStore::CODEC_SERIALIZING);
                 if ($kvs->clear() === false) {
@@ -114,16 +127,19 @@
                     $_info_msg_ht .= '<p>ˆê——•\Ž¦—p‚̃f[ƒ^ƒLƒƒƒbƒVƒ…‚ðÁ‹Ž‚µ‚Ü‚µ‚½B</p>';
                 }
             }
+
+            // ƒRƒ“ƒpƒCƒ‹Ï‚݃eƒ“ƒvƒŒ[ƒg‚ðíœ
             $result_files = P2Util::garbageCollection($flexy->options['compileDir'], -1, '', '', TRUE);
             $removed_files = $result_files['successed'];
             if (!empty($result_files['failed'])) {
-                $_info_msg_ht .= '<p>ˆÈ‰º‚̃tƒ@ƒCƒ‹‚ªíœ‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½B</p>';
+                $_info_msg_ht .= '<p>ˆÈ‰º‚̃Rƒ“ƒpƒCƒ‹Ï‚݃eƒ“ƒvƒŒ[ƒg‚ªíœ‚Å‚«‚Ü‚¹‚ñ‚Å‚µ‚½B</p>';
                 $_info_msg_ht .= '<ul><li>';
                 $_info_msg_ht .= implode('</li><li>', array_map('htmlspecialchars', $result_files['failed']));
                 $_info_msg_ht .= '</li></ul>';
             }
             break;
 
+        // ƒGƒ‰[ƒƒO‚ðÁ‹Ž‚·‚é
         case 'clearErrorLog':
             $result = $db->query('DELETE FROM ' . $db->quoteIdentifier($ini['General']['error_table']));
             if (DB::isError($result)) {
@@ -133,6 +149,7 @@
             }
             break;
 
+        // ƒuƒ‰ƒbƒNƒŠƒXƒg‚ðÁ‹Ž‚·‚é
         case 'clearBlackList':
             $result = $db->query('DELETE FROM ' . $db->quoteIdentifier($ini['General']['blacklist_table']));
             if (DB::isError($result)) {
@@ -142,31 +159,33 @@
             }
             break;
 
-        case 'vacuumDB':
+        // ƒf[ƒ^ƒx[ƒX‚ðÅ“K‰»‚·‚é
+        case 'optimizeDB':
             // SQLite2 ‚̉摜ƒLƒƒƒbƒVƒ…ƒf[ƒ^ƒx[ƒX‚ðVACUUM
             if ($db->dsn['phptype'] == 'sqlite') {
                 $result = $db->query('VACUUM');
                 if (DB::isError($result)) {
                     $_info_msg_ht .= $result->getMessage();
                 } else {
-                $_info_msg_ht .= '<p>‰æ‘œƒf[ƒ^ƒx[ƒX‚𐮗‚µ‚Ü‚µ‚½B</p>';
+                    $_info_msg_ht .= '<p>‰æ‘œƒf[ƒ^ƒx[ƒX‚ðÅ“K‰»‚µ‚Ü‚µ‚½B</p>';
                 }
             }
 
-            // SQLite3 ‚̈ꗗ•\Ž¦—pƒf[ƒ^ƒLƒƒƒbƒVƒ…‚ðVACUUM
-            if (file_exists($_conf['iv2_cache_db_path'])) {
+            // SQLite3 ‚̈ꗗ•\Ž¦—pƒf[ƒ^ƒLƒƒƒbƒVƒ…‚ðVACUUM,REINDX
+            if ($viewer_cache_exists) {
                 $kvs = P2KeyValueStore::getStore($_conf['iv2_cache_db_path'],
                                                  P2KeyValueStore::CODEC_SERIALIZING);
-                $kvs->vacuum();
+                $kvs->optimize();
                 unset($kvs);
-                $_info_msg_ht .= '<p>ˆê——•\Ž¦—p‚̃f[ƒ^ƒLƒƒƒbƒVƒ…‚𐮗‚µ‚Ü‚µ‚½B</p>';
+                $_info_msg_ht .= '<p>ˆê——•\Ž¦—p‚̃f[ƒ^ƒLƒƒƒbƒVƒ…‚ðÅ“K‰»‚µ‚Ü‚µ‚½B</p>';
             }
             break;
 
+        // –¢’è‹`‚̃ŠƒNƒGƒXƒg
         default:
-            $_info_msg_ht .= '<p>•s³‚ȃNƒGƒŠ: ' . htmlspecialchars($_POST['action'], ENT_QUOTES) . '</p>';
+            $_info_msg_ht .= '<p>–¢’è‹`‚̃ŠƒNƒGƒXƒg‚Å‚·B</p>';
+    }
 
-    }
     if (isset($removed_files)) {
         $flexy->setData('removedFiles', $removed_files);
     }
@@ -183,6 +202,11 @@
 $flexy->setData('doctype', $_conf['doctype']);
 $flexy->setData('extra_headers',   $_conf['extra_headers_ht']);
 $flexy->setData('extra_headers_x', $_conf['extra_headers_xht']);
+if ($db->dsn['phptype'] == 'sqlite' || $viewer_cache_exists) {
+    $flexy->setData('enable_optimize_db', true);
+} else {
+    $flexy->setData('enable_optimize_db', false);
+}
 
 P2Util::header_nocache();
 $flexy->compile('ic2mng.tpl.html');

Modified: p2ex/trunk/index.php
===================================================================
--- p2ex/trunk/index.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/index.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -18,10 +18,21 @@
 // ‘Oˆ—
 //=============================================================
 // ƒAƒNƒZƒX‹‘”Û—p‚Ì.htaccess‚ðƒf[ƒ^ƒfƒBƒŒƒNƒgƒŠ‚ɍ쐬‚·‚é
-makeDenyHtaccess($_conf['pref_dir']);
-makeDenyHtaccess($_conf['dat_dir']);
-makeDenyHtaccess($_conf['idx_dir']);
-makeDenyHtaccess($_conf['db_dir']);
+$secret_dirs = array_unique(array(
+    $_conf['pref_dir'],
+    $_conf['dat_dir'],
+    $_conf['idx_dir'],
+    $_conf['db_dir'],
+    $_conf['admin_dir'],
+    $_conf['cache_dir'],
+    $_conf['cookie_dir'],
+    $_conf['compile_dir'],
+    $_conf['session_dir'],
+    $_conf['tmp_dir'],
+));
+foreach ($secret_dirs as $dir) {
+    makeDenyHtaccess($dir);
+}
 
 //=============================================================
 
@@ -89,11 +100,10 @@
     // PC—p HTMLƒvƒŠƒ“ƒg
     //======================================================
     //P2Util::header_nocache();
-    if ($_conf['doctype']) { 
-        echo str_replace(
-            array('Transitional', 'loose.dtd'),
-            array('Frameset', 'frameset.dtd'),
-            $_conf['doctype']);
+    if ($_conf['doctype']) {
+        echo str_replace(array('Transitional', 'loose.dtd'),
+                         array('Frameset', 'frameset.dtd'),
+                         $_conf['doctype']);
     }
     echo <<<EOHEADER
 <html lang="ja">
@@ -148,6 +158,9 @@
 {
     $hta = $dir . '/.htaccess';
     if (!file_exists($hta)) {
+        if (!is_dir($dir)) {
+            FileCtl::mkdir_for($hta);
+        }
         $data = 'Order allow,deny'."\n".'Deny from all'."\n";
         FileCtl::file_write_contents($hta, $data);
     }

Modified: p2ex/trunk/iv2.php
===================================================================
--- p2ex/trunk/iv2.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/iv2.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -174,19 +174,19 @@
     } else {
         $cache_clear = false;
     }
-    $do_vacuum = false;
+    $optimize_db = false;
 
     if ($cache_clear == 'all') {
         $kvs->clear();
-        $do_vacuum = true;
+        $optimize_db = true;
     } elseif ($cache_clear == 'gc') {
         $kvs->gc($cache_lifetime);
-        $do_vacuum = true;
+        $optimize_db = true;
     }
 
-    if ($do_vacuum) {
-        // ƒLƒƒƒbƒVƒ…‚ðVACUUM
-        $kvs->vacuum();
+    if ($optimize_db) {
+        // ƒLƒƒƒbƒVƒ…‚ðVACUUM,REINDEX
+        $kvs->optimize();
 
         // SQLite‚È‚çVACUUM‚ðŽÀs
         if ($db_class == 'db_sqlite') {
@@ -931,6 +931,16 @@
     no_loop: false,
     no_updown: false
 };
+p2BindReady(function(){
+    var toolbar = document.getElementById('toolbar');
+    var toolbarHeight = getCurrentStyle(toolbar).height;
+    if (toolbarHeight == 'auto') {
+        toolbarHeight = toolbar.clientHeight;
+    } else {
+        toolbarHeight = parsePixels(toolbarHeight);
+    }
+    document.getElementById('header').style.height = toolbarHeight + 'px';
+}, null);
 // ]]>
 </script>\n
 EOJS;

Added: p2ex/trunk/js/editpref.js
===================================================================
--- p2ex/trunk/js/editpref.js	                        (rev 0)
+++ p2ex/trunk/js/editpref.js	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,87 @@
+/**
+ * rep2expack - Ý’èŠÇ—ƒy[ƒW—pJavaScript
+ */
+
+// {{{ globals
+
+var _EDITPREF_ACTIVEDIVID = null;
+
+// }}}
+// {{{ showCacheMetaData()
+
+/**
+ * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚̃ƒ^ƒf[ƒ^‚ðƒ|ƒbƒvƒAƒbƒv•\Ž¦‚·‚é
+ */
+function showCacheMetaData(divID, event) {
+	var popup = document.getElementById(divID);
+	if (!popup) {
+		reutrn;
+	}
+
+	if (_EDITPREF_ACTIVEDIVID != divID) {
+		if (_EDITPREF_ACTIVEDIVID) {
+			// ’x‰„‚È‚µ‚Ń|ƒbƒvƒAƒbƒv‚ð‰B‚·
+			doHideResPopUp(_EDITPREF_ACTIVEDIVID);
+		}
+		_EDITPREF_ACTIVEDIVID = divID;
+		setCacheMetaDataPopUpHeight(popup);
+	} else if (popup.style.visibility != 'visible') {
+		setCacheMetaDataPopUpHeight(popup);
+	}
+
+	showResPopUp(divID, event);
+}
+
+// }}}
+// {{{ hideCacheMetaData()
+
+/**
+ * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚̃ƒ^ƒf[ƒ^‚ð‰B‚·
+ */
+function hideCacheMetaData(divID) {
+	hideResPopUp(divID);
+}
+
+// }}}
+// {{{ setCacheMetaDataPopUpHeight()
+
+/**
+ * ƒ|ƒbƒvƒAƒbƒv‚̍‚‚³‚𒲐®‚·‚é
+ */
+function setCacheMetaDataPopUpHeight(popup)
+{
+	var popupHeight, windowHeight;
+
+	windowHeight = getWindowHeight();
+	popup.style.height = 'auto';
+	popup.style.overflow = 'visible';
+	popupHeight = getCurrentStyle(popup).height;
+	if (popupHeight == 'auto') {
+		popupHeight = popup.clientHeight;
+	} else {
+		popupHeight = parsePixels(popupHeight);
+	}
+
+	if (popupHeight > windowHeight) {
+		if (windowHeight > 50) {
+			popupHeight = windowHeight - 20;
+		} else {
+			popupHeight = windowHeight;
+		}
+		popup.style.height = popupHeight + 'px';
+		popup.style.overflow = 'auto';
+	}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: javascript
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
+/* vim: set syn=javascript fenc=cp932 ai noet ts=4 sw=4 sts=4 fdm=marker: */

Modified: p2ex/trunk/js/motolspopup.js
===================================================================
--- p2ex/trunk/js/motolspopup.js	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/js/motolspopup.js	2010-01-17 09:10:54 UTC (rev 790)
@@ -39,7 +39,19 @@
 		title = '';
 	}
 
-	target = origin.hasAttribute('target') ? origin.getAttribute('target') : null;
+	if (typeof origin.hasAttribute == 'function') {
+		if (origin.hasAttribute('target')) {
+			target = origin.getAttribute('target');
+		} else {
+			target = null;
+		}
+	} else {
+		target = origin.getAttribute('target');
+	}
+	if (target && !target.length) {
+		target = null;
+	}
+
 	baseUrl = origin.getAttribute('href');
 	for (i = 0; i < l; i++) {
 		anchor = div.childNodes[i];

Modified: p2ex/trunk/js/respopup.js
===================================================================
--- p2ex/trunk/js/respopup.js	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/js/respopup.js	2010-01-17 09:10:54 UTC (rev 790)
@@ -195,6 +195,9 @@
 		var y_adjust = -10;	// yŽ²ˆÊ’u’²®
 		if (this.divID.indexOf('spm_') == 0) {
 			y_adjust = -10;
+		} else if (this.divID.indexOf('matome_cache_meta') == 0) {
+			x_adjust += 10;
+			y_adjust += 10;
 		}
 		if (this.popOBJ.style.visibility != "visible") {
 			this.popOBJ.style.zIndex = this.zNum;

Added: p2ex/trunk/lib/MatomeCache.php
===================================================================
--- p2ex/trunk/lib/MatomeCache.php	                        (rev 0)
+++ p2ex/trunk/lib/MatomeCache.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,144 @@
+<?php
+
+// {{{ MatomeCache
+
+/**
+ * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…ƒf[ƒ^ƒNƒ‰ƒX
+ */
+class MatomeCache
+{
+    // {{{ properties
+
+    /**
+     * ‚Ü‚Æ‚ß“Ç‚Ý‚Ì“à—e (HTML)
+     *
+     * @var string
+     */
+    private $_content;
+
+    /**
+     * ‚܂Ƃߓǂ݂̃ƒ^ƒf[ƒ^
+     *
+     * @var array
+     */
+    private $_metaData;
+
+    /**
+     * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚ðŽc‚·”
+     *
+     * @var int
+     */
+    private $_maxNumEntries;
+
+    /**
+     * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚ª—LŒø‚©‚Ç‚¤‚©
+     *
+     * @var bool
+     */
+    private $_enabled;
+
+    // }}}
+    // {{{ __construct()
+
+    /**
+     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
+     *
+     * “à—e‚ð‰Šú‰»‚µAƒL[‚ðŽæ“¾‚·‚éB
+     *
+     * @param string $title
+     * @param int $maxNumEntries
+     */
+    public function __construct($title, $maxNumEntries = -1)
+    {
+        $this->_content = '';
+        $this->_metaData = array(
+            'time' => time(),
+            'title' => $title,
+            'threads' => array(),
+            'size' => null,
+        );
+        $this->_maxNumEntries = $maxNumEntries;
+        if ($maxNumEntries == 0) {
+            $this->_enabled = false;
+        } else {
+            $this->_enabled = true;
+        }
+    }
+
+    // }}}
+    // {{{ __destruct()
+
+    /**
+     * ƒfƒXƒgƒ‰ƒNƒ^
+     *
+     * “à—e‚ð•Û‘¶‚µAŒÃ‚¢ƒLƒƒƒbƒVƒ…‚ðíœ‚·‚éB
+     * ƒXƒŒƒbƒhî•ñ‚ª‹ó‚̏ꍇ‚͐V’…ƒŒƒX‚È‚µ‚Æ‚Ý‚È‚µA•Û‘¶‚µ‚È‚¢B
+     *
+     * @param void
+     */
+    public function __destruct()
+    {
+        if ($this->_enabled && count($this->_metaData['threads'])) {
+            $this->_metaData['size'] = strlen($this->_content);
+            MatomeCacheList::add($this->_content, $this->_metaData);
+            if ($this->_maxNumEntries > 0) {
+                MatomeCacheList::trim($this->_maxNumEntries);
+            }
+        }
+    }
+
+    // }}}
+    // {{{ concat()
+
+    /**
+     * “à—e‚ð’ljÁ‚·‚é
+     *
+     * @param string $content
+     * @return void
+     */
+    public function concat($content)
+    {
+        if ($this->_enabled) {
+            $this->_content .= $content;
+        }
+    }
+
+    // }}}
+    // {{{ addReadThread()
+
+    /**
+     * ‚Ü‚Æ‚ß“Ç‚Ý‚ÉŠÜ‚Ü‚ê‚éƒXƒŒƒbƒhî•ñ‚ð’ljÁ‚·‚é
+     *
+     * @param ThreadRead $aThread
+     * @return void
+     */
+    public function addReadThread(ThreadRead $aThread)
+    {
+        if ($this->_enabled) {
+            $this->_metaData['threads'][] = array(
+                'title' => $aThread->ttitle_hd,
+                'host'=> $aThread->host,
+                'bbs'=> $aThread->bbs,
+                'key'=> $aThread->key,
+                'ls' => sprintf('%d-%dn',
+                                $aThread->resrange['start'],
+                                $aThread->resrange['to']),
+            );
+        }
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Added: p2ex/trunk/lib/MatomeCacheList.php
===================================================================
--- p2ex/trunk/lib/MatomeCacheList.php	                        (rev 0)
+++ p2ex/trunk/lib/MatomeCacheList.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,176 @@
+<?php
+
+// {{{ MatomeCacheList
+
+/**
+ * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…ƒŠƒXƒgƒNƒ‰ƒX
+ */
+class MatomeCacheList
+{
+    // {{{ add()
+
+    /**
+     * V‚µ‚¢ƒGƒ“ƒgƒŠ‚ð’ljÁ‚·‚é
+     *
+     * @param string $content
+     * @param array $metaData
+     * @return $key
+     */
+    static public function add($content, array $metaData)
+    {
+        $key = sprintf('%s%0.6f', self::getKeyPrefix(), microtime(true));
+        MatomeCacheDataStore::set($key, $content);
+        MatomeCacheMetaDataStore::set($key, $metaData);
+        return $key;
+    }
+
+    // }}}
+    // {{{ getKeyPrefix()
+
+    /**
+     * ƒL[Ú“ªŽ«‚ðŽæ“¾‚·‚é
+     *
+     * @param string $type
+     * @param bool $forSearch
+     * @return array
+     */
+    static public function getKeyPrefix($type = null)
+    {
+        global $_conf, $_login;
+
+        if ($type === null) {
+            if ($_conf['iphone']) {
+                $type = 'iphone';
+            } elseif ($_conf['ktai']) {
+                $type = 'ktai';
+            } else {
+                $type = 'pc';
+            }
+        }
+
+        return $_login->user_u . '/' . $type . '/';
+    }
+
+    // }}}
+    // {{{ getList()
+
+    /**
+     * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚̃ŠƒXƒg‚ðŽæ“¾‚·‚é
+     *
+     * @param string $type
+     * @return array
+     */
+    static public function getList($type = null)
+    {
+        $prefix = self::getKeyPrefix($type);
+        $orderBy = array('mtime' => 'DESC', 'key' => 'DESC');
+
+        return MatomeCacheMetaDataStore::getKVS()->getAll($prefix, $orderBy);
+    }
+
+    // }}}
+    // {{{ getAllList()
+
+    /**
+     * ‘S‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚̃ŠƒXƒg‚ðŽæ“¾‚·‚é
+     *
+     * @param string $type
+     * @return array
+     */
+    static public function getAllList()
+    {
+        $types = array('pc', 'ktai', 'iphone');
+        $lists = array();
+        foreach ($types as $type) {
+            $lists[$type] = self::getList($type);
+        }
+        return $list;
+    }
+
+    // }}}
+    // {{{ trim()
+
+    /**
+     * Žc‚·”‚ðŽw’肵‚ăLƒƒƒbƒVƒ…‚ðíœ‚·‚é
+     *
+     * @param int $number
+     * @return int
+     */
+    static public function trim($length, $type = null)
+    {
+        // $length‚ª•‰”‚̏ꍇ‚͍폜‚µ‚È‚¢
+        if ($length < 0) {
+            return false;
+        }
+
+        $prefix = self::getKeyPrefix($type);
+
+        // $length‚ªƒ[ƒ‚̏ꍇ‚Í‘SŒíœ
+        if ($length == 0) {
+            return self::clear($prefix);
+        }
+
+        // XVŽž‡‚Ƀ\[ƒg‚µ‚Ä$length+1”Ԗڂ̃ŒƒR[ƒh‚ðŽæ“¾
+        $kvs = MatomeCacheDataStore::getKVS();
+        $orderBy = array('mtime' => 'DESC', 'key' => 'DESC');
+        $result = $kvs->getAll($prefix, $orderBy, 1, $length, true);
+        if (empty($result)) {
+            return 0;
+        }
+
+        $mtime = current($result)->mtime;
+        $query = 'DELETE FROM $__table WHERE '
+               . P2KeyValueStore::C_KEY_BEGINS
+               . ' AND $__mtime <= :mtime';
+
+        // Œ©‚‚©‚Á‚½ƒŒƒR[ƒh‚ƁA‚»‚ê‚æ‚èXVŽž‚ªŒÃ‚¢ƒf[ƒ^‚ðíœ
+        $stmt = $kvs->prepare($query);
+        $kvs->bindValueForPrefixSearch($stmt, $prefix);
+        $stmt->bindValue(':mtime', $mtime, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            $numRemoved = $stmt->rowCount();
+        } else {
+            return false;
+        }
+
+        // ƒƒ^ƒf[ƒ^‚àíœ
+        $kvs = MatomeCacheMetaDataStore::getKVS();
+        $stmt = $kvs->prepare($query);
+        $kvs->bindValueForPrefixSearch($stmt, $prefix);
+        $stmt->bindValue(':mtime', $mtime, PDO::PARAM_INT);
+        $stmt->execute();
+
+        // íœ‚µ‚½ƒf[ƒ^”‚ð•Ô‚·
+        return $numRemoved;
+    }
+
+    // }}}
+    // {{{ optimize()
+    
+    /**
+     * ‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚ðÅ“K‰»‚·‚é
+     *
+     * @param void
+     * @return void
+     */
+    static public function optimize()
+    {
+        MatomeCacheDataStore::getKVS()->optimize();
+        MatomeCacheMetaDataStore::getKVS()->optimize();
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/P2DataStore/AbstractDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/AbstractDataStore.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/P2DataStore/AbstractDataStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -27,15 +27,17 @@
      * ƒf[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
      *
      * @param string $databasePath
-     * @param string $type
+     * @param string $codec
+     * @param string $tableName
      * @return P2KeyValueStore
      */
     static protected function _getKVS($databasePath,
-                                      $type = P2KeyValueStore::CODEC_SERIALIZING)
+                                      $codec = P2KeyValueStore::CODEC_SERIALIZING,
+                                      $tableName = null)
     {
         global $_conf;
 
-        $id = $type . ':' . $databasePath;
+        $id = $codec . ':' . $databasePath;
 
         if (array_key_exists($id, self::$_kvs)) {
             return self::$_kvs[$id];
@@ -46,7 +48,7 @@
         }
 
         try {
-            $kvs = P2KeyValueStore::getStore($databasePath, $type);
+            $kvs = P2KeyValueStore::getStore($databasePath, $codec, $tableName);
             self::$_kvs[$id] = $kvs;
         } catch (Exception $e) {
             p2die(get_class($e) . ': ' . $e->getMessage());
@@ -83,6 +85,7 @@
     static public function get($key)
     {
         return self::getKVS()->get($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -101,6 +104,7 @@
     static public function set($key, $value)
     {
         $kvs = self::getKVS();
+            // static::getKVS()
         if ($kvs->exists($key)) {
             return $kvs->update($key, $value);
         } else {
@@ -121,6 +125,7 @@
     static public function delete($key)
     {
         return self::getKVS()->delete($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -135,25 +140,8 @@
      */
     static public function clear($prefix = null)
     {
-        $kvs = self::getKVS();
-
-        if ($prefix === null) {
-            return $kvs->clear();
-        }
-
-        $pattern = str_replace(array(  '%',   '_',   '\\'),
-                               array('\\%', '\\_', '\\\\'),
-                               $kvs->encodeKey($prefix));
-        $query = 'DELETE FROM $__table WHERE $__key LIKE :pattern ESCAPE :escape';
-        $stmt = $kvs->prepare($query);
-        $stmt->bindValue(':pattern', $pattern);
-        $stmt->bindValue(':escape', '\\');
-
-        if ($stmt->execute()) {
-            return $stmt->rowCount();
-        } else {
-            return false;
-        }
+        return self::getKVS()->clear($prefix);
+            // static::getKVS();
     }
 
     // }}}

Modified: p2ex/trunk/lib/P2DataStore/CookieDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/CookieDataStore.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/P2DataStore/CookieDataStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -34,6 +34,7 @@
     static public function get($key)
     {
         return self::getKVS()->get($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -52,6 +53,7 @@
     static public function set($key, $value)
     {
         $kvs = self::getKVS();
+            // static::getKVS()
         if ($kvs->exists($key)) {
             return $kvs->update($key, $value);
         } else {
@@ -72,6 +74,7 @@
     static public function delete($key)
     {
         return self::getKVS()->delete($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -86,25 +89,8 @@
      */
     static public function clear($prefix = null)
     {
-        $kvs = self::getKVS();
-
-        if ($prefix === null) {
-            return $kvs->clear();
-        }
-
-        $pattern = str_replace(array(  '%',   '_',   '\\'),
-                               array('\\%', '\\_', '\\\\'),
-                               $kvs->encodeKey($prefix));
-        $query = 'DELETE FROM $__table WHERE $__key LIKE :pattern ESCAPE :escape';
-        $stmt = $kvs->prepare($query);
-        $stmt->bindValue(':pattern', $pattern);
-        $stmt->bindValue(':escape', '\\');
-
-        if ($stmt->execute()) {
-            return $stmt->rowCount();
-        } else {
-            return false;
-        }
+        return self::getKVS()->clear($prefix);
+            // static::getKVS();
     }
 
     // }}}

Added: p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php	                        (rev 0)
+++ p2ex/trunk/lib/P2DataStore/MatomeCacheDataStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,112 @@
+<?php
+/**
+ * rep2expack - V’…‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…ŠÇ—ƒNƒ‰ƒX
+ */
+
+// {{{ MatomeCacheDataStore
+
+class MatomeCacheDataStore extends AbstractDataStore
+{
+    // {{{ getKVS()
+
+    /**
+     * ‘‚«ž‚݃f[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
+     *
+     * @param void
+     * @return P2KeyValueStore
+     */
+    static public function getKVS()
+    {
+        return self::_getKVS($GLOBALS['_conf']['matome_db_path'],
+                             P2KeyValueStore::CODEC_COMPRESSING);
+    }
+
+    // }}}
+    // {{{ AbstractDataStore.php ‚©‚ç‚̃Rƒsƒy / PHP 5.3 ‚Ì’x‰„Ã“I‘©”›‚ðŽg‚Á‚č폜‚µ‚½‚¢
+    // {{{ get()
+
+    /**
+     * ƒf[ƒ^‚ðŽæ“¾‚·‚é
+     *
+     * @param string $key
+     * @return mixed
+     * @see P2KeyValueStore::get()
+     */
+    static public function get($key)
+    {
+        return self::getKVS()->get($key);
+            // static::getKVS()
+    }
+
+    // }}}
+    // {{{ set()
+
+    /**
+     * ƒf[ƒ^‚ð•Û‘¶‚·‚é
+     *
+     * @param string $key
+     * @param mixed $value
+     * @return bool
+     * @see P2KeyValueStore::exists(),
+     *      P2KeyValueStore::set(),
+     *      P2KeyValueStore::update()
+     */
+    static public function set($key, $value)
+    {
+        $kvs = self::getKVS();
+            // static::getKVS()
+        if ($kvs->exists($key)) {
+            return $kvs->update($key, $value);
+        } else {
+            return $kvs->set($key, $value);
+        }
+    }
+
+    // }}}
+    // {{{ delete()
+
+    /**
+     * ƒf[ƒ^‚ðíœ‚·‚é
+     *
+     * @param string $key
+     * @return bool
+     * @see P2KeyValueStore::delete()
+     */
+    static public function delete($key)
+    {
+        return self::getKVS()->delete($key);
+            // static::getKVS()
+    }
+
+    // }}}
+    // {{{ clear()
+
+    /**
+     * ‚·‚ׂẴf[ƒ^‚Ü‚½‚̓L[‚ªŽw’肳‚ꂽÚ“ªŽ«‚ÅŽn‚Ü‚éƒf[ƒ^‚ðíœ‚·‚é
+     *
+     * @param string $prefix
+     * @return int
+     * @see P2KeyValueStore::clear()
+     */
+    static public function clear($prefix = null)
+    {
+        return self::getKVS()->clear($prefix);
+            // static::getKVS();
+    }
+
+    // }}}
+    // }}} ƒRƒsƒy‚±‚±‚Ü‚Å
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Added: p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php	                        (rev 0)
+++ p2ex/trunk/lib/P2DataStore/MatomeCacheMetaDataStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,112 @@
+<?php
+/**
+ * rep2expack - V’…‚܂Ƃߓǂ݃LƒƒƒbƒVƒ…‚̃ƒ^ƒf[ƒ^ŠÇ—ƒNƒ‰ƒX
+ */
+
+// {{{ MatomeCacheMetaDataStore
+
+class MatomeCacheMetaDataStore extends AbstractDataStore
+{
+    // {{{ getKVS()
+
+    /**
+     * ‘‚«ž‚݃f[ƒ^‚ð•Û‘¶‚·‚éP2KeyValueStoreƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
+     *
+     * @param void
+     * @return P2KeyValueStore
+     */
+    static public function getKVS()
+    {
+        return self::_getKVS($GLOBALS['_conf']['matome_db_path'],
+                             P2KeyValueStore::CODEC_ARRAYSHIFTJIS);
+    }
+
+    // }}}
+    // {{{ AbstractDataStore.php ‚©‚ç‚̃Rƒsƒy / PHP 5.3 ‚Ì’x‰„Ã“I‘©”›‚ðŽg‚Á‚č폜‚µ‚½‚¢
+    // {{{ get()
+
+    /**
+     * ƒf[ƒ^‚ðŽæ“¾‚·‚é
+     *
+     * @param string $key
+     * @return mixed
+     * @see P2KeyValueStore::get()
+     */
+    static public function get($key)
+    {
+        return self::getKVS()->get($key);
+            // static::getKVS()
+    }
+
+    // }}}
+    // {{{ set()
+
+    /**
+     * ƒf[ƒ^‚ð•Û‘¶‚·‚é
+     *
+     * @param string $key
+     * @param mixed $value
+     * @return bool
+     * @see P2KeyValueStore::exists(),
+     *      P2KeyValueStore::set(),
+     *      P2KeyValueStore::update()
+     */
+    static public function set($key, $value)
+    {
+        $kvs = self::getKVS();
+            // static::getKVS()
+        if ($kvs->exists($key)) {
+            return $kvs->update($key, $value);
+        } else {
+            return $kvs->set($key, $value);
+        }
+    }
+
+    // }}}
+    // {{{ delete()
+
+    /**
+     * ƒf[ƒ^‚ðíœ‚·‚é
+     *
+     * @param string $key
+     * @return bool
+     * @see P2KeyValueStore::delete()
+     */
+    static public function delete($key)
+    {
+        return self::getKVS()->delete($key);
+            // static::getKVS()
+    }
+
+    // }}}
+    // {{{ clear()
+
+    /**
+     * ‚·‚ׂẴf[ƒ^‚Ü‚½‚̓L[‚ªŽw’肳‚ꂽÚ“ªŽ«‚ÅŽn‚Ü‚éƒf[ƒ^‚ðíœ‚·‚é
+     *
+     * @param string $prefix
+     * @return int
+     * @see P2KeyValueStore::clear()
+     */
+    static public function clear($prefix = null)
+    {
+        return self::getKVS()->clear($prefix);
+            // static::getKVS();
+    }
+
+    // }}}
+    // }}} ƒRƒsƒy‚±‚±‚Ü‚Å
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/P2DataStore/PostDataStore.php
===================================================================
--- p2ex/trunk/lib/P2DataStore/PostDataStore.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/P2DataStore/PostDataStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -34,6 +34,7 @@
     static public function get($key)
     {
         return self::getKVS()->get($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -52,6 +53,7 @@
     static public function set($key, $value)
     {
         $kvs = self::getKVS();
+            // static::getKVS()
         if ($kvs->exists($key)) {
             return $kvs->update($key, $value);
         } else {
@@ -72,6 +74,7 @@
     static public function delete($key)
     {
         return self::getKVS()->delete($key);
+            // static::getKVS()
     }
 
     // }}}
@@ -86,25 +89,8 @@
      */
     static public function clear($prefix = null)
     {
-        $kvs = self::getKVS();
-
-        if ($prefix === null) {
-            return $kvs->clear();
-        }
-
-        $pattern = str_replace(array(  '%',   '_',   '\\'),
-                               array('\\%', '\\_', '\\\\'),
-                               $kvs->encodeKey($prefix));
-        $query = 'DELETE FROM $__table WHERE $__key LIKE :pattern ESCAPE :escape';
-        $stmt = $kvs->prepare($query);
-        $stmt->bindValue(':pattern', $pattern);
-        $stmt->bindValue(':escape', '\\');
-
-        if ($stmt->execute()) {
-            return $stmt->rowCount();
-        } else {
-            return false;
-        }
+        return self::getKVS()->clear($prefix);
+            // static::getKVS();
     }
 
     // }}}

Added: p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/Array.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,82 @@
+<?php
+
+// {{{ P2KeyValueStore_Codec_Array
+
+/**
+ * ”z—ñ‚ðƒVƒŠƒAƒ‰ƒCƒYEƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚éCodec
+ *
+ * ƒVƒŠƒAƒ‰ƒCƒYŒã‚̃TƒCƒY‚ªˆ³k‚ð•K—v‚Æ‚·‚é‚Ù‚Ç‘å‚«‚­‚È‚¢ê‡‚ÉŽg‚¤B
+ * ”z—ñ‚Ì—v‘f‚É•¶Žš—ñ‚ðŠÜ‚ޏꍇA‘Ó–‚ÈUTF-8ƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃç‚È‚¢B
+ */
+class P2KeyValueStore_Codec_Array implements P2KeyValueStore_Codec_Interface
+{
+    // {{{ encodeKey()
+
+    /**
+     * ƒL[‚Í‚»‚Ì‚Ü‚Ü
+     *
+     * @param string $key
+     * @return string
+     */
+    public function encodeKey($key)
+    {
+        return $key;
+    }
+
+    // }}}
+    // {{{ decodeKey()
+
+    /**
+     * ƒL[‚Í‚»‚Ì‚Ü‚Ü
+     *
+     * @param string $key
+     * @return string
+     */
+    public function decodeKey($key)
+    {
+        return $key;
+    }
+
+    // }}}
+    // {{{ encodeValue()
+
+    /**
+     * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param array $array
+     * @return string
+     */
+    public function encodeValue($array)
+    {
+        return serialize($array);
+    }
+
+    // }}}
+    // {{{ decodeValue()
+
+    /**
+     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param string $value
+     * @return array
+     */
+    public function decodeValue($value)
+    {
+        return unserialize($value);
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Added: p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Codec/ArrayShiftJIS.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,58 @@
+<?php
+
+// {{{ P2KeyValueStore_Codec_ArrayShiftJIS
+
+/**
+ * ”z—ñ‚ðƒVƒŠƒAƒ‰ƒCƒYEƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚éCodec
+ *
+ * ƒVƒŠƒAƒ‰ƒCƒYŒã‚̃TƒCƒY‚ªˆ³k‚ð•K—v‚Æ‚·‚é‚Ù‚Ç‘å‚«‚­‚È‚¢ê‡‚ÉŽg‚¤B
+ * ”z—ñ‚Ì—v‘f‚ÉŠÜ‚Ü‚ê‚镶Žš—ñ‚͑Ó–‚ÈShift_JISƒV[ƒPƒ“ƒX‚Å‚È‚¯‚ê‚΂Ȃ炸A
+ * ƒL[‚͐”’l‚©US-ASCII•¶Žš—ñ‚Å‚ ‚邱‚Æ‚ðŠú‘Ò‚·‚éB
+ */
+class P2KeyValueStore_Codec_ArrayShiftJIS extends P2KeyValueStore_Codec_Array
+{
+    // {{{ encodeValue()
+
+    /**
+     * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param array $array
+     * @return string
+     */
+    public function encodeValue($array)
+    {
+        mb_convert_variables('UTF-8', 'Shift_JIS', $array);
+        return parent::encodeValue($array);
+    }
+
+    // }}}
+    // {{{ decodeValue()
+
+    /**
+     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param string $value
+     * @return array
+     */
+    public function decodeValue($value)
+    {
+        $array = parent::decodeValue($value);
+        mb_convert_variables('SJIS-win', 'UTF-8', $array);
+        return $array;
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/P2KeyValueStore.php
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/P2KeyValueStore.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -34,11 +34,15 @@
     const Q_CLEAR       = 'DELETE FROM $__table';
     const Q_GC          = 'DELETE FROM $__table WHERE mtime < :expires';
 
+    const C_KEY_BEGINS = 'arkey LIKE :pattern ESCAPE :escape';
+
     const CODEC_DEFAULT     = 'P2KeyValueStore_Codec_Default';
     const CODEC_BINARY      = 'P2KeyValueStore_Codec_Binary';
     const CODEC_COMPRESSING = 'P2KeyValueStore_Codec_Compressing';
     const CODEC_SHIFTJIS    = 'P2KeyValueStore_Codec_ShiftJIS';
     const CODEC_SERIALIZING = 'P2KeyValueStore_Codec_Serializing';
+    const CODEC_ARRAY       = 'P2KeyValueStore_Codec_Array';
+    const CODEC_ARRAYSHIFTJIS = 'P2KeyValueStore_Codec_ArrayShiftJIS';
 
     const MEMORY_DATABASE   = ':memory:';
 
@@ -101,10 +105,13 @@
      *
      * @param string $fileName
      * @param string $codec
+     * @param string $tableName
      * @return P2KeyValueStore
      * @throws PDOException
      */
-    static public function getStore($fileName, $codec = self::CODEC_DEFAULT)
+    static public function getStore($fileName,
+                                    $codec = self::CODEC_DEFAULT,
+                                    $tableName = null)
     {
         // ƒIƒuƒWƒFƒNƒgID‚ƃe[ƒuƒ‹–¼‚ðŒˆ’è
         if (is_object($codec)) {
@@ -112,14 +119,20 @@
         } else {
             $className = $codec;
         }
+
         $lcName = strtolower($className);
         if (strpos($lcName, 'p2keyvaluestore_codec_') === 0) {
             $codecId = substr($lcName, 22);
         } else {
             $codecId = 'user_' . $lcName;
         }
+
         $kvsId = $lcName . ':' . $fileName;
-        $tableName = 'kvs_' . $codecId;
+        if ($tableName === null) {
+            $tableName = 'kvs_' . $codecId;
+        } else {
+            $kvsId = strtolower($tableName) . ':' . $kvsId;
+        }
 
         // P2KeyValueStore‚̃LƒƒƒbƒVƒ…‚ðŠm”F
         if (array_key_exists($kvsId, self::$_kvsCache)) {
@@ -131,6 +144,7 @@
             $pdo = self::$_pdoCache[$fileName];
         } else {
             $pdo = new PDO('sqlite:' . $fileName);
+            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             self::$_pdoCache[$fileName] = $pdo;
         }
 
@@ -237,14 +251,41 @@
      */
     public function prepare($query, $forwardOnly = true)
     {
-        return $this->_prepare(str_replace(array('$__key', '$__value'),
-                                           array( 'arkey',    'value'),
-                                           $query),
-                               true,
-                               $forwardOnly);
+        $mapping = array(
+            '$__key'   => 'arkey',
+            '$__value' => 'value',
+            '$__mtime' => 'mtime',
+            '$__order' => 'sort_order',
+        );
+
+        $query = str_replace(array_keys($mapping), array_values($mapping), $query);
+
+        return $this->_prepare($query, true, $forwardOnly);
     }
 
     // }}}
+    // {{{ bindValueForPrefixSearch()
+
+    /**
+     * ƒŒƒR[ƒh‚ðÚ“ªŽ«‚ÅŒŸõ‚·‚éÛ‚Ì’l‚ðƒGƒXƒP[ƒv&ƒoƒCƒ“ƒh‚·‚é
+     *
+     * @param PDOStatement $stmt
+     * @param string $prefix
+     * @param string $escape
+     * @return void
+     */
+    public function bindValueForPrefixSearch(PDOStatement $stmt,
+                                             $prefix,
+                                             $escape = '\\')
+    {
+        $pattern = str_replace(array('%', '_', $escape),
+                               array("{$escape}%", "{$escape}_", "{$escape}{$escape}"),
+                               $this->_codec->encodeKey($prefix)) . '%';
+        $stmt->bindValue(':pattern', $pattern);
+        $stmt->bindValue(':escape', $escape);
+    }
+
+    // }}}
     // {{{ buildOrderBy()
 
     /**
@@ -273,15 +314,11 @@
         foreach ($orderBy as $column => $direction) {
             $column = strtolower($column);
             if (array_key_exists($column, $mapping)) {
-                $condition = $mapping[$column] . ' ';
+                $condition = $mapping[$column];
                 if (strcasecmp($direction, 'ASC') == 0) {
-                    $condition .= 'ASC';
+                    $condition .= ' ASC';
                 } elseif (strcasecmp($direction, 'DESC') == 0) {
-                    $condition .= 'DESC';
-                } elseif (0 < (int)$direction) {
-                    $condition .= 'ASC';
-                } else {
-                    $condition .= 'DESC';
+                    $condition .= ' DESC';
                 }
             }
             $terms[] = $condition;
@@ -371,7 +408,7 @@
             return null;
         } else {
             return array(
-                'key' => $this->_codec->decodeKey($row->key),
+                'key' => $this->_codec->decodeKey($row->arkey),
                 'value' => $this->_codec->decodeValue($row->value),
             );
         }
@@ -438,33 +475,43 @@
      * ‘S‚ẴŒƒR[ƒh‚ð˜A‘z”z—ñ‚Æ‚µ‚Ä•Ô‚·
      * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
      *
+     * @param string $prefix
      * @param array $orderBy
      * @param int $limit
      * @param int $offset
      * @param bool $getRaw
      * @return array
      */
-    public function getAll(array $orderBy = null,
-                           $limit = null, $offset = null,
+    public function getAll($prefix = null,
+                           array $orderBy = null,
+                           $limit = null,
+                           $offset = null,
                            $getRaw = false)
     {
-        $query = self::Q_GETALL
-               . $this->buildOrderBy($orderBy)
-               . $this->buildLimit($limit, $offset);
+        $query = self::Q_GETALL;
+        if ($prefix !== null) {
+            $query .= ' WHERE ' . self::C_KEY_BEGINS;
+        }
+        $query.= $this->buildOrderBy($orderBy);
+        $query.= $this->buildLimit($limit, $offset);
+
         $stmt = $this->_prepare($query, true);
+        if ($prefix !== null) {
+            $this->bindValueForPrefixSearch($stmt, $prefix);
+        }
         $stmt->execute();
 
         $values = array();
         if ($getRaw) {
             $stmt->setFetchMode(PDO::FETCH_CLASS, 'P2KeyValueStore_Result');
             while ($row = $stmt->fetch()) {
-                $values[$this->_codec->decodeKey($row->key)] = $row;
+                $values[$this->_codec->decodeKey($row->arkey)] = $row;
             }
         } else {
             $stmt->setFetchMode(PDO::FETCH_INTO, $this->_sharedResult);
             while ($row = $stmt->fetch()) {
                 $value = $this->_codec->decodeValue($row->value);
-                $values[$this->_codec->decodeKey($row->key)] = $value;
+                $values[$this->_codec->decodeKey($row->arkey)] = $value;
             }
         }
 
@@ -479,17 +526,28 @@
      * Žå‚Æ‚µ‚ÄP2KeyValueStore_Iterator‚ÅŽg‚¤
      * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
      *
+     * @param string $prefix
      * @param array $orderBy
      * @param int $limit
      * @param int $offset
      * @return array
      */
-    public function getIds(array $orderBy = null, $limit = null, $offset = null)
+    public function getIds($prefix = null,
+                           array $orderBy = null,
+                           $limit = null,
+                           $offset = null)
     {
-        $query = self::Q_GETIDS
-               . $this->buildOrderBy($orderBy)
-               . $this->buildLimit($limit, $offset);
+        $query = self::Q_GETIDS;
+        if ($prefix !== null) {
+            $query .= ' WHERE ' . self::C_KEY_BEGINS;
+        }
+        $query.= $this->buildOrderBy($orderBy);
+        $query.= $this->buildLimit($limit, $offset);
+
         $stmt = $this->_prepare($query, true);
+        if ($prefix !== null) {
+            $this->bindValueForPrefixSearch($stmt, $prefix);
+        }
         $stmt->execute();
 
         return $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
@@ -502,19 +560,30 @@
      * ‘S‚ẴL[‚Ì”z—ñ‚ð•Ô‚·
      * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
      *
+     * @param string $prefix
      * @param array $orderBy
      * @param int $limit
      * @param int $offset
      * @return array
      */
-    public function getKeys(array $orderBy = null, $limit = null, $offset = null)
+    public function getKeys($prefix = null,
+                            array $orderBy = null,
+                            $limit = null,
+                            $offset = null)
     {
-        $query = self::Q_GETKEYS
-               . $this->buildOrderBy($orderBy)
-               . $this->buildLimit($limit, $offset);
+        $query = self::Q_GETKEYS;
+        if ($prefix !== null) {
+            $query .= ' WHERE ' . self::C_KEY_BEGINS;
+        }
+        $query.= $this->buildOrderBy($orderBy);
+        $query.= $this->buildLimit($limit, $offset);
+
         $stmt = $this->_prepare($query, true);
+        if ($prefix !== null) {
+            $this->bindValueForPrefixSearch($stmt, $prefix);
+        }
+        $stmt->execute();
         $stmt->setFetchMode(PDO::FETCH_COLUMN, 0);
-        $stmt->execute();
 
         $keys = array();
         while (($key = $stmt->fetch()) !== false) {
@@ -664,14 +733,23 @@
     // {{{ clear()
 
     /**
-     * ‚·‚ׂẴŒƒR[ƒh‚ðíœ‚·‚é
+     * ‚·‚ׂẴŒƒR[ƒh‚Ü‚½‚̓L[‚ªŽw’肳‚ꂽÚ“ªŽ«‚ÅŽn‚܂郌ƒR[ƒh‚ðíœ‚·‚é
      *
-     * @param void
+     * @param string $prefix
      * @return int
      */
-    public function clear()
+    public function clear($prefix = null)
     {
-        $stmt = $this->_prepare(self::Q_CLEAR, true);
+        $query = self::Q_CLEAR;
+        if ($prefix !== null) {
+            $query .= ' WHERE ' . self::C_KEY_BEGINS;
+        }
+
+        $stmt = $this->_prepare($query, true);
+        if ($prefix !== null) {
+            $this->bindValueForPrefixSearch($stmt, $prefix);
+        }
+
         if ($stmt->execute()) {
             return $stmt->rowCount();
         } else {
@@ -700,19 +778,20 @@
     }
 
     // }}}
-    // {{{ vacuum()
+    // {{{ optimize()
 
     /**
-     * ì¬Ï‚݃vƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðƒNƒŠƒA‚µAVACUUM‚𔭍s‚·‚é
+     * ì¬Ï‚݃vƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðƒNƒŠƒA‚µAVACUUM‚ÆREINDEX‚𔭍s‚·‚é
      * ‘¼‚̃vƒƒZƒX‚ª“¯‚¶ƒf[ƒ^ƒx[ƒX‚ðŠJ‚¢‚Ä‚¢‚é‚Æ‚«‚ÉŽÀs‚·‚ׂ«‚Å‚Í‚È‚¢
      *
      * @param void
      * @return void
      */
-    public function vacuum()
+    public function optimize()
     {
         self::$_stmtCache[$this->_pdoId] = array();
         $this->_pdo->exec('VACUUM');
+        $this->_pdo->exec('REINDEX');
     }
 
     // }}}

Modified: p2ex/trunk/lib/P2Util.php
===================================================================
--- p2ex/trunk/lib/P2Util.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/P2Util.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -1142,9 +1142,7 @@
      */
     static public function isBrowserSafariGroup()
     {
-        return (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari')      !== false ||
-                strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') !== false ||
-                strpos($_SERVER['HTTP_USER_AGENT'], 'Konqueror')   !== false);
+        return UA::isSafariGroup();
     }
 
     // }}}
@@ -1166,8 +1164,7 @@
      */
     static public function isBrowserNintendoDS()
     {
-        return (strpos($_SERVER['HTTP_USER_AGENT'], 'Nitro') !== false &&
-                strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false);
+        return UA::isNintendoDS();
     }
 
     // }}}
@@ -1178,34 +1175,21 @@
      */
     static public function isBrowserPSP()
     {
-        return (strpos($_SERVER['HTTP_USER_AGENT'], 'PlayStation Portable') !== false);
+        return UA::isPSP();
     }
 
     // }}}
     // {{{ isBrowserIphone()
 
     /**
-     * ƒuƒ‰ƒEƒU‚ªiPhone or iPod Touch‚È‚çtrue‚ð•Ô‚·
+     * ƒuƒ‰ƒEƒU‚ªiPhone, iPod Touch or Android‚È‚çtrue‚ð•Ô‚·
      */
     static public function isBrowserIphone()
     {
-        return (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false ||
-                strpos($_SERVER['HTTP_USER_AGENT'], 'iPod')   !== false);
+        return UA::isIPhoneGroup();
     }
 
     // }}}
-    // }}}
-    // {{{ isBrowserAndroid()
-
-    /**
-     * ƒuƒ‰ƒEƒU‚ªAndroidh‚È‚çtrue‚ð•Ô‚·
-     */
-    static public function isBrowserAndroid()
-    {
-        return (strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false);
-    }
-
-    // }}}
     // {{{ isUrlWikipediaJa()
 
     /**
@@ -1305,7 +1289,7 @@
             $key .= $_SESSION['login_microtime'];
         }
 
-        return self::urlSafeBase64Encode(sha1($key, true));
+        return UrlSafeBase64::encode(sha1($key, true));
     }
 
     // }}}
@@ -1999,38 +1983,6 @@
     }
 
     // }}}
-    // {{{ urlSafeBase64Decode()
-
-    /**
-     * URL-safe Base64 ƒfƒR[ƒh
-     *
-     * @param string $str
-     * @return string
-     */
-    static public function urlSafeBase64Decode($str)
-    {
-        $mod = strlen($str) % 4;
-        if ($mod) {
-            $str .= str_repeat('=', 4 - $mod);
-        }
-        return base64_decode(strtr($str, '-_', '+/'), true);
-    }
-
-    // }}}
-    // {{{ urlSafeBase64Encode()
-
-    /**
-     * URL-safe Base64 ƒGƒ“ƒR[ƒh
-     *
-     * @param string $str
-     * @return string
-     */
-    static public function urlSafeBase64Encode($str)
-    {
-        return strtr(rtrim(base64_encode($str), '='), '+/', '-_');
-    }
-
-    // }}}
     // {{{ rawurldecodeCallback()
 
     /**

Modified: p2ex/trunk/lib/UA.php
===================================================================
--- p2ex/trunk/lib/UA.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/UA.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -429,7 +429,7 @@
         }
 
         // Mozilla/4.0 (PSP (PlayStation Portable); 2.00)
-        if (preg_match('/PlayStation Portable/', $ua)) {
+        if (false !== strpos($ua, 'PlayStation Portable')) {
             return true;
         }
         return false;
@@ -451,7 +451,7 @@
         }
 
         // Mozilla/4.0 (compatible; MSIE 6.0; Nitro) Opera 8.5 [ja]
-        if (preg_match('/ Nitro/', $ua)) {
+        if (false !== strpos($ua, ' Nitro')) {
             return true;
         }
         return false;

Added: p2ex/trunk/lib/UrlSafeBase64.php
===================================================================
--- p2ex/trunk/lib/UrlSafeBase64.php	                        (rev 0)
+++ p2ex/trunk/lib/UrlSafeBase64.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,55 @@
+<?php
+
+// {{{ UrlSafeBase64
+
+/**
+ * ƒGƒXƒP[ƒv‚¹‚¸‚ÉURL‚É–„‚ߍž‚ß‚éBase64•ÏŠ·ƒNƒ‰ƒX
+ */
+class UrlSafeBase64
+{
+    // {{{ decode()
+
+    /**
+     * URL-safe Base64 ƒfƒR[ƒh
+     *
+     * @param string $str
+     * @return string
+     */
+    static public function decode($str)
+    {
+        $mod = strlen($str) % 4;
+        if ($mod) {
+            $str .= str_repeat('=', 4 - $mod);
+        }
+        return base64_decode(strtr($str, '-_', '+/'), true);
+    }
+
+    // }}}
+    // {{{ encode()
+
+    /**
+     * URL-safe Base64 ƒGƒ“ƒR[ƒh
+     *
+     * @param string $str
+     * @return string
+     */
+    static public function encode($str)
+    {
+        return strtr(rtrim(base64_encode($str), '='), '+/', '-_');
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/bootstrap.php
===================================================================
--- p2ex/trunk/lib/bootstrap.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/bootstrap.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -157,10 +157,11 @@
 
 $_conf['use_cookies'] = true;
 
-$mobile = Net_UserAgent_Mobile::singleton();
+$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
+$mobile = Net_UserAgent_Mobile::singleton($userAgent);
 
 // iPhone, iPod Touch or Android
-if (P2Util::isBrowserIphone() || P2Util::isBrowserAndroid()) {
+if (UA::isIPhoneGroup($userAgent)) {
     $_conf['ktai'] = true;
     $_conf['iphone'] = true;
     $_conf['input_type_search'] = true;
@@ -169,7 +170,7 @@
 // PC“™
 } elseif ($mobile->isNonMobile()) {
     // Safari
-    if (P2Util::isBrowserSafariGroup()) {
+    if (UA::isSafariGroup($userAgent)) {
         $_conf['input_type_search'] = true;
         $_conf['accept_charset'] = 'UTF-8';
 
@@ -178,7 +179,7 @@
         $_conf['ktai'] = true;
 
     // Œg‘уQ[ƒ€‹@
-    } elseif (P2Util::isBrowserNintendoDS() || P2Util::isBrowserPSP()) {
+    } elseif (UA::isNintendoDS($userAgent) || UA::isPSP($userAgent)) {
         $_conf['ktai'] = true;
     }
 

Modified: p2ex/trunk/lib/expack/ic2/templates/ic2mng.tpl.html
===================================================================
--- p2ex/trunk/lib/expack/ic2/templates/ic2mng.tpl.html	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/expack/ic2/templates/ic2mng.tpl.html	2010-01-17 09:10:54 UTC (rev 790)
@@ -84,10 +84,9 @@
 		[<a href="ic2_viewtable.php?table=blacklist#footer" target="read">ƒuƒ‰ƒbƒNƒŠƒXƒg‚ðŒ©‚é</a>]
 	</div>
 
-	<div>
-		<input type="radio" name="action" id="action_vacuumDB" value="vacuumDB" onclick="dropZeroOptions(false)" />
-		<label for="action_vacuumDB">ƒf[ƒ^ƒx[ƒX‚𐮗‚·‚é</label>
-		<!-- VACUUM‚ðŽÀs -->
+	<div flexy:if="enable_optimize_db">
+		<input type="radio" name="action" id="action_optimizeDB" value="optimizeDB" onclick="dropZeroOptions(false)" />
+		<label for="action_optimizeDB">ƒf[ƒ^ƒx[ƒX‚ðÅ“K‰»‚·‚é</label>
 	</div>
 
 	<hr />

Deleted: p2ex/trunk/lib/read_new.inc.php
===================================================================
--- p2ex/trunk/lib/read_new.inc.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/read_new.inc.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -1,171 +0,0 @@
-<?php
-/**
- * rep2 - for read_new.php, read_new_k.php
- */
-
-// {{{ saveMatomeCache()
-
-/**
- * V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ðŽc‚·
- *
- * register_shutdown_function() ‚©‚çŒÄ‚΂ê‚éBi‘Š‘΃pƒX‚̃tƒ@ƒCƒ‹‚͈µ‚¦‚È‚¢Hj
- */
-function saveMatomeCache()
-{
-    global $_conf;
-
-    if (!empty($GLOBALS['pref_dir_realpath_failed_msg'])) {
-        return false;
-    }
-
-    if (!empty($GLOBALS['matome_naipo'])) {
-        return true;
-    }
-
-    if ($_conf['ktai']) {
-        $ext = '.k' . $_conf['matome_cache_ext'];
-    } else {
-        $ext = $_conf['matome_cache_ext'];
-    }
-
-    $lock = new P2Lock($_conf['matome_cache_path'] . $ext, false);
-
-    // ƒ[ƒe[ƒVƒ‡ƒ“
-    $max = $_conf['matome_cache_max'];
-    $i = $max;
-    while ($i >= 0) {
-        $di = ($i == 0) ? '' : '.'.$i;
-        $tfile = $_conf['matome_cache_path'] . $di . $ext;
-        $next = $i + 1;
-        $nfile = $_conf['matome_cache_path'] . '.' . $next . $ext;
-        if (file_exists($tfile)) {
-            if ($i == $max) {
-                unlink($tfile);
-            } else {
-                if (P2_OS_WINDOWS && file_exists($nfile)) {
-                    unlink($nfile);
-                }
-                rename($tfile, $nfile);
-            }
-        }
-        $i--;
-    }
-
-    // V‹K‹L˜^
-    $file = $_conf['matome_cache_path'] . $ext;
-    //echo "<!-- {$file} -->";
-
-    FileCtl::make_datafile($file, $_conf['p2_perm']);
-    if (FileCtl::file_write_contents($file, $GLOBALS['read_new_html']) === false) {
-        p2die('cannot write file.');
-    }
-
-    return true;
-}
-
-// }}}
-// {{{ saveMatomeCacheFromTmpFile()
-
-/**
- * V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ðŽc‚·iˆêŽžƒtƒ@ƒCƒ‹‚ɏ‘‚«ž‚ñ‚¾“à—e‚ð‰ü‚߂ăLƒƒƒbƒVƒ…‚É•Û‘¶j
- */
-function saveMatomeCacheFromTmpFile()
-{
-    global $_conf;
-
-    if (!empty($GLOBALS['pref_dir_realpath_failed_msg'])) {
-        return false;
-    }
-
-    if (!empty($GLOBALS['matome_naipo'])) {
-        return true;
-    }
-
-    if (!is_resource($GLOBALS['read_new_tmp_fh'])) {
-        return false;
-    }
-
-    if ($_conf['ktai']) {
-        $ext = '.k' . $_conf['matome_cache_ext'];
-    } else {
-        $ext = $_conf['matome_cache_ext'];
-    }
-
-    // ƒ[ƒe[ƒVƒ‡ƒ“
-    $max = $_conf['matome_cache_max'];
-    $i = $max;
-    while ($i >= 0) {
-        $di = ($i == 0) ? '' : '.'.$i;
-        $tfile = $_conf['matome_cache_path'] . $di . $ext;
-        $next = $i + 1;
-        $nfile = $_conf['matome_cache_path'] . '.' . $next . $ext;
-        if (file_exists($tfile)) {
-            if ($i == $max) {
-                unlink($tfile);
-            } else {
-                rename($tfile, $nfile);
-            }
-        }
-        $i--;
-    }
-
-    // V‹K‹L˜^
-    $file = $_conf['matome_cache_path'] . $ext;
-    //echo "<!-- {$file} -->";
-
-    FileCtl::make_datafile($file, $_conf['p2_perm']);
-    $fh = fopen($file, 'wb');
-    if (!$fh) {
-        p2die('cannot write file.');
-    }
-    @flock($fh, LOCK_EX);
-    fseek($GLOBALS['read_new_tmp_fh'], 0);
-    do {
-        fwrite($fh, fread($GLOBALS['read_new_tmp_fh'], 100000));
-    } while (!feof($GLOBALS['read_new_tmp_fh']));
-    @flock($fh, LOCK_UN);
-    fclose($fh);
-
-    return true;
-}
-
-// }}}
-// {{{ getMatomeCache()
-
-/**
- * V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ðŽæ“¾
- */
-function getMatomeCache($num = '')
-{
-    global $_conf;
-
-    if ($_conf['ktai']) {
-        $ext = '.k' . $_conf['matome_cache_ext'];
-    } else {
-        $ext = $_conf['matome_cache_ext'];
-    }
-
-    $dnum = ($num) ? '.'.$num : '';
-    $file = $_conf['matome_cache_path'] . $dnum . $ext;
-
-    $cont = FileCtl::file_read_contents($file);
-
-    if (strlen($cont) > 0) {
-        return $cont;
-    } else {
-        return false;
-    }
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/lib/startup.funcs.php
===================================================================
--- p2ex/trunk/lib/startup.funcs.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/lib/startup.funcs.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -154,27 +154,29 @@
     if (preg_match('/^(?:
             BbsMap |
             BrdCtl |
-            BrdMenu(?:[A-Z][A-Za-z]*)? |
+            BrdMenu(?:Cate|Ita)? |
             DataPhp |
             FavSetManager |
             FileCtl |
             HostCheck |
             Login |
             MD5Crypt |
+            MatomeCache(List)? |
             NgAbornCtl |
             P2[A-Z][A-Za-z]* |
             PresetManager |
             ResHist |
             Session |
             SettingTxt |
-            ShowBrdMenu(?:[A-Z][A-Za-z]*)? |
-            ShowThread(?:[A-Z][A-Za-z]*)? |
+            ShowBrdMenu(?:K|Pc) |
+            ShowThread(?:K|Pc)? |
             StrCtl |
             StrSjis |
             SubjectTxt |
-            Thread(?:[A-Z][A-Za-z]*)? |
+            Thread(?:List|Read)? |
             UA |
-            Wap[A-Z][A-Za-z]*
+            UrlSafeBase64 |
+            Wap(UserAgent|Request|Response)
         )$/x', $name))
     {
         if (strncmp($name, 'Wap', 3) === 0) {

Modified: p2ex/trunk/read_new.php
===================================================================
--- p2ex/trunk/read_new.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/read_new.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -5,29 +5,9 @@
  */
 
 require_once './conf/conf.inc.php';
-require_once P2_LIB_DIR . '/read_new.inc.php';
 
 $_login->authorize(); // ƒ†[ƒU”FØ
 
-// ‚Ü‚Æ‚ß‚æ‚݂̃LƒƒƒbƒVƒ…“Ç‚Ý
-if (!empty($_GET['cview'])) {
-    $cnum = (isset($_GET['cnum'])) ? intval($_GET['cnum']) : NULL;
-    if ($cont = getMatomeCache($cnum)) {
-        echo $cont;
-    } else {
-        header('Content-Type: text/plain; charset=Shift_JIS');
-        echo 'p2 error: V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ª‚È‚¢‚æ';
-    }
-    exit;
-}
-
-// Èƒƒ‚ƒŠÝ’è
-// 1 ‚É‚·‚é‚ƃLƒƒƒbƒVƒ…‚ðƒƒ‚ƒŠ‚Å‚È‚­ˆêŽžƒtƒ@ƒCƒ‹‚É•ÛŽ‚·‚é
-// i‚Ç‚¿‚ç‚Å‚àÅI“I‚ɂ̓tƒ@ƒCƒ‹‚ɏ‘‚«ž‚Ü‚ê‚éj
-if (!defined('P2_READ_NEW_SAVE_MEMORY')) {
-    define('P2_READ_NEW_SAVE_MEMORY', 0);
-}
-
 //==================================================================
 // •Ï”
 //==================================================================
@@ -64,18 +44,6 @@
 // ƒƒCƒ“
 //====================================================================
 
-if (P2_READ_NEW_SAVE_MEMORY) {
-    register_shutdown_function('saveMatomeCacheFromTmpFile');
-    $read_new_tmp_fh = tmpfile();
-    if (!is_resource($read_new_tmp_fh)) {
-        p2die('cannot make tmpfile.');
-    }
-} else {
-    register_shutdown_function('saveMatomeCache');
-    $read_new_html = '';
-}
-ob_start();
-
 $aThreadList = new ThreadList();
 
 // ”‚ƃ‚[ƒh‚̃Zƒbƒg===================================
@@ -120,6 +88,8 @@
 // ƒy[ƒWƒwƒbƒ_•\Ž¦ ===================================
 $ptitle_hd = htmlspecialchars($aThreadList->ptitle, ENT_QUOTES);
 $ptitle_ht = "{$ptitle_hd} ‚Ì V’…‚Ü‚Æ‚ß“Ç‚Ý";
+$matomeCache = new MatomeCache($ptitle_hd, $_conf['matome_cache_max']);
+ob_start();
 
 if ($aThreadList->spmode) {
     $sb_ht = <<<EOP
@@ -349,26 +319,19 @@
     echo $_info_msg_ht;
     $_info_msg_ht = '';
 
-    if (P2_READ_NEW_SAVE_MEMORY) {
-        fwrite($read_new_tmp_fh, ob_get_flush());
-    } else {
-        $read_new_html .= ob_get_flush();
-    }
+    $matomeCache->concat(ob_get_flush());
     flush();
     ob_start();
 
     if (($aThread->readnum < 1) || $aThread->unum) {
         readNew($aThread);
+        $matomeCache->addReadThread($aThread);
     } elseif ($aThread->diedat) {
         echo $aThread->getdat_error_msg_ht;
         echo "<hr>\n";
     }
 
-    if (P2_READ_NEW_SAVE_MEMORY) {
-        fwrite($read_new_tmp_fh, ob_get_flush());
-    } else {
-        $read_new_html .= ob_get_flush();
-    }
+    $matomeCache->concat(ob_get_flush());
     flush();
     ob_start();
 
@@ -673,11 +636,7 @@
 
 echo '</body></html>';
 
-if (P2_READ_NEW_SAVE_MEMORY) {
-    fwrite($read_new_tmp_fh, ob_get_flush());
-} else {
-    $read_new_html .= ob_get_flush();
-}
+$matomeCache->concat(ob_get_flush());
 
 // NG‚ ‚ځ[‚ñ‚ð‹L˜^
 NgAbornCtl::saveNgAborns();

Added: p2ex/trunk/read_new_cache.php
===================================================================
--- p2ex/trunk/read_new_cache.php	                        (rev 0)
+++ p2ex/trunk/read_new_cache.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -0,0 +1,33 @@
+<?php
+/**
+ * rep2 - V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ð“Ç‚Þ
+ */
+
+require_once './conf/conf.inc.php';
+
+$_login->authorize();
+
+if (array_key_exists('ckey', $_GET) && is_string($_GET['ckey'])) {
+    $ckey = MatomeCacheList::getKeyPrefix() . $_GET['ckey'];
+    $cont = MatomeCacheDataStore::get($ckey);
+} else {
+    $cont = null;
+}
+
+if ($cont) {
+    echo $cont;
+} else {
+    header('Content-Type: text/plain; charset=Shift_JIS');
+    echo 'rep2 error: V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ª‚È‚¢‚æ';
+}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Modified: p2ex/trunk/read_new_k.php
===================================================================
--- p2ex/trunk/read_new_k.php	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/read_new_k.php	2010-01-17 09:10:54 UTC (rev 790)
@@ -5,29 +5,9 @@
  */
 
 require_once './conf/conf.inc.php';
-require_once P2_LIB_DIR . '/read_new.inc.php';
 
 $_login->authorize(); // ƒ†[ƒU”FØ
 
-// ‚Ü‚Æ‚ß‚æ‚݂̃LƒƒƒbƒVƒ…“Ç‚Ý
-if (!empty($_GET['cview'])) {
-    $cnum = (isset($_GET['cnum'])) ? intval($_GET['cnum']) : NULL;
-    if ($cont = getMatomeCache($cnum)) {
-        echo $cont;
-    } else {
-        header('Content-Type: text/plain; charset=Shift_JIS');
-        echo 'p2 error: V’…‚܂Ƃߓǂ݂̃LƒƒƒbƒVƒ…‚ª‚È‚¢‚æ';
-    }
-    exit;
-}
-
-// Èƒƒ‚ƒŠÝ’è
-// 1 ‚É‚·‚é‚ƃLƒƒƒbƒVƒ…‚ðƒƒ‚ƒŠ‚Å‚È‚­ˆêŽžƒtƒ@ƒCƒ‹‚É•ÛŽ‚·‚é
-// i‚Ç‚¿‚ç‚Å‚àÅI“I‚ɂ̓tƒ@ƒCƒ‹‚ɏ‘‚«ž‚Ü‚ê‚éj
-if (!defined('P2_READ_NEW_SAVE_MEMORY')) {
-    define('P2_READ_NEW_SAVE_MEMORY', 0);
-}
-
 //==================================================================
 // •Ï”
 //==================================================================
@@ -71,18 +51,6 @@
 // ƒƒCƒ“
 //====================================================================
 
-if (P2_READ_NEW_SAVE_MEMORY) {
-    register_shutdown_function('saveMatomeCacheFromTmpFile');
-    $read_new_tmp_fh = tmpfile();
-    if (!is_resource($read_new_tmp_fh)) {
-        p2die('cannot make tmpfile.');
-    }
-} else {
-    register_shutdown_function('saveMatomeCache');
-    $read_new_html = '';
-}
-ob_start();
-
 $aThreadList = new ThreadList();
 
 // ”‚ƃ‚[ƒh‚̃Zƒbƒg ===================================
@@ -127,6 +95,8 @@
 // ƒy[ƒWƒwƒbƒ_•\Ž¦ ===================================
 $ptitle_hd = htmlspecialchars($aThreadList->ptitle, ENT_QUOTES);
 $ptitle_ht = "{$ptitle_hd} ‚Ì V’…‚Ü‚Æ‚ß“Ç‚Ý";
+$matomeCache = new MatomeCache($ptitle_hd, $_conf['matome_cache_max']);
+ob_start();
 
 // &amp;sb_view={$sb_view}
 if ($aThreadList->spmode) {
@@ -331,28 +301,21 @@
     if ($aThread->isonline) { $online_num++; } // ¶‘¶”set
 
     echo $_info_msg_ht;
-    $_info_msg_ht = "";
+    $_info_msg_ht = '';
 
-    if (P2_READ_NEW_SAVE_MEMORY) {
-        fwrite($read_new_tmp_fh, ob_get_flush());
-    } else {
-        $read_new_html .= ob_get_flush();
-    }
+    $matomeCache->concat(ob_get_flush());
     flush();
     ob_start();
 
     if (($aThread->readnum < 1) || $aThread->unum) {
         readNew($aThread);
+        $matomeCache->addReadThread($aThread);
     } elseif ($aThread->diedat) {
         echo $aThread->getdat_error_msg_ht;
         echo "<hr>\n";
     }
 
-    if (P2_READ_NEW_SAVE_MEMORY) {
-        fwrite($read_new_tmp_fh, ob_get_flush());
-    } else {
-        $read_new_html .= ob_get_flush();
-    }
+    $matomeCache->concat(ob_get_flush());
     flush();
     ob_start();
 
@@ -632,11 +595,7 @@
 
 echo '</body></html>';
 
-if (P2_READ_NEW_SAVE_MEMORY) {
-    fwrite($read_new_tmp_fh, ob_get_flush());
-} else {
-    $read_new_html .= ob_get_flush();
-}
+$matomeCache->concat(ob_get_flush());
 
 // NG‚ ‚ځ[‚ñ‚ð‹L˜^
 NgAbornCtl::saveNgAborns();

Modified: p2ex/trunk/style/editpref_css.inc
===================================================================
--- p2ex/trunk/style/editpref_css.inc	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/style/editpref_css.inc	2010-01-17 09:10:54 UTC (rev 790)
@@ -29,6 +29,12 @@
 	margin-right: auto;
 }
 
+ul#matome_cache div.popup_element ul {
+	margin: 0;
+	padding: 0;
+	list-style-type: none;
+}
+
 EOSTYLE;
 
 /*

Modified: p2ex/trunk/style/iv2_css.inc
===================================================================
--- p2ex/trunk/style/iv2_css.inc	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/style/iv2_css.inc	2010-01-17 09:10:54 UTC (rev 790)
@@ -37,7 +37,7 @@
 }
 
 div#header {
-	height: 3.75em;
+	height: 4em;
 }
 
 div#content {

Modified: p2ex/trunk/style/style_css.inc
===================================================================
--- p2ex/trunk/style/style_css.inc	2010-01-16 22:49:33 UTC (rev 789)
+++ p2ex/trunk/style/style_css.inc	2010-01-17 09:10:54 UTC (rev 790)
@@ -115,6 +115,8 @@
 
 .popup_element {
 	position: absolute;
+	top: 0;
+	left: 0;
 	visibility: hidden; /* •’i‚͉B‚µ‚Ä‚¨‚­*/
 	{$respop_background}
 	{$respop_border}



P2-php-svn メーリングリストの案内
Back to archive index