0) { $target_list=getTargets($uri_id); echo json_encode($target_list); } function getUriID($uri='') { GLOBAL $mysqli; if (filter_var($uri, FILTER_VALIDATE_URL)) { $url_bits = parse_url($uri); if (!isset($url_bits['scheme'])) $url_bits['scheme']=''; if (!isset($url_bits['path'])) $url_bits['path']=''; if (!isset($url_bits['host'])) $url_bits['host']=''; $final_uri = $url_bits['scheme'].'://'.$url_bits['host'].rtrim($url_bits['path'], '/\\'); } else { RETURN 0; } //blacklisted URI? privacy policy, serp, etc if (!checkBlacklist($uri)) RETURN 0; //is this site whitelisted? $sql="SELECT id FROM site WHERE active=1 AND hostname='".$url_bits['host']."'"; if ($result = $mysqli->query($sql)) { if ($result->num_rows == 0) RETURN 0; } $sql="SELECT id FROM uri WHERE uri='$final_uri'"; if ($result = $mysqli->query($sql)) { if ($result->num_rows > 0) { $obj = $result->fetch_object(); //inc imp cnt $sql = " INSERT INTO uri_metric (mdate, uri_id) VALUES (CURDATE(), $obj->id) ON DUPLICATE KEY UPDATE imp_cnt=imp_cnt+1"; $mysqli->query($sql); RETURN $obj->id; } else { $sql="INSERT INTO uri (uri, added_dts) VALUES ('$final_uri', NOW())"; //echo $sql; $mysqli->query($sql); } } else { } RETURN 0; } function getTargets($uri_id) { GLOBAL $mysqli; //if (!isset($_GET['uri'])) die('no get uri'); $retval=array(); //if this is a test, just pull all targets $url_where = "1=1"; if ($uri_id <> 65) $url_where = "uri_id=$uri_id"; $sql=" SELECT keyword, content_block FROM uri_target LEFT JOIN target on target_id=target.id WHERE $url_where AND target.active=1 AND kwx_status=1 GROUP BY keyword ORDER BY target.priority DESC, LENGTH(keyword) DESC"; //echo $sql; if ($result = $mysqli->query($sql)) { for ($i=0; $obj = $result->fetch_object(); $i++) { $retval[$i]['keyword'] = $obj->keyword; $retval[$i]['content_block'] = $obj->content_block; } //$retval = substr($retval, 0, -1); } //echo 'rv: '.$retval; RETURN $retval; //RETURN '"joint pain","pain medications","supplements","topical creams","bro"'; } function checkBlacklist($uri='') { GLOBAL $mysqli; $uri=mysqli_real_escape_string($mysqli, $uri); //is this site whitelisted? $sql="SELECT * FROM uri_blacklist WHERE LOCATE(path_substring, '$uri') > 0 AND LENGTH(path_substring) > 3"; if ($result = $mysqli->query($sql)) { if ($result->num_rows > 0) RETURN FALSE; } RETURN TRUE; } ?>