svnno****@sourc*****
svnno****@sourc*****
2010年 1月 14日 (木) 08:31:20 JST
Revision: 778 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=778 Author: rsk Date: 2010-01-14 08:31:20 +0900 (Thu, 14 Jan 2010) Log Message: ----------- expack: - conf.inc.phpããé¢æ°ã¨ç°å¢ãã§ãã¯ã«ä½¿ãå¤æ°ãããããå¥ãã¡ã¤ã«ã«åå²ã - ä¸é¨ã®ãã¡ã¤ã«ãrep2 1.8.xã«åããã¦ãªãã¼ã ã Modified Paths: -------------- p2ex/trunk/conf/conf.inc.php p2ex/trunk/lib/Login.php p2ex/trunk/lib/P2Util.php p2ex/trunk/lib/bootstrap.php p2ex/trunk/lib/migrators/100113_1300.php p2ex/trunk/lib/migrators/yymmdd_hhmm.php Added Paths: ----------- p2ex/trunk/conf/setup_info.php p2ex/trunk/lib/global.funcs.php p2ex/trunk/lib/md5_crypt.funcs.php p2ex/trunk/lib/setup.funcs.php Removed Paths: ------------- p2ex/trunk/lib/md5_crypt.inc.php p2ex/trunk/lib/p2util.inc.php -------------- next part -------------- Modified: p2ex/trunk/conf/conf.inc.php =================================================================== --- p2ex/trunk/conf/conf.inc.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/conf/conf.inc.php 2010-01-13 23:31:20 UTC (rev 778) @@ -49,7 +49,7 @@ // }}} // î{ÝèðÀs -p2configure(); +p2_init(); // N[Abv if (basename($_SERVER['SCRIPT_NAME']) != 'edit_conf_user.php') { @@ -62,12 +62,12 @@ $htm = array(); $word = null; -// {{{ p2configure() +// {{{ p2_init() /** * êÏÅO[oÏðõµÈ¢æ¤ÉÝèðÖ» */ -function p2configure() +function p2_init() { global $MYSTYLE, $STYLE, $debug; global $skin, $skin_en, $skin_name, $skin_uniq; @@ -183,36 +183,23 @@ // õpXðZbg $include_path = ''; if (defined('P2_PEAR_HACK_DIR')) { - $include_path .= P2_PEAR_HACK_DIR . PATH_SEPARATOR; + $include_path = P2_PEAR_HACK_DIR . PATH_SEPARATOR; } if (is_dir(P2_PEAR_DIR)) { $include_path .= P2_PEAR_DIR . PATH_SEPARATOR; - } else { - $paths = array(); - foreach (explode(PATH_SEPARATOR, get_include_path()) as $dir) { - if (is_dir($dir)) { - $dir = realpath($dir); - if ($dir != P2_BASE_DIR) { - $paths[] = $dir; - } - } - } - if (count($paths)) { - $include_path .= implode(PATH_SEPARATOR, array_unique($paths)) . PATH_SEPARATOR; - } } - $include_path .= P2_BASE_DIR; // fallback - set_include_path($include_path); - spl_autoload_register('p2autoload'); + set_include_path($include_path . get_include_path()); // }}} // {{{ «`FbNÆfobO // [eBeBðÇÝÞ - include P2_LIB_DIR . '/p2util.inc.php'; + include P2_LIB_DIR . '/global.funcs.php'; + include P2_LIB_DIR . '/setup.funcs.php'; + spl_autoload_register('p2_load_class'); // ®ì«ðmF (vð½µÄ¢éÈçRgAEgÂ) - p2checkenv(__LINE__); + p2_check_environment(__LINE__); if ($debug) { if (!class_exists('Benchmark_Profiler', false)) { @@ -226,8 +213,7 @@ // }}} // {{{ ¶R[hÌwè - //mb_detect_order("CP932,CP51932,ASCII"); - mb_internal_encoding('CP932'); + mb_internal_encoding('SJIS-win'); mb_http_output('pass'); mb_substitute_character(63); // ¶R[hϷɸsµ½¶ª "?" ÉÈé //mb_substitute_character(0x3013); // ¬ @@ -235,7 +221,7 @@ if (function_exists('mb_ereg_replace')) { define('P2_MBREGEX_AVAILABLE', 1); - mb_regex_encoding('CP932'); + mb_regex_encoding('SJIS-win'); } else { define('P2_MBREGEX_AVAILABLE', 0); } @@ -279,7 +265,7 @@ $_conf['detect_hint'] = ''; $_conf['detect_hint_input_ht'] = '<input type="hidden" name="_hint" value="">'; $_conf['detect_hint_input_xht'] = '<input type="hidden" name="_hint" value="" />'; - //$_conf['detect_hint_utf8'] = mb_convert_encoding('', 'UTF-8', 'CP932'); + //$_conf['detect_hint_utf8'] = mb_convert_encoding('', 'UTF-8', 'SJIS-win'); $_conf['detect_hint_q'] = '_hint=%81%9D%81%9E'; // rawurlencode($_conf['detect_hint']) $_conf['detect_hint_q_utf8'] = '_hint=%E2%97%8E%E2%97%87'; // rawurlencode($_conf['detect_hint_utf8']) @@ -337,214 +323,7 @@ } // }}} -// {{{ p2checkenv() -/** - * ®ì«ðmF·é - * - * @return bool - */ -function p2checkenv($check_recommended) -{ - global $_info_msg_ht; - - $php_version = phpversion(); - $required_version = '5.2.8'; - $recommended_version52 = '5.2.12'; - $recommended_version53 = '5.3.1'; - $required_extensions = array( - 'dom', - 'json', - 'libxml', - 'mbstring', - 'pcre', - 'pdo', - 'pdo_sqlite', - 'session', - 'spl', - //'xsl', - 'zlib', - ); - - // PHPÌo[W - if (version_compare($php_version, $required_version, '<')) { - p2die("PHP {$required_version} ¢ÅÍg¦Ü¹ñB"); - } - - // K{g£W [ - foreach ($required_extensions as $ext) { - if (!extension_loaded($ext)) { - p2die("{$ext} g£W [ª[h³êĢܹñB"); - } - } - - // Lø¾Æ®ìµÈ¢php.inifBNeBu - $directives = array( - 'safe_mode', - 'register_globals', - 'magic_quotes_gpc', - 'mbstring.encoding_translation', - 'session.cookie_httponly', - ); - foreach ($directives as $directive) { - if (ini_get($directive)) { - p2die("{$directive} ª On Å·B", - "php.ini Å {$directive} ð Off ɵľ³¢B"); - } - } - - // eAccelerator - if (extension_loaded('eaccelerator') && - version_compare(EACCELERATOR_VERSION, '0.9.5.2', '<')) - { - $err = 'eAcceleratorðXVµÄ¾³¢B'; - $ev = EACCELERATOR_VERSION; - $msg = <<<EOP -<p>PHP 5.2ÅáOðߨūȢâèÌ éeAccelerator ({$ev})ªCXg[³êĢܷB<br> -eAcceleratorð³øÉ·é©A±ÌâèªC³³ê½eAccelerator 0.9.5.2È~ðgpµÄ¾³¢B<br> -<a href="http://eaccelerator.net/">http://eaccelerator.net/</a></p> -EOP; - p2die($err, $msg, true); - } - - // §o[W - if ($check_recommended) { - if (version_compare($php_version, '5.3.0-dev', '>=')) { - $recommended_version = $recommended_version53; - } else { - $recommended_version = $recommended_version52; - } - if (version_compare($php_version, $recommended_version, '<')) { - // title.php ÌÝbZ[Wð\¦ - if (basename($_SERVER['PHP_SELF'], '.php') == 'title') { - $_info_msg_ht .= <<<EOP -<p><strong>§o[WæèâPHPÅ®ìµÄ¢Ü·B</strong><em>(PHP {$php_version})</em><br> -PHP {$recommended_version} È~ÉAbvf[g·é±Æ𨷷ߵܷB</p> -<p style="font-size:smaller">±ÌbZ[Wð\¦µÈ¢æ¤É·éÉÍ <em>{\$rep2_directory}</em>/conf/conf.inc.php Ì {$check_recommended} sÚA<br> -<samp>p2checkenv(__LINE__);</samp> ð <samp>p2checkenv(false);</samp> É«·¦Ä¾³¢B</p> -EOP; - } - return false; - } - } - - return true; -} - -// }}} -// {{{ p2checkmigration() - -/** - * }CO[VÌKvª é©Ç¤©ð`FbN - * - * @param string $config_version - * @return array - */ -function p2checkmigration($config_version) -{ - // "yymmdd.hhmm" `®Ì}CO[VªKvÈÏXÌ Á½o[WÔÌzñ - // lÍj[N©Â¸É\[g³êĢȯêÎÈçÈ¢ - $versions = array( - '100113.1300', - ); - - $migrators = array(); - $found = false; - - foreach ($versions as $version) { - if ($found || version_compare($config_version, $version, '<')) { - $found = true; - $migrator_name = str_replace('.', '_', $version); - $migrator_func = 'p2_migrate_' . $migrator_name; - $migrator_file = '/migrators/' . $migrator_name . '.php'; - $migrators[$migrator_func] = $migrator_file; - } - } - - if ($found) { - return $migrators; - } else { - return null; - } -} - -// }}} -// {{{ p2migrate() - -/** - * }CO[VðÀs - * - * @param array $user_conf â[U[Ýè - * @param array $migrators }CO[VÖÌXg - * @return array Vµ¢[U[Ýè - */ -function p2migrate(array $user_conf, array $migrators) -{ - global $_conf; - - foreach ($migrators as $migrator_func => $migrator_file) { - include P2_LIB_DIR . $migrator_file; - $user_conf = $migrator_func($_conf, $user_conf); - } - - return $user_conf; -} - -// }}} -// {{{ p2autoload() - -/** - * NX[_[ - * - * @string $name - * @return void - */ -function p2autoload($name) -{ - if (preg_match('/^(?: - BbsMap | - BrdCtl | - BrdMenu\\w* | - DataPhp | - FavSetManager | - FileCtl | - HostCheck | - Login | - NgAbornCtl | - P2\\w+ | - PresetManager | - ResHist | - Session | - SettingTxt | - ShowBrdMenu\\w* | - ShowThread\\w* | - StrCtl | - StrSjis | - SubjectTxt | - Thread\\w* | - Wap\\w+ - )$/x', $name)) - { - if ($name == 'P2Lock') { - include P2_LIB_DIR . '/FileCtl.php'; - } elseif ($name == 'ResArticle') { - include P2_LIB_DIR . '/ResHist.php'; - } elseif (strncmp($name, 'Wap', 3) === 0) { - include P2_LIB_DIR . '/Wap.php'; - } elseif (strncmp($name, 'P2Http', 6) === 0) { - include P2_LIB_DIR . '/P2HttpExt.php'; - } elseif (strncmp($name, 'BrdMenu', 7) === 0) { - include P2_LIB_DIR . '/BrdMenu.php'; - } else { - include P2_LIB_DIR . '/' . $name . '.php'; - } - } elseif (preg_match('/^\\w+DataStore$/', $name)) { - include P2_LIB_DIR . '/P2DataStore/' . $name . '.php'; - } -} - -// }}} - /* * Local Variables: * mode: php Added: p2ex/trunk/conf/setup_info.php =================================================================== --- p2ex/trunk/conf/setup_info.php (rev 0) +++ p2ex/trunk/conf/setup_info.php 2010-01-13 23:31:20 UTC (rev 778) @@ -0,0 +1,53 @@ +<?php +/** + * rep2expack - «`FbNÅgp·éÏ + */ + +// K{o[W +$p2_required_version_5_2 = '5.2.8'; +$p2_required_version_5_3 = '5.3.0'; + +// §o[W +$p2_recommended_version_5_2 = '5.2.12'; +$p2_recommended_version_5_3 = '5.3.1'; + +// K{g£W [ +$p2_required_extensions = array( + 'dom', + 'json', + 'libxml', + 'mbstring', + 'pcre', + 'pdo', + 'pdo_sqlite', + 'session', + 'spl', + //'xsl', + 'zlib', +); + +// Lø¾Æ®ìµÈ¢php.inifBNeBu +$p2_incompatible_ini_directives = array( + 'safe_mode', + 'register_globals', + 'magic_quotes_gpc', + 'mbstring.encoding_translation', + 'session.cookie_httponly', +); + +// ÚsXNvgÌÀsªKvÈÏXÌ Á½o[WÔÌzñ +// lÍ "yymmdd.hhmm" `®Åj[N©Â¸É\[g³êĢȯêÎÈçÈ¢ +$p2_changed_versions = array( + '100113.1300', +); + +/* + * 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/Login.php =================================================================== --- p2ex/trunk/lib/Login.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/Login.php 2010-01-13 23:31:20 UTC (rev 778) @@ -732,7 +732,9 @@ return false; } - require_once P2_LIB_DIR . '/md5_crypt.inc.php'; + if (!function_exists('md5_encrypt')) { + include P2_LIB_DIR . '/md5_crypt.funcs.php'; + } $key = $this->getMd5CryptKey(); @@ -756,7 +758,9 @@ { global $_conf; - require_once P2_LIB_DIR . '/md5_crypt.inc.php'; + if (!function_exists('md5_decrypt')) { + include P2_LIB_DIR . '/md5_crypt.funcs.php'; + } $key = $this->getMd5CryptKey(); Modified: p2ex/trunk/lib/P2Util.php =================================================================== --- p2ex/trunk/lib/P2Util.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/P2Util.php 2010-01-13 23:31:20 UTC (rev 778) @@ -1060,7 +1060,9 @@ { global $_conf; - require_once P2_LIB_DIR . '/md5_crypt.inc.php'; + if (!function_exists('md5_encrypt')) { + include P2_LIB_DIR . '/md5_crypt.funcs.php'; + } $md5_crypt_key = self::getAngoKey(); $crypted_login2chPW = md5_encrypt($login2chPW, $md5_crypt_key, 32); @@ -1094,7 +1096,9 @@ { global $_conf; - require_once P2_LIB_DIR . '/md5_crypt.inc.php'; + if (!function_exists('md5_decrypt')) { + include P2_LIB_DIR . '/md5_crypt.funcs.php'; + } if (!file_exists($_conf['idpw2ch_php'])) { return false; Modified: p2ex/trunk/lib/bootstrap.php =================================================================== --- p2ex/trunk/lib/bootstrap.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/bootstrap.php 2010-01-13 23:31:20 UTC (rev 778) @@ -1,7 +1,7 @@ <?php /** * rep2expack - ú»XNvg - * conf/conf.inc.php Ì p2configure() ©çÇÝÜêéB + * conf/conf.inc.php Ì p2_init() ©çÇÝÜêéB */ require_once 'Net/UserAgent/Mobile.php'; @@ -41,8 +41,8 @@ if ($config_version !== $_conf['p2expack']) { // ÝèÌXV - if ($migrators = p2checkmigration($config_version)) { - $conf_user = p2migrate($conf_user, $migrators); + if ($migrators = p2_check_migration($config_version)) { + $conf_user = p2_invoke_migrators($migrators, $conf_user); } // ftHgÝèðÇÝÝA[U[ÝèÆÆàÉ}[W Copied: p2ex/trunk/lib/global.funcs.php (from rev 777, p2ex/trunk/lib/p2util.inc.php) =================================================================== --- p2ex/trunk/lib/global.funcs.php (rev 0) +++ p2ex/trunk/lib/global.funcs.php 2010-01-13 23:31:20 UTC (rev 778) @@ -0,0 +1,621 @@ +<?php +/** + * rep2expack - [eBeBÖQ + */ + +// {{{ CONSTANTS + +/** + * ®ÌÅålÆŬl + */ +define('P2_INT_MAX', PHP_INT_MAX); +define('P2_INT_MIN', - PHP_INT_MAX - 1); + +/** + * ¿É}b`·é³K\» + */ +//define('P2_REGEX_KANJI', mb_convert_encoding('/[ê-ê]/u', 'UTF-8', 'SJIS-win')); +define('P2_REGEX_KANJI', '/[\\x{4e00}-\\x{9fa0}]/u'); + +/** + *·²KȪ©¿«p³K\» + */ +/* +define('P2_REGEX_WAKATI', mb_convert_encoding('/(' . implode('|', array( + //'[ê-ê]+[-ñ]*', + //'[ê-ê]+', + '[êñOlÜZµªã\]+', + '[-ê]+', + '[-ñ][-ñ[`JK]*', + '[@-][@-[`JK]*', + //'[a-z][a-z_\\-]*', + //'[0-9][0-9.]*', + '[0-9a-z][0-9a-z_\\-]*', +)) . ')/u', 'UTF-8', 'SJIS-win')); +*/ +define('P2_REGEX_WAKATI', '/( +#[\\x{4e00}-\\x{9fa0}]+[\\x{3041}-\\x{3093}]*| +#[\\x{4e00}-\\x{9fa0}]+| +[\\x{4e00}\\x{4e8c}\\x{4e09}\\x{56db}\\x{4e94}\\x{516d}\\x{4e03}\\x{516b}\\x{4e5d}\\x{5341}]+| +[\\x{4e01}-\\x{9fa0}]+| +[\\x{3041}-\\x{3093}][\\x{3041}-\\x{3093}\\x{30fc}\\x{301c}\\x{309b}\\x{309c}]*| +[\\x{30a1}-\\x{30f6}][\\x{30a1}-\\x{30f6}\\x{30fc}\\x{301c}\\x{309b}\\x{309c}]*| +#[a-z][a-z_\\-]*| +#[0-9][0-9.]*| +[0-9a-z][0-9a-z_\\-]*)/ux'); + +/** + * UTF-8,NFDÌÐçªÈEJ^JiÌ÷¹E¼÷¹É}b`·é³K\» + */ +/* +define('P2_REGEX_NFD_KANA', + str_replace( + array('%u3099%', '%u309A%'), + array(pack('C*', 0xE3, 0x82, 0x99), pack('C*', 0xE3, 0x82, 0x9A)), + mb_convert_encoding( + '/([¤©-±³-»½-ÆÍ-ÙEJ-RT-\^-gn-zTR])%u3099%|([Í-Ùn-z])%u309A%/u', + 'UTF-8', + 'SJIS-win' + ) + ) +); +*/ +define('P2_REGEX_NFD_KANA', '/([\\x{3046}\\x{304b}-\\x{3053}\\x{3055}-\\x{305d}\\x{305f}-\\x{3068}\\x{306f}-\\x{307b}\\x{30a6}\\x{30ab}-\\x{30b3}\\x{30b5}-\\x{30bd}\\x{30bf}-\\x{30c8}\\x{30cf}-\\x{30db}\\x{309d}\\x{30fd}])\\x{3099}|([\\x{306f}-\\x{307b}\\x{30cf}-\\x{30db}])\\x{309a}/u'); + +// }}} +// {{{ p2h() + +/** +* htmlspecialchars($value, ENT_QUOTES) ÌV[gJbg +* +* @param string $str +* @param string $charset +* @param bool $double_encode +* @return string +*/ +function p2h($str, $charset = 'Shift_JIS', $double_encode = true) +{ + return htmlspecialchars($str, ENT_QUOTES, $charset, $double_encode); +} + +// }}} +// {{{ p2die() + +/** + * bZ[Wð\¦µÄI¹ + * wb_ªoͳêÄ¢éêA<body>ÜÅÍoÍÏÆ©È· + * + * I¹Xe[^XR[h2ÍP2CommandRunnerÉG[bZ[Wª + * HTMLÅ é±ÆðÊm·é½ß + * + * @param string $err G[Tv + * @param string $msg Ú×Èྠ+ * @param bool $raw Ú×Èà¾ðGXP[v·é©Û© + * @return void + */ +function p2die($err = null, $msg = null, $raw = false) +{ + if (!defined('P2_CLI_RUN') && !headers_sent()) { + header('Expires: ' . http_date(0)); // útªß + header('Last-Modified: ' . http_date()); // íÉC³³êÄ¢é + header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 + header('Cache-Control: post-check=0, pre-check=0', false); + header('Pragma: no-cache'); // HTTP/1.0 + echo <<<EOH +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> +<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> +{$GLOBALS['_conf']['extra_headers_ht']} +<title>rep2 error</title> +</head> +<body> +EOH; + } + + echo '<h3>rep2 error</h3>'; + + if ($err !== null) { + echo '<p><strong>', htmlspecialchars($err, ENT_QUOTES), '</strong></p>'; + } + + if ($msg !== null) { + if ($raw) { + echo $msg; + } else { + echo '<p>', nl2br(htmlspecialchars($msg, ENT_QUOTES)), '</p>'; + } + } + + if (true) { + echo '<pre><em>backtrace:</em>'; + + $p2_file_prefix = P2_BASE_DIR . DIRECTORY_SEPARATOR; + $p2_base_dir_len = strlen(P2_BASE_DIR); + $backtrace = debug_backtrace(); + $c = count($backtrace); + + foreach ($backtrace as $bt) { + echo "\n"; + + if (strpos($bt['file'], $p2_file_prefix) === 0) { + $filename = '.' . substr($bt['file'], $p2_base_dir_len); + } else { + $filename = '(external)' . DIRECTORY_SEPARATOR . basename($bt['file']); + } + printf(' % 2d. %s (line %d)', $c--, $filename, $bt['line']); + + if (array_key_exists('function', $bt) && $bt['function'] !== '' && $bt['function'] !== 'p2die') { + if (array_key_exists('class', $bt) && $bt['class'] !== '') { + printf(': %s%s%s()', + $bt['class'], + str_replace('>', '>', $bt['type']), + $bt['function'] + ); + } else { + printf(': %s()', $bt['function']); + } + } + } + + echo '</pre>'; + } + + if (!defined('P2_CLI_RUN')) { + echo '</body></html>'; + } + exit(2); +} + +// }}} +// {{{ http_date() + +if (!function_exists('http_date')) { + /** + * pecl_httpÌhttp_date()ÌPure PHPÅ + * + * @param int $timestamp + * @return string + */ + function http_date($timestamp = null) + { + if ($timestamp === null) { + //return str_replace('+0000', 'GMT', gmdate(DATE_RFC1123)); + return gmdate('D, d M Y H:i:s \\G\\M\\T'); + } + //return str_replace('+0000', 'GMT', gmdate(DATE_RFC1123, $timestamp)); + return gmdate('D, d M Y H:i:s \\G\\M\\T', $timestamp); + } +} + +// }}} +// {{{ ctype + +/** + * ctypeg£W [ÖÌPure PHPÅ (cntrl,graph,print,punct,spaceͤ) + */ +if (!extension_loaded('ctype')) { + function ctype_alnum($str) { return (bool)preg_match('/^[0-9A-Za-z]+$/', $str); } + function ctype_alpha($str) { return (bool)preg_match('/^[A-Za-z]+$/', $str); } + function ctype_digit($str) { return (bool)preg_match('/^[0-9]+$/', $str); } + function ctype_lower($str) { return (bool)preg_match('/^[a-z]+$/', $str); } + function ctype_upper($str) { return (bool)preg_match('/^[A-Z]+$/', $str); } + function ctype_xdigit($str) { return (bool)preg_match('/^[0-9A-Fa-f]+$/', $str); } +} + +// }}} +// {{{ p2_scan_nullbyte() + +/** + * NGXgp[^©çNULLoCgðoµ½çI¹·é + * array_walk_recursive() pR[obNÖ + * + * @param mixed $value + * @param mixed $key + * @return void + */ +function p2_scan_nullbyte($value, $key) +{ + if (is_string($value) && strpos($value, P2_NULLBYTE) !== false) { + p2die('NGXgp[^ÉNULLoCgªÜÜêĢܷB'); + } +} + +// }}} +// {{{ p2_scan_script_injection() + +/** + * ¶ÌÜÜHTMLÉßÜêé host, bbs, key, ls É + * HTMLÌÁ궪ÜÜêÄ¢½çI¹·é + * + * @param array $request + * @return void + */ +function p2_scan_script_injection($request) +{ + foreach (array('host', 'bbs', 'key', 'ls') as $key) { + if (array_key_exists($key, $request)) { + $value = $request[$key]; + if (htmlspecialchars($value, ENT_QUOTES) != $value) { + p2die('NGXgp[^És³È¶ª èÜ·B'); + } + } + } +} + +// }}} +// {{{ p2_print_memory_usage() + +/** + * ÌgpÊð\¦·é + * + * @return void + */ +function p2_print_memory_usage() +{ + if (function_exists('memory_get_usage')) { + $usage = memory_get_usage(); + } elseif (function_exists('xdebug_memory_usage')) { + $usage = xdebug_memory_usage(); + } else { + $usage = -1; + } + $kb = $usage / 1024; + $kb = number_format($kb, 2, '.', ''); + + echo 'Memory Usage: ' . $kb . 'KiB'; +} + +// }}} +// {{{ p2_realpath() + +/** + * ÀݵȢ(©àµêÈ¢)t@CÌâÎpXðæ¾·é + * + * @param string $path + * @return string + */ +function p2_realpath($path) +{ + if (file_exists($path)) { + return realpath($path); + } + if (!class_exists('File_Util', false)) { + require 'File/Util.php'; + } + return File_Util::realPath($path); +} + +// }}} +// {{{ p2_si2int() + +/** + * SIÚª«Â«Ìlð®ÉÏ··é + * + * @param numeric $num + * @param string $kmg + * @return int + * @throws OverflowException, UnderflowException + */ +function p2_si2int($num, $kmg) +{ + $real = p2_si2real($num, $kmg); + if ($real > PHP_INT_MAX) { + throw new OverflowException(sprintf('Integer overflow (%0.0f)', $real)); + //return PHP_INT_MAX; + } + if ($real < P2_INT_MIN) { + throw new UnderflowException(sprintf('Integer underflow (%0.0f)', $real)); + //return P2_INT_MIN; + } + return (int)$real; +} + +// }}} +// {{{ p2_si2real() + +/** + * SIÚª«Â«ÌlðÀÉÏ··é + * µ§ÉÍ1000{·é̪³µ¢ªA ¦Ä1024{·é + * + * @param numeric $num + * @param string $kmg + * @return float + */ +function p2_si2real($num, $kmg) +{ + $num = (float)$num; + switch ($kmg[0]) { + case 'G': case 'g': $num *= 1024; + case 'M': case 'm': $num *= 1024; + case 'M': case 'k': $num *= 1024; + } + return $num; +} + +// }}} +// {{{ p2_mb_basename() + +/** + * }`oCgÎÌbasename() + * + * @param string $path + * @param string $encoding + * @return string + */ +function p2_mb_basename($path, $encoding = 'SJIS-win') +{ + if (DIRECTORY_SEPARATOR != '/') { + $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); + } + if (!mb_substr_count($path, '/', $encoding)) { + return $path; + } + $len = mb_strlen($path, $encoding); + $pos = mb_strrpos($path, '/', $encoding); + return mb_substr($path, $pos + 1, $len - $pos, $encoding); +} + +// }}} +// {{{ p2_mb_ereg_count() + +/** + * }`oCg³K\»É}b`µ½ñðÔ· + * + * @param string $pattern + * @param string $string + * @param string $option + * @return int + */ +function p2_mb_ereg_count($pattern, $string, $option = null) +{ + if ($option === null) { + if (!mb_ereg_search_init($string, $pattern)) { + return false; + } + } else { + if (!mb_ereg_search_init($string, $pattern, $option)) { + return false; + } + } + + $i = 0; + + while (mb_ereg_search()) { + $i++; + } + + return $i; +} + +// }}} +// {{{ p2_set_filtering_word() + +/** + * tB^}b`OpÌO[oÏðÝè·é + * + * @param string $word + * @param string $method + * @return string + */ +function p2_set_filtering_word($word, $method = 'regex') +{ + $word_fm = StrCtl::wordForMatch($word, $method); + + if (strlen($word_fm) == 0) { + $word_fm = null; + $GLOBALS['word_fm'] = null; + $GLOBALS['words_fm'] = array(); + } elseif ($method == 'just' || $method == 'regex') { + $GLOBALS['word_fm'] = $word_fm; + $GLOBALS['words_fm'] = array($word_fm); + } elseif (P2_MBREGEX_AVAILABLE == 1) { + $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $word_fm); + $GLOBALS['words_fm'] = mb_split('\\s+', $word_fm); + } else { + $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $word_fm); + $GLOBALS['words_fm'] = preg_split('/\\s+/', $word_fm); + } + + return $word_fm; +} + +// }}} +// {{{ p2_normalize() + +if (extension_loaded('intl')) { + /** + * NormalizerNXðgÁ½³K»Ö + * + * @param string $str + * @return string + */ + function p2_normalize($str) + { + return strtolower(Normalizer::normalize(mb_convert_encoding( + $str, 'UTF-8', 'SJIS-win'), Normalizer::NFKC)); + } +} else { + /** + * ·²KȳK»Ö + * + * @param string $str + * @return string + */ + function p2_normalize($str) + { + return mb_strtolower(mb_convert_kana(mb_convert_encoding( + $str, 'UTF-8', 'SJIS-win'), 'KVas', 'UTF-8'), 'UTF-8'); + } +} + +// }}} +// {{{ p2_wakati() + +/** + * ·²KȪ©¿«Ö + * + * @param string $str + * @return array + */ +function p2_wakati($str) +{ + $str = preg_replace(P2_REGEX_WAKATI, '$0 ', p2_normalize($str)); + return preg_split('/\\s+/u', $str, -1, PREG_SPLIT_NO_EMPTY); +} + +// }}} +// {{{ p2_get_highlighting_regex + +/** + * p2_wakati()ÌÊAL[[hÌzñ©çnCCgp̳K\»ð¶¬·é + * + * @param array $words + * @return string + */ +function p2_get_highlighting_regex(array $words) +{ + $featured_words = array_filter($words, '_p2_get_highlighting_regex_filter'); + if (count($featured_words) == 0) { + $featured_words = $words; + } + //rsort($featured_words, SORT_STRING); + + $pattern = mb_convert_encoding(implode(' ', $featured_words), 'SJIS-win', 'UTF-8'); + return str_replace(' ', '|', StrCtl::wordForMatch($pattern, 'or')); + +} + +// }}} +// {{{ _p2_get_highlighting_regex_filter + +/** + * p2_get_highlighting_regex()©çÄÑo³êéR[obNÖ + * + * @param string $str + * @return bool + */ +function _p2_get_highlighting_regex_filter($str) +{ + if (preg_match(P2_REGEX_KANJI, $str)) { + return true; + } elseif (mb_strlen($str, 'UTF-8') > 1 && preg_match(P2_REGEX_WAKATI, $str)) { + return true; + } else { + return false; + } +} + +// }}} +// {{{ p2_combine_nfd_kana() + +/** + * Safari ©çAbv[h³ê½t@C¼Ì¶»¯ðâ³·éÖ + * ´¹+÷_E´¹+¼÷_ðê¶ÉÜÆßé (NFD ųK»³ê½ ©È ð NFC É·é) + * üoÍ̶R[hÍUTF-8 + * + * @param string $str + * @return string + */ +function p2_combine_nfd_kana($str) +{ + if (extension_loaded('intl')) { + return Normalizer::normalize($str, Normalizer::NFC); + } + return preg_replace_callback(P2_REGEX_NFD_KANA, '_p2_combine_nfd_kana', $str); +} + +// }}} +// {{{ _p2_combine_nfd_kana() + +/** + * p2_combine_nfd_kana()©çÄÑo³êéR[obNÖ + * + * @param array $m + * @return string + */ +function _p2_combine_nfd_kana($m) +{ + if ($m[1]) { + $C = unpack('C*', $m[1]); + $C[3] += 1; + } elseif ($m[2]) { + $C = unpack('C*', $m[2]); + $C[3] += 2; + } else { + return $m[0]; // è¦È¢ + } + + return pack('C*', $C[1], $C[2], $C[3]); +} + +// }}} +// {{{ p2_correct_css_fonts() + +/** + * X^CV[gÌtHgwèð²®·é + * + * @param string|array $fonts + * @return string + */ +function p2_correct_css_fontfamily($fonts) +{ + if (is_string($fonts)) { + $fonts = preg_split('/(["\'])?\\s*,\\s*(?(1)\\1)/', trim($fonts, " \t\"'")); + } elseif (!is_array($fonts)) { + return ''; + } + $fonts = '"' . implode('","', $fonts) . '"'; + $fonts = preg_replace('/"(serif|sans-serif|cursive|fantasy|monospace)"/', '\\1', $fonts); + return trim($fonts, '"'); +} + +// }}} +// {{{ p2_correct_css_color() + +/** + * X^CV[gÌFwèð²®·é + * + * @param string $color + * @return string + */ +function p2_correct_css_color($color) +{ + return preg_replace('/^#([0-9A-F])([0-9A-F])([0-9A-F])$/i', '#$1$1$2$2$3$3', $color); +} + +// }}} +// {{{ p2_escape_css_url() + +/** + * X^CV[gÌURLðGXP[v·é + * + * CSSÅÁÉÓ¡Ì ég[NÅ éó¶AVONH[gA + * _uNH[gAÊAobNXbV ðURLGR[h·é + * + * @param string $url + * @return string + */ +function p2_escape_css_url($url) +{ + if (strpos($url, chr(0)) !== false) { + return ''; + } + return str_replace(array( "\t", "\n", "\r", ' ', '"', "'", '(', ')', '\\'), + array('%09', '%0A', '%0D', '%20', '%22', '%27', '%28', '%29', '%5C'), + $url); +} + +// }}} + +/* + * 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: Copied: p2ex/trunk/lib/md5_crypt.funcs.php (from rev 777, p2ex/trunk/lib/md5_crypt.inc.php) =================================================================== --- p2ex/trunk/lib/md5_crypt.funcs.php (rev 0) +++ p2ex/trunk/lib/md5_crypt.funcs.php 2010-01-13 23:31:20 UTC (rev 778) @@ -0,0 +1,89 @@ +<?php +/** + * ±Ìt@CÌÖÍAPHP}j Ay[WæèÌqØÅ·B´ÓB + * @link http://jp.php.net/manual/ja/function.md5.php + * + * Alexander Valyalkin + * 01-Jul-2004 05:41 + * Below is MD5-based block cypher (MDC-like), which works in 128bit CFB mode. + * It is very useful to encrypt secret data before transfer it over the network. + * $iv_len - initialization vector's length. + * 0 <= $iv_len <= 512 + */ + +// {{{ get_rnd_iv() + +function get_rnd_iv($iv_len) +{ + $iv = ''; + while ($iv_len-- > 0) { + $iv .= chr(mt_rand() & 0xff); + } + return $iv; +} + +// }}} +// {{{ md5_decrypt() + +function md5_encrypt($plain_text, $password, $iv_len = 16) +{ + $plain_text .= "\x13"; + $n = strlen($plain_text); + if ($n % 16) $plain_text .= str_repeat(chr(0), 16 - ($n % 16)); + $i = 0; + $enc_text = get_rnd_iv($iv_len); + $iv = substr($password ^ $enc_text, 0, 512); + while ($i < $n) { + $block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv)); + $enc_text .= $block; + $iv = substr($block . $iv, 0, 512) ^ $password; + $i += 16; + } + return base64_encode($enc_text); +} + +// }}} +// {{{ md5_decrypt() + +function md5_decrypt($enc_text, $password, $iv_len = 16) +{ + $enc_text = base64_decode($enc_text); + $n = strlen($enc_text); + $i = $iv_len; + $plain_text = ''; + $iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512); + while ($i < $n) { + $block = substr($enc_text, $i, 16); + $plain_text .= $block ^ pack('H*', md5($iv)); + $iv = substr($block . $iv, 0, 512) ^ $password; + $i += 16; + } + return preg_replace('/\\x13\\x00*$/', '', $plain_text); +} + +// }}} + +/******************************************/ +/* +$plain_text = 'very secret string'; +$password = 'very secret password'; +echo "plain text is: [${plain_text}]<br />\n"; +echo "password is: [${password}]<br />\n"; + +$enc_text = md5_encrypt($plain_text, $password); +echo "encrypted text is: [${enc_text}]<br />\n"; + +$plain_text2 = md5_decrypt($enc_text, $password); +echo "decrypted text is: [${plain_text2}]<br />\n"; +*/ + +/* + * 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: Deleted: p2ex/trunk/lib/md5_crypt.inc.php =================================================================== --- p2ex/trunk/lib/md5_crypt.inc.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/md5_crypt.inc.php 2010-01-13 23:31:20 UTC (rev 778) @@ -1,89 +0,0 @@ -<?php -/** - * ±Ìt@CÌÖÍAPHP}j Ay[WæèÌqØÅ·B´ÓB - * @link http://jp.php.net/manual/ja/function.md5.php - * - * Alexander Valyalkin - * 01-Jul-2004 05:41 - * Below is MD5-based block cypher (MDC-like), which works in 128bit CFB mode. - * It is very useful to encrypt secret data before transfer it over the network. - * $iv_len - initialization vector's length. - * 0 <= $iv_len <= 512 - */ - -// {{{ get_rnd_iv() - -function get_rnd_iv($iv_len) -{ - $iv = ''; - while ($iv_len-- > 0) { - $iv .= chr(mt_rand() & 0xff); - } - return $iv; -} - -// }}} -// {{{ md5_decrypt() - -function md5_encrypt($plain_text, $password, $iv_len = 16) -{ - $plain_text .= "\x13"; - $n = strlen($plain_text); - if ($n % 16) $plain_text .= str_repeat(chr(0), 16 - ($n % 16)); - $i = 0; - $enc_text = get_rnd_iv($iv_len); - $iv = substr($password ^ $enc_text, 0, 512); - while ($i < $n) { - $block = substr($plain_text, $i, 16) ^ pack('H*', md5($iv)); - $enc_text .= $block; - $iv = substr($block . $iv, 0, 512) ^ $password; - $i += 16; - } - return base64_encode($enc_text); -} - -// }}} -// {{{ md5_decrypt() - -function md5_decrypt($enc_text, $password, $iv_len = 16) -{ - $enc_text = base64_decode($enc_text); - $n = strlen($enc_text); - $i = $iv_len; - $plain_text = ''; - $iv = substr($password ^ substr($enc_text, 0, $iv_len), 0, 512); - while ($i < $n) { - $block = substr($enc_text, $i, 16); - $plain_text .= $block ^ pack('H*', md5($iv)); - $iv = substr($block . $iv, 0, 512) ^ $password; - $i += 16; - } - return preg_replace('/\\x13\\x00*$/', '', $plain_text); -} - -// }}} - -/******************************************/ -/* -$plain_text = 'very secret string'; -$password = 'very secret password'; -echo "plain text is: [${plain_text}]<br />\n"; -echo "password is: [${password}]<br />\n"; - -$enc_text = md5_encrypt($plain_text, $password); -echo "encrypted text is: [${enc_text}]<br />\n"; - -$plain_text2 = md5_decrypt($enc_text, $password); -echo "decrypted text is: [${plain_text2}]<br />\n"; -*/ - -/* - * 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/migrators/100113_1300.php =================================================================== --- p2ex/trunk/lib/migrators/100113_1300.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/migrators/100113_1300.php 2010-01-13 23:31:20 UTC (rev 778) @@ -8,21 +8,21 @@ /** * rev.100113.1300 * - * @param array $core_conf rep2RAÌÝè - * @param array $user_conf â[U[Ýè + * @param array $core_config rep2RAÌÝè + * @param array $user_config â[U[Ýè * @return array Vµ¢[U[Ýè */ -function p2_migrate_100113_1300(array $core_conf, array $user_conf) +function p2_migrate_100113_1300(array $core_config, array $user_config) { - $data_dir = $core_conf['data_dir']; - $db_dir = $core_conf['db_dir']; - $cache_dir = $core_conf['cache_dir']; - $cookie_dir = $core_conf['cookie_dir']; + $data_dir = $core_config['data_dir']; + $db_dir = $core_config['db_dir']; + $cache_dir = $core_config['cache_dir']; + $cookie_dir = $core_config['cookie_dir']; // {{{ zXg`FbNÌgethostbyaddr()LbV $old_hostcheck_db = $cache_dir . '/hostcheck_gethostby.sq3'; - $new_hostcheck_db = $core_conf['hostcheck_db_path']; + $new_hostcheck_db = $core_config['hostcheck_db_path']; _100113_1300_rename_db($old_hostcheck_db, $new_hostcheck_db); _100113_1300_rename_table($new_hostcheck_db, 'kvs_p2keyvaluestore', 'kvs_default'); @@ -43,7 +43,7 @@ // {{{ epCookieXg[W $old_cookie_db = $cookie_dir . '/p2_cookies.sqlite3'; - $new_cookie_db = $core_conf['cookie_db_path']; + $new_cookie_db = $core_config['cookie_db_path']; _100113_1300_rename_db($old_cookie_db, $new_cookie_db); _100113_1300_rename_table($new_cookie_db, 'kvs_p2keyvaluestore_serializing', 'kvs_serializing'); @@ -52,14 +52,14 @@ // {{{ «Ýf[^ÌobNAbvXg[W $old_post_db = $cookie_dir . '/p2_post_data.sqlite3'; - $new_post_db = $core_conf['post_db_path']; + $new_post_db = $core_config['post_db_path']; _100113_1300_rename_db($old_post_db, $new_post_db); _100113_1300_rename_table($new_post_db, 'kvs_p2keyvaluestore_serializing', 'kvs_serializing'); // }}} - return $user_conf; + return $user_config; } // }}} Modified: p2ex/trunk/lib/migrators/yymmdd_hhmm.php =================================================================== --- p2ex/trunk/lib/migrators/yymmdd_hhmm.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/migrators/yymmdd_hhmm.php 2010-01-13 23:31:20 UTC (rev 778) @@ -8,13 +8,13 @@ /** * yymmdd_hhmm ðÀÛÌo[WÔÉu·µÄÖÌgðLq·é * - * @param array $core_conf rep2RAÌÝè - * @param array $user_conf â[U[Ýè + * @param array $core_config rep2RAÌÝè + * @param array $user_config â[U[Ýè * @return array Vµ¢[U[Ýè */ -function p2_migrate_yymmdd_hhmm(array $core_conf, array $user_conf) +function p2_migrate_yymmdd_hhmm(array $core_config, array $user_config) { - return $user_conf; + return $user_config; } // }}} Deleted: p2ex/trunk/lib/p2util.inc.php =================================================================== --- p2ex/trunk/lib/p2util.inc.php 2010-01-13 16:07:10 UTC (rev 777) +++ p2ex/trunk/lib/p2util.inc.php 2010-01-13 23:31:20 UTC (rev 778) @@ -1,621 +0,0 @@ -<?php -/** - * rep2expack - [eBeBÖQ - */ - -// {{{ CONSTANTS - -/** - * ®ÌÅålÆŬl - */ -define('P2_INT_MAX', PHP_INT_MAX); -define('P2_INT_MIN', - PHP_INT_MAX - 1); - -/** - * ¿É}b`·é³K\» - */ -//define('P2_REGEX_KANJI', mb_convert_encoding('/[ê-ê]/u', 'UTF-8', 'SJIS-win')); -define('P2_REGEX_KANJI', '/[\\x{4e00}-\\x{9fa0}]/u'); - -/** - *·²KȪ©¿«p³K\» - */ -/* -define('P2_REGEX_WAKATI', mb_convert_encoding('/(' . implode('|', array( - //'[ê-ê]+[-ñ]*', - //'[ê-ê]+', - '[êñOlÜZµªã\]+', - '[-ê]+', - '[-ñ][-ñ[`JK]*', - '[@-][@-[`JK]*', - //'[a-z][a-z_\\-]*', - //'[0-9][0-9.]*', - '[0-9a-z][0-9a-z_\\-]*', -)) . ')/u', 'UTF-8', 'SJIS-win')); -*/ -define('P2_REGEX_WAKATI', '/( -#[\\x{4e00}-\\x{9fa0}]+[\\x{3041}-\\x{3093}]*| -#[\\x{4e00}-\\x{9fa0}]+| -[\\x{4e00}\\x{4e8c}\\x{4e09}\\x{56db}\\x{4e94}\\x{516d}\\x{4e03}\\x{516b}\\x{4e5d}\\x{5341}]+| -[\\x{4e01}-\\x{9fa0}]+| -[\\x{3041}-\\x{3093}][\\x{3041}-\\x{3093}\\x{30fc}\\x{301c}\\x{309b}\\x{309c}]*| -[\\x{30a1}-\\x{30f6}][\\x{30a1}-\\x{30f6}\\x{30fc}\\x{301c}\\x{309b}\\x{309c}]*| -#[a-z][a-z_\\-]*| -#[0-9][0-9.]*| -[0-9a-z][0-9a-z_\\-]*)/ux'); - -/** - * UTF-8,NFDÌÐçªÈEJ^JiÌ÷¹E¼÷¹É}b`·é³K\» - */ -/* -define('P2_REGEX_NFD_KANA', - str_replace( - array('%u3099%', '%u309A%'), - array(pack('C*', 0xE3, 0x82, 0x99), pack('C*', 0xE3, 0x82, 0x9A)), - mb_convert_encoding( - '/([¤©-±³-»½-ÆÍ-ÙEJ-RT-\^-gn-zTR])%u3099%|([Í-Ùn-z])%u309A%/u', - 'UTF-8', - 'SJIS-win' - ) - ) -); -*/ -define('P2_REGEX_NFD_KANA', '/([\\x{3046}\\x{304b}-\\x{3053}\\x{3055}-\\x{305d}\\x{305f}-\\x{3068}\\x{306f}-\\x{307b}\\x{30a6}\\x{30ab}-\\x{30b3}\\x{30b5}-\\x{30bd}\\x{30bf}-\\x{30c8}\\x{30cf}-\\x{30db}\\x{309d}\\x{30fd}])\\x{3099}|([\\x{306f}-\\x{307b}\\x{30cf}-\\x{30db}])\\x{309a}/u'); - -// }}} -// {{{ p2h() - -/** -* htmlspecialchars($value, ENT_QUOTES) ÌV[gJbg -* -* @param string $str -* @param string $charset -* @param bool $double_encode -* @return string -*/ -function p2h($str, $charset = 'Shift_JIS', $double_encode = true) -{ - return htmlspecialchars($str, ENT_QUOTES, $charset, $double_encode); -} - -// }}} -// {{{ p2die() - -/** - * bZ[Wð\¦µÄI¹ - * wb_ªoͳêÄ¢éêA<body>ÜÅÍoÍÏÆ©È· - * - * I¹Xe[^XR[h2ÍP2CommandRunnerÉG[bZ[Wª - * HTMLÅ é±ÆðÊm·é½ß - * - * @param string $err G[Tv - * @param string $msg Ú×Èྠ- * @param bool $raw Ú×Èà¾ðGXP[v·é©Û© - * @return void - */ -function p2die($err = null, $msg = null, $raw = false) -{ - if (!defined('P2_CLI_RUN') && !headers_sent()) { - header('Expires: ' . http_date(0)); // útªß - header('Last-Modified: ' . http_date()); // íÉC³³êÄ¢é - header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 - header('Cache-Control: post-check=0, pre-check=0', false); - header('Pragma: no-cache'); // HTTP/1.0 - echo <<<EOH -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> -<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"> -{$GLOBALS['_conf']['extra_headers_ht']} -<title>rep2 error</title> -</head> -<body> -EOH; - } - - echo '<h3>rep2 error</h3>'; - - if ($err !== null) { - echo '<p><strong>', htmlspecialchars($err, ENT_QUOTES), '</strong></p>'; - } - - if ($msg !== null) { - if ($raw) { - echo $msg; - } else { - echo '<p>', nl2br(htmlspecialchars($msg, ENT_QUOTES)), '</p>'; - } - } - - if (true) { - echo '<pre><em>backtrace:</em>'; - - $p2_file_prefix = P2_BASE_DIR . DIRECTORY_SEPARATOR; - $p2_base_dir_len = strlen(P2_BASE_DIR); - $backtrace = debug_backtrace(); - $c = count($backtrace); - - foreach ($backtrace as $bt) { - echo "\n"; - - if (strpos($bt['file'], $p2_file_prefix) === 0) { - $filename = '.' . substr($bt['file'], $p2_base_dir_len); - } else { - $filename = '(external)' . DIRECTORY_SEPARATOR . basename($bt['file']); - } - printf(' % 2d. %s (line %d)', $c--, $filename, $bt['line']); - - if (array_key_exists('function', $bt) && $bt['function'] !== '' && $bt['function'] !== 'p2die') { - if (array_key_exists('class', $bt) && $bt['class'] !== '') { - printf(': %s%s%s()', - $bt['class'], - str_replace('>', '>', $bt['type']), - $bt['function'] - ); - } else { - printf(': %s()', $bt['function']); - } - } - } - - echo '</pre>'; - } - - if (!defined('P2_CLI_RUN')) { - echo '</body></html>'; - } - exit(2); -} - -// }}} -// {{{ http_date() - -if (!function_exists('http_date')) { - /** - * pecl_httpÌhttp_date()ÌPure PHPÅ - * - * @param int $timestamp - * @return string - */ - function http_date($timestamp = null) - { - if ($timestamp === null) { - //return str_replace('+0000', 'GMT', gmdate(DATE_RFC1123)); - return gmdate('D, d M Y H:i:s \\G\\M\\T'); - } - //return str_replace('+0000', 'GMT', gmdate(DATE_RFC1123, $timestamp)); - return gmdate('D, d M Y H:i:s \\G\\M\\T', $timestamp); - } -} - -// }}} -// {{{ ctype - -/** - * ctypeg£W [ÖÌPure PHPÅ (cntrl,graph,print,punct,spaceͤ) - */ -if (!extension_loaded('ctype')) { - function ctype_alnum($str) { return (bool)preg_match('/^[0-9A-Za-z]+$/', $str); } - function ctype_alpha($str) { return (bool)preg_match('/^[A-Za-z]+$/', $str); } - function ctype_digit($str) { return (bool)preg_match('/^[0-9]+$/', $str); } - function ctype_lower($str) { return (bool)preg_match('/^[a-z]+$/', $str); } - function ctype_upper($str) { return (bool)preg_match('/^[A-Z]+$/', $str); } - function ctype_xdigit($str) { return (bool)preg_match('/^[0-9A-Fa-f]+$/', $str); } -} - -// }}} -// {{{ p2_scan_nullbyte() - -/** - * NGXgp[^©çNULLoCgðoµ½çI¹·é - * array_walk_recursive() pR[obNÖ - * - * @param mixed $value - * @param mixed $key - * @return void - */ -function p2_scan_nullbyte($value, $key) -{ - if (is_string($value) && strpos($value, P2_NULLBYTE) !== false) { - p2die('NGXgp[^ÉNULLoCgªÜÜêĢܷB'); - } -} - -// }}} -// {{{ p2_scan_script_injection() - -/** - * ¶ÌÜÜHTMLÉßÜêé host, bbs, key, ls É - * HTMLÌÁ궪ÜÜêÄ¢½çI¹·é - * - * @param array $request - * @return void - */ -function p2_scan_script_injection($request) -{ - foreach (array('host', 'bbs', 'key', 'ls') as $key) { - if (array_key_exists($key, $request)) { - $value = $request[$key]; - if (htmlspecialchars($value, ENT_QUOTES) != $value) { - p2die('NGXgp[^És³È¶ª èÜ·B'); - } - } - } -} - -// }}} -// {{{ p2_print_memory_usage() - -/** - * ÌgpÊð\¦·é - * - * @return void - */ -function p2_print_memory_usage() -{ - if (function_exists('memory_get_usage')) { - $usage = memory_get_usage(); - } elseif (function_exists('xdebug_memory_usage')) { - $usage = xdebug_memory_usage(); - } else { - $usage = -1; - } - $kb = $usage / 1024; - $kb = number_format($kb, 2, '.', ''); - - echo 'Memory Usage: ' . $kb . 'KiB'; -} - -// }}} -// {{{ p2_realpath() - -/** - * ÀݵȢ(©àµêÈ¢)t@CÌâÎpXðæ¾·é - * - * @param string $path - * @return string - */ -function p2_realpath($path) -{ - if (file_exists($path)) { - return realpath($path); - } - if (!class_exists('File_Util', false)) { - require 'File/Util.php'; - } - return File_Util::realPath($path); -} - -// }}} -// {{{ p2_si2int() - -/** - * SIÚª«Â«Ìlð®ÉÏ··é - * - * @param numeric $num - * @param string $kmg - * @return int - * @throws OverflowException, UnderflowException - */ -function p2_si2int($num, $kmg) -{ - $real = p2_si2real($num, $kmg); - if ($real > PHP_INT_MAX) { - throw new OverflowException(sprintf('Integer overflow (%0.0f)', $real)); - //return PHP_INT_MAX; - } - if ($real < P2_INT_MIN) { - throw new UnderflowException(sprintf('Integer underflow (%0.0f)', $real)); - //return P2_INT_MIN; - } - return (int)$real; -} - -// }}} -// {{{ p2_si2real() - -/** - * SIÚª«Â«ÌlðÀÉÏ··é - * µ§ÉÍ1000{·é̪³µ¢ªA ¦Ä1024{·é - * - * @param numeric $num - * @param string $kmg - * @return float - */ -function p2_si2real($num, $kmg) -{ - $num = (float)$num; - switch ($kmg[0]) { - case 'G': case 'g': $num *= 1024; - case 'M': case 'm': $num *= 1024; - case 'M': case 'k': $num *= 1024; - } - return $num; -} - -// }}} -// {{{ p2_mb_basename() - -/** - * }`oCgÎÌbasename() - * - * @param string $path - * @param string $encoding - * @return string - */ -function p2_mb_basename($path, $encoding = 'SJIS-win') -{ - if (DIRECTORY_SEPARATOR != '/') { - $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); - } - if (!mb_substr_count($path, '/', $encoding)) { - return $path; - } - $len = mb_strlen($path, $encoding); - $pos = mb_strrpos($path, '/', $encoding); - return mb_substr($path, $pos + 1, $len - $pos, $encoding); -} - -// }}} -// {{{ p2_mb_ereg_count() - -/** - * }`oCg³K\»É}b`µ½ñðÔ· - * - * @param string $pattern - * @param string $string - * @param string $option - * @return int - */ -function p2_mb_ereg_count($pattern, $string, $option = null) -{ - if ($option === null) { - if (!mb_ereg_search_init($string, $pattern)) { - return false; - } - } else { - if (!mb_ereg_search_init($string, $pattern, $option)) { - return false; - } - } - - $i = 0; - - while (mb_ereg_search()) { - $i++; - } - - return $i; -} - -// }}} -// {{{ p2_set_filtering_word() - -/** - * tB^}b`OpÌO[oÏðÝè·é - * - * @param string $word - * @param string $method - * @return string - */ -function p2_set_filtering_word($word, $method = 'regex') -{ - $word_fm = StrCtl::wordForMatch($word, $method); - - if (strlen($word_fm) == 0) { - $word_fm = null; - $GLOBALS['word_fm'] = null; - $GLOBALS['words_fm'] = array(); - } elseif ($method == 'just' || $method == 'regex') { - $GLOBALS['word_fm'] = $word_fm; - $GLOBALS['words_fm'] = array($word_fm); - } elseif (P2_MBREGEX_AVAILABLE == 1) { - $GLOBALS['word_fm'] = mb_ereg_replace('\\s+', '|', $word_fm); - $GLOBALS['words_fm'] = mb_split('\\s+', $word_fm); - } else { - $GLOBALS['word_fm'] = preg_replace('/\\s+/', '|', $word_fm); - $GLOBALS['words_fm'] = preg_split('/\\s+/', $word_fm); - } - - return $word_fm; -} - -// }}} -// {{{ p2_normalize() - -if (extension_loaded('intl')) { - /** - * NormalizerNXðgÁ½³K»Ö - * - * @param string $str - * @return string - */ - function p2_normalize($str) - { - return strtolower(Normalizer::normalize(mb_convert_encoding( - $str, 'UTF-8', 'SJIS-win'), Normalizer::NFKC)); - } -} else { - /** - * ·²KȳK»Ö - * - * @param string $str - * @return string - */ - function p2_normalize($str) - { - return mb_strtolower(mb_convert_kana(mb_convert_encoding( - $str, 'UTF-8', 'SJIS-win'), 'KVas', 'UTF-8'), 'UTF-8'); - } -} - -// }}} -// {{{ p2_wakati() - -/** - * ·²KȪ©¿«Ö - * - * @param string $str - * @return array - */ -function p2_wakati($str) -{ - $str = preg_replace(P2_REGEX_WAKATI, '$0 ', p2_normalize($str)); - return preg_split('/\\s+/u', $str, -1, PREG_SPLIT_NO_EMPTY); -} - -// }}} -// {{{ p2_get_highlighting_regex - -/** - * p2_wakati()ÌÊAL[[hÌzñ©çnCCgp̳K\»ð¶¬·é - * - * @param array $words - * @return string - */ -function p2_get_highlighting_regex(array $words) -{ - $featured_words = array_filter($words, '_p2_get_highlighting_regex_filter'); - if (count($featured_words) == 0) { - $featured_words = $words; - } - //rsort($featured_words, SORT_STRING); - - $pattern = mb_convert_encoding(implode(' ', $featured_words), 'SJIS-win', 'UTF-8'); - return str_replace(' ', '|', StrCtl::wordForMatch($pattern, 'or')); - -} - -// }}} -// {{{ _p2_get_highlighting_regex_filter - -/** - * p2_get_highlighting_regex()©çÄÑo³êéR[obNÖ - * - * @param string $str - * @return bool - */ -function _p2_get_highlighting_regex_filter($str) -{ - if (preg_match(P2_REGEX_KANJI, $str)) { - return true; - } elseif (mb_strlen($str, 'UTF-8') > 1 && preg_match(P2_REGEX_WAKATI, $str)) { - return true; - } else { - return false; - } -} - -// }}} -// {{{ p2_combine_nfd_kana() - -/** - * Safari ©çAbv[h³ê½t@C¼Ì¶»¯ðâ³·éÖ - * ´¹+÷_E´¹+¼÷_ðê¶ÉÜÆßé (NFD ųK»³ê½ ©È ð NFC É·é) - * üoÍ̶R[hÍUTF-8 - * - * @param string $str - * @return string - */ -function p2_combine_nfd_kana($str) -{ - if (extension_loaded('intl')) { - return Normalizer::normalize($str, Normalizer::NFC); - } - return preg_replace_callback(P2_REGEX_NFD_KANA, '_p2_combine_nfd_kana', $str); -} - -// }}} -// {{{ _p2_combine_nfd_kana() - -/** - * p2_combine_nfd_kana()©çÄÑo³êéR[obNÖ - * - * @param array $m - * @return string - */ -function _p2_combine_nfd_kana($m) -{ - if ($m[1]) { - $C = unpack('C*', $m[1]); - $C[3] += 1; - } elseif ($m[2]) { - $C = unpack('C*', $m[2]); - $C[3] += 2; - } else { - return $m[0]; // è¦È¢ - } - - return pack('C*', $C[1], $C[2], $C[3]); -} - -// }}} -// {{{ p2_correct_css_fonts() - -/** - * X^CV[gÌtHgwèð²®·é - * - * @param string|array $fonts - * @return string - */ -function p2_correct_css_fontfamily($fonts) -{ - if (is_string($fonts)) { - $fonts = preg_split('/(["\'])?\\s*,\\s*(?(1)\\1)/', trim($fonts, " \t\"'")); - } elseif (!is_array($fonts)) { - return ''; - } - $fonts = '"' . implode('","', $fonts) . '"'; - $fonts = preg_replace('/"(serif|sans-serif|cursive|fantasy|monospace)"/', '\\1', $fonts); - return trim($fonts, '"'); -} - -// }}} -// {{{ p2_correct_css_color() - -/** - * X^CV[gÌFwèð²®·é - * - * @param string $color - * @return string - */ -function p2_correct_css_color($color) -{ - return preg_replace('/^#([0-9A-F])([0-9A-F])([0-9A-F])$/i', '#$1$1$2$2$3$3', $color); -} - -// }}} -// {{{ p2_escape_css_url() - -/** - * X^CV[gÌURLðGXP[v·é - * - * CSSÅÁÉÓ¡Ì ég[NÅ éó¶AVONH[gA - * _uNH[gAÊAobNXbV ðURLGR[h·é - * - * @param string $url - * @return string - */ -function p2_escape_css_url($url) -{ - if (strpos($url, chr(0)) !== false) { - return ''; - } - return str_replace(array( "\t", "\n", "\r", ' ', '"', "'", '(', ')', '\\'), - array('%09', '%0A', '%0D', '%20', '%22', '%27', '%28', '%29', '%5C'), - $url); -} - -// }}} - -/* - * 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/setup.funcs.php =================================================================== --- p2ex/trunk/lib/setup.funcs.php (rev 0) +++ p2ex/trunk/lib/setup.funcs.php 2010-01-13 23:31:20 UTC (rev 778) @@ -0,0 +1,204 @@ +<?php +/** + * rep2expack - ZbgAbvpÖQ + */ + +// {{{ p2_check_environment() + +/** + * ®ì«ðmF·é + * + * @return bool + */ +function p2_check_environment($check_recommended) +{ + global $_info_msg_ht; + + include P2_CONF_DIR . '/setup_info.php'; + + $php_version = phpversion(); + + if (version_compare($php_version, '5.3.0-dev', '>=')) { + $required_version = $p2_required_version_5_3; + $recommended_version = $p2_recommended_version_5_3; + } else { + $required_version = $p2_required_version_5_2; + $recommended_version = $p2_recommended_version_5_2; + } + + // PHPÌo[W + if (version_compare($php_version, $required_version, '<')) { + p2die("PHP {$required_version} ¢ÅÍg¦Ü¹ñB"); + } + + // K{g£W [ + foreach ($p2_required_extensions as $ext) { + if (!extension_loaded($ext)) { + p2die("{$ext} g£W [ª[h³êĢܹñB"); + } + } + + // Lø¾Æ®ìµÈ¢php.inifBNeBu + foreach ($p2_incompatible_ini_directives as $directive) { + if (ini_get($directive)) { + p2die("{$directive} ª On Å·B", + "php.ini Å {$directive} ð Off ɵľ³¢B"); + } + } + + // eAccelerator + if (extension_loaded('eaccelerator') && + version_compare(EACCELERATOR_VERSION, '0.9.5.2', '<')) + { + $err = 'eAcceleratorðXVµÄ¾³¢B'; + $ev = EACCELERATOR_VERSION; + $msg = <<<EOP +<p>PHP 5.2ÅáOðߨūȢâèÌ éeAccelerator ({$ev})ªCXg[³êĢܷB<br> +eAcceleratorð³øÉ·é©A±ÌâèªC³³ê½eAccelerator 0.9.5.2È~ðgpµÄ¾³¢B<br> +<a href="http://eaccelerator.net/">http://eaccelerator.net/</a></p> +EOP; + p2die($err, $msg, true); + } + + // §o[W + if ($check_recommended) { + if (version_compare($php_version, $recommended_version, '<')) { + // title.php ÌÝbZ[Wð\¦ + if (basename($_SERVER['PHP_SELF'], '.php') == 'title') { + $_info_msg_ht .= <<<EOP +<p><strong>§o[WæèâPHPÅ®ìµÄ¢Ü·B</strong> +<em>(PHP {$php_version})</em><br> +PHP {$recommended_version} È~ÉAbvf[g·é±Æ𨷷ߵܷB</p> +<p style="font-size:smaller">±ÌbZ[Wð\¦µÈ¢æ¤É·éÉÍ +<em>{\$rep2_directory}</em>/conf/conf.inc.php Ì {$check_recommended} sÚA<br> +<samp>p2_check_environment(<strong>__LINE__</strong>);</samp> ð +<samp>p2_check_environment(<strong>false</strong>);</samp> É«·¦Ä¾³¢B</p> +EOP; + } + return false; + } + } + + return true; +} + +// }}} +// {{{ p2_check_migration() + +/** + * }CO[VÌKvª é©Ç¤©ð`FbN + * + * @param string $config_version + * @return array + */ +function p2_check_migration($config_version) +{ + include P2_CONF_DIR . '/setup_info.php'; + + $migrators = array(); + $found = false; + + foreach ($p2_changed_versions as $version) { + if ($found || version_compare($config_version, $version, '<')) { + $found = true; + $migrator_name = str_replace('.', '_', $version); + $migrator_func = 'p2_migrate_' . $migrator_name; + $migrator_file = '/migrators/' . $migrator_name . '.php'; + $migrators[$migrator_func] = $migrator_file; + } + } + + if ($found) { + return $migrators; + } else { + return null; + } +} + +// }}} +// {{{ p2_invoke_migrators() + +/** + * }CO[VðÀs + * + * @param array $migrators }CO[VÖÌXg + * @param array $user_config â[U[Ýè + * @return array Vµ¢[U[Ýè + */ +function p2_invoke_migrators(array $migrators, array $user_config) +{ + global $_conf; + + foreach ($migrators as $migrator_func => $migrator_file) { + include P2_LIB_DIR . $migrator_file; + $user_config = $migrator_func($_conf, $user_config); + } + + return $user_config; +} + +// }}} +// {{{ p2_load_class() + +/** + * NX[_[ + * + * @string $name + * @return void + */ +function p2_load_class($name) +{ + if (preg_match('/^(?: + BbsMap | + BrdCtl | + BrdMenu\\w* | + DataPhp | + FavSetManager | + FileCtl | + HostCheck | + Login | + NgAbornCtl | + P2\\w+ | + PresetManager | + ResHist | + Session | + SettingTxt | + ShowBrdMenu\\w* | + ShowThread\\w* | + StrCtl | + StrSjis | + SubjectTxt | + Thread\\w* | + Wap\\w+ + )$/x', $name)) + { + if ($name == 'P2Lock') { + include P2_LIB_DIR . '/FileCtl.php'; + } elseif ($name == 'ResArticle') { + include P2_LIB_DIR . '/ResHist.php'; + } elseif (strncmp($name, 'Wap', 3) === 0) { + include P2_LIB_DIR . '/Wap.php'; + } elseif (strncmp($name, 'P2Http', 6) === 0) { + include P2_LIB_DIR . '/P2HttpExt.php'; + } elseif (strncmp($name, 'BrdMenu', 7) === 0) { + include P2_LIB_DIR . '/BrdMenu.php'; + } else { + include P2_LIB_DIR . '/' . $name . '.php'; + } + } elseif (preg_match('/^\\w+DataStore$/', $name)) { + include P2_LIB_DIR . '/P2DataStore/' . $name . '.php'; + } +} + +// }}} + +/* + * 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: