Version 2.0.0

This commit is contained in:
Neo committed 2025-12-19 00:19:56 -08:00
1 parent 5699abfc0e
commit 0eecc172d9
696 files changed
+120723 -77160

No files matched your search

+278 -211
View File
@@ -2,16 +2,15 @@
/*
+--------------------------------------------------------------------------
| Invision Power Board v1.3.1 Final
| ========================================
| Invision Power Board v2.0.0
| =============================================
| by Matthew Mecham
| (c) 2001 - 2003 Invision Power Services
| (c) 2001 - 2004 Invision Power Services, Inc.
| http://www.invisionpower.com
| ========================================
| =============================================
| Web: http://www.invisionboard.com
| Time: Thu, 23 Sep 2004 23:05:01 GMT
| Release: 3cb325c445e1909182084806ae7f8226
| Email: matt@invisionpower.com
| Time: Tue, 21 Sep 2004 16:34:28 GMT
| Release: 150aa7a702c3c8b6f6eb90ad49305d2f
| Licence Info: http://www.invisionboard.com/?license
+---------------------------------------------------------------------------
|
@@ -30,34 +29,34 @@ class search_lib extends Search
var $parser = "";
var $is = "";
//--------------------------------------------
//-----------------------------------------
// Constructor
//--------------------------------------------
//-----------------------------------------
function search_lib($that)
{
global $ibforums, $DB, $std, $print;
global $ibforums, $DB, $std, $print;
$this->is = &$that; // hahaha!
}
//--------------------------------------------
//-----------------------------------------
// Simple search
//--------------------------------------------
//-----------------------------------------
function do_simple_search()
{
global $ibforums, $DB, $std, $HTTP_POST_VARS, $print;
global $ibforums, $DB, $std, $HTTP_POST_VARS, $print, $forums;
if ( ! $ibforums->input['sid'] )
{
$boolean = "";
//--------------------------------------------
//-----------------------------------------
// NEW SEARCH.. Check Keywords..
//--------------------------------------------
//-----------------------------------------
if ( $this->is->mysql_version >= 40010 )
{
@@ -76,45 +75,79 @@ class search_lib extends Search
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_words') );
}
if (strlen(trim($keywords)) < 4)
if (strlen(trim($keywords)) < $ibforums->vars['min_search_word'])
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => 4) );
}
//--------------------------------------------
//-----------------------------------------
// Check for filter abuse..
//-----------------------------------------
$tmp = explode( ' ', $keywords );
foreach( $tmp as $t )
{
if ( ! $t )
{
continue;
}
$t = preg_replace( "#[\+\-\*\.]#", "", $t );
//-----------------------------------------
// Allow abc* but not a***
//-----------------------------------------
if ( strlen( $t ) < 3 )
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => 4) );
}
}
//print $check_keywords; exit();
//-----------------------------------------
// Get forums...
//--------------------------------------------
//-----------------------------------------
$forums = $this->is->get_searchable_forums();
$myforums = $this->is->get_searchable_forums();
if ($forums == "")
if ($myforums == "")
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') );
}
//--------------------------------------------
//-----------------------------------------
// How many results?
//--------------------------------------------
//-----------------------------------------
$DB->query("SELECT COUNT(*) as dracula FROM ibf_posts p WHERE p.forum_id IN ($forums) AND MATCH(post) AGAINST ('$check_keywords' $boolean)");
$DB->query("SELECT COUNT(*) as dracula
FROM ".SQL_PREFIX."posts p
LEFT JOIN ".SQL_PREFIX."topics t ON (t.tid=p.topic_id)
WHERE t.forum_id IN ($myforums)
AND MATCH(p.post) AGAINST ('$check_keywords' $boolean)");
$count = $DB->fetch_row();
if ( $count['dracula'] < 1 ) // Tee-hee!
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );
$this->output .= $this->is->html->search_error_page($ibforums->input['keywords']);
$print->add_output( $this->output );
$print->do_output( array( 'TITLE' => $ibforums->lang['g_simple_title'], 'JS' => 0, NAV => array( $ibforums->lang['g_simple_title'] ) ) );
}
//--------------------------------------------
//-----------------------------------------
// Store it daddy-o!
//--------------------------------------------
//-----------------------------------------
$cache = "SELECT MATCH(post) AGAINST ('$check_keywords' $boolean) as score, t.tid, t.title, t.posts, t.views,
f.category, f.id, f.name, p.post, p.author_id, p.author_name, p.post_date, p.pid
FROM ibf_posts p
LEFT JOIN ibf_forums f ON (p.forum_id=f.id)
LEFT JOIN ibf_topics t on (p.topic_id=t.tid)
WHERE p.forum_id IN ($forums) AND t.title IS NOT NULL
$cache = "SELECT MATCH(post) AGAINST ('$check_keywords' $boolean) as score, t.tid, t.posts as topic_posts, t.title as topic_title, t.views, t.forum_id,
p.post, p.author_id, p.author_name, p.post_date, p.pid, p.post_htmlstate,m.*, me.*
FROM ".SQL_PREFIX."posts p
LEFT JOIN ".SQL_PREFIX."topics t on (p.topic_id=t.tid)
LEFT JOIN ".SQL_PREFIX."members m on (m.id=p.author_id)
LEFT JOIN ".SQL_PREFIX."member_extra me on (me.id=p.author_id)
WHERE t.forum_id IN ($myforums) AND t.title IS NOT NULL
AND MATCH(post) AGAINST ('$check_keywords' $boolean)";
if ( $ibforums->input['sortby'] != "relevant" )
@@ -138,14 +171,25 @@ class search_lib extends Search
$DB->query("INSERT INTO ibf_search_results ({$str['FIELD_NAMES']}) VALUES ({$str['FIELD_VALUES']})");
$print->redirect_screen( $ibforums->lang['search_redirect'] , "act=Search&CODE=simpleresults&sid=$unique_id&highlite=".urlencode(trim(str_replace( '&amp;', '&', $ibforums->input['keywords']))) );
$hilight = str_replace( '&quot;', '', $ibforums->input['keywords'] );
$hilight = urlencode(trim(str_replace( '&amp;', '&', $hilight)));
$print->redirect_screen( $ibforums->lang['search_redirect'] , "act=Search&CODE=simpleresults&sid=$unique_id&highlite=".$hilight );
}
else
{
//--------------------------------------------
//-----------------------------------------
// Load up the topic stuff
//-----------------------------------------
require_once( ROOT_PATH.'sources/topics.php' );
$this->topics = new topics();
$this->topics->topic_init();
//-----------------------------------------
// Get SQL schtuff
//--------------------------------------------
//-----------------------------------------
$this->unique_id = $ibforums->input['sid'];
@@ -165,9 +209,9 @@ class search_lib extends Search
$check_keywords = preg_replace( '/&amp;(lt|gt|quot);/', "&\\1;", trim(urldecode($ibforums->input['highlite'])) );
//--------------------------------------------
//-----------------------------------------
// Display
//--------------------------------------------
//-----------------------------------------
$this->links = $std->build_pagelinks(
array(
@@ -177,28 +221,13 @@ class search_lib extends Search
'CUR_ST_VAL' => $this->is->first,
'L_SINGLE' => $ibforums->lang['sp_single'],
'L_MULTI' => "",
'BASE_URL' => $ibforums->base_url."&amp;act=Search&amp;CODE=simpleresults&amp;sid=".$this->unique_id."&amp;highlite=".urlencode($check_keywords),
'BASE_URL' => $ibforums->base_url."&amp;act=Search&amp;CODE=simpleresults&amp;sid=".$this->unique_id."&amp;highlite=".urlencode(str_replace('"', '', $check_keywords)),
)
);
require "./sources/lib/post_parser.php";
$this->parser = new post_parser();
//--------------------------------------------
// Get categories
//--------------------------------------------
$DB->query("SELECT id, name FROM ibf_categories");
while ( $cat = $DB->fetch_row() )
{
$cat_array[ $cat['id'] ] = $cat['name'];
}
//--------------------------------------------
//-----------------------------------------
// oh look, a query!
//--------------------------------------------
//-----------------------------------------
$last_tid = 0;
@@ -206,7 +235,7 @@ class search_lib extends Search
$SQLtime->startTimer();
$DB->query($query." LIMIT {$this->is->first},25");
$outer = $DB->query($query." LIMIT {$this->is->first},25");
$ex_time = sprintf( "%.4f",$SQLtime->endTimer() );
@@ -225,10 +254,12 @@ class search_lib extends Search
'ex_time' => $ex_time,
'keyword' => $check_keywords,
) );
$attach_pids = array();
while ( $row = $DB->fetch_row() )
while ( $row = $DB->fetch_row($outer) )
{
//---------------------------------------------------------------------
//-----------------------------------------
// Listen up, this is relevant.
// MySQL's relevance is a bit of a mystery. It's
// based on many hazy variables such as placing, occurance
@@ -236,89 +267,12 @@ class search_lib extends Search
// No one can really disect what this means in human terms, so I'm
// going to simply assume that anything over 1.0 is 100%, and *100 any
// other relevance result.
//---------------------------------------------------------------------
//-----------------------------------------
$member = $this->topics->parse_member( $row );
$row['relevance'] = sprintf( "%3d", ( $row['score'] > 1.0 ) ? 100 : $row['score'] * 100 );
//-----------------------------------------
// Fix up da post
//-----------------------------------------
$row['post'] = $this->parser->unconvert($row['post']);
// Strip out BB tags
$row['post'] = preg_replace( "#\[.+?/?\]#", "", $row['post'] );
// Try and locate keyword in the post...
$start = 0;
$end = 250;
$tmp_post = strtolower($row['post']);
$tmp_words = explode(" ", trim(strtolower($check_keywords)) );
if ( $st = strpos( $tmp_post, $tmp_words[0] ) )
{
$start = $st - 100;
$start = $start < 0 ? 0 : $start;
$end += $start;
}
$row['post'] = substr( $row['post'], $start, $end );
// Finish tidy up..
if ( $start > 0 )
{
// We're cutting at the start, so..
// If it's not a capital letter, it's probably
// cut a word in half / it's a lower case word so it doesnt matter
if ( ! preg_match( "/^[A-Z]/", $row['post'] ) )
{
// find the first space..
if ( $new_start = strpos( $row['post'], " " ) )
{
// Cut to space..
$row['post'] = substr( $row['post'], $new_start );
$row['post'] = '...'.$row['post'];
}
}
}
// Tidy up the end..
// Find the last space..
if ( strlen( $row['post'] ) > 250 )
{
if ( $new_end = strrpos( $row['post'], " " ) )
{
$row['post'] = substr( $row['post'], 0, $new_end );
$row['post'] .= '...';
}
}
// Basic highlighting
$row['post'] = preg_replace( "/".preg_quote($tmp_words[0], '/')."/i", "<strong>".$tmp_words[0]."</strong>", $row['post'] );
$row['css_class'] = 'googleroot';
if ( $row['tid'] == $last_tid )
{
$row['css_class'] = 'googlechild';
}
$last_tid = $row['tid'];
$row['cat_id'] = $row['category'];
$row['cat_name'] = $cat_array[ $row['category'] ];
$row['post_date'] = $std->get_date( $row['post_date'], 'LONG' );
// Link member's name
@@ -328,12 +282,68 @@ class search_lib extends Search
$row['author_name'] = "<a href='{$ibforums->base_url}act=Profile&amp;MID={$row['author_id']}'>{$row['author_name']}</a>";
}
$this->output .= $this->is->html->result_simple_entry($row);
}
//-----------------------------------------
// Attachments?
//-----------------------------------------
if ( strstr( $row['post'], '[attachmentid=' ) )
{
$attach_pids[] = $row['pid'];
}
//-----------------------------------------
// Fix up quotes..
//-----------------------------------------
$row['post'] = $this->topics->parser->unconvert( $row['post'] );
$row['post'] = $this->topics->parser->convert( array(
'TEXT' => $row['post'],
'CODE' => $forums->forum_by_id[$row['forum_id']]['use_ibc'],
'SMILIES' => 1,
'HTML' => 0
) );
$this->topics->parser->pp_do_html = ( $forums->forum_by_id[$row['forum_id']]['use_html'] and $ibforums->cache['group_cache'][ $row['mgroup'] ]['g_dohtml'] and $row['post_htmlstate'] ) ? 1 : 0;
$this->topics->parser->pp_wordwrap = $ibforums->vars['post_wordwrap'];
$this->topics->parser->pp_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
$row['post'] = $this->topics->parser->post_db_parse( $row['post'] );
$keywords_array = explode( " ", str_replace( "+", " ", $ibforums->input['highlite'] ) );
if ( count($keywords_array) )
{
foreach( $keywords_array as $keys )
{
if ( $keys == "" )
{
continue;
}
$this->output .= $this->is->html->result_simple_footer(array(
'links' => $this->links,
) );
while( preg_match( "/(^|\s|'|\"|>)(".preg_quote($keys, '/').")(\s|'|\"|,|\.|!|<br|$)/is", $row['post'] ) )
{
$row['post'] = preg_replace( "/(^|\s|'|\"|>)(".preg_quote($keys, '/').")(\s|'|\"|,|\.|!|<br|$)/is", "\\1<span class='searchlite'>\\2</span>\\3", $row['post'] );
}
}
}
$row['forum_name'] = $forums->forum_by_id[ $row['forum_id'] ]['name'];
$this->output .= $this->is->html->RenderPostRow($row, $member);
}
//-----------------------------------------
// Add in attachments?
//-----------------------------------------
if ( count( $attach_pids ) )
{
$this->output = $this->topics->parse_attachments( $this->output, $attach_pids );
}
$this->output .= $this->is->html->end_results_table(array( 'SHOW_PAGES' => $this->links ) , 1 );
$print->add_output("$this->output");
$print->do_output( array( 'TITLE' => $ibforums->lang['g_simple_title'], 'JS' => 0, NAV => array( $ibforums->lang['g_simple_title'] ) ) );
@@ -345,22 +355,22 @@ class search_lib extends Search
//--------------------------------------------
//-----------------------------------------
// Main Board Search-e-me-doo-daa
//--------------------------------------------
//-----------------------------------------
function do_main_search()
{
global $ibforums, $DB, $std, $HTTP_POST_VARS, $print;
//------------------------------------
//-----------------------------------------
// Do we have any input?
//------------------------------------
//-----------------------------------------
//------------------------------------
//-----------------------------------------
// USING FULL TEXT - Wooohoo!!
//------------------------------------
//-----------------------------------------
if ($ibforums->input['namesearch'] != "")
@@ -392,7 +402,7 @@ class search_lib extends Search
$type='nameonly';
}
//------------------------------------
//-----------------------------------------
if ( $this->is->mysql_version >= 40010 )
{
@@ -415,33 +425,58 @@ class search_lib extends Search
}
else
{
if (strlen(trim($keywords)) < 4)
if ( strlen(trim($keywords)) < $ibforums->vars['min_search_word'] and $type != 'nameonly' )
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => 4) );
}
}
//------------------------------------
//-----------------------------------------
// Check for filter abuse..
//-----------------------------------------
$tmp = explode( ' ', $keywords );
foreach( $tmp as $t )
{
if ( ! $t )
{
continue;
}
$t = preg_replace( "#[\+\-\*\.]#", "", $t );
//-----------------------------------------
// Allow abc* but not a***
//-----------------------------------------
if ( ( strlen( $t ) < $ibforums->vars['min_search_word'] ) and $type != 'nameonly' )
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => 4) );
}
}
//-----------------------------------------
if ($ibforums->input['search_in'] == 'titles')
{
$this->is->search_in = 'titles';
}
//------------------------------------
//-----------------------------------------
$forums = $this->is->get_searchable_forums();
//------------------------------------
//-----------------------------------------
// Do we have any forums to search in?
//------------------------------------
//-----------------------------------------
if ($forums == "")
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') );
}
//------------------------------------
//-----------------------------------------
foreach( array( 'last_post', 'posts', 'starter_name', 'forum_id' ) as $v )
{
@@ -451,7 +486,7 @@ class search_lib extends Search
}
}
//------------------------------------
//-----------------------------------------
foreach ( array( 1, 7, 30, 60, 90, 180, 365, 0 ) as $v )
{
@@ -461,14 +496,14 @@ class search_lib extends Search
}
}
//------------------------------------
//-----------------------------------------
if ($ibforums->input['sort_order'] == 'asc')
{
$this->is->sort_order = 'asc';
}
//------------------------------------
//-----------------------------------------
if ($ibforums->input['result_type'] == 'posts')
{
@@ -480,16 +515,24 @@ class search_lib extends Search
$ibforums->vars['min_search_word'] = 4;
}
//------------------------------------
//-----------------------------------------
// Add on the prune days
//------------------------------------
//-----------------------------------------
if ($this->is->prune > 0)
{
$gt_lt = $ibforums->input['prune_type'] == 'older' ? "<" : ">";
$time = time() - ($ibforums->input['prune'] * 86400);
$topics_datecut = "t.last_post $gt_lt $time AND";
if ( $this->is->result_type == 'posts' )
{
$topics_datecut = "t.start_date $gt_lt $time AND";
}
else
{
$topics_datecut = "t.last_post $gt_lt $time AND";
}
$posts_datecut = "p.post_date $gt_lt $time AND";
}
@@ -500,9 +543,9 @@ class search_lib extends Search
if ( $name_filter != "" )
{
//------------------------------------------------------------------
//-----------------------------------------
// Get all the possible matches for the supplied name from the DB
//------------------------------------------------------------------
//-----------------------------------------
$name_filter = str_replace( '|', "&#124;", $name_filter );
@@ -551,93 +594,117 @@ class search_lib extends Search
if ($type != 'nameonly')
{
$topics_query = "SELECT t.tid
FROM ibf_topics t
WHERE $topics_datecut t.forum_id IN ($forums)
$topics_name AND t.approved=1 AND MATCH(title) AGAINST ('".trim($keywords)."' $boolean)";
$posts_query = "SELECT p.pid ".
"FROM ibf_posts p ".
"WHERE $posts_datecut p.forum_id IN ($forums)".
" AND p.queued <> 1".
" $posts_name AND MATCH(post) AGAINST ('".trim($keywords)."' $boolean)";
if ( ! $this->is->topic_search_only )
{
$topics_query = "SELECT t.tid
FROM ibf_topics t
WHERE $topics_datecut t.forum_id IN ($forums)
$topics_name AND t.approved=1 AND MATCH(title) AGAINST ('".trim($keywords)."' $boolean)";
$posts_query = "SELECT p.pid
FROM ibf_posts p
LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid )
WHERE $posts_datecut t.forum_id IN ($forums)
AND p.queued <> 1
$posts_name AND MATCH(post) AGAINST ('".trim($keywords)."' $boolean)";
}
else
{
//-----------------------------------------
// Search in topic only
//-----------------------------------------
$posts_query = "SELECT p.pid
FROM ibf_posts p
LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid )
WHERE
p.topic_id={$this->is->topic_id}
AND $posts_datecut t.forum_id IN ($forums)
AND p.queued <> 1
$posts_name AND MATCH(post) AGAINST ('".trim($keywords)."' $boolean)";
}
}
else
{
$topics_query = "SELECT t.tid
FROM ibf_topics t
WHERE $topics_datecut t.forum_id IN ($forums)
$topics_name";
$posts_query = "SELECT p.pid ".
"FROM ibf_posts p ".
"WHERE $posts_datecut p.forum_id IN ($forums)".
" AND p.queued <> 1".
" $posts_name";
$posts_query = "SELECT p.pid
FROM ibf_posts p
LEFT JOIN ibf_topics t ON ( p.topic_id=t.tid )
WHERE $posts_datecut t.forum_id IN ($forums)
AND p.queued <> 1
$posts_name";
}
//------------------------------------------------
//-----------------------------------------
// Get the topic ID's to serialize and store into
// the database
//------------------------------------------------
//-----------------------------------------
$topics = "";
$posts = "";
$topic_array = array();
$post_array = array();
//------------------------------------
//-----------------------------------------
$DB->query($topics_query);
$topic_max_hits = $DB->get_num_rows();
while ($row = $DB->fetch_row() )
if ( ! $this->is->topic_search_only )
{
$topics .= $row['tid'].",";
$DB->query($topics_query);
while ($row = $DB->fetch_row() )
{
$topic_array[ $row['tid'] ] = $row['tid'];
}
$DB->free_result();
}
$DB->free_result();
//------------------------------------
//-----------------------------------------
$DB->query($posts_query);
$post_max_hits = $DB->get_num_rows();
while ($row = $DB->fetch_row() )
{
$posts .= $row['pid'].",";
$post_array[ $row['pid'] ] = $row['pid'];
}
$DB->free_result();
//------------------------------------
//-----------------------------------------
$topics = preg_replace( "/,$/", "", $topics );
$posts = preg_replace( "/,$/", "", $posts );
$topics = implode( ",", $topic_array );
$posts = implode( ",", $post_array );
//------------------------------------------------
//-----------------------------------------
// Do we have any results?
//------------------------------------------------
//-----------------------------------------
if ($topics == "" and $posts == "")
{
$std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) );
$this->output .= $this->is->html->search_error_page($ibforums->input['keywords']);
$print->add_output( $this->output );
$print->do_output( array( 'TITLE' => $ibforums->lang['g_simple_title'], 'JS' => 0, NAV => array( $ibforums->lang['g_simple_title'] ) ) );
}
//------------------------------------------------
//-----------------------------------------
// If we are still here, return data like a good
// boy (or girl). Yes Reg; or girl.
// What have the Romans ever done for us?
//------------------------------------------------
//-----------------------------------------
return array(
'topic_id' => $topics,
'post_id' => $posts,
'topic_max' => $topic_max_hits,
'post_max' => $post_max_hits,
'keywords' => $keywords,
'topic_max' => intval( count( $topic_array ) ),
'post_max' => intval( count( $post_array ) ),
'keywords' => str_replace( '"', "", $keywords ),
);
}
@@ -645,4 +712,4 @@ class search_lib extends Search
}
?>
?>