<?php
include( $_SERVER["DOCUMENT_ROOT"] . "/includes/head.txt");
//john pfeiffer 2010-06-03 php find in html/text
//2010-06-09 - list all files in dir => array for searching
//2010-06-11 - searchin the first file from the dirlisting above
//to do - skip searching in <>
?>
<?php //include function get_list_of_files from parameter: directory
include( $_SERVER["DOCUMENT_ROOT"] . "/includes/list_files_in_dir.txt");
?>
<body onload="document.entryform.searchfield.focus()"> <!-- default cursor -->
<form name="entryform" method="post" action="
<?php echo $_SERVER['php_SELF']; ?>
">
find in this directory: <input type="text" name="searchfield" width="200" /><input type="submit" value="Submit" />
</form>
<?php
if( !isset($_POST['searchfield']) || empty($_POST['searchfield'] ) )
{
echo "<b>You really ought to search for something.</b>";
echo "<br />\n";
}
else
{
$servername = $_SERVER['SERVER_NAME']; // get the current file's URL, server portion
$page = $_SERVER['PHP_SELF']; // get the current file's URL, dir & file name portion
$current_directory = opendir( getcwd() ); //get current working directory
$filelist = list_files_in_dir( $current_directory ); //directory's files listed in an array
$title = explode("/", $page); //break the url into pieces
$currentfile = end($title); //the name of the current file (last piece)
$directory = prev($title); //find the current directory
$urlpath = 'http://' . $servername;
$urlpath = $urlpath . "/" . $directory . "/" . $filelist[0];
$target_url = strtolower( "http://kittyandbear.net" );
$target_url = $urlpath;
$searchfield = $_POST['searchfield'];
$searchfield = trim( $searchfield );
echo "SEARCHING " . '<a href="' . $urlpath . '">' . $urlpath . "</a><br />\n";
print_r( $filelist );
$result = file_get_contents( $target_url );
if( $result == false )
{ exit("error getting contents"); }
$found_position = stripos( $result , $searchfield );
if( $found_position === FALSE )
{ echo "<b>Sorry, not found</b>";
echo "<br />\n";
}
else
{
echo "<hr>";
echo $found_position . " = ";
if( ($found_position - 50) > 0 )
{ echo substr( $result , $found_position - 50, 50 ); }
echo '<span style="font-size: 120%">';
echo substr( $result , $found_position , strlen( $searchfield ) );
echo "</span>";
if( ($found_position + strlen( $searchfield) + 50) < strlen( $result ) )
{
echo "<br />\n";
echo $found_position + strlen( $searchfield ) +50 . " = ";
//echo substr( $result , $found_position , 50 );
echo substr( $result , ($found_position + strlen( $searchfield )) , 50);
}
print_r( $result );
$result = htmlentities($result, ENT_QUOTES);
print_r( $result );
echo "<br />\n";
echo "<hr>";
}
}
echo "<br />\n";
?>
<?php //include date modified
include( $_SERVER["DOCUMENT_ROOT"] . "/includes/foot.txt");
?>
<?php //include the google analytics javascript
include( $_SERVER["DOCUMENT_ROOT"] . "/includes/google-code.htm");
?>
</body>
</html>