1
|
<?php
|
2
|
|
3
|
require_once(dirname(__FILE__).'/../constants.inc.php');
|
4
|
|
5
|
class TilesGeneratorException extends Exception {}
|
6
|
class TilesGeneratorRightsException extends TilesGeneratorException {}
|
7
|
class TilesGeneratorScriptException extends TilesGeneratorException {}
|
8
|
|
9
|
class TilesGenerator {
|
10
|
private $panorama;
|
11
|
|
12
|
const SCRIPT_RELATIVE_PATH = 'to_tiles/gen_tiles.sh';
|
13
|
|
14
|
public function __construct($img_path, $panorama) {
|
15
|
|
16
|
|
17
|
|
18
|
$this->panorama = $panorama;
|
19
|
$this->img_path = $img_path;
|
20
|
}
|
21
|
|
22
|
public function prepare() {
|
23
|
$err = false;
|
24
|
$pano_path = $this->panorama->tiles_path();
|
25
|
|
26
|
if (! is_dir(PANORAMA_PATH)) {
|
27
|
if (! mkdir(PANORAMA_PATH)) {
|
28
|
$err = "le répertoire \"PANORAMA_PATH\" n'est pas accessible et ne peut être créé";
|
29
|
}
|
30
|
} else {
|
31
|
if (file_exists($pano_path)) {
|
32
|
if ($this->panorama->has_tiles()) {
|
33
|
$err = sprintf("\"%s\" contient déjà un découpage de panorama.",
|
34
|
$pano_path);
|
35
|
}
|
36
|
} else {
|
37
|
mkdir($pano_path);
|
38
|
}
|
39
|
}
|
40
|
if ($err) {
|
41
|
throw (new TilesGeneratorRightsException($err));
|
42
|
}
|
43
|
|
44
|
}
|
45
|
|
46
|
public function mk_command() {
|
47
|
|
48
|
|
49
|
$c = sprintf('%s/%s -p "%s" "%s"',
|
50
|
CELUTZ_PATH, $this::SCRIPT_RELATIVE_PATH,
|
51
|
$this->panorama->tiles_prefix(), $this->img_path);
|
52
|
return escapeshellcmd($c);
|
53
|
}
|
54
|
|
55
|
public function process() {
|
56
|
$err = false;
|
57
|
if ($fp = popen($this->mk_command(), 'r')) {
|
58
|
while (!feof($fp)) {
|
59
|
$results = fgets($fp, 4096);
|
60
|
if (strlen($results) == 0) {
|
61
|
|
62
|
flush();
|
63
|
} else {
|
64
|
$tok = strtok($results, "\n");
|
65
|
while ($tok !== false) {
|
66
|
echo htmlspecialchars(sprintf("%s\n",$tok))."<br/>";
|
67
|
flush();
|
68
|
$tok = strtok("\n");
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
if (pclose($fp) !== 0) {
|
73
|
$err = "Opération en échec durant l'exécution du script";
|
74
|
}
|
75
|
} else {
|
76
|
$err = 'Opération en échec à l\'ouverture du script !';
|
77
|
}
|
78
|
|
79
|
if ($err) {
|
80
|
throw (new TilesGeneratorScriptException($err));
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
|
85
|
?>
|