#!/usr/bin/php
<?php
define("VERSION", "0.1.4");
define("REQUIRED_PHP_VERSION", "4.3.0");
error_reporting (E_ALL);

  if (version_compare(phpversion(), REQUIRED_PHP_VERSION)<0) {
    die("Error: TightURL ".VERSION." needs PHP >= ".REQUIRED_PHP_VERSION." (you are using ".phpversion().")");
  }

  if (file_exists("tighturl.tltpattern.inc.php")) include("tighturl.tltpattern.inc.php");
  if (file_exists("tighturl.urlpattern.inc.php")) include("tighturl.urlpattern.inc.php");
  if (file_exists("tighturl.ptcpattern.inc.php")) include("tighturl.ptcpattern.inc.php");
  if (file_exists("tighturl.blippattern.inc.php")) include("tighturl.blippattern.inc.php");
  (include("tighturl.lib.inc.php")) or die("Error: cannot load tighturl.lib.inc.php");
  if (file_exists("tighturl.config.inc.php")) include("tighturl.config.inc.php");

  // Connect to MySQL, open database.
  $conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die("Error: Cannot connect to database.");
  $db = mysql_select_db($dbname, $conn) or die("Error: Cannot select database. ". mysql_error());

  // Query records with status normal, and added within last 10 days or records with status normal and more than 7 hits and hit within the last 7 days
  TightURL_KillBot("SELECT * FROM $dbtable where status=0 && (DATE_SUB(CURDATE(), INTERVAL 10 DAY) <= adddate || (hits > 7 && DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= lasthit)) ORDER BY id;");
  TightURL_NewReport("SELECT * FROM $dbtable where (status=0) && (checkcount < 2) ORDER BY id;");
  exit;

?>
