list.php 3.55 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4
<?php

$base = "models";

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
5 6
$THUMBNAME = "thumb.jpeg";
$READMENAME = "README.txt";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
7

8 9 10 11 12 13 14
$showall = false;

if (isset($_GET['showall'])){
  $showall = true;
}

$models = selective_scandir($base,false);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
15 16 17 18 19
$res = "";

foreach($models as $model){

    $model_path = "$base/$model";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
20
    $thumb = "$model_path/$THUMBNAME";
21 22 23

    $versions = selective_scandir($model_path,$showall);

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
24 25
    // create thumb
    create_thumbnail($model_path,$versions,$thumb);
26

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
27 28 29
    if (!is_file($thumb)){
        $thumb="";
    }
30

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
31
    $res .= "<model name='$model' thumb='$thumb'>\n";
32

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
33 34
    // read kml
    $res .= "\t<map>\n".parse_kml("$base/$model/$model.kml")."\t</map>\n";
35

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
36
    foreach($versions as $version){
37

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
38
        $res .= "\t<version name='$version'>\n";
39

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
40 41 42 43 44
        $comments = "-";
        $readme = "$model_path/$version/$READMENAME";
        if (is_file($readme)){
            $comments = trim(file_get_contents($readme),"\t\n\r");
        }
45

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
46
        $res .= "\t\t<comments>$comments</comments>\n";
47

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
48
        $res .= "\t</version>\n";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
49 50 51 52

    }

    $res .= "</model>\n";
53

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
54 55
}

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
56 57
return_xml($res);

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
58 59
//functions

60
function selective_scandir($path,$showall){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
61 62 63 64 65 66 67

    $results = Array();

    $contents = scandir($path);

    foreach($contents as $item){
        if ($item!='.'&&$item!='..'&&is_dir("$path/$item")){
68 69 70 71 72 73 74 75
            if ($showall){
              array_push($results,$item);
            }else{
              if (($item[0]!=".")&&($item[0]!="_")){
                array_push($results,$item);
              }
            }

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
76 77
        }
    }
78

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    return $results;

}

function return_xml($str){

    $str = "<?xml version='1.0'  standalone='yes'?>\n<Document>\n$str</Document>";

    header("Content-Type: text/xml");
    header("Content-Length: ".strlen($str)."\n");
    header("Pragma: no-cache\n");
    printf($str);

}

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
94 95 96
function create_thumbnail($path,$vpaths,$thumbname){

    if (!is_file($thumbname)){
97

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
98
        if (count($vpaths)>=1){
99

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
100
            $srcpath = "$path/{$vpaths[0]}";
101

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
102 103
            $files = scandir($srcpath);
            foreach($files as $file){
104

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
105
                $test = preg_match('/(texture-bgnd-ext)/',$file);
106

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
107 108
                if ($test){
                    $file = "$srcpath/$file";
109

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
110
                    if (extension_loaded('imagick')){
111

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
112
                        $imagick = new Imagick($file);
113

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
114
                        $imagick->trimImage(0);
115

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
116 117
                        $w = $imagick->getImageWidth();
                        $h = $imagick->getImageHeight();
118

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
119
                        $imagick->borderImage('black', 100, 100);
120

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
121
                        //$imagick->cropImage($w/2, $h/4, $w/4, $h/4);
122

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
123
                        $imagick->thumbnailImage(200, 100, true, true);
124

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
125
                        $imagick->writeImage($thumbname);
126

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
127 128 129
                    }
                    break;
                }
130

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
131 132 133 134 135 136 137 138 139
                /*
                $pinfo = pathinfo("$srcpath/$file");
                if ($pinfo['extension']=="jpeg"){
                    $file = "$srcpath/$file";
                    echo "go-go-go with $file";
                    break;
                }
                */
            }
140

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
141
        }
142

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
143
    }
144

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
145 146 147 148 149 150 151 152 153
    return 0;

}

function parse_kml($file){

    $res = "";

    if (is_file($file)){
154

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
155
        $xml = simplexml_load_file($file);
156

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
157
        $recs = $xml->Document->children();
158

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
159 160 161
        foreach($recs as $rec){
            $res .= "\t".$rec->Camera->asXML()."\n";
        }
162

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176
    }else{
        $res = <<<TEXT
<Camera>
    <longitude>-111.9328843</longitude>
    <latitude>40.7233861</latitude>
    <altitude>1305.1</altitude>
    <heading>0</heading>
    <tilt>90</tilt>
    <roll>00</roll>
</Camera>
TEXT;
    }

    return $res;
177

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
178 179
}

180
?>