<?
/*
==> HOW TO USE
1) Change
mysql_pconnect('localhost', 'Mysql Username', 'Mysql Password');
Note you must replace "Mysql Username" and "Mysql Password" to your
real username/password.
## EVERYTHING IS CONSIDERED TO BE DONE MANUALLY, THROUGH
## THIS DOCUMENT! THERE IS NO USER INTERFACE WHATSOEVER!
2) Installation
Change
$x->wait();
to
$x->install();
It will install Indexer.
3) Index
Change
$x->install();
to
$x->getFiles();
4) Change the variable $dir so it points to a valid directory.
It is recommended that you add a trailing slash; however, our selfcheck
should append it if it is not already attached.
### Notes
1) To truncate the database we are using (it is called 'search') do:
$x->truncate();
2) To see stats do:
$x->stats();
3) To run viewer which is powered via the GET of URL 'files' do:
$x->viewer();
4) To see all cached files do:
$x->all();
5) To delete cached (indexed) pages do:
$x->deleteSome(#ID#);
where you replace #ID# with the ID you want to delete.
NOTE
This application is done for fun, only.
The enhanced version may be released, but it may not be released too.
Check http://dev.recgr.com often so you don't miss it!
-Nino
[26th July 2006]
*/
ob_start();
if ($_GET['source'] == 'on') {
echo '<html><body>' ."\n";
highlight_file('indexer.php');
echo '</body></html>' ."\n";
ob_end_flush();
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?
$conn = @mysql_pconnect('localhost', 'Mysql Username', 'Mysql Password');
if (!$conn) {
echo("The application couldn't connect to DB.");
echo mysql_error();
die();
}
$db = @mysql_select_db('sknino_nino');
if (!$db) {
echo("The application couldn't select the DB.");
echo mysql_error();
die();
}
clearstatcache();
set_time_limit(1000);
// Main Class
class index {
function getFiles() {
$dir = 'REPLACE THIS WITH YOUR FOLDER';
if ( (strrpos($dir, '/') + 1) != strlen($dir) ) {
$dir .= '/';
}
if (!is_dir($dir)) {
return;
}
$d = dir($dir);
// dir() is a stand-alone class
while ( ($files = $d->read()) !== false) {
if ($files != "" && $files != "." && $files != "..") {
$content = file_get_contents($dir.$files);
$fname = $files;
$fext_exp = explode('.', $fname);
$fext = end($fext_exp);
$query = sprintf("INSERT INTO search (file, content) VALUES ('%s', '%s')", mysql_real_escape_string($fname), mysql_real_escape_string($content));
if (is_file($dir.$files)) {
if ($fext == 'htm' || $fext == 'html' || $fext == 'php') {
mysql_query($query);
} // mysql_query();
} // is_file();
} // if not zero or dot(s)
} // while loop
$d->close();
} //getFiles();
function truncate() {
$sql = 'TRUNCATE TABLE `search`';
mysql_query($sql);
}
function stats() {
$sql = "SELECT count(`id`) FROM search";
echo mysql_result(mysql_query($sql), 0);
echo " files cached.";
}
function viewer() {
$f = $_GET['file'];
$sql = "SELECT * FROM search WHERE id = $f";
$q = mysql_query($sql);
if (@mysql_num_rows($q) <= 0) {
echo "No results found.";
return;
}
$f = mysql_fetch_assoc($q);
ob_end_clean();
echo $f['content'];
die();
}
function install($is_sure) {
if ($is_sure != true) {
return;
}
$sql = 'CREATE TABLE `search` ('
. ' `file` VARCHAR(200) NOT NULL, '
. ' `content` TEXT NOT NULL, '
. ' `id` BIGINT NOT NULL AUTO_INCREMENT,'
. ' PRIMARY KEY (`file`),'
. ' UNIQUE (`id`)'
. ' )'
. ' TYPE = myisam;';
mysql_query($sql) or die("Couldn't install the service!");
$sql_blog = 'ALTER TABLE `search` CHANGE `content` `content` LONGBLOB NOT NULL';
mysql_query($sql_blog) or trigger_error("Error: couldn't change the field type to BLOB.");
}
function all() {
ob_end_clean();
$q = mysql_query("SELECT * FROM search ORDER BY id ASC");
while ($f = mysql_fetch_assoc($q)) {
echo "<strong>{$f['file']}</strong> <br /> <br /> \n";
echo "<div> \n";
echo $f['content'];
echo "</div> \n";
}
die();
}
function delSome($id) {
mysql_query("DELETE FROM search WHERE id = $id");
}
function wait() {
echo "Welcome to the Indexer!";
}
}
$x = new index;
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>Indexer</title>
</head>
<body>
<?
// use the Indexer
$x->wait();
?>
</body>
</html>
<?
ob_end_flush();
?>