コード例 #1
0
ファイル: FullSearch.php プロジェクト: reviforks/moniwiki
function do_fullsearch($formatter, $options)
{
    global $Config;
    $ret =& $options;
    $qnext = '';
    if (!empty($options['offset']) and is_numeric($options['offset'])) {
        if ($options['offset'] > 0) {
            $qnext = '&offset=' . $options['offset'];
        }
    }
    $options['value'] = _stripslashes($options['value']);
    if (!isset($options['value'][0])) {
        $options['value'] = $formatter->page->name;
    }
    if (!empty($options['backlinks'])) {
        $title = sprintf(_("BackLinks search for \"%s\""), $options['value']);
    } else {
        if (!empty($options['keywords'])) {
            $title = sprintf(_("KeyWords search for \"%s\""), $options['value']);
        } else {
            $title = sprintf(_("Full text search for \"%s\""), $options['value']);
        }
    }
    if (!empty($options['backlinks'])) {
        $options['.title'] = sprintf(_("BackLinks of %s"), _html_escape($options['value']));
    }
    $out = macro_FullSearch($formatter, $options['value'], $ret);
    $options['msg'] = !empty($ret['msg']) ? $ret['msg'] : '';
    $options['msgtype'] = 'search';
    $formatter->send_header("", $options);
    $formatter->send_title($title, $formatter->link_url("FindPage"), $options);
    if (!empty($ret['form'])) {
        print $ret['form'];
    }
    print $out;
    $qext = '';
    if (!empty($options['backlinks'])) {
        $qext = '&backlinks=1';
    } else {
        if (!empty($options['keywords'])) {
            $qext = '&keywords=1';
        }
    }
    $offset = '';
    if (isset($options['value'][0])) {
        $val = _html_escape($options['value']);
        printf(_("Found %s matching %s out of %s total pages"), $ret['hit'], $ret['hit'] == 1 ? _("page") : _("pages"), $ret['all']);
        if (!empty($ret['next'])) {
            $limit = isset($DBInfo->fullsearch_page_limit[0]) ? $DBInfo->fullsearch_page_limit : 5000;
            // 5000 pages
            if (isset($ret['searched'])) {
                $limit = $ret['searched'];
            }
            printf(_(" (%s pages are searched)") . '<br />', $limit);
        } else {
            echo '<br />';
        }
        if (empty($ret['context'])) {
            $tag = $formatter->link_to("?action=fullsearch&amp;value={$val}{$qext}{$qnext}&amp;context=20", _("Show Context."));
            print $tag . '<br />';
        }
        if ($options['id'] != 'Anonymous') {
            if (!empty($ret['next']) and $ret['next'] < $ret['all']) {
                $qoff = '&amp;offset=' . $ret['next'];
                $tag = $formatter->link_to("?action=fullsearch{$qext}&amp;value={$val}{$qoff}", _("Search next results"));
                echo $tag;
            }
            if (empty($options['backlinks']) and empty($options['keywords']) or !empty($Config['show_refresh'])) {
                $tag = $formatter->link_to("?action=fullsearch{$qext}&amp;value={$val}{$qnext}&amp;refresh=1", _("Refresh"));
                printf(_(" (%s search results)"), $tag);
            }
        }
    }
    $value = _urlencode($options['value']);
    print '<h2>' . sprintf(_("You can also click %s to search title.\n"), $formatter->link_to("?action=titlesearch&amp;value={$value}", _("here"))) . "</h2>\n";
    $args['noaction'] = 1;
    $formatter->send_footer($args, $options);
}
コード例 #2
0
ファイル: backlinks.php プロジェクト: sedrion/moniwiki
function macro_BackLinks($formatter, $value = '', $params = array())
{
    global $Config;
    // setup dynamic macro
    if ($formatter->_macrocache and empty($params['call'])) {
        return $formatter->macro_cache_repl('BackLinks', $value);
    }
    if (empty($params['call'])) {
        $formatter->_dynamic_macros['@BackLinks'] = 1;
    }
    if (!isset($value[0]) || $value === true) {
        $value = $formatter->page->name;
    }
    $params['backlinks'] = 1;
    $params['call'] = 1;
    $hits = macro_FullSearch($formatter, $value, $params);
    // $hits is sorted array
    $out = '';
    $title = '';
    // check the internal category parameter
    if (!isset($params['.category'])) {
        if (isset($Config['category_regex'][0]) && preg_match('@' . $Config['category_regex'] . '@', $value, $m, PREG_OFFSET_CAPTURE)) {
            if (isset($m[1])) {
                $params['.category'] = $m[1];
            } else {
                $params['.category'] = substr($value, strlen($m[0][0]));
            }
            // FIXME
        }
    }
    if (isset($params['.category'][0])) {
        // check subcategories
        $category = $params['.category'];
        $title = '<h2>' . sprintf(_("Pages in category \"%s\"."), _html_escape($category)) . '</h2>';
        $cats = array();
        foreach ($hits as $p => $c) {
            if (preg_match('@' . $Config['category_regex'] . '@', $p, $m, PREG_OFFSET_CAPTURE)) {
                if (isset($m[1])) {
                    $cats[$p] = $m[1];
                } else {
                    $cats[$p] = substr($p, strlen($m[0][0]));
                }
                // FIXME
                unset($hits[$p]);
            }
        }
        if (count($cats) > 0) {
            $params['.count'] = true;
            $out = '<h2>' . _("Subcategories") . '</h2>';
            $out .= _index($formatter, $cats, $params);
            $params['.count'] = false;
        }
    } else {
        if (empty($params['.notitle'])) {
            $title = '<h2>' . sprintf(_("BackLinks of \"%s\"."), _html_escape($value)) . '</h2>' . "\n";
        }
    }
    $index = _index($formatter, $hits, $params);
    if ($index !== false) {
        return $out . $title . $index;
    }
    if (empty($out)) {
        if (isset($params['.category'][0])) {
            return '<h2>' . sprintf(_("No pages found in category \"%s\"."), _html_escape($params['.category'])) . '</h2>';
        } else {
            return '<h2>' . _("No backlinks found.") . '</h2>';
        }
    }
    return $out;
}