$info)
{
printLine(getHeader(localize('Checking ') . $screen, 2), 0, FALSE);
flush();
//tokenize screen description ($info[SI_DESCRIPTION])
$Line = split("\n", cleanText($info[SI_DESCRIPTION]));
$LineCount = count($Line);
$inPHP = FALSE;
for($n=0; $n < $LineCount; $n++)
{
//tokenize line
$token = ereg_replace("[[:punct:]]", " ", strtolower(strtok(trim($Line[$n]), " ")));
while($token != '')
{
if(strlen($token) > SEARCH_MINIMUM_WORD_LENGTH)
{
//count that this token has appeared once
//on this screen
$ScreenIndex[$token][$screen]++;
}
$token = strtolower(strtok(" "));
}
}
//tokenize screen keywords ($info[SI_DESCRIPTION])
$Line = split("\n", cleanText($info[SI_KEYWORDS]));
$LineCount = count($Line);
$inPHP = FALSE;
for($n=0; $n < $LineCount; $n++)
{
//tokenize line
$token = strtolower(strtok(trim($Line[$n]), " "));
while($token != '')
{
if(strlen($token) > SEARCH_MINIMUM_WORD_LENGTH)
{
//count that this token has appeared once
//on this screen
$ScreenIndex[$token][$screen]++;
}
$token = strtolower(strtok(" "));
}
}
//tokenize screen body ($screen)
if(!file_exists(getScreenPath($screen)))
{
//skip screen if it doesn't exist
continue;
}
$Line = split("\n", cleanText(implode("", file(getScreenPath($screen)))));
$LineCount = count($Line);
for($n=0; $n < $LineCount; $n++)
{
//tokenize line
$token = strtok(trim($Line[$n]), " ");
while($token != '')
{
$token = trim(ereg_replace("[!,.:]", "", $token));
if(strlen($token) > SEARCH_MINIMUM_WORD_LENGTH)
{
//count that this token has appeared once
//on this screen
$ScreenIndex[$token][$screen]++;
}
$token = strtok(" ");
}
}
}
/*
** Take out high-frequence words
*/
print(localize('Dropping words that appear too frequently. '));
print(localize('Ratio') . ": $ScreenAppearanceLimit/" . count($ScreenInfo) . "
\n");
foreach($ScreenIndex as $token=>$data)
{
if(count($data) > $ScreenAppearanceLimit)
{
printLine("Taking out $token (" . count($data) . ")");
unset($ScreenIndex[$token]);
}
}
$outerStarted = FALSE;
$ArrayDef = "array(\n";
for(reset($ScreenIndex[$token]); $screen = key($ScreenIndex[$token]); next($ScreenIndex[$token]))
{
if($innerStarted)
{
$ArrayDef .= ",\n";
}
$ArrayDef .= "\t\t'$screen'=>'" . $ScreenIndex[$token][$screen] . "'";
$innerStarted = TRUE;
}
$outerStarted = TRUE;
}
$ArrayDef .= "\n\t)\n";
$ArrayDef .= "\n);\n";
$ArrayDef .= "?>\n";
if(DEBUG)
{
print("
"); print(prepareText($ArrayDef)); print(""); } //re-create ScreenIndex module if($fp = fopen(MODULE . "configuration/ScreenIndex", "w")) { fputs($fp, $ArrayDef); fclose($fp); } else { print("Unable to write new ScreenIndex. Did you chmod it to allow the "); print("Web server to write to it?"); } ?>