#!/usr/local/bin/php -q db=DB; $authQuery=new query; $authQuery->conn_id=&$connection->conn_id; $urlQuery=new query; $urlQuery->conn_id=&$connection->conn_id; $counter=0; # Now connect to the database $connection->conn_id=@mysql_connect(DB_HOST, DB_USER_NAME, DB_PASSWD); if(!$connection->conn_id) { mail(ADMIN_EMAIL, EMAIL_SUBJECT, 'The script failed to connect to the database.'); exit; } # And select the database we are working against else { if(mysql_select_db($connection->db, $connection->conn_id)!=true) { $connection->error=mysql_error($connection->conn_id); mail(ADMIN_EMAIL, EMAIL_SUBJECT, $connection->error); exit; } } # Let's first open the files with our search terms. $author_terms=@file(AUTHOR_FILE); $url_terms=@file(URL_FILE); $auth_size=count($author_terms); $url_size=count($url_terms); # Let's check that we actually got arrays from those files. if( (!$author_terms)||(!$url_terms) ) // && (is_array($author_terms)) ) { mail(ADMIN_EMAIL, 'Your spam cleaning script', 'It appears that we failed to open one or both of the terms files'); mysql_close($connection->conn_id); exit; } # Iterate over the lists and delete the junk using the above queries. Authors first. for($counter=0; $counter<$auth_size; ++$counter) { # Clean up author term a little first $author_terms[$counter]=trim($author_terms[$counter]); str_replace("\n", '', $author_terms[$counter]); if(empty($author_terms[$counter])) { continue; } $SQL='DELETE FROM '.AUTHOR_TABLE.' WHERE LOCATE(\''.$author_terms[$counter].'\', '.AUTHOR_FIELD.') != 0'; # Now search and delete it from the table $authQuery->res_id=mysql_query($SQL, $connection->conn_id); if(!$authQuery->res_id) { $authQuery->error=mysql_error($authQuery->conn_id); mail(ADMIN_EMAIL, EMAIL_SUBJECT, $authQuery->error); exit; } } # Now urls for($counter=0; $counter<$url_size; ++$counter) { # Clean up author term a little first $url_terms[$counter]=trim($url_terms[$counter]); str_replace("\n", '', $url_terms[$counter]); if(empty($url_terms[$counter])) { continue; } $SQL='DELETE FROM '.URL_TABLE.' WHERE LOCATE(\''.$url_terms[$counter].'\', '.URL_FIELD.') != 0'; # Now search and delete it from the table $urlQuery->res_id=mysql_query($SQL, $connection->conn_id); if(!$urlQuery->res_id) { $urlQuery->error=mysql_error($urlQuery->conn_id); mail(ADMIN_EMAIL, EMAIL_SUBJECT, $urlQuery->error); exit; } } # That should be all. Close up shop and email the boss. mysql_close($connection->conn_id); mail(ADMIN_EMAIL, EMAIL_SUBJECT, 'Execution of the spam clean up file ran with success.'); ########################################################################################################### # Some data structures class connection { var $conn_id; var $error; var $db; } class query { var $conn_id; var $res_id; var $error; } class tracking { var $search_term; var $deleted_rows; var $date; }