function do_titleindex($formatter, $options) { global $DBInfo, $Config; if (isset($options['q'])) { if (!$options['q']) { print ''; return; } #if (!$options['q']) { print "<ul></ul>"; return; } $limit = isset($options['limit']) ? intval($options['limit']) : 100; $limit = min(100, $limit); $val = ''; $rule = ''; while ($DBInfo->use_hangul_search) { include_once "lib/unicode.php"; $val = $options['q']; if (strtoupper($DBInfo->charset) != 'UTF-8' and function_exists('iconv')) { $val = iconv($DBInfo->charset, 'UTF-8', $options['q']); } if (!$val) { break; } $rule = utf8_hangul_getSearchRule($val); $test = @preg_match("/^{$rule}/", ''); if ($test === false) { $rule = $options['q']; } break; } if (!$rule) { $rule = trim($options['q']); } $test = validate_needle('^' . $rule); if (!$test) { $rule = preg_quote($rule); } $indexer = $DBInfo->lazyLoad('titleindexer'); $pages = $indexer->getLikePages($rule, $limit); sort($pages); //array_unshift($pages, $options['q']); $ct = "Content-Type: text/plain"; $ct .= '; charset=' . $DBInfo->charset; header($ct); $maxage = 60 * 10; header('Cache-Control: public, max-age=' . $maxage . ',s-maxage=' . $maxage . ', post-check=0, pre-check=0'); if ($pages) { $ret = implode("\n", $pages); #$ret= "<ul>\n<li>".implode("</li>\n<li>",$pages)."</li>\n</ul>\n"; } else { #$ret= "<ul>\n<li>".$options['q']."</li></ul>"; $ret = ''; #$ret= "<ul>\n</ul>"; } if (strtoupper($DBInfo->charset) != 'UTF-8' and function_exists('iconv')) { $val = iconv('UTF-8', $DBInfo->charset, $ret); if ($val) { print $val; return; } } #print 'x'.$rule; print $ret; return; } else { if ($options['sec'] == '') { if (!empty($DBInfo->no_all_titleindex)) { return; } $tc = new Cache_text('persist', array('depth' => 0)); // all pages $mtime = $DBInfo->mtime(); $lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', $mtime); $etag = md5($mtime . $DBInfo->etag_seed); $options['etag'] = $etag; $options['mtime'] = $mtime; // set the s-maxage for proxy $date = gmdate('Y-m-d-H-i-s', $mtime); $proxy_maxage = !empty($Config['proxy_maxage']) ? ', s-maxage=' . $Config['proxy_maxage'] : ''; $header[] = 'Content-Type: text/plain'; $header[] = 'Cache-Control: public' . $proxy_maxage . ', max-age=0, must-revalidate'; $need = http_need_cond_request($mtime, $lastmod, $etag); if (!$need) { $header[] = 'HTTP/1.0 304 Not Modified'; } else { $header[] = 'Content-Disposition: attachment; filename="titleindex-' . $date . '.txt"'; } $formatter->send_header($header, $options); if (!$need) { @ob_end_clean(); return; } if (($out = $tc->fetch('titleindex', 0, array('print' => 1))) === false) { $args = array('all' => 1); $pages = $DBInfo->getPageLists($args); sort($pages); $out = join("\n", $pages); $ttl = !empty($DBInfo->titleindex_ttl) ? $DBInfo->titleindex_ttl : 60 * 60 * 24; $tc->update('titleindex', $out, $ttl); echo $out; } return; } } $formatter->send_header("", $options); $formatter->send_title("", "", $options); print macro_TitleIndex($formatter, $options['sec'], $options); $formatter->send_footer($args, $options); }
function do_fastsearch($formatter, $options) { global $DBInfo; $default_limit = isset($DBInfo->fastsearch_limit) ? $DBInfo->fastsearch_limit : 30; $rule = ''; if ($options['action'] == 'titleindex' || isset($_GET['q'][0])) { $options['value'] = $_GET['q']; $options['arena'] = 'titlesearch'; while (!empty($DBInfo->use_hangul_search)) { include_once "lib/unicode.php"; $val = $_GET['q']; if (strtoupper($DBInfo->charset) != 'UTF-8' and function_exists('iconv')) { $val = iconv($DBInfo->charset, 'UTF-8', $val); } if (!$val) { break; } $rule = utf8_hangul_getSearchRule($val); $test = @preg_match("/^{$rule}/", ''); if ($test === false) { $rule = $options['value']; } break; } if (!$rule) { $rule = trim($options['value']); } } $ret = $options; $extra = ''; if (!empty($options['backlinks']) || $options['arena'] == 'pagelinks') { $title = sprintf(_("BackLinks search for \"%s\""), $options['value']); $extra = '&arena=pagelinks'; } else { if (!empty($options['titlesearch']) || $options['arena'] == 'titlesearch') { $title = sprintf(_("Title search for \"%s\""), $options['value']); if (!empty($options['titlesearch'])) { $ret['arena'] = 'titlesearch'; } $extra = '&arena=titlesearch'; } else { $title = sprintf(_("Full text search for \"%s\""), $options['value']); } } if ($rule) { $out = macro_FastSearch($formatter, $rule, $ret); } else { $out = macro_FastSearch($formatter, $options['value'], $ret); } if (isset($_GET['q'][0])) { header("Content-Type: text/plain"); print join("\n", $out); return; } $options['msg'] = !empty($ret['msg']) ? $ret['msg'] : ''; $formatter->send_header("", $options); $formatter->send_title($title, $formatter->link_url("FindPage"), $options); if (!empty($ret['form'])) { print $ret['form']; } print $out; $context = !empty($options['context']) ? $options['context'] : 0; $limit = isset($options['limit'][0]) ? $options['limit'] : $default_limit; if ($context) { $extra = '&context=' . $context; } if ($options['value']) { printf(_("Found %s matching %s out of %s total pages") . "<br />\n", $ret['hit'], $ret['hit'] == 1 ? _("page") : _("pages"), $ret['all']); if (!empty($limit) and $ret['hit'] > $limit) { echo $formatter->link_to("?action=fastsearch&value={$options['value']}&limit=0" . $extra, sprintf(_("Show all %d results"), $ret['hit'])) . "<br />\n"; } } $args['noaction'] = 1; $formatter->send_footer($args, $options); }