OSDN Git Service

Cleanup. Some Japanese => English
authorhenoheno <henoheno>
Sun, 27 Mar 2005 10:23:06 +0000 (19:23 +0900)
committerhenoheno <henoheno>
Sun, 27 Mar 2005 10:23:06 +0000 (19:23 +0900)
lib/func.php

index 2381a82..dc84cfe 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: func.php,v 1.34 2005/03/27 08:21:14 henoheno Exp $
+// $Id: func.php,v 1.35 2005/03/27 10:23:06 henoheno Exp $
 //
 // General functions
 
@@ -87,7 +87,7 @@ function is_freeze($page, $clearcache = FALSE)
        }
 }
 
-// ¼«Æ°¥Æ¥ó¥×¥ì¡¼¥È
+// Auto template
 function auto_template($page)
 {
        global $auto_template_func, $auto_template_rules;
@@ -121,53 +121,57 @@ function auto_template($page)
        return $body;
 }
 
-// ¸¡º÷¸ì¤òŸ³«¤¹¤ë
-function get_search_words($words, $special = FALSE)
+// Expand search words
+function get_search_words($words, $do_escape = FALSE)
 {
        $retval = array();
 
-       // Perl¥á¥â - Àµ¤·¤¯¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á¤µ¤»¤ë
-       // http://www.din.or.jp/~ohzaki/perl.htm#JP_Match
-
-       $eucpre = $eucpost = '';
+       $pre = $post = '';
        if (SOURCE_ENCODING == 'EUC-JP') {
-               $eucpre = '(?<!\x8F)';
-               // # JIS X 0208 ¤¬ 0ʸ»ú°Ê¾å³¤¤¤Æ # ASCII, SS2, SS3 ¤Þ¤¿¤Ï½ªÃ¼
-               $eucpost = '(?=(?:[\xA1-\xFE][\xA1-\xFE])*(?:[\x00-\x7F\x8E\x8F]|\z))';
+               // Perl memo - Correct pattern-matching with EUC-JP
+               // http://www.din.or.jp/~ohzaki/perl.htm#JP_Match (Japanese)
+               $pre  = '(?<!\x8F)';
+               $post = '(?=(?:[\xA1-\xFE][\xA1-\xFE])*' . // JIS X 0208
+                       '(?:[\x00-\x7F\x8E\x8F]|\z))';     // ASCII, SS2, SS3, or the last
        }
+
+       // function: just preg_quote()
        $quote_func = create_function('$str', 'return preg_quote($str, \'/\');');
 
-       // LANG == 'ja'¤Ç¡¢mb_convert_kana¤¬»È¤¨¤ë¾ì¹ç¤Ïmb_convert_kana¤ò»ÈÍÑ
+       // function: mb_convert_kana() or nothing
        $convert_kana = create_function('$str, $option',
                (LANG == 'ja' && function_exists('mb_convert_kana')) ?
                        'return mb_convert_kana($str, $option);' : 'return $str;');
 
        foreach ($words as $word) {
-               // ±Ñ¿ô»ú¤ÏȾ³Ñ,¥«¥¿¥«¥Ê¤ÏÁ´³Ñ,¤Ò¤é¤¬¤Ê¤Ï¥«¥¿¥«¥Ê¤Ë
+               // 'a': Zenkaku-Alphabet to Hankaku-Alphabet
+               // 'K': Hankaku-Katakana to Zenkaku-Katakana
+               // 'C': Zenkaku-Hiragana to Zenkaku-Katakana
+               // 'V': Merge 'A character and A voiced sound symbol' to 'A character with the symbol'
                $word_zk = $convert_kana($word, 'aKCV');
-               $chars = array();
-               for ($pos = 0; $pos < mb_strlen($word_zk); $pos++) {
+               $len     = mb_strlen($word_zk);
+               $chars   = array();
+               for ($pos = 0; $pos < $len; $pos++) {
                        $char = mb_substr($word_zk, $pos, 1);
-                       // $special : htmlspecialchars()¤òÄ̤¹¤«
-                       $arr = array($quote_func($special ? htmlspecialchars($char) : $char));
+                       $arr = array($quote_func($do_escape ? htmlspecialchars($char) : $char));
                        if (strlen($char) == 1) {
-                               // ±Ñ¿ô»ú
+                               // Single-byte characters
                                foreach (array(strtoupper($char), strtolower($char)) as $_char) {
-                                       if ($char != '&')
-                                               $arr[] = $quote_func($_char);
+                                       if ($char != '&') $arr[] = $quote_func($_char);
                                        $ord = ord($_char);
-                                       $arr[] = sprintf('&#(?:%d|x%x);', $ord, $ord); // ¼ÂÂλ²¾È
-                                       $arr[] = $quote_func($convert_kana($_char, 'A')); // Á´³Ñ
+                                       $arr[] = sprintf('&#(?:%d|x%x);', $ord, $ord);    // Entity references
+                                       $arr[] = $quote_func($convert_kana($_char, 'A')); // Zenkaku-Alphabet
                                }
                        } else {
-                               // ¥Þ¥ë¥Á¥Ð¥¤¥Èʸ»ú
-                               $arr[] = $quote_func($convert_kana($char, 'c')); // ¤Ò¤é¤¬¤Ê
-                               $arr[] = $quote_func($convert_kana($char, 'k')); // È¾³Ñ¥«¥¿¥«¥Ê
+                               // Multi-byte characters
+                               $arr[] = $quote_func($convert_kana($char, 'c')); // Zenkaku-Katakana to Zenkaku-Hiragana
+                               $arr[] = $quote_func($convert_kana($char, 'k')); // Zenkaku-Katakana to Hankaku-Katakana
                        }
                        $chars[] = '(?:' . join('|', array_unique($arr)) . ')';
                }
-               $retval[$word] = $eucpre.join('', $chars) . $eucpost;
+               $retval[$word] = $pre . join('', $chars) . $post;
        }
+
        return $retval;
 }
 
@@ -193,7 +197,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE)
 
                // ¸¡º÷Âоݥڡ¼¥¸¤ÎÀ©¸Â¤ò¤«¤±¤ë¤«¤É¤¦¤« (¥Ú¡¼¥¸Ì¾¤ÏÀ©¸Â³°)
                if ($search_auth && ! check_readable($page, false, false)) {
-                       $source = get_source(); // ¸¡º÷Âоݥڡ¼¥¸ÆâÍƤò¶õ¤Ë¡£
+                       $source = get_source(); // Empty
                } else {
                        $source = get_source($page);
                }
