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

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 22日 (金) 17:57:57 JST


Revision: 797
          http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=797
Author:   rsk
Date:     2010-01-22 17:57:56 +0900 (Fri, 22 Jan 2010)

Log Message:
-----------
expack:
- クライアントがiモードブラウザ2.xかどうかを判定するメソッド
  UA::isIModeBrowser2() を追加。
-- DoCoMo端末でもiモードブラウザ2.xのときはCookieを使うように変更。
- URLゲートウェイ変換の実装をP2Util::througIme()から新しいクラスP2Imeに分離。 
-- 変換処理はこれまでどおりP2Util::througIme()を使う。
- ユーザー設定編集で変更を確定後も、変更前のタブを復元するようにした。 
  (
- 設定管理 > ユーザ設定編集 > rep2基本設定 > ETC > through_ime_http_only を
  「HTTPSでは直」に設定すると、HTTPSでアクセスしているときは外部URLゲートを
  通さないようにした。既定値はこれまでと同じ「常に通す」。
  (最近のWebブラウザの多くは https → http の遷移でRefererを送出しないため)

Modified Paths:
--------------
    p2ex/trunk/conf/conf.inc.php
    p2ex/trunk/conf/conf_user_def.inc.php
    p2ex/trunk/edit_conf_user.php
    p2ex/trunk/js/edit_conf_user.js
    p2ex/trunk/lib/P2Util.php
    p2ex/trunk/lib/ShowThreadPc.php
    p2ex/trunk/lib/UA.php
    p2ex/trunk/lib/bootstrap.php

Added Paths:
-----------
    p2ex/trunk/lib/P2Ime.php


-------------- next part --------------
Modified: p2ex/trunk/conf/conf.inc.php
===================================================================
--- p2ex/trunk/conf/conf.inc.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/conf/conf.inc.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -90,7 +90,7 @@
     $_conf['expack.download_url']   = 'http://page2.skr.jp/rep2/downloads.html';
     $_conf['expack.history_url']    = 'http://page2.skr.jp/rep2/history.html';
     $_conf['expack.tgrep_url']      = 'http://page2.xrea.jp/tgrep/search';
-    $_conf['expack.ime_url']        = 'http://page2.skr.jp/gate.php';
+    $_conf['expack.gate_php']       = 'http://page2.skr.jp/gate.php';
     $_conf['menu_php']              = 'menu.php';
     $_conf['subject_php']           = 'subject.php';
     $_conf['read_php']              = 'read.php';
@@ -125,7 +125,7 @@
     ini_set('arg_separator.output', '&');
 
     // Windows ‚È‚ç
-    if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
+    if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
         // Windows
         defined('PATH_SEPARATOR') or define('PATH_SEPARATOR', ';');
         defined('DIRECTORY_SEPARATOR') or define('DIRECTORY_SEPARATOR', '\\');
@@ -136,6 +136,13 @@
         define('P2_OS_WINDOWS', 0);
     }
 
+    // HTTPSÚ‘±‚È‚ç
+    if (array_key_exists('HTTPS', $_SERVER) && strcasecmp($_SERVER['HTTPS'], 'on') === 0) {
+        define('P2_HTTPS_CONNECTION', 1);
+    } else {
+        define('P2_HTTPS_CONNECTION', 0);
+    }
+
     // ƒkƒ‹ƒoƒCƒg’萔
     // mbstring.script_encoding = SJIS-win ‚¾‚Æ
     // "\0", "\x00" ˆÈ~‚ªƒJƒbƒg‚³‚ê‚é‚̂ŁAchr()ŠÖ”‚ðŽg‚¤

Modified: p2ex/trunk/conf/conf_user_def.inc.php
===================================================================
--- p2ex/trunk/conf/conf_user_def.inc.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/conf/conf_user_def.inc.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -337,6 +337,10 @@
     'google' => 'Google',
 );
 
+// HTTPS‚ŃAƒNƒZƒX‚µ‚Ä‚¢‚é‚Æ‚«‚ÍŠO•”URLƒQ[ƒg‚ð’Ê‚³‚È‚¢iHTTPS‚Å‚Í’¼:1, í‚É’Ê‚·:0j
+$conf_user_def['through_ime_http_only'] = 0; // (0)
+$conf_user_rad['through_ime_http_only'] = array('1' => 'HTTPS‚Å‚Í’¼', '0' => 'í‚É’Ê‚·');
+
 // ƒQ[ƒg‚ÅŽ©“®“]‘—‚µ‚È‚¢Šg’£ŽqiƒJƒ“ƒ}‹æØ‚è‚ŁAŠg’£Žq‚Ì‘O‚̃sƒŠƒIƒh‚Í•s—vj
 $conf_user_def['ime_manual_ext'] = "exe,zip"; // ("exe,zip") 
 

