Advertisement
Guest User

Untitled

a guest
Nov 14th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.59 KB | None | 0 0
  1. <?php
  2. /**
  3.  * NET AFFILIATION
  4.  
  5.  
  6.  $regie->setRegie('NetAffiliation', // nom de la régie indiqué ci-dessus
  7.             array(
  8.                 'login' => '',  //email de login
  9.                 'passe' => '', //mdp du web service sur la plateforme
  10.                 'channel' => '' //id du site à renseigner obligatoirement
  11.                
  12.             )
  13.         );  
  14.  
  15.  * -----------------------------------------------------------------------------
  16.  */
  17. class AffiliStat_NetAffiliation extends AffiliStat implements iAffiliStat
  18. {
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.     }
  23.  
  24.     public function __destruct()
  25.     {
  26.         parent::__destruct();
  27.     }
  28.  
  29.     /**
  30.      * Connexion
  31.      */
  32.     public function login()
  33.     {
  34.         /* On recup charge.php pour pouvoir se connecter */
  35.         $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut=2013-11-01&fin=2013-11-14&champs=idcamp,nomcamp,idsite,nomsite,gaiatt,gaival';
  36.         //echo $URL;
  37.        
  38.         $data = array(
  39.                     'identif' => $this->login,
  40.                     'mdp' => $this->passe
  41.                 );
  42.     }
  43.  
  44.  
  45.     /**
  46.      * Stats par jour
  47.      */
  48.     public function parJour($parDate=NULL, $moinsJour=NULL)
  49.     {
  50.         if ($moinsJour !== NULL)
  51.         {
  52.             $parDate = date('Y-m-d',time()-3600*24*$moinsJour);
  53.         }
  54.  
  55.         //$URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$parDate.'&fin='.$parDate.'&champs=gaiatt,gaival';
  56.        
  57.         $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$parDate.'&fin='.$parDate.'&champs=idsite,gaiatt,gaival&dim=2';
  58.         //echo $URL;
  59.        
  60.         $xml = file_get_contents($URL);
  61.         $rows = explode(PHP_EOL, $xml);
  62.        
  63.         $total = array();
  64.         foreach($rows as $row){
  65.             $row1 = explode(';', $row);
  66.             //print_r($row1);
  67.             $channel = $this->param['channel'];
  68.             if(($row1[1] != '') AND ($row1[0] == $channel)){
  69.                 $rowtotal = $row1[1] + $row1[2];
  70.                 $total[] = $rowtotal;
  71.             }
  72.         }
  73.        
  74.         $return[$parDate] = array_sum($total);
  75.        
  76.         return $return;
  77.     }
  78.  
  79.     /**
  80.      * Stats par mois
  81.      */
  82.     public function parMois($mois=NULL, $an=NULL, $moinsMois=NULL)
  83.     {
  84.        
  85.         if ($moinsMois !== NULL)
  86.         {
  87.             $leMois = date('Y-m',strtotime('-' . $moinsMois . ' month'));
  88.             $data = $this->_parametre(
  89.                         date('Y-m-01',strtotime('-' . $moinsMois . ' month')),
  90.                         date('Y-m-t',strtotime('-' . $moinsMois . ' month')));
  91.             //print_r($data);
  92.             $debutmois = $data['dateDailyDeb1'];
  93.             $finmois = $data['dateDailyFin1'];
  94.         }
  95.         elseif ($mois !== NULL && $an !== NULL)
  96.         {
  97.             $leMois = $mois.'-'.$an;
  98.             $data = $this->_parametre(
  99.                             date('Y-m-01',strtotime('-' . $moinsMois . ' month')),
  100.                             date('Y-m-t',strtotime('-' . $moinsMois . ' month')));
  101.                 //print_r($data);
  102.                 $debutmois = $data['dateDailyDeb1'];
  103.                 $finmois = $data['dateDailyFin1'];
  104.         }
  105.  
  106.         $URL = 'https://stat.netaffiliation.com/listing.php?authl='.$this->login.'&authv='.$this->passe.'&debut='.$debutmois.'&fin='.$finmois.'&champs=idsite,gaiatt,gaival&dim=2';
  107.         //echo $URL;
  108.        
  109.         $xml = file_get_contents($URL);
  110.         $rows = explode(PHP_EOL, $xml);
  111.        
  112.         $total = array();
  113.         foreach($rows as $row){
  114.             $row1 = explode(';', $row);
  115.             //print_r($row1);
  116.             $channel = $this->param['channel'];
  117.             if(($row1[1] != '') AND ($row1[0] == $channel)){
  118.                 $rowtotal = $row1[1] + $row1[2];
  119.                 $total[] = $rowtotal;
  120.             }
  121.         }
  122.        
  123.         $return[$parDate] = array_sum($total);
  124.        
  125.         return $return;
  126.     }
  127.  
  128.     /**
  129.      * On est connecté ?
  130.      */
  131.     public function isConnecte()
  132.     {
  133.         $arrRecordFile = $this->_getRecord();
  134.         $arrRecordFile = $arrRecordFile[$this->_getRecordValue()];
  135.  
  136.         if (isset($arrRecordFile))
  137.         {
  138.             $diffTime = time()-(int)$arrRecordFile['time'];
  139.  
  140.             if ($diffTime < (15*60))
  141.             {
  142.                 $URL = 'http://'.$arrRecordFile['sousDomaine'].'.netaffiliation.com/aff/';
  143.  
  144.                 $ch = curl_init();
  145.                 curl_setopt($ch, CURLOPT_URL, $URL);
  146.                 curl_setopt($ch, CURLOPT_HEADER, true);
  147.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  148.                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  149.                 curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookie());
  150.                 curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookie());
  151.                 $String = curl_exec($ch);
  152.                 curl_close($ch);
  153.  
  154.                 if (!preg_match('|.*302 Found.*|is',$String))
  155.                 {
  156.                     $this->sousDomaine = $arrRecordFile['sousDomaine'];
  157.                     return true;
  158.                 }
  159.             }
  160.         }
  161.  
  162.         return false;
  163.     }
  164.  
  165.     /**
  166.      * Fonction
  167.      */
  168.     private function _parametre ($dateDeb, $dateFin)
  169.     {
  170.         return array(
  171.                     'dateDailyDeb1' => $dateDeb,
  172.                     'dateDailyFin1' => $dateFin,
  173.                     'mode' => 'AjaxDaily',
  174.                 );
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement