X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Ffunc.php;h=c3bcf4969c5ee900e237ad71cedc80416d846fd8;hb=48b6d10fa3e8c7d525cd5c7ae467ef35c88e83fe;hp=a605143abefee86f16007ed4763afcc076ac1a84;hpb=dd11c00d6224f9f5c0faad0f9ead4470906532ff;p=pukiwiki%2Fpukiwiki.git diff --git a/lib/func.php b/lib/func.php index a605143..c3bcf49 100644 --- a/lib/func.php +++ b/lib/func.php @@ -1,8 +1,8 @@ $value) + $keys[$key] = '/' . $value . '/S'; - $_pages = get_existpages(); - $pages = array(); + $pages = get_existpages(); - $non_list_pattern = '/' . $non_list . '/'; - foreach ($_pages as $page) { - if ($page == $whatsnew || (! $search_non_list && preg_match($non_list_pattern, $page))) - continue; + // Avoid + if ($base != '') { + $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages); + } + if (! $search_non_list) { + $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages)); + } + $pages = array_flip($pages); + unset($pages[$whatsnew]); + + $count = count($pages); + foreach (array_keys($pages) as $page) { + $b_match = FALSE; - // ¸¡º÷Âоݥڡ¼¥¸¤ÎÀ©¸Â¤ò¤«¤±¤ë¤«¤É¤¦¤« (¥Ú¡¼¥¸Ì¾¤ÏÀ©¸Â³°) + // Search for page name + if (! $non_format) { + foreach ($keys as $key) { + $b_match = preg_match($key, $page); + if ($b_type xor $b_match) break; // OR + } + if ($b_match) continue; + } + + // Search auth for page contents if ($search_auth && ! check_readable($page, false, false)) { - $source = get_source(); // Empty - } else { - $source = get_source($page); + unset($pages[$page]); + --$count; } - if (! $non_format) - array_unshift($source, $page); // ¥Ú¡¼¥¸Ì¾¤â¸¡º÷ÂÐ¾Ý¤Ë - $b_match = FALSE; + // Search for page contents foreach ($keys as $key) { - $tmp = preg_grep('/' . $key . '/', $source); - $b_match = ! empty($tmp); - if ($b_match xor $b_type) break; + $b_match = preg_match($key, get_source($page, TRUE, TRUE)); + if ($b_type xor $b_match) break; // OR } - if ($b_match) $pages[$page] = get_filetime($page); + if ($b_match) continue; + + unset($pages[$page]); // Miss } if ($non_format) return array_keys($pages); @@ -225,11 +268,12 @@ function do_search($word, $type = 'AND', $non_format = FALSE) return str_replace('$1', $s_word, $_msg_notfoundresult); ksort($pages); + $retval = '' . "\n"; $retval .= str_replace('$1', $s_word, str_replace('$2', count($pages), - str_replace('$3', count($_pages), $b_type ? $_msg_andresult : $_msg_orresult))); + str_replace('$3', $count, $b_type ? $_msg_andresult : $_msg_orresult))); return $retval; } @@ -738,19 +782,9 @@ if (! function_exists('md5_file')) { // (PHP 4 >= 4.3.0, PHP5) if (! function_exists('sha1')) { if (extension_loaded('mhash')) { - function sha1($str, $raw_output = FALSE) - { - if ($raw_output) { - // PHP 5.0.0 or lator only :) - return mhash(MHASH_SHA1, $str); - } else { - return bin2hex(mhash(MHASH_SHA1, $str)); - } - } - } else { - function sha1($str, $raw_output = FALSE) + function sha1($str) { - die('Function sha1() not found and extension \'mhash\' not exists'); + return bin2hex(mhash(MHASH_SHA1, $str)); } } }