list.php 3.66 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

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
8
$models = selective_scandir($base);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
9 10 11 12 13
$res = "";

foreach($models as $model){

    $model_path = "$base/$model";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
14
    $thumb = "$model_path/$THUMBNAME";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
15 16 17
    
    $versions = selective_scandir($model_path);
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
18 19 20 21 22 23 24 25 26 27 28 29
    // create thumb
    create_thumbnail($model_path,$versions,$thumb);
    
    if (!is_file($thumb)){
        $thumb="";
    }
    
    $res .= "<model name='$model' thumb='$thumb'>\n";
    
    // read kml
    $res .= "\t<map>\n".parse_kml("$base/$model/$model.kml")."\t</map>\n";
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
30 31
    foreach($versions as $version){
        
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
32 33 34 35 36 37 38 39 40 41 42
        $res .= "\t<version name='$version'>\n";
        
        $comments = "-";
        $readme = "$model_path/$version/$READMENAME";
        if (is_file($readme)){
            $comments = trim(file_get_contents($readme),"\t\n\r");
        }
        
        $res .= "\t\t<comments>$comments</comments>\n";
        
        $res .= "\t</version>\n";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
43 44 45 46 47 48 49

    }

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

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
50 51
return_xml($res);

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
//functions

function selective_scandir($path){

    $results = Array();

    $contents = scandir($path);

    foreach($contents as $item){
        if ($item!='.'&&$item!='..'&&is_dir("$path/$item")){
            array_push($results,$item);
        }
    }
    
    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
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
function create_thumbnail($path,$vpaths,$thumbname){

    if (!is_file($thumbname)){
    
        if (count($vpaths)>=1){
        
            $srcpath = "$path/{$vpaths[0]}";
            
            $files = scandir($srcpath);
            foreach($files as $file){
            
                $test = preg_match('/(texture-bgnd-ext)/',$file);
            
                if ($test){
                    $file = "$srcpath/$file";
                    
                    if (extension_loaded('imagick')){
                        
                        $imagick = new Imagick($file);
                        
                        $imagick->trimImage(0);
                        
                        $w = $imagick->getImageWidth();
                        $h = $imagick->getImageHeight();
                        
                        $imagick->borderImage('black', 100, 100);
                        
                        //$imagick->cropImage($w/2, $h/4, $w/4, $h/4);
                        
                        $imagick->thumbnailImage(200, 100, true, true);
                        
                        $imagick->writeImage($thumbname);
                        
                    }
                    break;
                }
                
                /*
                $pinfo = pathinfo("$srcpath/$file");
                if ($pinfo['extension']=="jpeg"){
                    $file = "$srcpath/$file";
                    echo "go-go-go with $file";
                    break;
                }
                */
            }
    
        }
    
    }
    
    return 0;

}

function parse_kml($file){

    $res = "";

    if (is_file($file)){
    
        $xml = simplexml_load_file($file);
        
        $recs = $xml->Document->children();
        
        foreach($recs as $rec){
            $res .= "\t".$rec->Camera->asXML()."\n";
        }
        
    }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;
    
}

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
167
?>