@@ -233,14 +237,14 @@ function do_search($word, $type = 'AND', $non_format = FALSE)
        return $retval;
 }
 
-// ¥×¥í¥°¥é¥à¤Ø¤Î°ú¿ô¤Î¥Á¥§¥Ã¥¯
+// Argument check for program
 function arg_check($str)
 {
        global $vars;
        return isset($vars['cmd']) && (strpos($vars['cmd'], $str) === 0);
 }
 
-// ¥Ú¡¼¥¸Ì¾¤Î¥¨¥ó¥³¡¼¥É
+// Encode page-name
 function encode($key)
 {
        return ($key == '') ? '' : strtoupper(bin2hex($key));
@@ -248,7 +252,7 @@ function encode($key)
        // But PHP 4.3.10 says 'Warning: unpack(): Type H: outside of string in ...'
 }
 
-// ¥Ú¡¼¥¸Ì¾¤Î¥Ç¥³¡¼¥É
+// Decode page name
 function decode($key)
 {
        // preg_match()       = Warning: pack(): Type H: illegal hex digit ...
@@ -257,7 +261,7 @@ function decode($key)
                substr(pack('H*', '20202020' . $key), 4) : $key;
 }
 
-// [[ ]] ¤ò¼è¤ê½ü¤¯
+// Remove [[ ]] (brackets)
 function strip_bracket($str)
 {
        $match = array();
@@ -268,7 +272,7 @@ function strip_bracket($str)
        }
 }
 
-// ¥Ú¡¼¥¸°ìÍ÷¤ÎºîÀ®
+// Create list of pages
 function page_list($pages, $cmd = 'read', $withfilename = FALSE)
 {
        global $script, $list_index;
@@ -402,14 +406,14 @@ EOD;
        exit;
 }
 
-// ¸½ºß»þ¹ï¤ò¥Þ¥¤¥¯¥íÉäǼèÆÀ
+// Have the time (as microtime)
 function getmicrotime()
 {
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$sec + (float)$usec);
 }
 
