// Shustikov Lander v2 - Michael Yun Zhou
// Oct 25, 2005
require ('/var/www/webScripts/POI/domainNameScrub.php');
$domain_name = domainNameScrub($_SERVER['HTTP_HOST']);
include_once '/var/www/webScripts/POI/POIStats.php';
PoiStats($domain_name);
//require ('/var/www/webScripts/proaxis/MySQL_Connect.php');
require ('/var/www/webScripts/POI/MySQL_Connect.php');
//$data_base = "histology";
$data_base = "shustikov";
$link = mysql_connect ($hostDB, $userDB, $passwordDB)OR die ('Could not connect to MySQL: ' . mysql_error() );
mysql_select_db ($data_base) OR die ('Could not select the database: ' . mysql_error($link) );
$domain_select = mysql_query( "SELECT * FROM domains WHERE domain_name = '$domain_name'") or die(mysql_error());
$row = mysql_fetch_array($domain_select, MYSQL_ASSOC);
$did = $row["id"];
$sitekeyword = $row["keyword_1"];
$dtitle = $row["title"];
$dchannel = $row["channel"];
$keyword_1 = $row["keyword_2"];
$keyword_2 = $row["keyword_3"];
$keyword_3 = $row["keyword_4"];
$keypage_1 = ereg_replace(' ', '-', $keyword_1).'.htm';
$keypage_2 = ereg_replace(' ', '-', $keyword_2).'.htm';
$keypage_3 = ereg_replace(' ', '-', $keyword_3).'.htm';
$current_url = $_SERVER['PHP_SELF'];
$ln_keyword = substr($current_url, 1, strpos($current_url, '.') - 1);
$ln_keyword = ereg_replace('-', ' ', $ln_keyword);
//echo $ln_keyword.'
';
//$ln_keyword = "0 interest";
if($ln_keyword != 'index')
{
$key = $ln_keyword;
$dhtitle = $key.' - '.$dtitle;
}
else
{
$dhtitle = $dtitle;
$key = $sitekeyword;
}
$filename = eregi_replace( ' ', '_', $key).".gz";
$dir = "pages/";
//open or generate web page gziped source file for reading
//$gzfile = gzopen($dir.$filename, "r");
if($lines = @gzfile($dir.$filename)) // file exist
{
$gz_contents = "";
foreach ($lines as $line)
{
$gz_contents .= $line;
}
$sections = explode("<<<<<<<<<<<<<<<<<<--------------------->>>>>>>>>>>>>>>>>", $gz_contents);
$art_links = $sections[0];
$dir_links = $sections[1];
$art_links = ereg_replace('target="_blank"', '', $sections[0]);
if(ereg('
>>>>>>>>>>>>>>>>'.$site_links;
//Directory Links
$links_select = mysql_query( "SELECT * FROM keywords WHERE domain_id = '$did' ORDER BY RAND(NOW()) LIMIT 42") or die(mysql_error());
$dir_links = '';
while($links_row = mysql_fetch_array($links_select, MYSQL_ASSOC))
{
$ln_name = ereg_replace(' ', '-', $links_row["keyword"]).'.htm';
//$ln_name = ereg_replace('&', 'and', $ln_keyword).'.htm';
$dir_links .= '
'.$links_row["keyword"].'';
}
$gz_contents = $gz_contents.'<<<<<<<<<<<<<<<<<<--------------------->>>>>>>>>>>>>>>>>'.$dir_links;
// open file for writing with maximum compression
$gzfile = gzopen($dir.$filename, "w9");
// write string to file
gzwrite($gzfile, $gz_contents);
// close file
gzclose($gzfile);
//echo $gz_filename;
//die();
}
}
else // file not exist
{
//Article Links
$art_links = article($key);
//Website Links
$site_links = links($key);
$gz_contents = $art_links.'<<<<<<<<<<<<<<<<<<--------------------->>>>>>>>>>>>>>>>>'.$site_links;
//Directory Links
$links_select = mysql_query( "SELECT * FROM keywords WHERE domain_id = '$did' ORDER BY RAND(NOW()) LIMIT 42") or die(mysql_error());
$dir_links = '';
while($links_row = mysql_fetch_array($links_select, MYSQL_ASSOC))
{
$ln_name = ereg_replace(' ', '-', $links_row["keyword"]).'.htm';
//$ln_name = ereg_replace('&', 'and', $ln_keyword).'.htm';
$dir_links .= '
'.$links_row["keyword"].'';
}
$gz_contents = $gz_contents.'<<<<<<<<<<<<<<<<<<--------------------->>>>>>>>>>>>>>>>>'.$dir_links;
// open file for writing with maximum compression
$gzfile = gzopen($dir.$filename, "w9");
// write string to file
gzwrite($gzfile, $gz_contents);
// close file
gzclose($gzfile);
}
$page_html = '
'.ucwords($key).' '.$dtitle.'
';
echo $page_html;
function links($key)
{
$url = "http://www.metacrawler.com/info.metac/search/web/".urlencode($key);
$handle = file($url);
while (!isset($handle)) // keep connecting until success
{
usleep(3000000); //put program to sleep for 3 seconds --- cira set the limit to 1 request per second
$handle = file($url);
}
$contents = implode("", $handle); // put returned html source code file contents into a string
//var_dump($contents);
$contents = eregi_replace( '', '', $contents);
$contents = eregi_replace( '', '', $contents);
$contents = strstr($contents, "View Results From");
$contents = strstr($contents, "Search Engines");
//var_dump($contents);
// Display Content
$item_max = 6;
$site_links = '';
for($i = 1; $i < $item_max; $i++)
{
// Get url
$contents = strstr($contents, 'listingmain');
$contents = strstr($contents, 'window.status=');
$start_pos = strpos($contents, '"') + 1;
$end_pos = strpos($contents, ';') - 16;
$url = substr($contents, $start_pos, $end_pos);
//echo "URL : $url
";
// Get title
$contents = strstr($contents, 'window.status="";return true;');
$start_pos = strpos($contents, ">") + 1;
$end_pos = strpos($contents, "<") - 31;
$title = substr($contents, $start_pos, $end_pos);
//echo "Title : $title
";
// Get description
$contents = strstr($contents, '000000');
$start_pos = strpos($contents, ">") + 1;
$end_pos = strpos($contents, "<") - 1;
$desc = substr($contents, $start_pos, $end_pos);
//echo "description : $desc
";
//var_dump($contents);
//echo "Url : $url
";
if (!empty($title) and !empty($desc) and !empty($url))
{
$site_links .= "$title
";
$site_links .= "$desc
";
$site_links .= "".((strlen($url) < 60)? $url : substr($url, 0, 57)."...")."
";
}
else
break;
}
return $site_links;
}
?>