codes****@googl*****
codes****@googl*****
2009年 3月 9日 (月) 04:18:39 JST
Author: tatsumi.imai Date: Sun Mar 8 11:29:56 2009 New Revision: 1238 Modified: trunk/geeklog-1-jp-extended/system/custom/custom_cellular.php Log: ケータイハックで以下の2点を修正。 ページ内リンクを参照するとセッションが切れる ・CUSTOM_refresh()でページ内リンクの処理をしていなかったため。処理を追加しま した。 ブロックメニューで表示されるリンクにセッションIDがない ・_mobile_add_sessid()でリンクの抽出に使っているパターンがURLの引用符として 二重引用符(")しか考慮していないのに、CUSTOM_MOBILE_blockMenu()ではURLを引用 符(')でくくってしまっているため。 ・CUSTOM_MOBILE_blockMenu()は他に合わせて二重引用符を使うように修正。 ・_mobile_add_sessid()の正規表現を変更し、_mobile_session_callback()で終端に 二重引用符を付加していた部分の処理を修正して、正規表現に一致したものを付加す るように修正。 Modified: trunk/geeklog-1-jp-extended/system/custom/custom_cellular.php ============================================================================== --- trunk/geeklog-1-jp-extended/system/custom/custom_cellular.php (original) +++ trunk/geeklog-1-jp-extended/system/custom/custom_cellular.php Sun Mar 8 11:29:56 2009 @@ -8,8 +8,8 @@ * Geeklog hack for cellular phones. * Copyright (c) 2006 - 2008 Tatsumi Imai(http://im-ltd.ath.cx) * License: GPL v2 or later - * Time-stamp: <2008-07-14 23:42:55 imai> - */ + * Time-stamp: <2009-03-09 03:13:44 imai> + * */ // 設定 $CUSTOM_MOBILE_CONF['debug'] = false; @@ -256,25 +256,40 @@ function CUSTOM_refresh($url) { global $LANG05,$CUSTOM_MOBILE_CONF; - $msg = mb_convert_encoding($LANG05['5'], 'sjis-win', - mb_detect_encoding($LANG05['5'], "UTF-8,EUC-JP,JIS,sjis-win")); if(CUSTOM_MOBILE_is_cellular()) { + // ページ内リンクを探す + $pos = strpos($url, '#'); + if($pos === false) { + //CUSTOM_MOBILE_debug("not matched: " . $url); + $link = ""; + } else { + //CUSTOM_MOBILE_debug("matched: " . $url); + $link = substr($url, $pos); + $url = substr($url, 0, $pos); + } if($CUSTOM_MOBILE_CONF['refresh_use_location']) { $sepa = '?'; if (strpos($url, '?') > 0) { - //2009-02-19 Kunitsuji update + // 2009-02-19 Kunitsuji update $sepa = '&'; //$sepa = '&'; } - $location_url = 'Location: ' . $url . $sepa . SID; + $location_url = 'Location: ' . $url . $sepa . SID . link; header( $location_url ); exit; } else { + $msg = mb_convert_encoding($LANG05['5'], 'sjis-win', + mb_detect_encoding($LANG05['5'], "UTF-8,EUC-JP,JIS,sjis-win")); + $sepa = '?'; + if (strpos($url, '?') > 0) { + $sepa = '&'; + } + $location_url = $url . $sepa . SID . link; return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"" . "\"http://www.w3.org/TR/html4/loose.dtd\">\n" . "<html><head><title>$msg</title></head>" . - "<body><a href=\"$url\">$msg</a></body></html>\n"; + "<body><a href=\"$location_url\">$msg</a></body></html>\n"; } } else { return "<html><head><meta http-equiv=\"refresh\" content=\"0; URL=$url\"></head></html>\n"; @@ -468,8 +483,8 @@ global $_CONF; // ページ内の<a>タグ、<form>タグのurlを抽出 - $pat1 = '!(<a\s+.*?href=")([^\"]*?)"!i'; - $pat2 = '!(<form\s+.*?action=")([^\"]*?)"!i'; + $pat1 = '!(<a\s+.*?href=)([\'"])([^\2]*?)(\2)!i'; + $pat2 = '!(<form\s+.*?action=)([\'"])([^\2]*?)(\2)!i'; $search = array($pat1, $pat2,); // コールバック関数に渡してセッションIDを追加する return preg_replace_callback($search, _mobile_session_callback, $content); @@ -479,8 +494,9 @@ function _mobile_session_callback($matches) { global $_CONF; $pat = $_CONF['site_url']; - $ret = $matches[1].$matches[2]; - + $ret = substr($matches[0], 0, -1); + $delim = substr($matches[0], -1); + // forumのバグ? cf: forum/createtopic.php line 342 & forum/viewtopic.php line 100. $ret = preg_replace('!true#\d+!', 'true', $ret); @@ -488,13 +504,13 @@ // 絶対アドレス if(!preg_match("!$pat!", $ret)) { // 外部サイトだったらそのまま返す - return $ret . '"'; + return $ret . $delim; } else { ; // 自サイト } } else if(preg_match("![a-z]+:.+!", $ret)){ // http以外のプロトコル - return $ret . '"'; + return $ret . $delim; } else { ; // 相対アドレス } @@ -526,7 +542,7 @@ // URLクエリのセパレータ $sep = strpos($ret, '?')?'&':'?'; // SIDを追加する - $ret = $ret . $sep . htmlspecialchars(SID) . $link . '"'; + $ret = $ret . $sep . htmlspecialchars(SID) . $link . $delim; //CUSTOM_MOBILE_debug("sid added: " . $ret); return $ret; }