Modified: p2ex/trunk/edit_conf_user.php
===================================================================
--- p2ex/trunk/edit_conf_user.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/edit_conf_user.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -86,19 +86,49 @@
 // {{{ Œg‘Ñ‚Å•\Ž¦‚·‚éƒOƒ‹[ƒv
 
 if ($_conf['ktai']) {
-    if (isset($_POST['edit_conf_user_group_en'])) {
-        $selected_group = UrlSafeBase64::decode($_POST['edit_conf_user_group_en']);
-    } elseif (isset($_POST['edit_conf_user_group'])) {
-        $selected_group = $_POST['edit_conf_user_group'];
-    } elseif (isset($_GET['edit_conf_user_group_en'])) {
-        $selected_group = UrlSafeBase64::decode($_GET['edit_conf_user_group_en']);
-    } elseif (isset($_GET['edit_conf_user_group'])) {
-        $selected_group = $_GET['edit_conf_user_group'];
+    if (isset($_REQUEST['edit_conf_user_group_en'])) {
+        $selected_group = UrlSafeBase64::decode($_REQUEST['edit_conf_user_group_en']);
+    } elseif (isset($_REQUEST['edit_conf_user_group'])) {
+        $selected_group = $_REQUEST['edit_conf_user_group'];
     } else {
         $selected_group = null;
     }
 } else {
     $selected_group = 'all';
+    if (isset($_REQUEST['active_tab1'])) {
+        $active_tab1 = $_REQUEST['active_tab1'];
+        $active_tab1_ht = htmlspecialchars($active_tab1, ENT_QUOTES);
+        $active_tab1_js = "'" . StrCtl::toJavaScript($active_tab1) . "'";
+    } else {
+        $active_tab1 = null;
+        $active_tab1_ht = '';
+        $active_tab1_js = 'null';
+    }
+    if (isset($_REQUEST['active_tab2'])) {
+        $active_tab2 = $_REQUEST['active_tab2'];
+        $active_tab2_ht = htmlspecialchars($active_tab2, ENT_QUOTES);
+        $active_tab2_js = "'" . StrCtl::toJavaScript($active_tab2) . "'";
+    } else {
+        $active_tab2 = null;
+        $active_tab2_ht = '';
+        $active_tab2_js = 'null';
+    }
+    $parent_tabs_js = "['" . implode("','", array(
+        StrCtl::toJavaScript('rep2Šî–{Ý’è'),
+        StrCtl::toJavaScript('Œg‘Ñ’[––Ý’è'),
+        StrCtl::toJavaScript('Šg’£ƒpƒbƒNÝ’è'),
+    )) . "']";
+    $active_tab_hidden_ht = <<<EOP
+<input type="hidden" id="active_tab1" name="active_tab1" value="{$active_tab1_ht}">
+<input type="hidden" id="active_tab2" name="active_tab2" value="{$active_tab2_ht}">
+<script type="text/javascript">
+// <![CDATA[
+_EDIT_CONF_USER_JS_PARENT_TABS = $parent_tabs_js;
+_EDIT_CONF_USER_JS_ACTIVE_TAB1 = $active_tab1_js;
+_EDIT_CONF_USER_JS_ACTIVE_TAB2 = $active_tab2_js;
+// ]]>
+</script>
+EOP;
 }
 
 $groups = array();
@@ -173,6 +203,7 @@
 
 // PC—p•\Ž¦
 if (!$_conf['ktai']) {
+    echo $active_tab_hidden_ht;
     echo <<<EOP
 <div class="tabber">
 <div class="tabbertab" title="rep2Šî–{Ý’è">
@@ -335,6 +366,7 @@
         array('res_hist_rec_num', '‘‚«ž‚Ý—š—ð‚Ì‹L˜^”'),
         array('res_write_rec', '‘‚«ž‚Ý“à—eƒƒO‚ð‹L˜^'),
         array('through_ime', 'ŠO•”URLƒWƒƒƒ“ƒv‚·‚éÛ‚É’Ê‚·ƒQ[ƒg<br>u’¼Úv‚Å‚àCookie‚ªŽg‚¦‚È‚¢’[––‚Å‚Í gate.php ‚ð’Ê‚·'),
+        array('through_ime_http_only', ' HTTPS‚ŃAƒNƒZƒX‚µ‚Ä‚¢‚é‚Æ‚«‚ÍŠO•”URLƒQ[ƒg‚ð’Ê‚³‚È‚¢<br>(Å‹ß‚ÌWebƒuƒ‰ƒEƒU‚Ì‘½‚­‚Í https ¨ http ‚Ì‘JˆÚ‚ÅReferer‚𑗏o‚µ‚Ü‚¹‚ñ‚ªA<br>uHTTPS‚Å‚Í’¼v‚É‚·‚éê‡‚́A‚¨Žg‚¢‚̃uƒ‰ƒEƒU‚ÌŽd—l‚ðŠm”F‚µ‚Ä‚­‚¾‚³‚¢)'),
         array('ime_manual_ext', 'ƒQ[ƒg‚ÅŽ©“®“]‘—‚µ‚È‚¢Šg’£ŽqiƒJƒ“ƒ}‹æØ‚è‚ŁAŠg’£Žq‚Ì‘O‚̃sƒŠƒIƒh‚Í•s—vj'),
         array('join_favrank', '<a href="http://akid.s17.xrea.com/favrank/favrank.html" target="_blank">‚¨‹C‚ɃXƒŒ‹¤—L</a>‚ÉŽQ‰Á'),
         array('merge_favita', '‚¨‹C‚ɔ‚̃XƒŒˆê——‚ð‚Ü‚Æ‚ß‚Ä•\Ž¦ (‚¨‹C‚ɔ‚̐”‚É‚æ‚Á‚Ă͏ˆ—‚ÉŽžŠÔ‚ª‚©‚©‚é)'),

Modified: p2ex/trunk/js/edit_conf_user.js
===================================================================
--- p2ex/trunk/js/edit_conf_user.js	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/js/edit_conf_user.js	2010-01-22 08:57:56 UTC (rev 797)
@@ -2,6 +2,13 @@
  * rep2expack - ƒ†[ƒUÝ’èŠÇ—‚ÌUI‚ðƒ^ƒu‰»‚·‚é
  */
 
+// {{{ GLOBALS
+
+var _EDIT_CONF_USER_JS_PARENT_TABS = [];
+var _EDIT_CONF_USER_JS_ACTIVE_TAB1 = null;
+var _EDIT_CONF_USER_JS_ACTIVE_TAB2 = null;
+
+// }}}
 // {{{ _edit_conf_user_js_onload()
 
 var _edit_conf_user_js_onload = function() {
@@ -29,7 +36,8 @@
 
 	// ‚P‚Â–Ú‚Ì 'tabbernav' ‚É‘—MEƒŠƒZƒbƒg—p‚̃^ƒu‚ð’ljÁ‚·‚é
 	var tabs = document.getElementsByTagName('ul');
-	for (var i = 0; i < tabs.length; i++) {
+	var i, l = tabs.length;
+	for (i = 0; i < l; i++) {
 		if (tabs[i].className != 'tabbernav') {
 			continue;
 		}
@@ -68,8 +76,56 @@
 		tabs[i].appendChild(document.createElement('li')).appendChild(saveTab);
 		tabs[i].appendChild(document.createElement('li')).appendChild(resetTab);
 		tabs[i].appendChild(document.createElement('li')).appendChild(defaultTab);
-		return;
+		break;
 	}
+
+	// ƒ^ƒu‚ðƒAƒNƒeƒBƒx[ƒg
+	var anchors, anchor, callback, title, group, group1, group2, j, k;
+
+	k = _EDIT_CONF_USER_JS_PARENT_TABS.length;
+	group1 = document.getElementById('active_tab1');
+	group2 = document.getElementById('active_tab2');
+
+	anchors = document.evaluate('.//ul[contains(concat(" ", @class, " "), " tabbernav ")]'
+								+ '//a[@href = "javascript:void(null);" and @title]',
+								document.body, null,
+								XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
+	l = anchors.snapshotLength;
+
+	for (i = 0; i < l; i++) {
+		anchor = anchors.snapshotItem(i);
+		if (typeof anchor.onclick === 'function') {
+			title = anchor.getAttribute('title');
+
+			if (title == _EDIT_CONF_USER_JS_ACTIVE_TAB1 ||
+				title == _EDIT_CONF_USER_JS_ACTIVE_TAB2)
+			{
+				anchor.onclick();
+			}
+
+			group = group2;
+			for (j = 0; j < k; j++) {
+				if (title === _EDIT_CONF_USER_JS_PARENT_TABS[j]) {
+					group = group1;
+					break;
+				}
+			}
+
+			if (group) {
+				callback = (function(field, title) {
+					return function() {
+						field.value = title;
+					};
+				})(group, title);
+
+				if (typeof anchor.addEventListener === 'function') {
+					anchor.addEventListener('click', callback, false);
+				} else if (typeof anchor.attachEvent === 'function') {
+					anchor.attachEvent('click', callback);
+				}
+			}
+		}
+	}
 };
 
 // }}}

Added: p2ex/trunk/lib/P2Ime.php
===================================================================
--- p2ex/trunk/lib/P2Ime.php	                        (rev 0)
+++ p2ex/trunk/lib/P2Ime.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -0,0 +1,305 @@
+<?php
+
+// {{{ P2Ime
+
+/**
+ * rep2 - URLƒQ[ƒgƒEƒFƒC•ÏŠ·ƒNƒ‰ƒX
+ */
+class P2Ime
+{
+    // {{{ properties
+
+    /**
+     * througth() ‚©‚çŒÄ‚яo‚³‚ê‚éAŽÀÛ‚ÌURL•ÏŠ·ƒƒ\ƒbƒh–¼
+     *
+     * @var string
+     */
+    protected $_method;
+
+    /**
+     * Ž©“®“]‘—‚µ‚È‚¢—áŠOŠg’£Žq‚̃ŠƒXƒg
+     *
+     * @var array
+     */
+    protected $_exceptions;
+
+    /**
+     * Ž©“®“]‘—‚µ‚È‚¢—áŠOŠg’£Žq‚̍őå‚Ì’·‚³
+     *
+     * @var int
+     */
+    protected $_maxExceptionLength;
+
+    /**
+     * httpƒvƒƒgƒRƒ‹‚̃Šƒ“ƒN‚̓Q[ƒg‚ð’Ê‚³‚È‚¢
+     *
+     * @var bool
+     */
+    protected $_ignoreHttp;
+
+    /**
+     * ƒQ[ƒg‚ÌURL
+     *
+     * @var string
+     */
+    protected $_gateUrl;
+
+    /**
+     * Ž©“®“]‘—‚Ì‘Ò‚¿ŽžŠÔ (•b)
+     * •‰”‚̏ꍇ‚ÍŽè“®“]‘—
+     *
+     * @var int
+     */
+    protected $_delay;
+
+    // }}}
+    // {{{ __construct()
+
+    /**
+     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
+     *
+     * @param string $type
+     * @param array $exceptions
+     * @param bool $ignoreHttp
+     */
+    public function __construct($type = null, array $exceptions = null, $ignoreHttp = null)
+    {
+        global $_conf;
+
+        // {{{ ƒpƒ‰ƒ[ƒ^‚̏‰Šú‰»
+
+        // ƒQ[ƒgƒEƒFƒCƒ^ƒCƒv
+        if ($type === null) {
+            $type = $_conf['through_ime'];
+            // Cookie‚ª–³Œø (URI‚ɃZƒbƒVƒ‡ƒ“ID‚ðŠÜ‚Þ) ‚Ì‚Æ‚«‚Í‹­§
+            if (!$type && !$_conf['use_cookies']) {
+                $type = 'ex';
+            }
+        }
+
+        // p‚Ì‚ÝŽè“®“]‘—
+        if ($type == 'p2pm') {
+            $type = 'p2';
+        } elseif ($type == 'expm') {
+            $type = 'ex';
+        }
+
+        // Ž©“®“]‘—‚µ‚È‚¢Šg’£Žq
+        if ($exceptions === null) {
+            if ($_conf['ime_manual_ext']) {
+                $this->_exceptions = explode(',', strtolower(trim($_conf['ime_manual_ext'])));
+            } else {
+                $this->_exceptions = array();
+            }
+        } else {
+            $this->_exceptions = array_map('strtolower', $exceptions);
+        }
+        if ($this->_exceptions) {
+            $this->_maxExceptionLength = max(array_map('strlen', $this->_exceptions));
+        } else {
+            $this->_maxExceptionLength = 0;
+        }
+
+        // http‚̃Šƒ“ƒN‚Í’Ê‚³‚È‚¢
+        if ($ignoreHttp === null) {
+            // $_conf['through_ime_http_only'] ‚ª 1 ‚ŁA
+            // ƒZƒLƒ…ƒA‚Ȑڑ±‚ŁACookie‚ª—LŒø (URI‚ɃZƒbƒVƒ‡ƒ“ID‚ðŠÜ‚Ü‚È‚¢) ‚Ì‚Æ‚«A
+            // httpƒvƒƒgƒRƒ‹‚̃Šƒ“ƒN‚̓Q[ƒg‚ð’Ê‚³‚È‚¢B
+            if ($_conf['through_ime_http_only'] && P2_HTTPS_CONNECTION && $_conf['use_cookies']) {
+                $this->_ignoreHttp = true;
+            } else {
+                $this->_ignoreHttp = false;
+            }
+        } else {
+            $this->_ignoreHttp = (bool)$ignoreHttp;
+        }
+
+        // Ž©“®“]‘—‚Ì‘Ò‚¿ŽžŠÔ‚ÌŠù’è’l
+        $this->_delay = -1;
+
+        // }}}
+        // {{{ ƒQ[ƒgƒEƒFƒC”»’è
+
+        switch ($type) {
+        // {{{ p2ime
+        case 'p2':   // Ž©“®“]‘—
+        case 'p2m':  // Žè“®“]‘—
+            $this->_method = '_throughP2Ime';
+            if ($type == 'p2m') {
+                $this->_delay = -1;
+            } else {
+                $this->_delay = 0;
+            }
+            $this->_gateUrl = $_conf['p2ime_url'];
+            break;
+        // }}}
+        // {{{ gate.php
+        case 'ex':   // Ž©“®“]‘—1•b
+        case 'exq':  // Ž©“®“]‘—0•b
+        case 'exm':  // Žè“®“]‘—
+            $this->_method = '_throughGatePhp';
+            if ($type == 'exm') {
+                $this->_delay = -1;
+            } elseif ($type == 'exq') {
+                $this->_delay = 0;
+            } else {
+                $this->_delay = 1;
+            }
+            $this->_gateUrl = $_conf['expack.gate_php'];
+            break;
+        // }}}
+        // {{{ Google
+        case 'google':
+            $this->_method = '_throughGoogleGateway';
+            if ($_conf['ktai'] && !$_conf['iphone']) {
+                $this->_gateUrl = 'http://www.google.co.jp/gwt/x?u=';
+            } else {
+                $this->_gateUrl = 'http://www.google.co.jp/url?q=';
+            }
+            break;
+        // }}}
+        default:
+            $this->_method = '_passThrough';
+            $this->_gateUrl = null;
+        }
+
+        // }}}
+    }
+
+    // }}}
+    // {{{ through()
+
+    /**
+     * URL‚ð•ÏŠ·‚·‚é
+     *
+     * @param string $url
+     * @param int $delay
+     * @param bool $escape
+     * @return string
+     */
+    public function through($url, $delay = null, $escape = true)
+    {
+        if ($delay === null) {
+            if ($this->_isExceptionUrl($url)) {
+                $delay = -1;
+            } else {
+                $delay = $this->_delay;
+            }
+        }
+
+        if (!($this->_ignoreHttp && preg_match('!^http://!', $url))) {
+            $url = $this->{$this->_method}($url, $delay);
+        }
+        if ($escape) {
+            return htmlspecialchars($url, ENT_QUOTES, 'Shift_JIS', false);
+        } else {
+            return $url;
+        }
+    }
+
+    // }}}
+    // {{{ _throughP2Ime()
+
+    /**
+     * p2ime‚ð’Ê‚·‚悤‚ÉURL‚ð•ÏŠ·‚·‚é
+     *
+     * p2ime‚́Aenc, m, url ‚̈ø”‡˜‚ªŒÅ’肳‚ê‚Ä‚¢‚é‚Ì‚Å’ˆÓ
+     *
+     * @param string $url
+     * @param int $delay
+     * @return string
+     */
+    protected function _throughP2Ime($url, $delay)
+    {
+        if ($delay < 0) {
+            return $this->_gateUrl . '?enc=1&url=' . rawurlencode($url);
+        } else {
+            return $this->_gateUrl . '?enc=1&m=1&url=' . rawurlencode($url);
+        }
+    }
+
+    // }}}
+    // {{{ _throughGatePhp()
+
+    /**
+     * gate.php‚ð’Ê‚·‚悤‚ÉURL‚ð•ÏŠ·‚·‚é
+     *
+     * @param string $url
+     * @param int $delay
+     * @return string
+     */
+    protected function _throughGatePhp($url, $delay)
+    {
+        return sprintf('%s?u=%s&d=%d', $this->_gateUrl, rawurlencode($url), $delay);
+    }
+
+    // }}}
+    // {{{ _throughGoogleGateway()
+
+    /**
+     * Google‚ÌURLƒQ[ƒgƒEƒFƒC‚ð’Ê‚·‚悤‚ÉURL‚ð•ÏŠ·‚·‚é
+     *
+     * @param string $url
+     * @param int $delay (unused)
+     * @return string
+     */
+    protected function _throughGoogleGateway($url, $delay)
+    {
+        return $this->_gateUrl . rawurlencode($url);
+    }
+
+    // }}}
+    // {{{ _passThrough()
+
+    /**
+     * URL‚ð‚»‚Ì‚Ü‚Ü•Ô‚·
+     *
+     * @param string $url
+     * @param int $delay (unused)
+     * @return string
+     */
+    protected function _passThrough($url, $delay)
+    {
+        return $url;
+    }
+
+    // }}}
+    // {{{ _isExceptionUrl()
+
+    /**
+     * Ž©“®“]‘—‚Ì—áŠOURL”»’è
+     *
+     * @param string $url
+     * @return bool
+     */
+    protected function _isExceptionUrl($url)
+    {
+        if ($this->_exceptions) {
+            if (false !== ($pos = strrpos($url, '.'))) {
+                $pos++;
+                if (strlen($url) - $pos <= $this->_maxExceptionLength) {
+                    $extension = strtolower(substr($url, $pos));
+                    if (in_array($extension, $this->_exceptions)) {
+                        return false;
+                    }
+                }
+            }
+        }
+        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/P2Util.php
===================================================================
--- p2ex/trunk/lib/P2Util.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/lib/P2Util.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -54,12 +54,19 @@
     static private $_hostIsJbbsShitaraba = array();
 
     /**
-     * ”‚²‚Ƃ̏‘‚«ž‚ݐݒ肨‚æ‚уXƒŒƒbƒh‚²‚Ƃ̏‘‚«ž‚݃f[ƒ^‚ð•Û‘¶‚·‚éƒf[ƒ^ƒx[ƒX
+     * P2ImeƒIƒuƒWƒFƒNƒg
      *
-     * @var P2KeyValueStore
+     * @var P2Ime
      */
-    static private $_postDataStore = null;
+    static private $_ime = null;
 
+    /**
+     * P2Ime‚ÅŽ©“®“]‘—‚µ‚È‚¢Šg’£Žq‚̃ŠƒXƒg
+     *
+     * @var array
+     */
+    static private $_imeMenualExtensions = null;
+
     // }}}
     // {{{ getMyHost()
 
@@ -101,7 +108,7 @@
         // ”z—ñŽw’è—p‚ɁA[]‚¾‚¯‚»‚Ì‚Ü‚ÜŽc‚µ‚āAURLƒGƒ“ƒR[ƒh‚ð‚©‚¯‚é
         return $key_urlen = preg_replace_callback(
             '/[^\\[\\]]+/',
-            array(__CLASS__, 'rawurldecodeCallback'),
+            array(__CLASS__, 'rawurlencodeCallback'),
             $key
         );
     }
@@ -694,73 +701,35 @@
 
     /**
      * ’†ŒpƒQ[ƒg‚ð’Ê‚·‚½‚ß‚ÌURL•ÏŠ·
+     *
+     * @param   string  $url
+     * @param   int     $delay  •‰”‚̏ꍇ‚ÍŽè“®“]‘—A‚»‚êˆÈŠO‚̓Q[ƒg‚ÌŽd—l‚É‚æ‚é
+     * @return  string
      */
-    static public function throughIme($url)
+    static public function throughIme($url, $delay = null)
     {
-        global $_conf;
-        static $manual_exts = null;
-
-        if (is_null($manual_exts)) {
-            if ($_conf['ime_manual_ext']) {
-                $manual_exts = explode(',', trim($_conf['ime_manual_ext']));
-            } else {
-                $manual_exts = array();
-            }
+        if (self::$_ime === null) {
+            self::configureIme();
         }
 
-        $url_en = rawurlencode($url);
+        return self::$_ime->through($url, $delay);
+    }
 
-        $gate = $_conf['through_ime'];
-        if ($manual_exts &&
-            false !== ($ppos = strrpos($url, '.')) &&
-            in_array(substr($url, $ppos + 1), $manual_exts) &&
-            ($gate == 'p2' || $gate == 'ex')
-        ) {
-            $gate .= 'm';
-        }
+    // }}}
+    // {{{ configureIme()
 
-        // p2ime‚́Aenc, m, url ‚̈ø”‡˜‚ªŒÅ’肳‚ê‚Ä‚¢‚é‚Ì‚Å’ˆÓ
-        switch ($gate) {
-        /*
-        case '2ch': // ime.nu
-            $url_r = preg_replace('|^(\w+)://(.+)$|', '$1://ime.nu/$2', $url);
-            break;
-        */
-        case 'p2': // Ž©“®“]‘—
-        case 'p2pm': // p‚Ì‚ÝŽè“®“]‘—
-            $url_r = $_conf['p2ime_url'] . '?enc=1&amp;url=' . $url_en;
-            break;
-        case 'p2m': // Žè“®“]‘—
-            $url_r = $_conf['p2ime_url'] . '?enc=1&amp;m=1&amp;url=' . $url_en;
-            break;
-        case 'ex': // Ž©“®“]‘—1•b
-        case 'expm': // p‚Ì‚ÝŽè“®“]‘—
-            $url_r = $_conf['expack.ime_url'] . '?u=' . $url_en . '&amp;d=1';
-            break;
-        case 'exq': // Ž©“®“]‘—0•b
-            $url_r = $_conf['expack.ime_url'] . '?u=' . $url_en . '&amp;d=0';
-            break;
-        case 'exm': // Žè“®“]‘—
-            $url_r = $_conf['expack.ime_url'] . '?u=' . $url_en;
-            break;
-        case 'google':
-            $url_r = 'http://www.google.co.jp/';
-            if ($_conf['ktai'] && !$_conf['iphone']) {
-                $url_r .= 'gwt/x?u=';
-            } else {
-                $url_r .= 'url?q=';
-            }
-            $url_r .= $url_en;
-            break;
-        default:
-            if ($_conf['use_cookies']) {
-                $url_r = $url;
-            } else {
-                $url_r = $_conf['expack.ime_url'] . '?u=' . $url_en;
-            }
-        }
-
-        return $url_r;
+    /**
+     * URL•ÏŠ·‚̐ݒè‚ð‚·‚é
+     *
+     * @param   string  $type
+     * @param   array   $exceptions
+     * @param   boolean $ignoreHttp
+     * @return  void
+     * @see     P2Ime::__construct()
+     */
+    static public function configureIme($type = null, array $exceptions = null, $ignoreHttp = null)
+    {
+        self::$_ime = new P2Ime($type, $exceptions, $ignoreHttp);
     }
 
     // }}}
@@ -1983,16 +1952,16 @@
     }
 
     // }}}
-    // {{{ rawurldecodeCallback()
+    // {{{ rawurlencodeCallback()
 
     /**
      * preg_replace_callback()‚̃R[ƒ‹ƒoƒbƒNŠÖ”‚Æ‚µ‚Ä
-     * ƒ}ƒbƒ`‰ÓŠ‘S‘Ì‚Érawurldecode()‚ð‚©‚¯‚é
+     * ƒ}ƒbƒ`‰ÓŠ‘S‘Ì‚Érawurlencode()‚ð‚©‚¯‚é
      *
      * @param   array   $m
      * @return  string
      */
-    static public function rawurldecodeCallback(array $m)
+    static public function rawurlencodeCallback(array $m)
     {
         return rawurlencode($m[0]);
     }

Modified: p2ex/trunk/lib/ShowThreadPc.php
===================================================================
--- p2ex/trunk/lib/ShowThreadPc.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/lib/ShowThreadPc.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -1024,11 +1024,9 @@
 
             // HTMLƒ|ƒbƒvƒAƒbƒv
             if ($_conf['iframe_popup'] && $is_http) {
-                // p2pm/expm Žw’è‚̏ꍇ‚̂݁A“Á•Ê‚ÉŽè“®“]‘—Žw’è‚ð’ljÁ‚·‚é
-                if ($_conf['through_ime'] == 'p2pm') {
-                    $pop_url = preg_replace('/\\?(enc=1&amp;)url=/', '?$1m=1&amp;url=', $link_url);
-                } elseif ($_conf['through_ime'] == 'expm') {
-                    $pop_url = preg_replace('/(&amp;d=-?\d+)?$/', '&amp;d=-1', $link_url);
+                // *pm Žw’è‚̏ꍇ‚̂݁A“Á•Ê‚ÉŽè“®“]‘—Žw’è‚ð’ljÁ‚·‚é
+                if (substr($_conf['through_ime'], -2) == 'pm') {
+                    $pop_url = P2Util::throughIme($purl[0], -1);
                 } else {
                     $pop_url = $link_url;
                 }
@@ -1044,6 +1042,7 @@
                 } else {
                     $brocra_checker_url = rtrim($_conf['brocra_checker_url'], '/') . '/' . $url;
                 }
+                $brocra_checker_url_orig = $brocra_checker_url;
                 // ƒuƒ‰ƒNƒ‰ƒ`ƒFƒbƒJEime
                 if ($_conf['through_ime']) {
                     $brocra_checker_url = P2Util::throughIme($brocra_checker_url);
@@ -1053,11 +1052,9 @@
                 $check_mark_suffix = ']';
                 // ƒuƒ‰ƒNƒ‰ƒ`ƒFƒbƒJEHTMLƒ|ƒbƒvƒAƒbƒv
                 if ($_conf['iframe_popup']) {
-                    // p2pm/expm Žw’è‚̏ꍇ‚̂݁A“Á•Ê‚ÉŽè“®“]‘—Žw’è‚ð’ljÁ‚·‚é
-                    if ($_conf['through_ime'] == 'p2pm') {
-                        $brocra_pop_url = preg_replace('/\\?(enc=1&amp;)url=/', '?$1m=1&amp;url=', $brocra_checker_url);
-                    } elseif ($_conf['through_ime'] == 'expm') {
-                        $brocra_pop_url = $brocra_checker_url . '&amp;d=-1';
+                    // *pm Žw’è‚̏ꍇ‚̂݁A“Á•Ê‚ÉŽè“®“]‘—Žw’è‚ð’ljÁ‚·‚é
+                    if (substr($_conf['through_ime'], -2) == 'pm') {
+                        $brocra_checker_url = P2Util::throughIme($brocra_checker_url_orig, -1);
                     } else {
                         $brocra_pop_url = $brocra_checker_url;
                     }

Modified: p2ex/trunk/lib/UA.php
===================================================================
--- p2ex/trunk/lib/UA.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/lib/UA.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -104,7 +104,7 @@
         }
 
         $isMobile = false;
-        if ($nuam = &self::getNet_UserAgent_Mobile($ua)) {
+        if ($nuam = self::getNet_UserAgent_Mobile($ua)) {
             if (!$nuam->isNonMobile()) {
                 $isMobile = true;
             }
@@ -504,6 +504,25 @@
     }
 
     // }}}
+    // {{{ isIModeBrowser2()
+
+    /**
+     * UA‚ªiƒ‚[ƒhƒuƒ‰ƒEƒU2.x‚È‚ç true ‚ð•Ô‚·
+     *
+     * @param   string   $ua  UA‚ðŽw’è‚·‚é‚È‚ç
+     * @return  boolean
+     */
+    static public function isIModeBrowser2($ua = null)
+    {
+        $nuam = self::getNet_UserAgent_Mobile($ua);
+        if ($nuam->isDoCoMo() && preg_match('!^DoCoMo/2\\.!', $nuam->getUserAgent())) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
 }
 
 // }}}

Modified: p2ex/trunk/lib/bootstrap.php
===================================================================
--- p2ex/trunk/lib/bootstrap.php	2010-01-21 11:39:53 UTC (rev 796)
+++ p2ex/trunk/lib/bootstrap.php	2010-01-22 08:57:56 UTC (rev 797)
@@ -189,7 +189,11 @@
 
     // NTT docomo iƒ‚[ƒh
     if ($mobile->isDoCoMo()) {
-        $_conf['use_cookies'] = false;
+        if (UA::isIModeBrowser2()) {
+            $_conf['use_cookies'] = true;
+        } else {
+            $_conf['use_cookies'] = false;
+        }
 
     // au EZweb
     //} elseif ($mobile->isEZweb()) {



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