-// Æü»þ¤òÆÀ¤ë
+// Get the date
 function get_date($format, $timestamp = NULL)
 {
        $format = preg_replace('/(?<!\\\)T/',
@@ -420,7 +424,7 @@ function get_date($format, $timestamp = NULL)
        return date($format, $time);
 }
 
-// Æü»þʸ»úÎó¤òºî¤ë
+// Format date string
 function format_date($val, $paren = FALSE)
 {
        global $date_format, $time_format, $weeklabels;
@@ -434,7 +438,7 @@ function format_date($val, $paren = FALSE)
        return $paren ? '(' . $date . ')' : $date;
 }
 
-// ·Ð²á»þ¹ïʸ»úÎó¤òºî¤ë
+// Get short string of the passage, 'N seconds/minutes/hours/days/years ago'
 function get_passage($time, $paren = TRUE)
 {
        static $units = array('m'=>60, 'h'=>24, 'd'=>1);
@@ -457,8 +461,7 @@ function drop_submit($str)
                '<input$1type="hidden"', $str);
 }
 
-// AutoLink¤Î¥Ñ¥¿¡¼¥ó¤òÀ¸À®¤¹¤ë
-// thx for hirofummy
+// Generate AutoLink patterns (thx to hirofummy)
 function get_autolink_pattern(& $pages)
 {
        global $WikiName, $autolink, $nowikiname;
@@ -470,11 +473,10 @@ function get_autolink_pattern(& $pages)
        unset($config);
        $auto_pages = array_merge($ignorepages, $forceignorepages);
 
-       foreach ($pages as $page) {
+       foreach ($pages as $page)
                if (preg_match('/^' . $WikiName . '$/', $page) ?
                    $nowikiname : strlen($page) >= $autolink)
                        $auto_pages[] = $page;
-       }
 
        if (empty($auto_pages)) {
                $result = $result_a = $nowikiname ? '(?!)' : $WikiName;
@@ -500,12 +502,11 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
        $x = (mb_strlen($pages[$start]) <= $pos);
        if ($x) ++$start;
 
-       for ($i = $start; $i < $end; $i = $j)
-       {
+       for ($i = $start; $i < $end; $i = $j) {
                $char = mb_substr($pages[$i], $pos, 1);
-               for ($j = $i; $j < $end; $j++) {
+               for ($j = $i; $j < $end; $j++)
                        if (mb_substr($pages[$j], $pos, 1) != $char) break;
-               }
+
                if ($i != $start) $result .= '|';
                if ($i >= ($j - 1)) {
                        $result .= str_replace(' ', '\\ ', preg_quote(mb_substr($pages[$i], $pos), '/'));
@@ -521,7 +522,7 @@ function get_autolink_pattern_sub(& $pages, $start, $end, $pos)
        return $result;
 }
 
-// pukiwiki.php¥¹¥¯¥ê¥×¥È¤Îabsolute-uri¤òÀ¸À®
+// Get absolute-URI of this script
 function get_script_uri($init_uri = '')
 {
        global $script_directory_index;
@@ -577,16 +578,15 @@ function get_script_uri($init_uri = '')
        return $script;
 }
 
-/*
-ÊÑ¿ôÆâ¤Înull(\0)¥Ð¥¤¥È¤òºï½ü¤¹¤ë
-PHP¤Ïfopen("hoge.php\0.txt")¤Ç"hoge.php"¤ò³«¤¤¤Æ¤·¤Þ¤¦¤Ê¤É¤ÎÌäÂꤢ¤ê
-
-http://ns1.php.gr.jp/pipermail/php-users/2003-January/012742.html
-[PHP-users 12736] null byte attack
-
-2003-05-16: magic quotes gpc¤ÎÉü¸µ½èÍý¤òÅý¹ç
-2003-05-21: Ï¢ÁÛÇÛÎó¤Î¥­¡¼¤Ïbinary safe
-*/
+// Remove null(\0) bytes from variables
+//
+// NOTE: PHP had vulnerabilities that opens "hoge.php" via fopen("hoge.php\0.txt") etc.
+// [PHP-users 12736] null byte attack
+// http://ns1.php.gr.jp/pipermail/php-users/2003-January/012742.html
+//
+// 2003-05-16: magic quotes gpc¤ÎÉü¸µ½èÍý¤òÅý¹ç
+// 2003-05-21: Ï¢ÁÛÇÛÎó¤Î¥­¡¼¤Ïbinary safe
+//
 function input_filter($param)
 {
        static $magic_quotes_gpc = NULL;
@@ -607,7 +607,7 @@ function sanitize($param) {
        return input_filter($param);
 }
 
-// CSV·Á¼°¤Îʸ»úÎó¤òÇÛÎó¤Ë
+// Explode Comma-Separated Values to an array
 function csv_explode($separator, $string)
 {
        $retval = $matches = array();