partner/library/Scores/Mappy.php

76 lines
1.6 KiB
PHP
Raw Normal View History

2013-10-15 15:30:21 +00:00
<?php
2014-04-22 14:16:46 +00:00
class Mappy
2013-10-15 15:30:21 +00:00
{
protected $login = 'scoresdecisions';
protected $password = 'g1nq3iKv';
2014-04-22 14:16:46 +00:00
2013-10-15 15:30:21 +00:00
protected $villes = array(
2014-04-22 14:16:46 +00:00
'BORDEAUX',
'CAEN' ,
2013-10-15 15:30:21 +00:00
'CANNES',
2014-04-22 14:16:46 +00:00
'GRENOBLE',
'LA BAULE',
2013-10-15 15:30:21 +00:00
'LILLE',
2014-04-22 14:16:46 +00:00
'LYON',
'MARSEILLE',
2013-10-15 15:30:21 +00:00
'MONTPELLIER',
2014-04-22 14:16:46 +00:00
'NANCY',
'NANTES',
2013-10-15 15:30:21 +00:00
'NICE',
2014-04-22 14:16:46 +00:00
'RENNES',
'STRASBOURG',
2013-10-15 15:30:21 +00:00
'TOULOUSE',
2014-04-22 14:16:46 +00:00
'ASNIERES-SUR-SEINE',
'BOULOGNE-BILLANCOURT',
2013-10-15 15:30:21 +00:00
'COURBEVOIE',
2014-04-22 14:16:46 +00:00
'ISSY-LES-MOULINEAUX',
2013-10-15 15:30:21 +00:00
'LEVALLOIS-PERRET',
2014-04-22 14:16:46 +00:00
'MONTROUGE',
'NANTERRE',
2013-10-15 15:30:21 +00:00
'NEUILLY-SUR-SEINE',
2014-04-22 14:16:46 +00:00
'RUEIL-MALMAISON',
'SEVRES',
2013-10-15 15:30:21 +00:00
'VERSAILLES',
2014-04-22 14:16:46 +00:00
'PARIS'
2013-10-15 15:30:21 +00:00
);
2014-04-22 14:16:46 +00:00
2013-10-15 15:30:21 +00:00
public function getToken()
{
$ACCESSOR_URL = 'http://axe.mappy.com/1v1/';
$timestamp = time();
$hash = md5($this->login."@".$this->password."@".$timestamp);
$preToken = $this->login."@".$timestamp."@".$hash;
$urlGetToken = $ACCESSOR_URL . 'token/generate.aspx?auth=' . urlencode($preToken) . '&ip=' . urlencode($_SERVER["REMOTE_ADDR"]);
2014-04-22 14:16:46 +00:00
$fh = @fopen($urlGetToken, 'rb');
2013-10-15 15:30:21 +00:00
if ($fh == false) return false;
$token = '';
while (!feof($fh))$token .= fread($fh, 8192);
fclose($fh);
return ($token);
}
2014-04-22 14:16:46 +00:00
2013-10-15 15:30:21 +00:00
protected function cleanAdress($ville)
{
$ville = ' '.trim(preg_replace('/([0-9]|ARRONDISSEMENT|_)/i', ' ', $ville)).' ';
$ville = trim(strtr($ville, array(' EME ' => '', ' ER ' => '')));
return (ucwords(strtolower($ville)));
}
2014-04-22 14:16:46 +00:00
2013-10-15 15:30:21 +00:00
public function villeCouverte($ville)
{
$ville = $this->cleanAdress($ville);
2014-04-22 14:16:46 +00:00
/*if (in_array(strtoupper($ville),$this->villes)){
2013-10-15 15:30:21 +00:00
return true;
2014-04-22 14:16:46 +00:00
}*/
return false;
}
2013-10-15 15:30:21 +00:00
public function getJs()
{
$token = $this->getToken();
$href = 'http://axe.mappy.com/1v1/init/get.aspx?auth='.$token.'&version=2.16&solution=ajax';
2014-04-22 14:16:46 +00:00
return $href;
2013-10-15 15:30:21 +00:00
}
2014-04-22 14:16:46 +00:00
2013-10-15 15:30:21 +00:00
}