Advertisement
Guest User

API FFTT 2015 v1

a guest
Aug 25th, 2015
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.25 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.     class API_FFTT
  5.     {
  6.  
  7.         private function random_str($nbr) { // Génération sérial
  8.             $str = "";
  9.             $chaine = "ABCDEFGHIJKLMNOPQRSUTVWXYZ0123456789";
  10.             $nb_chars = strlen($chaine);
  11.             for($i=0; $i<$nbr; $i++)
  12.             {
  13.             $str .= $chaine[ rand(0, ($nb_chars-1)) ];
  14.             }
  15.             return $str;
  16.         }
  17.  
  18.        
  19.         public function initialisationAPI() { // Pour tests connexion
  20.             $ID = "MON_ID";
  21.             $cle = md5("MON_PASS");
  22.             $serie = $this->random_str(15);
  23.             $_SESSION["API"] = $serie ;
  24.             $tm = round(microtime(true)*1000); // timestamp en ms
  25.             $tmEntier = sprintf("%.0f", $tm); // pour ne pas avoir de notation scientifique
  26.             $tmc = hash_hmac("sha1",$tmEntier,$cle); // timestamp codé
  27.             $chaine = 'http://www.fftt.com/mobile/pxml/xml_initialisation.php?serie='.$serie.'&tm='.$tmEntier.'&tmc='.$tmc.'&id='.$ID;
  28.             $result = file_get_contents($chaine);
  29.  
  30.             $dom = new DomDocument();
  31.             $dom->loadXML($result);
  32.             $reponse = $dom->getElementsByTagName('appli')->item(0)->nodeValue;
  33.             return $reponse;
  34.         }
  35.  
  36.        
  37.         public function connexionAPI($api, $params = null){
  38.             $ID = "MON_ID";
  39.             $cle = md5("MON_PASS");
  40.             $tm = round(microtime(true)*1000); // timestamp en ms
  41.             $tmEntier = sprintf("%.0f", $tm); // pour ne pas avoir de notation scientifique
  42.             $tmc = hash_hmac("sha1",$tmEntier,$cle); // timestamp codé
  43.             $serie = $_SESSION["API"];
  44.             $url = 'http://www.fftt.com/mobile/pxml/'.$api.'.php?serie='.$serie.'&tm='.$tmEntier.'&tmc='.$tmc.'&id='.$ID;
  45.            
  46.             if (!empty($params)) {
  47.                 $url .= '&' . http_build_query($params);
  48.                 }
  49.            
  50.             $result_xml = simplexml_load_string(file_get_contents($url));
  51.             return json_decode(json_encode($result_xml), true);
  52.         }
  53.  
  54.        
  55.         public function getClubsByDepartement($departement){
  56.  
  57.                 $extract = $this->connexionAPI('xml_club_dep2', array ('dep' => $departement));
  58.                 return $this->getCollection($extract['club']);
  59.         }
  60.  
  61.        
  62.         public function getClub($numero){
  63.  
  64.                 $extract = $this->connexionAPI('xml_club_detail', array ('club' => $numero));
  65.                 return $this->getObject($extract['club']);
  66.         }
  67.  
  68.  
  69.         public function getOrganismes($type){
  70.  
  71.                 if (!in_array($type, array('Z', 'L', 'D'))) {
  72.                     $type = 'L';
  73.                 }
  74.                 $extract = $this->connexionAPI('xml_organisme', array ('type' => $type));
  75.                 return $this->getCollection($extract['organisme']);
  76.         }
  77.  
  78.  
  79.         public function getEpreuves($organisme, $type){
  80.  
  81.                 if (!in_array($type, array('E', 'I'))) {
  82.                 $type = 'E';
  83.                 }
  84.                
  85.                 $extract = $this->connexionAPI('xml_epreuve', array ('organisme' => $organisme, 'type' =>$type));
  86.                 return $this->getCollection($extract['epreuve']);
  87.         }
  88.  
  89.  
  90.         public function getDivisions($organisme, $epreuve, $type){   //ajout du type
  91.  
  92.                 $extract = $this->connexionAPI('xml_division', array ('organisme' => $organisme, 'epreuve' => $epreuve, 'type' =>$type));
  93.                 return $this->getCollection($extract['division']);
  94.         }
  95.  
  96.  
  97.         public function getPoules($division, $poule = null) {
  98.  
  99.                 $extract = $this->connexionAPI('xml_result_equ', array ('auto' => '1', 'D1' => $division, 'cx_poule' => $poule ,'action' => 'poule'));
  100.                 $poules = $this->getCollection($extract['poule']);
  101.                
  102.                 foreach($poules as &$poule) {
  103.                 $params = array();
  104.                 parse_str($poule['lien'], $params);
  105.                 $poule['idpoule'] = $params['cx_poule'];
  106.                 $poule['iddiv'] = $params['D1'];
  107.             }
  108.            
  109.             return $poules;
  110.                
  111.         }
  112.        
  113.  
  114.         public function getPouleClassement($division, $poule = null) {
  115.  
  116.                 $extract = $this->connexionAPI('xml_result_equ', array ('auto' => '1', 'D1' => $division, 'cx_poule' => $poule ,'action' => 'classement'));
  117.                 return $this->getCollection($extract['classement']);
  118.  
  119.         }
  120.  
  121.  
  122.         public function getPouleRencontres($division, $poule = null) {
  123.  
  124.                 $extract = $this->connexionAPI('xml_result_equ', array ('auto' => '1', 'D1' => $division, 'cx_poule' => $poule));
  125.                 return $this->getObject($extract['tour']);
  126.  
  127.         }
  128.  
  129.  
  130.         public function getRencontre($link){
  131.  
  132.                 $params = array();
  133.                 parse_str($link, $params);
  134.                 $extract = $this->connexionAPI('xml_chp_renc', $params);
  135.                 return $this->getObject($extract);
  136.         }
  137.  
  138.  
  139.         public function getEquipesByClub($club, $type = null){
  140.  
  141.             if ($type && !in_array($type, array('M', 'F'))) {
  142.             $type = 'M';
  143.             }
  144.  
  145.             $extract =$this->connexionAPI('xml_equipe', array ('numclu' => $club, 'type' => $type));
  146.             $teams = $this->getCollection($extract['equipe']);
  147.                
  148.             foreach($teams as &$team) {
  149.                 $params = array();
  150.                 parse_str($team['liendivision'], $params);
  151.                 $team['idpoule'] = $params['cx_poule'];
  152.                 $team['iddiv'] = $params['D1'];
  153.             }
  154.                 return $teams;
  155.         }
  156.  
  157.  
  158.         public function getIndivResult($action, $epreuve, $division, $tableau = null ){ //NOUVEAU
  159.  
  160.             $action = (($action !='classement') OR ($action !='partie')) ? 'tour' : $action;
  161.             $extract = $this->connexionAPI('xml_result_indiv', array ('epr' => $epreuve, 'res_division' => $division, 'cx_tableau' => $tableau));
  162.             return $this->getObject($extract[$action]);
  163.         }
  164.  
  165.        
  166.         public function getIndivClassement($res_division){ //NOUVEAU
  167.  
  168.                 $extract = $this->connexionAPI('xml_res_cla', array ('division' => $res_division));
  169.                 return $this->getObject($extract['classement']);
  170.         }  
  171.  
  172.        
  173.         public function getJoueursByName($nom , $prenom= ''){
  174.  
  175.                 $extract = $this->connexionAPI('xml_liste_joueur', array ('nom' => strtoupper($nom), 'prenom' => ucfirst(strtolower($prenom))));
  176.                 return $this->getCollection($extract['joueur']);
  177.         }
  178.  
  179.  
  180.         public function getJoueursByClub($club){
  181.  
  182.                 $extract = $this->connexionAPI('xml_liste_joueur', array ('club' => $club));
  183.                 return $this->getCollection($extract['joueur']);
  184.         }
  185.  
  186.        
  187.         public function getLicencesByClub($club){
  188.  
  189.                 $extract = $this->connexionAPI('xml_liste_joueur_o', array ('club' => $club));
  190.                 return $this->getCollection($extract['joueur']);
  191.         }
  192.  
  193.        
  194.         public function getLicencesByName($nom, $prenom = ''){
  195.  
  196.                 $extract = $this->connexionAPI('xml_liste_joueur_o', array ('nom' => strtoupper($nom), 'prenom' => ucfirst(strtolower($prenom))));
  197.                 return $this->getCollection($extract['joueur']);
  198.         }
  199.        
  200.        
  201.         public function getLicencesSpid($licence){  //NOUVEAU
  202.  
  203.                 $extract = $this->connexionAPI('xml_liste_joueur_o', array ('licence' => $licence));
  204.                 return $this->getCollection($extract['joueur']);
  205.         }      
  206.        
  207.        
  208.         public function getJoueurLicence($licence){ //NOUVEAU
  209.  
  210.                 $extract = $this->connexionAPI('xml_joueur', array ('licence' => $licence));
  211.                 $extract['joueur']['natio'] = empty($extract['joueur']['natio']) ? 'F' : $extract['joueur']['natio']; // Nationalité
  212.                 return $this->getObject($extract['joueur']);
  213.         }
  214.        
  215.        
  216.         public function getJoueur($licence) {
  217.  
  218.                 $extract = $this->connexionAPI('xml_joueur', array ('licence' => $licence));
  219.                 $extract['joueur']['natio'] = empty($extract['joueur']['natio']) ? 'F' : $extract['joueur']['natio']; // Nationalité
  220.                 $extract['joueur']['photo'] = "http://www.fftt.com/espacelicencie/photolicencie/{$extract['joueur']['licence']}_.jpg"; //url photo
  221.                 $extract['joueur']['progmois'] = round($extract['joueur']['point'] - $extract['joueur']['apoint'], 2); // Progression mensuelle
  222.                 $extract['joueur']['progann'] = round($extract['joueur']['point'] - $extract['joueur']['valinit'], 2); // Progression annuelle
  223.                 return $this->getObject($extract['joueur']);
  224.  
  225.         }
  226.  
  227.        
  228.         public function getLicence($licence){
  229.  
  230.                 $extract = $this->connexionAPI('xml_licence', array ('licence' => $licence));
  231.                 return $this->getObject($extract['licence']);
  232.         }
  233.        
  234.        
  235.         public function getJoueurParties($licence){
  236.  
  237.                 $extract = $this->connexionAPI('xml_partie_mysql', array ('licence' => $licence));
  238.                 return $this->getCollection($extract['partie']);
  239.         }
  240.  
  241.        
  242.         public function getJoueurPartiesSpid($licence){   //A TESTER ULTERIEUREMENT
  243.  
  244.                 $extract = $this->connexionAPI('xml_partie', array ('numlic' => $licence));
  245.                 return $this->getCollection($extract['resultat']);
  246.         }
  247.  
  248.        
  249.         public function ActuFFTT(){ //NOUVEAU
  250.  
  251.                 $extract = $this->connexionAPI('xml_new_actu');
  252.                 return $this->getObject($extract['news']);
  253.         }
  254.  
  255.  
  256.         public function JoueurHisto($licence){ //NOUVEAU
  257.  
  258.                 $extract = $this->connexionAPI('xml_histo_classement', array ('numlic' => $licence));
  259.                 return $this->getCollection($extract['histo']);
  260.         }
  261.  
  262.        
  263.         public static function getCollection($data, $key = null){
  264.             if (empty($data)) {
  265.                 return array();
  266.             }
  267.      
  268.             if ($key) {
  269.                 if (!array_key_exists($key, $data)) {
  270.                     return array();
  271.                 }
  272.                 $data = $data[$key];
  273.             }
  274.      
  275.             return isset($data[0]) ? $data : array($data);
  276.         }
  277.    
  278.    
  279.         public static function getObject($data, $key = null){
  280.             if ($key) {
  281.                 return @array_key_exists($key, $data) ? $data[$key] : null;
  282.             } else {
  283.                 return empty($data) ? null : $data;
  284.             }
  285.         }
  286.    
  287.    
  288.     }
  289.  
  290. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement