Projet

Général

Profil

Révision ea08a2a7

Ajouté par Jocelyn Delande il y a presque 11 ans

adds a rm_reference.php webservice and fixed the typing from/to ini files

Voir les différences:

ajax/rm_reference.php
1
<?php
2
require_once('../class/FormValidator.class.php');
3
require_once('../class/RefPoint.class.php');
4
require_once('../class/site_point.class.php');
5

  
6
$fields_spec = array('panorama'  => array('required'),
7
                     'ref_point' => array('required'),
8
);
9

  
10

  
11
$validator = new FormValidator($fields_spec);
12
if ($validator->validate($_REQUEST)) {
13
  $vals = $validator->sane_values();
14

  
15
  // temp test code
16
  $pano = site_point::get($vals['panorama']);
17

  
18
  $ref_point_name = urldecode($vals['ref_point']);
19
  $ref_point = RefPoint::get($ref_point_name);
20

  
21
  $pano->unset_reference($ref_point);
22
  $pano->save_params();
23

  
24
 } else {
25
   // Set our response code
26
   http_response_code(400);
27
   echo var_dump($validator->errors());
28
 }
29
// Test url : clear ;curl 'http://localhost/~jocelyn/panorama/ajax/add_reference.php?x=42&y=42&panorama=pano_couttolenc_bords_jointifs&ref_point=%C3%89glise%20saint-jacques'
30

  
31
?>
class/site_point.class.php
1 1
<?php
2 2
require_once(dirname(__FILE__).'/../constants.inc.php');
3
require_once(dirname(__FILE__).'/utils.class.php');
3 4

  
4 5
//
5 6
class PanoramaFormatException extends Exception {
......
40 41
	    $params = parse_ini_file($this->params_path());
41 42
	    if ($params) {
42 43
		    $this->params = $params;
44
		    foreach ($params[self::$REF_KEY] as $ref => $vals) {
45
			    $bits = explode(',',$vals);
46
			    $this->params[self::$REF_KEY][$ref] = array(floatval($bits[0]),
47
			                                          floatval($bits[1]));
48
		    }
49
		    if (isset($params['image_loop'])) {
50
			    $this->params['image_loop'] = (bool)($params['image_loop']);
51
		    }
43 52
		    return $params;
44 53
	    }
45 54
    }
......
66 75
				               $refv[0], $refv[1]);
67 76
			  }
68 77
		  } else {
69
			  $o.= "$k = $v\n";
78
			  $o.= "$k = ".utils::php2ini($v)."\n";
70 79
		  }
71 80
	  }
72 81
	  file_put_contents($this->params_path(), $o);
......
171 180
	  $this->params[self::$REF_KEY][$ref_name] = array($x, $y);
172 181
  }
173 182

  
183
  public function unset_reference($ref_point) {
184
	  /**
185
	   * Unregisters a reference, within a panorama.
186
	   * does nothing if the RefPoint is not registered.
187
	   *
188
	   * @param $ref_point a RefPoint instance
189
	   */
190
	  $p = $this->get_params();
191
	  $ref_name = $ref_point->name;
192
	  if (isset($p[self::$REF_KEY]) &&
193
	      isset($p[self::$REF_KEY][$ref_name])) {
194
		  unset($this->params[self::$REF_KEY][$ref_name]);
195
	  }
196
  }
197

  
198

  
199

  
174 200
  public static function get($name) {
175 201
	  /** Instantiate a site_point, given its name
176 202
	   */
class/utils.class.php
48 48
	   */
49 49
	  return preg_replace('/\.[^.]+$/', '', $filename);
50 50
  }
51

  
52
  public static function php2ini($v) {
53
	  /** convert php var to a string representing it in an ini file.
54
	   * @return a string, ready to be inserted into a ini file.
55
	   */
56
    if (is_numeric($v)) {
57
      return $v;
58
    }
59
    $type = gettype($v);
60
    switch($type) {
61
      case 'boolean': return $v ? "true" : "false";
62
      default: return '"'.$v.'"';
63
    }
64
    return $v;
65
  }
51 66
}
52 67

  
53 68
?>

Formats disponibles : Unified diff