source: subversion/sites/other/tilesAtHome/lib/checkupload.inc @ 3655

Last change on this file since 3655 was 2963, checked in by ojw, 13 years ago

remove tests

File size: 1.7 KB
Line 
1<?php
2
3#-------------------------------------------------------------------
4# Looks at an uploaded directory, and tests whether it is one
5# complete tileset
6#
7# Returns (valid,x,y,layer) as array, where x,y are at zoom-12 and layer is a string
8#-------------------------------------------------------------------
9function CheckUploadDir($Dir){
10
11  $dp = opendir($Dir);
12  if(!$dp){
13     print "No such $Dir\n";
14     return(array(0,0,0,""));
15   }
16
17  $Count = 0;
18  $XExpect = -1;
19  $YExpect = -1;
20  $LExpect = "";
21
22  while($Filename = readdir($dp)){
23
24    if($Filename != ".." && $Filename != "."){
25      if(preg_match("/(\w+)_(\d+)_(\d+)_(\d+)\.png/", $Filename, $Matches)){
26        $Layer = $Matches[1];
27        $Z = $Matches[2];
28        $X = $Matches[3];
29        $Y = $Matches[4];
30     
31        list($Valid,$X2,$Y2) = WhichTileset($X,$Y,$Z);
32        if($Valid != 1){
33          print "Tile not in any tileset: $Filename\n";
34          return(array(0,0,0,""));
35        }
36        printf("%d: %d,%d,%d in layer %s = %d, %d\n", $Count,$X,$Y,$Z,$Layer,$X2,$Y2);
37       
38        if($Count == 0){
39          // First time: store the tileset
40          $XExpect = $X2;
41          $YExpect = $Y2;
42          $LExpect = $Layer;
43        }
44        else{
45          // Every other time: check the tileset is same as first one
46          if($XExpect != $X2){print "X bad\n"; return(array(0,0,0));}
47          if($YExpect != $Y2){print "Y bad\n"; return(array(0,0,0));}
48          if($LExpect != $Layer){print "L bad\n"; return(array(0,0,0));}
49        }
50
51        $Count++;
52      }
53      else{
54        print "$Filename doesn't match";
55        return(array(0,0,0,""));
56      }
57    }
58  }
59
60  if($Count != 1365){
61    print "Too few images ($Count)\n";
62    return(array(0,0,0,""));
63  }
64  return(array(1,$X2,$Y2,$Layer));
65}
66
67?>
Note: See TracBrowser for help on using the repository browser.