forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FN_igc2kmz.php
110 lines (82 loc) · 3.27 KB
/
FN_igc2kmz.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
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
<?
//************************************************************************
// Leonardo XC Server, http://www.leonardoxc.net
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: FN_igc2kmz.php,v 1.19 2011/01/31 15:04:47 manolis Exp $
//
//************************************************************************
function igc2kmz($file,$outputFile,$timezone,$flightID) {
global $CONF,$CONF_tables_prefix,$baseInstallationPath,$db;
$str="";
$version=$CONF['googleEarth']['igc2kmz']['version'];
$kmzFile=$outputFile.".$version.kmz";
deleteOldKmzFiles($outputFile,$version);
// exit;
if ( is_file($kmzFile) ) return $version;
$python=$CONF['googleEarth']['igc2kmz']['python'];
putenv('PYTHON_EGG_CACHE='.dirname(__FILE__).'/data/tmp');
// put some env for python2.5?
// putenv("PATH=".$CONF['googleEarth']['igc2kmz']['python'] );
putenv("PATH=/usr/local/bin/" );
$path=realpath($CONF['googleEarth']['igc2kmz']['path']);
if (! defined('SQL_LAYER') ) define('SQL_LAYER','mysql');
global $phpbb3AbsPath, $dbhost,$dbname,$dbuser,$dbpasswd;
$dbpasswdCon=$dbpasswd;
if (!$dbpasswdCon) $dbpasswdCon=$db->password;
$dbhostCon=$dbhost;
if (!$dbhostCon) $dbhostCon=$db->server;
if (!$dbhostCon) $dbhostCon='localhost';
$engine=SQL_LAYER."://".$db->user.':'.$dbpasswdCon.'@'.$dbhostCon.'/'.$db->dbname;
$cmd="$python $path/bin/leonardo2kmz.py";
$cmd.=" --engine '$engine'";
$cmd.=" --table-prefix=$CONF_tables_prefix";
$cmd.=" --directory '".realpath(dirname(__FILE__))."'";
// $cmd.=" --igcpath '".dirname(__FILE__).'/'.$CONF['paths']['intermediate']."'";
// $cmd.=" --directory '".realpath(dirname(__FILE__).'/../..')."'";
$cmd.=" --url 'http://".$_SERVER['SERVER_NAME']."$baseInstallationPath'";
// $cmd.=" --icon '$baseInstallationPath/templates/basic/tpl/leonardo_logo.gif' ";
// $cmd.=" --photos_path '".$CONF['paths']['photos']."' ";
// $cmd.=" --photos_url '$baseInstallationPath/'".$CONF['paths']['photos']."'' ";
//DEFAULT_PHOTOS_PATH = 'data/flights/photos/%YEAR%/%PILOTID%'
//DEFAULT_PHOTOS_URL = '/modules/leonardo/data/flights/photos/%YEAR%/%PILOTID%'
$cmd.=" --output '$kmzFile'";
$cmd.=" --tz-offset $timezone";
$cmd.=" --igc-path=".$CONF['paths']['intermediate']." "; // data/flights/intermediate/%YEAR%/%PILOTID%
$cmd.=" $flightID";
DEBUG('igc2kmz',1,"igc2kmz: $cmd <BR>");
exec($cmd,$res);
if (0) {
//echo "timezone: $timezone<br>";
echo "cmd: $cmd<BR>";
print_r($res);
//print_r($db);
//echo "$dbhost , $dbname ,$dbuser ,$dbpasswd @";
exit;
}
return $version;
}
function deleteOldKmzFiles($file,$version) {
// echo "$file,$version #";
$dir=dirname($file);
$name=basename($file).'.';
$namelen=strlen($name);
if ( !is_dir($dir) ) return;
$current_dir = opendir($dir);
while($entryname = readdir($current_dir)){
// echo "^ $entryname ^<BR> ";
if (preg_match("/$name([\d\.]+)\.kmz$/",$entryname,$matches) ) {
// print_r($matches);
if ($matches[1] != $version ) {
unlink("${dir}/${entryname}");
}
}
}
closedir($current_dir);
}
?>