1 |
1 |
<?php
|
2 |
2 |
require_once(dirname(__FILE__).'/../constants.inc.php');
|
|
3 |
|
|
4 |
//
|
|
5 |
class PanoramaFormatException extends Exception {
|
|
6 |
/** If the files organization is not correct for a panorama, we can't let it go...
|
|
7 |
*/
|
|
8 |
}
|
|
9 |
|
3 |
10 |
class site_point {
|
4 |
11 |
/** Defines a point, with a panorama
|
5 |
12 |
*/
|
... | ... | |
11 |
18 |
|
12 |
19 |
public function __construct($dir) {
|
13 |
20 |
// si $dir n'est pas un répertoire il ne s'agit pas d'un panorama.
|
14 |
|
if (!is_dir($dir)) return;
|
|
21 |
if (!is_dir($dir)) {
|
|
22 |
throw new PanoramaFormatException("$dir does not contain a panorama");
|
|
23 |
}
|
15 |
24 |
$this->base_dir = $dir;
|
16 |
|
$dir_fd = opendir($this->base_dir);
|
17 |
|
|
18 |
|
while (false !== ($file = readdir($dir_fd))) {
|
19 |
|
|
20 |
|
if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
|
21 |
|
$this->prefix = $reg[1];
|
22 |
|
|
23 |
|
break;
|
24 |
|
}
|
25 |
|
}
|
26 |
|
closedir($dir_fd);
|
27 |
|
if ($this->prefix === false) return false;
|
28 |
|
$this->parse_and_cache_params();
|
|
25 |
$this->prefix = basename($dir);
|
29 |
26 |
}
|
30 |
27 |
|
31 |
28 |
public function params_path() {
|
... | ... | |
34 |
31 |
|
35 |
32 |
private function parse_and_cache_params() {
|
36 |
33 |
if (is_file($this->params_path())) {
|
37 |
|
$this->params = @parse_ini_file($this->params_path());
|
|
34 |
$params = parse_ini_file($this->params_path());
|
|
35 |
if ($params) {
|
|
36 |
$this->params = $params;
|
|
37 |
return $params;
|
|
38 |
}
|
38 |
39 |
}
|
|
40 |
return array();
|
39 |
41 |
}
|
40 |
42 |
|
41 |
43 |
public function get_params() {
|
42 |
44 |
// the params are cached
|
43 |
|
if (isset($this->params)) {
|
|
45 |
if (isset($this->params) && $this->params) {
|
44 |
46 |
return $this->params;
|
45 |
47 |
} else {
|
46 |
|
return parse_and_cache_params();
|
|
48 |
return $this->parse_and_cache_params();
|
47 |
49 |
}
|
48 |
50 |
}
|
49 |
51 |
|
... | ... | |
161 |
163 |
}
|
162 |
164 |
|
163 |
165 |
|
164 |
|
public static function get_all() {
|
|
166 |
public static function get_all($only_with_params=false) {
|
|
167 |
/**
|
|
168 |
* @param $only_with_params : filters out the panoramas which are not parametrized
|
|
169 |
*/
|
165 |
170 |
$panos = array_diff(scandir(PANORAMA_PATH), array('..', '.'));
|
166 |
171 |
$pano_instances = array();
|
|
172 |
|
167 |
173 |
foreach ($panos as $pano_name) {
|
168 |
|
$pano_instances[] = site_point::get($pano_name);
|
|
174 |
$pano = site_point::get($pano_name);
|
|
175 |
if (! $only_with_params || $pano->has_params() ) {
|
|
176 |
$pano_instances[] = $pano;
|
|
177 |
}
|
169 |
178 |
}
|
170 |
179 |
return $pano_instances;
|
171 |
180 |
}
|
small fixes arround site_point::get_all() usage