From: Maxious Date: Sun, 04 Sep 2011 15:32:27 +0000 Subject: Try to avoid bots in analytics and improve page titles X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=e1bdff3ead7371e46f0fd527ad0af3f82433aa99 --- Try to avoid bots in analytics and improve page titles --- --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -32,7 +32,7 @@ -' . $pageTitle . ' +' . $pageTitle . ' - Canberra Bus Timetable --- a/include/common.inc.php +++ b/include/common.inc.php @@ -31,7 +31,7 @@ function isDebugServer() { - return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "10.1.0.4" || $_SERVER['SERVER_NAME'] == + return isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "10.1.0.4" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1") ; } @@ -47,7 +47,9 @@ function isAnalyticsOn() { - return !isDebugServer(); + $user_agent = $_SERVER['HTTP_USER_AGENT']; + return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) && +!preg_match('/baidu/i', $user_agent); } function isDebug($debugReason = "other") { --- a/updatedb.php +++ b/updatedb.php @@ -2,9 +2,6 @@ if ( php_sapi_name() == "cli") { include ('include/common.inc.php'); $conn = pg_connect("dbname=transitdata user=postgres password=snmc host=localhost") or die('connection failed'); -$pdconn = new PDO("pgsql:dbname=transitdata;user=postgres;password=snmc;host=localhost"); - - // Unzip cbrfeed.zip, import all csv files to database $unzip = true; $zip = zip_open(dirname(__FILE__) . "/cbrfeed.zip"); @@ -34,18 +31,8 @@ echo "Opening $file \n"; $line = 0; $handle = fopen($tmpdir . $file, "r"); - if ($tablename =="stop_times") { - $stmt = $pdconn->prepare("insert into stop_times (trip_id,stop_id,stop_sequence) values(:trip_id, :stop_id, :stop_sequence);"); - $stmt->bindParam(':trip_id',$trip_id); - $stmt->bindParam(':stop_id',$stop_id); - $stmt->bindParam(':stop_sequence',$stop_sequence); - } - - while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { - if ($line == 0) { - - } else { + if ($line > 0) { $query = "insert into $tablename values("; $valueCount = 0; foreach ($data as $value) { @@ -57,22 +44,14 @@ } else { $query.= "');"; } - if ($tablename =="stop_times" && $data[1] == "") { - // $query = "insert into $tablename (trip_id,stop_id,stop_sequence) values('{$data[0]}','{$data[3]}','{$data[4]}');"; - $trip_id=$data[0]; - $stop_id=$data[3]; - $stop_sequence=$data[4]; - } + if ($tablename =="stop_times" && $data[1] == "") { + $query = "insert into $tablename (trip_id,stop_id,stop_sequence) values('{$data[0]}','{$data[3]}','{$data[4]}');"; + } } - if ($tablename =="stop_times") { - $stmt->execute(); - } - else { - $result = pg_query($conn, $query); - } + $result = pg_query($conn, $query); $line++; - if ($line % 10000 == 0) echo "$line records... ".date('c')."\n"; + if ($line % 10000 == 0) echo "$line records... \n"; } fclose($handle); echo "Found a total of $line records in $file.\n";