<?php
//
// (RE-)FILL YOUR SEARCH WORDLIST
//  Script Copyright 2001 phpBB Group (support@phpbb.com)
//  Taken from upgrade.php
//

define('IN_PHPBB'true);

error_reporting  (E_ERROR E_WARNING E_PARSE); // This will NOT report uninitialized variables
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime

//
// If we are being called from the install script then we don't need these
// as they are already included.
//
include('extension.inc');
include(
'config.'.$phpEx);
include(
'includes/constants.'.$phpEx);
include(
'includes/functions.'.$phpEx);


//
// Force the DB type to be MySQL
//
$dbms 'mysql';

include(
'includes/db.'.$phpEx);
include(
'includes/bbcode.'.$phpEx);
include(
'includes/functions_search.'.$phpEx);

set_time_limit(0); // Unlimited execution time

// ---------------
// Begin functions
//
function common_header()
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css">
<!--
/* Specifiy background images for selected styles
   This can't be done within the external style sheet as NS4 sees image paths relative to
   the page which called the style sheet (i.e. this page in the root phpBB directory)
   whereas all other browsers see image paths relative to the style sheet. Stupid NS again!
*/
TH            { background-image: url(templates/subSilver/images/cellpic3.gif) }
TD.cat        { background-image: url(templates/subSilver/images/cellpic1.gif) }
TD.rowpic    { background-image: url(templates/subSilver/images/cellpic2.jpg); background-repeat: repeat-y }
td.icqback    { background-image: url(templates/subSilver/images/icon_icq_add.gif); background-repeat: no-repeat }
TD.catHead,TD.catSides,TD.catLeft,TD.catRight,TD.catBottom { background-image: url(templates/subSilver/images/cellpic1.gif) }

font,th,td,p,body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt }
a:link,a:active,a:visited { font-family: Verdana, Arial, Helvetica, sans-serif; color : #006699; font-size:11pt }
a:hover        { font-family: Verdana, Arial, Helvetica, sans-serif;  text-decoration: underline; color : #DD6900; font-size:11pt }
hr    { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}

.maintitle,h1,h2    {font-weight: bold; font-size: 22px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; text-decoration: none; line-height : 120%; color : #000000;}

.ok {color:green}

/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
@import url("templates/subSilver/formIE.css"); 
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">

<table width="100%" border="0" cellspacing="0" cellpadding="10" align="center"> 
    <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td><img src="templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
                <td align="center" width="100%" valign="middle"><span class="maintitle">Upgrading to phpBB 2.0</span></td>
            </tr>
        </table></td>
    </tr>
</table>

<br clear="all" />

<?
    
return;
}

function 
common_footer()
{
?>

<br clear="all" />

</body>
</html>
<?
    
return;
}

function 
query($sql$errormsg)
{
    global 
$db;

    if ( !(
$result $db->sql_query($sql)) )
    {
        print 
"<br><font color=\"red\">\n";
        print 
"$errormsg<br>";

        
$sql_error $db->sql_error();
        print 
$sql_error['code'] .": "$sql_error['message']. "<br>\n";

        print 
"<pre>$sql</pre>";
        print 
"</font>\n";

        return 
FALSE;
    }
    else
    {
        return 
$result;
    }
}


common_header();

//
// Generate search word list
//
// Fetch a batch of posts_text entries
//

$sql "SELECT COUNT(*) as total, MAX(post_id) as max_post_id 
    FROM " 
POSTS_TEXT_TABLE;
$result query($sql"Couldn't get post count totals");

$max_post_id $db->sql_fetchrow($result);

$totalposts $max_post_id['total'];
$max_post_id $max_post_id['max_post_id'];
$per_percent round(( $totalposts 500 ) * 10);

$postcounter = ( !isset($HTTP_GET_VARS['batchstart']) ) ? $HTTP_GET_VARS['batchstart'];

$batchsize 150// Process this many posts per loop
$batchcount 0;
$total_percent 0;

for(;
$postcounter <= $max_post_id$postcounter += $batchsize)
{
    
$batchstart $postcounter 1;
    
$batchend $postcounter $batchsize;
    
$batchcount++;

    print 
" * Fulltext Indexing ( $batchstart to $batchend ) :: ";
    
flush();
    
    
$sql "SELECT *
        FROM " 
POSTS_TEXT_TABLE ."
        WHERE post_id 
            BETWEEN $batchstart 
                AND $batchend"
;
    
$posts_result query($sql"Couldn't obtain post_text");

    
$per_pct ceil$db->sql_numrows($posts_result) / 40 );
    
$inc 0;

    if ( 
$row $db->sql_fetchrow($posts_result) )
    { 
        do
        {
            
add_search_words('global'$row['post_id'], $row['post_text'], $row['post_subject']);

            
$inc++;
            if ( 
$inc == $per_pct )
            {
                print 
".";
                
flush();
                
$inc 0;
            }
        }
        while( 
$row $db->sql_fetchrow($posts_result) );
    }

    
$db->sql_freeresult($posts_result);
    
    
// Remove common words after the first 2 batches and after every 4th batch after that.
    
if ( $batchcount == )
    {
        
remove_common('global'0.4);
    }

    print 
" <span class=\"ok\"><b>OK</b></span><br />\n";
}

common_footer();
?>