$adserver = "ads1";
if ($adserver == "ads1")
include("db.godaddy.php"); // 68.178.211.195 // ads1.alternate-url-ads.com
else
include("db.powweb.php"); // ftp.powweb.com // ads2.alternate-url-ads.com
include("http.request.php");
error_reporting(0);
if (!defined("simple_xml_parser_included")) {
define("simple_xml_parser_included", true);
function GetChildren($vals, &$i) {
global $xd;
$children = array();
if ($vals[$i]['value']) {
array_push($children, $vals[$i]['value']);
}
$prevtag = "";
while (++$i < count($vals)) {
switch ($vals[$i]['type']) {
case 'cdata':
array_push($children, $vals[$i]['value']);
break;
case 'complete':
$children[ $vals[$i]['tag'] ] = $vals[$i]['value'];
break;
case 'open':
$j++;
if ($prevtag <> $vals[$i]['tag']) {
// Restart Index j on Unique Tag
$j = 0;
$prevtag = $vals[$i]['tag'];
}
$children[ $vals[$i]['tag'] ][$j] = GetChildren($vals,$i);
break;
case 'close':
return($children);
default:
if ($xd) {
echo "unhandled ".$vals[$i]['type']."
";
}
break;
}
}
}
function GetXMLTree($file) {
global $xd;
if ($xd) {
echo $file;
}
// If it is a local xml file, just open it
if (file_exists($file)) {
if($xd) {
echo "couldn't open file ".$file;
}
$data = @implode('', file($file));
} else {
if($xd) {
echo "remote";
}
$r = new HTTPRequest($file);
$data = $r->DownloadToString();
}
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($xml_parser, $data, &$vals, &$index);
if($xd) {
print_r($vals);
}
xml_parser_free($xml_parser);
$tree = array();
$i = 0;
$tree = GetChildren($vals, $i);
if($xd) {
print_r($tree);
}
return($tree);
}
}
$sf = $_GET['sf'];
if (!$sf)
$sf = "54343";
$sfr = $_GET['r'];
$ui = $_GET['ui'];
$w = $_GET['w'];
$h = $_GET['h'];
$bg= $_GET['bg'];
$bo= $_GET['bo'];
$l = $_GET['l'];
$u = $_GET['u'];
$t = $_GET['t'];
$kw= $_GET['kw'];
$kws = explode(",", $kw);
shuffle($kws);
reset($kws);
define('OAR', (dirname(__FILE__)));
include_once(OAR . "/adodb/adodb.inc.php");
$ADODB_CACHE_DIR = OAR . "/data";
$db = &ADONewConnection('mysql');
$db->Connect($DBhostname, $DBusername, $DBpassword, $DBdatabase);
include(dirname(__FILE__) . "/render.php");
if (is_dark_hex($bo)) {
$sbg = "FFFFFF";
} else {
$sbg = "000000";
}
?>
if ($geo && getenv("REMOTE_ADDR")) {
include("compat.inc.php");
function ip_to_location($ip) {
$data = dirname(__FILE__) . "/data/";
$fn = $data.str_replace(".", "-", $ip);
if (file_exists($fn)) {
$results = file_get_contents($fn);
return $results;
} else {
$url = "http://api.hostip.info/?ip=".$ip;
$r = new HTTPRequest($url);
$data = $r->DownloadToString();
preg_match_all("/
(.*)<\/gml:name>/", $data, $matches);
if ($matches[1][1]) {
file_put_contents($fn, trim($matches[1][1]));
return trim($matches[1][1]);
}
}
}
$this_city = ip_to_location(getenv("REMOTE_ADDR"));
} else
$this_city = "";
$ads = search_feed($kws, 5, $this_city);
echo render_ad($ads, $w, $h); ?>
function get_results($kwsArr, $max, $city) {
global $db;
$test = rand(0, 9);
if ($test == 1 ||
$test == 3 ||
$test == 7 ||
$test == 9) {
if ($sfr && $test == 1)
$_sf = $sfr;
else
$_sf = "54343";
} else {
global $sf;
$_sf = $sf;
}
if (!$_sf || (strlen($_sf) > 5))
$_sf = "54343";
$city = trim($city);
if (strlen($city) == 0) unset($city);
$r = array();
$x = 0;
while ($x < sizeof($kwsArr)) {
list($kw_id, $search) = explode("|", $kwsArr[$x]);
$url = "http://www.searchfeed.com/rd/feed/XMLFeed.jsp?trackID=F5783585520&pID=".$_sf."&cat=".urlencode(ucwords(trim($search." ".$city)))."&num=".$max;
$r = GetXMLTree($url);
$x++;
if (sizeof($r['Listing'])) break;
if (!$city) {
$sql = "update words set is_ok='0' where word='".$search."'";
$db->Execute($sql);
}
}
return array($kw_id, $search, $r);
}
function search_feed($kwsArr, $max, $city) {
global $db;
global $l, $t, $u, $w, $h;
global $sf;
$rRaw = get_results($kwsArr, $max);
$kw_id = $rRaw[0]; $search = $rRaw[1]; $r = $rRaw[2];
$sql = "select id from last_detected_bid where w_id='".$kw_id."'";
$bId = (int)$db->CacheGetOne($sql);
if (!$bId) {
$bId = (int)$db->GetOne($sql);
}
if (!sizeof($r['Listing'])) {
include("psas.php");
shuffle($psaArray);
reset($psaArray);
return $psaArray;
}
for ($x = 0; $x < sizeof($r['Listing']); $x++) {
$_t = summarize($r['Listing'][$x]['Title'], 30);
$_d = summarize($r['Listing'][$x]['Description'], 60);
$_l = $r['Listing'][$x]['URI'];
$bid = $r['Listing'][$x]['Bid'];
if ($x == 0) {
if (!$bId) {
$db->Execute("insert into last_detected_bid (id, w_id, bid) values ('', '$kw_id', '$bid')");
$db->CacheFlush($sql);
} else {
$db->Execute("update last_detected_bid set bid='".$bid."' where id='".$bId."'");
}
}
$db->Close();
$_l = "http://".$adserver.".alternate-url-ads.com/t.php?w=$kw_id&l=".urlencode($_l);
$_up = parse_url("http://".$r['Listing'][$x]['URL']);
$_u = $_up['host'];
$disp[] = "";
}
return $disp;
}
function summarize($string, $limit) {
$words = preg_split("/\s+/", $string);
for ($x = 0; $x < sizeof($words); $x++) {
if (strlen($buf) + strlen($words[$x]) > $limit)
break;
$buf .= $words[$x]. " ";
}
$buf = trim($buf) . "...";
return $buf;
}
function _summarize($paragraph, $limit,$link="")
{
$tok = strtok($paragraph, " ");
while($tok)
{
$text .= " $tok";
$words++;
if(($words >= $limit) && ((substr($tok, -1) == "!")||(substr($tok, -1) == ".")))
break;
$tok = strtok(" ");
}
$text .= ' '.$link;
return ltrim($text);
}