All pastes #265413 Raw Edit

Stuff

public text v1 · immutable
·published 2006-12-03 07:18 UTC
rendered paste body
<?
chdir(dirname(__FILE__)); 

define ( "DEAD_SECONDS" , 2 * 86400 ); //how many seconds can a map be dead?
define ( "DEAD_DAYS_LIMIT" , 1550 ); //how many maps to search for inactivity per exec
define ( "LIMIT" , 1550 ); //how many maps to draw updates on per exec

include "_init.php";

include "includes/draw.class.php";

/* clean maps that have not had a hit for DEAD_SECONDS seconds */

$random_sample = mysql_query ( "SELECT * FROM ".TBL_MAPS." WHERE dateAdded<".(time()-DEAD_SECONDS)." ORDER BY rand() LIMIT " . DEAD_DAYS_LIMIT );

while ( $s = mysql_fetch_array ( $random_sample ) ){

      $last_hit = mysql_fetch_array ( mysql_query ( "SELECT * FROM ".TBL_VISITORS." WHERE mapID='$s[mapID]' ORDER BY date DESC LIMIT 1" ) );

      if ( $last_hit['date'] < ( time - DEAD_SECONDS ) ){

         if ( is_file( "large_user_maps/$s[mapID].png" ) ){ unlink ( "large_user_maps/$s[mapID].png" ); }
         if ( is_file( "small_user_maps/$s[mapID].png" ) ){ unlink ( "small_user_maps/$s[mapID].png" ); }

         mysql_query ( "DELETE FROM ".TBL_MAPS." WHERE mapID='$s[mapID]'" );
         mysql_query ( "DELETE FROM ".TBL_VISITORS." WHERE mapID='$s[mapID]'" );
         mysql_query ( "DELETE FROM ".TBL_VISITORS_LOG." WHERE mapID='$s[mapID]'" );

      }

}

/* this script loops through maps, grabs new co-ordinates and invokes draw class */

$maps = mysql_query ( "SELECT map.icon_small_owner,map.icon_large_owner,map.icon_large_visitor,map.icon_small_visitor,map.updateStamp,map.textOwner,map.textVisitor,map.mapID,map.mapStyle,reg.longitude,reg.latitude FROM ".TBL_MAPS." map, ".TBL_REGIONS." reg WHERE map.regionID=reg.regionID ORDER BY map.updateStamp ASC LIMIT " . LIMIT );

while ( $m = mysql_fetch_array ( $maps ) ){

   $draw = new draw;
   
   $draw -> init_user_map ( $m['mapID'] , $m['mapStyle'] , $m['latitude'] , $m['longitude'] , $m['icon_large_owner'] ,  $m['icon_small_owner'] , $m['textOwner'] , $m['textVisitor'] ,  $m['icon_large_visitor'] ,  $m['icon_small_visitor']  );

   $new_coords = mysql_query ( "SELECT * FROM ".TBL_VISITORS." vis, ".TBL_REGIONS." reg WHERE vis.regionID = reg.regionID && vis.mapID='$m[mapID]' && vis.date > '$m[updateStamp]'" );

   if ( mysql_num_rows ( $new_coords ) > 0 ){

      $draw -> prep_draw();

      while ( $o = mysql_fetch_array ( $new_coords ) ){

            $draw -> plot ( $o['latitude'] , $o['longitude'] , $m['icon_large_visitor'] ,  $m['icon_small_visitor'] );

      }

      $draw -> plot ( $m['latitude'] , $m['longitude'] , $m['icon_large_owner'] ,  $m['icon_small_owner'] );

      $total = mysql_fetch_array ( mysql_query ( "SELECT sum(count) as total_count FROM ".TBL_VISITORS." WHERE mapID='$m[mapID]'" ) );
      $draw -> add_count ($total['total_count'],$m['mapStyle']);

      $draw -> finish_draw();

   }

   mysql_query ( "UPDATE ".TBL_MAPS." SET updateStamp='".time()."' WHERE mapID='$m[mapID]'" );

}

include "_dinit.php";

?>