diff -r de56132c008d -r bdac73ed481e plugins/SpecialSearch.php --- a/plugins/SpecialSearch.php Sun Mar 28 21:49:26 2010 -0400 +++ b/plugins/SpecialSearch.php Sun Mar 28 23:10:46 2010 -0400 @@ -1,12 +1,12 @@ get_permissions('mod_misc') ) - { - die_friendly('Unauthorized', '

You need to be an administrator to rebuild the search index

'); - } - $template->header(); - @set_time_limit(0); - echo '

'; - if($paths->rebuild_search_index(true)) - echo '

Index rebuilt!

'; - else - echo '

Index was not rebuilt due to an error.'; - $template->footer(); + global $db, $session, $paths, $template, $plugins; // Common objects + if ( !$session->get_permissions('mod_misc') ) + { + die_friendly('Unauthorized', '

You need to be an administrator to rebuild the search index

'); + } + $template->header(); + @set_time_limit(0); + echo '

'; + if($paths->rebuild_search_index(true)) + echo '

Index rebuilt!

'; + else + echo '

Index was not rebuilt due to an error.'; + $template->footer(); } function page_Special_Search() { - global $db, $session, $paths, $template, $plugins; // Common objects - global $aggressive_optimize_html; - global $lang; - - require_once(ENANO_ROOT.'/includes/search.php'); - - $aggressive_optimize_html = false; - - if ( !$q = $paths->getParam(0) ) - $q = ( isset($_GET['q']) ) ? $_GET['q'] : ''; - - if(isset($_GET['words_any'])) - { - $q = ''; - if(!empty($_GET['words_any'])) - { - $q .= $_GET['words_any'] . ' '; - } - if(!empty($_GET['exact_phrase'])) - { - $q .= '"' . $_GET['exact_phrase'] . '" '; - } - if(!empty($_GET['exclude_words'])) - { - $not = explode(' ', $_GET['exclude_words']); - foreach ( $not as $i => $foo ) - { - $not[$i] = '-' . $not[$i]; - } - $q .= implode(' ', $not) . ' '; - } - if(!empty($_GET['require_words'])) - { - $req = explode(' ', $_GET['require_words']); - foreach ( $req as $i => $foo ) - { - $req[$i] = '+' . $req[$i]; - } - $q .= implode(' ', $req) . ' '; - } - } - $q = trim($q); - - $template->header(); - - $qin = ( isset($q) ) ? str_replace('"', '\"', htmlspecialchars($q)) : ''; - $search_form = '

-   ' . $lang->get('search_btn_advanced_search') . ' - ' . ( $session->auth_level > USER_LEVEL_MEMBER ? '' : '' ) . ' -
'; - - if ( !empty($q) ) - { - $search_start = microtime_float(); - - $results = perform_search($q, $warn, ( isset($_GET['match_case']) ), $word_list); - $warn = array_unique($warn); - - if ( file_exists( ENANO_ROOT . '/themes/' . $template->theme . '/search-result.tpl' ) ) - { - $parser = $template->makeParser('search-result.tpl'); - } - else - { - $tpl_code = << - -
-

-

{PAGE_NOTE}{PAGE_TITLE}

- {PAGE_TEXT} - {PAGE_URL} - - {PAGE_LENGTH} {PAGE_LENGTH_UNIT} - - {lang:search_lbl_relevance} {RELEVANCE_SCORE}% -

-
- - - + global $db, $session, $paths, $template, $plugins; // Common objects + global $aggressive_optimize_html; + global $lang; + + require_once(ENANO_ROOT.'/includes/search.php'); + + $aggressive_optimize_html = false; + + if ( !$q = $paths->getParam(0) ) + $q = ( isset($_GET['q']) ) ? $_GET['q'] : ''; + + if(isset($_GET['words_any'])) + { + $q = ''; + if(!empty($_GET['words_any'])) + { + $q .= $_GET['words_any'] . ' '; + } + if(!empty($_GET['exact_phrase'])) + { + $q .= '"' . $_GET['exact_phrase'] . '" '; + } + if(!empty($_GET['exclude_words'])) + { + $not = explode(' ', $_GET['exclude_words']); + foreach ( $not as $i => $foo ) + { + $not[$i] = '-' . $not[$i]; + } + $q .= implode(' ', $not) . ' '; + } + if(!empty($_GET['require_words'])) + { + $req = explode(' ', $_GET['require_words']); + foreach ( $req as $i => $foo ) + { + $req[$i] = '+' . $req[$i]; + } + $q .= implode(' ', $req) . ' '; + } + } + $q = trim($q); + + $template->header(); + + $qin = ( isset($q) ) ? str_replace('"', '\"', htmlspecialchars($q)) : ''; + $search_form = '
+   ' . $lang->get('search_btn_advanced_search') . ' + ' . ( $session->auth_level > USER_LEVEL_MEMBER ? '' : '' ) . ' +
'; + + if ( !empty($q) ) + { + $search_start = microtime_float(); + + $results = perform_search($q, $warn, ( isset($_GET['match_case']) ), $word_list); + $warn = array_unique($warn); + + if ( file_exists( ENANO_ROOT . '/themes/' . $template->theme . '/search-result.tpl' ) ) + { + $parser = $template->makeParser('search-result.tpl'); + } + else + { + $tpl_code = << + +
+

+

{PAGE_NOTE}{PAGE_TITLE}

+ {PAGE_TEXT} + {PAGE_URL} - + {PAGE_LENGTH} {PAGE_LENGTH_UNIT} - + {lang:search_lbl_relevance} {RELEVANCE_SCORE}% +

+
+ + + LONGSTRING; - $parser = $template->makeParserText($tpl_code); - } - foreach ( $results as $i => $_ ) - { - $result =& $results[$i]; - $result['page_text'] = str_replace(array('', ''), array('', ''), $result['page_text']); - if ( !empty($result['page_text']) ) - $result['page_text'] .= '
'; - $result['page_name'] = str_replace(array('', ''), array('', ''), $result['page_name']); - $result['url_highlight'] = str_replace(array('', ''), array('', ''), $result['url_highlight']); - if ( $result['page_length'] >= 1048576 ) - { - $result['page_length'] = round($result['page_length'] / 1048576, 1); - $length_unit = $lang->get('etc_unit_megabytes_short'); - } - else if ( $result['page_length'] >= 1024 ) - { - $result['page_length'] = round($result['page_length'] / 1024, 1); - $length_unit = $lang->get('etc_unit_kilobytes_short'); - } - else - { - $length_unit = $lang->get('etc_unit_bytes'); - } - //$url = makeUrlComplete($result['namespace'], $result['page_id']); - //$url = preg_replace('/\?.+$/', '', $url); - $url = $result['url_highlight']; - - $parser->assign_vars(array( - 'PAGE_TITLE' => $result['page_name'], - 'PAGE_TEXT' => $result['page_text'], - 'PAGE_LENGTH' => $result['page_length'], - 'RELEVANCE_SCORE' => $result['score'], - 'RESULT_URL' => makeUrlNS($result['namespace'], $result['page_id'], false, true) . ( isset($result['url_append']) ? $result['url_append'] : '' ), - 'PAGE_LENGTH_UNIT' => $length_unit, - 'PAGE_URL' => $url, - 'PAGE_NOTE' => ( isset($result['page_note']) ? $result['page_note'] . ' ' : '' ) - )); - $has_content = ( $result['namespace'] == 'Special' || !empty($result['zero_length']) ); - - $code = $plugins->setHook('search_global_results'); - foreach ( $code as $cmd ) - { - eval($cmd); - } - - $parser->assign_bool(array( - 'special_page' => $has_content - )); - $result = $parser->run(); - } - unset($result); - - $per_page = 10; - $start = ( isset($_GET['start']) ? intval($_GET['start']) : 0 ); - // for plugin compatibility: - $offset =& $start; - $start_string = $start + 1; - $per_string = $start_string + $per_page - 1; - $num_results = count($results); - if ( $per_string > $num_results ) - $per_string = $num_results; - - $search_time = microtime_float() - $search_start; - $search_time = round($search_time, 3); - - $q_trim = ( strlen($q) > 30 ) ? substr($q, 0, 27) . '...' : $q; - $q_trim = htmlspecialchars($q_trim); - - $result_detail = $lang->get('search_msg_result_detail', array( - 'start_string' => $start_string, - 'per_string' => $per_string, - 'q_trim' => $q_trim, - 'num_results' => $num_results, - 'search_time' => $search_time - )); - $result_string = ( count($results) > 0 ) ? $result_detail : $lang->get('search_msg_no_results'); - - echo '
-
- ' . $result_string . ' -
- ' . $lang->get('search_lbl_site_search') . ' -
-
- ' . $search_form . ' -
'; - - if ( count($warn) > 0 ) - { - echo '
'; - echo '' . $lang->get('search_err_query_title') . '
- ' . $lang->get('search_err_query_body'); - echo '
  • ' . implode('
  • ', $warn) . '
'; - echo '
'; - } - - if ( count($results) > 0 ) - { - $html = paginate_array( - $results, - count($results), - makeUrlNS('Special', 'Search', 'q=' . str_replace('%', '%%', htmlspecialchars(urlencode($q))) . '&start=%s'), - $start, - $per_page - ); - echo $html; - } - else - { - // No results for the search - echo '

' . $lang->get('search_body_no_results_title', array('query' => htmlspecialchars($q))) . '

'; - echo $lang->get('search_body_no_results_body', array( - 'query' => htmlspecialchars($q), - 'create_url' => makeUrl($q), - 'special_url' => makeUrlNS('Special', 'SpecialPages'), - )); - } - $code = $plugins->setHook('search_results'); - foreach ( $code as $cmd ) - { - eval($cmd); - } - } - else - { - ?> -
- - - auth_level > USER_LEVEL_MEMBER ? '' : '' ); - endif; ?> -
- - - - - - - - - - - - - - - - - - - - - - - - -
get('search_th_advanced_search'); ?>
get('search_lbl_field_any'); ?>
get('search_lbl_field_exact'); ?>
get('search_lbl_field_none'); ?>
get('search_lbl_field_all'); ?>
- - - -
- - -
-
-
- footer(); + $parser = $template->makeParserText($tpl_code); + } + foreach ( $results as $i => $_ ) + { + $result =& $results[$i]; + $result['page_text'] = str_replace(array('', ''), array('', ''), $result['page_text']); + if ( !empty($result['page_text']) ) + $result['page_text'] .= '
'; + $result['page_name'] = str_replace(array('', ''), array('', ''), $result['page_name']); + $result['url_highlight'] = str_replace(array('', ''), array('', ''), $result['url_highlight']); + if ( $result['page_length'] >= 1048576 ) + { + $result['page_length'] = round($result['page_length'] / 1048576, 1); + $length_unit = $lang->get('etc_unit_megabytes_short'); + } + else if ( $result['page_length'] >= 1024 ) + { + $result['page_length'] = round($result['page_length'] / 1024, 1); + $length_unit = $lang->get('etc_unit_kilobytes_short'); + } + else + { + $length_unit = $lang->get('etc_unit_bytes'); + } + //$url = makeUrlComplete($result['namespace'], $result['page_id']); + //$url = preg_replace('/\?.+$/', '', $url); + $url = $result['url_highlight']; + + $parser->assign_vars(array( + 'PAGE_TITLE' => $result['page_name'], + 'PAGE_TEXT' => $result['page_text'], + 'PAGE_LENGTH' => $result['page_length'], + 'RELEVANCE_SCORE' => $result['score'], + 'RESULT_URL' => makeUrlNS($result['namespace'], $result['page_id'], false, true) . ( isset($result['url_append']) ? $result['url_append'] : '' ), + 'PAGE_LENGTH_UNIT' => $length_unit, + 'PAGE_URL' => $url, + 'PAGE_NOTE' => ( isset($result['page_note']) ? $result['page_note'] . ' ' : '' ) + )); + $has_content = ( $result['namespace'] == 'Special' || !empty($result['zero_length']) ); + + $code = $plugins->setHook('search_global_results'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + + $parser->assign_bool(array( + 'special_page' => $has_content + )); + $result = $parser->run(); + } + unset($result); + + $per_page = 10; + $start = ( isset($_GET['start']) ? intval($_GET['start']) : 0 ); + // for plugin compatibility: + $offset =& $start; + $start_string = $start + 1; + $per_string = $start_string + $per_page - 1; + $num_results = count($results); + if ( $per_string > $num_results ) + $per_string = $num_results; + + $search_time = microtime_float() - $search_start; + $search_time = round($search_time, 3); + + $q_trim = ( strlen($q) > 30 ) ? substr($q, 0, 27) . '...' : $q; + $q_trim = htmlspecialchars($q_trim); + + $result_detail = $lang->get('search_msg_result_detail', array( + 'start_string' => $start_string, + 'per_string' => $per_string, + 'q_trim' => $q_trim, + 'num_results' => $num_results, + 'search_time' => $search_time + )); + $result_string = ( count($results) > 0 ) ? $result_detail : $lang->get('search_msg_no_results'); + + echo '
+
+ ' . $result_string . ' +
+ ' . $lang->get('search_lbl_site_search') . ' +
+
+ ' . $search_form . ' +
'; + + if ( count($warn) > 0 ) + { + echo '
'; + echo '' . $lang->get('search_err_query_title') . '
+ ' . $lang->get('search_err_query_body'); + echo '
  • ' . implode('
  • ', $warn) . '
'; + echo '
'; + } + + if ( count($results) > 0 ) + { + $html = paginate_array( + $results, + count($results), + makeUrlNS('Special', 'Search', 'q=' . str_replace('%', '%%', htmlspecialchars(urlencode($q))) . '&start=%s'), + $start, + $per_page + ); + echo $html; + } + else + { + // No results for the search + echo '

' . $lang->get('search_body_no_results_title', array('query' => htmlspecialchars($q))) . '

'; + echo $lang->get('search_body_no_results_body', array( + 'query' => htmlspecialchars($q), + 'create_url' => makeUrl($q), + 'special_url' => makeUrlNS('Special', 'SpecialPages'), + )); + } + $code = $plugins->setHook('search_results'); + foreach ( $code as $cmd ) + { + eval($cmd); + } + } + else + { + ?> +
+ + + auth_level > USER_LEVEL_MEMBER ? '' : '' ); + endif; ?> +
+ + + + + + + + + + + + + + + + + + + + + + + + +
get('search_th_advanced_search'); ?>
get('search_lbl_field_any'); ?>
get('search_lbl_field_exact'); ?>
get('search_lbl_field_none'); ?>
get('search_lbl_field_all'); ?>
+ + + +
+ + +
+
+
+ footer(); } ?>