Advertisement
Darkimmortal

sprays.php cron

Aug 26th, 2012
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2.     chdir(dirname(__FILE__));
  3.    
  4.     define("OUTDIR", "~~~");
  5.     define("INDIR", "~~~");
  6.     define("DELETEDAYS", "30");
  7.     define("FORMAT", "gif");
  8.    
  9.     mysql_pconnect("localhost", "~~~", "~~~");
  10.     mysql_select_db("sourcemod");
  11.     $res = mysql_query("SELECT * FROM sprays WHERE datediff(NOW(), firstdate) < ".DELETEDAYS." or (date > 0 and datediff(NOW(), date) < ".DELETEDAYS.")");
  12.     chdir(OUTDIR);
  13.    
  14.     $done = array();
  15.     $cmd = "";
  16.     echo "There were ".mysql_num_rows($res)." files found to be processed.";
  17.     while($row = mysql_fetch_assoc($res)){
  18.         $out = '';
  19.         echo "Processing: " . $row['filename']." \n";
  20.         if(!file_exists(INDIR."/{$row['filename']}.dat"))
  21.         {
  22.             echo "\t File does not exist in ". INDIR . "... Skipping. \n";
  23.             continue;
  24.         }
  25.        
  26.         $done[$row['filename']] = true;
  27.        
  28.         if(file_exists(OUTDIR."/{$row['filename']}.".FORMAT))
  29.         {
  30.             echo "\t File exists in ". OUTDIR . "... Skipping. \n";
  31.             continue;
  32.         }
  33.        
  34.         if(!copy(INDIR."/{$row['filename']}.dat", OUTDIR."/{$row['filename']}.vtf"))
  35.          {
  36.             echo "\t File failed to copy... Skipping. \n";
  37.             continue;
  38.         }
  39.         exec("/usr/local/bin/vtfconv ".escapeshellarg($row['filename']).".vtf", $out);
  40.         $output = implode("\n", $out);
  41.         if(strpos($output, "Could not open file...exiting") !== false)
  42.         {
  43.             echo "\t VTFConv could not open the file... Skipping. \n";
  44.             continue;
  45.         }
  46.        
  47.         $derp = 0;
  48.         $src = array();
  49.         while(file_exists(OUTDIR."/{$row['filename']}.vtf.{$derp}.png")){
  50.             $src[]="{$row['filename']}.vtf.{$derp}.png";
  51.             $derp ++;
  52.         }
  53.        
  54.         if($derp < 1){
  55.             echo "Failed to convert ".OUTDIR."/{$row['filename']}.vtf\n";
  56.             continue;
  57.         }
  58.         exec("convert -delay 25 -loop 0 -set dispose background ".implode(" ", $src)." {$row['filename']}.gif");
  59.        
  60.        
  61.         echo "\t Saved {$derp} frame(s) to ".OUTDIR."/{$row['filename']}.".FORMAT."\n";
  62.  
  63.     }
  64.    
  65.     $files = array_merge(array(), (array)glob(OUTDIR."/*.png", GLOB_MARK));
  66.     foreach($files as $file){
  67.         unlink($file);
  68.     }
  69.    
  70.     $files = glob(OUTDIR."/*.".FORMAT, GLOB_MARK);
  71.     foreach($files as $file){
  72.         $fid = str_replace(".".FORMAT, "", substr($file, strrpos($file, "/")+1));
  73.         if(!array_key_exists($fid, $done)){
  74.             unlink($file);
  75.             @unlink(INDIR."/{$fid}.dat");
  76.             @unlink(OUTDIR."/{$fid}.vtf");
  77.             @unlink(INDIR."/{$fid}.dat.ztmp");
  78.         }
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement