svnno****@sourc*****
svnno****@sourc*****
2010年 1月 16日 (土) 07:33:34 JST
Revision: 786 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=786 Author: rsk Date: 2010-01-16 07:33:34 +0900 (Sat, 16 Jan 2010) Log Message: ----------- expack: - rep2 1.8.60 lib/global.funcs.php, lib/P2Util.php ããããã¤ãã®é¢æ°ã移æ¤ã - ãã°ã¤ã³ã¯ããã¼ã®ä»æ§ãrep2 1.8.60ã«åãããã Modified Paths: -------------- p2ex/trunk/conf/conf.inc.php p2ex/trunk/conf/setup_info.php p2ex/trunk/lib/HostCheck.php p2ex/trunk/lib/Login.php p2ex/trunk/lib/MD5Crypt.php p2ex/trunk/lib/P2Util.php p2ex/trunk/lib/Session.php p2ex/trunk/lib/global.funcs.php p2ex/trunk/lib/login_first.inc.php p2ex/trunk/lib/setup.funcs.php Added Paths: ----------- p2ex/trunk/lib/UA.php -------------- next part -------------- Modified: p2ex/trunk/conf/conf.inc.php =================================================================== --- p2ex/trunk/conf/conf.inc.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/conf/conf.inc.php 2010-01-15 22:33:34 UTC (rev 786) @@ -170,25 +170,13 @@ // PEARCXg[fBNgAõpXÉÇÁ³êé define('P2_PEAR_DIR', P2_BASE_DIR . '/includes'); - // PEARðnbNµ½t@CpfBNgAÊíÌPEARæèDæIÉõpXÉÇÁ³êé - // Cache/Container/db.php(PEAR::Cache)ªMySQLè¾Á½ÌÅAÄpIɵ½àÌðu¢Ä¢é - // include_pathðÇÁ·éÌÍptH[}XÉe¿ðyÚ·½ßA{ÉKvÈêÌÝè` - if (defined('P2_USE_PEAR_HACK')) { - define('P2_PEAR_HACK_DIR', P2_BASE_DIR . '/lib/pear_hack'); - } - // R}hCc[ define('P2_CLI_DIR', P2_BASE_DIR . '/cli'); // õpXðZbg - $include_path = ''; - if (defined('P2_PEAR_HACK_DIR')) { - $include_path = P2_PEAR_HACK_DIR . PATH_SEPARATOR; - } if (is_dir(P2_PEAR_DIR)) { - $include_path .= P2_PEAR_DIR . PATH_SEPARATOR; + set_include_path(P2_PEAR_DIR . PATH_SEPARATOR . get_include_path()); } - set_include_path($include_path . get_include_path()); // }}} // {{{ «`FbNÆfobO Modified: p2ex/trunk/conf/setup_info.php =================================================================== --- p2ex/trunk/conf/setup_info.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/conf/setup_info.php 2010-01-15 22:33:34 UTC (rev 786) @@ -32,7 +32,7 @@ 'register_globals', 'magic_quotes_gpc', 'mbstring.encoding_translation', - 'session.cookie_httponly', + 'session.auto_start', ); // ÚsXNvgÌÀsªKvÈÏXÌ Á½o[WÔÌzñ Modified: p2ex/trunk/lib/HostCheck.php =================================================================== --- p2ex/trunk/lib/HostCheck.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/HostCheck.php 2010-01-15 22:33:34 UTC (rev 786) @@ -134,10 +134,10 @@ ($flag == $types['private'] && self::isAddressPrivate($address)) || ($flag == $types['docomo'] && self::isAddressDocomo($address)) || ($flag == $types['au'] && self::isAddressAu($address)) || - ($flag == $types['softbank'] && self::isAddressSoftbank($address)) || + ($flag == $types['softbank'] && self::isAddressSoftBank($address)) || ($flag == $types['willcom'] && self::isAddressWillcom($address)) || ($flag == $types['emobile'] && self::isAddressEmobile($address)) || - ($flag == $types['iphone'] && self::isAddressIphone($address)) || + ($flag == $types['iphone'] && self::isAddressIPhone($address)) || ($flag == $types['custom'] && (!empty($custom) || !empty($custom_re)) && self::isAddressInBand($address, $custom, $custom_re, 'custom', filemtime(P2_CONF_DIR . '/conf_hostcheck.php') @@ -549,12 +549,12 @@ } // }}} - // {{{ isAddressSoftbank() + // {{{ isAddressSoftBank() /** * SoftBank? */ - static public function isAddressSoftbank($address = null) + static public function isAddressSoftBank($address = null) { include P2_CONF_DIR . '/ip_softbank.php'; @@ -621,12 +621,12 @@ } // }}} - // {{{ isAddressIphone() + // {{{ isAddressIPhone() /** * iPhone 3G (SoftBank)? */ - static public function isAddressIphone($address = null) + static public function isAddressIPhone($address = null) { include P2_CONF_DIR . '/ip_iphone.php'; @@ -645,6 +645,134 @@ } // }}} + // {{{ isAddressJigWeb() + + /** + * IPÍ jig web? + * + * @param string $addr + * @return boolean + */ + function isAddressJigWeb($addr = null) + { + if (is_null($addr)) { + $addr = $_SERVER['REMOTE_ADDR']; + } + // bw5022.jig.jp + $reghost = '/^bw\d+\.jig\.jp$/'; + + $bands = array( + '202.181.98.241', // 2007/08/06 + //'210.143.108.0/24', // 2005/6/23 + ); + return self::isAddressInBand($addr, $bands, $reghost, 'jigweb'); + } + + // }}} + // {{{ isAddressJig() + + /** + * IPÍ jigAv? + * + * @link http://br.jig.jp/pc/ip_br.html + * @static + * @access public + * @return boolean + */ + function isAddressJig($addr = null) + { + if (is_null($addr)) { + $addr = $_SERVER['REMOTE_ADDR']; + } + + // br***.jig.jp + $reghost = '/^br\d+\.jig\.jp$/'; + + // @updated 2009/06/04 + $bands = array( + '59.106.14.175/32', + '59.106.14.176/32', + '59.106.23.169/32', + '59.106.23.170/31', + '59.106.23.172/31', + '59.106.23.174/32', + '112.78.114.171/32', + '112.78.114.172/30', + '112.78.114.176/29', + '112.78.114.184/30', + '112.78.114.188/31', + '112.78.114.191/32', + '112.78.114.192/29', + '112.78.114.200/30', + '112.78.114.204/31', + '112.78.114.206/32', + '112.78.114.208/32', + '202.181.96.94/32', + '202.181.98.153/32', + '202.181.98.156/32', + '202.181.98.160/32', + '202.181.98.179/32', + '202.181.98.182/32', + '202.181.98.185/32', + '202.181.98.196/32', + '202.181.98.218/32', + '202.181.98.221/32', + '202.181.98.223/32', + '202.181.98.247/32', + '210.188.205.81/32', + '210.188.205.83/32', + '210.188.205.97/32', + '210.188.205.166/31', + '210.188.205.168/31', + '210.188.205.170/32', + '210.188.220.169/32', + '210.188.220.170/31', + '210.188.220.172/30', + '219.94.133.167/32', + '219.94.133.192/32', + '219.94.133.243/32', + '219.94.144.5/32', + '219.94.144.6/31', + '219.94.144.23/32', + '219.94.144.24/32', + '219.94.147.35/32', + '219.94.147.36/30', + '219.94.147.42/31', + '219.94.147.44/32', + '219.94.166.8/30', + '219.94.166.173/32', + '219.94.197.196/30', + '219.94.197.200/30', + '219.94.197.204/31' + ); + return self::isAddressInBand($addr, $bands, $reghost, 'jig'); + } + + // }}} + // {{{ isAddressIbis() + + /** + * IPÍ ibis? + * + * @static + * @access public + * @return boolean + */ + static public function isAddressIbis($addr = null) + { + if (is_null($addr)) { + $addr = $_SERVER['REMOTE_ADDR']; + } + + // http://qb5.2ch.net/test/read.cgi/operate/1183341095/504 + $bands = array( + '219.117.203.9', // VXeÚsª®¹·êÎpµÈÈéçµ¢ + '59.106.52.16/29' + ); + return self::isAddressInBand($addr, $bands); + } + + // }}} } // }}} Modified: p2ex/trunk/lib/Login.php =================================================================== --- p2ex/trunk/lib/Login.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/Login.php 2010-01-15 22:33:34 UTC (rev 786) @@ -665,17 +665,28 @@ /** * cookieFØðo^/ð·é + * + * @param void + * @return boolean */ public function registCookie() { + $r = true; + if (!empty($_REQUEST['ctl_regist_cookie'])) { if ($_REQUEST['regist_cookie'] == '1') { - $this->setCookieCid($this->user_u, $this->pass_x); + $ignore_cip = false; + if (!empty($_POST['ignore_cip'])) { + $ignore_cip = true; + } + $r = $this->setCookieCid($this->user_u, $this->pass_x, $ignore_cip); } else { // NbL[ðNA - $this->clearCookieAuth(); + $r = $this->clearCookieAuth(); } } + + return $r; } // }}} @@ -703,19 +714,32 @@ /** * CIDðcookieÉZbg·é * + * @param string $user_u + * @param string $pass_x + * @param boolean|null $ignore_cip * @return boolean */ - public function setCookieCid($user_u, $pass_x) + protected function setCookieCid($user_u, $pass_x, $ignore_cip = null) { global $_conf; + $time = time() + 60*60*24 * $_conf['cid_expire_day']; + + if (!is_null($ignore_cip)) { + if ($ignore_cip) { + P2Util::setCookie('ignore_cip', '1', $time); + $_COOKIE['ignore_cip'] = '1'; + } else { + P2Util::unsetCookie('ignore_cip'); + // O̽ßhCwèȵà + setcookie('ignore_cip', '', time() - 3600); + } + } + if ($cid = $this->makeCid($user_u, $pass_x)) { - $time = time() + 60*60*24 * $_conf['cid_expire_day']; - setcookie('cid', $cid, $time); - return true; - } else { - return false; + return P2Util::setCookie('cid', $cid, $time); } + return false; } // }}} @@ -732,14 +756,10 @@ return false; } - $key = $this->getMd5CryptKey(); - - $idtime = $user_u. ':'. time(). ':'; - $pw_enc = md5($idtime . $pass_x); - $str = $idtime . $pw_enc; - $cid = MD5Crypt::encrypt($str, $key, 32); - - return $cid; + $user_time = $user_u . ':' . time() . ':'; + $md5_utpx = md5($user_time . $pass_x); + $cid_src = $user_time . $md5_utpx; + return $cid = MD5Crypt::encrypt($cid_src, self::getMd5CryptPassForCid()); } // }}} @@ -754,17 +774,19 @@ { global $_conf; - $key = $this->getMd5CryptKey(); + $dec = MD5Crypt::decrypt($cid, self::getMd5CryptPassForCid()); - $dec = MD5Crypt::decrypt($cid, $key, 32); - list($user, $time, $pw_enc) = explode(':', $dec, 3); + $user = $time = $md5_utpx = null; + list($user, $time, $md5_utpx) = explode(':', $dec, 3); + if (!strlen($user) || !$time || !$md5_utpx) { + return false; + } // LøúÀ ú - if (time() > $time + (86400 * $_conf['cid_expire_day'])) { + if (time() > $time + (60*60*24 * $_conf['cid_expire_day'])) { return false; // úÀØê - } else { - return array($user, $time, $pw_enc); } + return array($user, $time, $md5_utpx); } // }}} @@ -816,17 +838,45 @@ } // }}} - // {{{ getMd5CryptKey() + // {{{ getMd5CryptPassForCid() /** - * MD5Crypt::encrypt, MD5Crypt::decrypt ̽ßÉNvgL[ð¾é + * MD5Crypt::encrypt, MD5Crypt::decrypt ̽ßÌ password(salt) ð¾é + * iNbL[Ìcid̶¬ÉpµÄ¢éj * - * @return string + * @param void + * @access private + * @return string */ - public function getMd5CryptKey() + static private function getMd5CryptPassForCid() { - //return $_SERVER['SERVER_NAME'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['SERVER_SOFTWARE']; - return $_SERVER['SERVER_NAME'] . $_SERVER['SERVER_SOFTWARE']; + //return md5($_SERVER['SERVER_NAME'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['SERVER_SOFTWARE']); + + //$seed = $_SERVER['SERVER_NAME'] . $_SERVER['SERVER_SOFTWARE']; + $seed = $_SERVER['SERVER_SOFTWARE']; + + // [J`FbNðµÄAHostCheck::isAddressDocomo() ÈÇÅzXg¼ðø@ïð¸ç· + $notK = (bool)(HostCheck::isAddressLocal() || HostCheck::isAddressPrivate()); + + // gÑ»è³ê½êÍA IP`FbNȵ + if ( + !$notK and + //!$_conf['cid_seed_ip'] or + UA::isK(geti($_SERVER['HTTP_USER_AGENT'])) + || HostCheck::isAddressDocomo() || HostCheck::isAddressAu() || HostCheck::isAddressSoftBank() + || HostCheck::isAddressWillcom() + || HostCheck::isAddressJigWeb() || HostCheck::isAddressJig() + || HostCheck::isAddressIbis() + ) { + ; + } elseif (!empty($_COOKIE['ignore_cip'])) { + ; + } else { + $now_ips = explode('.', $_SERVER['REMOTE_ADDR']); + $seed .= $now_ips[0]; + } + + return md5($seed, true); } // }}} Modified: p2ex/trunk/lib/MD5Crypt.php =================================================================== --- p2ex/trunk/lib/MD5Crypt.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/MD5Crypt.php 2010-01-15 22:33:34 UTC (rev 786) @@ -32,6 +32,8 @@ static public function encrypt($plain_text, $password, $iv_len = 16) { + $password = self::adjustPassword($password, $iv_len); // added by aki + $plain_text .= "\x13"; $n = strlen($plain_text); if ($n % 16) { @@ -54,6 +56,8 @@ static public function decrypt($enc_text, $password, $iv_len = 16) { + $password = self::adjustPassword($password, $iv_len); // added by aki + $enc_text = base64_decode($enc_text); $n = strlen($enc_text); $i = $iv_len; @@ -69,8 +73,27 @@ } // }}} + // {{{ adjustPassword() + /** + * $passwordisaltjÌ·³ª $iv_len ð´¦Ä¢½ç md5() µ½ãAJbgµÄûßé + * + * @author aki + * @since 2007/07/02 + * @access private + * @return string + */ + static private function adjustPassword($password, $iv_len) + { + if (strlen($password) > $iv_len) { + $password = substr(md5($password), 0, $iv_len); + } + return $password; + } + + // }}} } + // }}} /******************************************/ Modified: p2ex/trunk/lib/P2Util.php =================================================================== --- p2ex/trunk/lib/P2Util.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/P2Util.php 2010-01-15 22:33:34 UTC (rev 786) @@ -61,6 +61,172 @@ static private $_postDataStore = null; // }}} + // {{{ getMyHost() + + /** + * |[gÔðíÁ½zXg¼ðæ¾·é + * + * @param void + * @return string|null + */ + static public function getMyHost() + { + if (!isset($_SERVER['HTTP_HOST'])) { + return null; + } + return preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']); + } + + // }}} + // {{{ getCookieDomain() + + /** + * @param void + * @return string + */ + static public function getCookieDomain() + { + return ''; + } + + // }}} + // {{{ encodeCookieName() + + /** + * @param string $key + * @return string + */ + static private function encodeCookieName($key) + { + // zñwèpÉA[]¾¯»ÌÜÜcµÄAURLGR[hð©¯é + return $key_urlen = preg_replace_callback( + '/[^\\[\\]]+/', + array(__CLASS__, 'rawurldecodeCallback'), + $key + ); + } + + // }}} + // {{{ setCookie() + + /** + * setcookie() ÅÍAauÅKvÈmax ageªÝè³êÈ¢ÌÅA±¿çðp·é + * + * @access public + * @param string $key + * @param string $value + * @param int $expires + * @param string $path + * @param string $domain + * @param boolean $secure + * @param boolean $httponly + * @return boolean + */ + static public function setCookie($key, $value = '', $expires = null, $path = '', $domain = null, $secure = false, $httponly = true) + { + if (is_null($domain)) { + $domain = self::getCookieDomain(); + } + is_null($expires) and $expires = time() + 60 * 60 * 24 * 365; + + if (headers_sent()) { + return false; + } + + // Mac IEÍA®ìsÇðN±·çµ¢ÁÛ¢ÌÅAhttponlyÌÎÛ©çO·Bi»à»àÎàµÄ¢È¢j + // MAC IE5.1 Mozilla/4.0 (compatible; MSIE 5.16; Mac_PowerPC) + if (preg_match('/MSIE \d\\.\d+; Mac/', geti($_SERVER['HTTP_USER_AGENT']))) { + $httponly = false; + } + + // setcookie($key, $value, $expires, $path, $domain, $secure = false, $httponly = true); + /* + if (is_array($name)) { + list($k, $v) = each($name); + $name = $k . '[' . $v . ']'; + } + */ + if ($expires) { + $maxage = $expires - time(); + } + + header( + 'Set-Cookie: '. self::encodeCookieName($key) . '=' . rawurlencode($value) + . (empty($domain) ? '' : '; Domain=' . $domain) + . (empty($expires) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', $expires) . ' GMT') + . (empty($maxage) ? '' : '; Max-Age=' . $maxage) + . (empty($path) ? '' : '; Path=' . $path) + . (!$secure ? '' : '; Secure') + . (!$httponly ? '' : '; HttpOnly'), + $replace = false + ); + + return true; + } + + // }}} + // {{{ unsetCookie() + + /** + * NbL[ðÁ·éBÏ $_COOKIE àB + * + * @param string $key key, k1[k2] + * @param string $path + * @param string $domain + * @return boolean + */ + static public function unsetCookie($key, $path = '', $domain = null) + { + if (is_null($domain)) { + $domain = self::getCookieDomain(); + } + + // zñðsetcookie()·éÍAL[¶ñðPHPÌzñÌêÌæ¤ÉA'' â "" ÅNH[gµÈ¢B + // »êçÍL[¶ñƵÄF¯³êĵܤB['hoge']ÅÍÈA[hoge]Æwè·éB + // setcookie()ÅAêL[Í[]ÅÍÜÈ¢æ¤É·éBi³øÈÆÈéBj k1[k2] Æ¢¤\LÅwè·éB + // setcookie()ÅÍzñðÜÆßÄí·é±ÆÍÅ«È¢B + // k1 ÌwèÅ k1[k2] ÍÁ¦È¢ÌÅA±Ì\bhÅεĢéB + + // $keyªzñƵÄwè³êÄ¢½Èç + $cakey = null; // $_COOKIEpÌL[ + if (preg_match('/\]$/', $key)) { + // ÅÌL[ð[]ÅÍÞ + $cakey = preg_replace('/^([^\[]+)/', '[$1]', $key); + // []ÌL[ð''ÅÍÞ + $cakey = preg_replace('/\[([^\[\]]+)\]/', "['$1']", $cakey); + //var_dump($cakey); + } + + // ÎÛCookielªzñÅ êÎÄAðs¤ + $cArray = null; + if ($cakey) { + eval("isset(\$_COOKIE{$cakey}) && is_array(\$_COOKIE{$cakey}) and \$cArray = \$_COOKIE{$cakey};"); + } else { + if (isset($_COOKIE[$key]) && is_array($_COOKIE[$key])) { + $cArray = $_COOKIE[$key]; + } + } + if (is_array($cArray)) { + foreach ($cArray as $k => $v) { + $keyr = "{$key}[{$k}]"; + if (!self::unsetCookie($keyr, $path, $domain)) { + return false; + } + } + } + + if (is_array($cArray) or setcookie("$key", '', time() - 3600, $path, $domain)) { + if ($cakey) { + eval("unset(\$_COOKIE{$cakey});"); + } else { + unset($_COOKIE[$key]); + } + return true; + } + return false; + } + + // }}} // {{{ fileDownload() /** @@ -106,7 +272,7 @@ if ($wap_res->isRedirect() && array_key_exists('Location', $wap_res->headers)) { $location = $wap_res->headers['Location']; $location_ht = htmlspecialchars($location, ENT_QUOTES); - $location_t = P2Util::throughIme($location); + $location_t = self::throughIme($location); $_info_msg_ht .= "Location: <a href=\"{$location_t}\"{$_conf['ext_win_target_at']}>{$location_ht}</a><br>"; } $_info_msg_ht .= "p2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$wap_req->url}</a> Éڱūܹñŵ½B</div>"; @@ -1865,6 +2031,21 @@ } // }}} + // {{{ rawurldecodeCallback() + + /** + * preg_replace_callback()ÌR[obNÖÆµÄ + * }b`ÓSÌÉrawurldecode()ð©¯é + * + * @param array $m + * @return string + */ + static public function rawurldecodeCallback(array $m) + { + return rawurlencode($m[0]); + } + + // }}} // {{{ debug() /* static public function debug() Modified: p2ex/trunk/lib/Session.php =================================================================== --- p2ex/trunk/lib/Session.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/Session.php 2010-01-15 22:33:34 UTC (rev 786) @@ -50,6 +50,8 @@ */ public function __construct($session_name = null, $session_id = null, $use_cookies = true) { + $this->setCookieHttpOnly(); + // LbV §äȵ session_cache_limiter('none'); @@ -308,10 +310,11 @@ $_SESSION = array(); // ZbVðØf·éÉÍZbVNbL[àí·éB - // Note: ZbVîñ¾¯ÅÈZbVðjó·éB - if (isset($_COOKIE[session_name()])) { - unset($_COOKIE[session_name()]); - setcookie(session_name(), '', time() - 42000); + $session_name = session_name(); + if (isset($_COOKIE[$session_name])) { + //setcookie($session_name, '', time() - 42000); + P2Util::unsetCookie($session_name); + unset($_COOKIE[$session_name]); } // ÅIIÉAZbVðjó·é @@ -329,6 +332,29 @@ } // }}} + // {{{ setCookieHttpOnly() + + /** + * ZbVÌsetcookieÉHttpOnlyðwè·é + * http://msdn2.microsoft.com/ja-jp/library/system.web.httpcookie.httponly(VS.80).aspx + * + * @param void + * @return void + */ + private function setCookieHttpOnly() + { + $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; + + // Mac IEÍA®ìsÇðN±·çµ¢ÁÛ¢ÌÅÎÛ©çO·Bi»à»àÎàµÄ¢È¢j + // Mozilla/4.0 (compatible; MSIE 5.16; Mac_PowerPC) + if (preg_match('/MSIE \d\\.\d+; Mac/', $ua)) { + return; + } + + ini_set('session.cookie_httponly', true); + } + + // }}} } // }}} Added: p2ex/trunk/lib/UA.php =================================================================== --- p2ex/trunk/lib/UA.php (rev 0) +++ p2ex/trunk/lib/UA.php 2010-01-15 22:33:34 UTC (rev 786) @@ -0,0 +1,524 @@ +<?php +// á¦ÎANG[ª b=k Èç isK() ªtrueÆÈéÌÅAgÑü¯\¦Éµ½è·é + +// {{{ ±ÌNXÅÌÝp·éO[oÏi_UA_*j +// over PHP5ÉÀèÅ«éÈçvCx[gÈNXÏɵ½¢Æ±ëÌàÌ + +// @see getQueryKey() +$GLOBALS['_UA_query_key'] = 'b'; + +// @see setPCQuery() // b=pc +$GLOBALS['_UA_PC_query'] = 'pc'; + +// @see setMobileQuery() // b=k +$GLOBALS['_UA_mobile_query'] = 'k'; + +// @see setIPhoneGroupQuery() // b=i +$GLOBALS['_UA_iphonegroup_query'] = 'i'; + +$GLOBALS['_UA_force_mode'] = null; + +// }}} +// {{{ UA + +// [todo] enableJS() â enableAjax() à~µ¢©à + +/** + * static\bhÅp·é + */ +class UA +{ + // {{{ setForceMode() + + /** + * §IÉ[hipc, kjðwè·é + * iNG[ðZbg·éí¯ÅÍÈ¢j + */ + static public function setForceMode($v) + { + $GLOBALS['_UA_force_mode'] = $v; + } + + // }}} + // {{{ isPC() + + /** + * UAªPCiñoCjÈçtrueðÔ· + * iPhoneàÜñÅ¢éªA¢¸êÜÜÈÈéÂ\«ª é±ÆÉÓB + * »ÝAiPhoneÍsetForceMode()ÅisMobileByQuery()µ¢µÄ¢éBiøÍãßÅj + * + * @return boolean + */ + static public function isPC($ua = null) + { + return !self::isMobile($ua); + } + + // }}} + // {{{ isK() + + /** + * isMobile() ÌGCAXÉÈÁÄ¢é + * + * [plan] gÑisK()ÆAoCisMobile()ÍAÊÌàÌƵÄæʵ½ûª¢¢©ÈBiisMobile()ÍisK()ðÜÞàÌƵÄj + * gÑFæʪ¬³¢By[WÌ\¦eÊɧÀª éBÌANZXL[ðg¤B + * oCFgÑƯ¶æʪ¬³ß¾ªAtuEUÅAJavaScriptªg¦éB + */ + static public function isK($ua = null) + { + return self::isMobile($ua); + } + + // }}} + // {{{ isMobile() + + /** + * UAªgÑ\¦ÎÛÈçtrueðÔ· + * isK()ÆÓ¡ðæÊ·é\èª éÌÅA»êÜÅÌÔÍgíȢŨi»_AgÁĢȢj + * iisMobileByQuery()ÈÇÍgíêÄ¢éªj + * isM()ɵ½¢CàB + * + * @params string $ua UAðwè·éÈç + * @return boolean + */ + static public function isMobile($ua = null) + { + static $cache_ = null; + + // §wèª êÎ + if (isset($GLOBALS['_UA_force_mode'])) { + // ±±ÍLbV µÈ¢ + return ($GLOBALS['_UA_force_mode'] == $GLOBALS['_UA_mobile_query']); + } + + // øÌUAª³wèÈçANG[wèðQÆ + if (is_null($ua)) { + if (self::getQueryValue()) { + return self::isMobileByQuery(); + } + } + + // øÌUAª³wèÈçALbV Lø + if (is_null($ua) and !is_null($cache_)) { + return $cache_; + } + + $isMobile = false; + if ($nuam = &self::getNet_UserAgent_Mobile($ua)) { + if (!$nuam->isNonMobile()) { + $isMobile = true; + } + } + + /* + // NetFrontniÜÞPSPjàoCÉ + if (!$isMobile) { + $isMobile = self::isNetFront($ua); + } + + // Nintendo DSàoCÉ + if (!$isMobile) { + $isMobile = self::isNintendoDS($ua); + } + */ + + // øÌUAª³wèÈçALbV Û¶ + if (is_null($ua)) { + $cache_ = $isMobile; + } + + return $isMobile; + } + + // }}} + // {{{ isIPhoneGroup() + + /** + * UAªiPhone, iPod touchÈçtrueðÔ·B + * + * @param string $aua UAðwè·éÈç + * @return boolean + */ + static public function isIPhoneGroup($aua = null) + { + static $cache_ = null; + + // §wèª êÎ`FbN + if (isset($GLOBALS['_UA_force_mode'])) { + // ÚsÌÖXãAøÍðãßÄ¢é + // return ($GLOBALS['_UA_force_mode'] == $GLOBALS['_UA_iphonegroup_query']); + if ($GLOBALS['_UA_force_mode'] == $GLOBALS['_UA_iphonegroup_query']) { + return true; + } + } + + $ua = $aua; + + // UAÌøª³wèÈçA + if (is_null($aua)) { + // NG[wèðQÆ + if (self::getQueryValue()) { + //// ãûÝ·ãAb=kÅàiPhoneÆÝÈ·±Æð·B + //if (!self::isMobileByQuery()) { + return self::isIPhoneGroupByQuery(); + //} + } + + // iLbV ·éÙÇÅÍÈ¢©àj + // øÌUAª³wèÈçALbV Lø + if (!is_null($cache_)) { + return $cache_; + } + + // NCAgÌUAÅ»Ê + if (isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + } + + $isiPhoneGroup = false; + + // iPhone + // Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 + + // iPod touch + // Mozilla/5.0 (iPod; U; CPU like Mac OS X; ja-jp) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A110a Safari/419.3 + if (preg_match('/(iPhone|iPod)/', $ua) || self::isAndroidWebKit($ua)) { + $isiPhoneGroup = true; + } + + // UAÌøª³wèÈçALbV Û¶ + if (is_null($aua)) { + $cache_ = $isiPhoneGroup; + } + return $isiPhoneGroup; + } + + // }}} + // {{{ isPCByQuery() + + /** + * NG[ªPCðwèµÄ¢éÈçtrueðÔ· + * + * @return boolean + */ + static private function isPCByQuery() + { + $qv = self::getQueryValue(); + if (isset($qv) && $qv == self::getPCQuery()) { + return true; + } + return false; + } + + // }}} + // {{{ isMobileByQuery() + + /** + * NG[ªgÑðwèµÄ¢éÈçtrueðÔ· + * + * @return boolean + */ + static private function isMobileByQuery() + { + $qv = self::getQueryValue(); + if (isset($qv) && $qv == self::getMobileQuery()) { + return true; + } + return false; + } + + /** + * NG[ªIPhoneGroupðwèµÄ¢éÈçtrueðÔ· + * + * @return boolean + */ + static private function isIPhoneGroupByQuery() + { + $qv = self::getQueryValue(); + if (isset($qv) && $qv == self::getIPhoneGroupQuery()) { + return true; + } + return false; + } + + // }}} + // {{{ getQueryValue() + + /** + * \¦[hwèpÌNG[lðæ¾·é + * + * @return string|null + */ + static public function getQueryValue($key = null) + { + if (is_null($key)) { + if (!$key = self::getQueryKey()) { + return null; + } + } + + $r = null; + if (isset($_REQUEST[$key])) { + if (preg_match('/^\\w+$/', $_REQUEST[$key])) { + $r = $_REQUEST[$key]; + } + } + return $r; + } + + // }}} + // {{{ getQueryKey() + + /** + * @return string + */ + static public function getQueryKey() + { + return $GLOBALS['_UA_query_key']; + } + + // }}} + // {{{ setPCQuery() + + /** + * @param string $pc default is 'pc' + * @return void + */ + static public function setPCQuery($pc) + { + $GLOBALS['_UA_PC_query'] = $pc; + } + + // }}} + // {{{ getPCQuery() + + /** + * @return string + */ + static public function getPCQuery() + { + return $GLOBALS['_UA_PC_query']; + } + + // }}} + // {{{ setMobileQuery() + + /** + * @param string $k default is 'k' + * @return void + */ + static public function setMobileQuery($k) + { + $GLOBALS['_UA_mobile_query'] = $k; + } + + // }}} + // {{{ getMobileQuery() + + /** + * @return string + */ + static public function getMobileQuery() + { + return $GLOBALS['_UA_mobile_query']; + } + + // }}} + // {{{ setIPhoneGroupQuery() + + /** + * @param string $i default is 'i' + * @return void + */ + static public function setIPhoneGroupQuery($i) + { + $GLOBALS['_UA_iphonegroup_query'] = $i; + } + + // }}} + // {{{ getIPhoneGroupQuery() + + /** + * @return string + */ + static public function getIPhoneGroupQuery() + { + return $GLOBALS['_UA_iphonegroup_query']; + } + + // }}} + // {{{ getNet_UserAgent_Mobile() + + /** + * Net_UserAgent_Mobile::singleton() ÌÊðæ¾·éB + * REAR Error Í false ÉÏ·³êéB + * + * @param string $ua + * @return Net_UserAgent_Mobile|false + */ + static public function getNet_UserAgent_Mobile($ua = null) + { + static $cache_ = null; + + if (is_null($ua) and !is_null($cache_)) { + return $cache_; + } + + if (!class_exists('Net_UserAgent_Mobile', false)) { + require 'Net/UserAgent/Mobile.php'; + } + + if (!is_null($ua)) { + $nuam = Net_UserAgent_Mobile::factory($ua); + } else { + $nuam = Net_UserAgent_Mobile::singleton(); + } + + if (PEAR::isError($nuam)) { + trigger_error($nuam->toString, E_USER_WARNING); + $return = false; + + } elseif (!$nuam) { + $return = false; // null + + } else { + $return = $nuam; + } + + if (is_null($ua)) { + $cache_ = $return; + } + + return $return; + } + + // }}} + // {{{ isNetFront() + + /** + * UAªNetFrontigÑAPDAAPSPjÈçtrueðÔ· + * + * @param string $ua UAðwè·éÈç + * @return boolean + */ + static public function isNetFront($ua = null) + { + if (is_null($ua) and isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + + if (preg_match('/(NetFront|AVEFront\/|AVE-Front\/)/', $ua)) { + return true; + } + if (self::isPSP()) { + return true; + } + return false; + } + + // }}} + // {{{ isPSP() + + /** + * UAªPSPÈçtrueðÔ·BNetFrontnçµ¢B + * + * @param string $ua UAðwè·éÈç + * @return boolean + */ + static public function isPSP($ua = null) + { + if (is_null($ua) and isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + + // Mozilla/4.0 (PSP (PlayStation Portable); 2.00) + if (preg_match('/PlayStation Portable/', $ua)) { + return true; + } + return false; + } + + // }}} + // {{{ isNintendoDS() + + /** + * UAªNintendo DSÈçtrueðÔ·B + * + * @param string $ua UAðwè·éÈç + * @return boolean + */ + static public function isNintendoDS($ua = null) + { + if (is_null($ua) and isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + + // Mozilla/4.0 (compatible; MSIE 6.0; Nitro) Opera 8.5 [ja] + if (preg_match('/ Nitro/', $ua)) { + return true; + } + return false; + } + + // }}} + // {{{ isAndroidWebKit() + + /** + * UAªAndroidiÅWebkitjÈçtrueðÔ·B + * + * @param string $ua UAðwè·éÈç + * @return boolean + */ + static public function isAndroidWebKit($ua = null) + { + if (is_null($ua) and isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + if (!$ua) { + return false; + } + // V~ [^ + // Mozilla/5.0 (Linux; U; Android 1.0; en-us; generic) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 + // T-mobile G1 + // Mozilla/5.0 (Linux; U; Android 1.0; en-us; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2 + // genericÆdreamªÙÈé + if (false !== strpos('Android', $ua) && false !== strpos('WebKit', $ua)) { + return true; + } + return false; + } + + // }}} + // {{{ isSafariGroup() + + /** + * UAªSafarinÈç true ðÔ· + * + * @param string $ua UAðwè·éÈç + * @return boolean + */ + static public function isSafariGroup($ua = null) + { + if (is_null($ua) and isset($_SERVER['HTTP_USER_AGENT'])) { + $ua = $_SERVER['HTTP_USER_AGENT']; + } + + return (boolean)preg_match('/Safari|AppleWebKit|Konqueror/', $ua); + } + + // }}} +} + +// }}} + +/* + * 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/global.funcs.php =================================================================== --- p2ex/trunk/lib/global.funcs.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/global.funcs.php 2010-01-15 22:33:34 UTC (rev 786) @@ -3,6 +3,86 @@ * rep2expack - [eBeBÖQ */ +// {{{ rep2 1.8.x lib/global.funcs.php æè + +/** + * htmlspecialchars() Ìʼݽ¢ÈàÌ + * + * @param string $alt lªóÌÆ«ÌãÖ¶ñ + * @return string|null + */ +function hs($str, $alt = '', $quoteStyle = ENT_QUOTES) +{ + return (isset($str) && strlen($str) > 0) ? htmlspecialchars($str, $quoteStyle) : $alt; +} + +/** + * notice Ì}§àµÄêé hs() + * QÆÅlðó¯æéÌÍC}C`¾ªA»¤µÈ¯êÎnoticeÌ}§ªÅ«È¢ + * + * @param &string $str ¶ñÏÌQÆ + * @return string|null + */ +function hsi(&$str, $alt = '', $quoteStyle = ENT_QUOTES) +{ + return (isset($str) && strlen($str) > 0) ? htmlspecialchars($str, $quoteStyle) : $alt; +} + +/** + * echo hs() + * + * @return void + */ +function eh($str, $alt = '', $quoteStyle = ENT_QUOTES) +{ + echo hs($str, $alt, $quoteStyle); +} + +/** + * echo hs() inoticeð}§·éj + * + * @param &string $str ¶ñÏÌQÆ + * @return void + */ +function ehi(&$str, $alt = '', $quoteStyle = ENT_QUOTES) +{ + echo hs($str, $alt, $quoteStyle); +} + +/** + * ¶ÝµÈ¢ÏÌ notice ðo·±ÆÈAÏÌlðæ¾·é + * + * ±ÌÖÅzñÌgðæ¾µæ¤Æ·éÆAzñ»ÌàÌð쬵ĵܤ±Æª éÌÉÓB + * ÂÜè $hoge ª¶ÝµÈ¢ÉAgeti($hoge['huga']) Æ·éÆA $hoge Í array('huga' => null) ÆÈÁĵܤB + * + * @return mixed + */ +function geti(&$var, $alt = null) +{ + return isset($var) ? $var : $alt; +} + +/** + * üsðt¯Ä¶ñðoÍ·éBcli(\n)Æweb(<br>)Åoͪϻ·éB + * ø̶ñÍ¡æé±ÆªÂ\BøªÈ¯êÎüs¾¯ðoÍ·éB + * + * @return void + */ +function echoln() +{ + $n = (php_sapi_name() == 'cli') ? "\n" : '<br>'; + + if ($args = func_get_args()) { + foreach ($args as $v) { + echo $v . $n; + } + } else { + echo $n; + } +} + +// }}} + // {{{ CONSTANTS /** Modified: p2ex/trunk/lib/login_first.inc.php =================================================================== --- p2ex/trunk/lib/login_first.inc.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/login_first.inc.php 2010-01-15 22:33:34 UTC (rev 786) @@ -149,8 +149,19 @@ $regist_cookie_checked = ''; } } - $auth_sub_input_ht = '<input type="hidden" name="ctl_regist_cookie" value="1">'."\n". - '<input type="checkbox" id="regist_cookie" name="regist_cookie" value="1"'.$regist_cookie_checked.'><label for="regist_cookie">cookieÉÛ¶·éi§j</label><br>'; + $ignore_cip_checked = ''; + if (isset($_POST['submit_newuser']) || isset($_POST['submit_userlogin'])) { + if (geti($_POST['ignore_cip']) == '1') { + $ignore_cip_checked = ' checked'; + } + } else { + if (geti($_COOKIE['ignore_cip']) == '1') { + $ignore_cip_checked = ' checked'; + } + } + $auth_sub_input_ht = '<input type="hidden" name="ctl_regist_cookie" value="1">' + . sprintf('<input type="checkbox" id="regist_cookie" name="regist_cookie" value="1"%s><label for="regist_cookie">OCîñðCookieÉÛ¶·éi§j</label><br>', $regist_cookie_checked) + . sprintf('<input type="checkbox" id="ignore_cip" name="ignore_cip" value="1"%s><label for="ignore_cip">CookieFØÉIP̯ê«ð`FbNµÈ¢</label><br>', $ignore_cip_checked); } // }}} Modified: p2ex/trunk/lib/setup.funcs.php =================================================================== --- p2ex/trunk/lib/setup.funcs.php 2010-01-15 21:36:43 UTC (rev 785) +++ p2ex/trunk/lib/setup.funcs.php 2010-01-15 22:33:34 UTC (rev 786) @@ -173,6 +173,7 @@ StrSjis | SubjectTxt | Thread(?:[A-Z][A-Za-z]*)? | + UA | Wap[A-Z][A-Za-z]* )$/x', $name)) {